From f45fe5458c4f24e127fb34c8ba2f124fc46dafc3 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 23 Oct 2019 20:07:04 +0200 Subject: [PATCH 1/9] Make dev-master 1.4.x-dev --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 66d6738b..01b804b9 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.3.x-dev" + "dev-master": "1.4.x-dev" } }, "autoload": { From 413f040de3c6542625a3a70ddcf2b466c0c2723e Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 23 Oct 2019 20:07:14 +0200 Subject: [PATCH 2/9] Add website configuration --- .doctrine-project.json | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .doctrine-project.json diff --git a/.doctrine-project.json b/.doctrine-project.json new file mode 100644 index 00000000..06747ffa --- /dev/null +++ b/.doctrine-project.json @@ -0,0 +1,24 @@ +{ + "active": true, + "name": "Data fixtures", + "slug": "data-fixtures", + "docsSlug": "doctrine-data-fixtures", + "versions": [ + { + "name": "1.4", + "branchName": "master", + "slug": "latest", + "upcoming": true + }, + { + "name": "1.3", + "branchName": "1.3", + "slug": "1.3", + "current": true, + "aliases": [ + "current", + "stable" + ] + } + ] +} From 47e31e0a70102ccaec2284f6234f152ff5af0c3a Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 23 Oct 2019 20:09:01 +0200 Subject: [PATCH 3/9] Drop support for PHP 7.1 --- .travis.yml | 1 - composer.json | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 79cf9b35..c3b9fb15 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,6 @@ cache: - $HOME/.composer/cache php: - - 7.1 - 7.2 - 7.3 diff --git a/composer.json b/composer.json index 01b804b9..125a50f4 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ } ], "require": { - "php": "^7.1", + "php": "^7.2", "doctrine/common": "~2.2" }, "conflict": { From 7984b9109670cae5c5bf250f417da5bb90d9b765 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 23 Oct 2019 20:15:25 +0200 Subject: [PATCH 4/9] Test against PHP 7.4 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index c3b9fb15..fc42c19f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ cache: php: - 7.2 - 7.3 + - 7.4snapshot services: mongodb From 4d4203080bdbba57d27b1dfaa2c69cdf43f98c89 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 23 Oct 2019 20:24:07 +0200 Subject: [PATCH 5/9] Add test against lowest dependencies --- .travis.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index fc42c19f..58926226 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,8 +17,14 @@ before_install: - pecl install -f mongodb - composer validate --strict -before_script: - - composer install +install: + - composer update --prefer-stable --prefer-dist ${COMPOSER_FLAGS} script: - ./vendor/bin/phpunit -v + +jobs: + include: + # Tests the lowest set of dependencies + - php: 7.2 + env: LOWEST COMPOSER_FLAGS="--prefer-lowest" From 2be96f2f658a268b4a24528470df9ac0b093c27b Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 23 Oct 2019 20:18:43 +0200 Subject: [PATCH 6/9] Introduce doctrine/coding-standard and apply fixes --- .gitignore | 1 + .travis.yml | 6 + composer.json | 1 + .../Common/DataFixtures/AbstractFixture.php | 50 ++-- .../DependentFixtureInterface.php | 56 ++--- .../Listener/MongoDBReferenceListener.php | 34 ++- .../Event/Listener/ORMReferenceListener.php | 35 ++- .../Exception/CircularReferenceException.php | 20 +- .../Executor/AbstractExecutor.php | 26 +- .../DataFixtures/Executor/MongoDBExecutor.php | 14 +- .../DataFixtures/Executor/ORMExecutor.php | 22 +- .../DataFixtures/Executor/PHPCRExecutor.php | 25 +- .../Common/DataFixtures/FixtureInterface.php | 6 +- lib/Doctrine/Common/DataFixtures/Loader.php | 229 +++++++++++------- .../DataFixtures/OrderedFixtureInterface.php | 13 +- .../DataFixtures/ProxyReferenceRepository.php | 28 ++- .../DataFixtures/Purger/MongoDBPurger.php | 18 +- .../Common/DataFixtures/Purger/ORMPurger.php | 134 +++++----- .../DataFixtures/Purger/PHPCRPurger.php | 10 +- .../DataFixtures/Purger/PurgerInterface.php | 6 +- .../DataFixtures/ReferenceRepository.php | 57 +++-- .../DataFixtures/SharedFixtureInterface.php | 15 +- .../DataFixtures/Sorter/TopologicalSorter.php | 37 ++- .../Common/DataFixtures/Sorter/Vertex.php | 25 +- phpcs.xml.dist | 50 ++++ .../Tests/Common/DataFixtures/BaseTest.php | 11 +- .../DataFixtures/DependentFixtureTest.php | 145 ++++++----- .../Executor/ORMExecutorSharedFixtureTest.php | 29 +-- .../DataFixtures/Executor/ORMExecutorTest.php | 16 +- .../Executor/PHPCRExecutorTest.php | 25 +- .../Tests/Common/DataFixtures/FixtureTest.php | 7 +- .../Tests/Common/DataFixtures/LoaderTest.php | 14 +- .../DataFixtures/OrderedFixtureTest.php | 26 +- .../ProxyReferenceRepositoryTest.php | 37 ++- .../DataFixtures/Purger/MongoDBPurgerTest.php | 17 +- .../Purger/ORMPurgerExcludeTest.php | 48 ++-- .../DataFixtures/Purger/ORMPurgerTest.php | 40 ++- .../DataFixtures/ReferenceRepositoryTest.php | 57 ++--- .../Sorter/TopologicalSorterTest.php | 6 +- .../Common/DataFixtures/Sorter/VertexTest.php | 3 +- .../Common/DataFixtures/TestDocument/Role.php | 6 + .../Common/DataFixtures/TestEntity/Quoted.php | 67 ++++- .../Common/DataFixtures/TestEntity/Role.php | 20 +- .../Common/DataFixtures/TestEntity/User.php | 72 ++++-- .../TestEntity/UserWithSchema.php | 78 ++++-- .../DataFixtures/TestFixtures/MyFixture1.php | 2 + .../DataFixtures/TestFixtures/MyFixture2.php | 2 + .../DataFixtures/TestFixtures/NotAFixture.php | 4 +- .../DataFixtures/TestFixtures/RoleFixture.php | 7 +- .../DataFixtures/TestFixtures/UserFixture.php | 7 +- .../TestPurgeEntity/ExcludedEntity.php | 26 +- .../TestPurgeEntity/IncludedEntity.php | 26 +- tests/Doctrine/Tests/Mock/Node.php | 9 +- 53 files changed, 991 insertions(+), 734 deletions(-) create mode 100644 phpcs.xml.dist diff --git a/.gitignore b/.gitignore index f1a8d7d0..b1f7b92a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ phpunit.xml vendor/ +.phpcs-cache composer.lock diff --git a/.travis.yml b/.travis.yml index 58926226..b60a7fed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,3 +28,9 @@ jobs: # Tests the lowest set of dependencies - php: 7.2 env: LOWEST COMPOSER_FLAGS="--prefer-lowest" + + - stage: Code Quality + env: CODING_STANDARDS + php: 7.2 + script: + - ./vendor/bin/phpcs diff --git a/composer.json b/composer.json index 125a50f4..6d3ec1fc 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,7 @@ }, "require-dev": { "alcaeus/mongo-php-adapter": "^1.1", + "doctrine/coding-standard": "^6.0", "doctrine/dbal": "^2.5.4", "doctrine/mongodb-odm": "^1.3.0", "doctrine/orm": "^2.5.4", diff --git a/lib/Doctrine/Common/DataFixtures/AbstractFixture.php b/lib/Doctrine/Common/DataFixtures/AbstractFixture.php index 7edb131e..732c4ca4 100644 --- a/lib/Doctrine/Common/DataFixtures/AbstractFixture.php +++ b/lib/Doctrine/Common/DataFixtures/AbstractFixture.php @@ -1,25 +1,25 @@ */ abstract class AbstractFixture implements SharedFixtureInterface { /** * Fixture reference repository - * + * * @var ReferenceRepository */ protected $referenceRepository; - + /** * {@inheritdoc} */ @@ -27,60 +27,68 @@ public function setReferenceRepository(ReferenceRepository $referenceRepository) { $this->referenceRepository = $referenceRepository; } - + /** * Set the reference entry identified by $name * and referenced to managed $object. If $name * already is set, it overrides it - * + * + * @see Doctrine\Common\DataFixtures\ReferenceRepository::setReference + * * @param string $name * @param object $object - managed object - * @see Doctrine\Common\DataFixtures\ReferenceRepository::setReference + * * @return void */ public function setReference($name, $object) { $this->referenceRepository->setReference($name, $object); } - + /** * Set the reference entry identified by $name * and referenced to managed $object. If $name - * already is set, it throws a + * already is set, it throws a * BadMethodCallException exception - * + * + * @see Doctrine\Common\DataFixtures\ReferenceRepository::addReference + * * @param string $name * @param object $object - managed object - * @see Doctrine\Common\DataFixtures\ReferenceRepository::addReference - * @throws \BadMethodCallException - if repository already has - * a reference by $name + * * @return void + * + * @throws BadMethodCallException - if repository already has a reference by $name. */ public function addReference($name, $object) { $this->referenceRepository->addReference($name, $object); } - + /** * Loads an object using stored reference * named by $name - * - * @param string $name + * * @see Doctrine\Common\DataFixtures\ReferenceRepository::getReference + * + * @param string $name + * * @return object */ public function getReference($name) { return $this->referenceRepository->getReference($name); } - + /** * Check if an object is stored using reference * named by $name - * - * @param string $name + * * @see Doctrine\Common\DataFixtures\ReferenceRepository::hasReference - * @return boolean + * + * @param string $name + * + * @return bool */ public function hasReference($name) { diff --git a/lib/Doctrine/Common/DataFixtures/DependentFixtureInterface.php b/lib/Doctrine/Common/DataFixtures/DependentFixtureInterface.php index 4caa1222..5cac4501 100644 --- a/lib/Doctrine/Common/DataFixtures/DependentFixtureInterface.php +++ b/lib/Doctrine/Common/DataFixtures/DependentFixtureInterface.php @@ -1,37 +1,19 @@ -. - */ - -namespace Doctrine\Common\DataFixtures; - -/** - * DependentFixtureInterface needs to be implemented - * by fixtures which depend on other fixtures - * - * @author Gustavo Adrian - */ -interface DependentFixtureInterface -{ - /** - * This method must return an array of fixtures classes - * on which the implementing class depends on - * - * @return array - */ - public function getDependencies(); -} + */ final class MongoDBReferenceListener implements EventSubscriber { - /** - * @var ReferenceRepository - */ + /** @var ReferenceRepository */ private $referenceRepository; /** * Initialize listener - * - * @param ReferenceRepository $referenceRepository */ public function __construct(ReferenceRepository $referenceRepository) { @@ -35,28 +30,27 @@ public function __construct(ReferenceRepository $referenceRepository) */ public function getSubscribedEvents() { - return [ - 'postPersist' - ]; + return ['postPersist']; } /** * Populates identities for stored references - * - * @param LifecycleEventArgs $args */ public function postPersist(LifecycleEventArgs $args) { $object = $args->getDocument(); - if (($names = $this->referenceRepository->getReferenceNames($object)) !== false) { - foreach ($names as $name) { - $identity = $args->getDocumentManager() - ->getUnitOfWork() - ->getDocumentIdentifier($object); + $names = $this->referenceRepository->getReferenceNames($object); + if ($names === false) { + return; + } + + foreach ($names as $name) { + $identity = $args->getDocumentManager() + ->getUnitOfWork() + ->getDocumentIdentifier($object); - $this->referenceRepository->setReferenceIdentity($name, $identity); - } + $this->referenceRepository->setReferenceIdentity($name, $identity); } } } diff --git a/lib/Doctrine/Common/DataFixtures/Event/Listener/ORMReferenceListener.php b/lib/Doctrine/Common/DataFixtures/Event/Listener/ORMReferenceListener.php index fb9327d2..ba43e377 100644 --- a/lib/Doctrine/Common/DataFixtures/Event/Listener/ORMReferenceListener.php +++ b/lib/Doctrine/Common/DataFixtures/Event/Listener/ORMReferenceListener.php @@ -1,29 +1,24 @@ */ final class ORMReferenceListener implements EventSubscriber { - /** - * @var ReferenceRepository - */ + /** @var ReferenceRepository */ private $referenceRepository; /** * Initialize listener - * - * @param ReferenceRepository $referenceRepository */ public function __construct(ReferenceRepository $referenceRepository) { @@ -35,28 +30,28 @@ public function __construct(ReferenceRepository $referenceRepository) */ public function getSubscribedEvents() { - return [ - 'postPersist' // would be better to use onClear, but it is supported only in 2.1 - ]; + // would be better to use onClear, but it is supported only in 2.1 + return ['postPersist']; } /** * Populates identities for stored references - * - * @param LifecycleEventArgs $args */ public function postPersist(LifecycleEventArgs $args) { $object = $args->getEntity(); - if (($names = $this->referenceRepository->getReferenceNames($object)) !== false) { - foreach ($names as $name) { - $identity = $args->getEntityManager() - ->getUnitOfWork() - ->getEntityIdentifier($object); + $names = $this->referenceRepository->getReferenceNames($object); + if ($names === false) { + return; + } + + foreach ($names as $name) { + $identity = $args->getEntityManager() + ->getUnitOfWork() + ->getEntityIdentifier($object); - $this->referenceRepository->setReferenceIdentity($name, $identity); - } + $this->referenceRepository->setReferenceIdentity($name, $identity); } } } diff --git a/lib/Doctrine/Common/DataFixtures/Exception/CircularReferenceException.php b/lib/Doctrine/Common/DataFixtures/Exception/CircularReferenceException.php index 8e4caedd..005df34a 100644 --- a/lib/Doctrine/Common/DataFixtures/Exception/CircularReferenceException.php +++ b/lib/Doctrine/Common/DataFixtures/Exception/CircularReferenceException.php @@ -1,9 +1,11 @@ - */ abstract class AbstractExecutor { @@ -57,8 +60,6 @@ public function setReferenceRepository(ReferenceRepository $referenceRepository) /** * Sets the Purger instance to use for this executor instance. - * - * @param PurgerInterface $purger */ public function setPurger(PurgerInterface $purger) { @@ -96,16 +97,13 @@ public function log($message) /** * Load a fixture with the given persistence manager. - * - * @param ObjectManager $manager - * @param FixtureInterface $fixture */ public function load(ObjectManager $manager, FixtureInterface $fixture) { if ($this->logger) { $prefix = ''; if ($fixture instanceof OrderedFixtureInterface) { - $prefix = sprintf('[%d] ',$fixture->getOrder()); + $prefix = sprintf('[%d] ', $fixture->getOrder()); } $this->log('loading ' . $prefix . get_class($fixture)); } @@ -120,12 +118,12 @@ public function load(ObjectManager $manager, FixtureInterface $fixture) /** * Purges the database before loading. * - * @throws \Exception if the purger is not defined + * @throws Exception if the purger is not defined. */ public function purge() { if ($this->purger === null) { - throw new \Exception('Doctrine\Common\DataFixtures\Purger\PurgerInterface instance is required if you want to purge the database before loading your data fixtures.'); + throw new Exception('Doctrine\Common\DataFixtures\Purger\PurgerInterface instance is required if you want to purge the database before loading your data fixtures.'); } if ($this->logger) { $this->log('purging database'); @@ -136,8 +134,8 @@ public function purge() /** * Executes the given array of data fixtures. * - * @param array $fixtures Array of fixtures to execute. - * @param boolean $append Whether to append the data fixtures or purge the database before loading. + * @param array $fixtures Array of fixtures to execute. + * @param bool $append Whether to append the data fixtures or purge the database before loading. */ abstract public function execute(array $fixtures, $append = false); } diff --git a/lib/Doctrine/Common/DataFixtures/Executor/MongoDBExecutor.php b/lib/Doctrine/Common/DataFixtures/Executor/MongoDBExecutor.php index daf10782..b0fe7077 100644 --- a/lib/Doctrine/Common/DataFixtures/Executor/MongoDBExecutor.php +++ b/lib/Doctrine/Common/DataFixtures/Executor/MongoDBExecutor.php @@ -1,16 +1,16 @@ */ class MongoDBExecutor extends AbstractExecutor { @@ -19,7 +19,7 @@ class MongoDBExecutor extends AbstractExecutor * * @param DocumentManager $dm DocumentManager instance used for persistence. */ - public function __construct(DocumentManager $dm, MongoDBPurger $purger = null) + public function __construct(DocumentManager $dm, ?MongoDBPurger $purger = null) { $this->dm = $dm; if ($purger !== null) { @@ -34,7 +34,7 @@ public function __construct(DocumentManager $dm, MongoDBPurger $purger = null) /** * Retrieve the DocumentManager instance this executor instance is using. * - * @return \Doctrine\ODM\MongoDB\DocumentManager + * @return DocumentManager */ public function getObjectManager() { @@ -50,7 +50,7 @@ public function setReferenceRepository(ReferenceRepository $referenceRepository) ); $this->referenceRepository = $referenceRepository; - $this->listener = new MongoDBReferenceListener($this->referenceRepository); + $this->listener = new MongoDBReferenceListener($this->referenceRepository); $this->dm->getEventManager()->addEventSubscriber($this->listener); } diff --git a/lib/Doctrine/Common/DataFixtures/Executor/ORMExecutor.php b/lib/Doctrine/Common/DataFixtures/Executor/ORMExecutor.php index 5bcaab6f..246c0efa 100644 --- a/lib/Doctrine/Common/DataFixtures/Executor/ORMExecutor.php +++ b/lib/Doctrine/Common/DataFixtures/Executor/ORMExecutor.php @@ -1,30 +1,28 @@ */ class ORMExecutor extends AbstractExecutor { - /** - * @var EntityManagerInterface - */ + /** @var EntityManagerInterface */ private $em; - + /** * Construct new fixtures loader instance. * * @param EntityManagerInterface $em EntityManagerInterface instance used for persistence. */ - public function __construct(EntityManagerInterface $em, ORMPurger $purger = null) + public function __construct(EntityManagerInterface $em, ?ORMPurger $purger = null) { $this->em = $em; if ($purger !== null) { @@ -39,7 +37,7 @@ public function __construct(EntityManagerInterface $em, ORMPurger $purger = null /** * Retrieve the EntityManagerInterface instance this executor instance is using. * - * @return \Doctrine\ORM\EntityManagerInterface + * @return EntityManagerInterface */ public function getObjectManager() { @@ -55,7 +53,7 @@ public function setReferenceRepository(ReferenceRepository $referenceRepository) ); $this->referenceRepository = $referenceRepository; - $this->listener = new ORMReferenceListener($this->referenceRepository); + $this->listener = new ORMReferenceListener($this->referenceRepository); $this->em->getEventManager()->addEventSubscriber($this->listener); } @@ -63,7 +61,7 @@ public function setReferenceRepository(ReferenceRepository $referenceRepository) public function execute(array $fixtures, $append = false) { $executor = $this; - $this->em->transactional(function(EntityManagerInterface $em) use ($executor, $fixtures, $append) { + $this->em->transactional(static function (EntityManagerInterface $em) use ($executor, $fixtures, $append) { if ($append === false) { $executor->purge(); } diff --git a/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php b/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php index ec634c25..e30b365a 100644 --- a/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php +++ b/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php @@ -1,36 +1,36 @@ - * @author Daniel Barsotti */ class PHPCRExecutor extends AbstractExecutor { - /** - * @var DocumentManagerInterface - */ + /** @var DocumentManagerInterface */ private $dm; /** * @param DocumentManagerInterface $dm manager instance used for persisting the fixtures * @param PHPCRPurger $purger to remove the current data if append is false */ - public function __construct(DocumentManagerInterface $dm, PHPCRPurger $purger = null) + public function __construct(DocumentManagerInterface $dm, ?PHPCRPurger $purger = null) { parent::__construct($dm); $this->dm = $dm; - if ($purger !== null) { - $purger->setDocumentManager($dm); - $this->setPurger($purger); + if ($purger === null) { + return; } + + $purger->setDocumentManager($dm); + $this->setPurger($purger); } public function getObjectManager() @@ -43,7 +43,7 @@ public function execute(array $fixtures, $append = false) { $that = $this; - $function = function ($dm) use ($append, $that, $fixtures) { + $function = static function ($dm) use ($append, $that, $fixtures) { if ($append === false) { $that->purge(); } @@ -60,4 +60,3 @@ public function execute(array $fixtures, $append = false) } } } - diff --git a/lib/Doctrine/Common/DataFixtures/FixtureInterface.php b/lib/Doctrine/Common/DataFixtures/FixtureInterface.php index 96bfb103..3cc3fc79 100644 --- a/lib/Doctrine/Common/DataFixtures/FixtureInterface.php +++ b/lib/Doctrine/Common/DataFixtures/FixtureInterface.php @@ -1,20 +1,18 @@ */ interface FixtureInterface { /** * Load data fixtures with the passed EntityManager - * - * @param ObjectManager $manager */ public function load(ObjectManager $manager); } diff --git a/lib/Doctrine/Common/DataFixtures/Loader.php b/lib/Doctrine/Common/DataFixtures/Loader.php index 5c5b0e54..10256200 100644 --- a/lib/Doctrine/Common/DataFixtures/Loader.php +++ b/lib/Doctrine/Common/DataFixtures/Loader.php @@ -1,13 +1,38 @@ */ class Loader { @@ -28,14 +53,14 @@ class Loader /** * Determines if we must order fixtures by number * - * @var boolean + * @var bool */ private $orderFixturesByNumber = false; - + /** * Determines if we must order fixtures by its dependencies * - * @var boolean + * @var bool */ private $orderFixturesByDependencies = false; @@ -50,18 +75,20 @@ class Loader * Find fixtures classes in a given directory and load them. * * @param string $dir Directory to find fixture classes in. + * * @return array $fixtures Array of loaded fixture object instances. */ public function loadFromDirectory($dir) { - if (!is_dir($dir)) { - throw new \InvalidArgumentException(sprintf('"%s" does not exist', $dir)); + if (! is_dir($dir)) { + throw new InvalidArgumentException(sprintf('"%s" does not exist', $dir)); } - $iterator = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($dir), - \RecursiveIteratorIterator::LEAVES_ONLY + $iterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($dir), + RecursiveIteratorIterator::LEAVES_ONLY ); + return $this->loadFromIterator($iterator); } @@ -69,15 +96,17 @@ public function loadFromDirectory($dir) * Find fixtures classes in a given file and load them. * * @param string $fileName File to find fixture classes in. + * * @return array $fixtures Array of loaded fixture object instances. */ public function loadFromFile($fileName) { - if (!is_readable($fileName)) { - throw new \InvalidArgumentException(sprintf('"%s" does not exist or is not readable', $fileName)); + if (! is_readable($fileName)) { + throw new InvalidArgumentException(sprintf('"%s" does not exist or is not readable', $fileName)); } - $iterator = new \ArrayIterator([new \SplFileInfo($fileName)]); + $iterator = new ArrayIterator([new SplFileInfo($fileName)]); + return $this->loadFromIterator($iterator); } @@ -86,7 +115,7 @@ public function loadFromFile($fileName) * * @param FixtureInterface $fixture * - * @return boolean + * @return bool */ public function hasFixture($fixture) { @@ -97,12 +126,13 @@ public function hasFixture($fixture) * Get a specific fixture instance * * @param string $className + * * @return FixtureInterface */ public function getFixture($className) { - if (!isset($this->fixtures[$className])) { - throw new \InvalidArgumentException(sprintf( + if (! isset($this->fixtures[$className])) { + throw new InvalidArgumentException(sprintf( '"%s" is not a registered fixture', $className )); @@ -113,32 +143,36 @@ public function getFixture($className) /** * Add a fixture object instance to the loader. - * - * @param FixtureInterface $fixture */ public function addFixture(FixtureInterface $fixture) { $fixtureClass = get_class($fixture); - if (!isset($this->fixtures[$fixtureClass])) { - if ($fixture instanceof OrderedFixtureInterface && $fixture instanceof DependentFixtureInterface) { - throw new \InvalidArgumentException(sprintf('Class "%s" can\'t implement "%s" and "%s" at the same time.', - get_class($fixture), - 'OrderedFixtureInterface', - 'DependentFixtureInterface')); - } + if (isset($this->fixtures[$fixtureClass])) { + return; + } - $this->fixtures[$fixtureClass] = $fixture; + if ($fixture instanceof OrderedFixtureInterface && $fixture instanceof DependentFixtureInterface) { + throw new InvalidArgumentException(sprintf( + 'Class "%s" can\'t implement "%s" and "%s" at the same time.', + get_class($fixture), + 'OrderedFixtureInterface', + 'DependentFixtureInterface' + )); + } - if ($fixture instanceof OrderedFixtureInterface) { - $this->orderFixturesByNumber = true; - } elseif ($fixture instanceof DependentFixtureInterface) { - $this->orderFixturesByDependencies = true; - foreach($fixture->getDependencies() as $class) { - if (class_exists($class)) { - $this->addFixture($this->createFixture($class)); - } + $this->fixtures[$fixtureClass] = $fixture; + + if ($fixture instanceof OrderedFixtureInterface) { + $this->orderFixturesByNumber = true; + } elseif ($fixture instanceof DependentFixtureInterface) { + $this->orderFixturesByDependencies = true; + foreach ($fixture->getDependencies() as $class) { + if (! class_exists($class)) { + continue; } + + $this->addFixture($this->createFixture($class)); } } } @@ -159,8 +193,8 @@ public function getFixtures() if ($this->orderFixturesByDependencies) { $this->orderFixturesByDependencies(); } - - if (!$this->orderFixturesByNumber && !$this->orderFixturesByDependencies) { + + if (! $this->orderFixturesByNumber && ! $this->orderFixturesByDependencies) { $this->orderedFixtures = $this->fixtures; } @@ -171,21 +205,25 @@ public function getFixtures() * Check if a given fixture is transient and should not be considered a data fixtures * class. * - * @return boolean + * @return bool */ public function isTransient($className) { - $rc = new \ReflectionClass($className); - if ($rc->isAbstract()) return true; + $rc = new ReflectionClass($className); + if ($rc->isAbstract()) { + return true; + } $interfaces = class_implements($className); - return in_array(FixtureInterface::class, $interfaces) ? false : true; + + return ! in_array(FixtureInterface::class, $interfaces); } /** * Creates the fixture object from the class. * * @param string $class + * * @return FixtureInterface */ protected function createFixture($class) @@ -195,51 +233,59 @@ protected function createFixture($class) /** * Orders fixtures by number - * - * @todo maybe there is a better way to handle reordering + * * @return void + * + * @todo maybe there is a better way to handle reordering */ private function orderFixturesByNumber() { $this->orderedFixtures = $this->fixtures; - usort($this->orderedFixtures, function($a, $b) { + usort($this->orderedFixtures, static function ($a, $b) { if ($a instanceof OrderedFixtureInterface && $b instanceof OrderedFixtureInterface) { if ($a->getOrder() === $b->getOrder()) { return 0; } + return $a->getOrder() < $b->getOrder() ? -1 : 1; - } elseif ($a instanceof OrderedFixtureInterface) { + } + + if ($a instanceof OrderedFixtureInterface) { return $a->getOrder() === 0 ? 0 : 1; - } elseif ($b instanceof OrderedFixtureInterface) { + } + + if ($b instanceof OrderedFixtureInterface) { return $b->getOrder() === 0 ? 0 : -1; } + return 0; }); } - - + /** * Orders fixtures by dependencies - * + * * @return void */ private function orderFixturesByDependencies() { $sequenceForClasses = []; - // If fixtures were already ordered by number then we need + // If fixtures were already ordered by number then we need // to remove classes which are not instances of OrderedFixtureInterface // in case fixtures implementing DependentFixtureInterface exist. // This is because, in that case, the method orderFixturesByDependencies - // will handle all fixtures which are not instances of + // will handle all fixtures which are not instances of // OrderedFixtureInterface if ($this->orderFixturesByNumber) { $count = count($this->orderedFixtures); - for ($i = 0 ; $i < $count ; ++$i) { - if (!($this->orderedFixtures[$i] instanceof OrderedFixtureInterface)) { - unset($this->orderedFixtures[$i]); + for ($i = 0; $i < $count; ++$i) { + if ($this->orderedFixtures[$i] instanceof OrderedFixtureInterface) { + continue; } + + unset($this->orderedFixtures[$i]); } } @@ -249,19 +295,21 @@ private function orderFixturesByDependencies() if ($fixture instanceof OrderedFixtureInterface) { continue; - } elseif ($fixture instanceof DependentFixtureInterface) { + } + + if ($fixture instanceof DependentFixtureInterface) { $dependenciesClasses = $fixture->getDependencies(); - + $this->validateDependencies($dependenciesClasses); - if (!is_array($dependenciesClasses) || empty($dependenciesClasses)) { - throw new \InvalidArgumentException(sprintf('Method "%s" in class "%s" must return an array of classes which are dependencies for the fixture, and it must be NOT empty.', 'getDependencies', $fixtureClass)); + if (! is_array($dependenciesClasses) || empty($dependenciesClasses)) { + throw new InvalidArgumentException(sprintf('Method "%s" in class "%s" must return an array of classes which are dependencies for the fixture, and it must be NOT empty.', 'getDependencies', $fixtureClass)); } if (in_array($fixtureClass, $dependenciesClasses)) { - throw new \InvalidArgumentException(sprintf('Class "%s" can\'t have itself as a dependency', $fixtureClass)); + throw new InvalidArgumentException(sprintf('Class "%s" can\'t have itself as a dependency', $fixtureClass)); } - + // We mark this class as unsequenced $sequenceForClasses[$fixtureClass] = -1; } else { @@ -271,40 +319,42 @@ private function orderFixturesByDependencies() } // Now we order fixtures by sequence - $sequence = 1; + $sequence = 1; $lastCount = -1; - + while (($count = count($unsequencedClasses = $this->getUnsequencedClasses($sequenceForClasses))) > 0 && $count !== $lastCount) { foreach ($unsequencedClasses as $key => $class) { - $fixture = $this->fixtures[$class]; - $dependencies = $fixture->getDependencies(); + $fixture = $this->fixtures[$class]; + $dependencies = $fixture->getDependencies(); $unsequencedDependencies = $this->getUnsequencedClasses($sequenceForClasses, $dependencies); - if (count($unsequencedDependencies) === 0) { - $sequenceForClasses[$class] = $sequence++; - } + if (count($unsequencedDependencies) !== 0) { + continue; + } + + $sequenceForClasses[$class] = $sequence++; } - + $lastCount = $count; } $orderedFixtures = []; - - // If there're fixtures unsequenced left and they couldn't be sequenced, + + // If there're fixtures unsequenced left and they couldn't be sequenced, // it means we have a circular reference if ($count > 0) { - $msg = 'Classes "%s" have produced a CircularReferenceException. '; + $msg = 'Classes "%s" have produced a CircularReferenceException. '; $msg .= 'An example of this problem would be the following: Class C has class B as its dependency. '; $msg .= 'Then, class B has class A has its dependency. Finally, class A has class C as its dependency. '; $msg .= 'This case would produce a CircularReferenceException.'; - + throw new CircularReferenceException(sprintf($msg, implode(',', $unsequencedClasses))); } else { // We order the classes by sequence asort($sequenceForClasses); foreach ($sequenceForClasses as $class => $sequence) { - // If fixtures were ordered + // If fixtures were ordered $orderedFixtures[] = $this->fixtures[$class]; } } @@ -315,10 +365,10 @@ private function orderFixturesByDependencies() private function validateDependencies($dependenciesClasses) { $loadedFixtureClasses = array_keys($this->fixtures); - + foreach ($dependenciesClasses as $class) { - if (!in_array($class, $loadedFixtureClasses)) { - throw new \RuntimeException(sprintf('Fixture "%s" was declared as a dependency, but it should be added in fixture loader first.', $class)); + if (! in_array($class, $loadedFixtureClasses)) { + throw new RuntimeException(sprintf('Fixture "%s" was declared as a dependency, but it should be added in fixture loader first.', $class)); } } @@ -329,14 +379,16 @@ private function getUnsequencedClasses($sequences, $classes = null) { $unsequencedClasses = []; - if (is_null($classes)) { + if ($classes === null) { $classes = array_keys($sequences); } foreach ($classes as $class) { - if ($sequences[$class] === -1) { - $unsequencedClasses[] = $class; + if ($sequences[$class] !== -1) { + continue; } + + $unsequencedClasses[] = $class; } return $unsequencedClasses; @@ -345,16 +397,19 @@ private function getUnsequencedClasses($sequences, $classes = null) /** * Load fixtures from files contained in iterator. * - * @param \Iterator $iterator Iterator over files from which fixtures should be loaded. + * @param Iterator $iterator Iterator over files from which fixtures should be loaded. + * * @return array $fixtures Array of loaded fixture object instances. */ - private function loadFromIterator(\Iterator $iterator) + private function loadFromIterator(Iterator $iterator) { $includedFiles = []; foreach ($iterator as $file) { - if (($fileName = $file->getBasename($this->fileExtension)) == $file->getBasename()) { + $fileName = $file->getBasename($this->fileExtension); + if ($fileName === $file->getBasename()) { continue; } + $sourceFile = realpath($file->getPathName()); require_once $sourceFile; $includedFiles[] = $sourceFile; @@ -366,14 +421,16 @@ private function loadFromIterator(\Iterator $iterator) sort($declared); foreach ($declared as $className) { - $reflClass = new \ReflectionClass($className); + $reflClass = new ReflectionClass($className); $sourceFile = $reflClass->getFileName(); - if (in_array($sourceFile, $includedFiles) && ! $this->isTransient($className)) { - $fixture = $this->createFixture($className); - $fixtures[] = $fixture; - $this->addFixture($fixture); + if (! in_array($sourceFile, $includedFiles) || $this->isTransient($className)) { + continue; } + + $fixture = $this->createFixture($className); + $fixtures[] = $fixture; + $this->addFixture($fixture); } return $fixtures; diff --git a/lib/Doctrine/Common/DataFixtures/OrderedFixtureInterface.php b/lib/Doctrine/Common/DataFixtures/OrderedFixtureInterface.php index 8f7b9430..e5959260 100644 --- a/lib/Doctrine/Common/DataFixtures/OrderedFixtureInterface.php +++ b/lib/Doctrine/Common/DataFixtures/OrderedFixtureInterface.php @@ -1,21 +1,20 @@ - * @author Jonathan H. Wage */ interface OrderedFixtureInterface -{ +{ /** * Get the order of this fixture - * - * @return integer - */ + * + * @return int + */ public function getOrder(); } diff --git a/lib/Doctrine/Common/DataFixtures/ProxyReferenceRepository.php b/lib/Doctrine/Common/DataFixtures/ProxyReferenceRepository.php index cddbe517..6fcffca0 100644 --- a/lib/Doctrine/Common/DataFixtures/ProxyReferenceRepository.php +++ b/lib/Doctrine/Common/DataFixtures/ProxyReferenceRepository.php @@ -1,18 +1,24 @@ - * @author Anthon Pang */ class ProxyReferenceRepository extends ReferenceRepository { @@ -52,12 +58,10 @@ public function serialize() $simpleReferences[$name] = [$className, $this->getIdentifier($reference, $unitOfWork)]; } - $serializedData = json_encode([ + return json_encode([ 'references' => $simpleReferences, 'identities' => $this->getIdentities(), ]); - - return $serializedData; } /** @@ -92,13 +96,19 @@ public function unserialize($serializedData) * * @param string $baseCacheName Base cache name * - * @return boolean + * @return bool */ public function load($baseCacheName) { $filename = $baseCacheName . '.ser'; - if ( ! file_exists($filename) || ($serializedData = file_get_contents($filename)) === false) { + if (! file_exists($filename)) { + return false; + } + + $serializedData = file_get_contents($filename); + + if ($serializedData === false) { return false; } diff --git a/lib/Doctrine/Common/DataFixtures/Purger/MongoDBPurger.php b/lib/Doctrine/Common/DataFixtures/Purger/MongoDBPurger.php index ce5cce96..d7d2bfed 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/MongoDBPurger.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/MongoDBPurger.php @@ -1,17 +1,17 @@ */ class MongoDBPurger implements PurgerInterface { - /** DocumentManager instance used for persistence. */ + /** @var DocumentManager|null */ private $dm; /** @@ -19,15 +19,13 @@ class MongoDBPurger implements PurgerInterface * * @param DocumentManager $dm DocumentManager instance used for persistence. */ - public function __construct(DocumentManager $dm = null) + public function __construct(?DocumentManager $dm = null) { $this->dm = $dm; } /** * Set the DocumentManager instance this purger instance should use. - * - * @param DocumentManager $dm */ public function setDocumentManager(DocumentManager $dm) { @@ -37,7 +35,7 @@ public function setDocumentManager(DocumentManager $dm) /** * Retrieve the DocumentManager instance this purger instance is using. * - * @return \Doctrine\ODM\MongoDB\DocumentManager + * @return DocumentManager */ public function getObjectManager() { @@ -49,9 +47,11 @@ public function purge() { $metadatas = $this->dm->getMetadataFactory()->getAllMetadata(); foreach ($metadatas as $metadata) { - if ( ! $metadata->isMappedSuperclass) { - $this->dm->getDocumentCollection($metadata->name)->drop(); + if ($metadata->isMappedSuperclass) { + continue; } + + $this->dm->getDocumentCollection($metadata->name)->drop(); } $this->dm->getSchemaManager()->ensureIndexes(); } diff --git a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php index 16eca488..6aa24105 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php @@ -1,28 +1,29 @@ - * @author Benjamin Eberlei */ class ORMPurger implements PurgerInterface { - const PURGE_MODE_DELETE = 1; - const PURGE_MODE_TRUNCATE = 2; + public const PURGE_MODE_DELETE = 1; + public const PURGE_MODE_TRUNCATE = 2; - /** EntityManagerInterface instance used for persistence. */ + /** @var EntityManagerInterface|null */ private $em; /** @@ -33,28 +34,29 @@ class ORMPurger implements PurgerInterface private $purgeMode = self::PURGE_MODE_DELETE; /** - * Table/view names to be excleded from purge - * - * @var string[] - */ + * Table/view names to be excleded from purge + * + * @var string[] + */ private $excluded; /** * Construct new purger instance. * - * @param EntityManagerInterface $em EntityManagerInterface instance used for persistence. - * @param string[] $excluded array of table/view names to be excleded from purge + * @param EntityManagerInterface $em EntityManagerInterface instance used for persistence. + * @param string[] $excluded array of table/view names to be excleded from purge */ - public function __construct(EntityManagerInterface $em = null, array $excluded = []) + public function __construct(?EntityManagerInterface $em = null, array $excluded = []) { - $this->em = $em; + $this->em = $em; $this->excluded = $excluded; } /** * Set the purge mode * - * @param $mode + * @param int $mode + * * @return void */ public function setPurgeMode($mode) @@ -74,18 +76,16 @@ public function getPurgeMode() /** * Set the EntityManagerInterface instance this purger instance should use. - * - * @param EntityManagerInterface $em */ public function setEntityManager(EntityManagerInterface $em) { - $this->em = $em; + $this->em = $em; } /** * Retrieve the EntityManagerInterface instance this purger instance is using. * - * @return \Doctrine\ORM\EntityManagerInterface + * @return EntityManagerInterface */ public function getObjectManager() { @@ -98,9 +98,11 @@ public function purge() $classes = []; foreach ($this->em->getMetadataFactory()->getAllMetadata() as $metadata) { - if (! $metadata->isMappedSuperclass && ! (isset($metadata->isEmbeddedClass) && $metadata->isEmbeddedClass)) { - $classes[] = $metadata; + if ($metadata->isMappedSuperclass || (isset($metadata->isEmbeddedClass) && $metadata->isEmbeddedClass)) { + continue; } + + $classes[] = $metadata; } $commitOrder = $this->getCommitOrder($this->em, $classes); @@ -115,8 +117,7 @@ public function purge() for ($i = count($commitOrder) - 1; $i >= 0; --$i) { $class = $commitOrder[$i]; - if ( - (isset($class->isEmbeddedClass) && $class->isEmbeddedClass) || + if ((isset($class->isEmbeddedClass) && $class->isEmbeddedClass) || $class->isMappedSuperclass || ($class->isInheritanceTypeSingleTable() && $class->name !== $class->rootEntityName) ) { @@ -126,15 +127,15 @@ public function purge() $orderedTables[] = $this->getTableName($class, $platform); } - $connection = $this->em->getConnection(); - $filterExpr = $connection->getConfiguration()->getFilterSchemaAssetsExpression(); + $connection = $this->em->getConnection(); + $filterExpr = $connection->getConfiguration()->getFilterSchemaAssetsExpression(); $emptyFilterExpression = empty($filterExpr); $schemaAssetsFilter = method_exists($connection->getConfiguration(), 'getSchemaAssetsFilter') ? $connection->getConfiguration()->getSchemaAssetsFilter() : null; - foreach($orderedTables as $tbl) { + foreach ($orderedTables as $tbl) { // If we have a filter expression, check it and skip if necessary - if (!$emptyFilterExpression && !preg_match($filterExpr, $tbl)) { + if (! $emptyFilterExpression && ! preg_match($filterExpr, $tbl)) { continue; } @@ -144,12 +145,12 @@ public function purge() } // Support schema asset filters as presented in - if (is_callable($schemaAssetsFilter) && !$schemaAssetsFilter($tbl)) { + if (is_callable($schemaAssetsFilter) && ! $schemaAssetsFilter($tbl)) { continue; } if ($this->purgeMode === self::PURGE_MODE_DELETE) { - $connection->executeUpdate("DELETE FROM " . $tbl); + $connection->executeUpdate('DELETE FROM ' . $tbl); } else { $connection->executeUpdate($platform->getTruncateTableSQL($tbl, true)); } @@ -157,8 +158,7 @@ public function purge() } /** - * @param EntityManagerInterface $em - * @param ClassMetadata[] $classes + * @param ClassMetadata[] $classes * * @return ClassMetadata[] */ @@ -167,7 +167,7 @@ private function getCommitOrder(EntityManagerInterface $em, array $classes) $sorter = new TopologicalSorter(); foreach ($classes as $class) { - if ( ! $sorter->hasNode($class->name)) { + if (! $sorter->hasNode($class->name)) { $sorter->addNode($class->name, $class); } @@ -176,7 +176,7 @@ private function getCommitOrder(EntityManagerInterface $em, array $classes) $parentClass = $em->getClassMetadata($parentClass); $parentClassName = $parentClass->getName(); - if ( ! $sorter->hasNode($parentClassName)) { + if (! $sorter->hasNode($parentClassName)) { $sorter->addNode($parentClassName, $parentClass); } @@ -184,29 +184,31 @@ private function getCommitOrder(EntityManagerInterface $em, array $classes) } foreach ($class->associationMappings as $assoc) { - if ($assoc['isOwningSide']) { - /* @var $targetClass ClassMetadata */ - $targetClass = $em->getClassMetadata($assoc['targetEntity']); - $targetClassName = $targetClass->getName(); + if (! $assoc['isOwningSide']) { + continue; + } - if ( ! $sorter->hasNode($targetClassName)) { - $sorter->addNode($targetClassName, $targetClass); - } + /** @var ClassMetadata $targetClass */ + $targetClass = $em->getClassMetadata($assoc['targetEntity']); + $targetClassName = $targetClass->getName(); - // add dependency ($targetClass before $class) - $sorter->addDependency($targetClassName, $class->name); + if (! $sorter->hasNode($targetClassName)) { + $sorter->addNode($targetClassName, $targetClass); + } - // parents of $targetClass before $class, too - foreach ($targetClass->parentClasses as $parentClass) { - $parentClass = $em->getClassMetadata($parentClass); - $parentClassName = $parentClass->getName(); + // add dependency ($targetClass before $class) + $sorter->addDependency($targetClassName, $class->name); - if ( ! $sorter->hasNode($parentClassName)) { - $sorter->addNode($parentClassName, $parentClass); - } + // parents of $targetClass before $class, too + foreach ($targetClass->parentClasses as $parentClass) { + $parentClass = $em->getClassMetadata($parentClass); + $parentClassName = $parentClass->getName(); - $sorter->addDependency($parentClassName, $class->name); + if (! $sorter->hasNode($parentClassName)) { + $sorter->addNode($parentClassName, $parentClass); } + + $sorter->addDependency($parentClassName, $class->name); } } } @@ -216,7 +218,7 @@ private function getCommitOrder(EntityManagerInterface $em, array $classes) /** * @param array $classes - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform + * * @return array */ private function getAssociationTables(array $classes, AbstractPlatform $platform) @@ -225,9 +227,11 @@ private function getAssociationTables(array $classes, AbstractPlatform $platform foreach ($classes as $class) { foreach ($class->associationMappings as $assoc) { - if ($assoc['isOwningSide'] && $assoc['type'] == ClassMetadata::MANY_TO_MANY) { - $associationTables[] = $this->getJoinTableName($assoc, $class, $platform); + if (! $assoc['isOwningSide'] || $assoc['type'] !== ClassMetadata::MANY_TO_MANY) { + continue; } + + $associationTables[] = $this->getJoinTableName($assoc, $class, $platform); } } @@ -235,31 +239,31 @@ private function getAssociationTables(array $classes, AbstractPlatform $platform } /** + * @param ClassMetadata $class + * @param AbstractPlatform $platform * - * @param \Doctrine\ORM\Mapping\ClassMetadata $class - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform * @return string */ private function getTableName($class, $platform) { - if (isset($class->table['schema']) && !method_exists($class, 'getSchemaName')) { - return $class->table['schema'].'.'.$this->em->getConfiguration()->getQuoteStrategy()->getTableName($class, $platform); + if (isset($class->table['schema']) && ! method_exists($class, 'getSchemaName')) { + return $class->table['schema'] . '.' . $this->em->getConfiguration()->getQuoteStrategy()->getTableName($class, $platform); } return $this->em->getConfiguration()->getQuoteStrategy()->getTableName($class, $platform); } /** - * * @param array $association - * @param \Doctrine\ORM\Mapping\ClassMetadata $class - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform + * @param ClassMetadata $class + * @param AbstractPlatform $platform + * * @return string */ private function getJoinTableName($assoc, $class, $platform) { - if (isset($assoc['joinTable']['schema']) && !method_exists($class, 'getSchemaName')) { - return $assoc['joinTable']['schema'].'.'.$this->em->getConfiguration()->getQuoteStrategy()->getJoinTableName($assoc, $class, $platform); + if (isset($assoc['joinTable']['schema']) && ! method_exists($class, 'getSchemaName')) { + return $assoc['joinTable']['schema'] . '.' . $this->em->getConfiguration()->getQuoteStrategy()->getJoinTableName($assoc, $class, $platform); } return $this->em->getConfiguration()->getQuoteStrategy()->getJoinTableName($assoc, $class, $platform); diff --git a/lib/Doctrine/Common/DataFixtures/Purger/PHPCRPurger.php b/lib/Doctrine/Common/DataFixtures/Purger/PHPCRPurger.php index e5c85272..800f5196 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/PHPCRPurger.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/PHPCRPurger.php @@ -1,5 +1,7 @@ */ class PHPCRPurger implements PurgerInterface { - /** - * @var DocumentManagerInterface - */ + /** @var DocumentManagerInterface */ private $dm; - public function __construct(DocumentManagerInterface $dm = null) + public function __construct(?DocumentManagerInterface $dm = null) { $this->dm = $dm; } diff --git a/lib/Doctrine/Common/DataFixtures/Purger/PurgerInterface.php b/lib/Doctrine/Common/DataFixtures/Purger/PurgerInterface.php index 76421fb7..c41ea508 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/PurgerInterface.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/PurgerInterface.php @@ -1,11 +1,11 @@ */ interface PurgerInterface { @@ -14,5 +14,5 @@ interface PurgerInterface * * @return void */ - function purge(); + public function purge(); } diff --git a/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php b/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php index da076562..7663ec52 100644 --- a/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php +++ b/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php @@ -1,16 +1,23 @@ */ class ReferenceRepository { @@ -54,7 +61,7 @@ public function __construct(ObjectManager $manager) protected function getIdentifier($reference, $uow) { // In case Reference is not yet managed in UnitOfWork - if ( ! $this->hasIdentifier($reference)) { + if (! $this->hasIdentifier($reference)) { $class = $this->manager->getClassMetadata(get_class($reference)); return $class->getIdentifierValues($reference); @@ -86,18 +93,20 @@ public function setReference($name, $reference) { $this->references[$name] = $reference; - if ($this->hasIdentifier($reference)) { - // in case if reference is set after flush, store its identity - $uow = $this->manager->getUnitOfWork(); - $this->identities[$name] = $this->getIdentifier($reference, $uow); + if (! $this->hasIdentifier($reference)) { + return; } + + // in case if reference is set after flush, store its identity + $uow = $this->manager->getUnitOfWork(); + $this->identities[$name] = $this->getIdentifier($reference, $uow); } /** * Store the identifier of a reference * * @param string $name - * @param mixed $identity + * @param mixed $identity */ public function setReferenceIdentity($name, $identity) { @@ -115,15 +124,17 @@ public function setReferenceIdentity($name, $identity) * * @param string $name * @param object $object - managed object - * @throws \BadMethodCallException - if repository already has - * a reference by $name + * * @return void + * + * @throws BadMethodCallException - if repository already has a reference by $name. */ public function addReference($name, $object) { if (isset($this->references[$name])) { - throw new \BadMethodCallException("Reference to: ({$name}) already exists, use method setReference in order to override it"); + throw new BadMethodCallException(sprintf('Reference to "%s" already exists, use method setReference in order to override it', $name)); } + $this->setReference($name, $object); } @@ -132,20 +143,22 @@ public function addReference($name, $object) * named by $name * * @param string $name - * @throws \OutOfBoundsException - if repository does not exist + * * @return object + * + * @throws OutOfBoundsException - if repository does not exist. */ public function getReference($name) { - if (!$this->hasReference($name)) { - throw new \OutOfBoundsException("Reference to: ({$name}) does not exist"); + if (! $this->hasReference($name)) { + throw new OutOfBoundsException(sprintf('Reference to "%s" does not exist', $name)); } $reference = $this->references[$name]; - $meta = $this->manager->getClassMetadata(get_class($reference)); + $meta = $this->manager->getClassMetadata(get_class($reference)); - if (!$this->manager->contains($reference) && isset($this->identities[$name])) { - $reference = $this->manager->getReference( + if (! $this->manager->contains($reference) && isset($this->identities[$name])) { + $reference = $this->manager->getReference( $meta->name, $this->identities[$name] ); @@ -160,7 +173,8 @@ public function getReference($name) * named by $name * * @param string $name - * @return boolean + * + * @return bool */ public function hasReference($name) { @@ -172,6 +186,7 @@ public function hasReference($name) * list of stored references * * @param object $reference + * * @return array */ public function getReferenceNames($reference) @@ -222,7 +237,7 @@ public function getManager() /** * Checks if object has identifier already in unit of work. * - * @param $reference + * @param string $reference * * @return bool */ @@ -233,8 +248,8 @@ private function hasIdentifier($reference) if ($this->manager instanceof PhpcrDocumentManager) { return $uow->contains($reference); - } else { - return $uow->isInIdentityMap($reference); } + + return $uow->isInIdentityMap($reference); } } diff --git a/lib/Doctrine/Common/DataFixtures/SharedFixtureInterface.php b/lib/Doctrine/Common/DataFixtures/SharedFixtureInterface.php index c3e145bf..f58b4c3f 100644 --- a/lib/Doctrine/Common/DataFixtures/SharedFixtureInterface.php +++ b/lib/Doctrine/Common/DataFixtures/SharedFixtureInterface.php @@ -1,23 +1,16 @@ */ interface SharedFixtureInterface extends FixtureInterface -{ - /** - * Set the reference repository - * - * @param ReferenceRepository $referenceRepository - */ - function setReferenceRepository(ReferenceRepository $referenceRepository); +{ + public function setReferenceRepository(ReferenceRepository $referenceRepository); } diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php index be4dd673..42a4cc0b 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php @@ -1,9 +1,14 @@ - * @author Roman Borschel - * * @internal this class is to be used only by data-fixtures internals: do not * rely on it in your own libraries/applications. */ @@ -38,14 +40,14 @@ class TopologicalSorter /** * Allow or not cyclic dependencies * - * @var boolean + * @var bool */ private $allowCyclicDependencies; /** * Construct TopologicalSorter object * - * @param boolean $allowCyclicDependencies + * @param bool $allowCyclicDependencies */ public function __construct($allowCyclicDependencies = true) { @@ -55,8 +57,7 @@ public function __construct($allowCyclicDependencies = true) /** * Adds a new node (vertex) to the graph, assigning its hash and value. * - * @param string $hash - * @param ClassMetadata $node + * @param string $hash * * @return void */ @@ -98,10 +99,10 @@ public function addDependency($fromHash, $toHash) * * Note: Highly performance-sensitive method. * - * @throws \RuntimeException - * @throws CircularReferenceException - * * @return array + * + * @throws RuntimeException + * @throws CircularReferenceException */ public function sort() { @@ -126,18 +127,16 @@ public function sort() * * Note: Highly performance-sensitive method. * - * @throws \RuntimeException + * @throws RuntimeException * @throws CircularReferenceException - * - * @param Vertex $definition */ private function visit(Vertex $definition) { $definition->state = Vertex::IN_PROGRESS; foreach ($definition->dependencyList as $dependency) { - if ( ! isset($this->nodeList[$dependency])) { - throw new \RuntimeException(sprintf( + if (! isset($this->nodeList[$dependency])) { + throw new RuntimeException(sprintf( 'Fixture "%s" has a dependency of fixture "%s", but it not listed to be loaded.', get_class($definition->value), $dependency @@ -155,13 +154,13 @@ private function visit(Vertex $definition) case Vertex::VISITED: break; case Vertex::IN_PROGRESS: - if ( ! $this->allowCyclicDependencies) { + if (! $this->allowCyclicDependencies) { throw new CircularReferenceException( sprintf( 'Graph contains cyclic dependency between the classes "%s" and' - .' "%s". An example of this problem would be the following: ' - .'Class C has class B as its dependency. Then, class B has class A has its dependency. ' - .'Finally, class A has class C as its dependency.', + . ' "%s". An example of this problem would be the following: ' + . 'Class C has class B as its dependency. Then, class B has class A has its dependency. ' + . 'Finally, class A has class C as its dependency.', $definition->value->getName(), $childDefinition->value->getName() ) diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/Vertex.php b/lib/Doctrine/Common/DataFixtures/Sorter/Vertex.php index 5b0cbf6d..feee46cf 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/Vertex.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/Vertex.php @@ -1,12 +1,12 @@ - * * @internal this class is to be used only by data-fixtures internals: do not * rely on it in your own libraries/applications. This class is * designed to work with {@see \Doctrine\Common\DataFixtures\Sorter\TopologicalSorter} @@ -14,28 +14,19 @@ */ class Vertex { - const NOT_VISITED = 0; - const IN_PROGRESS = 1; - const VISITED = 2; + public const NOT_VISITED = 0; + public const IN_PROGRESS = 1; + public const VISITED = 2; - /** - * @var int one of either {@see self::NOT_VISITED}, {@see self::IN_PROGRESS} or {@see self::VISITED}. - */ + /** @var int one of either {@see self::NOT_VISITED}, {@see self::IN_PROGRESS} or {@see self::VISITED}. */ public $state = self::NOT_VISITED; - /** - * @var ClassMetadata Actual node value - */ + /** @var ClassMetadata Actual node value */ public $value; - /** - * @var string[] Map of node dependencies defined as hashes. - */ + /** @var string[] Map of node dependencies defined as hashes. */ public $dependencyList = []; - /** - * @param ClassMetadata $value - */ public function __construct(ClassMetadata $value) { $this->value = $value; diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 00000000..1a5fe7e2 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,50 @@ + + + + + + + + + + + + lib + tests + + + + + + + + + + + + + + tests/* + + + + lib/Doctrine/Common/DataFixtures/AbstractFixture.php + lib/Doctrine/Common/DataFixtures/Executor/AbstractExecutor.php + + + + lib/Doctrine/Common/DataFixtures/Exception/CircularReferenceException.php + + + + lib/Doctrine/Common/DataFixtures/DependentFixtureInterface.php + lib/Doctrine/Common/DataFixtures/FixtureInterface.php + lib/Doctrine/Common/DataFixtures/Purger/PurgerInterface.php + lib/Doctrine/Common/DataFixtures/OrderedFixtureInterface.php + lib/Doctrine/Common/DataFixtures/SharedFixtureInterface.php + + + + tests/* + + diff --git a/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php b/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php index bde7a387..40d38517 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php @@ -1,16 +1,15 @@ */ abstract class BaseTest extends TestCase { @@ -23,7 +22,8 @@ abstract class BaseTest extends TestCase protected function getMockAnnotationReaderEntityManager() { $dbParams = ['driver' => 'pdo_sqlite', 'memory' => true]; - $config = Setup::createAnnotationMetadataConfiguration([__DIR__.'/TestEntity'], true); + $config = Setup::createAnnotationMetadataConfiguration([__DIR__ . '/TestEntity'], true); + return EntityManager::create($dbParams, $config); } @@ -37,7 +37,8 @@ protected function getMockAnnotationReaderEntityManager() protected function getMockSqliteEntityManager() { $dbParams = ['driver' => 'pdo_sqlite', 'memory' => true]; - $config = Setup::createAnnotationMetadataConfiguration([__DIR__.'/TestEntity'], true); + $config = Setup::createAnnotationMetadataConfiguration([__DIR__ . '/TestEntity'], true); + return EntityManager::create($dbParams, $config); } } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/DependentFixtureTest.php b/tests/Doctrine/Tests/Common/DataFixtures/DependentFixtureTest.php index 66d72e0a..af08d402 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/DependentFixtureTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/DependentFixtureTest.php @@ -1,30 +1,32 @@ */ class DependentFixtureTest extends BaseTest { - public function test_orderFixturesByDependencies_orderClassesWithASingleParent() + public function testOrderFixturesByDependenciesOrderClassesWithASingleParent() { $loader = new Loader(); - $loader->addFixture(new DependentFixture3); - $loader->addFixture(new DependentFixture1); - $loader->addFixture(new DependentFixture2); - $loader->addFixture(new BaseParentFixture1); + $loader->addFixture(new DependentFixture3()); + $loader->addFixture(new DependentFixture1()); + $loader->addFixture(new DependentFixture2()); + $loader->addFixture(new BaseParentFixture1()); $orderedFixtures = $loader->getFixtures(); @@ -35,16 +37,16 @@ public function test_orderFixturesByDependencies_orderClassesWithASingleParent() $this->assertInstanceOf(DependentFixture3::class, array_shift($orderedFixtures)); } - public function test_orderFixturesByDependencies_orderClassesWithAMultipleParents() + public function testOrderFixturesByDependenciesOrderClassesWithAMultipleParents() { $loader = new Loader(); - $addressFixture = new AddressFixture(); - $contactMethodFixture = new ContactMethodFixture(); - $contactFixture = new ContactFixture(); - $baseParentFixture = new BaseParentFixture1(); - $countryFixture = new CountryFixture(); - $stateFixture = new StateFixture(); + $addressFixture = new AddressFixture(); + $contactMethodFixture = new ContactMethodFixture(); + $contactFixture = new ContactFixture(); + $baseParentFixture = new BaseParentFixture1(); + $countryFixture = new CountryFixture(); + $stateFixture = new StateFixture(); $loader->addFixture($addressFixture); $loader->addFixture($contactMethodFixture); @@ -57,12 +59,12 @@ public function test_orderFixturesByDependencies_orderClassesWithAMultipleParent $this->assertCount(6, $orderedFixtures); - $contactFixtureOrder = array_search($contactFixture, $orderedFixtures); + $contactFixtureOrder = array_search($contactFixture, $orderedFixtures); $contactMethodFixtureOrder = array_search($contactMethodFixture, $orderedFixtures); - $addressFixtureOrder = array_search($addressFixture, $orderedFixtures); - $countryFixtureOrder = array_search($countryFixture, $orderedFixtures); - $stateFixtureOrder = array_search($stateFixture, $orderedFixtures); - $baseParentFixtureOrder = array_search($baseParentFixture, $orderedFixtures); + $addressFixtureOrder = array_search($addressFixture, $orderedFixtures); + $countryFixtureOrder = array_search($countryFixture, $orderedFixtures); + $stateFixtureOrder = array_search($stateFixture, $orderedFixtures); + $baseParentFixtureOrder = array_search($baseParentFixture, $orderedFixtures); // Order of fixtures is not exact. We need to test, however, that dependencies are // indeed satisfied @@ -80,41 +82,40 @@ public function test_orderFixturesByDependencies_orderClassesWithAMultipleParent $this->assertGreaterThan($countryFixtureOrder, $addressFixtureOrder); } - - public function test_orderFixturesByDependencies_circularReferencesMakeMethodThrowCircularReferenceException() + public function testOrderFixturesByDependenciesCircularReferencesMakeMethodThrowCircularReferenceException() { $loader = new Loader(); - $loader->addFixture(new CircularReferenceFixture3); - $loader->addFixture(new CircularReferenceFixture); - $loader->addFixture(new CircularReferenceFixture2); + $loader->addFixture(new CircularReferenceFixture3()); + $loader->addFixture(new CircularReferenceFixture()); + $loader->addFixture(new CircularReferenceFixture2()); $this->expectException(CircularReferenceException::class); $loader->getFixtures(); } - public function test_orderFixturesByDependencies_fixturesCantHaveItselfAsParent() + public function testOrderFixturesByDependenciesFixturesCantHaveItselfAsParent() { $loader = new Loader(); - $loader->addFixture(new FixtureWithItselfAsParent); + $loader->addFixture(new FixtureWithItselfAsParent()); $this->expectException(InvalidArgumentException::class); $loader->getFixtures(); } - public function test_inCaseThereAreFixturesOrderedByNumberAndByDependenciesBothOrdersAreExecuted() + public function testInCaseThereAreFixturesOrderedByNumberAndByDependenciesBothOrdersAreExecuted() { $loader = new Loader(); - $loader->addFixture(new OrderedByNumberFixture1); - $loader->addFixture(new OrderedByNumberFixture3); - $loader->addFixture(new OrderedByNumberFixture2); - $loader->addFixture(new DependentFixture3); - $loader->addFixture(new DependentFixture1); - $loader->addFixture(new DependentFixture2); - $loader->addFixture(new BaseParentFixture1); + $loader->addFixture(new OrderedByNumberFixture1()); + $loader->addFixture(new OrderedByNumberFixture3()); + $loader->addFixture(new OrderedByNumberFixture2()); + $loader->addFixture(new DependentFixture3()); + $loader->addFixture(new DependentFixture1()); + $loader->addFixture(new DependentFixture2()); + $loader->addFixture(new BaseParentFixture1()); $orderedFixtures = $loader->getFixtures(); @@ -128,21 +129,21 @@ public function test_inCaseThereAreFixturesOrderedByNumberAndByDependenciesBothO $this->assertInstanceOf(DependentFixture3::class, array_shift($orderedFixtures)); } - public function test_inCaseAFixtureHasAnUnexistentDependencyOrIfItWasntLoaded_throwsException() + public function testInCaseAFixtureHasAnUnexistentDependencyOrIfItWasntLoadedThrowsException() { $loader = new Loader(); - $loader->addFixture(new FixtureWithUnexistentDependency); + $loader->addFixture(new FixtureWithUnexistentDependency()); $this->expectException(RuntimeException::class); $loader->getFixtures(); } - public function test_inCaseGetFixturesReturnsDifferentResultsEachTime() + public function testInCaseGetFixturesReturnsDifferentResultsEachTime() { $loader = new Loader(); - $loader->addFixture(new DependentFixture1); - $loader->addFixture(new BaseParentFixture1); + $loader->addFixture(new DependentFixture1()); + $loader->addFixture(new BaseParentFixture1()); // Intentionally calling getFixtures() twice $loader->getFixtures(); @@ -157,7 +158,8 @@ public function test_inCaseGetFixturesReturnsDifferentResultsEachTime() class DependentFixture1 implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) - {} + { + } public function getDependencies() { @@ -168,7 +170,8 @@ public function getDependencies() class DependentFixture2 implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) - {} + { + } public function getDependencies() { @@ -179,7 +182,8 @@ public function getDependencies() class DependentFixture3 implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) - {} + { + } public function getDependencies() { @@ -190,13 +194,15 @@ public function getDependencies() class BaseParentFixture1 implements FixtureInterface { public function load(ObjectManager $manager) - {} + { + } } class CountryFixture implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) - {} + { + } public function getDependencies() { @@ -207,13 +213,14 @@ public function getDependencies() class StateFixture implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) - {} + { + } public function getDependencies() { return [ BaseParentFixture1::class, - CountryFixture::class + CountryFixture::class, ]; } } @@ -221,14 +228,15 @@ public function getDependencies() class AddressFixture implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) - {} + { + } public function getDependencies() { return [ BaseParentFixture1::class, CountryFixture::class, - StateFixture::class + StateFixture::class, ]; } } @@ -236,7 +244,8 @@ public function getDependencies() class ContactMethodFixture implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) - {} + { + } public function getDependencies() { @@ -247,13 +256,14 @@ public function getDependencies() class ContactFixture implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) - {} + { + } public function getDependencies() { return [ AddressFixture::class, - ContactMethodFixture::class + ContactMethodFixture::class, ]; } } @@ -261,7 +271,8 @@ public function getDependencies() class CircularReferenceFixture implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) - {} + { + } public function getDependencies() { @@ -272,7 +283,8 @@ public function getDependencies() class CircularReferenceFixture2 implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) - {} + { + } public function getDependencies() { @@ -283,7 +295,8 @@ public function getDependencies() class CircularReferenceFixture3 implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) - {} + { + } public function getDependencies() { @@ -294,18 +307,20 @@ public function getDependencies() class FixtureWithItselfAsParent implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) - {} + { + } public function getDependencies() { - return [FixtureWithItselfAsParent::class]; + return [self::class]; } } class FixtureWithUnexistentDependency implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) - {} + { + } public function getDependencies() { @@ -316,7 +331,8 @@ public function getDependencies() class FixtureImplementingBothOrderingInterfaces implements FixtureInterface, OrderedFixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) - {} + { + } public function getOrder() { @@ -332,7 +348,8 @@ public function getDependencies() class OrderedByNumberFixture1 implements FixtureInterface, OrderedFixtureInterface { public function load(ObjectManager $manager) - {} + { + } public function getOrder() { @@ -343,7 +360,8 @@ public function getOrder() class OrderedByNumberFixture2 implements FixtureInterface, OrderedFixtureInterface { public function load(ObjectManager $manager) - {} + { + } public function getOrder() { @@ -354,7 +372,8 @@ public function getOrder() class OrderedByNumberFixture3 implements FixtureInterface, OrderedFixtureInterface { public function load(ObjectManager $manager) - {} + { + } public function getOrder() { diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php index 419f4951..b72101a6 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php @@ -1,5 +1,7 @@ */ class ORMExecutorSharedFixtureTest extends BaseTest { - const TEST_ENTITY_ROLE = Role::class; - const TEST_ENTITY_USER = User::class; + public const TEST_ENTITY_ROLE = Role::class; + public const TEST_ENTITY_USER = User::class; public function testFixtureExecution() { - $em = $this->getMockAnnotationReaderEntityManager(); - $purger = new ORMPurger(); + $em = $this->getMockAnnotationReaderEntityManager(); + $purger = new ORMPurger(); $executor = new ORMExecutor($em, $purger); $referenceRepository = $executor->getReferenceRepository(); - $fixture = $this->getMockFixture(); + $fixture = $this->getMockFixture(); $fixture->expects($this->once()) ->method('load') ->with($em); @@ -40,27 +41,27 @@ public function testFixtureExecution() public function testSharedFixtures() { - if (!extension_loaded('pdo_sqlite')) { + if (! extension_loaded('pdo_sqlite')) { $this->markTestSkipped('Missing pdo_sqlite extension.'); } - $em = $this->getMockSqliteEntityManager(); + $em = $this->getMockSqliteEntityManager(); $schemaTool = new SchemaTool($em); $schemaTool->dropSchema([]); $schemaTool->createSchema([ $em->getClassMetadata(self::TEST_ENTITY_ROLE), - $em->getClassMetadata(self::TEST_ENTITY_USER) + $em->getClassMetadata(self::TEST_ENTITY_USER), ]); - $purger = new ORMPurger(); + $purger = new ORMPurger(); $executor = new ORMExecutor($em, $purger); - $userFixture = new TestFixtures\UserFixture; - $roleFixture = new TestFixtures\RoleFixture; + $userFixture = new TestFixtures\UserFixture(); + $roleFixture = new TestFixtures\RoleFixture(); $executor->execute([$roleFixture, $userFixture], true); $referenceRepository = $executor->getReferenceRepository(); - $references = $referenceRepository->getReferences(); + $references = $referenceRepository->getReferences(); $this->assertCount(2, $references); $roleReference = $referenceRepository->getReference('admin-role'); diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorTest.php index b5a184c5..00fab108 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorTest.php @@ -1,5 +1,7 @@ */ class ORMExecutorTest extends BaseTest { public function testExecuteWithNoPurge() { - $em = $this->getMockSqliteEntityManager(); + $em = $this->getMockSqliteEntityManager(); $purger = $this->getMockPurger(); $purger->expects($this->once()) ->method('setEntityManager') ->with($em); $executor = new ORMExecutor($em, $purger); - $fixture = $this->getMockFixture(); + $fixture = $this->getMockFixture(); $fixture->expects($this->once()) ->method('load') ->with($em); @@ -31,13 +31,13 @@ public function testExecuteWithNoPurge() public function testExecuteWithPurge() { - $em = $this->getMockSqliteEntityManager(); + $em = $this->getMockSqliteEntityManager(); $purger = $this->getMockPurger(); $purger->expects($this->once()) ->method('purge') ->will($this->returnValue(null)); $executor = new ORMExecutor($em, $purger); - $fixture = $this->getMockFixture(); + $fixture = $this->getMockFixture(); $fixture->expects($this->once()) ->method('load') ->with($em); @@ -46,9 +46,9 @@ public function testExecuteWithPurge() public function testExecuteTransaction() { - $em = $this->getMockSqliteEntityManager(); + $em = $this->getMockSqliteEntityManager(); $executor = new ORMExecutor($em); - $fixture = $this->getMockFixture(); + $fixture = $this->getMockFixture(); $fixture->expects($this->once()) ->method('load') ->with($em); diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php index 42477aa4..d301fa33 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php @@ -1,5 +1,7 @@ - * * @covers \Doctrine\Common\DataFixtures\Executor\PHPCRExecutor */ class PHPCRExecutorTest extends BaseTest @@ -29,7 +32,7 @@ public function testExecuteSingleFixtureWithNoPurge() ->expects($this->once()) ->method('transactional') ->with($this->isType('callable')) - ->will($this->returnCallback(function ($callback) use ($dm) { + ->will($this->returnCallback(static function ($callback) use ($dm) { return $callback($dm); })); @@ -49,7 +52,7 @@ public function testExecuteMultipleFixturesWithNoPurge() ->expects($this->once()) ->method('transactional') ->with($this->isType('callable')) - ->will($this->returnCallback(function ($callback) use ($dm) { + ->will($this->returnCallback(static function ($callback) use ($dm) { return $callback($dm); })); @@ -68,7 +71,7 @@ public function testExecuteFixtureWithPurge() ->expects($this->once()) ->method('transactional') ->with($this->isType('callable')) - ->will($this->returnCallback(function ($callback) use ($dm) { + ->will($this->returnCallback(static function ($callback) use ($dm) { return $callback($dm); })); $purger->expects($this->once())->method('purge'); @@ -88,7 +91,7 @@ public function testExecuteFixtureWithoutPurge() ->expects($this->once()) ->method('transactional') ->with($this->isType('callable')) - ->will($this->returnCallback(function ($callback) use ($dm) { + ->will($this->returnCallback(static function ($callback) use ($dm) { return $callback($dm); })); $purger->expects($this->never())->method('purge'); @@ -110,13 +113,13 @@ public function testFailedTransactionalStopsPurgingAndFixtureLoading() try { $executor->execute([$fixture], true); - } catch (\Exception $caughtException) { + } catch (Throwable $caughtException) { $this->assertSame($exception, $caughtException); } } /** - * @return PHPCRPurger|\PHPUnit_Framework_MockObject_MockObject + * @return PHPCRPurger|PHPUnit_Framework_MockObject_MockObject */ private function getPurger() { @@ -124,11 +127,11 @@ private function getPurger() } /** - * @return DocumentManager|\PHPUnit_Framework_MockObject_MockObject + * @return DocumentManager|PHPUnit_Framework_MockObject_MockObject */ private function getDocumentManager() { - if (!class_exists(DocumentManager::class)) { + if (! class_exists(DocumentManager::class)) { $this->markTestSkipped('Missing doctrine/phpcr-odm'); } @@ -144,7 +147,7 @@ private function getDocumentManager() } /** - * @return FixtureInterface|\PHPUnit_Framework_MockObject_MockObject + * @return FixtureInterface|PHPUnit_Framework_MockObject_MockObject */ private function getMockFixture() { diff --git a/tests/Doctrine/Tests/Common/DataFixtures/FixtureTest.php b/tests/Doctrine/Tests/Common/DataFixtures/FixtureTest.php index 1ca99762..b8a19b1d 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/FixtureTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/FixtureTest.php @@ -1,5 +1,7 @@ */ class FixtureTest extends BaseTest { public function testFixtureInterface() { - $em = $this->createMock(ObjectManager::class); + $em = $this->createMock(ObjectManager::class); $fixture = new MyFixture2(); $fixture->load($em); @@ -24,6 +24,7 @@ public function testFixtureInterface() class MyFixture2 implements FixtureInterface { + /** @var bool */ public $loaded = false; public function load(ObjectManager $manager) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/LoaderTest.php b/tests/Doctrine/Tests/Common/DataFixtures/LoaderTest.php index 0b6e3f73..3a2182e0 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/LoaderTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/LoaderTest.php @@ -1,5 +1,7 @@ */ class LoaderTest extends BaseTest { @@ -24,7 +24,7 @@ public function testLoadFromDirectory() $this->assertCount(3, $loader->getFixtures()); - $loader->loadFromDirectory(__DIR__.'/TestFixtures'); + $loader->loadFromDirectory(__DIR__ . '/TestFixtures'); $this->assertCount(7, $loader->getFixtures()); $this->assertTrue($loader->isTransient(NotAFixture::class)); $this->assertFalse($loader->isTransient(MyFixture1::class)); @@ -39,11 +39,11 @@ public function testLoadFromFile() $this->assertCount(3, $loader->getFixtures()); - $loader->loadFromFile(__DIR__.'/TestFixtures/MyFixture1.php'); + $loader->loadFromFile(__DIR__ . '/TestFixtures/MyFixture1.php'); $this->assertCount(4, $loader->getFixtures()); - $loader->loadFromFile(__DIR__.'/TestFixtures/NotAFixture.php'); + $loader->loadFromFile(__DIR__ . '/TestFixtures/NotAFixture.php'); $this->assertCount(4, $loader->getFixtures()); - $loader->loadFromFile(__DIR__.'/TestFixtures/MyFixture2.php'); + $loader->loadFromFile(__DIR__ . '/TestFixtures/MyFixture2.php'); $this->assertCount(5, $loader->getFixtures()); $this->assertTrue($loader->isTransient(NotAFixture::class)); $this->assertFalse($loader->isTransient(MyFixture1::class)); @@ -52,7 +52,7 @@ public function testLoadFromFile() public function testGetFixture() { $loader = new Loader(); - $loader->loadFromFile(__DIR__.'/TestFixtures/MyFixture1.php'); + $loader->loadFromFile(__DIR__ . '/TestFixtures/MyFixture1.php'); $fixture = $loader->getFixture(MyFixture1::class); diff --git a/tests/Doctrine/Tests/Common/DataFixtures/OrderedFixtureTest.php b/tests/Doctrine/Tests/Common/DataFixtures/OrderedFixtureTest.php index 3ad14ceb..7bfba466 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/OrderedFixtureTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/OrderedFixtureTest.php @@ -1,26 +1,26 @@ */ class OrderedFixtureTest extends BaseTest { public function testFixtureOrder() { $loader = new Loader(); - $loader->addFixture(new OrderedFixture1); - $loader->addFixture(new OrderedFixture2); - $loader->addFixture(new OrderedFixture3); - $loader->addFixture(new BaseFixture1); + $loader->addFixture(new OrderedFixture1()); + $loader->addFixture(new OrderedFixture2()); + $loader->addFixture(new OrderedFixture3()); + $loader->addFixture(new BaseFixture1()); $orderedFixtures = $loader->getFixtures(); @@ -35,7 +35,8 @@ public function testFixtureOrder() class OrderedFixture1 implements FixtureInterface, OrderedFixtureInterface { public function load(ObjectManager $manager) - {} + { + } public function getOrder() { @@ -46,7 +47,8 @@ public function getOrder() class OrderedFixture2 implements FixtureInterface, OrderedFixtureInterface { public function load(ObjectManager $manager) - {} + { + } public function getOrder() { @@ -57,7 +59,8 @@ public function getOrder() class OrderedFixture3 implements FixtureInterface, OrderedFixtureInterface { public function load(ObjectManager $manager) - {} + { + } public function getOrder() { @@ -68,5 +71,6 @@ public function getOrder() class BaseFixture1 implements FixtureInterface { public function load(ObjectManager $manager) - {} + { + } } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/ProxyReferenceRepositoryTest.php b/tests/Doctrine/Tests/Common/DataFixtures/ProxyReferenceRepositoryTest.php index 9f722982..9b0ece3f 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/ProxyReferenceRepositoryTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/ProxyReferenceRepositoryTest.php @@ -1,27 +1,26 @@ - * @author Anthon Pang */ class ProxyReferenceRepositoryTest extends BaseTest { - const TEST_ENTITY_ROLE = Role::class; + public const TEST_ENTITY_ROLE = Role::class; public function testReferenceEntry() { - $em = $this->getMockAnnotationReaderEntityManager(); - $role = new TestEntity\Role; + $em = $this->getMockAnnotationReaderEntityManager(); + $role = new TestEntity\Role(); $role->setName('admin'); $meta = $em->getClassMetadata(self::TEST_ENTITY_ROLE); $meta->getReflectionProperty('id')->setValue($role, 1); @@ -38,7 +37,7 @@ public function testReferenceEntry() public function testReferenceIdentityPopulation() { - $em = $this->getMockSqliteEntityManager(); + $em = $this->getMockSqliteEntityManager(); $referenceRepository = $this->getMockBuilder(ProxyReferenceRepository::class) ->setConstructorArgs([$em]) ->getMock(); @@ -47,9 +46,7 @@ public function testReferenceIdentityPopulation() ); $schemaTool = new SchemaTool($em); $schemaTool->dropSchema([]); - $schemaTool->createSchema([ - $em->getClassMetadata(self::TEST_ENTITY_ROLE) - ]); + $schemaTool->createSchema([$em->getClassMetadata(self::TEST_ENTITY_ROLE)]); $referenceRepository->expects($this->once()) ->method('addReference') @@ -63,24 +60,22 @@ public function testReferenceIdentityPopulation() ->method('setReferenceIdentity') ->with('admin-role', ['id' => 1]); - $roleFixture = new TestFixtures\RoleFixture; + $roleFixture = new TestFixtures\RoleFixture(); $roleFixture->setReferenceRepository($referenceRepository); $roleFixture->load($em); } public function testReferenceReconstruction() { - $em = $this->getMockSqliteEntityManager(); + $em = $this->getMockSqliteEntityManager(); $referenceRepository = new ProxyReferenceRepository($em); - $listener = new ORMReferenceListener($referenceRepository); + $listener = new ORMReferenceListener($referenceRepository); $em->getEventManager()->addEventSubscriber($listener); $schemaTool = new SchemaTool($em); $schemaTool->dropSchema([]); - $schemaTool->createSchema([ - $em->getClassMetadata(self::TEST_ENTITY_ROLE) - ]); - $roleFixture = new TestFixtures\RoleFixture; + $schemaTool->createSchema([$em->getClassMetadata(self::TEST_ENTITY_ROLE)]); + $roleFixture = new TestFixtures\RoleFixture(); $roleFixture->setReferenceRepository($referenceRepository); $roleFixture->load($em); @@ -120,13 +115,13 @@ public function testReferenceReconstruction() public function testReferenceMultipleEntries() { - $em = $this->getMockSqliteEntityManager(); + $em = $this->getMockSqliteEntityManager(); $referenceRepository = new ProxyReferenceRepository($em); $em->getEventManager()->addEventSubscriber(new ORMReferenceListener($referenceRepository)); $schemaTool = new SchemaTool($em); $schemaTool->createSchema([$em->getClassMetadata(self::TEST_ENTITY_ROLE)]); - $role = new TestEntity\Role; + $role = new TestEntity\Role(); $role->setName('admin'); $em->persist($role); diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Purger/MongoDBPurgerTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Purger/MongoDBPurgerTest.php index d50cd0ef..a733a6c0 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Purger/MongoDBPurgerTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Purger/MongoDBPurgerTest.php @@ -1,22 +1,25 @@ markTestSkipped('Missing doctrine/mongodb-odm'); } @@ -31,7 +34,7 @@ private function getDocumentManager() AnnotationDriver::registerAnnotationClasses(); $dm = DocumentManager::create(null, $config); - if (!$dm->getConnection()->connect()) { + if (! $dm->getConnection()->connect()) { $this->markTestSkipped('Unable to connect to MongoDB'); } @@ -46,14 +49,14 @@ private function getPurger() public function testPurgeKeepsIndices() { $purger = $this->getPurger(); - $dm = $purger->getObjectManager(); + $dm = $purger->getObjectManager(); $collection = $dm->getDocumentCollection(self::TEST_DOCUMENT_ROLE); $collection->drop(); $this->assertCount(0, $collection->getIndexInfo()); - $role = new Role; + $role = new Role(); $role->setName('role'); $dm->persist($role); $dm->flush(); diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php index b68de4b8..80f28e46 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php @@ -1,7 +1,8 @@ markTestSkipped('Missing pdo_sqlite extension.'); } $dbParams = ['driver' => 'pdo_sqlite', 'memory' => true]; - $config = Setup::createAnnotationMetadataConfiguration([__DIR__.'/../TestPurgeEntity'], true); - $em = EntityManager::create($dbParams, $config); + $config = Setup::createAnnotationMetadataConfiguration([__DIR__ . '/../TestPurgeEntity'], true); + $em = EntityManager::create($dbParams, $config); - $connection = $em->getConnection(); + $connection = $em->getConnection(); $configuration = $connection->getConfiguration(); $configuration->setFilterSchemaAssetsExpression(null); - $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em); + $schemaTool = new SchemaTool($em); $schemaTool->dropDatabase(); $schemaTool->createSchema([ $em->getClassMetadata(self::TEST_ENTITY_INCLUDED), - $em->getClassMetadata(self::TEST_ENTITY_EXCLUDED) + $em->getClassMetadata(self::TEST_ENTITY_EXCLUDED), ]); $entity = new ExcludedEntity(); @@ -58,10 +63,11 @@ protected function loadTestData(){ * Execute test purge * * @param string|null $expression - * @param array $list + * @param array $list */ - public function executeTestPurge($expression, array $list, ?callable $filter = null){ - $em = $this->loadTestData(); + public function executeTestPurge($expression, array $list, ?callable $filter = null) + { + $em = $this->loadTestData(); $excludedRepository = $em->getRepository(self::TEST_ENTITY_EXCLUDED); $includedRepository = $em->getRepository(self::TEST_ENTITY_INCLUDED); @@ -71,19 +77,19 @@ public function executeTestPurge($expression, array $list, ?callable $filter = n $this->assertGreaterThan(0, count($included)); $this->assertGreaterThan(0, count($excluded)); - $connection = $em->getConnection(); + $connection = $em->getConnection(); $configuration = $connection->getConfiguration(); $configuration->setFilterSchemaAssetsExpression($expression); if ($filter !== null) { - if (!method_exists($configuration, 'setSchemaAssetsFilter')) { + if (! method_exists($configuration, 'setSchemaAssetsFilter')) { $this->markTestSkipped('DBAL 2.9 or newer is required to test schema assets filters'); } $configuration->setSchemaAssetsFilter($filter); } - $purger = new ORMPurger($em,$list); + $purger = new ORMPurger($em, $list); $purger->purge(); $excluded = $excludedRepository->findAll(); @@ -96,14 +102,16 @@ public function executeTestPurge($expression, array $list, ?callable $filter = n /** * Test for purge exclusion usig dbal filter expression regexp. */ - public function testPurgeExcludeUsingFilterExpression(){ + public function testPurgeExcludeUsingFilterExpression() + { $this->executeTestPurge('~^(?!ExcludedEntity)~', [], null); } /** * Test for purge exclusion usig explicit exclution list. */ - public function testPurgeExcludeUsingList(){ + public function testPurgeExcludeUsingList() + { $this->executeTestPurge(null, ['ExcludedEntity'], null); } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerTest.php index d5d53b9b..eb40e9e7 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerTest.php @@ -1,34 +1,29 @@ */ class ORMPurgerTest extends BaseTest { - const TEST_ENTITY_USER = TestEntity\User::class; - const TEST_ENTITY_USER_WITH_SCHEMA = TestEntity\UserWithSchema::class; - const TEST_ENTITY_QUOTED = TestEntity\Quoted::class; - + public const TEST_ENTITY_USER = TestEntity\User::class; + public const TEST_ENTITY_USER_WITH_SCHEMA = TestEntity\UserWithSchema::class; + public const TEST_ENTITY_QUOTED = TestEntity\Quoted::class; public function testGetAssociationTables() { - $em = $this->getMockAnnotationReaderEntityManager(); + $em = $this->getMockAnnotationReaderEntityManager(); $metadata = $em->getClassMetadata(self::TEST_ENTITY_USER); $platform = $em->getConnection()->getDatabasePlatform(); - $purger = new ORMPurger($em); - $class = new ReflectionClass(ORMPurger::class); - $method = $class->getMethod('getAssociationTables'); + $purger = new ORMPurger($em); + $class = new ReflectionClass(ORMPurger::class); + $method = $class->getMethod('getAssociationTables'); $method->setAccessible(true); $associationTables = $method->invokeArgs($purger, [[$metadata], $platform]); $this->assertEquals($associationTables[0], 'readers.author_reader'); @@ -36,12 +31,12 @@ public function testGetAssociationTables() public function testGetAssociationTablesQuoted() { - $em = $this->getMockAnnotationReaderEntityManager(); + $em = $this->getMockAnnotationReaderEntityManager(); $metadata = $em->getClassMetadata(self::TEST_ENTITY_QUOTED); $platform = $em->getConnection()->getDatabasePlatform(); - $purger = new ORMPurger($em); - $class = new ReflectionClass(ORMPurger::class); - $method = $class->getMethod('getAssociationTables'); + $purger = new ORMPurger($em); + $class = new ReflectionClass(ORMPurger::class); + $method = $class->getMethod('getAssociationTables'); $method->setAccessible(true); $associationTables = $method->invokeArgs($purger, [[$metadata], $platform]); $this->assertEquals($associationTables[0], '"INSERT"'); @@ -49,15 +44,14 @@ public function testGetAssociationTablesQuoted() public function testTableNameWithSchema() { - $em = $this->getMockAnnotationReaderEntityManager(); + $em = $this->getMockAnnotationReaderEntityManager(); $metadata = $em->getClassMetadata(self::TEST_ENTITY_USER_WITH_SCHEMA); $platform = $em->getConnection()->getDatabasePlatform(); - $purger = new ORMPurger($em); - $class = new ReflectionClass(ORMPurger::class); - $method = $class->getMethod('getTableName'); + $purger = new ORMPurger($em); + $class = new ReflectionClass(ORMPurger::class); + $method = $class->getMethod('getTableName'); $method->setAccessible(true); $tableName = $method->invokeArgs($purger, [$metadata, $platform]); - $this->assertStringStartsWith('test_schema',$tableName); + $this->assertStringStartsWith('test_schema', $tableName); } - } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php b/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php index 64a989b7..b1ba08f6 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php @@ -1,30 +1,31 @@ - * @author Manuel Gonalez - */ class ReferenceRepositoryTest extends BaseTest { public function testReferenceEntry() { $em = $this->getMockAnnotationReaderEntityManager(); - - $role = new TestEntity\Role; + + $role = new TestEntity\Role(); $role->setName('admin'); - + $meta = $em->getClassMetadata(Role::class); $meta->getReflectionProperty('id')->setValue($role, 1); @@ -41,7 +42,7 @@ public function testReferenceEntry() public function testReferenceIdentityPopulation() { - $em = $this->getMockSqliteEntityManager(); + $em = $this->getMockSqliteEntityManager(); $referenceRepository = $this->getMockBuilder(ReferenceRepository::class) ->setConstructorArgs([$em]) ->getMock(); @@ -50,9 +51,7 @@ public function testReferenceIdentityPopulation() ); $schemaTool = new SchemaTool($em); $schemaTool->dropSchema([]); - $schemaTool->createSchema([ - $em->getClassMetadata(Role::class) - ]); + $schemaTool->createSchema([$em->getClassMetadata(Role::class)]); $referenceRepository->expects($this->once()) ->method('addReference') @@ -66,7 +65,7 @@ public function testReferenceIdentityPopulation() ->method('setReferenceIdentity') ->with('admin-role', ['id' => 1]); - $roleFixture = new TestFixtures\RoleFixture; + $roleFixture = new TestFixtures\RoleFixture(); $roleFixture->setReferenceRepository($referenceRepository); $roleFixture->load($em); @@ -74,17 +73,15 @@ public function testReferenceIdentityPopulation() public function testReferenceReconstruction() { - $em = $this->getMockSqliteEntityManager(); + $em = $this->getMockSqliteEntityManager(); $referenceRepository = new ReferenceRepository($em); $em->getEventManager()->addEventSubscriber( new ORMReferenceListener($referenceRepository) ); $schemaTool = new SchemaTool($em); $schemaTool->dropSchema([]); - $schemaTool->createSchema([ - $em->getClassMetadata(Role::class) - ]); - $roleFixture = new TestFixtures\RoleFixture; + $schemaTool->createSchema([$em->getClassMetadata(Role::class)]); + $roleFixture = new TestFixtures\RoleFixture(); $roleFixture->setReferenceRepository($referenceRepository); $roleFixture->load($em); @@ -102,13 +99,13 @@ public function testReferenceReconstruction() public function testReferenceMultipleEntries() { - $em = $this->getMockSqliteEntityManager(); + $em = $this->getMockSqliteEntityManager(); $referenceRepository = new ReferenceRepository($em); $em->getEventManager()->addEventSubscriber(new ORMReferenceListener($referenceRepository)); $schemaTool = new SchemaTool($em); $schemaTool->createSchema([$em->getClassMetadata(Role::class)]); - $role = new TestEntity\Role; + $role = new TestEntity\Role(); $role->setName('admin'); $em->persist($role); @@ -125,7 +122,7 @@ public function testUndefinedReference() { $referenceRepository = new ReferenceRepository($this->getMockSqliteEntityManager()); - $this->expectException(\OutOfBoundsException::class); + $this->expectException(OutOfBoundsException::class); $this->expectExceptionMessage('Reference to: (foo) does not exist'); $referenceRepository->getReference('foo'); @@ -134,19 +131,19 @@ public function testUndefinedReference() public function testThrowsExceptionAddingDuplicatedReference() { $referenceRepository = new ReferenceRepository($this->getMockSqliteEntityManager()); - $referenceRepository->addReference('duplicated_reference', new \stdClass()); + $referenceRepository->addReference('duplicated_reference', new stdClass()); - $this->expectException(\BadMethodCallException::class); + $this->expectException(BadMethodCallException::class); $this->expectExceptionMessage('Reference to: (duplicated_reference) already exists, use method setReference in order to override it'); - $referenceRepository->addReference('duplicated_reference', new \stdClass()); + $referenceRepository->addReference('duplicated_reference', new stdClass()); } public function testThrowsExceptionTryingToGetWrongReference() { $referenceRepository = new ReferenceRepository($this->getMockSqliteEntityManager()); - $this->expectException(\OutOfBoundsException::class); + $this->expectException(OutOfBoundsException::class); $this->expectExceptionMessage('Reference to: (missing_reference) does not exist'); $referenceRepository->getReference('missing_reference'); @@ -154,7 +151,7 @@ public function testThrowsExceptionTryingToGetWrongReference() public function testHasIdentityCheck() { - $role = new Role(); + $role = new Role(); $referenceRepository = new ReferenceRepository($this->getMockSqliteEntityManager()); $referenceRepository->setReferenceIdentity('entity', $role); @@ -165,14 +162,12 @@ public function testHasIdentityCheck() public function testSetReferenceHavingIdentifier() { - $em = $this->getMockSqliteEntityManager(); + $em = $this->getMockSqliteEntityManager(); $referenceRepository = new ReferenceRepository($em); $schemaTool = new SchemaTool($em); $schemaTool->dropSchema([]); - $schemaTool->createSchema([ - $em->getClassMetadata(Role::class) - ]); + $schemaTool->createSchema([$em->getClassMetadata(Role::class)]); $role = new Role(); $role->setName('role_name'); @@ -187,7 +182,7 @@ public function testSetReferenceHavingIdentifier() public function testGetIdentifierWhenHasNotBeenManagedYetByUnitOfWork() { - $role = new Role(); + $role = new Role(); $identitiesExpected = ['id' => 1]; /** @var UnitOfWork | ProphecyInterface $uow */ diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php index 46df1792..1934a555 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php @@ -1,5 +1,6 @@ - * * @covers \Doctrine\Common\DataFixtures\Sorter\TopologicalSorter */ class TopologicalSorterTest extends BaseTest @@ -159,7 +159,7 @@ public function testFailureSortMissingDependency() $sorter->addDependency('1', '2'); - $this->expectException(\RuntimeException::class); + $this->expectException(RuntimeException::class); $sorter->sort(); } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php index d11ed951..9fef86b6 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php @@ -1,5 +1,6 @@ - * * @covers \Doctrine\Common\DataFixtures\Sorter\Vertex */ class VertexTest extends BaseTest diff --git a/tests/Doctrine/Tests/Common/DataFixtures/TestDocument/Role.php b/tests/Doctrine/Tests/Common/DataFixtures/TestDocument/Role.php index aa6e3dbc..4bbd7698 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/TestDocument/Role.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/TestDocument/Role.php @@ -1,5 +1,7 @@ id; + } + + public function setId(?int $id) : void + { + $this->id = $id; + } + + public function getSelect() : ?string + { + return $this->select; + } + + public function setSelect(?string $select) : void + { + $this->select = $select; + } + + /** + * @return Collection|null + */ + public function getSelects() : ?Collection + { + return $this->selects; + } + + /** + * @param Collection|null $selects + */ + public function setSelects(?Collection $selects) : void + { + $this->selects = $selects; + } } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/TestEntity/Role.php b/tests/Doctrine/Tests/Common/DataFixtures/TestEntity/Role.php index 5ab3786e..67b22d27 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/TestEntity/Role.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/TestEntity/Role.php @@ -1,21 +1,29 @@ name; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Common/DataFixtures/TestEntity/User.php b/tests/Doctrine/Tests/Common/DataFixtures/TestEntity/User.php index ea8d3559..cf4a1a4b 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/TestEntity/User.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/TestEntity/User.php @@ -1,54 +1,70 @@ id = $id; } - + + public function getId() : ?int + { + return $this->id; + } + public function setCode($code) { $this->code = $code; } - + + public function getCode() : ?string + { + return $this->code; + } + public function setPassword($password) { $this->password = md5($password); @@ -93,7 +119,7 @@ public function getRole() } /** - * @return User[] + * @return User[]|Collection */ public function getReaders() { @@ -101,7 +127,8 @@ public function getReaders() } /** - * @param User[] $readers + * @param User[]|Collection $readers + * * @return User */ public function setReaders($readers) @@ -112,7 +139,7 @@ public function setReaders($readers) } /** - * @return User[] + * @return User[]|Collection */ public function getAuthors() { @@ -120,7 +147,8 @@ public function getAuthors() } /** - * @param User[] $authors + * @param User[]|Collection $authors + * * @return User */ public function setAuthors($authors) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/TestEntity/UserWithSchema.php b/tests/Doctrine/Tests/Common/DataFixtures/TestEntity/UserWithSchema.php index 9258a592..409fe9ae 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/TestEntity/UserWithSchema.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/TestEntity/UserWithSchema.php @@ -1,55 +1,71 @@ id = $id; } - + + public function getId() : ?int + { + return $this->id; + } + public function setCode($code) { $this->code = $code; } - + + public function getCode() : ?string + { + return $this->code; + } + public function setPassword($password) { $this->password = md5($password); @@ -94,7 +120,7 @@ public function getRole() } /** - * @return User[] + * @return UserWithSchema[]|Collection */ public function getReaders() { @@ -102,8 +128,9 @@ public function getReaders() } /** - * @param User[] $readers - * @return User + * @param UserWithSchema[]|Collection $readers + * + * @return UserWithSchema */ public function setReaders($readers) { @@ -113,7 +140,7 @@ public function setReaders($readers) } /** - * @return User[] + * @return UserWithSchema[]|Collection */ public function getAuthors() { @@ -121,8 +148,9 @@ public function getAuthors() } /** - * @param User[] $authors - * @return User + * @param UserWithSchema[]|Collection $authors + * + * @return UserWithSchema */ public function setAuthors($authors) { diff --git a/tests/Doctrine/Tests/Common/DataFixtures/TestFixtures/MyFixture1.php b/tests/Doctrine/Tests/Common/DataFixtures/TestFixtures/MyFixture1.php index 3cb00bad..bfa5be68 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/TestFixtures/MyFixture1.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/TestFixtures/MyFixture1.php @@ -1,5 +1,7 @@ setId(4); $admin->setCode('007'); $admin->setEmail('admin@example.com'); diff --git a/tests/Doctrine/Tests/Common/DataFixtures/TestPurgeEntity/ExcludedEntity.php b/tests/Doctrine/Tests/Common/DataFixtures/TestPurgeEntity/ExcludedEntity.php index 8999cfc5..f1143e46 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/TestPurgeEntity/ExcludedEntity.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/TestPurgeEntity/ExcludedEntity.php @@ -1,25 +1,31 @@ id = $id; } - - public function getId() { + + public function getId() + { return $this->id; } } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/TestPurgeEntity/IncludedEntity.php b/tests/Doctrine/Tests/Common/DataFixtures/TestPurgeEntity/IncludedEntity.php index 15125184..20bba90c 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/TestPurgeEntity/IncludedEntity.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/TestPurgeEntity/IncludedEntity.php @@ -1,25 +1,31 @@ id = $id; } - - public function getId() { + + public function getId() + { return $this->id; } } diff --git a/tests/Doctrine/Tests/Mock/Node.php b/tests/Doctrine/Tests/Mock/Node.php index 6dcad84a..64fbdc4a 100644 --- a/tests/Doctrine/Tests/Mock/Node.php +++ b/tests/Doctrine/Tests/Mock/Node.php @@ -1,23 +1,18 @@ */ class Node { - /** - * @var mixed - */ + /** @var mixed */ public $value; /** - * Constructor. - * * @param mixed $value */ public function __construct($value) From f4842c57c42f2ca43b827c1008d4da020ff86312 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 23 Oct 2019 21:57:23 +0200 Subject: [PATCH 7/9] Fix tests after fixing CS --- tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php | 4 ++-- .../Common/DataFixtures/Purger/ORMPurgerExcludeTest.php | 4 ++-- .../Tests/Common/DataFixtures/ReferenceRepositoryTest.php | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php b/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php index 40d38517..85e51541 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php @@ -22,7 +22,7 @@ abstract class BaseTest extends TestCase protected function getMockAnnotationReaderEntityManager() { $dbParams = ['driver' => 'pdo_sqlite', 'memory' => true]; - $config = Setup::createAnnotationMetadataConfiguration([__DIR__ . '/TestEntity'], true); + $config = Setup::createAnnotationMetadataConfiguration([__DIR__ . '/TestEntity'], true, null, null, false); return EntityManager::create($dbParams, $config); } @@ -37,7 +37,7 @@ protected function getMockAnnotationReaderEntityManager() protected function getMockSqliteEntityManager() { $dbParams = ['driver' => 'pdo_sqlite', 'memory' => true]; - $config = Setup::createAnnotationMetadataConfiguration([__DIR__ . '/TestEntity'], true); + $config = Setup::createAnnotationMetadataConfiguration([__DIR__ . '/TestEntity'], true, null, null, false); return EntityManager::create($dbParams, $config); } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php index 80f28e46..fcfbf2fc 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php @@ -32,7 +32,7 @@ protected function loadTestData() } $dbParams = ['driver' => 'pdo_sqlite', 'memory' => true]; - $config = Setup::createAnnotationMetadataConfiguration([__DIR__ . '/../TestPurgeEntity'], true); + $config = Setup::createAnnotationMetadataConfiguration([__DIR__ . '/../TestPurgeEntity'], true, null, null, false); $em = EntityManager::create($dbParams, $config); $connection = $em->getConnection(); @@ -118,7 +118,7 @@ public function testPurgeExcludeUsingList() public function testPurgeExcludeUsingFilterCallable() : void { $this->executeTestPurge(null, [], static function (string $table) : bool { - return preg_match('~^(?!ExcludedEntity)~', $table); + return (bool) preg_match('~^(?!ExcludedEntity)~', $table); }); } } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php b/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php index b1ba08f6..97ea6cd6 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php @@ -123,7 +123,7 @@ public function testUndefinedReference() $referenceRepository = new ReferenceRepository($this->getMockSqliteEntityManager()); $this->expectException(OutOfBoundsException::class); - $this->expectExceptionMessage('Reference to: (foo) does not exist'); + $this->expectExceptionMessage('Reference to "foo" does not exist'); $referenceRepository->getReference('foo'); } @@ -134,7 +134,7 @@ public function testThrowsExceptionAddingDuplicatedReference() $referenceRepository->addReference('duplicated_reference', new stdClass()); $this->expectException(BadMethodCallException::class); - $this->expectExceptionMessage('Reference to: (duplicated_reference) already exists, use method setReference in order to override it'); + $this->expectExceptionMessage('Reference to "duplicated_reference" already exists, use method setReference in order to override it'); $referenceRepository->addReference('duplicated_reference', new stdClass()); } @@ -144,7 +144,7 @@ public function testThrowsExceptionTryingToGetWrongReference() $referenceRepository = new ReferenceRepository($this->getMockSqliteEntityManager()); $this->expectException(OutOfBoundsException::class); - $this->expectExceptionMessage('Reference to: (missing_reference) does not exist'); + $this->expectExceptionMessage('Reference to "missing_reference" does not exist'); $referenceRepository->getReference('missing_reference'); } From daa1e95093338eb2ac937ff0a9dbd0dd2b6390ca Mon Sep 17 00:00:00 2001 From: "Jonathan H. Wage" Date: Fri, 15 Jun 2018 01:57:48 +0100 Subject: [PATCH 8/9] Update phpunit.xml --- phpunit.xml.dist | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 1236a734..1427ae9c 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,14 +1,9 @@ - @@ -19,7 +14,7 @@ - lib + ./lib/Doctrine/ From c84be3d47f9f370e33b3a72ae4c6cb1484d0362d Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 30 Oct 2019 19:43:53 +0100 Subject: [PATCH 9/9] Bump dependency to doctrine/common to latest version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6d3ec1fc..cebc0a9b 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ ], "require": { "php": "^7.2", - "doctrine/common": "~2.2" + "doctrine/common": "^2.11" }, "conflict": { "doctrine/phpcr-odm": "<1.3.0"