-
-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,10 +18,13 @@ | |
use Doctrine\Migrations\Version\Version; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Console\Helper\HelperSet; | ||
use Symfony\Component\Console\Helper\QuestionHelper; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
use function array_map; | ||
use function explode; | ||
use function sprintf; | ||
use function sys_get_temp_dir; | ||
use function trim; | ||
|
||
|
@@ -139,6 +142,44 @@ public function testExecutedUnavailableMigrationsCancel(): void | |
self::assertSame(3, $statusCode); | ||
} | ||
|
||
/** @return array<string, int|null, array<string[]>> */ | ||
public static function getNamespaceSelected(): array | ||
Check failure on line 146 in tests/Tools/Console/Command/DiffCommandTest.php GitHub Actions / Static Analysis with PHPStan (8.3)
Check failure on line 146 in tests/Tools/Console/Command/DiffCommandTest.php GitHub Actions / Static Analysis with PHPStan (8.3)
|
||
{ | ||
return [ | ||
'no' => [null, 'FooNs'], | ||
'first' => [0, 'FooNs'], | ||
'two' => [1, 'FooNs2'], | ||
]; | ||
} | ||
|
||
/** @dataProvider getNamespaceSelected */ | ||
public function testExecuteWithMultipleDirectories(int|null $input, string $namespace): void | ||
{ | ||
$this->migrationStatusCalculator | ||
->method('getNewMigrations') | ||
->willReturn(new AvailableMigrationsList([])); | ||
|
||
$this->migrationStatusCalculator | ||
->method('getExecutedUnavailableMigrations') | ||
->willReturn(new ExecutedMigrationsList([])); | ||
|
||
$this->configuration->addMigrationsDirectory('FooNs2', sys_get_temp_dir()); | ||
|
||
$this->diffCommand->setHelperSet(new HelperSet(['question' => new QuestionHelper()])); | ||
|
||
$this->migrationDiffGenerator->expects(self::once())->method('generate'); | ||
|
||
$this->diffCommandTester->setInputs([$input]); | ||
$this->diffCommandTester->execute([]); | ||
|
||
$output = $this->diffCommandTester->getDisplay(true); | ||
|
||
self::assertStringContainsString('Please choose a namespace (defaults to the first one)', $output); | ||
self::assertStringContainsString('[0] FooNs', $output); | ||
self::assertStringContainsString('[1] FooNs2', $output); | ||
self::assertStringContainsString(sprintf('You have selected the "%s" namespace', $namespace), $output); | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->migrationDiffGenerator = $this->createMock(DiffGenerator::class); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,10 +18,13 @@ | |
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
use RuntimeException; | ||
use Symfony\Component\Console\Helper\HelperSet; | ||
use Symfony\Component\Console\Helper\QuestionHelper; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
use function array_map; | ||
use function explode; | ||
use function sprintf; | ||
use function sys_get_temp_dir; | ||
use function trim; | ||
|
||
|
@@ -62,6 +65,16 @@ public function testExecute(): void | |
->method('getMigrations') | ||
->willReturn(new AvailableMigrationsSet([])); | ||
|
||
$classNameGenerator = $this->createMock(ClassNameGenerator::class); | ||
$classNameGenerator->expects(self::any()) | ||
->method('generateClassName') | ||
->with('FooNs') | ||
->willReturn('FooNs\\Version1234'); | ||
|
||
$this->dependencyFactory->expects(self::any()) | ||
->method('getClassNameGenerator') | ||
->willReturn($classNameGenerator); | ||
|
||
$this->schemaDumper->expects(self::once()) | ||
->method('dump') | ||
->with('FooNs\\Version1234', ['/foo/'], true, 80); | ||
|
@@ -88,6 +101,40 @@ public function testExecute(): void | |
); | ||
} | ||
|
||
/** @return array<string, int|null, array<string[]>> */ | ||
public static function getNamespaceSelected(): array | ||
Check failure on line 105 in tests/Tools/Console/Command/DumpSchemaCommandTest.php GitHub Actions / Static Analysis with PHPStan (8.3)
Check failure on line 105 in tests/Tools/Console/Command/DumpSchemaCommandTest.php GitHub Actions / Static Analysis with PHPStan (8.3)
|
||
{ | ||
return [ | ||
'no' => [null, 'FooNs'], | ||
'first' => [0, 'FooNs'], | ||
'two' => [1, 'FooNs2'], | ||
]; | ||
} | ||
|
||
/** @dataProvider getNamespaceSelected */ | ||
public function testExecuteWithMultipleDirectories(int|null $input, string $namespace): void | ||
{ | ||
$this->migrationRepository->expects(self::once()) | ||
->method('getMigrations') | ||
->willReturn(new AvailableMigrationsSet([])); | ||
|
||
$this->configuration->addMigrationsDirectory('FooNs2', sys_get_temp_dir()); | ||
|
||
$this->dumpSchemaCommand->setHelperSet(new HelperSet(['question' => new QuestionHelper()])); | ||
|
||
$this->schemaDumper->expects(self::once())->method('dump'); | ||
|
||
$this->dumpSchemaCommandTester->setInputs([$input]); | ||
$this->dumpSchemaCommandTester->execute([]); | ||
|
||
$output = $this->dumpSchemaCommandTester->getDisplay(true); | ||
|
||
self::assertStringContainsString('Please choose a namespace (defaults to the first one)', $output); | ||
self::assertStringContainsString('[0] FooNs', $output); | ||
self::assertStringContainsString('[1] FooNs2', $output); | ||
self::assertStringContainsString(sprintf('You have selected the "%s" namespace', $namespace), $output); | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->configuration = new Configuration(); | ||
|
@@ -97,16 +144,6 @@ protected function setUp(): void | |
$this->migrationRepository = $this->createMock(FilesystemMigrationsRepository::class); | ||
$this->schemaDumper = $this->createMock(SchemaDumper::class); | ||
|
||
$classNameGenerator = $this->createMock(ClassNameGenerator::class); | ||
$classNameGenerator->expects(self::any()) | ||
->method('generateClassName') | ||
->with('FooNs') | ||
->willReturn('FooNs\\Version1234'); | ||
|
||
$this->dependencyFactory->expects(self::any()) | ||
->method('getClassNameGenerator') | ||
->willReturn($classNameGenerator); | ||
|
||
$this->dependencyFactory->expects(self::any()) | ||
->method('getSchemaDumper') | ||
->willReturn($this->schemaDumper); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,13 @@ | |
use Doctrine\Migrations\Tools\Console\Command\GenerateCommand; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Console\Helper\HelperSet; | ||
use Symfony\Component\Console\Helper\QuestionHelper; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
use function array_map; | ||
use function explode; | ||
use function sprintf; | ||
use function sys_get_temp_dir; | ||
use function trim; | ||
|
||
|
@@ -39,6 +42,16 @@ public function testExecute(): void | |
->with('FooNs\\Version1234') | ||
->willReturn('/path/to/migration.php'); | ||
|
||
$classNameGenerator = $this->createMock(ClassNameGenerator::class); | ||
$classNameGenerator->expects(self::once()) | ||
->method('generateClassName') | ||
->with('FooNs') | ||
->willReturn('FooNs\\Version1234'); | ||
|
||
$this->dependencyFactory->expects(self::once()) | ||
->method('getClassNameGenerator') | ||
->willReturn($classNameGenerator); | ||
|
||
$this->generateCommandTest->execute([]); | ||
$output = $this->generateCommandTest->getDisplay(true); | ||
|
||
|
@@ -51,6 +64,34 @@ public function testExecute(): void | |
], array_map(trim(...), explode("\n", trim($output)))); | ||
} | ||
|
||
/** @return array<string, int|null, array<string[]>> */ | ||
public static function getNamespaceSelected(): array | ||
Check failure on line 68 in tests/Tools/Console/Command/GenerateCommandTest.php GitHub Actions / Static Analysis with PHPStan (8.3)
Check failure on line 68 in tests/Tools/Console/Command/GenerateCommandTest.php GitHub Actions / Static Analysis with PHPStan (8.3)
|
||
{ | ||
return [ | ||
'no' => [null, 'FooNs'], | ||
'first' => [0, 'FooNs'], | ||
'two' => [1, 'FooNs2'], | ||
]; | ||
} | ||
|
||
/** @dataProvider getNamespaceSelected */ | ||
public function testExecuteWithMultipleDirectories(int|null $input, string $namespace): void | ||
{ | ||
$this->configuration->addMigrationsDirectory('FooNs2', sys_get_temp_dir()); | ||
|
||
$this->generateCommand->setHelperSet(new HelperSet(['question' => new QuestionHelper()])); | ||
|
||
$this->generateCommandTest->setInputs([$input]); | ||
$this->generateCommandTest->execute([]); | ||
|
||
$output = $this->generateCommandTest->getDisplay(true); | ||
|
||
self::assertStringContainsString('Please choose a namespace (defaults to the first one)', $output); | ||
self::assertStringContainsString('[0] FooNs', $output); | ||
self::assertStringContainsString('[1] FooNs2', $output); | ||
self::assertStringContainsString(sprintf('You have selected the "%s" namespace', $namespace), $output); | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->configuration = new Configuration(); | ||
|
@@ -59,16 +100,6 @@ protected function setUp(): void | |
$this->dependencyFactory = $this->createMock(DependencyFactory::class); | ||
$this->migrationGenerator = $this->createMock(Generator::class); | ||
|
||
$classNameGenerator = $this->createMock(ClassNameGenerator::class); | ||
$classNameGenerator->expects(self::once()) | ||
->method('generateClassName') | ||
->with('FooNs') | ||
->willReturn('FooNs\\Version1234'); | ||
|
||
$this->dependencyFactory->expects(self::once()) | ||
->method('getClassNameGenerator') | ||
->willReturn($classNameGenerator); | ||
|
||
$this->dependencyFactory->expects(self::any()) | ||
->method('getConfiguration') | ||
->willReturn($this->configuration); | ||
|