doctrine /
DoctrineMigrationsBundle
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Doctrine\Bundle\MigrationsBundle\Tests\DependencyInjection; |
||
| 6 | |||
| 7 | use Doctrine\Bundle\MigrationsBundle\DependencyInjection\CompilerPass\ConfigureDependencyFactoryPass; |
||
| 8 | use Doctrine\Bundle\MigrationsBundle\DependencyInjection\DoctrineMigrationsExtension; |
||
| 9 | use Doctrine\Migrations\Tools\Console\Command\CurrentCommand; |
||
| 10 | use Doctrine\Migrations\Tools\Console\Command\DiffCommand; |
||
| 11 | use Doctrine\Migrations\Tools\Console\Command\DumpSchemaCommand; |
||
| 12 | use Doctrine\Migrations\Tools\Console\Command\ExecuteCommand; |
||
| 13 | use Doctrine\Migrations\Tools\Console\Command\GenerateCommand; |
||
| 14 | use Doctrine\Migrations\Tools\Console\Command\LatestCommand; |
||
| 15 | use Doctrine\Migrations\Tools\Console\Command\ListCommand; |
||
| 16 | use Doctrine\Migrations\Tools\Console\Command\MigrateCommand; |
||
| 17 | use Doctrine\Migrations\Tools\Console\Command\RollupCommand; |
||
| 18 | use Doctrine\Migrations\Tools\Console\Command\StatusCommand; |
||
| 19 | use Doctrine\Migrations\Tools\Console\Command\SyncMetadataCommand; |
||
| 20 | use Doctrine\Migrations\Tools\Console\Command\UpToDateCommand; |
||
| 21 | use Doctrine\Migrations\Tools\Console\Command\VersionCommand; |
||
| 22 | use Doctrine\ORM\EntityManager; |
||
| 23 | use PHPUnit\Framework\MockObject\MockObject; |
||
| 24 | use PHPUnit\Framework\TestCase; |
||
| 25 | use Symfony\Bundle\FrameworkBundle\Console\Application; |
||
| 26 | use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass; |
||
| 27 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
||
| 28 | use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; |
||
| 29 | use Symfony\Component\HttpKernel\KernelInterface; |
||
| 30 | use function sys_get_temp_dir; |
||
| 31 | |||
| 32 | class DoctrineCommandsTest extends TestCase |
||
| 33 | { |
||
| 34 | /** |
||
| 35 | * @dataProvider getCommands |
||
| 36 | */ |
||
| 37 | public function testCommandRegistered(string $name, string $instance) : void |
||
| 38 | { |
||
| 39 | $application = $this->getApplication(); |
||
| 40 | |||
| 41 | self::assertInstanceOf($instance, $application->find($name)); |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @return string[][] |
||
| 46 | */ |
||
| 47 | public function getCommands() : array |
||
| 48 | { |
||
| 49 | return [ |
||
| 50 | ['doctrine:migrations:diff', DiffCommand::class], |
||
| 51 | ['doctrine:migrations:current', CurrentCommand::class], |
||
| 52 | ['doctrine:migrations:dump-schema', DumpSchemaCommand::class], |
||
| 53 | ['doctrine:migrations:execute', ExecuteCommand::class], |
||
| 54 | ['doctrine:migrations:generate', GenerateCommand::class], |
||
| 55 | ['doctrine:migrations:latest', LatestCommand::class], |
||
| 56 | ['doctrine:migrations:list', ListCommand::class], |
||
| 57 | ['doctrine:migrations:migrate', MigrateCommand::class], |
||
| 58 | ['doctrine:migrations:rollup', RollupCommand::class], |
||
| 59 | ['doctrine:migrations:status', StatusCommand::class], |
||
| 60 | ['doctrine:migrations:sync-metadata-storage', SyncMetadataCommand::class], |
||
| 61 | ['doctrine:migrations:up-to-date', UpToDateCommand::class], |
||
| 62 | ['doctrine:migrations:version', VersionCommand::class], |
||
| 63 | ]; |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @return MockObject|KernelInterface |
||
| 68 | */ |
||
| 69 | private function getKernel(ContainerBuilder $container) |
||
| 70 | { |
||
| 71 | $kernel = $this->createMock(KernelInterface::class); |
||
| 72 | |||
| 73 | $kernel |
||
| 74 | ->method('getContainer') |
||
| 75 | ->willReturn($container); |
||
| 76 | |||
| 77 | $kernel |
||
| 78 | ->method('getBundles') |
||
| 79 | ->willReturn([]); |
||
| 80 | |||
| 81 | return $kernel; |
||
| 82 | } |
||
| 83 | |||
| 84 | private function getApplication() : Application |
||
| 85 | { |
||
| 86 | $container = new ContainerBuilder(new ParameterBag([ |
||
| 87 | 'kernel.debug' => false, |
||
| 88 | 'kernel.bundles' => [], |
||
| 89 | 'kernel.cache_dir' => sys_get_temp_dir(), |
||
| 90 | 'kernel.environment' => 'test', |
||
| 91 | 'kernel.project_dir' => __DIR__ . '/../', |
||
| 92 | ])); |
||
| 93 | |||
| 94 | $kernel = $this->getKernel($container); |
||
| 95 | $application = new Application($kernel); |
||
| 96 | $container->set('application', $application); |
||
| 97 | |||
| 98 | $em = $this->createMock(EntityManager::class); |
||
| 99 | $container->set('doctrine.orm.default_entity_manager', $em); |
||
| 100 | |||
| 101 | $container->addCompilerPass(new AddConsoleCommandPass()); |
||
| 102 | |||
| 103 | $extension = new DoctrineMigrationsExtension(); |
||
| 104 | $extension->load([ |
||
| 105 | 'doctrine_migrations' => [ |
||
| 106 | 'migrations_paths' => ['DoctrineMigrationsTest' => 'a'], |
||
| 107 | ], |
||
| 108 | ], $container); |
||
| 109 | |||
| 110 | $container->addCompilerPass(new ConfigureDependencyFactoryPass()); |
||
| 111 | $container->compile(); |
||
| 112 | |||
| 113 | return $application; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 114 | } |
||
| 115 | } |
||
| 116 |