@@ -12,22 +12,37 @@ class CommandlineTest extends OpenApiTestCase
1212{
1313 use UsesExamples;
1414
15+ private function getCommandToExecute (string $ cmd , ?string $ devNullRedir = null ): string
16+ {
17+ if (PHP_OS_FAMILY === 'Windows ' ) {
18+ $ cmd = 'php ' . $ cmd ;
19+ $ devNull = 'NUL ' ;
20+ } else {
21+ $ devNull = '/dev/null ' ;
22+ }
23+ if ($ devNullRedir ) {
24+ $ cmd .= " $ devNullRedir $ devNull " ;
25+ }
26+
27+ return $ cmd ;
28+ }
29+
1530 public function testStdout (): void
1631 {
1732 $ basePath = $ this ->examplePath ('petstore ' );
1833 $ path = "$ basePath/annotations " ;
19- exec (__DIR__ . '/../bin/openapi --bootstrap ' . __DIR__ . '/cl_bootstrap.php --format yaml ' . escapeshellarg ($ path ) . ' 2> /dev/null ' , $ output , $ retval );
34+ exec ($ this -> getCommandToExecute ( __DIR__ . '/../bin/openapi --bootstrap ' . __DIR__ . '/cl_bootstrap.php --format yaml ' . escapeshellarg ($ path ), ' 2> ' ) , $ output , $ retval );
2035 $ this ->assertSame (0 , $ retval , implode (PHP_EOL , $ output ));
2136 $ yaml = implode (PHP_EOL , $ output );
2237 $ this ->assertSpecEquals (file_get_contents ($ this ->getSpecFilename ('petstore ' )), $ yaml );
2338 }
2439
25- public function testOutputTofile (): void
40+ public function testOutputToFile (): void
2641 {
2742 $ basePath = $ this ->examplePath ('petstore ' );
2843 $ path = "$ basePath/annotations " ;
2944 $ filename = sys_get_temp_dir () . '/swagger-php-clitest.yaml ' ;
30- exec (__DIR__ . '/../bin/openapi --bootstrap ' . __DIR__ . '/cl_bootstrap.php --format yaml -o ' . escapeshellarg ($ filename ) . ' ' . escapeshellarg ($ path ) . ' 2> /dev/null ' , $ output , $ retval );
45+ exec ($ this -> getCommandToExecute ( __DIR__ . '/../bin/openapi --bootstrap ' . __DIR__ . '/cl_bootstrap.php --format yaml -o ' . escapeshellarg ($ filename ) . ' ' . escapeshellarg ($ path ), ' 2> ' ) , $ output , $ retval );
3146 $ this ->assertSame (0 , $ retval , implode (PHP_EOL , $ output ));
3247 $ this ->assertCount (0 , $ output , 'No output to stdout ' );
3348 $ yaml = file_get_contents ($ filename );
@@ -40,15 +55,15 @@ public function testAddProcessor(): void
4055 $ basePath = $ this ->examplePath ('petstore ' );
4156 $ path = "$ basePath/annotations " ;
4257 $ cmd = __DIR__ . '/../bin/openapi --bootstrap ' . __DIR__ . '/cl_bootstrap.php --processor OperationId --format yaml ' . escapeshellarg ($ path );
43- exec ($ cmd . ' 2> /dev/null ' , $ output , $ retval );
58+ exec ($ this -> getCommandToExecute ( $ cmd, ' 2> ' ) , $ output , $ retval );
4459 $ this ->assertSame (0 , $ retval , $ cmd . PHP_EOL . implode (PHP_EOL , $ output ));
4560 }
4661
4762 public function testExcludeListWarning (): void
4863 {
4964 $ basePath = $ this ->examplePath ('petstore ' );
5065 $ path = "$ basePath/annotations " ;
51- exec (__DIR__ . '/../bin/openapi -e foo,bar ' . escapeshellarg ($ path ) . ' 2>&1 ' , $ output , $ retval );
66+ exec ($ this -> getCommandToExecute ( __DIR__ . '/../bin/openapi -e foo,bar ' . escapeshellarg ($ path ) . ' 2>&1 ' ) , $ output , $ retval );
5267 $ this ->assertSame (1 , $ retval );
5368 $ output = implode (PHP_EOL , $ output );
5469 $ this ->assertStringContainsString ('Comma-separated exclude paths are deprecated ' , $ output );
@@ -58,7 +73,7 @@ public function testMissingArg(): void
5873 {
5974 $ basePath = $ this ->examplePath ('petstore ' );
6075 $ path = "$ basePath/annotations " ;
61- exec (__DIR__ . '/../bin/openapi ' . escapeshellarg ($ path ) . ' -e 2>&1 ' , $ output , $ retval );
76+ exec ($ this -> getCommandToExecute ( __DIR__ . '/../bin/openapi ' . escapeshellarg ($ path ) . ' -e 2>&1 ' ) , $ output , $ retval );
6277 $ this ->assertSame (1 , $ retval );
6378 $ output = implode (PHP_EOL , $ output );
6479 $ this ->assertStringContainsString ('Error: Missing argument for "-e" ' , $ output );
0 commit comments