overrideConfigValues( [ // Run with the default useBundled=true 'PygmentizePath' => false, // Silence wfWarn for the expected Shellbox error MainConfigNames::DevelopmentWarnings => false, ] ); } private function stubShellbox( ?BoxedResult $result, ?Exception $e ) { $factory = $this->createStub( CommandFactory::class ); $command = new class ( $result, $e ) extends BoxedCommand { private $result; private $e; public function __construct( $result, $e ) { $this->result = $result; $this->e = $e; } public function execute(): BoxedResult { if ( $this->e ) { throw $this->e; } return $this->result; } }; $factory->method( 'createBoxed' )->willReturn( $command ); $this->setService( 'ShellCommandFactory', $factory ); } public static function provideHighlight() { yield 'basic' => [ ( new BoxedResult ) ->stdout( '
x
' ]; yield 'pre-fallback for non-zero exit' => [ ( new BoxedResult ) ->stdout( 'Boo' ) ->exitCode( 42 ), null, '
"example"
' ]; yield 'pre-fallback for network error (T292663)' => [ null, new ShellboxError( 'Wazaaaa', 0 ), '
"example"
' ]; } /** * @dataProvider provideHighlight */ public function testHighlightBasic( ?BoxedResult $result, ?Exception $e, string $expect ) { $this->stubShellbox( $result, $e ); $status = SyntaxHighlight::highlight( '"example"', 'json' ); $this->assertSame( $expect, $status->getValue() ); } }