From 5b9c3fd7cb7a1824f8dbf2e57a6db0c0afbd6c9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20Felix=20=C5=A0ulc?= Date: Sat, 10 Jun 2023 18:07:01 +0200 Subject: [PATCH] Tests: modernize --- tests/Cases/Unit/DI/MigrationsExtension.phpt | 109 +++++++++++++++ .../Cases/Unit/DI/MigrationsExtensionTest.php | 128 ------------------ tests/Toolkit/NeonLoader.php | 19 --- tests/bootstrap.php | 7 +- 4 files changed, 111 insertions(+), 152 deletions(-) create mode 100644 tests/Cases/Unit/DI/MigrationsExtension.phpt delete mode 100644 tests/Cases/Unit/DI/MigrationsExtensionTest.php delete mode 100644 tests/Toolkit/NeonLoader.php diff --git a/tests/Cases/Unit/DI/MigrationsExtension.phpt b/tests/Cases/Unit/DI/MigrationsExtension.phpt new file mode 100644 index 0000000..50973b1 --- /dev/null +++ b/tests/Cases/Unit/DI/MigrationsExtension.phpt @@ -0,0 +1,109 @@ +withCompiler(function (Compiler $compiler): void { + $compiler->addExtension('migrations', new MigrationsExtension()); + $compiler->addConfig(Neonkit::load(' + parameters: + appDir: /root + migrations: + directory: %appDir%/migrations + services: + - Symfony\Component\Console\Application + - Doctrine\DBAL\Driver\Mysqli\Driver + - Doctrine\DBAL\Connection([]) + ')); + $compiler->addDependencies([__FILE__]); + }) + ->build(); + + /** @var Configuration $configuration */ + $configuration = $container->getByType(Configuration::class); + Assert::equal(['Migrations' => '/root/migrations'], $configuration->getMigrationDirectories()); + Assert::count(13, $container->findByType(DoctrineCommand::class)); + // 4 default helpers + Assert::count(4, iterator_to_array($container->getByType(Application::class)->getHelperSet())); +}); + +Toolkit::test(function (): void { + $container = ContainerBuilder::of() + ->withCompiler(function (Compiler $compiler): void { + $compiler->addExtension('migrations', new MigrationsExtension()); + $compiler->addConfig(Neonkit::load(' + migrations: + directory: /fake/migrations + namespace: Fake + services: + - Doctrine\DBAL\Driver\Mysqli\Driver + - Doctrine\DBAL\Connection([]) + ')); + $compiler->addDependencies([__FILE__]); + }) + ->build(); + + /** @var Configuration $configuration */ + $configuration = $container->getByType(Configuration::class); + Assert::equal(['Fake' => '/fake/migrations'], $configuration->getMigrationDirectories()); +}); + +Toolkit::test(function (): void { + $container = ContainerBuilder::of() + ->withCompiler(function (Compiler $compiler): void { + $compiler->addExtension('migrations', new MigrationsExtension()); + $compiler->addConfig(Neonkit::load(' + migrations: + directory: /root/migrations + services: + - Doctrine\DBAL\Driver\Mysqli\Driver + - Doctrine\DBAL\Connection([]) + ')); + $compiler->addDependencies([__FILE__]); + }) + ->build(); + + /** @var Configuration $configuration */ + $configuration = $container->getByType(Configuration::class); + Assert::equal(['Migrations' => '/root/migrations'], $configuration->getMigrationDirectories()); + Assert::count(13, $container->findByType(DoctrineCommand::class)); +}); + +Toolkit::test(function (): void { + $container = ContainerBuilder::of() + ->withCompiler(function (Compiler $compiler): void { + $compiler->addExtension('migrations', new MigrationsExtension()); + $compiler->addConfig(Neonkit::load(' + parameters: + appDir: /root + migrations: + directory: %appDir%/migrations + services: + - Doctrine\DBAL\Driver\Mysqli\Driver + - Doctrine\DBAL\Connection([]) + ')); + $compiler->addDependencies([__FILE__]); + }) + ->build(); + + /** @var DependencyFactory $dependencyFactory */ + $dependencyFactory = $container->getByType(DependencyFactory::class); + Assert::type(DependencyFactory::class, $dependencyFactory); + Assert::type(DbalMigrationFactory::class, $dependencyFactory->getMigrationFactory()); +}); diff --git a/tests/Cases/Unit/DI/MigrationsExtensionTest.php b/tests/Cases/Unit/DI/MigrationsExtensionTest.php deleted file mode 100644 index 7b0685f..0000000 --- a/tests/Cases/Unit/DI/MigrationsExtensionTest.php +++ /dev/null @@ -1,128 +0,0 @@ -load(function (Compiler $compiler): void { - $compiler->addExtension('migrations', new MigrationsExtension()); - $compiler->addConfig(NeonLoader::load(' - parameters: - appDir: /root - migrations: - directory: %appDir%/migrations - services: - - Symfony\Component\Console\Application - - Doctrine\DBAL\Driver\Mysqli\Driver - - Doctrine\DBAL\Connection([]) - ')); - $compiler->addDependencies([__FILE__]); - }, __METHOD__); - - /** @var Container $container */ - $container = new $class(); - - /** @var Configuration $configuration */ - $configuration = $container->getByType(Configuration::class); - Assert::equal(['Migrations' => '/root/migrations'], $configuration->getMigrationDirectories()); - Assert::count(13, $container->findByType(DoctrineCommand::class)); - // 4 default helpers - Assert::count(4, iterator_to_array($container->getByType(Application::class)->getHelperSet())); - } - - public function testCustom(): void - { - $loader = new ContainerLoader(TMP_DIR, true); - $class = $loader->load(function (Compiler $compiler): void { - $compiler->addExtension('migrations', new MigrationsExtension()); - $compiler->addConfig(NeonLoader::load(' - migrations: - directory: /fake/migrations - namespace: Fake - services: - - Doctrine\DBAL\Driver\Mysqli\Driver - - Doctrine\DBAL\Connection([]) - ')); - $compiler->addDependencies([__FILE__]); - }, __METHOD__); - - /** @var Container $container */ - $container = new $class(); - - /** @var Configuration $configuration */ - $configuration = $container->getByType(Configuration::class); - Assert::equal(['Fake' => '/fake/migrations'], $configuration->getMigrationDirectories()); - } - - public function testWithoutConsole(): void - { - $loader = new ContainerLoader(TMP_DIR, true); - $class = $loader->load(function (Compiler $compiler): void { - $compiler->addExtension('migrations', new MigrationsExtension()); - $compiler->addConfig(NeonLoader::load(' - migrations: - directory: /root/migrations - services: - - Doctrine\DBAL\Driver\Mysqli\Driver - - Doctrine\DBAL\Connection([]) - ')); - $compiler->addDependencies([__FILE__]); - }, __METHOD__); - - /** @var Container $container */ - $container = new $class(); - - /** @var Configuration $configuration */ - $configuration = $container->getByType(Configuration::class); - Assert::equal(['Migrations' => '/root/migrations'], $configuration->getMigrationDirectories()); - Assert::count(13, $container->findByType(DoctrineCommand::class)); - } - - public function testDependencyFactory(): void - { - $loader = new ContainerLoader(TMP_DIR, true); - $class = $loader->load(function (Compiler $compiler): void { - $compiler->addExtension('migrations', new MigrationsExtension()); - $compiler->addConfig(NeonLoader::load(' - parameters: - appDir: /root - migrations: - directory: %appDir%/migrations - services: - - Doctrine\DBAL\Driver\Mysqli\Driver - - Doctrine\DBAL\Connection([]) - ')); - $compiler->addDependencies([__FILE__]); - }, __METHOD__); - - /** @var Container $container */ - $container = new $class(); - - /** @var DependencyFactory $dependencyFactory */ - $dependencyFactory = $container->getByType(DependencyFactory::class); - Assert::type(DependencyFactory::class, $dependencyFactory); - Assert::type(DbalMigrationFactory::class, $dependencyFactory->getMigrationFactory()); - } - -} - -(new MigrationsExtensionTest())->run(); diff --git a/tests/Toolkit/NeonLoader.php b/tests/Toolkit/NeonLoader.php deleted file mode 100644 index 8c0d6d8..0000000 --- a/tests/Toolkit/NeonLoader.php +++ /dev/null @@ -1,19 +0,0 @@ -process((array) Neon::decode($str)); - } - -} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index f9ee4bc..86c92a0 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,13 +1,10 @@