Skip to content

Commit d595b3e

Browse files
committed
Improve test and fix issue
1 parent 5d00b25 commit d595b3e

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

src/Console/GenerateInput.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
namespace OpenApi\Console;
88

9-
use OpenApi\Annotations as OA;
109
use Symfony\Component\Console\Attribute\Argument;
1110
use Symfony\Component\Console\Attribute\Option;
1211
use Symfony\Component\Console\Exception\InvalidArgumentException;
@@ -44,7 +43,7 @@ class GenerateInput
4443
public array $removeProcessor = [];
4544

4645
#[Option('The OpenAPI version')]
47-
public string $version = OA\OpenApi::DEFAULT_VERSION;
46+
public ?string $version = null;
4847

4948
#[Option('Show additional error information', shortcut: 'd')]
5049
public bool $debug = false;

tests/CommandlineTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace OpenApi\Tests;
88

99
use OpenApi\Tests\Concerns\UsesExamples;
10+
use PHPUnit\Framework\Attributes\DataProvider;
1011

1112
final class CommandlineTest extends OpenApiTestCase
1213
{
@@ -78,12 +79,19 @@ public function testMissingArg(): void
7879
$this->assertStringContainsString('The "--exclude" option requires a value.', $output);
7980
}
8081

81-
public function testVersionDefault(): void
82+
public static function versionCases(): iterable
83+
{
84+
yield 'default' => ['', '3.1.0'];
85+
yield 'override' => ['--version=3.0.3', '3.0.3'];
86+
}
87+
88+
#[DataProvider('versionCases')]
89+
public function testVersionDefault(string $args, string $expectedVersion): void
8290
{
8391
$fixture = $this->fixture('Explicit310.php');
84-
$cmd = __DIR__ . '/../bin/openapi --bootstrap ' . $fixture . ' ' . escapeshellarg($fixture);
92+
$cmd = __DIR__ . '/../bin/openapi --bootstrap ' . $fixture . " $args " . escapeshellarg($fixture);
8593
exec($this->getCommandToExecute($cmd, '2>'), $output, $retval);
8694
$this->assertSame(0, $retval, $cmd . PHP_EOL . implode(PHP_EOL, $output));
87-
$this->assertStringContainsString('openapi: 3.1.0', implode(PHP_EOL, $output));
95+
$this->assertStringContainsString("openapi: $expectedVersion", implode(PHP_EOL, $output));
8896
}
8997
}

tests/Fixtures/Explicit310.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@
3636
),
3737
],
3838
)]
39-
class Explicit310 { }
39+
class Explicit310
40+
{
41+
}

0 commit comments

Comments
 (0)