From 016ff236de2b103a88f734cb98761588b7db8b2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sat, 1 Jan 2022 19:24:08 +0100 Subject: [PATCH] Modernize the code (#12) --- composer.json | 3 +- fixtures/DataFixtures/Loader/FakeLoader.php | 9 +- .../Loader/FakeLoaderPersisterAware.php | 11 +- .../FixtureLocator/FakeFixtureLocator.php | 9 +- fixtures/Functional/AppKernel.php | 18 +- fixtures/Functional/ConfigurableKernel.php | 16 +- .../Functional/SimpleBundle/SimpleBundle.php | 3 - .../SimpleBundle/files/{bar.yml => bar.yaml} | 0 .../SimpleBundle/files/{foo.yml => foo.yaml} | 0 fixtures/Functional/SimpleKernel.php | 6 - .../fixtures/{aentity.yml => aentity.yaml} | 0 .../fixtures/{bentity.yml => bentity.yaml} | 0 .../Resources/fixtures/AEnv/DataLoader.php | 29 --- .../Resources/fixtures/BEnv/DataLoader.php | 29 --- .../fixtures/CEnv/{empty.yml => empty.yaml} | 0 .../Resources/fixtures/DEnv/DataLoader.php | 32 --- .../products/{product1.yml => product1.yaml} | 0 .../products/{product2.yml => product2.yaml} | 0 .../Resources/fixtures/EEnv/DataLoader.php | 27 --- .../fixtures/EEnv/{empty.yml => empty.yaml} | 0 .../Resources/fixtures/data-loader.yaml | 3 + .../Resources/fixtures/data-loader.yml | 3 - .../Faker/Provider/FooProvider.php | 2 +- .../DataFixtures/Processor/BrandProcessor.php | 42 ---- .../fixtures/Dev/{dev.yml => dev.yaml} | 0 .../fixtures/Inte/{inte.yml => inte.yaml} | 0 .../fixtures/{brand.yml => brand.yaml} | 0 .../fixtures/{product.yml => product.yaml} | 0 fixtures/Functional/TestKernel.php | 9 +- fixtures/Functional/WithoutDoctrineKernel.php | 13 +- fixtures/Functional/bootstrap.php | 6 +- .../config/{config.yml => config.yaml} | 2 +- ...trine.yml => config_without_doctrine.yaml} | 8 +- .../config/{doctrine.yml => doctrine.yaml} | 0 .../config/test/{config.yml => config.yaml} | 10 +- fixtures/HttpKernel/DummyKernel.php | 113 ++-------- fixtures/Loader/FakeLoader.php | 11 +- .../AnotherDummyBundle/AnotherDummyBundle.php | 3 - .../resources/dev/{file10.yml => file10.yaml} | 0 .../DummyBundle/DummyBundle.php | 3 - .../EmptyBundle/EmptyBundle.php | 3 - fixtures/Logger/FakeLogger.php | 30 --- fixtures/NotCallableTrait.php | 12 +- .../FakeDoctrineManagerRegistry.php | 66 ++---- .../ObjectMapper/FakeEntityManager.php | 204 ++++-------------- fixtures/Resolver/ABundle.php | 3 - fixtures/Resolver/BBundle.php | 3 - fixtures/Resolver/FakeBundleResolver.php | 11 +- fixtures/Resolver/ResolverKernel.php | 11 +- .../fixture_files/{city.yml => city.yaml} | 0 phpunit.xml.dist | 3 +- src/Alice/FileLocator/KernelFileLocator.php | 7 +- .../InstantiatedReferenceInstantiator.php | 44 ++-- src/BundleResolverInterface.php | 4 +- .../DoctrineOrmLoadDataFixturesCommand.php | 78 +++---- src/DependencyInjection/Configuration.php | 29 +-- .../HautelookAliceExtension.php | 39 ++-- .../Resolver/BundleNotFoundException.php | 12 +- src/FixtureLocatorInterface.php | 4 +- src/Loader/DoctrineOrmLoader.php | 31 ++- src/LoaderInterface.php | 2 +- src/Locator/EnvDirectoryLocator.php | 10 +- src/Locator/EnvironmentlessFilesLocator.php | 4 +- src/PhpUnit/BaseDatabaseTrait.php | 18 +- src/PhpUnit/RecreateDatabaseTrait.php | 2 +- src/PhpUnit/RefreshDatabaseTrait.php | 8 +- src/Resolver/Bundle/NoBundleResolver.php | 7 +- src/Resolver/Bundle/SimpleBundleResolver.php | 6 +- src/Resolver/File/KernelFileResolver.php | 10 +- .../InstantiatedReferenceInstantiatorTest.php | 37 ++-- tests/Alice/Loader/ServiceFactoryTest.php | 8 +- ...LoadDataFixturesCommandIntegrationTest.php | 149 ++++++------- .../Doctrine/LoadDataFixturesCommandTest.php | 38 ++-- .../DependencyInjection/ConfigurationTest.php | 12 +- .../HautelookAliceBundleTest.php | 78 +++---- tests/Loader/DoctrineOrmLoaderTest.php | 26 ++- tests/Locator/EnvDirectoryLocatorTest.php | 40 ++-- .../EnvironmentlessFilesLocatorTest.php | 15 +- tests/PhpUnit/RefreshTestTrait.php | 12 +- .../Resolver/Bundle/NoBundleResolverTest.php | 17 +- .../Bundle/SimpleBundleResolverTest.php | 15 +- .../Resolver/File/KernelFileResolverTest.php | 58 +++-- 82 files changed, 537 insertions(+), 1049 deletions(-) rename fixtures/Functional/SimpleBundle/files/{bar.yml => bar.yaml} (100%) rename fixtures/Functional/SimpleBundle/files/{foo.yml => foo.yaml} (100%) rename fixtures/Functional/TestBundle/Bundle/ABundle/Resources/fixtures/{aentity.yml => aentity.yaml} (100%) rename fixtures/Functional/TestBundle/Bundle/BBundle/Resources/fixtures/{bentity.yml => bentity.yaml} (100%) delete mode 100644 fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/AEnv/DataLoader.php delete mode 100644 fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/BEnv/DataLoader.php rename fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/CEnv/{empty.yml => empty.yaml} (100%) delete mode 100644 fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/DEnv/DataLoader.php rename fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/DEnv/products/{product1.yml => product1.yaml} (100%) rename fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/DEnv/products/{product2.yml => product2.yaml} (100%) delete mode 100644 fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/EEnv/DataLoader.php rename fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/EEnv/{empty.yml => empty.yaml} (100%) create mode 100644 fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/data-loader.yaml delete mode 100644 fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/data-loader.yml delete mode 100644 fixtures/Functional/TestBundle/DataFixtures/Processor/BrandProcessor.php rename fixtures/Functional/TestBundle/Resources/fixtures/Dev/{dev.yml => dev.yaml} (100%) rename fixtures/Functional/TestBundle/Resources/fixtures/Inte/{inte.yml => inte.yaml} (100%) rename fixtures/Functional/TestBundle/Resources/fixtures/{brand.yml => brand.yaml} (100%) rename fixtures/Functional/TestBundle/Resources/fixtures/{product.yml => product.yaml} (100%) rename fixtures/Functional/config/{config.yml => config.yaml} (87%) rename fixtures/Functional/config/{config_without_doctrine.yml => config_without_doctrine.yaml} (86%) rename fixtures/Functional/config/{doctrine.yml => doctrine.yaml} (100%) rename fixtures/Functional/config/test/{config.yml => config.yaml} (89%) rename fixtures/Locator/EnvDirectoryLocator/AnotherDummyBundle/resources/dev/{file10.yml => file10.yaml} (100%) rename fixtures/fixture_files/{city.yml => city.yaml} (100%) diff --git a/composer.json b/composer.json index 4b8f0e69..442ff95f 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,8 @@ "phpunit/phpunit": "^9.5", "phpspec/prophecy": "^1.7", "symfony/phpunit-bridge": "^6.0", - "phpspec/prophecy-phpunit": "^2.0" + "phpspec/prophecy-phpunit": "^2.0", + "doctrine/shards": "^1.0" }, "extra": { diff --git a/fixtures/DataFixtures/Loader/FakeLoader.php b/fixtures/DataFixtures/Loader/FakeLoader.php index 4ec06079..68e24c0b 100644 --- a/fixtures/DataFixtures/Loader/FakeLoader.php +++ b/fixtures/DataFixtures/Loader/FakeLoader.php @@ -15,20 +15,15 @@ use Fidry\AliceDataFixtures\LoaderInterface as DataFixturesLoaderInterface; use Fidry\AliceDataFixtures\Persistence\PurgeMode; +use function func_get_args; use Hautelook\AliceBundle\NotCallableTrait; -/** - * @author Théo FIDRY - */ class FakeLoader implements DataFixturesLoaderInterface { use NotCallableTrait; - /** - * {@inheritdoc} - */ public function load(array $fixturesFiles, array $parameters = [], array $objects = [], PurgeMode $purgeMode = null): array { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } } diff --git a/fixtures/DataFixtures/Loader/FakeLoaderPersisterAware.php b/fixtures/DataFixtures/Loader/FakeLoaderPersisterAware.php index 2a714c0e..e5608492 100644 --- a/fixtures/DataFixtures/Loader/FakeLoaderPersisterAware.php +++ b/fixtures/DataFixtures/Loader/FakeLoaderPersisterAware.php @@ -15,17 +15,12 @@ use Fidry\AliceDataFixtures\Persistence\PersisterAwareInterface; use Fidry\AliceDataFixtures\Persistence\PersisterInterface; +use function func_get_args; -/** - * @author Théo FIDRY - */ class FakeLoaderPersisterAware extends FakeLoader implements PersisterAwareInterface { - /** - * {@inheritdoc} - */ - public function withPersister(PersisterInterface $persister) + public function withPersister(PersisterInterface $persister): self { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } } diff --git a/fixtures/FixtureLocator/FakeFixtureLocator.php b/fixtures/FixtureLocator/FakeFixtureLocator.php index a7690040..e019a738 100644 --- a/fixtures/FixtureLocator/FakeFixtureLocator.php +++ b/fixtures/FixtureLocator/FakeFixtureLocator.php @@ -13,21 +13,16 @@ namespace Hautelook\AliceBundle\FixtureLocator; +use function func_get_args; use Hautelook\AliceBundle\FixtureLocatorInterface; use Hautelook\AliceBundle\NotCallableTrait; -/** - * @author Théo FIDRY - */ class FakeFixtureLocator implements FixtureLocatorInterface { use NotCallableTrait; - /** - * {@inheritdoc} - */ public function locateFiles(array $bundles, string $environment): array { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } } diff --git a/fixtures/Functional/AppKernel.php b/fixtures/Functional/AppKernel.php index e2d2b01b..88cc44ed 100644 --- a/fixtures/Functional/AppKernel.php +++ b/fixtures/Functional/AppKernel.php @@ -25,9 +25,6 @@ class AppKernel extends Kernel { - /** - * {@inheritdoc} - */ public function registerBundles(): iterable { return [ @@ -39,23 +36,18 @@ public function registerBundles(): iterable ]; } - /** - * {@inheritdoc} - */ public function registerContainerConfiguration(LoaderInterface $loader) { if ('public' !== $this->getEnvironment()) { - $loader->load(__DIR__.'/config/config.yml'); + $loader->load(__DIR__.'/config/config.yaml'); } else { - $loader->load(__DIR__.'/config/test/config.yml'); + $loader->load(__DIR__.'/config/test/config.yaml'); } - $loader->load(__DIR__.'/config/doctrine.yml'); + + $loader->load(__DIR__.'/config/doctrine.yaml'); } - /** - * {@inheritdoc} - */ - public function build(ContainerBuilder $container) + public function build(ContainerBuilder $container): void { parent::build($container); diff --git a/fixtures/Functional/ConfigurableKernel.php b/fixtures/Functional/ConfigurableKernel.php index f56c4f8c..bdc9d470 100644 --- a/fixtures/Functional/ConfigurableKernel.php +++ b/fixtures/Functional/ConfigurableKernel.php @@ -19,16 +19,13 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\HttpKernel\Kernel; -/** - * @author Théo FIDRY - */ class ConfigurableKernel extends Kernel { - private $addedBundles = []; - /** - * {@inheritdoc} + * @var list */ + private array $addedBundles = []; + public function registerBundles(): iterable { return array_merge( @@ -47,11 +44,8 @@ public function addBundle(Bundle $bundle): self return $this; } - /** - * {@inheritdoc} - */ - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { - $loader->load(__DIR__.'/config/config.yml'); + $loader->load(__DIR__.'/config/config.yaml'); } } diff --git a/fixtures/Functional/SimpleBundle/SimpleBundle.php b/fixtures/Functional/SimpleBundle/SimpleBundle.php index 14d6021e..8e6aec85 100644 --- a/fixtures/Functional/SimpleBundle/SimpleBundle.php +++ b/fixtures/Functional/SimpleBundle/SimpleBundle.php @@ -15,9 +15,6 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; -/** - * @author Théo FIDRY - */ class SimpleBundle extends Bundle { } diff --git a/fixtures/Functional/SimpleBundle/files/bar.yml b/fixtures/Functional/SimpleBundle/files/bar.yaml similarity index 100% rename from fixtures/Functional/SimpleBundle/files/bar.yml rename to fixtures/Functional/SimpleBundle/files/bar.yaml diff --git a/fixtures/Functional/SimpleBundle/files/foo.yml b/fixtures/Functional/SimpleBundle/files/foo.yaml similarity index 100% rename from fixtures/Functional/SimpleBundle/files/foo.yml rename to fixtures/Functional/SimpleBundle/files/foo.yaml diff --git a/fixtures/Functional/SimpleKernel.php b/fixtures/Functional/SimpleKernel.php index 899abf4a..dc5e4f54 100644 --- a/fixtures/Functional/SimpleKernel.php +++ b/fixtures/Functional/SimpleKernel.php @@ -17,14 +17,8 @@ use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\HttpKernel\Kernel; -/** - * @author Théo FIDRY - */ class SimpleKernel extends Kernel { - /** - * {@inheritdoc} - */ public function registerBundles(): iterable { return [ diff --git a/fixtures/Functional/TestBundle/Bundle/ABundle/Resources/fixtures/aentity.yml b/fixtures/Functional/TestBundle/Bundle/ABundle/Resources/fixtures/aentity.yaml similarity index 100% rename from fixtures/Functional/TestBundle/Bundle/ABundle/Resources/fixtures/aentity.yml rename to fixtures/Functional/TestBundle/Bundle/ABundle/Resources/fixtures/aentity.yaml diff --git a/fixtures/Functional/TestBundle/Bundle/BBundle/Resources/fixtures/bentity.yml b/fixtures/Functional/TestBundle/Bundle/BBundle/Resources/fixtures/bentity.yaml similarity index 100% rename from fixtures/Functional/TestBundle/Bundle/BBundle/Resources/fixtures/bentity.yml rename to fixtures/Functional/TestBundle/Bundle/BBundle/Resources/fixtures/bentity.yaml diff --git a/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/AEnv/DataLoader.php b/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/AEnv/DataLoader.php deleted file mode 100644 index 77cb5117..00000000 --- a/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/AEnv/DataLoader.php +++ /dev/null @@ -1,29 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace Hautelook\AliceBundle\Functional\TestBundle\Bundle\CBundle\DataFixtures\ORM\AEnv; - -use Hautelook\AliceBundle\Doctrine\DataFixtures\AbstractLoader; - -class DataLoader extends AbstractLoader -{ - /** - * {@inheritdoc} - */ - public function getFixtures() - { - return [ - __DIR__.'/../../../../ABundle/Resources/fixtures/aentity.yml', - ]; - } -} diff --git a/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/BEnv/DataLoader.php b/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/BEnv/DataLoader.php deleted file mode 100644 index 05fbafb9..00000000 --- a/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/BEnv/DataLoader.php +++ /dev/null @@ -1,29 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace Hautelook\AliceBundle\Functional\TestBundle\Bundle\CBundle\DataFixtures\ORM\BEnv; - -use Hautelook\AliceBundle\Doctrine\DataFixtures\AbstractLoader; - -class DataLoader extends AbstractLoader -{ - /** - * {@inheritdoc} - */ - public function getFixtures() - { - return [ - __DIR__.'/../../../../BBundle/Resources/fixtures/bentity.yml', - ]; - } -} diff --git a/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/CEnv/empty.yml b/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/CEnv/empty.yaml similarity index 100% rename from fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/CEnv/empty.yml rename to fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/CEnv/empty.yaml diff --git a/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/DEnv/DataLoader.php b/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/DEnv/DataLoader.php deleted file mode 100644 index 729550cc..00000000 --- a/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/DEnv/DataLoader.php +++ /dev/null @@ -1,32 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace Hautelook\AliceBundle\Functional\TestBundle\Bundle\CBundle\DataFixtures\ORM\DEnv; - -use Hautelook\AliceBundle\Doctrine\DataFixtures\AbstractLoader; -use Symfony\Component\Finder\Finder; - -class DataLoader extends AbstractLoader -{ - /** - * {@inheritdoc} - */ - public function getFixtures() - { - $finder = new Finder(); - - $finder->in(__DIR__.'/products')->depth(0)->files()->name('*.yml')->sortByName(); - - return iterator_to_array($finder); - } -} diff --git a/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/DEnv/products/product1.yml b/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/DEnv/products/product1.yaml similarity index 100% rename from fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/DEnv/products/product1.yml rename to fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/DEnv/products/product1.yaml diff --git a/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/DEnv/products/product2.yml b/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/DEnv/products/product2.yaml similarity index 100% rename from fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/DEnv/products/product2.yml rename to fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/DEnv/products/product2.yaml diff --git a/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/EEnv/DataLoader.php b/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/EEnv/DataLoader.php deleted file mode 100644 index 9b1a9576..00000000 --- a/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/EEnv/DataLoader.php +++ /dev/null @@ -1,27 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace Hautelook\AliceBundle\Functional\TestBundle\Bundle\CBundle\DataFixtures\ORM\EEnv; - -use Hautelook\AliceBundle\Doctrine\DataFixtures\AbstractLoader; - -class DataLoader extends AbstractLoader -{ - /** - * {@inheritdoc} - */ - public function getFixtures() - { - return [new \SplFileInfo(__DIR__.'/empty.yml')]; - } -} diff --git a/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/EEnv/empty.yml b/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/EEnv/empty.yaml similarity index 100% rename from fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/EEnv/empty.yml rename to fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/EEnv/empty.yaml diff --git a/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/data-loader.yaml b/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/data-loader.yaml new file mode 100644 index 00000000..2307cfa2 --- /dev/null +++ b/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/data-loader.yaml @@ -0,0 +1,3 @@ +include: + - '@TestABundle/Resources/fixtures/aentity.yaml' + - '@TestBBundle/Resources/fixtures/bentity.yaml' diff --git a/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/data-loader.yml b/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/data-loader.yml deleted file mode 100644 index e376f186..00000000 --- a/fixtures/Functional/TestBundle/Bundle/CBundle/Resources/fixtures/data-loader.yml +++ /dev/null @@ -1,3 +0,0 @@ -include: - - '@TestABundle/Resources/fixtures/aentity.yml' - - '@TestBBundle/Resources/fixtures/bentity.yml' diff --git a/fixtures/Functional/TestBundle/DataFixtures/Faker/Provider/FooProvider.php b/fixtures/Functional/TestBundle/DataFixtures/Faker/Provider/FooProvider.php index 8498c4ff..3fa2cf42 100644 --- a/fixtures/Functional/TestBundle/DataFixtures/Faker/Provider/FooProvider.php +++ b/fixtures/Functional/TestBundle/DataFixtures/Faker/Provider/FooProvider.php @@ -15,7 +15,7 @@ class FooProvider { - public static function foo($str) + public static function foo(string $str): string { return 'foo'.$str; } diff --git a/fixtures/Functional/TestBundle/DataFixtures/Processor/BrandProcessor.php b/fixtures/Functional/TestBundle/DataFixtures/Processor/BrandProcessor.php deleted file mode 100644 index 3b0cd00b..00000000 --- a/fixtures/Functional/TestBundle/DataFixtures/Processor/BrandProcessor.php +++ /dev/null @@ -1,42 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace Hautelook\AliceBundle\Functional\TestBundle\DataFixtures\Processor; - -use Hautelook\AliceBundle\Functional\TestBundle\Entity\Brand; -use Nelmio\Alice\ProcessorInterface; - -/** - * @see https://github.com/nelmio/alice/blob/master/doc/processors.md#processors - * - * @author Théo FIDRY - */ -class BrandProcessor implements ProcessorInterface -{ - /** - * {@inheritdoc} - */ - public function preProcess($object) - { - if ($object instanceof Brand) { - $object->canonicalName = strtolower($object->getName()); - } - } - - /** - * {@inheritdoc} - */ - public function postProcess($object) - { - } -} diff --git a/fixtures/Functional/TestBundle/Resources/fixtures/Dev/dev.yml b/fixtures/Functional/TestBundle/Resources/fixtures/Dev/dev.yaml similarity index 100% rename from fixtures/Functional/TestBundle/Resources/fixtures/Dev/dev.yml rename to fixtures/Functional/TestBundle/Resources/fixtures/Dev/dev.yaml diff --git a/fixtures/Functional/TestBundle/Resources/fixtures/Inte/inte.yml b/fixtures/Functional/TestBundle/Resources/fixtures/Inte/inte.yaml similarity index 100% rename from fixtures/Functional/TestBundle/Resources/fixtures/Inte/inte.yml rename to fixtures/Functional/TestBundle/Resources/fixtures/Inte/inte.yaml diff --git a/fixtures/Functional/TestBundle/Resources/fixtures/brand.yml b/fixtures/Functional/TestBundle/Resources/fixtures/brand.yaml similarity index 100% rename from fixtures/Functional/TestBundle/Resources/fixtures/brand.yml rename to fixtures/Functional/TestBundle/Resources/fixtures/brand.yaml diff --git a/fixtures/Functional/TestBundle/Resources/fixtures/product.yml b/fixtures/Functional/TestBundle/Resources/fixtures/product.yaml similarity index 100% rename from fixtures/Functional/TestBundle/Resources/fixtures/product.yml rename to fixtures/Functional/TestBundle/Resources/fixtures/product.yaml diff --git a/fixtures/Functional/TestKernel.php b/fixtures/Functional/TestKernel.php index 9e43adfa..a8125979 100644 --- a/fixtures/Functional/TestKernel.php +++ b/fixtures/Functional/TestKernel.php @@ -25,9 +25,6 @@ use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\HttpKernel\Kernel; -/** - * @author Théo FIDRY - */ class TestKernel extends Kernel { public function registerBundles(): iterable @@ -45,9 +42,9 @@ public function registerBundles(): iterable ]; } - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { - $loader->load(__DIR__.'/config/config.yml'); - $loader->load(__DIR__.'/config/doctrine.yml'); + $loader->load(__DIR__.'/config/config.yaml'); + $loader->load(__DIR__.'/config/doctrine.yaml'); } } diff --git a/fixtures/Functional/WithoutDoctrineKernel.php b/fixtures/Functional/WithoutDoctrineKernel.php index ade4d0b0..d4edbdeb 100644 --- a/fixtures/Functional/WithoutDoctrineKernel.php +++ b/fixtures/Functional/WithoutDoctrineKernel.php @@ -24,11 +24,11 @@ */ class WithoutDoctrineKernel extends Kernel { - private $addedBundles = []; - /** - * {@inheritdoc} + * @var list */ + private array $addedBundles = []; + public function registerBundles(): iterable { return array_merge( @@ -47,11 +47,8 @@ public function addBundle(Bundle $bundle): self return $this; } - /** - * {@inheritdoc} - */ - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { - $loader->load(__DIR__.'/config/config_without_doctrine.yml'); + $loader->load(__DIR__.'/config/config_without_doctrine.yaml'); } } diff --git a/fixtures/Functional/bootstrap.php b/fixtures/Functional/bootstrap.php index 788fb91c..a890c6fe 100644 --- a/fixtures/Functional/bootstrap.php +++ b/fixtures/Functional/bootstrap.php @@ -12,11 +12,13 @@ declare(strict_types=1); use Composer\Autoload\ClassLoader; +use Doctrine\Common\Annotations\AnnotationRegistry; /** @var ClassLoader $loader */ $loader = require __DIR__.'/../../vendor/autoload.php'; -if (class_exists('Doctrine\Common\Annotations\AnnotationRegistry', true)) { - \Doctrine\Common\Annotations\AnnotationRegistry::registerLoader([$loader, 'loadClass']); + +if (class_exists(AnnotationRegistry::class, true)) { + AnnotationRegistry::registerLoader([$loader, 'loadClass']); } return $loader; diff --git a/fixtures/Functional/config/config.yml b/fixtures/Functional/config/config.yaml similarity index 87% rename from fixtures/Functional/config/config.yml rename to fixtures/Functional/config/config.yaml index 8273de80..e5b1cf9f 100644 --- a/fixtures/Functional/config/config.yml +++ b/fixtures/Functional/config/config.yaml @@ -8,7 +8,7 @@ framework: services: data_fixtures.faker.provider.foo: class: Hautelook\AliceBundle\Functional\TestBundle\DataFixtures\Faker\Provider\FooProvider - tags: [ { name: nelmio_alice.faker.provider } ] + tags: [ 'nelmio_alice.faker.provider' ] app.city_factory: class: Hautelook\AliceBundle\Functional\TestBundle\Entity\CityFactory diff --git a/fixtures/Functional/config/config_without_doctrine.yml b/fixtures/Functional/config/config_without_doctrine.yaml similarity index 86% rename from fixtures/Functional/config/config_without_doctrine.yml rename to fixtures/Functional/config/config_without_doctrine.yaml index e4fc8af7..6e81af46 100644 --- a/fixtures/Functional/config/config_without_doctrine.yml +++ b/fixtures/Functional/config/config_without_doctrine.yaml @@ -6,21 +6,21 @@ framework: test: ~ services: + _defaults: + public: true + data_fixtures.faker.provider.foo: class: Hautelook\AliceBundle\Functional\TestBundle\DataFixtures\Faker\Provider\FooProvider - tags: [ { name: nelmio_alice.faker.provider } ] + tags: [ 'nelmio_alice.faker.provider' ] fidry_alice_data_fixtures.loader.doctrine: class: Hautelook\AliceBundle\Loader\FakeLoader - public: true fidry_alice_data_fixtures.doctrine.persister_loader: class: Hautelook\AliceBundle\Loader\FakeLoader - public: true app.city_factory: class: Hautelook\AliceBundle\Functional\TestBundle\Entity\CityFactory - public: true logger: class: Psr\Log\NullLogger diff --git a/fixtures/Functional/config/doctrine.yml b/fixtures/Functional/config/doctrine.yaml similarity index 100% rename from fixtures/Functional/config/doctrine.yml rename to fixtures/Functional/config/doctrine.yaml diff --git a/fixtures/Functional/config/test/config.yml b/fixtures/Functional/config/test/config.yaml similarity index 89% rename from fixtures/Functional/config/test/config.yml rename to fixtures/Functional/config/test/config.yaml index ec148e76..5221a3ce 100644 --- a/fixtures/Functional/config/test/config.yml +++ b/fixtures/Functional/config/test/config.yaml @@ -8,25 +8,24 @@ framework: cache: file services: + _defaults: + public: true + data_fixtures.faker.provider.foo: class: Hautelook\AliceBundle\Functional\TestBundle\DataFixtures\Faker\Provider\FooProvider - tags: [ { name: nelmio_alice.faker.provider } ] - public: true + tags: [ 'nelmio_alice.faker.provider' ] app.city_factory: class: Hautelook\AliceBundle\Functional\TestBundle\Entity\CityFactory - public: true logger: class: Psr\Log\NullLogger - public: true hautelook_alice.data_fixtures.loader.file_resolver_loader: class: Fidry\AliceDataFixtures\Loader\FileResolverLoader arguments: $decoratedLoader: '@fidry_alice_data_fixtures.doctrine.purger_loader' $fileResolver: '@hautelook_alice.resolver.file' - public: true hautelook_alice.loader.doctrine_orm_loader: class: Hautelook\AliceBundle\Loader\DoctrineOrmLoader @@ -35,4 +34,3 @@ services: $fixtureLocator: '@hautelook_alice.locator' $purgeLoader: '@hautelook_alice.data_fixtures.purge_loader' $appendLoader: '@hautelook_alice.data_fixtures.append_loader' - public: true \ No newline at end of file diff --git a/fixtures/HttpKernel/DummyKernel.php b/fixtures/HttpKernel/DummyKernel.php index a7445d9b..494f8cfc 100644 --- a/fixtures/HttpKernel/DummyKernel.php +++ b/fixtures/HttpKernel/DummyKernel.php @@ -13,7 +13,9 @@ namespace Hautelook\AliceBundle\HttpKernel; +use function func_get_args; use Hautelook\AliceBundle\NotCallableTrait; +use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -21,183 +23,112 @@ use Symfony\Component\HttpKernel\Bundle\BundleInterface; use Symfony\Component\HttpKernel\KernelInterface; -/** - * @author Théo FIDRY - */ class DummyKernel implements KernelInterface { use NotCallableTrait; - /** - * {@inheritdoc} - */ public function serialize() { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function unserialize($serialized) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function handle(Request $request, $type = self::MAIN_REQUEST, $catch = true): Response { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function registerBundles(): iterable { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ - public function registerContainerConfiguration(\Symfony\Component\Config\Loader\LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ - public function boot() + public function boot(): void { // Do nothing } - /** - * {@inheritdoc} - */ - public function shutdown() + public function shutdown(): void { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getBundles(): array { return []; } - /** - * {@inheritdoc} - */ public function getBundle($name, $first = true): BundleInterface { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function locateResource($name, $dir = null, $first = true): string { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ - public function getName() + public function getName(): string { return 'fake'; } - /** - * {@inheritdoc} - */ public function getEnvironment(): string { return 'fake_env'; } - /** - * {@inheritdoc} - */ public function isDebug(): bool { return true; } - /** - * {@inheritdoc} - */ - public function getRootDir() + public function getRootDir(): string { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getContainer(): ContainerInterface { return new Container(); } - /** - * {@inheritdoc} - */ public function getStartTime(): float { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getCacheDir(): string { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getLogDir(): string { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getCharset(): string { - $this->__call(__METHOD__, \func_get_args()); - } - - /** - * {@inheritdoc} - */ - public function isClassInActiveBundle($class) - { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getProjectDir(): string { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } public function getBuildDir(): string { - // TODO: Implement getBuildDir() method. + $this->__call(__METHOD__, func_get_args()); } } diff --git a/fixtures/Loader/FakeLoader.php b/fixtures/Loader/FakeLoader.php index 609b34de..31f6b005 100644 --- a/fixtures/Loader/FakeLoader.php +++ b/fixtures/Loader/FakeLoader.php @@ -14,20 +14,15 @@ namespace Hautelook\AliceBundle\Loader; use Doctrine\ORM\EntityManagerInterface; +use function func_get_args; use Hautelook\AliceBundle\LoaderInterface; use Hautelook\AliceBundle\NotCallableTrait; use Symfony\Bundle\FrameworkBundle\Console\Application; -/** - * @author Théo FIDRY - */ class FakeLoader implements LoaderInterface { use NotCallableTrait; - /** - * {@inheritdoc} - */ public function load( Application $application, EntityManagerInterface $manager, @@ -37,7 +32,7 @@ public function load( bool $purgeWithTruncate, string $shard = null, bool $noBundles = false - ) { - $this->__call(__METHOD__, \func_get_args()); + ): array { + $this->__call(__METHOD__, func_get_args()); } } diff --git a/fixtures/Locator/EnvDirectoryLocator/AnotherDummyBundle/AnotherDummyBundle.php b/fixtures/Locator/EnvDirectoryLocator/AnotherDummyBundle/AnotherDummyBundle.php index 62550434..7fafd0fb 100644 --- a/fixtures/Locator/EnvDirectoryLocator/AnotherDummyBundle/AnotherDummyBundle.php +++ b/fixtures/Locator/EnvDirectoryLocator/AnotherDummyBundle/AnotherDummyBundle.php @@ -15,9 +15,6 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; -/** - * @author Théo FIDRY - */ class AnotherDummyBundle extends Bundle { } diff --git a/fixtures/Locator/EnvDirectoryLocator/AnotherDummyBundle/resources/dev/file10.yml b/fixtures/Locator/EnvDirectoryLocator/AnotherDummyBundle/resources/dev/file10.yaml similarity index 100% rename from fixtures/Locator/EnvDirectoryLocator/AnotherDummyBundle/resources/dev/file10.yml rename to fixtures/Locator/EnvDirectoryLocator/AnotherDummyBundle/resources/dev/file10.yaml diff --git a/fixtures/Locator/EnvDirectoryLocator/DummyBundle/DummyBundle.php b/fixtures/Locator/EnvDirectoryLocator/DummyBundle/DummyBundle.php index 1785ce47..0857cc27 100644 --- a/fixtures/Locator/EnvDirectoryLocator/DummyBundle/DummyBundle.php +++ b/fixtures/Locator/EnvDirectoryLocator/DummyBundle/DummyBundle.php @@ -15,9 +15,6 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; -/** - * @author Théo FIDRY - */ class DummyBundle extends Bundle { } diff --git a/fixtures/Locator/EnvDirectoryLocator/EmptyBundle/EmptyBundle.php b/fixtures/Locator/EnvDirectoryLocator/EmptyBundle/EmptyBundle.php index 158fb467..c58743bf 100644 --- a/fixtures/Locator/EnvDirectoryLocator/EmptyBundle/EmptyBundle.php +++ b/fixtures/Locator/EnvDirectoryLocator/EmptyBundle/EmptyBundle.php @@ -15,9 +15,6 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; -/** - * @author Théo FIDRY - */ class EmptyBundle extends Bundle { } diff --git a/fixtures/Logger/FakeLogger.php b/fixtures/Logger/FakeLogger.php index 411f32a5..3856e05f 100644 --- a/fixtures/Logger/FakeLogger.php +++ b/fixtures/Logger/FakeLogger.php @@ -16,80 +16,50 @@ use Hautelook\AliceBundle\NotCallableTrait; use Psr\Log\LoggerInterface; -/** - * @author Théo FIDRY - */ class FakeLogger implements LoggerInterface { use NotCallableTrait; - /** - * {@inheritdoc} - */ public function emergency($message, array $context = []): void { $this->__call(__METHOD__, \func_get_args()); } - /** - * {@inheritdoc} - */ public function alert($message, array $context = []): void { $this->__call(__METHOD__, \func_get_args()); } - /** - * {@inheritdoc} - */ public function critical($message, array $context = []): void { $this->__call(__METHOD__, \func_get_args()); } - /** - * {@inheritdoc} - */ public function error($message, array $context = []): void { $this->__call(__METHOD__, \func_get_args()); } - /** - * {@inheritdoc} - */ public function warning($message, array $context = []): void { $this->__call(__METHOD__, \func_get_args()); } - /** - * {@inheritdoc} - */ public function notice($message, array $context = []): void { $this->__call(__METHOD__, \func_get_args()); } - /** - * {@inheritdoc} - */ public function info($message, array $context = []): void { $this->__call(__METHOD__, \func_get_args()); } - /** - * {@inheritdoc} - */ public function debug($message, array $context = []): void { $this->__call(__METHOD__, \func_get_args()); } - /** - * {@inheritdoc} - */ public function log($level, $message, array $context = []): void { $this->__call(__METHOD__, \func_get_args()); diff --git a/fixtures/NotCallableTrait.php b/fixtures/NotCallableTrait.php index 9c6e0891..8c576c09 100644 --- a/fixtures/NotCallableTrait.php +++ b/fixtures/NotCallableTrait.php @@ -13,18 +13,18 @@ namespace Hautelook\AliceBundle; -/** - * @author Théo FIDRY - */ +use DomainException; +use function sprintf; + trait NotCallableTrait { public function __call($method, $arguments) { - throw new \DomainException( + throw new DomainException( sprintf( 'Did not expect "%s" to be called.', - $method - ) + $method, + ), ); } } diff --git a/fixtures/Persistence/FakeDoctrineManagerRegistry.php b/fixtures/Persistence/FakeDoctrineManagerRegistry.php index 85217dbe..3c802405 100644 --- a/fixtures/Persistence/FakeDoctrineManagerRegistry.php +++ b/fixtures/Persistence/FakeDoctrineManagerRegistry.php @@ -14,108 +14,70 @@ namespace Hautelook\AliceBundle\Persistence; use Doctrine\Persistence\ManagerRegistry; +use function func_get_args; use Hautelook\AliceBundle\NotCallableTrait; -/** - * @author Théo FIDRY - */ class FakeDoctrineManagerRegistry implements ManagerRegistry { use NotCallableTrait; - /** - * {@inheritdoc} - */ - public function getDefaultConnectionName() + public function getDefaultConnectionName(): string { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getConnection($name = null) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getConnections() { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getConnectionNames() { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getDefaultManagerName() { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getManager($name = null) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getManagers() { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function resetManager($name = null) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getAliasNamespace($alias) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getManagerNames() { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getRepository($persistentObject, $persistentManagerName = null) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getManagerForClass($class) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } } diff --git a/fixtures/Persistence/ObjectMapper/FakeEntityManager.php b/fixtures/Persistence/ObjectMapper/FakeEntityManager.php index 2e457fc5..72fbce1c 100644 --- a/fixtures/Persistence/ObjectMapper/FakeEntityManager.php +++ b/fixtures/Persistence/ObjectMapper/FakeEntityManager.php @@ -15,332 +15,210 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query\ResultSetMapping; +use function func_get_args; use Hautelook\AliceBundle\NotCallableTrait; -/** - * @author Théo FIDRY - */ class FakeEntityManager implements EntityManagerInterface { use NotCallableTrait; - /** - * {@inheritdoc} - */ public function getCache() { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getConnection() { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getExpressionBuilder() { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function beginTransaction() { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function transactional($func) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function commit() { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function rollback() { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function createQuery($dql = '') { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function createNamedQuery($name) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function createNativeQuery($sql, ResultSetMapping $rsm) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function createNamedNativeQuery($name) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function createQueryBuilder() { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getReference($entityName, $id) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getPartialReference($entityName, $identifier) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function close() { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function copy($entity, $deep = false) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function lock($entity, $lockMode, $lockVersion = null) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getEventManager() { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getConfiguration() { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function isOpen() { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getUnitOfWork() { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getHydrator($hydrationMode) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function newHydrator($hydrationMode) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getProxyFactory() { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getFilters() { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function isFiltersStateClean() { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function hasFilters() { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function find($className, $id) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function persist($object) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function remove($object) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function merge($object) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function clear($objectName = null) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function detach($object) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function refresh($object) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function flush() { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getRepository($className) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getMetadataFactory() { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function initializeObject($obj) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function contains($object) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } - /** - * {@inheritdoc} - */ public function getClassMetadata($className) { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } } diff --git a/fixtures/Resolver/ABundle.php b/fixtures/Resolver/ABundle.php index f238df3a..543479fd 100644 --- a/fixtures/Resolver/ABundle.php +++ b/fixtures/Resolver/ABundle.php @@ -15,9 +15,6 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; -/** - * @author Théo FIDRY - */ class ABundle extends Bundle { } diff --git a/fixtures/Resolver/BBundle.php b/fixtures/Resolver/BBundle.php index 4e5b94a4..e3ce2c27 100644 --- a/fixtures/Resolver/BBundle.php +++ b/fixtures/Resolver/BBundle.php @@ -15,9 +15,6 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; -/** - * @author Théo FIDRY - */ class BBundle extends Bundle { } diff --git a/fixtures/Resolver/FakeBundleResolver.php b/fixtures/Resolver/FakeBundleResolver.php index f9a51cd7..75177c1b 100644 --- a/fixtures/Resolver/FakeBundleResolver.php +++ b/fixtures/Resolver/FakeBundleResolver.php @@ -13,22 +13,17 @@ namespace Hautelook\AliceBundle\Resolver; +use function func_get_args; use Hautelook\AliceBundle\BundleResolverInterface; use Hautelook\AliceBundle\NotCallableTrait; use Symfony\Bundle\FrameworkBundle\Console\Application; -/** - * @author Théo FIDRY - */ class FakeBundleResolver implements BundleResolverInterface { use NotCallableTrait; - /** - * {@inheritdoc} - */ - public function resolveBundles(Application $application, array $names) + public function resolveBundles(Application $application, array $names): array { - $this->__call(__METHOD__, \func_get_args()); + $this->__call(__METHOD__, func_get_args()); } } diff --git a/fixtures/Resolver/ResolverKernel.php b/fixtures/Resolver/ResolverKernel.php index e20a60f4..d8253bf6 100644 --- a/fixtures/Resolver/ResolverKernel.php +++ b/fixtures/Resolver/ResolverKernel.php @@ -16,14 +16,8 @@ use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\HttpKernel\Kernel; -/** - * @author Théo FIDRY - */ class ResolverKernel extends Kernel { - /** - * {@inheritdoc} - */ public function registerBundles(): iterable { return [ @@ -32,10 +26,7 @@ public function registerBundles(): iterable ]; } - /** - * {@inheritdoc} - */ - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { // Do nothing. } diff --git a/fixtures/fixture_files/city.yml b/fixtures/fixture_files/city.yaml similarity index 100% rename from fixtures/fixture_files/city.yml rename to fixtures/fixture_files/city.yaml diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7bd141a0..6671c28d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -4,8 +4,7 @@ bootstrap="fixtures/Functional/bootstrap.php" colors="true" forceCoversAnnotation="true" - verbose="true" - stopOnFailure="true"> + verbose="true"> diff --git a/src/Alice/FileLocator/KernelFileLocator.php b/src/Alice/FileLocator/KernelFileLocator.php index d2d985b1..71bd0059 100644 --- a/src/Alice/FileLocator/KernelFileLocator.php +++ b/src/Alice/FileLocator/KernelFileLocator.php @@ -21,8 +21,8 @@ final class KernelFileLocator implements FileLocatorInterface { use IsAServiceTrait; - private $fileLocator; - private $kernel; + private FileLocatorInterface $fileLocator; + private KernelInterface $kernel; public function __construct(FileLocatorInterface $decoratedFileLocator, KernelInterface $kernel) { @@ -30,9 +30,6 @@ public function __construct(FileLocatorInterface $decoratedFileLocator, KernelIn $this->kernel = $kernel; } - /** - * {@inheritdoc} - */ public function locate(string $name, string $currentPath = null): string { if ('@' === $name[0]) { diff --git a/src/Alice/Generator/Instantiator/Chainable/InstantiatedReferenceInstantiator.php b/src/Alice/Generator/Instantiator/Chainable/InstantiatedReferenceInstantiator.php index ba199b30..ff19602e 100644 --- a/src/Alice/Generator/Instantiator/Chainable/InstantiatedReferenceInstantiator.php +++ b/src/Alice/Generator/Instantiator/Chainable/InstantiatedReferenceInstantiator.php @@ -13,6 +13,8 @@ namespace Hautelook\AliceBundle\Alice\Generator\Instantiator\Chainable; +use function get_class; +use LogicException; use Nelmio\Alice\Definition\MethodCall\MethodCallWithReference; use Nelmio\Alice\Definition\Object\SimpleObject; use Nelmio\Alice\Definition\ServiceReference\InstantiatedReference; @@ -22,6 +24,7 @@ use Nelmio\Alice\Generator\ResolvedFixtureSet; use Nelmio\Alice\IsAServiceTrait; use Nelmio\Alice\Throwable\Exception\Generator\Instantiator\InstantiationException; +use function sprintf; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -29,19 +32,13 @@ final class InstantiatedReferenceInstantiator implements ChainableInstantiatorIn { use IsAServiceTrait; - private $container; + private ?ContainerInterface $container = null; - /** - * {@inheritdoc} - */ public function setContainer(ContainerInterface $container = null) { $this->container = $container; } - /** - * {@inheritdoc} - */ public function canInstantiate(FixtureInterface $fixture): bool { $constructor = $fixture->getSpecs()->getConstructor(); @@ -53,9 +50,6 @@ public function canInstantiate(FixtureInterface $fixture): bool ; } - /** - * {@inheritdoc} - */ public function instantiate( FixtureInterface $fixture, ResolvedFixtureSet $fixtureSet, @@ -67,23 +61,32 @@ public function instantiate( return $this->generateSet($fixture, $fixtureSet, $instance); } - private function checkContainer(string $method) + private function checkContainer(string $method): void { if (null === $this->container) { - throw new \LogicException( + throw new LogicException( sprintf( - 'Expected instantiator method "%s" to be used only if it has a container, but no container could' - .' be found.', - $method - ) + 'Expected instantiator method "%s" to be used only if it has a container, but no container could be found.', + $method, + ), ); } } - private function createInstance(FixtureInterface $fixture) + private function createInstance(FixtureInterface $fixture): object { $constructor = $fixture->getSpecs()->getConstructor(); - list($class, $factoryReference, $method, $arguments) = [ + + if (null === $constructor) { + throw new InstantiationException( + sprintf( + 'Expected fixture "%s" to have a constructor.', + $fixture->getId(), + ), + ); + } + + [$class, $factoryReference, $method, $arguments] = [ $fixture->getClassName(), $constructor->getCaller()->getId(), $constructor->getMethod(), @@ -97,12 +100,13 @@ private function createInstance(FixtureInterface $fixture) $factory = $this->container->get($factoryReference); $instance = $factory->$method(...$arguments); - if (false === $instance instanceof $class) { + + if (!($instance instanceof $class)) { throw new InstantiationException( sprintf( 'Instantiated fixture was expected to be an instance of "%s". Got "%s" instead.', $class, - \get_class($instance) + get_class($instance) ) ); } diff --git a/src/BundleResolverInterface.php b/src/BundleResolverInterface.php index 2953f6ce..6b57064d 100644 --- a/src/BundleResolverInterface.php +++ b/src/BundleResolverInterface.php @@ -27,7 +27,7 @@ interface BundleResolverInterface * * @throws BundleNotFoundException * - * @return BundleInterface[] + * @return list */ - public function resolveBundles(Application $application, array $names); + public function resolveBundles(Application $application, array $names): array; } diff --git a/src/Console/Command/Doctrine/DoctrineOrmLoadDataFixturesCommand.php b/src/Console/Command/Doctrine/DoctrineOrmLoadDataFixturesCommand.php index 947208a6..f4342fa6 100644 --- a/src/Console/Command/Doctrine/DoctrineOrmLoadDataFixturesCommand.php +++ b/src/Console/Command/Doctrine/DoctrineOrmLoadDataFixturesCommand.php @@ -15,8 +15,10 @@ use Doctrine\Persistence\ManagerRegistry; use DomainException; +use const E_USER_DEPRECATED; use Hautelook\AliceBundle\LoaderInterface as AliceBundleLoaderInterface; -use RuntimeException; +use InvalidArgumentException; +use function sprintf; use Symfony\Bundle\FrameworkBundle\Console\Application as FrameworkBundleConsoleApplication; use Symfony\Component\Console\Application as ConsoleApplication; use Symfony\Component\Console\Command\Command; @@ -25,39 +27,30 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ConfirmationQuestion; +use function trigger_error; /** * Command used to load the fixtures. */ class DoctrineOrmLoadDataFixturesCommand extends Command { - /** - * @var string - */ protected static $defaultName = 'hautelook:fixtures:load'; - /** - * @var ManagerRegistry - */ - private $doctrine; - - /** - * @var AliceBundleLoaderInterface - */ - private $loader; + private ManagerRegistry $doctrine; + private AliceBundleLoaderInterface $loader; - public function __construct(string $name, ManagerRegistry $managerRegistry, AliceBundleLoaderInterface $loader) - { + public function __construct( + string $name, + ManagerRegistry $managerRegistry, + AliceBundleLoaderInterface $loader + ) { parent::__construct($name); $this->doctrine = $managerRegistry; $this->loader = $loader; } - /** - * {@inheritdoc} - */ - protected function configure() + protected function configure(): void { $this ->setAliases([self::$defaultName]) @@ -102,49 +95,44 @@ protected function configure() ; } - /** - * {@inheritdoc} - */ - public function setApplication(ConsoleApplication $application = null) + public function setApplication(ConsoleApplication $application = null): void { - if (null !== $application && false === $application instanceof FrameworkBundleConsoleApplication) { - throw new \InvalidArgumentException( + if (null !== $application + && !($application instanceof FrameworkBundleConsoleApplication) + ) { + throw new InvalidArgumentException( sprintf( 'Expected application to be an instance of "%s".', - FrameworkBundleConsoleApplication::class - ) + FrameworkBundleConsoleApplication::class, + ), ); } parent::setApplication($application); } - /** - * {@inheritdoc} - * - * @throws RuntimeException Unsupported Application type - */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { // Warn the user that the database will be purged // Ask him to confirm his choice - if ($input->isInteractive() && !$input->getOption('append')) { - if (false === $this->askConfirmation( + if ( + $input->isInteractive() + && !$input->getOption('append') + && !$this->askConfirmation( $input, $output, 'Careful, database will be purged. Do you want to continue y/N ?', false ) - ) { - return 0; - } + ) { + return self::SUCCESS; } $noBundles = $input->getOption('no-bundles') ?? false; if (!$noBundles) { @trigger_error( 'The configuration parameter hautelook_alice.root_dirs should be used to specify the directories to include. If done or if you do not need to load bundle\'s fixtures, use the --no-bundles option', - \E_USER_DEPRECATED + E_USER_DEPRECATED ); } @@ -152,7 +140,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($bundles) { @trigger_error( 'The option --bundle is deprecated. Use the configuration parameter hautelook_alice.root_dirs to include the desired directories instead', - \E_USER_DEPRECATED + E_USER_DEPRECATED ); } @@ -176,13 +164,15 @@ protected function execute(InputInterface $input, OutputInterface $output) /** * Prompts to the user a message to ask him a confirmation. * - * @param string $question - * @param bool $default * * @return bool User choice */ - private function askConfirmation(InputInterface $input, OutputInterface $output, $question, $default) - { + private function askConfirmation( + InputInterface $input, + OutputInterface $output, + string $question, + bool $default + ): bool { /** @var QuestionHelper $questionHelper */ $questionHelper = $this->getHelperSet()->get('question'); $question = new ConfirmationQuestion($question, $default); diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 9760c875..d935de3d 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -15,7 +15,6 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; -use Symfony\Component\HttpKernel\Kernel; /** * @private @@ -25,31 +24,11 @@ */ final class Configuration implements ConfigurationInterface { - /** - * {@inheritdoc} - */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('hautelook_alice'); - if (method_exists($treeBuilder, 'getRootNode')) { - $rootNode = $treeBuilder->getRootNode(); - } else { - // BC for symfony/config < 4.2 - $rootNode = $treeBuilder->root('hautelook_alice'); - } - - $defaultRootDirsValue = [ - '%kernel.root_dir%', - '%kernel.project_dir%', - ]; - if (Kernel::VERSION_ID >= 50000) { - $defaultRootDirsValue = [ - '%kernel.project_dir%', - ]; - } - - $rootNode + $treeBuilder->getRootNode() ->children() ->arrayNode('fixtures_path') ->info('Path(s) to which to look for fixtures relative to the bundle/root directory paths.') @@ -59,7 +38,9 @@ public function getConfigTreeBuilder() ->end() ->arrayNode('root_dirs') ->info('List of root directories into which to look for the fixtures.') - ->defaultValue($defaultRootDirsValue) + ->defaultValue([ + '%kernel.project_dir%', + ]) ->scalarPrototype() ->end() ->end() diff --git a/src/DependencyInjection/HautelookAliceExtension.php b/src/DependencyInjection/HautelookAliceExtension.php index b38d3f64..04c06ed8 100644 --- a/src/DependencyInjection/HautelookAliceExtension.php +++ b/src/DependencyInjection/HautelookAliceExtension.php @@ -13,9 +13,11 @@ namespace Hautelook\AliceBundle\DependencyInjection; +use function array_keys; use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; use Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle; use Hautelook\AliceBundle\HautelookAliceBundle; +use function implode; use LogicException; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -32,27 +34,31 @@ */ final class HautelookAliceExtension extends Extension { - const SERVICES_DIR = __DIR__.'/../../resources/config'; + private const SERVICES_DIR = __DIR__.'/../../resources/config'; - /** - * {@inheritdoc} - */ - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { - $missingBundles = [DoctrineBundle::class => true, FidryAliceDataFixturesBundle::class => true]; + $missingBundles = [ + DoctrineBundle::class => true, + FidryAliceDataFixturesBundle::class => true, + ]; + foreach ($container->getParameter('kernel.bundles') as $bundle) { unset($missingBundles[$bundle]); + if (!$missingBundles) { break; } } if ($missingBundles) { - throw new LogicException(sprintf( - 'To register "%s", you also need: "%s".', - HautelookAliceBundle::class, - implode('", "', array_keys($missingBundles)) - )); + throw new LogicException( + sprintf( + 'To register "%s", you also need: "%s".', + HautelookAliceBundle::class, + implode('", "', array_keys($missingBundles)), + ), + ); } $this->loadConfig($configs, $container); @@ -61,11 +67,8 @@ public function load(array $configs, ContainerBuilder $container) /** * Loads alice configuration and add the configuration values to the application parameters. - * - * @throws \InvalidArgumentException - * @throws \Exception */ - private function loadConfig(array $configs, ContainerBuilder $container) + private function loadConfig(array $configs, ContainerBuilder $container): void { $configuration = new Configuration(); $processedConfiguration = $this->processConfiguration($configuration, $configs); @@ -81,7 +84,7 @@ private function loadConfig(array $configs, ContainerBuilder $container) /** * Loads all the services declarations. */ - private function loadServices(ContainerBuilder $container) + private function loadServices(ContainerBuilder $container): void { $loader = new XmlFileLoader($container, new FileLocator(self::SERVICES_DIR)); $finder = new Finder(); @@ -89,9 +92,7 @@ private function loadServices(ContainerBuilder $container) $finder->files()->in(self::SERVICES_DIR); foreach ($finder as $file) { - $loader->load( - $file->getRelativePathname() - ); + $loader->load($file->getRelativePathname()); } } } diff --git a/src/Exception/Resolver/BundleNotFoundException.php b/src/Exception/Resolver/BundleNotFoundException.php index 6b86eb78..c51c6cf4 100644 --- a/src/Exception/Resolver/BundleNotFoundException.php +++ b/src/Exception/Resolver/BundleNotFoundException.php @@ -13,19 +13,21 @@ namespace Hautelook\AliceBundle\Exception\Resolver; +use function array_keys; +use function implode; +use RuntimeException; +use function sprintf; use Symfony\Component\HttpKernel\Bundle\BundleInterface; use Throwable; -class BundleNotFoundException extends \RuntimeException +final class BundleNotFoundException extends RuntimeException { /** * @param BundleInterface[] $bundles - * - * @return static */ - public static function create(string $bundle, array $bundles, int $code = 0, Throwable $previous = null) + public static function create(string $bundle, array $bundles, int $code = 0, Throwable $previous = null): self { - return new static( + return new self( sprintf( 'The bundle "%s" was not found. Bundles available are: ["%s"].', $bundle, diff --git a/src/FixtureLocatorInterface.php b/src/FixtureLocatorInterface.php index 9f802d8e..d5ba2f44 100644 --- a/src/FixtureLocatorInterface.php +++ b/src/FixtureLocatorInterface.php @@ -20,9 +20,9 @@ interface FixtureLocatorInterface /** * Locales all the fixture files to load. * - * @param BundleInterface[] $bundles + * @param list $bundles * - * @return string[] Fixtures files paths + * @return list Fixtures files paths */ public function locateFiles(array $bundles, string $environment): array; } diff --git a/src/Loader/DoctrineOrmLoader.php b/src/Loader/DoctrineOrmLoader.php index 2725195a..f410b0bb 100644 --- a/src/Loader/DoctrineOrmLoader.php +++ b/src/Loader/DoctrineOrmLoader.php @@ -13,13 +13,14 @@ namespace Hautelook\AliceBundle\Loader; -use Doctrine\DBAL\Sharding\PoolingShardConnection; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\Shards\DBAL\PoolingShardConnection; use Fidry\AliceDataFixtures\Bridge\Doctrine\Persister\ObjectManagerPersister; use Fidry\AliceDataFixtures\LoaderInterface; use Fidry\AliceDataFixtures\Persistence\PersisterAwareInterface; use Fidry\AliceDataFixtures\Persistence\PersisterInterface; use Fidry\AliceDataFixtures\Persistence\PurgeMode; +use function get_class; use Hautelook\AliceBundle\BundleResolverInterface; use Hautelook\AliceBundle\FixtureLocatorInterface; use Hautelook\AliceBundle\LoaderInterface as AliceBundleLoaderInterface; @@ -29,19 +30,20 @@ use Nelmio\Alice\IsAServiceTrait; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; +use function sprintf; use Symfony\Bundle\FrameworkBundle\Console\Application; class DoctrineOrmLoader implements AliceBundleLoaderInterface, LoggerAwareInterface { use IsAServiceTrait; - private $bundleResolver; - private $fixtureLocator; - /** @var LoaderInterface|PersisterAwareInterface */ - private $purgeLoader; - /** @var LoaderInterface|PersisterAwareInterface */ - private $appendLoader; - private $logger; + private BundleResolverInterface $bundleResolver; + private FixtureLocatorInterface $fixtureLocator; + /** @var LoaderInterface&PersisterAwareInterface */ + private LoaderInterface $purgeLoader; + /** @var LoaderInterface&PersisterAwareInterface */ + private LoaderInterface $appendLoader; + private LoggerInterface $logger; public function __construct( BundleResolverInterface $bundleResolver, @@ -76,9 +78,6 @@ public function __construct( $this->logger = $logger ?? new NullLogger(); } - /** - * {@inheritdoc} - */ public function withLogger(LoggerInterface $logger): self { return new self( @@ -90,9 +89,6 @@ public function withLogger(LoggerInterface $logger): self ); } - /** - * {@inheritdoc} - */ public function load( Application $application, EntityManagerInterface $manager, @@ -102,7 +98,7 @@ public function load( bool $purgeWithTruncate, string $shard = null, bool $noBundles = false - ) { + ): array { if ($append && $purgeWithTruncate) { throw new LogicException( 'Cannot append loaded fixtures and at the same time purge the database. Choose one.' @@ -153,7 +149,7 @@ protected function loadFixtures( array $files, array $parameters, ?PurgeMode $purgeMode - ) { + ): array { $persister = $this->createPersister($manager); $loader = $loader->withPersister($persister); @@ -164,6 +160,7 @@ protected function loadFixtures( private function connectToShardConnection(EntityManagerInterface $manager, string $shard) { $connection = $manager->getConnection(); + if ($connection instanceof PoolingShardConnection) { $connection->connect($shard); @@ -176,7 +173,7 @@ private function connectToShardConnection(EntityManagerInterface $manager, strin .' of "%s", got "%s" instead.', $shard, PoolingShardConnection::class, - \get_class($connection) + get_class($connection) ) ); } diff --git a/src/LoaderInterface.php b/src/LoaderInterface.php index 5ec66700..ec5422ca 100644 --- a/src/LoaderInterface.php +++ b/src/LoaderInterface.php @@ -44,5 +44,5 @@ public function load( bool $purgeWithTruncate, string $shard = null, bool $noBundles = false - ); + ): array; } diff --git a/src/Locator/EnvDirectoryLocator.php b/src/Locator/EnvDirectoryLocator.php index c96b3173..018766fd 100644 --- a/src/Locator/EnvDirectoryLocator.php +++ b/src/Locator/EnvDirectoryLocator.php @@ -13,6 +13,8 @@ namespace Hautelook\AliceBundle\Locator; +use function array_map; +use function array_merge; use Hautelook\AliceBundle\FixtureLocatorInterface; use Nelmio\Alice\IsAServiceTrait; use Symfony\Component\Finder\Finder as SymfonyFinder; @@ -22,8 +24,8 @@ final class EnvDirectoryLocator implements FixtureLocatorInterface { use IsAServiceTrait; - private $fixturePaths; - private $rootDirs; + private array $fixturePaths; + private array $rootDirs; /** * @param string[] $fixturePaths paths in which to look for fixtures relative to the bundle/base directory paths @@ -46,7 +48,7 @@ public function __construct(array $fixturePaths, array $rootDirs) */ public function locateFiles(array $bundles, string $environment): array { - $fixtureFiles = array_merge( + return array_merge( ...array_map( function (string $rootDir) use ($environment): array { return $this->doLocateFiles($rootDir, $environment); @@ -60,8 +62,6 @@ function (BundleInterface $bundle) use ($environment): array { $bundles ) ); - - return $fixtureFiles; } /** diff --git a/src/Locator/EnvironmentlessFilesLocator.php b/src/Locator/EnvironmentlessFilesLocator.php index a8bbd8c3..bdec7849 100644 --- a/src/Locator/EnvironmentlessFilesLocator.php +++ b/src/Locator/EnvironmentlessFilesLocator.php @@ -13,6 +13,8 @@ namespace Hautelook\AliceBundle\Locator; +use function array_flip; +use function array_keys; use Hautelook\AliceBundle\FixtureLocatorInterface; use Nelmio\Alice\IsAServiceTrait; @@ -20,7 +22,7 @@ final class EnvironmentlessFilesLocator implements FixtureLocatorInterface { use IsAServiceTrait; - private $fixtureLocator; + private FixtureLocatorInterface $fixtureLocator; public function __construct(FixtureLocatorInterface $fixtureLocator) { diff --git a/src/PhpUnit/BaseDatabaseTrait.php b/src/PhpUnit/BaseDatabaseTrait.php index feaffa58..f1849b96 100644 --- a/src/PhpUnit/BaseDatabaseTrait.php +++ b/src/PhpUnit/BaseDatabaseTrait.php @@ -13,7 +13,9 @@ namespace Hautelook\AliceBundle\PhpUnit; +use function is_a; use LogicException; +use function sprintf; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; @@ -22,37 +24,37 @@ trait BaseDatabaseTrait /** * @var string|null The name of the Doctrine manager to use */ - protected static $manager; + protected static ?string $manager = null; /** * @var string[] The list of bundles where to look for fixtures */ - protected static $bundles = []; + protected static array $bundles = []; /** * @var bool Append fixtures instead of purging */ - protected static $append = false; + protected static bool $append = false; /** * @var bool Use TRUNCATE to purge */ - protected static $purgeWithTruncate = true; + protected static bool $purgeWithTruncate = true; /** * @var string|null The name of the Doctrine shard to use */ - protected static $shard; + protected static ?string $shard = null; /** * @var string|null The name of the Doctrine connection to use */ - protected static $connection; + protected static ?string $connection = null; /** * @var array|null Contain loaded fixture from alice */ - protected static $fixtures; + protected static ?array $fixtures = null; protected static function ensureKernelTestCase(): void { @@ -63,7 +65,7 @@ protected static function ensureKernelTestCase(): void protected static function populateDatabase(): void { - $container = static::$container ?? static::$kernel->getContainer(); + $container = static::$kernel->getContainer(); static::$fixtures = $container->get('hautelook_alice.loader')->load( new Application(static::$kernel), // OK this is ugly... But there is no other way without redesigning LoaderInterface from the ground. $container->get('doctrine')->getManager(static::$manager), diff --git a/src/PhpUnit/RecreateDatabaseTrait.php b/src/PhpUnit/RecreateDatabaseTrait.php index 10d35b5d..3775aa7b 100644 --- a/src/PhpUnit/RecreateDatabaseTrait.php +++ b/src/PhpUnit/RecreateDatabaseTrait.php @@ -38,7 +38,7 @@ protected static function bootKernel(array $options = []): KernelInterface protected static function buildSchema(): void { - $container = static::$container ?? static::$kernel->getContainer(); + $container = static::$kernel->getContainer(); $em = $container->get('doctrine')->getManager(static::$manager); $meta = $em->getMetadataFactory()->getAllMetadata(); diff --git a/src/PhpUnit/RefreshDatabaseTrait.php b/src/PhpUnit/RefreshDatabaseTrait.php index 60102f3f..cb997352 100644 --- a/src/PhpUnit/RefreshDatabaseTrait.php +++ b/src/PhpUnit/RefreshDatabaseTrait.php @@ -25,7 +25,7 @@ trait RefreshDatabaseTrait { use BaseDatabaseTrait; - protected static $dbPopulated = false; + protected static bool $dbPopulated = false; protected static function bootKernel(array $options = []): KernelInterface { @@ -37,15 +37,15 @@ protected static function bootKernel(array $options = []): KernelInterface static::$dbPopulated = true; } - $container = static::$container ?? static::$kernel->getContainer(); + $container = static::$kernel->getContainer(); $container->get('doctrine')->getConnection(static::$connection)->beginTransaction(); return $kernel; } - protected static function ensureKernelShutdown() + protected static function ensureKernelShutdown(): void { - $container = static::$container ?? null; + $container = null; if (null === $container && null !== static::$kernel) { $container = static::$kernel->getContainer(); } diff --git a/src/Resolver/Bundle/NoBundleResolver.php b/src/Resolver/Bundle/NoBundleResolver.php index c748aa37..6ed69cf1 100644 --- a/src/Resolver/Bundle/NoBundleResolver.php +++ b/src/Resolver/Bundle/NoBundleResolver.php @@ -24,17 +24,14 @@ final class NoBundleResolver implements BundleResolverInterface { use IsAServiceTrait; - private $decoratedResolver; + private BundleResolverInterface $decoratedResolver; public function __construct(BundleResolverInterface $decoratedResolver) { $this->decoratedResolver = $decoratedResolver; } - /** - * {@inheritdoc} - */ - public function resolveBundles(Application $application, array $names) + public function resolveBundles(Application $application, array $names): array { if ([] === $names) { return array_values($application->getKernel()->getBundles()); diff --git a/src/Resolver/Bundle/SimpleBundleResolver.php b/src/Resolver/Bundle/SimpleBundleResolver.php index d2967cfc..307a0f13 100644 --- a/src/Resolver/Bundle/SimpleBundleResolver.php +++ b/src/Resolver/Bundle/SimpleBundleResolver.php @@ -13,6 +13,7 @@ namespace Hautelook\AliceBundle\Resolver\Bundle; +use function array_values; use Hautelook\AliceBundle\BundleResolverInterface; use Hautelook\AliceBundle\Exception\Resolver\BundleNotFoundException; use Nelmio\Alice\IsAServiceTrait; @@ -22,10 +23,7 @@ final class SimpleBundleResolver implements BundleResolverInterface { use IsAServiceTrait; - /** - * {@inheritdoc} - */ - public function resolveBundles(Application $application, array $names) + public function resolveBundles(Application $application, array $names): array { $bundles = $application->getKernel()->getBundles(); diff --git a/src/Resolver/File/KernelFileResolver.php b/src/Resolver/File/KernelFileResolver.php index 8bc9fd82..8f0a380a 100644 --- a/src/Resolver/File/KernelFileResolver.php +++ b/src/Resolver/File/KernelFileResolver.php @@ -13,25 +13,27 @@ namespace Hautelook\AliceBundle\Resolver\File; +use function array_keys; use Fidry\AliceDataFixtures\FileResolverInterface; +use function file_exists; use InvalidArgumentException; +use function is_file; use Nelmio\Alice\IsAServiceTrait; +use function realpath; +use function sprintf; use Symfony\Component\HttpKernel\KernelInterface; final class KernelFileResolver implements FileResolverInterface { use IsAServiceTrait; - private $kernel; + private KernelInterface $kernel; public function __construct(KernelInterface $kernel) { $this->kernel = $kernel; } - /** - * {@inheritdoc} - */ public function resolve(array $filePaths): array { $resolvedFixtures = []; diff --git a/tests/Alice/Generator/Instantiator/Chainable/InstantiatedReferenceInstantiatorTest.php b/tests/Alice/Generator/Instantiator/Chainable/InstantiatedReferenceInstantiatorTest.php index fa78cef9..8bc1629a 100644 --- a/tests/Alice/Generator/Instantiator/Chainable/InstantiatedReferenceInstantiatorTest.php +++ b/tests/Alice/Generator/Instantiator/Chainable/InstantiatedReferenceInstantiatorTest.php @@ -15,6 +15,8 @@ use Hautelook\AliceBundle\Functional\TestBundle\Entity\City; use Hautelook\AliceBundle\Functional\TestBundle\Entity\CityFactory; +use function is_a; +use LogicException; use Nelmio\Alice\Definition\Fixture\SimpleFixture; use Nelmio\Alice\Definition\MethodCall\MethodCallWithReference; use Nelmio\Alice\Definition\MethodCallBag; @@ -28,6 +30,7 @@ use Nelmio\Alice\Generator\ResolvedFixtureSet; use Nelmio\Alice\ObjectBag; use Nelmio\Alice\ParameterBag; +use Nelmio\Alice\Throwable\Exception\Generator\Instantiator\InstantiationException; use PHPUnit\Framework\TestCase; use ReflectionClass; use Symfony\Component\DependencyInjection\Container; @@ -37,25 +40,25 @@ */ class InstantiatedReferenceInstantiatorTest extends TestCase { - public function testIsAChainableInstantiator() + public function testIsAChainableInstantiator(): void { - $this->assertTrue(is_a(InstantiatedReferenceInstantiator::class, ChainableInstantiatorInterface::class, true)); + self::assertTrue(is_a(InstantiatedReferenceInstantiator::class, ChainableInstantiatorInterface::class, true)); } - public function testIsNotClonable() + public function testIsNotClonable(): void { - $this->assertFalse((new ReflectionClass(InstantiatedReferenceInstantiator::class))->isCloneable()); + self::assertFalse((new ReflectionClass(InstantiatedReferenceInstantiator::class))->isCloneable()); } - public function testCannotInstantiateFixtureWithDefaultConstructor() + public function testCannotInstantiateFixtureWithDefaultConstructor(): void { $fixture = new SimpleFixture('dummy', 'Dummy', new SpecificationBag(null, new PropertyBag(), new MethodCallBag())); $instantiator = new InstantiatedReferenceInstantiator(); - $this->assertFalse($instantiator->canInstantiate($fixture)); + self::assertFalse($instantiator->canInstantiate($fixture)); } - public function testCannotInstantiateFixtureWithStaticFactoryMethodCallConstructor() + public function testCannotInstantiateFixtureWithStaticFactoryMethodCallConstructor(): void { $fixture = new SimpleFixture( 'dummy', @@ -71,10 +74,10 @@ public function testCannotInstantiateFixtureWithStaticFactoryMethodCallConstruct ); $instantiator = new InstantiatedReferenceInstantiator(); - $this->assertFalse($instantiator->canInstantiate($fixture)); + self::assertFalse($instantiator->canInstantiate($fixture)); } - public function testCanInstantiateFixtureWitAServiceReferenceFactory() + public function testCanInstantiateFixtureWitAServiceReferenceFactory(): void { $fixture = new SimpleFixture( 'dummy', @@ -90,12 +93,12 @@ public function testCanInstantiateFixtureWitAServiceReferenceFactory() ); $instantiator = new InstantiatedReferenceInstantiator(); - $this->assertTrue($instantiator->canInstantiate($fixture)); + self::assertTrue($instantiator->canInstantiate($fixture)); } - public function testThrowsAnExceptionIfNoContainerIsSetWhilstTryingToInstantiateObject() + public function testThrowsAnExceptionIfNoContainerIsSetWhilstTryingToInstantiateObject(): void { - $this->expectException(\LogicException::class); + $this->expectException(LogicException::class); $this->expectExceptionMessage('Expected instantiator method "Hautelook\AliceBundle\Alice\Generator\Instantiator\Chainable\InstantiatedReferenceInstantiator::instantiate" to be used only if it has a container, but no container could be found.'); $fixture = new SimpleFixture( @@ -121,7 +124,7 @@ public function testThrowsAnExceptionIfNoContainerIsSetWhilstTryingToInstantiate $instantiator->instantiate($fixture, $set, new GenerationContext()); } - public function testInstantiatesObjectWithFactoryAndArguments() + public function testInstantiatesObjectWithFactoryAndArguments(): void { $fixture = new SimpleFixture( 'dummy', @@ -152,12 +155,12 @@ public function testInstantiatesObjectWithFactoryAndArguments() $expected = $cityFactory->create('foo'); $actual = $set->getObjects()->get($fixture)->getInstance(); - $this->assertEquals($expected, $actual); + self::assertEquals($expected, $actual); } - public function testThrowsAnExceptionIfTheInstantiatedFixtureIsNotOfTheClassExpected() + public function testThrowsAnExceptionIfTheInstantiatedFixtureIsNotOfTheClassExpected(): void { - $this->expectException(\Nelmio\Alice\Throwable\Exception\Generator\Instantiator\InstantiationException::class); + $this->expectException(InstantiationException::class); $this->expectExceptionMessage('Instantiated fixture was expected to be an instance of "Dummy". Got "Hautelook\AliceBundle\Functional\TestBundle\Entity\City" instead.'); $fixture = new SimpleFixture( @@ -178,7 +181,7 @@ public function testThrowsAnExceptionIfTheInstantiatedFixtureIsNotOfTheClassExpe ) ); $container = new Container(); - $container->set('city_factory', $cityFactory = new CityFactory()); + $container->set('city_factory', new CityFactory()); $instantiator = new InstantiatedReferenceInstantiator(); $instantiator->setContainer($container); diff --git a/tests/Alice/Loader/ServiceFactoryTest.php b/tests/Alice/Loader/ServiceFactoryTest.php index a285e41b..50f2550e 100644 --- a/tests/Alice/Loader/ServiceFactoryTest.php +++ b/tests/Alice/Loader/ServiceFactoryTest.php @@ -22,13 +22,13 @@ */ class ServiceFactoryTest extends TestCase { - public function testCanUseServiceFactory() + public function testCanUseServiceFactory(): void { $kernel = new TestKernel('ServiceFactoryTest', true); $kernel->boot(); $loader = $kernel->getContainer()->get('nelmio_alice.file_loader'); - $set = $loader->loadFile(__DIR__.'/../../../fixtures/fixture_files/city.yml'); + $set = $loader->loadFile(__DIR__.'/../../../fixtures/fixture_files/city.yaml'); $cityFactory = new CityFactory(); $expected = []; @@ -36,8 +36,8 @@ public function testCanUseServiceFactory() $expected['city_'.$i] = $cityFactory->create((string) $i); } - $this->assertCount(\count($expected), $set->getObjects()); - $this->assertEquals($expected, $set->getObjects()); + self::assertCount(\count($expected), $set->getObjects()); + self::assertEquals($expected, $set->getObjects()); $kernel->shutdown(); } diff --git a/tests/Console/Command/Doctrine/LoadDataFixturesCommandIntegrationTest.php b/tests/Console/Command/Doctrine/LoadDataFixturesCommandIntegrationTest.php index f71a42a2..a90e56c0 100644 --- a/tests/Console/Command/Doctrine/LoadDataFixturesCommandIntegrationTest.php +++ b/tests/Console/Command/Doctrine/LoadDataFixturesCommandIntegrationTest.php @@ -13,16 +13,24 @@ namespace Hautelook\AliceBundle\Console\Command\Doctrine; -use Doctrine\DBAL\Sharding\PoolingShardConnection; +use function array_diff; +use function array_merge; +use function array_shift; use Doctrine\ORM\EntityManagerInterface; -use Hautelook\AliceBundle\Functional\AppKernel; +use Doctrine\Shards\DBAL\PoolingShardConnection; +use function explode; +use function getcwd; use Hautelook\AliceBundle\Functional\TestBundle\Entity\Brand; use Hautelook\AliceBundle\Functional\TestBundle\Entity\Product; use Hautelook\AliceBundle\Functional\TestKernel; use PHPUnit\Framework\TestCase; +use function preg_replace; +use function str_replace; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Tester\CommandTester; +use Symfony\Component\HttpKernel\KernelInterface; +use function trim; /** * @coversNothing @@ -30,29 +38,14 @@ */ class LoadDataFixturesCommandIntegrationTest extends TestCase { - /** - * @var Application - */ - private $application; + private Application $application; - /** - * @var AppKernel - */ - private $kernel; + private KernelInterface $kernel; - /** - * @var DoctrineOrmLoadDataFixturesCommand - */ - private $command; + private DoctrineOrmLoadDataFixturesCommand $command; - /** - * @var EntityManagerInterface - */ - private $defaultEntityManager; + private EntityManagerInterface $defaultEntityManager; - /** - * {@inheritdoc} - */ protected function setUp(): void { $this->kernel = new TestKernel('LoadDataFixturesCommandIntegrationTest', true); @@ -87,15 +80,12 @@ protected function setUp(): void } } - /** - * {@inheritdoc} - */ protected function tearDown(): void { $this->kernel->shutdown(); } - public function testFixturesLoading() + public function testFixturesLoading(): void { $command = $this->application->find('hautelook:fixtures:load'); $commandTester = new CommandTester($command); @@ -113,7 +103,7 @@ public function testFixturesLoading() $this->verifyBrands(10); } - public function testAppendFixtures() + public function testAppendFixtures(): void { $command = $this->application->find('hautelook:fixtures:load'); $commandTester = new CommandTester($command); @@ -144,7 +134,7 @@ public function testAppendFixtures() /** * @dataProvider loadCommandProvider */ - public function testFixturesRegisteringUsingInvalidManager(array $inputs, string $expected) + public function testFixturesRegisteringUsingInvalidManager(array $inputs, string $expected): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessageMatches('/^Doctrine (fixtures|ORM) Manager named "foo" does not exist\.$/'); @@ -162,7 +152,7 @@ public function testFixturesRegisteringUsingInvalidManager(array $inputs, string ['interactive' => false] ); - $this->assertFixturesDisplayEquals($expected, $commandTester->getDisplay()); + self::assertFixturesDisplayEquals($expected, $commandTester->getDisplay()); } /** @@ -183,10 +173,10 @@ public function testFixturesRegisteringUsingMySQL(array $inputs, string $expecte ['interactive' => false] ); - $this->assertFixturesDisplayEquals($expected, $commandTester->getDisplay()); + self::assertFixturesDisplayEquals($expected, $commandTester->getDisplay()); } - public function loadCommandProvider() + public static function loadCommandProvider(): iterable { $data = []; @@ -194,10 +184,10 @@ public function loadCommandProvider() [], <<<'EOF' > fixtures found: - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/brand.yml - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/product.yml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/brand.yaml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/product.yaml - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Bundle/ABundle/Resources/fixtures/aentity.php - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Bundle/BBundle/Resources/fixtures/bentity.yml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Bundle/BBundle/Resources/fixtures/bentity.yaml > purging database > fixtures loaded EOF @@ -209,11 +199,11 @@ public function loadCommandProvider() ], <<<'EOF' > fixtures found: - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/brand.yml - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/product.yml - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/Dev/dev.yml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/brand.yaml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/product.yaml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/Dev/dev.yaml - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Bundle/ABundle/Resources/fixtures/aentity.php - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Bundle/BBundle/Resources/fixtures/bentity.yml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Bundle/BBundle/Resources/fixtures/bentity.yaml > purging database > fixtures loaded EOF @@ -225,11 +215,11 @@ public function loadCommandProvider() ], <<<'EOF' > fixtures found: - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/brand.yml - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/product.yml - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/Prod/prod.yml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/brand.yaml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/product.yaml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/Prod/prod.yaml - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Bundle/ABundle/Resources/fixtures/aentity.php - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Bundle/BBundle/Resources/fixtures/bentity.yml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Bundle/BBundle/Resources/fixtures/bentity.yaml > purging database > fixtures loaded EOF @@ -242,10 +232,10 @@ public function loadCommandProvider() <<<'EOF' > fixtures found: - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Bundle/ABundle/Resources/fixtures/aentity.php - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Bundle/BBundle/Resources/fixtures/bentity.yml - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/Prod/prod.yml - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/brand.yml - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/product.yml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Bundle/BBundle/Resources/fixtures/bentity.yaml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/Prod/prod.yaml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/brand.yaml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/product.yaml > purging database > fixtures loaded EOF @@ -260,9 +250,9 @@ public function loadCommandProvider() ], <<<'EOF' > fixtures found: - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/brand.yml - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/product.yml - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/Dev/dev.yml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/brand.yaml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/product.yaml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/Dev/dev.yaml > purging database > fixtures loaded EOF @@ -293,9 +283,9 @@ public function loadCommandProvider() ], <<<'EOF' > fixtures found: - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/brand.yml - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/product.yml - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/Dev/dev.yml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/brand.yaml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/product.yaml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/Dev/dev.yaml - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Bundle/ABundle/Resources/fixtures/aentity.php > purging database > fixtures loaded @@ -312,7 +302,7 @@ public function loadCommandProvider() <<<'EOF' > fixtures found: - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Bundle/ABundle/Resources/fixtures/aentity.php - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Bundle/BBundle/Resources/fixtures/bentity.yml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Bundle/BBundle/Resources/fixtures/bentity.yaml > purging database > fixtures loaded EOF @@ -327,8 +317,8 @@ public function loadCommandProvider() ], <<<'EOF' > fixtures found: - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/brand.yml - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/product.yml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/brand.yaml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/product.yaml > purging database > fixtures loaded EOF @@ -343,9 +333,9 @@ public function loadCommandProvider() ], <<<'EOF' > fixtures found: - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/brand.yml - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/product.yml - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/Ignored2/notIgnored.yml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/brand.yaml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/product.yaml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/Ignored2/notIgnored.yaml > purging database > fixtures loaded EOF @@ -360,9 +350,9 @@ public function loadCommandProvider() ], <<<'EOF' > fixtures found: - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/brand.yml - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/product.yml - - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/Provider/testFormatter.yml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/brand.yaml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/product.yaml + - /home/travis/build/theofidry/AliceBundle/tests/Functional/TestBundle/Resources/fixtures/Provider/testFormatter.yaml > purging database > fixtures loaded EOF @@ -370,29 +360,28 @@ public function loadCommandProvider() // Fix paths foreach ($data as $index => $dataSet) { - $data[$index][1] = str_replace('/home/travis/build/theofidry/AliceBundle', getcwd(), $dataSet[1]); + $data[$index][1] = str_replace( + '/home/travis/build/theofidry/AliceBundle', + getcwd(), + $dataSet[1], + ); } return $data; } - /** - * @param string $expected - * @param string $display - */ - protected function assertFixturesDisplayEquals($expected, $display) + protected static function assertFixturesDisplayEquals(string $expected, string $display): void { - $expected = $this->normalizeFixturesDisplay($expected); - $display = $this->normalizeFixturesDisplay($display); - $this->assertCount(0, array_diff($expected, $display)); + $expected = self::normalizeFixturesDisplay($expected); + $display = self::normalizeFixturesDisplay($display); + + self::assertCount(0, array_diff($expected, $display)); } /** - * @param string $display - * * @return string[] */ - private function normalizeFixturesDisplay($display) + private static function normalizeFixturesDisplay(string $display): array { $display = trim($display, ' '); $display = trim($display, "\t"); @@ -412,9 +401,9 @@ private function runConsole(string $command, array $options = []): int return $this->application->run(new ArrayInput($options)); } - private function verifyProducts(int $count) + private function verifyProducts(int $count): void { - $this->assertCount( + self::assertCount( $count, $this->defaultEntityManager->getRepository(Product::class)->findAll() ); @@ -422,19 +411,19 @@ private function verifyProducts(int $count) for ($i = 1; $i <= $count; ++$i) { /* @var Product|null $product */ $product = $this->defaultEntityManager->find(Product::class, $i); - $this->assertNotNull($product); - $this->assertStringStartsWith('Awesome Product', $product->getDescription()); + self::assertNotNull($product); + self::assertStringStartsWith('Awesome Product', $product->getDescription()); // Make sure every product has a brand - $this->assertInstanceOf( + self::assertInstanceOf( Brand::class, $product->getBrand() ); } } - private function verifyBrands(int $count) + private function verifyBrands(int $count): void { - $this->assertCount( + self::assertCount( $count, $this->defaultEntityManager->getRepository(Brand::class)->findAll() ); @@ -442,7 +431,7 @@ private function verifyBrands(int $count) for ($i = 1; $i <= $count; ++$i) { /* @var Brand|null $brand */ $brand = $this->defaultEntityManager->find(Brand::class, $i); - $this->assertNotNull($brand); + self::assertNotNull($brand); } } } diff --git a/tests/Console/Command/Doctrine/LoadDataFixturesCommandTest.php b/tests/Console/Command/Doctrine/LoadDataFixturesCommandTest.php index bac332a0..177f4db2 100644 --- a/tests/Console/Command/Doctrine/LoadDataFixturesCommandTest.php +++ b/tests/Console/Command/Doctrine/LoadDataFixturesCommandTest.php @@ -38,30 +38,30 @@ class LoadDataFixturesCommandTest extends TestCase { use ProphecyTrait; - public function testIsACommand() + public function testIsACommand(): void { - $this->assertTrue(is_a(DoctrineOrmLoadDataFixturesCommand::class, Command::class, true)); + self::assertTrue(is_a(DoctrineOrmLoadDataFixturesCommand::class, Command::class, true)); } - public function testCanSetTheCommandApplication() + public function testCanSetTheCommandApplication(): void { $application = new FrameworkBundleConsoleApplication(new DummyKernel()); $command = new DoctrineOrmLoadDataFixturesCommand('dummy', new FakeDoctrineManagerRegistry(), new FakeLoader()); $command->setApplication($application); - $this->assertSame($application, $command->getApplication()); + self::assertSame($application, $command->getApplication()); } - public function testCanResetTheCommandApplication() + public function testCanResetTheCommandApplication(): void { $command = new DoctrineOrmLoadDataFixturesCommand('dummy', new FakeDoctrineManagerRegistry(), new FakeLoader()); $command->setApplication(null); - $this->assertTrue(true); + self::assertTrue(true); } - public function testThrowsAnExceptionIfInvalidApplicationIsGiven() + public function testThrowsAnExceptionIfInvalidApplicationIsGiven(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Expected application to be an instance of "Symfony\Bundle\FrameworkBundle\Console\Application".'); @@ -73,7 +73,7 @@ public function testThrowsAnExceptionIfInvalidApplicationIsGiven() /** * @group legacy */ - public function testCallCommandWithoutArguments() + public function testCallCommandWithoutArguments(): void { $application = new FrameworkBundleConsoleApplication(new DummyKernel()); $application->setAutoExit(false); @@ -83,13 +83,13 @@ public function testCallCommandWithoutArguments() ]); $input->setInteractive(false); - /** @var ManagerRegistry|ObjectProphecy $managerRegistryProphecy */ + /** @var ObjectProphecy $managerRegistryProphecy */ $managerRegistryProphecy = $this->prophesize(ManagerRegistry::class); $managerRegistryProphecy->getManager(null)->willReturn($manager = new FakeEntityManager()); /** @var ManagerRegistry $managerRegistry */ $managerRegistry = $managerRegistryProphecy->reveal(); - /** @var LoaderInterface|ObjectProphecy $loaderProphecy */ + /** @var ObjectProphecy $loaderProphecy */ $loaderProphecy = $this->prophesize(LoaderInterface::class); $loaderProphecy ->load($application, $manager, [], 'fake_env', false, false, null, false) @@ -102,12 +102,12 @@ public function testCallCommandWithoutArguments() $command->setApplication($application); $exit = $command->run($input, new NullOutput()); - $this->assertEquals(0, $exit); + self::assertEquals(0, $exit); $loaderProphecy->load(Argument::cetera())->shouldHaveBeenCalledTimes(1); $managerRegistryProphecy->getManager(Argument::any())->shouldHaveBeenCalledTimes(1); } - public function testCallCommandWithArguments() + public function testCallCommandWithArguments(): void { $application = new FrameworkBundleConsoleApplication(new DummyKernel()); $application->setAutoExit(false); @@ -126,13 +126,13 @@ public function testCallCommandWithArguments() ]); $input->setInteractive(false); - /** @var ManagerRegistry|ObjectProphecy $managerRegistryProphecy */ + /** @var ObjectProphecy $managerRegistryProphecy */ $managerRegistryProphecy = $this->prophesize(ManagerRegistry::class); $managerRegistryProphecy->getManager('DummyManager')->willReturn($manager = new FakeEntityManager()); /** @var ManagerRegistry $managerRegistry */ $managerRegistry = $managerRegistryProphecy->reveal(); - /** @var LoaderInterface|ObjectProphecy $loaderProphecy */ + /** @var ObjectProphecy $loaderProphecy */ $loaderProphecy = $this->prophesize(LoaderInterface::class); $loaderProphecy ->load($application, $manager, ['ABundle', 'BBundle'], 'dummy_env', true, true, 'shard_id', false) @@ -145,12 +145,12 @@ public function testCallCommandWithArguments() $command->setApplication($application); $exit = $command->run($input, new NullOutput()); - $this->assertEquals(0, $exit); + self::assertEquals(0, $exit); $loaderProphecy->load(Argument::cetera())->shouldHaveBeenCalledTimes(1); $managerRegistryProphecy->getManager(Argument::any())->shouldHaveBeenCalledTimes(1); } - public function testCallCommandWithBundleAndNoBundlesFlags() + public function testCallCommandWithBundleAndNoBundlesFlags(): void { $application = new FrameworkBundleConsoleApplication(new DummyKernel()); $application->setAutoExit(false); @@ -170,13 +170,13 @@ public function testCallCommandWithBundleAndNoBundlesFlags() ]); $input->setInteractive(false); - /** @var ManagerRegistry|ObjectProphecy $managerRegistryProphecy */ + /** @var ObjectProphecy $managerRegistryProphecy */ $managerRegistryProphecy = $this->prophesize(ManagerRegistry::class); $managerRegistryProphecy->getManager('DummyManager')->willReturn($manager = new FakeEntityManager()); /** @var ManagerRegistry $managerRegistry */ $managerRegistry = $managerRegistryProphecy->reveal(); - /** @var LoaderInterface|ObjectProphecy $loaderProphecy */ + /** @var ObjectProphecy $loaderProphecy */ $loaderProphecy = $this->prophesize(LoaderInterface::class); $loaderProphecy ->load($application, $manager, ['ABundle', 'BBundle'], 'dummy_env', true, true, 'shard_id', true) @@ -193,7 +193,7 @@ public function testCallCommandWithBundleAndNoBundlesFlags() $this->fail(); } catch (DomainException $exception) { - $this->assertSame( + self::assertSame( '--bundle and --no-bundles flags cannot be specified both in same time.', $exception->getMessage() ); diff --git a/tests/DependencyInjection/ConfigurationTest.php b/tests/DependencyInjection/ConfigurationTest.php index dcf70331..475ad7df 100644 --- a/tests/DependencyInjection/ConfigurationTest.php +++ b/tests/DependencyInjection/ConfigurationTest.php @@ -21,7 +21,7 @@ */ class ConfigurationTest extends TestCase { - public function testDefaultValues() + public function testDefaultValues(): void { $configuration = new Configuration(); $processor = new Processor(); @@ -35,10 +35,10 @@ public function testDefaultValues() $actual = $processor->processConfiguration($configuration, []); - $this->assertEquals($expected, $actual); + self::assertEquals($expected, $actual); } - public function testDefaultValuesCanBeOverridden() + public function testDefaultValuesCanBeOverridden(): void { $configuration = new Configuration(); $processor = new Processor(); @@ -62,10 +62,10 @@ public function testDefaultValuesCanBeOverridden() ] ); - $this->assertEquals($expected, $actual); + self::assertEquals($expected, $actual); } - public function testSingleFixturePathIsConvertedToArray() + public function testSingleFixturePathIsConvertedToArray(): void { $configuration = new Configuration(); $processor = new Processor(); @@ -89,6 +89,6 @@ public function testSingleFixturePathIsConvertedToArray() ] ); - $this->assertEquals($expected, $actual); + self::assertEquals($expected, $actual); } } diff --git a/tests/DependencyInjection/HautelookAliceBundleTest.php b/tests/DependencyInjection/HautelookAliceBundleTest.php index 483fdf12..e4dd757e 100644 --- a/tests/DependencyInjection/HautelookAliceBundleTest.php +++ b/tests/DependencyInjection/HautelookAliceBundleTest.php @@ -14,9 +14,21 @@ namespace Hautelook\AliceBundle\DependencyInjection; use Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle; +use Fidry\AliceDataFixtures\Loader\FileResolverLoader; +use Fidry\AliceDataFixtures\LoaderInterface; +use Hautelook\AliceBundle\BundleResolverInterface; +use Hautelook\AliceBundle\Console\Command\Doctrine\DoctrineOrmLoadDataFixturesCommand; +use Hautelook\AliceBundle\FixtureLocatorInterface; use Hautelook\AliceBundle\Functional\AppKernel; use Hautelook\AliceBundle\Functional\ConfigurableKernel; use Hautelook\AliceBundle\Functional\WithoutDoctrineKernel; +use Hautelook\AliceBundle\Loader\DoctrineOrmLoader; +use Hautelook\AliceBundle\LoaderInterface as HautelookLoaderInterface; +use Hautelook\AliceBundle\Locator\EnvDirectoryLocator; +use Hautelook\AliceBundle\Locator\EnvironmentlessFilesLocator; +use Hautelook\AliceBundle\Resolver\Bundle\NoBundleResolver; +use Hautelook\AliceBundle\Resolver\Bundle\SimpleBundleResolver; +use LogicException; use Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; @@ -27,27 +39,24 @@ */ class HautelookAliceBundleTest extends KernelTestCase { - /** - * {@inheritdoc} - */ protected function tearDown(): void { parent::tearDown(); static::$class = null; } - public function testCannotBootIfFidryAliceDataFixturesBundleIsNotRegistered() + public function testCannotBootIfFidryAliceDataFixturesBundleIsNotRegistered(): void { - $this->expectException(\LogicException::class); + $this->expectException(LogicException::class); $this->expectExceptionMessage('To register "Hautelook\AliceBundle\HautelookAliceBundle", you also need: "Doctrine\Bundle\DoctrineBundle\DoctrineBundle", "Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle".'); self::$kernel = new ConfigurableKernel('ConfigurableKernel0', true); self::$kernel->boot(); } - public function testWillReplaceFixtureLoadCommandWithErrorInformationCommandIfDoctrineBundleIsNotRegistered() + public function testWillReplaceFixtureLoadCommandWithErrorInformationCommandIfDoctrineBundleIsNotRegistered(): void { - $this->expectException(\LogicException::class); + $this->expectException(LogicException::class); $this->expectExceptionMessage('To register "Hautelook\AliceBundle\HautelookAliceBundle", you also need: "Doctrine\Bundle\DoctrineBundle\DoctrineBundle".'); self::$kernel = new WithoutDoctrineKernel('ConfigurableKernel1', true); @@ -56,79 +65,76 @@ public function testWillReplaceFixtureLoadCommandWithErrorInformationCommandIfDo self::$kernel->boot(); } - public function testServiceRegistration() + public function testServiceRegistration(): void { - parent::bootKernel(['environment' => 'public', 'debug' => true]); + self::bootKernel(['environment' => 'public', 'debug' => true]); $container = self::getContainer(); // Resolvers - $this->assertInstanceOf( - \Hautelook\AliceBundle\Resolver\Bundle\SimpleBundleResolver::class, + self::assertInstanceOf( + SimpleBundleResolver::class, $container->get('hautelook_alice.resolver.bundle.simple_resolver') ); - $this->assertInstanceOf( - \Hautelook\AliceBundle\Resolver\Bundle\NoBundleResolver::class, + self::assertInstanceOf( + NoBundleResolver::class, $container->get('hautelook_alice.resolver.bundle.no_bundle_resolver') ); - $this->assertInstanceOf( - \Hautelook\AliceBundle\BundleResolverInterface::class, + self::assertInstanceOf( + BundleResolverInterface::class, $container->get('hautelook_alice.resolver.bundle') ); // Locators - $this->assertInstanceOf( - \Hautelook\AliceBundle\Locator\EnvironmentlessFilesLocator::class, + self::assertInstanceOf( + EnvironmentlessFilesLocator::class, $container->get('hautelook_alice.locator.environmentless') ); - $this->assertInstanceOf( - \Hautelook\AliceBundle\Locator\EnvDirectoryLocator::class, + self::assertInstanceOf( + EnvDirectoryLocator::class, $container->get('hautelook_alice.locator.env_directory') ); - $this->assertInstanceOf( - \Hautelook\AliceBundle\FixtureLocatorInterface::class, + self::assertInstanceOf( + FixtureLocatorInterface::class, $container->get('hautelook_alice.locator') ); // Loader - $this->assertInstanceOf( - \Fidry\AliceDataFixtures\Loader\FileResolverLoader::class, + self::assertInstanceOf( + FileResolverLoader::class, $container->get('hautelook_alice.data_fixtures.loader.file_resolver_loader') ); - $this->assertInstanceOf( - \Fidry\AliceDataFixtures\LoaderInterface::class, + self::assertInstanceOf( + LoaderInterface::class, $container->get('hautelook_alice.data_fixtures.purge_loader') ); - $this->assertInstanceOf( - \Fidry\AliceDataFixtures\LoaderInterface::class, + self::assertInstanceOf( + LoaderInterface::class, $container->get('hautelook_alice.data_fixtures.append_loader') ); - $this->assertInstanceOf( - \Hautelook\AliceBundle\Loader\DoctrineOrmLoader::class, + self::assertInstanceOf( + DoctrineOrmLoader::class, $container->get('hautelook_alice.loader.doctrine_orm_loader') ); - $this->assertInstanceOf( - \Hautelook\AliceBundle\LoaderInterface::class, + self::assertInstanceOf( + HautelookLoaderInterface::class, $container->get('hautelook_alice.loader') ); // Commands - $this->assertInstanceOf( - \Hautelook\AliceBundle\Console\Command\Doctrine\DoctrineOrmLoadDataFixturesCommand::class, + self::assertInstanceOf( + DoctrineOrmLoadDataFixturesCommand::class, $container->get('hautelook_alice.console.command.doctrine.doctrine_orm_load_data_fixtures_command') ); } - /** - * {@inheritdoc} - */ protected static function getKernelClass(): string { return AppKernel::class; diff --git a/tests/Loader/DoctrineOrmLoaderTest.php b/tests/Loader/DoctrineOrmLoaderTest.php index ca601854..df976f42 100644 --- a/tests/Loader/DoctrineOrmLoaderTest.php +++ b/tests/Loader/DoctrineOrmLoaderTest.php @@ -19,6 +19,8 @@ use Hautelook\AliceBundle\Logger\FakeLogger; use Hautelook\AliceBundle\LoggerAwareInterface; use Hautelook\AliceBundle\Resolver\FakeBundleResolver; +use InvalidArgumentException; +use function is_a; use PHPUnit\Framework\TestCase; use ReflectionClass; @@ -27,26 +29,32 @@ */ class DoctrineOrmLoaderTest extends TestCase { - public function testIsALoader() + public function testIsALoader(): void { - $this->assertTrue(is_a(DoctrineOrmLoader::class, LoaderInterface::class, true)); + self::assertTrue(is_a(DoctrineOrmLoader::class, LoaderInterface::class, true)); } - public function testIsLoggerAware() + public function testIsLoggerAware(): void { - $this->assertTrue(is_a(DoctrineOrmLoader::class, LoggerAwareInterface::class, true)); + self::assertTrue(is_a(DoctrineOrmLoader::class, LoggerAwareInterface::class, true)); } - public function testIsNotClonable() + public function testIsNotClonable(): void { - $this->assertFalse((new ReflectionClass(DoctrineOrmLoader::class))->isCloneable()); + self::assertFalse((new ReflectionClass(DoctrineOrmLoader::class))->isCloneable()); } - public function testDataFixtureLoaderMustBePersisterAware() + public function testDataFixtureLoaderMustBePersisterAware(): void { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Expected loader to be an instance of "Fidry\AliceDataFixtures\Persistence\PersisterAwareInterface".'); - new DoctrineOrmLoader(new FakeBundleResolver(), new FakeFixtureLocator(), new FakeLoader(), new FakeLoader(), new FakeLogger()); + new DoctrineOrmLoader( + new FakeBundleResolver(), + new FakeFixtureLocator(), + new FakeLoader(), + new FakeLoader(), + new FakeLogger(), + ); } } diff --git a/tests/Locator/EnvDirectoryLocatorTest.php b/tests/Locator/EnvDirectoryLocatorTest.php index f5123bb0..d85c66b4 100644 --- a/tests/Locator/EnvDirectoryLocatorTest.php +++ b/tests/Locator/EnvDirectoryLocatorTest.php @@ -13,12 +13,14 @@ namespace Hautelook\AliceBundle\Locator; +use const DIRECTORY_SEPARATOR; use Hautelook\AliceBundle\FixtureLocatorInterface; use Hautelook\AliceBundle\Locator\EnvDirectoryLocator\AnotherDummyBundle\AnotherDummyBundle; use Hautelook\AliceBundle\Locator\EnvDirectoryLocator\DummyBundle\DummyBundle; use Hautelook\AliceBundle\Locator\EnvDirectoryLocator\EmptyBundle\EmptyBundle; use Hautelook\AliceBundle\Locator\EnvDirectoryLocator\OneMoreDummyBundle\OneMoreDummyBundle; use PHPUnit\Framework\TestCase; +use function realpath; use ReflectionClass; /** @@ -26,29 +28,29 @@ */ class EnvDirectoryLocatorTest extends TestCase { - public function testIsAFixtureLocator() + public function testIsAFixtureLocator(): void { - $this->assertTrue(is_a(EnvDirectoryLocator::class, FixtureLocatorInterface::class, true)); + self::assertTrue(is_a(EnvDirectoryLocator::class, FixtureLocatorInterface::class, true)); } - public function testIsNotClonable() + public function testIsNotClonable(): void { - $this->assertFalse((new ReflectionClass(EnvDirectoryLocator::class))->isCloneable()); + self::assertFalse((new ReflectionClass(EnvDirectoryLocator::class))->isCloneable()); } /** * @dataProvider provideSets */ - public function testGetFilesFromABundle(array $bundles, string $environment, array $paths, array $expected) + public function testGetFilesFromABundle(array $bundles, string $environment, array $paths, array $expected): void { $invalidPath = ''; $locator = new EnvDirectoryLocator($paths, [$invalidPath]); $actual = $locator->locateFiles($bundles, $environment); - $this->assertEqualsCanonicalizing($expected, $actual); + self::assertEqualsCanonicalizing($expected, $actual); } - public function provideSets() + public function provideSets(): ?\Generator { yield 'bundle without any resources' => [ [new EmptyBundle()], @@ -126,7 +128,9 @@ public function provideSets() 'dev', ['resources'], [ - realpath(__DIR__.'/../../fixtures/Locator/EnvDirectoryLocator/AnotherDummyBundle/resources/dev/file10.yml'), + realpath( + __DIR__.'/../../fixtures/Locator/EnvDirectoryLocator/AnotherDummyBundle/resources/dev/file10.yaml' + ), ], ]; @@ -146,26 +150,26 @@ public function testGetFilesFromSeveralBundles( string $environment, array $paths, array $expected - ) { + ): void { $invalidPath = ''; $locator = new EnvDirectoryLocator($paths, [$invalidPath]); $actual = $locator->locateFiles($bundles, $environment); - $this->assertEqualsCanonicalizing($expected, $actual); + self::assertEqualsCanonicalizing($expected, $actual); } - public function provideSetsForSeveralBundles() + public function provideSetsForSeveralBundles(): ?\Generator { - $baseDir = 'Resources'.\DIRECTORY_SEPARATOR.'fixtures'; - $baseDir2 = 'Resources'.\DIRECTORY_SEPARATOR.'fixtures2'; + $baseDir = 'Resources'.DIRECTORY_SEPARATOR.'fixtures'; + $baseDir2 = 'Resources'.DIRECTORY_SEPARATOR.'fixtures2'; $env = 'test'; $bundleA = new DummyBundle(); $bundleB = new OneMoreDummyBundle(); - $prefixA1 = $bundleA->getPath().\DIRECTORY_SEPARATOR.$baseDir.\DIRECTORY_SEPARATOR.$env.\DIRECTORY_SEPARATOR; - $prefixA2 = $bundleA->getPath().\DIRECTORY_SEPARATOR.$baseDir2.\DIRECTORY_SEPARATOR.$env.\DIRECTORY_SEPARATOR; - $prefixB = $bundleB->getPath().\DIRECTORY_SEPARATOR.$baseDir.\DIRECTORY_SEPARATOR.$env.\DIRECTORY_SEPARATOR; + $prefixA1 = $bundleA->getPath().DIRECTORY_SEPARATOR.$baseDir.DIRECTORY_SEPARATOR.$env.DIRECTORY_SEPARATOR; + $prefixA2 = $bundleA->getPath().DIRECTORY_SEPARATOR.$baseDir2.DIRECTORY_SEPARATOR.$env.DIRECTORY_SEPARATOR; + $prefixB = $bundleB->getPath().DIRECTORY_SEPARATOR.$baseDir.DIRECTORY_SEPARATOR.$env.DIRECTORY_SEPARATOR; yield 'several bundles with fixture files' => [ [$bundleA, $bundleB], @@ -186,11 +190,11 @@ public function provideSetsForSeveralBundles() ]; } - public function testGetFilesFromProjectDir() + public function testGetFilesFromProjectDir(): void { $basePath = realpath(__DIR__.'/../..'); $locator = new EnvDirectoryLocator(['fixtures/fixture_files'], [$basePath]); - $this->assertSame([$basePath.'/fixtures/fixture_files/city.yml'], $locator->locateFiles([], '')); + self::assertSame([$basePath.'/fixtures/fixture_files/city.yaml'], $locator->locateFiles([], '')); } } diff --git a/tests/Locator/EnvironmentlessFilesLocatorTest.php b/tests/Locator/EnvironmentlessFilesLocatorTest.php index 90db2519..3901fcc3 100644 --- a/tests/Locator/EnvironmentlessFilesLocatorTest.php +++ b/tests/Locator/EnvironmentlessFilesLocatorTest.php @@ -14,6 +14,7 @@ namespace Hautelook\AliceBundle\Locator; use Hautelook\AliceBundle\FixtureLocatorInterface; +use function is_a; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; @@ -27,22 +28,22 @@ class EnvironmentlessFilesLocatorTest extends TestCase { use ProphecyTrait; - public function testIsAFixtureLocator() + public function testIsAFixtureLocator(): void { - $this->assertTrue(is_a(EnvironmentlessFilesLocator::class, FixtureLocatorInterface::class, true)); + self::assertTrue(is_a(EnvironmentlessFilesLocator::class, FixtureLocatorInterface::class, true)); } - public function testIsNotClonable() + public function testIsNotClonable(): void { - $this->assertFalse((new ReflectionClass(EnvironmentlessFilesLocator::class))->isCloneable()); + self::assertFalse((new ReflectionClass(EnvironmentlessFilesLocator::class))->isCloneable()); } - public function testConcateneAllLocatorFiles() + public function testConcateneAllLocatorFiles(): void { $bundles = ['ABdundle', 'BBundle']; $env = 'dev'; - /** @var FixtureLocatorInterface|ObjectProphecy $decoratedLocatorProphecy */ + /** @var ObjectProphecy $decoratedLocatorProphecy */ $decoratedLocatorProphecy = $this->prophesize(FixtureLocatorInterface::class); $decoratedLocatorProphecy ->locateFiles($bundles, $env) @@ -64,7 +65,7 @@ public function testConcateneAllLocatorFiles() $locator = new EnvironmentlessFilesLocator($decoratedLocator); $actual = $locator->locateFiles($bundles, $env); - $this->assertEquals($expected, $actual); + self::assertEquals($expected, $actual); $decoratedLocatorProphecy->locateFiles(Argument::cetera())->shouldHaveBeenCalledTimes(2); } diff --git a/tests/PhpUnit/RefreshTestTrait.php b/tests/PhpUnit/RefreshTestTrait.php index 39173d24..d1f83c3e 100644 --- a/tests/PhpUnit/RefreshTestTrait.php +++ b/tests/PhpUnit/RefreshTestTrait.php @@ -22,10 +22,10 @@ */ trait RefreshTestTrait { - public function testRefresh() + public function testRefresh(): void { $manager = $this->getManager(); - $this->assertInitialState($manager); + self::assertInitialState($manager); $newBrand = new Brand(); $newBrand->setName('Les-Tilleuls.coop'); @@ -33,12 +33,12 @@ public function testRefresh() $manager->flush(); $brands = $manager->getRepository(Brand::class)->findAll(); - $this->assertCount(11, $brands); + self::assertCount(11, $brands); } - public function testShouldBeRefreshed() + public function testShouldBeRefreshed(): void { - $this->assertInitialState($this->getManager()); + self::assertInitialState($this->getManager()); } protected static function getKernelClass(): string @@ -57,6 +57,6 @@ private function getManager(): EntityManager private function assertInitialState(EntityManager $manager): void { $brands = $manager->getRepository(Brand::class)->findAll(); - $this->assertCount(10, $brands); + self::assertCount(10, $brands); } } diff --git a/tests/Resolver/Bundle/NoBundleResolverTest.php b/tests/Resolver/Bundle/NoBundleResolverTest.php index 20ee0d7d..0a10411c 100644 --- a/tests/Resolver/Bundle/NoBundleResolverTest.php +++ b/tests/Resolver/Bundle/NoBundleResolverTest.php @@ -16,6 +16,7 @@ use Hautelook\AliceBundle\BundleResolverInterface; use Hautelook\AliceBundle\Resolver\FakeBundleResolver; use Hautelook\AliceBundle\Resolver\ResolverKernel; +use function is_a; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; @@ -29,17 +30,17 @@ class NoBundleResolverTest extends TestCase { use ProphecyTrait; - public function testIsABundleResolver() + public function testIsABundleResolver(): void { - $this->assertTrue(is_a(NoBundleResolver::class, BundleResolverInterface::class, true)); + self::assertTrue(is_a(NoBundleResolver::class, BundleResolverInterface::class, true)); } - public function testIsNotClonable() + public function testIsNotClonable(): void { - $this->assertFalse((new ReflectionClass(NoBundleResolver::class))->isCloneable()); + self::assertFalse((new ReflectionClass(NoBundleResolver::class))->isCloneable()); } - public function testReturnsAllBundlesIfNoBundleIsRequested() + public function testReturnsAllBundlesIfNoBundleIsRequested(): void { $kernel = new ResolverKernel(__FUNCTION__, true); $kernel->boot(); @@ -47,7 +48,7 @@ public function testReturnsAllBundlesIfNoBundleIsRequested() $resolver = new NoBundleResolver(new FakeBundleResolver()); $result = $resolver->resolveBundles($application, []); - $this->assertSame( + self::assertSame( [ $kernel->getBundle('ABundle'), $kernel->getBundle('BBundle'), @@ -58,7 +59,7 @@ public function testReturnsAllBundlesIfNoBundleIsRequested() $kernel->shutdown(); } - public function testReturnsTheDecoratedResolverResultIfABundleIsRequested() + public function testReturnsTheDecoratedResolverResultIfABundleIsRequested(): void { $kernel = new ResolverKernel(__FUNCTION__, true); $application = new Application($kernel); @@ -72,7 +73,7 @@ public function testReturnsTheDecoratedResolverResultIfABundleIsRequested() $resolver = new NoBundleResolver($decoratedResolver); $actual = $resolver->resolveBundles($application, $bundles); - $this->assertSame($expected, $actual); + self::assertSame($expected, $actual); $decoratedResolverProphecy->resolveBundles(Argument::cetera())->shouldHaveBeenCalledTimes(1); } diff --git a/tests/Resolver/Bundle/SimpleBundleResolverTest.php b/tests/Resolver/Bundle/SimpleBundleResolverTest.php index c7abd81b..b1e5e0aa 100644 --- a/tests/Resolver/Bundle/SimpleBundleResolverTest.php +++ b/tests/Resolver/Bundle/SimpleBundleResolverTest.php @@ -15,6 +15,7 @@ use Hautelook\AliceBundle\BundleResolverInterface; use Hautelook\AliceBundle\Resolver\ResolverKernel; +use function is_a; use PHPUnit\Framework\TestCase; use ReflectionClass; use Symfony\Bundle\FrameworkBundle\Console\Application; @@ -24,17 +25,17 @@ */ class SimpleBundleResolverTest extends TestCase { - public function testIsABundleResolver() + public function testIsABundleResolver(): void { - $this->assertTrue(is_a(SimpleBundleResolver::class, BundleResolverInterface::class, true)); + self::assertTrue(is_a(SimpleBundleResolver::class, BundleResolverInterface::class, true)); } - public function testIsNotClonable() + public function testIsNotClonable(): void { - $this->assertFalse((new ReflectionClass(SimpleBundleResolver::class))->isCloneable()); + self::assertFalse((new ReflectionClass(SimpleBundleResolver::class))->isCloneable()); } - public function testCanResolveBundles() + public function testCanResolveBundles(): void { $kernel = new ResolverKernel(__FUNCTION__, true); $kernel->boot(); @@ -42,7 +43,7 @@ public function testCanResolveBundles() $resolver = new SimpleBundleResolver(); $result = $resolver->resolveBundles($application, ['ABundle']); - $this->assertSame( + self::assertSame( [ $kernel->getBundle('ABundle'), ], @@ -52,7 +53,7 @@ public function testCanResolveBundles() $kernel->shutdown(); } - public function testThrowsAnExceptionWhenBundleCoudlNotBeFound() + public function testThrowsAnExceptionWhenBundleCoudlNotBeFound(): void { $this->expectException(\Hautelook\AliceBundle\Exception\Resolver\BundleNotFoundException::class); $this->expectExceptionMessage('The bundle "UnknownBundle" was not found. Bundles available are: ["ABundle", "BBundle"].'); diff --git a/tests/Resolver/File/KernelFileResolverTest.php b/tests/Resolver/File/KernelFileResolverTest.php index e5a958e9..148d70e4 100644 --- a/tests/Resolver/File/KernelFileResolverTest.php +++ b/tests/Resolver/File/KernelFileResolverTest.php @@ -16,10 +16,14 @@ use Fidry\AliceDataFixtures\FileResolverInterface; use Hautelook\AliceBundle\Functional\SimpleKernel; use Hautelook\AliceBundle\HttpKernel\DummyKernel; +use InvalidArgumentException; +use function is_a; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; +use function realpath; use ReflectionClass; use Symfony\Component\HttpKernel\KernelInterface; +use TypeError; /** * @covers \Hautelook\AliceBundle\Resolver\File\KernelFileResolver @@ -28,32 +32,26 @@ class KernelFileResolverTest extends TestCase { use ProphecyTrait; - /** - * @var KernelInterface|null - */ - protected $kernel; + protected KernelInterface $kernel; - /** - * {@inheritdoc} - */ protected function tearDown(): void { - if (null !== $this->kernel) { + if (isset($this->kernel)) { $this->kernel->shutdown(); } } - public function testIsAFileResolver() + public function testIsAFileResolver(): void { - $this->assertTrue(is_a(KernelFileResolver::class, FileResolverInterface::class, true)); + self::assertTrue(is_a(KernelFileResolver::class, FileResolverInterface::class, true)); } - public function testIsNotClonable() + public function testIsNotClonable(): void { - $this->assertFalse((new ReflectionClass(KernelFileResolver::class))->isCloneable()); + self::assertFalse((new ReflectionClass(KernelFileResolver::class))->isCloneable()); } - public function testReturnResolvedFiles() + public function testReturnResolvedFiles(): void { $files = $expected = [ __FILE__, @@ -62,38 +60,38 @@ public function testReturnResolvedFiles() $resolver = new KernelFileResolver(new DummyKernel()); $actual = $resolver->resolve($files); - $this->assertSame($expected, $actual); + self::assertSame($expected, $actual); } - public function testThrowsAnErrorIfOneOfTheFilePathGivenIsNotAString() + public function testThrowsAnErrorIfOneOfTheFilePathGivenIsNotAString(): void { - $this->expectException(\TypeError::class); + $this->expectException(TypeError::class); $resolver = new KernelFileResolver(new DummyKernel()); $resolver->resolve([true]); } - public function testThrowsAnExceptionIfFileDoesNotExist() + public function testThrowsAnExceptionIfFileDoesNotExist(): void { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('The file "unknown" was not found.'); $resolver = new KernelFileResolver(new DummyKernel()); $resolver->resolve(['unknown']); } - public function testThrowsAnExceptionIfFileIsADirectory() + public function testThrowsAnExceptionIfFileIsADirectory(): void { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessageMatches('/^Expected "\/.*?\/tests\/Resolver\/File" to be a fixture file, got a directory instead\.$/'); $resolver = new KernelFileResolver(new DummyKernel()); $resolver->resolve([__DIR__]); } - public function testThrowsAnExceptionIfFileResolvedByTheKernelDoesNotExist() + public function testThrowsAnExceptionIfFileResolvedByTheKernelDoesNotExist(): void { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $files = [ '@SimpleBundle/dummy.yml', @@ -106,9 +104,9 @@ public function testThrowsAnExceptionIfFileResolvedByTheKernelDoesNotExist() $resolver->resolve($files); } - public function testThrowsAnExceptionIfFileResolvedByTheKernelIsADirectory() + public function testThrowsAnExceptionIfFileResolvedByTheKernelIsADirectory(): void { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Expected "@SimpleBundle/files" to be a fixture file, got a directory instead.'); $files = [ @@ -122,11 +120,11 @@ public function testThrowsAnExceptionIfFileResolvedByTheKernelIsADirectory() $resolver->resolve($files); } - public function testAbsoluteFilePathAreReturnedAndDuplicatesAreRemoved() + public function testAbsoluteFilePathAreReturnedAndDuplicatesAreRemoved(): void { $files = [ - '@SimpleBundle/files/foo.yml', - '@SimpleBundle/files/bar.yml', + '@SimpleBundle/files/foo.yaml', + '@SimpleBundle/files/bar.yaml', __FILE__, __DIR__.'/../File/KernelFileResolverTest.php', ]; @@ -135,14 +133,14 @@ public function testAbsoluteFilePathAreReturnedAndDuplicatesAreRemoved() $this->kernel->boot(); $expected = [ - realpath(__DIR__.'/../../../fixtures/Functional/SimpleBundle/files/foo.yml'), - realpath(__DIR__.'/../../../fixtures/Functional/SimpleBundle/files/bar.yml'), + realpath(__DIR__.'/../../../fixtures/Functional/SimpleBundle/files/foo.yaml'), + realpath(__DIR__.'/../../../fixtures/Functional/SimpleBundle/files/bar.yaml'), __FILE__, ]; $resolver = new KernelFileResolver($this->kernel); $actual = $resolver->resolve($files); - $this->assertSame($expected, $actual); + self::assertSame($expected, $actual); } }