From 54cc61a3f2f28b102391ba4499737647ec6f6199 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 12 Dec 2014 19:46:48 +0100 Subject: [PATCH 001/129] #164 - PHPCR purger should expect fixture loading to use the transactional of doctrine/phpcr-odm#582 --- .../Executor/PHPCRExecutorTest.php | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php new file mode 100644 index 00000000..ab55b5b3 --- /dev/null +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php @@ -0,0 +1,86 @@ +. + */ + +namespace Doctrine\Tests\Common\DataFixtures\Executor; + +use Doctrine\Common\DataFixtures\Executor\PHPCRExecutor; +use Exception; +use PHPUnit_Framework_TestCase; + +/** + * Tests for {@see \Doctrine\Common\DataFixtures\Executor\PHPCRExecutor} + * + * @author Marco Pivetta + * + * @covers \Doctrine\Common\DataFixtures\Executor\PHPCRExecutor + */ +class PHPCRExecutorTest extends PHPUnit_Framework_TestCase +{ + public function testExecuteSingleFixtureWithNoPurge() + { + $dm = $this->getDocumentManager(); + $executor = new PHPCRExecutor($dm); + $fixture = $this->getMockFixture(); + + $fixture->expects($this->once())->method('load')->with($dm); + $dm + ->expects($this->once()) + ->method('transactional') + ->with($this->isType('callable')) + ->will($this->returnCallback(function ($callback) use ($dm) { + return $callback($dm); + })); + + $executor->execute(array($fixture), true); + } + + /** + * @return \Doctrine\Common\DataFixtures\Purger\PHPCRPurger|\PHPUnit_Framework_MockObject_MockObject + */ + private function getPurger() + { + return $this->getMock('Doctrine\Common\DataFixtures\Purger\PHPCRPurger', array(), array(), '', false); + } + + /** + * @return \Doctrine\ODM\PHPCR\DocumentManager|\PHPUnit_Framework_MockObject_MockObject + */ + private function getDocumentManager() + { + return $this->getMock( + 'Doctrine\ODM\PHPCR\DocumentManager', + array( + 'transactional', + 'flush', + 'clear', + ), + array(), + '', + false + ); + } + + /** + * @return \Doctrine\Common\DataFixtures\FixtureInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private function getMockFixture() + { + return $this->getMock('Doctrine\Common\DataFixtures\FixtureInterface', array(), array(), '', false); + } +} From 2895d6d00797b64d10f52bf680eee3ba1f6c0460 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 12 Dec 2014 19:47:55 +0100 Subject: [PATCH 002/129] #164 - PHPCR purger should expect fixture loading to use _a single_ the `DocumentManager#transactional()` call as of doctrine/phpcr-odm#582 --- .../Executor/PHPCRExecutorTest.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php index ab55b5b3..29e547e1 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php @@ -50,6 +50,26 @@ public function testExecuteSingleFixtureWithNoPurge() $executor->execute(array($fixture), true); } + public function testExecuteMultipleFixturesWithNoPurge() + { + $dm = $this->getDocumentManager(); + $executor = new PHPCRExecutor($dm); + $fixture1 = $this->getMockFixture(); + $fixture2 = $this->getMockFixture(); + + $fixture1->expects($this->once())->method('load')->with($dm); + $fixture2->expects($this->once())->method('load')->with($dm); + $dm + ->expects($this->once()) + ->method('transactional') + ->with($this->isType('callable')) + ->will($this->returnCallback(function ($callback) use ($dm) { + return $callback($dm); + })); + + $executor->execute(array($fixture1, $fixture2), true); + } + /** * @return \Doctrine\Common\DataFixtures\Purger\PHPCRPurger|\PHPUnit_Framework_MockObject_MockObject */ From c8d203a25fb05810706ea3f3c13af6ccff491078 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 12 Dec 2014 19:48:31 +0100 Subject: [PATCH 003/129] #164 - PHPCR executor should expect purging to use a `DocumentManager#transactional()` call as of doctrine/phpcr-odm#582 --- .../Executor/PHPCRExecutorTest.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php index 29e547e1..8ac291fc 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php @@ -70,6 +70,26 @@ public function testExecuteMultipleFixturesWithNoPurge() $executor->execute(array($fixture1, $fixture2), true); } + public function testExecuteFixtureWithPurge() + { + $dm = $this->getDocumentManager(); + $purger = $this->getPurger(); + $executor = new PHPCRExecutor($dm, $purger); + $fixture = $this->getMockFixture(); + + $fixture->expects($this->once())->method('load')->with($dm); + $dm + ->expects($this->once()) + ->method('transactional') + ->with($this->isType('callable')) + ->will($this->returnCallback(function ($callback) use ($dm) { + return $callback($dm); + })); + $purger->expects($this->once())->method('purge'); + + $executor->execute(array($fixture), false); + } + /** * @return \Doctrine\Common\DataFixtures\Purger\PHPCRPurger|\PHPUnit_Framework_MockObject_MockObject */ From 53e758f74933031b5fc6f3b924a5e366c6c3beb7 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 12 Dec 2014 19:49:38 +0100 Subject: [PATCH 004/129] #164 - PHPCR executor should skip purging when told to do so --- .../Executor/PHPCRExecutorTest.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php index 8ac291fc..285e5321 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php @@ -90,6 +90,26 @@ public function testExecuteFixtureWithPurge() $executor->execute(array($fixture), false); } + public function testExecuteFixtureWithoutPurge() + { + $dm = $this->getDocumentManager(); + $purger = $this->getPurger(); + $executor = new PHPCRExecutor($dm, $purger); + $fixture = $this->getMockFixture(); + + $fixture->expects($this->once())->method('load')->with($dm); + $dm + ->expects($this->once()) + ->method('transactional') + ->with($this->isType('callable')) + ->will($this->returnCallback(function ($callback) use ($dm) { + return $callback($dm); + })); + $purger->expects($this->never())->method('purge'); + + $executor->execute(array($fixture), true); + } + /** * @return \Doctrine\Common\DataFixtures\Purger\PHPCRPurger|\PHPUnit_Framework_MockObject_MockObject */ From 444e159ca7d067419bbd4bd15b5a888a6baecebb Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 12 Dec 2014 19:50:09 +0100 Subject: [PATCH 005/129] #164 - PHPCR executor should stop loading/purging when `DocumentManager#transactional()`fails, as of doctrine/phpcr-odm#582 --- .../Executor/PHPCRExecutorTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php index 285e5321..e03dd3fc 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php @@ -110,6 +110,25 @@ public function testExecuteFixtureWithoutPurge() $executor->execute(array($fixture), true); } + public function testFailedTransactionalStopsPurgingAndFixtureLoading() + { + $dm = $this->getDocumentManager(); + $purger = $this->getPurger(); + $executor = new PHPCRExecutor($dm, $purger); + $fixture = $this->getMockFixture(); + $exception = new Exception(); + + $fixture->expects($this->never())->method('load'); + $dm->expects($this->once())->method('transactional')->will($this->throwException($exception)); + $purger->expects($this->never())->method('purge'); + + try { + $executor->execute(array($fixture), true); + } catch (\Exception $caughtException) { + $this->assertSame($exception, $caughtException); + } + } + /** * @return \Doctrine\Common\DataFixtures\Purger\PHPCRPurger|\PHPUnit_Framework_MockObject_MockObject */ From aa58c8ea5e9eaad4c1bfeb4112a74dd674289ea6 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 12 Dec 2014 19:50:59 +0100 Subject: [PATCH 006/129] #164 - Wrap `PHPCRExecutor#execute()` body with a `DocumentManager#transactional()` call as of doctrine/phpcr-odm#582 --- .../DataFixtures/Executor/PHPCRExecutor.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php b/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php index ec8ff63c..7b7e65c7 100644 --- a/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php +++ b/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php @@ -58,12 +58,18 @@ public function getObjectManager() /** @inheritDoc */ public function execute(array $fixtures, $append = false) { - if ($append === false) { - $this->purge(); - } - foreach ($fixtures as $fixture) { - $this->load($this->dm, $fixture); - } + $purger = $this->purger; + $that = $this; + + $this->dm->transactional(function ($dm) use ($purger, $append, $that, $fixtures) { + if ($append === false) { + $this->purge(); + } + + foreach ($fixtures as $fixture) { + $that->load($dm, $fixture); + } + }); } } From db049e4bb7868db009e161316aac2f8dbeca7b23 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 25 Mar 2015 21:23:24 +0000 Subject: [PATCH 007/129] #164 #165 - making sure that the `Doctrine\ODM\PHPCR\DocumentManager` definitions are available --- .../Executor/PHPCRExecutorTest.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php index e03dd3fc..b5d7df98 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php @@ -142,6 +142,8 @@ private function getPurger() */ private function getDocumentManager() { + $this->loadDocumentManagerClass(); + return $this->getMock( 'Doctrine\ODM\PHPCR\DocumentManager', array( @@ -162,4 +164,39 @@ private function getMockFixture() { return $this->getMock('Doctrine\Common\DataFixtures\FixtureInterface', array(), array(), '', false); } + + /** + * Ensures that the {@see \Doctrine\ODM\PHPCR\DocumentManager} class exists + */ + private function loadDocumentManagerClass() + { + + if (class_exists('Doctrine\ODM\PHPCR\DocumentManager')) { + return; + } + + // hold my beer while I do some mocking + eval( + <<<'PHP' +namespace Doctrine\ODM\PHPCR; + +class DocumentManager implements \Doctrine\Common\Persistence\ObjectManager +{ + public function find($className, $id) {} + public function persist($object) {} + public function remove($object) {} + public function merge($object) {} + public function clear($objectName = null) {} + public function detach($object) {} + public function refresh($object) {} + public function flush() {} + public function getRepository($className) {} + public function getClassMetadata($className) {} + public function getMetadataFactory() {} + public function initializeObject($obj) {} + public function contains($object) {} +} +PHP + ); + } } From 04e839a07f6ad6bcc87627362ef2f6c1e98fbc92 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 25 Mar 2015 21:23:53 +0000 Subject: [PATCH 008/129] #164 #165 - PHP 5.3 compat: `$this` is not accessible in closure scope --- .../Common/DataFixtures/Executor/PHPCRExecutor.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php b/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php index 7b7e65c7..99e7342e 100644 --- a/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php +++ b/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php @@ -58,12 +58,11 @@ public function getObjectManager() /** @inheritDoc */ public function execute(array $fixtures, $append = false) { - $purger = $this->purger; - $that = $this; + $that = $this; - $this->dm->transactional(function ($dm) use ($purger, $append, $that, $fixtures) { + $this->dm->transactional(function ($dm) use ($append, $that, $fixtures) { if ($append === false) { - $this->purge(); + $that->purge(); } foreach ($fixtures as $fixture) { From 130b37502f5bd55ed450018e47b2809bc286a47a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lavoie?= Date: Fri, 27 Mar 2015 17:17:38 -0400 Subject: [PATCH 009/129] Added a conflict on doctrim/orm < 2.4 --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index 2aade9b8..f5cd58ed 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,9 @@ "require-dev": { "doctrine/orm": "~2.4" }, + "conflict": { + "doctrine/orm": "< 2.4" + }, "suggest": { "doctrine/orm": "For loading ORM fixtures", "doctrine/mongodb-odm": "For loading MongoDB ODM fixtures", From 9143567eadef83e1cf5e896a9b5739308bc457fd Mon Sep 17 00:00:00 2001 From: Gerry Vandermaesen Date: Thu, 24 Oct 2013 17:08:09 +0200 Subject: [PATCH 010/129] Changed the MongoDBPurger class to only clear collections, not remove them. Instead of dropping all collections, we should remove all documents in a collection instead. This avoids problems where indexes are lost while dropping the collection, and collections not being recreated (with a schema create tool) while loading fixtures. Changed MongoDBPurge to drop + ensureIndexes --- lib/Doctrine/Common/DataFixtures/Purger/MongoDBPurger.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Doctrine/Common/DataFixtures/Purger/MongoDBPurger.php b/lib/Doctrine/Common/DataFixtures/Purger/MongoDBPurger.php index 8883ab8b..4229e800 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/MongoDBPurger.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/MongoDBPurger.php @@ -70,5 +70,6 @@ public function purge() $this->dm->getDocumentCollection($metadata->name)->drop(); } } + $this->dm->getSchemaManager()->ensureIndexes(); } } From 1a94cab4cc1775214e2d40f160ccbe8724319d08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lavoie?= Date: Sat, 28 Mar 2015 16:08:35 -0400 Subject: [PATCH 011/129] added MongoDB test (including MongoDBPurgerTest) --- .travis.yml | 9 ++- .../DataFixtures/Purger/MongoDBPurgerTest.php | 67 +++++++++++++++++++ .../Common/DataFixtures/TestDocument/Role.php | 37 ++++++++++ 3 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/Tests/Common/DataFixtures/Purger/MongoDBPurgerTest.php create mode 100644 tests/Doctrine/Tests/Common/DataFixtures/TestDocument/Role.php diff --git a/.travis.yml b/.travis.yml index 753ffcc0..6bbd8f03 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,13 @@ php: - 5.6 - hhvm -install: composer install +services: mongodb + +before_install: + - "[ $TRAVIS_PHP_VERSION = 'hhvm' ] || echo 'extension = mongo.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini" + +install: + - composer install --dev + - "[ $TRAVIS_PHP_VERSION = 'hhvm' ] || composer require 'doctrine/mongodb-odm' '*@beta'" script: phpunit -v diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Purger/MongoDBPurgerTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Purger/MongoDBPurgerTest.php new file mode 100644 index 00000000..42b7d972 --- /dev/null +++ b/tests/Doctrine/Tests/Common/DataFixtures/Purger/MongoDBPurgerTest.php @@ -0,0 +1,67 @@ +markTestSkipped('Missing doctrine/mongodb-odm'); + } + + $root = dirname(dirname(dirname(dirname(dirname(__DIR__))))); + + $config = new Configuration(); + $config->setProxyDir($root . '/generate/proxies'); + $config->setProxyNamespace('Proxies'); + $config->setHydratorDir($root . '/generate/hydrators'); + $config->setHydratorNamespace('Hydrators'); + $config->setMetadataDriverImpl(AnnotationDriver::create(dirname(__DIR__) . '/TestDocument')); + AnnotationDriver::registerAnnotationClasses(); + + $dm = DocumentManager::create(null, $config); + if (!$dm->getConnection()->connect()) { + $this->markTestSkipped('Unable to connect to MongoDB'); + } + + return $dm; + } + + private function getPurger() + { + return new MongoDBPurger($this->getDocumentManager()); + } + + public function testPurgeKeepsIndices() + { + $purger = $this->getPurger(); + $dm = $purger->getObjectManager(); + + $collection = $dm->getDocumentCollection(self::TEST_DOCUMENT_ROLE); + $collection->drop(); + + $this->assertCount(0, $collection->getIndexInfo()); + + $role = new Role; + $role->setName('role'); + $dm->persist($role); + $dm->flush(); + + $schema = $dm->getSchemaManager()->ensureDocumentIndexes(self::TEST_DOCUMENT_ROLE); + $this->assertCount(2, $collection->getIndexInfo()); + + $purger->purge(); + $this->assertCount(2, $collection->getIndexInfo()); + } +} diff --git a/tests/Doctrine/Tests/Common/DataFixtures/TestDocument/Role.php b/tests/Doctrine/Tests/Common/DataFixtures/TestDocument/Role.php new file mode 100644 index 00000000..463cd610 --- /dev/null +++ b/tests/Doctrine/Tests/Common/DataFixtures/TestDocument/Role.php @@ -0,0 +1,37 @@ +id; + } + + public function setName($name) + { + $this->name = $name; + } + + public function getName() + { + return $this->name; + } +} From 70020ae434da2e87fb62b40aba1211ef4fb04182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lavoie?= Date: Sat, 28 Mar 2015 18:24:17 -0400 Subject: [PATCH 012/129] bumped branch-alias to 1.1.x-dev --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f5cd58ed..b67bec8a 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.1.x-dev" } } } From fbe42159145de18016dc79e726a3694f96c94b22 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Mon, 30 Mar 2015 11:38:55 +0200 Subject: [PATCH 013/129] handle older versions of phpcr-odm --- .../Common/DataFixtures/Executor/PHPCRExecutor.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php b/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php index 99e7342e..cef09975 100644 --- a/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php +++ b/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php @@ -60,7 +60,7 @@ public function execute(array $fixtures, $append = false) { $that = $this; - $this->dm->transactional(function ($dm) use ($append, $that, $fixtures) { + $function = function ($dm) use ($append, $that, $fixtures) { if ($append === false) { $that->purge(); } @@ -68,7 +68,13 @@ public function execute(array $fixtures, $append = false) foreach ($fixtures as $fixture) { $that->load($dm, $fixture); } - }); + }; + + if (method_exists($this->dm, 'transactional')) { + $this->dm->transactional($function); + } else { + $function($this->dm); + } } } From 7c4d7c863dc1b07241d9ce6d9a1ff0b439805b78 Mon Sep 17 00:00:00 2001 From: plfort Date: Wed, 8 Apr 2015 14:59:00 +0200 Subject: [PATCH 014/129] Use QuoteStrategy from Configuration to get table names --- .../Common/DataFixtures/Purger/ORMPurger.php | 34 +++-- .../DataFixtures/Purger/ORMPurgerTest.php | 24 +++- .../TestEntity/UserWithSchema.php | 133 ++++++++++++++++++ 3 files changed, 180 insertions(+), 11 deletions(-) create mode 100644 tests/Doctrine/Tests/Common/DataFixtures/TestEntity/UserWithSchema.php diff --git a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php index 90633896..3934d6ab 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php @@ -23,6 +23,7 @@ use Doctrine\ORM\Internal\CommitOrderCalculator; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\ORM\Mapping\ClassMetadataInfo; /** * Class responsible for purging databases of data before reloading data fixtures. @@ -127,8 +128,8 @@ public function purge() ) { continue; } - - $orderedTables[] = $class->getQuotedTableName($platform); + + $orderedTables[] = $this->getTableName($class, $platform); } foreach($orderedTables as $tbl) { @@ -194,19 +195,36 @@ private function getCommitOrder(EntityManagerInterface $em, array $classes) private function getAssociationTables(array $classes, AbstractPlatform $platform) { $associationTables = array(); - + foreach ($classes as $class) { foreach ($class->associationMappings as $assoc) { if ($assoc['isOwningSide'] && $assoc['type'] == ClassMetadata::MANY_TO_MANY) { - if (isset($assoc['joinTable']['schema'])) { - $associationTables[] = $assoc['joinTable']['schema'] . '.' . $class->getQuotedJoinTableName($assoc, $platform); - } else { - $associationTables[] = $class->getQuotedJoinTableName($assoc, $platform); - } + $associationTables[] = $this->getJoinTableName($assoc, $class, $platform); } } } return $associationTables; } + + /** + * + * @param \Doctrine\ORM\Mapping\ClassMetadata $class + * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform + * @return string + */ + private function 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 + * @return string + */ + private function getJoinTableName($assoc, $class, $platform){ + return $this->em->getConfiguration()->getQuoteStrategy()->getJoinTableName($assoc, $class, $platform); + } } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerTest.php index ac2ae791..353ea4cd 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerTest.php @@ -5,6 +5,8 @@ use Doctrine\Common\DataFixtures\Purger\ORMPurger; use ReflectionClass; +use Doctrine\ORM\EntityManager; +use Doctrine\ORM\Tools\Setup; /** * Doctrine\Tests\Common\DataFixtures\ORMPurgerTest @@ -14,31 +16,47 @@ class ORMPurgerTest extends BaseTest { const TEST_ENTITY_USER = 'Doctrine\Tests\Common\DataFixtures\TestEntity\User'; + const TEST_ENTITY_USER_WITH_SCHEMA = 'Doctrine\Tests\Common\DataFixtures\TestEntity\UserWithSchema'; const TEST_ENTITY_QUOTED = 'Doctrine\Tests\Common\DataFixtures\TestEntity\Quoted'; + public function testGetAssociationTables() { $em = $this->getMockAnnotationReaderEntityManager(); $metadata = $em->getClassMetadata(self::TEST_ENTITY_USER); $platform = $em->getConnection()->getDatabasePlatform(); - $purger = new ORMPurger(); + $purger = new ORMPurger($em); $class = new ReflectionClass('Doctrine\Common\DataFixtures\Purger\ORMPurger'); $method = $class->getMethod('getAssociationTables'); $method->setAccessible(true); $associationTables = $method->invokeArgs($purger, array(array($metadata), $platform)); $this->assertEquals($associationTables[0], 'readers.author_reader'); } - + public function testGetAssociationTablesQuoted() { $em = $this->getMockAnnotationReaderEntityManager(); $metadata = $em->getClassMetadata(self::TEST_ENTITY_QUOTED); $platform = $em->getConnection()->getDatabasePlatform(); - $purger = new ORMPurger(); + $purger = new ORMPurger($em); $class = new ReflectionClass('Doctrine\Common\DataFixtures\Purger\ORMPurger'); $method = $class->getMethod('getAssociationTables'); $method->setAccessible(true); $associationTables = $method->invokeArgs($purger, array(array($metadata), $platform)); $this->assertEquals($associationTables[0], '"INSERT"'); } + + public function testTableNameWithSchema() + { + $em = $this->getMockAnnotationReaderEntityManager(); + $metadata = $em->getClassMetadata(self::TEST_ENTITY_USER_WITH_SCHEMA); + $platform = $em->getConnection()->getDatabasePlatform(); + $purger = new ORMPurger($em); + $class = new ReflectionClass('Doctrine\Common\DataFixtures\Purger\ORMPurger'); + $method = $class->getMethod('getTableName'); + $method->setAccessible(true); + $tableName = $method->invokeArgs($purger, array($metadata, $platform)); + $this->assertStringStartsWith('test_schema',$tableName); + } + } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/TestEntity/UserWithSchema.php b/tests/Doctrine/Tests/Common/DataFixtures/TestEntity/UserWithSchema.php new file mode 100644 index 00000000..9258a592 --- /dev/null +++ b/tests/Doctrine/Tests/Common/DataFixtures/TestEntity/UserWithSchema.php @@ -0,0 +1,133 @@ +id = $id; + } + + public function setCode($code) + { + $this->code = $code; + } + + public function setPassword($password) + { + $this->password = md5($password); + } + + public function getPassword() + { + return $this->password; + } + + public function setEmail($email) + { + $this->email = $email; + } + + public function getEmail() + { + return $this->email; + } + + public function setRole(Role $role) + { + $this->role = $role; + } + + public function getRole() + { + return $this->role; + } + + /** + * @return User[] + */ + public function getReaders() + { + return $this->readers; + } + + /** + * @param User[] $readers + * @return User + */ + public function setReaders($readers) + { + $this->readers = $readers; + + return $this; + } + + /** + * @return User[] + */ + public function getAuthors() + { + return $this->authors; + } + + /** + * @param User[] $authors + * @return User + */ + public function setAuthors($authors) + { + $this->authors = $authors; + + return $this; + } +} From 20fa6a422e1b000df7c325ef00e46fe24b6076ac Mon Sep 17 00:00:00 2001 From: Denis Medved Date: Fri, 26 Jun 2015 17:09:20 +0300 Subject: [PATCH 015/129] fix DELETE sql query --- lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php index 90633896..f7ba9748 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php @@ -133,7 +133,7 @@ public function purge() foreach($orderedTables as $tbl) { if ($this->purgeMode === self::PURGE_MODE_DELETE) { - $this->em->getConnection()->executeUpdate("DELETE FROM " . $tbl); + $this->em->getConnection()->executeUpdate('DELETE FROM `' . $tbl . '`'); } else { $this->em->getConnection()->executeUpdate($platform->getTruncateTableSQL($tbl, true)); } From 495ca6e84c1c3adc1ed3ea3df806fa8bf34f829e Mon Sep 17 00:00:00 2001 From: Denis Medved Date: Fri, 26 Jun 2015 17:54:34 +0300 Subject: [PATCH 016/129] add quote for table name --- lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php index f7ba9748..d1d988f2 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php @@ -131,11 +131,13 @@ public function purge() $orderedTables[] = $class->getQuotedTableName($platform); } + $connection = $this->em->getConnection(); foreach($orderedTables as $tbl) { if ($this->purgeMode === self::PURGE_MODE_DELETE) { - $this->em->getConnection()->executeUpdate('DELETE FROM `' . $tbl . '`'); + $tbl = $connection->quoteIdentifier($tbl); + $connection->executeUpdate('DELETE FROM ' . $tbl ); } else { - $this->em->getConnection()->executeUpdate($platform->getTruncateTableSQL($tbl, true)); + $connection->executeUpdate($platform->getTruncateTableSQL($tbl, true)); } } } From e82a024cd268d05adc096ad52507ae29c3130caa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sat, 11 Jul 2015 22:47:58 +0200 Subject: [PATCH 017/129] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5ad95c85..2f873d2e 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ [![Build Status](https://travis-ci.org/doctrine/data-fixtures.png)](https://travis-ci.org/doctrine/data-fixtures) This extension aims to provide a simple way to manage and execute the loading of data fixtures -for the Doctrine ORM or ODM. You can write fixture classes by implementing the -Doctrine\Common\DataFixtures\FixtureInterface interface: +for the [Doctrine ORM or ODM](http://www.doctrine-project.org/). You can write fixture classes +by implementing the [`Doctrine\Common\DataFixtures\FixtureInterface`](lib/Doctrine/Common/DataFixtures/FixtureInterface.php) interface: ```php namespace MyDataFixtures; @@ -12,7 +12,7 @@ namespace MyDataFixtures; use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\DataFixtures\FixtureInterface; -class LoadUserData implements FixtureInterface +class UserFixtureLoader implements FixtureInterface { public function load(ObjectManager $manager) { From b424cc40c688b6c34f68e098c001ca30693c2962 Mon Sep 17 00:00:00 2001 From: aramalipoor Date: Tue, 4 Aug 2015 15:00:41 +0430 Subject: [PATCH 018/129] Use contains() when document manager is of Phpcr --- .../DataFixtures/ReferenceRepository.php | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php b/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php index d3df4bd1..6385ed7e 100644 --- a/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php +++ b/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php @@ -20,6 +20,7 @@ namespace Doctrine\Common\DataFixtures; use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\ODM\PHPCR\DocumentManager as PhpcrDocumentManager; /** * ReferenceRepository class manages references for @@ -75,7 +76,7 @@ public function __construct(ObjectManager $manager) protected function getIdentifier($reference, $uow) { // In case Reference is not yet managed in UnitOfWork - if ( ! $uow->isInIdentityMap($reference)) { + if ( ! $this->hasIdentifier($reference)) { $class = $this->manager->getClassMetadata(get_class($reference)); return $class->getIdentifierValues($reference); @@ -101,9 +102,10 @@ protected function getIdentifier($reference, $uow) public function setReference($name, $reference) { $this->references[$name] = $reference; - // in case if reference is set after flush, store its identity - $uow = $this->manager->getUnitOfWork(); - if ($uow->isInIdentityMap($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); } } @@ -158,14 +160,15 @@ public function getReference($name) $reference = $this->references[$name]; $meta = $this->manager->getClassMetadata(get_class($reference)); - $uow = $this->manager->getUnitOfWork(); - if (!$uow->isInIdentityMap($reference) && isset($this->identities[$name])) { + + if (!$this->manager->contains($reference) && isset($this->identities[$name])) { $reference = $this->manager->getReference( $meta->name, $this->identities[$name] ); $this->references[$name] = $reference; // already in identity map } + return $reference; } @@ -232,4 +235,23 @@ public function getManager() { return $this->manager; } + + /** + * Checks if object has identifier already in unit of work. + * + * @param $reference + * + * @return bool + */ + private function hasIdentifier($reference) + { + // in case if reference is set after flush, store its identity + $uow = $this->manager->getUnitOfWork(); + + if ($this->manager instanceof PhpcrDocumentManager) { + return $uow->contains($reference); + } else { + return $uow->isInIdentityMap($reference); + } + } } From ce786648c306f38b8106ed32bfe107dc307828b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Mon, 17 Aug 2015 14:48:27 +0100 Subject: [PATCH 019/129] Update ORMExecutor.php --- lib/Doctrine/Common/DataFixtures/Executor/ORMExecutor.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Doctrine/Common/DataFixtures/Executor/ORMExecutor.php b/lib/Doctrine/Common/DataFixtures/Executor/ORMExecutor.php index c180a100..26990c72 100644 --- a/lib/Doctrine/Common/DataFixtures/Executor/ORMExecutor.php +++ b/lib/Doctrine/Common/DataFixtures/Executor/ORMExecutor.php @@ -31,6 +31,11 @@ */ class ORMExecutor extends AbstractExecutor { + /** + * @var EntityManagerInterface + */ + private $em; + /** * Construct new fixtures loader instance. * From fbeae005922ba2b7ee607e6b50817a90889edf68 Mon Sep 17 00:00:00 2001 From: Alexandre Segura Date: Fri, 21 Aug 2015 11:35:39 +0200 Subject: [PATCH 020/129] Fix getTableName & getJoinTableName for Doctrine 2.4.* - Verify if getSchemaName method exists before calling QuoteStrategy - Skip ORMPurgerTest::testTableNameWithSchema when testing for Doctrine < 2.5.0 --- .../Common/DataFixtures/Purger/ORMPurger.php | 26 +++++++++++++------ .../DataFixtures/Purger/ORMPurgerTest.php | 12 ++++++--- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php index 3934d6ab..c9ff00bf 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php @@ -128,7 +128,7 @@ public function purge() ) { continue; } - + $orderedTables[] = $this->getTableName($class, $platform); } @@ -195,7 +195,7 @@ private function getCommitOrder(EntityManagerInterface $em, array $classes) private function getAssociationTables(array $classes, AbstractPlatform $platform) { $associationTables = array(); - + foreach ($classes as $class) { foreach ($class->associationMappings as $assoc) { if ($assoc['isOwningSide'] && $assoc['type'] == ClassMetadata::MANY_TO_MANY) { @@ -206,25 +206,35 @@ private function getAssociationTables(array $classes, AbstractPlatform $platform return $associationTables; } - + /** - * + * * @param \Doctrine\ORM\Mapping\ClassMetadata $class * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform * @return string */ - private function getTableName($class, $platform){ + 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); + } + return $this->em->getConfiguration()->getQuoteStrategy()->getTableName($class, $platform); } - + /** - * + * * @param array $association * @param \Doctrine\ORM\Mapping\ClassMetadata $class * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform * @return string */ - private function getJoinTableName($assoc, $class, $platform){ + 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); + } + return $this->em->getConfiguration()->getQuoteStrategy()->getJoinTableName($assoc, $class, $platform); } } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerTest.php index 353ea4cd..89223656 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerTest.php @@ -4,6 +4,7 @@ namespace Doctrine\Tests\Common\DataFixtures; use Doctrine\Common\DataFixtures\Purger\ORMPurger; +use Doctrine\ORM\Version as ORMVersion; use ReflectionClass; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Tools\Setup; @@ -19,7 +20,7 @@ class ORMPurgerTest extends BaseTest const TEST_ENTITY_USER_WITH_SCHEMA = 'Doctrine\Tests\Common\DataFixtures\TestEntity\UserWithSchema'; const TEST_ENTITY_QUOTED = 'Doctrine\Tests\Common\DataFixtures\TestEntity\Quoted'; - + public function testGetAssociationTables() { $em = $this->getMockAnnotationReaderEntityManager(); @@ -32,7 +33,7 @@ public function testGetAssociationTables() $associationTables = $method->invokeArgs($purger, array(array($metadata), $platform)); $this->assertEquals($associationTables[0], 'readers.author_reader'); } - + public function testGetAssociationTablesQuoted() { $em = $this->getMockAnnotationReaderEntityManager(); @@ -45,9 +46,14 @@ public function testGetAssociationTablesQuoted() $associationTables = $method->invokeArgs($purger, array(array($metadata), $platform)); $this->assertEquals($associationTables[0], '"INSERT"'); } - + public function testTableNameWithSchema() { + $isDoctrine25 = (ORMVersion::compare('2.5.0') <= 0); + if (!$isDoctrine25) { + $this->markTestSkipped('@Table schema attribute is not supported in Doctrine < 2.5.0'); + } + $em = $this->getMockAnnotationReaderEntityManager(); $metadata = $em->getClassMetadata(self::TEST_ENTITY_USER_WITH_SCHEMA); $platform = $em->getConnection()->getDatabasePlatform(); From 0a932cc4ff7867bb0c1ebd219ac051b0163b0eca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Votruba?= Date: Thu, 8 Oct 2015 15:23:38 +0200 Subject: [PATCH 021/129] travis: PHP 7.0 nightly added, consistent indenting --- .travis.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6bbd8f03..d90b2006 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,15 +11,17 @@ php: - 5.4 - 5.5 - 5.6 + - 7.0 - hhvm services: mongodb before_install: - - "[ $TRAVIS_PHP_VERSION = 'hhvm' ] || echo 'extension = mongo.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini" + - "if [[ $TRAVIS_PHP_VERSION != 'hhvm' && $TRAVIS_PHP_VERSION != '7.0' ]]; then echo 'extension = mongo.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi" install: - - composer install --dev - - "[ $TRAVIS_PHP_VERSION = 'hhvm' ] || composer require 'doctrine/mongodb-odm' '*@beta'" + - composer install --dev + - "if [[ $TRAVIS_PHP_VERSION != 'hhvm' && $TRAVIS_PHP_VERSION != '7.0' ]]; then composer require 'doctrine/mongodb-odm' '*@beta'; fi" -script: phpunit -v +script: + - phpunit From 5db2ca9f0318ae8eaeb44b80565ddfcd8e06cb01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Votruba?= Date: Fri, 9 Oct 2015 00:32:28 +0200 Subject: [PATCH 022/129] travis: add PHPUnit verbose mode --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d90b2006..1ed77744 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,4 +24,4 @@ install: - "if [[ $TRAVIS_PHP_VERSION != 'hhvm' && $TRAVIS_PHP_VERSION != '7.0' ]]; then composer require 'doctrine/mongodb-odm' '*@beta'; fi" script: - - phpunit + - phpunit -v From 084080c11c1055d603b052b7cd645f634ea2ec43 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 23 Oct 2015 16:24:23 +0200 Subject: [PATCH 023/129] typo --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2f873d2e..41474a02 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ use Doctrine\Common\DataFixtures\Loader; use MyDataFixtures\LoadUserData; $loader = new Loader(); -$loader->addFixture(new LoadUserData); +$loader->addFixture(new LoadUserData()); ``` You can load a set of fixtures from a directory as well: @@ -89,7 +89,7 @@ class LoadUserRoleData extends AbstractFixture $adminRole = new Role(); $adminRole->setName('admin'); - $anonymousRole = new Role; + $anonymousRole = new Role(); $anonymousRole->setName('anonymous'); $manager->persist($adminRole); From 6cc88767dff248b5dd9cdbc355249efe4a4ab1b5 Mon Sep 17 00:00:00 2001 From: Jenn Date: Fri, 23 Oct 2015 23:22:18 -0400 Subject: [PATCH 024/129] Update LICENSE updated copyright year from 2012 to 2015 --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 813d3883..2336c7fc 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2006-2012 Doctrine Project +Copyright (c) 2006-2015 Doctrine Project Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in From d230cb65a4e748fc26e8112d4b6f8c28cac975c7 Mon Sep 17 00:00:00 2001 From: Ben Davies Date: Wed, 4 May 2016 09:31:03 +0100 Subject: [PATCH 025/129] quoteIdentifier not required. already done by QuoteStrategy --- lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php index 2c1ef71f..aaae3075 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php @@ -135,8 +135,7 @@ public function purge() $connection = $this->em->getConnection(); foreach($orderedTables as $tbl) { if ($this->purgeMode === self::PURGE_MODE_DELETE) { - $tbl = $connection->quoteIdentifier($tbl); - $connection->executeUpdate('DELETE FROM ' . $tbl ); + $connection->executeUpdate('DELETE FROM ' . $tbl); } else { $connection->executeUpdate($platform->getTruncateTableSQL($tbl, true)); } From 987e5f35142ac4ac5dc60a16d1eb18293964bc25 Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Wed, 4 May 2016 22:11:45 +0000 Subject: [PATCH 026/129] Bring own implementation of TopologicalSorter to data-fixtures library --- .travis.yml | 7 +- composer.json | 3 +- .../Common/DataFixtures/Purger/ORMPurger.php | 26 +-- .../DataFixtures/Sorter/TopologicalSorter.php | 198 ++++++++++++++++++ .../Sorter/TopologicalSorterTest.php | 134 ++++++++++++ tests/Doctrine/Tests/Mock/Node.php | 44 ++++ 6 files changed, 395 insertions(+), 17 deletions(-) create mode 100644 lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php create mode 100644 tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php create mode 100644 tests/Doctrine/Tests/Mock/Node.php diff --git a/.travis.yml b/.travis.yml index 1ed77744..09308483 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,9 +19,10 @@ services: mongodb before_install: - "if [[ $TRAVIS_PHP_VERSION != 'hhvm' && $TRAVIS_PHP_VERSION != '7.0' ]]; then echo 'extension = mongo.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi" -install: - - composer install --dev +before_script: + - composer self-update + - composer install --prefer-source - "if [[ $TRAVIS_PHP_VERSION != 'hhvm' && $TRAVIS_PHP_VERSION != '7.0' ]]; then composer require 'doctrine/mongodb-odm' '*@beta'; fi" script: - - phpunit -v + - ./vendor/bin/phpunit -v diff --git a/composer.json b/composer.json index b67bec8a..f7bf27ed 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,8 @@ "doctrine/common": "~2.2" }, "require-dev": { - "doctrine/orm": "~2.4" + "doctrine/orm": "~2.4", + "phpunit/phpunit": "^4.0|^5.0" }, "conflict": { "doctrine/orm": "< 2.4" diff --git a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php index 2c1ef71f..d20d3d19 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php @@ -20,7 +20,7 @@ namespace Doctrine\Common\DataFixtures\Purger; use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\Internal\CommitOrderCalculator; +use Doctrine\Common\DataFixtures\Sorter\TopologicalSorter; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\ORM\Mapping\ClassMetadataInfo; @@ -145,48 +145,48 @@ public function purge() private function getCommitOrder(EntityManagerInterface $em, array $classes) { - $calc = new CommitOrderCalculator; + $calc = new TopologicalSorter(); foreach ($classes as $class) { - $calc->addClass($class); + $calc->addNode($class->name, $class); // $class before its parents foreach ($class->parentClasses as $parentClass) { $parentClass = $em->getClassMetadata($parentClass); - if ( ! $calc->hasClass($parentClass->name)) { - $calc->addClass($parentClass); + if ( ! $calc->hasNode($parentClass->name)) { + $calc->addNode($parentClass->name, $parentClass); } - $calc->addDependency($class, $parentClass); + $calc->addDependency($class->name, $parentClass->name); } foreach ($class->associationMappings as $assoc) { if ($assoc['isOwningSide']) { $targetClass = $em->getClassMetadata($assoc['targetEntity']); - if ( ! $calc->hasClass($targetClass->name)) { - $calc->addClass($targetClass); + if ( ! $calc->hasNode($targetClass->name)) { + $calc->addNode($targetClass->name, $targetClass); } // add dependency ($targetClass before $class) - $calc->addDependency($targetClass, $class); + $calc->addDependency($targetClass->name, $class->name); // parents of $targetClass before $class, too foreach ($targetClass->parentClasses as $parentClass) { $parentClass = $em->getClassMetadata($parentClass); - if ( ! $calc->hasClass($parentClass->name)) { - $calc->addClass($parentClass); + if ( ! $calc->hasNode($parentClass->name)) { + $calc->addNode($parentClass->name, $parentClass); } - $calc->addDependency($parentClass, $class); + $calc->addDependency($parentClass->name, $class->name); } } } } - return $calc->getCommitOrder(); + return $calc->sort(); } /** diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php new file mode 100644 index 00000000..2a26973a --- /dev/null +++ b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php @@ -0,0 +1,198 @@ +. + */ + +namespace Doctrine\Common\DataFixtures\Sorter; + +/** + * TopologicalSorter is an ordering algorithm for directed graphs (DG) and/or + * directed acyclic graphs (DAG) by using a depth-first searching (DFS) to + * traverse the graph built in memory. + * This algorithm have a linear running time based on nodes (V) and dependency + * between the nodes (E), resulting in a computational complexity of O(V + E). + * + * @author Guilherme Blanco + * @author Roman Borschel + */ +class TopologicalSorter +{ + const NOT_VISITED = 0; + const IN_PROGRESS = 1; + const VISITED = 2; + + /** + * Matrix of nodes (aka. vertex). + * Keys are provided hashes and values are the node definition objects. + * + * The node state definition contains the following properties: + * + * - state (integer) + * Whether the node is NOT_VISITED or IN_PROGRESS + * + * - value (object) + * Actual node value + * + * - dependencyList (array) + * Map of node dependencies defined as hashes. + * + * @var array + */ + private $nodeList = array(); + + /** + * Volatile variable holding calculated nodes during sorting process. + * + * @var array + */ + private $sortedNodeList = array(); + + /** + * Adds a new node (vertex) to the graph, assigning its hash and value. + * + * @param string $hash + * @param object $node + * + * @return void + */ + public function addNode($hash, $node) + { + $definition = new \stdClass(); + + $definition->state = self::NOT_VISITED; + $definition->value = $node; + $definition->dependencyList = array(); + + $this->nodeList[$hash] = $definition; + } + + /** + * Checks the existence of a node in the graph. + * + * @param string $hash + * + * @return bool + */ + public function hasNode($hash) + { + return isset($this->nodeList[$hash]); + } + + /** + * Adds a new dependency (edge) to the graph using their hashes. + * + * @param string $fromNode + * @param string $toNode + * + * @return void + */ + public function addDependency($fromHash, $toHash) + { + $definition = $this->nodeList[$fromHash]; + + $definition->dependencyList[] = $toHash; + } + + /** + * Sets the dependency list (edges) to the graph using their hashes. + * + * @param string $fromHash + * @param array $dependencyList + * + * @return void + */ + public function setDependencyList($fromHash, array $dependencyList) + { + $definition = $this->nodeList[$fromHash]; + + $definition->dependencyList = $dependencyList; + } + + /** + * Return a valid order list of all current nodes. + * The desired topological sorting is the postorder of these searches. + * + * {@internal Highly performance-sensitive method.} + * + * @return array + */ + public function sort() + { + foreach ($this->nodeList as $definition) { + if ($definition->state !== self::NOT_VISITED) { + continue; + } + + $this->visit($definition); + } + + $sortedList = $this->sortedNodeList; + + $this->nodeList = array(); + $this->sortedNodeList = array(); + + return $sortedList; + } + + /** + * Visit a given node definition for reordering. + * + * {@internal Highly performance-sensitive method.} + * + * @throws \RuntimeException + * + * @param \stdClass $definition + */ + private function visit($definition) + { + $definition->state = self::IN_PROGRESS; + + foreach ($definition->dependencyList as $dependency) { + 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 + ) + ); + } + + $childDefinition = $this->nodeList[$dependency]; + + switch ($childDefinition->state) { + case self::VISITED: + continue; + + case self::IN_PROGRESS: + $message = 'Graph contains cyclic dependency. 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.'; + + throw new \RuntimeException($message); + + case self::NOT_VISITED: + $this->visit($childDefinition); + } + } + + $definition->state = self::VISITED; + + $this->sortedNodeList[] = $definition->value; + } +} diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php new file mode 100644 index 00000000..08f87712 --- /dev/null +++ b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php @@ -0,0 +1,134 @@ +. + */ + +namespace Doctrine\Test\DataFixtures\Sorter; + +use Doctrine\Common\DataFixtures\Sorter\TopologicalSorter; +use Doctrine\Tests\Mock; + +/** + * TopologicalSorter tests. + * + * {@internal When writing tests here consider that a lot of graph + * constellations can have many valid orderings, so you may want to + * build a graph that has only 1 valid order to simplify your tests} + * + * @author Guilherme Blanco + */ +class TopologicalSorterTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Doctrine\Fixture\Sorter\TopologicalSorter + */ + private $sorter; + + /** + * {@inheritdoc} + */ + public function setUp() + { + $this->sorter = new TopologicalSorter(); + } + + public function testSuccessSortLinearDependency() + { + $node1 = new Mock\Node(1); + $node2 = new Mock\Node(2); + $node3 = new Mock\Node(3); + $node4 = new Mock\Node(4); + $node5 = new Mock\Node(5); + + $this->sorter->addNode('1', $node1); + $this->sorter->addNode('2', $node2); + $this->sorter->addNode('3', $node3); + $this->sorter->addNode('4', $node4); + $this->sorter->addNode('5', $node5); + + $this->sorter->addDependency('1', '2'); + $this->sorter->addDependency('2', '3'); + $this->sorter->addDependency('3', '4'); + $this->sorter->addDependency('5', '1'); + + $sortedList = $this->sorter->sort(); + $correctList = array($node4, $node3, $node2, $node1, $node5); + + $this->assertSame($correctList, $sortedList); + } + + public function testSuccessSortMultiDependency() + { + $node1 = new Mock\Node(1); + $node2 = new Mock\Node(2); + $node3 = new Mock\Node(3); + $node4 = new Mock\Node(4); + $node5 = new Mock\Node(5); + + $this->sorter->addNode('1', $node1); + $this->sorter->addNode('2', $node2); + $this->sorter->addNode('3', $node3); + $this->sorter->addNode('4', $node4); + $this->sorter->addNode('5', $node5); + + $this->sorter->addDependency('3', '2'); + $this->sorter->addDependency('3', '4'); + $this->sorter->addDependency('3', '5'); + $this->sorter->addDependency('4', '1'); + $this->sorter->addDependency('5', '1'); + + $sortedList = $this->sorter->sort(); + $correctList = array($node1, $node2, $node4, $node5, $node3); + + $this->assertSame($correctList, $sortedList); + } + + /** + * @expectedException RuntimeException + */ + public function testFailureSortCyclicDependency() + { + $node1 = new Mock\Node(1); + $node2 = new Mock\Node(2); + $node3 = new Mock\Node(3); + + $this->sorter->addNode('1', $node1); + $this->sorter->addNode('2', $node2); + $this->sorter->addNode('3', $node3); + + $this->sorter->addDependency('1', '2'); + $this->sorter->addDependency('2', '3'); + $this->sorter->addDependency('3', '1'); + + $this->sorter->sort(); + } + + /** + * @expectedException RuntimeException + */ + public function testFailureSortMissingDependency() + { + $node1 = new Mock\Node(1); + + $this->sorter->addNode('1', $node1); + + $this->sorter->addDependency('1', '2'); + + $this->sorter->sort(); + } +} diff --git a/tests/Doctrine/Tests/Mock/Node.php b/tests/Doctrine/Tests/Mock/Node.php new file mode 100644 index 00000000..d66c6f99 --- /dev/null +++ b/tests/Doctrine/Tests/Mock/Node.php @@ -0,0 +1,44 @@ +. + */ + +namespace Doctrine\Tests\Mock; + +/** + * Node. + * + * @author Guilherme Blanco + */ +class Node +{ + /** + * @var mixed + */ + public $value; + + /** + * Constructor. + * + * @param mixed $value + */ + public function __construct($value) + { + $this->value = $value; + } +} From 9e7f9feaf7755575fe80e806b4ce1cc3ec9bb9b2 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 10:10:36 +0200 Subject: [PATCH 027/129] Marking `TopologicalSorter` as internal --- lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php index 2a26973a..925bf66e 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php @@ -29,6 +29,9 @@ * * @author Guilherme Blanco * @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. */ class TopologicalSorter { From e31c1c6a10d20961b29170c6592791adcb23e128 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 10:12:09 +0200 Subject: [PATCH 028/129] Renaming `$calc` to `$sorter` --- .../Common/DataFixtures/Purger/ORMPurger.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php index d20d3d19..cb441488 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php @@ -145,48 +145,48 @@ public function purge() private function getCommitOrder(EntityManagerInterface $em, array $classes) { - $calc = new TopologicalSorter(); + $sorter = new TopologicalSorter(); foreach ($classes as $class) { - $calc->addNode($class->name, $class); + $sorter->addNode($class->name, $class); // $class before its parents foreach ($class->parentClasses as $parentClass) { $parentClass = $em->getClassMetadata($parentClass); - if ( ! $calc->hasNode($parentClass->name)) { - $calc->addNode($parentClass->name, $parentClass); + if ( ! $sorter->hasNode($parentClass->name)) { + $sorter->addNode($parentClass->name, $parentClass); } - $calc->addDependency($class->name, $parentClass->name); + $sorter->addDependency($class->name, $parentClass->name); } foreach ($class->associationMappings as $assoc) { if ($assoc['isOwningSide']) { $targetClass = $em->getClassMetadata($assoc['targetEntity']); - if ( ! $calc->hasNode($targetClass->name)) { - $calc->addNode($targetClass->name, $targetClass); + if ( ! $sorter->hasNode($targetClass->name)) { + $sorter->addNode($targetClass->name, $targetClass); } // add dependency ($targetClass before $class) - $calc->addDependency($targetClass->name, $class->name); + $sorter->addDependency($targetClass->name, $class->name); // parents of $targetClass before $class, too foreach ($targetClass->parentClasses as $parentClass) { $parentClass = $em->getClassMetadata($parentClass); - if ( ! $calc->hasNode($parentClass->name)) { - $calc->addNode($parentClass->name, $parentClass); + if ( ! $sorter->hasNode($parentClass->name)) { + $sorter->addNode($parentClass->name, $parentClass); } - $calc->addDependency($parentClass->name, $class->name); + $sorter->addDependency($parentClass->name, $class->name); } } } } - return $calc->sort(); + return $sorter->sort(); } /** From deeccba427fb429d72e3a945c01aeaea99d09947 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 10:12:50 +0200 Subject: [PATCH 029/129] Removed unused variable --- lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php index cb441488..444c307f 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php @@ -101,9 +101,8 @@ public function getObjectManager() public function purge() { $classes = array(); - $metadatas = $this->em->getMetadataFactory()->getAllMetadata(); - foreach ($metadatas as $metadata) { + foreach ($this->em->getMetadataFactory()->getAllMetadata() as $metadata) { if (! $metadata->isMappedSuperclass && ! (isset($metadata->isEmbeddedClass) && $metadata->isEmbeddedClass)) { $classes[] = $metadata; } From 079b9043f3213bca33603876bdc5e572c1ad35b4 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 10:16:19 +0200 Subject: [PATCH 030/129] Sorting conditionals that have actual performance impact --- lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php index 444c307f..4b99d996 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php @@ -121,9 +121,9 @@ public function purge() $class = $commitOrder[$i]; if ( - ($class->isInheritanceTypeSingleTable() && $class->name != $class->rootEntityName) || (isset($class->isEmbeddedClass) && $class->isEmbeddedClass) || - $class->isMappedSuperclass + $class->isMappedSuperclass || + ($class->isInheritanceTypeSingleTable() && $class->name !== $class->rootEntityName) ) { continue; } @@ -142,6 +142,12 @@ public function purge() } } + /** + * @param EntityManagerInterface $em + * @param ClassMetadata[] $classes + * + * @return ClassMetadata[] + */ private function getCommitOrder(EntityManagerInterface $em, array $classes) { $sorter = new TopologicalSorter(); From bf72b0998ef2c60abc5ad4e78f4d0b769ccc876f Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 10:22:18 +0200 Subject: [PATCH 031/129] Removing excessive reliance on `Doctrine\ORM\Mapping\ClassMetadata` internals (one API call left) --- .../Common/DataFixtures/Purger/ORMPurger.php | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php index 4b99d996..792bfea8 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php @@ -157,35 +157,39 @@ private function getCommitOrder(EntityManagerInterface $em, array $classes) // $class before its parents foreach ($class->parentClasses as $parentClass) { - $parentClass = $em->getClassMetadata($parentClass); + $parentClass = $em->getClassMetadata($parentClass); + $parentClassName = $parentClass->getName(); - if ( ! $sorter->hasNode($parentClass->name)) { - $sorter->addNode($parentClass->name, $parentClass); + if ( ! $sorter->hasNode($parentClassName)) { + $sorter->addNode($parentClassName, $parentClass); } - $sorter->addDependency($class->name, $parentClass->name); + $sorter->addDependency($class->name, $parentClassName); } foreach ($class->associationMappings as $assoc) { if ($assoc['isOwningSide']) { - $targetClass = $em->getClassMetadata($assoc['targetEntity']); + /* @var $targetClass ClassMetadata */ + $targetClass = $em->getClassMetadata($assoc['targetEntity']); + $targetClassName = $targetClass->getName(); - if ( ! $sorter->hasNode($targetClass->name)) { - $sorter->addNode($targetClass->name, $targetClass); + if ( ! $sorter->hasNode($targetClassName)) { + $sorter->addNode($targetClassName, $targetClass); } // add dependency ($targetClass before $class) - $sorter->addDependency($targetClass->name, $class->name); + $sorter->addDependency($targetClassName, $class->name); // parents of $targetClass before $class, too foreach ($targetClass->parentClasses as $parentClass) { - $parentClass = $em->getClassMetadata($parentClass); + $parentClass = $em->getClassMetadata($parentClass); + $parentClassName = $parentClass->getName(); - if ( ! $sorter->hasNode($parentClass->name)) { - $sorter->addNode($parentClass->name, $parentClass); + if ( ! $sorter->hasNode($parentClassName)) { + $sorter->addNode($parentClassName, $parentClass); } - $sorter->addDependency($parentClass->name, $class->name); + $sorter->addDependency($parentClassName, $class->name); } } } From 72c037687403597d12162fa0599a07732665d441 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 10:24:01 +0200 Subject: [PATCH 032/129] Removing `continue` usage (which would behave like a `break` inside a `switch` statement) --- lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php index 925bf66e..41b0a869 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php @@ -180,7 +180,7 @@ private function visit($definition) switch ($childDefinition->state) { case self::VISITED: - continue; + break; case self::IN_PROGRESS: $message = 'Graph contains cyclic dependency. An example of this problem would be the following: ' From ec4159ee503945032cd451795cb642f32084b16c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 10:24:27 +0200 Subject: [PATCH 033/129] Docblock parameter mismatch corrections --- lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php index 41b0a869..e402fab4 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php @@ -99,8 +99,8 @@ public function hasNode($hash) /** * Adds a new dependency (edge) to the graph using their hashes. * - * @param string $fromNode - * @param string $toNode + * @param string $fromHash + * @param string $toHash * * @return void */ From 4c8a492115328d5f73670b4f7ffe5bbd3d8ee8d9 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 10:24:52 +0200 Subject: [PATCH 034/129] Removing unused method --- .../DataFixtures/Sorter/TopologicalSorter.php | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php index e402fab4..c7a4b712 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php @@ -111,21 +111,6 @@ public function addDependency($fromHash, $toHash) $definition->dependencyList[] = $toHash; } - /** - * Sets the dependency list (edges) to the graph using their hashes. - * - * @param string $fromHash - * @param array $dependencyList - * - * @return void - */ - public function setDependencyList($fromHash, array $dependencyList) - { - $definition = $this->nodeList[$fromHash]; - - $definition->dependencyList = $dependencyList; - } - /** * Return a valid order list of all current nodes. * The desired topological sorting is the postorder of these searches. From 72e5ea9d0d4198207aa114f9167bab021e0a6051 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 10:28:26 +0200 Subject: [PATCH 035/129] Removing `@internal` comment --- lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php index c7a4b712..83aff412 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php @@ -115,7 +115,7 @@ public function addDependency($fromHash, $toHash) * Return a valid order list of all current nodes. * The desired topological sorting is the postorder of these searches. * - * {@internal Highly performance-sensitive method.} + * Note: Highly performance-sensitive method. * * @return array */ From 893123d7ed5314d234b7be8be1337f6c1662ae59 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 10:31:09 +0200 Subject: [PATCH 036/129] Removing `@internal` comment - wrong context, correcting annotated types --- .../Common/DataFixtures/Sorter/TopologicalSorterTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php index 08f87712..c1416941 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php @@ -26,16 +26,16 @@ /** * TopologicalSorter tests. * - * {@internal When writing tests here consider that a lot of graph - * constellations can have many valid orderings, so you may want to - * build a graph that has only 1 valid order to simplify your tests} + * Note: When writing tests here consider that a lot of graph + * constellations can have many valid orderings, so you may want to + * build a graph that has only 1 valid order to simplify your tests * * @author Guilherme Blanco */ class TopologicalSorterTest extends \PHPUnit_Framework_TestCase { /** - * @var \Doctrine\Fixture\Sorter\TopologicalSorter + * @var \Doctrine\Common\DataFixtures\Sorter\TopologicalSorter */ private $sorter; From 813fb306e87af0a1b8bb7a1506358c1c0ad5a5b1 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 10:31:25 +0200 Subject: [PATCH 037/129] Coverage annotations for the `Doctrine\Common\DataFixtures\Sorter\TopologicalSorter` test --- .../Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php index c1416941..e9702764 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php @@ -31,6 +31,8 @@ * build a graph that has only 1 valid order to simplify your tests * * @author Guilherme Blanco + * + * @covers \Doctrine\Common\DataFixtures\Sorter\TopologicalSorter */ class TopologicalSorterTest extends \PHPUnit_Framework_TestCase { From 9ff23a802fe03f3c2ff3accd0bf93627619e6b2e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 10:33:38 +0200 Subject: [PATCH 038/129] Can safely assume PHP 5.5+ is used (since the patch is about ORM 2.5 compat) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f7bf27ed..7e333737 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ {"name": "Jonathan Wage", "email": "jonwage@gmail.com"} ], "require": { - "php": ">=5.3.2", + "php": "^5.5 || ^7.0", "doctrine/common": "~2.2" }, "require-dev": { From d1512dd234ee22105c042fcd5536cf590410db61 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 10:35:04 +0200 Subject: [PATCH 039/129] Avoiding reliance on `@expectedException`, replacing instance access with static access for assertions --- .../DataFixtures/Sorter/TopologicalSorterTest.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php index e9702764..8f84b0db 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php @@ -71,7 +71,7 @@ public function testSuccessSortLinearDependency() $sortedList = $this->sorter->sort(); $correctList = array($node4, $node3, $node2, $node1, $node5); - $this->assertSame($correctList, $sortedList); + self::assertSame($correctList, $sortedList); } public function testSuccessSortMultiDependency() @@ -97,12 +97,9 @@ public function testSuccessSortMultiDependency() $sortedList = $this->sorter->sort(); $correctList = array($node1, $node2, $node4, $node5, $node3); - $this->assertSame($correctList, $sortedList); + self::assertSame($correctList, $sortedList); } - /** - * @expectedException RuntimeException - */ public function testFailureSortCyclicDependency() { $node1 = new Mock\Node(1); @@ -117,12 +114,11 @@ public function testFailureSortCyclicDependency() $this->sorter->addDependency('2', '3'); $this->sorter->addDependency('3', '1'); + $this->expectException(\RuntimeException::class); + $this->sorter->sort(); } - /** - * @expectedException RuntimeException - */ public function testFailureSortMissingDependency() { $node1 = new Mock\Node(1); @@ -131,6 +127,8 @@ public function testFailureSortMissingDependency() $this->sorter->addDependency('1', '2'); + $this->expectException(\RuntimeException::class); + $this->sorter->sort(); } } From ccbc7b4d125a3e64040c6adc229de5d5617632b0 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 10:44:33 +0200 Subject: [PATCH 040/129] Spec for a tiny `Node` object to be reused in `TopologicalSorter` internals --- .../Common/DataFixtures/Sorter/NodeTest.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/Doctrine/Tests/Common/DataFixtures/Sorter/NodeTest.php diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/NodeTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/NodeTest.php new file mode 100644 index 00000000..272a9067 --- /dev/null +++ b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/NodeTest.php @@ -0,0 +1,41 @@ +. + */ + +namespace Doctrine\Test\DataFixtures\Sorter; + +use Doctrine\Common\DataFixtures\Sorter\Node; + +/** + * @author Marco Pivetta + * + * @covers \Doctrine\Common\DataFixtures\Sorter\Node + */ +class NodeTest extends \PHPUnit_Framework_TestCase +{ + public function testNode() + { + $value = new \stdClass(); + $node = new Node($value); + + self::assertSame($value, $node->value); + self::assertSame(Node::NOT_VISITED, $node->state); + self::assertSame([], $node->dependencyList); + } +} From 144c6060552ab96c7c1470605c760df5083cab94 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 10:44:45 +0200 Subject: [PATCH 041/129] Implemented `Node` as per specification --- .../Common/DataFixtures/Sorter/Node.php | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 lib/Doctrine/Common/DataFixtures/Sorter/Node.php diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/Node.php b/lib/Doctrine/Common/DataFixtures/Sorter/Node.php new file mode 100644 index 00000000..6e137b14 --- /dev/null +++ b/lib/Doctrine/Common/DataFixtures/Sorter/Node.php @@ -0,0 +1,58 @@ +. + */ + +namespace Doctrine\Common\DataFixtures\Sorter; + +/** + * @author Marco Pivetta + * + * @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} + * only. + */ +class Node +{ + const NOT_VISITED = 0; + const IN_PROGRESS = 1; + const VISITED = 2; + + /** + * @var int one of either {@see self::NOT_VISITED}, {@see self::IN_PROGRESS} or {@see self::VISITED}. + */ + public $state = self::NOT_VISITED; + + /** + * @var mixed Actual node value + */ + public $value; + + /** + * @var string[] Map of node dependencies defined as hashes. + */ + public $dependencyList = []; + + /** + * @param mixed $value + */ + public function __construct($value) + { + $this->value = $value; + } +} From 04db70b1e86d87907ff05f886d203dfa96740cce Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 10:46:03 +0200 Subject: [PATCH 042/129] Renaming `Node` to `Vertex` --- .../DataFixtures/Sorter/{Node.php => Vertex.php} | 2 +- .../Sorter/{NodeTest.php => VertexTest.php} | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) rename lib/Doctrine/Common/DataFixtures/Sorter/{Node.php => Vertex.php} (99%) rename tests/Doctrine/Tests/Common/DataFixtures/Sorter/{NodeTest.php => VertexTest.php} (83%) diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/Node.php b/lib/Doctrine/Common/DataFixtures/Sorter/Vertex.php similarity index 99% rename from lib/Doctrine/Common/DataFixtures/Sorter/Node.php rename to lib/Doctrine/Common/DataFixtures/Sorter/Vertex.php index 6e137b14..6d066f62 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/Node.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/Vertex.php @@ -27,7 +27,7 @@ * designed to work with {@see \Doctrine\Common\DataFixtures\Sorter\TopologicalSorter} * only. */ -class Node +class Vertex { const NOT_VISITED = 0; const IN_PROGRESS = 1; diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/NodeTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php similarity index 83% rename from tests/Doctrine/Tests/Common/DataFixtures/Sorter/NodeTest.php rename to tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php index 272a9067..6b4e1799 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/NodeTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php @@ -20,22 +20,22 @@ namespace Doctrine\Test\DataFixtures\Sorter; -use Doctrine\Common\DataFixtures\Sorter\Node; +use Doctrine\Common\DataFixtures\Sorter\Vertex; /** * @author Marco Pivetta * - * @covers \Doctrine\Common\DataFixtures\Sorter\Node + * @covers \Doctrine\Common\DataFixtures\Sorter\Vertex */ -class NodeTest extends \PHPUnit_Framework_TestCase +class VertexTest extends \PHPUnit_Framework_TestCase { public function testNode() { $value = new \stdClass(); - $node = new Node($value); + $node = new Vertex($value); self::assertSame($value, $node->value); - self::assertSame(Node::NOT_VISITED, $node->state); + self::assertSame(Vertex::NOT_VISITED, $node->state); self::assertSame([], $node->dependencyList); } } From 980355057a1224b83f5306ab3c2b1067e8d9ead8 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 10:48:43 +0200 Subject: [PATCH 043/129] Reusing the `Vertex` class in `TopologicalSorter` internals --- .../DataFixtures/Sorter/TopologicalSorter.php | 38 +++++-------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php index 83aff412..ef8d0c24 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php @@ -1,5 +1,4 @@ state (integer) - * Whether the node is NOT_VISITED or IN_PROGRESS - * - * - value (object) - * Actual node value - * - * - dependencyList (array) - * Map of node dependencies defined as hashes. - * - * @var array + * @var Vertex[] */ - private $nodeList = array(); + private $nodeList = []; /** * Volatile variable holding calculated nodes during sorting process. * * @var array */ - private $sortedNodeList = array(); + private $sortedNodeList = []; /** * Adds a new node (vertex) to the graph, assigning its hash and value. * * @param string $hash - * @param object $node + * @param mixed $node * * @return void */ public function addNode($hash, $node) { - $definition = new \stdClass(); - - $definition->state = self::NOT_VISITED; - $definition->value = $node; - $definition->dependencyList = array(); - - $this->nodeList[$hash] = $definition; + $this->nodeList[$hash] = new Vertex($node); } /** @@ -131,8 +113,8 @@ public function sort() $sortedList = $this->sortedNodeList; - $this->nodeList = array(); - $this->sortedNodeList = array(); + $this->nodeList = []; + $this->sortedNodeList = []; return $sortedList; } @@ -140,13 +122,13 @@ public function sort() /** * Visit a given node definition for reordering. * - * {@internal Highly performance-sensitive method.} + * Note: Highly performance-sensitive method. * * @throws \RuntimeException * - * @param \stdClass $definition + * @param Vertex $definition */ - private function visit($definition) + private function visit(Vertex $definition) { $definition->state = self::IN_PROGRESS; From b24cbc66a9b5f865dd95a49df0a3ecc0eff56450 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 10:49:48 +0200 Subject: [PATCH 044/129] Removing `Vertex` constants from the `TopologicalSorter` --- .../DataFixtures/Sorter/TopologicalSorter.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php index ef8d0c24..40df673b 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php @@ -34,10 +34,6 @@ */ class TopologicalSorter { - const NOT_VISITED = 0; - const IN_PROGRESS = 1; - const VISITED = 2; - /** * Matrix of nodes (aka. vertex). * Keys are provided hashes and values are the node definition objects. @@ -104,7 +100,7 @@ public function addDependency($fromHash, $toHash) public function sort() { foreach ($this->nodeList as $definition) { - if ($definition->state !== self::NOT_VISITED) { + if ($definition->state !== Vertex::NOT_VISITED) { continue; } @@ -130,7 +126,7 @@ public function sort() */ private function visit(Vertex $definition) { - $definition->state = self::IN_PROGRESS; + $definition->state = Vertex::IN_PROGRESS; foreach ($definition->dependencyList as $dependency) { if ( ! isset($this->nodeList[$dependency])) { @@ -146,22 +142,22 @@ private function visit(Vertex $definition) $childDefinition = $this->nodeList[$dependency]; switch ($childDefinition->state) { - case self::VISITED: + case Vertex::VISITED: break; - case self::IN_PROGRESS: + case Vertex::IN_PROGRESS: $message = 'Graph contains cyclic dependency. 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.'; throw new \RuntimeException($message); - case self::NOT_VISITED: + case Vertex::NOT_VISITED: $this->visit($childDefinition); } } - $definition->state = self::VISITED; + $definition->state = Vertex::VISITED; $this->sortedNodeList[] = $definition->value; } From 18179286c37904f0d9d13296b5476ca0420bf832 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 10:53:18 +0200 Subject: [PATCH 045/129] A `CircularReferenceException` is to be thrown when circular references are found --- .../DataFixtures/Sorter/TopologicalSorter.php | 23 ++++++++++--------- .../Sorter/TopologicalSorterTest.php | 3 ++- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php index 40df673b..a364d5bb 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php @@ -19,6 +19,8 @@ namespace Doctrine\Common\DataFixtures\Sorter; +use Doctrine\Common\DataFixtures\Exception\CircularReferenceException; + /** * TopologicalSorter is an ordering algorithm for directed graphs (DG) and/or * directed acyclic graphs (DAG) by using a depth-first searching (DFS) to @@ -121,6 +123,7 @@ public function sort() * Note: Highly performance-sensitive method. * * @throws \RuntimeException + * @throws CircularReferenceException * * @param Vertex $definition */ @@ -130,13 +133,11 @@ private function visit(Vertex $definition) foreach ($definition->dependencyList as $dependency) { 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 - ) - ); + throw new \RuntimeException(sprintf( + 'Fixture "%s" has a dependency of fixture "%s", but it not listed to be loaded.', + get_class($definition->value), + $dependency + )); } $childDefinition = $this->nodeList[$dependency]; @@ -146,11 +147,11 @@ private function visit(Vertex $definition) break; case Vertex::IN_PROGRESS: - $message = 'Graph contains cyclic dependency. An example of this problem would be the following: ' + throw new CircularReferenceException( + 'Graph contains cyclic dependency. 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.'; - - throw new \RuntimeException($message); + . 'Finally, class A has class C as its dependency.' + ); case Vertex::NOT_VISITED: $this->visit($childDefinition); diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php index 8f84b0db..604ec12a 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php @@ -20,6 +20,7 @@ namespace Doctrine\Test\DataFixtures\Sorter; +use Doctrine\Common\DataFixtures\Exception\CircularReferenceException; use Doctrine\Common\DataFixtures\Sorter\TopologicalSorter; use Doctrine\Tests\Mock; @@ -114,7 +115,7 @@ public function testFailureSortCyclicDependency() $this->sorter->addDependency('2', '3'); $this->sorter->addDependency('3', '1'); - $this->expectException(\RuntimeException::class); + $this->expectException(CircularReferenceException::class); $this->sorter->sort(); } From 8405bb89ca496ce17f2a9ca6a975fdc498e63d3a Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 10:55:52 +0200 Subject: [PATCH 046/129] Documenting thrown exceptions --- lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php index a364d5bb..60babc34 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php @@ -97,6 +97,9 @@ public function addDependency($fromHash, $toHash) * * Note: Highly performance-sensitive method. * + * @throws \RuntimeException + * @throws CircularReferenceException + * * @return array */ public function sort() From 5eba2273f210f7d70b33947cd62cffb859744d16 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 11:11:11 +0200 Subject: [PATCH 047/129] Dropping PHP 5.5 and below from supported versions --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7e333737..5bce1e3e 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ {"name": "Jonathan Wage", "email": "jonwage@gmail.com"} ], "require": { - "php": "^5.5 || ^7.0", + "php": "^5.6 || ^7.0", "doctrine/common": "~2.2" }, "require-dev": { From 8c25385356886baf0b0bdf34655b727f73ed2420 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 11:13:02 +0200 Subject: [PATCH 048/129] Relying on latest PHPUnit --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5bce1e3e..351654c1 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ }, "require-dev": { "doctrine/orm": "~2.4", - "phpunit/phpunit": "^4.0|^5.0" + "phpunit/phpunit": "^5.4.6" }, "conflict": { "doctrine/orm": "< 2.4" From 5a2d4e7cd20e344770bce5bd8f76552e3e412239 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 11:13:28 +0200 Subject: [PATCH 049/129] Relying on latest ORM for testing --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 351654c1..7a6047b6 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "doctrine/common": "~2.2" }, "require-dev": { - "doctrine/orm": "~2.4", + "doctrine/orm": "^2.5.4", "phpunit/phpunit": "^5.4.6" }, "conflict": { From 8b8a4bd039a1ec762c492ec7f2ac46e8c256b5fc Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 11:16:59 +0200 Subject: [PATCH 050/129] DBAL is used inside the test suite --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 7a6047b6..f34a167e 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,7 @@ }, "require-dev": { "doctrine/orm": "^2.5.4", + "doctrine/dbal": "^2.5.4", "phpunit/phpunit": "^5.4.6" }, "conflict": { From f3f8c12f575a4d11a4484bc2a8c2abd7b82e778a Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 11:26:29 +0200 Subject: [PATCH 051/129] Avoiding reliance on `getMock()`, which was deprecated --- .../Tests/Common/DataFixtures/BaseTest.php | 18 ++++++++---- .../Executor/ORMExecutorSharedFixtureTest.php | 4 +-- .../DataFixtures/Executor/ORMExecutorTest.php | 14 ++++----- .../Executor/PHPCRExecutorTest.php | 29 ++++++++++--------- .../Tests/Common/DataFixtures/FixtureTest.php | 4 +-- .../Tests/Common/DataFixtures/LoaderTest.php | 14 +++++---- 6 files changed, 46 insertions(+), 37 deletions(-) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php b/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php index 6e5fb0bd..0f367e1a 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php @@ -19,6 +19,12 @@ namespace Doctrine\Tests\Common\DataFixtures; +use Doctrine\Common\EventManager; +use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; +use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver; +use Doctrine\DBAL\Platforms\MySqlPlatform; +use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Tools\Setup; use PHPUnit_Framework_TestCase; @@ -32,17 +38,17 @@ abstract class BaseTest extends PHPUnit_Framework_TestCase { protected function getMockEntityManager() { - $driver = $this->getMock('Doctrine\DBAL\Driver'); + $driver = $this->createMock(Driver::class); $driver->expects($this->once()) ->method('getDatabasePlatform') - ->will($this->returnValue($this->getMock('Doctrine\DBAL\Platforms\MySqlPlatform'))); + ->will($this->returnValue($this->createMock(MySqlPlatform::class))); - $conn = $this->getMock('Doctrine\DBAL\Connection', array(), array(array(), $driver)); + $conn = $this->getMock(Connection::class, [], [[], $driver]); $conn->expects($this->once()) ->method('getEventManager') - ->will($this->returnValue($this->getMock('Doctrine\Common\EventManager'))); + ->will($this->returnValue($this->createMock(EventManager::class))); - $config = $this->getMock('Doctrine\ORM\Configuration'); + $config = $this->getMock(Configuration::class); $config->expects($this->once()) ->method('getProxyDir') ->will($this->returnValue('test')); @@ -53,7 +59,7 @@ protected function getMockEntityManager() $config->expects($this->once()) ->method('getMetadataDriverImpl') - ->will($this->returnValue($this->getMock('Doctrine\ORM\Mapping\Driver\DriverChain'))); + ->will($this->returnValue($this->createMock(MappingDriver::class))); $em = EntityManager::create($conn, $config); return $em; diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php index f752597f..d4966b70 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php @@ -21,7 +21,7 @@ use Doctrine\Common\DataFixtures\Executor\ORMExecutor; use Doctrine\Common\DataFixtures\Purger\ORMPurger; -use Doctrine\ORM\Proxy\Proxy; +use Doctrine\Common\DataFixtures\SharedFixtureInterface; use Doctrine\Tests\Common\DataFixtures\TestEntity\Role; use Doctrine\Tests\Common\DataFixtures\TestEntity\User; @@ -90,6 +90,6 @@ public function testSharedFixtures() private function getMockFixture() { - return $this->getMock('Doctrine\Common\DataFixtures\SharedFixtureInterface'); + return $this->createMock(SharedFixtureInterface::class); } } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorTest.php index c4a641a0..75b74e04 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorTest.php @@ -19,9 +19,9 @@ namespace Doctrine\Tests\Common\DataFixtures\Executor; -use Doctrine\ORM\EntityManager; use Doctrine\Common\DataFixtures\Executor\ORMExecutor; -use PHPUnit_Framework_TestCase; +use Doctrine\Common\DataFixtures\FixtureInterface; +use Doctrine\Common\DataFixtures\Purger\ORMPurger; use Doctrine\Tests\Common\DataFixtures\BaseTest; /** @@ -39,7 +39,7 @@ public function testExecuteWithNoPurge() ->method('setEntityManager') ->with($em); $executor = new ORMExecutor($em, $purger); - $fixture = $this->getMockFixture($em); + $fixture = $this->getMockFixture(); $fixture->expects($this->once()) ->method('load') ->with($em); @@ -54,7 +54,7 @@ public function testExecuteWithPurge() ->method('purge') ->will($this->returnValue(null)); $executor = new ORMExecutor($em, $purger); - $fixture = $this->getMockFixture($em); + $fixture = $this->getMockFixture(); $fixture->expects($this->once()) ->method('load') ->with($em); @@ -69,13 +69,13 @@ public function testExecuteTransaction() $executor->execute(array($fixture), true); } - private function getMockFixture($em) + private function getMockFixture() { - return $this->getMock('Doctrine\Common\DataFixtures\FixtureInterface'); + return $this->createMock(FixtureInterface::class); } private function getMockPurger() { - return $this->getMock('Doctrine\Common\DataFixtures\Purger\ORMPurger'); + return $this->createMock(ORMPurger::class); } } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php index b5d7df98..84f064ac 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php @@ -20,6 +20,9 @@ namespace Doctrine\Tests\Common\DataFixtures\Executor; use Doctrine\Common\DataFixtures\Executor\PHPCRExecutor; +use Doctrine\Common\DataFixtures\FixtureInterface; +use Doctrine\Common\DataFixtures\Purger\PHPCRPurger; +use Doctrine\ODM\PHPCR\DocumentManager; use Exception; use PHPUnit_Framework_TestCase; @@ -130,39 +133,37 @@ public function testFailedTransactionalStopsPurgingAndFixtureLoading() } /** - * @return \Doctrine\Common\DataFixtures\Purger\PHPCRPurger|\PHPUnit_Framework_MockObject_MockObject + * @return PHPCRPurger|\PHPUnit_Framework_MockObject_MockObject */ private function getPurger() { - return $this->getMock('Doctrine\Common\DataFixtures\Purger\PHPCRPurger', array(), array(), '', false); + return $this->createMock(PHPCRPurger::class, [], [], '', false); } /** - * @return \Doctrine\ODM\PHPCR\DocumentManager|\PHPUnit_Framework_MockObject_MockObject + * @return DocumentManager|\PHPUnit_Framework_MockObject_MockObject */ private function getDocumentManager() { $this->loadDocumentManagerClass(); - return $this->getMock( - 'Doctrine\ODM\PHPCR\DocumentManager', - array( + return $this + ->getMockBuilder(DocumentManager::class) + ->setMethods([ 'transactional', 'flush', 'clear', - ), - array(), - '', - false - ); + ]) + ->disableOriginalConstructor() + ->getMock(); } /** - * @return \Doctrine\Common\DataFixtures\FixtureInterface|\PHPUnit_Framework_MockObject_MockObject + * @return FixtureInterface|\PHPUnit_Framework_MockObject_MockObject */ private function getMockFixture() { - return $this->getMock('Doctrine\Common\DataFixtures\FixtureInterface', array(), array(), '', false); + return $this->createMock(FixtureInterface::class); } /** @@ -171,7 +172,7 @@ private function getMockFixture() private function loadDocumentManagerClass() { - if (class_exists('Doctrine\ODM\PHPCR\DocumentManager')) { + if (class_exists(DocumentManager::class)) { return; } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/FixtureTest.php b/tests/Doctrine/Tests/Common/DataFixtures/FixtureTest.php index 4c73cf5b..4e3f9b8c 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/FixtureTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/FixtureTest.php @@ -31,11 +31,11 @@ class FixtureTest extends BaseTest { public function testFixtureInterface() { - $em = $this->getMock('Doctrine\Common\Persistence\ObjectManager'); + $em = $this->createMock(ObjectManager::class); $fixture = new MyFixture2(); $fixture->load($em); - $this->assertTrue($fixture->loaded); + self::assertTrue($fixture->loaded); } } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/LoaderTest.php b/tests/Doctrine/Tests/Common/DataFixtures/LoaderTest.php index 48e67b5d..19273352 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/LoaderTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/LoaderTest.php @@ -19,7 +19,9 @@ namespace Doctrine\Tests\Common\DataFixtures; +use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Common\DataFixtures\Loader; +use Doctrine\Common\DataFixtures\SharedFixtureInterface; /** * Test fixtures loader. @@ -31,9 +33,9 @@ class LoaderTest extends BaseTest public function testLoadFromDirectory() { $loader = new Loader(); - $loader->addFixture($this->getMock('Doctrine\Common\DataFixtures\FixtureInterface'), array(), array(), 'Mock1'); - $loader->addFixture($this->getMock('Doctrine\Common\DataFixtures\FixtureInterface', array(), array(), 'Mock2')); - $loader->addFixture($this->getMock('Doctrine\Common\DataFixtures\SharedFixtureInterface', array(), array(), 'Mock3')); + $loader->addFixture($this->getMockBuilder(FixtureInterface::class)->setMockClassName('Mock1')->getMock()); + $loader->addFixture($this->getMockBuilder(FixtureInterface::class)->setMockClassName('Mock2')->getMock()); + $loader->addFixture($this->getMockBuilder(SharedFixtureInterface::class)->setMockClassName('Mock3')->getMock()); $this->assertCount(3, $loader->getFixtures()); @@ -46,9 +48,9 @@ public function testLoadFromDirectory() public function testLoadFromFile() { $loader = new Loader(); - $loader->addFixture($this->getMock('Doctrine\Common\DataFixtures\FixtureInterface'), array(), array(), 'Mock1'); - $loader->addFixture($this->getMock('Doctrine\Common\DataFixtures\FixtureInterface', array(), array(), 'Mock2')); - $loader->addFixture($this->getMock('Doctrine\Common\DataFixtures\SharedFixtureInterface', array(), array(), 'Mock3')); + $loader->addFixture($this->getMockBuilder(FixtureInterface::class)->setMockClassName('Mock1')->getMock()); + $loader->addFixture($this->getMockBuilder(FixtureInterface::class)->setMockClassName('Mock2')->getMock()); + $loader->addFixture($this->getMockBuilder(SharedFixtureInterface::class)->setMockClassName('Mock3')->getMock()); $this->assertCount(3, $loader->getFixtures()); From 220faefb6f219b75bc87d2b6e989407c272625de Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 11:29:26 +0200 Subject: [PATCH 052/129] Stop testing old/dead PHP versions --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 09308483..85952764 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,9 +7,6 @@ cache: - $HOME/.composer/cache php: - - 5.3 - - 5.4 - - 5.5 - 5.6 - 7.0 - hhvm From 8d52ced47dbafa54441db27444f5326498848768 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 11:29:57 +0200 Subject: [PATCH 053/129] Test also against PHP nightly --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 85952764..c1b7cda3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,8 +9,13 @@ cache: php: - 5.6 - 7.0 + - nightly - hhvm +matrix: + allow_failures: + - php: nightly + services: mongodb before_install: From dc47be4185444fe11e65daf4e63c0e8506f364c4 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 11:32:01 +0200 Subject: [PATCH 054/129] Simpler test bootstrapping --- phpunit.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7a757e18..99eb5525 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,7 +8,7 @@ convertWarningsToExceptions="true" stopOnFailure="false" syntaxCheck="false" - bootstrap="tests/bootstrap.php" + bootstrap="vendor/autoload.php" > From 34a684e1045e8ae1adf2cdb2894f41b5c0c8cf36 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 11:32:14 +0200 Subject: [PATCH 055/129] Removing old test bootstrapper --- tests/bootstrap.php | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 tests/bootstrap.php diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index a5ecb857..00000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,21 +0,0 @@ -. - */ - -require_once __DIR__ . "/../vendor/autoload.php"; From cf5ec270ccb74e92048385ed65b4b8f0fdea437e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 11:32:57 +0200 Subject: [PATCH 056/129] Correcting number of arguments passed to the mock builder methods --- .../Tests/Common/DataFixtures/Executor/ORMExecutorTest.php | 2 +- .../Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorTest.php index 75b74e04..42860a42 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorTest.php @@ -65,7 +65,7 @@ public function testExecuteTransaction() { $em = $this->getMockSqliteEntityManager(); $executor = new ORMExecutor($em); - $fixture = $this->getMockFixture($em); + $fixture = $this->getMockFixture(); $executor->execute(array($fixture), true); } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php index 84f064ac..8c507d41 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php @@ -137,7 +137,7 @@ public function testFailedTransactionalStopsPurgingAndFixtureLoading() */ private function getPurger() { - return $this->createMock(PHPCRPurger::class, [], [], '', false); + return $this->createMock(PHPCRPurger::class); } /** From e43370b24b585120d87e899256176d187366c9f9 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 11:33:46 +0200 Subject: [PATCH 057/129] Removed useless parentheses --- .../DataFixtures/DependentFixtureTest.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/DependentFixtureTest.php b/tests/Doctrine/Tests/Common/DataFixtures/DependentFixtureTest.php index 33dc55ef..428d45d0 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/DependentFixtureTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/DependentFixtureTest.php @@ -84,19 +84,19 @@ public function test_orderFixturesByDependencies_orderClassesWithAMultipleParent // BaseParentFixture1 has no dependencies, so it will always be first in this case $this->assertEquals($baseParentFixtureOrder, 0); - $this->assertTrue(($contactFixtureOrder > $contactMethodFixtureOrder)); - $this->assertTrue(($contactFixtureOrder > $addressFixtureOrder)); - $this->assertTrue(($contactFixtureOrder > $countryFixtureOrder)); - $this->assertTrue(($contactFixtureOrder > $stateFixtureOrder)); - $this->assertTrue(($contactFixtureOrder > $contactMethodFixtureOrder)); - - $this->assertTrue(($addressFixtureOrder > $stateFixtureOrder)); - $this->assertTrue(($addressFixtureOrder > $countryFixtureOrder)); + $this->assertTrue($contactFixtureOrder > $contactMethodFixtureOrder); + $this->assertTrue($contactFixtureOrder > $addressFixtureOrder); + $this->assertTrue($contactFixtureOrder > $countryFixtureOrder); + $this->assertTrue($contactFixtureOrder > $stateFixtureOrder); + $this->assertTrue($contactFixtureOrder > $contactMethodFixtureOrder); + + $this->assertTrue($addressFixtureOrder > $stateFixtureOrder); + $this->assertTrue($addressFixtureOrder > $countryFixtureOrder); } /** - * @expectedException Doctrine\Common\DataFixtures\Exception\CircularReferenceException + * @expectedException \Doctrine\Common\DataFixtures\Exception\CircularReferenceException */ public function test_orderFixturesByDependencies_circularReferencesMakeMethodThrowCircularReferenceException() { @@ -110,7 +110,7 @@ public function test_orderFixturesByDependencies_circularReferencesMakeMethodThr } /** - * @expectedException InvalidArgumentException + * @expectedException \InvalidArgumentException */ public function test_orderFixturesByDependencies_fixturesCantHaveItselfAsParent() { From d7d13bf89b59fc4096ea04e8c7b31e3f473d3ee7 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 11:33:59 +0200 Subject: [PATCH 058/129] Imported required `SchemaTool` --- .../DataFixtures/Executor/ORMExecutorSharedFixtureTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php index d4966b70..eacba9c9 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php @@ -22,6 +22,7 @@ use Doctrine\Common\DataFixtures\Executor\ORMExecutor; use Doctrine\Common\DataFixtures\Purger\ORMPurger; use Doctrine\Common\DataFixtures\SharedFixtureInterface; +use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Tests\Common\DataFixtures\TestEntity\Role; use Doctrine\Tests\Common\DataFixtures\TestEntity\User; @@ -61,7 +62,7 @@ public function testSharedFixtures() } $em = $this->getMockSqliteEntityManager(); - $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em); + $schemaTool = new SchemaTool($em); $schemaTool->dropSchema(array()); $schemaTool->createSchema(array( $em->getClassMetadata(self::TEST_ENTITY_ROLE), From dabaa28a68acebf0d87224991f47484d885b2049 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 11:34:19 +0200 Subject: [PATCH 059/129] Removing useless assignment --- tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php b/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php index 0f367e1a..1f9f53b9 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php @@ -61,8 +61,7 @@ protected function getMockEntityManager() ->method('getMetadataDriverImpl') ->will($this->returnValue($this->createMock(MappingDriver::class))); - $em = EntityManager::create($conn, $config); - return $em; + return EntityManager::create($conn, $config); } /** From 363647c495a2767788a0475da1e24aef963d7163 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 11:35:31 +0200 Subject: [PATCH 060/129] Removing unused `getMockEntityManager` method --- .../Tests/Common/DataFixtures/BaseTest.php | 33 ------------------- 1 file changed, 33 deletions(-) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php b/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php index 1f9f53b9..6903e768 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php @@ -19,12 +19,7 @@ namespace Doctrine\Tests\Common\DataFixtures; -use Doctrine\Common\EventManager; -use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; -use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver; -use Doctrine\DBAL\Platforms\MySqlPlatform; -use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Tools\Setup; use PHPUnit_Framework_TestCase; @@ -36,34 +31,6 @@ */ abstract class BaseTest extends PHPUnit_Framework_TestCase { - protected function getMockEntityManager() - { - $driver = $this->createMock(Driver::class); - $driver->expects($this->once()) - ->method('getDatabasePlatform') - ->will($this->returnValue($this->createMock(MySqlPlatform::class))); - - $conn = $this->getMock(Connection::class, [], [[], $driver]); - $conn->expects($this->once()) - ->method('getEventManager') - ->will($this->returnValue($this->createMock(EventManager::class))); - - $config = $this->getMock(Configuration::class); - $config->expects($this->once()) - ->method('getProxyDir') - ->will($this->returnValue('test')); - - $config->expects($this->once()) - ->method('getProxyNamespace') - ->will($this->returnValue('Proxies')); - - $config->expects($this->once()) - ->method('getMetadataDriverImpl') - ->will($this->returnValue($this->createMock(MappingDriver::class))); - - return EntityManager::create($conn, $config); - } - /** * EntityManager mock object together with * annotation mapping driver From 2e7e18d42cc105eca308f26769bf01e8505cc931 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 11:40:16 +0200 Subject: [PATCH 061/129] Removing reliance on `setExpectedException` and similar functionality (deprecated) --- .../DataFixtures/DependentFixtureTest.php | 24 +++++++++---------- .../DataFixtures/ReferenceRepositoryTest.php | 11 ++++----- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/DependentFixtureTest.php b/tests/Doctrine/Tests/Common/DataFixtures/DependentFixtureTest.php index 428d45d0..d5480670 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/DependentFixtureTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/DependentFixtureTest.php @@ -19,11 +19,14 @@ namespace Doctrine\Tests\Common\DataFixtures; +use Doctrine\Common\DataFixtures\Exception\CircularReferenceException; use Doctrine\Common\DataFixtures\Loader; use Doctrine\Common\DataFixtures\DependentFixtureInterface; use Doctrine\Common\DataFixtures\OrderedFixtureInterface; use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Common\Persistence\ObjectManager; +use InvalidArgumentException; +use RuntimeException; /** * Test Fixture ordering by dependencies. @@ -95,9 +98,6 @@ public function test_orderFixturesByDependencies_orderClassesWithAMultipleParent } - /** - * @expectedException \Doctrine\Common\DataFixtures\Exception\CircularReferenceException - */ public function test_orderFixturesByDependencies_circularReferencesMakeMethodThrowCircularReferenceException() { $loader = new Loader(); @@ -106,19 +106,20 @@ public function test_orderFixturesByDependencies_circularReferencesMakeMethodThr $loader->addFixture(new CircularReferenceFixture); $loader->addFixture(new CircularReferenceFixture2); - $orderedFixtures = $loader->getFixtures(); + $this->expectException(CircularReferenceException::class); + + $loader->getFixtures(); } - /** - * @expectedException \InvalidArgumentException - */ public function test_orderFixturesByDependencies_fixturesCantHaveItselfAsParent() { $loader = new Loader(); $loader->addFixture(new FixtureWithItselfAsParent); - $orderedFixtures = $loader->getFixtures(); + $this->expectException(InvalidArgumentException::class); + + $loader->getFixtures(); } public function test_inCaseThereAreFixturesOrderedByNumberAndByDependenciesBothOrdersAreExecuted() @@ -144,15 +145,14 @@ public function test_inCaseThereAreFixturesOrderedByNumberAndByDependenciesBothO $this->assertInstanceOf(__NAMESPACE__ . '\DependentFixture3', array_shift($orderedFixtures)); } - /** - * @expectedException RuntimeException - */ public function test_inCaseAFixtureHasAnUnexistentDependencyOrIfItWasntLoaded_throwsException() { $loader = new Loader(); $loader->addFixture(new FixtureWithUnexistentDependency); - $orderedFixtures = $loader->getFixtures(); + $this->expectException(RuntimeException::class); + + $loader->getFixtures(); } public function test_inCaseGetFixturesReturnsDifferentResultsEachTime() diff --git a/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php b/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php index 81232274..79158ea4 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php @@ -133,14 +133,13 @@ public function testReferenceMultipleEntries() $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $referenceRepository->getReference('duplicate')); } - /** - * @expectedException OutOfBoundsException - * @expectedExceptionMessage Reference to: (foo) does not exist - */ public function testUndefinedReference() { - $em = $this->getMockSqliteEntityManager(); - $referenceRepository = new ReferenceRepository($em); + $referenceRepository = new ReferenceRepository($this->getMockSqliteEntityManager()); + + $this->expectException(\OutOfBoundsException::class); + $this->expectExceptionMessage('Reference to: (foo) does not exist'); + $referenceRepository->getReference('foo'); } } From ac2ce69d591e74619518e175fb4a4082daca9e74 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 19 Jun 2016 12:11:35 +0200 Subject: [PATCH 062/129] Master is now 1.3.x-dev --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f34a167e..612d2cac 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.1.x-dev" + "dev-master": "1.3.x-dev" } } } From 41313b3d229f3d1ec29b6bfebd2b2b0a9d7bb175 Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Mon, 20 Jun 2016 10:49:32 +0200 Subject: [PATCH 063/129] Added support for self referencing classes in the TopologicalSorter --- .../Common/DataFixtures/Sorter/TopologicalSorter.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php index 60babc34..62a89793 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php @@ -145,6 +145,11 @@ private function visit(Vertex $definition) $childDefinition = $this->nodeList[$dependency]; + // allow self referencing classes + if ($definition->value->getName() === $childDefinition->value->getName()) { + continue; + } + switch ($childDefinition->state) { case Vertex::VISITED: break; From 4f113e2ea5fd547f49e6dba4470125395507f80a Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Mon, 20 Jun 2016 13:21:41 +0200 Subject: [PATCH 064/129] Updated condition to detect self referencing classes --- lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php index 62a89793..44fa4d27 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php @@ -146,7 +146,7 @@ private function visit(Vertex $definition) $childDefinition = $this->nodeList[$dependency]; // allow self referencing classes - if ($definition->value->getName() === $childDefinition->value->getName()) { + if ($definition === $childDefinition) { continue; } From d1beb4cec132521e581e9d999c33da418b6778b9 Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Mon, 20 Jun 2016 13:41:54 +0200 Subject: [PATCH 065/129] Added test --- .../Sorter/TopologicalSorterTest.php | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php index 604ec12a..2835dd61 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php @@ -120,6 +120,32 @@ public function testFailureSortCyclicDependency() $this->sorter->sort(); } + public function testNoFailureOnSelfReferencingCyclicDependency() + { + $node1 = new Mock\Node(1); + $node2 = new Mock\Node(2); + $node3 = new Mock\Node(3); + $node4 = new Mock\Node(4); + $node5 = new Mock\Node(5); + + $this->sorter->addNode('1', $node1); + $this->sorter->addNode('2', $node2); + $this->sorter->addNode('3', $node3); + $this->sorter->addNode('4', $node4); + $this->sorter->addNode('5', $node5); + + $this->sorter->addDependency('1', '2'); + $this->sorter->addDependency('1', '1'); + $this->sorter->addDependency('2', '3'); + $this->sorter->addDependency('3', '4'); + $this->sorter->addDependency('5', '1'); + + $sortedList = $this->sorter->sort(); + $correctList = array($node4, $node3, $node2, $node1, $node5); + + self::assertSame($correctList, $sortedList); + } + public function testFailureSortMissingDependency() { $node1 = new Mock\Node(1); From c5eb5de3e44d38508999e2ea3f92845b88edb4e8 Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Mon, 20 Jun 2016 13:46:22 +0200 Subject: [PATCH 066/129] Renamed test --- .../Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php index 2835dd61..20e202f3 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php @@ -120,7 +120,7 @@ public function testFailureSortCyclicDependency() $this->sorter->sort(); } - public function testNoFailureOnSelfReferencingCyclicDependency() + public function testNoFailureOnSelfReferencingDependency() { $node1 = new Mock\Node(1); $node2 = new Mock\Node(2); From d5caa92565d440d096652bc0689566eae3c7362a Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Wed, 22 Jun 2016 07:49:54 +0200 Subject: [PATCH 067/129] Improved CircularReferenceException --- .../Common/DataFixtures/Sorter/TopologicalSorter.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php index 44fa4d27..4c6eb2fc 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php @@ -156,9 +156,14 @@ private function visit(Vertex $definition) case Vertex::IN_PROGRESS: throw new CircularReferenceException( - 'Graph contains cyclic dependency. 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.' + 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.', + $definition->value->getName(), + $childDefinition->value->getName() + ) ); case Vertex::NOT_VISITED: From de08f972244f8422bcdcbf5b942b60b1bf662bfd Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Sun, 26 Jun 2016 10:39:05 +0200 Subject: [PATCH 068/129] Added name to node --- tests/Doctrine/Tests/Mock/Node.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/Doctrine/Tests/Mock/Node.php b/tests/Doctrine/Tests/Mock/Node.php index d66c6f99..cd5c1121 100644 --- a/tests/Doctrine/Tests/Mock/Node.php +++ b/tests/Doctrine/Tests/Mock/Node.php @@ -32,6 +32,11 @@ class Node */ public $value; + /** + * @var mixed + */ + public $name; + /** * Constructor. * @@ -40,5 +45,6 @@ class Node public function __construct($value) { $this->value = $value; + $this->name = 'Node ' . (string) $value; } } From b59ae9fb223172a4110d9d18ca20ef91f8f0393a Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Sun, 26 Jun 2016 11:08:53 +0200 Subject: [PATCH 069/129] Added getName method to Node --- tests/Doctrine/Tests/Mock/Node.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/Doctrine/Tests/Mock/Node.php b/tests/Doctrine/Tests/Mock/Node.php index cd5c1121..0546fd50 100644 --- a/tests/Doctrine/Tests/Mock/Node.php +++ b/tests/Doctrine/Tests/Mock/Node.php @@ -47,4 +47,12 @@ public function __construct($value) $this->value = $value; $this->name = 'Node ' . (string) $value; } + + /** + * @return mixed + */ + public function getName() + { + return $this->name; + } } From ae776f7a9f2b1b9f400714959ce7ecc542d61f3f Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Sun, 26 Jun 2016 11:43:01 +0200 Subject: [PATCH 070/129] Improved Exception --- .../DataFixtures/Sorter/TopologicalSorter.php | 17 +++++++++++++++-- tests/Doctrine/Tests/Mock/Node.php | 14 -------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php index 4c6eb2fc..f34efb41 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php @@ -155,14 +155,27 @@ private function visit(Vertex $definition) break; case Vertex::IN_PROGRESS: + if ($definition->value instanceof \Doctrine\ORM\Mapping\ClassMetadata) { + 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.', + $definition->value->getName(), + $childDefinition->value->getName() + ) + ); + } + 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.', - $definition->value->getName(), - $childDefinition->value->getName() + get_class($definition->value), + get_class($childDefinition->value) ) ); diff --git a/tests/Doctrine/Tests/Mock/Node.php b/tests/Doctrine/Tests/Mock/Node.php index 0546fd50..d66c6f99 100644 --- a/tests/Doctrine/Tests/Mock/Node.php +++ b/tests/Doctrine/Tests/Mock/Node.php @@ -32,11 +32,6 @@ class Node */ public $value; - /** - * @var mixed - */ - public $name; - /** * Constructor. * @@ -45,14 +40,5 @@ class Node public function __construct($value) { $this->value = $value; - $this->name = 'Node ' . (string) $value; - } - - /** - * @return mixed - */ - public function getName() - { - return $this->name; } } From 6d41aa65f1e1912e2cf9f9a68452f0ec0dcb6fe0 Mon Sep 17 00:00:00 2001 From: Mike Girouard Date: Wed, 29 Jun 2016 15:59:51 -0700 Subject: [PATCH 071/129] Add a getFixture method --- lib/Doctrine/Common/DataFixtures/Loader.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/Doctrine/Common/DataFixtures/Loader.php b/lib/Doctrine/Common/DataFixtures/Loader.php index 4323ca92..d3680f4c 100644 --- a/lib/Doctrine/Common/DataFixtures/Loader.php +++ b/lib/Doctrine/Common/DataFixtures/Loader.php @@ -110,6 +110,21 @@ public function hasFixture($fixture) return isset($this->fixtures[get_class($fixture)]); } + /** + * Get a specific fixture instance + * + * @param string $className + * @return FixtureInterface + */ + public function getFixture($className) + { + if (isset($this->fixtures[$className])) { + throw new \InvalidArgumentException(sprintf('"%s" is not a registered fixture')); + } + + return $this->fixtures[$className]; + } + /** * Add a fixture object instance to the loader. * From 823548420ccacd03883cb3ca153ef7048b91ba28 Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Thu, 30 Jun 2016 14:48:06 +0200 Subject: [PATCH 072/129] Vertex noew requires ClassMetadataInfo as value --- .../DataFixtures/Sorter/TopologicalSorter.php | 24 +++--------- .../Common/DataFixtures/Sorter/Vertex.php | 8 ++-- .../Sorter/TopologicalSorterTest.php | 39 ++++++++++--------- .../Common/DataFixtures/Sorter/VertexTest.php | 3 +- 4 files changed, 33 insertions(+), 41 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php index f34efb41..947235e8 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php @@ -20,6 +20,7 @@ namespace Doctrine\Common\DataFixtures\Sorter; use Doctrine\Common\DataFixtures\Exception\CircularReferenceException; +use Doctrine\ORM\Mapping\ClassMetadataInfo; /** * TopologicalSorter is an ordering algorithm for directed graphs (DG) and/or @@ -54,12 +55,12 @@ class TopologicalSorter /** * Adds a new node (vertex) to the graph, assigning its hash and value. * - * @param string $hash - * @param mixed $node + * @param string $hash + * @param ClassMetadataInfo $node * * @return void */ - public function addNode($hash, $node) + public function addNode($hash, ClassMetadataInfo $node) { $this->nodeList[$hash] = new Vertex($node); } @@ -155,27 +156,14 @@ private function visit(Vertex $definition) break; case Vertex::IN_PROGRESS: - if ($definition->value instanceof \Doctrine\ORM\Mapping\ClassMetadata) { - 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.', - $definition->value->getName(), - $childDefinition->value->getName() - ) - ); - } - 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.', - get_class($definition->value), - get_class($childDefinition->value) + $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 6d066f62..34340771 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/Vertex.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/Vertex.php @@ -19,6 +19,8 @@ namespace Doctrine\Common\DataFixtures\Sorter; +use Doctrine\ORM\Mapping\ClassMetadataInfo; + /** * @author Marco Pivetta * @@ -39,7 +41,7 @@ class Vertex public $state = self::NOT_VISITED; /** - * @var mixed Actual node value + * @var ClassMetadataInfo Actual node value */ public $value; @@ -49,9 +51,9 @@ class Vertex public $dependencyList = []; /** - * @param mixed $value + * @param ClassMetadataInfo $value */ - public function __construct($value) + public function __construct(ClassMetadataInfo $value) { $this->value = $value; } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php index 20e202f3..6a8441c1 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php @@ -22,6 +22,7 @@ use Doctrine\Common\DataFixtures\Exception\CircularReferenceException; use Doctrine\Common\DataFixtures\Sorter\TopologicalSorter; +use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\Tests\Mock; /** @@ -52,11 +53,11 @@ public function setUp() public function testSuccessSortLinearDependency() { - $node1 = new Mock\Node(1); - $node2 = new Mock\Node(2); - $node3 = new Mock\Node(3); - $node4 = new Mock\Node(4); - $node5 = new Mock\Node(5); + $node1 = new ClassMetadataInfo(1); + $node2 = new ClassMetadataInfo(2); + $node3 = new ClassMetadataInfo(3); + $node4 = new ClassMetadataInfo(4); + $node5 = new ClassMetadataInfo(5); $this->sorter->addNode('1', $node1); $this->sorter->addNode('2', $node2); @@ -77,11 +78,11 @@ public function testSuccessSortLinearDependency() public function testSuccessSortMultiDependency() { - $node1 = new Mock\Node(1); - $node2 = new Mock\Node(2); - $node3 = new Mock\Node(3); - $node4 = new Mock\Node(4); - $node5 = new Mock\Node(5); + $node1 = new ClassMetadataInfo(1); + $node2 = new ClassMetadataInfo(2); + $node3 = new ClassMetadataInfo(3); + $node4 = new ClassMetadataInfo(4); + $node5 = new ClassMetadataInfo(5); $this->sorter->addNode('1', $node1); $this->sorter->addNode('2', $node2); @@ -103,9 +104,9 @@ public function testSuccessSortMultiDependency() public function testFailureSortCyclicDependency() { - $node1 = new Mock\Node(1); - $node2 = new Mock\Node(2); - $node3 = new Mock\Node(3); + $node1 = new ClassMetadataInfo(1); + $node2 = new ClassMetadataInfo(2); + $node3 = new ClassMetadataInfo(3); $this->sorter->addNode('1', $node1); $this->sorter->addNode('2', $node2); @@ -122,11 +123,11 @@ public function testFailureSortCyclicDependency() public function testNoFailureOnSelfReferencingDependency() { - $node1 = new Mock\Node(1); - $node2 = new Mock\Node(2); - $node3 = new Mock\Node(3); - $node4 = new Mock\Node(4); - $node5 = new Mock\Node(5); + $node1 = new ClassMetadataInfo(1); + $node2 = new ClassMetadataInfo(2); + $node3 = new ClassMetadataInfo(3); + $node4 = new ClassMetadataInfo(4); + $node5 = new ClassMetadataInfo(5); $this->sorter->addNode('1', $node1); $this->sorter->addNode('2', $node2); @@ -148,7 +149,7 @@ public function testNoFailureOnSelfReferencingDependency() public function testFailureSortMissingDependency() { - $node1 = new Mock\Node(1); + $node1 = new ClassMetadataInfo(1); $this->sorter->addNode('1', $node1); diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php index 6b4e1799..600a979e 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php @@ -21,6 +21,7 @@ namespace Doctrine\Test\DataFixtures\Sorter; use Doctrine\Common\DataFixtures\Sorter\Vertex; +use Doctrine\ORM\Mapping\ClassMetadataInfo; /** * @author Marco Pivetta @@ -31,7 +32,7 @@ class VertexTest extends \PHPUnit_Framework_TestCase { public function testNode() { - $value = new \stdClass(); + $value = new ClassMetadataInfo('\Sample\Entity'); $node = new Vertex($value); self::assertSame($value, $node->value); From 99d3259c9cdd0f7c8fa33d0709eb19f993e13e19 Mon Sep 17 00:00:00 2001 From: Manuel Gonzalez Date: Sat, 25 Jun 2016 23:23:24 +0100 Subject: [PATCH 073/129] Adding test to reference repository --- phpunit.xml.dist | 6 + .../DataFixtures/ReferenceRepositoryTest.php | 116 +++++++++++++++--- 2 files changed, 106 insertions(+), 16 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 99eb5525..885d4308 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -15,4 +15,10 @@ ./tests/Doctrine/ + + + + lib + + diff --git a/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php b/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php index 79158ea4..a0e85af1 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php @@ -21,40 +21,45 @@ use Doctrine\Common\DataFixtures\ReferenceRepository; use Doctrine\Common\DataFixtures\Event\Listener\ORMReferenceListener; -use Doctrine\ORM\Tools\SchemaTool; +use Doctrine\Common\Persistence\Mapping\ClassMetadata; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Proxy\Proxy; +use Doctrine\ORM\Tools\SchemaTool; +use Doctrine\ORM\UnitOfWork; +use Doctrine\Tests\Common\DataFixtures\TestEntity\Role; +use Prophecy\Prophecy\ProphecyInterface; /** - * Test ReferenceRepository. - * * @author Gediminas Morkevicius + * @author Manuel Gonalez */ class ReferenceRepositoryTest extends BaseTest { - const TEST_ENTITY_ROLE = 'Doctrine\Tests\Common\DataFixtures\TestEntity\Role'; - public function testReferenceEntry() { $em = $this->getMockAnnotationReaderEntityManager(); + $role = new TestEntity\Role; $role->setName('admin'); - $meta = $em->getClassMetadata(self::TEST_ENTITY_ROLE); + + $meta = $em->getClassMetadata(Role::class); $meta->getReflectionProperty('id')->setValue($role, 1); $referenceRepo = new ReferenceRepository($em); + $this->assertSame($em, $referenceRepo->getManager()); + $referenceRepo->addReference('test', $role); $references = $referenceRepo->getReferences(); - $this->assertCount(1, $references); $this->assertArrayHasKey('test', $references); - $this->assertInstanceOf(self::TEST_ENTITY_ROLE, $references['test']); + $this->assertInstanceOf(Role::class, $references['test']); } public function testReferenceIdentityPopulation() { $em = $this->getMockSqliteEntityManager(); - $referenceRepository = $this->getMockBuilder('Doctrine\Common\DataFixtures\ReferenceRepository') + $referenceRepository = $this->getMockBuilder(ReferenceRepository::class) ->setConstructorArgs(array($em)) ->getMock(); $em->getEventManager()->addEventSubscriber( @@ -63,7 +68,7 @@ public function testReferenceIdentityPopulation() $schemaTool = new SchemaTool($em); $schemaTool->dropSchema(array()); $schemaTool->createSchema(array( - $em->getClassMetadata(self::TEST_ENTITY_ROLE) + $em->getClassMetadata(Role::class) )); $referenceRepository->expects($this->once()) @@ -94,7 +99,7 @@ public function testReferenceReconstruction() $schemaTool = new SchemaTool($em); $schemaTool->dropSchema(array()); $schemaTool->createSchema(array( - $em->getClassMetadata(self::TEST_ENTITY_ROLE) + $em->getClassMetadata(Role::class) )); $roleFixture = new TestFixtures\RoleFixture; $roleFixture->setReferenceRepository($referenceRepository); @@ -103,13 +108,13 @@ public function testReferenceReconstruction() // first test against managed state $ref = $referenceRepository->getReference('admin-role'); - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $ref); + $this->assertNotInstanceOf(Proxy::class, $ref); // now test reference reconstruction from identity $em->clear(); $ref = $referenceRepository->getReference('admin-role'); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $ref); + $this->assertInstanceOf(Proxy::class, $ref); } public function testReferenceMultipleEntries() @@ -118,7 +123,7 @@ public function testReferenceMultipleEntries() $referenceRepository = new ReferenceRepository($em); $em->getEventManager()->addEventSubscriber(new ORMReferenceListener($referenceRepository)); $schemaTool = new SchemaTool($em); - $schemaTool->createSchema(array($em->getClassMetadata(self::TEST_ENTITY_ROLE))); + $schemaTool->createSchema(array($em->getClassMetadata(Role::class))); $role = new TestEntity\Role; $role->setName('admin'); @@ -129,8 +134,8 @@ public function testReferenceMultipleEntries() $em->flush(); $em->clear(); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $referenceRepository->getReference('admin')); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $referenceRepository->getReference('duplicate')); + $this->assertInstanceOf(Proxy::class, $referenceRepository->getReference('admin')); + $this->assertInstanceOf(Proxy::class, $referenceRepository->getReference('duplicate')); } public function testUndefinedReference() @@ -142,4 +147,83 @@ public function testUndefinedReference() $referenceRepository->getReference('foo'); } + + public function testThrowsExceptionAddingDuplicatedReference() + { + $referenceRepository = new ReferenceRepository($this->getMockSqliteEntityManager()); + $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'); + + $referenceRepository->addReference('duplicated_reference', new \stdClass()); + } + + public function testThrowsExceptionTryingToGetWrongReference() + { + $referenceRepository = new ReferenceRepository($this->getMockSqliteEntityManager()); + + $this->expectException(\OutOfBoundsException::class); + $this->expectExceptionMessage('Reference to: (missing_reference) does not exist'); + + $referenceRepository->getReference('missing_reference'); + } + + public function testHasIdentityCheck() + { + $role = new Role(); + $referenceRepository = new ReferenceRepository($this->getMockSqliteEntityManager()); + $referenceRepository->setReferenceIdentity('entity', $role); + + $this->assertTrue($referenceRepository->hasIdentity('entity')); + $this->assertFalse($referenceRepository->hasIdentity('invalid_entity')); + $this->assertEquals(['entity' => $role], $referenceRepository->getIdentities()); + } + + public function testSetReferenceHavingIdentifier() + { + $em = $this->getMockSqliteEntityManager(); + $referenceRepository = new ReferenceRepository($em); + + $schemaTool = new SchemaTool($em); + $schemaTool->dropSchema(array()); + $schemaTool->createSchema(array( + $em->getClassMetadata(Role::class) + )); + + $role = new Role(); + $role->setName('role_name'); + $em->persist($role); + $em->flush(); + + $referenceRepository->setReference('entity', $role); + $identities = $referenceRepository->getIdentities(); + $this->assertCount(1, $identities); + $this->assertArrayHasKey('entity', $identities); + } + + public function testGetIdentifierWhenHasNotBeenManagedYetByUnitOfWork() + { + $role = new Role(); + $identitiesExpected = ['id' => 1]; + + /** @var UnitOfWork | ProphecyInterface $uow */ + $uow = $this->prophesize(UnitOfWork::class); + $uow->isInIdentityMap($role)->shouldBeCalledTimes(2)->willReturn(true, false); + + /** @var ClassMetadata $classMetadata */ + $classMetadata = $this->prophesize(ClassMetadata::class); + $classMetadata->getIdentifierValues($role)->shouldBeCalled()->willReturn($identitiesExpected); + + /** @var EntityManagerInterface | ProphecyInterface $em */ + $em = $this->prophesize(EntityManagerInterface::class); + $em->getUnitOfWork()->shouldBeCalled()->willReturn($uow); + $em->getClassMetadata(Role::class)->shouldBeCalled()->willReturn($classMetadata); + + $referenceRepository = new ReferenceRepository($em->reveal()); + $referenceRepository->setReference('entity', $role); + $identities = $referenceRepository->getIdentities(); + + $this->assertEquals($identitiesExpected, $identities['entity']); + } } From bc6e94224851e331626f98b49747cede67f36058 Mon Sep 17 00:00:00 2001 From: Mike Girouard Date: Thu, 30 Jun 2016 10:48:42 -0700 Subject: [PATCH 074/129] Fix bad sprintf call --- lib/Doctrine/Common/DataFixtures/Loader.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/Common/DataFixtures/Loader.php b/lib/Doctrine/Common/DataFixtures/Loader.php index d3680f4c..72fc5ac6 100644 --- a/lib/Doctrine/Common/DataFixtures/Loader.php +++ b/lib/Doctrine/Common/DataFixtures/Loader.php @@ -119,7 +119,10 @@ public function hasFixture($fixture) public function getFixture($className) { if (isset($this->fixtures[$className])) { - throw new \InvalidArgumentException(sprintf('"%s" is not a registered fixture')); + throw new \InvalidArgumentException(sprintf( + '"%s" is not a registered fixture', + $className + )); } return $this->fixtures[$className]; From 1e4a4eebc03eb2eedbd66881051e618e84f28f88 Mon Sep 17 00:00:00 2001 From: Mike Girouard Date: Thu, 30 Jun 2016 11:00:04 -0700 Subject: [PATCH 075/129] Add test, fix bad logic --- lib/Doctrine/Common/DataFixtures/Loader.php | 2 +- .../Doctrine/Tests/Common/DataFixtures/LoaderTest.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/Common/DataFixtures/Loader.php b/lib/Doctrine/Common/DataFixtures/Loader.php index 72fc5ac6..5252c1f1 100644 --- a/lib/Doctrine/Common/DataFixtures/Loader.php +++ b/lib/Doctrine/Common/DataFixtures/Loader.php @@ -118,7 +118,7 @@ public function hasFixture($fixture) */ public function getFixture($className) { - if (isset($this->fixtures[$className])) { + if (!isset($this->fixtures[$className])) { throw new \InvalidArgumentException(sprintf( '"%s" is not a registered fixture', $className diff --git a/tests/Doctrine/Tests/Common/DataFixtures/LoaderTest.php b/tests/Doctrine/Tests/Common/DataFixtures/LoaderTest.php index 19273352..efc13625 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/LoaderTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/LoaderTest.php @@ -22,6 +22,7 @@ use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Common\DataFixtures\Loader; use Doctrine\Common\DataFixtures\SharedFixtureInterface; +use TestFixtures\MyFixture1; /** * Test fixtures loader. @@ -63,4 +64,14 @@ public function testLoadFromFile() $this->assertTrue($loader->isTransient('TestFixtures\NotAFixture')); $this->assertFalse($loader->isTransient('TestFixtures\MyFixture1')); } + + public function testGetFixture() + { + $loader = new Loader(); + $loader->loadFromFile(__DIR__.'/TestFixtures/MyFixture1.php'); + + $fixture = $loader->getFixture(MyFixture1::class); + + $this->assertInstanceOf(MyFixture1::class, $fixture); + } } From abf71fed0875e6b209982079781d0d6781eff4cd Mon Sep 17 00:00:00 2001 From: YaoOcelotl Date: Tue, 5 Jul 2016 03:02:56 -0500 Subject: [PATCH 076/129] Add ability to exclude tables from purge in ORM (#225) Added the option to exclude tables/views from purge --- .../Common/DataFixtures/Purger/ORMPurger.php | 33 ++++-- .../Purger/ORMPurgerExcludeTest.php | 108 ++++++++++++++++++ .../TestPurgeEntity/ExcludedEntity.php | 25 ++++ .../TestPurgeEntity/IncludedEntity.php | 25 ++++ 4 files changed, 181 insertions(+), 10 deletions(-) create mode 100644 tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php create mode 100644 tests/Doctrine/Tests/Common/DataFixtures/TestPurgeEntity/ExcludedEntity.php create mode 100644 tests/Doctrine/Tests/Common/DataFixtures/TestPurgeEntity/IncludedEntity.php diff --git a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php index c5c22188..ec44d7ee 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php @@ -46,14 +46,23 @@ class ORMPurger implements PurgerInterface */ private $purgeMode = self::PURGE_MODE_DELETE; + /** + * 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 */ - public function __construct(EntityManagerInterface $em = null) + public function __construct(EntityManagerInterface $em = null, array $excluded = array()) { $this->em = $em; + $this->excluded = $excluded; } /** @@ -131,14 +140,18 @@ public function purge() $orderedTables[] = $this->getTableName($class, $platform); } - $connection = $this->em->getConnection(); - foreach($orderedTables as $tbl) { - if ($this->purgeMode === self::PURGE_MODE_DELETE) { - $connection->executeUpdate('DELETE FROM ' . $tbl); - } else { - $connection->executeUpdate($platform->getTruncateTableSQL($tbl, true)); - } - } + $connection = $this->em->getConnection(); + $filterExpr = $connection->getConfiguration()->getFilterSchemaAssetsExpression(); + $emptyFilterExpression = empty($filterExpr); + foreach($orderedTables as $tbl) { + if(($emptyFilterExpression||preg_match($filterExpr, $tbl)) && array_search($tbl, $this->excluded) === false){ + if ($this->purgeMode === self::PURGE_MODE_DELETE) { + $connection->executeUpdate("DELETE FROM " . $tbl); + } else { + $connection->executeUpdate($platform->getTruncateTableSQL($tbl, true)); + } + } + } } /** @@ -247,4 +260,4 @@ private function getJoinTableName($assoc, $class, $platform) return $this->em->getConfiguration()->getQuoteStrategy()->getJoinTableName($assoc, $class, $platform); } -} +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php new file mode 100644 index 00000000..9c9bd777 --- /dev/null +++ b/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php @@ -0,0 +1,108 @@ +markTestSkipped('Missing pdo_sqlite extension.'); + } + + $dbParams = array('driver' => 'pdo_sqlite', 'memory' => true); + $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__.'/../TestPurgeEntity'), true); + $em = EntityManager::create($dbParams, $config); + + $connection = $em->getConnection(); + $configuration = $connection->getConfiguration(); + $configuration->setFilterSchemaAssetsExpression(null); + + $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em); + $schemaTool->dropDatabase(); + $schemaTool->createSchema(array( + $em->getClassMetadata(self::TEST_ENTITY_INCLUDED), + $em->getClassMetadata(self::TEST_ENTITY_EXCLUDED) + )); + + $entity = new ExcludedEntity(); + $entity->setId(1); + $em->persist($entity); + + $entity = new IncludedEntity(); + $entity->setId(1); + $em->persist($entity); + + $em->flush(); + + return $em; + } + + /** + * Execute test purge + * + * @param string|null $expression + * @param array $list + */ + public function executeTestPurge($expression, array $list){ + $em = $this->loadTestData(); + $excludedRepository = $em->getRepository(self::TEST_ENTITY_EXCLUDED); + $includedRepository = $em->getRepository(self::TEST_ENTITY_INCLUDED); + + $excluded = $excludedRepository->findAll(); + $included = $includedRepository->findAll(); + + $this->assertGreaterThan(0, count($included)); + $this->assertGreaterThan(0, count($excluded)); + + $connection = $em->getConnection(); + $configuration = $connection->getConfiguration(); + $configuration->setFilterSchemaAssetsExpression($expression); + + $purger = new ORMPurger($em,$list); + $purger->purge(); + + $excluded = $excludedRepository->findAll(); + $included = $includedRepository->findAll(); + + $this->assertEquals(0, count($included)); + $this->assertGreaterThan(0, count($excluded)); + + } + + /** + * Test for purge exclusion usig dbal filter expression regexp. + * + */ + public function testPurgeExcludeUsingFilterExpression(){ + $this->executeTestPurge('~^(?!ExcludedEntity)~', array()); + } + + /** + * Test for purge exclusion usig explicit exclution list. + * + */ + public function testPurgeExcludeUsingList(){ + $this->executeTestPurge(null,array('ExcludedEntity')); + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/Common/DataFixtures/TestPurgeEntity/ExcludedEntity.php b/tests/Doctrine/Tests/Common/DataFixtures/TestPurgeEntity/ExcludedEntity.php new file mode 100644 index 00000000..c3e594a6 --- /dev/null +++ b/tests/Doctrine/Tests/Common/DataFixtures/TestPurgeEntity/ExcludedEntity.php @@ -0,0 +1,25 @@ +id = $id; + } + + 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 new file mode 100644 index 00000000..5038263e --- /dev/null +++ b/tests/Doctrine/Tests/Common/DataFixtures/TestPurgeEntity/IncludedEntity.php @@ -0,0 +1,25 @@ +id = $id; + } + + public function getId() { + return $this->id; + } +} \ No newline at end of file From f6ffd3185c31ee6e0ea9bd2c5eefd2d7ab61cc40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ustek?= Date: Wed, 6 Jul 2016 00:04:12 +0200 Subject: [PATCH 077/129] Make the order of data fixtures loading deterministic (#215) --- lib/Doctrine/Common/DataFixtures/Loader.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Doctrine/Common/DataFixtures/Loader.php b/lib/Doctrine/Common/DataFixtures/Loader.php index 4323ca92..ea438b74 100644 --- a/lib/Doctrine/Common/DataFixtures/Loader.php +++ b/lib/Doctrine/Common/DataFixtures/Loader.php @@ -350,6 +350,9 @@ private function loadFromIterator(\Iterator $iterator) $fixtures = array(); $declared = get_declared_classes(); + // Make the declared classes order deterministic + sort($declared); + foreach ($declared as $className) { $reflClass = new \ReflectionClass($className); $sourceFile = $reflClass->getFileName(); From a7ed7dec6fe29e1175718e9728b7d5aedaf76ca9 Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Thu, 7 Jul 2016 20:43:47 +0200 Subject: [PATCH 078/129] Updated Vertex to use ClassMetadata instead of ClassMetadataInfo --- .../DataFixtures/Sorter/TopologicalSorter.php | 6 +-- .../Common/DataFixtures/Sorter/Vertex.php | 8 ++-- .../Sorter/TopologicalSorterTest.php | 40 +++++++++---------- .../Common/DataFixtures/Sorter/VertexTest.php | 4 +- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php index 947235e8..c8644b53 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php @@ -20,7 +20,7 @@ namespace Doctrine\Common\DataFixtures\Sorter; use Doctrine\Common\DataFixtures\Exception\CircularReferenceException; -use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\ORM\Mapping\ClassMetadata; /** * TopologicalSorter is an ordering algorithm for directed graphs (DG) and/or @@ -56,11 +56,11 @@ class TopologicalSorter * Adds a new node (vertex) to the graph, assigning its hash and value. * * @param string $hash - * @param ClassMetadataInfo $node + * @param ClassMetadata $node * * @return void */ - public function addNode($hash, ClassMetadataInfo $node) + public function addNode($hash, ClassMetadata $node) { $this->nodeList[$hash] = new Vertex($node); } diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/Vertex.php b/lib/Doctrine/Common/DataFixtures/Sorter/Vertex.php index 34340771..0316d1d3 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/Vertex.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/Vertex.php @@ -19,7 +19,7 @@ namespace Doctrine\Common\DataFixtures\Sorter; -use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\ORM\Mapping\ClassMetadata; /** * @author Marco Pivetta @@ -41,7 +41,7 @@ class Vertex public $state = self::NOT_VISITED; /** - * @var ClassMetadataInfo Actual node value + * @var ClassMetadata Actual node value */ public $value; @@ -51,9 +51,9 @@ class Vertex public $dependencyList = []; /** - * @param ClassMetadataInfo $value + * @param ClassMetadata $value */ - public function __construct(ClassMetadataInfo $value) + public function __construct(ClassMetadata $value) { $this->value = $value; } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php index 6a8441c1..8e744650 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php @@ -22,7 +22,7 @@ use Doctrine\Common\DataFixtures\Exception\CircularReferenceException; use Doctrine\Common\DataFixtures\Sorter\TopologicalSorter; -use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\Tests\Mock; /** @@ -53,11 +53,11 @@ public function setUp() public function testSuccessSortLinearDependency() { - $node1 = new ClassMetadataInfo(1); - $node2 = new ClassMetadataInfo(2); - $node3 = new ClassMetadataInfo(3); - $node4 = new ClassMetadataInfo(4); - $node5 = new ClassMetadataInfo(5); + $node1 = new ClassMetadata(1); + $node2 = new ClassMetadata(2); + $node3 = new ClassMetadata(3); + $node4 = new ClassMetadata(4); + $node5 = new ClassMetadata(5); $this->sorter->addNode('1', $node1); $this->sorter->addNode('2', $node2); @@ -78,11 +78,11 @@ public function testSuccessSortLinearDependency() public function testSuccessSortMultiDependency() { - $node1 = new ClassMetadataInfo(1); - $node2 = new ClassMetadataInfo(2); - $node3 = new ClassMetadataInfo(3); - $node4 = new ClassMetadataInfo(4); - $node5 = new ClassMetadataInfo(5); + $node1 = new ClassMetadata(1); + $node2 = new ClassMetadata(2); + $node3 = new ClassMetadata(3); + $node4 = new ClassMetadata(4); + $node5 = new ClassMetadata(5); $this->sorter->addNode('1', $node1); $this->sorter->addNode('2', $node2); @@ -104,9 +104,9 @@ public function testSuccessSortMultiDependency() public function testFailureSortCyclicDependency() { - $node1 = new ClassMetadataInfo(1); - $node2 = new ClassMetadataInfo(2); - $node3 = new ClassMetadataInfo(3); + $node1 = new ClassMetadata(1); + $node2 = new ClassMetadata(2); + $node3 = new ClassMetadata(3); $this->sorter->addNode('1', $node1); $this->sorter->addNode('2', $node2); @@ -123,11 +123,11 @@ public function testFailureSortCyclicDependency() public function testNoFailureOnSelfReferencingDependency() { - $node1 = new ClassMetadataInfo(1); - $node2 = new ClassMetadataInfo(2); - $node3 = new ClassMetadataInfo(3); - $node4 = new ClassMetadataInfo(4); - $node5 = new ClassMetadataInfo(5); + $node1 = new ClassMetadata(1); + $node2 = new ClassMetadata(2); + $node3 = new ClassMetadata(3); + $node4 = new ClassMetadata(4); + $node5 = new ClassMetadata(5); $this->sorter->addNode('1', $node1); $this->sorter->addNode('2', $node2); @@ -149,7 +149,7 @@ public function testNoFailureOnSelfReferencingDependency() public function testFailureSortMissingDependency() { - $node1 = new ClassMetadataInfo(1); + $node1 = new ClassMetadata(1); $this->sorter->addNode('1', $node1); diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php index 600a979e..de2e9f84 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php @@ -21,7 +21,7 @@ namespace Doctrine\Test\DataFixtures\Sorter; use Doctrine\Common\DataFixtures\Sorter\Vertex; -use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\ORM\Mapping\ClassMetadata; /** * @author Marco Pivetta @@ -32,7 +32,7 @@ class VertexTest extends \PHPUnit_Framework_TestCase { public function testNode() { - $value = new ClassMetadataInfo('\Sample\Entity'); + $value = new ClassMetadata('\Sample\Entity'); $node = new Vertex($value); self::assertSame($value, $node->value); From fbd7abf58f7496998d79e37087554f8dbd6ae7d2 Mon Sep 17 00:00:00 2001 From: "a.saintvanne" Date: Tue, 26 Jul 2016 18:37:57 +0200 Subject: [PATCH 079/129] Retrieve old behaviour on Sorter --- .../Common/DataFixtures/Purger/ORMPurger.php | 6 ++++-- .../DataFixtures/Sorter/TopologicalSorter.php | 13 +------------ .../DataFixtures/Sorter/TopologicalSorterTest.php | 4 +++- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php index ec44d7ee..aece53b9 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php @@ -165,7 +165,9 @@ private function getCommitOrder(EntityManagerInterface $em, array $classes) $sorter = new TopologicalSorter(); foreach ($classes as $class) { - $sorter->addNode($class->name, $class); + if ( ! $sorter->hasNode($class->name)) { + $sorter->addNode($class->name, $class); + } // $class before its parents foreach ($class->parentClasses as $parentClass) { @@ -207,7 +209,7 @@ private function getCommitOrder(EntityManagerInterface $em, array $classes) } } - return $sorter->sort(); + return array_reverse($sorter->sort()); } /** diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php index c8644b53..946be795 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php @@ -153,19 +153,8 @@ private function visit(Vertex $definition) switch ($childDefinition->state) { case Vertex::VISITED: - break; - case Vertex::IN_PROGRESS: - 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.', - $definition->value->getName(), - $childDefinition->value->getName() - ) - ); + break; case Vertex::NOT_VISITED: $this->visit($childDefinition); diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php index 8e744650..90b2017f 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php @@ -116,7 +116,9 @@ public function testFailureSortCyclicDependency() $this->sorter->addDependency('2', '3'); $this->sorter->addDependency('3', '1'); - $this->expectException(CircularReferenceException::class); + $sortedList = $this->sorter->sort(); + + self::assertSame(array($node3, $node2, $node1), $sortedList); $this->sorter->sort(); } From ce8112c225e2c22847a125dca9f3c0ae8f9bab4a Mon Sep 17 00:00:00 2001 From: "a.saintvanne" Date: Tue, 26 Jul 2016 18:42:09 +0200 Subject: [PATCH 080/129] Replace switch case to simple if --- .../Common/DataFixtures/Sorter/TopologicalSorter.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php index 946be795..c6017d78 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php @@ -151,14 +151,10 @@ private function visit(Vertex $definition) continue; } - switch ($childDefinition->state) { - case Vertex::VISITED: - case Vertex::IN_PROGRESS: - break; - - case Vertex::NOT_VISITED: - $this->visit($childDefinition); + if ($childDefinition->state == Vertex::NOT_VISITED) { + $this->visit($childDefinition); } + } $definition->state = Vertex::VISITED; From 73c5b6ddef9bae64ae37c1237cdc12353aafe25d Mon Sep 17 00:00:00 2001 From: "a.saintvanne" Date: Tue, 26 Jul 2016 18:56:08 +0200 Subject: [PATCH 081/129] Rename test function name --- .../Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php index 90b2017f..ad3ed3c2 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php @@ -102,7 +102,7 @@ public function testSuccessSortMultiDependency() self::assertSame($correctList, $sortedList); } - public function testFailureSortCyclicDependency() + public function testSortCyclicDependency() { $node1 = new ClassMetadata(1); $node2 = new ClassMetadata(2); From 4b97c4ce960930b68c263fb8da0a1d9a328bd0f7 Mon Sep 17 00:00:00 2001 From: "a.saintvanne" Date: Wed, 27 Jul 2016 12:36:27 +0200 Subject: [PATCH 082/129] Reintroduce exception on cyclic dependencies --- .../DataFixtures/Sorter/TopologicalSorter.php | 39 ++++- .../Sorter/TopologicalSorterTest.php | 134 ++++++++++-------- 2 files changed, 112 insertions(+), 61 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php index c6017d78..62e5ad33 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php @@ -52,6 +52,23 @@ class TopologicalSorter */ private $sortedNodeList = []; + /** + * Allow or not cyclic dependencies + * + * @var boolean + */ + private $allowCyclicDependencies; + + /** + * Construct TopologicalSorter object + * + * @param boolean $allowCyclicDependencies + */ + public function __construct($allowCyclicDependencies = true) + { + $this->allowCyclicDependencies = $allowCyclicDependencies; + } + /** * Adds a new node (vertex) to the graph, assigning its hash and value. * @@ -151,10 +168,26 @@ private function visit(Vertex $definition) continue; } - if ($childDefinition->state == Vertex::NOT_VISITED) { - $this->visit($childDefinition); + switch ($childDefinition->state) { + case Vertex::VISITED: + break; + case Vertex::IN_PROGRESS: + 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.', + $definition->value->getName(), + $childDefinition->value->getName() + ) + ); + } + break; + case Vertex::NOT_VISITED: + $this->visit($childDefinition); } - } $definition->state = Vertex::VISITED; diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php index ad3ed3c2..5630294b 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php @@ -23,7 +23,6 @@ use Doctrine\Common\DataFixtures\Exception\CircularReferenceException; use Doctrine\Common\DataFixtures\Sorter\TopologicalSorter; use Doctrine\ORM\Mapping\ClassMetadata; -use Doctrine\Tests\Mock; /** * TopologicalSorter tests. @@ -38,39 +37,28 @@ */ class TopologicalSorterTest extends \PHPUnit_Framework_TestCase { - /** - * @var \Doctrine\Common\DataFixtures\Sorter\TopologicalSorter - */ - private $sorter; - - /** - * {@inheritdoc} - */ - public function setUp() - { - $this->sorter = new TopologicalSorter(); - } - public function testSuccessSortLinearDependency() { + $sorter = new TopologicalSorter(); + $node1 = new ClassMetadata(1); $node2 = new ClassMetadata(2); $node3 = new ClassMetadata(3); $node4 = new ClassMetadata(4); $node5 = new ClassMetadata(5); - $this->sorter->addNode('1', $node1); - $this->sorter->addNode('2', $node2); - $this->sorter->addNode('3', $node3); - $this->sorter->addNode('4', $node4); - $this->sorter->addNode('5', $node5); + $sorter->addNode('1', $node1); + $sorter->addNode('2', $node2); + $sorter->addNode('3', $node3); + $sorter->addNode('4', $node4); + $sorter->addNode('5', $node5); - $this->sorter->addDependency('1', '2'); - $this->sorter->addDependency('2', '3'); - $this->sorter->addDependency('3', '4'); - $this->sorter->addDependency('5', '1'); + $sorter->addDependency('1', '2'); + $sorter->addDependency('2', '3'); + $sorter->addDependency('3', '4'); + $sorter->addDependency('5', '1'); - $sortedList = $this->sorter->sort(); + $sortedList = $sorter->sort(); $correctList = array($node4, $node3, $node2, $node1, $node5); self::assertSame($correctList, $sortedList); @@ -78,25 +66,27 @@ public function testSuccessSortLinearDependency() public function testSuccessSortMultiDependency() { + $sorter = new TopologicalSorter(); + $node1 = new ClassMetadata(1); $node2 = new ClassMetadata(2); $node3 = new ClassMetadata(3); $node4 = new ClassMetadata(4); $node5 = new ClassMetadata(5); - $this->sorter->addNode('1', $node1); - $this->sorter->addNode('2', $node2); - $this->sorter->addNode('3', $node3); - $this->sorter->addNode('4', $node4); - $this->sorter->addNode('5', $node5); + $sorter->addNode('1', $node1); + $sorter->addNode('2', $node2); + $sorter->addNode('3', $node3); + $sorter->addNode('4', $node4); + $sorter->addNode('5', $node5); - $this->sorter->addDependency('3', '2'); - $this->sorter->addDependency('3', '4'); - $this->sorter->addDependency('3', '5'); - $this->sorter->addDependency('4', '1'); - $this->sorter->addDependency('5', '1'); + $sorter->addDependency('3', '2'); + $sorter->addDependency('3', '4'); + $sorter->addDependency('3', '5'); + $sorter->addDependency('4', '1'); + $sorter->addDependency('5', '1'); - $sortedList = $this->sorter->sort(); + $sortedList = $sorter->sort(); $correctList = array($node1, $node2, $node4, $node5, $node3); self::assertSame($correctList, $sortedList); @@ -104,46 +94,72 @@ public function testSuccessSortMultiDependency() public function testSortCyclicDependency() { + $sorter = new TopologicalSorter(); + $node1 = new ClassMetadata(1); $node2 = new ClassMetadata(2); $node3 = new ClassMetadata(3); - $this->sorter->addNode('1', $node1); - $this->sorter->addNode('2', $node2); - $this->sorter->addNode('3', $node3); + $sorter->addNode('1', $node1); + $sorter->addNode('2', $node2); + $sorter->addNode('3', $node3); + + $sorter->addDependency('1', '2'); + $sorter->addDependency('2', '3'); + $sorter->addDependency('3', '1'); + + $sortedList = $sorter->sort(); + $correctList = array($node3, $node2, $node1); + + self::assertSame($correctList, $sortedList); + + $sorter->sort(); + } + + public function testFailureSortCyclicDependency() + { + $sorter = new TopologicalSorter(false); + + $node1 = new ClassMetadata(1); + $node2 = new ClassMetadata(2); + $node3 = new ClassMetadata(3); - $this->sorter->addDependency('1', '2'); - $this->sorter->addDependency('2', '3'); - $this->sorter->addDependency('3', '1'); + $sorter->addNode('1', $node1); + $sorter->addNode('2', $node2); + $sorter->addNode('3', $node3); - $sortedList = $this->sorter->sort(); + $sorter->addDependency('1', '2'); + $sorter->addDependency('2', '3'); + $sorter->addDependency('3', '1'); - self::assertSame(array($node3, $node2, $node1), $sortedList); + $this->expectException(CircularReferenceException::class); - $this->sorter->sort(); + $sorter->sort(); } public function testNoFailureOnSelfReferencingDependency() { + $sorter = new TopologicalSorter(); + $node1 = new ClassMetadata(1); $node2 = new ClassMetadata(2); $node3 = new ClassMetadata(3); $node4 = new ClassMetadata(4); $node5 = new ClassMetadata(5); - $this->sorter->addNode('1', $node1); - $this->sorter->addNode('2', $node2); - $this->sorter->addNode('3', $node3); - $this->sorter->addNode('4', $node4); - $this->sorter->addNode('5', $node5); + $sorter->addNode('1', $node1); + $sorter->addNode('2', $node2); + $sorter->addNode('3', $node3); + $sorter->addNode('4', $node4); + $sorter->addNode('5', $node5); - $this->sorter->addDependency('1', '2'); - $this->sorter->addDependency('1', '1'); - $this->sorter->addDependency('2', '3'); - $this->sorter->addDependency('3', '4'); - $this->sorter->addDependency('5', '1'); + $sorter->addDependency('1', '2'); + $sorter->addDependency('1', '1'); + $sorter->addDependency('2', '3'); + $sorter->addDependency('3', '4'); + $sorter->addDependency('5', '1'); - $sortedList = $this->sorter->sort(); + $sortedList = $sorter->sort(); $correctList = array($node4, $node3, $node2, $node1, $node5); self::assertSame($correctList, $sortedList); @@ -151,14 +167,16 @@ public function testNoFailureOnSelfReferencingDependency() public function testFailureSortMissingDependency() { + $sorter = new TopologicalSorter(); + $node1 = new ClassMetadata(1); - $this->sorter->addNode('1', $node1); + $sorter->addNode('1', $node1); - $this->sorter->addDependency('1', '2'); + $sorter->addDependency('1', '2'); $this->expectException(\RuntimeException::class); - $this->sorter->sort(); + $sorter->sort(); } } From 870e5b7bc2124080f2faa5c9d6c121b47d2baf5e Mon Sep 17 00:00:00 2001 From: rcarree Date: Tue, 17 Jan 2017 18:03:07 +0100 Subject: [PATCH 083/129] Rename example classes names for consistency --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 41474a02..65ea1f09 100644 --- a/README.md +++ b/README.md @@ -30,10 +30,10 @@ Now you can begin adding the fixtures to a loader instance: ```php use Doctrine\Common\DataFixtures\Loader; -use MyDataFixtures\LoadUserData; +use MyDataFixtures\UserDataLoader; $loader = new Loader(); -$loader->addFixture(new LoadUserData()); +$loader->addFixture(new UserDataLoader()); ``` You can load a set of fixtures from a directory as well: @@ -82,7 +82,7 @@ namespace MyDataFixtures; use Doctrine\Common\DataFixtures\AbstractFixture; use Doctrine\Common\Persistence\ObjectManager; -class LoadUserRoleData extends AbstractFixture +class UserRoleDataLoader extends AbstractFixture { public function load(ObjectManager $manager) { @@ -110,7 +110,7 @@ namespace MyDataFixtures; use Doctrine\Common\DataFixtures\AbstractFixture; use Doctrine\Common\Persistence\ObjectManager; -class LoadUserData extends AbstractFixture +class UserDataLoader extends AbstractFixture { public function load(ObjectManager $manager) { From ff25e45fa39aafc718b1ce6b653f0eeaac005758 Mon Sep 17 00:00:00 2001 From: Felipe Martins Date: Thu, 23 Feb 2017 14:58:41 -0300 Subject: [PATCH 084/129] Fix syntax highlighting on README --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 65ea1f09..00a98212 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,9 @@ $loader->loadFromDirectory('/path/to/MyDataFixtures'); Or you can load a set of fixtures from a file: - $loader->loadFromFile('/path/to/MyDataFixtures/MyFixture1.php'); +```php +$loader->loadFromFile('/path/to/MyDataFixtures/MyFixture1.php'); +``` You can get the added fixtures using the getFixtures() method: From cc6789f0d1e9c321711edb4bc7009dfe8d8057be Mon Sep 17 00:00:00 2001 From: aemaething Date: Sat, 29 Apr 2017 21:03:07 +0200 Subject: [PATCH 085/129] Added handling of PHPCR documents on method 'getIdentifier()'. --- lib/Doctrine/Common/DataFixtures/ReferenceRepository.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php b/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php index 6385ed7e..70402445 100644 --- a/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php +++ b/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php @@ -87,6 +87,11 @@ protected function getIdentifier($reference, $uow) return $uow->getEntityIdentifier($reference); } + // PHPCR ODM UnitOfWork + if ($this->manager instanceof PhpcrDocumentManager) { + return $uow->getDocumentId($reference); + } + // ODM UnitOfWork return $uow->getDocumentIdentifier($reference); } From d2a49c6763dce0f62749aad302f1f44b0f3bd5e0 Mon Sep 17 00:00:00 2001 From: Felipe Martins Date: Sat, 27 May 2017 23:41:57 -0300 Subject: [PATCH 086/129] Use PSR-4 instead of PSR-0 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 612d2cac..31752df0 100644 --- a/composer.json +++ b/composer.json @@ -26,10 +26,10 @@ "doctrine/phpcr-odm": "For loading PHPCR ODM fixtures" }, "autoload": { - "psr-0": { "Doctrine\\Common\\DataFixtures": "lib/" } + "psr-4": { "Doctrine\\Common\\DataFixtures\\": "lib/Doctrine/Common/DataFixtures" } }, "autoload-dev": { - "psr-0": { "Doctrine\\Tests": "tests/" } + "psr-4": { "Doctrine\\Tests\\": "tests/Doctrine/Tests" } }, "extra": { "branch-alias": { From c36e0ca2d11169dcc8d52bc230c54c827ba71385 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Sun, 6 Aug 2017 16:46:52 +0200 Subject: [PATCH 087/129] Require PHP 7.1 --- .travis.yml | 10 +++++----- composer.json | 8 +++----- .../Tests/Common/DataFixtures/TestDocument/Role.php | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index c1b7cda3..4e3396a0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,10 +7,9 @@ cache: - $HOME/.composer/cache php: - - 5.6 - - 7.0 + - 7.1 + - 7.2 - nightly - - hhvm matrix: allow_failures: @@ -19,12 +18,13 @@ matrix: services: mongodb before_install: - - "if [[ $TRAVIS_PHP_VERSION != 'hhvm' && $TRAVIS_PHP_VERSION != '7.0' ]]; then echo 'extension = mongo.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi" + - pecl install mongodb before_script: - composer self-update - composer install --prefer-source - - "if [[ $TRAVIS_PHP_VERSION != 'hhvm' && $TRAVIS_PHP_VERSION != '7.0' ]]; then composer require 'doctrine/mongodb-odm' '*@beta'; fi" + - composer require --ignore-platform-reqs alcaeus/mongo-php-adapter + - composer require doctrine/mongodb-odm script: - ./vendor/bin/phpunit -v diff --git a/composer.json b/composer.json index 31752df0..0b1969c3 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ {"name": "Jonathan Wage", "email": "jonwage@gmail.com"} ], "require": { - "php": "^5.6 || ^7.0", + "php": "^7.1", "doctrine/common": "~2.2" }, "require-dev": { @@ -17,13 +17,11 @@ "doctrine/dbal": "^2.5.4", "phpunit/phpunit": "^5.4.6" }, - "conflict": { - "doctrine/orm": "< 2.4" - }, "suggest": { "doctrine/orm": "For loading ORM fixtures", "doctrine/mongodb-odm": "For loading MongoDB ODM fixtures", - "doctrine/phpcr-odm": "For loading PHPCR ODM fixtures" + "doctrine/phpcr-odm": "For loading PHPCR ODM fixtures", + "alcaeus/mongo-php-adapter": "For using MongoDB ODM with PHP 7" }, "autoload": { "psr-4": { "Doctrine\\Common\\DataFixtures\\": "lib/Doctrine/Common/DataFixtures" } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/TestDocument/Role.php b/tests/Doctrine/Tests/Common/DataFixtures/TestDocument/Role.php index 463cd610..aa6e3dbc 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/TestDocument/Role.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/TestDocument/Role.php @@ -15,7 +15,7 @@ class Role private $id; /** - * @ODM\String + * @ODM\Field(type="string") * @ODM\Index */ private $name; From 5a2522c3d70346f97fc98e16eda42941dd92451e Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Sun, 6 Aug 2017 16:50:12 +0200 Subject: [PATCH 088/129] Introduce short array syntax and ::class constants --- .../Listener/MongoDBReferenceListener.php | 4 +- .../Event/Listener/ORMReferenceListener.php | 4 +- lib/Doctrine/Common/DataFixtures/Loader.php | 20 +-- .../DataFixtures/ProxyReferenceRepository.php | 8 +- .../Common/DataFixtures/Purger/ORMPurger.php | 8 +- .../DataFixtures/ReferenceRepository.php | 4 +- .../Tests/Common/DataFixtures/BaseTest.php | 8 +- .../DataFixtures/DependentFixtureTest.php | 90 +++++------ .../Executor/ORMExecutorSharedFixtureTest.php | 14 +- .../DataFixtures/Executor/ORMExecutorTest.php | 6 +- .../Executor/PHPCRExecutorTest.php | 10 +- .../Tests/Common/DataFixtures/LoaderTest.php | 9 +- .../DataFixtures/OrderedFixtureTest.php | 8 +- .../ProxyReferenceRepositoryTest.php | 39 ++--- .../DataFixtures/Purger/MongoDBPurgerTest.php | 2 +- .../Purger/ORMPurgerExcludeTest.php | 152 +++++++++--------- .../DataFixtures/Purger/ORMPurgerTest.php | 23 ++- .../DataFixtures/ReferenceRepositoryTest.php | 26 +-- .../Sorter/TopologicalSorterTest.php | 8 +- 19 files changed, 208 insertions(+), 235 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Event/Listener/MongoDBReferenceListener.php b/lib/Doctrine/Common/DataFixtures/Event/Listener/MongoDBReferenceListener.php index 04a4a2c4..3fa20f2d 100644 --- a/lib/Doctrine/Common/DataFixtures/Event/Listener/MongoDBReferenceListener.php +++ b/lib/Doctrine/Common/DataFixtures/Event/Listener/MongoDBReferenceListener.php @@ -52,9 +52,9 @@ public function __construct(ReferenceRepository $referenceRepository) */ public function getSubscribedEvents() { - return array( + return [ 'postPersist' - ); + ]; } /** diff --git a/lib/Doctrine/Common/DataFixtures/Event/Listener/ORMReferenceListener.php b/lib/Doctrine/Common/DataFixtures/Event/Listener/ORMReferenceListener.php index 0aeb3cf1..efc8cab1 100644 --- a/lib/Doctrine/Common/DataFixtures/Event/Listener/ORMReferenceListener.php +++ b/lib/Doctrine/Common/DataFixtures/Event/Listener/ORMReferenceListener.php @@ -52,9 +52,9 @@ public function __construct(ReferenceRepository $referenceRepository) */ public function getSubscribedEvents() { - return array( + return [ 'postPersist' // would be better to use onClear, but it is supported only in 2.1 - ); + ]; } /** diff --git a/lib/Doctrine/Common/DataFixtures/Loader.php b/lib/Doctrine/Common/DataFixtures/Loader.php index b3c20a33..0d8aafae 100644 --- a/lib/Doctrine/Common/DataFixtures/Loader.php +++ b/lib/Doctrine/Common/DataFixtures/Loader.php @@ -33,14 +33,14 @@ class Loader * * @var array */ - private $fixtures = array(); + private $fixtures = []; /** * Array of ordered fixture object instances. * * @var array */ - private $orderedFixtures = array(); + private $orderedFixtures = []; /** * Determines if we must order fixtures by number @@ -94,7 +94,7 @@ public function loadFromFile($fileName) throw new \InvalidArgumentException(sprintf('"%s" does not exist or is not readable', $fileName)); } - $iterator = new \ArrayIterator(array(new \SplFileInfo($fileName))); + $iterator = new \ArrayIterator([new \SplFileInfo($fileName)]); return $this->loadFromIterator($iterator); } @@ -167,7 +167,7 @@ public function addFixture(FixtureInterface $fixture) */ public function getFixtures() { - $this->orderedFixtures = array(); + $this->orderedFixtures = []; if ($this->orderFixturesByNumber) { $this->orderFixturesByNumber(); @@ -196,7 +196,7 @@ public function isTransient($className) if ($rc->isAbstract()) return true; $interfaces = class_implements($className); - return in_array('Doctrine\Common\DataFixtures\FixtureInterface', $interfaces) ? false : true; + return in_array(FixtureInterface::class, $interfaces) ? false : true; } /** @@ -231,7 +231,7 @@ private function orderFixturesByNumber() */ private function orderFixturesByDependencies() { - $sequenceForClasses = array(); + $sequenceForClasses = []; // If fixtures were already ordered by number then we need // to remove classes which are not instances of OrderedFixtureInterface @@ -294,7 +294,7 @@ private function orderFixturesByDependencies() $lastCount = $count; } - $orderedFixtures = array(); + $orderedFixtures = []; // If there're fixtures unsequenced left and they couldn't be sequenced, // it means we have a circular reference @@ -333,7 +333,7 @@ private function validateDependencies($dependenciesClasses) private function getUnsequencedClasses($sequences, $classes = null) { - $unsequencedClasses = array(); + $unsequencedClasses = []; if (is_null($classes)) { $classes = array_keys($sequences); @@ -356,7 +356,7 @@ private function getUnsequencedClasses($sequences, $classes = null) */ private function loadFromIterator(\Iterator $iterator) { - $includedFiles = array(); + $includedFiles = []; foreach ($iterator as $file) { if (($fileName = $file->getBasename($this->fileExtension)) == $file->getBasename()) { continue; @@ -366,7 +366,7 @@ private function loadFromIterator(\Iterator $iterator) $includedFiles[] = $sourceFile; } - $fixtures = array(); + $fixtures = []; $declared = get_declared_classes(); // Make the declared classes order deterministic sort($declared); diff --git a/lib/Doctrine/Common/DataFixtures/ProxyReferenceRepository.php b/lib/Doctrine/Common/DataFixtures/ProxyReferenceRepository.php index baf0bed7..e1b8ae16 100644 --- a/lib/Doctrine/Common/DataFixtures/ProxyReferenceRepository.php +++ b/lib/Doctrine/Common/DataFixtures/ProxyReferenceRepository.php @@ -61,18 +61,18 @@ protected function getRealClass($className) public function serialize() { $unitOfWork = $this->getManager()->getUnitOfWork(); - $simpleReferences = array(); + $simpleReferences = []; foreach ($this->getReferences() as $name => $reference) { $className = $this->getRealClass(get_class($reference)); - $simpleReferences[$name] = array($className, $this->getIdentifier($reference, $unitOfWork)); + $simpleReferences[$name] = [$className, $this->getIdentifier($reference, $unitOfWork)]; } - $serializedData = json_encode(array( + $serializedData = json_encode([ 'references' => $simpleReferences, 'identities' => $this->getIdentities(), - )); + ]); return $serializedData; } diff --git a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php index aece53b9..e215e271 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php @@ -59,7 +59,7 @@ class ORMPurger implements PurgerInterface * @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 = array()) + public function __construct(EntityManagerInterface $em = null, array $excluded = []) { $this->em = $em; $this->excluded = $excluded; @@ -109,7 +109,7 @@ public function getObjectManager() /** @inheritDoc */ public function purge() { - $classes = array(); + $classes = []; foreach ($this->em->getMetadataFactory()->getAllMetadata() as $metadata) { if (! $metadata->isMappedSuperclass && ! (isset($metadata->isEmbeddedClass) && $metadata->isEmbeddedClass)) { @@ -219,7 +219,7 @@ private function getCommitOrder(EntityManagerInterface $em, array $classes) */ private function getAssociationTables(array $classes, AbstractPlatform $platform) { - $associationTables = array(); + $associationTables = []; foreach ($classes as $class) { foreach ($class->associationMappings as $assoc) { @@ -262,4 +262,4 @@ private function getJoinTableName($assoc, $class, $platform) return $this->em->getConfiguration()->getQuoteStrategy()->getJoinTableName($assoc, $class, $platform); } -} \ No newline at end of file +} diff --git a/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php b/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php index 70402445..c98c1b7b 100644 --- a/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php +++ b/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php @@ -37,7 +37,7 @@ class ReferenceRepository * * @var array */ - private $references = array(); + private $references = []; /** * List of identifiers stored for references @@ -46,7 +46,7 @@ class ReferenceRepository * * @var array */ - private $identities = array(); + private $identities = []; /** * Currently used object manager diff --git a/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php b/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php index 6903e768..a99da217 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php @@ -39,8 +39,8 @@ abstract class BaseTest extends PHPUnit_Framework_TestCase */ protected function getMockAnnotationReaderEntityManager() { - $dbParams = array('driver' => 'pdo_sqlite', 'memory' => true); - $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__.'/TestEntity'), true); + $dbParams = ['driver' => 'pdo_sqlite', 'memory' => true]; + $config = Setup::createAnnotationMetadataConfiguration([__DIR__.'/TestEntity'], true); return EntityManager::create($dbParams, $config); } @@ -53,8 +53,8 @@ protected function getMockAnnotationReaderEntityManager() */ protected function getMockSqliteEntityManager() { - $dbParams = array('driver' => 'pdo_sqlite', 'memory' => true); - $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__.'/TestEntity'), true); + $dbParams = ['driver' => 'pdo_sqlite', 'memory' => 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 d5480670..7883bdd1 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/DependentFixtureTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/DependentFixtureTest.php @@ -46,10 +46,10 @@ public function test_orderFixturesByDependencies_orderClassesWithASingleParent() $orderedFixtures = $loader->getFixtures(); $this->assertCount(4, $orderedFixtures); - $this->assertInstanceOf(__NAMESPACE__ . '\BaseParentFixture1', array_shift($orderedFixtures)); - $this->assertInstanceOf(__NAMESPACE__ . '\DependentFixture1', array_shift($orderedFixtures)); - $this->assertInstanceOf(__NAMESPACE__ . '\DependentFixture2', array_shift($orderedFixtures)); - $this->assertInstanceOf(__NAMESPACE__ . '\DependentFixture3', array_shift($orderedFixtures)); + $this->assertInstanceOf(BaseParentFixture1::class, array_shift($orderedFixtures)); + $this->assertInstanceOf(DependentFixture1::class, array_shift($orderedFixtures)); + $this->assertInstanceOf(DependentFixture2::class, array_shift($orderedFixtures)); + $this->assertInstanceOf(DependentFixture3::class, array_shift($orderedFixtures)); } public function test_orderFixturesByDependencies_orderClassesWithAMultipleParents() @@ -136,13 +136,13 @@ public function test_inCaseThereAreFixturesOrderedByNumberAndByDependenciesBothO $orderedFixtures = $loader->getFixtures(); $this->assertCount(7, $orderedFixtures); - $this->assertInstanceOf(__NAMESPACE__ . '\OrderedByNumberFixture1', array_shift($orderedFixtures)); - $this->assertInstanceOf(__NAMESPACE__ . '\OrderedByNumberFixture2', array_shift($orderedFixtures)); - $this->assertInstanceOf(__NAMESPACE__ . '\OrderedByNumberFixture3', array_shift($orderedFixtures)); - $this->assertInstanceOf(__NAMESPACE__ . '\BaseParentFixture1', array_shift($orderedFixtures)); - $this->assertInstanceOf(__NAMESPACE__ . '\DependentFixture1', array_shift($orderedFixtures)); - $this->assertInstanceOf(__NAMESPACE__ . '\DependentFixture2', array_shift($orderedFixtures)); - $this->assertInstanceOf(__NAMESPACE__ . '\DependentFixture3', array_shift($orderedFixtures)); + $this->assertInstanceOf(OrderedByNumberFixture1::class, array_shift($orderedFixtures)); + $this->assertInstanceOf(OrderedByNumberFixture2::class, array_shift($orderedFixtures)); + $this->assertInstanceOf(OrderedByNumberFixture3::class, array_shift($orderedFixtures)); + $this->assertInstanceOf(BaseParentFixture1::class, array_shift($orderedFixtures)); + $this->assertInstanceOf(DependentFixture1::class, array_shift($orderedFixtures)); + $this->assertInstanceOf(DependentFixture2::class, array_shift($orderedFixtures)); + $this->assertInstanceOf(DependentFixture3::class, array_shift($orderedFixtures)); } public function test_inCaseAFixtureHasAnUnexistentDependencyOrIfItWasntLoaded_throwsException() @@ -166,8 +166,8 @@ public function test_inCaseGetFixturesReturnsDifferentResultsEachTime() $orderedFixtures = $loader->getFixtures(); $this->assertCount(2, $orderedFixtures); - $this->assertInstanceOf(__NAMESPACE__ . '\BaseParentFixture1', array_shift($orderedFixtures)); - $this->assertInstanceOf(__NAMESPACE__ . '\DependentFixture1', array_shift($orderedFixtures)); + $this->assertInstanceOf(BaseParentFixture1::class, array_shift($orderedFixtures)); + $this->assertInstanceOf(DependentFixture1::class, array_shift($orderedFixtures)); } } @@ -178,7 +178,7 @@ public function load(ObjectManager $manager) public function getDependencies() { - return array( 'Doctrine\Tests\Common\DataFixtures\BaseParentFixture1' ); + return [BaseParentFixture1::class]; } } @@ -189,7 +189,7 @@ public function load(ObjectManager $manager) public function getDependencies() { - return array( 'Doctrine\Tests\Common\DataFixtures\DependentFixture1' ); + return [DependentFixture1::class]; } } @@ -200,7 +200,7 @@ public function load(ObjectManager $manager) public function getDependencies() { - return array( 'Doctrine\Tests\Common\DataFixtures\DependentFixture2' ); + return [DependentFixture2::class]; } } @@ -217,9 +217,7 @@ public function load(ObjectManager $manager) public function getDependencies() { - return array( - 'Doctrine\Tests\Common\DataFixtures\BaseParentFixture1' - ); + return [BaseParentFixture1::class]; } } @@ -230,10 +228,10 @@ public function load(ObjectManager $manager) public function getDependencies() { - return array( - 'Doctrine\Tests\Common\DataFixtures\BaseParentFixture1', - 'Doctrine\Tests\Common\DataFixtures\CountryFixture' - ); + return [ + BaseParentFixture1::class, + CountryFixture::class + ]; } } @@ -244,11 +242,11 @@ public function load(ObjectManager $manager) public function getDependencies() { - return array( - 'Doctrine\Tests\Common\DataFixtures\BaseParentFixture1', - 'Doctrine\Tests\Common\DataFixtures\CountryFixture', - 'Doctrine\Tests\Common\DataFixtures\StateFixture' - ); + return [ + BaseParentFixture1::class, + CountryFixture::class, + StateFixture::class + ]; } } @@ -259,9 +257,7 @@ public function load(ObjectManager $manager) public function getDependencies() { - return array( - 'Doctrine\Tests\Common\DataFixtures\BaseParentFixture1' - ); + return [BaseParentFixture1::class]; } } @@ -272,10 +268,10 @@ public function load(ObjectManager $manager) public function getDependencies() { - return array( - 'Doctrine\Tests\Common\DataFixtures\AddressFixture', - 'Doctrine\Tests\Common\DataFixtures\ContactMethodFixture' - ); + return [ + AddressFixture::class, + ContactMethodFixture::class + ]; } } @@ -286,9 +282,7 @@ public function load(ObjectManager $manager) public function getDependencies() { - return array( - 'Doctrine\Tests\Common\DataFixtures\CircularReferenceFixture3' - ); + return [CircularReferenceFixture3::class]; } } @@ -299,9 +293,7 @@ public function load(ObjectManager $manager) public function getDependencies() { - return array( - 'Doctrine\Tests\Common\DataFixtures\CircularReferenceFixture' - ); + return [CircularReferenceFixture::class]; } } @@ -312,9 +304,7 @@ public function load(ObjectManager $manager) public function getDependencies() { - return array( - 'Doctrine\Tests\Common\DataFixtures\CircularReferenceFixture2' - ); + return [CircularReferenceFixture2::class]; } } @@ -325,9 +315,7 @@ public function load(ObjectManager $manager) public function getDependencies() { - return array( - 'Doctrine\Tests\Common\DataFixtures\FixtureWithItselfAsParent' - ); + return [FixtureWithItselfAsParent::class]; } } @@ -338,9 +326,7 @@ public function load(ObjectManager $manager) public function getDependencies() { - return array( - 'UnexistentDependency' - ); + return ['UnexistentDependency']; } } @@ -356,9 +342,7 @@ public function getOrder() public function getDependencies() { - return array( - 'Doctrine\Tests\Common\DataFixtures\FixtureWithItselfAsParent' - ); + return [FixtureWithItselfAsParent::class]; } } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php index eacba9c9..94301b0e 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php @@ -33,8 +33,8 @@ */ class ORMExecutorSharedFixtureTest extends BaseTest { - const TEST_ENTITY_ROLE = 'Doctrine\Tests\Common\DataFixtures\TestEntity\Role'; - const TEST_ENTITY_USER = 'Doctrine\Tests\Common\DataFixtures\TestEntity\User'; + const TEST_ENTITY_ROLE = Role::class; + const TEST_ENTITY_USER = User::class; public function testFixtureExecution() { @@ -52,7 +52,7 @@ public function testFixtureExecution() ->method('setReferenceRepository') ->with($referenceRepository); - $executor->execute(array($fixture), true); + $executor->execute([$fixture], true); } public function testSharedFixtures() @@ -63,18 +63,18 @@ public function testSharedFixtures() $em = $this->getMockSqliteEntityManager(); $schemaTool = new SchemaTool($em); - $schemaTool->dropSchema(array()); - $schemaTool->createSchema(array( + $schemaTool->dropSchema([]); + $schemaTool->createSchema([ $em->getClassMetadata(self::TEST_ENTITY_ROLE), $em->getClassMetadata(self::TEST_ENTITY_USER) - )); + ]); $purger = new ORMPurger(); $executor = new ORMExecutor($em, $purger); $userFixture = new TestFixtures\UserFixture; $roleFixture = new TestFixtures\RoleFixture; - $executor->execute(array($roleFixture, $userFixture), true); + $executor->execute([$roleFixture, $userFixture], true); $referenceRepository = $executor->getReferenceRepository(); $references = $referenceRepository->getReferences(); diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorTest.php index 42860a42..54cc606e 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorTest.php @@ -43,7 +43,7 @@ public function testExecuteWithNoPurge() $fixture->expects($this->once()) ->method('load') ->with($em); - $executor->execute(array($fixture), true); + $executor->execute([$fixture], true); } public function testExecuteWithPurge() @@ -58,7 +58,7 @@ public function testExecuteWithPurge() $fixture->expects($this->once()) ->method('load') ->with($em); - $executor->execute(array($fixture), false); + $executor->execute([$fixture], false); } public function testExecuteTransaction() @@ -66,7 +66,7 @@ public function testExecuteTransaction() $em = $this->getMockSqliteEntityManager(); $executor = new ORMExecutor($em); $fixture = $this->getMockFixture(); - $executor->execute(array($fixture), true); + $executor->execute([$fixture], true); } private function getMockFixture() diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php index 8c507d41..a6a72c86 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php @@ -50,7 +50,7 @@ public function testExecuteSingleFixtureWithNoPurge() return $callback($dm); })); - $executor->execute(array($fixture), true); + $executor->execute([$fixture], true); } public function testExecuteMultipleFixturesWithNoPurge() @@ -70,7 +70,7 @@ public function testExecuteMultipleFixturesWithNoPurge() return $callback($dm); })); - $executor->execute(array($fixture1, $fixture2), true); + $executor->execute([$fixture1, $fixture2], true); } public function testExecuteFixtureWithPurge() @@ -90,7 +90,7 @@ public function testExecuteFixtureWithPurge() })); $purger->expects($this->once())->method('purge'); - $executor->execute(array($fixture), false); + $executor->execute([$fixture], false); } public function testExecuteFixtureWithoutPurge() @@ -110,7 +110,7 @@ public function testExecuteFixtureWithoutPurge() })); $purger->expects($this->never())->method('purge'); - $executor->execute(array($fixture), true); + $executor->execute([$fixture], true); } public function testFailedTransactionalStopsPurgingAndFixtureLoading() @@ -126,7 +126,7 @@ public function testFailedTransactionalStopsPurgingAndFixtureLoading() $purger->expects($this->never())->method('purge'); try { - $executor->execute(array($fixture), true); + $executor->execute([$fixture], true); } catch (\Exception $caughtException) { $this->assertSame($exception, $caughtException); } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/LoaderTest.php b/tests/Doctrine/Tests/Common/DataFixtures/LoaderTest.php index efc13625..d725a20a 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/LoaderTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/LoaderTest.php @@ -23,6 +23,7 @@ use Doctrine\Common\DataFixtures\Loader; use Doctrine\Common\DataFixtures\SharedFixtureInterface; use TestFixtures\MyFixture1; +use TestFixtures\NotAFixture; /** * Test fixtures loader. @@ -42,8 +43,8 @@ public function testLoadFromDirectory() $loader->loadFromDirectory(__DIR__.'/TestFixtures'); $this->assertCount(7, $loader->getFixtures()); - $this->assertTrue($loader->isTransient('TestFixtures\NotAFixture')); - $this->assertFalse($loader->isTransient('TestFixtures\MyFixture1')); + $this->assertTrue($loader->isTransient(NotAFixture::class)); + $this->assertFalse($loader->isTransient(MyFixture1::class)); } public function testLoadFromFile() @@ -61,8 +62,8 @@ public function testLoadFromFile() $this->assertCount(4, $loader->getFixtures()); $loader->loadFromFile(__DIR__.'/TestFixtures/MyFixture2.php'); $this->assertCount(5, $loader->getFixtures()); - $this->assertTrue($loader->isTransient('TestFixtures\NotAFixture')); - $this->assertFalse($loader->isTransient('TestFixtures\MyFixture1')); + $this->assertTrue($loader->isTransient(NotAFixture::class)); + $this->assertFalse($loader->isTransient(MyFixture1::class)); } public function testGetFixture() diff --git a/tests/Doctrine/Tests/Common/DataFixtures/OrderedFixtureTest.php b/tests/Doctrine/Tests/Common/DataFixtures/OrderedFixtureTest.php index 42aa8aeb..a5157844 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/OrderedFixtureTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/OrderedFixtureTest.php @@ -42,10 +42,10 @@ public function testFixtureOrder() $orderedFixtures = $loader->getFixtures(); $this->assertCount(4, $orderedFixtures); - $this->assertInstanceOf(__NAMESPACE__ . '\BaseFixture1', $orderedFixtures[0]); - $this->assertInstanceOf(__NAMESPACE__ . '\OrderedFixture2', $orderedFixtures[1]); - $this->assertInstanceOf(__NAMESPACE__ . '\OrderedFixture1', $orderedFixtures[2]); - $this->assertInstanceOf(__NAMESPACE__ . '\OrderedFixture3', $orderedFixtures[3]); + $this->assertInstanceOf(BaseFixture1::class, $orderedFixtures[0]); + $this->assertInstanceOf(OrderedFixture2::class, $orderedFixtures[1]); + $this->assertInstanceOf(OrderedFixture1::class, $orderedFixtures[2]); + $this->assertInstanceOf(OrderedFixture3::class, $orderedFixtures[3]); } } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/ProxyReferenceRepositoryTest.php b/tests/Doctrine/Tests/Common/DataFixtures/ProxyReferenceRepositoryTest.php index 773599d9..4412ad90 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/ProxyReferenceRepositoryTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/ProxyReferenceRepositoryTest.php @@ -23,6 +23,7 @@ use Doctrine\Common\DataFixtures\Event\Listener\ORMReferenceListener; use Doctrine\ORM\Tools\SchemaTool; use Doctrine\ORM\Proxy\Proxy; +use Doctrine\Tests\Common\DataFixtures\TestEntity\Role; /** * Test ProxyReferenceRepository. @@ -32,7 +33,7 @@ */ class ProxyReferenceRepositoryTest extends BaseTest { - const TEST_ENTITY_ROLE = 'Doctrine\Tests\Common\DataFixtures\TestEntity\Role'; + const TEST_ENTITY_ROLE = Role::class; public function testReferenceEntry() { @@ -55,17 +56,17 @@ public function testReferenceEntry() public function testReferenceIdentityPopulation() { $em = $this->getMockSqliteEntityManager(); - $referenceRepository = $this->getMockBuilder('Doctrine\Common\DataFixtures\ProxyReferenceRepository') - ->setConstructorArgs(array($em)) + $referenceRepository = $this->getMockBuilder(ProxyReferenceRepository::class) + ->setConstructorArgs([$em]) ->getMock(); $em->getEventManager()->addEventSubscriber( new ORMReferenceListener($referenceRepository) ); $schemaTool = new SchemaTool($em); - $schemaTool->dropSchema(array()); - $schemaTool->createSchema(array( + $schemaTool->dropSchema([]); + $schemaTool->createSchema([ $em->getClassMetadata(self::TEST_ENTITY_ROLE) - )); + ]); $referenceRepository->expects($this->once()) ->method('addReference') @@ -73,11 +74,11 @@ public function testReferenceIdentityPopulation() $referenceRepository->expects($this->once()) ->method('getReferenceNames') - ->will($this->returnValue(array('admin-role'))); + ->will($this->returnValue(['admin-role'])); $referenceRepository->expects($this->once()) ->method('setReferenceIdentity') - ->with('admin-role', array('id' => 1)); + ->with('admin-role', ['id' => 1]); $roleFixture = new TestFixtures\RoleFixture; $roleFixture->setReferenceRepository($referenceRepository); @@ -92,10 +93,10 @@ public function testReferenceReconstruction() $em->getEventManager()->addEventSubscriber($listener); $schemaTool = new SchemaTool($em); - $schemaTool->dropSchema(array()); - $schemaTool->createSchema(array( + $schemaTool->dropSchema([]); + $schemaTool->createSchema([ $em->getClassMetadata(self::TEST_ENTITY_ROLE) - )); + ]); $roleFixture = new TestFixtures\RoleFixture; $roleFixture->setReferenceRepository($referenceRepository); @@ -103,7 +104,7 @@ public function testReferenceReconstruction() // first test against managed state $ref = $referenceRepository->getReference('admin-role'); - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $ref); + $this->assertNotInstanceOf(Proxy::class, $ref); // test reference reconstruction from serialized data (was managed) $serializedData = $referenceRepository->serialize(); @@ -114,14 +115,14 @@ public function testReferenceReconstruction() $ref = $proxyReferenceRepository->getReference('admin-role'); // before clearing, the reference is not yet a proxy - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $ref); - $this->assertInstanceOf('Doctrine\Tests\Common\DataFixtures\TestEntity\Role', $ref); + $this->assertNotInstanceOf(Proxy::class, $ref); + $this->assertInstanceOf(self::TEST_ENTITY_ROLE, $ref); // now test reference reconstruction from identity $em->clear(); $ref = $referenceRepository->getReference('admin-role'); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $ref); + $this->assertInstanceOf(Proxy::class, $ref); // test reference reconstruction from serialized data (was identity) $serializedData = $referenceRepository->serialize(); @@ -131,7 +132,7 @@ public function testReferenceReconstruction() $ref = $proxyReferenceRepository->getReference('admin-role'); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $ref); + $this->assertInstanceOf(Proxy::class, $ref); } public function testReferenceMultipleEntries() @@ -140,7 +141,7 @@ public function testReferenceMultipleEntries() $referenceRepository = new ProxyReferenceRepository($em); $em->getEventManager()->addEventSubscriber(new ORMReferenceListener($referenceRepository)); $schemaTool = new SchemaTool($em); - $schemaTool->createSchema(array($em->getClassMetadata(self::TEST_ENTITY_ROLE))); + $schemaTool->createSchema([$em->getClassMetadata(self::TEST_ENTITY_ROLE)]); $role = new TestEntity\Role; $role->setName('admin'); @@ -151,7 +152,7 @@ public function testReferenceMultipleEntries() $em->flush(); $em->clear(); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $referenceRepository->getReference('admin')); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $referenceRepository->getReference('duplicate')); + $this->assertInstanceOf(Proxy::class, $referenceRepository->getReference('admin')); + $this->assertInstanceOf(Proxy::class, $referenceRepository->getReference('duplicate')); } } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Purger/MongoDBPurgerTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Purger/MongoDBPurgerTest.php index 42b7d972..d50cd0ef 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Purger/MongoDBPurgerTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Purger/MongoDBPurgerTest.php @@ -12,7 +12,7 @@ class MongoDBPurgerTest extends BaseTest { - const TEST_DOCUMENT_ROLE = 'Doctrine\Tests\Common\DataFixtures\TestDocument\Role'; + const TEST_DOCUMENT_ROLE = Role::class; private function getDocumentManager() { diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php index 9c9bd777..3d83bb15 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php @@ -10,99 +10,91 @@ use Doctrine\Tests\Common\DataFixtures\TestPurgeEntity\ExcludedEntity; use Doctrine\Tests\Common\DataFixtures\TestPurgeEntity\IncludedEntity; -/** - * - * @author Charles J. C. Elling, Jul 2, 2016 - * - */ -class ORMPurgerExcludeTest extends BaseTest { - - const TEST_ENTITY_INCLUDED = 'Doctrine\Tests\Common\DataFixtures\TestPurgeEntity\IncludedEntity'; - const TEST_ENTITY_EXCLUDED = 'Doctrine\Tests\Common\DataFixtures\TestPurgeEntity\ExcludedEntity'; - - /** - * Loads test data - * - * @return \Doctrine\ORM\EntityManager - */ - protected function loadTestData(){ - if (!extension_loaded('pdo_sqlite')) { +class ORMPurgerExcludeTest extends BaseTest +{ + const TEST_ENTITY_INCLUDED = IncludedEntity::class; + const TEST_ENTITY_EXCLUDED = ExcludedEntity::class; + + /** + * Loads test data + * + * @return \Doctrine\ORM\EntityManager + */ + protected function loadTestData(){ + if (!extension_loaded('pdo_sqlite')) { $this->markTestSkipped('Missing pdo_sqlite extension.'); } - - $dbParams = array('driver' => 'pdo_sqlite', 'memory' => true); - $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__.'/../TestPurgeEntity'), true); + + $dbParams = ['driver' => 'pdo_sqlite', 'memory' => true]; + $config = Setup::createAnnotationMetadataConfiguration([__DIR__.'/../TestPurgeEntity'], true); $em = EntityManager::create($dbParams, $config); $connection = $em->getConnection(); $configuration = $connection->getConfiguration(); $configuration->setFilterSchemaAssetsExpression(null); - + $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em); $schemaTool->dropDatabase(); - $schemaTool->createSchema(array( - $em->getClassMetadata(self::TEST_ENTITY_INCLUDED), - $em->getClassMetadata(self::TEST_ENTITY_EXCLUDED) - )); - + $schemaTool->createSchema([ + $em->getClassMetadata(self::TEST_ENTITY_INCLUDED), + $em->getClassMetadata(self::TEST_ENTITY_EXCLUDED) + ]); + $entity = new ExcludedEntity(); $entity->setId(1); $em->persist($entity); - + $entity = new IncludedEntity(); $entity->setId(1); $em->persist($entity); - + $em->flush(); - - return $em; - } - - /** - * Execute test purge - * - * @param string|null $expression - * @param array $list - */ - public function executeTestPurge($expression, array $list){ - $em = $this->loadTestData(); - $excludedRepository = $em->getRepository(self::TEST_ENTITY_EXCLUDED); - $includedRepository = $em->getRepository(self::TEST_ENTITY_INCLUDED); - - $excluded = $excludedRepository->findAll(); - $included = $includedRepository->findAll(); - - $this->assertGreaterThan(0, count($included)); - $this->assertGreaterThan(0, count($excluded)); - - $connection = $em->getConnection(); - $configuration = $connection->getConfiguration(); - $configuration->setFilterSchemaAssetsExpression($expression); - - $purger = new ORMPurger($em,$list); - $purger->purge(); - - $excluded = $excludedRepository->findAll(); - $included = $includedRepository->findAll(); - - $this->assertEquals(0, count($included)); - $this->assertGreaterThan(0, count($excluded)); - - } - - /** - * Test for purge exclusion usig dbal filter expression regexp. - * - */ - public function testPurgeExcludeUsingFilterExpression(){ - $this->executeTestPurge('~^(?!ExcludedEntity)~', array()); - } - - /** - * Test for purge exclusion usig explicit exclution list. - * - */ - public function testPurgeExcludeUsingList(){ - $this->executeTestPurge(null,array('ExcludedEntity')); - } -} \ No newline at end of file + + return $em; + } + + /** + * Execute test purge + * + * @param string|null $expression + * @param array $list + */ + public function executeTestPurge($expression, array $list){ + $em = $this->loadTestData(); + $excludedRepository = $em->getRepository(self::TEST_ENTITY_EXCLUDED); + $includedRepository = $em->getRepository(self::TEST_ENTITY_INCLUDED); + + $excluded = $excludedRepository->findAll(); + $included = $includedRepository->findAll(); + + $this->assertGreaterThan(0, count($included)); + $this->assertGreaterThan(0, count($excluded)); + + $connection = $em->getConnection(); + $configuration = $connection->getConfiguration(); + $configuration->setFilterSchemaAssetsExpression($expression); + + $purger = new ORMPurger($em,$list); + $purger->purge(); + + $excluded = $excludedRepository->findAll(); + $included = $includedRepository->findAll(); + + $this->assertEquals(0, count($included)); + $this->assertGreaterThan(0, count($excluded)); + } + + /** + * Test for purge exclusion usig dbal filter expression regexp. + */ + public function testPurgeExcludeUsingFilterExpression(){ + $this->executeTestPurge('~^(?!ExcludedEntity)~', []); + } + + /** + * Test for purge exclusion usig explicit exclution list. + */ + public function testPurgeExcludeUsingList(){ + $this->executeTestPurge(null, ['ExcludedEntity']); + } +} diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerTest.php index 89223656..d5d53b9b 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerTest.php @@ -16,9 +16,9 @@ */ class ORMPurgerTest extends BaseTest { - const TEST_ENTITY_USER = 'Doctrine\Tests\Common\DataFixtures\TestEntity\User'; - const TEST_ENTITY_USER_WITH_SCHEMA = 'Doctrine\Tests\Common\DataFixtures\TestEntity\UserWithSchema'; - const TEST_ENTITY_QUOTED = 'Doctrine\Tests\Common\DataFixtures\TestEntity\Quoted'; + const TEST_ENTITY_USER = TestEntity\User::class; + const TEST_ENTITY_USER_WITH_SCHEMA = TestEntity\UserWithSchema::class; + const TEST_ENTITY_QUOTED = TestEntity\Quoted::class; public function testGetAssociationTables() @@ -27,10 +27,10 @@ public function testGetAssociationTables() $metadata = $em->getClassMetadata(self::TEST_ENTITY_USER); $platform = $em->getConnection()->getDatabasePlatform(); $purger = new ORMPurger($em); - $class = new ReflectionClass('Doctrine\Common\DataFixtures\Purger\ORMPurger'); + $class = new ReflectionClass(ORMPurger::class); $method = $class->getMethod('getAssociationTables'); $method->setAccessible(true); - $associationTables = $method->invokeArgs($purger, array(array($metadata), $platform)); + $associationTables = $method->invokeArgs($purger, [[$metadata], $platform]); $this->assertEquals($associationTables[0], 'readers.author_reader'); } @@ -40,28 +40,23 @@ public function testGetAssociationTablesQuoted() $metadata = $em->getClassMetadata(self::TEST_ENTITY_QUOTED); $platform = $em->getConnection()->getDatabasePlatform(); $purger = new ORMPurger($em); - $class = new ReflectionClass('Doctrine\Common\DataFixtures\Purger\ORMPurger'); + $class = new ReflectionClass(ORMPurger::class); $method = $class->getMethod('getAssociationTables'); $method->setAccessible(true); - $associationTables = $method->invokeArgs($purger, array(array($metadata), $platform)); + $associationTables = $method->invokeArgs($purger, [[$metadata], $platform]); $this->assertEquals($associationTables[0], '"INSERT"'); } public function testTableNameWithSchema() { - $isDoctrine25 = (ORMVersion::compare('2.5.0') <= 0); - if (!$isDoctrine25) { - $this->markTestSkipped('@Table schema attribute is not supported in Doctrine < 2.5.0'); - } - $em = $this->getMockAnnotationReaderEntityManager(); $metadata = $em->getClassMetadata(self::TEST_ENTITY_USER_WITH_SCHEMA); $platform = $em->getConnection()->getDatabasePlatform(); $purger = new ORMPurger($em); - $class = new ReflectionClass('Doctrine\Common\DataFixtures\Purger\ORMPurger'); + $class = new ReflectionClass(ORMPurger::class); $method = $class->getMethod('getTableName'); $method->setAccessible(true); - $tableName = $method->invokeArgs($purger, array($metadata, $platform)); + $tableName = $method->invokeArgs($purger, [$metadata, $platform]); $this->assertStringStartsWith('test_schema',$tableName); } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php b/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php index a0e85af1..3b30bc90 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php @@ -60,16 +60,16 @@ public function testReferenceIdentityPopulation() { $em = $this->getMockSqliteEntityManager(); $referenceRepository = $this->getMockBuilder(ReferenceRepository::class) - ->setConstructorArgs(array($em)) + ->setConstructorArgs([$em]) ->getMock(); $em->getEventManager()->addEventSubscriber( new ORMReferenceListener($referenceRepository) ); $schemaTool = new SchemaTool($em); - $schemaTool->dropSchema(array()); - $schemaTool->createSchema(array( + $schemaTool->dropSchema([]); + $schemaTool->createSchema([ $em->getClassMetadata(Role::class) - )); + ]); $referenceRepository->expects($this->once()) ->method('addReference') @@ -77,11 +77,11 @@ public function testReferenceIdentityPopulation() $referenceRepository->expects($this->once()) ->method('getReferenceNames') - ->will($this->returnValue(array('admin-role'))); + ->will($this->returnValue(['admin-role'])); $referenceRepository->expects($this->once()) ->method('setReferenceIdentity') - ->with('admin-role', array('id' => 1)); + ->with('admin-role', ['id' => 1]); $roleFixture = new TestFixtures\RoleFixture; $roleFixture->setReferenceRepository($referenceRepository); @@ -97,10 +97,10 @@ public function testReferenceReconstruction() new ORMReferenceListener($referenceRepository) ); $schemaTool = new SchemaTool($em); - $schemaTool->dropSchema(array()); - $schemaTool->createSchema(array( + $schemaTool->dropSchema([]); + $schemaTool->createSchema([ $em->getClassMetadata(Role::class) - )); + ]); $roleFixture = new TestFixtures\RoleFixture; $roleFixture->setReferenceRepository($referenceRepository); @@ -123,7 +123,7 @@ public function testReferenceMultipleEntries() $referenceRepository = new ReferenceRepository($em); $em->getEventManager()->addEventSubscriber(new ORMReferenceListener($referenceRepository)); $schemaTool = new SchemaTool($em); - $schemaTool->createSchema(array($em->getClassMetadata(Role::class))); + $schemaTool->createSchema([$em->getClassMetadata(Role::class)]); $role = new TestEntity\Role; $role->setName('admin'); @@ -186,10 +186,10 @@ public function testSetReferenceHavingIdentifier() $referenceRepository = new ReferenceRepository($em); $schemaTool = new SchemaTool($em); - $schemaTool->dropSchema(array()); - $schemaTool->createSchema(array( + $schemaTool->dropSchema([]); + $schemaTool->createSchema([ $em->getClassMetadata(Role::class) - )); + ]); $role = new Role(); $role->setName('role_name'); diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php index 5630294b..b3b874eb 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php @@ -59,7 +59,7 @@ public function testSuccessSortLinearDependency() $sorter->addDependency('5', '1'); $sortedList = $sorter->sort(); - $correctList = array($node4, $node3, $node2, $node1, $node5); + $correctList = [$node4, $node3, $node2, $node1, $node5]; self::assertSame($correctList, $sortedList); } @@ -87,7 +87,7 @@ public function testSuccessSortMultiDependency() $sorter->addDependency('5', '1'); $sortedList = $sorter->sort(); - $correctList = array($node1, $node2, $node4, $node5, $node3); + $correctList = [$node1, $node2, $node4, $node5, $node3]; self::assertSame($correctList, $sortedList); } @@ -109,7 +109,7 @@ public function testSortCyclicDependency() $sorter->addDependency('3', '1'); $sortedList = $sorter->sort(); - $correctList = array($node3, $node2, $node1); + $correctList = [$node3, $node2, $node1]; self::assertSame($correctList, $sortedList); @@ -160,7 +160,7 @@ public function testNoFailureOnSelfReferencingDependency() $sorter->addDependency('5', '1'); $sortedList = $sorter->sort(); - $correctList = array($node4, $node3, $node2, $node1, $node5); + $correctList = [$node4, $node3, $node2, $node1, $node5]; self::assertSame($correctList, $sortedList); } From a24d3f43c3bec905da58936eef2d7e324d777abb Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Sun, 6 Aug 2017 16:55:52 +0200 Subject: [PATCH 089/129] Bump phpunit dependency to 6.3 --- composer.json | 2 +- tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php | 4 ++-- .../Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php | 4 ++-- .../Common/DataFixtures/Sorter/TopologicalSorterTest.php | 3 ++- .../Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php | 3 ++- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 0b1969c3..1176d25e 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "require-dev": { "doctrine/orm": "^2.5.4", "doctrine/dbal": "^2.5.4", - "phpunit/phpunit": "^5.4.6" + "phpunit/phpunit": "^6.3" }, "suggest": { "doctrine/orm": "For loading ORM fixtures", diff --git a/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php b/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php index a99da217..29e9d74b 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php @@ -22,14 +22,14 @@ use Doctrine\DBAL\Driver; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Tools\Setup; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; /** * Base test class * * @author Jonathan H. Wage */ -abstract class BaseTest extends PHPUnit_Framework_TestCase +abstract class BaseTest extends TestCase { /** * EntityManager mock object together with diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php index a6a72c86..d2841d02 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php @@ -23,8 +23,8 @@ use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Common\DataFixtures\Purger\PHPCRPurger; use Doctrine\ODM\PHPCR\DocumentManager; +use Doctrine\Tests\Common\DataFixtures\BaseTest; use Exception; -use PHPUnit_Framework_TestCase; /** * Tests for {@see \Doctrine\Common\DataFixtures\Executor\PHPCRExecutor} @@ -33,7 +33,7 @@ * * @covers \Doctrine\Common\DataFixtures\Executor\PHPCRExecutor */ -class PHPCRExecutorTest extends PHPUnit_Framework_TestCase +class PHPCRExecutorTest extends BaseTest { public function testExecuteSingleFixtureWithNoPurge() { diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php index b3b874eb..9b935fc9 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php @@ -23,6 +23,7 @@ use Doctrine\Common\DataFixtures\Exception\CircularReferenceException; use Doctrine\Common\DataFixtures\Sorter\TopologicalSorter; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\Tests\Common\DataFixtures\BaseTest; /** * TopologicalSorter tests. @@ -35,7 +36,7 @@ * * @covers \Doctrine\Common\DataFixtures\Sorter\TopologicalSorter */ -class TopologicalSorterTest extends \PHPUnit_Framework_TestCase +class TopologicalSorterTest extends BaseTest { public function testSuccessSortLinearDependency() { diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php index de2e9f84..bceab311 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php @@ -22,13 +22,14 @@ use Doctrine\Common\DataFixtures\Sorter\Vertex; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\Tests\Common\DataFixtures\BaseTest; /** * @author Marco Pivetta * * @covers \Doctrine\Common\DataFixtures\Sorter\Vertex */ -class VertexTest extends \PHPUnit_Framework_TestCase +class VertexTest extends BaseTest { public function testNode() { From 03ee528bfbb1b315ee8fb387ba95ad5a84d27078 Mon Sep 17 00:00:00 2001 From: Massimiliano Arione Date: Thu, 7 Sep 2017 20:45:46 +0200 Subject: [PATCH 090/129] remove tabs --- .../Common/DataFixtures/Purger/ORMPurger.php | 24 +++++++++---------- .../TestPurgeEntity/ExcludedEntity.php | 8 +++---- .../TestPurgeEntity/IncludedEntity.php | 10 ++++---- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php index e215e271..0dc919d0 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php @@ -140,18 +140,18 @@ public function purge() $orderedTables[] = $this->getTableName($class, $platform); } - $connection = $this->em->getConnection(); - $filterExpr = $connection->getConfiguration()->getFilterSchemaAssetsExpression(); - $emptyFilterExpression = empty($filterExpr); - foreach($orderedTables as $tbl) { - if(($emptyFilterExpression||preg_match($filterExpr, $tbl)) && array_search($tbl, $this->excluded) === false){ - if ($this->purgeMode === self::PURGE_MODE_DELETE) { - $connection->executeUpdate("DELETE FROM " . $tbl); - } else { - $connection->executeUpdate($platform->getTruncateTableSQL($tbl, true)); - } - } - } + $connection = $this->em->getConnection(); + $filterExpr = $connection->getConfiguration()->getFilterSchemaAssetsExpression(); + $emptyFilterExpression = empty($filterExpr); + foreach($orderedTables as $tbl) { + if(($emptyFilterExpression||preg_match($filterExpr, $tbl)) && array_search($tbl, $this->excluded) === false){ + if ($this->purgeMode === self::PURGE_MODE_DELETE) { + $connection->executeUpdate("DELETE FROM " . $tbl); + } else { + $connection->executeUpdate($platform->getTruncateTableSQL($tbl, true)); + } + } + } } /** diff --git a/tests/Doctrine/Tests/Common/DataFixtures/TestPurgeEntity/ExcludedEntity.php b/tests/Doctrine/Tests/Common/DataFixtures/TestPurgeEntity/ExcludedEntity.php index c3e594a6..8999cfc5 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/TestPurgeEntity/ExcludedEntity.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/TestPurgeEntity/ExcludedEntity.php @@ -8,7 +8,7 @@ * @Entity */ class ExcludedEntity{ - + /** * @Column(type="integer") * @Id @@ -19,7 +19,7 @@ public function setId($id){ $this->id = $id; } - public function getId() { - return $this->id; - } + 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 5038263e..15125184 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/TestPurgeEntity/IncludedEntity.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/TestPurgeEntity/IncludedEntity.php @@ -8,7 +8,7 @@ * @Entity */ class IncludedEntity{ - + /** * @Column(type="integer") * @Id @@ -19,7 +19,7 @@ public function setId($id){ $this->id = $id; } - public function getId() { - return $this->id; - } -} \ No newline at end of file + public function getId() { + return $this->id; + } +} From 4688448b32f994fc80a42f2783fb6d51cc7e193c Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Mon, 27 Nov 2017 09:23:56 -0500 Subject: [PATCH 091/129] Adding a hook point for creating the fixture objects --- lib/Doctrine/Common/DataFixtures/Loader.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Loader.php b/lib/Doctrine/Common/DataFixtures/Loader.php index 0d8aafae..fad6265f 100644 --- a/lib/Doctrine/Common/DataFixtures/Loader.php +++ b/lib/Doctrine/Common/DataFixtures/Loader.php @@ -153,7 +153,7 @@ public function addFixture(FixtureInterface $fixture) $this->orderFixturesByDependencies = true; foreach($fixture->getDependencies() as $class) { if (class_exists($class)) { - $this->addFixture(new $class); + $this->addFixture($this->createFixture($class)); } } } @@ -199,6 +199,17 @@ public function isTransient($className) return in_array(FixtureInterface::class, $interfaces) ? false : true; } + /** + * Creates the fixture object from the class. + * + * @param string $class + * @return FixtureInterface + */ + protected function createFixture($class) + { + return new $class(); + } + /** * Orders fixtures by number * @@ -376,7 +387,7 @@ private function loadFromIterator(\Iterator $iterator) $sourceFile = $reflClass->getFileName(); if (in_array($sourceFile, $includedFiles) && ! $this->isTransient($className)) { - $fixture = new $className; + $fixture = $this->createFixture($className); $fixtures[] = $fixture; $this->addFixture($fixture); } From 7b76ccc8e648c4502aad7f61347326c8a072bd3b Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Mon, 27 Nov 2017 19:46:48 +0100 Subject: [PATCH 092/129] Add changelog --- CHANGELOG.md | 170 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..8bae0c9c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,170 @@ +# Change Log +All notable changes to this project will be documented in this file. +This project adheres to [Semantic Versioning](http://semver.org/). + +## [1.3.0] - 2017-11-27 + +### Fixed + - [248: Rename example classes names for consistency](https://github.com/doctrine/data-fixtures/pull/248) - @Kwadz + - [253: Fix syntax highlighting on README](https://github.com/doctrine/data-fixtures/pull/253) - @fefas + - [269: Remove tabs](https://github.com/doctrine/data-fixtures/pull/269) - @garak + +### Changed + - [266: Bump PHP requirement to 7.1](https://github.com/doctrine/data-fixtures/pull/266) - @alcaeus + +### Added + - [255: Added handling of PHPCR documents on method `getIdentifier()`](https://github.com/doctrine/data-fixtures/pull/255) - @aemaething + - [274: Hook point to control creating fixtures objects](https://github.com/doctrine/data-fixtures/pull/274) - @weaverryan + +### Fixed + - [572: Only show generated migration in verbose mode](https://github.com/doctrine/migrations/pull/572) - @alcaeus + +## [1.6.0] - 2017-11-09 + +### Fixed + - [536: Fix typo in exception message](https://github.com/doctrine/migrations/pull/536) - @mantiz + - [545: Allow nullable custom template](https://github.com/doctrine/migrations/pull/545) - @PapsOu + - [560: Fix `--dry-run` and `--write-sql` with `addSql`](https://github.com/doctrine/migrations/pull/560) - @mikeSimonson + - [569: Allow using absolute paths for custom template](https://github.com/doctrine/migrations/pull/569) - @alcaeus + +### Changed + - [537: Require PHP 7.1](https://github.com/doctrine/migrations/pull/537) - @lcobucci + - [563: Remove copyright headers](https://github.com/doctrine/migrations/pull/563) - @mikeSimonson + - [534: Change RecursiveRegexFinder to follow Symlinks](https://github.com/doctrine/migrations/pull/534) - @burci + +### Added + - [506: Add migration events](https://github.com/doctrine/migrations/pull/506) - @chrisguitarguy + - [509: Add delta in migrate command](https://github.com/doctrine/migrations/pull/509) - @Safranil + - [535: Allow changing migration class template in generate command](https://github.com/doctrine/migrations/pull/535) - @PapsOu + - [542: Enable phpcs to ensure coding style](https://github.com/doctrine/migrations/pull/542) - @lcobucci + - [562: Allow providing a path for file dump](https://github.com/doctrine/migrations/pull/562) - @mikeSimonson + - [565: Allow Symfony 4](https://github.com/doctrine/migrations/565) - @weaverryan + - [568: Add `ConfigurationHelperInterface` to allow overriding internal class](https://github.com/doctrine/migrations/pull/568) - @alcaeus + - [571: Allow changing migration class template in diff command](https://github.com/doctrine/migrations/pull/571) - @alcaeus + +## [1.5.0] - 2016-12-25 + +### Fixed + - [447: Fix typo in error code](https://github.com/doctrine/migrations/pull/447) thanks to @funivan + - [448: Removed unused import](https://github.com/doctrine/migrations/pull/448) thanks to @localheinz + - [451: Case insensitive method calls and types](https://github.com/doctrine/migrations/pull/451) thanks to @localheinz + - [449: Use the class keyword](https://github.com/doctrine/migrations/pull/449) thanks to @localheinz + - [453: Use better assertions](https://github.com/doctrine/migrations/pull/453) thanks to @localheinz + - [452: Fix the visibility of the AbstractTest](https://github.com/doctrine/migrations/pull/452) thanks to @localheinz + - [450: Use the short array syntax](https://github.com/doctrine/migrations/pull/450) thanks to @localheinz + - [464: Clean the github autogenerated zip archive](https://github.com/doctrine/migrations/pull/464) thanks to @mlocati + - [457: Fix an issue where the migration wheren't sorted propely](https://github.com/doctrine/migrations/pull/457) thanks to @JHGitty, @Charles68 + - [451: Case insensitive method calls and types](https://github.com/doctrine/migrations/pull/451) thanks to @localheinz + - [471: Fix loading the configuration from a php file](https://github.com/doctrine/migrations/pull/471) thanks to @aaa2000 + - [451: Case insensitive method calls and types](https://github.com/doctrine/migrations/pull/451) thanks to @localheinz + - [472: Change comment marker a cross platform one ](https://github.com/doctrine/migrations/pull/472) thanks to @aaa2000 + - [476: Add test for the execute command](https://github.com/doctrine/migrations/pull/476) thanks to @chrisguitarguy + - [470: Case insensitive method calls and types](https://github.com/doctrine/migrations/pull/470) thanks to @abacaphiliac + - [489: Better help message in the execute command](https://github.com/doctrine/migrations/pull/489) thanks to @eko + - [500: Updating the dev dependencies](https://github.com/doctrine/migrations/pull/500) thanks to @mikeSimonson + - [501: Fix a bug in a rarely used message call](https://github.com/doctrine/migrations/pull/501) thanks to @Seldaek + +### Changed + - [478: Changed the default generated version number to UTC](https://github.com/doctrine/migrations/pull/446) thanks to @c960657 + - [479: Explicitly connecting to support master slave connections](https://github.com/doctrine/migrations/pull/479) thanks to @chrisguitarguy + - [482: Use strict comparaison in the generated migrations](https://github.com/doctrine/migrations/pull/482) thanks to @tifabien + +### Added + - [470: Add uptodate command](https://github.com/doctrine/migrations/pull/470) thanks to @abacaphiliac + - [477: Add parameters to the output of the dry run migrations](https://github.com/doctrine/migrations/pull/477) thanks to @chrisguitarguy + - [497: Show the content of the generated file on the console](https://github.com/doctrine/migrations/pull/497) thanks to @ErikTrapman + - [480: Don't prompt the user for confirmation when there is nothing to do](https://github.com/doctrine/migrations/pull/480) thanks to @chrisguitarguy + + +## [1.4.1] - 2016-03-14 +### Fixed + - [439: Add missing dependency in the phar build](https://github.com/doctrine/migrations/pull/439) + + +## [1.4.0] - 2016-02-23 +### Added + - [431: Formatted diffs](https://github.com/doctrine/migrations/pull/431) + - [437: Allowing to set the column name from config too](https://github.com/doctrine/migrations/pull/437) + +## [1.3.1] - 2016-02-23 +### Fixed + - [433: Fix: ExecuteCommand by making sure that it autoload the versions](https://github.com/doctrine/migrations/pull/433) + - [434: Fixing an issue in the order at which some configuration key are loaded](https://github.com/doctrine/migrations/pull/434) + +### Changed + - [429: code refactoring for clarity](https://github.com/doctrine/migrations/pull/429) + - [428: code refactoring for clarity](https://github.com/doctrine/migrations/pull/428) + +### Added + - [425: ProxyManager ~2.0 is also compatible with migrations](https://github.com/doctrine/migrations/pull/425) + + +## [1.3.0] - 2016-01-23 +### Fixed + - [421: Fix issue with some method when the migrations were not loaded](https://github.com/doctrine/migrations/pull/421) + - [405: Correcting composer constraints: allowing PHP 7, dropping 5.4 support](https://github.com/doctrine/migrations/pull/405) + - [406: putting the composer.json back in the archive](https://github.com/doctrine/migrations/pull/406) + +### Changed + - [233: Separate Configuration Objects from Configuration File Loading](https://github.com/doctrine/migrations/issues/233) + - [407: Replacing the Schema by a proxy](https://github.com/doctrine/migrations/pull/407) + - [422: Refactor the getConnection into a chainloader](https://github.com/doctrine/migrations/pull/422) + - [Dropped the support for php 5.4](https://github.com/doctrine/migrations/pull/393) + - [Again make the phar more than 3 times smaller](https://github.com/doctrine/migrations/pull/396) + +### Added + - [404: add possibility to read doctrine's config/cli-config.php](https://github.com/doctrine/migrations/pull/404) + - [409: Add a failing test case for an edge case with the write-sql option](https://github.com/doctrine/migrations/pull/409) + - [424: Adding a regression test for the configuration](https://github.com/doctrine/migrations/pull/424) + - [391: Give the possibility to override the Migration template](https://github.com/doctrine/migrations/pull/391) + +## [1.2.2] - 2016-01-07 +### Fixed + - [Fix the write-sql option in the version class too](https://github.com/doctrine/migrations/commit/91043f742da8506ab7115a1d14247ce26375f6f5) + +## [1.2.1] - 2015-12-23 +### Fixed + - [Fix the write-sql option](https://github.com/doctrine/migrations/pull/400) + +## [1.2.0] - 2015-12-15 +### Fixed + - [fix "all migrated versions shown as unavailable executed" ](https://github.com/doctrine/migrations/commit/875849e2a80d37dc8bf5dd0663e464b6789e3b56) + - [Prevent the use of 0 as migration name as it is used internally and conflict](http://github.com/doctrine/migrations/commit/5df49c5ad5dc2265401a54a3b9e6ecb3e7cda8d0) + - [composer: drop symfony/console from suggested packages, since it's required package](http://github.com/doctrine/migrations/commit/d263c7bfac7188009ab0717ed5aa6577e80) + - [fix spaces and complete missing file-docblocks](http://github.com/doctrine/migrations/commit/4b68a69c3e35492b36ec140ebb216cdb80ffe655) + - [RecursiveDirectoryIterator don't obtain some order of the file list.](http://github.com/doctrine/migrations/commit/ed95c05c14381e64404f1135763fcc9b65317b96) + - [Fix the yml parser issue with unescaped backslash in double quoted string](http://github.com/doctrine/migrations/commit/af3cce7d2e490ead821fcbdb54b4772b4913ee1d) + +### Changed + - [Adding compression to the generation of the phar](http://github.com/doctrine/migrations/commit/70730ff8655f0be89ce0f06d1e279930d7eb2550) + - [tests: move autoload of tests to composer](http://github.com/doctrine/migrations/commit/3a4f8368e4b7b95d2e6c51c26f6dc41bb05a5ce5) + - [travis: drop PHP 7.0 from allowed failures, it passes well](http://github.com/doctrine/migrations/commit/57ec2f071a7a840c554058b77f2089893d06ba23) + - [Revert the use of exec to run sql queries](http://github.com/doctrine/migrations/commit/0af6e6e705b905a56cbed26cb5c17faad4c2c04f) + +### Added + - [Adding a little script to prepare and generate the phar](http://github.com/doctrine/migrations/commit/3a8ef413e7f8a42d4e0f3d32d30601b26fb27e60) + - [Configuration: check if migration class exists added](http://github.com/doctrine/migrations/commit/a53d7c83b319341c985d2a21950e260fa55b0b8d) + - [Made composer.json compatible with SF 3.0](http://github.com/doctrine/migrations/commit/4e909f2e661a8414a3e04ce987a09c9e849cd13f) + - [Added configurable version column name](http://github.com/doctrine/migrations/commit/02ddf4318b84a20bb0e3486acfc6e6f41cc63426) + +## [1.1.0] - 2015-09-29 +### Fixed + - [Switch unexisting tag to ](http://github.com/doctrine/migrations/commit/93a81ff0dcc858de4df5c17d97f2f24b3bfa3c36) + - [Ensure that Yaml::parse return an array as it can apparently return a string](http://github.com/doctrine/migrations/commit/1499f0cc3e5f5b20a510ba8f0779d5c68a9e5084) + - [Avoid uploading code coverage to Scrutinizer for HHVM and PHP 7](http://github.com/doctrine/migrations/commit/d47d65021dcb711480bf27f6d0bbba138e220f12) + - [Improve the Travis configuration by persisting the composer cache](http://github.com/doctrine/migrations/commit/bda0509b479ae6605b8fa749b0999b4ce2ff8c04) + - [Keep the license file in the downloadable archives](https://github.com/doctrine/migrations/commit/dfbee38e004899bc078d5d47b13bea53799fca1e#diff-fc723d30b02a4cca7a534518111c1a66) + +### Changed + - [Use short array syntax](http://github.com/doctrine/migrations/commit/50a6e18c95ff617325229a4a649d65c1a11445bc) + - [composer: use PSR-4 autoload](http://github.com/doctrine/migrations/commit/7fb8d301b2f4d4a564433165e0604b7d34013844) + - [refactoring the configuration loading](http://github.com/doctrine/migrations/commit/e95b277111c74cfe65eb959d4471f45a815e1ece) + - [Drop support for php 5.3](https://github.com/doctrine/migrations/commit/0e60856a10e8b510daa612fe25f6245aece77e68) + - [compressing the phar so that it's half the size now](https://github.com/doctrine/migrations/commit/70730ff8655f0be89ce0f06d1e279930d7eb2550) + +### Added + - [Added the ability to auto create migrations in a folder by month and year](http://github.com/doctrine/migrations/commit/0b8e40868e12a36de7f689add61857b9ba29c4bc) + - [Set default name for configuration helper](http://github.com/doctrine/migrations/commit/1f3592f2f126a022db275192f17b8d5c01f19822) + - [Added ability to load config from php array or json files.](http://github.com/doctrine/migrations/commit/8cf01d623f9eb3728ba86c22970347107a8f0be7) + - [Added the possibility to inject the OutputWriter after instantiation](https://github.com/doctrine/migrations/pull/342) + - [Added the --allow-no-migration option to avoid throwing an exception if no migrations are found](https://github.com/doctrine/migrations/commit/a9ec86faa3a3f7f592a633af43b6ef6c9f358239#diff-0a4648a19ba565cda76b349e89552a9b) From 5954beade8b351448f4b9ab37310abf29c5e440f Mon Sep 17 00:00:00 2001 From: Gabriel Caruso Date: Mon, 27 Nov 2017 16:50:37 -0200 Subject: [PATCH 093/129] Use assertEmpty --- tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php index bceab311..7ad08c00 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php @@ -38,6 +38,6 @@ public function testNode() self::assertSame($value, $node->value); self::assertSame(Vertex::NOT_VISITED, $node->state); - self::assertSame([], $node->dependencyList); + self::assertEmpty($node->dependencyList); } } From 9d7045b5c1b45d64c5795daf3fd8555246d0a147 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Mon, 4 Dec 2017 16:22:18 +0100 Subject: [PATCH 094/129] Don't use ignore-platform-reqs when installing mongo-php-adapter --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4e3396a0..fab1c4c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,8 @@ before_install: before_script: - composer self-update - composer install --prefer-source - - composer require --ignore-platform-reqs alcaeus/mongo-php-adapter + - composer config "platform.ext-mongo" "1.6.16" + - composer require alcaeus/mongo-php-adapter - composer require doctrine/mongodb-odm script: From d50404248e4bda2249d035af7832848edc8172fb Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Mon, 4 Dec 2017 16:54:20 +0100 Subject: [PATCH 095/129] Force installation of mongodb pecl extension --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fab1c4c9..b68b9945 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ matrix: services: mongodb before_install: - - pecl install mongodb + - pecl install -f mongodb before_script: - composer self-update From 09d039026306167907a8a6798b4f2a74794c0419 Mon Sep 17 00:00:00 2001 From: dpastori Date: Tue, 5 Dec 2017 11:41:04 +0100 Subject: [PATCH 096/129] added backslash to phpDoc for BadMethodCallException --- lib/Doctrine/Common/DataFixtures/AbstractFixture.php | 2 +- lib/Doctrine/Common/DataFixtures/ReferenceRepository.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/AbstractFixture.php b/lib/Doctrine/Common/DataFixtures/AbstractFixture.php index 1e7fb674..ae3ad189 100644 --- a/lib/Doctrine/Common/DataFixtures/AbstractFixture.php +++ b/lib/Doctrine/Common/DataFixtures/AbstractFixture.php @@ -69,7 +69,7 @@ public function setReference($name, $object) * @param string $name * @param object $object - managed object * @see Doctrine\Common\DataFixtures\ReferenceRepository::addReference - * @throws BadMethodCallException - if repository already has + * @throws \BadMethodCallException - if repository already has * a reference by $name * @return void */ diff --git a/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php b/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php index c98c1b7b..070a8eb9 100644 --- a/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php +++ b/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php @@ -137,7 +137,7 @@ public function setReferenceIdentity($name, $identity) * * @param string $name * @param object $object - managed object - * @throws BadMethodCallException - if repository already has + * @throws \BadMethodCallException - if repository already has * a reference by $name * @return void */ @@ -154,7 +154,7 @@ public function addReference($name, $object) * named by $name * * @param string $name - * @throws OutOfBoundsException - if repository does not exist + * @throws \OutOfBoundsException - if repository does not exist * @return object */ public function getReference($name) From e8d7c2935d1cc4767a61e1091da2488d16037ae2 Mon Sep 17 00:00:00 2001 From: Gabriel Caruso Date: Sun, 10 Dec 2017 05:36:17 -0200 Subject: [PATCH 097/129] Refactoring tests --- .../Common/DataFixtures/DependentFixtureTest.php | 16 ++++++++-------- .../Executor/ORMExecutorSharedFixtureTest.php | 6 +++--- .../DataFixtures/Purger/ORMPurgerExcludeTest.php | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/DependentFixtureTest.php b/tests/Doctrine/Tests/Common/DataFixtures/DependentFixtureTest.php index 7883bdd1..fe72eb0e 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/DependentFixtureTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/DependentFixtureTest.php @@ -87,14 +87,14 @@ public function test_orderFixturesByDependencies_orderClassesWithAMultipleParent // BaseParentFixture1 has no dependencies, so it will always be first in this case $this->assertEquals($baseParentFixtureOrder, 0); - $this->assertTrue($contactFixtureOrder > $contactMethodFixtureOrder); - $this->assertTrue($contactFixtureOrder > $addressFixtureOrder); - $this->assertTrue($contactFixtureOrder > $countryFixtureOrder); - $this->assertTrue($contactFixtureOrder > $stateFixtureOrder); - $this->assertTrue($contactFixtureOrder > $contactMethodFixtureOrder); - - $this->assertTrue($addressFixtureOrder > $stateFixtureOrder); - $this->assertTrue($addressFixtureOrder > $countryFixtureOrder); + $this->assertGreaterThan($contactMethodFixtureOrder, $contactFixtureOrder); + $this->assertGreaterThan($addressFixtureOrder, $contactFixtureOrder); + $this->assertGreaterThan($countryFixtureOrder, $contactFixtureOrder); + $this->assertGreaterThan($stateFixtureOrder, $contactFixtureOrder); + $this->assertGreaterThan($contactMethodFixtureOrder, $contactFixtureOrder); + + $this->assertGreaterThan($stateFixtureOrder, $addressFixtureOrder); + $this->assertGreaterThan($countryFixtureOrder, $addressFixtureOrder); } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php index 94301b0e..bc2edb2a 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php @@ -79,13 +79,13 @@ public function testSharedFixtures() $referenceRepository = $executor->getReferenceRepository(); $references = $referenceRepository->getReferences(); - $this->assertEquals(2, count($references)); + $this->assertCount(2, $references); $roleReference = $referenceRepository->getReference('admin-role'); - $this->assertTrue($roleReference instanceof Role); + $this->assertInstanceOf(Role::class, $roleReference); $this->assertEquals('admin', $roleReference->getName()); $userReference = $referenceRepository->getReference('admin'); - $this->assertTrue($userReference instanceof User); + $this->assertInstanceOf(User::class, $userReference); $this->assertEquals('admin@example.com', $userReference->getEmail()); } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php index 3d83bb15..41452a10 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php @@ -80,7 +80,7 @@ public function executeTestPurge($expression, array $list){ $excluded = $excludedRepository->findAll(); $included = $includedRepository->findAll(); - $this->assertEquals(0, count($included)); + $this->assertCount(0, $included); $this->assertGreaterThan(0, count($excluded)); } From a73047a27cf7b01880b60837c093fdb633e5a089 Mon Sep 17 00:00:00 2001 From: Luis Lopes Date: Thu, 14 Dec 2017 16:16:56 +0000 Subject: [PATCH 098/129] Added access modifier to DependentFixtureInterface Implement the access modifier making it PSR-2 compliant --- lib/Doctrine/Common/DataFixtures/DependentFixtureInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/Common/DataFixtures/DependentFixtureInterface.php b/lib/Doctrine/Common/DataFixtures/DependentFixtureInterface.php index ad34d4db..4caa1222 100644 --- a/lib/Doctrine/Common/DataFixtures/DependentFixtureInterface.php +++ b/lib/Doctrine/Common/DataFixtures/DependentFixtureInterface.php @@ -33,5 +33,5 @@ interface DependentFixtureInterface * * @return array */ - function getDependencies(); + public function getDependencies(); } From 318df610720a7a7de0add8b27107654877642ac4 Mon Sep 17 00:00:00 2001 From: mike Date: Thu, 21 Dec 2017 11:36:10 +0100 Subject: [PATCH 099/129] Removing the license header --- .../Common/DataFixtures/AbstractFixture.php | 17 ----------------- .../Event/Listener/MongoDBReferenceListener.php | 17 ----------------- .../Event/Listener/ORMReferenceListener.php | 17 ----------------- .../DataFixtures/Executor/MongoDBExecutor.php | 17 ----------------- .../DataFixtures/Executor/ORMExecutor.php | 17 ----------------- .../DataFixtures/Executor/PHPCRExecutor.php | 17 ----------------- .../Common/DataFixtures/FixtureInterface.php | 17 ----------------- lib/Doctrine/Common/DataFixtures/Loader.php | 17 ----------------- .../DataFixtures/OrderedFixtureInterface.php | 17 ----------------- .../DataFixtures/ProxyReferenceRepository.php | 17 ----------------- .../DataFixtures/Purger/MongoDBPurger.php | 17 ----------------- .../Common/DataFixtures/Purger/ORMPurger.php | 17 ----------------- .../Common/DataFixtures/Purger/PHPCRPurger.php | 17 ----------------- .../DataFixtures/Purger/PurgerInterface.php | 17 ----------------- .../Common/DataFixtures/ReferenceRepository.php | 17 ----------------- .../DataFixtures/SharedFixtureInterface.php | 17 ----------------- .../DataFixtures/Sorter/TopologicalSorter.php | 17 ----------------- .../Common/DataFixtures/Sorter/Vertex.php | 17 ----------------- .../Tests/Common/DataFixtures/BaseTest.php | 17 ----------------- .../DataFixtures/DependentFixtureTest.php | 17 ----------------- .../Executor/ORMExecutorSharedFixtureTest.php | 17 ----------------- .../DataFixtures/Executor/ORMExecutorTest.php | 17 ----------------- .../DataFixtures/Executor/PHPCRExecutorTest.php | 17 ----------------- .../Tests/Common/DataFixtures/FixtureTest.php | 17 ----------------- .../Tests/Common/DataFixtures/LoaderTest.php | 17 ----------------- .../Common/DataFixtures/OrderedFixtureTest.php | 17 ----------------- .../ProxyReferenceRepositoryTest.php | 17 ----------------- .../DataFixtures/ReferenceRepositoryTest.php | 17 ----------------- .../Sorter/TopologicalSorterTest.php | 17 ----------------- .../Common/DataFixtures/Sorter/VertexTest.php | 17 ----------------- tests/Doctrine/Tests/Mock/Node.php | 17 ----------------- 31 files changed, 527 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/AbstractFixture.php b/lib/Doctrine/Common/DataFixtures/AbstractFixture.php index ae3ad189..7edb131e 100644 --- a/lib/Doctrine/Common/DataFixtures/AbstractFixture.php +++ b/lib/Doctrine/Common/DataFixtures/AbstractFixture.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\DataFixtures; diff --git a/lib/Doctrine/Common/DataFixtures/Event/Listener/MongoDBReferenceListener.php b/lib/Doctrine/Common/DataFixtures/Event/Listener/MongoDBReferenceListener.php index 3fa20f2d..746b4696 100644 --- a/lib/Doctrine/Common/DataFixtures/Event/Listener/MongoDBReferenceListener.php +++ b/lib/Doctrine/Common/DataFixtures/Event/Listener/MongoDBReferenceListener.php @@ -1,22 +1,5 @@ . - */ namespace Doctrine\Common\DataFixtures\Event\Listener; diff --git a/lib/Doctrine/Common/DataFixtures/Event/Listener/ORMReferenceListener.php b/lib/Doctrine/Common/DataFixtures/Event/Listener/ORMReferenceListener.php index efc8cab1..fb9327d2 100644 --- a/lib/Doctrine/Common/DataFixtures/Event/Listener/ORMReferenceListener.php +++ b/lib/Doctrine/Common/DataFixtures/Event/Listener/ORMReferenceListener.php @@ -1,22 +1,5 @@ . - */ namespace Doctrine\Common\DataFixtures\Event\Listener; diff --git a/lib/Doctrine/Common/DataFixtures/Executor/MongoDBExecutor.php b/lib/Doctrine/Common/DataFixtures/Executor/MongoDBExecutor.php index 104415cf..daf10782 100644 --- a/lib/Doctrine/Common/DataFixtures/Executor/MongoDBExecutor.php +++ b/lib/Doctrine/Common/DataFixtures/Executor/MongoDBExecutor.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\DataFixtures\Executor; diff --git a/lib/Doctrine/Common/DataFixtures/Executor/ORMExecutor.php b/lib/Doctrine/Common/DataFixtures/Executor/ORMExecutor.php index 26990c72..5bcaab6f 100644 --- a/lib/Doctrine/Common/DataFixtures/Executor/ORMExecutor.php +++ b/lib/Doctrine/Common/DataFixtures/Executor/ORMExecutor.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\DataFixtures\Executor; diff --git a/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php b/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php index cef09975..b259c1ee 100644 --- a/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php +++ b/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\DataFixtures\Executor; diff --git a/lib/Doctrine/Common/DataFixtures/FixtureInterface.php b/lib/Doctrine/Common/DataFixtures/FixtureInterface.php index 3d66bf46..96bfb103 100644 --- a/lib/Doctrine/Common/DataFixtures/FixtureInterface.php +++ b/lib/Doctrine/Common/DataFixtures/FixtureInterface.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\DataFixtures; diff --git a/lib/Doctrine/Common/DataFixtures/Loader.php b/lib/Doctrine/Common/DataFixtures/Loader.php index fad6265f..5c5b0e54 100644 --- a/lib/Doctrine/Common/DataFixtures/Loader.php +++ b/lib/Doctrine/Common/DataFixtures/Loader.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\DataFixtures; diff --git a/lib/Doctrine/Common/DataFixtures/OrderedFixtureInterface.php b/lib/Doctrine/Common/DataFixtures/OrderedFixtureInterface.php index 6fc8032f..8f7b9430 100644 --- a/lib/Doctrine/Common/DataFixtures/OrderedFixtureInterface.php +++ b/lib/Doctrine/Common/DataFixtures/OrderedFixtureInterface.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\DataFixtures; diff --git a/lib/Doctrine/Common/DataFixtures/ProxyReferenceRepository.php b/lib/Doctrine/Common/DataFixtures/ProxyReferenceRepository.php index e1b8ae16..cddbe517 100644 --- a/lib/Doctrine/Common/DataFixtures/ProxyReferenceRepository.php +++ b/lib/Doctrine/Common/DataFixtures/ProxyReferenceRepository.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\DataFixtures; diff --git a/lib/Doctrine/Common/DataFixtures/Purger/MongoDBPurger.php b/lib/Doctrine/Common/DataFixtures/Purger/MongoDBPurger.php index 4229e800..ce5cce96 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/MongoDBPurger.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/MongoDBPurger.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\DataFixtures\Purger; diff --git a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php index 0dc919d0..af393f0f 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\DataFixtures\Purger; diff --git a/lib/Doctrine/Common/DataFixtures/Purger/PHPCRPurger.php b/lib/Doctrine/Common/DataFixtures/Purger/PHPCRPurger.php index be3603bb..3299e990 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/PHPCRPurger.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/PHPCRPurger.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\DataFixtures\Purger; diff --git a/lib/Doctrine/Common/DataFixtures/Purger/PurgerInterface.php b/lib/Doctrine/Common/DataFixtures/Purger/PurgerInterface.php index 7d85b0f8..76421fb7 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/PurgerInterface.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/PurgerInterface.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\DataFixtures\Purger; diff --git a/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php b/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php index 070a8eb9..123fac5e 100644 --- a/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php +++ b/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\DataFixtures; diff --git a/lib/Doctrine/Common/DataFixtures/SharedFixtureInterface.php b/lib/Doctrine/Common/DataFixtures/SharedFixtureInterface.php index 5d3d0a89..c3e145bf 100644 --- a/lib/Doctrine/Common/DataFixtures/SharedFixtureInterface.php +++ b/lib/Doctrine/Common/DataFixtures/SharedFixtureInterface.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\DataFixtures; diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php index 62e5ad33..be4dd673 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\DataFixtures\Sorter; diff --git a/lib/Doctrine/Common/DataFixtures/Sorter/Vertex.php b/lib/Doctrine/Common/DataFixtures/Sorter/Vertex.php index 0316d1d3..5b0cbf6d 100644 --- a/lib/Doctrine/Common/DataFixtures/Sorter/Vertex.php +++ b/lib/Doctrine/Common/DataFixtures/Sorter/Vertex.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Common\DataFixtures\Sorter; diff --git a/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php b/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php index 29e9d74b..bde7a387 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\Common\DataFixtures; diff --git a/tests/Doctrine/Tests/Common/DataFixtures/DependentFixtureTest.php b/tests/Doctrine/Tests/Common/DataFixtures/DependentFixtureTest.php index fe72eb0e..66d72e0a 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/DependentFixtureTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/DependentFixtureTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\Common\DataFixtures; diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php index bc2edb2a..419f4951 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorSharedFixtureTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\Common\DataFixtures; diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorTest.php index 54cc606e..e50feb26 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\Common\DataFixtures\Executor; diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php index d2841d02..c601e377 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\Common\DataFixtures\Executor; diff --git a/tests/Doctrine/Tests/Common/DataFixtures/FixtureTest.php b/tests/Doctrine/Tests/Common/DataFixtures/FixtureTest.php index 4e3f9b8c..1ca99762 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/FixtureTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/FixtureTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\Common\DataFixtures; diff --git a/tests/Doctrine/Tests/Common/DataFixtures/LoaderTest.php b/tests/Doctrine/Tests/Common/DataFixtures/LoaderTest.php index d725a20a..0b6e3f73 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/LoaderTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/LoaderTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\Common\DataFixtures; diff --git a/tests/Doctrine/Tests/Common/DataFixtures/OrderedFixtureTest.php b/tests/Doctrine/Tests/Common/DataFixtures/OrderedFixtureTest.php index a5157844..3ad14ceb 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/OrderedFixtureTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/OrderedFixtureTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\Common\DataFixtures; diff --git a/tests/Doctrine/Tests/Common/DataFixtures/ProxyReferenceRepositoryTest.php b/tests/Doctrine/Tests/Common/DataFixtures/ProxyReferenceRepositoryTest.php index 4412ad90..9f722982 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/ProxyReferenceRepositoryTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/ProxyReferenceRepositoryTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\Common\DataFixtures; diff --git a/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php b/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php index 3b30bc90..64a989b7 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/ReferenceRepositoryTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\Common\DataFixtures; diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php index 9b935fc9..46df1792 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/TopologicalSorterTest.php @@ -1,22 +1,5 @@ . - */ namespace Doctrine\Test\DataFixtures\Sorter; diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php index 7ad08c00..d11ed951 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php @@ -1,22 +1,5 @@ . - */ namespace Doctrine\Test\DataFixtures\Sorter; diff --git a/tests/Doctrine/Tests/Mock/Node.php b/tests/Doctrine/Tests/Mock/Node.php index d66c6f99..6dcad84a 100644 --- a/tests/Doctrine/Tests/Mock/Node.php +++ b/tests/Doctrine/Tests/Mock/Node.php @@ -1,22 +1,5 @@ . - */ namespace Doctrine\Tests\Mock; From 0834f3926902a4ebbb46a20c1609601fa460e2cc Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Tue, 13 Feb 2018 09:47:03 +0100 Subject: [PATCH 100/129] fix test running instructions --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 00a98212..2c954903 100644 --- a/README.md +++ b/README.md @@ -192,10 +192,10 @@ class MyOtherFixture extends AbstractFixture ## Running the tests: -PHPUnit 3.5 or newer together with Mock_Object package is required. +Phpunit is included in the dev requirements of this package. + To setup and run tests follow these steps: - go to the root directory of data-fixtures - run: **composer install --dev** -- copy the phpunit config **cp phpunit.xml.dist phpunit.xml** -- run: **phpunit** +- run: **vendor/bin/phpunit** From ab3b082fce0a63bea8b6db1ae9cbcd04adc15a33 Mon Sep 17 00:00:00 2001 From: Gabriel Caruso Date: Wed, 14 Mar 2018 16:16:36 -0300 Subject: [PATCH 101/129] Use PHPUnit 7 Signed-off-by: Gabriel Caruso --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1176d25e..92595f76 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "require-dev": { "doctrine/orm": "^2.5.4", "doctrine/dbal": "^2.5.4", - "phpunit/phpunit": "^6.3" + "phpunit/phpunit": "^7.0" }, "suggest": { "doctrine/orm": "For loading ORM fixtures", From b0d7c8a4ade3acd4d5f8f89fa4cb1f1544c31db6 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Tue, 13 Feb 2018 09:34:06 +0100 Subject: [PATCH 102/129] clean up phpcr executor --- .travis.yml | 1 + composer.json | 3 ++ .../Executor/AbstractExecutor.php | 37 +++++++++---------- .../DataFixtures/Executor/PHPCRExecutor.php | 26 ++++++------- .../DataFixtures/Purger/PHPCRPurger.php | 24 ++---------- .../DataFixtures/ReferenceRepository.php | 9 +---- 6 files changed, 40 insertions(+), 60 deletions(-) diff --git a/.travis.yml b/.travis.yml index b68b9945..4aa5fd5b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,6 +26,7 @@ before_script: - composer config "platform.ext-mongo" "1.6.16" - composer require alcaeus/mongo-php-adapter - composer require doctrine/mongodb-odm + - composer require jackalope/jackalope-doctrine-dbal doctrine/phpcr-odm script: - ./vendor/bin/phpunit -v diff --git a/composer.json b/composer.json index 1176d25e..73ee2abf 100644 --- a/composer.json +++ b/composer.json @@ -33,5 +33,8 @@ "branch-alias": { "dev-master": "1.3.x-dev" } + }, + "conflict": { + "doctrine/phpcr-odm": "<1.3.0" } } diff --git a/lib/Doctrine/Common/DataFixtures/Executor/AbstractExecutor.php b/lib/Doctrine/Common/DataFixtures/Executor/AbstractExecutor.php index 94b3ff2d..a92ff25b 100644 --- a/lib/Doctrine/Common/DataFixtures/Executor/AbstractExecutor.php +++ b/lib/Doctrine/Common/DataFixtures/Executor/AbstractExecutor.php @@ -16,31 +16,33 @@ */ abstract class AbstractExecutor { - /** Purger instance for purging database before loading data fixtures */ + /** + * Purger instance for purging database before loading data fixtures + * + * @var PurgerInterface + */ protected $purger; - /** Logger callback for logging messages when loading data fixtures */ + /** + * Logger callback for logging messages when loading data fixtures + * + * @var callable + */ protected $logger; /** * Fixture reference repository + * * @var ReferenceRepository */ protected $referenceRepository; - /** - * Loads an instance of reference repository - * - * @param Doctrine\Common\Persistence\ObjectManager $manager - */ public function __construct(ObjectManager $manager) { $this->referenceRepository = new ReferenceRepository($manager); } /** - * Get reference repository - * * @return ReferenceRepository */ public function getReferenceRepository() @@ -48,11 +50,6 @@ public function getReferenceRepository() return $this->referenceRepository; } - /** - * Set the reference repository - * - * @param ReferenceRepository $referenceRepository Reference repository - */ public function setReferenceRepository(ReferenceRepository $referenceRepository) { $this->referenceRepository = $referenceRepository; @@ -69,9 +66,7 @@ public function setPurger(PurgerInterface $purger) } /** - * Get purger - * - * @return Purger + * @return PurgerInterface */ public function getPurger() { @@ -81,7 +76,7 @@ public function getPurger() /** * Set the logger callable to execute with the log() method. * - * @param $logger + * @param callable $logger */ public function setLogger($logger) { @@ -102,7 +97,7 @@ public function log($message) /** * Load a fixture with the given persistence manager. * - * @param Doctrine\Common\Persistence\ObjectManager $manager + * @param ObjectManager $manager * @param FixtureInterface $fixture */ public function load(ObjectManager $manager, FixtureInterface $fixture) @@ -124,6 +119,8 @@ public function load(ObjectManager $manager, FixtureInterface $fixture) /** * Purges the database before loading. + * + * @throws \Exception if the purger is not defined */ public function purge() { @@ -139,7 +136,7 @@ public function purge() /** * Executes the given array of data fixtures. * - * @param array $fixtures Array of fixtures to execute. + * @param array $fixtures Array of fixtures to execute. * @param boolean $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/PHPCRExecutor.php b/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php index b259c1ee..ec634c25 100644 --- a/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php +++ b/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php @@ -2,7 +2,7 @@ namespace Doctrine\Common\DataFixtures\Executor; -use Doctrine\ODM\PHPCR\DocumentManager; +use Doctrine\ODM\PHPCR\DocumentManagerInterface; use Doctrine\Common\DataFixtures\Purger\PHPCRPurger; /** @@ -14,25 +14,25 @@ class PHPCRExecutor extends AbstractExecutor { /** - * Construct new fixtures loader instance. - * - * @param DocumentManager $dm DocumentManager instance used for persistence. + * @var DocumentManagerInterface */ - public function __construct(DocumentManager $dm, PHPCRPurger $purger = null) + 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) { + parent::__construct($dm); + $this->dm = $dm; if ($purger !== null) { - $this->purger = $purger; - $this->purger->setDocumentManager($dm); + $purger->setDocumentManager($dm); + $this->setPurger($purger); } - parent::__construct($dm); } - /** - * Retrieve the DocumentManager instance this executor instance is using. - * - * @return \Doctrine\ODM\PHPCR\DocumentManager - */ public function getObjectManager() { return $this->dm; diff --git a/lib/Doctrine/Common/DataFixtures/Purger/PHPCRPurger.php b/lib/Doctrine/Common/DataFixtures/Purger/PHPCRPurger.php index 3299e990..e5c85272 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/PHPCRPurger.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/PHPCRPurger.php @@ -2,9 +2,9 @@ namespace Doctrine\Common\DataFixtures\Purger; -use PHPCR\Util\NodeHelper; - use Doctrine\ODM\PHPCR\DocumentManager; +use Doctrine\ODM\PHPCR\DocumentManagerInterface; +use PHPCR\Util\NodeHelper; /** * Class responsible for purging databases of data before reloading data fixtures. @@ -14,36 +14,20 @@ class PHPCRPurger implements PurgerInterface { /** - * DocumentManager instance used for persistence. - * @var DocumentManager + * @var DocumentManagerInterface */ private $dm; - /** - * Construct new purger instance. - * - * @param DocumentManager $dm DocumentManager instance used for persistence. - */ - public function __construct(DocumentManager $dm = null) + public function __construct(DocumentManagerInterface $dm = null) { $this->dm = $dm; } - /** - * Set the DocumentManager instance this purger instance should use. - * - * @param DocumentManager $dm - */ public function setDocumentManager(DocumentManager $dm) { $this->dm = $dm; } - /** - * Retrieve the DocumentManager instance this purger instance is using. - * - * @return \Doctrine\ODM\PHPCR\DocumentManager - */ public function getObjectManager() { return $this->dm; diff --git a/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php b/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php index 123fac5e..da076562 100644 --- a/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php +++ b/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php @@ -34,15 +34,10 @@ class ReferenceRepository /** * Currently used object manager * - * @var Doctrine\Common\Persistence\ObjectManager + * @var ObjectManager */ private $manager; - /** - * Initialize the ReferenceRepository - * - * @param Doctrine\Common\Persistence\ObjectManager $manager - */ public function __construct(ObjectManager $manager) { $this->manager = $manager; @@ -217,7 +212,7 @@ public function getReferences() /** * Get object manager * - * @return Doctrine\Common\Persistence\ObjectManager + * @return ObjectManager */ public function getManager() { From 2bdb16ee6fbbc4a373d20a01381ec1f8235a7a34 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Sat, 13 Oct 2018 20:58:47 +0200 Subject: [PATCH 103/129] CI: Test against PHP 7.3 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 4aa5fd5b..c49dba84 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ cache: php: - 7.1 - 7.2 + - 7.3 - nightly matrix: From 81422d4a091462b5f65b97375aa04e82bd98d97f Mon Sep 17 00:00:00 2001 From: Vitaliy Ryaboy Date: Fri, 26 Apr 2019 17:58:01 +0200 Subject: [PATCH 104/129] remove unnecessary files for production --- .gitattributes | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..3c94a696 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +# Auto-detect text files, ensure they use LF. +* text=auto eol=lf + +# Exclude non-essential files from dist +/tests export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.travis.yml export-ignore +/phpunit.xml.dist export-ignore From 8133b3f6309b46d478e309cf98da60ae6c74d3be Mon Sep 17 00:00:00 2001 From: "Jonathan H. Wage" Date: Fri, 24 May 2019 12:58:02 -0500 Subject: [PATCH 105/129] Add .github/FUNDING.yml --- .github/FUNDING.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..43c81dec --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +patreon: phpdoctrine +tidelift: packagist/doctrine%2Fdata-fixtures +custom: https://www.doctrine-project.org/sponsorship.html From 92c9d05d3f6b52d557095c6f46e749fd1388f38c Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Tue, 9 Jul 2019 21:30:21 +0200 Subject: [PATCH 106/129] Respect schema asset filters from DBAL 2.9+ --- .../Common/DataFixtures/Purger/ORMPurger.php | 31 +++++++++++++++---- .../Purger/ORMPurgerExcludeTest.php | 22 +++++++++++-- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php index af393f0f..16eca488 100644 --- a/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php +++ b/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php @@ -7,6 +7,9 @@ use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\ORM\Mapping\ClassMetadataInfo; +use function array_search; +use function is_callable; +use function preg_match; /** * Class responsible for purging databases of data before reloading data fixtures. @@ -126,13 +129,29 @@ public function purge() $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) { - if(($emptyFilterExpression||preg_match($filterExpr, $tbl)) && array_search($tbl, $this->excluded) === false){ - if ($this->purgeMode === self::PURGE_MODE_DELETE) { - $connection->executeUpdate("DELETE FROM " . $tbl); - } else { - $connection->executeUpdate($platform->getTruncateTableSQL($tbl, true)); - } + // If we have a filter expression, check it and skip if necessary + if (!$emptyFilterExpression && !preg_match($filterExpr, $tbl)) { + continue; + } + + // If the table is excluded, skip it as well + if (array_search($tbl, $this->excluded) !== false) { + continue; + } + + // Support schema asset filters as presented in + if (is_callable($schemaAssetsFilter) && !$schemaAssetsFilter($tbl)) { + continue; + } + + if ($this->purgeMode === self::PURGE_MODE_DELETE) { + $connection->executeUpdate("DELETE FROM " . $tbl); + } else { + $connection->executeUpdate($platform->getTruncateTableSQL($tbl, true)); } } } diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php index 41452a10..b68de4b8 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerExcludeTest.php @@ -9,6 +9,7 @@ use Doctrine\ORM\Tools\Setup; use Doctrine\Tests\Common\DataFixtures\TestPurgeEntity\ExcludedEntity; use Doctrine\Tests\Common\DataFixtures\TestPurgeEntity\IncludedEntity; +use function method_exists; class ORMPurgerExcludeTest extends BaseTest { @@ -59,7 +60,7 @@ protected function loadTestData(){ * @param string|null $expression * @param array $list */ - public function executeTestPurge($expression, array $list){ + 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); @@ -74,6 +75,14 @@ public function executeTestPurge($expression, array $list){ $configuration = $connection->getConfiguration(); $configuration->setFilterSchemaAssetsExpression($expression); + if ($filter !== null) { + 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->purge(); @@ -88,13 +97,20 @@ public function executeTestPurge($expression, array $list){ * Test for purge exclusion usig dbal filter expression regexp. */ public function testPurgeExcludeUsingFilterExpression(){ - $this->executeTestPurge('~^(?!ExcludedEntity)~', []); + $this->executeTestPurge('~^(?!ExcludedEntity)~', [], null); } /** * Test for purge exclusion usig explicit exclution list. */ public function testPurgeExcludeUsingList(){ - $this->executeTestPurge(null, ['ExcludedEntity']); + $this->executeTestPurge(null, ['ExcludedEntity'], null); + } + + public function testPurgeExcludeUsingFilterCallable() : void + { + $this->executeTestPurge(null, [], static function (string $table) : bool { + return preg_match('~^(?!ExcludedEntity)~', $table); + }); } } From bfa9aa306932d21cc272e20afc4b6f3750a84fe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Wed, 4 Sep 2019 23:07:32 +0200 Subject: [PATCH 107/129] Enhancement: Use SVG badge for Travis build status --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2c954903..cabb7e23 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Doctrine Data Fixtures Extension -[![Build Status](https://travis-ci.org/doctrine/data-fixtures.png)](https://travis-ci.org/doctrine/data-fixtures) +[![Build Status](https://travis-ci.org/doctrine/data-fixtures.svg?branch=master)](https://travis-ci.org/doctrine/data-fixtures) This extension aims to provide a simple way to manage and execute the loading of data fixtures for the [Doctrine ORM or ODM](http://www.doctrine-project.org/). You can write fixture classes From 0e6c91b1908fc05af0c54bfd5a97db00dcd11c24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Wed, 4 Sep 2019 23:09:57 +0200 Subject: [PATCH 108/129] Enhancement: Keep packages sorted in composer.json --- composer.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7c2b6293..67cce5e2 100644 --- a/composer.json +++ b/composer.json @@ -13,8 +13,8 @@ "doctrine/common": "~2.2" }, "require-dev": { - "doctrine/orm": "^2.5.4", "doctrine/dbal": "^2.5.4", + "doctrine/orm": "^2.5.4", "phpunit/phpunit": "^7.0" }, "suggest": { @@ -36,5 +36,8 @@ }, "conflict": { "doctrine/phpcr-odm": "<1.3.0" + }, + "config": { + "sort-packages": true } } From 4a3c70812316160874147206495b661bae66daa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Wed, 4 Sep 2019 23:12:13 +0200 Subject: [PATCH 109/129] Enhancement: Reference phpunit.xsd as installed with composer --- phpunit.xml.dist | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 885d4308..e2a1475e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,6 +1,8 @@ - Date: Wed, 4 Sep 2019 23:13:17 +0200 Subject: [PATCH 110/129] Fix: Remove non-existent attribute --- phpunit.xml.dist | 1 - 1 file changed, 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e2a1475e..1236a734 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,7 +9,6 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" stopOnFailure="false" - syntaxCheck="false" bootstrap="vendor/autoload.php" > From 31404e27e5870d950d95eceb694e2e97bcc84f36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Wed, 4 Sep 2019 23:14:23 +0200 Subject: [PATCH 111/129] Fix: No need to update composer itself --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c49dba84..4e7b66ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,6 @@ before_install: - pecl install -f mongodb before_script: - - composer self-update - composer install --prefer-source - composer config "platform.ext-mongo" "1.6.16" - composer require alcaeus/mongo-php-adapter From 1a51830c4ec88d9477607377e57dc1cdc5097e06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Thu, 5 Sep 2019 11:45:13 +0200 Subject: [PATCH 112/129] Enhancement: Normalize composer.json --- composer.json | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index 67cce5e2..34eab23a 100644 --- a/composer.json +++ b/composer.json @@ -2,42 +2,51 @@ "name": "doctrine/data-fixtures", "type": "library", "description": "Data Fixtures for all Doctrine Object Managers", - "keywords": ["database"], + "keywords": [ + "database" + ], "homepage": "http://www.doctrine-project.org", "license": "MIT", "authors": [ - {"name": "Jonathan Wage", "email": "jonwage@gmail.com"} + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + } ], "require": { "php": "^7.1", "doctrine/common": "~2.2" }, + "conflict": { + "doctrine/phpcr-odm": "<1.3.0" + }, "require-dev": { "doctrine/dbal": "^2.5.4", "doctrine/orm": "^2.5.4", "phpunit/phpunit": "^7.0" }, "suggest": { - "doctrine/orm": "For loading ORM fixtures", + "alcaeus/mongo-php-adapter": "For using MongoDB ODM with PHP 7", "doctrine/mongodb-odm": "For loading MongoDB ODM fixtures", - "doctrine/phpcr-odm": "For loading PHPCR ODM fixtures", - "alcaeus/mongo-php-adapter": "For using MongoDB ODM with PHP 7" - }, - "autoload": { - "psr-4": { "Doctrine\\Common\\DataFixtures\\": "lib/Doctrine/Common/DataFixtures" } + "doctrine/orm": "For loading ORM fixtures", + "doctrine/phpcr-odm": "For loading PHPCR ODM fixtures" }, - "autoload-dev": { - "psr-4": { "Doctrine\\Tests\\": "tests/Doctrine/Tests" } + "config": { + "sort-packages": true }, "extra": { "branch-alias": { "dev-master": "1.3.x-dev" } }, - "conflict": { - "doctrine/phpcr-odm": "<1.3.0" + "autoload": { + "psr-4": { + "Doctrine\\Common\\DataFixtures\\": "lib/Doctrine/Common/DataFixtures" + } }, - "config": { - "sort-packages": true + "autoload-dev": { + "psr-4": { + "Doctrine\\Tests\\": "tests/Doctrine/Tests" + } } } From fcdb61fc6b0e6fb58e3cdd6271aa4e81a2994151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Thu, 5 Sep 2019 11:46:29 +0200 Subject: [PATCH 113/129] Enhancement: Validate composer.json --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 4e7b66ec..fc0477f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,7 @@ services: mongodb before_install: - pecl install -f mongodb + - composer validate --strict before_script: - composer install --prefer-source From d6e225b60edc9fec0ba15402234ad8d5f87df4d0 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 23 Oct 2019 20:25:06 +0200 Subject: [PATCH 114/129] Drop nightly build --- .travis.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index c49dba84..5352e4c2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,11 +10,6 @@ php: - 7.1 - 7.2 - 7.3 - - nightly - -matrix: - allow_failures: - - php: nightly services: mongodb From 7de1e14bfaeaf60702a1c450dcd673621ab37001 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 23 Oct 2019 20:25:11 +0200 Subject: [PATCH 115/129] Test against MongoDB ODM 1.x only --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5352e4c2..9d8137b9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,10 +18,10 @@ before_install: before_script: - composer self-update - - composer install --prefer-source - composer config "platform.ext-mongo" "1.6.16" - - composer require alcaeus/mongo-php-adapter - - composer require doctrine/mongodb-odm + - composer require --no-update alcaeus/mongo-php-adapter + - composer require --no-update doctrine/mongodb-odm "^1.3.0" + - composer install --prefer-source - composer require jackalope/jackalope-doctrine-dbal doctrine/phpcr-odm script: From babb1480a1579fcf7d6a6b57f31078906e452129 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 23 Oct 2019 20:42:45 +0200 Subject: [PATCH 116/129] Remove unsupported attribute in PHPUnit configuration --- phpunit.xml.dist | 1 - 1 file changed, 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 885d4308..b345e155 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -7,7 +7,6 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" stopOnFailure="false" - syntaxCheck="false" bootstrap="vendor/autoload.php" > From 986bbc9a65e6fc6bb3cb70e01125a159db61a5b4 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 23 Oct 2019 20:43:01 +0200 Subject: [PATCH 117/129] Fix risky test --- .../Tests/Common/DataFixtures/Executor/ORMExecutorTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorTest.php index e50feb26..b5a184c5 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/ORMExecutorTest.php @@ -49,6 +49,9 @@ public function testExecuteTransaction() $em = $this->getMockSqliteEntityManager(); $executor = new ORMExecutor($em); $fixture = $this->getMockFixture(); + $fixture->expects($this->once()) + ->method('load') + ->with($em); $executor->execute([$fixture], true); } From 98c6307fba8d470fa05174467b513314e6c5f04a Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 23 Oct 2019 20:43:12 +0200 Subject: [PATCH 118/129] Remove hack for doctrine/phpcr-odm --- .../Executor/PHPCRExecutorTest.php | 39 ++----------------- 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php index c601e377..42477aa4 100644 --- a/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php +++ b/tests/Doctrine/Tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php @@ -128,7 +128,9 @@ private function getPurger() */ private function getDocumentManager() { - $this->loadDocumentManagerClass(); + if (!class_exists(DocumentManager::class)) { + $this->markTestSkipped('Missing doctrine/phpcr-odm'); + } return $this ->getMockBuilder(DocumentManager::class) @@ -148,39 +150,4 @@ private function getMockFixture() { return $this->createMock(FixtureInterface::class); } - - /** - * Ensures that the {@see \Doctrine\ODM\PHPCR\DocumentManager} class exists - */ - private function loadDocumentManagerClass() - { - - if (class_exists(DocumentManager::class)) { - return; - } - - // hold my beer while I do some mocking - eval( - <<<'PHP' -namespace Doctrine\ODM\PHPCR; - -class DocumentManager implements \Doctrine\Common\Persistence\ObjectManager -{ - public function find($className, $id) {} - public function persist($object) {} - public function remove($object) {} - public function merge($object) {} - public function clear($objectName = null) {} - public function detach($object) {} - public function refresh($object) {} - public function flush() {} - public function getRepository($className) {} - public function getClassMetadata($className) {} - public function getMetadataFactory() {} - public function initializeObject($obj) {} - public function contains($object) {} -} -PHP - ); - } } From ee6db173b07948034f4a8d80cfc6f5f66e40a876 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 23 Oct 2019 20:46:27 +0200 Subject: [PATCH 119/129] Add all dev dependencies to composer.json --- .travis.yml | 6 +----- composer.json | 11 ++++++++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9d8137b9..8e2c38e4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,11 +18,7 @@ before_install: before_script: - composer self-update - - composer config "platform.ext-mongo" "1.6.16" - - composer require --no-update alcaeus/mongo-php-adapter - - composer require --no-update doctrine/mongodb-odm "^1.3.0" - - composer install --prefer-source - - composer require jackalope/jackalope-doctrine-dbal doctrine/phpcr-odm + - composer install script: - ./vendor/bin/phpunit -v diff --git a/composer.json b/composer.json index 7c2b6293..69394f74 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,11 @@ "require-dev": { "doctrine/orm": "^2.5.4", "doctrine/dbal": "^2.5.4", - "phpunit/phpunit": "^7.0" + "phpunit/phpunit": "^7.0", + "alcaeus/mongo-php-adapter": "^1.1", + "doctrine/mongodb-odm": "^1.3.0", + "jackalope/jackalope-doctrine-dbal": "^1.3", + "doctrine/phpcr-odm": "^1.4" }, "suggest": { "doctrine/orm": "For loading ORM fixtures", @@ -36,5 +40,10 @@ }, "conflict": { "doctrine/phpcr-odm": "<1.3.0" + }, + "config": { + "platform": { + "ext-mongo": "1.6.16" + } } } From 328484f87e01ed416da394e4311adfeab6e0c7e6 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 23 Oct 2019 21:08:58 +0200 Subject: [PATCH 120/129] Drop phpcr-odm from testing --- composer.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 69394f74..79647efd 100644 --- a/composer.json +++ b/composer.json @@ -17,9 +17,7 @@ "doctrine/dbal": "^2.5.4", "phpunit/phpunit": "^7.0", "alcaeus/mongo-php-adapter": "^1.1", - "doctrine/mongodb-odm": "^1.3.0", - "jackalope/jackalope-doctrine-dbal": "^1.3", - "doctrine/phpcr-odm": "^1.4" + "doctrine/mongodb-odm": "^1.3.0" }, "suggest": { "doctrine/orm": "For loading ORM fixtures", From f45fe5458c4f24e127fb34c8ba2f124fc46dafc3 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 23 Oct 2019 20:07:04 +0200 Subject: [PATCH 121/129] 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 122/129] 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 123/129] 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 124/129] 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 125/129] 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 126/129] 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 127/129] 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 128/129] 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 129/129] 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"