From af2f6a6fff39a9215704df85dee684fbd3d36954 Mon Sep 17 00:00:00 2001 From: Matthew Turland Date: Mon, 29 Jun 2015 22:58:48 -0500 Subject: [PATCH 001/877] Corrected bad class reference in "Adding own commands" --- docs/en/reference/tools.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/tools.rst b/docs/en/reference/tools.rst index 51f4573000e..d9773519141 100644 --- a/docs/en/reference/tools.rst +++ b/docs/en/reference/tools.rst @@ -476,7 +476,7 @@ To include a new command on Doctrine Console, you need to do modify the Date: Thu, 3 Dec 2015 13:15:12 +0100 Subject: [PATCH 002/877] Fixed DDC-3740 The count must return an integer, not a string --- lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 8d6ce7e7d3a..408c41e5b61 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -822,7 +822,7 @@ public function count($criteria = array()) ? $this->expandCriteriaParameters($criteria) : $this->expandParameters($criteria); - return $this->conn->executeQuery($sql, $params, $types)->fetchColumn(); + return (int) $this->conn->executeQuery($sql, $params, $types)->fetchColumn(); } /** From 744c30833739b70893f72e9352eb34825cd83ebd Mon Sep 17 00:00:00 2001 From: Bill Schaller Date: Fri, 8 Jan 2016 13:58:02 -0500 Subject: [PATCH 003/877] Remove dead code SQLWalker::walkCaseExpression --- lib/Doctrine/ORM/Query/SqlWalker.php | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 92cb3d75760..45a6293f113 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -1169,33 +1169,6 @@ public function walkJoin($join) return $sql; } - /** - * Walks down a CaseExpression AST node and generates the corresponding SQL. - * - * @param AST\CoalesceExpression|AST\NullIfExpression|AST\GeneralCaseExpression|AST\SimpleCaseExpression $expression - * - * @return string The SQL. - */ - public function walkCaseExpression($expression) - { - switch (true) { - case ($expression instanceof AST\CoalesceExpression): - return $this->walkCoalesceExpression($expression); - - case ($expression instanceof AST\NullIfExpression): - return $this->walkNullIfExpression($expression); - - case ($expression instanceof AST\GeneralCaseExpression): - return $this->walkGeneralCaseExpression($expression); - - case ($expression instanceof AST\SimpleCaseExpression): - return $this->walkSimpleCaseExpression($expression); - - default: - return ''; - } - } - /** * Walks down a CoalesceExpression AST node and generates the corresponding SQL. * From 2c70f4edf76812c01e511161f2e52c676810ab8a Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 20 Jan 2016 16:42:58 +0100 Subject: [PATCH 004/877] [DOCUMENTATION] Update tests README --- tests/README.markdown | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/tests/README.markdown b/tests/README.markdown index c1027acedd3..45e32c237ec 100644 --- a/tests/README.markdown +++ b/tests/README.markdown @@ -1,25 +1,24 @@ # Running the Doctrine 2 Testsuite -## Setting up a PHPUnit Configuration XML +To execute the Doctrine2 testsuite, you just need to execute this simple steps: -.. + * Clone the project from GitHub + * Enter the Doctrine2 folder + * Install the dependencies + * Execute the tests + + All this is (normally) done with: -## Testing Lock-Support +``` +git clone git@github.com:doctrine/doctrine2.git +cd doctrine2 +composer install +./vendor/bin/phpunit +``` -The Lock support in Doctrine 2 is tested using Gearman, which allows to run concurrent tasks in parallel. -Install Gearman with PHP as follows: +## Pre-requisites +Doctrine2 works on many database vendors; the tests can detect the presence of installed vendors, but you need at least one of those; the easier to install is SQLite. -1. Go to http://www.gearman.org and download the latest Gearman Server -2. Compile it and then call ldconfig -3. Start it up "gearmand -vvvv" -4. Install pecl/gearman by calling "gearman-beta" +If you're using a Debian-derivative Linux distribution, you can install SQLite with: -You can then go into tests/ and start up two workers: - - php Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php - -Then run the locking test-suite: - - phpunit --configuration Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php - -This can run considerable time, because it is using sleep() to test for the timing ranges of locks. \ No newline at end of file + sudo apt-get install sqlite From 1e97cf21e8e3253ade0f8cd359c6cdf1b8617ce4 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 20 Jan 2016 16:52:13 +0100 Subject: [PATCH 005/877] Reverting removal of lock tests paragraph; minor fixes --- tests/README.markdown | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/tests/README.markdown b/tests/README.markdown index 45e32c237ec..dfba6fa217b 100644 --- a/tests/README.markdown +++ b/tests/README.markdown @@ -9,16 +9,34 @@ To execute the Doctrine2 testsuite, you just need to execute this simple steps: All this is (normally) done with: -``` -git clone git@github.com:doctrine/doctrine2.git -cd doctrine2 -composer install -./vendor/bin/phpunit -``` + git clone git@github.com:doctrine/doctrine2.git + cd doctrine2 + composer install + ./vendor/bin/phpunit ## Pre-requisites Doctrine2 works on many database vendors; the tests can detect the presence of installed vendors, but you need at least one of those; the easier to install is SQLite. -If you're using a Debian-derivative Linux distribution, you can install SQLite with: +If you're using Debian, or a Debian-derivate Linux distribution (like Ubuntu), you can install SQLite with: sudo apt-get install sqlite + +## Testing Lock-Support + +The Lock support in Doctrine 2 is tested using Gearman, which allows to run concurrent tasks in parallel. +Install Gearman with PHP as follows: + +1. Go to http://www.gearman.org and download the latest Gearman Server +2. Compile it and then call ldconfig +3. Start it up "gearmand -vvvv" +4. Install pecl/gearman by calling "gearman-beta" + +You can then go into `tests/` and start up two workers: + + php Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php + +Then run the locking test-suite: + + phpunit --configuration Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php + +This can run considerable time, because it is using sleep() to test for the timing ranges of locks. From f06f383a385449093fa9342ac6ce2adcdebc357e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Machulda?= Date: Sat, 12 Mar 2016 01:24:56 +0000 Subject: [PATCH 006/877] Cleanup no longer used coveralls settings --- .coveralls.yml | 4 ---- README.md | 8 ++++---- composer.json | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) delete mode 100644 .coveralls.yml diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index b086fff7a45..00000000000 --- a/.coveralls.yml +++ /dev/null @@ -1,4 +0,0 @@ -# for php-coveralls -service_name: travis-ci -src_dir: lib -coverage_clover: build/logs/clover*.xml diff --git a/README.md b/README.md index 6c46f637c8b..96862eea214 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,9 @@ without requiring unnecessary code duplication. [Master image]: https://img.shields.io/travis/doctrine/doctrine2/master.svg?style=flat-square [Master]: https://travis-ci.org/doctrine/doctrine2 - [Master coverage image]: https://img.shields.io/coveralls/doctrine/doctrine2/master.svg?style=flat-square - [Master coverage]: https://coveralls.io/r/doctrine/doctrine2?branch=master + [Master coverage image]: https://img.shields.io/scrutinizer/coverage/g/doctrine/doctrine2/master.svg?style=flat-square + [Master coverage]: https://scrutinizer-ci.com/g/doctrine/doctrine2/?branch=master [2.5 image]: https://img.shields.io/travis/doctrine/doctrine2/2.5.svg?style=flat-square [2.5]: https://github.com/doctrine/doctrine2/tree/2.5 - [2.5 coverage image]: https://img.shields.io/coveralls/doctrine/doctrine2/2.5.svg?style=flat-square - [2.5 coverage]: https://coveralls.io/r/doctrine/doctrine2?branch=2.5 + [2.5 coverage image]: https://img.shields.io/scrutinizer/coverage/g/doctrine/doctrine2/2.5.svg?style=flat-square + [2.5 coverage]: https://scrutinizer-ci.com/g/doctrine/doctrine2/?branch=2.5 diff --git a/composer.json b/composer.json index cd1f81ade3b..ee12f777998 100644 --- a/composer.json +++ b/composer.json @@ -43,6 +43,6 @@ } }, "archive": { - "exclude": ["!vendor", "tests", "*phpunit.xml", ".travis.yml", "build.xml", "build.properties", "composer.phar", "vendor/satooshi", "lib/vendor", "*.swp", "*coveralls.yml"] + "exclude": ["!vendor", "tests", "*phpunit.xml", ".travis.yml", "build.xml", "build.properties", "composer.phar", "vendor/satooshi", "lib/vendor", "*.swp"] } } From b3df49b2f3810adbcb65812ac0dfe9369104bcc5 Mon Sep 17 00:00:00 2001 From: Aaron Merryman Date: Wed, 23 Mar 2016 18:54:20 -0700 Subject: [PATCH 007/877] Update tools.rst --- docs/en/reference/tools.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/tools.rst b/docs/en/reference/tools.rst index 51f4573000e..a601010f02d 100644 --- a/docs/en/reference/tools.rst +++ b/docs/en/reference/tools.rst @@ -205,7 +205,7 @@ tables of the current model to clean up with orphaned tables. You can also use database introspection to update your schema easily with the ``updateSchema()`` method. It will compare your existing database schema to the passed array of -``ClassMetdataInfo`` instances. +``ClassMetadataInfo`` instances. .. code-block:: php From 60e2224e6ba0c040f3394081b9663779a60a491a Mon Sep 17 00:00:00 2001 From: Guilliam Xavier Date: Thu, 24 Mar 2016 18:08:58 +0100 Subject: [PATCH 008/877] Fix PHP syntax error in composite-primary-keys.rst Add missing semicolon after `private $year` on line 12 of `Car` class example code to fix `Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting ',' or ';' in [...]/VehicleCatalogue/Model/Car.php on line 14` --- docs/en/tutorials/composite-primary-keys.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/tutorials/composite-primary-keys.rst b/docs/en/tutorials/composite-primary-keys.rst index dd4e49e04aa..b93d14d09f7 100644 --- a/docs/en/tutorials/composite-primary-keys.rst +++ b/docs/en/tutorials/composite-primary-keys.rst @@ -38,7 +38,7 @@ and year of production as primary keys: /** @Id @Column(type="string") */ private $name; /** @Id @Column(type="integer") */ - private $year + private $year; public function __construct($name, $year) { From 2f2236a1d6e558bdd4ea702afb4a359cb06d3eaa Mon Sep 17 00:00:00 2001 From: Andrei Sozonov Date: Fri, 1 Apr 2016 15:54:17 +0300 Subject: [PATCH 009/877] fix typo --- lib/Doctrine/ORM/Query/Expr/OrderBy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Query/Expr/OrderBy.php b/lib/Doctrine/ORM/Query/Expr/OrderBy.php index 932548bd603..291be6131f6 100644 --- a/lib/Doctrine/ORM/Query/Expr/OrderBy.php +++ b/lib/Doctrine/ORM/Query/Expr/OrderBy.php @@ -97,7 +97,7 @@ public function getParts() /** * @return string */ - public function __tostring() + public function __toString() { return $this->preSeparator . implode($this->separator, $this->parts) . $this->postSeparator; } From 165722cf05ba4b7dad8ad4caa28c1f99af8d10ac Mon Sep 17 00:00:00 2001 From: iBet7o Date: Sun, 17 Apr 2016 17:31:48 -0500 Subject: [PATCH 010/877] Fix bug: orderBy documentation --- docs/en/reference/query-builder.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/en/reference/query-builder.rst b/docs/en/reference/query-builder.rst index 57eee179f63..9d90f798ded 100644 --- a/docs/en/reference/query-builder.rst +++ b/docs/en/reference/query-builder.rst @@ -113,7 +113,7 @@ suggested standard way to build queries: $qb->expr()->eq('u.id', '?1'), $qb->expr()->like('u.nickname', '?2') )) - ->orderBy('u.surname', 'ASC')); + ->orderBy('u.surname', 'ASC'); Here is a complete list of helper methods available in ``QueryBuilder``: @@ -126,7 +126,7 @@ Here is a complete list of helper methods available in ``QueryBuilder``: // Example - $qb->select(array('u', 'p')) // Example - $qb->select($qb->expr()->select('u', 'p')) public function select($select = null); - + // addSelect does not override previous calls to select // // Example - $qb->select('u'); @@ -562,4 +562,3 @@ same query of example 6 written using Of course this is the hardest way to build a DQL query in Doctrine. To simplify some of these efforts, we introduce what we call as ``Expr`` helper class. - From c5283eea8756c5ffd6dc311d8ccc9cafa5d69717 Mon Sep 17 00:00:00 2001 From: Maks Rafalko Date: Sun, 1 May 2016 15:03:40 +0300 Subject: [PATCH 011/877] Fix typo `cached` -> `catched` --- docs/en/cookbook/validation-of-entities.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/cookbook/validation-of-entities.rst b/docs/en/cookbook/validation-of-entities.rst index fb0254417b0..d49daa84f89 100644 --- a/docs/en/cookbook/validation-of-entities.rst +++ b/docs/en/cookbook/validation-of-entities.rst @@ -89,7 +89,7 @@ events for one method, this will happen before Beta 1 though. Now validation is performed whenever you call ``EntityManager#persist($order)`` or when you call ``EntityManager#flush()`` and an order is about to be updated. Any -Exception that happens in the lifecycle callbacks will be cached by +Exception that happens in the lifecycle callbacks will be catched by the EntityManager and the current transaction is rolled back. Of course you can do any type of primitive checks, not null, From fafb8166f40585e0c186fdb06f228d4a83e4b1ce Mon Sep 17 00:00:00 2001 From: ismail BASKIN Date: Sun, 22 May 2016 19:36:15 +0300 Subject: [PATCH 012/877] Fix custom-id-generator class attribute type custom-id-generator tag's attribute type must be FQCN. But NMTOKEN type doesn't support backslash character. --- doctrine-mapping.xsd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doctrine-mapping.xsd b/doctrine-mapping.xsd index aef47b2a66a..bb8624190e1 100644 --- a/doctrine-mapping.xsd +++ b/doctrine-mapping.xsd @@ -412,7 +412,7 @@ - + From 7ef3e3a60ca3bf0a7cad0cd00da9052ef5c95793 Mon Sep 17 00:00:00 2001 From: Michal Zuber Date: Wed, 22 Jun 2016 08:50:36 +0200 Subject: [PATCH 013/877] Check for Xcache from INI setting On a shared webhosting the Xcache module is loaded, but it can be disabled with .htaccess `php_flag xcache.cacher Off` which causes issues. --- lib/Doctrine/ORM/Tools/Setup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Tools/Setup.php b/lib/Doctrine/ORM/Tools/Setup.php index 79d4670ad0f..d0cfe3f3bfe 100644 --- a/lib/Doctrine/ORM/Tools/Setup.php +++ b/lib/Doctrine/ORM/Tools/Setup.php @@ -126,7 +126,7 @@ public static function createConfiguration($isDevMode = false, $proxyDir = null, if ($isDevMode === false && $cache === null) { if (extension_loaded('apc')) { $cache = new \Doctrine\Common\Cache\ApcCache(); - } elseif (extension_loaded('xcache')) { + } elseif (ini_get('xcache.cacher')) { $cache = new \Doctrine\Common\Cache\XcacheCache(); } elseif (extension_loaded('memcache')) { $memcache = new \Memcache(); From 12789ee6cacc2cad32c9b244e8e41bef8b7b3529 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 19:27:49 +0200 Subject: [PATCH 014/877] Basic tests around `addToIdentityMap` with valid string identifiers (empty string allowed) --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 77 +++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 9b0c6a8f5f4..51823aa276c 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -363,6 +363,43 @@ public function invalidAssociationValuesDataProvider() [new ArrayCollection()], ]; } + + /** + * @dataProvider entitiesWithValidIdentifiersProvider + * + * @param object $entity + * + * @return void + */ + public function testAddToIdentityMapValidIdentifiers($entity) + { + $this->_unitOfWork->registerManaged( + $entity, + $this->_emMock->getClassMetadata(get_class($entity))->getIdentifierValues($entity), + [] + ); + $this->_unitOfWork->addToIdentityMap($entity); + + self::assertInternalType('string', $this->_unitOfWork->getEntityIdentifier($entity)); + // note: cloning to avoid lookup by spl_object_hash() + self::assertTrue($this->_unitOfWork->isInIdentityMap(clone $entity)); + } + + public function entitiesWithValidIdentifiersProvider() + { + $emptyString = new EntityWithStringIdentifier(); + + $emptyString->id = ''; + + $nonEmptyString = new EntityWithStringIdentifier(); + + $nonEmptyString->id = uniqid('', true); + + return [ + 'empty string, single field' => [$emptyString], + 'non-empty string, single field' => [$nonEmptyString], + ]; + } } /** @@ -469,3 +506,43 @@ class VersionedAssignedIdentifierEntity */ public $version; } + +/** @Entity */ +class EntityWithStringIdentifier +{ + /** + * @Id @Column(type="string") + * + * @var string|null + */ + public $id; +} + +/** @Entity */ +class EntityWithBooleanIdentifier +{ + /** + * @Id @Column(type="boolean") + * + * @var bool|null + */ + public $id; +} + +/** @Entity */ +class EntityWithCompositeStringIdentifier +{ + /** + * @Id @Column(type="string") + * + * @var string|null + */ + public $id1; + + /** + * @Id @Column(type="string") + * + * @var string|null + */ + public $id2; +} From 549bfe127c79266f64b6534ffed81799570760f3 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 19:34:24 +0200 Subject: [PATCH 015/877] Correcting test case: expecting identifier hashes to support empty strings --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 51823aa276c..b0b38b9e2fc 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -368,10 +368,11 @@ public function invalidAssociationValuesDataProvider() * @dataProvider entitiesWithValidIdentifiersProvider * * @param object $entity + * @param string $idHash * * @return void */ - public function testAddToIdentityMapValidIdentifiers($entity) + public function testAddToIdentityMapValidIdentifiers($entity, $idHash) { $this->_unitOfWork->registerManaged( $entity, @@ -380,9 +381,8 @@ public function testAddToIdentityMapValidIdentifiers($entity) ); $this->_unitOfWork->addToIdentityMap($entity); - self::assertInternalType('string', $this->_unitOfWork->getEntityIdentifier($entity)); // note: cloning to avoid lookup by spl_object_hash() - self::assertTrue($this->_unitOfWork->isInIdentityMap(clone $entity)); + self::assertSame($entity, $this->_unitOfWork->getByIdHash($idHash, get_class($entity))); } public function entitiesWithValidIdentifiersProvider() @@ -395,9 +395,15 @@ public function entitiesWithValidIdentifiersProvider() $nonEmptyString->id = uniqid('', true); + $emptyStrings = new EntityWithCompositeStringIdentifier(); + + $emptyStrings->id1 = ''; + $emptyStrings->id2 = ''; + return [ - 'empty string, single field' => [$emptyString], - 'non-empty string, single field' => [$nonEmptyString], + 'empty string, single field' => [$emptyString, ''], + 'non-empty string, single field' => [$nonEmptyString, $nonEmptyString->id], + 'empty strings, two fields' => [$emptyStrings, ' '], ]; } } From 29d9f344e88e9281345c799188919d5764c9217a Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 19:35:39 +0200 Subject: [PATCH 016/877] Non-empty composite key identifiers should also be supported --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index b0b38b9e2fc..6b5f63a6fca 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -393,17 +393,23 @@ public function entitiesWithValidIdentifiersProvider() $nonEmptyString = new EntityWithStringIdentifier(); - $nonEmptyString->id = uniqid('', true); + $nonEmptyString->id = uniqid('id', true); $emptyStrings = new EntityWithCompositeStringIdentifier(); $emptyStrings->id1 = ''; $emptyStrings->id2 = ''; + $nonEmptyStrings = new EntityWithCompositeStringIdentifier(); + + $nonEmptyStrings->id1 = uniqid('id1', true); + $nonEmptyStrings->id2 = uniqid('id2', true); + return [ 'empty string, single field' => [$emptyString, ''], 'non-empty string, single field' => [$nonEmptyString, $nonEmptyString->id], 'empty strings, two fields' => [$emptyStrings, ' '], + 'non-empty strings, two fields' => [$nonEmptyStrings, $nonEmptyStrings->id1 . ' ' . $nonEmptyStrings->id2], ]; } } From aa1fda6d5fb940b2ad888e40c13c30a52f69a3a8 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 19:38:48 +0200 Subject: [PATCH 017/877] Checking for boolean true/false identifiers --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 6b5f63a6fca..b26fce19f95 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -405,11 +405,21 @@ public function entitiesWithValidIdentifiersProvider() $nonEmptyStrings->id1 = uniqid('id1', true); $nonEmptyStrings->id2 = uniqid('id2', true); + $booleanTrue = new EntityWithBooleanIdentifier(); + + $booleanTrue->id = true; + + $booleanFalse = new EntityWithBooleanIdentifier(); + + $booleanFalse->id = false; + return [ 'empty string, single field' => [$emptyString, ''], 'non-empty string, single field' => [$nonEmptyString, $nonEmptyString->id], 'empty strings, two fields' => [$emptyStrings, ' '], 'non-empty strings, two fields' => [$nonEmptyStrings, $nonEmptyStrings->id1 . ' ' . $nonEmptyStrings->id2], + 'boolean true' => [$booleanTrue, '1'], + 'boolean false' => [$booleanTrue, ''], ]; } } From da7582d32976edd151ea76dd05fcee05067d9e41 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 19:43:03 +0200 Subject: [PATCH 018/877] Typo fix: s/$booleanTrue/$booleanFalse (C&P mistake) --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index b26fce19f95..67121e1a4fa 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -419,7 +419,7 @@ public function entitiesWithValidIdentifiersProvider() 'empty strings, two fields' => [$emptyStrings, ' '], 'non-empty strings, two fields' => [$nonEmptyStrings, $nonEmptyStrings->id1 . ' ' . $nonEmptyStrings->id2], 'boolean true' => [$booleanTrue, '1'], - 'boolean false' => [$booleanTrue, ''], + 'boolean false' => [$booleanFalse, ''], ]; } } From 9abccba1093bbefbd4b08e676b74265ceaa8dbfa Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 19:58:43 +0200 Subject: [PATCH 019/877] When invalid (null) identifiers are provided, an exception should be thrown --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 56 +++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 67121e1a4fa..e94a187d716 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -6,6 +6,7 @@ use Doctrine\Common\NotifyPropertyChanged; use Doctrine\Common\PropertyChangedListener; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\ORMInvalidArgumentException; use Doctrine\ORM\UnitOfWork; use Doctrine\Tests\Mocks\ConnectionMock; use Doctrine\Tests\Mocks\DriverMock; @@ -422,6 +423,61 @@ public function entitiesWithValidIdentifiersProvider() 'boolean false' => [$booleanFalse, ''], ]; } + + /** + * @dataProvider entitiesWithInvalidIdentifiersProvider + * + * @param object $entity + * + * @return void + */ + public function testAddToIdentityMapInvalidIdentifiers($entity) + { + $this->_unitOfWork->registerManaged( + $entity, + $this->_emMock->getClassMetadata(get_class($entity))->getIdentifierValues($entity), + [] + ); + + $this->expectException(ORMInvalidArgumentException::class); + + $this->_unitOfWork->addToIdentityMap($entity); + } + + + public function entitiesWithInvalidIdentifiersProvider() + { + $emptyString = new EntityWithStringIdentifier(); + + $emptyString->id = ''; + + $nonEmptyString = new EntityWithStringIdentifier(); + + $nonEmptyString->id = uniqid('id', true); + + $emptyStrings = new EntityWithCompositeStringIdentifier(); + + $emptyStrings->id1 = ''; + $emptyStrings->id2 = ''; + + $nonEmptyStrings = new EntityWithCompositeStringIdentifier(); + + $nonEmptyStrings->id1 = uniqid('id1', true); + $nonEmptyStrings->id2 = uniqid('id2', true); + + $booleanTrue = new EntityWithBooleanIdentifier(); + + $booleanTrue->id = true; + + $booleanFalse = new EntityWithBooleanIdentifier(); + + $booleanFalse->id = false; + + return [ + 'null string, single field' => [new EntityWithStringIdentifier()], + 'null strings, two fieldds' => [new EntityWithCompositeStringIdentifier()], + ]; + } } /** From 5b8b548bd4b91118ace8da96c6e01e5ed8aee445 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 20:08:24 +0200 Subject: [PATCH 020/877] When invalid (null) identifiers are provided, an exception should be thrown --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 32 ++++++--------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index e94a187d716..cab05d56d82 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -447,35 +447,19 @@ public function testAddToIdentityMapInvalidIdentifiers($entity) public function entitiesWithInvalidIdentifiersProvider() { - $emptyString = new EntityWithStringIdentifier(); - - $emptyString->id = ''; - - $nonEmptyString = new EntityWithStringIdentifier(); - - $nonEmptyString->id = uniqid('id', true); - - $emptyStrings = new EntityWithCompositeStringIdentifier(); - - $emptyStrings->id1 = ''; - $emptyStrings->id2 = ''; - - $nonEmptyStrings = new EntityWithCompositeStringIdentifier(); + $firstNullString = new EntityWithCompositeStringIdentifier(); - $nonEmptyStrings->id1 = uniqid('id1', true); - $nonEmptyStrings->id2 = uniqid('id2', true); + $firstNullString->id2 = uniqid('id2', true); - $booleanTrue = new EntityWithBooleanIdentifier(); + $secondNullString = new EntityWithCompositeStringIdentifier(); - $booleanTrue->id = true; - - $booleanFalse = new EntityWithBooleanIdentifier(); - - $booleanFalse->id = false; + $secondNullString->id1 = uniqid('id1', true); return [ - 'null string, single field' => [new EntityWithStringIdentifier()], - 'null strings, two fieldds' => [new EntityWithCompositeStringIdentifier()], + 'null string, single field' => [new EntityWithStringIdentifier()], + 'null strings, two fields' => [new EntityWithCompositeStringIdentifier()], + 'first null string, two fields' => [$firstNullString], + 'second null string, two fields' => [$secondNullString], ]; } } From 282917426747fcb11d7beaf669af0eb571266402 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 20:28:21 +0200 Subject: [PATCH 021/877] Simplified test: invalid entities must make it in the `UnitOfWork` manually, via `registerManaged` --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 25 +++++++-------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index cab05d56d82..4ecbdc3e0b2 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -375,11 +375,7 @@ public function invalidAssociationValuesDataProvider() */ public function testAddToIdentityMapValidIdentifiers($entity, $idHash) { - $this->_unitOfWork->registerManaged( - $entity, - $this->_emMock->getClassMetadata(get_class($entity))->getIdentifierValues($entity), - [] - ); + $this->_unitOfWork->persist($entity); $this->_unitOfWork->addToIdentityMap($entity); // note: cloning to avoid lookup by spl_object_hash() @@ -428,20 +424,15 @@ public function entitiesWithValidIdentifiersProvider() * @dataProvider entitiesWithInvalidIdentifiersProvider * * @param object $entity + * @param array $identifier * * @return void */ - public function testAddToIdentityMapInvalidIdentifiers($entity) + public function testAddToIdentityMapInvalidIdentifiers($entity, array $identifier) { - $this->_unitOfWork->registerManaged( - $entity, - $this->_emMock->getClassMetadata(get_class($entity))->getIdentifierValues($entity), - [] - ); - $this->expectException(ORMInvalidArgumentException::class); - $this->_unitOfWork->addToIdentityMap($entity); + $this->_unitOfWork->registerManaged($entity, $identifier, []); } @@ -456,10 +447,10 @@ public function entitiesWithInvalidIdentifiersProvider() $secondNullString->id1 = uniqid('id1', true); return [ - 'null string, single field' => [new EntityWithStringIdentifier()], - 'null strings, two fields' => [new EntityWithCompositeStringIdentifier()], - 'first null string, two fields' => [$firstNullString], - 'second null string, two fields' => [$secondNullString], + 'null string, single field' => [new EntityWithStringIdentifier(), ['id' => null]], + 'null strings, two fields' => [new EntityWithCompositeStringIdentifier(), ['id1' => null, 'id2' => null]], + 'first null string, two fields' => [$firstNullString, ['id1' => null, 'id2' => $firstNullString->id2]], + 'second null string, two fields' => [$secondNullString, ['id1' => $secondNullString->id1, 'id2' => null]], ]; } } From 1cb8d790b64f542406a576b878d67abe284e7275 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 20:29:00 +0200 Subject: [PATCH 022/877] Disallowing `null` as part of the entity identifier --- lib/Doctrine/ORM/UnitOfWork.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index c54d97a0b2d..23bee140127 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1398,12 +1398,13 @@ public function isEntityScheduled($entity) public function addToIdentityMap($entity) { $classMetadata = $this->em->getClassMetadata(get_class($entity)); - $idHash = implode(' ', $this->entityIdentifiers[spl_object_hash($entity)]); + $identifier = $this->entityIdentifiers[spl_object_hash($entity)]; - if ($idHash === '') { + if (in_array(null, $identifier, true)) { throw ORMInvalidArgumentException::entityWithoutIdentity($classMetadata->name, $entity); } + $idHash = implode(' ', $identifier); $className = $classMetadata->rootEntityName; if (isset($this->identityMap[$className][$idHash])) { From 7544934158eabe248986551b3d25eabacecbcc9c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 20:39:52 +0200 Subject: [PATCH 023/877] Removing note that is not valid anymore --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 4ecbdc3e0b2..6ccaa51e4eb 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -378,7 +378,6 @@ public function testAddToIdentityMapValidIdentifiers($entity, $idHash) $this->_unitOfWork->persist($entity); $this->_unitOfWork->addToIdentityMap($entity); - // note: cloning to avoid lookup by spl_object_hash() self::assertSame($entity, $this->_unitOfWork->getByIdHash($idHash, get_class($entity))); } From 0d82128b2e59c9142f1297bae13ed616405996ee Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 20:57:02 +0200 Subject: [PATCH 024/877] Registering a managed entity with an empty identifier is to be disallowed --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 6ccaa51e4eb..6a2c882e84e 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -419,6 +419,13 @@ public function entitiesWithValidIdentifiersProvider() ]; } + public function testRegisteringAManagedInstanceRequiresANonEmptyIdentifier() + { + $this->expectException(ORMInvalidArgumentException::class); + + $this->_unitOfWork->registerManaged(new EntityWithBooleanIdentifier(), [], []); + } + /** * @dataProvider entitiesWithInvalidIdentifiersProvider * From dbcdc1d42a53dd3fdec33c976cd5e73d1d76de8f Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 20:57:49 +0200 Subject: [PATCH 025/877] Empty identifiers must be disallowed --- lib/Doctrine/ORM/UnitOfWork.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 23bee140127..7ac24cc6028 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1400,7 +1400,7 @@ public function addToIdentityMap($entity) $classMetadata = $this->em->getClassMetadata(get_class($entity)); $identifier = $this->entityIdentifiers[spl_object_hash($entity)]; - if (in_array(null, $identifier, true)) { + if (empty($identifier) || in_array(null, $identifier, true)) { throw ORMInvalidArgumentException::entityWithoutIdentity($classMetadata->name, $entity); } From 5d12593e70752af2ca23baafed83dec3b0d17690 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 21:29:10 +0200 Subject: [PATCH 026/877] Rewrote `ManyToOne` SLC tests to not rely on multi-level auto-generated identifiers Background: Test relied on an `A->B->C` association: * `A#id` being `B` * `B#id` being `C` * `C#id` being an auto-generated identifier (post-insert) This cannot work, because it breaks the UnitOfWork's identity map. Specifically, no entries for `A` and `B` can exist in the identity map until `C` entries are persisted (post-insert). That means that the identifier generator for `A` and `B` should not be an "assigned" generator, but should instead be a post-insert generator waiting for other entities to be persisted. We cannot fix this in ORM 2.x, but we'll need to invent something for 3.x in order to fix that (directed graph, or caching the order of operations in the metadata graph). --- tests/Doctrine/Tests/Models/Cache/Action.php | 9 ++------- .../Doctrine/Tests/Models/Cache/ComplexAction.php | 4 ++-- tests/Doctrine/Tests/Models/Cache/Token.php | 6 +++--- .../Functional/SecondLevelCacheManyToOneTest.php | 14 +++++++------- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/tests/Doctrine/Tests/Models/Cache/Action.php b/tests/Doctrine/Tests/Models/Cache/Action.php index 25609abedb5..d23ab494bfb 100644 --- a/tests/Doctrine/Tests/Models/Cache/Action.php +++ b/tests/Doctrine/Tests/Models/Cache/Action.php @@ -14,13 +14,8 @@ class Action /** * @Id - * @GeneratedValue - * @Column(type="integer") - */ - public $id; - - /** - * @Column + * @Column(type="string") + * @GeneratedValue(strategy="NONE") */ public $name; diff --git a/tests/Doctrine/Tests/Models/Cache/ComplexAction.php b/tests/Doctrine/Tests/Models/Cache/ComplexAction.php index 46d0414d3a2..5f5faf6ddd0 100644 --- a/tests/Doctrine/Tests/Models/Cache/ComplexAction.php +++ b/tests/Doctrine/Tests/Models/Cache/ComplexAction.php @@ -20,14 +20,14 @@ class ComplexAction /** * @Id * @OneToOne(targetEntity="Action", cascade={"persist", "remove"}) - * @JoinColumn(name="action1_id", referencedColumnName="id") + * @JoinColumn(name="action1_name", referencedColumnName="name") */ public $action1; /** * @Id * @OneToOne(targetEntity="Action", cascade={"persist", "remove"}) - * @JoinColumn(name="action2_id", referencedColumnName="id") + * @JoinColumn(name="action2_name", referencedColumnName="name") */ public $action2; diff --git a/tests/Doctrine/Tests/Models/Cache/Token.php b/tests/Doctrine/Tests/Models/Cache/Token.php index f6c712e3624..ba3fdb1821a 100644 --- a/tests/Doctrine/Tests/Models/Cache/Token.php +++ b/tests/Doctrine/Tests/Models/Cache/Token.php @@ -36,7 +36,7 @@ class Token /** * @ManyToOne(targetEntity="Action", cascade={"persist", "remove"}, inversedBy="tokens") - * @JoinColumn(name="action_id", referencedColumnName="id") + * @JoinColumn(name="action_name", referencedColumnName="name") * @var array */ public $action; @@ -44,8 +44,8 @@ class Token /** * @ManyToOne(targetEntity="ComplexAction", cascade={"persist", "remove"}, inversedBy="tokens") * @JoinColumns({ - * @JoinColumn(name="complex_action1_id", referencedColumnName="action1_id"), - * @JoinColumn(name="complex_action2_id", referencedColumnName="action2_id") + * @JoinColumn(name="complex_action1_name", referencedColumnName="action1_name"), + * @JoinColumn(name="complex_action2_name", referencedColumnName="action2_name") * }) * @var ComplexAction */ diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php index 00fa409736f..57215f8e000 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php @@ -193,7 +193,7 @@ public function testPutAndLoadNonCacheableManyToOne() $this->_em->clear(); $this->assertTrue($this->cache->containsEntity(Token::CLASSNAME, $token->token)); - $this->assertFalse($this->cache->containsEntity(Token::CLASSNAME, $action->id)); + $this->assertFalse($this->cache->containsEntity(Token::CLASSNAME, $action->name)); $queryCount = $this->getCurrentQueryCount(); $entity = $this->_em->find(Token::CLASSNAME, $token->token); @@ -204,7 +204,7 @@ public function testPutAndLoadNonCacheableManyToOne() $this->assertInstanceOf(Action::CLASSNAME, $entity->getAction()); $this->assertEquals('exec', $entity->getAction()->name); - $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); + $this->assertEquals($queryCount, $this->getCurrentQueryCount()); } public function testPutAndLoadNonCacheableCompositeManyToOne() @@ -231,9 +231,9 @@ public function testPutAndLoadNonCacheableCompositeManyToOne() $this->_em->clear(); $this->assertTrue($this->cache->containsEntity(Token::CLASSNAME, $token->token)); - $this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action1->id)); - $this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action2->id)); - $this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action3->id)); + $this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action1->name)); + $this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action2->name)); + $this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action3->name)); $queryCount = $this->getCurrentQueryCount(); /** @@ -255,8 +255,8 @@ public function testPutAndLoadNonCacheableCompositeManyToOne() $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); $this->assertEquals('login', $entity->getComplexAction()->getAction1()->name); - $this->assertEquals($queryCount + 2, $this->getCurrentQueryCount()); + $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); $this->assertEquals('rememberme', $entity->getComplexAction()->getAction2()->name); - $this->assertEquals($queryCount + 3, $this->getCurrentQueryCount()); + $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); } } \ No newline at end of file From d330da898fcce3696f760a3086d38c9bae56110b Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 22:24:37 +0200 Subject: [PATCH 027/877] Correcting order of deletes: `cache_token` relies on `cache_complex_action` --- tests/Doctrine/Tests/OrmFunctionalTestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index d18b9496571..6e17a92ad52 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -460,8 +460,8 @@ protected function tearDown() $conn->executeUpdate('DELETE FROM cache_state'); $conn->executeUpdate('DELETE FROM cache_country'); $conn->executeUpdate('DELETE FROM cache_login'); - $conn->executeUpdate('DELETE FROM cache_complex_action'); $conn->executeUpdate('DELETE FROM cache_token'); + $conn->executeUpdate('DELETE FROM cache_complex_action'); $conn->executeUpdate('DELETE FROM cache_action'); $conn->executeUpdate('DELETE FROM cache_client'); } From 44feacd32764207e2394d9f42e1de57f3571b79d Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 7 Jul 2016 23:46:09 +0200 Subject: [PATCH 028/877] Corrected SLC test expected query count: since the identity map is now consistently hashing identifiers --- tests/Doctrine/Tests/ORM/Performance/SecondLevelCacheTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Performance/SecondLevelCacheTest.php b/tests/Doctrine/Tests/ORM/Performance/SecondLevelCacheTest.php index 61b9c7ce77e..774945c5aa6 100644 --- a/tests/Doctrine/Tests/ORM/Performance/SecondLevelCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/SecondLevelCacheTest.php @@ -101,7 +101,7 @@ public function testFindEntityOneToManyWithCache() $this->findEntityOneToMany($em, __FUNCTION__); - $this->assertEquals(487, $this->countQuery($em)); + $this->assertEquals(472, $this->countQuery($em)); } public function testQueryEntityWithoutCache() From da43aa2d49cf48dcd9ee740f56c8150e1513576f Mon Sep 17 00:00:00 2001 From: Greg Bell Date: Tue, 12 Jul 2016 16:05:20 +1000 Subject: [PATCH 029/877] Clarify language regarding ArrayCollections. See https://groups.google.com/forum/#!topic/doctrine-user/yJ8ABqBP5mI --- docs/en/tutorials/getting-started.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/en/tutorials/getting-started.rst b/docs/en/tutorials/getting-started.rst index 6b5cb72942e..ef473431741 100644 --- a/docs/en/tutorials/getting-started.rst +++ b/docs/en/tutorials/getting-started.rst @@ -616,12 +616,12 @@ domain model to match the requirements: } } -Whenever an entity is recreated from the database, an Collection -implementation of the type Doctrine is injected into your entity -instead of an array. Compared to the ArrayCollection this -implementation helps the Doctrine ORM understand the changes that -have happened to the collection which are noteworthy for -persistence. +You use Doctrine's ArrayCollections in your Doctrine models, rather +than plain PHP arrays, so that Doctrine can watch what happens with +them and act appropriately. Note that if you dump your entities, +you'll see a "PersistentCollection" in place of your ArrayCollection, +which is just an +internal Doctrine class with the same interface. .. warning:: From b785a8dc02c4f5961cbc3d017ca2ae28542d8e1b Mon Sep 17 00:00:00 2001 From: Erik van Velzen Date: Mon, 18 Jul 2016 18:16:34 +0200 Subject: [PATCH 030/877] Add @CustomIdGenerator to documentation --- docs/en/reference/annotations-reference.rst | 25 +++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/en/reference/annotations-reference.rst b/docs/en/reference/annotations-reference.rst index 19e9e8b70ba..7b59aa678ab 100644 --- a/docs/en/reference/annotations-reference.rst +++ b/docs/en/reference/annotations-reference.rst @@ -37,6 +37,7 @@ Index - :ref:`@ColumnResult ` - :ref:`@Cache ` - :ref:`@ChangeTrackingPolicy ` +- :ref:`@CustomIdGenerator ` - :ref:`@DiscriminatorColumn ` - :ref:`@DiscriminatorMap ` - :ref:`@Embeddable ` @@ -233,6 +234,30 @@ Example: */ class User {} +.. _annref_customidgenerator: + +@CustomIdGenerator +~~~~~~~~~~~~~~~~~~~~~ + +This annotations allows you to specify a user-provided class to generate identifiers. This annotation only works when both :ref:`@Id ` and :ref:`@GeneratedValue(strategy="CUSTOM") ` are specified. + +Required attributes: + +- **class**: name of the class which should extend Doctrine\ORM\Id\AbstractIdGenerator + +Example: + +.. code-block:: php + + Date: Thu, 21 Jul 2016 13:52:27 +1200 Subject: [PATCH 031/877] missing $cme under reverse eng code sample --- docs/en/reference/tools.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/reference/tools.rst b/docs/en/reference/tools.rst index 51f4573000e..f97e6aac737 100644 --- a/docs/en/reference/tools.rst +++ b/docs/en/reference/tools.rst @@ -395,6 +395,7 @@ to yml: .. code-block:: php getExporter('yml', '/path/to/export/yml'); $exporter->setMetadata($metadata); $exporter->export(); From 718ee42e8ed03712df40bcf05f1c27e0ec6b2f41 Mon Sep 17 00:00:00 2001 From: Michal-sk Date: Thu, 21 Jul 2016 07:39:07 +0200 Subject: [PATCH 032/877] Update association-mapping.rst Added pointers on how to interpret the method names. This helped me to quicker grasp the concept of the Relations and there methods. Added a @var annotation to the `Collection` interface to make it clear that the `$groups` is a child of the `Collection` interface. --- docs/en/reference/association-mapping.rst | 26 ++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/en/reference/association-mapping.rst b/docs/en/reference/association-mapping.rst index a1a9f83a81a..d2b2cced7c3 100644 --- a/docs/en/reference/association-mapping.rst +++ b/docs/en/reference/association-mapping.rst @@ -16,6 +16,8 @@ This chapter is split into three different sections. - :ref:`association_mapping_defaults` are explained that simplify the use-case examples. - :ref:`collections` are introduced that contain entities in associations. +One tip for working with relations is to read the relation from left to right, where the left word referece to the current class. + To gain a full understanding of associations you should also read about :doc:`owning and inverse sides of associations ` @@ -35,6 +37,7 @@ A many-to-one association is the most common association between objects. // ... /** + * Many Users have One Address. * @ManyToOne(targetEntity="Address") * @JoinColumn(name="address_id", referencedColumnName="id") */ @@ -111,6 +114,7 @@ direction only. // ... /** + * One Product has One Shipping. * @OneToOne(targetEntity="Shipping") * @JoinColumn(name="shipping_id", referencedColumnName="id") */ @@ -183,6 +187,7 @@ it is bidirectional. // ... /** + * One Customer has One Cart. * @OneToOne(targetEntity="Cart", mappedBy="customer") */ private $cart; @@ -196,6 +201,7 @@ it is bidirectional. // ... /** + * One Cart has One Customer. * @OneToOne(targetEntity="Customer", inversedBy="cart") * @JoinColumn(name="customer_id", referencedColumnName="id") */ @@ -269,6 +275,7 @@ below. // ... /** + * One Student has One Student. * @OneToOne(targetEntity="Student") * @JoinColumn(name="mentor_id", referencedColumnName="id") */ @@ -316,6 +323,7 @@ association. { // ... /** + * One Product has Many Features. * @OneToMany(targetEntity="Feature", mappedBy="product") */ private $features; @@ -331,6 +339,7 @@ association. { // ... /** + * Many Features have One Product. * @ManyToOne(targetEntity="Product", inversedBy="features") * @JoinColumn(name="product_id", referencedColumnName="id") */ @@ -408,6 +417,7 @@ The following example sets up such a unidirectional one-to-many association: // ... /** + * Many User have Many Phonenumbers. * @ManyToMany(targetEntity="Phonenumber") * @JoinTable(name="users_phonenumbers", * joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")}, @@ -508,11 +518,13 @@ database perspective is known as an adjacency list approach. { // ... /** + * One Category has Many Categories. * @OneToMany(targetEntity="Category", mappedBy="parent") */ private $children; /** + * Many Categories have One Category. * @ManyToOne(targetEntity="Category", inversedBy="children") * @JoinColumn(name="parent_id", referencedColumnName="id") */ @@ -578,6 +590,7 @@ entities: // ... /** + * Many Users have Many Groups. * @ManyToMany(targetEntity="Group") * @JoinTable(name="users_groups", * joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")}, @@ -678,6 +691,7 @@ one is bidirectional. // ... /** + * Many Users have Many Groups. * @ManyToMany(targetEntity="Group", inversedBy="users") * @JoinTable(name="users_groups") */ @@ -695,6 +709,7 @@ one is bidirectional. { // ... /** + * Many Groups have Many Users. * @ManyToMany(targetEntity="User", mappedBy="groups") */ private $users; @@ -825,11 +840,13 @@ field named ``$friendsWithMe`` and ``$myFriends``. // ... /** + * Many Users have Many Users. * @ManyToMany(targetEntity="User", mappedBy="myFriends") */ private $friendsWithMe; /** + * Many Users have many Users. * @ManyToMany(targetEntity="User", inversedBy="friendsWithMe") * @JoinTable(name="friends", * joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")}, @@ -911,6 +928,7 @@ mapping: Date: Thu, 21 Jul 2016 13:41:21 +0200 Subject: [PATCH 033/877] Update association-mapping.rst Added spoken word examples of the relationship methods --- docs/en/reference/association-mapping.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/en/reference/association-mapping.rst b/docs/en/reference/association-mapping.rst index d2b2cced7c3..1b58baa0db2 100644 --- a/docs/en/reference/association-mapping.rst +++ b/docs/en/reference/association-mapping.rst @@ -16,7 +16,13 @@ This chapter is split into three different sections. - :ref:`association_mapping_defaults` are explained that simplify the use-case examples. - :ref:`collections` are introduced that contain entities in associations. -One tip for working with relations is to read the relation from left to right, where the left word referece to the current class. +One tip for working with relations is to read the relation from left to right, where the left word refers to the current Entity. For example: + +- OneToMany - One instance of the current Entity has Many instances (references) to the refered Entity. +- ManyToOne - Many instances of the current Entity refer to One instance of the refered Entity. +- OneToOne - One instance of the current Entity refers to One instance of the refered Entity. + +See below for all the possible relations. To gain a full understanding of associations you should also read about :doc:`owning and inverse sides of associations ` From eb62ae59335f5409a8980d67e1d13e0f482c10b5 Mon Sep 17 00:00:00 2001 From: giginos Date: Fri, 12 Aug 2016 16:26:08 +0200 Subject: [PATCH 034/877] Wrong return type of getResult() @see https://github.com/doctrine/doctrine2/issues/5971 --- lib/Doctrine/ORM/AbstractQuery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 0b2b0663c09..581a99c429a 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -718,7 +718,7 @@ public function getHydrationMode() * * @param int $hydrationMode * - * @return array + * @return mixed */ public function getResult($hydrationMode = self::HYDRATE_OBJECT) { From 75f44008d67b1d7237a2a7a3d742a98e0665ca04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Potk=C3=A1ny?= Date: Tue, 16 Aug 2016 01:31:46 +0200 Subject: [PATCH 035/877] Remove unneeded ternary operator from Query::contains --- lib/Doctrine/ORM/Query.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index a7c6f852de7..e3f23cc6b47 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -561,7 +561,7 @@ public function getState() */ public function contains($dql) { - return stripos($this->getDQL(), $dql) === false ? false : true; + return stripos($this->getDQL(), $dql) !== false; } /** From 0da6669fac1d91e2489958cc47ea1a9e73d3a66a Mon Sep 17 00:00:00 2001 From: Carl Vuorinen Date: Sat, 3 Sep 2016 23:52:34 +0300 Subject: [PATCH 036/877] Fix functional test query logger DebugStack starts queries array from index 1 rather than 0 so the last query was never printed. Also array params caused an 'Array to string conversion' error --- tests/Doctrine/Tests/OrmFunctionalTestCase.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 6e17a92ad52..907c006173b 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -750,10 +750,10 @@ protected function onNotSuccessfulTest($e) if(isset($this->_sqlLoggerStack->queries) && count($this->_sqlLoggerStack->queries)) { $queries = ""; - for($i = count($this->_sqlLoggerStack->queries)-1; $i > max(count($this->_sqlLoggerStack->queries)-25, 0) && isset($this->_sqlLoggerStack->queries[$i]); $i--) { - $query = $this->_sqlLoggerStack->queries[$i]; - $params = array_map(function($p) { if (is_object($p)) return get_class($p); else return "'".$p."'"; }, $query['params'] ?: array()); - $queries .= ($i+1).". SQL: '".$query['sql']."' Params: ".implode(", ", $params).PHP_EOL; + $last25queries = array_slice(array_reverse($this->_sqlLoggerStack->queries, true), 0, 25, true); + foreach ($last25queries as $i => $query) { + $params = array_map(function($p) { if (is_object($p)) return get_class($p); else return var_export($p, true); }, $query['params'] ?: array()); + $queries .= $i.". SQL: '".$query['sql']."' Params: ".implode(", ", $params).PHP_EOL; } $trace = $e->getTrace(); From 3bec698fed43756cdf808ec0bd13b1cccb6159c6 Mon Sep 17 00:00:00 2001 From: John Keller Date: Tue, 12 Apr 2016 13:43:45 -0700 Subject: [PATCH 037/877] add functional test and bug fix for issue #5762 --- .../ORM/Internal/Hydration/ObjectHydrator.php | 3 + .../ORM/Functional/Ticket/GH5762Test.php | 228 ++++++++++++++++++ 2 files changed, 231 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index 70d47655dab..ebea42cac7c 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -329,6 +329,9 @@ protected function hydrateRowData(array $row, array &$result) // Split the row data into chunks of class data. $rowData = $this->gatherRowData($row, $id, $nonemptyComponents); + // reset result pointers for each data row + $this->resultPointers = array(); + // Hydrate the data chunks foreach ($rowData['data'] as $dqlAlias => $data) { $entityName = $this->_rsm->aliasMap[$dqlAlias]; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php new file mode 100644 index 00000000000..809417c0470 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php @@ -0,0 +1,228 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\GH5762Driver'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\GH5762DriverRide'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\GH5762Car'), + )); + } + + public function testIssue() + { + $result = $this->fetchData(); + + $this->assertInstanceOf(__NAMESPACE__ . '\GH5762Driver', $result); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result->getDriverRides()); + $this->assertInstanceOf(__NAMESPACE__ . '\GH5762DriverRide', $result->getDriverRides()->get(0)); + $this->assertInstanceOf(__NAMESPACE__ . '\GH5762Car', $result->getDriverRides()->get(0)->getCar()); + + $cars = array(); + foreach ($result->getDriverRides() as $ride) { + $cars[] = $ride->getCar()->getBrand(); + } + $this->assertEquals(count($cars), count(array_unique($cars))); + + $this->assertContains('BMW', $cars); + $this->assertContains('Crysler', $cars); + $this->assertContains('Dodge', $cars); + $this->assertContains('Mercedes', $cars); + $this->assertContains('Volvo', $cars); + } + + private function fetchData() + { + $this->createData(); + + $qb = $this->_em->createQueryBuilder(); + $qb->select('d, dr, c') + ->from(__NAMESPACE__ . '\GH5762Driver', 'd') + ->leftJoin('d.driverRides', 'dr') + ->leftJoin('dr.car', 'c') + ->where('d.id = 1'); + + return $qb->getQuery()->getSingleResult(); + } + + private function createData() + { + $car1 = new GH5762Car('BMW', '7 Series'); + $car2 = new GH5762Car('Crysler', '300'); + $car3 = new GH5762Car('Dodge', 'Dart'); + $car4 = new GH5762Car('Mercedes', 'C-Class'); + $car5 = new GH5762Car('Volvo', 'XC90'); + + $driver = new GH5762Driver(1, 'John Doe'); + + $ride1 = new GH5762DriverRide($driver, $car1); + $ride2 = new GH5762DriverRide($driver, $car2); + $ride3 = new GH5762DriverRide($driver, $car3); + $ride4 = new GH5762DriverRide($driver, $car4); + $ride5 = new GH5762DriverRide($driver, $car5); + + $this->_em->persist($car1); + $this->_em->persist($car2); + $this->_em->persist($car3); + $this->_em->persist($car4); + $this->_em->persist($car5); + + $this->_em->persist($driver); + + $this->_em->persist($ride1); + $this->_em->persist($ride2); + $this->_em->persist($ride3); + $this->_em->persist($ride4); + $this->_em->persist($ride5); + + $this->_em->flush(); + $this->_em->clear(); + } +} + +/** + * @Entity + * @Table(name="driver") + */ +class GH5762Driver +{ + + /** + * @Id + * @Column(type="integer") + * @GeneratedValue(strategy="NONE") + */ + private $id; + + /** + * @Column(type="string", length=255); + */ + private $name; + + /** + * @OneToMany(targetEntity="GH5762DriverRide", mappedBy="driver") + */ + private $driverRides; + + function __construct($id, $name) + { + $this->driverRides = new ArrayCollection(); + $this->id = $id; + $this->name = $name; + } + + function getId() + { + return $this->id; + } + + function getName() + { + return $this->name; + } + + function getDriverRides() + { + return $this->driverRides; + } +} + +/** + * @Entity + * @Table(name="driver_ride") + */ +class GH5762DriverRide +{ + + /** + * @Id + * @ManyToOne(targetEntity="GH5762Driver", inversedBy="driverRides") + * @JoinColumn(name="driver_id", referencedColumnName="id") + */ + private $driver; + + /** + * @Id + * @ManyToOne(targetEntity="GH5762Car", inversedBy="carRides") + * @JoinColumn(name="car", referencedColumnName="brand") + */ + private $car; + + function __construct(GH5762Driver $driver, GH5762Car $car) + { + $this->driver = $driver; + $this->car = $car; + + $this->driver->getDriverRides()->add($this); + $this->car->getCarRides()->add($this); + } + + function getDriver() + { + return $this->driver; + } + + function getCar() + { + return $this->car; + } +} + +/** + * @Entity + * @Table(name="car") + */ +class GH5762Car +{ + + /** + * @Id + * @Column(type="string", length=25) + * @GeneratedValue(strategy="NONE") + */ + private $brand; + + /** + * @Column(type="string", length=255); + */ + private $model; + + /** + * @OneToMany(targetEntity="GH5762DriverRide", mappedBy="car") + */ + private $carRides; + + function __construct($brand, $model) + { + $this->carRides = new ArrayCollection(); + $this->brand = $brand; + $this->model = $model; + } + + function getBrand() + { + return $this->brand; + } + + function getModel() + { + return $this->model; + } + + function getCarRides() + { + return $this->carRides; + } +} From c6ea8b1129fbd9cb720148123aa0c1c6ec28e127 Mon Sep 17 00:00:00 2001 From: Alexander Kurilo Date: Mon, 29 Aug 2016 23:17:24 +0300 Subject: [PATCH 038/877] Remove irrelevant accessors (#5762) --- .../ORM/Functional/Ticket/GH5762Test.php | 84 +++++-------------- 1 file changed, 21 insertions(+), 63 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php index 809417c0470..ff3dac7e6e2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php @@ -15,9 +15,9 @@ protected function setup() parent::setup(); $this->_schemaTool->createSchema(array( - $this->_em->getClassMetadata(__NAMESPACE__ . '\GH5762Driver'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\GH5762DriverRide'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\GH5762Car'), + $this->_em->getClassMetadata(GH5762Driver::class), + $this->_em->getClassMetadata(GH5762DriverRide::class), + $this->_em->getClassMetadata(GH5762Car::class), )); } @@ -26,13 +26,13 @@ public function testIssue() $result = $this->fetchData(); $this->assertInstanceOf(__NAMESPACE__ . '\GH5762Driver', $result); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result->getDriverRides()); - $this->assertInstanceOf(__NAMESPACE__ . '\GH5762DriverRide', $result->getDriverRides()->get(0)); - $this->assertInstanceOf(__NAMESPACE__ . '\GH5762Car', $result->getDriverRides()->get(0)->getCar()); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result->driverRides); + $this->assertInstanceOf(__NAMESPACE__ . '\GH5762DriverRide', $result->driverRides->get(0)); + $this->assertInstanceOf(__NAMESPACE__ . '\GH5762Car', $result->driverRides->get(0)->car); $cars = array(); - foreach ($result->getDriverRides() as $ride) { - $cars[] = $ride->getCar()->getBrand(); + foreach ($result->driverRides as $ride) { + $cars[] = $ride->car->brand; } $this->assertEquals(count($cars), count(array_unique($cars))); @@ -93,50 +93,34 @@ private function createData() } /** - * @Entity + * @Entity * @Table(name="driver") */ class GH5762Driver { - /** * @Id * @Column(type="integer") * @GeneratedValue(strategy="NONE") */ - private $id; + public $id; /** * @Column(type="string", length=255); */ - private $name; + public $name; /** * @OneToMany(targetEntity="GH5762DriverRide", mappedBy="driver") */ - private $driverRides; + public $driverRides; - function __construct($id, $name) + public function __construct($id, $name) { $this->driverRides = new ArrayCollection(); $this->id = $id; $this->name = $name; } - - function getId() - { - return $this->id; - } - - function getName() - { - return $this->name; - } - - function getDriverRides() - { - return $this->driverRides; - } } /** @@ -145,38 +129,27 @@ function getDriverRides() */ class GH5762DriverRide { - /** * @Id * @ManyToOne(targetEntity="GH5762Driver", inversedBy="driverRides") * @JoinColumn(name="driver_id", referencedColumnName="id") */ - private $driver; + public $driver; /** * @Id * @ManyToOne(targetEntity="GH5762Car", inversedBy="carRides") * @JoinColumn(name="car", referencedColumnName="brand") */ - private $car; + public $car; function __construct(GH5762Driver $driver, GH5762Car $car) { $this->driver = $driver; $this->car = $car; - $this->driver->getDriverRides()->add($this); - $this->car->getCarRides()->add($this); - } - - function getDriver() - { - return $this->driver; - } - - function getCar() - { - return $this->car; + $this->driver->driverRides->add($this); + $this->car->carRides->add($this); } } @@ -192,37 +165,22 @@ class GH5762Car * @Column(type="string", length=25) * @GeneratedValue(strategy="NONE") */ - private $brand; + public $brand; /** * @Column(type="string", length=255); */ - private $model; + public $model; /** * @OneToMany(targetEntity="GH5762DriverRide", mappedBy="car") */ - private $carRides; + public $carRides; - function __construct($brand, $model) + public function __construct($brand, $model) { $this->carRides = new ArrayCollection(); $this->brand = $brand; $this->model = $model; } - - function getBrand() - { - return $this->brand; - } - - function getModel() - { - return $this->model; - } - - function getCarRides() - { - return $this->carRides; - } } From 74ec055d577d71b477c7da7d6694ef636c51c8a6 Mon Sep 17 00:00:00 2001 From: Alexander Kurilo Date: Mon, 29 Aug 2016 22:29:41 +0300 Subject: [PATCH 039/877] Use ::class const instead of FQCN string (#5762) --- .../Tests/ORM/Functional/Ticket/GH5762Test.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php index ff3dac7e6e2..a602921de99 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php @@ -3,11 +3,13 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\ORM\PersistentCollection; +use Doctrine\Tests\OrmFunctionalTestCase; /** * @group GH-5762 */ -class GH5762Test extends \Doctrine\Tests\OrmFunctionalTestCase +class GH5762Test extends OrmFunctionalTestCase { protected function setup() @@ -25,10 +27,10 @@ public function testIssue() { $result = $this->fetchData(); - $this->assertInstanceOf(__NAMESPACE__ . '\GH5762Driver', $result); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result->driverRides); - $this->assertInstanceOf(__NAMESPACE__ . '\GH5762DriverRide', $result->driverRides->get(0)); - $this->assertInstanceOf(__NAMESPACE__ . '\GH5762Car', $result->driverRides->get(0)->car); + $this->assertInstanceOf(GH5762Driver::class, $result); + $this->assertInstanceOf(PersistentCollection::class, $result->driverRides); + $this->assertInstanceOf(GH5762DriverRide::class, $result->driverRides->get(0)); + $this->assertInstanceOf(GH5762Car::class, $result->driverRides->get(0)->car); $cars = array(); foreach ($result->driverRides as $ride) { @@ -49,7 +51,7 @@ private function fetchData() $qb = $this->_em->createQueryBuilder(); $qb->select('d, dr, c') - ->from(__NAMESPACE__ . '\GH5762Driver', 'd') + ->from(GH5762Driver::class, 'd') ->leftJoin('d.driverRides', 'dr') ->leftJoin('dr.car', 'c') ->where('d.id = 1'); From 140960ebb1f1b5568d7921e1a54381a5640501c7 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 7 Sep 2016 23:17:40 +0200 Subject: [PATCH 040/877] #5975 short array syntax --- lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index ebea42cac7c..14aed2a67fe 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -330,7 +330,7 @@ protected function hydrateRowData(array $row, array &$result) $rowData = $this->gatherRowData($row, $id, $nonemptyComponents); // reset result pointers for each data row - $this->resultPointers = array(); + $this->resultPointers = []; // Hydrate the data chunks foreach ($rowData['data'] as $dqlAlias => $data) { From 50f321f2e9ad8133420e17ca61afa564d0b9b479 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 7 Sep 2016 23:18:39 +0200 Subject: [PATCH 041/877] #5975 minor test cleanups --- .../ORM/Functional/Ticket/GH5762Test.php | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php index a602921de99..b42dd653496 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php @@ -11,10 +11,9 @@ */ class GH5762Test extends OrmFunctionalTestCase { - - protected function setup() + protected function setUp() { - parent::setup(); + parent::setUp(); $this->_schemaTool->createSchema(array( $this->_em->getClassMetadata(GH5762Driver::class), @@ -27,22 +26,23 @@ public function testIssue() { $result = $this->fetchData(); - $this->assertInstanceOf(GH5762Driver::class, $result); - $this->assertInstanceOf(PersistentCollection::class, $result->driverRides); - $this->assertInstanceOf(GH5762DriverRide::class, $result->driverRides->get(0)); - $this->assertInstanceOf(GH5762Car::class, $result->driverRides->get(0)->car); + self::assertInstanceOf(GH5762Driver::class, $result); + self::assertInstanceOf(PersistentCollection::class, $result->driverRides); + self::assertInstanceOf(GH5762DriverRide::class, $result->driverRides->get(0)); + self::assertInstanceOf(GH5762Car::class, $result->driverRides->get(0)->car); $cars = array(); foreach ($result->driverRides as $ride) { $cars[] = $ride->car->brand; } - $this->assertEquals(count($cars), count(array_unique($cars))); - $this->assertContains('BMW', $cars); - $this->assertContains('Crysler', $cars); - $this->assertContains('Dodge', $cars); - $this->assertContains('Mercedes', $cars); - $this->assertContains('Volvo', $cars); + self::assertEquals(count($cars), count(array_unique($cars))); + + self::assertContains('BMW', $cars); + self::assertContains('Crysler', $cars); + self::assertContains('Dodge', $cars); + self::assertContains('Mercedes', $cars); + self::assertContains('Volvo', $cars); } private function fetchData() From a90035e81af2e9a424c0268a36101c3483e06571 Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Fri, 2 Sep 2016 15:43:28 -0300 Subject: [PATCH 042/877] Expose `EntityPersister::count()` through `EntityRepository::count()` --- docs/en/reference/working-with-objects.rst | 54 +++++++++------- docs/en/tutorials/getting-started.rst | 62 +++++++++++-------- lib/Doctrine/ORM/EntityRepository.php | 35 +++++++++-- .../Entity/BasicEntityPersister.php | 2 +- .../ORM/Functional/EntityRepositoryTest.php | 24 +++++++ 5 files changed, 121 insertions(+), 56 deletions(-) diff --git a/docs/en/reference/working-with-objects.rst b/docs/en/reference/working-with-objects.rst index 8368c9f1309..bcc9bf18537 100644 --- a/docs/en/reference/working-with-objects.rst +++ b/docs/en/reference/working-with-objects.rst @@ -41,7 +41,7 @@ headline "Hello World" with the ID 1234: find('CMS\Article', 1234); $article->setHeadline('Hello World dude!'); - + $article2 = $entityManager->find('CMS\Article', 1234); echo $article2->getHeadline(); @@ -93,25 +93,25 @@ from newly opened EntityManager. { /** @Id @Column(type="integer") @GeneratedValue */ private $id; - + /** @Column(type="string") */ private $headline; - + /** @ManyToOne(targetEntity="User") */ private $author; - + /** @OneToMany(targetEntity="Comment", mappedBy="article") */ private $comments; - + public function __construct() { $this->comments = new ArrayCollection(); } - + public function getAuthor() { return $this->author; } public function getComments() { return $this->comments; } } - + $article = $em->find('Article', 1); This code only retrieves the ``Article`` instance with id 1 executing @@ -132,22 +132,22 @@ your code. See the following code: find('Article', 1); - + // accessing a method of the user instance triggers the lazy-load echo "Author: " . $article->getAuthor()->getName() . "\n"; - + // Lazy Loading Proxies pass instanceof tests: if ($article->getAuthor() instanceof User) { // a User Proxy is a generated "UserProxy" class } - + // accessing the comments as an iterator triggers the lazy-load // retrieving ALL the comments of this article from the database // using a single SELECT statement foreach ($article->getComments() as $comment) { echo $comment->getText() . "\n\n"; } - + // Article::$comments passes instanceof tests for the Collection interface // But it will NOT pass for the ArrayCollection interface if ($article->getComments() instanceof \Doctrine\Common\Collections\Collection) { @@ -167,7 +167,7 @@ methods along the lines of the ``getName()`` method shown below: { // lazy loading code } - + public function getName() { $this->_load(); @@ -262,7 +262,7 @@ which means that its persistent state will be deleted once for and appear in query and collection results. See the section on :ref:`Database and UnitOfWork Out-Of-Sync ` for more information. - + Example: @@ -681,13 +681,13 @@ methods on a repository as follows: getRepository('MyProject\Domain\User')->findBy(array('age' => 20)); - + // All users that are 20 years old and have a surname of 'Miller' $users = $em->getRepository('MyProject\Domain\User')->findBy(array('age' => 20, 'surname' => 'Miller')); - + // A single user by its nickname $user = $em->getRepository('MyProject\Domain\User')->findOneBy(array('nickname' => 'romanb')); @@ -723,10 +723,18 @@ examples are equivalent: getRepository('MyProject\Domain\User')->findOneBy(array('nickname' => 'romanb')); - + // A single user by its nickname (__call magic) $user = $em->getRepository('MyProject\Domain\User')->findOneByNickname('romanb'); +Additionally, you can just count the result of the provided conditions when you don't really need the data: + +.. code-block:: php + + getRepository('MyProject\Domain\User')->count(array('nickname' => 'nonexistent')); + By Criteria ~~~~~~~~~~~ @@ -774,7 +782,7 @@ A DQL query is represented by an instance of the createQuery("select u from MyDomain\Model\User u where u.age >= 20 and u.age <= 30"); $users = $q->getResult(); @@ -817,18 +825,18 @@ in a central location. getRepository('MyDomain\Model\User')->getAllAdminUsers(); diff --git a/docs/en/tutorials/getting-started.rst b/docs/en/tutorials/getting-started.rst index ef473431741..5e04442461f 100644 --- a/docs/en/tutorials/getting-started.rst +++ b/docs/en/tutorials/getting-started.rst @@ -103,7 +103,7 @@ Install Doctrine using the Composer Dependency Management tool, by calling: $ composer install This will install the packages Doctrine Common, Doctrine DBAL, Doctrine ORM, -Symfony YAML and Symfony Console into the `vendor` directory. The Symfony +Symfony YAML and Symfony Console into the `vendor` directory. The Symfony dependencies are not required by Doctrine but will be used in this tutorial. Add the following directories: @@ -131,22 +131,22 @@ step: // bootstrap.php use Doctrine\ORM\Tools\Setup; use Doctrine\ORM\EntityManager; - + require_once "vendor/autoload.php"; - + // Create a simple "default" Doctrine ORM configuration for Annotations $isDevMode = true; $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), $isDevMode); // or if you prefer yaml or XML //$config = Setup::createXMLMetadataConfiguration(array(__DIR__."/config/xml"), $isDevMode); //$config = Setup::createYAMLMetadataConfiguration(array(__DIR__."/config/yaml"), $isDevMode); - + // database configuration parameters $conn = array( 'driver' => 'pdo_sqlite', 'path' => __DIR__ . '/db.sqlite', ); - + // obtaining the entity manager $entityManager = EntityManager::create($conn, $config); @@ -185,7 +185,7 @@ doctrine command. Its a fairly simple file: getRepository('Product') + ->count(array('name' => $productName)); + Conclusion ---------- diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index 08b2ff19344..2b8c1cb51ab 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -196,16 +196,32 @@ public function findOneBy(array $criteria, array $orderBy = null) } /** - * Adds support for magic finders. + * Counts entities by a set of criteria. + * + * @todo Add this method to `ObjectRepository` interface in the next major release + * + * @param array $criteria + * + * @return int The quantity of objects that matches the criteria. + */ + public function count(array $criteria) + { + $persister = $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName); + + return $persister->count($criteria); + } + + /** + * Adds support for magic finders/counters. * * @param string $method * @param array $arguments * - * @return array|object The found entity/entities. + * @return array|object|int The found entity/entities or its resulting count. * * @throws ORMException - * @throws \BadMethodCallException If the method called is an invalid find* method - * or no find* method at all and therefore an invalid + * @throws \BadMethodCallException If the method called is an invalid find* or countBy method + * or no find* or countBy method at all and therefore an invalid * method call. */ public function __call($method, $arguments) @@ -221,6 +237,11 @@ public function __call($method, $arguments) $method = 'findOneBy'; break; + case (0 === strpos($method, 'countBy')): + $by = substr($method, 7); + $method = 'count'; + break; + default: throw new \BadMethodCallException( "Undefined method '$method'. The method name must start with ". @@ -228,14 +249,16 @@ public function __call($method, $arguments) ); } - if (empty($arguments)) { + $argsCount = count($arguments); + + if (0 === $argsCount) { throw ORMException::findByRequiresParameter($method . $by); } $fieldName = lcfirst(\Doctrine\Common\Util\Inflector::classify($by)); if ($this->_class->hasField($fieldName) || $this->_class->hasAssociation($fieldName)) { - switch (count($arguments)) { + switch ($argsCount) { case 1: return $this->$method(array($fieldName => $arguments[0])); diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 3b2faf878d7..c62a10a120c 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -822,7 +822,7 @@ public function count($criteria = array()) ? $this->expandCriteriaParameters($criteria) : $this->expandParameters($criteria); - return $this->conn->executeQuery($sql, $params, $types)->fetchColumn(); + return (int) $this->conn->executeQuery($sql, $params, $types)->fetchColumn(); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php index ffca89ba0b8..e0b96387a6f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php @@ -272,6 +272,30 @@ public function testFindByAlias() $this->assertEquals(4, count($users)); } + public function testCount() + { + $this->loadFixture(); + $repos = $this->_em->getRepository(CmsUser::class); + + $userCount = $repos->count(array()); + $this->assertSame(4, $userCount); + + $userCount = $repos->count(array('status' => 'dev')); + $this->assertSame(2, $userCount); + + $userCount = $repos->count(array('status' => 'nonexistent')); + $this->assertSame(0, $userCount); + } + + public function testCountBy() + { + $this->loadFixture(); + $repos = $this->_em->getRepository(CmsUser::class); + + $userCount = $repos->countByStatus('dev'); + $this->assertSame(2, $userCount); + } + /** * @expectedException \Doctrine\ORM\ORMException */ From bea3c653bc3e0780ca6ec170235953ef2a75842e Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Wed, 7 Sep 2016 17:39:51 -0300 Subject: [PATCH 043/877] Updated docs --- docs/en/reference/working-with-objects.rst | 48 +++++++++---------- docs/en/tutorials/getting-started.rst | 56 +++++++++++----------- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/docs/en/reference/working-with-objects.rst b/docs/en/reference/working-with-objects.rst index bcc9bf18537..2b52fac412c 100644 --- a/docs/en/reference/working-with-objects.rst +++ b/docs/en/reference/working-with-objects.rst @@ -41,7 +41,7 @@ headline "Hello World" with the ID 1234: find('CMS\Article', 1234); $article->setHeadline('Hello World dude!'); - + $article2 = $entityManager->find('CMS\Article', 1234); echo $article2->getHeadline(); @@ -93,25 +93,25 @@ from newly opened EntityManager. { /** @Id @Column(type="integer") @GeneratedValue */ private $id; - + /** @Column(type="string") */ private $headline; - + /** @ManyToOne(targetEntity="User") */ private $author; - + /** @OneToMany(targetEntity="Comment", mappedBy="article") */ private $comments; - + public function __construct() { $this->comments = new ArrayCollection(); } - + public function getAuthor() { return $this->author; } public function getComments() { return $this->comments; } } - + $article = $em->find('Article', 1); This code only retrieves the ``Article`` instance with id 1 executing @@ -132,22 +132,22 @@ your code. See the following code: find('Article', 1); - + // accessing a method of the user instance triggers the lazy-load echo "Author: " . $article->getAuthor()->getName() . "\n"; - + // Lazy Loading Proxies pass instanceof tests: if ($article->getAuthor() instanceof User) { // a User Proxy is a generated "UserProxy" class } - + // accessing the comments as an iterator triggers the lazy-load // retrieving ALL the comments of this article from the database // using a single SELECT statement foreach ($article->getComments() as $comment) { echo $comment->getText() . "\n\n"; } - + // Article::$comments passes instanceof tests for the Collection interface // But it will NOT pass for the ArrayCollection interface if ($article->getComments() instanceof \Doctrine\Common\Collections\Collection) { @@ -167,7 +167,7 @@ methods along the lines of the ``getName()`` method shown below: { // lazy loading code } - + public function getName() { $this->_load(); @@ -262,7 +262,7 @@ which means that its persistent state will be deleted once for and appear in query and collection results. See the section on :ref:`Database and UnitOfWork Out-Of-Sync ` for more information. - + Example: @@ -681,13 +681,13 @@ methods on a repository as follows: getRepository('MyProject\Domain\User')->findBy(array('age' => 20)); - + // All users that are 20 years old and have a surname of 'Miller' $users = $em->getRepository('MyProject\Domain\User')->findBy(array('age' => 20, 'surname' => 'Miller')); - + // A single user by its nickname $user = $em->getRepository('MyProject\Domain\User')->findOneBy(array('nickname' => 'romanb')); @@ -723,7 +723,7 @@ examples are equivalent: getRepository('MyProject\Domain\User')->findOneBy(array('nickname' => 'romanb')); - + // A single user by its nickname (__call magic) $user = $em->getRepository('MyProject\Domain\User')->findOneByNickname('romanb'); @@ -733,7 +733,7 @@ Additionally, you can just count the result of the provided conditions when you getRepository('MyProject\Domain\User')->count(array('nickname' => 'nonexistent')); + $availableNickname = 0 === $em->getRepository('MyProject\Domain\User')->count(['nickname' => 'nonexistent']); By Criteria ~~~~~~~~~~~ @@ -782,7 +782,7 @@ A DQL query is represented by an instance of the createQuery("select u from MyDomain\Model\User u where u.age >= 20 and u.age <= 30"); $users = $q->getResult(); @@ -825,18 +825,18 @@ in a central location. getRepository('MyDomain\Model\User')->getAllAdminUsers(); diff --git a/docs/en/tutorials/getting-started.rst b/docs/en/tutorials/getting-started.rst index 5e04442461f..05492b13308 100644 --- a/docs/en/tutorials/getting-started.rst +++ b/docs/en/tutorials/getting-started.rst @@ -103,7 +103,7 @@ Install Doctrine using the Composer Dependency Management tool, by calling: $ composer install This will install the packages Doctrine Common, Doctrine DBAL, Doctrine ORM, -Symfony YAML and Symfony Console into the `vendor` directory. The Symfony +Symfony YAML and Symfony Console into the `vendor` directory. The Symfony dependencies are not required by Doctrine but will be used in this tutorial. Add the following directories: @@ -131,22 +131,22 @@ step: // bootstrap.php use Doctrine\ORM\Tools\Setup; use Doctrine\ORM\EntityManager; - + require_once "vendor/autoload.php"; - + // Create a simple "default" Doctrine ORM configuration for Annotations $isDevMode = true; $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), $isDevMode); // or if you prefer yaml or XML //$config = Setup::createXMLMetadataConfiguration(array(__DIR__."/config/xml"), $isDevMode); //$config = Setup::createYAMLMetadataConfiguration(array(__DIR__."/config/yaml"), $isDevMode); - + // database configuration parameters $conn = array( 'driver' => 'pdo_sqlite', 'path' => __DIR__ . '/db.sqlite', ); - + // obtaining the entity manager $entityManager = EntityManager::create($conn, $config); @@ -185,7 +185,7 @@ doctrine command. Its a fairly simple file: getRepository('Product') - ->count(array('name' => $productName)); + $productCount = $entityManager->getRepository(Product::class) + ->count(['name' => $productName]); Conclusion ---------- From 591bae0855c111d1c247eb204125643566b30868 Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Wed, 7 Sep 2016 18:43:17 -0300 Subject: [PATCH 044/877] Swap logic from `EntityRespository::__call()` --- lib/Doctrine/ORM/EntityRepository.php | 106 ++++++++++++++------------ lib/Doctrine/ORM/ORMException.php | 15 ++++ 2 files changed, 71 insertions(+), 50 deletions(-) diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index 2b8c1cb51ab..39f8bf3bc36 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -212,71 +212,34 @@ public function count(array $criteria) } /** - * Adds support for magic finders/counters. + * Adds support for magic method calls. * * @param string $method * @param array $arguments * - * @return array|object|int The found entity/entities or its resulting count. + * @return mixed The returned value from the resolved method. * * @throws ORMException - * @throws \BadMethodCallException If the method called is an invalid find* or countBy method - * or no find* or countBy method at all and therefore an invalid - * method call. + * @throws \BadMethodCallException If the method called is invalid */ public function __call($method, $arguments) { - switch (true) { - case (0 === strpos($method, 'findBy')): - $by = substr($method, 6); - $method = 'findBy'; - break; - - case (0 === strpos($method, 'findOneBy')): - $by = substr($method, 9); - $method = 'findOneBy'; - break; - - case (0 === strpos($method, 'countBy')): - $by = substr($method, 7); - $method = 'count'; - break; - - default: - throw new \BadMethodCallException( - "Undefined method '$method'. The method name must start with ". - "either findBy or findOneBy!" - ); + if (0 === strpos($method, 'findBy')) { + return $this->resolveMagicCall('findBy', substr($method, 6), $arguments); } - $argsCount = count($arguments); - - if (0 === $argsCount) { - throw ORMException::findByRequiresParameter($method . $by); + if (0 === strpos($method, 'findOneBy')) { + return $this->resolveMagicCall('findOneBy', substr($method, 9), $arguments); } - $fieldName = lcfirst(\Doctrine\Common\Util\Inflector::classify($by)); - - if ($this->_class->hasField($fieldName) || $this->_class->hasAssociation($fieldName)) { - switch ($argsCount) { - case 1: - return $this->$method(array($fieldName => $arguments[0])); - - case 2: - return $this->$method(array($fieldName => $arguments[0]), $arguments[1]); - - case 3: - return $this->$method(array($fieldName => $arguments[0]), $arguments[1], $arguments[2]); - - case 4: - return $this->$method(array($fieldName => $arguments[0]), $arguments[1], $arguments[2], $arguments[3]); - - default: - // Do nothing - } + if (0 === strpos($method, 'countBy')) { + return $this->resolveMagicCall('count', substr($method, 7), $arguments); } - throw ORMException::invalidFindByCall($this->_entityName, $fieldName, $method.$by); + throw new \BadMethodCallException( + "Undefined method '$method'. The method name must start with ". + "either findBy or findOneBy!" + ); } /** @@ -325,4 +288,47 @@ public function matching(Criteria $criteria) return new LazyCriteriaCollection($persister, $criteria); } + + /** + * Resolves a magic method call to the proper existent method at `EntityRepository`. + * + * @param string $method The method to call + * @param string $by The property name used as condition + * @param array $arguments The arguments to pass at method call + * + * @throws ORMException If the method called is invalid. + * + * @return mixed + */ + private function resolveMagicCall($method, $by, array $arguments = []) + { + $argsCount = count($arguments); + + if (0 === $argsCount) { + throw ORMException::findByRequiresParameter($method . $by); + } + + $fieldName = lcfirst(\Doctrine\Common\Util\Inflector::classify($by)); + + if ($this->_class->hasField($fieldName) || $this->_class->hasAssociation($fieldName)) { + switch ($argsCount) { + case 1: + return $this->$method(array($fieldName => $arguments[0])); + + case 2: + return $this->$method(array($fieldName => $arguments[0]), $arguments[1]); + + case 3: + return $this->$method(array($fieldName => $arguments[0]), $arguments[1], $arguments[2]); + + case 4: + return $this->$method(array($fieldName => $arguments[0]), $arguments[1], $arguments[2], $arguments[3]); + + default: + // Do nothing + } + } + + throw ORMException::invalidMagicCall($this->_entityName, $fieldName, $method.$by); + } } diff --git a/lib/Doctrine/ORM/ORMException.php b/lib/Doctrine/ORM/ORMException.php index 6d8a6d631f4..919789d9249 100644 --- a/lib/Doctrine/ORM/ORMException.php +++ b/lib/Doctrine/ORM/ORMException.php @@ -187,6 +187,21 @@ public static function invalidFindByCall($entityName, $fieldName, $method) ); } + /** + * @param string $entityName + * @param string $fieldName + * @param string $method + * + * @return ORMException + */ + public static function invalidMagicCall($entityName, $fieldName, $method) + { + return new self( + "Entity '".$entityName."' has no field '".$fieldName."'. ". + "You can therefore not call '".$method."' on the entities' repository" + ); + } + /** * @param string $entityName * @param string $associationFieldName From 61f6b667c0026565f5cbfa9f0c4066266bdb61e9 Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Wed, 7 Sep 2016 19:24:38 -0300 Subject: [PATCH 045/877] Remove `default` clause at `EntityRepository::resolveMagicCall()` --- lib/Doctrine/ORM/EntityRepository.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index 39f8bf3bc36..00e53c341c5 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -323,9 +323,6 @@ private function resolveMagicCall($method, $by, array $arguments = []) case 4: return $this->$method(array($fieldName => $arguments[0]), $arguments[1], $arguments[2], $arguments[3]); - - default: - // Do nothing } } From 6f79a378d56101516ad379307794e4ada0a76caf Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 8 Sep 2016 00:43:29 +0200 Subject: [PATCH 046/877] #6003 removed useless method parameter count checking duplication --- lib/Doctrine/ORM/EntityRepository.php | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index 00e53c341c5..a3fcf0aff93 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -310,22 +310,10 @@ private function resolveMagicCall($method, $by, array $arguments = []) $fieldName = lcfirst(\Doctrine\Common\Util\Inflector::classify($by)); - if ($this->_class->hasField($fieldName) || $this->_class->hasAssociation($fieldName)) { - switch ($argsCount) { - case 1: - return $this->$method(array($fieldName => $arguments[0])); - - case 2: - return $this->$method(array($fieldName => $arguments[0]), $arguments[1]); - - case 3: - return $this->$method(array($fieldName => $arguments[0]), $arguments[1], $arguments[2]); - - case 4: - return $this->$method(array($fieldName => $arguments[0]), $arguments[1], $arguments[2], $arguments[3]); - } + if (! ($this->_class->hasField($fieldName) || $this->_class->hasAssociation($fieldName))) { + throw ORMException::invalidMagicCall($this->_entityName, $fieldName, $method . $by); } - throw ORMException::invalidMagicCall($this->_entityName, $fieldName, $method.$by); + return $this->$method([$fieldName => $arguments[0]], ...array_slice($arguments, 1)); } } From 5e51a985b7df08f45604642e154a98c65b9aac31 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 8 Sep 2016 00:47:39 +0200 Subject: [PATCH 047/877] #6003 no default parameter needed --- lib/Doctrine/ORM/EntityRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index a3fcf0aff93..7ba60b71ec3 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -300,7 +300,7 @@ public function matching(Criteria $criteria) * * @return mixed */ - private function resolveMagicCall($method, $by, array $arguments = []) + private function resolveMagicCall($method, $by, array $arguments) { $argsCount = count($arguments); From de4c854ac955526285eab6111b9ba9a446d44b62 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 8 Sep 2016 00:48:52 +0200 Subject: [PATCH 048/877] #6003 removed useless `count()` call --- lib/Doctrine/ORM/EntityRepository.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index 7ba60b71ec3..cdd90baf063 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -302,9 +302,7 @@ public function matching(Criteria $criteria) */ private function resolveMagicCall($method, $by, array $arguments) { - $argsCount = count($arguments); - - if (0 === $argsCount) { + if (! $arguments) { throw ORMException::findByRequiresParameter($method . $by); } From 7bf4a65c92413773af3039448eccc296c34cffe9 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 8 Sep 2016 00:53:35 +0200 Subject: [PATCH 049/877] #6003 imported used symbol --- lib/Doctrine/ORM/EntityRepository.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index cdd90baf063..ce7b7c23ac2 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -19,6 +19,7 @@ namespace Doctrine\ORM; +use Doctrine\Common\Util\Inflector; use Doctrine\ORM\Query\ResultSetMappingBuilder; use Doctrine\Common\Persistence\ObjectRepository; use Doctrine\Common\Collections\Selectable; @@ -306,7 +307,7 @@ private function resolveMagicCall($method, $by, array $arguments) throw ORMException::findByRequiresParameter($method . $by); } - $fieldName = lcfirst(\Doctrine\Common\Util\Inflector::classify($by)); + $fieldName = lcfirst(Inflector::classify($by)); if (! ($this->_class->hasField($fieldName) || $this->_class->hasAssociation($fieldName))) { throw ORMException::invalidMagicCall($this->_entityName, $fieldName, $method . $by); From e2cba87662c0ce01fb8b680daa3c6857ee6dfa1c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 8 Sep 2016 00:54:49 +0200 Subject: [PATCH 050/877] #6003 corrected return type definition --- lib/Doctrine/ORM/EntityRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index ce7b7c23ac2..f47608ea7eb 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -203,7 +203,7 @@ public function findOneBy(array $criteria, array $orderBy = null) * * @param array $criteria * - * @return int The quantity of objects that matches the criteria. + * @return int The cardinality of the objects that match the given criteria. */ public function count(array $criteria) { From 36e99040824a3da5554ab38427406ec5b679f5a8 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 8 Sep 2016 00:55:09 +0200 Subject: [PATCH 051/877] #6003 inlined persister retrieval --- lib/Doctrine/ORM/EntityRepository.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index f47608ea7eb..85dd63c6eac 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -207,9 +207,7 @@ public function findOneBy(array $criteria, array $orderBy = null) */ public function count(array $criteria) { - $persister = $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName); - - return $persister->count($criteria); + return $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName)->count($criteria); } /** From c5c56a9dad69d138057c1e1707390dec6c241912 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 8 Sep 2016 00:55:49 +0200 Subject: [PATCH 052/877] #6003 clarifying thrown exception --- lib/Doctrine/ORM/EntityRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index 85dd63c6eac..0c28237570f 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -295,7 +295,7 @@ public function matching(Criteria $criteria) * @param string $by The property name used as condition * @param array $arguments The arguments to pass at method call * - * @throws ORMException If the method called is invalid. + * @throws ORMException If the method called is invalid or the requested field/association does not exist * * @return mixed */ From 12b5e79ff2d99ea6dfe8b23a77ae515c741c324a Mon Sep 17 00:00:00 2001 From: Carl Vuorinen Date: Fri, 2 Sep 2016 10:31:26 +0300 Subject: [PATCH 053/877] Create a failing test for issue #5989 Field with type=simple_array in a joined inheritance gets overridden by empty array in the hydrator --- .../Models/Issue5989/Issue5989Employee.php | 27 ++++++++++ .../Models/Issue5989/Issue5989Manager.php | 27 ++++++++++ .../Models/Issue5989/Issue5989Person.php | 29 +++++++++++ .../ORM/Functional/Ticket/Issue5989Test.php | 51 +++++++++++++++++++ .../Doctrine/Tests/OrmFunctionalTestCase.php | 11 ++++ 5 files changed, 145 insertions(+) create mode 100644 tests/Doctrine/Tests/Models/Issue5989/Issue5989Employee.php create mode 100644 tests/Doctrine/Tests/Models/Issue5989/Issue5989Manager.php create mode 100644 tests/Doctrine/Tests/Models/Issue5989/Issue5989Person.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/Issue5989Test.php diff --git a/tests/Doctrine/Tests/Models/Issue5989/Issue5989Employee.php b/tests/Doctrine/Tests/Models/Issue5989/Issue5989Employee.php new file mode 100644 index 00000000000..e3eaac7d8be --- /dev/null +++ b/tests/Doctrine/Tests/Models/Issue5989/Issue5989Employee.php @@ -0,0 +1,27 @@ +tags; + } + + public function setTags(array $tags) + { + $this->tags = $tags; + } +} diff --git a/tests/Doctrine/Tests/Models/Issue5989/Issue5989Manager.php b/tests/Doctrine/Tests/Models/Issue5989/Issue5989Manager.php new file mode 100644 index 00000000000..32c05398487 --- /dev/null +++ b/tests/Doctrine/Tests/Models/Issue5989/Issue5989Manager.php @@ -0,0 +1,27 @@ +tags; + } + + public function setTags(array $tags) + { + $this->tags = $tags; + } +} diff --git a/tests/Doctrine/Tests/Models/Issue5989/Issue5989Person.php b/tests/Doctrine/Tests/Models/Issue5989/Issue5989Person.php new file mode 100644 index 00000000000..c9e00c4c188 --- /dev/null +++ b/tests/Doctrine/Tests/Models/Issue5989/Issue5989Person.php @@ -0,0 +1,29 @@ +id; + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Issue5989Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Issue5989Test.php new file mode 100644 index 00000000000..29a5a3fa2b0 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Issue5989Test.php @@ -0,0 +1,51 @@ +useModelSet('issue5989'); + parent::setUp(); + } + + public function testSimpleArrayTypeHydratedCorrectlyInJoinedInheritance() + { + $manager = new Issue5989Manager(); + + $managerTags = array('tag1', 'tag2'); + $manager->setTags($managerTags); + $this->_em->persist($manager); + + $employee = new Issue5989Employee(); + + $employeeTags = array('tag2', 'tag3'); + $employee->setTags($employeeTags); + $this->_em->persist($employee); + + $this->_em->flush(); + + $managerId = $manager->getId(); + $employeeId = $employee->getId(); + + // clear entity manager so that $repository->find actually fetches them and uses the hydrator + // instead of just returning the existing managed entities + $this->_em->clear(); + + $repository = $this->_em->getRepository(Issue5989Person::class); + + $manager = $repository->find($managerId); + $employee = $repository->find($employeeId); + + static::assertEquals($managerTags, $manager->getTags()); + static::assertEquals($employeeTags, $employee->getTags()); + } +} diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 907c006173b..a6a3bece4ad 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -295,6 +295,11 @@ abstract class OrmFunctionalTestCase extends OrmTestCase 'Doctrine\Tests\Models\VersionedManyToOne\Category', 'Doctrine\Tests\Models\VersionedManyToOne\Article', ), + 'issue5989' => array( + 'Doctrine\Tests\Models\Issue5989\Issue5989Person', + 'Doctrine\Tests\Models\Issue5989\Issue5989Employee', + 'Doctrine\Tests\Models\Issue5989\Issue5989Manager', + ), ); /** @@ -563,6 +568,12 @@ protected function tearDown() $conn->executeUpdate('DELETE FROM versioned_many_to_one_category'); } + if (isset($this->_usedModelSets['issue5989'])) { + $conn->executeUpdate('DELETE FROM issue5989_persons'); + $conn->executeUpdate('DELETE FROM issue5989_employees'); + $conn->executeUpdate('DELETE FROM issue5989_managers'); + } + $this->_em->clear(); } From 95546d68c5eec4576b0d5dcb741175ee39692333 Mon Sep 17 00:00:00 2001 From: Carl Vuorinen Date: Sat, 3 Sep 2016 22:25:11 +0300 Subject: [PATCH 054/877] Fix hydration in a joined inheritance with simple array or json array SimpleArrayType and JsonArrayType convert NULL value to an empty array, which fails the null check that is used to prevent overwrite Fixes issue #5989 --- lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php index 92c77ddd3f3..798bd305ac2 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php @@ -121,6 +121,9 @@ protected function hydrateRowData(array $sqlResult, array &$result) continue; } + // Check if value is null before conversion (because some types convert null to something else) + $valueIsNull = $value === null; + // Convert field to a valid PHP value if (isset($cacheKeyInfo['type'])) { $type = $cacheKeyInfo['type']; @@ -130,7 +133,7 @@ protected function hydrateRowData(array $sqlResult, array &$result) $fieldName = $cacheKeyInfo['fieldName']; // Prevent overwrite in case of inherit classes using same property name (See AbstractHydrator) - if ( ! isset($data[$fieldName]) || $value !== null) { + if ( ! isset($data[$fieldName]) || ! $valueIsNull) { $data[$fieldName] = $value; } } From 00bbf4f52351280791fbc59761533d296b59861b Mon Sep 17 00:00:00 2001 From: Carl Vuorinen Date: Sun, 4 Sep 2016 18:37:03 +0300 Subject: [PATCH 055/877] Use yoda condition in the null check --- lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php index 798bd305ac2..785a2b79680 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php @@ -122,7 +122,7 @@ protected function hydrateRowData(array $sqlResult, array &$result) } // Check if value is null before conversion (because some types convert null to something else) - $valueIsNull = $value === null; + $valueIsNull = null === $value; // Convert field to a valid PHP value if (isset($cacheKeyInfo['type'])) { From d2cbd5e872ac637474846c79bed7df9738343ffa Mon Sep 17 00:00:00 2001 From: Carl Vuorinen Date: Thu, 8 Sep 2016 11:48:34 +0300 Subject: [PATCH 056/877] PR fixes (public properties & correct letter case in annotations) --- .../Tests/Models/Issue5989/Issue5989Employee.php | 14 ++------------ .../Tests/Models/Issue5989/Issue5989Manager.php | 14 ++------------ .../Tests/Models/Issue5989/Issue5989Person.php | 7 +------ .../ORM/Functional/Ticket/Issue5989Test.php | 16 ++++++++-------- 4 files changed, 13 insertions(+), 38 deletions(-) diff --git a/tests/Doctrine/Tests/Models/Issue5989/Issue5989Employee.php b/tests/Doctrine/Tests/Models/Issue5989/Issue5989Employee.php index e3eaac7d8be..9f5e248d8c6 100644 --- a/tests/Doctrine/Tests/Models/Issue5989/Issue5989Employee.php +++ b/tests/Doctrine/Tests/Models/Issue5989/Issue5989Employee.php @@ -9,19 +9,9 @@ class Issue5989Employee extends Issue5989Person { /** - * @column(type="simple_array", nullable=true) + * @Column(type="simple_array", nullable=true) * * @var array */ - private $tags; - - public function getTags() - { - return $this->tags; - } - - public function setTags(array $tags) - { - $this->tags = $tags; - } + public $tags; } diff --git a/tests/Doctrine/Tests/Models/Issue5989/Issue5989Manager.php b/tests/Doctrine/Tests/Models/Issue5989/Issue5989Manager.php index 32c05398487..e00067d9c57 100644 --- a/tests/Doctrine/Tests/Models/Issue5989/Issue5989Manager.php +++ b/tests/Doctrine/Tests/Models/Issue5989/Issue5989Manager.php @@ -9,19 +9,9 @@ class Issue5989Manager extends Issue5989Person { /** - * @column(type="simple_array", nullable=true) + * @Column(type="simple_array", nullable=true) * * @var array */ - private $tags; - - public function getTags() - { - return $this->tags; - } - - public function setTags(array $tags) - { - $this->tags = $tags; - } + public $tags; } diff --git a/tests/Doctrine/Tests/Models/Issue5989/Issue5989Person.php b/tests/Doctrine/Tests/Models/Issue5989/Issue5989Person.php index c9e00c4c188..d31e65def25 100644 --- a/tests/Doctrine/Tests/Models/Issue5989/Issue5989Person.php +++ b/tests/Doctrine/Tests/Models/Issue5989/Issue5989Person.php @@ -20,10 +20,5 @@ class Issue5989Person * @Column(type="integer") * @GeneratedValue */ - private $id; - - public function getId() - { - return $this->id; - } + public $id; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Issue5989Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Issue5989Test.php index 29a5a3fa2b0..cf601b99aed 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Issue5989Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Issue5989Test.php @@ -21,20 +21,20 @@ public function testSimpleArrayTypeHydratedCorrectlyInJoinedInheritance() { $manager = new Issue5989Manager(); - $managerTags = array('tag1', 'tag2'); - $manager->setTags($managerTags); + $managerTags = ['tag1', 'tag2']; + $manager->tags = $managerTags; $this->_em->persist($manager); $employee = new Issue5989Employee(); - $employeeTags = array('tag2', 'tag3'); - $employee->setTags($employeeTags); + $employeeTags =['tag2', 'tag3']; + $employee->tags = $employeeTags; $this->_em->persist($employee); $this->_em->flush(); - $managerId = $manager->getId(); - $employeeId = $employee->getId(); + $managerId = $manager->id; + $employeeId = $employee->id; // clear entity manager so that $repository->find actually fetches them and uses the hydrator // instead of just returning the existing managed entities @@ -45,7 +45,7 @@ public function testSimpleArrayTypeHydratedCorrectlyInJoinedInheritance() $manager = $repository->find($managerId); $employee = $repository->find($employeeId); - static::assertEquals($managerTags, $manager->getTags()); - static::assertEquals($employeeTags, $employee->getTags()); + static::assertEquals($managerTags, $manager->tags); + static::assertEquals($employeeTags, $employee->tags); } } From 43d22984ae56facfba103a5d8e2361ba75fac8ca Mon Sep 17 00:00:00 2001 From: Carl Vuorinen Date: Thu, 8 Sep 2016 13:50:28 +0300 Subject: [PATCH 057/877] Add unit test for SimpleObjectHydrator --- .../Hydration/SimpleObjectHydratorTest.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php index eb33c23c2cf..d567188342a 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php @@ -86,4 +86,34 @@ public function testInvalidDiscriminatorValueException() $hydrator = new \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator($this->_em); $hydrator->hydrateAll($stmt, $rsm); } + + /** + * @group issue-5989 + */ + public function testNullValueShouldNotOverwriteFieldWithSameNameInJoinedInheritance() + { + $rsm = new ResultSetMapping; + $rsm->addEntityResult('Doctrine\Tests\Models\Issue5989\Issue5989Person', 'p'); + $rsm->addFieldResult('p', 'p__id', 'id'); + $rsm->addFieldResult('p', 'm__tags', 'tags', 'Doctrine\Tests\Models\Issue5989\Issue5989Manager'); + $rsm->addFieldResult('p', 'e__tags', 'tags', 'Doctrine\Tests\Models\Issue5989\Issue5989Employee'); + $rsm->addMetaResult('p', 'discr', 'discr', false, 'string'); + $resultSet = array( + array( + 'p__id' => '1', + 'm__tags' => 'tag1,tag2', + 'e__tags' => null, + 'discr' => 'manager' + ), + ); + + $expectedEntity = new \Doctrine\Tests\Models\Issue5989\Issue5989Manager(); + $expectedEntity->id = 1; + $expectedEntity->tags = ['tag1', 'tag2']; + + $stmt = new HydratorMockStatement($resultSet); + $hydrator = new \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator($this->_em); + $result = $hydrator->hydrateAll($stmt, $rsm); + $this->assertEquals($result[0], $expectedEntity); + } } From 16a3a2a1326d902721e7cea3bab05e4a3e8c3875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Fri, 2 Sep 2016 09:53:41 +0000 Subject: [PATCH 058/877] Use microtime to have more precision on cache time --- UPGRADE.md | 6 ++++++ lib/Doctrine/ORM/Cache/QueryCacheEntry.php | 8 ++++---- lib/Doctrine/ORM/Cache/TimestampQueryCacheValidator.php | 2 +- tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index ed9a538b3ec..2195f5b820d 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,11 @@ # Upgrade to 2.5 +## Minor BC BREAK: query cache key time is now a float + +As of 2.5, the `QueryCacheEntry#time` property will contain a float value +instead of an integer in order to have more precision and also to be consistent +with the `TimestampCacheEntry#time`. + ## Minor BC BREAK: discriminator map must now include all non-transient classes It is now required that you declare the root of an inheritance in the diff --git a/lib/Doctrine/ORM/Cache/QueryCacheEntry.php b/lib/Doctrine/ORM/Cache/QueryCacheEntry.php index 74e4cdda561..b6af393fde1 100644 --- a/lib/Doctrine/ORM/Cache/QueryCacheEntry.php +++ b/lib/Doctrine/ORM/Cache/QueryCacheEntry.php @@ -38,18 +38,18 @@ class QueryCacheEntry implements CacheEntry /** * READ-ONLY: Public only for performance reasons, it should be considered immutable. * - * @var integer Time creation of this cache entry + * @var float Time creation of this cache entry */ public $time; /** - * @param array $result - * @param integer $time + * @param array $result + * @param float $time */ public function __construct($result, $time = null) { $this->result = $result; - $this->time = $time ?: time(); + $this->time = $time ?: microtime(true); } /** diff --git a/lib/Doctrine/ORM/Cache/TimestampQueryCacheValidator.php b/lib/Doctrine/ORM/Cache/TimestampQueryCacheValidator.php index 4e504e4f8da..71ac3e828c6 100644 --- a/lib/Doctrine/ORM/Cache/TimestampQueryCacheValidator.php +++ b/lib/Doctrine/ORM/Cache/TimestampQueryCacheValidator.php @@ -35,6 +35,6 @@ public function isValid(QueryCacheKey $key, QueryCacheEntry $entry) return true; } - return ($entry->time + $key->lifetime) > time(); + return ($entry->time + $key->lifetime) > microtime(true); } } diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php index b183eaed4dc..8fa09bac646 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php @@ -436,7 +436,7 @@ public function testGetShouldIgnoreOldQueryCacheEntryResult() array('id'=>2, 'name' => 'Bar') ); - $entry->time = time() - 100; + $entry->time = microtime(true) - 100; $this->region->addReturn('get', $entry); $this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $entities[0])); From b49026b657f093a5ba0084c63f8d7d55bfce320d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 7 Sep 2016 22:19:45 +0000 Subject: [PATCH 059/877] Add timestamp key to QueryCacheKey --- lib/Doctrine/ORM/AbstractQuery.php | 35 ++++++++++++++---- .../Entity/AbstractEntityPersister.php | 36 +++++++++---------- lib/Doctrine/ORM/Cache/QueryCacheKey.php | 29 ++++++++++----- 3 files changed, 68 insertions(+), 32 deletions(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 581a99c429a..0089eeede1b 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -28,6 +28,7 @@ use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\ORM\Cache; +use Doctrine\ORM\Query\ResultSetMapping; /** * Base contract for ORM queries. Base class for Query and NativeQuery. @@ -991,32 +992,54 @@ private function executeIgnoreQueryCache($parameters = null, $hydrationMode = nu private function executeUsingQueryCache($parameters = null, $hydrationMode = null) { $rsm = $this->getResultSetMapping(); - $querykey = new QueryCacheKey($this->getHash(), $this->lifetime, $this->cacheMode ?: Cache::MODE_NORMAL); $queryCache = $this->_em->getCache()->getQueryCache($this->cacheRegion); - $result = $queryCache->get($querykey, $rsm, $this->_hints); + $queryKey = new QueryCacheKey( + $this->getHash(), + $this->lifetime, + $this->cacheMode ?: Cache::MODE_NORMAL, + $this->getTimestampKey() + ); + + $result = $queryCache->get($queryKey, $rsm, $this->_hints); if ($result !== null) { if ($this->cacheLogger) { - $this->cacheLogger->queryCacheHit($queryCache->getRegion()->getName(), $querykey); + $this->cacheLogger->queryCacheHit($queryCache->getRegion()->getName(), $queryKey); } return $result; } $result = $this->executeIgnoreQueryCache($parameters, $hydrationMode); - $cached = $queryCache->put($querykey, $rsm, $result, $this->_hints); + $cached = $queryCache->put($queryKey, $rsm, $result, $this->_hints); if ($this->cacheLogger) { - $this->cacheLogger->queryCacheMiss($queryCache->getRegion()->getName(), $querykey); + $this->cacheLogger->queryCacheMiss($queryCache->getRegion()->getName(), $queryKey); if ($cached) { - $this->cacheLogger->queryCachePut($queryCache->getRegion()->getName(), $querykey); + $this->cacheLogger->queryCachePut($queryCache->getRegion()->getName(), $queryKey); } } return $result; } + /** + * @return \Doctrine\ORM\Cache\TimestampCacheKey|null + */ + private function getTimestampKey() + { + $entityName = reset($this->_resultSetMapping->aliasMap); + + if (empty($entityName)) { + return null; + } + + $metadata = $this->_em->getClassMetadata($entityName); + + return new Cache\TimestampCacheKey($metadata->getTableName()); + } + /** * Get the result cache id to use to store the result set cache entry. * Will return the configured id if it exists otherwise a hash will be diff --git a/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php b/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php index 5690f9169c2..75e28ec1b1e 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php @@ -372,13 +372,13 @@ public function load(array $criteria, $entity = null, $assoc = null, array $hint $query = $this->persister->getSelectSQL($criteria, null, null, $limit, null, $orderBy); $hash = $this->getHash($query, $criteria, null, null, null, $timestamp ? $timestamp->time : null); $rsm = $this->getResultSetMapping(); - $querykey = new QueryCacheKey($hash, 0, Cache::MODE_NORMAL); + $queryKey = new QueryCacheKey($hash, 0, Cache::MODE_NORMAL, $this->timestampKey); $queryCache = $this->cache->getQueryCache($this->regionName); - $result = $queryCache->get($querykey, $rsm); + $result = $queryCache->get($queryKey, $rsm); if ($result !== null) { if ($this->cacheLogger) { - $this->cacheLogger->queryCacheHit($this->regionName, $querykey); + $this->cacheLogger->queryCacheHit($this->regionName, $queryKey); } return $result[0]; @@ -388,15 +388,15 @@ public function load(array $criteria, $entity = null, $assoc = null, array $hint return null; } - $cached = $queryCache->put($querykey, $rsm, array($result)); + $cached = $queryCache->put($queryKey, $rsm, array($result)); if ($this->cacheLogger) { if ($result) { - $this->cacheLogger->queryCacheMiss($this->regionName, $querykey); + $this->cacheLogger->queryCacheMiss($this->regionName, $queryKey); } if ($cached) { - $this->cacheLogger->queryCachePut($this->regionName, $querykey); + $this->cacheLogger->queryCachePut($this->regionName, $queryKey); } } @@ -412,28 +412,28 @@ public function loadAll(array $criteria = array(), array $orderBy = null, $limit $query = $this->persister->getSelectSQL($criteria, null, null, $limit, $offset, $orderBy); $hash = $this->getHash($query, $criteria, null, null, null, $timestamp ? $timestamp->time : null); $rsm = $this->getResultSetMapping(); - $querykey = new QueryCacheKey($hash, 0, Cache::MODE_NORMAL); + $queryKey = new QueryCacheKey($hash, 0, Cache::MODE_NORMAL, $this->timestampKey); $queryCache = $this->cache->getQueryCache($this->regionName); - $result = $queryCache->get($querykey, $rsm); + $result = $queryCache->get($queryKey, $rsm); if ($result !== null) { if ($this->cacheLogger) { - $this->cacheLogger->queryCacheHit($this->regionName, $querykey); + $this->cacheLogger->queryCacheHit($this->regionName, $queryKey); } return $result; } $result = $this->persister->loadAll($criteria, $orderBy, $limit, $offset); - $cached = $queryCache->put($querykey, $rsm, $result); + $cached = $queryCache->put($queryKey, $rsm, $result); if ($this->cacheLogger) { if ($result) { - $this->cacheLogger->queryCacheMiss($this->regionName, $querykey); + $this->cacheLogger->queryCacheMiss($this->regionName, $queryKey); } if ($cached) { - $this->cacheLogger->queryCachePut($this->regionName, $querykey); + $this->cacheLogger->queryCachePut($this->regionName, $queryKey); } } @@ -514,28 +514,28 @@ public function loadCriteria(Criteria $criteria) $timestamp = $this->timestampRegion->get($this->timestampKey); $hash = $this->getHash($query, $criteria, $orderBy, $limit, $offset, $timestamp ? $timestamp->time : null); $rsm = $this->getResultSetMapping(); - $querykey = new QueryCacheKey($hash, 0, Cache::MODE_NORMAL); + $queryKey = new QueryCacheKey($hash, 0, Cache::MODE_NORMAL, $this->timestampKey); $queryCache = $this->cache->getQueryCache($this->regionName); - $cacheResult = $queryCache->get($querykey, $rsm); + $cacheResult = $queryCache->get($queryKey, $rsm); if ($cacheResult !== null) { if ($this->cacheLogger) { - $this->cacheLogger->queryCacheHit($this->regionName, $querykey); + $this->cacheLogger->queryCacheHit($this->regionName, $queryKey); } return $cacheResult; } $result = $this->persister->loadCriteria($criteria); - $cached = $queryCache->put($querykey, $rsm, $result); + $cached = $queryCache->put($queryKey, $rsm, $result); if ($this->cacheLogger) { if ($result) { - $this->cacheLogger->queryCacheMiss($this->regionName, $querykey); + $this->cacheLogger->queryCacheMiss($this->regionName, $queryKey); } if ($cached) { - $this->cacheLogger->queryCachePut($this->regionName, $querykey); + $this->cacheLogger->queryCachePut($this->regionName, $queryKey); } } diff --git a/lib/Doctrine/ORM/Cache/QueryCacheKey.php b/lib/Doctrine/ORM/Cache/QueryCacheKey.php index 9a7d2b7bcc8..0e072a36fc0 100644 --- a/lib/Doctrine/ORM/Cache/QueryCacheKey.php +++ b/lib/Doctrine/ORM/Cache/QueryCacheKey.php @@ -45,14 +45,27 @@ class QueryCacheKey extends CacheKey public $cacheMode; /** - * @param string $hash Result cache id - * @param integer $lifetime Query lifetime - * @param integer $cacheMode Query cache mode + * READ-ONLY: Public only for performance reasons, it should be considered immutable. + * + * @var TimestampCacheKey|null + */ + public $timestampKey; + + /** + * @param string $hash Result cache id + * @param integer $lifetime Query lifetime + * @param int $cacheMode Query cache mode + * @param TimestampCacheKey|null $timestampKey */ - public function __construct($hash, $lifetime = 0, $cacheMode = Cache::MODE_NORMAL) - { - $this->hash = $hash; - $this->lifetime = $lifetime; - $this->cacheMode = $cacheMode; + public function __construct( + $hash, + $lifetime = 0, + $cacheMode = Cache::MODE_NORMAL, + TimestampCacheKey $timestampKey = null + ) { + $this->hash = $hash; + $this->lifetime = $lifetime; + $this->cacheMode = $cacheMode; + $this->timestampKey = $timestampKey; } } From b431332cefe8e968d6af73033eaffc472eec7d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Fri, 2 Sep 2016 09:54:14 +0000 Subject: [PATCH 060/877] Evict query cache when entities are updated --- lib/Doctrine/ORM/Cache/CacheConfiguration.php | 4 ++- .../Cache/TimestampQueryCacheValidator.php | 34 ++++++++++++++++++ .../Tests/ORM/Cache/CacheConfigTest.php | 8 ++++- .../SecondLevelCacheQueryCacheTest.php | 35 ++++++++++++++++++- 4 files changed, 78 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Cache/CacheConfiguration.php b/lib/Doctrine/ORM/Cache/CacheConfiguration.php index 4891cac4909..eb3ec428df3 100644 --- a/lib/Doctrine/ORM/Cache/CacheConfiguration.php +++ b/lib/Doctrine/ORM/Cache/CacheConfiguration.php @@ -110,7 +110,9 @@ public function setRegionsConfiguration(RegionsConfiguration $regionsConfig) public function getQueryValidator() { if ($this->queryValidator === null) { - $this->queryValidator = new TimestampQueryCacheValidator(); + $this->queryValidator = new TimestampQueryCacheValidator( + $this->cacheFactory->getTimestampRegion() + ); } return $this->queryValidator; diff --git a/lib/Doctrine/ORM/Cache/TimestampQueryCacheValidator.php b/lib/Doctrine/ORM/Cache/TimestampQueryCacheValidator.php index 71ac3e828c6..c6404d3b25d 100644 --- a/lib/Doctrine/ORM/Cache/TimestampQueryCacheValidator.php +++ b/lib/Doctrine/ORM/Cache/TimestampQueryCacheValidator.php @@ -26,15 +26,49 @@ */ class TimestampQueryCacheValidator implements QueryCacheValidator { + /** + * @var TimestampRegion + */ + private $timestampRegion; + + /** + * @param TimestampRegion $timestampRegion + */ + public function __construct(TimestampRegion $timestampRegion) + { + $this->timestampRegion = $timestampRegion; + } + /** * {@inheritdoc} */ public function isValid(QueryCacheKey $key, QueryCacheEntry $entry) { + if ($this->regionUpdated($key, $entry)) { + return false; + } + if ($key->lifetime == 0) { return true; } return ($entry->time + $key->lifetime) > microtime(true); } + + /** + * @param QueryCacheKey $key + * @param QueryCacheEntry $entry + * + * @return bool + */ + private function regionUpdated(QueryCacheKey $key, QueryCacheEntry $entry) + { + if ($key->timestampKey === null) { + return false; + } + + $timestamp = $this->timestampRegion->get($key->timestampKey); + + return $timestamp && $timestamp->time > $entry->time; + } } diff --git a/tests/Doctrine/Tests/ORM/Cache/CacheConfigTest.php b/tests/Doctrine/Tests/ORM/Cache/CacheConfigTest.php index 321207c39ba..0de086387a0 100644 --- a/tests/Doctrine/Tests/ORM/Cache/CacheConfigTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/CacheConfigTest.php @@ -6,6 +6,7 @@ use Doctrine\ORM\Cache\CacheFactory; use Doctrine\ORM\Cache\QueryCacheValidator; use Doctrine\ORM\Cache\Logging\CacheLogger; +use Doctrine\ORM\Cache\TimestampRegion; use Doctrine\Tests\DoctrineTestCase; /** @@ -67,6 +68,11 @@ public function testSetGetCacheFactory() public function testSetGetQueryValidator() { + $factory = $this->createMock(CacheFactory::class); + $factory->method('getTimestampRegion')->willReturn($this->createMock(TimestampRegion::class)); + + $this->config->setCacheFactory($factory); + $validator = $this->createMock(QueryCacheValidator::class); $this->assertInstanceOf('Doctrine\ORM\Cache\TimestampQueryCacheValidator', $this->config->getQueryValidator()); @@ -75,4 +81,4 @@ public function testSetGetQueryValidator() $this->assertEquals($validator, $this->config->getQueryValidator()); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheQueryCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheQueryCacheTest.php index 97d8ce82a1c..b34b0f82565 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheQueryCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheQueryCacheTest.php @@ -1120,4 +1120,37 @@ public function testNonCacheableQueryUpdateStatementException() ->setCacheable(true) ->getResult(); } -} \ No newline at end of file + + public function testQueryCacheShouldBeEvictedOnTimestampUpdate() + { + $this->loadFixturesCountries(); + $this->_em->clear(); + + $queryCount = $this->getCurrentQueryCount(); + $dql = 'SELECT country FROM Doctrine\Tests\Models\Cache\Country country'; + + $result1 = $this->_em->createQuery($dql) + ->setCacheable(true) + ->getResult(); + + $this->assertCount(2, $result1); + $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); + + $this->_em->persist(new Country('France')); + $this->_em->flush(); + $this->_em->clear(); + + $queryCount = $this->getCurrentQueryCount(); + + $result2 = $this->_em->createQuery($dql) + ->setCacheable(true) + ->getResult(); + + $this->assertCount(3, $result2); + $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); + + foreach ($result2 as $entity) { + $this->assertInstanceOf(Country::CLASSNAME, $entity); + } + } +} From dd476094af6e811a394ec048ba96b9cfa48811f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 7 Sep 2016 22:32:59 +0000 Subject: [PATCH 061/877] The timestamp verification is now done by the validator So it's useless to keep it here too. --- .../Persister/Entity/AbstractEntityPersister.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php b/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php index 75e28ec1b1e..1a41014b94f 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php @@ -287,17 +287,16 @@ private function storeJoinedAssociations($entity) * @param array $orderBy * @param integer $limit * @param integer $offset - * @param integer $timestamp * * @return string */ - protected function getHash($query, $criteria, array $orderBy = null, $limit = null, $offset = null, $timestamp = null) + protected function getHash($query, $criteria, array $orderBy = null, $limit = null, $offset = null) { list($params) = ($criteria instanceof Criteria) ? $this->persister->expandCriteriaParameters($criteria) : $this->persister->expandParameters($criteria); - return sha1($query . serialize($params) . serialize($orderBy) . $limit . $offset . $timestamp); + return sha1($query . serialize($params) . serialize($orderBy) . $limit . $offset); } /** @@ -368,9 +367,8 @@ public function load(array $criteria, $entity = null, $assoc = null, array $hint } //handle only EntityRepository#findOneBy - $timestamp = $this->timestampRegion->get($this->timestampKey); $query = $this->persister->getSelectSQL($criteria, null, null, $limit, null, $orderBy); - $hash = $this->getHash($query, $criteria, null, null, null, $timestamp ? $timestamp->time : null); + $hash = $this->getHash($query, $criteria, null, null, null); $rsm = $this->getResultSetMapping(); $queryKey = new QueryCacheKey($hash, 0, Cache::MODE_NORMAL, $this->timestampKey); $queryCache = $this->cache->getQueryCache($this->regionName); @@ -408,9 +406,8 @@ public function load(array $criteria, $entity = null, $assoc = null, array $hint */ public function loadAll(array $criteria = array(), array $orderBy = null, $limit = null, $offset = null) { - $timestamp = $this->timestampRegion->get($this->timestampKey); $query = $this->persister->getSelectSQL($criteria, null, null, $limit, $offset, $orderBy); - $hash = $this->getHash($query, $criteria, null, null, null, $timestamp ? $timestamp->time : null); + $hash = $this->getHash($query, $criteria, null, null, null); $rsm = $this->getResultSetMapping(); $queryKey = new QueryCacheKey($hash, 0, Cache::MODE_NORMAL, $this->timestampKey); $queryCache = $this->cache->getQueryCache($this->regionName); @@ -511,8 +508,7 @@ public function loadCriteria(Criteria $criteria) $limit = $criteria->getMaxResults(); $offset = $criteria->getFirstResult(); $query = $this->persister->getSelectSQL($criteria); - $timestamp = $this->timestampRegion->get($this->timestampKey); - $hash = $this->getHash($query, $criteria, $orderBy, $limit, $offset, $timestamp ? $timestamp->time : null); + $hash = $this->getHash($query, $criteria, $orderBy, $limit, $offset); $rsm = $this->getResultSetMapping(); $queryKey = new QueryCacheKey($hash, 0, Cache::MODE_NORMAL, $this->timestampKey); $queryCache = $this->cache->getQueryCache($this->regionName); From d27cffa8e65574c0468388f48977ac4859d44e1a Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 8 Sep 2016 13:51:21 +0200 Subject: [PATCH 062/877] #6001 documenting minor BC break in `QueryCacheEntry#time` type - specific version used --- UPGRADE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UPGRADE.md b/UPGRADE.md index 2195f5b820d..b71e10adb65 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -2,7 +2,7 @@ ## Minor BC BREAK: query cache key time is now a float -As of 2.5, the `QueryCacheEntry#time` property will contain a float value +As of 2.5.5, the `QueryCacheEntry#time` property will contain a float value instead of an integer in order to have more precision and also to be consistent with the `TimestampCacheEntry#time`. From 5353137617345555ffba689d5a4b3ca451683222 Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Thu, 8 Sep 2016 13:32:06 -0300 Subject: [PATCH 063/877] Update exception message at `EntityRepository::__call()` --- lib/Doctrine/ORM/EntityRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index 0c28237570f..1934a18d0c7 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -237,7 +237,7 @@ public function __call($method, $arguments) throw new \BadMethodCallException( "Undefined method '$method'. The method name must start with ". - "either findBy or findOneBy!" + "either findBy, findOneBy or countBy!" ); } From e43b9e9e3a14f90213e4c8fe52f08e9df9cc1c3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Fri, 9 Sep 2016 07:52:44 +0000 Subject: [PATCH 064/877] Use `isIdGeneratorIdentity()` to add the ID on query It's quite handy when creating CUSTOM id generators that should also rely on AUTO_INCREMENT stuff (one can just extend the `ClassMedatadaFactory` and create a different instance of `ClassMetadata` that overrides that method). --- lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index c62a10a120c..d577df6d9a5 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -1442,7 +1442,7 @@ protected function getInsertColumnList() continue; } - if ($this->class->generatorType != ClassMetadata::GENERATOR_TYPE_IDENTITY || $this->class->identifier[0] != $name) { + if (! $this->class->isIdGeneratorIdentity() || $this->class->identifier[0] != $name) { $columns[] = $this->quoteStrategy->getColumnName($name, $this->class, $this->platform); $this->columnTypes[$name] = $this->class->fieldMappings[$name]['type']; } From 60346e00469c9a06d2428e57d7132d2a4c32c57e Mon Sep 17 00:00:00 2001 From: guhelski Date: Fri, 9 Sep 2016 16:46:35 +0200 Subject: [PATCH 065/877] Fix typo --- docs/en/tutorials/embeddables.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/tutorials/embeddables.rst b/docs/en/tutorials/embeddables.rst index 681aa75366d..1dcb3c1477a 100644 --- a/docs/en/tutorials/embeddables.rst +++ b/docs/en/tutorials/embeddables.rst @@ -1,7 +1,7 @@ Separating Concerns using Embeddables ------------------------------------- -Embeddables are classes which are not entities themself, but are embedded +Embeddables are classes which are not entities themselves, but are embedded in entities and can also be queried in DQL. You'll mostly want to use them to reduce duplication or separating concerns. Value objects such as date range or address are the primary use case for this feature. Embeddables can only From 48dcbe9d354575a973ad27987bb4d6e0ad8481b2 Mon Sep 17 00:00:00 2001 From: Walt Sorensen Date: Fri, 9 Sep 2016 15:18:48 -0600 Subject: [PATCH 066/877] As of HHVM 3.15 pgsql is supported --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5a9fb2dcb0c..8f1ccf1f210 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,9 +52,6 @@ matrix: env: DB=mariadb addons: mariadb: 10.1 - exclude: - - php: hhvm - env: DB=pgsql # driver for PostgreSQL currently unsupported by HHVM, requires 3rd party dependency allow_failures: - php: nightly From 01d51bfca391e49bbb596c90d1a9c4766533155a Mon Sep 17 00:00:00 2001 From: Mathieu De Zutter Date: Tue, 1 Mar 2016 10:58:37 +0100 Subject: [PATCH 067/877] Avoid conflicts due to spl_object_hash(). When merging an entity with a to-many association, it will store the original entity data using the object hash of the to-be-merged entity instead of the managed entity. Since this to-be-merged entity is not managed by Doctrine, it can disappear from the memory. A new object can reuse the same memory location and thus have the same object hash. When one tries to persist this object as new, Doctrine will refuse it because it thinks that the entity is managed+dirty. This patch is a very naive fix: it just disables storing the original entity data in case of to-many associations. It may not be the ideal or even a good solution at all, but it solves the problem of object hash reuse. The test case relies on the immediate reusing of memory locations by PHP. The variable $user has twice the same object hash, though referring a different object. Tested on PHP 5.6.17 Without the fix, the test fails on the last line with: A managed+dirty entity Doctrine\Tests\Models\CMS\CmsUser@[...] can not be scheduled for insertion. --- lib/Doctrine/ORM/UnitOfWork.php | 2 +- .../Tests/ORM/Functional/OidReuseTest.php | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/OidReuseTest.php diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 7ac24cc6028..403ab668dc3 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -3405,7 +3405,7 @@ private function mergeEntityStateIntoManagedCopy($entity, $managedCopy) $managedCol->setOwner($managedCopy, $assoc2); $prop->setValue($managedCopy, $managedCol); - $this->originalEntityData[spl_object_hash($entity)][$name] = $managedCol; +// $this->originalEntityData[spl_object_hash($entity)][$name] = $managedCol; } if ($assoc2['isCascadeMerge']) { diff --git a/tests/Doctrine/Tests/ORM/Functional/OidReuseTest.php b/tests/Doctrine/Tests/ORM/Functional/OidReuseTest.php new file mode 100644 index 00000000000..40aaf423830 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/OidReuseTest.php @@ -0,0 +1,34 @@ +useModelSet('cms'); + parent::setUp(); + } + + public function testOidReuse() + { + $user = new CmsUser(); + $this->_em->merge($user); + + $user = null; + + $user = new CmsUser(); + $this->_em->persist($user); + } + +} \ No newline at end of file From b8c7d871bee7a4290551439ce65c7a66cf92041d Mon Sep 17 00:00:00 2001 From: Mathieu De Zutter Date: Tue, 1 Mar 2016 19:36:57 +0100 Subject: [PATCH 068/877] Remove old code in comments. --- lib/Doctrine/ORM/UnitOfWork.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 403ab668dc3..59ee1c1cb7b 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -3404,8 +3404,6 @@ private function mergeEntityStateIntoManagedCopy($entity, $managedCopy) ); $managedCol->setOwner($managedCopy, $assoc2); $prop->setValue($managedCopy, $managedCol); - -// $this->originalEntityData[spl_object_hash($entity)][$name] = $managedCol; } if ($assoc2['isCascadeMerge']) { From 44af69c5d2299e46f90a94e91c35711afe8392de Mon Sep 17 00:00:00 2001 From: Mathieu De Zutter Date: Tue, 1 Mar 2016 19:51:38 +0100 Subject: [PATCH 069/877] Additional assertion to check that unreferenced objects are not in UOW. --- tests/Doctrine/Tests/ORM/Functional/OidReuseTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/OidReuseTest.php b/tests/Doctrine/Tests/ORM/Functional/OidReuseTest.php index 40aaf423830..742b183fe33 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OidReuseTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OidReuseTest.php @@ -22,11 +22,19 @@ protected function setUp() public function testOidReuse() { + $uow = $this->_em->getUnitOfWork(); + $reflexion = new \ReflectionClass(get_class($uow)); + $originalEntityDataProperty = $reflexion->getProperty('originalEntityData'); + $originalEntityDataProperty->setAccessible(true); + $user = new CmsUser(); + $oid = spl_object_hash($user); $this->_em->merge($user); $user = null; + $this->assertArrayNotHasKey($oid, $originalEntityDataProperty->getValue($uow)); + $user = new CmsUser(); $this->_em->persist($user); } From d7a0ed0611077d46fc3e1b8573ed7956cfc91e03 Mon Sep 17 00:00:00 2001 From: Walt Sorensen Date: Fri, 9 Sep 2016 15:35:33 -0600 Subject: [PATCH 070/877] pin to HHVM 3.15 and add PHP 7.1 Stop testing against old HHVM 3.9 and test against current LTS 3.15 --- .travis.yml | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8f1ccf1f210..ba3e61bfb93 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,8 @@ language: php php: - 5.6 - 7.0 + - 7.1 - nightly - - hhvm env: - DB=mysql @@ -27,6 +27,32 @@ after_script: matrix: include: + - php: hhvm-3.15 + sudo: true + dist: trusty + group: edge # until the next update + addons: + apt: + packages: + - mysql-server-5.6 + - mysql-client-core-5.6 + - mysql-client-5.6 + services: + - mysql + env: DB=mysql + - php: hhvm-3.15 + sudo: true + dist: trusty + group: edge # until the next update + services: + - postgresql + env: DB=pgsql + - php: hhvm-3.15 + sudo: true + dist: trusty + group: edge # until the next update + env: DB=sqlite + - php: 5.6 env: DB=mariadb addons: @@ -35,10 +61,17 @@ matrix: env: DB=mariadb addons: mariadb: 5.5 - - php: hhvm + - php: 7.1 env: DB=mariadb addons: mariadb: 5.5 + - php: hhvm-3.15 + sudo: true + dist: trusty + group: edge # until the next Trusty update + addons: + mariadb: 5.5 + env: DB=mariadb - php: 5.6 env: DB=mariadb @@ -48,11 +81,19 @@ matrix: env: DB=mariadb addons: mariadb: 10.1 - - php: hhvm + - php: 7.1 env: DB=mariadb addons: mariadb: 10.1 + - php: hhvm-3.15 + sudo: true + dist: trusty + group: edge # until the next Trusty update + addons: + mariadb: 10.1 + env: DB=mariadb allow_failures: + - php: 7.1 - php: nightly sudo: false From e52ca954f0aa2190ab66ef7c89eac1a8b2d09234 Mon Sep 17 00:00:00 2001 From: Walt Sorensen Date: Fri, 9 Sep 2016 15:42:31 -0600 Subject: [PATCH 071/877] fixing the xdebug error with php 7.1, nightly and HHVM-3.15 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ba3e61bfb93..96dba18a78e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ env: before_script: - if [[ $TRAVIS_PHP_VERSION = '7.0' && $DB = 'sqlite' ]]; then PHPUNIT_FLAGS="--coverage-clover ./build/logs/clover.xml"; else PHPUNIT_FLAGS=""; fi - - if [[ $TRAVIS_PHP_VERSION != '7.0' && $TRAVIS_PHP_VERSION != 'hhvm' ]]; then phpenv config-rm xdebug.ini; fi + - if [[ $TRAVIS_PHP_VERSION -lt '7.0' && $TRAVIS_PHP_VERSION != 'hhv*' ]]; then phpenv config-rm xdebug.ini; fi - composer self-update - composer install --prefer-source From a879811b6c0b80031e6dbbf4137bed80c8f21482 Mon Sep 17 00:00:00 2001 From: Walt Sorensen Date: Fri, 9 Sep 2016 15:51:34 -0600 Subject: [PATCH 072/877] Fast finish to avoid waiting on allowed failures Also Allow HHVM 3.15 with pgsql to fail --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 96dba18a78e..d497867dfad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,6 +26,7 @@ after_script: - if [[ $TRAVIS_PHP_VERSION = '7.0' && $DB = 'sqlite' ]]; then php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml; fi matrix: + fast_finish: true include: - php: hhvm-3.15 sudo: true @@ -95,6 +96,8 @@ matrix: allow_failures: - php: 7.1 - php: nightly + - php: hhvm-3.15 + env: DB=pgsql sudo: false From fda2cd7d0e8fe4ebc1e7be6062e88349ba9d9995 Mon Sep 17 00:00:00 2001 From: Walt Sorensen Date: Fri, 9 Sep 2016 15:59:23 -0600 Subject: [PATCH 073/877] Set all HHVM-3.15 to allowed failure --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d497867dfad..a18cfd21a98 100644 --- a/.travis.yml +++ b/.travis.yml @@ -97,7 +97,6 @@ matrix: - php: 7.1 - php: nightly - php: hhvm-3.15 - env: DB=pgsql sudo: false From 1f521d26f360c8d85fda29a8ea5a1763e4dd349e Mon Sep 17 00:00:00 2001 From: Walt Sorensen Date: Fri, 9 Sep 2016 17:21:03 -0600 Subject: [PATCH 074/877] Set to HHVM latest (currently 3.15 until next release) Move sudo: false to the top line to be more clear about use of containers as default vs the trusty builds for HHVM --- .travis.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index a18cfd21a98..f1963e0d2a5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +sudo: false language: php php: @@ -28,7 +29,7 @@ after_script: matrix: fast_finish: true include: - - php: hhvm-3.15 + - php: hhvm sudo: true dist: trusty group: edge # until the next update @@ -41,14 +42,14 @@ matrix: services: - mysql env: DB=mysql - - php: hhvm-3.15 + - php: hhvm sudo: true dist: trusty group: edge # until the next update services: - postgresql env: DB=pgsql - - php: hhvm-3.15 + - php: hhvm sudo: true dist: trusty group: edge # until the next update @@ -66,7 +67,7 @@ matrix: env: DB=mariadb addons: mariadb: 5.5 - - php: hhvm-3.15 + - php: hhvm sudo: true dist: trusty group: edge # until the next Trusty update @@ -96,9 +97,7 @@ matrix: allow_failures: - php: 7.1 - php: nightly - - php: hhvm-3.15 - -sudo: false + - php: hhvm cache: directories: From 29f51b4a26780ece722029f6b6b1ac3e9ca618ef Mon Sep 17 00:00:00 2001 From: Walt Sorensen Date: Fri, 9 Sep 2016 18:00:40 -0600 Subject: [PATCH 075/877] Remove the last hhvm3.15 tag --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f1963e0d2a5..7098ab84d40 100644 --- a/.travis.yml +++ b/.travis.yml @@ -87,7 +87,7 @@ matrix: env: DB=mariadb addons: mariadb: 10.1 - - php: hhvm-3.15 + - php: hhvm sudo: true dist: trusty group: edge # until the next Trusty update From 99d704ff45b1a5f000821e240785fb92a83f7f43 Mon Sep 17 00:00:00 2001 From: Walt Sorensen Date: Sat, 10 Sep 2016 12:15:25 -0600 Subject: [PATCH 076/877] Drop mariadb: 5.5 tests reorder matrix so all HHVM tests are at the bottom --- .travis.yml | 58 ++++++++++++++++++----------------------------------- 1 file changed, 19 insertions(+), 39 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7098ab84d40..4c3b1c6239a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,6 +29,25 @@ after_script: matrix: fast_finish: true include: + - php: 5.6 + env: DB=mariadb + addons: + mariadb: 10.1 + - php: 7.0 + env: DB=mariadb + addons: + mariadb: 10.1 + - php: 7.1 + env: DB=mariadb + addons: + mariadb: 10.1 + - php: hhvm + sudo: true + dist: trusty + group: edge # until the next Trusty update + addons: + mariadb: 10.1 + env: DB=mariadb - php: hhvm sudo: true dist: trusty @@ -55,45 +74,6 @@ matrix: group: edge # until the next update env: DB=sqlite - - php: 5.6 - env: DB=mariadb - addons: - mariadb: 5.5 - - php: 7.0 - env: DB=mariadb - addons: - mariadb: 5.5 - - php: 7.1 - env: DB=mariadb - addons: - mariadb: 5.5 - - php: hhvm - sudo: true - dist: trusty - group: edge # until the next Trusty update - addons: - mariadb: 5.5 - env: DB=mariadb - - - php: 5.6 - env: DB=mariadb - addons: - mariadb: 10.1 - - php: 7.0 - env: DB=mariadb - addons: - mariadb: 10.1 - - php: 7.1 - env: DB=mariadb - addons: - mariadb: 10.1 - - php: hhvm - sudo: true - dist: trusty - group: edge # until the next Trusty update - addons: - mariadb: 10.1 - env: DB=mariadb allow_failures: - php: 7.1 - php: nightly From 75bf197e115ce7f66ff49adc7c96f2f72c896762 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 10 Sep 2016 20:15:33 +0200 Subject: [PATCH 077/877] #5689 moved `OidReuseTest` contents into the `UnitOfWork` tests --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 6a2c882e84e..a604641f85a 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -14,6 +14,7 @@ use Doctrine\Tests\Mocks\EntityPersisterMock; use Doctrine\Tests\Mocks\UnitOfWorkMock; use Doctrine\Tests\Models\CMS\CmsPhonenumber; +use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\Forum\ForumAvatar; use Doctrine\Tests\Models\Forum\ForumUser; use Doctrine\Tests\Models\GeoNames\City; @@ -459,6 +460,38 @@ public function entitiesWithInvalidIdentifiersProvider() 'second null string, two fields' => [$secondNullString, ['id1' => $secondNullString->id1, 'id2' => null]], ]; } + + /** + * @group 5689 + * @group 1465 + */ + public function testObjectHashesOfMergedEntitiesAreNotUsedInOriginalEntityDataMap() + { + $reflectionOriginalEntityData = new \ReflectionProperty('Doctrine\ORM\UnitOfWork', 'originalEntityData'); + + $reflectionOriginalEntityData->setAccessible(true); + + $user = new CmsUser(); + $user->name = 'ocramius'; + $mergedUser = $this->_unitOfWork->merge($user); + + self::assertSame([], $this->_unitOfWork->getOriginalEntityData($user), 'No original data was stored'); + self::assertSame([], $this->_unitOfWork->getOriginalEntityData($mergedUser), 'No original data was stored'); + + + $user = null; + $mergedUser = null; + + // force garbage collection of $user (frees the used object hashes, which may be recycled) + gc_collect_cycles(); + + $newUser = new CmsUser(); + $newUser->name = 'ocramius'; + + $this->_unitOfWork->persist($newUser); + + self::assertSame([], $this->_unitOfWork->getOriginalEntityData($newUser), 'No original data was stored'); + } } /** From f8436b2165ea6878e0fb45dbd3c30493443f544d Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 10 Sep 2016 20:15:59 +0200 Subject: [PATCH 078/877] #5689 removed `OidReuseTest`, which was moved to `UnitOfWork` tests --- .../Tests/ORM/Functional/OidReuseTest.php | 42 ------------------- 1 file changed, 42 deletions(-) delete mode 100644 tests/Doctrine/Tests/ORM/Functional/OidReuseTest.php diff --git a/tests/Doctrine/Tests/ORM/Functional/OidReuseTest.php b/tests/Doctrine/Tests/ORM/Functional/OidReuseTest.php deleted file mode 100644 index 742b183fe33..00000000000 --- a/tests/Doctrine/Tests/ORM/Functional/OidReuseTest.php +++ /dev/null @@ -1,42 +0,0 @@ -useModelSet('cms'); - parent::setUp(); - } - - public function testOidReuse() - { - $uow = $this->_em->getUnitOfWork(); - $reflexion = new \ReflectionClass(get_class($uow)); - $originalEntityDataProperty = $reflexion->getProperty('originalEntityData'); - $originalEntityDataProperty->setAccessible(true); - - $user = new CmsUser(); - $oid = spl_object_hash($user); - $this->_em->merge($user); - - $user = null; - - $this->assertArrayNotHasKey($oid, $originalEntityDataProperty->getValue($uow)); - - $user = new CmsUser(); - $this->_em->persist($user); - } - -} \ No newline at end of file From 503b211a22db02ea825942aacf6dbff87d438aaa Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 10 Sep 2016 20:19:15 +0200 Subject: [PATCH 079/877] #5689 removed unused reflection access --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index a604641f85a..0ff2572b914 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -467,10 +467,6 @@ public function entitiesWithInvalidIdentifiersProvider() */ public function testObjectHashesOfMergedEntitiesAreNotUsedInOriginalEntityDataMap() { - $reflectionOriginalEntityData = new \ReflectionProperty('Doctrine\ORM\UnitOfWork', 'originalEntityData'); - - $reflectionOriginalEntityData->setAccessible(true); - $user = new CmsUser(); $user->name = 'ocramius'; $mergedUser = $this->_unitOfWork->merge($user); From 67e205b36acdc73097b79802b097389a491216b9 Mon Sep 17 00:00:00 2001 From: Ed Hartwell Goose Date: Mon, 11 Apr 2016 17:01:55 +0100 Subject: [PATCH 080/877] Fixes #5755, uses '->getReflectionProperties()' instead of '->getReflectionClass()->getProperties()' to ensure all fields are copied, and adds test to confirm behaviour --- lib/Doctrine/ORM/Proxy/ProxyFactory.php | 2 +- .../Tests/ORM/Proxy/ProxyFactoryTest.php | 50 +++++++++++++++++-- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/ORM/Proxy/ProxyFactory.php b/lib/Doctrine/ORM/Proxy/ProxyFactory.php index 72f161eabf4..58dfc0932e5 100644 --- a/lib/Doctrine/ORM/Proxy/ProxyFactory.php +++ b/lib/Doctrine/ORM/Proxy/ProxyFactory.php @@ -196,7 +196,7 @@ private function createCloner(ClassMetadata $classMetadata, EntityPersister $ent ); } - foreach ($class->getReflectionClass()->getProperties() as $property) { + foreach ($class->getReflectionProperties() as $property) { if ( ! $class->hasField($property->name) && ! $class->hasAssociation($property->name)) { continue; } diff --git a/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php b/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php index dd5b730f67c..1d21207f636 100644 --- a/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php @@ -3,16 +3,17 @@ namespace Doctrine\Tests\ORM\Proxy; use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; +use Doctrine\Common\Proxy\AbstractProxyFactory; use Doctrine\ORM\EntityNotFoundException; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Persisters\Entity\BasicEntityPersister; use Doctrine\ORM\Proxy\ProxyFactory; use Doctrine\Tests\Mocks\ConnectionMock; +use Doctrine\Tests\Mocks\DriverMock; use Doctrine\Tests\Mocks\EntityManagerMock; use Doctrine\Tests\Mocks\UnitOfWorkMock; -use Doctrine\Tests\Mocks\DriverMock; -use Doctrine\Common\Proxy\AbstractProxyFactory; use Doctrine\Tests\OrmTestCase; +use Doctrine\Tests\Models\Company\CompanyEmployee; /** * Test the proxy generator. Its work is generating on-the-fly subclasses of a given model, which implement the Proxy pattern. @@ -65,9 +66,9 @@ public function testReferenceProxyDelegatesLoadingToThePersister() $persister ->expects($this->atLeastOnce()) - ->method('load') - ->with($this->equalTo($identifier), $this->isInstanceOf($proxyClass)) - ->will($this->returnValue(new \stdClass())); + ->method('load') + ->with($this->equalTo($identifier), $this->isInstanceOf($proxyClass)) + ->will($this->returnValue(new \stdClass())); $proxy->getDescription(); } @@ -139,6 +140,45 @@ public function testFailedProxyCloningDoesNotMarkTheProxyAsInitialized() $this->assertInstanceOf('Closure', $proxy->__getInitializer(), 'The initializer wasn\'t removed'); $this->assertInstanceOf('Closure', $proxy->__getCloner(), 'The cloner wasn\'t removed'); } + + public function testProxyClonesParentFields() + { + $companyEmployee = new CompanyEmployee(); + $companyEmployee->setSalary(1000); // A property on the CompanyEmployee + $companyEmployee->setName("Bob"); // A property on the parent class, CompanyPerson + + // Set the id of the CompanyEmployee (which is in the parent CompanyPerson) + $class = new \ReflectionClass('Doctrine\Tests\Models\Company\CompanyPerson'); + + $property = $class->getProperty('id'); + $property->setAccessible(true); + + $property->setValue($companyEmployee, 42); + + $classMetaData = $this->emMock->getClassMetadata('Doctrine\Tests\Models\Company\CompanyEmployee'); + + $persister = $this->getMock('Doctrine\ORM\Persisters\Entity\BasicEntityPersister', array('load', 'getClassMetadata'), array(), '', false); + $this->uowMock->setEntityPersister('Doctrine\Tests\Models\Company\CompanyEmployee', $persister); + + /* @var $proxy \Doctrine\Common\Proxy\Proxy */ + $proxy = $this->proxyFactory->getProxy('Doctrine\Tests\Models\Company\CompanyEmployee', array('id' => 42)); + + $persister + ->expects($this->atLeastOnce()) + ->method('load') + ->will($this->returnValue($companyEmployee)); + + $persister + ->expects($this->atLeastOnce()) + ->method('getClassMetadata') + ->will($this->returnValue($classMetaData)); + + $cloned = clone $proxy; + + $this->assertEquals(42, $cloned->getId(), "Expected the Id to be cloned"); + $this->assertEquals(1000, $cloned->getSalary(), "Expect properties on the CompanyEmployee class to be cloned"); + $this->assertEquals("Bob", $cloned->getName(), "Expect properties on the CompanyPerson class to be cloned"); + } } abstract class AbstractClass From 3fca33bdc42ddb70d2b284970e8e6533f11b06ba Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 10 Sep 2016 20:45:01 +0200 Subject: [PATCH 081/877] #5768 #5755 cleaned up test scenario, using new mocking logic as per PHPUnit 5.4+ --- .../Tests/ORM/Proxy/ProxyFactoryTest.php | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php b/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php index 1d21207f636..174daf3c02a 100644 --- a/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php @@ -12,6 +12,7 @@ use Doctrine\Tests\Mocks\DriverMock; use Doctrine\Tests\Mocks\EntityManagerMock; use Doctrine\Tests\Mocks\UnitOfWorkMock; +use Doctrine\Tests\Models\Company\CompanyPerson; use Doctrine\Tests\OrmTestCase; use Doctrine\Tests\Models\Company\CompanyEmployee; @@ -145,39 +146,42 @@ public function testProxyClonesParentFields() { $companyEmployee = new CompanyEmployee(); $companyEmployee->setSalary(1000); // A property on the CompanyEmployee - $companyEmployee->setName("Bob"); // A property on the parent class, CompanyPerson + $companyEmployee->setName('Bob'); // A property on the parent class, CompanyPerson // Set the id of the CompanyEmployee (which is in the parent CompanyPerson) - $class = new \ReflectionClass('Doctrine\Tests\Models\Company\CompanyPerson'); + $property = new \ReflectionProperty(CompanyPerson::class, 'id'); - $property = $class->getProperty('id'); $property->setAccessible(true); - $property->setValue($companyEmployee, 42); - $classMetaData = $this->emMock->getClassMetadata('Doctrine\Tests\Models\Company\CompanyEmployee'); + $classMetaData = $this->emMock->getClassMetadata(CompanyEmployee::class); - $persister = $this->getMock('Doctrine\ORM\Persisters\Entity\BasicEntityPersister', array('load', 'getClassMetadata'), array(), '', false); - $this->uowMock->setEntityPersister('Doctrine\Tests\Models\Company\CompanyEmployee', $persister); + $persister = $this + ->getMockBuilder(BasicEntityPersister::class) + ->setMethods(['load', 'getClassMetadata']) + ->disableOriginalConstructor() + ->getMock(); + $this->uowMock->setEntityPersister(CompanyEmployee::class, $persister); /* @var $proxy \Doctrine\Common\Proxy\Proxy */ - $proxy = $this->proxyFactory->getProxy('Doctrine\Tests\Models\Company\CompanyEmployee', array('id' => 42)); + $proxy = $this->proxyFactory->getProxy(CompanyEmployee::class, ['id' => 42]); $persister - ->expects($this->atLeastOnce()) + ->expects(self::atLeastOnce()) ->method('load') - ->will($this->returnValue($companyEmployee)); + ->willReturn($companyEmployee); $persister - ->expects($this->atLeastOnce()) + ->expects(self::atLeastOnce()) ->method('getClassMetadata') - ->will($this->returnValue($classMetaData)); + ->willReturn($classMetaData); + /* @var $cloned CompanyEmployee */ $cloned = clone $proxy; - $this->assertEquals(42, $cloned->getId(), "Expected the Id to be cloned"); - $this->assertEquals(1000, $cloned->getSalary(), "Expect properties on the CompanyEmployee class to be cloned"); - $this->assertEquals("Bob", $cloned->getName(), "Expect properties on the CompanyPerson class to be cloned"); + self::assertSame(42, $cloned->getId(), 'Expected the Id to be cloned'); + self::assertSame(1000, $cloned->getSalary(), 'Expect properties on the CompanyEmployee class to be cloned'); + self::assertSame('Bob', $cloned->getName(), 'Expect properties on the CompanyPerson class to be cloned'); } } From 05db15f7ee12fc843ded7f6eaa4a9623b3001b67 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Mon, 12 Sep 2016 12:22:49 -0500 Subject: [PATCH 082/877] Fix typo in batch-processing doc See http://www.dictionary.com/misspelling?term=apparant&s=t --- docs/en/reference/batch-processing.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/batch-processing.rst b/docs/en/reference/batch-processing.rst index 5d3cf188781..ce47c538c29 100644 --- a/docs/en/reference/batch-processing.rst +++ b/docs/en/reference/batch-processing.rst @@ -100,7 +100,7 @@ with the batching strategy that was already used for bulk inserts: Results may be fully buffered by the database client/ connection allocating additional memory not visible to the PHP process. For large sets this - may easily kill the process for no apparant reason. + may easily kill the process for no apparent reason. Bulk Deletes From 2ee56a595b0d1685f14dee724e2609f2d7ef2fab Mon Sep 17 00:00:00 2001 From: ReenExe Date: Thu, 15 Sep 2016 19:41:34 +0300 Subject: [PATCH 083/877] remove excess `check` --- lib/Doctrine/ORM/UnitOfWork.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 59ee1c1cb7b..1336a57f3fb 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1582,17 +1582,13 @@ public function isInIdentityMap($entity) { $oid = spl_object_hash($entity); - if ( ! isset($this->entityIdentifiers[$oid])) { + if (empty($this->entityIdentifiers[$oid])) { return false; } $classMetadata = $this->em->getClassMetadata(get_class($entity)); $idHash = implode(' ', $this->entityIdentifiers[$oid]); - if ($idHash === '') { - return false; - } - return isset($this->identityMap[$classMetadata->rootEntityName][$idHash]); } From 974a9f4b9e2519f56db5c36fcdc455e644df5f71 Mon Sep 17 00:00:00 2001 From: Tomas Kormanak Date: Sun, 2 Oct 2016 22:38:40 +0200 Subject: [PATCH 084/877] Fix PHP version in readme. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 96862eea214..dffd57ed1c0 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ | [![Build status][Master image]][Master] | [![Build status][2.5 image]][2.5] | | [![Coverage Status][Master coverage image]][Master coverage] | [![Coverage Status][2.5 coverage image]][2.5 coverage] | -Doctrine 2 is an object-relational mapper (ORM) for PHP 5.4+ that provides transparent persistence +Doctrine 2 is an object-relational mapper (ORM) for PHP 5.6+ that provides transparent persistence for PHP objects. It sits on top of a powerful database abstraction layer (DBAL). One of its key features is the option to write database queries in a proprietary object oriented SQL dialect called Doctrine Query Language (DQL), inspired by Hibernate's HQL. This provides developers with a powerful alternative to SQL that maintains flexibility From 96b3797ad677b1db64e7874c5d6695b2325c863a Mon Sep 17 00:00:00 2001 From: Adrian Zmenda Date: Mon, 3 Oct 2016 12:25:49 +0200 Subject: [PATCH 085/877] Update Autoloader namespace --- docs/en/reference/advanced-configuration.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/advanced-configuration.rst b/docs/en/reference/advanced-configuration.rst index 9d200f87005..abb72636cfb 100644 --- a/docs/en/reference/advanced-configuration.rst +++ b/docs/en/reference/advanced-configuration.rst @@ -394,7 +394,7 @@ means that you have to register a special autoloader for these classes: .. code-block:: php Date: Wed, 5 Oct 2016 14:16:47 +0300 Subject: [PATCH 086/877] Update events.rst https://github.com/doctrine/doctrine2/pull/169 --- docs/en/reference/events.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/events.rst b/docs/en/reference/events.rst index 171adca02ee..5a18a180655 100644 --- a/docs/en/reference/events.rst +++ b/docs/en/reference/events.rst @@ -179,7 +179,7 @@ the life-time of their registered entities. allows providing fallback metadata even when no actual metadata exists or could be found. This event is not a lifecycle callback. - preFlush - The preFlush event occurs at the very beginning of a flush - operation. This event is not a lifecycle callback. + operation. - onFlush - The onFlush event occurs after the change-sets of all managed entities are computed. This event is not a lifecycle callback. From 277833b4877be45052cbac0c6a7ab2ecfa47fa57 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Tue, 11 Oct 2016 16:59:03 +0200 Subject: [PATCH 087/877] Fixed typo + added link --- docs/en/reference/events.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/en/reference/events.rst b/docs/en/reference/events.rst index 5a18a180655..e6c8b0aa413 100644 --- a/docs/en/reference/events.rst +++ b/docs/en/reference/events.rst @@ -406,8 +406,8 @@ behaviors across different entity classes. Note that they require much more detailed knowledge about the inner workings of the EntityManager and UnitOfWork. Please read the -*Implementing Event Listeners* section carefully if you are trying -to write your own listener. +:ref:`reference-events-implementing-listeners` section carefully if you +are trying to write your own listener. For event subscribers, there are no surprises. They declare the lifecycle events in their ``getSubscribedEvents`` method and provide @@ -434,7 +434,7 @@ A lifecycle event listener looks like the following: } } -A lifecycle event subscriber may looks like this: +A lifecycle event subscriber may look like this: .. code-block:: php From a4379cc9e2044c9cb3a3657d5c655b6e9ece8f02 Mon Sep 17 00:00:00 2001 From: Arjan Date: Thu, 13 Oct 2016 22:54:32 +0200 Subject: [PATCH 088/877] Fixes named native query test - Makes sure the correct method is called in the test - Verifies that the correct method is called by checking the exception message --- tests/Doctrine/Tests/ORM/ConfigurationTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/ConfigurationTest.php b/tests/Doctrine/Tests/ORM/ConfigurationTest.php index d99d2b1e84e..7d55652dff1 100644 --- a/tests/Doctrine/Tests/ORM/ConfigurationTest.php +++ b/tests/Doctrine/Tests/ORM/ConfigurationTest.php @@ -136,6 +136,7 @@ public function testAddGetNamedQuery() $this->configuration->addNamedQuery('QueryName', $dql); $this->assertSame($dql, $this->configuration->getNamedQuery('QueryName')); $this->expectException(\Doctrine\ORM\ORMException::class); + $this->expectExceptionMessage('a named query'); $this->configuration->getNamedQuery('NonExistingQuery'); } @@ -148,7 +149,8 @@ public function testAddGetNamedNativeQuery() $this->assertSame($sql, $fetched[0]); $this->assertSame($rsm, $fetched[1]); $this->expectException(\Doctrine\ORM\ORMException::class); - $this->configuration->getNamedQuery('NonExistingQuery'); + $this->expectExceptionMessage('a named native query'); + $this->configuration->getNamedNativeQuery('NonExistingQuery'); } /** From 03da85e19e4ec7a64de208e187af9ce3f151e4d4 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Sat, 15 Oct 2016 15:41:10 +0900 Subject: [PATCH 089/877] fix namespace --- docs/en/reference/second-level-cache.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/en/reference/second-level-cache.rst b/docs/en/reference/second-level-cache.rst index e89beba310a..71286846fbd 100644 --- a/docs/en/reference/second-level-cache.rst +++ b/docs/en/reference/second-level-cache.rst @@ -156,17 +156,17 @@ Cached persisters are responsible to access cache regions. +-----------------------+-------------------------------------------------------------------------------+ | Cache Usage | Persister | +=======================+===============================================================================+ - | READ_ONLY | Doctrine\\ORM\\Cache\\Persister\\ReadOnlyCachedEntityPersister | + | READ_ONLY | Doctrine\\ORM\\Cache\\Persister\\Entity\\ReadOnlyCachedEntityPersister | +-----------------------+-------------------------------------------------------------------------------+ - | READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\ReadWriteCachedEntityPersister | + | READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\Entity\\ReadWriteCachedEntityPersister | +-----------------------+-------------------------------------------------------------------------------+ - | NONSTRICT_READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\NonStrictReadWriteCachedEntityPersister | + | NONSTRICT_READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\Entity\\NonStrictReadWriteCachedEntityPersister | +-----------------------+-------------------------------------------------------------------------------+ - | READ_ONLY | Doctrine\\ORM\\Cache\\Persister\\ReadOnlyCachedCollectionPersister | + | READ_ONLY | Doctrine\\ORM\\Cache\\Persister\\Collection\\ReadOnlyCachedCollectionPersister | +-----------------------+-------------------------------------------------------------------------------+ - | READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\ReadWriteCachedCollectionPersister | + | READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\Collection\\ReadWriteCachedCollectionPersister | +-----------------------+-------------------------------------------------------------------------------+ - | NONSTRICT_READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\NonStrictReadWriteCacheCollectionPersister | + | NONSTRICT_READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\Collection\\NonStrictReadWriteCacheCollectionPersister | +-----------------------+-------------------------------------------------------------------------------+ Configuration From fb1136cc9acd462da75a30d741e9d4a958a7c81b Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Sat, 15 Oct 2016 15:47:49 +0900 Subject: [PATCH 090/877] adjust the appearance of the table --- docs/en/reference/second-level-cache.rst | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/en/reference/second-level-cache.rst b/docs/en/reference/second-level-cache.rst index 71286846fbd..dca4bf828f6 100644 --- a/docs/en/reference/second-level-cache.rst +++ b/docs/en/reference/second-level-cache.rst @@ -153,21 +153,21 @@ Built-in cached persisters Cached persisters are responsible to access cache regions. - +-----------------------+-------------------------------------------------------------------------------+ - | Cache Usage | Persister | - +=======================+===============================================================================+ - | READ_ONLY | Doctrine\\ORM\\Cache\\Persister\\Entity\\ReadOnlyCachedEntityPersister | - +-----------------------+-------------------------------------------------------------------------------+ - | READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\Entity\\ReadWriteCachedEntityPersister | - +-----------------------+-------------------------------------------------------------------------------+ - | NONSTRICT_READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\Entity\\NonStrictReadWriteCachedEntityPersister | - +-----------------------+-------------------------------------------------------------------------------+ + +-----------------------+-------------------------------------------------------------------------------------------+ + | Cache Usage | Persister | + +=======================+===========================================================================================+ + | READ_ONLY | Doctrine\\ORM\\Cache\\Persister\\Entity\\ReadOnlyCachedEntityPersister | + +-----------------------+-------------------------------------------------------------------------------------------+ + | READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\Entity\\ReadWriteCachedEntityPersister | + +-----------------------+-------------------------------------------------------------------------------------------+ + | NONSTRICT_READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\Entity\\NonStrictReadWriteCachedEntityPersister | + +-----------------------+-------------------------------------------------------------------------------------------+ | READ_ONLY | Doctrine\\ORM\\Cache\\Persister\\Collection\\ReadOnlyCachedCollectionPersister | - +-----------------------+-------------------------------------------------------------------------------+ + +-----------------------+-------------------------------------------------------------------------------------------+ | READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\Collection\\ReadWriteCachedCollectionPersister | - +-----------------------+-------------------------------------------------------------------------------+ + +-----------------------+-------------------------------------------------------------------------------------------+ | NONSTRICT_READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\Collection\\NonStrictReadWriteCacheCollectionPersister | - +-----------------------+-------------------------------------------------------------------------------+ + +-----------------------+-------------------------------------------------------------------------------------------+ Configuration ------------- From 42c4938a8b904196c5cc66753e9b46f20a6d8806 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Tue, 18 Oct 2016 11:54:11 +0900 Subject: [PATCH 091/877] cache -> cached --- docs/en/reference/second-level-cache.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/second-level-cache.rst b/docs/en/reference/second-level-cache.rst index dca4bf828f6..07f39a34f99 100644 --- a/docs/en/reference/second-level-cache.rst +++ b/docs/en/reference/second-level-cache.rst @@ -166,7 +166,7 @@ Cached persisters are responsible to access cache regions. +-----------------------+-------------------------------------------------------------------------------------------+ | READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\Collection\\ReadWriteCachedCollectionPersister | +-----------------------+-------------------------------------------------------------------------------------------+ - | NONSTRICT_READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\Collection\\NonStrictReadWriteCacheCollectionPersister | + | NONSTRICT_READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\Collection\\NonStrictReadWriteCachedCollectionPersister | +-----------------------+-------------------------------------------------------------------------------------------+ Configuration From d3c2c4045291f20b25fbb41c799c56f4b5c56fde Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Tue, 18 Oct 2016 18:21:46 +0200 Subject: [PATCH 092/877] Updated a link (hopefully :-) --- docs/en/reference/working-with-objects.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/working-with-objects.rst b/docs/en/reference/working-with-objects.rst index 2b52fac412c..101cb3352d9 100644 --- a/docs/en/reference/working-with-objects.rst +++ b/docs/en/reference/working-with-objects.rst @@ -744,7 +744,7 @@ The Repository implement the ``Doctrine\Common\Collections\Selectable`` interface. That means you can build ``Doctrine\Common\Collections\Criteria`` and pass them to the ``matching($criteria)`` method. -See the :ref:`Working with Associations: Filtering collections +See :doc:`Working with Associations: Filtering collections `. By Eager Loading From d6eddab94fd71f18ee80b9d7f2a26fd4b32b246c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 18 Oct 2016 10:00:10 -0700 Subject: [PATCH 093/877] Revert "Merge pull request #6092 from ThomasLandauer/patch-2" This reverts commit ade3f3a7f36d4b8a2ccf14afd4b71e7b0d0509da, reversing changes made to a6e44d9305114c2a597bd7db2bb934f2c2325ed3. --- docs/en/reference/working-with-objects.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/working-with-objects.rst b/docs/en/reference/working-with-objects.rst index 101cb3352d9..2b52fac412c 100644 --- a/docs/en/reference/working-with-objects.rst +++ b/docs/en/reference/working-with-objects.rst @@ -744,7 +744,7 @@ The Repository implement the ``Doctrine\Common\Collections\Selectable`` interface. That means you can build ``Doctrine\Common\Collections\Criteria`` and pass them to the ``matching($criteria)`` method. -See :doc:`Working with Associations: Filtering collections +See the :ref:`Working with Associations: Filtering collections `. By Eager Loading From cdad5a82c56290a176ca035d3b47662256d519b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Schr=C3=B6der?= Date: Thu, 20 Oct 2016 13:32:59 +0200 Subject: [PATCH 094/877] Fixed typo in annotations reference --- docs/en/reference/annotations-reference.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/annotations-reference.rst b/docs/en/reference/annotations-reference.rst index 7b59aa678ab..e55a23eff9f 100644 --- a/docs/en/reference/annotations-reference.rst +++ b/docs/en/reference/annotations-reference.rst @@ -315,7 +315,7 @@ depending on whether the classes are in the namespace or not. @Embeddable ~~~~~~~~~~~~~~~~~~~~~ -The embeddable is required on an entity targed to be embeddable inside +The embeddable is required on an entity targeted to be embeddable inside another. It works together with the :ref:`@Embedded ` annotation to establish the relationship between two entities. From 3861cbf3172b7c7f84aff0b952fb200ea9cb9055 Mon Sep 17 00:00:00 2001 From: Garanzha Dmitriy Date: Tue, 18 Oct 2016 10:39:16 +0300 Subject: [PATCH 095/877] Remove duplicated enum type comment from declaration. --- docs/en/cookbook/mysql-enums.rst | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/en/cookbook/mysql-enums.rst b/docs/en/cookbook/mysql-enums.rst index 1d8df92590c..1765ecc90e8 100644 --- a/docs/en/cookbook/mysql-enums.rst +++ b/docs/en/cookbook/mysql-enums.rst @@ -98,7 +98,7 @@ For example for the previous enum type: public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { - return sprintf("ENUM('visible', 'invisible') COMMENT '(DC2Type:%s)'", self::ENUM_VISIBILITY); + return "ENUM('visible', 'invisible')"; } public function convertToPHPValue($value, AbstractPlatform $platform) @@ -118,6 +118,11 @@ For example for the previous enum type: { return self::ENUM_VISIBILITY; } + + public function requiresSQLCommentHint(AbstractPlatform $platform) + { + return true; + } } You can register this type with ``Type::addType('enumvisibility', 'MyProject\DBAL\EnumVisibilityType');``. @@ -152,7 +157,7 @@ You can generalize this approach easily to create a base class for enums: { $values = array_map(function($val) { return "'".$val."'"; }, $this->values); - return "ENUM(".implode(", ", $values).") COMMENT '(DC2Type:".$this->name.")'"; + return "ENUM(".implode(", ", $values).")"; } public function convertToPHPValue($value, AbstractPlatform $platform) @@ -172,6 +177,11 @@ You can generalize this approach easily to create a base class for enums: { return $this->name; } + + public function requiresSQLCommentHint(AbstractPlatform $platform) + { + return true; + } } With this base class you can define an enum as easily as: From 81fefb40dbd6b7b6f913501616075ecc779a1742 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Tue, 25 Oct 2016 23:51:31 -0300 Subject: [PATCH 096/877] composer require --dev malukenho/docheader --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f5b3b08f702..533c1929905 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,8 @@ }, "require-dev": { "symfony/yaml": "~2.3|~3.0", - "phpunit/phpunit": "^5.4" + "phpunit/phpunit": "^5.4", + "malukenho/docheader": "^0.1.4" }, "suggest": { "symfony/yaml": "If you want to use YAML Metadata Mapping Driver" From e4050edb4ecc76de625547343ed4431fa64f230c Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Tue, 25 Oct 2016 23:52:07 -0300 Subject: [PATCH 097/877] add license template file --- .docheader | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .docheader diff --git a/.docheader b/.docheader new file mode 100644 index 00000000000..23753e7fef2 --- /dev/null +++ b/.docheader @@ -0,0 +1,17 @@ +/* + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This software consists of voluntary contributions made by many individuals + * and is licensed under the MIT license. For more information, see + * . + */ From ca1a9473d3348cd0ed727ba6f2a5bfebe0ab4915 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Tue, 25 Oct 2016 23:53:17 -0300 Subject: [PATCH 098/877] add license checker to the build --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 5a9fb2dcb0c..31516a11639 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,7 @@ before_script: script: - ENABLE_SECOND_LEVEL_CACHE=0 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml $PHPUNIT_FLAGS - ENABLE_SECOND_LEVEL_CACHE=1 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml --exclude-group performance,non-cacheable,locking_functional + - ./vendor/bin/docheader check lib/ after_script: - if [[ $TRAVIS_PHP_VERSION = '7.0' && $DB = 'sqlite' ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi From b8a18cd0a101df0aadc5339f6aaead175596cfca Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Tue, 25 Oct 2016 23:58:42 -0300 Subject: [PATCH 099/877] fix license header inconsistencies --- lib/Doctrine/ORM/EntityManagerInterface.php | 4 +-- lib/Doctrine/ORM/Event/LifecycleEventArgs.php | 2 +- .../Mapping/Driver/SimplifiedXmlDriver.php | 2 +- .../Mapping/Driver/SimplifiedYamlDriver.php | 2 +- lib/Doctrine/ORM/Mapping/MappingException.php | 2 +- .../ORM/Query/AST/NewObjectExpression.php | 2 +- .../ORM/Tools/Export/ExportException.php | 19 +++++++++++- .../Tools/Pagination/CountOutputWalker.php | 24 +++++++++------ .../ORM/Tools/Pagination/CountWalker.php | 24 +++++++++------ .../Pagination/LimitSubqueryOutputWalker.php | 24 +++++++++------ .../Tools/Pagination/LimitSubqueryWalker.php | 29 ++++++++++--------- .../ORM/Tools/Pagination/WhereInWalker.php | 28 +++++++++--------- lib/Doctrine/ORM/Tools/SchemaValidator.php | 2 +- lib/Doctrine/ORM/Tools/Setup.php | 2 +- 14 files changed, 102 insertions(+), 64 deletions(-) diff --git a/lib/Doctrine/ORM/EntityManagerInterface.php b/lib/Doctrine/ORM/EntityManagerInterface.php index 016cfd4ec8b..09c7efdf9d2 100644 --- a/lib/Doctrine/ORM/EntityManagerInterface.php +++ b/lib/Doctrine/ORM/EntityManagerInterface.php @@ -7,9 +7,9 @@ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION); HOWEVER CAUSED AND ON ANY + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE); ARISING IN ANY WAY OUT OF THE USE + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This software consists of voluntary contributions made by many individuals diff --git a/lib/Doctrine/ORM/Event/LifecycleEventArgs.php b/lib/Doctrine/ORM/Event/LifecycleEventArgs.php index 9a5c8cf0624..c7eb80bf61f 100644 --- a/lib/Doctrine/ORM/Event/LifecycleEventArgs.php +++ b/lib/Doctrine/ORM/Event/LifecycleEventArgs.php @@ -15,7 +15,7 @@ * This software consists of voluntary contributions made by many individuals * and is licensed under the MIT license. For more information, see * . -*/ + */ namespace Doctrine\ORM\Event; diff --git a/lib/Doctrine/ORM/Mapping/Driver/SimplifiedXmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/SimplifiedXmlDriver.php index 85221f3a2bc..9bfd84cae38 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/SimplifiedXmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/SimplifiedXmlDriver.php @@ -15,7 +15,7 @@ * This software consists of voluntary contributions made by many individuals * and is licensed under the MIT license. For more information, see * . -*/ + */ namespace Doctrine\ORM\Mapping\Driver; diff --git a/lib/Doctrine/ORM/Mapping/Driver/SimplifiedYamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/SimplifiedYamlDriver.php index d2b8c0fcf03..8f38784f4e6 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/SimplifiedYamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/SimplifiedYamlDriver.php @@ -15,7 +15,7 @@ * This software consists of voluntary contributions made by many individuals * and is licensed under the MIT license. For more information, see * . -*/ + */ namespace Doctrine\ORM\Mapping\Driver; diff --git a/lib/Doctrine/ORM/Mapping/MappingException.php b/lib/Doctrine/ORM/Mapping/MappingException.php index ace42db2792..97686d6544e 100644 --- a/lib/Doctrine/ORM/Mapping/MappingException.php +++ b/lib/Doctrine/ORM/Mapping/MappingException.php @@ -14,7 +14,7 @@ * * This software consists of voluntary contributions made by many individuals * and is licensed under the MIT license. For more information, see - * . + * . */ namespace Doctrine\ORM\Mapping; diff --git a/lib/Doctrine/ORM/Query/AST/NewObjectExpression.php b/lib/Doctrine/ORM/Query/AST/NewObjectExpression.php index 65b94ac63cf..ec011ce29f0 100644 --- a/lib/Doctrine/ORM/Query/AST/NewObjectExpression.php +++ b/lib/Doctrine/ORM/Query/AST/NewObjectExpression.php @@ -13,7 +13,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This software consists of voluntary contributions made by many individuals - * and is licensed under the MIT. For more information, see + * and is licensed under the MIT license. For more information, see * . */ diff --git a/lib/Doctrine/ORM/Tools/Export/ExportException.php b/lib/Doctrine/ORM/Tools/Export/ExportException.php index 89ddfe22eb0..853159f17de 100644 --- a/lib/Doctrine/ORM/Tools/Export/ExportException.php +++ b/lib/Doctrine/ORM/Tools/Export/ExportException.php @@ -1,4 +1,21 @@ . + */ namespace Doctrine\ORM\Tools\Export; @@ -35,4 +52,4 @@ public static function attemptOverwriteExistingFile($file) { return new self("Attempting to overwrite an existing file '".$file."'."); } -} \ No newline at end of file +} diff --git a/lib/Doctrine/ORM/Tools/Pagination/CountOutputWalker.php b/lib/Doctrine/ORM/Tools/Pagination/CountOutputWalker.php index e44be6c57c4..2cfd029df2c 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/CountOutputWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/CountOutputWalker.php @@ -1,14 +1,20 @@ . */ namespace Doctrine\ORM\Tools\Pagination; diff --git a/lib/Doctrine/ORM/Tools/Pagination/CountWalker.php b/lib/Doctrine/ORM/Tools/Pagination/CountWalker.php index ff0c6b36331..628bd4cd138 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/CountWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/CountWalker.php @@ -1,14 +1,20 @@ . */ namespace Doctrine\ORM\Tools\Pagination; diff --git a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php index 92386e46de2..5d59722ed53 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php @@ -1,14 +1,20 @@ . */ namespace Doctrine\ORM\Tools\Pagination; diff --git a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php index fd51fb46bd5..b2a292ad9af 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php @@ -1,19 +1,20 @@ - * @copyright Copyright (c) 2010 David Abdemoulaie (http://hobodave.com/) - * @license http://hobodave.com/license.txt New BSD License + * This software consists of voluntary contributions made by many individuals + * and is licensed under the MIT license. For more information, see + * . */ namespace Doctrine\ORM\Tools\Pagination; diff --git a/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php b/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php index 9f42a1eea7a..1f54da10052 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php @@ -1,18 +1,20 @@ - * @copyright Copyright (c) 2010 David Abdemoulaie (http://hobodave.com/) - * @license http://hobodave.com/license.txt New BSD License + * This software consists of voluntary contributions made by many individuals + * and is licensed under the MIT license. For more information, see + * . */ namespace Doctrine\ORM\Tools\Pagination; diff --git a/lib/Doctrine/ORM/Tools/SchemaValidator.php b/lib/Doctrine/ORM/Tools/SchemaValidator.php index 03222700c10..3f5799a4de1 100644 --- a/lib/Doctrine/ORM/Tools/SchemaValidator.php +++ b/lib/Doctrine/ORM/Tools/SchemaValidator.php @@ -15,7 +15,7 @@ * This software consists of voluntary contributions made by many individuals * and is licensed under the MIT license. For more information, see * . -*/ + */ namespace Doctrine\ORM\Tools; diff --git a/lib/Doctrine/ORM/Tools/Setup.php b/lib/Doctrine/ORM/Tools/Setup.php index 79d4670ad0f..99262f103a7 100644 --- a/lib/Doctrine/ORM/Tools/Setup.php +++ b/lib/Doctrine/ORM/Tools/Setup.php @@ -15,7 +15,7 @@ * This software consists of voluntary contributions made by many individuals * and is licensed under the MIT license. For more information, see * . -*/ + */ namespace Doctrine\ORM\Tools; From dbe843fc4bae823cbe638cb7f396998908b93bca Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Wed, 26 Oct 2016 13:24:33 -0300 Subject: [PATCH 100/877] remove license from header of test files --- .../Tests/DbalTypes/CustomIdObject.php | 17 ---------------- .../Tests/DbalTypes/CustomIdObjectType.php | 17 ---------------- .../Tests/Mocks/EntityManagerMock.php | 19 ------------------ .../Tests/Mocks/StatementArrayMock.php | 8 +------- tests/Doctrine/Tests/Mocks/TaskMock.php | 19 ------------------ tests/Doctrine/Tests/Models/CMS/CmsGroup.php | 4 ---- tests/Doctrine/Tests/Models/CMS/CmsTag.php | 4 ---- .../CustomType/CustomIdObjectTypeChild.php | 17 ---------------- .../CustomType/CustomIdObjectTypeParent.php | 17 ---------------- .../DDC1476EntityWithDefaultFieldType.php | 20 +------------------ .../Tests/Models/DDC3711/DDC3711EntityA.php | 9 +++++---- .../Tests/Models/DDC3711/DDC3711EntityB.php | 9 +++++---- .../Models/DDC753/DDC753CustomRepository.php | 20 +------------------ .../Models/DDC753/DDC753DefaultRepository.php | 20 +------------------ .../DDC753EntityWithCustomRepository.php | 20 +------------------ ...DC753EntityWithDefaultCustomRepository.php | 20 +------------------ .../DDC753EntityWithInvalidRepository.php | 20 +------------------ .../Models/DDC753/DDC753InvalidRepository.php | 20 +------------------ .../Models/DDC869/DDC869ChequePayment.php | 20 +------------------ .../Models/DDC869/DDC869CreditCardPayment.php | 20 +------------------ .../Tests/Models/DDC869/DDC869Payment.php | 20 +------------------ .../Models/DDC869/DDC869PaymentRepository.php | 20 +------------------ .../Tests/Models/DDC889/DDC889Class.php | 20 +------------------ .../Tests/Models/DDC889/DDC889Entity.php | 20 +------------------ .../Tests/Models/DDC889/DDC889SuperClass.php | 20 +------------------ .../DirectoryTree/AbstractContentItem.php | 17 ---------------- .../Tests/Models/DirectoryTree/Directory.php | 17 ---------------- .../Tests/Models/DirectoryTree/File.php | 17 ---------------- .../ORM/Functional/CustomIdObjectTypeTest.php | 17 ---------------- .../EntityRepositoryCriteriaTest.php | 17 ---------------- .../Functional/MergeSharedEntitiesTest.php | 17 ---------------- .../PersistentCollectionCriteriaTest.php | 16 --------------- .../Functional/PersistentCollectionTest.php | 2 -- .../ORM/Functional/Ticket/DDC3711Test.php | 8 ++++---- .../ORM/Mapping/ClassMetadataBuilderTest.php | 17 ---------------- .../Tests/ORM/Mapping/FieldBuilderTest.php | 17 ---------------- .../JoinColumnClassNamingStrategy.php | 18 ----------------- .../Mapping/Symfony/AbstractDriverTest.php | 17 ---------------- .../ORM/Mapping/Symfony/XmlDriverTest.php | 17 ---------------- .../ORM/Mapping/Symfony/YamlDriverTest.php | 17 ---------------- .../ORM/Performance/ProxyPerformanceTest.php | 17 ---------------- .../JoinedSubclassPersisterTest.php | 17 ---------------- .../ORM/Query/CustomTreeWalkersJoinTest.php | 17 ---------------- .../Tests/ORM/Query/CustomTreeWalkersTest.php | 19 +----------------- .../ORM/Query/DeleteSqlGenerationTest.php | 19 ------------------ tests/Doctrine/Tests/ORM/Query/ExprTest.php | 17 ---------------- .../ORM/Query/ParameterTypeInfererTest.php | 18 +---------------- .../ORM/Query/QueryExpressionVisitorTest.php | 17 ---------------- .../ORM/Query/UpdateSqlGenerationTest.php | 19 ------------------ tests/Doctrine/Tests/ORM/QueryBuilderTest.php | 17 ---------------- .../ORM/Tools/ConvertDoctrine1SchemaTest.php | 19 ------------------ .../AbstractClassMetadataExporterTest.php | 19 ------------------ .../AnnotationClassMetadataExporterTest.php | 19 ------------------ .../Export/PhpClassMetadataExporterTest.php | 19 ------------------ .../Export/XmlClassMetadataExporterTest.php | 19 ------------------ .../Export/YamlClassMetadataExporterTest.php | 19 ------------------ 56 files changed, 31 insertions(+), 911 deletions(-) diff --git a/tests/Doctrine/Tests/DbalTypes/CustomIdObject.php b/tests/Doctrine/Tests/DbalTypes/CustomIdObject.php index df34ebccb5b..d777d2dc4bb 100644 --- a/tests/Doctrine/Tests/DbalTypes/CustomIdObject.php +++ b/tests/Doctrine/Tests/DbalTypes/CustomIdObject.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\DbalTypes; diff --git a/tests/Doctrine/Tests/DbalTypes/CustomIdObjectType.php b/tests/Doctrine/Tests/DbalTypes/CustomIdObjectType.php index 3d5aa0c19ac..f59ab151c5f 100644 --- a/tests/Doctrine/Tests/DbalTypes/CustomIdObjectType.php +++ b/tests/Doctrine/Tests/DbalTypes/CustomIdObjectType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\DbalTypes; diff --git a/tests/Doctrine/Tests/Mocks/EntityManagerMock.php b/tests/Doctrine/Tests/Mocks/EntityManagerMock.php index 24ecb59efe3..6f98e3c508a 100644 --- a/tests/Doctrine/Tests/Mocks/EntityManagerMock.php +++ b/tests/Doctrine/Tests/Mocks/EntityManagerMock.php @@ -1,23 +1,4 @@ . - */ namespace Doctrine\Tests\Mocks; diff --git a/tests/Doctrine/Tests/Mocks/StatementArrayMock.php b/tests/Doctrine/Tests/Mocks/StatementArrayMock.php index 4054b9a9ebd..9ef37da463f 100644 --- a/tests/Doctrine/Tests/Mocks/StatementArrayMock.php +++ b/tests/Doctrine/Tests/Mocks/StatementArrayMock.php @@ -1,10 +1,4 @@ _result); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Mocks/TaskMock.php b/tests/Doctrine/Tests/Mocks/TaskMock.php index 22676f67aaf..f097abc03c4 100644 --- a/tests/Doctrine/Tests/Mocks/TaskMock.php +++ b/tests/Doctrine/Tests/Mocks/TaskMock.php @@ -1,23 +1,4 @@ . - */ namespace Doctrine\Tests\Mocks; diff --git a/tests/Doctrine/Tests/Models/CMS/CmsGroup.php b/tests/Doctrine/Tests/Models/CMS/CmsGroup.php index b65ae8557d2..9707d8cc280 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsGroup.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsGroup.php @@ -1,8 +1,4 @@ . - */ namespace Doctrine\Tests\Models\CustomType; diff --git a/tests/Doctrine/Tests/Models/CustomType/CustomIdObjectTypeParent.php b/tests/Doctrine/Tests/Models/CustomType/CustomIdObjectTypeParent.php index 3045c647bbf..0460676fce3 100644 --- a/tests/Doctrine/Tests/Models/CustomType/CustomIdObjectTypeParent.php +++ b/tests/Doctrine/Tests/Models/CustomType/CustomIdObjectTypeParent.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\Models\CustomType; diff --git a/tests/Doctrine/Tests/Models/DDC1476/DDC1476EntityWithDefaultFieldType.php b/tests/Doctrine/Tests/Models/DDC1476/DDC1476EntityWithDefaultFieldType.php index 58afe8128c5..4f94dad1381 100644 --- a/tests/Doctrine/Tests/Models/DDC1476/DDC1476EntityWithDefaultFieldType.php +++ b/tests/Doctrine/Tests/Models/DDC1476/DDC1476EntityWithDefaultFieldType.php @@ -1,23 +1,5 @@ . - */ - namespace Doctrine\Tests\Models\DDC1476; /** @@ -73,4 +55,4 @@ public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $met $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_NONE); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DDC3711/DDC3711EntityA.php b/tests/Doctrine/Tests/Models/DDC3711/DDC3711EntityA.php index 3146969ed57..ecbfd52773c 100644 --- a/tests/Doctrine/Tests/Models/DDC3711/DDC3711EntityA.php +++ b/tests/Doctrine/Tests/Models/DDC3711/DDC3711EntityA.php @@ -1,12 +1,13 @@ - */ + namespace Doctrine\Tests\Models\DDC3711; use Doctrine\Common\Collections\ArrayCollection; +/** + * @author Marc Pantel + */ class DDC3711EntityA { /** @@ -75,4 +76,4 @@ public function addEntityB($entityB) return $this; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DDC3711/DDC3711EntityB.php b/tests/Doctrine/Tests/Models/DDC3711/DDC3711EntityB.php index ff589e0923a..48c4fd8602d 100644 --- a/tests/Doctrine/Tests/Models/DDC3711/DDC3711EntityB.php +++ b/tests/Doctrine/Tests/Models/DDC3711/DDC3711EntityB.php @@ -1,12 +1,13 @@ - */ + namespace Doctrine\Tests\Models\DDC3711; use Doctrine\Common\Collections\ArrayCollection; +/** + * @author Marc Pantel + */ class DDC3711EntityB { /** @@ -72,4 +73,4 @@ public function addEntityA($entityA) $this->entityA[] = $entityA; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DDC753/DDC753CustomRepository.php b/tests/Doctrine/Tests/Models/DDC753/DDC753CustomRepository.php index eaf9006c750..783faef61f0 100644 --- a/tests/Doctrine/Tests/Models/DDC753/DDC753CustomRepository.php +++ b/tests/Doctrine/Tests/Models/DDC753/DDC753CustomRepository.php @@ -1,23 +1,5 @@ . - */ - namespace Doctrine\Tests\Models\DDC753; use Doctrine\ORM\EntityRepository; @@ -33,4 +15,4 @@ public function isCustomRepository() return true; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DDC753/DDC753DefaultRepository.php b/tests/Doctrine/Tests/Models/DDC753/DDC753DefaultRepository.php index 5be9aa522e6..1a3e071fa7b 100644 --- a/tests/Doctrine/Tests/Models/DDC753/DDC753DefaultRepository.php +++ b/tests/Doctrine/Tests/Models/DDC753/DDC753DefaultRepository.php @@ -1,23 +1,5 @@ . - */ - namespace Doctrine\Tests\Models\DDC753; use Doctrine\ORM\EntityRepository; @@ -32,4 +14,4 @@ public function isDefaultRepository() return true; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithCustomRepository.php b/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithCustomRepository.php index 7b92e66ac73..7a9ce8d835b 100644 --- a/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithCustomRepository.php +++ b/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithCustomRepository.php @@ -1,23 +1,5 @@ . - */ - namespace Doctrine\Tests\Models\DDC753; /** @@ -36,4 +18,4 @@ class DDC753EntityWithCustomRepository /** @column(type="string") */ protected $name; -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithDefaultCustomRepository.php b/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithDefaultCustomRepository.php index 8ca2a2c9467..6f448755fde 100644 --- a/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithDefaultCustomRepository.php +++ b/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithDefaultCustomRepository.php @@ -1,23 +1,5 @@ . - */ - namespace Doctrine\Tests\Models\DDC753; /** @@ -36,4 +18,4 @@ class DDC753EntityWithDefaultCustomRepository /** @column(type="string") */ protected $name; -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithInvalidRepository.php b/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithInvalidRepository.php index d12660cf4a2..e480e912c4d 100644 --- a/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithInvalidRepository.php +++ b/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithInvalidRepository.php @@ -1,23 +1,5 @@ . - */ - namespace Doctrine\Tests\Models\DDC753; /** @@ -36,4 +18,4 @@ class DDC753EntityWithInvalidRepository /** @column(type="string") */ protected $name; -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DDC753/DDC753InvalidRepository.php b/tests/Doctrine/Tests/Models/DDC753/DDC753InvalidRepository.php index decc07078a4..4e8c7bad7bb 100644 --- a/tests/Doctrine/Tests/Models/DDC753/DDC753InvalidRepository.php +++ b/tests/Doctrine/Tests/Models/DDC753/DDC753InvalidRepository.php @@ -1,26 +1,8 @@ . - */ - namespace Doctrine\Tests\Models\DDC753; class DDC753InvalidRepository { -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php b/tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php index a9f548ffca6..00e5da01718 100644 --- a/tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php @@ -1,23 +1,5 @@ . - */ - namespace Doctrine\Tests\Models\DDC869; /** @@ -37,4 +19,4 @@ public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $met )); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php b/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php index cd637b3c07d..4c1f8c30602 100644 --- a/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php @@ -1,23 +1,5 @@ . - */ - namespace Doctrine\Tests\Models\DDC869; /** @@ -37,4 +19,4 @@ public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $met )); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php b/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php index 01e7fbefde4..ea052d12eb3 100644 --- a/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php @@ -1,23 +1,5 @@ . - */ - namespace Doctrine\Tests\Models\DDC869; /** @@ -54,4 +36,4 @@ public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $met $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_AUTO); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869PaymentRepository.php b/tests/Doctrine/Tests/Models/DDC869/DDC869PaymentRepository.php index f950df0e064..3c11b154bce 100644 --- a/tests/Doctrine/Tests/Models/DDC869/DDC869PaymentRepository.php +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869PaymentRepository.php @@ -1,23 +1,5 @@ . - */ - namespace Doctrine\Tests\Models\DDC869; use Doctrine\ORM\EntityRepository; @@ -34,4 +16,4 @@ public function isTrue() { return true; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DDC889/DDC889Class.php b/tests/Doctrine/Tests/Models/DDC889/DDC889Class.php index 7520568b038..8bba1274ca2 100644 --- a/tests/Doctrine/Tests/Models/DDC889/DDC889Class.php +++ b/tests/Doctrine/Tests/Models/DDC889/DDC889Class.php @@ -1,23 +1,5 @@ . - */ - namespace Doctrine\Tests\Models\DDC889; class DDC889Class extends DDC889SuperClass @@ -43,4 +25,4 @@ public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $met $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_AUTO); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DDC889/DDC889Entity.php b/tests/Doctrine/Tests/Models/DDC889/DDC889Entity.php index 59cd21a61eb..43884435fa7 100644 --- a/tests/Doctrine/Tests/Models/DDC889/DDC889Entity.php +++ b/tests/Doctrine/Tests/Models/DDC889/DDC889Entity.php @@ -1,23 +1,5 @@ . - */ - namespace Doctrine\Tests\Models\DDC889; /** @@ -30,4 +12,4 @@ public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $met { } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DDC889/DDC889SuperClass.php b/tests/Doctrine/Tests/Models/DDC889/DDC889SuperClass.php index 7cffe488bc9..42fd933868a 100644 --- a/tests/Doctrine/Tests/Models/DDC889/DDC889SuperClass.php +++ b/tests/Doctrine/Tests/Models/DDC889/DDC889SuperClass.php @@ -1,23 +1,5 @@ . - */ - namespace Doctrine\Tests\Models\DDC889; /** @@ -38,4 +20,4 @@ public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $met $metadata->isMappedSuperclass = true; $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_NONE); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DirectoryTree/AbstractContentItem.php b/tests/Doctrine/Tests/Models/DirectoryTree/AbstractContentItem.php index d2ba439a072..166f86cb049 100644 --- a/tests/Doctrine/Tests/Models/DirectoryTree/AbstractContentItem.php +++ b/tests/Doctrine/Tests/Models/DirectoryTree/AbstractContentItem.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\Models\DirectoryTree; diff --git a/tests/Doctrine/Tests/Models/DirectoryTree/Directory.php b/tests/Doctrine/Tests/Models/DirectoryTree/Directory.php index f0db778b813..cb3729974bc 100644 --- a/tests/Doctrine/Tests/Models/DirectoryTree/Directory.php +++ b/tests/Doctrine/Tests/Models/DirectoryTree/Directory.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\Models\DirectoryTree; diff --git a/tests/Doctrine/Tests/Models/DirectoryTree/File.php b/tests/Doctrine/Tests/Models/DirectoryTree/File.php index 428daad8b5c..2e18a06cfce 100644 --- a/tests/Doctrine/Tests/Models/DirectoryTree/File.php +++ b/tests/Doctrine/Tests/Models/DirectoryTree/File.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\Models\DirectoryTree; diff --git a/tests/Doctrine/Tests/ORM/Functional/CustomIdObjectTypeTest.php b/tests/Doctrine/Tests/ORM/Functional/CustomIdObjectTypeTest.php index 2e7abf76c2d..ea6fdfafffb 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CustomIdObjectTypeTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CustomIdObjectTypeTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\ORM\Functional; diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryCriteriaTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryCriteriaTest.php index 45f552d5949..76e269a20dd 100644 --- a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryCriteriaTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryCriteriaTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\ORM\Functional; diff --git a/tests/Doctrine/Tests/ORM/Functional/MergeSharedEntitiesTest.php b/tests/Doctrine/Tests/ORM/Functional/MergeSharedEntitiesTest.php index 28e89c36094..ffe64fcff0a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/MergeSharedEntitiesTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/MergeSharedEntitiesTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\ORM\Functional; diff --git a/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php b/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php index e38574b7c80..a730546d61f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php @@ -1,20 +1,4 @@ - */ namespace Doctrine\Tests\ORM\Functional\Ticket; @@ -9,6 +6,9 @@ use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\Tests\ORM\Mapping\YamlMappingDriverTest; +/** + * @author Marc Pantel + */ class DDC3711Test extends YamlMappingDriverTest { public function testCompositeKeyForJoinTableInManyToManyCreation() @@ -27,4 +27,4 @@ public function testCompositeKeyForJoinTableInManyToManyCreation() $this->assertEquals(array('link_b_id1' => "id1", 'link_b_id2' => "id2"), $entityA->associationMappings['entityB']['relationToTargetKeyColumns']); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php index 996c4059882..da4f4abf58d 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\ORM\Mapping; diff --git a/tests/Doctrine/Tests/ORM/Mapping/FieldBuilderTest.php b/tests/Doctrine/Tests/ORM/Mapping/FieldBuilderTest.php index 3d759aade95..67a0ebce032 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/FieldBuilderTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/FieldBuilderTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\ORM\Mapping; diff --git a/tests/Doctrine/Tests/ORM/Mapping/NamingStrategy/JoinColumnClassNamingStrategy.php b/tests/Doctrine/Tests/ORM/Mapping/NamingStrategy/JoinColumnClassNamingStrategy.php index 8de8fa94004..c4f967589f9 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/NamingStrategy/JoinColumnClassNamingStrategy.php +++ b/tests/Doctrine/Tests/ORM/Mapping/NamingStrategy/JoinColumnClassNamingStrategy.php @@ -1,23 +1,5 @@ . - */ - namespace Doctrine\Tests\ORM\Mapping\NamingStrategy; use Doctrine\ORM\Mapping\DefaultNamingStrategy; diff --git a/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php index e116c67634b..ac8f1d695c2 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php @@ -1,21 +1,4 @@ . -*/ namespace Doctrine\Tests\ORM\Mapping\Symfony; use Doctrine\Common\Persistence\Mapping\MappingException; diff --git a/tests/Doctrine/Tests/ORM/Mapping/Symfony/XmlDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/Symfony/XmlDriverTest.php index 5908b674a13..f32d9f2ad07 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/Symfony/XmlDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/Symfony/XmlDriverTest.php @@ -1,21 +1,4 @@ . -*/ namespace Doctrine\Tests\ORM\Mapping\Symfony; diff --git a/tests/Doctrine/Tests/ORM/Mapping/Symfony/YamlDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/Symfony/YamlDriverTest.php index c5d8d1cd1b3..5b7f38eadf0 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/Symfony/YamlDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/Symfony/YamlDriverTest.php @@ -1,21 +1,4 @@ . -*/ namespace Doctrine\Tests\ORM\Mapping\Symfony; diff --git a/tests/Doctrine/Tests/ORM/Performance/ProxyPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/ProxyPerformanceTest.php index ffe621eefd3..bc98c23f6f7 100644 --- a/tests/Doctrine/Tests/ORM/Performance/ProxyPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/ProxyPerformanceTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\ORM\Performance; diff --git a/tests/Doctrine/Tests/ORM/Persisters/JoinedSubclassPersisterTest.php b/tests/Doctrine/Tests/ORM/Persisters/JoinedSubclassPersisterTest.php index 18145070fbe..5d4e992f7fc 100644 --- a/tests/Doctrine/Tests/ORM/Persisters/JoinedSubclassPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Persisters/JoinedSubclassPersisterTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\ORM\Persisters; diff --git a/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersJoinTest.php b/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersJoinTest.php index 284cc1adcab..e47c48215c0 100644 --- a/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersJoinTest.php +++ b/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersJoinTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\ORM\Query; diff --git a/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersTest.php b/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersTest.php index af7d2bf55d0..4114c4f8b23 100644 --- a/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersTest.php +++ b/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\ORM\Functional; @@ -238,4 +221,4 @@ private function modifySelectStatement(Query\AST\SelectStatement $selectStatemen ) ); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Query/DeleteSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/DeleteSqlGenerationTest.php index 0bae052d808..8218339df35 100644 --- a/tests/Doctrine/Tests/ORM/Query/DeleteSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/DeleteSqlGenerationTest.php @@ -1,23 +1,4 @@ . - */ namespace Doctrine\Tests\ORM\Query; use Doctrine\Tests\OrmTestCase; diff --git a/tests/Doctrine/Tests/ORM/Query/ExprTest.php b/tests/Doctrine/Tests/ORM/Query/ExprTest.php index 01e82ce6580..61def177092 100644 --- a/tests/Doctrine/Tests/ORM/Query/ExprTest.php +++ b/tests/Doctrine/Tests/ORM/Query/ExprTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\ORM\Query; diff --git a/tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php b/tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php index d10c78c9c49..640a9131442 100644 --- a/tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php +++ b/tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php @@ -1,21 +1,5 @@ . - */ + namespace Doctrine\Tests\ORM\Query; use Doctrine\ORM\Query\ParameterTypeInferer; diff --git a/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php b/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php index 2b9fc2304b1..b8d688261a7 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\ORM\Query; diff --git a/tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php index 5dae79b3d57..4110b54e62d 100644 --- a/tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php @@ -1,23 +1,4 @@ . - */ namespace Doctrine\Tests\ORM\Query; diff --git a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php index 7b1e38c307b..acf4d08e699 100644 --- a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php +++ b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\ORM; diff --git a/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php b/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php index b0a07270da9..6c62ca3526c 100644 --- a/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php @@ -1,23 +1,4 @@ . - */ namespace Doctrine\Tests\ORM\Tools; diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php index d712730ff00..5edd47b0313 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php @@ -1,23 +1,4 @@ . - */ namespace Doctrine\Tests\ORM\Tools\Export; diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/AnnotationClassMetadataExporterTest.php b/tests/Doctrine/Tests/ORM/Tools/Export/AnnotationClassMetadataExporterTest.php index 9fa20941cb4..a432ec45187 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/AnnotationClassMetadataExporterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/AnnotationClassMetadataExporterTest.php @@ -1,23 +1,4 @@ . - */ namespace Doctrine\Tests\ORM\Tools\Export; diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/PhpClassMetadataExporterTest.php b/tests/Doctrine/Tests/ORM/Tools/Export/PhpClassMetadataExporterTest.php index 2ad37588f16..6ca3cf94830 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/PhpClassMetadataExporterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/PhpClassMetadataExporterTest.php @@ -1,23 +1,4 @@ . - */ namespace Doctrine\Tests\ORM\Tools\Export; diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/XmlClassMetadataExporterTest.php b/tests/Doctrine/Tests/ORM/Tools/Export/XmlClassMetadataExporterTest.php index 5bec99cfe91..3eca15f9c28 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/XmlClassMetadataExporterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/XmlClassMetadataExporterTest.php @@ -1,23 +1,4 @@ . - */ namespace Doctrine\Tests\ORM\Tools\Export; use Doctrine\ORM\Mapping\ClassMetadataInfo; diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/YamlClassMetadataExporterTest.php b/tests/Doctrine/Tests/ORM/Tools/Export/YamlClassMetadataExporterTest.php index 85c6e1c5ea1..a47c396d2ce 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/YamlClassMetadataExporterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/YamlClassMetadataExporterTest.php @@ -1,23 +1,4 @@ . - */ namespace Doctrine\Tests\ORM\Tools\Export; From dc07fc609ea23e40f82432440bc1a56f896a420e Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Wed, 26 Oct 2016 13:27:18 -0300 Subject: [PATCH 101/877] Revert "add license checker to the build" This reverts commit ca1a9473d3348cd0ed727ba6f2a5bfebe0ab4915. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 31516a11639..5a9fb2dcb0c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,6 @@ before_script: script: - ENABLE_SECOND_LEVEL_CACHE=0 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml $PHPUNIT_FLAGS - ENABLE_SECOND_LEVEL_CACHE=1 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml --exclude-group performance,non-cacheable,locking_functional - - ./vendor/bin/docheader check lib/ after_script: - if [[ $TRAVIS_PHP_VERSION = '7.0' && $DB = 'sqlite' ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi From 5c6ecdcf1b7a13e1ee4f12774b8871cce0a2e9ed Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Wed, 26 Oct 2016 13:27:29 -0300 Subject: [PATCH 102/877] Revert "add license template file" This reverts commit e4050edb4ecc76de625547343ed4431fa64f230c. --- .docheader | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 .docheader diff --git a/.docheader b/.docheader deleted file mode 100644 index 23753e7fef2..00000000000 --- a/.docheader +++ /dev/null @@ -1,17 +0,0 @@ -/* - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * This software consists of voluntary contributions made by many individuals - * and is licensed under the MIT license. For more information, see - * . - */ From 83da3d4b04e14e012568043f62ce6fd0faab8b2e Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Wed, 26 Oct 2016 13:27:38 -0300 Subject: [PATCH 103/877] Revert "composer require --dev malukenho/docheader" This reverts commit 81fefb40dbd6b7b6f913501616075ecc779a1742. --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 533c1929905..f5b3b08f702 100644 --- a/composer.json +++ b/composer.json @@ -25,8 +25,7 @@ }, "require-dev": { "symfony/yaml": "~2.3|~3.0", - "phpunit/phpunit": "^5.4", - "malukenho/docheader": "^0.1.4" + "phpunit/phpunit": "^5.4" }, "suggest": { "symfony/yaml": "If you want to use YAML Metadata Mapping Driver" From 11c2d815efed0d2c7bf2c03a00134e3fd5e7dfbf Mon Sep 17 00:00:00 2001 From: mike Date: Thu, 3 Nov 2016 20:40:48 +0100 Subject: [PATCH 104/877] Correcting a use statment in the documentation --- docs/en/reference/tools.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/tools.rst b/docs/en/reference/tools.rst index 51f4573000e..d9773519141 100644 --- a/docs/en/reference/tools.rst +++ b/docs/en/reference/tools.rst @@ -476,7 +476,7 @@ To include a new command on Doctrine Console, you need to do modify the Date: Sun, 6 Nov 2016 13:37:07 +0100 Subject: [PATCH 105/877] Fixed typo regarding the id generator mandatory for composite primary keys The strategy for composite primary keys must be "NONE" although the id generator class is \Doctrine\ORM\Id\AssignedGenerator. Calling the strategy "ASSIGNED" is misleading. --- docs/en/tutorials/composite-primary-keys.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/tutorials/composite-primary-keys.rst b/docs/en/tutorials/composite-primary-keys.rst index dd4e49e04aa..d8256db7561 100644 --- a/docs/en/tutorials/composite-primary-keys.rst +++ b/docs/en/tutorials/composite-primary-keys.rst @@ -13,7 +13,7 @@ This tutorial shows how the semantics of composite primary keys work and how the General Considerations ~~~~~~~~~~~~~~~~~~~~~~ -Every entity with a composite key cannot use an id generator other than "ASSIGNED". That means +Every entity with a composite key cannot use an id generator other than "NONE". That means the ID fields have to have their values set before you call ``EntityManager#persist($entity)``. Primitive Types only From 155672af4078fe8e45db9647ab00a0e8eadc515d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Schr=C3=B6der?= Date: Sun, 6 Nov 2016 14:05:50 +0100 Subject: [PATCH 106/877] Fixed typos regarding the strategy for composite keys (xml mapping reference) The strategy for composite primary keys must be "NONE" although the id generator class is \Doctrine\ORM\Id\AssignedGenerator. Calling the strategy "ASSIGNED" is misleading. --- docs/en/reference/xml-mapping.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/reference/xml-mapping.rst b/docs/en/reference/xml-mapping.rst index dbf97dc0ad1..5f013152789 100644 --- a/docs/en/reference/xml-mapping.rst +++ b/docs/en/reference/xml-mapping.rst @@ -321,12 +321,12 @@ Using the simplified definition above Doctrine will use no identifier strategy for this entity. That means you have to manually set the identifier before calling ``EntityManager#persist($entity)``. This is the so called -``ASSIGNED`` strategy. +``NONE`` strategy. If you want to switch the identifier generation strategy you have to nest a ```` element inside the id-element. This of course only works for surrogate keys. For composite keys you always -have to use the ``ASSIGNED`` strategy. +have to use the ``NONE`` strategy. .. code-block:: xml From 0bf3d7f84c4a20a85e222075f88b8c7a64aea157 Mon Sep 17 00:00:00 2001 From: Vladimir Reznichenko Date: Sun, 6 Nov 2016 14:22:47 +0100 Subject: [PATCH 107/877] Static Code Analysis with Php Inspections (EA Extended) --- lib/Doctrine/ORM/Cache/DefaultCache.php | 2 +- lib/Doctrine/ORM/Cache/Lock.php | 2 +- lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php | 3 +++ lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php | 6 +++--- lib/Doctrine/ORM/Query/ParameterTypeInferer.php | 4 ++-- lib/Doctrine/ORM/Query/TreeWalkerChainIterator.php | 2 +- lib/Doctrine/ORM/QueryBuilder.php | 2 +- .../Tools/Console/Command/ConvertDoctrine1SchemaCommand.php | 1 + .../ORM/Tools/Console/Command/ValidateSchemaCommand.php | 2 +- lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php | 2 +- lib/Doctrine/ORM/Tools/EntityGenerator.php | 2 +- 11 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/Doctrine/ORM/Cache/DefaultCache.php b/lib/Doctrine/ORM/Cache/DefaultCache.php index 78a22a80f1d..2557da4c175 100644 --- a/lib/Doctrine/ORM/Cache/DefaultCache.php +++ b/lib/Doctrine/ORM/Cache/DefaultCache.php @@ -314,7 +314,7 @@ private function buildEntityCacheKey(ClassMetadata $metadata, $identifier) private function buildCollectionCacheKey(ClassMetadata $metadata, $association, $ownerIdentifier) { if ( ! is_array($ownerIdentifier)) { - $ownerIdentifier = $this->toIdentifierArray($metadata, $ownerIdentifier);; + $ownerIdentifier = $this->toIdentifierArray($metadata, $ownerIdentifier); } return new CollectionCacheKey($metadata->rootEntityName, $association, $ownerIdentifier); diff --git a/lib/Doctrine/ORM/Cache/Lock.php b/lib/Doctrine/ORM/Cache/Lock.php index 5346aa32371..60f7d6c9d7d 100644 --- a/lib/Doctrine/ORM/Cache/Lock.php +++ b/lib/Doctrine/ORM/Cache/Lock.php @@ -53,6 +53,6 @@ public function __construct($value, $time = null) */ public static function createLockRead() { - return new self(uniqid(time())); + return new self(uniqid(time(), true)); } } diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 9e036b652d6..2d901322961 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -1629,6 +1629,7 @@ protected function _validateAndCompleteOneToOneMapping(array $mapping) ? $joinColumn['fieldName'] : $joinColumn['name']; } + unset($joinColumn); if ($uniqueConstraintColumns) { if ( ! $this->table) { @@ -1754,6 +1755,7 @@ protected function _validateAndCompleteManyToManyMapping(array $mapping) $mapping['relationToSourceKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName']; $mapping['joinTableColumns'][] = $joinColumn['name']; } + unset($joinColumn); foreach ($mapping['joinTable']['inverseJoinColumns'] as &$inverseJoinColumn) { if (empty($inverseJoinColumn['name'])) { @@ -1781,6 +1783,7 @@ protected function _validateAndCompleteManyToManyMapping(array $mapping) $mapping['relationToTargetKeyColumns'][$inverseJoinColumn['name']] = $inverseJoinColumn['referencedColumnName']; $mapping['joinTableColumns'][] = $inverseJoinColumn['name']; } + unset($inverseJoinColumn); } $mapping['orphanRemoval'] = isset($mapping['orphanRemoval']) && $mapping['orphanRemoval']; diff --git a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php index ac3b309fd7e..d6ddaf2d048 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php @@ -227,7 +227,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $fkCols = $myFk->getForeignColumns(); $cols = $myFk->getColumns(); - for ($i = 0; $i < count($cols); $i++) { + for ($i = 0, $colsCount = count($cols); $i < $colsCount; $i++) { $associationMapping['joinTable']['joinColumns'][] = array( 'name' => $cols[$i], 'referencedColumnName' => $fkCols[$i], @@ -237,7 +237,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $fkCols = $otherFk->getForeignColumns(); $cols = $otherFk->getColumns(); - for ($i = 0; $i < count($cols); $i++) { + for ($i = 0, $colsCount = count($cols); $i < $colsCount; $i++) { $associationMapping['joinTable']['inverseJoinColumns'][] = array( 'name' => $cols[$i], 'referencedColumnName' => $fkCols[$i], @@ -465,7 +465,7 @@ private function buildToOneAssociationMappings(ClassMetadataInfo $metadata) $associationMapping['id'] = true; } - for ($i = 0; $i < count($fkColumns); $i++) { + for ($i = 0, $fkColumnsCount = count($fkColumns); $i < $fkColumnsCount; $i++) { $associationMapping['joinColumns'][] = array( 'name' => $fkColumns[$i], 'referencedColumnName' => $fkForeignColumns[$i], diff --git a/lib/Doctrine/ORM/Query/ParameterTypeInferer.php b/lib/Doctrine/ORM/Query/ParameterTypeInferer.php index a12a559a730..597c7e2ea07 100644 --- a/lib/Doctrine/ORM/Query/ParameterTypeInferer.php +++ b/lib/Doctrine/ORM/Query/ParameterTypeInferer.php @@ -45,7 +45,7 @@ class ParameterTypeInferer */ public static function inferType($value) { - if (is_integer($value)) { + if (is_int($value)) { return Type::INTEGER; } @@ -58,7 +58,7 @@ public static function inferType($value) } if (is_array($value)) { - return is_integer(current($value)) + return is_int(current($value)) ? Connection::PARAM_INT_ARRAY : Connection::PARAM_STR_ARRAY; } diff --git a/lib/Doctrine/ORM/Query/TreeWalkerChainIterator.php b/lib/Doctrine/ORM/Query/TreeWalkerChainIterator.php index ee329604f8b..30db0817505 100644 --- a/lib/Doctrine/ORM/Query/TreeWalkerChainIterator.php +++ b/lib/Doctrine/ORM/Query/TreeWalkerChainIterator.php @@ -119,7 +119,7 @@ public function offsetGet($offset) */ public function offsetSet($offset, $value) { - if (is_null($offset)) { + if (null === $offset) { $this->walkers[] = $value; } else { $this->walkers[$offset] = $value; diff --git a/lib/Doctrine/ORM/QueryBuilder.php b/lib/Doctrine/ORM/QueryBuilder.php index ca754d66dd2..455e39ab38c 100644 --- a/lib/Doctrine/ORM/QueryBuilder.php +++ b/lib/Doctrine/ORM/QueryBuilder.php @@ -1458,7 +1458,7 @@ private function _getReducedDQLQueryPart($queryPartName, $options = array()) */ public function resetDQLParts($parts = null) { - if (is_null($parts)) { + if (null === $parts) { $parts = array_keys($this->_dqlParts); } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php index 71d72deb84d..0eb1735dc76 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php @@ -180,6 +180,7 @@ public function convertDoctrine1Schema(array $fromPaths, $destPath, $toType, $nu ); } } + unset($dirName); if ( ! file_exists($destPath)) { throw new \InvalidArgumentException( diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ValidateSchemaCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ValidateSchemaCommand.php index eb7697ccb73..57b16fc1c46 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ValidateSchemaCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ValidateSchemaCommand.php @@ -87,7 +87,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln(''); } - $exit += 1; + ++$exit; } else { $output->writeln('[Mapping] OK - The mapping files are correct.'); } diff --git a/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php b/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php index 8c9a24f3887..41927ce7a39 100644 --- a/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php +++ b/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php @@ -78,7 +78,7 @@ public function dumpIdentityMap(EntityManagerInterface $em) $uow = $em->getUnitOfWork(); $identityMap = $uow->getIdentityMap(); - $fh = fopen($this->file, "x+"); + $fh = fopen($this->file, 'xb+'); if (count($identityMap) == 0) { fwrite($fh, "Flush Operation [".$this->context."] - Empty identity map.\n"); diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 0fd7f3e8453..3c840ecbb6e 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -808,7 +808,7 @@ protected function parseTokensInEntityFile($src) $inNamespace = false; $inClass = false; - for ($i = 0; $i < count($tokens); $i++) { + for ($i = 0, $tokensCount = count($tokens); $i < $tokensCount; $i++) { $token = $tokens[$i]; if (in_array($token[0], array(T_WHITESPACE, T_COMMENT, T_DOC_COMMENT))) { continue; From db375a22cc5b7a036e7dc8f3c4b2368cfddb6761 Mon Sep 17 00:00:00 2001 From: Vladimir Reznichenko Date: Sun, 6 Nov 2016 17:58:45 +0100 Subject: [PATCH 108/877] Static Code Analysis with Php Inspections (EA Extended): revert unsets --- lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php | 3 --- .../Tools/Console/Command/ConvertDoctrine1SchemaCommand.php | 1 - 2 files changed, 4 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 2d901322961..9e036b652d6 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -1629,7 +1629,6 @@ protected function _validateAndCompleteOneToOneMapping(array $mapping) ? $joinColumn['fieldName'] : $joinColumn['name']; } - unset($joinColumn); if ($uniqueConstraintColumns) { if ( ! $this->table) { @@ -1755,7 +1754,6 @@ protected function _validateAndCompleteManyToManyMapping(array $mapping) $mapping['relationToSourceKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName']; $mapping['joinTableColumns'][] = $joinColumn['name']; } - unset($joinColumn); foreach ($mapping['joinTable']['inverseJoinColumns'] as &$inverseJoinColumn) { if (empty($inverseJoinColumn['name'])) { @@ -1783,7 +1781,6 @@ protected function _validateAndCompleteManyToManyMapping(array $mapping) $mapping['relationToTargetKeyColumns'][$inverseJoinColumn['name']] = $inverseJoinColumn['referencedColumnName']; $mapping['joinTableColumns'][] = $inverseJoinColumn['name']; } - unset($inverseJoinColumn); } $mapping['orphanRemoval'] = isset($mapping['orphanRemoval']) && $mapping['orphanRemoval']; diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php index 0eb1735dc76..71d72deb84d 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php @@ -180,7 +180,6 @@ public function convertDoctrine1Schema(array $fromPaths, $destPath, $toType, $nu ); } } - unset($dirName); if ( ! file_exists($destPath)) { throw new \InvalidArgumentException( From cdf4af5f2747aafd3c24b04799c37650dd7a3d42 Mon Sep 17 00:00:00 2001 From: Alexander Guz Date: Wed, 16 Nov 2016 17:56:07 +0100 Subject: [PATCH 109/877] Added unit test for boolean option values. It fail now. In `XmlDriver::_parseOptions` we need somehow to maintain a list of options, that are supposed to be boolean, and then call `$this->evaluateBoolean()` on them. --- .../Tests/ORM/Mapping/XmlMappingDriverTest.php | 11 +++++++++-- .../xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php index 735c16ed586..213eba30bbf 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php @@ -34,7 +34,7 @@ public function testClassTableInheritanceDiscriminatorMap() } /** - * @expectedException Doctrine\ORM\Cache\CacheException + * @expectedException \Doctrine\ORM\Cache\CacheException * @expectedExceptionMessage Entity association field "Doctrine\Tests\ORM\Mapping\XMLSLC#foo" not configured as part of the second-level cache. */ public function testFailingSecondLevelCacheAssociation() @@ -132,7 +132,7 @@ public function testEmbeddedMapping() /** * @group DDC-1468 * - * @expectedException Doctrine\Common\Persistence\Mapping\MappingException + * @expectedException \Doctrine\Common\Persistence\Mapping\MappingException * @expectedExceptionMessage Invalid mapping file 'Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml' for class 'Doctrine\Tests\Models\Generic\SerializationModel'. */ public function testInvalidMappingFileException() @@ -140,6 +140,13 @@ public function testInvalidMappingFileException() $this->createClassMetadata('Doctrine\Tests\Models\Generic\SerializationModel'); } + public function testBooleanValuesForOptionIsSetCorrectly() + { + $class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\User'); + $this->assertInternalType('bool', $class->fieldMappings['name']['options']['bool_opt']); + $this->assertFalse($class->fieldMappings['name']['options']['bool_opt']); + } + /** * @param string $xmlMappingFile * @dataProvider dataValidSchema diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml index 28b1e057122..a4a0fcef7ed 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml @@ -50,6 +50,7 @@ + From 8580f02c6ac78d1ec3811d43025792abb21d4d47 Mon Sep 17 00:00:00 2001 From: Alexander Guz Date: Wed, 16 Nov 2016 18:07:58 +0100 Subject: [PATCH 110/877] #6129 Use User::class to get metadata instead of string. --- tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php index 213eba30bbf..b8d638e78bd 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php @@ -140,9 +140,12 @@ public function testInvalidMappingFileException() $this->createClassMetadata('Doctrine\Tests\Models\Generic\SerializationModel'); } + /** + * @group #6129 + */ public function testBooleanValuesForOptionIsSetCorrectly() { - $class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\User'); + $class = $this->createClassMetadata(User::class); $this->assertInternalType('bool', $class->fieldMappings['name']['options']['bool_opt']); $this->assertFalse($class->fieldMappings['name']['options']['bool_opt']); } From 7bf206adb46dcb2fba3d070caac483d8ff7888b1 Mon Sep 17 00:00:00 2001 From: Alexander Guz Date: Wed, 16 Nov 2016 20:01:11 +0100 Subject: [PATCH 111/877] #6129 Moved test to AbstractMappingDriverTest. --- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 7 +++- .../ORM/Mapping/AbstractMappingDriverTest.php | 39 +++++++++++++++---- .../ORM/Mapping/XmlMappingDriverTest.php | 10 ----- .../php/Doctrine.Tests.ORM.Mapping.User.php | 4 +- .../Doctrine.Tests.ORM.Mapping.User.dcm.xml | 3 +- .../Doctrine.Tests.ORM.Mapping.User.dcm.yml | 2 + 6 files changed, 43 insertions(+), 22 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 00de4f2ea11..90fba4abf8c 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -653,6 +653,8 @@ private function _parseOptions(SimpleXMLElement $options) { $array = array(); + $booleanOptions = ['unsigned', 'fixed']; + /* @var $option SimpleXMLElement */ foreach ($options as $option) { if ($option->count()) { @@ -664,7 +666,10 @@ private function _parseOptions(SimpleXMLElement $options) $attr = $option->attributes(); if (isset($attr->name)) { - $array[(string) $attr->name] = $value; + $attrName = (string) $attr->name; + $array[$attrName] = in_array($attrName, $booleanOptions) + ? $this->evaluateBoolean($value) + : $value; } else { $array[] = $value; } diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 8d90931f953..3cc86c77abe 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -210,11 +210,14 @@ public function testStringFieldMappings($class) /** * @depends testEntityTableNameAndInheritance + * * @param ClassMetadata $class + * + * @return ClassMetadata */ - public function testFieldOptions($class) + public function testFieldOptions(ClassMetadata $class) { - $expected = array('foo' => 'bar', 'baz' => array('key' => 'val')); + $expected = ['foo' => 'bar', 'baz' => ['key' => 'val'], 'fixed' => false]; $this->assertEquals($expected, $class->fieldMappings['name']['options']); return $class; @@ -226,7 +229,7 @@ public function testFieldOptions($class) */ public function testIdFieldOptions($class) { - $this->assertEquals(array('foo' => 'bar'), $class->fieldMappings['id']['options']); + $this->assertEquals(['foo' => 'bar', 'unsigned' => false], $class->fieldMappings['id']['options']); return $class; } @@ -244,6 +247,26 @@ public function testIdentifier($class) return $class; } + /** + * @group #6129 + * + * @depends testIdentifier + * + * @param ClassMetadata $class + * + * @return ClassMetadata + */ + public function testBooleanValuesForOptionIsSetCorrectly(ClassMetadata $class) + { + $this->assertInternalType('bool', $class->fieldMappings['id']['options']['unsigned']); + $this->assertFalse($class->fieldMappings['id']['options']['unsigned']); + + $this->assertInternalType('bool', $class->fieldMappings['name']['options']['fixed']); + $this->assertFalse($class->fieldMappings['name']['options']['fixed']); + + return $class; + } + /** * @depends testIdentifier * @param ClassMetadata $class @@ -1048,14 +1071,14 @@ class User { /** * @Id - * @Column(type="integer", options={"foo": "bar"}) + * @Column(type="integer", options={"foo": "bar", "unsigned": false}) * @generatedValue(strategy="AUTO") * @SequenceGenerator(sequenceName="tablename_seq", initialValue=1, allocationSize=100) **/ public $id; /** - * @Column(length=50, nullable=true, unique=true, options={"foo": "bar", "baz": {"key": "val"}}) + * @Column(length=50, nullable=true, unique=true, options={"foo": "bar", "baz": {"key": "val"}, "fixed": false}) */ public $name; @@ -1129,7 +1152,7 @@ public static function loadMetadata(ClassMetadataInfo $metadata) 'fieldName' => 'id', 'type' => 'integer', 'columnName' => 'id', - 'options' => array('foo' => 'bar'), + 'options' => array('foo' => 'bar', 'unsigned' => false), )); $metadata->mapField(array( 'fieldName' => 'name', @@ -1138,7 +1161,7 @@ public static function loadMetadata(ClassMetadataInfo $metadata) 'unique' => true, 'nullable' => true, 'columnName' => 'name', - 'options' => array('foo' => 'bar', 'baz' => array('key' => 'val')), + 'options' => array('foo' => 'bar', 'baz' => array('key' => 'val'), 'fixed' => false), )); $metadata->mapField(array( 'fieldName' => 'email', @@ -1474,4 +1497,4 @@ public static function loadMetadata(ClassMetadataInfo $metadata) class SingleTableEntityIncompleteDiscriminatorColumnMappingSub1 extends SingleTableEntityIncompleteDiscriminatorColumnMapping {} class SingleTableEntityIncompleteDiscriminatorColumnMappingSub2 - extends SingleTableEntityIncompleteDiscriminatorColumnMapping {} \ No newline at end of file + extends SingleTableEntityIncompleteDiscriminatorColumnMapping {} diff --git a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php index b8d638e78bd..ae188057d26 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php @@ -140,16 +140,6 @@ public function testInvalidMappingFileException() $this->createClassMetadata('Doctrine\Tests\Models\Generic\SerializationModel'); } - /** - * @group #6129 - */ - public function testBooleanValuesForOptionIsSetCorrectly() - { - $class = $this->createClassMetadata(User::class); - $this->assertInternalType('bool', $class->fieldMappings['name']['options']['bool_opt']); - $this->assertFalse($class->fieldMappings['name']['options']['bool_opt']); - } - /** * @param string $xmlMappingFile * @dataProvider dataValidSchema diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php index 67dbd752d3e..5bcc6d0296f 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php @@ -19,7 +19,7 @@ 'fieldName' => 'id', 'type' => 'integer', 'columnName' => 'id', - 'options' => array('foo' => 'bar'), + 'options' => array('foo' => 'bar', 'unsigned' => false), )); $metadata->mapField(array( 'fieldName' => 'name', @@ -28,7 +28,7 @@ 'unique' => true, 'nullable' => true, 'columnName' => 'name', - 'options' => array('foo' => 'bar', 'baz' => array('key' => 'val')), + 'options' => array('foo' => 'bar', 'baz' => array('key' => 'val'), 'fixed' => false), )); $metadata->mapField(array( 'fieldName' => 'email', diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml index a4a0fcef7ed..bbf29aeaf70 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml @@ -41,6 +41,7 @@ + @@ -50,7 +51,7 @@ - + diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml index 457b24eea77..e3a32ce76be 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml @@ -18,6 +18,7 @@ Doctrine\Tests\ORM\Mapping\User: initialValue: 1 options: foo: bar + unsigned: false fields: name: type: string @@ -28,6 +29,7 @@ Doctrine\Tests\ORM\Mapping\User: foo: bar baz: key: val + fixed: false email: type: string column: user_email From f9a605f6ca1de37a8abf70e33fd363f7e3191c4c Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Thu, 17 Nov 2016 17:23:22 +0100 Subject: [PATCH 112/877] Add details about invalid Connection passed at creation. --- lib/Doctrine/ORM/EntityManager.php | 2 +- .../Doctrine/Tests/ORM/EntityManagerTest.php | 22 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 4de4932bcfc..112502b5af7 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -860,7 +860,7 @@ protected static function createConnection($connection, Configuration $config, E } if ( ! $connection instanceof Connection) { - throw new \InvalidArgumentException("Invalid argument: " . $connection); + throw new \InvalidArgumentException(sprintf('Invalid argument for connection "%s".', is_object($connection) ? get_class($connection) : gettype($connection) . '#' . $connection)); } if ($eventManager !== null && $connection->getEventManager() !== $eventManager) { diff --git a/tests/Doctrine/Tests/ORM/EntityManagerTest.php b/tests/Doctrine/Tests/ORM/EntityManagerTest.php index cf6fc99a439..1b08fb79e2b 100644 --- a/tests/Doctrine/Tests/ORM/EntityManagerTest.php +++ b/tests/Doctrine/Tests/ORM/EntityManagerTest.php @@ -2,6 +2,9 @@ namespace Doctrine\Tests\ORM; +use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; +use Doctrine\ORM\Configuration; +use Doctrine\ORM\EntityManager; use Doctrine\ORM\ORMException; use Doctrine\ORM\ORMInvalidArgumentException; use Doctrine\ORM\Query\ResultSetMapping; @@ -72,9 +75,9 @@ public function testCreateNamedNativeQuery() { $rsm = new ResultSetMapping(); $this->_em->getConfiguration()->addNamedNativeQuery('foo', 'SELECT foo', $rsm); - + $query = $this->_em->createNamedNativeQuery('foo'); - + $this->assertInstanceOf('Doctrine\ORM\NativeQuery', $query); } @@ -116,14 +119,14 @@ public function testCreateQuery() $this->assertInstanceOf('Doctrine\ORM\Query', $q); $this->assertEquals('SELECT 1', $q->getDql()); } - + /** * @covers Doctrine\ORM\EntityManager::createNamedQuery */ public function testCreateNamedQuery() { $this->_em->getConfiguration()->addNamedQuery('foo', 'SELECT 1'); - + $query = $this->_em->createNamedQuery('foo'); $this->assertInstanceOf('Doctrine\ORM\Query', $query); $this->assertEquals('SELECT 1', $query->getDql()); @@ -204,4 +207,15 @@ public function transactionalCallback($em) $this->assertSame($this->_em, $em); return 'callback'; } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessageRegExp /^Invalid argument for connection \"integer#1\".$/ + */ + public function testCreateInvalidConnection() + { + $config = new Configuration(); + $config->setMetadataDriverImpl($this->createMock(MappingDriver::class)); + EntityManager::create(1, $config); + } } From 8d433cdb394eaaabcf0a97908b47885b48a101fb Mon Sep 17 00:00:00 2001 From: Alexander Guz Date: Thu, 17 Nov 2016 21:05:58 +0100 Subject: [PATCH 113/877] #6129 Fixed code style and @depends in test. --- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 10 ++++------ .../Tests/ORM/Mapping/AbstractMappingDriverTest.php | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 90fba4abf8c..3d849918094 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -653,8 +653,6 @@ private function _parseOptions(SimpleXMLElement $options) { $array = array(); - $booleanOptions = ['unsigned', 'fixed']; - /* @var $option SimpleXMLElement */ foreach ($options as $option) { if ($option->count()) { @@ -663,11 +661,11 @@ private function _parseOptions(SimpleXMLElement $options) $value = (string) $option; } - $attr = $option->attributes(); + $attributes = $option->attributes(); - if (isset($attr->name)) { - $attrName = (string) $attr->name; - $array[$attrName] = in_array($attrName, $booleanOptions) + if (isset($attributes->name)) { + $nameAttribute = (string) $attributes->name; + $array[$nameAttribute] = in_array($nameAttribute, ['unsigned', 'fixed']) ? $this->evaluateBoolean($value) : $value; } else { diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 3cc86c77abe..c4fd1381dc5 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -250,7 +250,7 @@ public function testIdentifier($class) /** * @group #6129 * - * @depends testIdentifier + * @depends testLoadMapping * * @param ClassMetadata $class * From e37041aa942f52386586773d7304b50e069e706d Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Fri, 18 Nov 2016 08:06:11 +0100 Subject: [PATCH 114/877] Update message. --- lib/Doctrine/ORM/EntityManager.php | 8 +++++++- tests/Doctrine/Tests/ORM/EntityManagerTest.php | 7 +++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 112502b5af7..51d6dbf0526 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -860,7 +860,13 @@ protected static function createConnection($connection, Configuration $config, E } if ( ! $connection instanceof Connection) { - throw new \InvalidArgumentException(sprintf('Invalid argument for connection "%s".', is_object($connection) ? get_class($connection) : gettype($connection) . '#' . $connection)); + throw new \InvalidArgumentException( + sprintf( + 'Invalid $connection argument of type %s given%s.', + is_object($connection) ? get_class($connection) : gettype($connection), + is_object($connection) ? '' : ': "' . $connection . '"' + ) + ); } if ($eventManager !== null && $connection->getEventManager() !== $eventManager) { diff --git a/tests/Doctrine/Tests/ORM/EntityManagerTest.php b/tests/Doctrine/Tests/ORM/EntityManagerTest.php index 1b08fb79e2b..ec7f1301f24 100644 --- a/tests/Doctrine/Tests/ORM/EntityManagerTest.php +++ b/tests/Doctrine/Tests/ORM/EntityManagerTest.php @@ -208,12 +208,11 @@ public function transactionalCallback($em) return 'callback'; } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessageRegExp /^Invalid argument for connection \"integer#1\".$/ - */ public function testCreateInvalidConnection() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessageRegExp('/^Invalid \$connection argument of type integer given: \"1\".$/'); + $config = new Configuration(); $config->setMetadataDriverImpl($this->createMock(MappingDriver::class)); EntityManager::create(1, $config); From d2643eeb8b445ad8a18982121833c29b2c3757d8 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 18 Nov 2016 09:19:27 +0100 Subject: [PATCH 115/877] #6136 Removed regex assertion - constant assertion is sufficient --- tests/Doctrine/Tests/ORM/EntityManagerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/EntityManagerTest.php b/tests/Doctrine/Tests/ORM/EntityManagerTest.php index ec7f1301f24..d0cf2bcbb57 100644 --- a/tests/Doctrine/Tests/ORM/EntityManagerTest.php +++ b/tests/Doctrine/Tests/ORM/EntityManagerTest.php @@ -211,7 +211,7 @@ public function transactionalCallback($em) public function testCreateInvalidConnection() { $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessageRegExp('/^Invalid \$connection argument of type integer given: \"1\".$/'); + $this->expectExceptionMessage('Invalid $connection argument of type integer given: "1".'); $config = new Configuration(); $config->setMetadataDriverImpl($this->createMock(MappingDriver::class)); From 53cd9c4ca8d33cfe40cf3e872094bd117472ab29 Mon Sep 17 00:00:00 2001 From: Dmytro Boiko Date: Sat, 19 Nov 2016 23:34:10 +0200 Subject: [PATCH 116/877] Added examples for version column in the xml and yml formats --- .../transactions-and-concurrency.rst | 74 ++++++++++++++----- 1 file changed, 56 insertions(+), 18 deletions(-) diff --git a/docs/en/reference/transactions-and-concurrency.rst b/docs/en/reference/transactions-and-concurrency.rst index 3c8cfe33b89..1b79adc577e 100644 --- a/docs/en/reference/transactions-and-concurrency.rst +++ b/docs/en/reference/transactions-and-concurrency.rst @@ -187,30 +187,68 @@ has been modified by someone else already. You designate a version field in an entity as follows. In this example we'll use an integer. -.. code-block:: php +.. configuration-block:: - + + + + + + .. code-block:: yaml + + User: + type: entity + fields: + version: + version: + type: integer Alternatively a datetime type can be used (which maps to a SQL timestamp or datetime): -.. code-block:: php +.. configuration-block:: - + + + + + + .. code-block:: yaml + + User: + type: entity + fields: + version: + version: + type: datetime Version numbers (not timestamps) should however be preferred as they can not potentially conflict in a highly concurrent From 317e86802dc2900d063a0dddf1b87467692bbb28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Tue, 13 Sep 2016 12:56:20 +0000 Subject: [PATCH 117/877] Make child entity share the timestamp region with parent class --- lib/Doctrine/ORM/AbstractQuery.php | 2 +- .../Entity/AbstractEntityPersister.php | 2 +- ...condLevelCacheJoinTableInheritanceTest.php | 47 ++++++++++++++++++- ...ndLevelCacheSingleTableInheritanceTest.php | 43 ++++++++++++++++- 4 files changed, 89 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 0089eeede1b..5f4248b5f26 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -1037,7 +1037,7 @@ private function getTimestampKey() $metadata = $this->_em->getClassMetadata($entityName); - return new Cache\TimestampCacheKey($metadata->getTableName()); + return new Cache\TimestampCacheKey($metadata->rootEntityName); } /** diff --git a/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php b/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php index 1a41014b94f..a4e4f135c94 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php @@ -130,7 +130,7 @@ public function __construct(EntityPersister $persister, Region $region, EntityMa $this->cacheLogger = $cacheConfig->getCacheLogger(); $this->timestampRegion = $cacheFactory->getTimestampRegion(); $this->hydrator = $cacheFactory->buildEntityHydrator($em, $class); - $this->timestampKey = new TimestampCacheKey($this->class->getTableName()); + $this->timestampKey = new TimestampCacheKey($this->class->rootEntityName); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheJoinTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheJoinTableInheritanceTest.php index e81b08b96f9..9864172fab4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheJoinTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheJoinTableInheritanceTest.php @@ -3,8 +3,8 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Tests\Models\Cache\Attraction; -use Doctrine\Tests\Models\Cache\AttractionInfo; use Doctrine\Tests\Models\Cache\AttractionContactInfo; +use Doctrine\Tests\Models\Cache\AttractionInfo; use Doctrine\Tests\Models\Cache\AttractionLocationInfo; /** @@ -188,4 +188,47 @@ public function testOneToManyRelationJoinTable() $this->assertInstanceOf(AttractionContactInfo::CLASSNAME, $entity->getInfos()->get(0)); $this->assertEquals($this->attractionsInfo[0]->getFone(), $entity->getInfos()->get(0)->getFone()); } -} \ No newline at end of file + + public function testQueryCacheShouldBeEvictedOnTimestampUpdate() + { + $this->loadFixturesCountries(); + $this->loadFixturesStates(); + $this->loadFixturesCities(); + $this->loadFixturesAttractions(); + $this->loadFixturesAttractionsInfo(); + $this->evictRegions(); + $this->_em->clear(); + + $queryCount = $this->getCurrentQueryCount(); + $dql = 'SELECT attractionInfo FROM Doctrine\Tests\Models\Cache\AttractionInfo attractionInfo'; + + $result1 = $this->_em->createQuery($dql) + ->setCacheable(true) + ->getResult(); + + $this->assertCount(count($this->attractionsInfo), $result1); + $this->assertEquals($queryCount + 5, $this->getCurrentQueryCount()); + + $contact = new AttractionContactInfo( + '1234-1234', + $this->_em->find(Attraction::class, $this->attractions[5]->getId()) + ); + + $this->_em->persist($contact); + $this->_em->flush(); + $this->_em->clear(); + + $queryCount = $this->getCurrentQueryCount(); + + $result2 = $this->_em->createQuery($dql) + ->setCacheable(true) + ->getResult(); + + $this->assertCount(count($this->attractionsInfo) + 1, $result2); + $this->assertEquals($queryCount + 6, $this->getCurrentQueryCount()); + + foreach ($result2 as $entity) { + $this->assertInstanceOf(AttractionInfo::CLASSNAME, $entity); + } + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheSingleTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheSingleTableInheritanceTest.php index 3f8487d9946..0ee1df176fd 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheSingleTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheSingleTableInheritanceTest.php @@ -210,4 +210,45 @@ public function testOneToManyRelationSingleTable() $this->assertEquals($this->attractions[0]->getName(), $entity->getAttractions()->get(0)->getName()); $this->assertEquals($this->attractions[1]->getName(), $entity->getAttractions()->get(1)->getName()); } -} \ No newline at end of file + + public function testQueryCacheShouldBeEvictedOnTimestampUpdate() + { + $this->loadFixturesCountries(); + $this->loadFixturesStates(); + $this->loadFixturesCities(); + $this->loadFixturesAttractions(); + $this->_em->clear(); + + $queryCount = $this->getCurrentQueryCount(); + $dql = 'SELECT attraction FROM Doctrine\Tests\Models\Cache\Attraction attraction'; + + $result1 = $this->_em->createQuery($dql) + ->setCacheable(true) + ->getResult(); + + $this->assertCount(count($this->attractions), $result1); + $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); + + $contact = new Beach( + 'Botafogo', + $this->_em->find(City::class, $this->cities[1]->getId()) + ); + + $this->_em->persist($contact); + $this->_em->flush(); + $this->_em->clear(); + + $queryCount = $this->getCurrentQueryCount(); + + $result2 = $this->_em->createQuery($dql) + ->setCacheable(true) + ->getResult(); + + $this->assertCount(count($this->attractions) + 1, $result2); + $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); + + foreach ($result2 as $entity) { + $this->assertInstanceOf(Attraction::CLASSNAME, $entity); + } + } +} From 39dcf3e4c6ff3e49ea9d318d6b76709bc4d08b0f Mon Sep 17 00:00:00 2001 From: Matteo Beccati Date: Tue, 22 Nov 2016 07:33:39 +0100 Subject: [PATCH 118/877] Fix incompatibility w/ PHP7.2+ Mock_ParserResult_*::getParameterMappings() was returning null, which was then passed to count() on Query.php:308, causing a "Parameter must be an array or an object that implements Countable" error. --- tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php index a2444527102..bdfe766ce34 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php @@ -135,7 +135,9 @@ public function testQueryCache_HitDoesNotSaveParserResult() ->method('execute') ->will($this->returnValue( 10 )); - $parserResultMock = $this->createMock(ParserResult::class); + $parserResultMock = $this->getMockBuilder(ParserResult::class) + ->setMethods(array('getSqlExecutor')) + ->getMock(); $parserResultMock->expects($this->once()) ->method('getSqlExecutor') ->will($this->returnValue($sqlExecMock)); From 1b39cd87ad58b95d44ceb01c73db82aedfacec90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 20 Nov 2016 20:57:19 +0000 Subject: [PATCH 119/877] Allow using objects as discriminators --- .../ORM/Internal/Hydration/ObjectHydrator.php | 7 +- .../ORM/Functional/Ticket/GH6141Test.php | 195 ++++++++++++++++++ 2 files changed, 199 insertions(+), 3 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH6141Test.php diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index 14aed2a67fe..d2d23a252bf 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -251,12 +251,13 @@ private function getEntity(array $data, $dqlAlias) } $discrMap = $this->_metadataCache[$className]->discriminatorMap; + $discriminatorValue = (string) $data[$discrColumn]; - if ( ! isset($discrMap[$data[$discrColumn]])) { - throw HydrationException::invalidDiscriminatorValue($data[$discrColumn], array_keys($discrMap)); + if ( ! isset($discrMap[$discriminatorValue])) { + throw HydrationException::invalidDiscriminatorValue($discriminatorValue, array_keys($discrMap)); } - $className = $discrMap[$data[$discrColumn]]; + $className = $discrMap[$discriminatorValue]; unset($data[$discrColumn]); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6141Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6141Test.php new file mode 100644 index 00000000000..3ca71928dc4 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6141Test.php @@ -0,0 +1,195 @@ +_schemaTool->createSchema( + [ + $this->_em->getClassMetadata(GH6141Person::class), + $this->_em->getClassMetadata(GH6141Boss::class), + $this->_em->getClassMetadata(GH6141Employee::class), + ] + ); + } + + public function testEnumDiscriminatorsShouldBeConvertedToString() + { + $boss = new GH6141Boss('John'); + $employee = new GH6141Employee('Bob'); + + $this->_em->persist($boss); + $this->_em->persist($employee); + $this->_em->flush(); + $this->_em->clear(); + + // Using DQL here to make sure that we'll use ObjectHydrator instead of SimpleObjectHydrator + $query = $this->_em->createQueryBuilder() + ->select('person') + ->from(GH6141Person::class, 'person') + ->where('person.name = :name') + ->setMaxResults(1) + ->getQuery(); + + $query->setParameter('name', 'John'); + self::assertEquals($boss, $query->getOneOrNullResult(AbstractQuery::HYDRATE_OBJECT)); + self::assertEquals( + GH6141People::get(GH6141People::BOSS), + $query->getOneOrNullResult(AbstractQuery::HYDRATE_ARRAY)['discr'] + ); + + $query->setParameter('name', 'Bob'); + self::assertEquals($employee, $query->getOneOrNullResult(AbstractQuery::HYDRATE_OBJECT)); + self::assertEquals( + GH6141People::get(GH6141People::EMPLOYEE), + $query->getOneOrNullResult(AbstractQuery::HYDRATE_ARRAY)['discr'] + ); + } +} + +class GH6141PeopleType extends StringType +{ + const NAME = 'gh6141people'; + + /** + * {@inheritdoc} + */ + public function convertToDatabaseValue($value, AbstractPlatform $platform) + { + if (!$value instanceof GH6141People) { + $value = GH6141People::get($value); + } + + return (string) $value; + } + + /** + * {@inheritdoc} + */ + public function convertToPhpValue($value, AbstractPlatform $platform) + { + return GH6141People::get($value); + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return self::NAME; + } +} + +class GH6141People +{ + const BOSS = 'boss'; + const EMPLOYEE = 'employee'; + + /** + * @var string + */ + private $value; + + /** + * @param string $value + * + * @return GH6141People + * + * @throws \InvalidArgumentException + */ + public static function get($value) + { + if (!self::isValid($value)) { + throw new \InvalidArgumentException(); + } + + return new self($value); + } + + /** + * @param string $valid + * + * @return bool + */ + private static function isValid($valid) + { + return in_array($valid, [self::BOSS, self::EMPLOYEE]); + } + + /** + * @param string $value + */ + private function __construct($value) + { + $this->value = $value; + } + + /** + * @return string + */ + public function getValue() + { + return $this->value; + } + + /** + * @return string + */ + public function __toString() + { + return $this->value; + } +} + +/** + * @Entity + * @InheritanceType("JOINED") + * @DiscriminatorColumn(name="discr", type="gh6141people") + * @DiscriminatorMap({ + * "boss" = GH6141Boss::class, + * "employee" = GH6141Employee::class + * }) + */ +abstract class GH6141Person +{ + /** + * @Id + * @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + */ + public $id; + + /** + * @Column(type="string") + */ + public $name; + + /** + * @param string $name + */ + public function __construct($name) + { + $this->name = $name; + } +} + +/** @Entity */ +class GH6141Boss extends GH6141Person +{ +} + +/** @Entity */ +class GH6141Employee extends GH6141Person +{ +} From 6344fd34cb3e9746741fa8903017299ee33164de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 23 Nov 2016 19:20:47 +0100 Subject: [PATCH 120/877] Improving the documentation of enums as discriminators test @Ocramius was too eager to merge stuff Related to: https://github.com/doctrine/doctrine2/pull/6141 --- .../Tests/ORM/Functional/Ticket/GH6141Test.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6141Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6141Test.php index 3ca71928dc4..00ae936a4b1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6141Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6141Test.php @@ -24,6 +24,13 @@ protected function setUp() ); } + /** + * The intent of this test is to ensure that the ORM is capable + * of using objects as discriminators (which makes things a bit + * more dynamic as you can see on the mapping of `GH6141Person`) + * + * @group 6141 + */ public function testEnumDiscriminatorsShouldBeConvertedToString() { $boss = new GH6141Boss('John'); @@ -157,8 +164,8 @@ public function __toString() * @InheritanceType("JOINED") * @DiscriminatorColumn(name="discr", type="gh6141people") * @DiscriminatorMap({ - * "boss" = GH6141Boss::class, - * "employee" = GH6141Employee::class + * Doctrine\Tests\ORM\Functional\Ticket\GH6141People::BOSS = GH6141Boss::class, + * Doctrine\Tests\ORM\Functional\Ticket\GH6141People::EMPLOYEE = GH6141Employee::class * }) */ abstract class GH6141Person From e2b198112e79accd1e45affc63e54a52043400a8 Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Sun, 21 Aug 2016 21:05:55 -0300 Subject: [PATCH 121/877] [minor] Add missing type hints, add strictness for some checks, remove some useless calls --- .../ReadOnlyCachedCollectionPersister.php | 2 +- .../Entity/AbstractEntityPersister.php | 4 +- .../ORM/Mapping/ClassMetadataInfo.php | 46 +++++++--------- lib/Doctrine/ORM/Query/AST/InputParameter.php | 2 +- lib/Doctrine/ORM/Query/SqlWalker.php | 5 +- lib/Doctrine/ORM/Tools/EntityGenerator.php | 55 ++++++++++--------- lib/Doctrine/ORM/Tools/SchemaTool.php | 8 +-- .../Tests/ORM/Functional/Locking/LockTest.php | 4 +- 8 files changed, 59 insertions(+), 67 deletions(-) diff --git a/lib/Doctrine/ORM/Cache/Persister/Collection/ReadOnlyCachedCollectionPersister.php b/lib/Doctrine/ORM/Cache/Persister/Collection/ReadOnlyCachedCollectionPersister.php index 4f35ceb10dc..dfc816c5ab9 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Collection/ReadOnlyCachedCollectionPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Collection/ReadOnlyCachedCollectionPersister.php @@ -35,7 +35,7 @@ class ReadOnlyCachedCollectionPersister extends NonStrictReadWriteCachedCollecti */ public function update(PersistentCollection $collection) { - if ($collection->isDirty() && count($collection->getSnapshot()) > 0) { + if ($collection->isDirty() && $collection->getSnapshot()) { throw CacheException::updateReadOnlyCollection(ClassUtils::getClass($collection->getOwner()), $this->association['fieldName']); } diff --git a/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php b/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php index a4e4f135c94..c1e2d50adbd 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php @@ -104,7 +104,7 @@ abstract class AbstractEntityPersister implements CachedEntityPersister /** * Associations configured as FETCH_EAGER, as well as all inverse one-to-one associations. * - * @var array + * @var array|null */ protected $joinedAssociations; @@ -476,7 +476,7 @@ public function loadById(array $identifier, $entity = null) $cacheEntry = $this->hydrator->buildCacheEntry($class, $cacheKey, $entity); $cached = $this->region->put($cacheKey, $cacheEntry); - if ($cached && ($this->joinedAssociations === null || count($this->joinedAssociations) > 0)) { + if ($cached && (null === $this->joinedAssociations || $this->joinedAssociations)) { $this->storeJoinedAssociations($entity); } diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 9e036b652d6..8fa11f36046 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -720,7 +720,7 @@ public function getIdentifierValues($entity) foreach ($this->identifier as $idField) { $value = $this->reflFields[$idField]->getValue($entity); - if ($value !== null) { + if (null !== $value) { $id[$idField] = $value; } } @@ -1085,7 +1085,7 @@ public function enableCache(array $cache) */ public function enableAssociationCache($fieldName, array $cache) { - $this->associationMappings[$fieldName]['cache'] = $this->getAssociationCacheDefaults ($fieldName, $cache); + $this->associationMappings[$fieldName]['cache'] = $this->getAssociationCacheDefaults($fieldName, $cache); } /** @@ -1128,7 +1128,7 @@ public function setChangeTrackingPolicy($policy) */ public function isChangeTrackingDeferredExplicit() { - return $this->changeTrackingPolicy == self::CHANGETRACKING_DEFERRED_EXPLICIT; + return self::CHANGETRACKING_DEFERRED_EXPLICIT === $this->changeTrackingPolicy; } /** @@ -1138,7 +1138,7 @@ public function isChangeTrackingDeferredExplicit() */ public function isChangeTrackingDeferredImplicit() { - return $this->changeTrackingPolicy == self::CHANGETRACKING_DEFERRED_IMPLICIT; + return self::CHANGETRACKING_DEFERRED_IMPLICIT === $this->changeTrackingPolicy; } /** @@ -1148,7 +1148,7 @@ public function isChangeTrackingDeferredImplicit() */ public function isChangeTrackingNotify() { - return $this->changeTrackingPolicy == self::CHANGETRACKING_NOTIFY; + return self::CHANGETRACKING_NOTIFY === $this->changeTrackingPolicy; } /** @@ -1169,7 +1169,7 @@ public function isIdentifier($fieldName) return $fieldName === $this->identifier[0]; } - return in_array($fieldName, $this->identifier); + return in_array($fieldName, $this->identifier, true); } /** @@ -1183,11 +1183,7 @@ public function isUniqueField($fieldName) { $mapping = $this->getFieldMapping($fieldName); - if ($mapping !== false) { - return isset($mapping['unique']) && $mapping['unique'] == true; - } - - return false; + return false !== $mapping && isset($mapping['unique']) && $mapping['unique']; } /** @@ -1201,11 +1197,7 @@ public function isNullable($fieldName) { $mapping = $this->getFieldMapping($fieldName); - if ($mapping !== false) { - return isset($mapping['nullable']) && $mapping['nullable'] == true; - } - - return false; + return false !== $mapping && isset($mapping['nullable']) && $mapping['nullable']; } /** @@ -1391,7 +1383,7 @@ public function getSqlResultSetMappings() protected function _validateAndCompleteFieldMapping(array &$mapping) { // Check mandatory fields - if ( ! isset($mapping['fieldName']) || strlen($mapping['fieldName']) == 0) { + if ( ! isset($mapping['fieldName']) || !$mapping['fieldName']) { throw MappingException::missingFieldName($this->name); } @@ -1405,21 +1397,21 @@ protected function _validateAndCompleteFieldMapping(array &$mapping) $mapping['columnName'] = $this->namingStrategy->propertyToColumnName($mapping['fieldName'], $this->name); } - if ($mapping['columnName'][0] === '`') { + if ('`' === $mapping['columnName'][0]) { $mapping['columnName'] = trim($mapping['columnName'], '`'); $mapping['quoted'] = true; } $this->columnNames[$mapping['fieldName']] = $mapping['columnName']; - if (isset($this->fieldNames[$mapping['columnName']]) || ($this->discriminatorColumn != null && $this->discriminatorColumn['name'] == $mapping['columnName'])) { + if (isset($this->fieldNames[$mapping['columnName']]) || ($this->discriminatorColumn && $this->discriminatorColumn['name'] === $mapping['columnName'])) { throw MappingException::duplicateColumnName($this->name, $mapping['columnName']); } $this->fieldNames[$mapping['columnName']] = $mapping['fieldName']; // Complete id mapping - if (isset($mapping['id']) && $mapping['id'] === true) { + if (isset($mapping['id']) && true === $mapping['id']) { if ($this->versionField == $mapping['fieldName']) { throw MappingException::cannotVersionIdField($this->name, $mapping['fieldName']); } @@ -1435,7 +1427,7 @@ protected function _validateAndCompleteFieldMapping(array &$mapping) } if (Type::hasType($mapping['type']) && Type::getType($mapping['type'])->canRequireSQLConversion()) { - if (isset($mapping['id']) && $mapping['id'] === true) { + if (isset($mapping['id']) && true === $mapping['id']) { throw MappingException::sqlConversionNotAllowedForIdentifiers($this->name, $mapping['fieldName'], $mapping['type']); } @@ -1478,13 +1470,13 @@ protected function _validateAndCompleteAssociationMapping(array $mapping) $mapping['targetEntity'] = ltrim($mapping['targetEntity'], '\\'); } - if (($mapping['type'] & self::MANY_TO_ONE) > 0 && isset($mapping['orphanRemoval']) && $mapping['orphanRemoval'] == true) { + if (($mapping['type'] & self::MANY_TO_ONE) > 0 && isset($mapping['orphanRemoval']) && $mapping['orphanRemoval']) { throw MappingException::illegalOrphanRemoval($this->name, $mapping['fieldName']); } // Complete id mapping - if (isset($mapping['id']) && $mapping['id'] === true) { - if (isset($mapping['orphanRemoval']) && $mapping['orphanRemoval'] == true) { + if (isset($mapping['id']) && true === $mapping['id']) { + if (isset($mapping['orphanRemoval']) && $mapping['orphanRemoval']) { throw MappingException::illegalOrphanRemovalOnIdentifierAssociation($this->name, $mapping['fieldName']); } @@ -1511,7 +1503,7 @@ protected function _validateAndCompleteAssociationMapping(array $mapping) // Mandatory attributes for both sides // Mandatory: fieldName, targetEntity - if ( ! isset($mapping['fieldName']) || strlen($mapping['fieldName']) == 0) { + if ( ! isset($mapping['fieldName']) || !$mapping['fieldName']) { throw MappingException::missingFieldName($this->name); } @@ -1531,7 +1523,7 @@ protected function _validateAndCompleteAssociationMapping(array $mapping) $mapping['isOwningSide'] = false; } - if (isset($mapping['id']) && $mapping['id'] === true && $mapping['type'] & self::TO_MANY) { + if (isset($mapping['id']) && true === $mapping['id'] && $mapping['type'] & self::TO_MANY) { throw MappingException::illegalToManyIdentifierAssociation($this->name, $mapping['fieldName']); } @@ -3247,7 +3239,7 @@ public function fullyQualifiedClassName($className) return $className; } - if ($className !== null && strpos($className, '\\') === false && strlen($this->namespace) > 0) { + if ($className !== null && strpos($className, '\\') === false && $this->namespace) { return $this->namespace . '\\' . $className; } diff --git a/lib/Doctrine/ORM/Query/AST/InputParameter.php b/lib/Doctrine/ORM/Query/AST/InputParameter.php index cf50140be9b..4da550f9b4f 100644 --- a/lib/Doctrine/ORM/Query/AST/InputParameter.php +++ b/lib/Doctrine/ORM/Query/AST/InputParameter.php @@ -47,7 +47,7 @@ class InputParameter extends Node */ public function __construct($value) { - if (strlen($value) == 1) { + if (strlen($value) === 1) { throw \Doctrine\ORM\Query\QueryException::invalidParameterFormat($value); } diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 0fb389de046..87daa694bc8 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -2119,10 +2119,9 @@ public function walkLiteral($literal) return $this->conn->quote($literal->value); case AST\Literal::BOOLEAN: - $bool = strtolower($literal->value) == 'true' ? true : false; - $boolVal = $this->conn->getDatabasePlatform()->convertBooleans($bool); + $bool = 'true' === strtolower($literal->value); - return $boolVal; + return $this->conn->getDatabasePlatform()->convertBooleans($bool); case AST\Literal::NUMERIC: return $literal->value; diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 3c840ecbb6e..fa6cbf12dd0 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -371,7 +371,7 @@ public function writeEntityClass(ClassMetadataInfo $metadata, $outputDirectory) mkdir($dir, 0775, true); } - $this->isNew = !file_exists($path) || (file_exists($path) && $this->regenerateEntityIfExists); + $this->isNew = !file_exists($path) || $this->regenerateEntityIfExists; if ( ! $this->isNew) { $this->parseTokensInEntityFile(file_get_contents($path)); @@ -390,7 +390,7 @@ public function writeEntityClass(ClassMetadataInfo $metadata, $outputDirectory) if ($this->isNew) { file_put_contents($path, $this->generateEntityClass($metadata)); // If entity exists and we're allowed to update the entity class - } elseif ( ! $this->isNew && $this->updateEntityIfExists) { + } elseif ($this->updateEntityIfExists) { file_put_contents($path, $this->generateUpdatedEntityClass($metadata, $path)); } chmod($path, 0664); @@ -442,7 +442,7 @@ public function generateUpdatedEntityClass(ClassMetadataInfo $metadata, $path) $body = str_replace('', $this->spaces, $body); $last = strrpos($currentCode, '}'); - return substr($currentCode, 0, $last) . $body . (strlen($body) > 0 ? "\n" : '') . "}\n"; + return substr($currentCode, 0, $last) . $body . ($body ? "\n" : '') . "}\n"; } /** @@ -802,22 +802,23 @@ function ($type, $variable) use ($maxParamTypeLength) { protected function parseTokensInEntityFile($src) { $tokens = token_get_all($src); - $lastSeenNamespace = ""; + $tokensCount = count($tokens); + $lastSeenNamespace = ''; $lastSeenClass = false; $inNamespace = false; $inClass = false; - for ($i = 0, $tokensCount = count($tokens); $i < $tokensCount; $i++) { + for ($i = 0; $i < $tokensCount; $i++) { $token = $tokens[$i]; - if (in_array($token[0], array(T_WHITESPACE, T_COMMENT, T_DOC_COMMENT))) { + if (in_array($token[0], array(T_WHITESPACE, T_COMMENT, T_DOC_COMMENT), true)) { continue; } if ($inNamespace) { - if ($token[0] == T_NS_SEPARATOR || $token[0] == T_STRING) { + if (in_array($token[0], array(T_NS_SEPARATOR, T_STRING), true)) { $lastSeenNamespace .= $token[1]; - } elseif (is_string($token) && in_array($token, array(';', '{'))) { + } elseif (is_string($token) && in_array($token, array(';', '{'), true)) { $inNamespace = false; } } @@ -829,18 +830,18 @@ protected function parseTokensInEntityFile($src) $this->staticReflection[$lastSeenClass]['methods'] = array(); } - if ($token[0] == T_NAMESPACE) { - $lastSeenNamespace = ""; + if (T_NAMESPACE === $token[0]) { + $lastSeenNamespace = ''; $inNamespace = true; - } elseif ($token[0] == T_CLASS && $tokens[$i-1][0] != T_DOUBLE_COLON) { + } elseif (T_CLASS === $token[0] && T_DOUBLE_COLON !== $tokens[$i-1][0]) { $inClass = true; - } elseif ($token[0] == T_FUNCTION) { - if ($tokens[$i+2][0] == T_STRING) { + } elseif (T_FUNCTION === $token[0]) { + if (T_STRING === $tokens[$i+2][0]) { $this->staticReflection[$lastSeenClass]['methods'][] = strtolower($tokens[$i+2][1]); - } elseif ($tokens[$i+2] == "&" && $tokens[$i+3][0] == T_STRING) { + } elseif ($tokens[$i+2] == '&' && T_STRING === $tokens[$i+3][0]) { $this->staticReflection[$lastSeenClass]['methods'][] = strtolower($tokens[$i+3][1]); } - } elseif (in_array($token[0], array(T_VAR, T_PUBLIC, T_PRIVATE, T_PROTECTED)) && $tokens[$i+2][0] != T_FUNCTION) { + } elseif (in_array($token[0], array(T_VAR, T_PUBLIC, T_PRIVATE, T_PROTECTED), true) && T_FUNCTION !== $tokens[$i+2][0]) { $this->staticReflection[$lastSeenClass]['properties'][] = substr($tokens[$i+2][1], 1); } } @@ -871,7 +872,7 @@ protected function hasProperty($property, ClassMetadataInfo $metadata) return ( isset($this->staticReflection[$metadata->name]) && - in_array($property, $this->staticReflection[$metadata->name]['properties']) + in_array($property, $this->staticReflection[$metadata->name]['properties'], true) ); } @@ -901,7 +902,7 @@ protected function hasMethod($method, ClassMetadataInfo $metadata) return ( isset($this->staticReflection[$metadata->name]) && - in_array(strtolower($method), $this->staticReflection[$metadata->name]['methods']) + in_array(strtolower($method), $this->staticReflection[$metadata->name]['methods'], true) ); } @@ -938,7 +939,7 @@ protected function getTraits(ClassMetadataInfo $metadata) */ protected function hasNamespace(ClassMetadataInfo $metadata) { - return strpos($metadata->name, '\\') ? true : false; + return (bool) strpos($metadata->name, '\\'); } /** @@ -946,7 +947,7 @@ protected function hasNamespace(ClassMetadataInfo $metadata) */ protected function extendsClass() { - return $this->classToExtend ? true : false; + return (bool) $this->classToExtend; } /** @@ -1051,7 +1052,7 @@ protected function generateEntityAnnotation(ClassMetadataInfo $metadata) * * @return string */ - protected function generateTableAnnotation($metadata) + protected function generateTableAnnotation(ClassMetadataInfo $metadata) { if ($metadata->isEmbeddedClass) { return ''; @@ -1090,7 +1091,7 @@ protected function generateTableAnnotation($metadata) * * @return string */ - protected function generateTableConstraints($constraintName, $constraints) + protected function generateTableConstraints($constraintName, array $constraints) { $annotations = array(); foreach ($constraints as $name => $constraint) { @@ -1109,7 +1110,7 @@ protected function generateTableConstraints($constraintName, $constraints) * * @return string */ - protected function generateInheritanceAnnotation($metadata) + protected function generateInheritanceAnnotation(ClassMetadataInfo $metadata) { if ($metadata->inheritanceType != ClassMetadataInfo::INHERITANCE_TYPE_NONE) { return '@' . $this->annotationsPrefix . 'InheritanceType("'.$this->getInheritanceTypeString($metadata->inheritanceType).'")'; @@ -1121,7 +1122,7 @@ protected function generateInheritanceAnnotation($metadata) * * @return string */ - protected function generateDiscriminatorColumnAnnotation($metadata) + protected function generateDiscriminatorColumnAnnotation(ClassMetadataInfo $metadata) { if ($metadata->inheritanceType != ClassMetadataInfo::INHERITANCE_TYPE_NONE) { $discrColumn = $metadata->discriminatorColumn; @@ -1138,7 +1139,7 @@ protected function generateDiscriminatorColumnAnnotation($metadata) * * @return string */ - protected function generateDiscriminatorMapAnnotation($metadata) + protected function generateDiscriminatorMapAnnotation(ClassMetadataInfo $metadata) { if ($metadata->inheritanceType != ClassMetadataInfo::INHERITANCE_TYPE_NONE) { $inheritanceClassMap = array(); @@ -1228,7 +1229,7 @@ protected function generateEntityStubMethods(ClassMetadataInfo $metadata) * * @return bool */ - protected function isAssociationIsNullable($associationMapping) + protected function isAssociationIsNullable(array $associationMapping) { if (isset($associationMapping['id']) && $associationMapping['id']) { return false; @@ -1381,7 +1382,7 @@ protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, } $replacements = array( - '' => ucfirst($type) . ' ' . $variableName, + '' => ucfirst($type) . ' ' . $variableName . '.', '' => $methodTypeHint, '' => $variableType, '' => $variableName, @@ -1407,7 +1408,7 @@ protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, * * @return string */ - protected function generateLifecycleCallbackMethod($name, $methodName, $metadata) + protected function generateLifecycleCallbackMethod($name, $methodName, ClassMetadataInfo $metadata) { if ($this->hasMethod($methodName, $metadata)) { return ''; diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 15dddf7e6c0..da1a291d317 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -426,14 +426,14 @@ private function gatherColumn($class, array $mapping, Table $table) $options = array(); $options['length'] = isset($mapping['length']) ? $mapping['length'] : null; $options['notnull'] = isset($mapping['nullable']) ? ! $mapping['nullable'] : true; - if ($class->isInheritanceTypeSingleTable() && count($class->parentClasses) > 0) { + if ($class->isInheritanceTypeSingleTable() && $class->parentClasses) { $options['notnull'] = false; } $options['platformOptions'] = array(); - $options['platformOptions']['version'] = $class->isVersioned && $class->versionField == $mapping['fieldName'] ? true : false; + $options['platformOptions']['version'] = $class->isVersioned && $class->versionField === $mapping['fieldName']; - if (strtolower($columnType) == 'string' && $options['length'] === null) { + if (strtolower($columnType) === 'string' && null === $options['length']) { $options['length'] = 255; } @@ -470,7 +470,7 @@ private function gatherColumn($class, array $mapping, Table $table) if ($class->isIdGeneratorIdentity() && $class->getIdentifierFieldNames() == array($mapping['fieldName'])) { $options['autoincrement'] = true; } - if ($class->isInheritanceTypeJoined() && $class->name != $class->rootEntityName) { + if ($class->isInheritanceTypeJoined() && $class->name !== $class->rootEntityName) { $options['autoincrement'] = false; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php index 421b075d940..980cf35e3c1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php @@ -126,7 +126,7 @@ public function testLockPessimisticWrite_NoTransaction_ThrowsException() { public function testLockPessimisticWrite() { $writeLockSql = $this->_em->getConnection()->getDatabasePlatform()->getWriteLockSQL(); - if (strlen($writeLockSql) == 0) { + if (!$writeLockSql) { $this->markTestSkipped('Database Driver has no Write Lock support.'); } @@ -157,7 +157,7 @@ public function testLockPessimisticWrite() public function testLockPessimisticRead() { $readLockSql = $this->_em->getConnection()->getDatabasePlatform()->getReadLockSQL(); - if (strlen($readLockSql) == 0) { + if (!$readLockSql) { $this->markTestSkipped('Database Driver has no Write Lock support.'); } From 24da9061b9e857012359c850c171906d8959be88 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 26 Nov 2016 05:22:43 +0100 Subject: [PATCH 122/877] #5987 inlined check for boolean `'true'` literal --- lib/Doctrine/ORM/Query/SqlWalker.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 87daa694bc8..0aa4349a1a1 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -2119,9 +2119,7 @@ public function walkLiteral($literal) return $this->conn->quote($literal->value); case AST\Literal::BOOLEAN: - $bool = 'true' === strtolower($literal->value); - - return $this->conn->getDatabasePlatform()->convertBooleans($bool); + return $this->conn->getDatabasePlatform()->convertBooleans('true' === strtolower($literal->value)); case AST\Literal::NUMERIC: return $literal->value; From 3cd7b8c95130a2658fcdeda00333080779d85c3b Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 26 Nov 2016 05:23:04 +0100 Subject: [PATCH 123/877] #5987 CS: spacing after `!` (not) operator --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 2 +- tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index fa6cbf12dd0..e48e8535b1b 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -371,7 +371,7 @@ public function writeEntityClass(ClassMetadataInfo $metadata, $outputDirectory) mkdir($dir, 0775, true); } - $this->isNew = !file_exists($path) || $this->regenerateEntityIfExists; + $this->isNew = ! file_exists($path) || $this->regenerateEntityIfExists; if ( ! $this->isNew) { $this->parseTokensInEntityFile(file_get_contents($path)); diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php index 980cf35e3c1..8ac9bfefcb8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php @@ -126,7 +126,8 @@ public function testLockPessimisticWrite_NoTransaction_ThrowsException() { public function testLockPessimisticWrite() { $writeLockSql = $this->_em->getConnection()->getDatabasePlatform()->getWriteLockSQL(); - if (!$writeLockSql) { + + if (! $writeLockSql) { $this->markTestSkipped('Database Driver has no Write Lock support.'); } @@ -157,7 +158,8 @@ public function testLockPessimisticWrite() public function testLockPessimisticRead() { $readLockSql = $this->_em->getConnection()->getDatabasePlatform()->getReadLockSQL(); - if (!$readLockSql) { + + if (! $readLockSql) { $this->markTestSkipped('Database Driver has no Write Lock support.'); } From fa09a95023022da5f833afe7e640b016884e3785 Mon Sep 17 00:00:00 2001 From: Steevan BARBOYON Date: Mon, 31 Oct 2016 12:03:19 +0100 Subject: [PATCH 124/877] Clear $this->collection even when empty, to reset indexes --- lib/Doctrine/ORM/PersistentCollection.php | 2 ++ .../Tests/ORM/PersistentCollectionTest.php | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index c1f3cf1b6c9..000729754ec 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -542,6 +542,8 @@ public function isEmpty() public function clear() { if ($this->initialized && $this->isEmpty()) { + $this->collection->clear(); + return; } diff --git a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php index 4956e5648c9..41ce2959cb7 100644 --- a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php @@ -107,4 +107,29 @@ public function testNonObjects() $this->assertSame("dummy", $this->collection->get(2)); $this->assertSame(null, $this->collection->get(3)); } + + /** + * Test that PersistentCollection::clear() clear elements, and reset keys + */ + public function testClear() + { + $this->setUpPersistentCollection(); + + $this->collection->add('dummy'); + $this->assertEquals([0], array_keys($this->collection->toArray())); + + $this->collection->removeElement('dummy'); + $this->assertEquals([], array_keys($this->collection->toArray())); + + $this->collection->add('dummy'); + $this->collection->clear(); + $this->assertEquals([], array_keys($this->collection->toArray())); + + // test fix clear doesn't reset collection keys when collection is empty + $this->collection->add('dummy'); + $this->collection->removeElement('dummy'); + $this->collection->clear(); + $this->collection->add('dummy'); + $this->assertEquals([0], array_keys($this->collection->toArray())); + } } From 9acf1702921afbebdd9e825b42364557b92460bd Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 26 Nov 2016 06:02:16 +0100 Subject: [PATCH 125/877] #6110 split test into multiple sub-scenarios involving `PersistentCollection` key checking --- .../Tests/ORM/PersistentCollectionTest.php | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php index 41ce2959cb7..df1a16867f8 100644 --- a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php @@ -109,9 +109,9 @@ public function testNonObjects() } /** - * Test that PersistentCollection::clear() clear elements, and reset keys + * @group 6110 */ - public function testClear() + public function testRemovingElementsAlsoRemovesKeys() { $this->setUpPersistentCollection(); @@ -120,12 +120,27 @@ public function testClear() $this->collection->removeElement('dummy'); $this->assertEquals([], array_keys($this->collection->toArray())); + } + + /** + * @group 6110 + */ + public function testClearWillAlsoClearKeys() + { + $this->setUpPersistentCollection(); $this->collection->add('dummy'); $this->collection->clear(); $this->assertEquals([], array_keys($this->collection->toArray())); + } + + /** + * @group 6110 + */ + public function testClearWillAlsoResetKeyPositions() + { + $this->setUpPersistentCollection(); - // test fix clear doesn't reset collection keys when collection is empty $this->collection->add('dummy'); $this->collection->removeElement('dummy'); $this->collection->clear(); From 20190605a0af6122b1d89484298387294b6c08c8 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 26 Nov 2016 06:06:49 +0100 Subject: [PATCH 126/877] #6110 CS (whitespace removal) --- lib/Doctrine/ORM/PersistentCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index 000729754ec..b5948149a2f 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -543,7 +543,7 @@ public function clear() { if ($this->initialized && $this->isEmpty()) { $this->collection->clear(); - + return; } From d3c604567b20d01a2112307611ebf910d7847ede Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Tue, 4 Oct 2016 11:01:53 -0300 Subject: [PATCH 127/877] Update docblock generation for nullable fields --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 25 ++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index e48e8535b1b..b2bf1880e7b 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -1168,17 +1168,18 @@ protected function generateEntityStubMethods(ClassMetadataInfo $metadata) continue; } + $nullableField = $this->getNullableField($fieldMapping); if (( ! isset($fieldMapping['id']) || ! $fieldMapping['id'] || $metadata->generatorType == ClassMetadataInfo::GENERATOR_TYPE_NONE ) && (! $metadata->isEmbeddedClass || ! $this->embeddablesImmutable) ) { - if ($code = $this->generateEntityStubMethod($metadata, 'set', $fieldMapping['fieldName'], $fieldMapping['type'])) { + if ($code = $this->generateEntityStubMethod($metadata, 'set', $fieldMapping['fieldName'], $fieldMapping['type'], $nullableField)) { $methods[] = $code; } } - if ($code = $this->generateEntityStubMethod($metadata, 'get', $fieldMapping['fieldName'], $fieldMapping['type'])) { + if ($code = $this->generateEntityStubMethod($metadata, 'get', $fieldMapping['fieldName'], $fieldMapping['type'], $nullableField)) { $methods[] = $code; } } @@ -1205,7 +1206,7 @@ protected function generateEntityStubMethods(ClassMetadataInfo $metadata) if ($code = $this->generateEntityStubMethod($metadata, 'set', $associationMapping['fieldName'], $associationMapping['targetEntity'], $nullable)) { $methods[] = $code; } - if ($code = $this->generateEntityStubMethod($metadata, 'get', $associationMapping['fieldName'], $associationMapping['targetEntity'])) { + if ($code = $this->generateEntityStubMethod($metadata, 'get', $associationMapping['fieldName'], $associationMapping['targetEntity'], $nullable)) { $methods[] = $code; } } elseif ($associationMapping['type'] & ClassMetadataInfo::TO_MANY) { @@ -1355,7 +1356,7 @@ protected function generateEntityEmbeddedProperties(ClassMetadataInfo $metadata) * * @return string */ - protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null) + protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null) { $methodName = $type . Inflector::classify($fieldName); $variableName = Inflector::camelize($fieldName); @@ -1384,7 +1385,7 @@ protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $replacements = array( '' => ucfirst($type) . ' ' . $variableName . '.', '' => $methodTypeHint, - '' => $variableType, + '' => $variableType.(null !== $defaultValue ? ('|'.$defaultValue) : ''), '' => $variableName, '' => $methodName, '' => $fieldName, @@ -1627,7 +1628,7 @@ protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, Cla { $lines = array(); $lines[] = $this->spaces . '/**'; - $lines[] = $this->spaces . ' * @var ' . $this->getType($fieldMapping['type']); + $lines[] = $this->spaces . ' * @var ' . $this->getType($fieldMapping['type']) . ($this->getNullableField($fieldMapping) ? '|' . $this->getNullableField($fieldMapping) : '');; if ($this->generateAnnotations) { $lines[] = $this->spaces . ' *'; @@ -1809,6 +1810,18 @@ protected function getIdGeneratorTypeString($type) return static::$generatorStrategyMap[$type]; } + /** + * @param array $fieldMapping + * + * @return string|null + */ + protected function getNullableField(array $fieldMapping) + { + if (isset($fieldMapping['nullable']) && true === $fieldMapping['nullable']) { + return 'null'; + } + } + /** * Exports (nested) option elements. * From 087d0816012c310b5ad90f5fe04353f4824cefab Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Tue, 4 Oct 2016 11:07:37 -0300 Subject: [PATCH 128/877] Fix CS --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index b2bf1880e7b..5220fad5584 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -1385,11 +1385,11 @@ protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $replacements = array( '' => ucfirst($type) . ' ' . $variableName . '.', '' => $methodTypeHint, - '' => $variableType.(null !== $defaultValue ? ('|'.$defaultValue) : ''), + '' => $variableType . (null !== $defaultValue ? ('|' . $defaultValue) : ''), '' => $variableName, '' => $methodName, '' => $fieldName, - '' => ($defaultValue !== null ) ? (' = '.$defaultValue) : '', + '' => ($defaultValue !== null ) ? (' = ' . $defaultValue) : '', '' => $this->getClassName($metadata) ); From ad6469b64a455fe70818fe6d7943774303aa4302 Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Tue, 4 Oct 2016 11:40:12 -0300 Subject: [PATCH 129/877] Update tests --- tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index 0cbae94d7a3..d243bdbe467 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -368,8 +368,8 @@ public function testMethodDocBlockShouldStartWithBackSlash() $this->assertPhpDocReturnType('boolean', new \ReflectionMethod($book, 'removeComment')); $this->assertPhpDocVarType('\Doctrine\Tests\ORM\Tools\EntityGeneratorAuthor', new \ReflectionProperty($book, 'author')); - $this->assertPhpDocReturnType('\Doctrine\Tests\ORM\Tools\EntityGeneratorAuthor', new \ReflectionMethod($book, 'getAuthor')); - $this->assertPhpDocParamType('\Doctrine\Tests\ORM\Tools\EntityGeneratorAuthor', new \ReflectionMethod($book, 'setAuthor')); + $this->assertPhpDocReturnType('\Doctrine\Tests\ORM\Tools\EntityGeneratorAuthor|null', new \ReflectionMethod($book, 'getAuthor')); + $this->assertPhpDocParamType('\Doctrine\Tests\ORM\Tools\EntityGeneratorAuthor|null', new \ReflectionMethod($book, 'setAuthor')); $expectedClassName = '\\' . $embeddedMetadata->name; $this->assertPhpDocVarType($expectedClassName, new \ReflectionProperty($book, 'isbn')); From 1dfadef22146861d19bf3459c0376ec3dc0c6a45 Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Fri, 18 Nov 2016 12:35:51 -0300 Subject: [PATCH 130/877] Removed surplus semicolon at `EntityGenerator::generateFieldMappingPropertyDocBlock()` --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 5220fad5584..5bcfc4d8907 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -1628,7 +1628,7 @@ protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, Cla { $lines = array(); $lines[] = $this->spaces . '/**'; - $lines[] = $this->spaces . ' * @var ' . $this->getType($fieldMapping['type']) . ($this->getNullableField($fieldMapping) ? '|' . $this->getNullableField($fieldMapping) : '');; + $lines[] = $this->spaces . ' * @var ' . $this->getType($fieldMapping['type']) . ($this->getNullableField($fieldMapping) ? '|' . $this->getNullableField($fieldMapping) : ''); if ($this->generateAnnotations) { $lines[] = $this->spaces . ' *'; From 3341781f523e17a48c913d60adbed1e88e02ea13 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 26 Nov 2016 06:20:12 +0100 Subject: [PATCH 131/877] #6068 inlined code generating expression --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 5bcfc4d8907..1abd5a14c51 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -1173,10 +1173,9 @@ protected function generateEntityStubMethods(ClassMetadataInfo $metadata) ! $fieldMapping['id'] || $metadata->generatorType == ClassMetadataInfo::GENERATOR_TYPE_NONE ) && (! $metadata->isEmbeddedClass || ! $this->embeddablesImmutable) + && $code = $this->generateEntityStubMethod($metadata, 'set', $fieldMapping['fieldName'], $fieldMapping['type'], $nullableField) ) { - if ($code = $this->generateEntityStubMethod($metadata, 'set', $fieldMapping['fieldName'], $fieldMapping['type'], $nullableField)) { - $methods[] = $code; - } + $methods[] = $code; } if ($code = $this->generateEntityStubMethod($metadata, 'get', $fieldMapping['fieldName'], $fieldMapping['type'], $nullableField)) { From 1d2baedfd5b102f2a0f01b213147ddaa78feec2f Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 26 Nov 2016 06:22:25 +0100 Subject: [PATCH 132/877] #6068 simplified variable docblock codegen for nullable instance properties --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 1abd5a14c51..1fe26e79e2c 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -1627,7 +1627,9 @@ protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, Cla { $lines = array(); $lines[] = $this->spaces . '/**'; - $lines[] = $this->spaces . ' * @var ' . $this->getType($fieldMapping['type']) . ($this->getNullableField($fieldMapping) ? '|' . $this->getNullableField($fieldMapping) : ''); + $lines[] = $this->spaces . ' * @var ' + . $this->getType($fieldMapping['type']) + . ($this->getNullableField($fieldMapping) ? '|null' : ''); if ($this->generateAnnotations) { $lines[] = $this->spaces . ' *'; From a4f76bda34ed50c8743834a60b1a214d8cb752c0 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 26 Nov 2016 06:26:53 +0100 Subject: [PATCH 133/877] #6068 corrected nullable field expression generator, made it private to avoid misuse --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 1fe26e79e2c..3c0f9264f5a 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -1168,7 +1168,8 @@ protected function generateEntityStubMethods(ClassMetadataInfo $metadata) continue; } - $nullableField = $this->getNullableField($fieldMapping); + $nullableField = $this->nullableFieldExpression($fieldMapping); + if (( ! isset($fieldMapping['id']) || ! $fieldMapping['id'] || $metadata->generatorType == ClassMetadataInfo::GENERATOR_TYPE_NONE @@ -1629,7 +1630,7 @@ protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, Cla $lines[] = $this->spaces . '/**'; $lines[] = $this->spaces . ' * @var ' . $this->getType($fieldMapping['type']) - . ($this->getNullableField($fieldMapping) ? '|null' : ''); + . ($this->nullableFieldExpression($fieldMapping) ? '|null' : ''); if ($this->generateAnnotations) { $lines[] = $this->spaces . ' *'; @@ -1816,11 +1817,13 @@ protected function getIdGeneratorTypeString($type) * * @return string|null */ - protected function getNullableField(array $fieldMapping) + private function nullableFieldExpression(array $fieldMapping) { if (isset($fieldMapping['nullable']) && true === $fieldMapping['nullable']) { return 'null'; } + + return null; } /** From f8002ca27edebaecc554a543cb1729abe5e35f20 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 26 Nov 2016 06:35:23 +0100 Subject: [PATCH 134/877] #6068 hardened test logic to verify that nothing is present after the `|null` in `@var` and `@return` types --- .../Tests/ORM/Tools/EntityGeneratorTest.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index d243bdbe467..89c073fd221 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -1080,17 +1080,25 @@ public static function someMethod(){ */ private function assertPhpDocVarType($type, \ReflectionProperty $property) { - $this->assertEquals(1, preg_match('/@var\s+([^\s]+)/',$property->getDocComment(), $matches)); + $docComment = $property->getDocComment(); + $regex = '/@var\s+([\S]+)$/m'; + + $this->assertRegExp($regex, $docComment); + $this->assertEquals(1, preg_match($regex, $docComment, $matches)); $this->assertEquals($type, $matches[1]); } /** * @param string $type - * @param \ReflectionProperty $method + * @param \ReflectionMethod $method */ private function assertPhpDocReturnType($type, \ReflectionMethod $method) { - $this->assertEquals(1, preg_match('/@return\s+([^\s]+)/', $method->getDocComment(), $matches)); + $docComment = $method->getDocComment(); + $regex = '/@return\s+([\S]+)(\s+.*)$/m'; + + $this->assertRegExp($regex, $docComment); + $this->assertEquals(1, preg_match($regex, $docComment, $matches)); $this->assertEquals($type, $matches[1]); } From 12465e08ada4460ec0cc6d06f1d114976d6a944f Mon Sep 17 00:00:00 2001 From: ReenExe Date: Sun, 3 Jul 2016 00:28:56 +0300 Subject: [PATCH 135/877] agree with scrutinizer --- lib/Doctrine/ORM/Query/SqlWalker.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 0aa4349a1a1..6e607ffa9e9 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -501,7 +501,6 @@ private function generateFilterConditionSQL(ClassMetadata $targetEntity, $target default: //@todo: throw exception? return ''; - break; } $filterClauses = array(); From 401300b2957a2082cf97e76e925af16760541beb Mon Sep 17 00:00:00 2001 From: ReenExe Date: Sun, 3 Jul 2016 00:55:40 +0300 Subject: [PATCH 136/877] decrease nested if --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 3c0f9264f5a..e678ea8be3a 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -1259,21 +1259,21 @@ protected function isAssociationIsNullable(array $associationMapping) */ protected function generateEntityLifecycleCallbackMethods(ClassMetadataInfo $metadata) { - if (isset($metadata->lifecycleCallbacks) && $metadata->lifecycleCallbacks) { - $methods = array(); + if (empty($metadata->lifecycleCallbacks)) { + return ''; + } - foreach ($metadata->lifecycleCallbacks as $name => $callbacks) { - foreach ($callbacks as $callback) { - if ($code = $this->generateLifecycleCallbackMethod($name, $callback, $metadata)) { - $methods[] = $code; - } + $methods = []; + + foreach ($metadata->lifecycleCallbacks as $name => $callbacks) { + foreach ($callbacks as $callback) { + if ($code = $this->generateLifecycleCallbackMethod($name, $callback, $metadata)) { + $methods[] = $code; } } - - return implode("\n\n", $methods); } - return ""; + return implode("\n\n", $methods); } /** From b2f5da19a4ab28b70e565d6e9a195be0b3b90013 Mon Sep 17 00:00:00 2001 From: ReenExe Date: Sun, 3 Jul 2016 01:01:25 +0300 Subject: [PATCH 137/877] clear code --- lib/Doctrine/ORM/Query.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index e3f23cc6b47..6a8a50ae0a0 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -309,7 +309,9 @@ protected function _doExecute() if ($paramCount > $mappingCount) { throw QueryException::tooManyParameters($mappingCount, $paramCount); - } elseif ($paramCount < $mappingCount) { + } + + if ($paramCount < $mappingCount) { throw QueryException::tooFewParameters($mappingCount, $paramCount); } From 5d477cdbbc121ab587234c508ab20d4bf2b42b72 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 26 Nov 2016 06:42:46 +0100 Subject: [PATCH 138/877] #5914 `ClassMetadataInfo#$lifecycleCallbacks` is a multi-dimensional array --- lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 8fa11f36046..3058a2eda14 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -463,7 +463,7 @@ class ClassMetadataInfo implements ClassMetadata /** * READ-ONLY: The registered lifecycle callbacks for entities of this class. * - * @var array + * @var array[] */ public $lifecycleCallbacks = array(); From 0ed18fb062470a8d267a1bd88656430116b63e9f Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 26 Nov 2016 06:44:53 +0100 Subject: [PATCH 139/877] #5914 removed unused conditional inside `EntityGenerator`, replaced with `array_filter()` instead --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index e678ea8be3a..22d5b412a82 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -1267,13 +1267,11 @@ protected function generateEntityLifecycleCallbackMethods(ClassMetadataInfo $met foreach ($metadata->lifecycleCallbacks as $name => $callbacks) { foreach ($callbacks as $callback) { - if ($code = $this->generateLifecycleCallbackMethod($name, $callback, $metadata)) { - $methods[] = $code; - } + $methods[] = $this->generateLifecycleCallbackMethod($name, $callback, $metadata); } } - return implode("\n\n", $methods); + return implode("\n\n", array_filter($methods)); } /** From 52badf1cdd3b00fd193ce977363b2ee14394fc2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renan=20Gon=C3=A7alves?= Date: Sun, 11 Sep 2016 12:24:19 +0200 Subject: [PATCH 140/877] Convert generated id value to its PHP representation. According to the conversion rules of a specific DBAL mapping type. --- lib/Doctrine/ORM/UnitOfWork.php | 60 +++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 1336a57f3fb..9e759c0ad34 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -19,36 +19,33 @@ namespace Doctrine\ORM; -use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; -use Doctrine\DBAL\LockMode; -use Doctrine\ORM\Internal\HydrationCompleteHandler; -use Doctrine\ORM\Mapping\Reflection\ReflectionPropertiesGetter; -use Exception; -use InvalidArgumentException; -use UnexpectedValueException; - use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\Common\NotifyPropertyChanged; -use Doctrine\Common\PropertyChangedListener; +use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; use Doctrine\Common\Persistence\ObjectManagerAware; -use Doctrine\ORM\Mapping\ClassMetadata; -use Doctrine\ORM\Proxy\Proxy; - +use Doctrine\Common\PropertyChangedListener; +use Doctrine\DBAL\LockMode; +use Doctrine\ORM\Cache\Persister\CachedPersister; use Doctrine\ORM\Event\LifecycleEventArgs; -use Doctrine\ORM\Event\PreUpdateEventArgs; -use Doctrine\ORM\Event\PreFlushEventArgs; +use Doctrine\ORM\Event\ListenersInvoker; use Doctrine\ORM\Event\OnFlushEventArgs; use Doctrine\ORM\Event\PostFlushEventArgs; -use Doctrine\ORM\Event\ListenersInvoker; - -use Doctrine\ORM\Cache\Persister\CachedPersister; +use Doctrine\ORM\Event\PreFlushEventArgs; +use Doctrine\ORM\Event\PreUpdateEventArgs; +use Doctrine\ORM\Internal\HydrationCompleteHandler; +use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Mapping\Reflection\ReflectionPropertiesGetter; +use Doctrine\ORM\Persisters\Collection\ManyToManyPersister; +use Doctrine\ORM\Persisters\Collection\OneToManyPersister; use Doctrine\ORM\Persisters\Entity\BasicEntityPersister; -use Doctrine\ORM\Persisters\Entity\SingleTablePersister; use Doctrine\ORM\Persisters\Entity\JoinedSubclassPersister; -use Doctrine\ORM\Persisters\Collection\OneToManyPersister; -use Doctrine\ORM\Persisters\Collection\ManyToManyPersister; +use Doctrine\ORM\Persisters\Entity\SingleTablePersister; +use Doctrine\ORM\Proxy\Proxy; use Doctrine\ORM\Utility\IdentifierFlattener; +use Exception; +use InvalidArgumentException; +use UnexpectedValueException; /** * The UnitOfWork is responsible for tracking changes to objects during an @@ -890,7 +887,14 @@ private function persistNew($class, $entity) $idValue = $idGen->generate($this->em, $entity); if ( ! $idGen instanceof \Doctrine\ORM\Id\AssignedGenerator) { - $idValue = array($class->identifier[0] => $idValue); + $idField = $class->identifier[0]; + + $idValue = [ + $idField => $this->em->getConnection()->convertToPHPValue( + $idValue, + $class->getTypeOfField($idField) + ) + ]; $class->setIdentifierValues($entity, $idValue); } @@ -1008,16 +1012,20 @@ private function executeInserts($class) if ($postInsertIds) { // Persister returned post-insert IDs foreach ($postInsertIds as $postInsertId) { - $id = $postInsertId['generatedId']; + $idField = $class->identifier[0]; + $idValue = $this->em->getConnection()->convertToPHPValue( + $postInsertId['generatedId'], + $class->getTypeOfField($idField) + ); + $entity = $postInsertId['entity']; $oid = spl_object_hash($entity); - $idField = $class->identifier[0]; - $class->reflFields[$idField]->setValue($entity, $id); + $class->reflFields[$idField]->setValue($entity, $idValue); - $this->entityIdentifiers[$oid] = array($idField => $id); + $this->entityIdentifiers[$oid] = array($idField => $idValue); $this->entityStates[$oid] = self::STATE_MANAGED; - $this->originalEntityData[$oid][$idField] = $id; + $this->originalEntityData[$oid][$idField] = $idValue; $this->addToIdentityMap($entity); } From 0a86c324ad368ca5aaa68ab9714f338921a9583a Mon Sep 17 00:00:00 2001 From: Christian Hammerl Date: Sun, 27 Nov 2016 01:45:56 +0100 Subject: [PATCH 141/877] Add test case for autoincremented id of custom type --- .../ORM/Functional/Ticket/DDC5684Test.php | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC5684Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC5684Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC5684Test.php new file mode 100644 index 00000000000..22c3b069556 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC5684Test.php @@ -0,0 +1,111 @@ +_schemaTool->createSchema([$this->_em->getClassMetadata(DDC5684Object::CLASSNAME)]); + } + + protected function tearDown() + { + $this->_schemaTool->dropSchema([$this->_em->getClassMetadata(DDC5684Object::CLASSNAME)]); + + parent::tearDown(); + } + + public function testAutoIncrementIdWithCustomType() + { + $object = new DDC5684Object(); + $this->_em->persist($object); + $this->_em->flush(); + + $this->assertInstanceOf(DDC5684ObjectId::CLASSNAME, $object->id); + } + + public function testFetchObjectWithAutoIncrementedCustomType() + { + $object = new DDC5684Object(); + $this->_em->persist($object); + $this->_em->flush(); + $this->_em->clear(); + + $rawId = $object->id->value; + $object = $this->_em->find(DDC5684Object::CLASSNAME, new DDC5684ObjectId($rawId)); + + $this->assertInstanceOf(DDC5684ObjectId::CLASSNAME, $object->id); + $this->assertEquals($rawId, $object->id->value); + } +} + +class DDC5684ObjectIdType extends DBALTypes\IntegerType +{ + const NAME = 'ticket_5684_object_id'; + const CLASSNAME = __CLASS__; + + public function convertToPHPValue($value, AbstractPlatform $platform) + { + return new DDC5684ObjectId($value); + } + + public function convertToDatabaseValue($value, AbstractPlatform $platform) + { + return $value->value; + } + + public function getName() + { + return self::NAME; + } + + public function requiresSQLCommentHint(AbstractPlatform $platform) + { + return true; + } +} + +class DDC5684ObjectId +{ + const CLASSNAME = __CLASS__; + + public $value; + + public function __construct($value) + { + $this->value = $value; + } + + public function __toString() + { + return (string) $this->value; + } +} + +/** + * @Entity + * @Table(name="ticket_5684_objects") + */ +class DDC5684Object +{ + const CLASSNAME = __CLASS__; + + /** + * @Id + * @Column(type="ticket_5684_object_id") + * @GeneratedValue(strategy="AUTO") + */ + public $id; +} From e736d196770d5919ea26e35f7592f70a2e16920a Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 27 Nov 2016 17:42:12 +0100 Subject: [PATCH 142/877] #5935 #5684 #6020 #6152 extracted identifier conversion to a private method --- lib/Doctrine/ORM/UnitOfWork.php | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 9e759c0ad34..fbbab7b6a4b 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -887,14 +887,7 @@ private function persistNew($class, $entity) $idValue = $idGen->generate($this->em, $entity); if ( ! $idGen instanceof \Doctrine\ORM\Id\AssignedGenerator) { - $idField = $class->identifier[0]; - - $idValue = [ - $idField => $this->em->getConnection()->convertToPHPValue( - $idValue, - $class->getTypeOfField($idField) - ) - ]; + $idValue = [$class->getSingleIdentifierFieldName() => $this->convertSingleFieldIdentifierToPHPValue($class, $idValue)]; $class->setIdentifierValues($entity, $idValue); } @@ -1012,11 +1005,8 @@ private function executeInserts($class) if ($postInsertIds) { // Persister returned post-insert IDs foreach ($postInsertIds as $postInsertId) { - $idField = $class->identifier[0]; - $idValue = $this->em->getConnection()->convertToPHPValue( - $postInsertId['generatedId'], - $class->getTypeOfField($idField) - ); + $idField = $class->getSingleIdentifierFieldName(); + $idValue = $this->convertSingleFieldIdentifierToPHPValue($class, $postInsertId['generatedId']); $entity = $postInsertId['entity']; $oid = spl_object_hash($entity); @@ -3475,4 +3465,20 @@ private function clearEntityInsertionsForEntityName($entityName) } } } + + /** + * @param ClassMetadata $class + * @param mixed $identifierValue + * + * @return mixed the identifier after type conversion + * + * @throws \Doctrine\ORM\Mapping\MappingException if the entity has more than a single identifier + */ + private function convertSingleFieldIdentifierToPHPValue(ClassMetadata $class, $identifierValue) + { + return $this->em->getConnection()->convertToPHPValue( + $identifierValue, + $class->getTypeOfField($class->getSingleIdentifierFieldName()) + ); + } } From 73ea0ba8f38b6881ea360aa993260c15e7ecfd4b Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 27 Nov 2016 17:45:50 +0100 Subject: [PATCH 143/877] #5935 #5684 #6020 #6152 adding description to the test scenario --- tests/Doctrine/Tests/ORM/Functional/Ticket/DDC5684Test.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC5684Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC5684Test.php index 22c3b069556..78e9330a016 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC5684Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC5684Test.php @@ -5,6 +5,13 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types as DBALTypes; +/** + * This test verifies that custom post-insert identifiers respect type conversion semantics. + * The generated identifier must be converted via DBAL types before populating the entity + * identifier field. + * + * @group 5935 5684 6020 6152 + */ class DDC5684Test extends \Doctrine\Tests\OrmFunctionalTestCase { protected function setUp() From cff5c07014aa4c35a8f085018bf4883ebd5da828 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 27 Nov 2016 17:49:09 +0100 Subject: [PATCH 144/877] #5935 #5684 #6020 #6152 removed useless `NAME` constant from the test --- .../Tests/ORM/Functional/Ticket/DDC5684Test.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC5684Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC5684Test.php index 78e9330a016..a25178de210 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC5684Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC5684Test.php @@ -18,10 +18,10 @@ protected function setUp() { parent::setUp(); - if (DBALTypes\Type::hasType(DDC5684ObjectIdType::NAME)) { - DBALTypes\Type::overrideType(DDC5684ObjectIdType::NAME, DDC5684ObjectIdType::CLASSNAME); + if (DBALTypes\Type::hasType(DDC5684ObjectIdType::CLASSNAME)) { + DBALTypes\Type::overrideType(DDC5684ObjectIdType::CLASSNAME, DDC5684ObjectIdType::CLASSNAME); } else { - DBALTypes\Type::addType(DDC5684ObjectIdType::NAME, DDC5684ObjectIdType::CLASSNAME); + DBALTypes\Type::addType(DDC5684ObjectIdType::CLASSNAME, DDC5684ObjectIdType::CLASSNAME); } $this->_schemaTool->createSchema([$this->_em->getClassMetadata(DDC5684Object::CLASSNAME)]); @@ -60,7 +60,6 @@ public function testFetchObjectWithAutoIncrementedCustomType() class DDC5684ObjectIdType extends DBALTypes\IntegerType { - const NAME = 'ticket_5684_object_id'; const CLASSNAME = __CLASS__; public function convertToPHPValue($value, AbstractPlatform $platform) @@ -75,7 +74,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) public function getName() { - return self::NAME; + return self::CLASSNAME; } public function requiresSQLCommentHint(AbstractPlatform $platform) @@ -111,7 +110,7 @@ class DDC5684Object /** * @Id - * @Column(type="ticket_5684_object_id") + * @Column(type=Doctrine\Tests\ORM\Functional\Ticket\DDC5684ObjectIdType::class) * @GeneratedValue(strategy="AUTO") */ public $id; From 4a87f00fab72d8cfe7f04e92ce8966cdbc9edb50 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 11 Sep 2016 16:31:08 +0200 Subject: [PATCH 145/877] Avoid error when entityName isn't a string --- lib/Doctrine/ORM/UnitOfWork.php | 4 ++++ tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index fbbab7b6a4b..bc8d09fb810 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -3442,6 +3442,10 @@ public function hydrationComplete() */ private function clearIdentityMapForEntityName($entityName) { + if (is_object($entityName)) { + return; + } + if (! isset($this->identityMap[$entityName])) { return; } diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 0ff2572b914..84df1073d9a 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -349,6 +349,20 @@ public function testPersistedEntityAndClearManager() $this->assertFalse($this->_unitOfWork->isScheduledForInsert($entity2)); } + public function testClearManagerWithObject() + { + $entity = new Country(456, 'United Kingdom'); + + $this->_unitOfWork->persist($entity); + $this->assertTrue($this->_unitOfWork->isInIdentityMap($entity)); + + $this->_unitOfWork->clear($entity); + + // true because entity wasn't a string so it wasn't cleared + $this->assertTrue($this->_unitOfWork->isInIdentityMap($entity)); + $this->assertTrue($this->_unitOfWork->isScheduledForInsert($entity)); + } + /** * Data Provider * From 2a7d21ad181f1ccbb18bf4fc1d7851d913b56dd7 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 12 Sep 2016 12:08:42 +0200 Subject: [PATCH 146/877] Throw an exception instead of a workaround --- lib/Doctrine/ORM/UnitOfWork.php | 8 ++++---- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index bc8d09fb810..1340dc89169 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -2363,6 +2363,10 @@ public function getCommitOrderCalculator() */ public function clear($entityName = null) { + if ($entityName !== null && !is_string($entityName)) { + throw new \InvalidArgumentException(sprintf('Argument 1 passed to %s() must be a string, %s given', __METHOD__, gettype($entityName))); + } + if ($entityName === null) { $this->identityMap = $this->entityIdentifiers = @@ -3442,10 +3446,6 @@ public function hydrationComplete() */ private function clearIdentityMapForEntityName($entityName) { - if (is_object($entityName)) { - return; - } - if (! isset($this->identityMap[$entityName])) { return; } diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 84df1073d9a..def2ae91ae8 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -351,16 +351,28 @@ public function testPersistedEntityAndClearManager() public function testClearManagerWithObject() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('must be a string'); + $entity = new Country(456, 'United Kingdom'); $this->_unitOfWork->persist($entity); $this->assertTrue($this->_unitOfWork->isInIdentityMap($entity)); $this->_unitOfWork->clear($entity); + } + + public function testClearManagerWithNullValue() + { + $entity = new Country(456, 'United Kingdom'); - // true because entity wasn't a string so it wasn't cleared + $this->_unitOfWork->persist($entity); $this->assertTrue($this->_unitOfWork->isInIdentityMap($entity)); - $this->assertTrue($this->_unitOfWork->isScheduledForInsert($entity)); + + $this->_unitOfWork->clear(); + + $this->assertFalse($this->_unitOfWork->isInIdentityMap($entity)); + $this->assertFalse($this->_unitOfWork->isScheduledForInsert($entity)); } /** From be4aafd4f6aee5558842726cc7d53bc120def342 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 26 Nov 2016 23:12:09 +0100 Subject: [PATCH 147/877] Use ORMException instead of a default exception --- lib/Doctrine/ORM/ORMException.php | 14 +++++++++++++- lib/Doctrine/ORM/UnitOfWork.php | 2 +- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 3 ++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/ORMException.php b/lib/Doctrine/ORM/ORMException.php index 919789d9249..edfc47df649 100644 --- a/lib/Doctrine/ORM/ORMException.php +++ b/lib/Doctrine/ORM/ORMException.php @@ -101,7 +101,7 @@ public static function unrecognizedField($field) return new self("Unrecognized field: $field"); } - /** + /** * * @param string $class * @param string $association @@ -340,4 +340,16 @@ public static function cantUseInOperatorOnCompositeKeys() { return new self("Can't use IN operator on entities that have composite keys."); } + + /** + * Used when a given entityName hasn't the good type + * + * @param mixed $entityName The given entity (which shouldn't be a string) + * + * @return ORMException + */ + public static function invalidEntityName($entityName) + { + return new self(sprintf('Entity name must be a string, %s given', gettype($entityName))); + } } diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 1340dc89169..8fbac956da2 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -2364,7 +2364,7 @@ public function getCommitOrderCalculator() public function clear($entityName = null) { if ($entityName !== null && !is_string($entityName)) { - throw new \InvalidArgumentException(sprintf('Argument 1 passed to %s() must be a string, %s given', __METHOD__, gettype($entityName))); + throw ORMException::invalidEntityName($entityName); } if ($entityName === null) { diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index def2ae91ae8..c60de753e22 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -8,6 +8,7 @@ use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\ORMInvalidArgumentException; use Doctrine\ORM\UnitOfWork; +use Doctrine\ORM\ORMException; use Doctrine\Tests\Mocks\ConnectionMock; use Doctrine\Tests\Mocks\DriverMock; use Doctrine\Tests\Mocks\EntityManagerMock; @@ -351,7 +352,7 @@ public function testPersistedEntityAndClearManager() public function testClearManagerWithObject() { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(ORMException::class); $this->expectExceptionMessage('must be a string'); $entity = new Country(456, 'United Kingdom'); From 6b1d64d484b8cbf035eab575d8b194dbc250c8e1 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 27 Nov 2016 18:05:18 +0100 Subject: [PATCH 148/877] Remove unecessary persist in tests --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index c60de753e22..6e22ed4980d 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -357,9 +357,6 @@ public function testClearManagerWithObject() $entity = new Country(456, 'United Kingdom'); - $this->_unitOfWork->persist($entity); - $this->assertTrue($this->_unitOfWork->isInIdentityMap($entity)); - $this->_unitOfWork->clear($entity); } @@ -367,9 +364,6 @@ public function testClearManagerWithNullValue() { $entity = new Country(456, 'United Kingdom'); - $this->_unitOfWork->persist($entity); - $this->assertTrue($this->_unitOfWork->isInIdentityMap($entity)); - $this->_unitOfWork->clear(); $this->assertFalse($this->_unitOfWork->isInIdentityMap($entity)); From c4d41fe56a2beffb638e1d7e7d9ee6fb0a745f0a Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 27 Nov 2016 18:08:03 +0100 Subject: [PATCH 149/877] #6017 moved `ORMException::invalidEntityName` to `ORMInvalidArgumentException::invalidEntityName` --- lib/Doctrine/ORM/ORMInvalidArgumentException.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/Doctrine/ORM/ORMInvalidArgumentException.php b/lib/Doctrine/ORM/ORMInvalidArgumentException.php index 81466a0fed0..accf1cc1517 100644 --- a/lib/Doctrine/ORM/ORMInvalidArgumentException.php +++ b/lib/Doctrine/ORM/ORMInvalidArgumentException.php @@ -210,6 +210,18 @@ public static function invalidAssociation(ClassMetadata $targetClass, $assoc, $a )); } + /** + * Used when a given entityName hasn't the good type + * + * @param mixed $entityName The given entity (which shouldn't be a string) + * + * @return self + */ + public static function invalidEntityName($entityName) + { + return new self(sprintf('Entity name must be a string, %s given', gettype($entityName))); + } + /** * Helper method to show an object as string. * From 6ad9c9ea0475ffbbd585d43a93a1d60c324a16e0 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 27 Nov 2016 18:08:26 +0100 Subject: [PATCH 150/877] #6017 test coverage for `ORMInvalidArgumentException::invalidEntityName` --- .../ORM/ORMInvalidArgumentExceptionTest.php | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/ORMInvalidArgumentExceptionTest.php diff --git a/tests/Doctrine/Tests/ORM/ORMInvalidArgumentExceptionTest.php b/tests/Doctrine/Tests/ORM/ORMInvalidArgumentExceptionTest.php new file mode 100644 index 00000000000..81f22e2b7dc --- /dev/null +++ b/tests/Doctrine/Tests/ORM/ORMInvalidArgumentExceptionTest.php @@ -0,0 +1,60 @@ +getMessage()); + } + + /** + * @return string[][] + */ + public function invalidEntityNames() + { + return [ + [null, 'Entity name must be a string, NULL given'], + [true, 'Entity name must be a string, boolean given'], + [123, 'Entity name must be a string, integer given'], + [123.45, 'Entity name must be a string, double given'], + [new \stdClass(), 'Entity name must be a string, object given'], + ]; + } +} From 56598596a4343a0709358d7c88dc41ef6ca25d69 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 27 Nov 2016 18:09:51 +0100 Subject: [PATCH 151/877] #6017 adding `@group` annotation to newly introduced tests --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 6e22ed4980d..523baf07158 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -350,6 +350,9 @@ public function testPersistedEntityAndClearManager() $this->assertFalse($this->_unitOfWork->isScheduledForInsert($entity2)); } + /** + * @group 6017 + */ public function testClearManagerWithObject() { $this->expectException(ORMException::class); @@ -360,6 +363,9 @@ public function testClearManagerWithObject() $this->_unitOfWork->clear($entity); } + /** + * @group 6017 + */ public function testClearManagerWithNullValue() { $entity = new Country(456, 'United Kingdom'); From c97799f15174917119fd6604b5ee3b1584825e0e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 27 Nov 2016 18:10:57 +0100 Subject: [PATCH 152/877] #6017 expecting an `ORMInvalidArgumentException` when clearing with invalid data --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 523baf07158..61957aa1e2c 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -355,11 +355,10 @@ public function testPersistedEntityAndClearManager() */ public function testClearManagerWithObject() { - $this->expectException(ORMException::class); - $this->expectExceptionMessage('must be a string'); - $entity = new Country(456, 'United Kingdom'); + $this->expectException(ORMInvalidArgumentException::class); + $this->_unitOfWork->clear($entity); } From 754e1f5d4221d712c1cd8cfed97bfe60a7582c03 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 27 Nov 2016 18:11:27 +0100 Subject: [PATCH 153/877] #6017 throwing an `ORMInvalidArgumentException` when clearing with non-string data. Also removing duplicate null checking --- lib/Doctrine/ORM/UnitOfWork.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 8fbac956da2..e2f0616e8e1 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -2360,13 +2360,11 @@ public function getCommitOrderCalculator() * @param string|null $entityName if given, only entities of this type will get detached. * * @return void + * + * @throws ORMInvalidArgumentException if an invalid entity name is given */ public function clear($entityName = null) { - if ($entityName !== null && !is_string($entityName)) { - throw ORMException::invalidEntityName($entityName); - } - if ($entityName === null) { $this->identityMap = $this->entityIdentifiers = @@ -2384,6 +2382,10 @@ public function clear($entityName = null) $this->visitedCollections = $this->orphanRemovals = array(); } else { + if (! is_string($entityName)) { + throw ORMInvalidArgumentException::invalidEntityName($entityName); + } + $this->clearIdentityMapForEntityName($entityName); $this->clearEntityInsertionsForEntityName($entityName); } From 8f77afdc3447724f91c655f7cbef9f60998103c6 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 27 Nov 2016 18:12:00 +0100 Subject: [PATCH 154/877] #6017 removed unused `ORMException::invalidEntityName` --- lib/Doctrine/ORM/ORMException.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/lib/Doctrine/ORM/ORMException.php b/lib/Doctrine/ORM/ORMException.php index edfc47df649..039ef2eaaf9 100644 --- a/lib/Doctrine/ORM/ORMException.php +++ b/lib/Doctrine/ORM/ORMException.php @@ -340,16 +340,4 @@ public static function cantUseInOperatorOnCompositeKeys() { return new self("Can't use IN operator on entities that have composite keys."); } - - /** - * Used when a given entityName hasn't the good type - * - * @param mixed $entityName The given entity (which shouldn't be a string) - * - * @return ORMException - */ - public static function invalidEntityName($entityName) - { - return new self(sprintf('Entity name must be a string, %s given', gettype($entityName))); - } } From c1038096e0fdda78e68144849ebbdf088581f9e4 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 27 Nov 2016 18:17:30 +0100 Subject: [PATCH 155/877] #6017 requesting `clear('nonExistingEntityName')` should raise a `MappingException` --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 61957aa1e2c..a90b6d1915a 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -4,6 +4,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\NotifyPropertyChanged; +use Doctrine\Common\Persistence\Mapping\MappingException; use Doctrine\Common\PropertyChangedListener; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\ORMInvalidArgumentException; @@ -362,6 +363,16 @@ public function testClearManagerWithObject() $this->_unitOfWork->clear($entity); } + /** + * @group 6017 + */ + public function testClearManagerWithUnknownEntityName() + { + $this->expectException(MappingException::class); + + $this->_unitOfWork->clear(uniqid('nonExisting', true)); + } + /** * @group 6017 */ From dffd765b1e6365cb5879b43fe0cbb98789837f9b Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 27 Nov 2016 18:17:47 +0100 Subject: [PATCH 156/877] #6017 requesting `clear('nonExistingEntityName')` now raises a `MappingException` --- lib/Doctrine/ORM/UnitOfWork.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index e2f0616e8e1..07cf685682f 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -2386,6 +2386,8 @@ public function clear($entityName = null) throw ORMInvalidArgumentException::invalidEntityName($entityName); } + $entityName = $this->em->getClassMetadata($entityName)->getName(); + $this->clearIdentityMapForEntityName($entityName); $this->clearEntityInsertionsForEntityName($entityName); } From fdb2af07e78d7793eae9c8b04e8ab1032ab107fb Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 27 Nov 2016 18:21:35 +0100 Subject: [PATCH 157/877] #6017 hardened `clear()` logic, which now ensures that persisted entries are correctly cleared --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index a90b6d1915a..ef321e761fa 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -380,6 +380,11 @@ public function testClearManagerWithNullValue() { $entity = new Country(456, 'United Kingdom'); + $this->_unitOfWork->persist($entity); + + $this->assertTrue($this->_unitOfWork->isInIdentityMap($entity)); + $this->assertTrue($this->_unitOfWork->isScheduledForInsert($entity)); + $this->_unitOfWork->clear(); $this->assertFalse($this->_unitOfWork->isInIdentityMap($entity)); From 9894dcb4b078f88945b6e5970fa2c5dc664d152d Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 27 Nov 2016 18:22:01 +0100 Subject: [PATCH 158/877] #6017 `clear($proxyClassName)` should behave like `clear($realClassName)` --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index ef321e761fa..acf256a96cc 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -373,6 +373,26 @@ public function testClearManagerWithUnknownEntityName() $this->_unitOfWork->clear(uniqid('nonExisting', true)); } + /** + * @group 6017 + */ + public function testClearManagerWithProxyClassName() + { + $proxy = $this->_emMock->getReference(Country::class, ['id' => random_int(457, 100000)]); + + $entity = new Country(456, 'United Kingdom'); + + $this->_unitOfWork->persist($entity); + + $this->assertTrue($this->_unitOfWork->isInIdentityMap($entity)); + $this->assertTrue($this->_unitOfWork->isScheduledForInsert($entity)); + + $this->_unitOfWork->clear(get_class($proxy)); + + $this->assertFalse($this->_unitOfWork->isInIdentityMap($entity)); + $this->assertFalse($this->_unitOfWork->isScheduledForInsert($entity)); + } + /** * @group 6017 */ From 49333867f8813af20f9780ceaeb21ec9adcc31a3 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 27 Nov 2016 18:25:12 +0100 Subject: [PATCH 159/877] FQCN reference correction --- tests/Doctrine/Tests/ORM/EntityManagerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/EntityManagerTest.php b/tests/Doctrine/Tests/ORM/EntityManagerTest.php index d0cf2bcbb57..e0bf30b6f55 100644 --- a/tests/Doctrine/Tests/ORM/EntityManagerTest.php +++ b/tests/Doctrine/Tests/ORM/EntityManagerTest.php @@ -69,7 +69,7 @@ public function testCreateNativeQuery() } /** - * @covers Doctrine\ORM\EntityManager::createNamedNativeQuery + * @covers \Doctrine\ORM\EntityManager::createNamedNativeQuery */ public function testCreateNamedNativeQuery() { From 92274124f980ad5e584387bed7e6f961835c1682 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 27 Nov 2016 18:28:37 +0100 Subject: [PATCH 160/877] #6017 moving tests around `clear()` into the `EntityManager` tests `UnitOfWork` assumptions are OK, since we don't want to clutter the API even more down there --- .../Doctrine/Tests/ORM/EntityManagerTest.php | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/EntityManagerTest.php b/tests/Doctrine/Tests/ORM/EntityManagerTest.php index e0bf30b6f55..c28ca150e22 100644 --- a/tests/Doctrine/Tests/ORM/EntityManagerTest.php +++ b/tests/Doctrine/Tests/ORM/EntityManagerTest.php @@ -3,15 +3,20 @@ namespace Doctrine\Tests\ORM; use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; +use Doctrine\Common\Persistence\Mapping\MappingException; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; use Doctrine\ORM\ORMException; use Doctrine\ORM\ORMInvalidArgumentException; use Doctrine\ORM\Query\ResultSetMapping; +use Doctrine\Tests\Models\GeoNames\Country; use Doctrine\Tests\OrmTestCase; class EntityManagerTest extends OrmTestCase { + /** + * @var EntityManager + */ private $_em; function setUp() @@ -217,4 +222,60 @@ public function testCreateInvalidConnection() $config->setMetadataDriverImpl($this->createMock(MappingDriver::class)); EntityManager::create(1, $config); } + + /** + * @group 6017 + */ + public function testClearManagerWithObject() + { + $entity = new Country(456, 'United Kingdom'); + + $this->expectException(ORMInvalidArgumentException::class); + + $this->_em->clear($entity); + } + + /** + * @group 6017 + */ + public function testClearManagerWithUnknownEntityName() + { + $this->expectException(MappingException::class); + + $this->_em->clear(uniqid('nonExisting', true)); + } + + /** + * @group 6017 + */ + public function testClearManagerWithProxyClassName() + { + $proxy = $this->_em->getReference(Country::class, ['id' => random_int(457, 100000)]); + + $entity = new Country(456, 'United Kingdom'); + + $this->_em->persist($entity); + + $this->assertTrue($this->_em->contains($entity)); + + $this->_em->clear(get_class($proxy)); + + $this->assertFalse($this->_em->contains($entity)); + } + + /** + * @group 6017 + */ + public function testClearManagerWithNullValue() + { + $entity = new Country(456, 'United Kingdom'); + + $this->_em->persist($entity); + + $this->assertTrue($this->_em->contains($entity)); + + $this->_em->clear(null); + + $this->assertFalse($this->_em->contains($entity)); + } } From 1d7397caf09574d7cd58652931a4f5cb64923271 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 27 Nov 2016 18:33:53 +0100 Subject: [PATCH 161/877] #6017 moving entity name validity checks into the `EntityManager` API, documenting newly thrown exception types --- lib/Doctrine/ORM/EntityManager.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 51d6dbf0526..b61a2557ba1 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -19,6 +19,7 @@ namespace Doctrine\ORM; +use Doctrine\ORM\Mapping\MappingException; use Exception; use Doctrine\Common\EventManager; use Doctrine\DBAL\Connection; @@ -539,10 +540,22 @@ public function getPartialReference($entityName, $identifier) * @param string|null $entityName if given, only entities of this type will get detached * * @return void + * + * @throws ORMInvalidArgumentException if a non-null non-string value is given + * @throws \Doctrine\Common\Persistence\Mapping\MappingException if a $entityName is given, but that entity is not + * found in the mappings */ public function clear($entityName = null) { - $this->unitOfWork->clear($entityName); + if (null !== $entityName && ! is_string($entityName)) { + throw ORMInvalidArgumentException::invalidEntityName($entityName); + } + + $this->unitOfWork->clear( + null === $entityName + ? null + : $this->metadataFactory->getMetadataFor($entityName)->getName() + ); } /** From 53c5824a6bcc1bb5af63eddeae56ea74f8ee1b22 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 27 Nov 2016 18:35:05 +0100 Subject: [PATCH 162/877] #6017 removed `clear($entityName)` parameter validity checks The `UnitOfWork` is advanced stuff: don't touch if you don't know what you are doing. --- lib/Doctrine/ORM/UnitOfWork.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 07cf685682f..368fdfd6397 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -2382,12 +2382,6 @@ public function clear($entityName = null) $this->visitedCollections = $this->orphanRemovals = array(); } else { - if (! is_string($entityName)) { - throw ORMInvalidArgumentException::invalidEntityName($entityName); - } - - $entityName = $this->em->getClassMetadata($entityName)->getName(); - $this->clearIdentityMapForEntityName($entityName); $this->clearEntityInsertionsForEntityName($entityName); } From 44a61412351b279e814f63a28a09413d01c63965 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 27 Nov 2016 18:35:43 +0100 Subject: [PATCH 163/877] #6017 removed `clear($entityName)` tests from `UnitOfWorkTest`: now covered in `EntityManagerTest` --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 60 --------------------- 1 file changed, 60 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index acf256a96cc..5a32d2882b9 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -351,66 +351,6 @@ public function testPersistedEntityAndClearManager() $this->assertFalse($this->_unitOfWork->isScheduledForInsert($entity2)); } - /** - * @group 6017 - */ - public function testClearManagerWithObject() - { - $entity = new Country(456, 'United Kingdom'); - - $this->expectException(ORMInvalidArgumentException::class); - - $this->_unitOfWork->clear($entity); - } - - /** - * @group 6017 - */ - public function testClearManagerWithUnknownEntityName() - { - $this->expectException(MappingException::class); - - $this->_unitOfWork->clear(uniqid('nonExisting', true)); - } - - /** - * @group 6017 - */ - public function testClearManagerWithProxyClassName() - { - $proxy = $this->_emMock->getReference(Country::class, ['id' => random_int(457, 100000)]); - - $entity = new Country(456, 'United Kingdom'); - - $this->_unitOfWork->persist($entity); - - $this->assertTrue($this->_unitOfWork->isInIdentityMap($entity)); - $this->assertTrue($this->_unitOfWork->isScheduledForInsert($entity)); - - $this->_unitOfWork->clear(get_class($proxy)); - - $this->assertFalse($this->_unitOfWork->isInIdentityMap($entity)); - $this->assertFalse($this->_unitOfWork->isScheduledForInsert($entity)); - } - - /** - * @group 6017 - */ - public function testClearManagerWithNullValue() - { - $entity = new Country(456, 'United Kingdom'); - - $this->_unitOfWork->persist($entity); - - $this->assertTrue($this->_unitOfWork->isInIdentityMap($entity)); - $this->assertTrue($this->_unitOfWork->isScheduledForInsert($entity)); - - $this->_unitOfWork->clear(); - - $this->assertFalse($this->_unitOfWork->isInIdentityMap($entity)); - $this->assertFalse($this->_unitOfWork->isScheduledForInsert($entity)); - } - /** * Data Provider * From dc3b1668114893de1112745e8e3e5df1a1b6acb8 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 27 Nov 2016 18:38:57 +0100 Subject: [PATCH 164/877] #6017 replaced `random_int()` with `rand()`, since we still support oldstable PHP (5.6.x) --- tests/Doctrine/Tests/ORM/EntityManagerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/EntityManagerTest.php b/tests/Doctrine/Tests/ORM/EntityManagerTest.php index c28ca150e22..954a3f2f0dd 100644 --- a/tests/Doctrine/Tests/ORM/EntityManagerTest.php +++ b/tests/Doctrine/Tests/ORM/EntityManagerTest.php @@ -250,7 +250,7 @@ public function testClearManagerWithUnknownEntityName() */ public function testClearManagerWithProxyClassName() { - $proxy = $this->_em->getReference(Country::class, ['id' => random_int(457, 100000)]); + $proxy = $this->_em->getReference(Country::class, ['id' => rand(457, 100000)]); $entity = new Country(456, 'United Kingdom'); From 6af1d2843f003b60300bf45edd41bc22b6407f6b Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 4 Dec 2016 06:55:26 +0100 Subject: [PATCH 165/877] Bumping doctrine/common dependency to allow ^2.7.1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f5b3b08f702..a787c1752da 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "doctrine/collections": "~1.2", "doctrine/dbal": ">=2.5-dev,<2.7-dev", "doctrine/instantiator": "~1.0.1", - "doctrine/common": ">=2.5-dev,<2.7-dev", + "doctrine/common": "^2.7.1", "doctrine/cache": "~1.4", "symfony/console": "~2.5|~3.0" }, From 521588f498b7021afb40efc45108b0855651f53f Mon Sep 17 00:00:00 2001 From: eyepin Date: Wed, 7 Dec 2016 13:13:21 +0100 Subject: [PATCH 166/877] Update EntityGenerator.php orm:generate:entities genrates 2 blank lines PSR2: All PHP files MUST end with a single blank line. this worked for me --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 22d5b412a82..71ef0bbb597 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -421,7 +421,7 @@ public function generateEntityClass(ClassMetadataInfo $metadata) $this->generateEntityBody($metadata) ); - $code = str_replace($placeHolders, $replacements, static::$classTemplate) . "\n"; + $code = str_replace($placeHolders, $replacements, static::$classTemplate); return str_replace('', $this->spaces, $code); } From 1d5e16e9d9f6135fd558adef777e9da0d46a5622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 7 Dec 2016 23:32:17 +0100 Subject: [PATCH 167/877] Use short-array syntax on "tools" directory --- tools/sandbox/bootstrap.php | 8 ++++---- tools/sandbox/doctrine.php | 16 ++++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/tools/sandbox/bootstrap.php b/tools/sandbox/bootstrap.php index 1e7d8ba000d..410ea7f72e3 100644 --- a/tools/sandbox/bootstrap.php +++ b/tools/sandbox/bootstrap.php @@ -19,7 +19,7 @@ $config = new \Doctrine\ORM\Configuration(); // Set up Metadata Drivers -$driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__ . "/Entities")); +$driverImpl = $config->newDefaultAnnotationDriver([__DIR__ . "/Entities"]); $config->setMetadataDriverImpl($driverImpl); // Set up caches, depending on $debug variable. @@ -33,10 +33,10 @@ $config->setProxyNamespace('Proxies'); // Database connection information -$connectionOptions = array( +$connectionOptions = [ 'driver' => 'pdo_sqlite', 'path' => 'database.sqlite' -); +]; // Enable second-level cache $cacheConfig = new \Doctrine\ORM\Cache\CacheConfiguration(); @@ -52,4 +52,4 @@ $config->setSecondLevelCacheEnabled(true); $config->setSecondLevelCacheConfiguration($cacheConfig); -return EntityManager::create($connectionOptions, $config); \ No newline at end of file +return EntityManager::create($connectionOptions, $config); diff --git a/tools/sandbox/doctrine.php b/tools/sandbox/doctrine.php index 052968690ef..04c99e327b9 100644 --- a/tools/sandbox/doctrine.php +++ b/tools/sandbox/doctrine.php @@ -5,12 +5,15 @@ $cli = new \Symfony\Component\Console\Application('Doctrine Command Line Interface', Doctrine\Common\Version::VERSION); $cli->setCatchExceptions(true); -$cli->setHelperSet(new Symfony\Component\Console\Helper\HelperSet(array( - 'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()), - 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em) -))); +$cli->setHelperSet(new Symfony\Component\Console\Helper\HelperSet( + [ + 'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()), + 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em) + ] +)); -$cli->addCommands(array( +$cli->addCommands( + [ // DBAL Commands new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(), new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(), @@ -34,5 +37,6 @@ new \Doctrine\ORM\Tools\Console\Command\RunDqlCommand(), new \Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand(), -)); + ] +); $cli->run(); From 74c8a08828e275d2d1cb081b9133928be7173556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 7 Dec 2016 23:33:41 +0100 Subject: [PATCH 168/877] Use short-array syntax on "tests" directory --- .../EventListener/CacheMetadataListener.php | 6 +- .../Doctrine/Tests/Mocks/CacheRegionMock.php | 22 +- .../Tests/Mocks/ConcurrentRegionMock.php | 26 +- tests/Doctrine/Tests/Mocks/ConnectionMock.php | 14 +- tests/Doctrine/Tests/Mocks/DriverMock.php | 2 +- .../Tests/Mocks/EntityManagerMock.php | 2 +- .../Tests/Mocks/EntityPersisterMock.php | 18 +- .../Tests/Mocks/HydratorMockStatement.php | 2 +- .../Tests/Mocks/MetadataDriverMock.php | 2 +- tests/Doctrine/Tests/Mocks/TaskMock.php | 2 +- .../Tests/Mocks/TimestampRegionMock.php | 2 +- tests/Doctrine/Tests/Mocks/UnitOfWorkMock.php | 2 +- .../Doctrine/Tests/Models/CMS/CmsAddress.php | 116 ++-- tests/Doctrine/Tests/Models/CMS/CmsUser.php | 220 ++++--- .../Tests/Models/Company/CompanyContract.php | 24 +- .../Models/Company/CompanyFixContract.php | 8 +- .../Models/Company/CompanyFlexContract.php | 12 +- .../Company/CompanyFlexUltraContract.php | 10 +- .../Tests/Models/Company/CompanyPerson.php | 45 +- .../DDC1476EntityWithDefaultFieldType.php | 12 +- .../Tests/Models/DDC3346/DDC3346Author.php | 2 +- .../Tests/Models/DDC3579/DDC3579Admin.php | 5 +- .../Tests/Models/DDC3579/DDC3579User.php | 18 +- .../Models/DDC869/DDC869ChequePayment.php | 6 +- .../Models/DDC869/DDC869CreditCardPayment.php | 6 +- .../Tests/Models/DDC869/DDC869Payment.php | 12 +- .../Tests/Models/DDC889/DDC889Class.php | 6 +- .../Tests/Models/DDC889/DDC889SuperClass.php | 6 +- .../Tests/Models/DDC964/DDC964Admin.php | 34 +- .../Tests/Models/DDC964/DDC964Guest.php | 13 +- .../Tests/Models/DDC964/DDC964User.php | 48 +- .../Doctrine/Tests/Models/GeoNames/Admin1.php | 2 +- .../Tests/Models/Routing/RoutingRoute.php | 4 +- .../Tests/ORM/Cache/AbstractRegionTest.php | 16 +- .../Doctrine/Tests/ORM/Cache/CacheKeyTest.php | 30 +- .../Tests/ORM/Cache/CacheLoggerChainTest.php | 8 +- .../ORM/Cache/DefaultCacheFactoryTest.php | 34 +- .../Tests/ORM/Cache/DefaultCacheTest.php | 62 +- .../Cache/DefaultCollectionHydratorTest.php | 20 +- .../ORM/Cache/DefaultEntityHydratorTest.php | 60 +- .../Tests/ORM/Cache/DefaultQueryCacheTest.php | 166 ++--- .../Tests/ORM/Cache/DefaultRegionTest.php | 10 +- .../Tests/ORM/Cache/FileLockRegionTest.php | 18 +- .../Tests/ORM/Cache/MultiGetRegionTest.php | 6 +- .../AbstractCollectionPersisterTest.php | 24 +- ...ReadWriteCachedCollectionPersisterTest.php | 44 +- .../Entity/AbstractEntityPersisterTest.php | 102 +-- ...rictReadWriteCachedEntityPersisterTest.php | 20 +- .../ReadWriteCachedEntityPersisterTest.php | 36 +- .../ORM/Cache/StatisticsCacheLoggerTest.php | 10 +- .../Tests/ORM/CommitOrderCalculatorTest.php | 4 +- .../Doctrine/Tests/ORM/ConfigurationTest.php | 14 +- .../Decorator/EntityManagerDecoratorTest.php | 16 +- .../Doctrine/Tests/ORM/EntityManagerTest.php | 30 +- .../Tests/ORM/EntityNotFoundExceptionTest.php | 4 +- .../AbstractManyToManyAssociationTestCase.php | 3 +- .../Functional/AdvancedAssociationTest.php | 6 +- .../ORM/Functional/BasicFunctionalTest.php | 6 +- .../ORM/Functional/CascadeRemoveOrderTest.php | 14 +- .../Functional/ClassTableInheritanceTest.php | 6 +- .../Functional/ClassTableInheritanceTest2.php | 6 +- .../Functional/CompositePrimaryKeyTest.php | 17 +- ...ompositePrimaryKeyWithAssociationsTest.php | 8 +- .../ORM/Functional/DatabaseDriverTest.php | 54 +- .../ORM/Functional/DatabaseDriverTestCase.php | 6 +- .../ORM/Functional/DefaultValuesTest.php | 6 +- .../ORM/Functional/EntityListenersTest.php | 22 +- .../EntityRepositoryCriteriaTest.php | 2 +- .../ORM/Functional/EntityRepositoryTest.php | 86 +-- .../Functional/ExtraLazyCollectionTest.php | 4 +- .../Tests/ORM/Functional/IdentityMapTest.php | 10 +- .../JoinedTableCompositeKeyTest.php | 2 +- .../ORM/Functional/LifecycleCallbackTest.php | 18 +- .../Functional/Locking/GearmanLockTest.php | 27 +- .../Functional/Locking/LockAgentWorker.php | 8 +- .../Tests/ORM/Functional/Locking/LockTest.php | 2 +- .../ORM/Functional/Locking/OptimisticTest.php | 15 +- .../ManyToManyBasicAssociationTest.php | 2 +- .../Functional/MergeCompositeToOneKeyTest.php | 6 +- .../Tests/ORM/Functional/MergeProxiesTest.php | 6 +- .../Functional/MergeSharedEntitiesTest.php | 6 +- .../Tests/ORM/Functional/NativeQueryTest.php | 17 +- .../Tests/ORM/Functional/NewOperatorTest.php | 16 +- .../Tests/ORM/Functional/NotifyPolicyTest.php | 8 +- .../OneToManyBidirectionalAssociationTest.php | 2 +- ...neToManySelfReferentialAssociationTest.php | 3 +- ...OneToManyUnidirectionalAssociationTest.php | 4 +- .../OneToOneBidirectionalAssociationTest.php | 3 +- .../Functional/OneToOneEagerLoadingTest.php | 6 +- ...OneToOneSelfReferentialAssociationTest.php | 9 +- .../OneToOneUnidirectionalAssociationTest.php | 2 +- .../ORM/Functional/OrderedCollectionTest.php | 4 +- ...edJoinedTableInheritanceCollectionTest.php | 6 +- .../Tests/ORM/Functional/PaginationTest.php | 35 +- .../PersistentCollectionCriteriaTest.php | 4 +- .../Functional/PersistentCollectionTest.php | 6 +- .../ORM/Functional/PersistentObjectTest.php | 6 +- .../ORM/Functional/PostLoadEventTest.php | 26 +- .../Functional/ProxiesLikeEntitiesTest.php | 15 +- .../Tests/ORM/Functional/QueryCacheTest.php | 6 +- .../Tests/ORM/Functional/QueryTest.php | 39 +- .../Tests/ORM/Functional/ReadOnlyTest.php | 6 +- .../ORM/Functional/ReferenceProxyTest.php | 4 +- .../Tests/ORM/Functional/SQLFilterTest.php | 32 +- .../SchemaTool/CompanySchemaTest.php | 6 +- .../ORM/Functional/SchemaTool/DBAL483Test.php | 4 +- .../ORM/Functional/SchemaTool/DDC214Test.php | 12 +- .../SchemaTool/MySqlSchemaToolTest.php | 16 +- .../SchemaTool/PostgreSqlSchemaToolTest.php | 22 +- .../ORM/Functional/SchemaValidatorTest.php | 6 +- .../SecondLevelCacheAbstractTest.php | 22 +- ...econdLevelCacheCompositePrimaryKeyTest.php | 14 +- ...ompositePrimaryKeyWithAssociationsTest.php | 4 +- .../SecondLevelCacheConcurrentTest.php | 6 +- .../SecondLevelCacheQueryCacheTest.php | 8 +- .../SecondLevelCacheRepositoryTest.php | 10 +- .../ORM/Functional/SecondLevelCacheTest.php | 30 +- .../SequenceEmulatedIdentityStrategyTest.php | 2 +- .../ORM/Functional/SequenceGeneratorTest.php | 6 +- .../SingleTableCompositeKeyTest.php | 2 +- .../Functional/SingleTableInheritanceTest.php | 12 +- .../StandardEntityPersisterTest.php | 4 +- .../ORM/Functional/Ticket/DDC1080Test.php | 6 +- .../ORM/Functional/Ticket/DDC1113Test.php | 6 +- .../ORM/Functional/Ticket/DDC1151Test.php | 6 +- .../ORM/Functional/Ticket/DDC1163Test.php | 6 +- .../ORM/Functional/Ticket/DDC117Test.php | 20 +- .../ORM/Functional/Ticket/DDC1181Test.php | 6 +- .../ORM/Functional/Ticket/DDC1193Test.php | 6 +- .../ORM/Functional/Ticket/DDC1209Test.php | 6 +- .../ORM/Functional/Ticket/DDC1225Test.php | 6 +- .../ORM/Functional/Ticket/DDC1228Test.php | 8 +- .../ORM/Functional/Ticket/DDC1238Test.php | 6 +- .../ORM/Functional/Ticket/DDC1250Test.php | 6 +- .../ORM/Functional/Ticket/DDC1300Test.php | 6 +- .../ORM/Functional/Ticket/DDC1335Test.php | 14 +- .../ORM/Functional/Ticket/DDC1360Test.php | 11 +- .../ORM/Functional/Ticket/DDC1383Test.php | 6 +- .../ORM/Functional/Ticket/DDC1392Test.php | 6 +- .../ORM/Functional/Ticket/DDC1400Test.php | 6 +- .../ORM/Functional/Ticket/DDC1404Test.php | 6 +- .../ORM/Functional/Ticket/DDC142Test.php | 12 +- .../ORM/Functional/Ticket/DDC1430Test.php | 6 +- .../ORM/Functional/Ticket/DDC1436Test.php | 6 +- .../ORM/Functional/Ticket/DDC144Test.php | 6 +- .../ORM/Functional/Ticket/DDC1452Test.php | 6 +- .../ORM/Functional/Ticket/DDC1454Test.php | 6 +- .../ORM/Functional/Ticket/DDC1458Test.php | 6 +- .../ORM/Functional/Ticket/DDC1461Test.php | 6 +- .../ORM/Functional/Ticket/DDC1509Test.php | 6 +- .../ORM/Functional/Ticket/DDC1514Test.php | 6 +- .../ORM/Functional/Ticket/DDC1515Test.php | 6 +- .../ORM/Functional/Ticket/DDC1526Test.php | 8 +- .../ORM/Functional/Ticket/DDC1548Test.php | 8 +- .../ORM/Functional/Ticket/DDC1595Test.php | 6 +- .../ORM/Functional/Ticket/DDC1654Test.php | 8 +- .../ORM/Functional/Ticket/DDC1655Test.php | 12 +- .../ORM/Functional/Ticket/DDC1690Test.php | 8 +- .../ORM/Functional/Ticket/DDC1707Test.php | 6 +- .../ORM/Functional/Ticket/DDC1719Test.php | 12 +- .../ORM/Functional/Ticket/DDC1787Test.php | 6 +- .../ORM/Functional/Ticket/DDC1843Test.php | 8 +- .../ORM/Functional/Ticket/DDC1884Test.php | 4 +- .../ORM/Functional/Ticket/DDC1885Test.php | 12 +- .../ORM/Functional/Ticket/DDC1918Test.php | 2 +- .../ORM/Functional/Ticket/DDC1925Test.php | 6 +- .../ORM/Functional/Ticket/DDC192Test.php | 6 +- .../ORM/Functional/Ticket/DDC1998Test.php | 6 +- .../ORM/Functional/Ticket/DDC199Test.php | 6 +- .../ORM/Functional/Ticket/DDC2012Test.php | 32 +- .../ORM/Functional/Ticket/DDC2074Test.php | 2 +- .../ORM/Functional/Ticket/DDC2084Test.php | 8 +- .../ORM/Functional/Ticket/DDC2090Test.php | 18 +- .../ORM/Functional/Ticket/DDC2106Test.php | 8 +- .../ORM/Functional/Ticket/DDC211Test.php | 8 +- .../ORM/Functional/Ticket/DDC2138Test.php | 8 +- .../ORM/Functional/Ticket/DDC2175Test.php | 6 +- .../ORM/Functional/Ticket/DDC2182Test.php | 6 +- .../ORM/Functional/Ticket/DDC2214Test.php | 8 +- .../ORM/Functional/Ticket/DDC2230Test.php | 6 +- .../ORM/Functional/Ticket/DDC2231Test.php | 6 +- .../ORM/Functional/Ticket/DDC2252Test.php | 14 +- .../ORM/Functional/Ticket/DDC2256Test.php | 9 +- .../ORM/Functional/Ticket/DDC2306Test.php | 8 +- .../ORM/Functional/Ticket/DDC2346Test.php | 8 +- .../ORM/Functional/Ticket/DDC2350Test.php | 6 +- .../ORM/Functional/Ticket/DDC2359Test.php | 6 +- .../ORM/Functional/Ticket/DDC237Test.php | 6 +- .../ORM/Functional/Ticket/DDC2387Test.php | 8 +- .../ORM/Functional/Ticket/DDC2415Test.php | 26 +- .../ORM/Functional/Ticket/DDC2494Test.php | 18 +- .../ORM/Functional/Ticket/DDC2575Test.php | 16 +- .../ORM/Functional/Ticket/DDC2579Test.php | 10 +- .../ORM/Functional/Ticket/DDC258Test.php | 6 +- .../ORM/Functional/Ticket/DDC2660Test.php | 6 +- .../ORM/Functional/Ticket/DDC2692Test.php | 10 +- .../ORM/Functional/Ticket/DDC2759Test.php | 6 +- .../ORM/Functional/Ticket/DDC2775Test.php | 6 +- .../ORM/Functional/Ticket/DDC279Test.php | 6 +- .../ORM/Functional/Ticket/DDC2825Test.php | 12 +- .../ORM/Functional/Ticket/DDC2862Test.php | 22 +- .../ORM/Functional/Ticket/DDC2895Test.php | 16 +- .../ORM/Functional/Ticket/DDC2931Test.php | 6 +- .../ORM/Functional/Ticket/DDC2984Test.php | 18 +- .../ORM/Functional/Ticket/DDC2996Test.php | 6 +- .../ORM/Functional/Ticket/DDC3033Test.php | 16 +- .../ORM/Functional/Ticket/DDC3042Test.php | 6 +- .../ORM/Functional/Ticket/DDC3068Test.php | 12 +- .../ORM/Functional/Ticket/DDC309Test.php | 6 +- .../ORM/Functional/Ticket/DDC3123Test.php | 4 +- .../ORM/Functional/Ticket/DDC3170Test.php | 4 +- .../ORM/Functional/Ticket/DDC3192Test.php | 10 +- .../ORM/Functional/Ticket/DDC3223Test.php | 6 +- .../ORM/Functional/Ticket/DDC3300Test.php | 10 +- .../ORM/Functional/Ticket/DDC3330Test.php | 22 +- .../ORM/Functional/Ticket/DDC3346Test.php | 6 +- .../ORM/Functional/Ticket/DDC345Test.php | 6 +- .../ORM/Functional/Ticket/DDC353Test.php | 6 +- .../ORM/Functional/Ticket/DDC3597Test.php | 6 +- .../ORM/Functional/Ticket/DDC3644Test.php | 16 +- .../ORM/Functional/Ticket/DDC3711Test.php | 4 +- .../ORM/Functional/Ticket/DDC371Test.php | 6 +- .../ORM/Functional/Ticket/DDC3785Test.php | 14 +- .../ORM/Functional/Ticket/DDC381Test.php | 6 +- .../ORM/Functional/Ticket/DDC422Test.php | 6 +- .../ORM/Functional/Ticket/DDC425Test.php | 6 +- .../ORM/Functional/Ticket/DDC440Test.php | 6 +- .../ORM/Functional/Ticket/DDC444Test.php | 6 +- .../ORM/Functional/Ticket/DDC448Test.php | 6 +- .../ORM/Functional/Ticket/DDC493Test.php | 6 +- .../ORM/Functional/Ticket/DDC501Test.php | 4 +- .../ORM/Functional/Ticket/DDC512Test.php | 6 +- .../ORM/Functional/Ticket/DDC513Test.php | 6 +- .../ORM/Functional/Ticket/DDC522Test.php | 6 +- .../ORM/Functional/Ticket/DDC531Test.php | 6 +- .../ORM/Functional/Ticket/DDC588Test.php | 6 +- .../ORM/Functional/Ticket/DDC599Test.php | 6 +- .../ORM/Functional/Ticket/DDC618Test.php | 6 +- .../ORM/Functional/Ticket/DDC633Test.php | 6 +- .../ORM/Functional/Ticket/DDC656Test.php | 6 +- .../ORM/Functional/Ticket/DDC698Test.php | 6 +- .../ORM/Functional/Ticket/DDC719Test.php | 6 +- .../ORM/Functional/Ticket/DDC729Test.php | 6 +- .../ORM/Functional/Ticket/DDC735Test.php | 6 +- .../ORM/Functional/Ticket/DDC736Test.php | 5 +- .../ORM/Functional/Ticket/DDC742Test.php | 6 +- .../ORM/Functional/Ticket/DDC767Test.php | 2 +- .../ORM/Functional/Ticket/DDC809Test.php | 38 +- .../ORM/Functional/Ticket/DDC832Test.php | 6 +- .../ORM/Functional/Ticket/DDC837Test.php | 6 +- .../ORM/Functional/Ticket/DDC881Test.php | 6 +- .../ORM/Functional/Ticket/DDC949Test.php | 8 +- .../ORM/Functional/Ticket/DDC960Test.php | 6 +- .../ORM/Functional/Ticket/DDC992Test.php | 8 +- .../ORM/Functional/Ticket/GH5762Test.php | 8 +- .../ORM/Functional/Ticket/Ticket2481Test.php | 6 +- .../Tests/ORM/Functional/Ticket/Ticket69.php | 6 +- .../Tests/ORM/Functional/TypeTest.php | 5 +- .../ORM/Functional/UUIDGeneratorTest.php | 6 +- .../Functional/UnitOfWorkLifecycleTest.php | 4 +- .../ManyToManyCompositeIdForeignKeyTest.php | 10 +- .../ManyToManyCompositeIdTest.php | 8 +- .../OneToManyCompositeIdForeignKeyTest.php | 8 +- .../OneToManyCompositeIdTest.php | 6 +- .../OneToOneCompositeIdForeignKeyTest.php | 8 +- .../OneToOneCompositeIdTest.php | 6 +- .../Tests/ORM/Functional/ValueObjectsTest.php | 44 +- .../ORM/Functional/VersionedOneToOneTest.php | 8 +- .../Tests/ORM/Hydration/ArrayHydratorTest.php | 300 ++++----- .../ORM/Hydration/ObjectHydratorTest.php | 582 +++++++++--------- .../ORM/Hydration/ResultSetMappingTest.php | 105 ++-- .../ORM/Hydration/ScalarHydratorTest.php | 28 +- .../Hydration/SimpleObjectHydratorTest.php | 32 +- .../Hydration/SingleScalarHydratorTest.php | 56 +- .../Tests/ORM/Id/AssignedGeneratorTest.php | 4 +- .../Internal/HydrationCompleteHandlerTest.php | 18 +- .../Tests/ORM/LazyCriteriaCollectionTest.php | 14 +- .../ORM/Mapping/AbstractMappingDriverTest.php | 318 +++++----- .../ORM/Mapping/AnnotationDriverTest.php | 8 +- .../ORM/Mapping/AnsiQuoteStrategyTest.php | 60 +- .../Mapping/BasicInheritanceMappingTest.php | 6 +- .../ORM/Mapping/ClassMetadataBuilderTest.php | 348 ++++++----- .../ORM/Mapping/ClassMetadataFactoryTest.php | 55 +- .../Mapping/ClassMetadataLoadEventTest.php | 4 +- .../Tests/ORM/Mapping/ClassMetadataTest.php | 484 +++++++++------ .../Tests/ORM/Mapping/NamingStrategyTest.php | 191 +++--- .../Tests/ORM/Mapping/QuoteStrategyTest.php | 91 +-- .../ReflectionEmbeddedPropertyTest.php | 28 +- .../Mapping/Symfony/AbstractDriverTest.php | 26 +- .../ORM/Mapping/Symfony/XmlDriverTest.php | 2 +- .../ORM/Mapping/Symfony/YamlDriverTest.php | 2 +- .../ORM/Mapping/XmlMappingDriverTest.php | 20 +- .../ORM/Mapping/YamlMappingDriverTest.php | 2 +- .../Doctrine.Tests.Models.CMS.CmsAddress.php | 116 ++-- .../php/Doctrine.Tests.Models.CMS.CmsUser.php | 220 ++++--- .../php/Doctrine.Tests.Models.Cache.City.php | 56 +- ...e.Tests.Models.Company.CompanyContract.php | 26 +- ...ests.Models.Company.CompanyFixContract.php | 6 +- ...sts.Models.Company.CompanyFlexContract.php | 12 +- ...odels.Company.CompanyFlexUltraContract.php | 8 +- ...ine.Tests.Models.Company.CompanyPerson.php | 45 +- ...1476.DDC1476EntityWithDefaultFieldType.php | 14 +- ....Models.DDC2825.ExplicitSchemaAndTable.php | 12 +- ...dels.DDC2825.SchemaAndTableInTableName.php | 12 +- ...rine.Tests.Models.DDC3579.DDC3579Admin.php | 5 +- ...trine.Tests.Models.DDC3579.DDC3579User.php | 18 +- ...ests.Models.DDC869.DDC869ChequePayment.php | 6 +- ....Models.DDC869.DDC869CreditCardPayment.php | 6 +- ...rine.Tests.Models.DDC869.DDC869Payment.php | 14 +- ...ctrine.Tests.Models.DDC889.DDC889Class.php | 8 +- ...e.Tests.Models.DDC889.DDC889SuperClass.php | 8 +- ...ctrine.Tests.Models.DDC964.DDC964Admin.php | 32 +- ...ctrine.Tests.Models.DDC964.DDC964Guest.php | 11 +- ...octrine.Tests.Models.DDC964.DDC964User.php | 48 +- .../php/Doctrine.Tests.ORM.Mapping.Animal.php | 20 +- .../Doctrine.Tests.ORM.Mapping.Comment.php | 18 +- ...ctrine.Tests.ORM.Mapping.DDC1170Entity.php | 14 +- ...octrine.Tests.ORM.Mapping.DDC807Entity.php | 14 +- .../php/Doctrine.Tests.ORM.Mapping.PHPSLC.php | 12 +- .../php/Doctrine.Tests.ORM.Mapping.User.php | 122 ++-- .../Tests/ORM/Performance/DDC2602Test.php | 16 +- .../Performance/HydrationPerformanceTest.php | 128 ++-- .../Performance/PersisterPerformanceTest.php | 2 +- .../ORM/Performance/ProxyPerformanceTest.php | 14 +- .../ORM/Performance/SecondLevelCacheTest.php | 8 +- .../Performance/UnitOfWorkPerformanceTest.php | 2 +- ...tyPersisterCompositeTypeParametersTest.php | 14 +- ...sicEntityPersisterCompositeTypeSqlTest.php | 8 +- .../BasicEntityPersisterTypeValueSqlTest.php | 20 +- .../JoinedSubclassPersisterTest.php | 2 +- .../Tests/ORM/Proxy/ProxyFactoryTest.php | 16 +- .../ORM/Query/CustomTreeWalkersJoinTest.php | 14 +- .../Tests/ORM/Query/CustomTreeWalkersTest.php | 42 +- tests/Doctrine/Tests/ORM/Query/ExprTest.php | 40 +- .../ORM/Query/LanguageRecognitionTest.php | 66 +- tests/Doctrine/Tests/ORM/Query/LexerTest.php | 70 +-- .../ORM/Query/ParameterTypeInfererTest.php | 24 +- .../Tests/ORM/Query/ParserResultTest.php | 8 +- tests/Doctrine/Tests/ORM/Query/ParserTest.php | 33 +- .../ORM/Query/QueryExpressionVisitorTest.php | 38 +- tests/Doctrine/Tests/ORM/Query/QueryTest.php | 12 +- .../ORM/Query/SelectSqlGenerationTest.php | 64 +- .../Tests/ORM/Query/SqlWalkerTest.php | 12 +- tests/Doctrine/Tests/ORM/QueryBuilderTest.php | 34 +- .../DefaultRepositoryFactoryTest.php | 8 +- .../ClearCacheCollectionRegionCommandTest.php | 30 +- .../ClearCacheEntityRegionCommandTest.php | 30 +- .../ClearCacheQueryRegionCommandTest.php | 30 +- .../ConvertDoctrine1SchemaCommandTest.php | 2 +- .../GenerateRepositoriesCommandTest.php | 22 +- .../Tools/Console/Command/InfoCommandTest.php | 12 +- .../Command/MappingDescribeCommandTest.php | 24 +- .../Console/Command/RunDqlCommandTest.php | 18 +- .../ORM/Tools/ConvertDoctrine1SchemaTest.php | 2 +- .../Tests/ORM/Tools/EntityGeneratorTest.php | 228 ++++--- .../Tools/EntityRepositoryGeneratorTest.php | 16 +- .../AbstractClassMetadataExporterTest.php | 15 +- .../Export/XmlClassMetadataExporterTest.php | 22 +- .../Doctrine.Tests.ORM.Tools.Export.User.php | 112 ++-- .../ORM/Tools/Pagination/CountWalkerTest.php | 18 +- .../Pagination/LimitSubqueryWalkerTest.php | 42 +- .../Tools/Pagination/WhereInWalkerTest.php | 26 +- .../Tools/ResolveTargetEntityListenerTest.php | 14 +- .../Tests/ORM/Tools/SchemaToolTest.php | 28 +- .../Tests/ORM/Tools/SchemaValidatorTest.php | 67 +- tests/Doctrine/Tests/ORM/Tools/SetupTest.php | 12 +- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 10 +- .../ORM/Utility/IdentifierFlattenerTest.php | 6 +- .../Doctrine/Tests/OrmFunctionalTestCase.php | 170 ++--- tests/Doctrine/Tests/OrmTestCase.php | 13 +- tests/Doctrine/Tests/TestUtil.php | 12 +- 371 files changed, 4926 insertions(+), 3871 deletions(-) diff --git a/tests/Doctrine/Tests/EventListener/CacheMetadataListener.php b/tests/Doctrine/Tests/EventListener/CacheMetadataListener.php index f27e38c4779..e8cc6b23ae3 100644 --- a/tests/Doctrine/Tests/EventListener/CacheMetadataListener.php +++ b/tests/Doctrine/Tests/EventListener/CacheMetadataListener.php @@ -17,7 +17,7 @@ class CacheMetadataListener * * @var array */ - protected $enabledItems = array(); + protected $enabledItems = []; /** * @param \Doctrine\Common\Persistence\Event\LoadClassMetadataEventArgs $event @@ -63,9 +63,9 @@ protected function enableCaching(ClassMetadata $metadata, EntityManager $em) return; // Already handled in the past } - $cache = array( + $cache = [ 'usage' => ClassMetadata::CACHE_USAGE_NONSTRICT_READ_WRITE - ); + ]; if ($metadata->isVersioned) { return; diff --git a/tests/Doctrine/Tests/Mocks/CacheRegionMock.php b/tests/Doctrine/Tests/Mocks/CacheRegionMock.php index 519e724941c..c99303907ac 100644 --- a/tests/Doctrine/Tests/Mocks/CacheRegionMock.php +++ b/tests/Doctrine/Tests/Mocks/CacheRegionMock.php @@ -13,8 +13,8 @@ */ class CacheRegionMock implements Region { - public $calls = array(); - public $returns = array(); + public $calls = []; + public $returns = []; public $name; /** @@ -50,7 +50,7 @@ private function getReturn($method, $default) */ public function getName() { - $this->calls[__FUNCTION__][] = array(); + $this->calls[__FUNCTION__][] = []; return $this->name; } @@ -60,7 +60,7 @@ public function getName() */ public function contains(CacheKey $key) { - $this->calls[__FUNCTION__][] = array('key' => $key); + $this->calls[__FUNCTION__][] = ['key' => $key]; return $this->getReturn(__FUNCTION__, false); } @@ -70,7 +70,7 @@ public function contains(CacheKey $key) */ public function evict(CacheKey $key) { - $this->calls[__FUNCTION__][] = array('key' => $key); + $this->calls[__FUNCTION__][] = ['key' => $key]; return $this->getReturn(__FUNCTION__, true); } @@ -80,7 +80,7 @@ public function evict(CacheKey $key) */ public function evictAll() { - $this->calls[__FUNCTION__][] = array(); + $this->calls[__FUNCTION__][] = []; return $this->getReturn(__FUNCTION__, true); } @@ -90,7 +90,7 @@ public function evictAll() */ public function get(CacheKey $key) { - $this->calls[__FUNCTION__][] = array('key' => $key); + $this->calls[__FUNCTION__][] = ['key' => $key]; return $this->getReturn(__FUNCTION__, null); } @@ -100,7 +100,7 @@ public function get(CacheKey $key) */ public function getMultiple(CollectionCacheEntry $collection) { - $this->calls[__FUNCTION__][] = array('collection' => $collection); + $this->calls[__FUNCTION__][] = ['collection' => $collection]; return $this->getReturn(__FUNCTION__, null); } @@ -110,7 +110,7 @@ public function getMultiple(CollectionCacheEntry $collection) */ public function put(CacheKey $key, CacheEntry $entry, Lock $lock = null) { - $this->calls[__FUNCTION__][] = array('key' => $key, 'entry' => $entry); + $this->calls[__FUNCTION__][] = ['key' => $key, 'entry' => $entry]; return $this->getReturn(__FUNCTION__, true); } @@ -120,7 +120,7 @@ public function put(CacheKey $key, CacheEntry $entry, Lock $lock = null) */ public function clear() { - $this->calls = array(); - $this->returns = array(); + $this->calls = []; + $this->returns = []; } } diff --git a/tests/Doctrine/Tests/Mocks/ConcurrentRegionMock.php b/tests/Doctrine/Tests/Mocks/ConcurrentRegionMock.php index 49ed3298530..0f939999d70 100644 --- a/tests/Doctrine/Tests/Mocks/ConcurrentRegionMock.php +++ b/tests/Doctrine/Tests/Mocks/ConcurrentRegionMock.php @@ -17,12 +17,12 @@ */ class ConcurrentRegionMock implements ConcurrentRegion { - public $calls = array(); - public $exceptions = array(); - public $locks = array(); + public $calls = []; + public $exceptions = []; + public $locks = []; /** - * @var \Doctrine\ORM\Cache\Region + * @var \Doctrine\ORM\Cache\Region */ private $region; @@ -80,7 +80,7 @@ public function setLock(CacheKey $key, Lock $lock) */ public function contains(CacheKey $key) { - $this->calls[__FUNCTION__][] = array('key' => $key); + $this->calls[__FUNCTION__][] = ['key' => $key]; if (isset($this->locks[$key->hash])) { return false; @@ -96,7 +96,7 @@ public function contains(CacheKey $key) */ public function evict(CacheKey $key) { - $this->calls[__FUNCTION__][] = array('key' => $key); + $this->calls[__FUNCTION__][] = ['key' => $key]; $this->throwException(__FUNCTION__); @@ -108,7 +108,7 @@ public function evict(CacheKey $key) */ public function evictAll() { - $this->calls[__FUNCTION__][] = array(); + $this->calls[__FUNCTION__][] = []; $this->throwException(__FUNCTION__); @@ -120,7 +120,7 @@ public function evictAll() */ public function get(CacheKey $key) { - $this->calls[__FUNCTION__][] = array('key' => $key); + $this->calls[__FUNCTION__][] = ['key' => $key]; $this->throwException(__FUNCTION__); @@ -136,7 +136,7 @@ public function get(CacheKey $key) */ public function getMultiple(CollectionCacheEntry $collection) { - $this->calls[__FUNCTION__][] = array('collection' => $collection); + $this->calls[__FUNCTION__][] = ['collection' => $collection]; $this->throwException(__FUNCTION__); @@ -148,7 +148,7 @@ public function getMultiple(CollectionCacheEntry $collection) */ public function getName() { - $this->calls[__FUNCTION__][] = array(); + $this->calls[__FUNCTION__][] = []; $this->throwException(__FUNCTION__); @@ -160,7 +160,7 @@ public function getName() */ public function put(CacheKey $key, CacheEntry $entry, Lock $lock = null) { - $this->calls[__FUNCTION__][] = array('key' => $key, 'entry' => $entry); + $this->calls[__FUNCTION__][] = ['key' => $key, 'entry' => $entry]; $this->throwException(__FUNCTION__); @@ -181,7 +181,7 @@ public function put(CacheKey $key, CacheEntry $entry, Lock $lock = null) */ public function lock(CacheKey $key) { - $this->calls[__FUNCTION__][] = array('key' => $key); + $this->calls[__FUNCTION__][] = ['key' => $key]; $this->throwException(__FUNCTION__); @@ -197,7 +197,7 @@ public function lock(CacheKey $key) */ public function unlock(CacheKey $key, Lock $lock) { - $this->calls[__FUNCTION__][] = array('key' => $key, 'lock' => $lock); + $this->calls[__FUNCTION__][] = ['key' => $key, 'lock' => $lock]; $this->throwException(__FUNCTION__); diff --git a/tests/Doctrine/Tests/Mocks/ConnectionMock.php b/tests/Doctrine/Tests/Mocks/ConnectionMock.php index 49ca3e4ea5a..5a28ffa5a52 100644 --- a/tests/Doctrine/Tests/Mocks/ConnectionMock.php +++ b/tests/Doctrine/Tests/Mocks/ConnectionMock.php @@ -26,12 +26,12 @@ class ConnectionMock extends Connection /** * @var array */ - private $_inserts = array(); + private $_inserts = []; /** * @var array */ - private $_executeUpdates = array(); + private $_executeUpdates = []; /** * @param array $params @@ -60,7 +60,7 @@ public function getDatabasePlatform() /** * {@inheritdoc} */ - public function insert($tableName, array $data, array $types = array()) + public function insert($tableName, array $data, array $types = []) { $this->_inserts[$tableName][] = $data; } @@ -68,9 +68,9 @@ public function insert($tableName, array $data, array $types = array()) /** * {@inheritdoc} */ - public function executeUpdate($query, array $params = array(), array $types = array()) + public function executeUpdate($query, array $params = [], array $types = []) { - $this->_executeUpdates[] = array('query' => $query, 'params' => $params, 'types' => $types); + $this->_executeUpdates[] = ['query' => $query, 'params' => $params, 'types' => $types]; } /** @@ -84,7 +84,7 @@ public function lastInsertId($seqName = null) /** * {@inheritdoc} */ - public function fetchColumn($statement, array $params = array(), $colnum = 0, array $types = array()) + public function fetchColumn($statement, array $params = [], $colnum = 0, array $types = []) { return $this->_fetchOneResult; } @@ -153,7 +153,7 @@ public function getExecuteUpdates() */ public function reset() { - $this->_inserts = array(); + $this->_inserts = []; $this->_lastInsertId = 0; } } diff --git a/tests/Doctrine/Tests/Mocks/DriverMock.php b/tests/Doctrine/Tests/Mocks/DriverMock.php index 15a37c17dd6..c805f0bf9ff 100644 --- a/tests/Doctrine/Tests/Mocks/DriverMock.php +++ b/tests/Doctrine/Tests/Mocks/DriverMock.php @@ -25,7 +25,7 @@ class DriverMock implements Driver /** * {@inheritdoc} */ - public function connect(array $params, $username = null, $password = null, array $driverOptions = array()) + public function connect(array $params, $username = null, $password = null, array $driverOptions = []) { return new DriverConnectionMock(); } diff --git a/tests/Doctrine/Tests/Mocks/EntityManagerMock.php b/tests/Doctrine/Tests/Mocks/EntityManagerMock.php index 6f98e3c508a..f7af70227dd 100644 --- a/tests/Doctrine/Tests/Mocks/EntityManagerMock.php +++ b/tests/Doctrine/Tests/Mocks/EntityManagerMock.php @@ -72,7 +72,7 @@ public static function create($conn, Configuration $config = null, EventManager $config = new Configuration(); $config->setProxyDir(__DIR__ . '/../Proxies'); $config->setProxyNamespace('Doctrine\Tests\Proxies'); - $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(array(), true)); + $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([], true)); } if (null === $eventManager) { $eventManager = new EventManager(); diff --git a/tests/Doctrine/Tests/Mocks/EntityPersisterMock.php b/tests/Doctrine/Tests/Mocks/EntityPersisterMock.php index 6130f58f301..63be3397e68 100644 --- a/tests/Doctrine/Tests/Mocks/EntityPersisterMock.php +++ b/tests/Doctrine/Tests/Mocks/EntityPersisterMock.php @@ -14,17 +14,17 @@ class EntityPersisterMock extends BasicEntityPersister /** * @var array */ - private $inserts = array(); + private $inserts = []; /** * @var array */ - private $updates = array(); + private $updates = []; /** * @var array */ - private $deletes = array(); + private $deletes = []; /** * @var int @@ -39,7 +39,7 @@ class EntityPersisterMock extends BasicEntityPersister /** * @var array */ - private $postInsertIds = array(); + private $postInsertIds = []; /** * @var bool @@ -57,10 +57,10 @@ public function addInsert($entity) if ( ! is_null($this->mockIdGeneratorType) && $this->mockIdGeneratorType == ClassMetadata::GENERATOR_TYPE_IDENTITY || $this->class->isIdGeneratorIdentity()) { $id = $this->identityColumnValueCounter++; - $this->postInsertIds[] = array( + $this->postInsertIds[] = [ 'generatedId' => $id, 'entity' => $entity, - ); + ]; return $id; } return null; @@ -139,9 +139,9 @@ public function reset() { $this->existsCalled = false; $this->identityColumnValueCounter = 0; - $this->inserts = array(); - $this->updates = array(); - $this->deletes = array(); + $this->inserts = []; + $this->updates = []; + $this->deletes = []; } /** diff --git a/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php b/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php index 7afec2c607e..ca0df22fe71 100644 --- a/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php +++ b/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php @@ -108,7 +108,7 @@ public function errorInfo() /** * {@inheritdoc} */ - public function execute($params = array()) + public function execute($params = []) { } diff --git a/tests/Doctrine/Tests/Mocks/MetadataDriverMock.php b/tests/Doctrine/Tests/Mocks/MetadataDriverMock.php index b691ec02c3a..f14c256b19e 100644 --- a/tests/Doctrine/Tests/Mocks/MetadataDriverMock.php +++ b/tests/Doctrine/Tests/Mocks/MetadataDriverMock.php @@ -30,6 +30,6 @@ public function isTransient($className) */ public function getAllClassNames() { - return array(); + return []; } } diff --git a/tests/Doctrine/Tests/Mocks/TaskMock.php b/tests/Doctrine/Tests/Mocks/TaskMock.php index f097abc03c4..f6ce095add1 100644 --- a/tests/Doctrine/Tests/Mocks/TaskMock.php +++ b/tests/Doctrine/Tests/Mocks/TaskMock.php @@ -17,7 +17,7 @@ class TaskMock extends \Doctrine\Common\Cli\Tasks\AbstractTask * * @var array (TaskMock) */ - static public $instances = array(); + static public $instances = []; /** * @var int diff --git a/tests/Doctrine/Tests/Mocks/TimestampRegionMock.php b/tests/Doctrine/Tests/Mocks/TimestampRegionMock.php index b55c7c5e31d..3f088a4e492 100644 --- a/tests/Doctrine/Tests/Mocks/TimestampRegionMock.php +++ b/tests/Doctrine/Tests/Mocks/TimestampRegionMock.php @@ -14,6 +14,6 @@ class TimestampRegionMock extends CacheRegionMock implements TimestampRegion { public function update(CacheKey $key) { - $this->calls[__FUNCTION__][] = array('key' => $key); + $this->calls[__FUNCTION__][] = ['key' => $key]; } } diff --git a/tests/Doctrine/Tests/Mocks/UnitOfWorkMock.php b/tests/Doctrine/Tests/Mocks/UnitOfWorkMock.php index 3d7361e7f8e..f11f7152322 100644 --- a/tests/Doctrine/Tests/Mocks/UnitOfWorkMock.php +++ b/tests/Doctrine/Tests/Mocks/UnitOfWorkMock.php @@ -12,7 +12,7 @@ class UnitOfWorkMock extends UnitOfWork /** * @var array */ - private $_mockDataChangeSets = array(); + private $_mockDataChangeSets = []; /** * @var array|null diff --git a/tests/Doctrine/Tests/Models/CMS/CmsAddress.php b/tests/Doctrine/Tests/Models/CMS/CmsAddress.php index aaf4956d3d0..c896866432f 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsAddress.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsAddress.php @@ -124,91 +124,115 @@ public function setUser(CmsUser $user) { public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) { - $metadata->setPrimaryTable(array( + $metadata->setPrimaryTable( + [ 'name' => 'company_person', - )); + ] + ); - $metadata->mapField(array ( + $metadata->mapField( + [ 'id' => true, 'fieldName' => 'id', 'type' => 'integer', - )); + ] + ); - $metadata->mapField(array ( + $metadata->mapField( + [ 'fieldName' => 'zip', 'length' => 50, - )); + ] + ); - $metadata->mapField(array ( + $metadata->mapField( + [ 'fieldName' => 'city', 'length' => 50, - )); + ] + ); - $metadata->mapOneToOne(array( + $metadata->mapOneToOne( + [ 'fieldName' => 'user', 'targetEntity' => 'CmsUser', - 'joinColumns' => array(array('referencedColumnName' => 'id')) - )); + 'joinColumns' => [['referencedColumnName' => 'id']] + ] + ); - $metadata->addNamedNativeQuery(array ( + $metadata->addNamedNativeQuery( + [ 'name' => 'find-all', 'query' => 'SELECT id, country, city FROM cms_addresses', 'resultSetMapping' => 'mapping-find-all', - )); + ] + ); - $metadata->addNamedNativeQuery(array ( + $metadata->addNamedNativeQuery( + [ 'name' => 'find-by-id', 'query' => 'SELECT * FROM cms_addresses WHERE id = ?', 'resultClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsAddress', - )); + ] + ); - $metadata->addNamedNativeQuery(array ( + $metadata->addNamedNativeQuery( + [ 'name' => 'count', 'query' => 'SELECT COUNT(*) AS count FROM cms_addresses', 'resultSetMapping' => 'mapping-count', - )); + ] + ); - $metadata->addSqlResultSetMapping(array ( + $metadata->addSqlResultSetMapping( + [ 'name' => 'mapping-find-all', - 'columns' => array(), - 'entities' => array ( array ( - 'fields' => array ( - array ( + 'columns' => [], + 'entities' => [ + [ + 'fields' => [ + [ 'name' => 'id', 'column' => 'id', - ), - array ( + ], + [ 'name' => 'city', 'column' => 'city', - ), - array ( + ], + [ 'name' => 'country', 'column' => 'country', - ), - ), + ], + ], 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsAddress', - ), - ), - )); + ], + ], + ] + ); - $metadata->addSqlResultSetMapping(array ( + $metadata->addSqlResultSetMapping( + [ 'name' => 'mapping-without-fields', - 'columns' => array(), - 'entities' => array(array ( + 'columns' => [], + 'entities' => [ + [ 'entityClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsAddress', - 'fields' => array() - ) - ) - )); - - $metadata->addSqlResultSetMapping(array ( + 'fields' => [] + ] + ] + ] + ); + + $metadata->addSqlResultSetMapping( + [ 'name' => 'mapping-count', - 'columns' =>array ( - array ( + 'columns' => [ + [ 'name' => 'count', - ), - ) - )); + ], + ] + ] + ); $metadata->addEntityListener(\Doctrine\ORM\Events::postPersist, 'CmsAddressListener', 'postPersist'); $metadata->addEntityListener(\Doctrine\ORM\Events::prePersist, 'CmsAddressListener', 'prePersist'); @@ -222,4 +246,4 @@ public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $met $metadata->addEntityListener(\Doctrine\ORM\Events::preFlush, 'CmsAddressListener', 'preFlush'); $metadata->addEntityListener(\Doctrine\ORM\Events::postLoad, 'CmsAddressListener', 'postLoad'); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/CMS/CmsUser.php b/tests/Doctrine/Tests/Models/CMS/CmsUser.php index 10042efb527..de23216f71b 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsUser.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsUser.php @@ -271,188 +271,214 @@ public function setEmail(CmsEmail $email = null) { public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) { - $metadata->setPrimaryTable(array( + $metadata->setPrimaryTable( + [ 'name' => 'cms_users', - )); + ] + ); - $metadata->addNamedNativeQuery(array ( + $metadata->addNamedNativeQuery( + [ 'name' => 'fetchIdAndUsernameWithResultClass', 'query' => 'SELECT id, username FROM cms_users WHERE username = ?', 'resultClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', - )); + ] + ); - $metadata->addNamedNativeQuery(array ( + $metadata->addNamedNativeQuery( + [ 'name' => 'fetchAllColumns', 'query' => 'SELECT * FROM cms_users WHERE username = ?', 'resultClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', - )); + ] + ); - $metadata->addNamedNativeQuery(array ( + $metadata->addNamedNativeQuery( + [ 'name' => 'fetchJoinedAddress', 'query' => 'SELECT u.id, u.name, u.status, a.id AS a_id, a.country, a.zip, a.city FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id WHERE u.username = ?', 'resultSetMapping' => 'mappingJoinedAddress', - )); + ] + ); - $metadata->addNamedNativeQuery(array ( + $metadata->addNamedNativeQuery( + [ 'name' => 'fetchJoinedPhonenumber', 'query' => 'SELECT id, name, status, phonenumber AS number FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username = ?', 'resultSetMapping' => 'mappingJoinedPhonenumber', - )); + ] + ); - $metadata->addNamedNativeQuery(array ( + $metadata->addNamedNativeQuery( + [ 'name' => 'fetchUserPhonenumberCount', 'query' => 'SELECT id, name, status, COUNT(phonenumber) AS numphones FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username IN (?) GROUP BY id, name, status, username ORDER BY username', 'resultSetMapping' => 'mappingUserPhonenumberCount', - )); + ] + ); - $metadata->addNamedNativeQuery(array ( + $metadata->addNamedNativeQuery( + [ "name" => "fetchMultipleJoinsEntityResults", "resultSetMapping" => "mappingMultipleJoinsEntityResults", "query" => "SELECT u.id AS u_id, u.name AS u_name, u.status AS u_status, a.id AS a_id, a.zip AS a_zip, a.country AS a_country, COUNT(p.phonenumber) AS numphones FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id INNER JOIN cms_phonenumbers p ON u.id = p.user_id GROUP BY u.id, u.name, u.status, u.username, a.id, a.zip, a.country ORDER BY u.username" - )); + ] + ); - $metadata->addSqlResultSetMapping(array ( + $metadata->addSqlResultSetMapping( + [ 'name' => 'mappingJoinedAddress', - 'columns' => array(), - 'entities' => array(array ( - 'fields'=> array ( - array ( + 'columns' => [], + 'entities' => [ + [ + 'fields'=> [ + [ 'name' => 'id', 'column' => 'id', - ), - array ( + ], + [ 'name' => 'name', 'column' => 'name', - ), - array ( + ], + [ 'name' => 'status', 'column' => 'status', - ), - array ( + ], + [ 'name' => 'address.zip', 'column' => 'zip', - ), - array ( + ], + [ 'name' => 'address.city', 'column' => 'city', - ), - array ( + ], + [ 'name' => 'address.country', 'column' => 'country', - ), - array ( + ], + [ 'name' => 'address.id', 'column' => 'a_id', - ), - ), + ], + ], 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', 'discriminatorColumn' => null - ), - ), - )); + ], + ], + ] + ); - $metadata->addSqlResultSetMapping(array ( + $metadata->addSqlResultSetMapping( + [ 'name' => 'mappingJoinedPhonenumber', - 'columns' => array(), - 'entities' => array(array( - 'fields'=> array ( - array ( + 'columns' => [], + 'entities' => [ + [ + 'fields'=> [ + [ 'name' => 'id', 'column' => 'id', - ), - array ( + ], + [ 'name' => 'name', 'column' => 'name', - ), - array ( + ], + [ 'name' => 'status', 'column' => 'status', - ), - array ( + ], + [ 'name' => 'phonenumbers.phonenumber', 'column' => 'number', - ), - ), + ], + ], 'entityClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', 'discriminatorColumn' => null - ), - ), - )); + ], + ], + ] + ); - $metadata->addSqlResultSetMapping(array ( + $metadata->addSqlResultSetMapping( + [ 'name' => 'mappingUserPhonenumberCount', - 'columns' => array(), - 'entities' => array ( - array( - 'fields' => array ( - array ( + 'columns' => [], + 'entities' => [ + [ + 'fields' => [ + [ 'name' => 'id', 'column' => 'id', - ), - array ( + ], + [ 'name' => 'name', 'column' => 'name', - ), - array ( + ], + [ 'name' => 'status', 'column' => 'status', - ) - ), + ] + ], 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', 'discriminatorColumn' => null - ) - ), - 'columns' => array ( - array ( + ] + ], + 'columns' => [ + [ 'name' => 'numphones', - ) - ) - )); + ] + ] + ] + ); - $metadata->addSqlResultSetMapping(array( + $metadata->addSqlResultSetMapping( + [ 'name' => 'mappingMultipleJoinsEntityResults', - 'entities' => array(array( - 'fields' => array( - array( + 'entities' => [ + [ + 'fields' => [ + [ 'name' => 'id', 'column' => 'u_id', - ), - array( + ], + [ 'name' => 'name', 'column' => 'u_name', - ), - array( + ], + [ 'name' => 'status', 'column' => 'u_status', - ) - ), + ] + ], 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', 'discriminatorColumn' => null, - ), - array( - 'fields' => array( - array( + ], + [ + 'fields' => [ + [ 'name' => 'id', 'column' => 'a_id', - ), - array( + ], + [ 'name' => 'zip', 'column' => 'a_zip', - ), - array( + ], + [ 'name' => 'country', 'column' => 'a_country', - ), - ), + ], + ], 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsAddress', 'discriminatorColumn' => null, - ), - ), - 'columns' => array(array( + ], + ], + 'columns' => [ + [ 'name' => 'numphones', - ) - ) - )); + ] + ] + ] + ); } } diff --git a/tests/Doctrine/Tests/Models/Company/CompanyContract.php b/tests/Doctrine/Tests/Models/Company/CompanyContract.php index 1390982740e..15e691ba087 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyContract.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyContract.php @@ -134,28 +134,36 @@ static public function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $met { $metadata->setInheritanceType(\Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_JOINED); $metadata->setTableName( 'company_contracts'); - $metadata->setDiscriminatorColumn(array( + $metadata->setDiscriminatorColumn( + [ 'name' => 'discr', 'type' => 'string', - )); + ] + ); - $metadata->mapField(array( + $metadata->mapField( + [ 'id' => true, 'name' => 'id', 'fieldName' => 'id', - )); + ] + ); - $metadata->mapField(array( + $metadata->mapField( + [ 'type' => 'boolean', 'name' => 'completed', 'fieldName' => 'completed', - )); + ] + ); - $metadata->setDiscriminatorMap(array( + $metadata->setDiscriminatorMap( + [ "fix" => "CompanyFixContract", "flexible" => "CompanyFlexContract", "flexultra" => "CompanyFlexUltraContract" - )); + ] + ); $metadata->addEntityListener(\Doctrine\ORM\Events::postPersist, 'CompanyContractListener', 'postPersistHandler'); $metadata->addEntityListener(\Doctrine\ORM\Events::prePersist, 'CompanyContractListener', 'prePersistHandler'); diff --git a/tests/Doctrine/Tests/Models/Company/CompanyFixContract.php b/tests/Doctrine/Tests/Models/Company/CompanyFixContract.php index 87f3ce9529a..8fe94e2584d 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyFixContract.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyFixContract.php @@ -30,10 +30,12 @@ public function setFixPrice($fixPrice) static public function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) { - $metadata->mapField(array( + $metadata->mapField( + [ 'type' => 'integer', 'name' => 'fixPrice', 'fieldName' => 'fixPrice', - )); + ] + ); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/Company/CompanyFlexContract.php b/tests/Doctrine/Tests/Models/Company/CompanyFlexContract.php index 86e6b330cef..978e8d5e6cd 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyFlexContract.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyFlexContract.php @@ -110,16 +110,20 @@ public function removeManager(CompanyManager $manager) static public function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) { - $metadata->mapField(array( + $metadata->mapField( + [ 'type' => 'integer', 'name' => 'hoursWorked', 'fieldName' => 'hoursWorked', - )); + ] + ); - $metadata->mapField(array( + $metadata->mapField( + [ 'type' => 'integer', 'name' => 'pricePerHour', 'fieldName' => 'pricePerHour', - )); + ] + ); } } diff --git a/tests/Doctrine/Tests/Models/Company/CompanyFlexUltraContract.php b/tests/Doctrine/Tests/Models/Company/CompanyFlexUltraContract.php index 85126bd0edd..47313d032e7 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyFlexUltraContract.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyFlexUltraContract.php @@ -31,11 +31,13 @@ public function setMaxPrice($maxPrice) static public function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) { - $metadata->mapField(array( + $metadata->mapField( + [ 'type' => 'integer', 'name' => 'maxPrice', 'fieldName' => 'maxPrice', - )); + ] + ); $metadata->addEntityListener(\Doctrine\ORM\Events::postPersist, 'CompanyContractListener', 'postPersistHandler'); $metadata->addEntityListener(\Doctrine\ORM\Events::prePersist, 'CompanyContractListener', 'prePersistHandler'); @@ -47,8 +49,8 @@ static public function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $met $metadata->addEntityListener(\Doctrine\ORM\Events::preFlush, 'CompanyContractListener', 'preFlushHandler'); $metadata->addEntityListener(\Doctrine\ORM\Events::postLoad, 'CompanyContractListener', 'postLoadHandler'); - + $metadata->addEntityListener(\Doctrine\ORM\Events::prePersist, 'CompanyFlexUltraContractListener', 'prePersistHandler1'); $metadata->addEntityListener(\Doctrine\ORM\Events::prePersist, 'CompanyFlexUltraContractListener', 'prePersistHandler2'); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/Company/CompanyPerson.php b/tests/Doctrine/Tests/Models/Company/CompanyPerson.php index 4636fa4e30a..529c0e10949 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyPerson.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyPerson.php @@ -120,41 +120,50 @@ public function setSpouse(CompanyPerson $spouse) { public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) { - $metadata->setPrimaryTable(array( + $metadata->setPrimaryTable( + [ 'name' => 'company_person', - )); + ] + ); - $metadata->addNamedNativeQuery(array ( + $metadata->addNamedNativeQuery( + [ 'name' => 'fetchAllWithResultClass', 'query' => 'SELECT id, name, discr FROM company_persons ORDER BY name', 'resultClass' => 'Doctrine\\Tests\\Models\\Company\\CompanyPerson', - )); + ] + ); - $metadata->addNamedNativeQuery(array ( + $metadata->addNamedNativeQuery( + [ 'name' => 'fetchAllWithSqlResultSetMapping', 'query' => 'SELECT id, name, discr AS discriminator FROM company_persons ORDER BY name', 'resultSetMapping' => 'mappingFetchAll', - )); + ] + ); - $metadata->addSqlResultSetMapping(array ( + $metadata->addSqlResultSetMapping( + [ 'name' => 'mappingFetchAll', - 'columns' => array(), - 'entities' => array ( array ( - 'fields' => array ( - array ( + 'columns' => [], + 'entities' => [ + [ + 'fields' => [ + [ 'name' => 'id', 'column' => 'id', - ), - array ( + ], + [ 'name' => 'name', 'column' => 'name', - ), - ), + ], + ], 'entityClass' => 'Doctrine\Tests\Models\Company\CompanyPerson', 'discriminatorColumn' => 'discriminator', - ), - ), - )); + ], + ], + ] + ); } } diff --git a/tests/Doctrine/Tests/Models/DDC1476/DDC1476EntityWithDefaultFieldType.php b/tests/Doctrine/Tests/Models/DDC1476/DDC1476EntityWithDefaultFieldType.php index 4f94dad1381..b543b0fe589 100644 --- a/tests/Doctrine/Tests/Models/DDC1476/DDC1476EntityWithDefaultFieldType.php +++ b/tests/Doctrine/Tests/Models/DDC1476/DDC1476EntityWithDefaultFieldType.php @@ -44,13 +44,17 @@ public function setName($name) public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) { - $metadata->mapField(array( + $metadata->mapField( + [ 'id' => true, 'fieldName' => 'id', - )); - $metadata->mapField(array( + ] + ); + $metadata->mapField( + [ 'fieldName' => 'name', - )); + ] + ); $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_NONE); } diff --git a/tests/Doctrine/Tests/Models/DDC3346/DDC3346Author.php b/tests/Doctrine/Tests/Models/DDC3346/DDC3346Author.php index 5229ee280a2..e284532c0cc 100644 --- a/tests/Doctrine/Tests/Models/DDC3346/DDC3346Author.php +++ b/tests/Doctrine/Tests/Models/DDC3346/DDC3346Author.php @@ -24,5 +24,5 @@ class DDC3346Author /** * @OneToMany(targetEntity="DDC3346Article", mappedBy="user", fetch="EAGER", cascade={"detach"}) */ - public $articles = array(); + public $articles = []; } diff --git a/tests/Doctrine/Tests/Models/DDC3579/DDC3579Admin.php b/tests/Doctrine/Tests/Models/DDC3579/DDC3579Admin.php index effedc3c4b1..85383994cb0 100644 --- a/tests/Doctrine/Tests/Models/DDC3579/DDC3579Admin.php +++ b/tests/Doctrine/Tests/Models/DDC3579/DDC3579Admin.php @@ -15,8 +15,9 @@ class DDC3579Admin extends DDC3579User { public static function loadMetadata($metadata) { - $metadata->setAssociationOverride('groups', array( + $metadata->setAssociationOverride('groups', [ 'inversedBy' => 'admins' - )); + ] + ); } } diff --git a/tests/Doctrine/Tests/Models/DDC3579/DDC3579User.php b/tests/Doctrine/Tests/Models/DDC3579/DDC3579User.php index 7a7ea5de657..8b6193cdc3f 100644 --- a/tests/Doctrine/Tests/Models/DDC3579/DDC3579User.php +++ b/tests/Doctrine/Tests/Models/DDC3579/DDC3579User.php @@ -81,27 +81,33 @@ public function getGroups() public static function loadMetadata($metadata) { - $metadata->mapField(array( + $metadata->mapField( + [ 'id' => true, 'fieldName' => 'id', 'type' => 'integer', 'columnName' => 'user_id', 'length' => 150, - )); + ] + ); - $metadata->mapField(array( + $metadata->mapField( + [ 'fieldName' => 'name', 'type' => 'string', 'columnName'=> 'user_name', 'nullable' => true, 'unique' => false, 'length' => 250, - )); + ] + ); - $metadata->mapManyToMany(array( + $metadata->mapManyToMany( + [ 'fieldName' => 'groups', 'targetEntity' => 'DDC3579Group' - )); + ] + ); $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_AUTO); } diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php b/tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php index 00e5da01718..4690e068a4c 100644 --- a/tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php @@ -13,10 +13,12 @@ class DDC869ChequePayment extends DDC869Payment public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) { - $metadata->mapField(array( + $metadata->mapField( + [ 'fieldName' => 'serialNumber', 'type' => 'string', - )); + ] + ); } } diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php b/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php index 4c1f8c30602..6f314e31889 100644 --- a/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php @@ -13,10 +13,12 @@ class DDC869CreditCardPayment extends DDC869Payment public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) { - $metadata->mapField(array( + $metadata->mapField( + [ 'fieldName' => 'creditCardNumber', 'type' => 'string', - )); + ] + ); } } diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php b/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php index ea052d12eb3..f689a82ea4d 100644 --- a/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php @@ -21,16 +21,20 @@ class DDC869Payment public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) { - $metadata->mapField(array( + $metadata->mapField( + [ 'id' => true, 'fieldName' => 'id', 'type' => 'integer', 'columnName' => 'id', - )); - $metadata->mapField(array( + ] + ); + $metadata->mapField( + [ 'fieldName' => 'value', 'type' => 'float', - )); + ] + ); $metadata->isMappedSuperclass = true; $metadata->setCustomRepositoryClass("Doctrine\Tests\Models\DDC869\DDC869PaymentRepository"); $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_AUTO); diff --git a/tests/Doctrine/Tests/Models/DDC889/DDC889Class.php b/tests/Doctrine/Tests/Models/DDC889/DDC889Class.php index 8bba1274ca2..089261a83ba 100644 --- a/tests/Doctrine/Tests/Models/DDC889/DDC889Class.php +++ b/tests/Doctrine/Tests/Models/DDC889/DDC889Class.php @@ -15,12 +15,14 @@ class DDC889Class extends DDC889SuperClass public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) { - $metadata->mapField(array( + $metadata->mapField( + [ 'id' => true, 'fieldName' => 'id', 'type' => 'integer', 'columnName' => 'id', - )); + ] + ); $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_AUTO); } diff --git a/tests/Doctrine/Tests/Models/DDC889/DDC889SuperClass.php b/tests/Doctrine/Tests/Models/DDC889/DDC889SuperClass.php index 42fd933868a..8408a9ad74b 100644 --- a/tests/Doctrine/Tests/Models/DDC889/DDC889SuperClass.php +++ b/tests/Doctrine/Tests/Models/DDC889/DDC889SuperClass.php @@ -13,9 +13,11 @@ class DDC889SuperClass public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) { - $metadata->mapField(array( + $metadata->mapField( + [ 'fieldName' => 'name', - )); + ] + ); $metadata->isMappedSuperclass = true; $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_NONE); diff --git a/tests/Doctrine/Tests/Models/DDC964/DDC964Admin.php b/tests/Doctrine/Tests/Models/DDC964/DDC964Admin.php index 110326b2c93..29ea4dd4e14 100644 --- a/tests/Doctrine/Tests/Models/DDC964/DDC964Admin.php +++ b/tests/Doctrine/Tests/Models/DDC964/DDC964Admin.php @@ -23,23 +23,31 @@ class DDC964Admin extends DDC964User { public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) { - $metadata->setAssociationOverride('address',array( - 'joinColumns'=>array(array( + $metadata->setAssociationOverride('address', + [ + 'joinColumns'=> [ + [ 'name' => 'adminaddress_id', 'referencedColumnName' => 'id', - )) - )); + ] + ] + ] + ); - $metadata->setAssociationOverride('groups',array( - 'joinTable' => array( + $metadata->setAssociationOverride('groups', + [ + 'joinTable' => [ 'name' => 'ddc964_users_admingroups', - 'joinColumns' => array(array( + 'joinColumns' => [ + [ 'name' => 'adminuser_id', - )), - 'inverseJoinColumns' =>array (array ( + ] + ], + 'inverseJoinColumns' => [[ 'name' => 'admingroup_id', - )) - ) - )); + ]] + ] + ] + ); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DDC964/DDC964Guest.php b/tests/Doctrine/Tests/Models/DDC964/DDC964Guest.php index cb64d15fae8..23486b0fd6d 100644 --- a/tests/Doctrine/Tests/Models/DDC964/DDC964Guest.php +++ b/tests/Doctrine/Tests/Models/DDC964/DDC964Guest.php @@ -26,17 +26,20 @@ class DDC964Guest extends DDC964User { public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) { - $metadata->setAttributeOverride('id', array( + $metadata->setAttributeOverride('id', [ 'columnName' => 'guest_id', 'type' => 'integer', 'length' => 140, - )); + ] + ); - $metadata->setAttributeOverride('name',array( + $metadata->setAttributeOverride('name', + [ 'columnName' => 'guest_name', 'nullable' => false, 'unique' => true, 'length' => 240, - )); + ] + ); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DDC964/DDC964User.php b/tests/Doctrine/Tests/Models/DDC964/DDC964User.php index f1bfdae394d..a9f15c8c948 100644 --- a/tests/Doctrine/Tests/Models/DDC964/DDC964User.php +++ b/tests/Doctrine/Tests/Models/DDC964/DDC964User.php @@ -109,47 +109,59 @@ public function setAddress(DDC964Address $address) public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) { - $metadata->mapField(array( + $metadata->mapField( + [ 'id' => true, 'fieldName' => 'id', 'type' => 'integer', 'columnName' => 'user_id', 'length' => 150, - )); - $metadata->mapField(array( + ] + ); + $metadata->mapField( + [ 'fieldName' => 'name', 'type' => 'string', 'columnName'=> 'user_name', 'nullable' => true, 'unique' => false, 'length' => 250, - )); + ] + ); - $metadata->mapManyToOne(array( + $metadata->mapManyToOne( + [ 'fieldName' => 'address', 'targetEntity' => 'DDC964Address', - 'cascade' => array('persist','merge'), - 'joinColumn' => array('name'=>'address_id', 'referencedColumnMame'=>'id'), - )); + 'cascade' => ['persist','merge'], + 'joinColumn' => ['name'=>'address_id', 'referencedColumnMame'=>'id'], + ] + ); - $metadata->mapManyToMany(array( + $metadata->mapManyToMany( + [ 'fieldName' => 'groups', 'targetEntity' => 'DDC964Group', 'inversedBy' => 'users', - 'cascade' => array('persist','merge','detach'), - 'joinTable' => array( + 'cascade' => ['persist','merge','detach'], + 'joinTable' => [ 'name' => 'ddc964_users_groups', - 'joinColumns' => array(array( + 'joinColumns' => [ + [ 'name'=>'user_id', 'referencedColumnName'=>'id', - )), - 'inverseJoinColumns'=>array(array( + ] + ], + 'inverseJoinColumns'=> [ + [ 'name'=>'group_id', 'referencedColumnName'=>'id', - )) - ) - )); + ] + ] + ] + ] + ); $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_AUTO); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/GeoNames/Admin1.php b/tests/Doctrine/Tests/Models/GeoNames/Admin1.php index 15a0147edd2..11b9d8e8582 100644 --- a/tests/Doctrine/Tests/Models/GeoNames/Admin1.php +++ b/tests/Doctrine/Tests/Models/GeoNames/Admin1.php @@ -28,7 +28,7 @@ class Admin1 * @OneToMany(targetEntity="Admin1AlternateName", mappedBy="admin1") * @Cache */ - public $names = array(); + public $names = []; /** * @Column(type="string", length=255); diff --git a/tests/Doctrine/Tests/Models/Routing/RoutingRoute.php b/tests/Doctrine/Tests/Models/Routing/RoutingRoute.php index 9e5d5d02e76..7354e56ca25 100644 --- a/tests/Doctrine/Tests/Models/Routing/RoutingRoute.php +++ b/tests/Doctrine/Tests/Models/Routing/RoutingRoute.php @@ -30,10 +30,10 @@ class RoutingRoute * @OneToMany(targetEntity="RoutingRouteBooking", mappedBy="route") * @OrderBy({"passengerName" = "ASC"}) */ - public $bookings = array(); + public $bookings = []; public function __construct() { $this->legs = new ArrayCollection(); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Cache/AbstractRegionTest.php b/tests/Doctrine/Tests/ORM/Cache/AbstractRegionTest.php index ca01b069d46..665978f01d3 100644 --- a/tests/Doctrine/Tests/ORM/Cache/AbstractRegionTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/AbstractRegionTest.php @@ -37,10 +37,10 @@ protected abstract function createRegion(); static public function dataProviderCacheValues() { - return array( - array(new CacheKeyMock('key.1'), new CacheEntryMock(array('id'=>1, 'name' => 'bar'))), - array(new CacheKeyMock('key.2'), new CacheEntryMock(array('id'=>2, 'name' => 'foo'))), - ); + return [ + [new CacheKeyMock('key.1'), new CacheEntryMock(['id'=>1, 'name' => 'bar'])], + [new CacheKeyMock('key.2'), new CacheEntryMock(['id'=>2, 'name' => 'foo'])], + ]; } /** @@ -57,7 +57,7 @@ public function testPutGetContainsEvict($key, $value) $actual = $this->region->get($key); $this->assertEquals($value, $actual); - + $this->region->evict($key); $this->assertFalse($this->region->contains($key)); @@ -71,8 +71,8 @@ public function testEvictAll() $this->assertFalse($this->region->contains($key1)); $this->assertFalse($this->region->contains($key2)); - $this->region->put($key1, new CacheEntryMock(array('value' => 'foo'))); - $this->region->put($key2, new CacheEntryMock(array('value' => 'bar'))); + $this->region->put($key1, new CacheEntryMock(['value' => 'foo'])); + $this->region->put($key2, new CacheEntryMock(['value' => 'bar'])); $this->assertTrue($this->region->contains($key1)); $this->assertTrue($this->region->contains($key2)); @@ -82,4 +82,4 @@ public function testEvictAll() $this->assertFalse($this->region->contains($key1)); $this->assertFalse($this->region->contains($key2)); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Cache/CacheKeyTest.php b/tests/Doctrine/Tests/ORM/Cache/CacheKeyTest.php index 39c28af1e35..63c86d7f1af 100644 --- a/tests/Doctrine/Tests/ORM/Cache/CacheKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/CacheKeyTest.php @@ -13,57 +13,57 @@ class CacheKeyTest extends DoctrineTestCase { public function testEntityCacheKeyIdentifierCollision() { - $key1 = new EntityCacheKey('Foo', array('id'=>1)); - $key2 = new EntityCacheKey('Bar', array('id'=>1)); + $key1 = new EntityCacheKey('Foo', ['id'=>1]); + $key2 = new EntityCacheKey('Bar', ['id'=>1]); $this->assertNotEquals($key1->hash, $key2->hash); } public function testEntityCacheKeyIdentifierType() { - $key1 = new EntityCacheKey('Foo', array('id'=>1)); - $key2 = new EntityCacheKey('Foo', array('id'=>'1')); + $key1 = new EntityCacheKey('Foo', ['id'=>1]); + $key2 = new EntityCacheKey('Foo', ['id'=>'1']); $this->assertEquals($key1->hash, $key2->hash); } public function testEntityCacheKeyIdentifierOrder() { - $key1 = new EntityCacheKey('Foo', array('foo_bar'=>1, 'bar_foo'=> 2)); - $key2 = new EntityCacheKey('Foo', array('bar_foo'=>2, 'foo_bar'=> 1)); + $key1 = new EntityCacheKey('Foo', ['foo_bar'=>1, 'bar_foo'=> 2]); + $key2 = new EntityCacheKey('Foo', ['bar_foo'=>2, 'foo_bar'=> 1]); $this->assertEquals($key1->hash, $key2->hash); } public function testCollectionCacheKeyIdentifierType() { - $key1 = new CollectionCacheKey('Foo', 'assoc', array('id'=>1)); - $key2 = new CollectionCacheKey('Foo', 'assoc', array('id'=>'1')); + $key1 = new CollectionCacheKey('Foo', 'assoc', ['id'=>1]); + $key2 = new CollectionCacheKey('Foo', 'assoc', ['id'=>'1']); $this->assertEquals($key1->hash, $key2->hash); } public function testCollectionCacheKeyIdentifierOrder() { - $key1 = new CollectionCacheKey('Foo', 'assoc', array('foo_bar'=>1, 'bar_foo'=> 2)); - $key2 = new CollectionCacheKey('Foo', 'assoc', array('bar_foo'=>2, 'foo_bar'=> 1)); + $key1 = new CollectionCacheKey('Foo', 'assoc', ['foo_bar'=>1, 'bar_foo'=> 2]); + $key2 = new CollectionCacheKey('Foo', 'assoc', ['bar_foo'=>2, 'foo_bar'=> 1]); $this->assertEquals($key1->hash, $key2->hash); } public function testCollectionCacheKeyIdentifierCollision() { - $key1 = new CollectionCacheKey('Foo', 'assoc', array('id'=>1)); - $key2 = new CollectionCacheKey('Bar', 'assoc', array('id'=>1)); + $key1 = new CollectionCacheKey('Foo', 'assoc', ['id'=>1]); + $key2 = new CollectionCacheKey('Bar', 'assoc', ['id'=>1]); $this->assertNotEquals($key1->hash, $key2->hash); } public function testCollectionCacheKeyAssociationCollision() { - $key1 = new CollectionCacheKey('Foo', 'assoc1', array('id'=>1)); - $key2 = new CollectionCacheKey('Foo', 'assoc2', array('id'=>1)); + $key1 = new CollectionCacheKey('Foo', 'assoc1', ['id'=>1]); + $key2 = new CollectionCacheKey('Foo', 'assoc2', ['id'=>1]); $this->assertNotEquals($key1->hash, $key2->hash); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Cache/CacheLoggerChainTest.php b/tests/Doctrine/Tests/ORM/Cache/CacheLoggerChainTest.php index 0af90cb072c..625b0586733 100644 --- a/tests/Doctrine/Tests/ORM/Cache/CacheLoggerChainTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/CacheLoggerChainTest.php @@ -42,13 +42,13 @@ public function testGetAndSetLogger() $this->logger->setLogger('mock', $this->mock); $this->assertSame($this->mock, $this->logger->getLogger('mock')); - $this->assertEquals(array('mock' => $this->mock), $this->logger->getLoggers()); + $this->assertEquals(['mock' => $this->mock], $this->logger->getLoggers()); } public function testEntityCacheChain() { $name = 'my_entity_region'; - $key = new EntityCacheKey(State::CLASSNAME, array('id' => 1)); + $key = new EntityCacheKey(State::CLASSNAME, ['id' => 1]); $this->logger->setLogger('mock', $this->mock); @@ -72,7 +72,7 @@ public function testEntityCacheChain() public function testCollectionCacheChain() { $name = 'my_collection_region'; - $key = new CollectionCacheKey(State::CLASSNAME, 'cities', array('id' => 1)); + $key = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id' => 1]); $this->logger->setLogger('mock', $this->mock); @@ -116,4 +116,4 @@ public function testQueryCacheChain() $this->logger->queryCachePut($name, $key); $this->logger->queryCacheMiss($name, $key); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php index 40c997d4217..a948676d79d 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php @@ -40,9 +40,9 @@ protected function setUp() $this->em = $this->_getTestEntityManager(); $this->regionsConfig = new RegionsConfiguration; - $arguments = array($this->regionsConfig, $this->getSharedSecondLevelCacheDriverImpl()); + $arguments = [$this->regionsConfig, $this->getSharedSecondLevelCacheDriverImpl()]; $this->factory = $this->getMockBuilder(DefaultCacheFactory::class) - ->setMethods(array('getRegion')) + ->setMethods(['getRegion']) ->setConstructorArgs($arguments) ->getMock(); } @@ -261,24 +261,30 @@ public function testInvalidFileLockRegionDirectoryException() { $factory = new DefaultCacheFactory($this->regionsConfig, $this->getSharedSecondLevelCacheDriverImpl()); - $factory->getRegion(array( + $factory->getRegion( + [ 'usage' => ClassMetadata::CACHE_USAGE_READ_WRITE, 'region' => 'foo' - )); + ] + ); } public function testBuildsNewNamespacedCacheInstancePerRegionInstance() { $factory = new DefaultCacheFactory($this->regionsConfig, $this->getSharedSecondLevelCacheDriverImpl()); - $fooRegion = $factory->getRegion(array( + $fooRegion = $factory->getRegion( + [ 'region' => 'foo', 'usage' => ClassMetadata::CACHE_USAGE_READ_ONLY, - )); - $barRegion = $factory->getRegion(array( + ] + ); + $barRegion = $factory->getRegion( + [ 'region' => 'bar', 'usage' => ClassMetadata::CACHE_USAGE_READ_ONLY, - )); + ] + ); $this->assertSame('foo', $fooRegion->getCache()->getNamespace()); $this->assertSame('bar', $barRegion->getCache()->getNamespace()); @@ -293,10 +299,12 @@ public function testBuildsDefaultCacheRegionFromGenericCacheRegion() $this->assertInstanceOf( 'Doctrine\ORM\Cache\Region\DefaultRegion', - $factory->getRegion(array( + $factory->getRegion( + [ 'region' => 'bar', 'usage' => ClassMetadata::CACHE_USAGE_READ_ONLY, - )) + ] + ) ); } @@ -309,10 +317,12 @@ public function testBuildsMultiGetCacheRegionFromGenericCacheRegion() $this->assertInstanceOf( 'Doctrine\ORM\Cache\Region\DefaultMultiGetRegion', - $factory->getRegion(array( + $factory->getRegion( + [ 'region' => 'bar', 'usage' => ClassMetadata::CACHE_USAGE_READ_ONLY, - )) + ] + ) ); } diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheTest.php index c33d0839b92..866153fbbec 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheTest.php @@ -72,7 +72,7 @@ public function testImplementsCache() { $this->assertInstanceOf('Doctrine\ORM\Cache', $this->cache); } - + public function testGetEntityCacheRegionAccess() { $this->assertInstanceOf('Doctrine\ORM\Cache\Region', $this->cache->getEntityCacheRegion(State::CLASSNAME)); @@ -87,9 +87,9 @@ public function testGetCollectionCacheRegionAccess() public function testContainsEntity() { - $identifier = array('id'=>1); + $identifier = ['id'=>1]; $className = Country::CLASSNAME; - $cacheEntry = array_merge($identifier, array('name' => 'Brazil')); + $cacheEntry = array_merge($identifier, ['name' => 'Brazil']); $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, 1)); @@ -101,9 +101,9 @@ public function testContainsEntity() public function testEvictEntity() { - $identifier = array('id'=>1); + $identifier = ['id'=>1]; $className = Country::CLASSNAME; - $cacheEntry = array_merge($identifier, array('name' => 'Brazil')); + $cacheEntry = array_merge($identifier, ['name' => 'Brazil']); $this->putEntityCacheEntry($className, $identifier, $cacheEntry); @@ -117,9 +117,9 @@ public function testEvictEntity() public function testEvictEntityRegion() { - $identifier = array('id'=>1); + $identifier = ['id'=>1]; $className = Country::CLASSNAME; - $cacheEntry = array_merge($identifier, array('name' => 'Brazil')); + $cacheEntry = array_merge($identifier, ['name' => 'Brazil']); $this->putEntityCacheEntry($className, $identifier, $cacheEntry); @@ -133,9 +133,9 @@ public function testEvictEntityRegion() public function testEvictEntityRegions() { - $identifier = array('id'=>1); + $identifier = ['id'=>1]; $className = Country::CLASSNAME; - $cacheEntry = array_merge($identifier, array('name' => 'Brazil')); + $cacheEntry = array_merge($identifier, ['name' => 'Brazil']); $this->putEntityCacheEntry($className, $identifier, $cacheEntry); @@ -148,13 +148,13 @@ public function testEvictEntityRegions() public function testContainsCollection() { - $ownerId = array('id'=>1); + $ownerId = ['id'=>1]; $className = State::CLASSNAME; $association = 'cities'; - $cacheEntry = array( - array('id' => 11), - array('id' => 12), - ); + $cacheEntry = [ + ['id' => 11], + ['id' => 12], + ]; $this->assertFalse($this->cache->containsCollection(State::CLASSNAME, $association, 1)); @@ -166,13 +166,13 @@ public function testContainsCollection() public function testEvictCollection() { - $ownerId = array('id'=>1); + $ownerId = ['id'=>1]; $className = State::CLASSNAME; $association = 'cities'; - $cacheEntry = array( - array('id' => 11), - array('id' => 12), - ); + $cacheEntry = [ + ['id' => 11], + ['id' => 12], + ]; $this->putCollectionCacheEntry($className, $association, $ownerId, $cacheEntry); @@ -186,13 +186,13 @@ public function testEvictCollection() public function testEvictCollectionRegion() { - $ownerId = array('id'=>1); + $ownerId = ['id'=>1]; $className = State::CLASSNAME; $association = 'cities'; - $cacheEntry = array( - array('id' => 11), - array('id' => 12), - ); + $cacheEntry = [ + ['id' => 11], + ['id' => 12], + ]; $this->putCollectionCacheEntry($className, $association, $ownerId, $cacheEntry); @@ -206,13 +206,13 @@ public function testEvictCollectionRegion() public function testEvictCollectionRegions() { - $ownerId = array('id'=>1); + $ownerId = ['id'=>1]; $className = State::CLASSNAME; $association = 'cities'; - $cacheEntry = array( - array('id' => 11), - array('id' => 12), - ); + $cacheEntry = [ + ['id' => 11], + ['id' => 12], + ]; $this->putCollectionCacheEntry($className, $association, $ownerId, $cacheEntry); @@ -257,7 +257,7 @@ public function testToIdentifierArrayShouldLookupForEntityIdentifier() $method->setAccessible(true); $property->setValue($entity, $identifier); - $this->assertEquals(array('id'=>$identifier), $method->invoke($this->cache, $metadata, $identifier)); + $this->assertEquals(['id'=>$identifier], $method->invoke($this->cache, $metadata, $identifier)); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultCollectionHydratorTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultCollectionHydratorTest.php index ed0456e3908..e3c4d785bf5 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultCollectionHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultCollectionHydratorTest.php @@ -41,17 +41,21 @@ public function testImplementsCollectionEntryStructure() public function testLoadCacheCollection() { $targetRegion = $this->_em->getCache()->getEntityCacheRegion(City::CLASSNAME); - $entry = new CollectionCacheEntry(array( - new EntityCacheKey(City::CLASSNAME, array('id'=>31)), - new EntityCacheKey(City::CLASSNAME, array('id'=>32)), - )); + $entry = new CollectionCacheEntry( + [ + new EntityCacheKey(City::CLASSNAME, ['id'=>31]), + new EntityCacheKey(City::CLASSNAME, ['id'=>32]), + ] + ); - $targetRegion->put(new EntityCacheKey(City::CLASSNAME, array('id'=>31)), new EntityCacheEntry(City::CLASSNAME, array('id'=>31, 'name'=>'Foo'))); - $targetRegion->put(new EntityCacheKey(City::CLASSNAME, array('id'=>32)), new EntityCacheEntry(City::CLASSNAME, array('id'=>32, 'name'=>'Bar'))); + $targetRegion->put(new EntityCacheKey(City::CLASSNAME, ['id'=>31]), new EntityCacheEntry(City::CLASSNAME, ['id'=>31, 'name'=>'Foo'] + )); + $targetRegion->put(new EntityCacheKey(City::CLASSNAME, ['id'=>32]), new EntityCacheEntry(City::CLASSNAME, ['id'=>32, 'name'=>'Bar'] + )); $sourceClass = $this->_em->getClassMetadata(State::CLASSNAME); $targetClass = $this->_em->getClassMetadata(City::CLASSNAME); - $key = new CollectionCacheKey($sourceClass->name, 'cities', array('id'=>21)); + $key = new CollectionCacheKey($sourceClass->name, 'cities', ['id'=>21]); $collection = new PersistentCollection($this->_em, $targetClass, new ArrayCollection()); $list = $this->structure->loadCacheEntry($sourceClass, $key, $entry, $collection); @@ -75,4 +79,4 @@ public function testLoadCacheCollection() $this->assertEquals(UnitOfWork::STATE_MANAGED, $this->_em->getUnitOfWork()->getEntityState($collection[1])); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultEntityHydratorTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultEntityHydratorTest.php index 73878ee46d9..e7fdb617b7a 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultEntityHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultEntityHydratorTest.php @@ -43,8 +43,8 @@ public function testImplementsEntityEntryStructure() public function testCreateEntity() { $metadata = $this->em->getClassMetadata(Country::CLASSNAME); - $key = new EntityCacheKey($metadata->name, array('id'=>1)); - $entry = new EntityCacheEntry($metadata->name, array('id'=>1, 'name'=>'Foo')); + $key = new EntityCacheKey($metadata->name, ['id'=>1]); + $entry = new EntityCacheEntry($metadata->name, ['id'=>1, 'name'=>'Foo']); $entity = $this->structure->loadCacheEntry($metadata, $key, $entry); $this->assertInstanceOf($metadata->name, $entity); @@ -57,8 +57,8 @@ public function testCreateEntity() public function testLoadProxy() { $metadata = $this->em->getClassMetadata(Country::CLASSNAME); - $key = new EntityCacheKey($metadata->name, array('id'=>1)); - $entry = new EntityCacheEntry($metadata->name, array('id'=>1, 'name'=>'Foo')); + $key = new EntityCacheKey($metadata->name, ['id'=>1]); + $entry = new EntityCacheEntry($metadata->name, ['id'=>1, 'name'=>'Foo']); $proxy = $this->em->getReference($metadata->name, $key->identifier); $entity = $this->structure->loadCacheEntry($metadata, $key, $entry, $proxy); @@ -74,9 +74,9 @@ public function testBuildCacheEntry() { $entity = new Country('Foo'); $uow = $this->em->getUnitOfWork(); - $data = array('id'=>1, 'name'=>'Foo'); + $data = ['id'=>1, 'name'=>'Foo']; $metadata = $this->em->getClassMetadata(Country::CLASSNAME); - $key = new EntityCacheKey($metadata->name, array('id'=>1)); + $key = new EntityCacheKey($metadata->name, ['id'=>1]); $entity->setId(1); $uow->registerManaged($entity, $key->identifier, $data); @@ -88,10 +88,11 @@ public function testBuildCacheEntry() $this->assertArrayHasKey('id', $cache->data); $this->assertArrayHasKey('name', $cache->data); - $this->assertEquals(array( + $this->assertEquals( + [ 'id' => 1, 'name' => 'Foo', - ), $cache->data); + ], $cache->data); } public function testBuildCacheEntryAssociation() @@ -99,16 +100,16 @@ public function testBuildCacheEntryAssociation() $country = new Country('Foo'); $state = new State('Bat', $country); $uow = $this->em->getUnitOfWork(); - $countryData = array('id'=>11, 'name'=>'Foo'); - $stateData = array('id'=>12, 'name'=>'Bar', 'country' => $country); + $countryData = ['id'=>11, 'name'=>'Foo']; + $stateData = ['id'=>12, 'name'=>'Bar', 'country' => $country]; $metadata = $this->em->getClassMetadata(State::CLASSNAME); - $key = new EntityCacheKey($metadata->name, array('id'=>11)); + $key = new EntityCacheKey($metadata->name, ['id'=>11]); $country->setId(11); $state->setId(12); - $uow->registerManaged($country, array('id'=>11), $countryData); - $uow->registerManaged($state, array('id'=>12), $stateData); + $uow->registerManaged($country, ['id'=>11], $countryData); + $uow->registerManaged($state, ['id'=>12], $stateData); $cache = $this->structure->buildCacheEntry($metadata, $key, $state); @@ -118,11 +119,12 @@ public function testBuildCacheEntryAssociation() $this->assertArrayHasKey('id', $cache->data); $this->assertArrayHasKey('name', $cache->data); $this->assertArrayHasKey('country', $cache->data); - $this->assertEquals(array( + $this->assertEquals( + [ 'id' => 12, 'name' => 'Bar', - 'country' => new AssociationCacheEntry(Country::CLASSNAME, array('id' => 11)), - ), $cache->data); + 'country' => new AssociationCacheEntry(Country::CLASSNAME, ['id' => 11]), + ], $cache->data); } public function testBuildCacheEntryNonInitializedAssocProxy() @@ -130,13 +132,13 @@ public function testBuildCacheEntryNonInitializedAssocProxy() $proxy = $this->em->getReference(Country::CLASSNAME, 11); $entity = new State('Bat', $proxy); $uow = $this->em->getUnitOfWork(); - $entityData = array('id'=>12, 'name'=>'Bar', 'country' => $proxy); + $entityData = ['id'=>12, 'name'=>'Bar', 'country' => $proxy]; $metadata = $this->em->getClassMetadata(State::CLASSNAME); - $key = new EntityCacheKey($metadata->name, array('id'=>11)); + $key = new EntityCacheKey($metadata->name, ['id'=>11]); $entity->setId(12); - $uow->registerManaged($entity, array('id'=>12), $entityData); + $uow->registerManaged($entity, ['id'=>12], $entityData); $cache = $this->structure->buildCacheEntry($metadata, $key, $entity); @@ -146,11 +148,12 @@ public function testBuildCacheEntryNonInitializedAssocProxy() $this->assertArrayHasKey('id', $cache->data); $this->assertArrayHasKey('name', $cache->data); $this->assertArrayHasKey('country', $cache->data); - $this->assertEquals(array( + $this->assertEquals( + [ 'id' => 12, 'name' => 'Bar', - 'country' => new AssociationCacheEntry(Country::CLASSNAME, array('id' => 11)), - ), $cache->data); + 'country' => new AssociationCacheEntry(Country::CLASSNAME, ['id' => 11]), + ], $cache->data); } public function testCacheEntryWithWrongIdentifierType() @@ -158,13 +161,13 @@ public function testCacheEntryWithWrongIdentifierType() $proxy = $this->em->getReference(Country::CLASSNAME, 11); $entity = new State('Bat', $proxy); $uow = $this->em->getUnitOfWork(); - $entityData = array('id'=> 12, 'name'=>'Bar', 'country' => $proxy); + $entityData = ['id'=> 12, 'name'=>'Bar', 'country' => $proxy]; $metadata = $this->em->getClassMetadata(State::CLASSNAME); - $key = new EntityCacheKey($metadata->name, array('id'=>'12')); + $key = new EntityCacheKey($metadata->name, ['id'=>'12']); $entity->setId(12); - $uow->registerManaged($entity, array('id'=>12), $entityData); + $uow->registerManaged($entity, ['id'=>12], $entityData); $cache = $this->structure->buildCacheEntry($metadata, $key, $entity); @@ -175,11 +178,12 @@ public function testCacheEntryWithWrongIdentifierType() $this->assertArrayHasKey('name', $cache->data); $this->assertArrayHasKey('country', $cache->data); $this->assertSame($entity->getId(), $cache->data['id']); - $this->assertEquals(array( + $this->assertEquals( + [ 'id' => 12, 'name' => 'Bar', - 'country' => new AssociationCacheEntry(Country::CLASSNAME, array('id' => 11)), - ), $cache->data); + 'country' => new AssociationCacheEntry(Country::CLASSNAME, ['id' => 11]), + ], $cache->data); } } diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php index 8fa09bac646..f9b11bee8d3 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php @@ -79,7 +79,7 @@ public function testClearShouldEvictRegion() public function testPutBasicQueryResult() { - $result = array(); + $result = []; $key = new QueryCacheKey('query.key1', 0); $rsm = new ResultSetMappingBuilder($this->em); $metadata = $this->em->getClassMetadata(Country::CLASSNAME); @@ -92,7 +92,7 @@ public function testPutBasicQueryResult() $result[] = $entity; $metadata->setFieldValue($entity, 'id', $i); - $this->em->getUnitOfWork()->registerManaged($entity, array('id' => $i), array('name' => $name)); + $this->em->getUnitOfWork()->registerManaged($entity, ['id' => $i], ['name' => $name]); } $this->assertTrue($this->queryCache->put($key, $rsm, $result)); @@ -114,7 +114,7 @@ public function testPutBasicQueryResult() public function testPutToOneAssociationQueryResult() { - $result = array(); + $result = []; $uow = $this->em->getUnitOfWork(); $key = new QueryCacheKey('query.key1', 0); $rsm = new ResultSetMappingBuilder($this->em); @@ -122,7 +122,8 @@ public function testPutToOneAssociationQueryResult() $stateClass = $this->em->getClassMetadata(State::CLASSNAME); $rsm->addRootEntityFromClassMetadata(City::CLASSNAME, 'c'); - $rsm->addJoinedEntityFromClassMetadata(State::CLASSNAME, 's', 'c', 'state', array('id'=>'state_id', 'name'=>'state_name')); + $rsm->addJoinedEntityFromClassMetadata(State::CLASSNAME, 's', 'c', 'state', ['id'=>'state_id', 'name'=>'state_name'] + ); for ($i = 0; $i < 4; $i++) { $state = new State("State $i"); @@ -132,8 +133,8 @@ public function testPutToOneAssociationQueryResult() $cityClass->setFieldValue($city, 'id', $i); $stateClass->setFieldValue($state, 'id', $i*2); - $uow->registerManaged($state, array('id' => $state->getId()), array('name' => $city->getName())); - $uow->registerManaged($city, array('id' => $city->getId()), array('name' => $city->getName(), 'state' => $state)); + $uow->registerManaged($state, ['id' => $state->getId()], ['name' => $city->getName()]); + $uow->registerManaged($city, ['id' => $city->getId()], ['name' => $city->getName(), 'state' => $state]); } $this->assertTrue($this->queryCache->put($key, $rsm, $result)); @@ -153,7 +154,7 @@ public function testPutToOneAssociationQueryResult() public function testPutToOneAssociation2LevelsQueryResult() { - $result = array(); + $result = []; $uow = $this->em->getUnitOfWork(); $key = new QueryCacheKey('query.key1', 0); $rsm = new ResultSetMappingBuilder($this->em); @@ -162,8 +163,10 @@ public function testPutToOneAssociation2LevelsQueryResult() $countryClass = $this->em->getClassMetadata(Country::CLASSNAME); $rsm->addRootEntityFromClassMetadata(City::CLASSNAME, 'c'); - $rsm->addJoinedEntityFromClassMetadata(State::CLASSNAME, 's', 'c', 'state', array('id'=>'state_id', 'name'=>'state_name')); - $rsm->addJoinedEntityFromClassMetadata(Country::CLASSNAME, 'co', 's', 'country', array('id'=>'country_id', 'name'=>'country_name')); + $rsm->addJoinedEntityFromClassMetadata(State::CLASSNAME, 's', 'c', 'state', ['id'=>'state_id', 'name'=>'state_name'] + ); + $rsm->addJoinedEntityFromClassMetadata(Country::CLASSNAME, 'co', 's', 'country', ['id'=>'country_id', 'name'=>'country_name'] + ); for ($i = 0; $i < 4; $i++) { $country = new Country("Country $i"); @@ -176,9 +179,10 @@ public function testPutToOneAssociation2LevelsQueryResult() $stateClass->setFieldValue($state, 'id', $i*2); $countryClass->setFieldValue($country, 'id', $i*3); - $uow->registerManaged($country, array('id' => $country->getId()), array('name' => $country->getName())); - $uow->registerManaged($state, array('id' => $state->getId()), array('name' => $state->getName(), 'country' => $country)); - $uow->registerManaged($city, array('id' => $city->getId()), array('name' => $city->getName(), 'state' => $state)); + $uow->registerManaged($country, ['id' => $country->getId()], ['name' => $country->getName()]); + $uow->registerManaged($state, ['id' => $state->getId()], ['name' => $state->getName(), 'country' => $country] + ); + $uow->registerManaged($city, ['id' => $city->getId()], ['name' => $city->getName(), 'state' => $state]); } $this->assertTrue($this->queryCache->put($key, $rsm, $result)); @@ -202,14 +206,15 @@ public function testPutToOneAssociation2LevelsQueryResult() public function testPutToOneAssociationNullQueryResult() { - $result = array(); + $result = []; $uow = $this->em->getUnitOfWork(); $key = new QueryCacheKey('query.key1', 0); $rsm = new ResultSetMappingBuilder($this->em); $cityClass = $this->em->getClassMetadata(City::CLASSNAME); $rsm->addRootEntityFromClassMetadata(City::CLASSNAME, 'c'); - $rsm->addJoinedEntityFromClassMetadata(State::CLASSNAME, 's', 'c', 'state', array('id'=>'state_id', 'name'=>'state_name')); + $rsm->addJoinedEntityFromClassMetadata(State::CLASSNAME, 's', 'c', 'state', ['id'=>'state_id', 'name'=>'state_name'] + ); for ($i = 0; $i < 4; $i++) { $city = new City("City $i", null); @@ -217,7 +222,7 @@ public function testPutToOneAssociationNullQueryResult() $cityClass->setFieldValue($city, 'id', $i); - $uow->registerManaged($city, array('id' => $city->getId()), array('name' => $city->getName(), 'state' => null)); + $uow->registerManaged($city, ['id' => $city->getId()], ['name' => $city->getName(), 'state' => null]); } $this->assertTrue($this->queryCache->put($key, $rsm, $result)); @@ -233,7 +238,7 @@ public function testPutToOneAssociationNullQueryResult() public function testPutToManyAssociationQueryResult() { - $result = array(); + $result = []; $uow = $this->em->getUnitOfWork(); $key = new QueryCacheKey('query.key1', 0); $rsm = new ResultSetMappingBuilder($this->em); @@ -241,7 +246,7 @@ public function testPutToManyAssociationQueryResult() $stateClass = $this->em->getClassMetadata(State::CLASSNAME); $rsm->addRootEntityFromClassMetadata(State::CLASSNAME, 's'); - $rsm->addJoinedEntityFromClassMetadata(City::CLASSNAME, 'c', 's', 'cities', array('id'=>'c_id', 'name'=>'c_name')); + $rsm->addJoinedEntityFromClassMetadata(City::CLASSNAME, 'c', 's', 'cities', ['id'=>'c_id', 'name'=>'c_name']); for ($i = 0; $i < 4; $i++) { $state = new State("State $i"); @@ -256,9 +261,12 @@ public function testPutToManyAssociationQueryResult() $state->addCity($city1); $state->addCity($city2); - $uow->registerManaged($city1, array('id' => $city1->getId()), array('name' => $city1->getName(), 'state' => $state)); - $uow->registerManaged($city2, array('id' => $city2->getId()), array('name' => $city2->getName(), 'state' => $state)); - $uow->registerManaged($state, array('id' => $state->getId()), array('name' => $state->getName(), 'cities' => $state->getCities())); + $uow->registerManaged($city1, ['id' => $city1->getId()], ['name' => $city1->getName(), 'state' => $state] + ); + $uow->registerManaged($city2, ['id' => $city2->getId()], ['name' => $city2->getName(), 'state' => $state] + ); + $uow->registerManaged($state, ['id' => $state->getId()], ['name' => $state->getName(), 'cities' => $state->getCities()] + ); } $this->assertTrue($this->queryCache->put($key, $rsm, $result)); @@ -270,16 +278,18 @@ public function testGetBasicQueryResult() { $rsm = new ResultSetMappingBuilder($this->em); $key = new QueryCacheKey('query.key1', 0); - $entry = new QueryCacheEntry(array( - array('identifier' => array('id' => 1)), - array('identifier' => array('id' => 2)) - )); - - $data = array( - array('id'=>1, 'name' => 'Foo'), - array('id'=>2, 'name' => 'Bar') + $entry = new QueryCacheEntry( + [ + ['identifier' => ['id' => 1]], + ['identifier' => ['id' => 2]] + ] ); + $data = [ + ['id'=>1, 'name' => 'Foo'], + ['id'=>2, 'name' => 'Bar'] + ]; + $this->region->addReturn('get', $entry); $this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $data[0])); $this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $data[1])); @@ -299,7 +309,7 @@ public function testGetBasicQueryResult() public function testCancelPutResultIfEntityPutFails() { - $result = array(); + $result = []; $key = new QueryCacheKey('query.key1', 0); $rsm = new ResultSetMappingBuilder($this->em); $metadata = $this->em->getClassMetadata(Country::CLASSNAME); @@ -312,7 +322,7 @@ public function testCancelPutResultIfEntityPutFails() $result[] = $entity; $metadata->setFieldValue($entity, 'id', $i); - $this->em->getUnitOfWork()->registerManaged($entity, array('id' => $i), array('name' => $name)); + $this->em->getUnitOfWork()->registerManaged($entity, ['id' => $i], ['name' => $name]); } $this->region->addReturn('put', false); @@ -324,7 +334,7 @@ public function testCancelPutResultIfEntityPutFails() public function testCancelPutResultIfAssociationEntityPutFails() { - $result = array(); + $result = []; $uow = $this->em->getUnitOfWork(); $key = new QueryCacheKey('query.key1', 0); $rsm = new ResultSetMappingBuilder($this->em); @@ -332,7 +342,8 @@ public function testCancelPutResultIfAssociationEntityPutFails() $stateClass = $this->em->getClassMetadata(State::CLASSNAME); $rsm->addRootEntityFromClassMetadata(City::CLASSNAME, 'c'); - $rsm->addJoinedEntityFromClassMetadata(State::CLASSNAME, 's', 'c', 'state', array('id'=>'state_id', 'name'=>'state_name')); + $rsm->addJoinedEntityFromClassMetadata(State::CLASSNAME, 's', 'c', 'state', ['id'=>'state_id', 'name'=>'state_name'] + ); $state = new State("State 1"); $city = new City("City 2", $state); @@ -341,8 +352,8 @@ public function testCancelPutResultIfAssociationEntityPutFails() $cityClass->setFieldValue($city, 'id', 1); $stateClass->setFieldValue($state, 'id', 11); - $uow->registerManaged($state, array('id' => $state->getId()), array('name' => $city->getName())); - $uow->registerManaged($city, array('id' => $city->getId()), array('name' => $city->getName(), 'state' => $state)); + $uow->registerManaged($state, ['id' => $state->getId()], ['name' => $city->getName()]); + $uow->registerManaged($city, ['id' => $city->getId()], ['name' => $city->getName(), 'state' => $state]); $this->region->addReturn('put', true); // put root entity $this->region->addReturn('put', false); // association fails @@ -352,7 +363,7 @@ public function testCancelPutResultIfAssociationEntityPutFails() public function testCancelPutToManyAssociationQueryResult() { - $result = array(); + $result = []; $uow = $this->em->getUnitOfWork(); $key = new QueryCacheKey('query.key1', 0); $rsm = new ResultSetMappingBuilder($this->em); @@ -360,7 +371,7 @@ public function testCancelPutToManyAssociationQueryResult() $stateClass = $this->em->getClassMetadata(State::CLASSNAME); $rsm->addRootEntityFromClassMetadata(State::CLASSNAME, 's'); - $rsm->addJoinedEntityFromClassMetadata(City::CLASSNAME, 'c', 's', 'cities', array('id'=>'c_id', 'name'=>'c_name')); + $rsm->addJoinedEntityFromClassMetadata(City::CLASSNAME, 'c', 's', 'cities', ['id'=>'c_id', 'name'=>'c_name']); $state = new State("State"); $city1 = new City("City 1", $state); @@ -374,9 +385,10 @@ public function testCancelPutToManyAssociationQueryResult() $state->addCity($city1); $state->addCity($city2); - $uow->registerManaged($city1, array('id' => $city1->getId()), array('name' => $city1->getName(), 'state' => $state)); - $uow->registerManaged($city2, array('id' => $city2->getId()), array('name' => $city2->getName(), 'state' => $state)); - $uow->registerManaged($state, array('id' => $state->getId()), array('name' => $state->getName(), 'cities' => $state->getCities())); + $uow->registerManaged($city1, ['id' => $city1->getId()], ['name' => $city1->getName(), 'state' => $state]); + $uow->registerManaged($city2, ['id' => $city2->getId()], ['name' => $city2->getName(), 'state' => $state]); + $uow->registerManaged($state, ['id' => $state->getId()], ['name' => $state->getName(), 'cities' => $state->getCities()] + ); $this->region->addReturn('put', true); // put root entity $this->region->addReturn('put', false); // collection association fails @@ -390,10 +402,12 @@ public function testIgnoreCacheNonGetMode() { $rsm = new ResultSetMappingBuilder($this->em); $key = new QueryCacheKey('query.key1', 0, Cache::MODE_PUT); - $entry = new QueryCacheEntry(array( - array('identifier' => array('id' => 1)), - array('identifier' => array('id' => 2)) - )); + $entry = new QueryCacheEntry( + [ + ['identifier' => ['id' => 1]], + ['identifier' => ['id' => 2]] + ] + ); $rsm->addRootEntityFromClassMetadata(Country::CLASSNAME, 'c'); @@ -404,7 +418,7 @@ public function testIgnoreCacheNonGetMode() public function testIgnoreCacheNonPutMode() { - $result = array(); + $result = []; $rsm = new ResultSetMappingBuilder($this->em); $metadata = $this->em->getClassMetadata(Country::CLASSNAME); $key = new QueryCacheKey('query.key1', 0, Cache::MODE_GET); @@ -417,7 +431,7 @@ public function testIgnoreCacheNonPutMode() $result[] = $entity; $metadata->setFieldValue($entity, 'id', $i); - $this->em->getUnitOfWork()->registerManaged($entity, array('id' => $i), array('name' => $name)); + $this->em->getUnitOfWork()->registerManaged($entity, ['id' => $i], ['name' => $name]); } $this->assertFalse($this->queryCache->put($key, $rsm, $result)); @@ -427,14 +441,16 @@ public function testGetShouldIgnoreOldQueryCacheEntryResult() { $rsm = new ResultSetMappingBuilder($this->em); $key = new QueryCacheKey('query.key1', 50); - $entry = new QueryCacheEntry(array( - array('identifier' => array('id' => 1)), - array('identifier' => array('id' => 2)) - )); - $entities = array( - array('id'=>1, 'name' => 'Foo'), - array('id'=>2, 'name' => 'Bar') + $entry = new QueryCacheEntry( + [ + ['identifier' => ['id' => 1]], + ['identifier' => ['id' => 2]] + ] ); + $entities = [ + ['id'=>1, 'name' => 'Foo'], + ['id'=>2, 'name' => 'Bar'] + ]; $entry->time = microtime(true) - 100; @@ -451,16 +467,18 @@ public function testGetShouldIgnoreNonQueryCacheEntryResult() { $rsm = new ResultSetMappingBuilder($this->em); $key = new QueryCacheKey('query.key1', 0); - $entry = new \ArrayObject(array( - array('identifier' => array('id' => 1)), - array('identifier' => array('id' => 2)) - )); - - $data = array( - array('id'=>1, 'name' => 'Foo'), - array('id'=>2, 'name' => 'Bar') + $entry = new \ArrayObject( + [ + ['identifier' => ['id' => 1]], + ['identifier' => ['id' => 2]] + ] ); + $data = [ + ['id'=>1, 'name' => 'Foo'], + ['id'=>2, 'name' => 'Bar'] + ]; + $this->region->addReturn('get', $entry); $this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $data[0])); $this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $data[1])); @@ -474,10 +492,12 @@ public function testGetShouldIgnoreMissingEntityQueryCacheEntry() { $rsm = new ResultSetMappingBuilder($this->em); $key = new QueryCacheKey('query.key1', 0); - $entry = new QueryCacheEntry(array( - array('identifier' => array('id' => 1)), - array('identifier' => array('id' => 2)) - )); + $entry = new QueryCacheEntry( + [ + ['identifier' => ['id' => 1]], + ['identifier' => ['id' => 2]] + ] + ); $this->region->addReturn('get', $entry); $this->region->addReturn('get', null); @@ -508,14 +528,16 @@ public function testGetAssociationValue() $wurzburg->addAttraction(new Restaurant('Fischers Fritz', $wurzburg)); $rsm->addRootEntityFromClassMetadata(State::CLASSNAME, 's'); - $rsm->addJoinedEntityFromClassMetadata(City::CLASSNAME, 'c', 's', 'cities', array( + $rsm->addJoinedEntityFromClassMetadata(City::CLASSNAME, 'c', 's', 'cities', [ 'id' => 'c_id', 'name' => 'c_name' - )); - $rsm->addJoinedEntityFromClassMetadata(Restaurant::CLASSNAME, 'a', 'c', 'attractions', array( + ] + ); + $rsm->addJoinedEntityFromClassMetadata(Restaurant::CLASSNAME, 'a', 'c', 'attractions', [ 'id' => 'a_id', 'name' => 'a_name' - )); + ] + ); $cities = $reflection->invoke($this->queryCache, $rsm, 'c', $bavaria); $attractions = $reflection->invoke($this->queryCache, $rsm, 'a', $bavaria); @@ -537,7 +559,7 @@ public function testGetAssociationValue() */ public function testScalarResultException() { - $result = array(); + $result = []; $key = new QueryCacheKey('query.key1', 0); $rsm = new ResultSetMappingBuilder($this->em); @@ -552,7 +574,7 @@ public function testScalarResultException() */ public function testSupportMultipleRootEntitiesException() { - $result = array(); + $result = []; $key = new QueryCacheKey('query.key1', 0); $rsm = new ResultSetMappingBuilder($this->em); @@ -568,7 +590,7 @@ public function testSupportMultipleRootEntitiesException() */ public function testNotCacheableEntityException() { - $result = array(); + $result = []; $key = new QueryCacheKey('query.key1', 0); $rsm = new ResultSetMappingBuilder($this->em); $className = 'Doctrine\Tests\Models\Generic\BooleanModel'; @@ -583,7 +605,7 @@ public function testNotCacheableEntityException() $entity->booleanField = $boolean; $result[] = $entity; - $this->em->getUnitOfWork()->registerManaged($entity, array('id' => $i), array('booleanField' => $boolean)); + $this->em->getUnitOfWork()->registerManaged($entity, ['id' => $i], ['booleanField' => $boolean]); } $this->assertFalse($this->queryCache->put($key, $rsm, $result)); diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultRegionTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultRegionTest.php index 2bcc1fc21f2..5faed3c9e2c 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultRegionTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultRegionTest.php @@ -33,7 +33,7 @@ public function testSharedRegion() } $key = new CacheKeyMock('key'); - $entry = new CacheEntryMock(array('value' => 'foo')); + $entry = new CacheEntryMock(['value' => 'foo']); $region1 = new DefaultRegion('region1', new ApcCache()); $region2 = new DefaultRegion('region2', new ApcCache()); @@ -79,10 +79,10 @@ public function testEvictAllWithGenericCacheThrowsUnsupportedException() public function testGetMulti() { $key1 = new CacheKeyMock('key.1'); - $value1 = new CacheEntryMock(array('id' => 1, 'name' => 'bar')); + $value1 = new CacheEntryMock(['id' => 1, 'name' => 'bar']); $key2 = new CacheKeyMock('key.2'); - $value2 = new CacheEntryMock(array('id' => 2, 'name' => 'bar')); + $value2 = new CacheEntryMock(['id' => 2, 'name' => 'bar']); $this->assertFalse($this->region->contains($key1)); $this->assertFalse($this->region->contains($key2)); @@ -93,9 +93,9 @@ public function testGetMulti() $this->assertTrue($this->region->contains($key1)); $this->assertTrue($this->region->contains($key2)); - $actual = $this->region->getMultiple(new CollectionCacheEntry(array($key1, $key2))); + $actual = $this->region->getMultiple(new CollectionCacheEntry([$key1, $key2])); $this->assertEquals($value1, $actual[0]); $this->assertEquals($value2, $actual[1]); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Cache/FileLockRegionTest.php b/tests/Doctrine/Tests/ORM/Cache/FileLockRegionTest.php index 6fdef6feafb..5bb771ce756 100644 --- a/tests/Doctrine/Tests/ORM/Cache/FileLockRegionTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/FileLockRegionTest.php @@ -21,7 +21,7 @@ class FileLockRegionTest extends AbstractRegionTest * @var \Doctrine\ORM\Cache\ConcurrentRegion */ protected $region; - + /** * @var string */ @@ -67,7 +67,7 @@ public function testGetRegionName() public function testLockAndUnlock() { $key = new CacheKeyMock('key'); - $entry = new CacheEntryMock(array('foo' => 'bar')); + $entry = new CacheEntryMock(['foo' => 'bar']); $file = $this->getFileName($this->region, $key); $this->assertFalse($this->region->contains($key)); @@ -91,7 +91,7 @@ public function testLockAndUnlock() public function testLockWithExistingLock() { $key = new CacheKeyMock('key'); - $entry = new CacheEntryMock(array('foo' => 'bar')); + $entry = new CacheEntryMock(['foo' => 'bar']); $file = $this->getFileName($this->region, $key); $this->assertFalse($this->region->contains($key)); @@ -114,7 +114,7 @@ public function testLockWithExistingLock() public function testUnlockWithExistingLock() { $key = new CacheKeyMock('key'); - $entry = new CacheEntryMock(array('foo' => 'bar')); + $entry = new CacheEntryMock(['foo' => 'bar']); $file = $this->getFileName($this->region, $key); $this->assertFalse($this->region->contains($key)); @@ -143,7 +143,7 @@ public function testUnlockWithExistingLock() public function testPutWithExistingLock() { $key = new CacheKeyMock('key'); - $entry = new CacheEntryMock(array('foo' => 'bar')); + $entry = new CacheEntryMock(['foo' => 'bar']); $file = $this->getFileName($this->region, $key); $this->assertFalse($this->region->contains($key)); @@ -166,7 +166,7 @@ public function testPutWithExistingLock() public function testLockedEvict() { $key = new CacheKeyMock('key'); - $entry = new CacheEntryMock(array('foo' => 'bar')); + $entry = new CacheEntryMock(['foo' => 'bar']); $file = $this->getFileName($this->region, $key); $this->assertFalse($this->region->contains($key)); @@ -186,11 +186,11 @@ public function testLockedEvict() public function testLockedEvictAll() { $key1 = new CacheKeyMock('key1'); - $entry1 = new CacheEntryMock(array('foo1' => 'bar1')); + $entry1 = new CacheEntryMock(['foo1' => 'bar1']); $file1 = $this->getFileName($this->region, $key1); $key2 = new CacheKeyMock('key2'); - $entry2 = new CacheEntryMock(array('foo2' => 'bar2')); + $entry2 = new CacheEntryMock(['foo2' => 'bar2']); $file2 = $this->getFileName($this->region, $key2); $this->assertFalse($this->region->contains($key1)); @@ -222,7 +222,7 @@ public function testLockedEvictAll() public function testLockLifetime() { $key = new CacheKeyMock('key'); - $entry = new CacheEntryMock(array('foo' => 'bar')); + $entry = new CacheEntryMock(['foo' => 'bar']); $file = $this->getFileName($this->region, $key); $property = new \ReflectionProperty($this->region, 'lockLifetime'); diff --git a/tests/Doctrine/Tests/ORM/Cache/MultiGetRegionTest.php b/tests/Doctrine/Tests/ORM/Cache/MultiGetRegionTest.php index 65d21b93fbe..0d98665d0d0 100644 --- a/tests/Doctrine/Tests/ORM/Cache/MultiGetRegionTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/MultiGetRegionTest.php @@ -20,10 +20,10 @@ protected function createRegion() public function testGetMulti() { $key1 = new CacheKeyMock('key.1'); - $value1 = new CacheEntryMock(array('id' => 1, 'name' => 'bar')); + $value1 = new CacheEntryMock(['id' => 1, 'name' => 'bar']); $key2 = new CacheKeyMock('key.2'); - $value2 = new CacheEntryMock(array('id' => 2, 'name' => 'bar')); + $value2 = new CacheEntryMock(['id' => 2, 'name' => 'bar']); $this->assertFalse($this->region->contains($key1)); $this->assertFalse($this->region->contains($key2)); @@ -34,7 +34,7 @@ public function testGetMulti() $this->assertTrue($this->region->contains($key1)); $this->assertTrue($this->region->contains($key2)); - $actual = $this->region->getMultiple(new CollectionCacheEntry(array($key1, $key2))); + $actual = $this->region->getMultiple(new CollectionCacheEntry([$key1, $key2])); $this->assertEquals($value1, $actual[0]); $this->assertEquals($value2, $actual[1]); diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/AbstractCollectionPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/AbstractCollectionPersisterTest.php index adc8ec0ba8a..681b43f0b19 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/AbstractCollectionPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/AbstractCollectionPersisterTest.php @@ -35,7 +35,7 @@ abstract class AbstractCollectionPersisterTest extends OrmTestCase /** * @var array */ - protected $regionMockMethods = array( + protected $regionMockMethods = [ 'getName', 'contains', 'get', @@ -43,12 +43,12 @@ abstract class AbstractCollectionPersisterTest extends OrmTestCase 'put', 'evict', 'evictAll' - ); + ]; /** * @var array */ - protected $collectionPersisterMockMethods = array( + protected $collectionPersisterMockMethods = [ 'delete', 'update', 'count', @@ -60,7 +60,7 @@ abstract class AbstractCollectionPersisterTest extends OrmTestCase 'get', 'getMultiple', 'loadCriteria' - ); + ]; /** * @param \Doctrine\ORM\EntityManager $em @@ -133,7 +133,7 @@ public function testInvokeDelete() $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $this->collectionPersister->expects($this->once()) ->method('delete') @@ -150,7 +150,7 @@ public function testInvokeUpdate() $collection->setDirty(true); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $this->collectionPersister->expects($this->once()) ->method('update') @@ -165,7 +165,7 @@ public function testInvokeCount() $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $this->collectionPersister->expects($this->once()) ->method('count') @@ -182,7 +182,7 @@ public function testInvokeSlice() $collection = $this->createCollection($entity); $slice = $this->createCollection($entity); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $this->collectionPersister->expects($this->once()) ->method('slice') @@ -199,7 +199,7 @@ public function testInvokeContains() $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $this->collectionPersister->expects($this->once()) ->method('contains') @@ -215,7 +215,7 @@ public function testInvokeContainsKey() $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $this->collectionPersister->expects($this->once()) ->method('containsKey') @@ -232,7 +232,7 @@ public function testInvokeRemoveElement() $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $this->collectionPersister->expects($this->once()) ->method('removeElement') @@ -249,7 +249,7 @@ public function testInvokeGet() $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $this->collectionPersister->expects($this->once()) ->method('get') diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersisterTest.php index b41d27ab170..1c1e12b6dfd 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersisterTest.php @@ -16,7 +16,7 @@ */ class ReadWriteCachedCollectionPersisterTest extends AbstractCollectionPersisterTest { - protected $regionMockMethods = array( + protected $regionMockMethods = [ 'getName', 'contains', 'get', @@ -26,7 +26,7 @@ class ReadWriteCachedCollectionPersisterTest extends AbstractCollectionPersister 'evictAll', 'lock', 'unlock', - ); + ]; /** * {@inheritdoc} @@ -52,14 +52,14 @@ public function testDeleteShouldLockItem() $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $key = new CollectionCacheKey(State::CLASSNAME, 'cities', array('id'=>1)); + $key = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id'=>1]); $this->region->expects($this->once()) ->method('lock') ->with($this->equalTo($key)) ->will($this->returnValue($lock)); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $persister->delete($collection); } @@ -70,14 +70,14 @@ public function testUpdateShouldLockItem() $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $key = new CollectionCacheKey(State::CLASSNAME, 'cities', array('id'=>1)); + $key = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id'=>1]); $this->region->expects($this->once()) ->method('lock') ->with($this->equalTo($key)) ->will($this->returnValue($lock)); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $persister->update($collection); } @@ -88,7 +88,7 @@ public function testUpdateTransactionRollBackShouldEvictItem() $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $key = new CollectionCacheKey(State::CLASSNAME, 'cities', array('id'=>1)); + $key = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id'=>1]); $this->region->expects($this->once()) ->method('lock') @@ -100,7 +100,7 @@ public function testUpdateTransactionRollBackShouldEvictItem() ->with($this->equalTo($key)) ->will($this->returnValue($lock)); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $persister->update($collection); $persister->afterTransactionRolledBack(); @@ -112,7 +112,7 @@ public function testDeleteTransactionRollBackShouldEvictItem() $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $key = new CollectionCacheKey(State::CLASSNAME, 'cities', array('id'=>1)); + $key = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id'=>1]); $this->region->expects($this->once()) ->method('lock') @@ -123,7 +123,7 @@ public function testDeleteTransactionRollBackShouldEvictItem() ->method('evict') ->with($this->equalTo($key)); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $persister->delete($collection); $persister->afterTransactionRolledBack(); @@ -135,7 +135,7 @@ public function testTransactionRollBackDeleteShouldClearQueue() $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $key = new CollectionCacheKey(State::CLASSNAME, 'cities', array('id'=>1)); + $key = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id'=>1]); $property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Collection\ReadWriteCachedCollectionPersister', 'queuedCache'); $property->setAccessible(true); @@ -149,7 +149,7 @@ public function testTransactionRollBackDeleteShouldClearQueue() ->method('evict') ->with($this->equalTo($key)); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $persister->delete($collection); @@ -166,7 +166,7 @@ public function testTransactionRollBackUpdateShouldClearQueue() $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $key = new CollectionCacheKey(State::CLASSNAME, 'cities', array('id'=>1)); + $key = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id'=>1]); $property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Collection\ReadWriteCachedCollectionPersister', 'queuedCache'); $property->setAccessible(true); @@ -180,7 +180,7 @@ public function testTransactionRollBackUpdateShouldClearQueue() ->method('evict') ->with($this->equalTo($key)); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $persister->update($collection); @@ -197,7 +197,7 @@ public function testTransactionRollCommitDeleteShouldClearQueue() $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $key = new CollectionCacheKey(State::CLASSNAME, 'cities', array('id'=>1)); + $key = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id'=>1]); $property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Collection\ReadWriteCachedCollectionPersister', 'queuedCache'); $property->setAccessible(true); @@ -211,7 +211,7 @@ public function testTransactionRollCommitDeleteShouldClearQueue() ->method('evict') ->with($this->equalTo($key)); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $persister->delete($collection); @@ -228,7 +228,7 @@ public function testTransactionRollCommitUpdateShouldClearQueue() $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $key = new CollectionCacheKey(State::CLASSNAME, 'cities', array('id'=>1)); + $key = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id'=>1]); $property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Collection\ReadWriteCachedCollectionPersister', 'queuedCache'); $property->setAccessible(true); @@ -242,7 +242,7 @@ public function testTransactionRollCommitUpdateShouldClearQueue() ->method('evict') ->with($this->equalTo($key)); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $persister->update($collection); @@ -258,7 +258,7 @@ public function testDeleteLockFailureShouldIgnoreQueue() $entity = new State("Foo"); $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $key = new CollectionCacheKey(State::CLASSNAME, 'cities', array('id'=>1)); + $key = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id'=>1]); $property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Collection\ReadWriteCachedCollectionPersister', 'queuedCache'); $property->setAccessible(true); @@ -272,7 +272,7 @@ public function testDeleteLockFailureShouldIgnoreQueue() ->method('delete') ->with($this->equalTo($collection)); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $persister->delete($collection); $this->assertCount(0, $property->getValue($persister)); @@ -283,7 +283,7 @@ public function testUpdateLockFailureShouldIgnoreQueue() $entity = new State("Foo"); $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $key = new CollectionCacheKey(State::CLASSNAME, 'cities', array('id'=>1)); + $key = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id'=>1]); $property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Collection\ReadWriteCachedCollectionPersister', 'queuedCache'); $property->setAccessible(true); @@ -297,7 +297,7 @@ public function testUpdateLockFailureShouldIgnoreQueue() ->method('update') ->with($this->equalTo($collection)); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $persister->update($collection); $this->assertCount(0, $property->getValue($persister)); diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/AbstractEntityPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/AbstractEntityPersisterTest.php index 83fd3ad8579..7e4d83663c7 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/AbstractEntityPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/AbstractEntityPersisterTest.php @@ -38,7 +38,7 @@ abstract class AbstractEntityPersisterTest extends OrmTestCase /** * @var array */ - protected $regionMockMethods = array( + protected $regionMockMethods = [ 'getName', 'contains', 'get', @@ -46,12 +46,12 @@ abstract class AbstractEntityPersisterTest extends OrmTestCase 'put', 'evict', 'evictAll' - ); + ]; /** * @var array */ - protected $entityPersisterMockMethods = array( + protected $entityPersisterMockMethods = [ 'getClassMetadata', 'getResultSetMapping', 'getInserts', @@ -79,7 +79,7 @@ abstract class AbstractEntityPersisterTest extends OrmTestCase 'lock', 'getOneToManyCollection', 'exists' - ); + ]; /** * @param \Doctrine\ORM\EntityManager $em @@ -150,9 +150,9 @@ public function testInvokeGetInserts() $this->entityPersister->expects($this->once()) ->method('getInserts') - ->will($this->returnValue(array($entity))); + ->will($this->returnValue([$entity])); - $this->assertEquals(array($entity), $persister->getInserts()); + $this->assertEquals([$entity], $persister->getInserts()); } public function testInvokeGetSelectSQL() @@ -161,10 +161,14 @@ public function testInvokeGetSelectSQL() $this->entityPersister->expects($this->once()) ->method('getSelectSQL') - ->with($this->equalTo(array('name'=>'Foo')), $this->equalTo(array(0)), $this->equalTo(1), $this->equalTo(2), $this->equalTo(3), $this->equalTo(array(4))) + ->with($this->equalTo(['name'=>'Foo']), $this->equalTo([0]), $this->equalTo(1), $this->equalTo(2), $this->equalTo(3), $this->equalTo( + [4] + )) ->will($this->returnValue('SELECT * FROM foo WERE name = ?')); - $this->assertEquals('SELECT * FROM foo WERE name = ?', $persister->getSelectSQL(array('name'=>'Foo'), array(0), 1, 2, 3, array(4))); + $this->assertEquals('SELECT * FROM foo WERE name = ?', $persister->getSelectSQL( + ['name'=>'Foo'], [0], 1, 2, 3, [4] + )); } public function testInvokeGetInsertSQL() @@ -184,10 +188,10 @@ public function testInvokeExpandParameters() $this->entityPersister->expects($this->once()) ->method('expandParameters') - ->with($this->equalTo(array('name'=>'Foo'))) - ->will($this->returnValue(array('name'=>'Foo'))); + ->with($this->equalTo(['name'=>'Foo'])) + ->will($this->returnValue(['name'=>'Foo'])); - $this->assertEquals(array('name'=>'Foo'), $persister->expandParameters(array('name'=>'Foo'))); + $this->assertEquals(['name'=>'Foo'], $persister->expandParameters(['name'=>'Foo'])); } public function testInvokeExpandCriteriaParameters() @@ -198,9 +202,9 @@ public function testInvokeExpandCriteriaParameters() $this->entityPersister->expects($this->once()) ->method('expandCriteriaParameters') ->with($this->equalTo($criteria)) - ->will($this->returnValue(array('name'=>'Foo'))); + ->will($this->returnValue(['name'=>'Foo'])); - $this->assertEquals(array('name'=>'Foo'), $persister->expandCriteriaParameters($criteria)); + $this->assertEquals(['name'=>'Foo'], $persister->expandCriteriaParameters($criteria)); } public function testInvokeSelectConditionStatementSQL() @@ -209,10 +213,10 @@ public function testInvokeSelectConditionStatementSQL() $this->entityPersister->expects($this->once()) ->method('getSelectConditionStatementSQL') - ->with($this->equalTo('id'), $this->equalTo(1), $this->equalTo(array()), $this->equalTo('=')) + ->with($this->equalTo('id'), $this->equalTo(1), $this->equalTo([]), $this->equalTo('=')) ->will($this->returnValue('name = 1')); - $this->assertEquals('name = 1', $persister->getSelectConditionStatementSQL('id', 1, array(), '=')); + $this->assertEquals('name = 1', $persister->getSelectConditionStatementSQL('id', 1, [], '=')); } public function testInvokeExecuteInserts() @@ -221,9 +225,9 @@ public function testInvokeExecuteInserts() $this->entityPersister->expects($this->once()) ->method('executeInserts') - ->will($this->returnValue(array('id' => 1))); + ->will($this->returnValue(['id' => 1])); - $this->assertEquals(array('id' => 1), $persister->executeInserts()); + $this->assertEquals(['id' => 1], $persister->executeInserts()); } public function testInvokeUpdate() @@ -235,7 +239,7 @@ public function testInvokeUpdate() ->method('update') ->with($this->equalTo($entity)); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $this->assertNull($persister->update($entity)); } @@ -249,7 +253,7 @@ public function testInvokeDelete() ->method('delete') ->with($this->equalTo($entity)); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $this->assertNull($persister->delete($entity)); } @@ -273,10 +277,14 @@ public function testInvokeLoad() $this->entityPersister->expects($this->once()) ->method('load') - ->with($this->equalTo(array('id' => 1)), $this->equalTo($entity), $this->equalTo(array(0)), $this->equalTo(array(1)), $this->equalTo(2), $this->equalTo(3), $this->equalTo(array(4))) + ->with($this->equalTo(['id' => 1]), $this->equalTo($entity), $this->equalTo([0]), $this->equalTo( + [1] + ), $this->equalTo(2), $this->equalTo(3), $this->equalTo( + [4] + )) ->will($this->returnValue($entity)); - $this->assertEquals($entity, $persister->load(array('id' => 1), $entity, array(0), array(1), 2, 3, array(4))); + $this->assertEquals($entity, $persister->load(['id' => 1], $entity, [0], [1], 2, 3, [4])); } public function testInvokeLoadAll() @@ -287,18 +295,18 @@ public function testInvokeLoadAll() $rsm->addEntityResult(Country::CLASSNAME, 'c'); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $this->entityPersister->expects($this->once()) ->method('loadAll') - ->with($this->equalTo(array('id' => 1)), $this->equalTo(array(0)), $this->equalTo(1), $this->equalTo(2)) - ->will($this->returnValue(array($entity))); + ->with($this->equalTo(['id' => 1]), $this->equalTo([0]), $this->equalTo(1), $this->equalTo(2)) + ->will($this->returnValue([$entity])); $this->entityPersister->expects($this->once()) ->method('getResultSetMapping') ->will($this->returnValue($rsm)); - $this->assertEquals(array($entity), $persister->loadAll(array('id' => 1), array(0), 1, 2)); + $this->assertEquals([$entity], $persister->loadAll(['id' => 1], [0], 1, 2)); } public function testInvokeLoadById() @@ -308,10 +316,10 @@ public function testInvokeLoadById() $this->entityPersister->expects($this->once()) ->method('loadById') - ->with($this->equalTo(array('id' => 1)), $this->equalTo($entity)) + ->with($this->equalTo(['id' => 1]), $this->equalTo($entity)) ->will($this->returnValue($entity)); - $this->assertEquals($entity, $persister->loadById(array('id' => 1), $entity)); + $this->assertEquals($entity, $persister->loadById(['id' => 1], $entity)); } public function testInvokeLoadOneToOneEntity() @@ -321,10 +329,10 @@ public function testInvokeLoadOneToOneEntity() $this->entityPersister->expects($this->once()) ->method('loadOneToOneEntity') - ->with($this->equalTo(array()), $this->equalTo('foo'), $this->equalTo(array('id' => 11))) + ->with($this->equalTo([]), $this->equalTo('foo'), $this->equalTo(['id' => 11])) ->will($this->returnValue($entity)); - $this->assertEquals($entity, $persister->loadOneToOneEntity(array(), 'foo', array('id' => 11))); + $this->assertEquals($entity, $persister->loadOneToOneEntity([], 'foo', ['id' => 11])); } public function testInvokeRefresh() @@ -334,10 +342,10 @@ public function testInvokeRefresh() $this->entityPersister->expects($this->once()) ->method('refresh') - ->with($this->equalTo(array('id' => 1)), $this->equalTo($entity), $this->equalTo(0)) + ->with($this->equalTo(['id' => 1]), $this->equalTo($entity), $this->equalTo(0)) ->will($this->returnValue($entity)); - $this->assertNull($persister->refresh(array('id' => 1), $entity), 0); + $this->assertNull($persister->refresh(['id' => 1], $entity), 0); } public function testInvokeLoadCriteria() @@ -347,7 +355,7 @@ public function testInvokeLoadCriteria() $entity = new Country("Foo"); $criteria = new Criteria(); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $rsm->addEntityResult(Country::CLASSNAME, 'c'); $this->entityPersister->expects($this->once()) @@ -357,9 +365,9 @@ public function testInvokeLoadCriteria() $this->entityPersister->expects($this->once()) ->method('loadCriteria') ->with($this->equalTo($criteria)) - ->will($this->returnValue(array($entity))); + ->will($this->returnValue([$entity])); - $this->assertEquals(array($entity), $persister->loadCriteria($criteria)); + $this->assertEquals([$entity], $persister->loadCriteria($criteria)); } public function testInvokeGetManyToManyCollection() @@ -369,10 +377,10 @@ public function testInvokeGetManyToManyCollection() $this->entityPersister->expects($this->once()) ->method('getManyToManyCollection') - ->with($this->equalTo(array()), $this->equalTo('Foo'), $this->equalTo(1), $this->equalTo(2)) - ->will($this->returnValue(array($entity))); + ->with($this->equalTo([]), $this->equalTo('Foo'), $this->equalTo(1), $this->equalTo(2)) + ->will($this->returnValue([$entity])); - $this->assertEquals(array($entity), $persister->getManyToManyCollection(array(), 'Foo', 1 ,2)); + $this->assertEquals([$entity], $persister->getManyToManyCollection([], 'Foo', 1 ,2)); } public function testInvokeGetOneToManyCollection() @@ -382,16 +390,16 @@ public function testInvokeGetOneToManyCollection() $this->entityPersister->expects($this->once()) ->method('getOneToManyCollection') - ->with($this->equalTo(array()), $this->equalTo('Foo'), $this->equalTo(1), $this->equalTo(2)) - ->will($this->returnValue(array($entity))); + ->with($this->equalTo([]), $this->equalTo('Foo'), $this->equalTo(1), $this->equalTo(2)) + ->will($this->returnValue([$entity])); - $this->assertEquals(array($entity), $persister->getOneToManyCollection(array(), 'Foo', 1 ,2)); + $this->assertEquals([$entity], $persister->getOneToManyCollection([], 'Foo', 1 ,2)); } public function testInvokeLoadManyToManyCollection() { $mapping = $this->em->getClassMetadata('Doctrine\Tests\Models\Cache\Country'); - $assoc = array('type' => 1); + $assoc = ['type' => 1]; $coll = new PersistentCollection($this->em, $mapping, new ArrayCollection()); $persister = $this->createPersisterDefault(); $entity = new Country("Foo"); @@ -399,15 +407,15 @@ public function testInvokeLoadManyToManyCollection() $this->entityPersister->expects($this->once()) ->method('loadManyToManyCollection') ->with($this->equalTo($assoc), $this->equalTo('Foo'), $coll) - ->will($this->returnValue(array($entity))); + ->will($this->returnValue([$entity])); - $this->assertEquals(array($entity), $persister->loadManyToManyCollection($assoc, 'Foo', $coll)); + $this->assertEquals([$entity], $persister->loadManyToManyCollection($assoc, 'Foo', $coll)); } public function testInvokeLoadOneToManyCollection() { $mapping = $this->em->getClassMetadata('Doctrine\Tests\Models\Cache\Country'); - $assoc = array('type' => 1); + $assoc = ['type' => 1]; $coll = new PersistentCollection($this->em, $mapping, new ArrayCollection()); $persister = $this->createPersisterDefault(); $entity = new Country("Foo"); @@ -415,14 +423,14 @@ public function testInvokeLoadOneToManyCollection() $this->entityPersister->expects($this->once()) ->method('loadOneToManyCollection') ->with($this->equalTo($assoc), $this->equalTo('Foo'), $coll) - ->will($this->returnValue(array($entity))); + ->will($this->returnValue([$entity])); - $this->assertEquals(array($entity), $persister->loadOneToManyCollection($assoc, 'Foo', $coll)); + $this->assertEquals([$entity], $persister->loadOneToManyCollection($assoc, 'Foo', $coll)); } public function testInvokeLock() { - $identifier = array('id' => 1); + $identifier = ['id' => 1]; $persister = $this->createPersisterDefault(); $this->entityPersister->expects($this->once()) diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersisterTest.php index df1f6ac593c..ad05020e6b8 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersisterTest.php @@ -32,7 +32,7 @@ public function testTransactionRollBackShouldClearQueue() $property->setAccessible(true); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $persister->update($entity); $persister->delete($entity); @@ -48,8 +48,8 @@ public function testInsertTransactionCommitShouldPutCache() { $entity = new Country("Foo"); $persister = $this->createPersisterDefault(); - $key = new EntityCacheKey(Country::CLASSNAME, array('id'=>1)); - $entry = new EntityCacheEntry(Country::CLASSNAME, array('id'=>1, 'name'=>'Foo')); + $key = new EntityCacheKey(Country::CLASSNAME, ['id'=>1]); + $entry = new EntityCacheEntry(Country::CLASSNAME, ['id'=>1, 'name'=>'Foo']); $property = new \ReflectionProperty($persister, 'queuedCache'); $property->setAccessible(true); @@ -64,12 +64,12 @@ public function testInsertTransactionCommitShouldPutCache() $this->entityPersister->expects($this->once()) ->method('getInserts') - ->will($this->returnValue(array($entity))); + ->will($this->returnValue([$entity])); $this->entityPersister->expects($this->once()) ->method('executeInserts'); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $persister->addInsert($entity); $persister->executeInserts(); @@ -85,8 +85,8 @@ public function testUpdateTransactionCommitShouldPutCache() { $entity = new Country("Foo"); $persister = $this->createPersisterDefault(); - $key = new EntityCacheKey(Country::CLASSNAME, array('id'=>1)); - $entry = new EntityCacheEntry(Country::CLASSNAME, array('id'=>1, 'name'=>'Foo')); + $key = new EntityCacheKey(Country::CLASSNAME, ['id'=>1]); + $entry = new EntityCacheEntry(Country::CLASSNAME, ['id'=>1, 'name'=>'Foo']); $property = new \ReflectionProperty($persister, 'queuedCache'); $property->setAccessible(true); @@ -99,7 +99,7 @@ public function testUpdateTransactionCommitShouldPutCache() ->method('update') ->with($this->equalTo($entity)); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $persister->update($entity); @@ -114,7 +114,7 @@ public function testDeleteTransactionCommitShouldEvictCache() { $entity = new Country("Foo"); $persister = $this->createPersisterDefault(); - $key = new EntityCacheKey(Country::CLASSNAME, array('id'=>1)); + $key = new EntityCacheKey(Country::CLASSNAME, ['id'=>1]); $property = new \ReflectionProperty($persister, 'queuedCache'); $property->setAccessible(true); @@ -127,7 +127,7 @@ public function testDeleteTransactionCommitShouldEvictCache() ->method('delete') ->with($this->equalTo($entity)); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $persister->delete($entity); diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersisterTest.php index dc9fef43a0a..d90fd678b39 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersisterTest.php @@ -17,7 +17,7 @@ */ class ReadWriteCachedEntityPersisterTest extends AbstractEntityPersisterTest { - protected $regionMockMethods = array( + protected $regionMockMethods = [ 'getName', 'contains', 'get', @@ -27,7 +27,7 @@ class ReadWriteCachedEntityPersisterTest extends AbstractEntityPersisterTest 'evictAll', 'lock', 'unlock', - ); + ]; /** * {@inheritdoc} @@ -52,14 +52,14 @@ public function testDeleteShouldLockItem() $entity = new Country("Foo"); $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); - $key = new EntityCacheKey(Country::CLASSNAME, array('id'=>1)); + $key = new EntityCacheKey(Country::CLASSNAME, ['id'=>1]); $this->region->expects($this->once()) ->method('lock') ->with($this->equalTo($key)) ->will($this->returnValue($lock)); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $persister->delete($entity); } @@ -69,14 +69,14 @@ public function testUpdateShouldLockItem() $entity = new Country("Foo"); $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); - $key = new EntityCacheKey(Country::CLASSNAME, array('id'=>1)); + $key = new EntityCacheKey(Country::CLASSNAME, ['id'=>1]); $this->region->expects($this->once()) ->method('lock') ->with($this->equalTo($key)) ->will($this->returnValue($lock)); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $persister->update($entity); } @@ -86,7 +86,7 @@ public function testUpdateTransactionRollBackShouldEvictItem() $entity = new Country("Foo"); $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); - $key = new EntityCacheKey(Country::CLASSNAME, array('id'=>1)); + $key = new EntityCacheKey(Country::CLASSNAME, ['id'=>1]); $this->region->expects($this->once()) ->method('lock') @@ -98,7 +98,7 @@ public function testUpdateTransactionRollBackShouldEvictItem() ->with($this->equalTo($key)) ->will($this->returnValue($lock)); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $persister->update($entity); $persister->afterTransactionRolledBack(); @@ -109,7 +109,7 @@ public function testDeleteTransactionRollBackShouldEvictItem() $entity = new Country("Foo"); $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); - $key = new EntityCacheKey(Country::CLASSNAME, array('id'=>1)); + $key = new EntityCacheKey(Country::CLASSNAME, ['id'=>1]); $this->region->expects($this->once()) ->method('lock') @@ -120,7 +120,7 @@ public function testDeleteTransactionRollBackShouldEvictItem() ->method('evict') ->with($this->equalTo($key)); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $persister->delete($entity); $persister->afterTransactionRolledBack(); @@ -131,7 +131,7 @@ public function testTransactionRollBackShouldClearQueue() $entity = new Country("Foo"); $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); - $key = new EntityCacheKey(Country::CLASSNAME, array('id'=>1)); + $key = new EntityCacheKey(Country::CLASSNAME, ['id'=>1]); $property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister', 'queuedCache'); $property->setAccessible(true); @@ -145,7 +145,7 @@ public function testTransactionRollBackShouldClearQueue() ->method('evict') ->with($this->equalTo($key)); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $persister->update($entity); $persister->delete($entity); @@ -162,7 +162,7 @@ public function testTransactionCommitShouldClearQueue() $entity = new Country("Foo"); $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); - $key = new EntityCacheKey(Country::CLASSNAME, array('id'=>1)); + $key = new EntityCacheKey(Country::CLASSNAME, ['id'=>1]); $property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister', 'queuedCache'); $property->setAccessible(true); @@ -176,7 +176,7 @@ public function testTransactionCommitShouldClearQueue() ->method('evict') ->with($this->equalTo($key)); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $persister->update($entity); $persister->delete($entity); @@ -192,7 +192,7 @@ public function testDeleteLockFailureShouldIgnoreQueue() { $entity = new Country("Foo"); $persister = $this->createPersisterDefault(); - $key = new EntityCacheKey(Country::CLASSNAME, array('id'=>1)); + $key = new EntityCacheKey(Country::CLASSNAME, ['id'=>1]); $property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister', 'queuedCache'); $property->setAccessible(true); @@ -206,7 +206,7 @@ public function testDeleteLockFailureShouldIgnoreQueue() ->method('delete') ->with($this->equalTo($entity)); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $persister->delete($entity); $this->assertCount(0, $property->getValue($persister)); @@ -216,7 +216,7 @@ public function testUpdateLockFailureShouldIgnoreQueue() { $entity = new Country("Foo"); $persister = $this->createPersisterDefault(); - $key = new EntityCacheKey(Country::CLASSNAME, array('id'=>1)); + $key = new EntityCacheKey(Country::CLASSNAME, ['id'=>1]); $property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister', 'queuedCache'); $property->setAccessible(true); @@ -230,7 +230,7 @@ public function testUpdateLockFailureShouldIgnoreQueue() ->method('update') ->with($this->equalTo($entity)); - $this->em->getUnitOfWork()->registerManaged($entity, array('id'=>1), array('id'=>1, 'name'=>'Foo')); + $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); $persister->update($entity); $this->assertCount(0, $property->getValue($persister)); diff --git a/tests/Doctrine/Tests/ORM/Cache/StatisticsCacheLoggerTest.php b/tests/Doctrine/Tests/ORM/Cache/StatisticsCacheLoggerTest.php index 16c91729b22..0d5a7223719 100644 --- a/tests/Doctrine/Tests/ORM/Cache/StatisticsCacheLoggerTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/StatisticsCacheLoggerTest.php @@ -29,7 +29,7 @@ protected function setUp() public function testEntityCache() { $name = 'my_entity_region'; - $key = new EntityCacheKey(State::CLASSNAME, array('id' => 1)); + $key = new EntityCacheKey(State::CLASSNAME, ['id' => 1]); $this->logger->entityCacheHit($name, $key); $this->logger->entityCachePut($name, $key); @@ -46,7 +46,7 @@ public function testEntityCache() public function testCollectionCache() { $name = 'my_collection_region'; - $key = new CollectionCacheKey(State::CLASSNAME, 'cities', array('id' => 1)); + $key = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id' => 1]); $this->logger->collectionCacheHit($name, $key); $this->logger->collectionCachePut($name, $key); @@ -83,8 +83,8 @@ public function testMultipleCaches() $entityRegion = 'my_entity_region'; $queryRegion = 'my_query_region'; - $coolKey = new CollectionCacheKey(State::CLASSNAME, 'cities', array('id' => 1)); - $entityKey = new EntityCacheKey(State::CLASSNAME, array('id' => 1)); + $coolKey = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id' => 1]); + $entityKey = new EntityCacheKey(State::CLASSNAME, ['id' => 1]); $queryKey = new QueryCacheKey('my_query_hash'); $this->logger->queryCacheHit($queryRegion, $queryKey); @@ -131,4 +131,4 @@ public function testMultipleCaches() $this->assertArrayHasKey($queryRegion, $hit); $this->assertArrayHasKey($entityRegion, $hit); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php b/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php index 770ec7deb21..dba00d524a6 100644 --- a/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php +++ b/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php @@ -44,7 +44,7 @@ public function testCommitOrdering1() $sorted = $this->_calc->sort(); // There is only 1 valid ordering for this constellation - $correctOrder = array($class5, $class1, $class2, $class3, $class4); + $correctOrder = [$class5, $class1, $class2, $class3, $class4]; $this->assertSame($correctOrder, $sorted); } @@ -63,7 +63,7 @@ public function testCommitOrdering2() $sorted = $this->_calc->sort(); // There is only 1 valid ordering for this constellation - $correctOrder = array($class2, $class1); + $correctOrder = [$class2, $class1]; $this->assertSame($correctOrder, $sorted); } diff --git a/tests/Doctrine/Tests/ORM/ConfigurationTest.php b/tests/Doctrine/Tests/ORM/ConfigurationTest.php index 7d55652dff1..4988ac9b24c 100644 --- a/tests/Doctrine/Tests/ORM/ConfigurationTest.php +++ b/tests/Doctrine/Tests/ORM/ConfigurationTest.php @@ -75,7 +75,7 @@ public function testSetGetMetadataDriverImpl() public function testNewDefaultAnnotationDriver() { - $paths = array(__DIR__); + $paths = [__DIR__]; $reflectionClass = new ReflectionClass(__NAMESPACE__ . '\ConfigurationTestAnnotationReaderChecker'); $annotationDriver = $this->configuration->newDefaultAnnotationDriver($paths, false); @@ -99,7 +99,7 @@ public function testSetGetEntityNamespace() { $this->configuration->addEntityNamespace('TestNamespace', __NAMESPACE__); $this->assertSame(__NAMESPACE__, $this->configuration->getEntityNamespace('TestNamespace')); - $namespaces = array('OtherNamespace' => __NAMESPACE__); + $namespaces = ['OtherNamespace' => __NAMESPACE__]; $this->configuration->setEntityNamespaces($namespaces); $this->assertSame($namespaces, $this->configuration->getEntityNamespaces()); $this->expectException(\Doctrine\ORM\ORMException::class); @@ -259,7 +259,7 @@ public function testAddGetCustomStringFunction() $this->configuration->addCustomStringFunction('FunctionName', __CLASS__); $this->assertSame(__CLASS__, $this->configuration->getCustomStringFunction('FunctionName')); $this->assertSame(null, $this->configuration->getCustomStringFunction('NonExistingFunction')); - $this->configuration->setCustomStringFunctions(array('OtherFunctionName' => __CLASS__)); + $this->configuration->setCustomStringFunctions(['OtherFunctionName' => __CLASS__]); $this->assertSame(__CLASS__, $this->configuration->getCustomStringFunction('OtherFunctionName')); $this->expectException(\Doctrine\ORM\ORMException::class); $this->configuration->addCustomStringFunction('concat', __CLASS__); @@ -270,7 +270,7 @@ public function testAddGetCustomNumericFunction() $this->configuration->addCustomNumericFunction('FunctionName', __CLASS__); $this->assertSame(__CLASS__, $this->configuration->getCustomNumericFunction('FunctionName')); $this->assertSame(null, $this->configuration->getCustomNumericFunction('NonExistingFunction')); - $this->configuration->setCustomNumericFunctions(array('OtherFunctionName' => __CLASS__)); + $this->configuration->setCustomNumericFunctions(['OtherFunctionName' => __CLASS__]); $this->assertSame(__CLASS__, $this->configuration->getCustomNumericFunction('OtherFunctionName')); $this->expectException(\Doctrine\ORM\ORMException::class); $this->configuration->addCustomNumericFunction('abs', __CLASS__); @@ -281,7 +281,7 @@ public function testAddGetCustomDatetimeFunction() $this->configuration->addCustomDatetimeFunction('FunctionName', __CLASS__); $this->assertSame(__CLASS__, $this->configuration->getCustomDatetimeFunction('FunctionName')); $this->assertSame(null, $this->configuration->getCustomDatetimeFunction('NonExistingFunction')); - $this->configuration->setCustomDatetimeFunctions(array('OtherFunctionName' => __CLASS__)); + $this->configuration->setCustomDatetimeFunctions(['OtherFunctionName' => __CLASS__]); $this->assertSame(__CLASS__, $this->configuration->getCustomDatetimeFunction('OtherFunctionName')); $this->expectException(\Doctrine\ORM\ORMException::class); $this->configuration->addCustomDatetimeFunction('date_add', __CLASS__); @@ -300,9 +300,9 @@ public function testSetCustomHydrationModes() $this->assertSame(__CLASS__, $this->configuration->getCustomHydrationMode('HydrationModeName')); $this->configuration->setCustomHydrationModes( - array( + [ 'AnotherHydrationModeName' => __CLASS__ - ) + ] ); $this->assertNull($this->configuration->getCustomHydrationMode('HydrationModeName')); diff --git a/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php b/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php index c52ce550cbf..933580af014 100644 --- a/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php +++ b/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php @@ -14,7 +14,7 @@ public function setUp() { $this->wrapped = $this->createMock(EntityManagerInterface::class); $this->decorator = $this->getMockBuilder('Doctrine\ORM\Decorator\EntityManagerDecorator') - ->setConstructorArgs(array($this->wrapped)) + ->setConstructorArgs([$this->wrapped]) ->setMethods(null) ->getMock(); } @@ -23,7 +23,7 @@ public function getMethodParameters() { $class = new \ReflectionClass('Doctrine\ORM\EntityManager'); - $methods = array(); + $methods = []; foreach ($class->getMethods() as $method) { if ($method->isConstructor() || $method->isStatic() || !$method->isPublic()) { continue; @@ -31,17 +31,17 @@ public function getMethodParameters() /** Special case EntityManager::createNativeQuery() */ if ($method->getName() === 'createNativeQuery') { - $methods[] = array($method->getName(), array('name', new ResultSetMapping())); + $methods[] = [$method->getName(), ['name', new ResultSetMapping()]]; continue; } if ($method->getNumberOfRequiredParameters() === 0) { - $methods[] = array($method->getName(), array()); + $methods[] = [$method->getName(), []]; } elseif ($method->getNumberOfRequiredParameters() > 0) { - $methods[] = array($method->getName(), array_fill(0, $method->getNumberOfRequiredParameters(), 'req') ?: array()); + $methods[] = [$method->getName(), array_fill(0, $method->getNumberOfRequiredParameters(), 'req') ?: []]; } if ($method->getNumberOfParameters() != $method->getNumberOfRequiredParameters()) { - $methods[] = array($method->getName(), array_fill(0, $method->getNumberOfParameters(), 'all') ?: array()); + $methods[] = [$method->getName(), array_fill(0, $method->getNumberOfParameters(), 'all') ?: []]; } } @@ -58,8 +58,8 @@ public function testAllMethodCallsAreDelegatedToTheWrappedInstance($method, arra ->method($method) ->will($this->returnValue('INNER VALUE FROM ' . $method)); - call_user_func_array(array($stub, 'with'), $parameters); + call_user_func_array([$stub, 'with'], $parameters); - $this->assertSame('INNER VALUE FROM ' . $method, call_user_func_array(array($this->decorator, $method), $parameters)); + $this->assertSame('INNER VALUE FROM ' . $method, call_user_func_array([$this->decorator, $method], $parameters)); } } diff --git a/tests/Doctrine/Tests/ORM/EntityManagerTest.php b/tests/Doctrine/Tests/ORM/EntityManagerTest.php index 954a3f2f0dd..43471b643f5 100644 --- a/tests/Doctrine/Tests/ORM/EntityManagerTest.php +++ b/tests/Doctrine/Tests/ORM/EntityManagerTest.php @@ -139,13 +139,13 @@ public function testCreateNamedQuery() static public function dataMethodsAffectedByNoObjectArguments() { - return array( - array('persist'), - array('remove'), - array('merge'), - array('refresh'), - array('detach') - ); + return [ + ['persist'], + ['remove'], + ['merge'], + ['refresh'], + ['detach'] + ]; } /** @@ -160,13 +160,13 @@ public function testThrowsExceptionOnNonObjectValues($methodName) { static public function dataAffectedByErrorIfClosedException() { - return array( - array('flush'), - array('persist'), - array('remove'), - array('merge'), - array('refresh'), - ); + return [ + ['flush'], + ['persist'], + ['remove'], + ['merge'], + ['refresh'], + ]; } /** @@ -196,7 +196,7 @@ public function testTransactionalAcceptsReturn() public function testTransactionalAcceptsVariousCallables() { - $this->assertSame('callback', $this->_em->transactional(array($this, 'transactionalCallback'))); + $this->assertSame('callback', $this->_em->transactional([$this, 'transactionalCallback'])); } public function testTransactionalThrowsInvalidArgumentExceptionIfNonCallablePassed() diff --git a/tests/Doctrine/Tests/ORM/EntityNotFoundExceptionTest.php b/tests/Doctrine/Tests/ORM/EntityNotFoundExceptionTest.php index 7dce1b17169..2da4d568f01 100644 --- a/tests/Doctrine/Tests/ORM/EntityNotFoundExceptionTest.php +++ b/tests/Doctrine/Tests/ORM/EntityNotFoundExceptionTest.php @@ -16,7 +16,7 @@ public function testFromClassNameAndIdentifier() { $exception = EntityNotFoundException::fromClassNameAndIdentifier( 'foo', - array('foo' => 'bar') + ['foo' => 'bar'] ); $this->assertInstanceOf('Doctrine\ORM\EntityNotFoundException', $exception); @@ -24,7 +24,7 @@ public function testFromClassNameAndIdentifier() $exception = EntityNotFoundException::fromClassNameAndIdentifier( 'foo', - array() + [] ); $this->assertInstanceOf('Doctrine\ORM\EntityNotFoundException', $exception); diff --git a/tests/Doctrine/Tests/ORM/Functional/AbstractManyToManyAssociationTestCase.php b/tests/Doctrine/Tests/ORM/Functional/AbstractManyToManyAssociationTestCase.php index 37f0fcd2982..26445c1417a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/AbstractManyToManyAssociationTestCase.php +++ b/tests/Doctrine/Tests/ORM/Functional/AbstractManyToManyAssociationTestCase.php @@ -31,7 +31,8 @@ protected function _countForeignKeys($firstId, $secondId) FROM {$this->_table} WHERE {$this->_firstField} = ? AND {$this->_secondField} = ? - ", array($firstId, $secondId))->fetchAll()); + ", [$firstId, $secondId] + )->fetchAll()); } public function assertCollectionEquals(Collection $first, Collection $second) diff --git a/tests/Doctrine/Tests/ORM/Functional/AdvancedAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/AdvancedAssociationTest.php index 5546b285e86..e54a23115ee 100644 --- a/tests/Doctrine/Tests/ORM/Functional/AdvancedAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/AdvancedAssociationTest.php @@ -16,13 +16,15 @@ class AdvancedAssociationTest extends OrmFunctionalTestCase protected function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Phrase'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\PhraseType'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Definition'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Lemma'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Type') - )); + ] + ); } catch (\Exception $e) { // Swallow all exceptions. We do not test the schema tool here. } diff --git a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php index bee055f84ee..af62cb6d5a9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php @@ -127,7 +127,7 @@ public function testBasicOneToOne() // Check that the foreign key has been set $userId = $this->_em->getConnection()->executeQuery( - "SELECT user_id FROM cms_addresses WHERE id=?", array($address->id) + "SELECT user_id FROM cms_addresses WHERE id=?", [$address->id] )->fetchColumn(); $this->assertTrue(is_numeric($userId)); @@ -1075,11 +1075,11 @@ public function testFlushManyExplicitEntities() $this->_em->persist($userB); $this->_em->persist($userC); - $this->_em->flush(array($userA, $userB, $userB)); + $this->_em->flush([$userA, $userB, $userB]); $userC->name = 'changed name'; - $this->_em->flush(array($userA, $userB)); + $this->_em->flush([$userA, $userB]); $this->_em->refresh($userC); $this->assertTrue($userA->id > 0, 'user a has an id'); diff --git a/tests/Doctrine/Tests/ORM/Functional/CascadeRemoveOrderTest.php b/tests/Doctrine/Tests/ORM/Functional/CascadeRemoveOrderTest.php index a2392a3e86d..c552139af1c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CascadeRemoveOrderTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CascadeRemoveOrderTest.php @@ -14,20 +14,24 @@ protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\CascadeRemoveOrderEntityO'), $this->_em->getClassMetadata(__NAMESPACE__ . '\CascadeRemoveOrderEntityG'), - )); + ] + ); } protected function tearDown() { parent::tearDown(); - $this->_schemaTool->dropSchema(array( + $this->_schemaTool->dropSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\CascadeRemoveOrderEntityO'), $this->_em->getClassMetadata(__NAMESPACE__ . '\CascadeRemoveOrderEntityG'), - )); + ] + ); } public function testSingle() @@ -153,4 +157,4 @@ public function getId() { return $this->id; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php index 697f568ffb5..9d594e8c92b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php @@ -72,7 +72,7 @@ public function testCRUD() $this->_em->clear(); - $guilherme = $this->_em->getRepository(get_class($employee))->findOneBy(array('name' => 'Guilherme Blanco')); + $guilherme = $this->_em->getRepository(get_class($employee))->findOneBy(['name' => 'Guilherme Blanco']); $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $guilherme); $this->assertEquals('Guilherme Blanco', $guilherme->getName()); @@ -389,12 +389,12 @@ public function testFindByAssociation() $this->_em->clear(); $repos = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager'); - $pmanager = $repos->findOneBy(array('spouse' => $person->getId())); + $pmanager = $repos->findOneBy(['spouse' => $person->getId()]); $this->assertEquals($manager->getId(), $pmanager->getId()); $repos = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyPerson'); - $pmanager = $repos->findOneBy(array('spouse' => $person->getId())); + $pmanager = $repos->findOneBy(['spouse' => $person->getId()]); $this->assertEquals($manager->getId(), $pmanager->getId()); } diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest2.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest2.php index 5682bffe108..b7988054d23 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest2.php +++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest2.php @@ -15,12 +15,14 @@ protected function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\CTIParent'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\CTIChild'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\CTIRelated'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\CTIRelated2') - )); + ] + ); } catch (\Exception $ignored) { // Swallow all exceptions. We do not test the schema tool here. } diff --git a/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php index 1df74636cc8..a461fea19f8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php @@ -30,7 +30,7 @@ public function putGermanysBrandenburderTor() public function putTripAroundEurope() { - $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 100, 'long' => 200)); + $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', ['lat' => 100, 'long' => 200]); $tour = new NavTour("Trip around Europe"); $tour->addPointOfInterest($poi); @@ -46,7 +46,7 @@ public function testPersistCompositePkEntity() { $this->putGermanysBrandenburderTor(); - $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 100, 'long' => 200)); + $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', ['lat' => 100, 'long' => 200]); $this->assertInstanceOf('Doctrine\Tests\Models\Navigation\NavPointOfInterest', $poi); $this->assertEquals(100, $poi->getLat()); @@ -61,7 +61,7 @@ public function testSetParameterCompositeKeyObject() { $this->putGermanysBrandenburderTor(); - $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 100, 'long' => 200)); + $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', ['lat' => 100, 'long' => 200]); $photo = new NavPhotos($poi, "asdf"); $this->_em->persist($photo); $this->_em->flush(); @@ -79,7 +79,7 @@ public function testIdentityFunctionWithCompositePrimaryKey() { $this->putGermanysBrandenburderTor(); - $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 100, 'long' => 200)); + $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', ['lat' => 100, 'long' => 200]); $photo = new NavPhotos($poi, "asdf"); $this->_em->persist($photo); $this->_em->flush(); @@ -140,7 +140,7 @@ public function testSpecifyUnknownIdentifierPrimaryKeyFails() $this->expectException(ORMException::class); $this->expectExceptionMessage('The identifier long is missing for a query of Doctrine\Tests\Models\Navigation\NavPointOfInterest'); - $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('key1' => 100)); + $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', ['key1' => 100]); } public function testUnrecognizedIdentifierFieldsOnGetReference() @@ -148,7 +148,8 @@ public function testUnrecognizedIdentifierFieldsOnGetReference() $this->expectException(ORMException::class); $this->expectExceptionMessage("Unrecognized identifier fields: 'key1'"); - $poi = $this->_em->getReference('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 10, 'long' => 20, 'key1' => 100)); + $poi = $this->_em->getReference('Doctrine\Tests\Models\Navigation\NavPointOfInterest', ['lat' => 10, 'long' => 20, 'key1' => 100] + ); } /** @@ -158,7 +159,7 @@ public function testDeleteCompositePersistentCollection() { $this->putGermanysBrandenburderTor(); - $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 100, 'long' => 200)); + $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', ['lat' => 100, 'long' => 200]); $poi->addVisitor(new NavUser("test1")); $poi->addVisitor(new NavUser("test2")); @@ -169,7 +170,7 @@ public function testDeleteCompositePersistentCollection() $this->_em->flush(); $this->_em->clear(); - $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 100, 'long' => 200)); + $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', ['lat' => 100, 'long' => 200]); $this->assertEquals(0, count($poi->getVisitors())); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyWithAssociationsTest.php b/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyWithAssociationsTest.php index b735925e63f..3b5427f0559 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyWithAssociationsTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyWithAssociationsTest.php @@ -44,13 +44,13 @@ public function testFindByAbleToGetCompositeEntitiesWithMixedTypeIdentifiers() $admin1Repo = $this->_em->getRepository('Doctrine\Tests\Models\GeoNames\Admin1'); $admin1NamesRepo = $this->_em->getRepository('Doctrine\Tests\Models\GeoNames\Admin1AlternateName'); - $admin1Rome = $admin1Repo->findOneBy(array('country' => 'IT', 'id' => 1)); + $admin1Rome = $admin1Repo->findOneBy(['country' => 'IT', 'id' => 1]); - $names = $admin1NamesRepo->findBy(array('admin1' => $admin1Rome)); + $names = $admin1NamesRepo->findBy(['admin1' => $admin1Rome]); $this->assertCount(2, $names); - $name1 = $admin1NamesRepo->findOneBy(array('admin1' => $admin1Rome, 'id' => 1)); - $name2 = $admin1NamesRepo->findOneBy(array('admin1' => $admin1Rome, 'id' => 2)); + $name1 = $admin1NamesRepo->findOneBy(['admin1' => $admin1Rome, 'id' => 1]); + $name2 = $admin1NamesRepo->findOneBy(['admin1' => $admin1Rome, 'id' => 2]); $this->assertEquals(1, $name1->id); $this->assertEquals("Roma", $name1->name); diff --git a/tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTest.php b/tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTest.php index 37149abfd3a..5d08039e504 100644 --- a/tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTest.php @@ -33,15 +33,15 @@ public function testIssue2059() $user = new Table("ddc2059_user"); $user->addColumn('id', 'integer'); - $user->setPrimaryKey(array('id')); + $user->setPrimaryKey(['id']); $project = new Table("ddc2059_project"); $project->addColumn('id', 'integer'); $project->addColumn('user_id', 'integer'); $project->addColumn('user', 'string'); - $project->setPrimaryKey(array('id')); - $project->addForeignKeyConstraint('ddc2059_user', array('user_id'), array('id')); + $project->setPrimaryKey(['id']); + $project->addForeignKeyConstraint('ddc2059_user', ['user_id'], ['id']); - $metadata = $this->convertToClassMetadata(array($project, $user), array()); + $metadata = $this->convertToClassMetadata([$project, $user], []); $this->assertTrue(isset($metadata['Ddc2059Project']->fieldMappings['user'])); $this->assertTrue(isset($metadata['Ddc2059Project']->associationMappings['user2'])); @@ -55,12 +55,12 @@ public function testLoadMetadataFromDatabase() $table = new Table("dbdriver_foo"); $table->addColumn('id', 'integer'); - $table->setPrimaryKey(array('id')); - $table->addColumn('bar', 'string', array('notnull' => false, 'length' => 200)); + $table->setPrimaryKey(['id']); + $table->addColumn('bar', 'string', ['notnull' => false, 'length' => 200]); $this->_sm->dropAndCreateTable($table); - $metadatas = $this->extractClassMetadata(array("DbdriverFoo")); + $metadatas = $this->extractClassMetadata(["DbdriverFoo"]); $this->assertArrayHasKey('DbdriverFoo', $metadatas); $metadata = $metadatas['DbdriverFoo']; @@ -86,19 +86,19 @@ public function testLoadMetadataWithForeignKeyFromDatabase() $tableB = new Table("dbdriver_bar"); $tableB->addColumn('id', 'integer'); - $tableB->setPrimaryKey(array('id')); + $tableB->setPrimaryKey(['id']); $this->_sm->dropAndCreateTable($tableB); $tableA = new Table("dbdriver_baz"); $tableA->addColumn('id', 'integer'); - $tableA->setPrimaryKey(array('id')); + $tableA->setPrimaryKey(['id']); $tableA->addColumn('bar_id', 'integer'); - $tableA->addForeignKeyConstraint('dbdriver_bar', array('bar_id'), array('id')); + $tableA->addForeignKeyConstraint('dbdriver_bar', ['bar_id'], ['id']); $this->_sm->dropAndCreateTable($tableA); - $metadatas = $this->extractClassMetadata(array("DbdriverBar", "DbdriverBaz")); + $metadatas = $this->extractClassMetadata(["DbdriverBar", "DbdriverBaz"]); $this->assertArrayHasKey('DbdriverBaz', $metadatas); $bazMetadata = $metadatas['DbdriverBaz']; @@ -118,7 +118,7 @@ public function testDetectManyToManyTables() $this->markTestSkipped('Platform does not support foreign keys.'); } - $metadatas = $this->extractClassMetadata(array("CmsUsers", "CmsGroups", "CmsTags")); + $metadatas = $this->extractClassMetadata(["CmsUsers", "CmsGroups", "CmsTags"]); $this->assertArrayHasKey('CmsUsers', $metadatas, 'CmsUsers entity was not detected.'); $this->assertArrayHasKey('CmsGroups', $metadatas, 'CmsGroups entity was not detected.'); @@ -136,18 +136,18 @@ public function testIgnoreManyToManyTableWithoutFurtherForeignKeyDetails() { $tableB = new Table("dbdriver_bar"); $tableB->addColumn('id', 'integer'); - $tableB->setPrimaryKey(array('id')); + $tableB->setPrimaryKey(['id']); $tableA = new Table("dbdriver_baz"); $tableA->addColumn('id', 'integer'); - $tableA->setPrimaryKey(array('id')); + $tableA->setPrimaryKey(['id']); $tableMany = new Table("dbdriver_bar_baz"); $tableMany->addColumn('bar_id', 'integer'); $tableMany->addColumn('baz_id', 'integer'); - $tableMany->addForeignKeyConstraint('dbdriver_bar', array('bar_id'), array('id')); + $tableMany->addForeignKeyConstraint('dbdriver_bar', ['bar_id'], ['id']); - $metadatas = $this->convertToClassMetadata(array($tableA, $tableB), array($tableMany)); + $metadatas = $this->convertToClassMetadata([$tableA, $tableB], [$tableMany]); $this->assertEquals(0, count($metadatas['DbdriverBaz']->associationMappings), "no association mappings should be detected."); } @@ -160,24 +160,24 @@ public function testLoadMetadataFromDatabaseDetail() $table = new Table("dbdriver_foo"); - $table->addColumn('id', 'integer', array('unsigned' => true)); - $table->setPrimaryKey(array('id')); - $table->addColumn('column_unsigned', 'integer', array('unsigned' => true)); - $table->addColumn('column_comment', 'string', array('comment' => 'test_comment')); - $table->addColumn('column_default', 'string', array('default' => 'test_default')); - $table->addColumn('column_decimal', 'decimal', array('precision' => 4, 'scale' => 3)); + $table->addColumn('id', 'integer', ['unsigned' => true]); + $table->setPrimaryKey(['id']); + $table->addColumn('column_unsigned', 'integer', ['unsigned' => true]); + $table->addColumn('column_comment', 'string', ['comment' => 'test_comment']); + $table->addColumn('column_default', 'string', ['default' => 'test_default']); + $table->addColumn('column_decimal', 'decimal', ['precision' => 4, 'scale' => 3]); $table->addColumn('column_index1', 'string'); $table->addColumn('column_index2', 'string'); - $table->addIndex(array('column_index1','column_index2'), 'index1'); + $table->addIndex(['column_index1','column_index2'], 'index1'); $table->addColumn('column_unique_index1', 'string'); $table->addColumn('column_unique_index2', 'string'); - $table->addUniqueIndex(array('column_unique_index1', 'column_unique_index2'), 'unique_index1'); + $table->addUniqueIndex(['column_unique_index1', 'column_unique_index2'], 'unique_index1'); $this->_sm->dropAndCreateTable($table); - $metadatas = $this->extractClassMetadata(array("DbdriverFoo")); + $metadatas = $this->extractClassMetadata(["DbdriverFoo"]); $this->assertArrayHasKey('DbdriverFoo', $metadatas); @@ -208,13 +208,13 @@ public function testLoadMetadataFromDatabaseDetail() $this->assertTrue( ! empty($metadata->table['indexes']['index1']['columns'])); $this->assertEquals( - array('column_index1','column_index2'), + ['column_index1','column_index2'], $metadata->table['indexes']['index1']['columns'] ); $this->assertTrue( ! empty($metadata->table['uniqueConstraints']['unique_index1']['columns'])); $this->assertEquals( - array('column_unique_index1', 'column_unique_index2'), + ['column_unique_index1', 'column_unique_index2'], $metadata->table['uniqueConstraints']['unique_index1']['columns'] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTestCase.php b/tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTestCase.php index 03902c40ca9..89d3cd3583c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTestCase.php +++ b/tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTestCase.php @@ -11,13 +11,13 @@ */ abstract class DatabaseDriverTestCase extends OrmFunctionalTestCase { - protected function convertToClassMetadata(array $entityTables, array $manyTables = array()) + protected function convertToClassMetadata(array $entityTables, array $manyTables = []) { $sm = $this->_em->getConnection()->getSchemaManager(); $driver = new DatabaseDriver($sm); $driver->setTables($entityTables, $manyTables); - $metadatas = array(); + $metadatas = []; foreach ($driver->getAllClassNames() AS $className) { $class = new ClassMetadataInfo($className); $driver->loadMetadataForClass($className, $class); @@ -34,7 +34,7 @@ protected function convertToClassMetadata(array $entityTables, array $manyTables protected function extractClassMetadata(array $classNames) { $classNames = array_map('strtolower', $classNames); - $metadatas = array(); + $metadatas = []; $sm = $this->_em->getConnection()->getSchemaManager(); $driver = new DatabaseDriver($sm); diff --git a/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php b/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php index e81bd7f8ac1..75c0a20e642 100644 --- a/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php @@ -14,10 +14,12 @@ protected function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\DefaultValueUser'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\DefaultValueAddress') - )); + ] + ); } catch (\Exception $e) { // Swallow all exceptions. We do not test the schema tool here. } diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityListenersTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityListenersTest.php index 89901be1969..64bc31770da 100644 --- a/tests/Doctrine/Tests/ORM/Functional/EntityListenersTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/EntityListenersTest.php @@ -31,7 +31,7 @@ public function testPreFlushListeners() $fix = new CompanyFixContract(); $fix->setFixPrice(2000); - $this->listener->preFlushCalls = array(); + $this->listener->preFlushCalls = []; $this->_em->persist($fix); $this->_em->flush(); @@ -55,12 +55,12 @@ public function testPostLoadListeners() { $fix = new CompanyFixContract(); $fix->setFixPrice(2000); - + $this->_em->persist($fix); $this->_em->flush(); $this->_em->clear(); - $this->listener->postLoadCalls = array(); + $this->listener->postLoadCalls = []; $dql = "SELECT f FROM Doctrine\Tests\Models\Company\CompanyFixContract f WHERE f.id = ?1"; $fix = $this->_em->createQuery($dql)->setParameter(1, $fix->getId())->getSingleResult(); @@ -85,7 +85,7 @@ public function testPrePersistListeners() $fix = new CompanyFixContract(); $fix->setFixPrice(2000); - $this->listener->prePersistCalls = array(); + $this->listener->prePersistCalls = []; $this->_em->persist($fix); $this->_em->flush(); @@ -110,7 +110,7 @@ public function testPostPersistListeners() $fix = new CompanyFixContract(); $fix->setFixPrice(2000); - $this->listener->postPersistCalls = array(); + $this->listener->postPersistCalls = []; $this->_em->persist($fix); $this->_em->flush(); @@ -138,8 +138,8 @@ public function testPreUpdateListeners() $this->_em->persist($fix); $this->_em->flush(); - $this->listener->preUpdateCalls = array(); - + $this->listener->preUpdateCalls = []; + $fix->setFixPrice(2000); $this->_em->persist($fix); @@ -168,7 +168,7 @@ public function testPostUpdateListeners() $this->_em->persist($fix); $this->_em->flush(); - $this->listener->postUpdateCalls = array(); + $this->listener->postUpdateCalls = []; $fix->setFixPrice(2000); @@ -198,7 +198,7 @@ public function testPreRemoveListeners() $this->_em->persist($fix); $this->_em->flush(); - $this->listener->preRemoveCalls = array(); + $this->listener->preRemoveCalls = []; $this->_em->remove($fix); $this->_em->flush(); @@ -226,7 +226,7 @@ public function testPostRemoveListeners() $this->_em->persist($fix); $this->_em->flush(); - $this->listener->postRemoveCalls = array(); + $this->listener->postRemoveCalls = []; $this->_em->remove($fix); $this->_em->flush(); @@ -245,4 +245,4 @@ public function testPostRemoveListeners() $this->listener->postRemoveCalls[0][1] ); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryCriteriaTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryCriteriaTest.php index 76e269a20dd..694ad66dab7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryCriteriaTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryCriteriaTest.php @@ -23,7 +23,7 @@ protected function setUp() public function tearDown() { if ($this->_em) { - $this->_em->getConfiguration()->setEntityNamespaces(array()); + $this->_em->getConfiguration()->setEntityNamespaces([]); } parent::tearDown(); } diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php index e0b96387a6f..2aa25b8c784 100644 --- a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php @@ -28,7 +28,7 @@ protected function setUp() public function tearDown() { if ($this->_em) { - $this->_em->getConfiguration()->setEntityNamespaces(array()); + $this->_em->getConfiguration()->setEntityNamespaces([]); } parent::tearDown(); } @@ -92,7 +92,7 @@ public function loadAssociatedFixture() $this->_em->flush(); $this->_em->clear(); - return array($user->id, $address->id); + return [$user->id, $address->id]; } public function loadFixtureUserEmail() @@ -136,7 +136,7 @@ public function loadFixtureUserEmail() $this->_em->flush(); $this->_em->clear(); - return array($user1, $user2, $user3); + return [$user1, $user2, $user3]; } public function buildUser($name, $username, $status, $address) @@ -183,7 +183,7 @@ public function testFindByField() $user1Id = $this->loadFixture(); $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); - $users = $repos->findBy(array('status' => 'dev')); + $users = $repos->findBy(['status' => 'dev']); $this->assertEquals(2, count($users)); $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser',$users[0]); $this->assertEquals('Guilherme', $users[0]->name); @@ -208,7 +208,7 @@ public function testFindByAssociationWithIntegerAsParameter() $this->_em->clear(); $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsAddress'); - $addresses = $repository->findBy(array('user' => array($user1->getId(), $user2->getId()))); + $addresses = $repository->findBy(['user' => [$user1->getId(), $user2->getId()]]); $this->assertEquals(2, count($addresses)); $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress',$addresses[0]); @@ -232,7 +232,7 @@ public function testFindByAssociationWithObjectAsParameter() $this->_em->clear(); $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsAddress'); - $addresses = $repository->findBy(array('user' => array($user1, $user2))); + $addresses = $repository->findBy(['user' => [$user1, $user2]]); $this->assertEquals(2, count($addresses)); $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress',$addresses[0]); @@ -277,13 +277,13 @@ public function testCount() $this->loadFixture(); $repos = $this->_em->getRepository(CmsUser::class); - $userCount = $repos->count(array()); + $userCount = $repos->count([]); $this->assertSame(4, $userCount); - $userCount = $repos->count(array('status' => 'dev')); + $userCount = $repos->count(['status' => 'dev']); $this->assertSame(2, $userCount); - $userCount = $repos->count(array('status' => 'nonexistent')); + $userCount = $repos->count(['status' => 'nonexistent']); $this->assertSame(0, $userCount); } @@ -405,7 +405,7 @@ public function testFindByAssociationKey_ExceptionOnInverseSide() $this->expectException(ORMException::class); $this->expectExceptionMessage("You cannot search for the association field 'Doctrine\Tests\Models\CMS\CmsUser#address', because it is the inverse side of an association. Find methods only work on owning side associations."); - $user = $repos->findBy(array('address' => $addressId)); + $user = $repos->findBy(['address' => $addressId]); } /** @@ -415,7 +415,7 @@ public function testFindOneByAssociationKey() { list($userId, $addressId) = $this->loadAssociatedFixture(); $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsAddress'); - $address = $repos->findOneBy(array('user' => $userId)); + $address = $repos->findOneBy(['user' => $userId]); $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress', $address); $this->assertEquals($addressId, $address->id); @@ -429,8 +429,8 @@ public function testFindOneByOrderBy() $this->loadFixture(); $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); - $userAsc = $repos->findOneBy(array(), array("username" => "ASC")); - $userDesc = $repos->findOneBy(array(), array("username" => "DESC")); + $userAsc = $repos->findOneBy([], ["username" => "ASC"]); + $userDesc = $repos->findOneBy([], ["username" => "DESC"]); $this->assertNotSame($userAsc, $userDesc); } @@ -442,7 +442,7 @@ public function testFindByAssociationKey() { list($userId, $addressId) = $this->loadAssociatedFixture(); $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsAddress'); - $addresses = $repos->findBy(array('user' => $userId)); + $addresses = $repos->findBy(['user' => $userId]); $this->assertContainsOnly('Doctrine\Tests\Models\CMS\CmsAddress', $addresses); $this->assertEquals(1, count($addresses)); @@ -501,11 +501,11 @@ public function testInvalidNamedQueryRetrieval() public function testIsNullCriteriaDoesNotGenerateAParameter() { $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); - $users = $repos->findBy(array('status' => null, 'username' => 'romanb')); + $users = $repos->findBy(['status' => null, 'username' => 'romanb']); $params = $this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['params']; $this->assertEquals(1, count($params), "Should only execute with one parameter."); - $this->assertEquals(array('romanb'), $params); + $this->assertEquals(['romanb'], $params); } public function testIsNullCriteria() @@ -514,7 +514,7 @@ public function testIsNullCriteria() $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); - $users = $repos->findBy(array('status' => null)); + $users = $repos->findBy(['status' => null]); $this->assertEquals(1, count($users)); } @@ -527,10 +527,10 @@ public function testFindByLimitOffset() $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); - $users1 = $repos->findBy(array(), null, 1, 0); - $users2 = $repos->findBy(array(), null, 1, 1); + $users1 = $repos->findBy([], null, 1, 0); + $users2 = $repos->findBy([], null, 1, 1); - $this->assertEquals(4, count($repos->findBy(array()))); + $this->assertEquals(4, count($repos->findBy([]))); $this->assertEquals(1, count($users1)); $this->assertEquals(1, count($users2)); $this->assertNotSame($users1[0], $users2[0]); @@ -544,8 +544,8 @@ public function testFindByOrderBy() $this->loadFixture(); $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); - $usersAsc = $repos->findBy(array(), array("username" => "ASC")); - $usersDesc = $repos->findBy(array(), array("username" => "DESC")); + $usersAsc = $repos->findBy([], ["username" => "ASC"]); + $usersDesc = $repos->findBy([], ["username" => "DESC"]); $this->assertEquals(4, count($usersAsc), "Pre-condition: only four users in fixture"); $this->assertEquals(4, count($usersDesc), "Pre-condition: only four users in fixture"); @@ -561,8 +561,8 @@ public function testFindByOrderByAssociation() $this->loadFixtureUserEmail(); $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); - $resultAsc = $repository->findBy(array(), array('email' => 'ASC')); - $resultDesc = $repository->findBy(array(), array('email' => 'DESC')); + $resultAsc = $repository->findBy([], ['email' => 'ASC']); + $resultDesc = $repository->findBy([], ['email' => 'DESC']); $this->assertCount(3, $resultAsc); $this->assertCount(3, $resultDesc); @@ -579,8 +579,8 @@ public function testFindFieldByMagicCallOrderBy() $this->loadFixture(); $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); - $usersAsc = $repos->findByStatus('dev', array('username' => "ASC")); - $usersDesc = $repos->findByStatus('dev', array('username' => "DESC")); + $usersAsc = $repos->findByStatus('dev', ['username' => "ASC"]); + $usersDesc = $repos->findByStatus('dev', ['username' => "DESC"]); $this->assertEquals(2, count($usersAsc)); $this->assertEquals(2, count($usersDesc)); @@ -601,8 +601,8 @@ public function testFindFieldByMagicCallLimitOffset() $this->loadFixture(); $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); - $users1 = $repos->findByStatus('dev', array(), 1, 0); - $users2 = $repos->findByStatus('dev', array(), 1, 1); + $users1 = $repos->findByStatus('dev', [], 1, 0); + $users2 = $repos->findByStatus('dev', [], 1, 1); $this->assertEquals(1, count($users1)); $this->assertEquals(1, count($users2)); @@ -680,7 +680,7 @@ public function testCanRetrieveRepositoryFromClassNameWithLeadingBackslash() public function testInvalidOrderByAssociation() { $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser') - ->findBy(array('status' => 'test'), array('address' => 'ASC')); + ->findBy(['status' => 'test'], ['address' => 'ASC']); } /** @@ -692,7 +692,7 @@ public function testInvalidOrientation() $this->expectExceptionMessage('Invalid order by orientation specified for Doctrine\Tests\Models\CMS\CmsUser#username'); $repo = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); - $repo->findBy(array('status' => 'test'), array('username' => 'INVALID')); + $repo->findBy(['status' => 'test'], ['username' => 'INVALID']); } /** @@ -701,10 +701,10 @@ public function testInvalidOrientation() public function testFindByAssociationArray() { $repo = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsArticle'); - $data = $repo->findBy(array('user' => array(1, 2, 3))); + $data = $repo->findBy(['user' => [1, 2, 3]]); $query = array_pop($this->_sqlLoggerStack->queries); - $this->assertEquals(array(1,2,3), $query['params'][0]); + $this->assertEquals([1,2,3], $query['params'][0]); $this->assertEquals(Connection::PARAM_INT_ARRAY, $query['types'][0]); } @@ -760,7 +760,7 @@ public function testMatchingCriteriaInComparison() $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $users = $repository->matching(new Criteria( - Criteria::expr()->in('username', array('beberlei', 'gblanco')) + Criteria::expr()->in('username', ['beberlei', 'gblanco']) )); $this->assertEquals(2, count($users)); @@ -775,7 +775,7 @@ public function testMatchingCriteriaNotInComparison() $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $users = $repository->matching(new Criteria( - Criteria::expr()->notIn('username', array('beberlei', 'gblanco', 'asm89')) + Criteria::expr()->notIn('username', ['beberlei', 'gblanco', 'asm89']) )); $this->assertEquals(1, count($users)); @@ -874,7 +874,7 @@ public function testMatchingCriteriaAssocationInWithArray() $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $userId); $criteria = new Criteria( - Criteria::expr()->in('user', array($user)) + Criteria::expr()->in('user', [$user]) ); $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsAddress'); @@ -941,7 +941,7 @@ public function testCreateResultSetMappingBuilder() $rsm = $repository->createResultSetMappingBuilder('u'); $this->assertInstanceOf('Doctrine\ORM\Query\ResultSetMappingBuilder', $rsm); - $this->assertEquals(array('u' => 'Doctrine\Tests\Models\CMS\CmsUser'), $rsm->aliasMap); + $this->assertEquals(['u' => 'Doctrine\Tests\Models\CMS\CmsUser'], $rsm->aliasMap); } /** @@ -953,7 +953,7 @@ public function testFindByFieldInjectionPrevented() $this->expectExceptionMessage('Unrecognized field: '); $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); - $repository->findBy(array('username = ?; DELETE FROM cms_users; SELECT 1 WHERE 1' => 'test')); + $repository->findBy(['username = ?; DELETE FROM cms_users; SELECT 1 WHERE 1' => 'test']); } /** @@ -965,7 +965,7 @@ public function testFindOneByFieldInjectionPrevented() $this->expectExceptionMessage('Unrecognized field: '); $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); - $repository->findOneBy(array('username = ?; DELETE FROM cms_users; SELECT 1 WHERE 1' => 'test')); + $repository->findOneBy(['username = ?; DELETE FROM cms_users; SELECT 1 WHERE 1' => 'test']); } /** @@ -994,7 +994,7 @@ public function testFindInjectionPrevented() $this->expectExceptionMessage('Unrecognized identifier fields: '); $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); - $repository->find(array('username = ?; DELETE FROM cms_users; SELECT 1 WHERE 1' => 'test', 'id' => 1)); + $repository->find(['username = ?; DELETE FROM cms_users; SELECT 1 WHERE 1' => 'test', 'id' => 1]); } /** @@ -1016,7 +1016,7 @@ public function testFindByNullValueInInCondition() $this->_em->persist($user2); $this->_em->flush(); - $users = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findBy(array('status' => array(null))); + $users = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findBy(['status' => [null]]); $this->assertCount(1, $users); $this->assertSame($user1, reset($users)); @@ -1044,7 +1044,7 @@ public function testFindByNullValueInMultipleInCriteriaValues() $users = $this ->_em ->getRepository('Doctrine\Tests\Models\CMS\CmsUser') - ->findBy(array('status' => array('foo', null))); + ->findBy(['status' => ['foo', null]]); $this->assertCount(1, $users); $this->assertSame($user1, reset($users)); @@ -1072,12 +1072,12 @@ public function testFindMultipleByNullValueInMultipleInCriteriaValues() $users = $this ->_em ->getRepository('Doctrine\Tests\Models\CMS\CmsUser') - ->findBy(array('status' => array('dbal maintainer', null))); + ->findBy(['status' => ['dbal maintainer', null]]); $this->assertCount(2, $users); foreach ($users as $user) { - $this->assertTrue(in_array($user, array($user1, $user2))); + $this->assertTrue(in_array($user, [$user1, $user2])); } } } diff --git a/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php index c8af5bd8546..c0afab02175 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php @@ -1229,7 +1229,7 @@ private function loadTweetFixture() $this->_em->flush(); $this->_em->clear(); - return array($user->id, $tweet->id); + return [$user->id, $tweet->id]; } /** @@ -1250,6 +1250,6 @@ private function loadUserListFixture() $this->_em->flush(); $this->_em->clear(); - return array($user->id, $userList->id); + return [$user->id, $userList->id]; } } diff --git a/tests/Doctrine/Tests/ORM/Functional/IdentityMapTest.php b/tests/Doctrine/Tests/ORM/Functional/IdentityMapTest.php index 94a11dab490..15929ae270d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/IdentityMapTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/IdentityMapTest.php @@ -82,7 +82,7 @@ public function testSingleValuedAssociationIdentityMapBehaviorWithRefresh() $this->assertSame($user1, $address->user); //external update to CmsAddress - $this->_em->getConnection()->executeUpdate('update cms_addresses set user_id = ?', array($user2->getId())); + $this->_em->getConnection()->executeUpdate('update cms_addresses set user_id = ?', [$user2->getId()]); // But we want to have this external change! // Solution 1: refresh(), broken atm! @@ -125,7 +125,7 @@ public function testSingleValuedAssociationIdentityMapBehaviorWithRefreshQuery() $this->assertSame($user1, $address->user); //external update to CmsAddress - $this->_em->getConnection()->executeUpdate('update cms_addresses set user_id = ?', array($user2->getId())); + $this->_em->getConnection()->executeUpdate('update cms_addresses set user_id = ?', [$user2->getId()]); //select $q = $this->_em->createQuery('select a, u from Doctrine\Tests\Models\CMS\CmsAddress a join a.user u'); @@ -181,7 +181,8 @@ public function testCollectionValuedAssociationIdentityMapBehaviorWithRefreshQue $this->assertFalse($user->getPhonenumbers()->isDirty()); //external update to CmsAddress - $this->_em->getConnection()->executeUpdate('insert into cms_phonenumbers (phonenumber, user_id) VALUES (?,?)', array(999, $user->getId())); + $this->_em->getConnection()->executeUpdate('insert into cms_phonenumbers (phonenumber, user_id) VALUES (?,?)', [999, $user->getId()] + ); //select $q = $this->_em->createQuery('select u, p from Doctrine\Tests\Models\CMS\CmsUser u join u.phonenumbers p'); @@ -232,7 +233,8 @@ public function testCollectionValuedAssociationIdentityMapBehaviorWithRefresh() $this->assertEquals(3, count($user->getPhonenumbers())); //external update to CmsAddress - $this->_em->getConnection()->executeUpdate('insert into cms_phonenumbers (phonenumber, user_id) VALUES (?,?)', array(999, $user->getId())); + $this->_em->getConnection()->executeUpdate('insert into cms_phonenumbers (phonenumber, user_id) VALUES (?,?)', [999, $user->getId()] + ); //select $q = $this->_em->createQuery('select u, p from Doctrine\Tests\Models\CMS\CmsUser u join u.phonenumbers p'); diff --git a/tests/Doctrine/Tests/ORM/Functional/JoinedTableCompositeKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/JoinedTableCompositeKeyTest.php index 8f6e0cc59fd..21f7cabde1d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/JoinedTableCompositeKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/JoinedTableCompositeKeyTest.php @@ -58,7 +58,7 @@ private function findEntity() { return $this->_em->find( 'Doctrine\Tests\Models\CompositeKeyInheritance\JoinedRootClass', - array('keyPart1' => 'part-1', 'keyPart2' => 'part-2') + ['keyPart1' => 'part-1', 'keyPart2' => 'part-2'] ); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php b/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php index 50864592751..3a31f9c52c4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php @@ -15,12 +15,14 @@ protected function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\LifecycleCallbackEventArgEntity'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\LifecycleCallbackTestEntity'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\LifecycleCallbackTestUser'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\LifecycleCallbackCascader'), - )); + ] + ); } catch (\Exception $e) { // Swallow all exceptions. We do not test the schema tool here. } @@ -270,13 +272,13 @@ public function testCascadedEntitiesNotLoadedInPostLoadDuringIterationWithSimple public function testLifecycleCallbacksGetInherited() { $childMeta = $this->_em->getClassMetadata(__NAMESPACE__ . '\LifecycleCallbackChildEntity'); - $this->assertEquals(array('prePersist' => array(0 => 'doStuff')), $childMeta->lifecycleCallbacks); + $this->assertEquals(['prePersist' => [0 => 'doStuff']], $childMeta->lifecycleCallbacks); } public function testLifecycleListener_ChangeUpdateChangeSet() { $listener = new LifecycleListenerPreUpdate; - $this->_em->getEventManager()->addEventListener(array('preUpdate'), $listener); + $this->_em->getEventManager()->addEventListener(['preUpdate'], $listener); $user = new LifecycleCallbackTestUser; $user->setName('Bob'); @@ -292,7 +294,7 @@ public function testLifecycleListener_ChangeUpdateChangeSet() $this->_em->flush(); // preUpdate reverts Alice to Bob $this->_em->clear(); - $this->_em->getEventManager()->removeEventListener(array('preUpdate'), $listener); + $this->_em->getEventManager()->removeEventListener(['preUpdate'], $listener); $bob = $this->_em->createQuery($dql)->getSingleResult(); @@ -315,7 +317,7 @@ public function testLifecycleCallbackEventArgs() $this->_em->flush(); $this->_em->refresh($e); - + $this->_em->remove($e); $this->_em->flush(); @@ -358,7 +360,7 @@ public function testLifecycleCallbackEventArgs() 'Doctrine\ORM\Event\LifecycleEventArgs', $e->calls['postUpdateHandler'] ); - + $this->assertInstanceOf( 'Doctrine\ORM\Event\LifecycleEventArgs', $e->calls['preRemoveHandler'] @@ -517,7 +519,7 @@ class LifecycleCallbackEventArgEntity /** @Column() */ public $value; - public $calls = array(); + public $calls = []; /** * @PostPersist diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php index e69d3ee6aa3..b1ace3513aa 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php @@ -23,11 +23,11 @@ protected function setUp() $this->useModelSet('cms'); parent::setUp(); - $this->tasks = array(); + $this->tasks = []; $this->gearman = new \GearmanClient(); $this->gearman->addServer(); - $this->gearman->setCompleteCallback(array($this, "gearmanTaskCompleted")); + $this->gearman->setCompleteCallback([$this, "gearmanTaskCompleted"]); $article = new CmsArticle(); $article->text = "my article"; @@ -78,7 +78,7 @@ public function testFindWithOneLock() public function testDqlWithLock() { - $this->asyncDqlWithLock('SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a', array(), LockMode::PESSIMISTIC_WRITE); + $this->asyncDqlWithLock('SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a', [], LockMode::PESSIMISTIC_WRITE); $this->asyncFindWithLock('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId, LockMode::PESSIMISTIC_WRITE); $this->assertLockWorked(); @@ -140,37 +140,42 @@ protected function assertLockWorked($forTime = 2, $notLongerThan = null) protected function asyncFindWithLock($entityName, $entityId, $lockMode) { - $this->startJob('findWithLock', array( + $this->startJob('findWithLock', [ 'entityName' => $entityName, 'entityId' => $entityId, 'lockMode' => $lockMode, - )); + ] + ); } protected function asyncDqlWithLock($dql, $params, $lockMode) { - $this->startJob('dqlWithLock', array( + $this->startJob('dqlWithLock', [ 'dql' => $dql, 'dqlParams' => $params, 'lockMode' => $lockMode, - )); + ] + ); } protected function asyncLock($entityName, $entityId, $lockMode) { - $this->startJob('lock', array( + $this->startJob('lock', [ 'entityName' => $entityName, 'entityId' => $entityId, 'lockMode' => $lockMode, - )); + ] + ); } protected function startJob($fn, $fixture) { - $this->gearman->addTask($fn, serialize(array( + $this->gearman->addTask($fn, serialize( + [ 'conn' => $this->_em->getConnection()->getParams(), 'fixture' => $fixture - ))); + ] + )); $this->assertEquals(GEARMAN_SUCCESS, $this->gearman->returnCode()); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php b/tests/Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php index 0ca10460f80..c3d226aa482 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php @@ -17,9 +17,9 @@ static public function run() $worker = new \GearmanWorker(); $worker->addServer(); - $worker->addFunction("findWithLock", array($lockAgent, "findWithLock")); - $worker->addFunction("dqlWithLock", array($lockAgent, "dqlWithLock")); - $worker->addFunction('lock', array($lockAgent, 'lock')); + $worker->addFunction("findWithLock", [$lockAgent, "findWithLock"]); + $worker->addFunction("dqlWithLock", [$lockAgent, "dqlWithLock"]); + $worker->addFunction('lock', [$lockAgent, 'lock']); while($worker->work()) { if ($worker->returnCode() != GEARMAN_SUCCESS) { @@ -98,7 +98,7 @@ protected function createEntityManager($conn) $config->setProxyNamespace('MyProject\Proxies'); $config->setAutoGenerateProxyClasses(true); - $annotDriver = $config->newDefaultAnnotationDriver(array(__DIR__ . '/../../../Models/'), true); + $annotDriver = $config->newDefaultAnnotationDriver([__DIR__ . '/../../../Models/'], true); $config->setMetadataDriverImpl($annotDriver); $cache = new ArrayCache(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php index 8ac9bfefcb8..e92b9476baa 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php @@ -19,7 +19,7 @@ protected function setUp() { $this->useModelSet('cms'); parent::setUp(); - $this->handles = array(); + $this->handles = []; } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php index e4cad517168..ff1502daace 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php @@ -14,12 +14,14 @@ protected function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Locking\OptimisticJoinedParent'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Locking\OptimisticJoinedChild'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Locking\OptimisticStandard'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Locking\OptimisticTimestamp') - )); + ] + ); } catch (\Exception $e) { // Swallow all exceptions. We do not test the schema tool here. } @@ -55,7 +57,7 @@ public function testJoinedChildFailureThrowsException(OptimisticJoinedChild $chi // Manually update/increment the version so we can try and save the same // $test and make sure the exception is thrown saying the record was // changed or updated since you read it - $this->_conn->executeQuery('UPDATE optimistic_joined_parent SET version = ? WHERE id = ?', array(2, $test->id)); + $this->_conn->executeQuery('UPDATE optimistic_joined_parent SET version = ? WHERE id = ?', [2, $test->id]); // Now lets change a property and try and save it again $test->whatever = 'ok'; @@ -95,7 +97,7 @@ public function testJoinedParentFailureThrowsException(OptimisticJoinedParent $p // Manually update/increment the version so we can try and save the same // $test and make sure the exception is thrown saying the record was // changed or updated since you read it - $this->_conn->executeQuery('UPDATE optimistic_joined_parent SET version = ? WHERE id = ?', array(2, $test->id)); + $this->_conn->executeQuery('UPDATE optimistic_joined_parent SET version = ? WHERE id = ?', [2, $test->id]); // Now lets change a property and try and save it again $test->name = 'WHATT???'; @@ -151,7 +153,7 @@ public function testStandardFailureThrowsException(OptimisticStandard $entity) // Manually update/increment the version so we can try and save the same // $test and make sure the exception is thrown saying the record was // changed or updated since you read it - $this->_conn->executeQuery('UPDATE optimistic_standard SET version = ? WHERE id = ?', array(2, $test->id)); + $this->_conn->executeQuery('UPDATE optimistic_standard SET version = ? WHERE id = ?', [2, $test->id]); // Now lets change a property and try and save it again $test->name = 'WHATT???'; @@ -210,7 +212,8 @@ public function testOptimisticTimestampFailureThrowsException(OptimisticTimestam // Manually increment the version datetime column $format = $this->_em->getConnection()->getDatabasePlatform()->getDateTimeFormatString(); - $this->_conn->executeQuery('UPDATE optimistic_timestamp SET version = ? WHERE id = ?', array(date($format, strtotime($test->version->format($format)) + 3600), $test->id)); + $this->_conn->executeQuery('UPDATE optimistic_timestamp SET version = ? WHERE id = ?', [date($format, strtotime($test->version->format($format)) + 3600), $test->id] + ); // Try and update the record and it should throw an exception $caughtException = null; diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php index 2d051b68831..b6d5957a23e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php @@ -330,7 +330,7 @@ public function testClearAndResetCollection() $user = $this->_em->find(get_class($user), $user->id); - $coll = new ArrayCollection(array($group1, $group2)); + $coll = new ArrayCollection([$group1, $group2]); $user->groups = $coll; $this->_em->flush(); $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $user->groups, diff --git a/tests/Doctrine/Tests/ORM/Functional/MergeCompositeToOneKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/MergeCompositeToOneKeyTest.php index 9b3b338a083..48263f3c45a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/MergeCompositeToOneKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/MergeCompositeToOneKeyTest.php @@ -15,10 +15,12 @@ protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(Country::CLASSNAME), $this->_em->getClassMetadata(CompositeToOneKeyState::CLASSNAME), - )); + ] + ); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php b/tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php index 42bf4187e52..e32b0385cde 100644 --- a/tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php @@ -239,7 +239,7 @@ private function createEntityManager(SQLLogger $logger) $config->setProxyDir(realpath(__DIR__ . '/../../Proxies')); $config->setProxyNamespace('Doctrine\Tests\Proxies'); $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver( - array(realpath(__DIR__ . '/../../Models/Cache')), + [realpath(__DIR__ . '/../../Models/Cache')], true )); $config->setSQLLogger($logger); @@ -248,10 +248,10 @@ private function createEntityManager(SQLLogger $logger) // multi-connection is not relevant for the purpose of checking locking here, but merely // to stub out DB-level access and intercept it $connection = DriverManager::getConnection( - array( + [ 'driver' => 'pdo_sqlite', 'memory' => true - ), + ], $config ); diff --git a/tests/Doctrine/Tests/ORM/Functional/MergeSharedEntitiesTest.php b/tests/Doctrine/Tests/ORM/Functional/MergeSharedEntitiesTest.php index ffe64fcff0a..e77b396947b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/MergeSharedEntitiesTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/MergeSharedEntitiesTest.php @@ -15,10 +15,12 @@ protected function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\MSEFile'), $this->_em->getClassMetadata(__NAMESPACE__ . '\MSEPicture'), - )); + ] + ); } catch (ToolsException $ignored) { } } diff --git a/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php b/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php index 320aa357ac0..9d9eb233d08 100644 --- a/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php @@ -281,7 +281,8 @@ public function testJoinedOneToOneNativeQueryWithRSMBuilder() $rsm = new ResultSetMappingBuilder($this->_em); $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsUser', 'u'); - $rsm->addJoinedEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', 'a', 'u', 'address', array('id' => 'a_id')); + $rsm->addJoinedEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', 'a', 'u', 'address', ['id' => 'a_id'] + ); $query = $this->_em->createNativeQuery('SELECT u.*, a.*, a.id AS a_id FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id WHERE u.username = ?', $rsm); $query->setParameter(1, 'romanb'); @@ -349,7 +350,8 @@ public function testUnknownParentAliasThrowsException() { $rsm = new ResultSetMappingBuilder($this->_em); $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsUser', 'u'); - $rsm->addJoinedEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', 'a', 'un', 'address', array('id' => 'a_id')); + $rsm->addJoinedEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', 'a', 'un', 'address', ['id' => 'a_id'] + ); $query = $this->_em->createNativeQuery('SELECT u.*, a.*, a.id AS a_id FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id WHERE u.username = ?', $rsm); $query->setParameter(1, 'romanb'); @@ -558,7 +560,7 @@ public function testMixedNativeNamedQueryNormalJoin() $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $result = $repository->createNativeNamedQuery('fetchUserPhonenumberCount') - ->setParameter(1, array('test','FabioBatSilva'))->getResult(); + ->setParameter(1, ['test','FabioBatSilva'])->getResult(); $this->assertEquals(2, count($result)); $this->assertTrue(is_array($result[0])); @@ -746,10 +748,11 @@ public function testGenerateSelectClauseNoRenameSingleEntity() public function testGenerateSelectClauseCustomRenames() { $rsm = new ResultSetMappingBuilder($this->_em); - $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsUser', 'u', array( + $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsUser', 'u', [ 'id' => 'id1', 'username' => 'username2' - )); + ] + ); $selectClause = $rsm->generateSelectClause(); @@ -764,7 +767,7 @@ public function testGenerateSelectClauseRenameTableAlias() $rsm = new ResultSetMappingBuilder($this->_em); $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsUser', 'u'); - $selectClause = $rsm->generateSelectClause(array('u' => 'u1')); + $selectClause = $rsm->generateSelectClause(['u' => 'u1']); $this->assertSQLEquals('u1.id AS id, u1.status AS status, u1.username AS username, u1.name AS name, u1.email_id AS email_id', $selectClause); } @@ -804,7 +807,7 @@ public function testGenerateSelectClauseWithDiscriminatorColumn() $rsm->addFieldResult('u', $this->platform->getSQLResultCasing('id'), 'id'); $rsm->setDiscriminatorColumn('c', $this->platform->getSQLResultCasing('discr')); - $selectClause = $rsm->generateSelectClause(array('u' => 'u1', 'c' => 'c1')); + $selectClause = $rsm->generateSelectClause(['u' => 'u1', 'c' => 'c1']); $this->assertSQLEquals('u1.id as id, c1.discr as discr', $selectClause); } diff --git a/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php b/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php index 37067aec075..972412199de 100644 --- a/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php @@ -18,7 +18,7 @@ class NewOperatorTest extends OrmFunctionalTestCase * @var array */ private $fixtures; - + protected function setUp() { $this->useModelSet('cms'); @@ -26,13 +26,13 @@ protected function setUp() $this->loadFixtures(); } - + public function provideDataForHydrationMode() { - return array( - array(Query::HYDRATE_ARRAY), - array(Query::HYDRATE_OBJECT), - ); + return [ + [Query::HYDRATE_ARRAY], + [Query::HYDRATE_OBJECT], + ]; } private function loadFixtures() @@ -93,7 +93,7 @@ private function loadFixtures() $this->_em->flush(); $this->_em->clear(); - $this->fixtures = array($u1, $u2, $u3); + $this->fixtures = [$u1, $u2, $u3]; } /** @@ -223,7 +223,7 @@ public function testShouldSupportFromEntityNamespaceAlias() $this->_em->getConfiguration() ->addEntityNamespace('cms', 'Doctrine\Tests\Models\CMS'); - + $query = $this->_em->createQuery($dql); $result = $query->getResult(); diff --git a/tests/Doctrine/Tests/ORM/Functional/NotifyPolicyTest.php b/tests/Doctrine/Tests/ORM/Functional/NotifyPolicyTest.php index ecebc28d9e3..a289ef9dd80 100644 --- a/tests/Doctrine/Tests/ORM/Functional/NotifyPolicyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/NotifyPolicyTest.php @@ -18,10 +18,12 @@ protected function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\NotifyUser'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\NotifyGroup') - )); + ] + ); } catch (\Exception $e) { // Swallow all exceptions. We do not test the schema tool here. } @@ -91,7 +93,7 @@ public function testChangeTracking() } class NotifyBaseEntity implements NotifyPropertyChanged { - public $listeners = array(); + public $listeners = []; public function addPropertyChangedListener(PropertyChangedListener $listener) { $this->listeners[] = $listener; diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php index 8327142fda6..ddc7378f7a1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php @@ -232,7 +232,7 @@ private function _createFixture() public function assertFeatureForeignKeyIs($value, ECommerceFeature $feature) { $foreignKey = $this->_em->getConnection()->executeQuery( 'SELECT product_id FROM ecommerce_features WHERE id=?', - array($feature->getId()) + [$feature->getId()] )->fetchColumn(); $this->assertEquals($value, $foreignKey); } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php index 3d6c688bd2e..f6b64b5eb0a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php @@ -116,7 +116,8 @@ private function _createFixture() } public function assertForeignKeyIs($value, ECommerceCategory $child) { - $foreignKey = $this->_em->getConnection()->executeQuery('SELECT parent_id FROM ecommerce_categories WHERE id=?', array($child->getId()))->fetchColumn(); + $foreignKey = $this->_em->getConnection()->executeQuery('SELECT parent_id FROM ecommerce_categories WHERE id=?', [$child->getId()] + )->fetchColumn(); $this->assertEquals($value, $foreignKey); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManyUnidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManyUnidirectionalAssociationTest.php index e2c66311817..c13a6fe9971 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToManyUnidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToManyUnidirectionalAssociationTest.php @@ -12,14 +12,14 @@ */ class OneToManyUnidirectionalAssociationTest extends OrmFunctionalTestCase { - protected $locations = array(); + protected $locations = []; public function setUp() { $this->useModelSet('routing'); parent::setUp(); - $locations = array("Berlin", "Bonn", "Brasilia", "Atlanta"); + $locations = ["Berlin", "Bonn", "Brasilia", "Atlanta"]; foreach ($locations AS $locationName) { $location = new RoutingLocation(); diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php index 6d42e76348d..d2880ee81c3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php @@ -144,7 +144,8 @@ protected function _createFixture() } public function assertCartForeignKeyIs($value) { - $foreignKey = $this->_em->getConnection()->executeQuery('SELECT customer_id FROM ecommerce_carts WHERE id=?', array($this->cart->getId()))->fetchColumn(); + $foreignKey = $this->_em->getConnection()->executeQuery('SELECT customer_id FROM ecommerce_carts WHERE id=?', [$this->cart->getId()] + )->fetchColumn(); $this->assertEquals($value, $foreignKey); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php index 522a009eba8..8a99210020a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php @@ -15,13 +15,15 @@ protected function setUp() parent::setUp(); $schemaTool = new SchemaTool($this->_em); try { - $schemaTool->createSchema(array( + $schemaTool->createSchema( + [ $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Train'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\TrainDriver'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\TrainOwner'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Waggon'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\TrainOrder'), - )); + ] + ); } catch(\Exception $e) {} } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php index cad28d4c3c1..bc7897f6a54 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php @@ -86,9 +86,11 @@ public function testLazyLoadsAssociation() public function testMultiSelfReference() { try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\MultiSelfReference') - )); + ] + ); } catch (\Exception $e) { // Swallow all exceptions. We do not test the schema tool here. } @@ -118,7 +120,8 @@ public function assertLoadingOfAssociation($customer) } public function assertForeignKeyIs($value) { - $foreignKey = $this->_em->getConnection()->executeQuery('SELECT mentor_id FROM ecommerce_customers WHERE id=?', array($this->customer->getId()))->fetchColumn(); + $foreignKey = $this->_em->getConnection()->executeQuery('SELECT mentor_id FROM ecommerce_customers WHERE id=?', [$this->customer->getId()] + )->fetchColumn(); $this->assertEquals($value, $foreignKey); } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php index 60b5b36567b..2ffbfa44330 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php @@ -101,7 +101,7 @@ protected function _createFixture() public function assertForeignKeyIs($value) { $foreignKey = $this->_em->getConnection()->executeQuery( 'SELECT shipping_id FROM ecommerce_products WHERE id=?', - array($this->product->getId()) + [$this->product->getId()] )->fetchColumn(); $this->assertEquals($value, $foreignKey); } diff --git a/tests/Doctrine/Tests/ORM/Functional/OrderedCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/OrderedCollectionTest.php index c4e5dca7018..5d5c54e24e4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OrderedCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OrderedCollectionTest.php @@ -10,14 +10,14 @@ class OrderedCollectionTest extends OrmFunctionalTestCase { - protected $locations = array(); + protected $locations = []; public function setUp() { $this->useModelSet('routing'); parent::setUp(); - $locations = array("Berlin", "Bonn", "Brasilia", "Atlanta"); + $locations = ["Berlin", "Bonn", "Brasilia", "Atlanta"]; foreach ($locations AS $locationName) { $location = new RoutingLocation(); diff --git a/tests/Doctrine/Tests/ORM/Functional/OrderedJoinedTableInheritanceCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/OrderedJoinedTableInheritanceCollectionTest.php index b3d85340e97..d71bfb0b4c8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OrderedJoinedTableInheritanceCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OrderedJoinedTableInheritanceCollectionTest.php @@ -16,11 +16,13 @@ protected function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\OJTIC_Pet'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\OJTIC_Cat'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\OJTIC_Dog'), - )); + ] + ); } catch (\Exception $e) { // Swallow all exceptions. We do not test the schema tool here. } diff --git a/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php b/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php index 8afe9d3323d..dcf44ce4565 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php @@ -633,14 +633,15 @@ public function testQueryWalkerIsKept() { $dql = 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u'; $query = $this->_em->createQuery($dql); - $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\Tests\ORM\Functional\CustomPaginationTestTreeWalker')); + $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\Tests\ORM\Functional\CustomPaginationTestTreeWalker'] + ); $paginator = new Paginator($query, true); $paginator->setUseOutputWalkers(false); $this->assertCount(1, $paginator->getIterator()); $this->assertEquals(1, $paginator->count()); } - + public function testCountQueryStripsParametersInSelect() { $query = $this->_em->createQuery( @@ -695,7 +696,7 @@ public function testPaginationWithSubSelectOrderByExpression($useOutputWalker, $ public function populate() { - $groups = array(); + $groups = []; for ($j = 0; $j < 3; $j++) {; $group = new CmsGroup(); $group->name = "group$j"; @@ -762,28 +763,28 @@ public function populate() public function useOutputWalkers() { - return array( - array(true), - array(false), - ); + return [ + [true], + [false], + ]; } public function fetchJoinCollection() { - return array( - array(true), - array(false), - ); + return [ + [true], + [false], + ]; } public function useOutputWalkersAndFetchJoinCollection() { - return array( - array(true, false), - array(true, true), - array(false, false), - array(false, true), - ); + return [ + [true, false], + [true, true], + [false, false], + [false, true], + ]; } } diff --git a/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php b/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php index a730546d61f..99a04d52b6c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php @@ -24,7 +24,7 @@ protected function setUp() public function tearDown() { if ($this->_em) { - $this->_em->getConfiguration()->setEntityNamespaces(array()); + $this->_em->getConfiguration()->setEntityNamespaces([]); } parent::tearDown(); } @@ -75,7 +75,7 @@ public function testCanCountWithoutLoadingPersistentCollection() $repository = $this->_em->getRepository('Doctrine\Tests\Models\Tweet\User'); - $user = $repository->findOneBy(array('name' => 'ngal')); + $user = $repository->findOneBy(['name' => 'ngal']); $tweets = $user->tweets->matching(new Criteria()); $this->assertInstanceOf('Doctrine\ORM\LazyCriteriaCollection', $tweets); diff --git a/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php index d3d22825b02..3eac4263cee 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php @@ -13,10 +13,12 @@ protected function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\PersistentCollectionHolder'), $this->_em->getClassMetadata(__NAMESPACE__ . '\PersistentCollectionContent'), - )); + ] + ); } catch (\Exception $e) { } diff --git a/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php b/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php index 861b2922510..459c0549c3e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php @@ -17,9 +17,11 @@ protected function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\PersistentEntity'), - )); + ] + ); } catch (\Exception $e) { } diff --git a/tests/Doctrine/Tests/ORM/Functional/PostLoadEventTest.php b/tests/Doctrine/Tests/ORM/Functional/PostLoadEventTest.php index b6fb57964c3..0debc2ca6c8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PostLoadEventTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PostLoadEventTest.php @@ -46,7 +46,7 @@ public function testLoadedEntityUsingFindShouldTriggerEvent() $eventManager = $this->_em->getEventManager(); - $eventManager->addEventListener(array(Events::postLoad), $mockListener); + $eventManager->addEventListener([Events::postLoad], $mockListener); $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); } @@ -63,7 +63,7 @@ public function testLoadedEntityUsingQueryShouldTriggerEvent() $eventManager = $this->_em->getEventManager(); - $eventManager->addEventListener(array(Events::postLoad), $mockListener); + $eventManager->addEventListener([Events::postLoad], $mockListener); $query = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :id'); @@ -83,7 +83,7 @@ public function testLoadedAssociationToOneShouldTriggerEvent() $eventManager = $this->_em->getEventManager(); - $eventManager->addEventListener(array(Events::postLoad), $mockListener); + $eventManager->addEventListener([Events::postLoad], $mockListener); $query = $this->_em->createQuery('SELECT u, e FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.email e WHERE u.id = :id'); @@ -103,7 +103,7 @@ public function testLoadedAssociationToManyShouldTriggerEvent() $eventManager = $this->_em->getEventManager(); - $eventManager->addEventListener(array(Events::postLoad), $mockListener); + $eventManager->addEventListener([Events::postLoad], $mockListener); $query = $this->_em->createQuery('SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.phonenumbers p WHERE u.id = :id'); @@ -123,12 +123,12 @@ public function testLoadedProxyEntityShouldTriggerEvent() ->method('postLoad') ->will($this->returnValue(true)); - $eventManager->addEventListener(array(Events::postLoad), $mockListener); + $eventManager->addEventListener([Events::postLoad], $mockListener); $userProxy = $this->_em->getReference('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); // Now deactivate original listener and attach new one - $eventManager->removeEventListener(array(Events::postLoad), $mockListener); + $eventManager->removeEventListener([Events::postLoad], $mockListener); $mockListener2 = $this->createMock(PostLoadListener::class); @@ -137,7 +137,7 @@ public function testLoadedProxyEntityShouldTriggerEvent() ->method('postLoad') ->will($this->returnValue(true)); - $eventManager->addEventListener(array(Events::postLoad), $mockListener2); + $eventManager->addEventListener([Events::postLoad], $mockListener2); $userProxy->getName(); } @@ -155,7 +155,7 @@ public function testLoadedProxyPartialShouldTriggerEvent() ->method('postLoad') ->will($this->returnValue(true)); - $eventManager->addEventListener(array(Events::postLoad), $mockListener); + $eventManager->addEventListener([Events::postLoad], $mockListener); $query = $this->_em->createQuery('SELECT PARTIAL u.{id, name}, p FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.phonenumbers p WHERE u.id = :id'); @@ -177,7 +177,7 @@ public function testLoadedProxyAssociationToOneShouldTriggerEvent() $eventManager = $this->_em->getEventManager(); - $eventManager->addEventListener(array(Events::postLoad), $mockListener); + $eventManager->addEventListener([Events::postLoad], $mockListener); $emailProxy = $user->getEmail(); @@ -198,7 +198,7 @@ public function testLoadedProxyAssociationToManyShouldTriggerEvent() $eventManager = $this->_em->getEventManager(); - $eventManager->addEventListener(array(Events::postLoad), $mockListener); + $eventManager->addEventListener([Events::postLoad], $mockListener); $phonenumbersCol = $user->getPhonenumbers(); @@ -211,7 +211,7 @@ public function testLoadedProxyAssociationToManyShouldTriggerEvent() public function testAssociationsArePopulatedWhenEventIsFired() { $checkerListener = new PostLoadListenerCheckAssociationsArePopulated(); - $this->_em->getEventManager()->addEventListener(array(Events::postLoad), $checkerListener); + $this->_em->getEventManager()->addEventListener([Events::postLoad], $checkerListener); $qb = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->createQueryBuilder('u'); $qb->leftJoin('u.email', 'email'); @@ -229,7 +229,7 @@ public function testEventRaisedCorrectTimesWhenOtherEntityLoadedInEventHandler() { $eventManager = $this->_em->getEventManager(); $listener = new PostLoadListenerLoadEntityInEventHandler(); - $eventManager->addEventListener(array(Events::postLoad), $listener); + $eventManager->addEventListener([Events::postLoad], $listener); $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); $this->assertSame(1, $listener->countHandledEvents('Doctrine\Tests\Models\CMS\CmsUser'), 'Doctrine\Tests\Models\CMS\CmsUser should be handled once!'); @@ -303,7 +303,7 @@ public function postLoad(LifecycleEventArgs $event) class PostLoadListenerLoadEntityInEventHandler { - private $firedByClasses = array(); + private $firedByClasses = []; public function postLoad(LifecycleEventArgs $event) { diff --git a/tests/Doctrine/Tests/ORM/Functional/ProxiesLikeEntitiesTest.php b/tests/Doctrine/Tests/ORM/Functional/ProxiesLikeEntitiesTest.php index 1528404dfdd..7d9fbce9d0f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ProxiesLikeEntitiesTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ProxiesLikeEntitiesTest.php @@ -24,14 +24,16 @@ protected function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsArticle'), $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'), $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsEmail'), $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsGroup'), - )); + ] + ); } catch (\Exception $e) { } $this->user = new CmsUser(); @@ -48,7 +50,7 @@ protected function setUp() public function testPersistUpdate() { // Considering case (a) - $proxy = $this->_em->getProxyFactory()->getProxy('Doctrine\Tests\Models\CMS\CmsUser', array('id' => 123)); + $proxy = $this->_em->getProxyFactory()->getProxy('Doctrine\Tests\Models\CMS\CmsUser', ['id' => 123]); $proxy->__isInitialized__ = true; $proxy->id = null; $proxy->username = 'ocra'; @@ -87,7 +89,8 @@ public function testEntityWithIdentifier() */ public function testProxyAsDqlParameterPersist() { - $proxy = $this->_em->getProxyFactory()->getProxy('Doctrine\Tests\Models\CMS\CmsUser', array('id' => $this->user->getId())); + $proxy = $this->_em->getProxyFactory()->getProxy('Doctrine\Tests\Models\CMS\CmsUser', ['id' => $this->user->getId()] + ); $proxy->id = $this->user->getId(); $result = $this ->_em @@ -117,7 +120,7 @@ public function testFindWithProxyName() $result = $this ->_em ->getRepository('Doctrine\Tests\Proxies\__CG__\Doctrine\Tests\Models\CMS\CmsUser') - ->findOneBy(array('username' => $this->user->username)); + ->findOneBy(['username' => $this->user->username]); $this->assertSame($this->user->getId(), $result->getId()); $this->_em->clear(); $result = $this @@ -133,4 +136,4 @@ protected function tearDown() { $this->_em->createQuery('DELETE FROM Doctrine\Tests\Models\CMS\CmsUser u')->execute(); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php index bdfe766ce34..6eec3609fa3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php @@ -128,7 +128,7 @@ public function testQueryCache_HitDoesNotSaveParserResult() $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); $sqlExecMock = $this->getMockBuilder(AbstractSqlExecutor::class) - ->setMethods(array('execute')) + ->setMethods(['execute']) ->getMock(); $sqlExecMock->expects($this->once()) @@ -136,14 +136,14 @@ public function testQueryCache_HitDoesNotSaveParserResult() ->will($this->returnValue( 10 )); $parserResultMock = $this->getMockBuilder(ParserResult::class) - ->setMethods(array('getSqlExecutor')) + ->setMethods(['getSqlExecutor']) ->getMock(); $parserResultMock->expects($this->once()) ->method('getSqlExecutor') ->will($this->returnValue($sqlExecMock)); $cache = $this->getMockBuilder(CacheProvider::class) - ->setMethods(array('doFetch', 'doContains', 'doSave', 'doDelete', 'doFlush', 'doGetStats')) + ->setMethods(['doFetch', 'doContains', 'doSave', 'doDelete', 'doFlush', 'doGetStats']) ->getMock(); $cache->expects($this->at(0))->method('doFetch')->will($this->returnValue(1)); diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php index f234095060d..8d0ad2d8dc1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php @@ -174,8 +174,8 @@ public function testSetParameters() public function testSetParametersBackwardsCompatible() { $q = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = ?1 AND u.status = ?2'); - $q->setParameters(array(1 => 'jwage', 2 => 'active')); - + $q->setParameters([1 => 'jwage', 2 => 'active']); + $users = $q->getResult(); } @@ -200,16 +200,17 @@ public function testIterateResultAsArrayAndParams() $articleId = $article1->id; $query = $this->_em->createQuery("select a from Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.topic = ?1"); - $articles = $query->iterate(new ArrayCollection(array(new Parameter(1, 'Doctrine 2'))), Query::HYDRATE_ARRAY); + $articles = $query->iterate(new ArrayCollection([new Parameter(1, 'Doctrine 2')]), Query::HYDRATE_ARRAY); - $found = array(); + $found = []; foreach ($articles AS $article) { $found[] = $article; } $this->assertEquals(1, count($found)); - $this->assertEquals(array( - array(array('id' => $articleId, 'topic' => 'Doctrine 2', 'text' => 'This is an introduction to Doctrine 2.', 'version' => 1)) - ), $found); + $this->assertEquals( + [ + [['id' => $articleId, 'topic' => 'Doctrine 2', 'text' => 'This is an introduction to Doctrine 2.', 'version' => 1]] + ], $found); } public function testIterateResult_IterativelyBuildUpUnitOfWork() @@ -232,7 +233,7 @@ public function testIterateResult_IterativelyBuildUpUnitOfWork() $articles = $query->iterate(); $iteratedCount = 0; - $topics = array(); + $topics = []; foreach($articles AS $row) { $article = $row[0]; $topics[] = $article->topic; @@ -244,7 +245,7 @@ public function testIterateResult_IterativelyBuildUpUnitOfWork() $iteratedCount++; } - $this->assertEquals(array("Doctrine 2", "Symfony 2"), $topics); + $this->assertEquals(["Doctrine 2", "Symfony 2"], $topics); $this->assertEquals(2, $iteratedCount); $this->_em->flush(); @@ -271,7 +272,7 @@ public function testIterateResultClearEveryCycle() $articles = $query->iterate(); $iteratedCount = 0; - $topics = array(); + $topics = []; foreach($articles AS $row) { $article = $row[0]; $topics[] = $article->topic; @@ -281,7 +282,7 @@ public function testIterateResultClearEveryCycle() $iteratedCount++; } - $this->assertEquals(array("Doctrine 2", "Symfony 2"), $topics); + $this->assertEquals(["Doctrine 2", "Symfony 2"], $topics); $this->assertEquals(2, $iteratedCount); $this->_em->flush(); @@ -394,7 +395,7 @@ public function testSupportsQueriesWithEntityNamespaces() $this->fail($e->getMessage()); } - $this->_em->getConfiguration()->setEntityNamespaces(array()); + $this->_em->getConfiguration()->setEntityNamespaces([]); } /** @@ -502,7 +503,7 @@ public function testgetOneOrNullResultSeveralRows() $query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u"); $this->expectException(NonUniqueResultException::class); - + $fetchedUser = $query->getOneOrNullResult(); } @@ -545,10 +546,12 @@ public function testParameterOrder() $this->_em->clear(); $query = $this->_em->createQuery("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.status = :a AND u.id IN (:b)"); - $query->setParameters(new ArrayCollection(array( - new Parameter('b', array($user1->id, $user2->id, $user3->id)), + $query->setParameters(new ArrayCollection( + [ + new Parameter('b', [$user1->id, $user2->id, $user3->id]), new Parameter('a', 'developer') - ))); + ] + )); $result = $query->getResult(); $this->assertEquals(3, count($result)); @@ -578,7 +581,7 @@ public function testDqlWithAutoInferOfParameters() $this->_em->clear(); $query = $this->_em->createQuery("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username IN (?0)"); - $query->setParameter(0, array('beberlei', 'jwage')); + $query->setParameter(0, ['beberlei', 'jwage']); $users = $query->execute(); @@ -623,7 +626,7 @@ public function testQueryWithArrayOfEntitiesAsParameter() $this->_em->clear(); $query = $this->_em->createQuery("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u IN (?0) OR u.username = ?1"); - $query->setParameter(0, array($userA, $userC)); + $query->setParameter(0, [$userA, $userC]); $query->setParameter(1, 'beberlei'); $users = $query->execute(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ReadOnlyTest.php b/tests/Doctrine/Tests/ORM/Functional/ReadOnlyTest.php index dd8a23ff374..9eacc7a9c3c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ReadOnlyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ReadOnlyTest.php @@ -15,9 +15,11 @@ protected function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\ReadOnlyEntity'), - )); + ] + ); } catch(\Exception $e) { } } diff --git a/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php b/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php index 4baeed9f1b9..b7116a3cd7c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php @@ -57,7 +57,7 @@ public function testLazyLoadsFieldValuesFromDatabase() { $id = $this->createProduct(); - $productProxy = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct', array('id' => $id)); + $productProxy = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct', ['id' => $id]); $this->assertEquals('Doctrine Cookbook', $productProxy->getName()); } @@ -189,7 +189,7 @@ public function testDoNotInitializeProxyOnGettingTheIdentifier_DDC_1625() $this->assertEquals($id, $entity->getId()); $this->assertFalse($entity->__isInitialized__, "Getting the identifier doesn't initialize the proxy when extending."); } - + public function testDoNotInitializeProxyOnGettingTheIdentifierAndReturnTheRightType() { $product = new ECommerceProduct(); diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index 5fccc0bdb81..42db029060d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -92,7 +92,7 @@ public function testEntityManagerEnabledFilters() $em = $this->_getEntityManager(); // No enabled filters - $this->assertEquals(array(), $em->getFilters()->getEnabledFilters()); + $this->assertEquals([], $em->getFilters()->getEnabledFilters()); $this->configureFilters($em); $filter = $em->getFilters()->enable("locale"); @@ -170,11 +170,11 @@ public function testEntityManagerIsFilterEnabled() // Check for a disabled filter $em->getFilters()->disable("locale"); $this->assertFalse($em->getFilters()->isEnabled("locale")); - + // Check a non-existing filter - $this->assertFalse($em->getFilters()->isEnabled("foo_filter")); + $this->assertFalse($em->getFilters()->isEnabled("foo_filter")); } - + protected function configureFilters($em) { // Add filters to the configuration of the EM @@ -322,10 +322,10 @@ public function testSQLFilterToString() $filter2->setParameter('foo', 'bar', DBALType::STRING); $filter2->setParameter('locale', 'en', DBALType::STRING); - $parameters = array( - 'foo' => array('value' => 'bar', 'type' => DBALType::STRING), - 'locale' => array('value' => 'en', 'type' => DBALType::STRING), - ); + $parameters = [ + 'foo' => ['value' => 'bar', 'type' => DBALType::STRING], + 'locale' => ['value' => 'en', 'type' => DBALType::STRING], + ]; $this->assertEquals(serialize($parameters), ''.$filter); $this->assertEquals(''.$filter, ''.$filter2); @@ -399,12 +399,16 @@ public function testRepositoryFindBy() { $this->loadFixtureData(); - $this->assertCount(1, $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findBy(array('id' => $this->groupId2))); + $this->assertCount(1, $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findBy( + ['id' => $this->groupId2] + )); $this->useCMSGroupPrefixFilter(); $this->_em->clear(); - $this->assertCount(0, $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findBy(array('id' => $this->groupId2))); + $this->assertCount(0, $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findBy( + ['id' => $this->groupId2] + )); } public function testRepositoryFindByX() @@ -423,12 +427,16 @@ public function testRepositoryFindOneBy() { $this->loadFixtureData(); - $this->assertNotNull($this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findOneBy(array('id' => $this->groupId2))); + $this->assertNotNull($this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findOneBy( + ['id' => $this->groupId2] + )); $this->useCMSGroupPrefixFilter(); $this->_em->clear(); - $this->assertNull($this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findOneBy(array('id' => $this->groupId2))); + $this->assertNull($this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findOneBy( + ['id' => $this->groupId2] + )); } public function testRepositoryFindOneByX() diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/CompanySchemaTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/CompanySchemaTest.php index 32c75d25de6..66eee731af4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/CompanySchemaTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/CompanySchemaTest.php @@ -59,9 +59,11 @@ public function testDropPartSchemaWithForeignKeys() $this->markTestSkipped("Foreign Key test"); } - $sql = $this->_schemaTool->getDropSchemaSQL(array( + $sql = $this->_schemaTool->getDropSchemaSQL( + [ $this->_em->getClassMetadata('Doctrine\Tests\Models\Company\CompanyManager'), - )); + ] + ); $this->assertEquals(4, count($sql)); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DBAL483Test.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DBAL483Test.php index 22debe96212..54caeb34a6d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DBAL483Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DBAL483Test.php @@ -23,9 +23,9 @@ public function testDefaultValueIsComparedCorrectly() { $class = $this->_em->getClassMetadata(__NAMESPACE__ . '\\DBAL483Default'); - $this->schemaTool->createSchema(array($class)); + $this->schemaTool->createSchema([$class]); - $updateSql = $this->schemaTool->getUpdateSchemaSql(array($class)); + $updateSql = $this->schemaTool->getUpdateSchemaSql([$class]); $updateSql = array_filter($updateSql, function ($sql) { return strpos($sql, 'DBAL483') !== false; diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php index 4b4d0328d50..3ca501ae0dc 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php @@ -11,7 +11,7 @@ */ class DDC214Test extends OrmFunctionalTestCase { - private $classes = array(); + private $classes = []; private $schemaTool = null; public function setUp() @@ -31,14 +31,14 @@ public function setUp() */ public function testCmsAddressModel() { - $this->classes = array( + $this->classes = [ 'Doctrine\Tests\Models\CMS\CmsUser', 'Doctrine\Tests\Models\CMS\CmsPhonenumber', 'Doctrine\Tests\Models\CMS\CmsAddress', 'Doctrine\Tests\Models\CMS\CmsGroup', 'Doctrine\Tests\Models\CMS\CmsArticle', 'Doctrine\Tests\Models\CMS\CmsEmail', - ); + ]; $this->assertCreatedSchemaNeedsNoUpdates($this->classes); } @@ -48,7 +48,7 @@ public function testCmsAddressModel() */ public function testCompanyModel() { - $this->classes = array( + $this->classes = [ 'Doctrine\Tests\Models\Company\CompanyPerson', 'Doctrine\Tests\Models\Company\CompanyEmployee', 'Doctrine\Tests\Models\Company\CompanyManager', @@ -57,14 +57,14 @@ public function testCompanyModel() 'Doctrine\Tests\Models\Company\CompanyAuction', 'Doctrine\Tests\Models\Company\CompanyRaffle', 'Doctrine\Tests\Models\Company\CompanyCar' - ); + ]; $this->assertCreatedSchemaNeedsNoUpdates($this->classes); } public function assertCreatedSchemaNeedsNoUpdates($classes) { - $classMetadata = array(); + $classMetadata = []; foreach ($classes AS $class) { $classMetadata[] = $this->_em->getClassMetadata($class); } diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php index a923c40fca3..9df372c9102 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php @@ -16,14 +16,14 @@ protected function setUp() { public function testGetCreateSchemaSql() { - $classes = array( + $classes = [ $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsGroup'), $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsTag'), $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'), $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsEmail'), $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), - ); + ]; $tool = new SchemaTool($this->_em); $sql = $tool->getCreateSchemaSql($classes); @@ -49,9 +49,9 @@ public function testGetCreateSchemaSql() public function testGetCreateSchemaSql2() { - $classes = array( + $classes = [ $this->_em->getClassMetadata('Doctrine\Tests\Models\Generic\DecimalModel') - ); + ]; $tool = new SchemaTool($this->_em); $sql = $tool->getCreateSchemaSql($classes); @@ -62,9 +62,9 @@ public function testGetCreateSchemaSql2() public function testGetCreateSchemaSql3() { - $classes = array( + $classes = [ $this->_em->getClassMetadata('Doctrine\Tests\Models\Generic\BooleanModel') - ); + ]; $tool = new SchemaTool($this->_em); $sql = $tool->getCreateSchemaSql($classes); @@ -78,9 +78,9 @@ public function testGetCreateSchemaSql3() */ public function testGetCreateSchemaSql4() { - $classes = array( + $classes = [ $this->_em->getClassMetadata(__NAMESPACE__ . '\\MysqlSchemaNamespacedEntity') - ); + ]; $tool = new SchemaTool($this->_em); $sql = $tool->getCreateSchemaSql($classes); diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php index f98fe4bebd5..f71bfe9ceaa 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php @@ -25,11 +25,11 @@ public function testPostgresMetadataSequenceIncrementedBy10() public function testGetCreateSchemaSql() { - $classes = array( + $classes = [ $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'), $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), - ); + ]; $tool = new SchemaTool($this->_em); $sql = $tool->getCreateSchemaSql($classes); @@ -58,15 +58,15 @@ public function testGetCreateSchemaSql() $this->assertEquals("ALTER TABLE cms_users_tags ADD CONSTRAINT FK_93F5A1ADBAD26311 FOREIGN KEY (tag_id) REFERENCES cms_tags (id) NOT DEFERRABLE INITIALLY IMMEDIATE", array_shift($sql)); $this->assertEquals("ALTER TABLE cms_phonenumbers ADD CONSTRAINT FK_F21F790FA76ED395 FOREIGN KEY (user_id) REFERENCES cms_users (id) NOT DEFERRABLE INITIALLY IMMEDIATE", array_shift($sql)); - $this->assertEquals(array(), $sql, "SQL Array should be empty now."); + $this->assertEquals([], $sql, "SQL Array should be empty now."); $this->assertEquals(22, $sqlCount, "Total of 22 queries should be executed"); } public function testGetCreateSchemaSql2() { - $classes = array( + $classes = [ $this->_em->getClassMetadata('Doctrine\Tests\Models\Generic\DecimalModel') - ); + ]; $tool = new SchemaTool($this->_em); $sql = $tool->getCreateSchemaSql($classes); @@ -79,9 +79,9 @@ public function testGetCreateSchemaSql2() public function testGetCreateSchemaSql3() { - $classes = array( + $classes = [ $this->_em->getClassMetadata('Doctrine\Tests\Models\Generic\BooleanModel') - ); + ]; $tool = new SchemaTool($this->_em); $sql = $tool->getCreateSchemaSql($classes); @@ -93,11 +93,11 @@ public function testGetCreateSchemaSql3() public function testGetDropSchemaSql() { - $classes = array( + $classes = [ $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'), $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), - ); + ]; $tool = new SchemaTool($this->_em); $sql = $tool->getDropSchemaSQL($classes); @@ -119,10 +119,10 @@ public function testGetDropSchemaSql() */ public function testUpdateSchemaWithPostgreSQLSchema() { - $classes = array( + $classes = [ $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1657Screen'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1657Avatar'), - ); + ]; $tool = new SchemaTool($this->_em); $tool->createSchema($classes); diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php index 06eb67a2eb1..d6f98af1fa4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php @@ -14,12 +14,12 @@ class SchemaValidatorTest extends OrmFunctionalTestCase { static public function dataValidateModelSets() { - $modelSets = array(); + $modelSets = []; foreach (self::$_modelSets as $modelSet => $classes) { if ($modelSet == "customtype") { continue; } - $modelSets[] = array($modelSet); + $modelSets[] = [$modelSet]; } return $modelSets; } @@ -31,7 +31,7 @@ public function testValidateModelSets($modelSet) { $validator = new SchemaValidator($this->_em); - $classes = array(); + $classes = []; foreach (self::$_modelSets[$modelSet] as $className) { $classes[] = $this->_em->getClassMetadata($className); } diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheAbstractTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheAbstractTest.php index 320bbbb2f6a..becf7edbb4d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheAbstractTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheAbstractTest.php @@ -27,16 +27,16 @@ */ abstract class SecondLevelCacheAbstractTest extends OrmFunctionalTestCase { - protected $people = array(); - protected $addresses = array(); - protected $countries = array(); - protected $states = array(); - protected $cities = array(); - protected $travels = array(); - protected $travelers = array(); - protected $attractions = array(); - protected $attractionsInfo = array(); - protected $travelersWithProfile = array(); + protected $people = []; + protected $addresses = []; + protected $countries = []; + protected $states = []; + protected $cities = []; + protected $travels = []; + protected $travelers = []; + protected $attractions = []; + protected $attractionsInfo = []; + protected $travelersWithProfile = []; /** * @var \Doctrine\ORM\Cache @@ -280,4 +280,4 @@ protected function evictRegions() $this->cache->evictEntityRegions(); $this->cache->evictCollectionRegions(); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheCompositePrimaryKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheCompositePrimaryKeyTest.php index f5c10522532..efa8f9f4dc9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheCompositePrimaryKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheCompositePrimaryKeyTest.php @@ -24,10 +24,10 @@ public function testPutAndLoadCompositPrimaryKeyEntities() $leavingFrom = $this->_em->find(City::CLASSNAME, $leavingFromId); $goingTo = $this->_em->find(City::CLASSNAME, $goingToId); $flight = new Flight($leavingFrom, $goingTo); - $id = array( + $id = [ 'leavingFrom' => $leavingFromId, 'goingTo' => $goingToId, - ); + ]; $flight->setDeparture(new \DateTime('tomorrow')); @@ -70,10 +70,10 @@ public function testRemoveCompositPrimaryKeyEntities() $leavingFrom = $this->_em->find(City::CLASSNAME, $leavingFromId); $goingTo = $this->_em->find(City::CLASSNAME, $goingToId); $flight = new Flight($leavingFrom, $goingTo); - $id = array( + $id = [ 'leavingFrom' => $leavingFromId, 'goingTo' => $goingToId, - ); + ]; $flight->setDeparture(new \DateTime('tomorrow')); @@ -114,10 +114,10 @@ public function testUpdateCompositPrimaryKeyEntities() $leavingFrom = $this->_em->find(City::CLASSNAME, $leavingFromId); $goingTo = $this->_em->find(City::CLASSNAME, $goingToId); $flight = new Flight($leavingFrom, $goingTo); - $id = array( + $id = [ 'leavingFrom' => $leavingFromId, 'goingTo' => $goingToId, - ); + ]; $flight->setDeparture($now); @@ -172,4 +172,4 @@ public function testUpdateCompositPrimaryKeyEntities() $this->assertEquals($leavingFrom->getId(), $leavingFromId); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheCompositePrimaryKeyWithAssociationsTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheCompositePrimaryKeyWithAssociationsTest.php index dc4f40db07d..0fc7ae415f2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheCompositePrimaryKeyWithAssociationsTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheCompositePrimaryKeyWithAssociationsTest.php @@ -55,7 +55,7 @@ public function testFindByReturnsCachedEntity() $queries = $this->getCurrentQueryCount(); - $admin1Rome = $admin1Repo->findOneBy(array('country' => 'IT', 'id' => 1)); + $admin1Rome = $admin1Repo->findOneBy(['country' => 'IT', 'id' => 1]); $this->assertEquals("Italy", $admin1Rome->country->name); $this->assertEquals(2, count($admin1Rome->names)); @@ -65,7 +65,7 @@ public function testFindByReturnsCachedEntity() $queries = $this->getCurrentQueryCount(); - $admin1Rome = $admin1Repo->findOneBy(array('country' => 'IT', 'id' => 1)); + $admin1Rome = $admin1Repo->findOneBy(['country' => 'IT', 'id' => 1]); $this->assertEquals("Italy", $admin1Rome->country->name); $this->assertEquals(2, count($admin1Rome->names)); diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheConcurrentTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheConcurrentTest.php index f4d8e6b768d..ee5aa3fbdbb 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheConcurrentTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheConcurrentTest.php @@ -58,7 +58,7 @@ public function testBasicConcurrentEntityReadLock() $this->_em->clear(); $countryId = $this->countries[0]->getId(); - $cacheId = new EntityCacheKey(Country::CLASSNAME, array('id'=>$countryId)); + $cacheId = new EntityCacheKey(Country::CLASSNAME, ['id'=>$countryId]); $region = $this->_em->getCache()->getEntityCacheRegion(Country::CLASSNAME); $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $countryId)); @@ -97,7 +97,7 @@ public function testBasicConcurrentCollectionReadLock() $this->secondLevelCacheLogger->clearStats(); $stateId = $this->states[0]->getId(); - $cacheId = new CollectionCacheKey(State::CLASSNAME, 'cities', array('id'=>$stateId)); + $cacheId = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id'=>$stateId]); $region = $this->_em->getCache()->getCollectionCacheRegion(State::CLASSNAME, 'cities'); $this->assertTrue($this->cache->containsCollection(State::CLASSNAME, 'cities', $stateId)); @@ -147,4 +147,4 @@ public function getTimestampRegion() { return new TimestampRegionMock(); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheQueryCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheQueryCacheTest.php index b34b0f82565..51a93417b4e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheQueryCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheQueryCacheTest.php @@ -191,10 +191,10 @@ public function testQueryCacheModeRefresh() $countryName1 = $this->countries[0]->getName(); $countryName2 = $this->countries[1]->getName(); - $key1 = new EntityCacheKey(Country::CLASSNAME, array('id'=>$countryId1)); - $key2 = new EntityCacheKey(Country::CLASSNAME, array('id'=>$countryId2)); - $entry1 = new EntityCacheEntry(Country::CLASSNAME, array('id'=>$countryId1, 'name'=>'outdated')); - $entry2 = new EntityCacheEntry(Country::CLASSNAME, array('id'=>$countryId2, 'name'=>'outdated')); + $key1 = new EntityCacheKey(Country::CLASSNAME, ['id'=>$countryId1]); + $key2 = new EntityCacheKey(Country::CLASSNAME, ['id'=>$countryId2]); + $entry1 = new EntityCacheEntry(Country::CLASSNAME, ['id'=>$countryId1, 'name'=>'outdated']); + $entry2 = new EntityCacheEntry(Country::CLASSNAME, ['id'=>$countryId2, 'name'=>'outdated']); $region->put($key1, $entry1); $region->put($key2, $entry2); diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheRepositoryTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheRepositoryTest.php index 71f7d952f4f..8e37dd9600f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheRepositoryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheRepositoryTest.php @@ -92,7 +92,7 @@ public function testRepositoryCacheFindAllInvalidation() $this->assertCount(2, $countries); $this->assertInstanceOf(Country::CLASSNAME, $countries[0]); $this->assertInstanceOf(Country::CLASSNAME, $countries[1]); - + $country = new Country('foo'); $this->_em->persist($country); @@ -105,7 +105,7 @@ public function testRepositoryCacheFindAllInvalidation() $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); $country = $repository->find($country->getId()); - + $this->_em->remove($country); $this->_em->flush(); $this->_em->clear(); @@ -125,7 +125,7 @@ public function testRepositoryCacheFindBy() $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $criteria = array('name'=>$this->countries[0]->getName()); + $criteria = ['name'=>$this->countries[0]->getName()]; $repository = $this->_em->getRepository(Country::CLASSNAME); $queryCount = $this->getCurrentQueryCount(); @@ -155,7 +155,7 @@ public function testRepositoryCacheFindOneBy() $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $criteria = array('name'=>$this->countries[0]->getName()); + $criteria = ['name'=>$this->countries[0]->getName()]; $repository = $this->_em->getRepository(Country::CLASSNAME); $queryCount = $this->getCurrentQueryCount(); @@ -247,4 +247,4 @@ public function testRepositoryCacheFindAllToOneAssociation() $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $entities[0]->getCountry()); $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $entities[1]->getCountry()); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheTest.php index 56735840a4a..79044395a8f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheTest.php @@ -63,7 +63,7 @@ public function testPutAndLoadEntities() $this->assertInstanceOf(Country::CLASSNAME, $c3); $this->assertInstanceOf(Country::CLASSNAME, $c4); - + $this->assertEquals($c1->getId(), $c3->getId()); $this->assertEquals($c1->getName(), $c3->getName()); @@ -195,9 +195,13 @@ public function testUpdateEntities() public function testPostFlushFailure() { - $listener = new ListenerSecondLevelCacheTest(array(Events::postFlush => function(){ + $listener = new ListenerSecondLevelCacheTest( + [ + Events::postFlush => function(){ throw new \RuntimeException('post flush failure'); - })); + } + ] + ); $this->_em->getEventManager() ->addEventListener(Events::postFlush, $listener); @@ -225,9 +229,13 @@ public function testPostUpdateFailure() $this->loadFixturesStates(); $this->_em->clear(); - $listener = new ListenerSecondLevelCacheTest(array(Events::postUpdate => function(){ + $listener = new ListenerSecondLevelCacheTest( + [ + Events::postUpdate => function(){ throw new \RuntimeException('post update failure'); - })); + } + ] + ); $this->_em->getEventManager() ->addEventListener(Events::postUpdate, $listener); @@ -237,7 +245,7 @@ public function testPostUpdateFailure() $stateId = $this->states[0]->getId(); $stateName = $this->states[0]->getName(); $state = $this->_em->find(State::CLASSNAME, $stateId); - + $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $stateId)); $this->assertInstanceOf(State::CLASSNAME, $state); $this->assertEquals($stateName, $state->getName()); @@ -269,9 +277,13 @@ public function testPostRemoveFailure() $this->loadFixturesCountries(); $this->_em->clear(); - $listener = new ListenerSecondLevelCacheTest(array(Events::postRemove => function(){ + $listener = new ListenerSecondLevelCacheTest( + [ + Events::postRemove => function(){ throw new \RuntimeException('post remove failure'); - })); + } + ] + ); $this->_em->getEventManager() ->addEventListener(Events::postRemove, $listener); @@ -324,7 +336,7 @@ class ListenerSecondLevelCacheTest { public $callbacks; - public function __construct(array $callbacks = array()) + public function __construct(array $callbacks = []) { $this->callbacks = $callbacks; } diff --git a/tests/Doctrine/Tests/ORM/Functional/SequenceEmulatedIdentityStrategyTest.php b/tests/Doctrine/Tests/ORM/Functional/SequenceEmulatedIdentityStrategyTest.php index 02c891e7557..812d56d31d2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SequenceEmulatedIdentityStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SequenceEmulatedIdentityStrategyTest.php @@ -21,7 +21,7 @@ protected function setUp() } else { try { $this->_schemaTool->createSchema( - array($this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\SequenceEmulatedIdentityEntity')) + [$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\SequenceEmulatedIdentityEntity')] ); } catch (\Exception $e) { // Swallow all exceptions. We do not test the schema tool here. diff --git a/tests/Doctrine/Tests/ORM/Functional/SequenceGeneratorTest.php b/tests/Doctrine/Tests/ORM/Functional/SequenceGeneratorTest.php index 2fcd6a1b907..f77e1b0daad 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SequenceGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SequenceGeneratorTest.php @@ -19,9 +19,11 @@ public function setUp() } try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\SequenceEntity'), - )); + ] + ); } catch(\Exception $e) { } diff --git a/tests/Doctrine/Tests/ORM/Functional/SingleTableCompositeKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/SingleTableCompositeKeyTest.php index 53829a1c05e..80cf1596f53 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SingleTableCompositeKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SingleTableCompositeKeyTest.php @@ -58,7 +58,7 @@ private function findEntity() { return $this->_em->find( 'Doctrine\Tests\Models\CompositeKeyInheritance\SingleRootClass', - array('keyPart1' => 'part-1', 'keyPart2' => 'part-2') + ['keyPart1' => 'part-1', 'keyPart2' => 'part-2'] ); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php index 72be4c4d672..380f84b8bc7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php @@ -14,7 +14,7 @@ class SingleTableInheritanceTest extends OrmFunctionalTestCase { private $salesPerson; - private $engineers = array(); + private $engineers = []; private $fix; private $flex; private $ultra; @@ -232,7 +232,7 @@ public function testQueryScalarWithDiscriminatorValue() sort($discrValues); - $this->assertEquals(array('fix', 'flexible', 'flexultra'), $discrValues); + $this->assertEquals(['fix', 'flexible', 'flexultra'], $discrValues); } public function testQueryChildClassWithCondition() @@ -327,19 +327,19 @@ public function testFindByAssociation() $this->loadFullFixture(); $repos = $this->_em->getRepository("Doctrine\Tests\Models\Company\CompanyContract"); - $contracts = $repos->findBy(array('salesPerson' => $this->salesPerson->getId())); + $contracts = $repos->findBy(['salesPerson' => $this->salesPerson->getId()]); $this->assertEquals(3, count($contracts), "There should be 3 entities related to " . $this->salesPerson->getId() . " for 'Doctrine\Tests\Models\Company\CompanyContract'"); $repos = $this->_em->getRepository("Doctrine\Tests\Models\Company\CompanyFixContract"); - $contracts = $repos->findBy(array('salesPerson' => $this->salesPerson->getId())); + $contracts = $repos->findBy(['salesPerson' => $this->salesPerson->getId()]); $this->assertEquals(1, count($contracts), "There should be 1 entities related to " . $this->salesPerson->getId() . " for 'Doctrine\Tests\Models\Company\CompanyFixContract'"); $repos = $this->_em->getRepository("Doctrine\Tests\Models\Company\CompanyFlexContract"); - $contracts = $repos->findBy(array('salesPerson' => $this->salesPerson->getId())); + $contracts = $repos->findBy(['salesPerson' => $this->salesPerson->getId()]); $this->assertEquals(2, count($contracts), "There should be 2 entities related to " . $this->salesPerson->getId() . " for 'Doctrine\Tests\Models\Company\CompanyFlexContract'"); $repos = $this->_em->getRepository("Doctrine\Tests\Models\Company\CompanyFlexUltraContract"); - $contracts = $repos->findBy(array('salesPerson' => $this->salesPerson->getId())); + $contracts = $repos->findBy(['salesPerson' => $this->salesPerson->getId()]); $this->assertEquals(1, count($contracts), "There should be 1 entities related to " . $this->salesPerson->getId() . " for 'Doctrine\Tests\Models\Company\CompanyFlexUltraContract'"); } diff --git a/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php b/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php index a335b234e08..f7f651f1edb 100644 --- a/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php @@ -39,8 +39,8 @@ public function testAcceptsForeignKeysAsCriteria() $persister = $this->_em->getUnitOfWork()->getEntityPersister('Doctrine\Tests\Models\ECommerce\ECommerceCart'); $newCart = new ECommerceCart(); - $this->_em->getUnitOfWork()->registerManaged($newCart, array('id' => $cardId), array()); - $persister->load(array('customer_id' => $customer->getId()), $newCart, $class->associationMappings['customer']); + $this->_em->getUnitOfWork()->registerManaged($newCart, ['id' => $cardId], []); + $persister->load(['customer_id' => $customer->getId()], $newCart, $class->associationMappings['customer']); $this->assertEquals('Credit card', $newCart->getPayment()); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1080Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1080Test.php index 9369ca4c949..637b42cdfb5 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1080Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1080Test.php @@ -11,11 +11,13 @@ class DDC1080Test extends OrmFunctionalTestCase { public function testHydration() { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1080Foo'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1080Bar'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1080FooBar'), - )); + ] + ); $foo1 = new DDC1080Foo(); $foo1->setFooTitle('foo title 1'); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1113Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1113Test.php index e40f27994d0..9ff8882b5ae 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1113Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1113Test.php @@ -13,12 +13,14 @@ public function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1113Engine'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1113Vehicle'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1113Car'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1113Bus'), - )); + ] + ); } catch (\Exception $e) { } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1151Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1151Test.php index 8e67b514f57..053586bc96e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1151Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1151Test.php @@ -13,10 +13,12 @@ public function testQuoteForeignKey() $this->markTestSkipped("This test is useful for all databases, but designed only for postgresql."); } - $sql = $this->_schemaTool->getCreateSchemaSql(array( + $sql = $this->_schemaTool->getCreateSchemaSql( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1151User'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1151Group'), - )); + ] + ); $this->assertEquals("CREATE TABLE \"User\" (id INT NOT NULL, PRIMARY KEY(id))", $sql[0]); $this->assertEquals("CREATE TABLE ddc1151user_ddc1151group (ddc1151user_id INT NOT NULL, ddc1151group_id INT NOT NULL, PRIMARY KEY(ddc1151user_id, ddc1151group_id))", $sql[1]); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php index dad902b355c..8e8fcdb8bb0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php @@ -11,12 +11,14 @@ protected function setUp() { parent::setUp(); //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1163Product'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1163SpecialProduct'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1163ProxyHolder'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1163Tag'), - )); + ] + ); } public function testIssue() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php index 9c28b7e8858..51141b4e67b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php @@ -34,7 +34,7 @@ protected function setUp() { $link = new DDC117Link($this->article1, $this->article2, "Link-Description"); $this->_em->persist($link); - + $this->reference = new DDC117Reference($this->article1, $this->article2, "Test-Description"); $this->_em->persist($this->reference); @@ -53,7 +53,7 @@ protected function setUp() { */ public function testAssociationOnlyCompositeKey() { - $idCriteria = array('source' => $this->article1->id(), 'target' => $this->article2->id()); + $idCriteria = ['source' => $this->article1->id(), 'target' => $this->article2->id()]; $mapRef = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria); $this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Reference", $mapRef); @@ -92,7 +92,7 @@ public function testAssociationOnlyCompositeKey() */ public function testUpdateAssociationEntity() { - $idCriteria = array('source' => $this->article1->id(), 'target' => $this->article2->id()); + $idCriteria = ['source' => $this->article1->id(), 'target' => $this->article2->id()]; $mapRef = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria); $this->assertNotNull($mapRef); @@ -126,7 +126,7 @@ public function testFetchDql() */ public function testRemoveCompositeElement() { - $idCriteria = array('source' => $this->article1->id(), 'target' => $this->article2->id()); + $idCriteria = ['source' => $this->article1->id(), 'target' => $this->article2->id()]; $refRep = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria); @@ -143,7 +143,7 @@ public function testRemoveCompositeElement() */ public function testDqlRemoveCompositeElement() { - $idCriteria = array('source' => $this->article1->id(), 'target' => $this->article2->id()); + $idCriteria = ['source' => $this->article1->id(), 'target' => $this->article2->id()]; $dql = "DELETE "."Doctrine\Tests\Models\DDC117\DDC117Reference r WHERE r.source = ?1 AND r.target = ?2"; $this->_em->createQuery($dql) @@ -188,7 +188,7 @@ public function testInverseSideAccess() */ public function testMixedCompositeKey() { - $idCriteria = array('article' => $this->article1->id(), 'language' => 'en'); + $idCriteria = ['article' => $this->article1->id(), 'language' => 'en']; $this->translation = $this->_em->find('Doctrine\Tests\Models\DDC117\DDC117Translation', $idCriteria); $this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117Translation', $this->translation); @@ -282,10 +282,10 @@ public function testOneToOneCascadePersist() */ public function testReferencesToForeignKeyEntities() { - $idCriteria = array('source' => $this->article1->id(), 'target' => $this->article2->id()); + $idCriteria = ['source' => $this->article1->id(), 'target' => $this->article2->id()]; $reference = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria); - $idCriteria = array('article' => $this->article1->id(), 'language' => 'en'); + $idCriteria = ['article' => $this->article1->id(), 'language' => 'en']; $translation = $this->_em->find('Doctrine\Tests\Models\DDC117\DDC117Translation', $idCriteria); $approveChanges = new DDC117ApproveChanges($reference->source()->getDetails(), $reference, $translation); @@ -429,7 +429,7 @@ private function loadEditorFixture() */ public function testMergeForeignKeyIdentifierEntity() { - $idCriteria = array('source' => $this->article1->id(), 'target' => $this->article2->id()); + $idCriteria = ['source' => $this->article1->id(), 'target' => $this->article2->id()]; $refRep = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria); @@ -484,7 +484,7 @@ public function testGetEntityState() $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($this->reference)); - $idCriteria = array('source' => $this->article1->id(), 'target' => $this->article2->id()); + $idCriteria = ['source' => $this->article1->id(), 'target' => $this->article2->id()]; $reference = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria); $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_MANAGED, $this->_em->getUnitOfWork()->getEntityState($reference)); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php index b6d82816c0f..8cf1ebe150f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php @@ -9,11 +9,13 @@ class DDC1181Test extends OrmFunctionalTestCase public function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1181Hotel'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1181Booking'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1181Room'), - )); + ] + ); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php index a4ecf5d39e5..00d0a35a4b6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php @@ -10,11 +10,13 @@ protected function setUp() { parent::setUp(); //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1193Company'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1193Person'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1193Account') - )); + ] + ); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php index 06dde7696a6..7700aa0a5bf 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php @@ -10,11 +10,13 @@ protected function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1209_1'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1209_2'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1209_3') - )); + ] + ); } catch(\Exception $e) { } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1225Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1225Test.php index 95ff58fb587..105ae9f9042 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1225Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1225Test.php @@ -11,10 +11,12 @@ public function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1225_TestEntity1'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1225_TestEntity2'), - )); + ] + ); } catch(\PDOException $e) { } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1228Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1228Test.php index 913a3df768c..8a9f252df0e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1228Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1228Test.php @@ -12,10 +12,12 @@ public function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1228User'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1228Profile'), - )); + ] + ); } catch(\Exception $e) { } @@ -40,7 +42,7 @@ public function testOneToOnePersist() $this->assertTrue($user->getProfile()->__isInitialized__, "Proxy is not initialized"); $this->assertEquals("Bar", $user->getProfile()->getName()); - $this->assertEquals(array("id" => 1, "name" => "Foo"), $this->_em->getUnitOfWork()->getOriginalEntityData($user->getProfile())); + $this->assertEquals(["id" => 1, "name" => "Foo"], $this->_em->getUnitOfWork()->getOriginalEntityData($user->getProfile())); $this->_em->flush(); $this->_em->clear(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1238Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1238Test.php index dd0f99d0327..6c24b2f5583 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1238Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1238Test.php @@ -11,9 +11,11 @@ public function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1238User'), - )); + ] + ); } catch(\Exception $e) { } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1250Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1250Test.php index 3d88b8cb164..ed54ec681cd 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1250Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1250Test.php @@ -11,9 +11,11 @@ public function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1250ClientHistory'), - )); + ] + ); } catch(\PDOException $e) { } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1300Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1300Test.php index bffb48764f3..97fd33b2a25 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1300Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1300Test.php @@ -10,10 +10,12 @@ class DDC1300Test extends \Doctrine\Tests\OrmFunctionalTestCase public function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1300Foo'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1300FooLocale'), - )); + ] + ); } public function testIssue() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1335Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1335Test.php index 911a4bf618b..d92a32781e7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1335Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1335Test.php @@ -11,10 +11,12 @@ protected function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1335User'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1335Phone'), - )); + ] + ); $this->loadFixture(); } catch(\Exception $e) { } @@ -128,9 +130,9 @@ public function testIndexWithJoin() private function loadFixture() { - $p1 = array('11 xxxx-xxxx','11 yyyy-yyyy','11 zzzz-zzzz'); - $p2 = array('22 xxxx-xxxx','22 yyyy-yyyy','22 zzzz-zzzz'); - $p3 = array('33 xxxx-xxxx','33 yyyy-yyyy','33 zzzz-zzzz'); + $p1 = ['11 xxxx-xxxx','11 yyyy-yyyy','11 zzzz-zzzz']; + $p2 = ['22 xxxx-xxxx','22 yyyy-yyyy','22 zzzz-zzzz']; + $p3 = ['33 xxxx-xxxx','33 yyyy-yyyy','33 zzzz-zzzz']; $u1 = new DDC1335User("foo@foo.com", "Foo",$p1); $u2 = new DDC1335User("bar@bar.com", "Bar",$p2); @@ -171,7 +173,7 @@ class DDC1335User */ public $phones; - public function __construct($email, $name, array $numbers = array()) + public function __construct($email, $name, array $numbers = []) { $this->name = $name; $this->email = $email; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1360Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1360Test.php index e423de5bbf8..05a99b7cbb4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1360Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1360Test.php @@ -15,15 +15,18 @@ public function testSchemaDoubleQuotedCreate() $this->markTestSkipped("PostgreSQL only test."); } - $sql = $this->_schemaTool->getCreateSchemaSql(array( + $sql = $this->_schemaTool->getCreateSchemaSql( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1360DoubleQuote') - )); + ] + ); - $this->assertEquals(array( + $this->assertEquals( + [ 'CREATE SCHEMA user', 'CREATE TABLE "user"."user" (id INT NOT NULL, PRIMARY KEY(id))', 'CREATE SEQUENCE "user"."user_id_seq" INCREMENT BY 1 MINVALUE 1 START 1', - ), $sql); + ], $sql); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1383Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1383Test.php index fb6ae25e63f..a84fd715464 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1383Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1383Test.php @@ -12,10 +12,12 @@ protected function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1383AbstractEntity'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1383Entity'), - )); + ] + ); } catch(\Exception $ignored) {} } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1392Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1392Test.php index 2e0df824b90..5fe34f6ccbf 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1392Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1392Test.php @@ -14,10 +14,12 @@ protected function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1392File'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1392Picture'), - )); + ] + ); } catch (\Exception $ignored) { } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php index 41183ffdda0..22fd282ce24 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php @@ -12,11 +12,13 @@ protected function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1400Article'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1400User'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1400UserState'), - )); + ] + ); } catch (\Exception $ignored) { } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1404Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1404Test.php index 322582c20b4..e4d0a47f2ce 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1404Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1404Test.php @@ -13,10 +13,12 @@ protected function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1404ParentEntity'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1404ChildEntity'), - )); + ] + ); $this->loadFixtures(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC142Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC142Test.php index c985d61acbf..6f08cf80c11 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC142Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC142Test.php @@ -17,12 +17,14 @@ protected function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\User'), $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Group'), $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Phone'), $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Address'), - )); + ] + ); } catch(\Exception $e) { } } @@ -50,7 +52,7 @@ public function testCreateRetrieveUpdateDelete() $id = $user->id; $this->assertNotNull($id); - + $user = $this->_em->find('Doctrine\Tests\Models\Quote\User', $id); $address = $user->getAddress(); @@ -75,8 +77,8 @@ public function testCreateRetrieveUpdateDelete() $this->assertNull($user->getAddress()); $this->assertEquals('FabioBatSilva1', $user->name); - - + + $this->_em->remove($user); $this->_em->flush(); $this->_em->clear(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1430Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1430Test.php index 30e681d727b..3356d426809 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1430Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1430Test.php @@ -13,10 +13,12 @@ protected function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1430Order'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1430OrderProduct'), - )); + ] + ); $this->loadFixtures(); } catch (\Exception $exc) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1436Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1436Test.php index fa25c69e0aa..cd9ff6b3258 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1436Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1436Test.php @@ -12,9 +12,11 @@ protected function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1436Page'), - )); + ] + ); } catch (\Exception $ignored) { } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php index 2fc8eef93e5..d7b280f009c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php @@ -10,11 +10,13 @@ protected function setUp() { parent::setUp(); //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC144FlowElement'), // $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC144Expression'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC144Operand'), - )); + ] + ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1452Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1452Test.php index 4db5fe0cb19..4dd486c1e8c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1452Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1452Test.php @@ -15,10 +15,12 @@ protected function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1452EntityA'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1452EntityB'), - )); + ] + ); } catch (\Exception $ignored) { } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1454Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1454Test.php index 02e9003170b..f4b456e65a1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1454Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1454Test.php @@ -12,10 +12,12 @@ protected function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1454File'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1454Picture'), - )); + ] + ); } catch (\Exception $ignored) { } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1458Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1458Test.php index f04e6cb01a4..6f2d80afb4d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1458Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1458Test.php @@ -9,10 +9,12 @@ class DDC1258Test extends OrmFunctionalTestCase public function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\TestEntity'), $this->_em->getClassMetadata(__NAMESPACE__ . '\TestAdditionalEntity') - )); + ] + ); } public function testIssue() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1461Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1461Test.php index bfa4691558c..fd419d74352 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1461Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1461Test.php @@ -12,10 +12,12 @@ public function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1461TwitterAccount'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1461User') - )); + ] + ); } catch(\Exception $e) { } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1509Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1509Test.php index edceef666ca..351a963c496 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1509Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1509Test.php @@ -13,11 +13,13 @@ protected function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1509AbstractFile'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1509File'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1509Picture'), - )); + ] + ); } catch (\Exception $ignored) { } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1514Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1514Test.php index daaa69b2a6f..36dd46748c9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1514Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1514Test.php @@ -14,11 +14,13 @@ protected function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1514EntityA'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1514EntityB'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1514EntityC'), - )); + ] + ); } catch (\Exception $ignored) { } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1515Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1515Test.php index 9116a4df14d..2ceaaa1043e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1515Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1515Test.php @@ -11,10 +11,12 @@ class DDC1515Test extends \Doctrine\Tests\OrmFunctionalTestCase public function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1515Foo'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1515Bar'), - )); + ] + ); } public function testIssue() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1526Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1526Test.php index e2d770a5348..c33549afb5d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1526Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1526Test.php @@ -10,14 +10,16 @@ class DDC1526Test extends \Doctrine\Tests\OrmFunctionalTestCase public function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1526Menu'), - )); + ] + ); } public function testIssue() { - $parents = array(); + $parents = []; for ($i = 0; $i < 9; $i++) { $entity = new DDC1526Menu; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1548Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1548Test.php index 74c1fe1d530..179d4914c30 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1548Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1548Test.php @@ -10,11 +10,13 @@ class DDC1548Test extends \Doctrine\Tests\OrmFunctionalTestCase public function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1548E1'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1548E2'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1548Rel'), - )); + ] + ); } public function testIssue() @@ -78,4 +80,4 @@ class DDC1548Rel * @OneToOne(targetEntity="DDC1548E2", mappedBy="rel") */ public $e2; -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1595Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1595Test.php index 144894f179d..c44896b8585 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1595Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1595Test.php @@ -15,11 +15,13 @@ public function setUp() $this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\DebugStack); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1595BaseInheritance'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1595InheritedEntity1'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1595InheritedEntity2'), - )); + ] + ); } public function testIssue() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1654Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1654Test.php index a63eab8eb0d..aad2902d96e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1654Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1654Test.php @@ -10,10 +10,12 @@ class DDC1654Test extends \Doctrine\Tests\OrmFunctionalTestCase public function setUp() { parent::setUp(); - $this->setUpEntitySchema(array( + $this->setUpEntitySchema( + [ __NAMESPACE__ . '\\DDC1654Post', __NAMESPACE__ . '\\DDC1654Comment', - )); + ] + ); } public function tearDown() @@ -142,7 +144,7 @@ class DDC1654Post * @ManyToMany(targetEntity="DDC1654Comment", orphanRemoval=true, * cascade={"persist"}) */ - public $comments = array(); + public $comments = []; } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1655Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1655Test.php index cb5023a8605..3b24b4d91ad 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1655Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1655Test.php @@ -14,11 +14,13 @@ public function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1655Foo'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1655Bar'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1655Baz'), - )); + ] + ); } catch(\Exception $e) { } } @@ -26,10 +28,10 @@ public function setUp() public function testPostLoadOneToManyInheritance() { $cm = $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1655Foo'); - $this->assertEquals(array("postLoad" => array("postLoad")), $cm->lifecycleCallbacks); + $this->assertEquals(["postLoad" => ["postLoad"]], $cm->lifecycleCallbacks); $cm = $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1655Bar'); - $this->assertEquals(array("postLoad" => array("postLoad", "postSubLoaded")), $cm->lifecycleCallbacks); + $this->assertEquals(["postLoad" => ["postLoad", "postSubLoaded"]], $cm->lifecycleCallbacks); $baz = new DDC1655Baz(); $foo = new DDC1655Foo(); @@ -140,5 +142,5 @@ class DDC1655Baz /** * @OneToMany(targetEntity="DDC1655Foo", mappedBy="baz") */ - public $foos = array(); + public $foos = []; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1690Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1690Test.php index ed1cb4257bb..a108f81b860 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1690Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1690Test.php @@ -10,10 +10,12 @@ class DDC1690Test extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1690Parent'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1690Child') - )); + ] + ); } catch (\Exception $e) { // Swallow all exceptions. We do not test the schema tool here. } @@ -75,7 +77,7 @@ public function testChangeTracking() } class NotifyBaseEntity implements NotifyPropertyChanged { - public $listeners = array(); + public $listeners = []; public function addPropertyChangedListener(PropertyChangedListener $listener) { if (!in_array($listener, $this->listeners)) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1707Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1707Test.php index 5e587c4dfa8..dd6dcaeebfd 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1707Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1707Test.php @@ -15,10 +15,12 @@ public function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1509File'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1509Picture'), - )); + ] + ); } catch (\Exception $ignored) { } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php index a9cadb3ccc9..fe5a0de65b5 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php @@ -15,18 +15,22 @@ protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(self::CLASS_NAME), - )); + ] + ); } protected function tearDown() { parent::tearDown(); - $this->_schemaTool->dropSchema(array( + $this->_schemaTool->dropSchema( + [ $this->_em->getClassMetadata(self::CLASS_NAME), - )); + ] + ); } public function testCreateRetrieveUpdateDelete() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1787Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1787Test.php index 862d9196a8b..13410803050 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1787Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1787Test.php @@ -10,10 +10,12 @@ class DDC1787Test extends \Doctrine\Tests\OrmFunctionalTestCase public function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1787Foo'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1787Bar'), - )); + ] + ); } public function testIssue() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php index bf52e570b7c..6cf8c68c4c4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php @@ -16,12 +16,14 @@ protected function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\User'), $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Group'), $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Phone'), $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Address'), - )); + ] + ); } catch(\Exception $e) { } } @@ -109,7 +111,7 @@ public function testCreateRetrieveUpdateDelete() $this->_em->remove($e3); $this->_em->remove($e2); $this->_em->remove($e1); - + $this->_em->flush(); $this->_em->clear(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1884Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1884Test.php index 46f7cca7f46..2e638278d93 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1884Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1884Test.php @@ -72,7 +72,7 @@ private function createCars($class) $this->_em->persist($merc); $this->_em->persist($volvo); - return array($bimmer, $crysler, $merc, $volvo); + return [$bimmer, $crysler, $merc, $volvo]; } private function createDrivers($class) @@ -86,7 +86,7 @@ private function createDrivers($class) $this->_em->persist($foo); $this->_em->persist($john); - return array($john, $foo); + return [$john, $foo]; } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1885Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1885Test.php index 91f49282ee9..356a2c881d0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1885Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1885Test.php @@ -22,11 +22,13 @@ protected function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\User'), $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Group'), $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Address'), - )); + ] + ); } catch(\Exception $e) { } @@ -41,7 +43,7 @@ protected function setUp() $this->_em->persist($user); $this->_em->flush(); $this->_em->clear(); - + } public function testCreateRetrieveUpdateDelete() @@ -60,7 +62,7 @@ public function testCreateRetrieveUpdateDelete() $this->assertInstanceOf('Doctrine\Tests\Models\Quote\User', $user); $this->assertEquals('FabioBatSilva', $user->name); $this->assertEquals($u1Id, $user->id); - + $this->assertCount(2, $user->groups); $g1 = $user->getGroups()->get(0); @@ -85,7 +87,7 @@ public function testCreateRetrieveUpdateDelete() // Delete $this->_em->remove($user); - + $this->_em->flush(); $this->_em->clear(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1918Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1918Test.php index 64b3ad48dbc..4b0c7eb9151 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1918Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1918Test.php @@ -19,7 +19,7 @@ protected function setUp() public function testLastPageCorrect() { - $groups = array(); + $groups = []; for ($i = 0; $i < 3; $i++) { $group = new CmsGroup(); $group->name = "test"; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1925Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1925Test.php index 4c50cf26285..f42a3655f74 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1925Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1925Test.php @@ -12,10 +12,12 @@ class DDC1925Test extends \Doctrine\Tests\OrmFunctionalTestCase { public function testIssue() { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1925User'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1925Product'), - )); + ] + ); $user = new DDC1925User(); $user->setTitle("Test User"); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC192Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC192Test.php index f01a2abacab..2627a17d803 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC192Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC192Test.php @@ -8,10 +8,12 @@ class DDC192Test extends OrmFunctionalTestCase { public function testSchemaCreation() { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC192User'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC192Phonenumber') - )); + ] + ); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1998Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1998Test.php index 95e0a76f5b1..bc2fe26cfc1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1998Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1998Test.php @@ -15,9 +15,11 @@ public function testSqlConversionAsIdentifier() { Type::addType('ddc1998', __NAMESPACE__ . '\\DDC1998Type'); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1998Entity'), - )); + ] + ); $entity = new DDC1998Entity(); $entity->id = new DDC1998Id("foo"); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php index 17a115d0f05..9db6dad961a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php @@ -9,11 +9,13 @@ class DDC199Test extends OrmFunctionalTestCase protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC199ParentClass'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC199ChildClass'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC199RelatedClass') - )); + ] + ); } public function testPolymorphicLoading() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2012Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2012Test.php index 92510cb02c7..5d2be3bbc8d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2012Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2012Test.php @@ -17,18 +17,20 @@ protected function setUp() Type::addType(DDC2012TsVectorType::MYTYPE, __NAMESPACE__ . '\DDC2012TsVectorType'); - DDC2012TsVectorType::$calls = array(); + DDC2012TsVectorType::$calls = []; - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2012Item'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2012ItemPerson'), - )); + ] + ); } public function testIssue() { $item = new DDC2012ItemPerson(); - $item->tsv = array('word1', 'word2', 'word3'); + $item->tsv = ['word1', 'word2', 'word3']; $this->_em->persist($item); $this->_em->flush(); @@ -45,10 +47,10 @@ public function testIssue() $this->assertCount(1, DDC2012TsVectorType::$calls['convertToPHPValue']); $this->assertInstanceOf(__NAMESPACE__ . '\DDC2012Item', $item); - $this->assertEquals(array('word1', 'word2', 'word3'), $item->tsv); + $this->assertEquals(['word1', 'word2', 'word3'], $item->tsv); - $item->tsv = array('word1', 'word2'); + $item->tsv = ['word1', 'word2']; $this->_em->persist($item); $this->_em->flush(); @@ -61,7 +63,7 @@ public function testIssue() $this->assertCount(2, DDC2012TsVectorType::$calls['convertToPHPValue']); $this->assertInstanceOf(__NAMESPACE__ . '\DDC2012Item', $item); - $this->assertEquals(array('word1', 'word2'), $item->tsv); + $this->assertEquals(['word1', 'word2'], $item->tsv); } } @@ -103,7 +105,7 @@ class DDC2012TsVectorType extends Type { const MYTYPE = 'tsvector'; - public static $calls = array(); + public static $calls = []; /** * {@inheritdoc} @@ -122,10 +124,10 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) $value = implode(" ", $value); } - self::$calls[__FUNCTION__][] = array( + self::$calls[__FUNCTION__][] = [ 'value' => $value, 'platform' => $platform, - ); + ]; return $value; } @@ -135,10 +137,10 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) */ public function convertToPHPValue($value, AbstractPlatform $platform) { - self::$calls[__FUNCTION__][] = array( + self::$calls[__FUNCTION__][] = [ 'value' => $value, 'platform' => $platform, - ); + ]; return explode(" ", strtolower($value)); } @@ -148,14 +150,14 @@ public function convertToPHPValue($value, AbstractPlatform $platform) */ public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform) { - self::$calls[__FUNCTION__][] = array( + self::$calls[__FUNCTION__][] = [ 'sqlExpr' => $sqlExpr, 'platform' => $platform, - ); + ]; // changed to upper expression to keep the test compatible with other Databases //sprintf('to_tsvector(%s)', $sqlExpr); - + return $platform->getUpperExpression($sqlExpr); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2074Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2074Test.php index f53857ab3e3..b0ae37e0e74 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2074Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2074Test.php @@ -23,7 +23,7 @@ public function testShouldNotScheduleDeletionOnClonedInstances() $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceProduct'); $product = new ECommerceProduct(); $category = new ECommerceCategory(); - $collection = new PersistentCollection($this->_em, $class, new ArrayCollection(array($category))); + $collection = new PersistentCollection($this->_em, $class, new ArrayCollection([$category])); $collection->setOwner($product, $class->associationMappings['categories']); $uow = $this->_em->getUnitOfWork(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2084Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2084Test.php index abd0fe2d82b..eadbc1caf9d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2084Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2084Test.php @@ -12,10 +12,12 @@ public function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2084\MyEntity1'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2084\MyEntity2'), - )); + ] + ); } catch (\Exception $exc) { } } @@ -125,4 +127,4 @@ public function setValue($value) { $this->value = $value; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2090Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2090Test.php index cd6db885712..dc7563c6600 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2090Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2090Test.php @@ -44,11 +44,13 @@ public function testIssue() ->set('e.startDate', ':date') ->set('e.salary', ':salary') ->where('e = :e') - ->setParameters(array( + ->setParameters( + [ 'e' => $employee1, 'date' => $date1, 'salary' => 101, - )) + ] + ) ->getQuery() ->useQueryCache(true) ->execute(); @@ -58,11 +60,13 @@ public function testIssue() ->set('e.startDate', ':date') ->set('e.salary', ':salary') ->where('e = :e') - ->setParameters(array( + ->setParameters( + [ 'e' => $employee2, 'date' => $date2, 'salary' => 102, - )) + ] + ) ->getQuery() ->useQueryCache(true) ->execute(); @@ -82,7 +86,7 @@ public function testIssue() ->set('e.startDate', '?1') ->set('e.salary', '?2') ->where('e = ?0') - ->setParameters(array($employee1, $date1, 101)) + ->setParameters([$employee1, $date1, 101]) ->getQuery() ->useQueryCache(true) ->execute(); @@ -92,7 +96,7 @@ public function testIssue() ->set('e.startDate', '?1') ->set('e.salary', '?2') ->where('e = ?0') - ->setParameters(array($employee2, $date2, 102)) + ->setParameters([$employee2, $date2, 102]) ->getQuery() ->useQueryCache(true) ->execute(); @@ -108,4 +112,4 @@ public function testIssue() $this->assertEquals($date1, $e1->getStartDate()); $this->assertEquals($date2, $e2->getStartDate()); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php index 925362b08c9..3e3e8670f11 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php @@ -12,9 +12,11 @@ class DDC2106Test extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2106Entity'), - )); + ] + ); } public function testDetachedEntityAsId() @@ -24,7 +26,7 @@ public function testDetachedEntityAsId() $this->_em->persist($entity); $this->_em->flush(); $this->_em->detach($entity); - $entity = $this->_em->getRepository(__NAMESPACE__ . '\DDC2106Entity')->findOneBy(array()); + $entity = $this->_em->getRepository(__NAMESPACE__ . '\DDC2106Entity')->findOneBy([]); // ... and a managed entity without id $entityWithoutId = new DDC2106Entity(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC211Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC211Test.php index 728a393a0c2..cd94f75a5f7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC211Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC211Test.php @@ -9,10 +9,12 @@ class DDC211Test extends OrmFunctionalTestCase protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC211User'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC211Group') - )); + ] + ); } public function testIssue() @@ -25,7 +27,7 @@ public function testIssue() $this->_em->persist($user); $this->_em->flush(); - $groupNames = array('group 1', 'group 2', 'group 3', 'group 4'); + $groupNames = ['group 1', 'group 2', 'group 3', 'group 4']; foreach ($groupNames as $name) { $group = new DDC211Group; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2138Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2138Test.php index 97fdb3050bf..a0abb675410 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2138Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2138Test.php @@ -16,21 +16,21 @@ public function testForeignKeyOnSTIWithMultipleMapping() $em = $this->_em; $schemaTool = new SchemaTool($em); - $classes = array( + $classes = [ $em->getClassMetadata(__NAMESPACE__ . '\DDC2138User'), $em->getClassMetadata(__NAMESPACE__ . '\DDC2138Structure'), $em->getClassMetadata(__NAMESPACE__ . '\DDC2138UserFollowedObject'), $em->getClassMetadata(__NAMESPACE__ . '\DDC2138UserFollowedStructure'), $em->getClassMetadata(__NAMESPACE__ . '\DDC2138UserFollowedUser') - ); + ]; $schema = $schemaTool->getSchemaFromMetadata($classes); $this->assertTrue($schema->hasTable('users_followed_objects'), "Table users_followed_objects should exist."); /* @var $table \Doctrine\DBAL\Schema\Table */ $table = ($schema->getTable('users_followed_objects')); - $this->assertTrue($table->columnsAreIndexed(array('object_id'))); - $this->assertTrue($table->columnsAreIndexed(array('user_id'))); + $this->assertTrue($table->columnsAreIndexed(['object_id'])); + $this->assertTrue($table->columnsAreIndexed(['user_id'])); $foreignKeys = $table->getForeignKeys(); $this->assertCount(1, $foreignKeys, 'user_id column has to have FK, but not object_id'); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2175Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2175Test.php index 178685b391f..d1a2e27a9ae 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2175Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2175Test.php @@ -10,9 +10,11 @@ class DDC2175Test extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2175Entity'), - )); + ] + ); } public function testIssue() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2182Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2182Test.php index 031156dcc01..47e6671e8d3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2182Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2182Test.php @@ -10,10 +10,12 @@ public function testPassColumnOptionsToJoinColumns() $this->markTestSkipped("This test is useful for all databases, but designed only for mysql."); } - $sql = $this->_schemaTool->getCreateSchemaSql(array( + $sql = $this->_schemaTool->getCreateSchemaSql( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2182OptionParent'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2182OptionChild'), - )); + ] + ); $this->assertEquals("CREATE TABLE DDC2182OptionParent (id INT UNSIGNED NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[0]); $this->assertEquals("CREATE TABLE DDC2182OptionChild (id VARCHAR(255) NOT NULL, parent_id INT UNSIGNED DEFAULT NULL, INDEX IDX_B314D4AD727ACA70 (parent_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[1]); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2214Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2214Test.php index 060b6ba334e..03d9b8f5df4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2214Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2214Test.php @@ -17,10 +17,12 @@ protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2214Foo'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2214Bar'), - )); + ] + ); } public function testIssue() @@ -44,7 +46,7 @@ public function testIssue() $related = $this ->_em ->createQuery('SELECT b FROM '.__NAMESPACE__ . '\DDC2214Bar b WHERE b.id IN(:ids)') - ->setParameter('ids', array($bar)) + ->setParameter('ids', [$bar]) ->getResult(); $query = end($logger->queries); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2230Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2230Test.php index 8c2655d1be9..accb24a7ab3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2230Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2230Test.php @@ -17,10 +17,12 @@ protected function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2230User'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2230Address'), - )); + ] + ); } catch (ToolsException $e) {} } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2231Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2231Test.php index d6ff17c5515..1caeffcc7f8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2231Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2231Test.php @@ -14,9 +14,11 @@ class DDC2231Test extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2231EntityY'), - )); + ] + ); } public function testInjectObjectManagerInProxyIfInitializedInUow() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2252Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2252Test.php index 491cf3bd6ad..643c054ab8d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2252Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2252Test.php @@ -12,18 +12,20 @@ class DDC2252Test extends \Doctrine\Tests\OrmFunctionalTestCase private $user; private $merchant; private $membership; - private $privileges = array(); + private $privileges = []; protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\DDC2252User'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\DDC2252Privilege'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\DDC2252Membership'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\DDC2252MerchantAccount'), - )); + ] + ); $this->loadFixtures(); } @@ -56,10 +58,10 @@ public function loadFixtures() public function testIssue() { - $identifier = array( + $identifier = [ 'merchantAccount' => $this->merchant->getAccountid(), 'userAccount' => $this->user->getUid(), - ); + ]; $class = 'Doctrine\Tests\ORM\Functional\Ticket\DDC2252Membership'; $membership = $this->_em->find($class, $identifier); @@ -226,4 +228,4 @@ public function getPrivileges() { return $this->privileges; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2256Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2256Test.php index 42aeca43e3c..2ec88f9f374 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2256Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2256Test.php @@ -13,10 +13,12 @@ class DDC2256Test extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2256User'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2256Group') - )); + ] + ); } public function testIssue() @@ -53,7 +55,8 @@ public function testIssue() // Test ResultSetMappingBuilder. $rsm = new ResultSetMappingBuilder($this->_em); $rsm->addRootEntityFromClassMetadata('MyNamespace:DDC2256User', 'u'); - $rsm->addJoinedEntityFromClassMetadata('MyNamespace:DDC2256Group', 'g', 'u', 'group', array('id' => 'group_id', 'name' => 'group_name')); + $rsm->addJoinedEntityFromClassMetadata('MyNamespace:DDC2256Group', 'g', 'u', 'group', ['id' => 'group_id', 'name' => 'group_name'] + ); $this->_em->createNativeQuery($sql, $rsm)->getResult(); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2306Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2306Test.php index ca3ee1a50cd..81844369813 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2306Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2306Test.php @@ -16,12 +16,14 @@ protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2306Zone'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2306User'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2306Address'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2306UserAddress'), - )); + ] + ); } /** @@ -148,4 +150,4 @@ public function __construct(DDC2306User $user, DDC2306Address $address) $user->addresses->add($this); $address->users->add($this); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2346Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2346Test.php index 3d2781763e9..9172904c8f6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2346Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2346Test.php @@ -22,11 +22,13 @@ protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2346Foo'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2346Bar'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2346Baz'), - )); + ] + ); $this->logger = new DebugStack(); } @@ -106,4 +108,4 @@ class DDC2346Bar class DDC2346Baz extends DDC2346Bar { -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2350Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2350Test.php index 145b1733079..919f74cf787 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2350Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2350Test.php @@ -14,10 +14,12 @@ protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2350User'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2350Bug'), - )); + ] + ); } public function testEagerCollectionsAreOnlyRetrievedOnce() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2359Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2359Test.php index 12be3241a19..af51a2d7cf3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2359Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2359Test.php @@ -27,11 +27,11 @@ public function testIssue() /* @var $metadataFactory \Doctrine\ORM\Mapping\ClassMetadataFactory|\PHPUnit_Framework_MockObject_MockObject */ $metadataFactory = $this->getMockBuilder(ClassMetadataFactory::class) - ->setMethods(array('newClassMetadataInstance', 'wakeupReflection')) + ->setMethods(['newClassMetadataInstance', 'wakeupReflection']) ->getMock(); $configuration = $this->getMockBuilder(Configuration::class) - ->setMethods(array('getMetadataDriverImpl')) + ->setMethods(['getMetadataDriverImpl']) ->getMock(); $connection = $this->createMock(Connection::class); @@ -62,4 +62,4 @@ class DDC2359Foo { /** @Id @Column(type="integer") @GeneratedValue */ public $id; -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php index 3ff5cd9b42d..22536973994 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php @@ -7,11 +7,13 @@ class DDC237Test extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC237EntityX'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC237EntityY'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC237EntityZ') - )); + ] + ); } public function testUninitializedProxyIsInitializedOnFetchJoin() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2387Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2387Test.php index f74d4e15cfe..de4e2058955 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2387Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2387Test.php @@ -14,15 +14,15 @@ public function testCompositeAssociationKeyDetection() { $product = new \Doctrine\DBAL\Schema\Table('ddc2387_product'); $product->addColumn('id', 'integer'); - $product->setPrimaryKey(array('id')); + $product->setPrimaryKey(['id']); $attributes = new \Doctrine\DBAL\Schema\Table('ddc2387_attributes'); $attributes->addColumn('product_id', 'integer'); $attributes->addColumn('attribute_name', 'string'); - $attributes->setPrimaryKey(array('product_id', 'attribute_name')); - $attributes->addForeignKeyConstraint('ddc2387_product', array('product_id'), array('product_id')); + $attributes->setPrimaryKey(['product_id', 'attribute_name']); + $attributes->addForeignKeyConstraint('ddc2387_product', ['product_id'], ['product_id']); - $metadata = $this->convertToClassMetadata(array($product, $attributes), array()); + $metadata = $this->convertToClassMetadata([$product, $attributes], []); $this->assertEquals(ClassMetadataInfo::GENERATOR_TYPE_NONE, $metadata['Ddc2387Attributes']->generatorType); $this->assertEquals(ClassMetadataInfo::GENERATOR_TYPE_AUTO, $metadata['Ddc2387Product']->generatorType); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2415Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2415Test.php index 0283e64577c..aa29b9fea34 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2415Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2415Test.php @@ -16,12 +16,14 @@ protected function setUp() { parent::setUp(); - $this->_em->getConfiguration()->setMetadataDriverImpl(new StaticPHPDriver(array())); + $this->_em->getConfiguration()->setMetadataDriverImpl(new StaticPHPDriver([])); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2415ParentEntity'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2415ChildEntity'), - )); + ] + ); } public function testTicket() @@ -57,16 +59,20 @@ public function getId() public static function loadMetadata(ClassMetadataInfo $metadata) { - $metadata->mapField(array ( + $metadata->mapField( + [ 'id' => true, 'fieldName' => 'id', 'type' => 'string', - )); + ] + ); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_CUSTOM); - $metadata->setCustomGeneratorDefinition(array( + $metadata->setCustomGeneratorDefinition( + [ 'class' => 'Doctrine\Tests\ORM\Functional\Ticket\DDC2415Generator' - )); + ] + ); $metadata->isMappedSuperclass = true; } @@ -88,10 +94,12 @@ public function getName() public static function loadMetadata(ClassMetadataInfo $metadata) { - $metadata->mapField(array ( + $metadata->mapField( + [ 'fieldName' => 'name', 'type' => 'string', - )); + ] + ); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2494Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2494Test.php index b5a09f9223a..7590a14f1e0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2494Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2494Test.php @@ -15,14 +15,16 @@ protected function setUp() { parent::setUp(); - DDC2494TinyIntType::$calls = array(); + DDC2494TinyIntType::$calls = []; Type::addType('ddc2494_tinyint', __NAMESPACE__ . '\DDC2494TinyIntType'); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(DDC2494Currency::CLASSNAME), $this->_em->getClassMetadata(DDC2494Campaign::CLASSNAME), - )); + ] + ); } public function testIssue() @@ -160,7 +162,7 @@ public function getCurrency() class DDC2494TinyIntType extends Type { - public static $calls = array(); + public static $calls = []; /** * {@inheritdoc} @@ -177,11 +179,11 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) { $return = (string) $value; - self::$calls[__FUNCTION__][] = array( + self::$calls[__FUNCTION__][] = [ 'value' => $value, 'return' => $return, 'platform' => $platform, - ); + ]; return $return; } @@ -193,11 +195,11 @@ public function convertToPHPValue($value, AbstractPlatform $platform) { $return = (integer) $value; - self::$calls[__FUNCTION__][] = array( + self::$calls[__FUNCTION__][] = [ 'value' => $value, 'return' => $return, 'platform' => $platform, - ); + ]; return $return; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2575Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2575Test.php index 2f6b406d3b6..771b8b8012d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2575Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2575Test.php @@ -7,19 +7,21 @@ */ class DDC2575Test extends \Doctrine\Tests\OrmFunctionalTestCase { - private $rootsEntities = array(); - private $aEntities = array(); - private $bEntities = array(); + private $rootsEntities = []; + private $aEntities = []; + private $bEntities = []; protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2575Root'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2575A'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2575B'), - )); + ] + ); $entityRoot1 = new DDC2575Root(1); $entityB1 = new DDC2575B(2); @@ -61,7 +63,7 @@ public function testHydrationIssue() $query = $qb->getQuery(); $result = $query->getResult(); - + $this->assertCount(2, $result); $row = $result[0]; @@ -157,4 +159,4 @@ public function __construct($id, $value = 0) $this->id = $id; $this->sampleField = $value; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2579Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2579Test.php index fe68ff564df..f80eba96c80 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2579Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2579Test.php @@ -17,11 +17,13 @@ protected function setUp() Type::addType(DDC2579Type::NAME, DDC2579Type::CLASSNAME); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(DDC2579Entity::CLASSNAME), $this->_em->getClassMetadata(DDC2579EntityAssoc::CLASSNAME), $this->_em->getClassMetadata(DDC2579AssocAssoc::CLASSNAME), - )); + ] + ); } public function testIssue() @@ -36,7 +38,7 @@ public function testIssue() $this->_em->persist($assocAssoc); $this->_em->persist($entity); $this->_em->flush(); - + $entity->value++; $this->_em->persist($entity); @@ -45,7 +47,7 @@ public function testIssue() $id = $entity->id; $value = $entity->value; - $criteria = array('assoc' => $assoc, 'id' => $id); + $criteria = ['assoc' => $assoc, 'id' => $id]; $entity = $repository->findOneBy($criteria); $this->assertInstanceOf(DDC2579Entity::CLASSNAME, $entity); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC258Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC258Test.php index d9dca3752c9..e0cd3257b9a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC258Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC258Test.php @@ -9,12 +9,14 @@ class DDC258Test extends OrmFunctionalTestCase protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC258Super'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC258Class1'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC258Class2'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC258Class3'), - )); + ] + ); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2660Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2660Test.php index 2ec46ba29b4..0a542b1af7f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2660Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2660Test.php @@ -17,11 +17,13 @@ protected function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2660Product'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2660Customer'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2660CustomerOrder') - )); + ] + ); } catch(\Exception $e) { return; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2692Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2692Test.php index 437f89ffbd4..ff4739e48f9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2692Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2692Test.php @@ -18,9 +18,11 @@ protected function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2692Foo'), - )); + ] + ); } catch(\Exception $e) { return; } @@ -30,7 +32,7 @@ protected function setUp() public function testIsListenerCalledOnlyOnceOnPreFlush() { $listener = $this->getMockBuilder(DDC2692Listener::class) - ->setMethods(array('preFlush')) + ->setMethods(['preFlush']) ->getMock(); $listener->expects($this->once())->method('preFlush'); @@ -56,7 +58,7 @@ class DDC2692Foo class DDC2692Listener implements EventSubscriber { public function getSubscribedEvents() { - return array(\Doctrine\ORM\Events::preFlush); + return [\Doctrine\ORM\Events::preFlush]; } public function preFlush(PreFlushEventArgs $args) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2759Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2759Test.php index 6198663e601..1ebb4e9c13f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2759Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2759Test.php @@ -15,12 +15,14 @@ protected function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2759Qualification'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2759Category'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2759QualificationMetadata'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2759MetadataCategory'), - )); + ] + ); } catch(\Exception $e) { return; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2775Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2775Test.php index e98ff91a329..efc7a628692 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2775Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2775Test.php @@ -15,12 +15,14 @@ protected function setUp() { parent::setUp(); - $this->setUpEntitySchema(array( + $this->setUpEntitySchema( + [ 'Doctrine\Tests\ORM\Functional\Ticket\User', 'Doctrine\Tests\ORM\Functional\Ticket\Role', 'Doctrine\Tests\ORM\Functional\Ticket\AdminRole', 'Doctrine\Tests\ORM\Functional\Ticket\Authorization', - )); + ] + ); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC279Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC279Test.php index 2f1be3d32c1..499b85b68a4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC279Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC279Test.php @@ -7,12 +7,14 @@ class DDC279Test extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC279EntityXAbstract'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC279EntityX'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC279EntityY'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC279EntityZ'), - )); + ] + ); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php index 87c94cb8446..d5b287a7333 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php @@ -67,7 +67,7 @@ public function testClassSchemaMappingsValidity($className, $expectedSchemaName, public function testPersistenceOfEntityWithSchemaMapping($className) { try { - $this->_schemaTool->createSchema(array($this->_em->getClassMetadata($className))); + $this->_schemaTool->createSchema([$this->_em->getClassMetadata($className)]); } catch (ToolsException $e) { // table already exists } @@ -86,11 +86,11 @@ public function testPersistenceOfEntityWithSchemaMapping($className) */ public function getTestedClasses() { - return array( - array(ExplicitSchemaAndTable::CLASSNAME, 'explicit_schema', 'explicit_table'), - array(SchemaAndTableInTableName::CLASSNAME, 'implicit_schema', 'implicit_table'), - array(DDC2825ClassWithImplicitlyDefinedSchemaAndQuotedTableName::CLASSNAME, 'myschema', 'order'), - ); + return [ + [ExplicitSchemaAndTable::CLASSNAME, 'explicit_schema', 'explicit_table'], + [SchemaAndTableInTableName::CLASSNAME, 'implicit_schema', 'implicit_table'], + [DDC2825ClassWithImplicitlyDefinedSchemaAndQuotedTableName::CLASSNAME, 'myschema', 'order'], + ]; } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2862Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2862Test.php index 28535a3d722..d772e441ca3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2862Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2862Test.php @@ -16,10 +16,12 @@ public function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(DDC2862User::CLASSNAME), $this->_em->getClassMetadata(DDC2862Driver::CLASSNAME), - )); + ] + ); } catch (ToolsException $exc) { } } @@ -34,8 +36,8 @@ public function testIssue() $this->_em->flush(); $this->_em->clear(); - $this->assertTrue($this->_em->getCache()->containsEntity(DDC2862User::CLASSNAME, array('id' => $user1->getId()))); - $this->assertTrue($this->_em->getCache()->containsEntity(DDC2862Driver::CLASSNAME, array('id' => $driver1->getId()))); + $this->assertTrue($this->_em->getCache()->containsEntity(DDC2862User::CLASSNAME, ['id' => $user1->getId()])); + $this->assertTrue($this->_em->getCache()->containsEntity(DDC2862Driver::CLASSNAME, ['id' => $driver1->getId()])); $queryCount = $this->getCurrentQueryCount(); $driver2 = $this->_em->find(DDC2862Driver::CLASSNAME, $driver1->getId()); @@ -49,8 +51,8 @@ public function testIssue() $this->_em->flush(); $this->_em->clear(); - $this->assertTrue($this->_em->getCache()->containsEntity(DDC2862User::CLASSNAME, array('id' => $user1->getId()))); - $this->assertTrue($this->_em->getCache()->containsEntity(DDC2862Driver::CLASSNAME, array('id' => $driver1->getId()))); + $this->assertTrue($this->_em->getCache()->containsEntity(DDC2862User::CLASSNAME, ['id' => $user1->getId()])); + $this->assertTrue($this->_em->getCache()->containsEntity(DDC2862Driver::CLASSNAME, ['id' => $driver1->getId()])); $queryCount = $this->getCurrentQueryCount(); $driver3 = $this->_em->find(DDC2862Driver::CLASSNAME, $driver1->getId()); @@ -75,8 +77,8 @@ public function testIssueReopened() $this->_em->getCache()->evictEntityRegion(DDC2862User::CLASSNAME); $this->_em->getCache()->evictEntityRegion(DDC2862Driver::CLASSNAME); - $this->assertFalse($this->_em->getCache()->containsEntity(DDC2862User::CLASSNAME, array('id' => $user1->getId()))); - $this->assertFalse($this->_em->getCache()->containsEntity(DDC2862Driver::CLASSNAME, array('id' => $driver1->getId()))); + $this->assertFalse($this->_em->getCache()->containsEntity(DDC2862User::CLASSNAME, ['id' => $user1->getId()])); + $this->assertFalse($this->_em->getCache()->containsEntity(DDC2862Driver::CLASSNAME, ['id' => $driver1->getId()])); $queryCount = $this->getCurrentQueryCount(); $driver2 = $this->_em->find(DDC2862Driver::CLASSNAME, $driver1->getId()); @@ -87,8 +89,8 @@ public function testIssueReopened() $this->_em->clear(); - $this->assertFalse($this->_em->getCache()->containsEntity(DDC2862User::CLASSNAME, array('id' => $user1->getId()))); - $this->assertTrue($this->_em->getCache()->containsEntity(DDC2862Driver::CLASSNAME, array('id' => $driver1->getId()))); + $this->assertFalse($this->_em->getCache()->containsEntity(DDC2862User::CLASSNAME, ['id' => $user1->getId()])); + $this->assertTrue($this->_em->getCache()->containsEntity(DDC2862Driver::CLASSNAME, ['id' => $driver1->getId()])); $queryCount = $this->getCurrentQueryCount(); $driver3 = $this->_em->find(DDC2862Driver::CLASSNAME, $driver1->getId()); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2895Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2895Test.php index 5eece3f9bd8..7f8451a29f1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2895Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2895Test.php @@ -13,9 +13,11 @@ public function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC2895'), - )); + ] + ); } catch(\Exception $e) { } @@ -26,10 +28,10 @@ public function testPostLoadOneToManyInheritance() $cm = $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC2895'); $this->assertEquals( - array( - "prePersist" => array("setLastModifiedPreUpdate"), - "preUpdate" => array("setLastModifiedPreUpdate"), - ), + [ + "prePersist" => ["setLastModifiedPreUpdate"], + "preUpdate" => ["setLastModifiedPreUpdate"], + ], $cm->lifecycleCallbacks ); @@ -109,4 +111,4 @@ public function getId() { return $this->id; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2931Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2931Test.php index 8923f276454..ff494225fee 100755 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2931Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2931Test.php @@ -14,9 +14,11 @@ public function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2931User'), - )); + ] + ); } catch (\Exception $e) { // no action needed - schema seems to be already in place } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2984Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2984Test.php index 19439c1434c..bf685328f2c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2984Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2984Test.php @@ -15,18 +15,20 @@ class DDC2984Test extends \Doctrine\Tests\OrmFunctionalTestCase public function setUp() { parent::setUp(); - + if ( ! Type::hasType('ddc2984_domain_user_id')) { Type::addType( - 'ddc2984_domain_user_id', + 'ddc2984_domain_user_id', __NAMESPACE__ . '\DDC2984UserIdCustomDbalType' ); } try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2984User'), - )); + ] + ); } catch (\Exception $e) { // no action needed - schema seems to be already in place } @@ -36,10 +38,10 @@ public function testIssue() { $user = new DDC2984User(new DDC2984DomainUserId('unique_id_within_a_vo')); $user->applyName('Alex'); - + $this->_em->persist($user); $this->_em->flush($user); - + $repository = $this->_em->getRepository(__NAMESPACE__ . "\DDC2984User"); $sameUser = $repository->find(new DDC2984DomainUserId('unique_id_within_a_vo')); @@ -154,7 +156,7 @@ public function sameValueAs(DDC2984DomainUserId $other) { return $this->toString() === $other->toString(); } -} +} /** * Class DDC2984UserIdCustomDbalType @@ -196,4 +198,4 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) return $value->toString(); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2996Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2996Test.php index 09d7415d2f9..897d3bfdf35 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2996Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2996Test.php @@ -9,10 +9,12 @@ class DDC2996Test extends \Doctrine\Tests\OrmFunctionalTestCase { public function testIssue() { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC2996User'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC2996UserPreference'), - )); + ] + ); $pref = new DDC2996UserPreference(); $pref->user = new DDC2996User(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3033Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3033Test.php index e79551191d5..153457805a8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3033Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3033Test.php @@ -12,10 +12,12 @@ class DDC3033Test extends \Doctrine\Tests\OrmFunctionalTestCase { public function testIssue() { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC3033User'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC3033Product'), - )); + ] + ); $user = new DDC3033User(); $user->name = "Test User"; @@ -38,12 +40,12 @@ public function testIssue() $this->_em->persist($product); $this->_em->flush(); - $expect = array( - 'title' => array( + $expect = [ + 'title' => [ 0 => 'Test product', 1 => 'Test Change title', - ), - ); + ], + ]; $this->assertEquals($expect, $product->changeSet); } @@ -55,7 +57,7 @@ public function testIssue() */ class DDC3033Product { - public $changeSet = array(); + public $changeSet = []; /** * @var int $id diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3042Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3042Test.php index fe84e11ffd3..222b30fc027 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3042Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3042Test.php @@ -13,10 +13,12 @@ protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3042Foo'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3042Bar'), - )); + ] + ); } public function testSQLGenerationDoesNotProvokeAliasCollisions() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3068Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3068Test.php index d43e355635d..83eb50aa95b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3068Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3068Test.php @@ -8,7 +8,7 @@ /** * @group DDC-3068 - * + * * @author Giorgio Premi */ class DDC3068Test extends \Doctrine\Tests\OrmFunctionalTestCase @@ -40,17 +40,19 @@ protected function setUp() public function testFindUsingAnArrayOfObjectAsPrimaryKey() { - $ride1 = $this->_em->find('Doctrine\Tests\Models\Taxi\Ride', array( + $ride1 = $this->_em->find('Doctrine\Tests\Models\Taxi\Ride', [ 'driver' => $this->foo->getId(), - 'car' => $this->merc->getBrand()) + 'car' => $this->merc->getBrand() + ] ); $this->assertInstanceOf('Doctrine\Tests\Models\Taxi\Ride', $ride1); - $ride2 = $this->_em->find('Doctrine\Tests\Models\Taxi\Ride', array( + $ride2 = $this->_em->find('Doctrine\Tests\Models\Taxi\Ride', [ 'driver' => $this->foo, 'car' => $this->merc - )); + ] + ); $this->assertInstanceOf('Doctrine\Tests\Models\Taxi\Ride', $ride2); $this->assertSame($ride1, $ride2); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC309Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC309Test.php index 402c4374a41..4d5583c7507 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC309Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC309Test.php @@ -9,10 +9,12 @@ class DDC309Test extends OrmFunctionalTestCase protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC309Country'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC309User'), - )); + ] + ); } public function testTwoIterateHydrations() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3123Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3123Test.php index 7f82e6c8969..515aa9febc7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3123Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3123Test.php @@ -26,10 +26,10 @@ public function testIssue() $user->username = 'ocramius'; $this->_em->persist($user); - $uow->scheduleExtraUpdate($user, array('name' => 'changed name')); + $uow->scheduleExtraUpdate($user, ['name' => 'changed name']); $listener = $this->getMockBuilder(\stdClass::class) - ->setMethods(array(Events::postFlush)) + ->setMethods([Events::postFlush]) ->getMock(); $listener diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php index 4924d39f9d4..92f2c1b27ef 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php @@ -18,12 +18,12 @@ protected function setUp() parent::setUp(); $this->_schemaTool->createSchema( - array( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3170AbstractEntityJoined'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3170ProductJoined'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3170AbstractEntitySingleTable'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3170ProductSingleTable'), - ) + ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3192Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3192Test.php index da6a8de1d3f..79dd4267eb5 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3192Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3192Test.php @@ -25,10 +25,12 @@ protected function setUp() Type::addType('ddc3192_currency_code', __NAMESPACE__ . '\DDC3192CurrencyCode'); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(DDC3192Currency::CLASSNAME), $this->_em->getClassMetadata(DDC3192Transaction::CLASSNAME), - )); + ] + ); } public function testIssue() @@ -130,9 +132,9 @@ public function __construct($amount, DDC3192Currency $currency) class DDC3192CurrencyCode extends Type { - private static $map = array( + private static $map = [ 'BYR' => 974, - ); + ]; /** * {@inheritdoc} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3223Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3223Test.php index 541221aa08e..be2c5861719 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3223Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3223Test.php @@ -15,12 +15,14 @@ protected function setUp() { parent::setUp(); - $this->setUpEntitySchema(array( + $this->setUpEntitySchema( + [ 'Doctrine\Tests\ORM\Functional\Ticket\Journalist', 'Doctrine\Tests\ORM\Functional\Ticket\Participant', 'Doctrine\Tests\ORM\Functional\Ticket\Status', 'Doctrine\Tests\ORM\Functional\Ticket\ProfileStatus', - )); + ] + ); } public function testIssueGetId() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3300Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3300Test.php index b7905ca3de1..8014ae6f873 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3300Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3300Test.php @@ -16,20 +16,22 @@ public function testResolveTargetEntitiesChangesDiscriminatorMapValues() $resolveTargetEntity->addResolveTargetEntity( DDC3300BossInterface::INTERFACENAME, DDC3300Boss::CLASSNAME, - array() + [] ); $resolveTargetEntity->addResolveTargetEntity( DDC3300EmployeeInterface::INTERFACENAME, DDC3300Employee::CLASSNAME, - array() + [] ); $this->_em->getEventManager()->addEventSubscriber($resolveTargetEntity); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(DDC3300Person::CLASSNAME), - )); + ] + ); $boss = new DDC3300Boss(); $employee = new DDC3300Employee(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3330Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3330Test.php index a5ed2577026..9edf5817007 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3330Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3330Test.php @@ -16,10 +16,12 @@ protected function setUp() { parent::setUp(); - $this->setUpEntitySchema(array( + $this->setUpEntitySchema( + [ 'Doctrine\Tests\ORM\Functional\Ticket\DDC3330_Building', 'Doctrine\Tests\ORM\Functional\Ticket\DDC3330_Hall', - )); + ] + ); } public function testIssueCollectionOrderWithPaginator() @@ -29,7 +31,7 @@ public function testIssueCollectionOrderWithPaginator() $this->createBuildingAndHalls(); $this->_em->clear(); - + $query = $this->_em->createQuery( 'SELECT b, h'. ' FROM Doctrine\Tests\ORM\Functional\Ticket\DDC3330_Building b'. @@ -37,32 +39,32 @@ public function testIssueCollectionOrderWithPaginator() ' ORDER BY b.id ASC, h.name DESC' ) ->setMaxResults(3); - + $paginator = new Paginator($query, true); - + /*foreach ($paginator as $building) { echo 'BUILDING ID: '.$building->id."\n"; foreach ($building->halls as $hall) { echo ' - HALL: '.$hall->id.' - '.$hall->name."\n"; } }*/ - + $this->assertEquals(3, count(iterator_to_array($paginator)), 'Count is not correct for pagination'); } - + /** * Create a building and 10 halls */ private function createBuildingAndHalls() { $building = new DDC3330_Building(); - + for ($i = 0; $i < 10; $i++) { $hall = new DDC3330_Hall(); $hall->name = 'HALL-'.$i; $building->addHall($hall); } - + $this->_em->persist($building); $this->_em->flush(); } @@ -78,7 +80,7 @@ class DDC3330_Building * @GeneratedValue */ public $id; - + /** * @OneToMany(targetEntity="DDC3330_Hall", mappedBy="building", cascade={"persist"}) */ diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3346Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3346Test.php index ba286da24f2..85b2086c7c3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3346Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3346Test.php @@ -23,7 +23,7 @@ public function testFindOneWithEagerFetchWillNotHydrateLimitedCollection() { /* @var DDC3346Author $author */ $author = $this->_em->getRepository(DDC3346Author::CLASSNAME)->findOneBy( - array('username' => 'bwoogy') + ['username' => 'bwoogy'] ); $this->assertCount(2, $author->articles); @@ -33,7 +33,7 @@ public function testFindLimitedWithEagerFetchWillNotHydrateLimitedCollection() { /* @var DDC3346Author[] $authors */ $authors = $this->_em->getRepository(DDC3346Author::CLASSNAME)->findBy( - array('username' => 'bwoogy'), + ['username' => 'bwoogy'], null, 1 ); @@ -46,7 +46,7 @@ public function testFindWithEagerFetchAndOffsetWillNotHydrateLimitedCollection() { /* @var DDC3346Author[] $authors */ $authors = $this->_em->getRepository(DDC3346Author::CLASSNAME)->findBy( - array('username' => 'bwoogy'), + ['username' => 'bwoogy'], null, null, 0 // using an explicitly defined offset diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php index 255790d7cc3..ea4c37722b0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php @@ -8,11 +8,13 @@ protected function setUp() { parent::setUp(); //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC345User'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC345Group'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC345Membership'), - )); + ] + ); } public function testTwoIterateHydrations() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC353Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC353Test.php index 03d28bb2e99..5d9e8a01429 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC353Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC353Test.php @@ -10,10 +10,12 @@ protected function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC353File'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC353Picture'), - )); + ] + ); } catch(\Exception $ignored) {} } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3597Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3597Test.php index e6f25b852e0..b4bb7891ccf 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3597Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3597Test.php @@ -13,11 +13,13 @@ class DDC3597Test extends \Doctrine\Tests\OrmFunctionalTestCase { protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(DDC3597Root::CLASSNAME), $this->_em->getClassMetadata(DDC3597Media::CLASSNAME), $this->_em->getClassMetadata(DDC3597Image::CLASSNAME) - )); + ] + ); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3644Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3644Test.php index 46eeeab7447..f4e338eace8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3644Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3644Test.php @@ -16,12 +16,14 @@ protected function setUp() { parent::setUp(); - $this->setUpEntitySchema(array( + $this->setUpEntitySchema( + [ 'Doctrine\Tests\ORM\Functional\Ticket\DDC3644User', 'Doctrine\Tests\ORM\Functional\Ticket\DDC3644Address', 'Doctrine\Tests\ORM\Functional\Ticket\DDC3644Animal', 'Doctrine\Tests\ORM\Functional\Ticket\DDC3644Pet', - )); + ] + ); } /** @@ -33,7 +35,7 @@ public function testIssueWithRegularEntity() $current = new DDC3644Address('Sao Paulo, SP, Brazil'); $previous = new DDC3644Address('Rio de Janeiro, RJ, Brazil'); $initial = new DDC3644Address('Sao Carlos, SP, Brazil'); - $addresses = new ArrayCollection(array($current, $previous, $initial)); + $addresses = new ArrayCollection([$current, $previous, $initial]); $user = new DDC3644User(); $user->name = 'Guilherme Blanco'; @@ -53,7 +55,7 @@ public function testIssueWithRegularEntity() // Replace entire collection (this should trigger OneToManyPersister::remove()) $current = new DDC3644Address('Toronto, ON, Canada'); - $addresses = new ArrayCollection(array($current)); + $addresses = new ArrayCollection([$current]); $user = $this->_em->find(__NAMESPACE__ . '\DDC3644User', $userId); $user->setAddresses($addresses); @@ -84,7 +86,7 @@ public function testIssueWithJoinedEntity() // Define initial dataset $actual = new DDC3644Pet('Catharina'); $past = new DDC3644Pet('Nanny'); - $pets = new ArrayCollection(array($actual, $past)); + $pets = new ArrayCollection([$actual, $past]); $user = new DDC3644User(); $user->name = 'Guilherme Blanco'; @@ -103,7 +105,7 @@ public function testIssueWithJoinedEntity() // Replace entire collection (this should trigger OneToManyPersister::remove()) $actual = new DDC3644Pet('Valentina'); - $pets = new ArrayCollection(array($actual)); + $pets = new ArrayCollection([$actual]); $user = $this->_em->find(__NAMESPACE__ . '\DDC3644User', $userId); $user->setPets($pets); @@ -242,4 +244,4 @@ class DDC3644Pet extends DDC3644Animal * @JoinColumn(referencedColumnName="hash_id") */ public $owner; -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3711Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3711Test.php index 60d872b4a08..6a08b49bcd0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3711Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3711Test.php @@ -23,8 +23,8 @@ public function testCompositeKeyForJoinTableInManyToManyCreation() $entityA = new ClassMetadata('Doctrine\Tests\Models\DDC3711\DDC3711EntityA'); $entityA = $factory->getMetadataFor('Doctrine\Tests\Models\DDC3711\DDC3711EntityA'); - $this->assertEquals(array('link_a_id1' => "id1", 'link_a_id2' => "id2"), $entityA->associationMappings['entityB']['relationToSourceKeyColumns']); - $this->assertEquals(array('link_b_id1' => "id1", 'link_b_id2' => "id2"), $entityA->associationMappings['entityB']['relationToTargetKeyColumns']); + $this->assertEquals(['link_a_id1' => "id1", 'link_a_id2' => "id2"], $entityA->associationMappings['entityB']['relationToSourceKeyColumns']); + $this->assertEquals(['link_b_id1' => "id1", 'link_b_id2' => "id2"], $entityA->associationMappings['entityB']['relationToTargetKeyColumns']); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php index 37e94c542bc..f7013d6d802 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php @@ -12,10 +12,12 @@ protected function setUp() { parent::setUp(); //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC371Parent'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC371Child') - )); + ] + ); } public function testIssue() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3785Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3785Test.php index 4940c8abc8a..f5b8cac01ab 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3785Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3785Test.php @@ -15,11 +15,13 @@ protected function setUp() Type::addType('ddc3785_asset_id', __NAMESPACE__ . '\\DDC3785_AssetIdType'); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC3785_Asset'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC3785_AssetId'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC3785_Attribute') - )); + ] + ); } catch(\Exception $e) { } } @@ -30,10 +32,10 @@ protected function setUp() public function testOwningValueObjectIdIsCorrectlyTransformedWhenRemovingOrphanedChildEntities() { $id = new DDC3785_AssetId("919609ba-57d9-4a13-be1d-d202521e858a"); - $attributes = array( - $attribute1 = new DDC3785_Attribute("foo1", "bar1"), + $attributes = [ + $attribute1 = new DDC3785_Attribute("foo1", "bar1"), $attribute2 = new DDC3785_Attribute("foo2", "bar2") - ); + ]; $this->_em->persist($asset = new DDC3785_Asset($id, $attributes)); $this->_em->flush(); @@ -64,7 +66,7 @@ class DDC3785_Asset **/ private $attributes; - public function __construct(DDC3785_AssetId $id, $attributes = array()) + public function __construct(DDC3785_AssetId $id, $attributes = []) { $this->id = $id; $this->attributes = new ArrayCollection(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC381Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC381Test.php index eb3b77f5607..2bf52eb340e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC381Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC381Test.php @@ -9,9 +9,11 @@ protected function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC381Entity'), - )); + ] + ); } catch(\Exception $e) { } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC422Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC422Test.php index 07f374b36d8..0325e117538 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC422Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC422Test.php @@ -8,11 +8,13 @@ protected function setUp() { parent::setUp(); //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC422Guest'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC422Customer'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC422Contact') - )); + ] + ); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC425Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC425Test.php index d3d3e27ba9e..e6389ebf976 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC425Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC425Test.php @@ -8,10 +8,12 @@ class DDC425Test extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC425Entity'), //$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC425Other') - )); + ] + ); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC440Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC440Test.php index f4f944ad54a..7fa7b58bded 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC440Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC440Test.php @@ -9,10 +9,12 @@ protected function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\DDC440Phone'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\DDC440Client') - )); + ] + ); } catch (\Exception $e) { // Swallow all exceptions. We do not test the schema tool here. } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC444Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC444Test.php index 58ac8f20a97..2615e37c6dd 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC444Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC444Test.php @@ -8,9 +8,11 @@ public function setUp() { parent::setUp(); //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC444User'), - )); + ] + ); } public function testExplicitPolicy() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC448Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC448Test.php index 3688a80d82f..41d1fdee67c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC448Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC448Test.php @@ -9,11 +9,13 @@ class DDC448Test extends OrmFunctionalTestCase protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC448MainTable'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC448ConnectedClass'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC448SubTable'), - )); + ] + ); } public function testIssue() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC493Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC493Test.php index 1a8384f7da7..5aebed10753 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC493Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC493Test.php @@ -7,11 +7,13 @@ class DDC493Test extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC493Customer'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC493Distributor'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC493Contact') - )); + ] + ); } public function testIssue() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC501Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC501Test.php index 45c202ee5e9..3763b15d77a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC501Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC501Test.php @@ -89,13 +89,13 @@ protected function createAndPersistUser() $user->username = 'lukacho'; $user->status = 'developer'; - foreach(array(1111,2222,3333,4444) as $number) { + foreach([1111,2222,3333,4444] as $number) { $phone = new CmsPhonenumber; $phone->phonenumber = $number; $user->addPhonenumber($phone); } - foreach(array('Moshers', 'Headbangers') as $groupName) { + foreach(['Moshers', 'Headbangers'] as $groupName) { $group = new CmsGroup; $group->setName($groupName); $user->addGroup($group); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC512Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC512Test.php index c6d792d3981..4cc5aee8c70 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC512Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC512Test.php @@ -9,11 +9,13 @@ class DDC512Test extends OrmFunctionalTestCase protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC512Customer'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC512OfferItem'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC512Item'), - )); + ] + ); } public function testIssue() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC513Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC513Test.php index 36bb29c74a3..11a7d2f6f17 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC513Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC513Test.php @@ -7,11 +7,13 @@ class DDC513Test extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC513OfferItem'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC513Item'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC513Price'), - )); + ] + ); } public function testIssue() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php index f87216a55b0..d8592b482d4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php @@ -12,11 +12,13 @@ protected function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC522Customer'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC522Cart'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC522ForeignKeyTest') - )); + ] + ); } catch(\Exception $e) { } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC531Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC531Test.php index 50f96968df8..f205ae69757 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC531Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC531Test.php @@ -7,10 +7,12 @@ class DDC531Test extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC531Item'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC531SubItem'), - )); + ] + ); } public function testIssue() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC588Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC588Test.php index b5ace06b072..05543835924 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC588Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC588Test.php @@ -7,9 +7,11 @@ class DDC588Test extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC588Site'), - )); + ] + ); } public function testIssue() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC599Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC599Test.php index ed91bd59d6e..fb596da525d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC599Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC599Test.php @@ -9,11 +9,13 @@ protected function setUp() parent::setUp(); //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC599Item'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC599Subitem'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC599Child'), - )); + ] + ); } catch (\Exception $ignored) {} } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC618Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC618Test.php index 165a42b6d66..5d5a6ac1ecc 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC618Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC618Test.php @@ -11,10 +11,12 @@ protected function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC618Author'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC618Book') - )); + ] + ); // Create author 10/Joe with two books 22/JoeA and 20/JoeB $author = new DDC618Author(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php index 0a538ee3e28..b88b1b15441 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php @@ -8,10 +8,12 @@ protected function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC633Patient'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC633Appointment'), - )); + ] + ); } catch(\Exception $e) { } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC656Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC656Test.php index eb368cd891d..2ebffe3400d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC656Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC656Test.php @@ -8,9 +8,11 @@ protected function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC656Entity') - )); + ] + ); } catch(\Exception $e) { } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC698Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC698Test.php index cf15770a811..c9bb3f09e5d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC698Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC698Test.php @@ -8,10 +8,12 @@ protected function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC698Role'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC698Privilege') - )); + ] + ); } catch(\Exception $e) { } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC719Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC719Test.php index 428fe057afa..1ae26394cac 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC719Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC719Test.php @@ -8,9 +8,11 @@ protected function setUp() { parent::setUp(); //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC719Group'), - )); + ] + ); } public function testIsEmptySqlGeneration() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC729Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC729Test.php index 0dc89a3b36a..730eb99eebc 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC729Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC729Test.php @@ -10,10 +10,12 @@ public function setUp() try { $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->_em); - $schemaTool->createSchema(array( + $schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC729A'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC729B'), - )); + ] + ); } catch(\Exception $e) { } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC735Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC735Test.php index 41f7b293b08..61babe8e63b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC735Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC735Test.php @@ -10,10 +10,12 @@ protected function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC735Product'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC735Review') - )); + ] + ); } catch(\Exception $e) { } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC736Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC736Test.php index a93c91c7e4b..5141e9f3a95 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC736Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC736Test.php @@ -41,7 +41,7 @@ public function testReorderEntityFetchJoinForHydration() $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCart', $cart2); $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $cart2->getCustomer()); $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCustomer', $cart2->getCustomer()); - $this->assertEquals(array('name' => 'roman', 'payment' => 'cash'), $result); + $this->assertEquals(['name' => 'roman', 'payment' => 'cash'], $result); } /** @@ -65,7 +65,8 @@ public function testDqlTreeWalkerReordering() $dql = "select c, c.name, ca, ca.payment from Doctrine\Tests\Models\ECommerce\ECommerceCart ca join ca.customer c"; $result = $this->_em->createQuery($dql) - ->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\Tests\ORM\Functional\Ticket\DisableFetchJoinTreeWalker')) + ->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\Tests\ORM\Functional\Ticket\DisableFetchJoinTreeWalker'] + ) ->getResult(); /* @var $cart2 Doctrine\Tests\Models\ECommerce\ECommerceCart */ diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC742Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC742Test.php index 46dddff6b25..773ad06a859 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC742Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC742Test.php @@ -25,10 +25,12 @@ protected function setUp() $this->_em->getMetadataFactory()->setCacheDriver(new FilesystemCache($testDir)); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC742User'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC742Comment') - )); + ] + ); } catch(\Exception $e) { } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC767Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC767Test.php index bcf72e4e98d..8420db13275 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC767Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC767Test.php @@ -48,7 +48,7 @@ public function testCollectionChangesInsideTransaction() $this->assertNotNull($pUser, "User not retrieved from database."); - $groups = array($group2->id, $group3->id); + $groups = [$group2->id, $group3->id]; try { $this->_em->beginTransaction(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php index a88bbad81ed..f6d7b95b991 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php @@ -7,31 +7,33 @@ class DDC809Test extends \Doctrine\Tests\OrmFunctionalTestCase public function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC809Variant'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC809SpecificationValue') - )); + ] + ); $conn = $this->_em->getConnection(); - $conn->insert('specification_value_test', array('specification_value_id' => 94589)); - $conn->insert('specification_value_test', array('specification_value_id' => 94593)); - $conn->insert('specification_value_test', array('specification_value_id' => 94606)); - $conn->insert('specification_value_test', array('specification_value_id' => 94607)); - $conn->insert('specification_value_test', array('specification_value_id' => 94609)); - $conn->insert('specification_value_test', array('specification_value_id' => 94711)); + $conn->insert('specification_value_test', ['specification_value_id' => 94589]); + $conn->insert('specification_value_test', ['specification_value_id' => 94593]); + $conn->insert('specification_value_test', ['specification_value_id' => 94606]); + $conn->insert('specification_value_test', ['specification_value_id' => 94607]); + $conn->insert('specification_value_test', ['specification_value_id' => 94609]); + $conn->insert('specification_value_test', ['specification_value_id' => 94711]); - $conn->insert('variant_test', array('variant_id' => 545208)); - $conn->insert('variant_test', array('variant_id' => 545209)); + $conn->insert('variant_test', ['variant_id' => 545208]); + $conn->insert('variant_test', ['variant_id' => 545209]); - $conn->insert('var_spec_value_test', array('variant_id' => 545208, 'specification_value_id' => 94606)); - $conn->insert('var_spec_value_test', array('variant_id' => 545208, 'specification_value_id' => 94607)); - $conn->insert('var_spec_value_test', array('variant_id' => 545208, 'specification_value_id' => 94609)); - $conn->insert('var_spec_value_test', array('variant_id' => 545208, 'specification_value_id' => 94711)); + $conn->insert('var_spec_value_test', ['variant_id' => 545208, 'specification_value_id' => 94606]); + $conn->insert('var_spec_value_test', ['variant_id' => 545208, 'specification_value_id' => 94607]); + $conn->insert('var_spec_value_test', ['variant_id' => 545208, 'specification_value_id' => 94609]); + $conn->insert('var_spec_value_test', ['variant_id' => 545208, 'specification_value_id' => 94711]); - $conn->insert('var_spec_value_test', array('variant_id' => 545209, 'specification_value_id' => 94589)); - $conn->insert('var_spec_value_test', array('variant_id' => 545209, 'specification_value_id' => 94593)); - $conn->insert('var_spec_value_test', array('variant_id' => 545209, 'specification_value_id' => 94606)); - $conn->insert('var_spec_value_test', array('variant_id' => 545209, 'specification_value_id' => 94607)); + $conn->insert('var_spec_value_test', ['variant_id' => 545209, 'specification_value_id' => 94589]); + $conn->insert('var_spec_value_test', ['variant_id' => 545209, 'specification_value_id' => 94593]); + $conn->insert('var_spec_value_test', ['variant_id' => 545209, 'specification_value_id' => 94606]); + $conn->insert('var_spec_value_test', ['variant_id' => 545209, 'specification_value_id' => 94607]); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php index 219aed48d8b..6e7d4ea2c0b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php @@ -14,11 +14,13 @@ public function setUp() $this->_em->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger()); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC832JoinedIndex'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC832JoinedTreeIndex'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC832Like'), - )); + ] + ); } catch(\Exception $e) { } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC837Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC837Test.php index ef4484ee73b..5cb8f925ae6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC837Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC837Test.php @@ -7,13 +7,15 @@ class DDC837Test extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC837Super'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC837Class1'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC837Class2'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC837Class3'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC837Aggregate'), - )); + ] + ); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php index 22e39f849a9..5bbeca21001 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php @@ -10,11 +10,13 @@ protected function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC881User'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC881Phonenumber'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC881Phonecall'), - )); + ] + ); } catch (\Exception $e) { } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC949Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC949Test.php index a1634fe5d65..7e10c2c2cab 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC949Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC949Test.php @@ -29,8 +29,12 @@ public function testBooleanThroughRepository() $this->_em->flush(); $this->_em->clear(); - $true = $this->_em->getRepository('Doctrine\Tests\Models\Generic\BooleanModel')->findOneBy(array('booleanField' => true)); - $false = $this->_em->getRepository('Doctrine\Tests\Models\Generic\BooleanModel')->findOneBy(array('booleanField' => false)); + $true = $this->_em->getRepository('Doctrine\Tests\Models\Generic\BooleanModel')->findOneBy( + ['booleanField' => true] + ); + $false = $this->_em->getRepository('Doctrine\Tests\Models\Generic\BooleanModel')->findOneBy( + ['booleanField' => false] + ); $this->assertInstanceOf('Doctrine\Tests\Models\Generic\BooleanModel', $true, "True model not found"); $this->assertTrue($true->booleanField, "True Boolean Model should be true."); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC960Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC960Test.php index b1432ec8b72..7f9167601c9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC960Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC960Test.php @@ -10,10 +10,12 @@ protected function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC960Root'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC960Child') - )); + ] + ); } catch(\Exception $e) { } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC992Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC992Test.php index 25363b0b3e8..e8849e10f0a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC992Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC992Test.php @@ -13,11 +13,13 @@ public function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC992Role'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC992Parent'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC992Child'), - )); + ] + ); } catch(\Exception $e) { } @@ -65,7 +67,7 @@ public function testOneToManyChild() $this->assertEquals(1, count($parent->childs)); $this->assertEquals(0, count($parent->childs[0]->childs())); - $child = $parentRepository->findOneBy(array("id" => $child->id)); + $child = $parentRepository->findOneBy(["id" => $child->id]); $this->assertSame($parent->childs[0], $child); $this->_em->clear(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php index b42dd653496..b7a748ddc46 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php @@ -15,11 +15,13 @@ protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(GH5762Driver::class), $this->_em->getClassMetadata(GH5762DriverRide::class), $this->_em->getClassMetadata(GH5762Car::class), - )); + ] + ); } public function testIssue() @@ -31,7 +33,7 @@ public function testIssue() self::assertInstanceOf(GH5762DriverRide::class, $result->driverRides->get(0)); self::assertInstanceOf(GH5762Car::class, $result->driverRides->get(0)->car); - $cars = array(); + $cars = []; foreach ($result->driverRides as $ride) { $cars[] = $ride->car->brand; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket2481Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket2481Test.php index 91521b5d5dd..86a7d641f5d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket2481Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket2481Test.php @@ -9,9 +9,11 @@ protected function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\Ticket2481Product') - )); + ] + ); } catch (\Exception $e) { // Swallow all exceptions. We do not test the schema tool here. } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket69.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket69.php index d9ac1cc6ab3..d04ac27305e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket69.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket69.php @@ -14,11 +14,13 @@ protected function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\Lemma'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\Relation'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\RelationType') - )); + ] + ); } catch (\Exception $e) { // Swallow all exceptions. We do not test the schema tool here. } diff --git a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php index c27e0dee638..a8afcf8caf7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php @@ -78,7 +78,7 @@ public function testArray() $dql = "SELECT s FROM Doctrine\Tests\Models\Generic\SerializationModel s"; $serialize = $this->_em->createQuery($dql)->getSingleResult(); - $this->assertEquals(array("foo" => "bar", "bar" => "baz"), $serialize->array); + $this->assertEquals(["foo" => "bar", "bar" => "baz"], $serialize->array); } public function testObject() @@ -125,7 +125,8 @@ public function testDateTime() $this->assertInstanceOf('DateTime', $dateTimeDb->datetime); $this->assertEquals('2009-10-02 20:10:52', $dateTimeDb->datetime->format('Y-m-d H:i:s')); - $articles = $this->_em->getRepository( 'Doctrine\Tests\Models\Generic\DateTimeModel' )->findBy( array( 'datetime' => new \DateTime( "now" ) ) ); + $articles = $this->_em->getRepository( 'Doctrine\Tests\Models\Generic\DateTimeModel' )->findBy( ['datetime' => new \DateTime( "now" )] + ); $this->assertEquals( 0, count( $articles ) ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/UUIDGeneratorTest.php b/tests/Doctrine/Tests/ORM/Functional/UUIDGeneratorTest.php index d5d559a4ff1..c722771da32 100644 --- a/tests/Doctrine/Tests/ORM/Functional/UUIDGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/UUIDGeneratorTest.php @@ -15,9 +15,11 @@ public function setUp() $this->markTestSkipped('Currently restricted to MySQL platform.'); } - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\\UUIDEntity') - )); + ] + ); } public function testGenerateUUID() diff --git a/tests/Doctrine/Tests/ORM/Functional/UnitOfWorkLifecycleTest.php b/tests/Doctrine/Tests/ORM/Functional/UnitOfWorkLifecycleTest.php index 3e8285e8f89..8c4c500e728 100644 --- a/tests/Doctrine/Tests/ORM/Functional/UnitOfWorkLifecycleTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/UnitOfWorkLifecycleTest.php @@ -68,7 +68,7 @@ public function testAddToIdentityMapWithoutIdentity() $this->expectException(ORMInvalidArgumentException::class); $this->expectExceptionMessage("The given entity of type 'Doctrine\Tests\Models\CMS\CmsUser' (Doctrine\Tests\Models\CMS\CmsUser@"); - $this->_em->getUnitOfWork()->registerManaged($user, array(), array()); + $this->_em->getUnitOfWork()->registerManaged($user, [], []); } public function testMarkReadOnlyNonManaged() @@ -80,4 +80,4 @@ public function testMarkReadOnlyNonManaged() $this->_em->getUnitOfWork()->markReadOnly($user); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php index a6ad68d0a61..1094da877a7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php @@ -81,7 +81,7 @@ public function testThatEntitiesAreFetchedFromTheDatabase() $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', - array('id1' => 'def', 'foreignEntity' => 'abc') + ['id1' => 'def', 'foreignEntity' => 'abc'] ); $owning = $this->_em->find( @@ -106,7 +106,7 @@ public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFr $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', - array('id1' => 'def', 'foreignEntity' => 'abc') + ['id1' => 'def', 'foreignEntity' => 'abc'] ); $owning = $this->_em->find( @@ -132,7 +132,7 @@ public function testThatInversedEntityIsFetchedFromTheDatabaseUsingAuxiliaryEnti $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', - array('id1' => 'def', 'foreignEntity' => $auxiliary) + ['id1' => 'def', 'foreignEntity' => $auxiliary] ); $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', $inversed); @@ -158,7 +158,7 @@ public function testThatTheCollectionFromInversedToOwningIsLoaded() { $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', - array('id1' => 'def', 'foreignEntity' => 'abc') + ['id1' => 'def', 'foreignEntity' => 'abc'] ); $this->assertCount(1, $inversed->associatedEntities); @@ -176,7 +176,7 @@ public function testThatTheJoinTableRowsAreRemovedWhenRemovingTheAssociation() $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', - array('id1' => 'def', 'foreignEntity' => 'abc') + ['id1' => 'def', 'foreignEntity' => 'abc'] ); foreach ($inversed->associatedEntities as $owning) { diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php index 32779164807..c7470a1987e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php @@ -68,7 +68,7 @@ public function testThatEntitiesAreFetchedFromTheDatabase() { $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdEntity', - array('id1' => 'abc', 'id2' => 'def') + ['id1' => 'abc', 'id2' => 'def'] ); $owning = $this->_em->find( @@ -87,7 +87,7 @@ public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFr { $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdEntity', - array('id1' => 'abc', 'id2' => 'def') + ['id1' => 'abc', 'id2' => 'def'] ); $owning = $this->_em->find( @@ -120,7 +120,7 @@ public function testThatTheCollectionFromInversedToOwningIsLoaded() { $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdEntity', - array('id1' => 'abc', 'id2' => 'def') + ['id1' => 'abc', 'id2' => 'def'] ); $this->assertCount(1, $inversed->associatedEntities); @@ -138,7 +138,7 @@ public function testThatTheJoinTableRowsAreRemovedWhenRemovingTheAssociation() $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdEntity', - array('id1' => 'abc', 'id2' => 'def') + ['id1' => 'abc', 'id2' => 'def'] ); foreach ($inversed->associatedEntities as $owning) { diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php index e899fbeb8d3..eb3de5f1229 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php @@ -79,7 +79,7 @@ public function testThatEntitiesAreFetchedFromTheDatabase() $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', - array('id1' => 'def', 'foreignEntity' => 'abc') + ['id1' => 'def', 'foreignEntity' => 'abc'] ); $owning = $this->_em->find( @@ -104,7 +104,7 @@ public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFr $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', - array('id1' => 'def', 'foreignEntity' => 'abc') + ['id1' => 'def', 'foreignEntity' => 'abc'] ); $owning = $this->_em->find( @@ -130,7 +130,7 @@ public function testThatInversedEntityIsFetchedFromTheDatabaseUsingAuxiliaryEnti $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', - array('id1' => 'def', 'foreignEntity' => $auxiliary) + ['id1' => 'def', 'foreignEntity' => $auxiliary] ); $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', $inversed); @@ -160,7 +160,7 @@ public function testThatTheCollectionFromInversedToOwningIsLoaded() { $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', - array('id1' => 'def', 'foreignEntity' => 'abc') + ['id1' => 'def', 'foreignEntity' => 'abc'] ); $this->assertCount(1, $inversed->associatedEntities); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php index eabf26a8051..f68084eb520 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php @@ -66,7 +66,7 @@ public function testThatEntitiesAreFetchedFromTheDatabase() { $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdEntity', - array('id1' => 'abc', 'id2' => 'def') + ['id1' => 'abc', 'id2' => 'def'] ); $owning = $this->_em->find( @@ -85,7 +85,7 @@ public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFr { $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdEntity', - array('id1' => 'abc', 'id2' => 'def') + ['id1' => 'abc', 'id2' => 'def'] ); $owning = $this->_em->find( @@ -120,7 +120,7 @@ public function testThatTheCollectionFromInversedToOwningIsLoaded() { $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdEntity', - array('id1' => 'abc', 'id2' => 'def') + ['id1' => 'abc', 'id2' => 'def'] ); $this->assertCount(1, $inversed->associatedEntities); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php index 762cad2ee32..e527ee2ef17 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php @@ -78,7 +78,7 @@ public function testThatEntitiesAreFetchedFromTheDatabase() $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', - array('id1' => 'def', 'foreignEntity' => 'abc') + ['id1' => 'def', 'foreignEntity' => 'abc'] ); $owning = $this->_em->find( @@ -103,7 +103,7 @@ public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFr $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', - array('id1' => 'def', 'foreignEntity' => 'abc') + ['id1' => 'def', 'foreignEntity' => 'abc'] ); $owning = $this->_em->find( @@ -129,7 +129,7 @@ public function testThatInversedEntityIsFetchedFromTheDatabaseUsingAuxiliaryEnti $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', - array('id1' => 'def', 'foreignEntity' => $auxiliary) + ['id1' => 'def', 'foreignEntity' => $auxiliary] ); $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', $inversed); @@ -157,7 +157,7 @@ public function testThatTheEntityFromInversedToOwningIsEagerLoaded() { $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', - array('id1' => 'def', 'foreignEntity' => 'abc') + ['id1' => 'def', 'foreignEntity' => 'abc'] ); $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity', $inversed->associatedEntity); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php index a179ab61a59..2f944f2356a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php @@ -65,7 +65,7 @@ public function testThatEntitiesAreFetchedFromTheDatabase() { $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdEntity', - array('id1' => 'abc', 'id2' => 'def') + ['id1' => 'abc', 'id2' => 'def'] ); $owning = $this->_em->find( @@ -84,7 +84,7 @@ public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFr { $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdEntity', - array('id1' => 'abc', 'id2' => 'def') + ['id1' => 'abc', 'id2' => 'def'] ); $owning = $this->_em->find( @@ -119,7 +119,7 @@ public function testThatTheEntityFromInversedToOwningIsEagerLoaded() { $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdEntity', - array('id1' => 'abc', 'id2' => 'def') + ['id1' => 'abc', 'id2' => 'def'] ); $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdEntity', $inversed->associatedEntity); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php index 47e98d25cfb..02b4748beed 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php @@ -15,14 +15,16 @@ public function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC93Person'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC93Address'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC93Vehicle'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC93Car'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3027Animal'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3027Dog'), - )); + ] + ); } catch(\Exception $e) { } } @@ -175,35 +177,35 @@ public function testDqlOnEmbeddedObjectsField() $this->_em->clear(); $this->assertNull($this->_em->find(__NAMESPACE__.'\\DDC93Person', $person->id)); } - + public function testPartialDqlOnEmbeddedObjectsField() { $person = new DDC93Person('Karl', new DDC93Address('Foo', '12345', 'Gosport', new DDC93Country('England'))); $this->_em->persist($person); $this->_em->flush($person); $this->_em->clear(); - + // Prove that the entity was persisted correctly. $dql = "SELECT p FROM " . __NAMESPACE__ ."\\DDC93Person p WHERE p.name = :name"; - + $person = $this->_em->createQuery($dql) ->setParameter('name', 'Karl') ->getSingleResult(); - + $this->assertEquals('Gosport', $person->address->city); $this->assertEquals('Foo', $person->address->street); $this->assertEquals('12345', $person->address->zip); $this->assertEquals('England', $person->address->country->name); - + // Clear the EM and prove that the embeddable can be the subject of a partial query. $this->_em->clear(); - + $dql = "SELECT PARTIAL p.{id,address.city} FROM " . __NAMESPACE__ ."\\DDC93Person p WHERE p.name = :name"; - + $person = $this->_em->createQuery($dql) ->setParameter('name', 'Karl') ->getSingleResult(); - + // Selected field must be equal, all other fields must be null. $this->assertEquals('Gosport', $person->address->city); $this->assertNull($person->address->street); @@ -213,13 +215,13 @@ public function testPartialDqlOnEmbeddedObjectsField() // Clear the EM and prove that the embeddable can be the subject of a partial query regardless of attributes positions. $this->_em->clear(); - + $dql = "SELECT PARTIAL p.{address.city, id} FROM " . __NAMESPACE__ ."\\DDC93Person p WHERE p.name = :name"; - + $person = $this->_em->createQuery($dql) ->setParameter('name', 'Karl') ->getSingleResult(); - + // Selected field must be equal, all other fields must be null. $this->assertEquals('Gosport', $person->address->city); $this->assertNull($person->address->street); @@ -236,7 +238,7 @@ public function testDqlWithNonExistentEmbeddableField() $this->_em->createQuery("SELECT p FROM " . __NAMESPACE__ . "\\DDC93Person p WHERE p.address.asdfasdf IS NULL") ->execute(); } - + public function testPartialDqlWithNonExistentEmbeddableField() { $this->expectException(QueryException::class); @@ -310,17 +312,19 @@ public function testThrowsExceptionOnInfiniteEmbeddableNesting($embeddableClassN ) ); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\\' . $embeddableClassName), - )); + ] + ); } public function getInfiniteEmbeddableNestingData() { - return array( - array('DDCInfiniteNestingEmbeddable', 'DDCInfiniteNestingEmbeddable'), - array('DDCNestingEmbeddable1', 'DDCNestingEmbeddable4'), - ); + return [ + ['DDCInfiniteNestingEmbeddable', 'DDCInfiniteNestingEmbeddable'], + ['DDCNestingEmbeddable1', 'DDCNestingEmbeddable4'], + ]; } } diff --git a/tests/Doctrine/Tests/ORM/Functional/VersionedOneToOneTest.php b/tests/Doctrine/Tests/ORM/Functional/VersionedOneToOneTest.php index f354be60088..0fef61a483b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/VersionedOneToOneTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/VersionedOneToOneTest.php @@ -22,10 +22,10 @@ protected function setUp() try { $this->_schemaTool->createSchema( - array( + [ $this->_em->getClassMetadata('Doctrine\Tests\Models\VersionedOneToOne\FirstRelatedEntity'), $this->_em->getClassMetadata('Doctrine\Tests\Models\VersionedOneToOne\SecondRelatedEntity') - ) + ] ); } catch (ORMException $e) { } @@ -51,10 +51,10 @@ public function testSetVersionOnCreate() $this->_em->flush(); $firstEntity = $this->_em->getRepository('Doctrine\Tests\Models\VersionedOneToOne\FirstRelatedEntity') - ->findOneBy(array('name' => 'Fred')); + ->findOneBy(['name' => 'Fred']); $secondEntity = $this->_em->getRepository('Doctrine\Tests\Models\VersionedOneToOne\SecondRelatedEntity') - ->findOneBy(array('name' => 'Bob')); + ->findOneBy(['name' => 'Bob']); $this->assertSame($firstRelatedEntity, $firstEntity); $this->assertSame($secondRelatedEntity, $secondEntity); diff --git a/tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php index 0942a6051e0..4763ded58ef 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php @@ -9,12 +9,12 @@ class ArrayHydratorTest extends HydrationTestCase { public function provideDataForUserEntityResult() { - return array( - array(0), - array('user'), - array('scalars'), - array('newObjects'), - ); + return [ + [0], + ['user'], + ['scalars'], + ['newObjects'], + ]; } /** @@ -30,16 +30,16 @@ public function testSimpleEntityQuery() $rsm->addFieldResult('u', 'u__name', 'name'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'u__id' => '1', 'u__name' => 'romanb' - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage' - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); @@ -72,18 +72,18 @@ public function testSimpleEntityWithScalarQuery($userEntityKey) $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 's__id' => '1', 's__name' => 'romanb', 'sclr0' => 'ROMANB', - ), - array( + ], + [ 's__id' => '2', 's__name' => 'jwage', 'sclr0' => 'JWAGE', - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); @@ -122,16 +122,16 @@ public function testSimpleEntityQueryWithAliasedUserEntity() $rsm->addFieldResult('u', 'u__name', 'name'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'u__id' => '1', 'u__name' => 'romanb' - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage' - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); @@ -165,20 +165,20 @@ public function testSimpleMultipleRootEntityQuery() $rsm->addFieldResult('a', 'a__topic', 'topic'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'u__id' => '1', 'u__name' => 'romanb', 'a__id' => '1', 'a__topic' => 'Cool things.' - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage', 'a__id' => '2', 'a__topic' => 'Cool things II.' - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); @@ -215,20 +215,20 @@ public function testSimpleMultipleRootEntityQueryWithAliasedUserEntity() $rsm->addFieldResult('a', 'a__topic', 'topic'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'u__id' => '1', 'u__name' => 'romanb', 'a__id' => '1', 'a__topic' => 'Cool things.' - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage', 'a__id' => '2', 'a__topic' => 'Cool things II.' - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); @@ -269,20 +269,20 @@ public function testSimpleMultipleRootEntityQueryWithAliasedArticleEntity() $rsm->addFieldResult('a', 'a__topic', 'topic'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'u__id' => '1', 'u__name' => 'romanb', 'a__id' => '1', 'a__topic' => 'Cool things.' - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage', 'a__id' => '2', 'a__topic' => 'Cool things II.' - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); @@ -323,20 +323,20 @@ public function testSimpleMultipleRootEntityQueryWithAliasedEntities() $rsm->addFieldResult('a', 'a__topic', 'topic'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'u__id' => '1', 'u__name' => 'romanb', 'a__id' => '1', 'a__topic' => 'Cool things.' - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage', 'a__id' => '2', 'a__topic' => 'Cool things II.' - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); @@ -379,19 +379,19 @@ public function testMixedQueryNormalJoin($userEntityKey) $rsm->addScalarResult('sclr0', 'numPhones', 'integer'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => '2', - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'sclr0' => '1', - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); @@ -435,27 +435,27 @@ public function testMixedQueryFetchJoin($userEntityKey) $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', 'p__phonenumber' => '42', - ), - array( + ], + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', 'p__phonenumber' => '43', - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'sclr0' => 'JWAGE', 'p__phonenumber' => '91' - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); @@ -508,27 +508,27 @@ public function testMixedQueryFetchJoinCustomIndex($userEntityKey) $rsm->addIndexBy('p', 'phonenumber'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', 'p__phonenumber' => '42', - ), - array( + ], + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', 'p__phonenumber' => '43', - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'sclr0' => 'JWAGE', 'p__phonenumber' => '91' - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); @@ -593,57 +593,57 @@ public function testMixedQueryMultipleFetchJoin() $rsm->addFieldResult('a', 'a__topic', 'topic'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', 'p__phonenumber' => '42', 'a__id' => '1', 'a__topic' => 'Getting things done!' - ), - array( + ], + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', 'p__phonenumber' => '43', 'a__id' => '1', 'a__topic' => 'Getting things done!' - ), - array( + ], + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', 'p__phonenumber' => '42', 'a__id' => '2', 'a__topic' => 'ZendCon' - ), - array( + ], + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', 'p__phonenumber' => '43', 'a__id' => '2', 'a__topic' => 'ZendCon' - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'sclr0' => 'JWAGE', 'p__phonenumber' => '91', 'a__id' => '3', 'a__topic' => 'LINQ' - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'sclr0' => 'JWAGE', 'p__phonenumber' => '91', 'a__id' => '4', 'a__topic' => 'PHP7' - ), - ); + ], + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); @@ -720,9 +720,9 @@ public function testMixedQueryMultipleDeepMixedFetchJoin() $rsm->addFieldResult('c', 'c__topic', 'topic'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', @@ -731,8 +731,8 @@ public function testMixedQueryMultipleDeepMixedFetchJoin() 'a__topic' => 'Getting things done!', 'c__id' => '1', 'c__topic' => 'First!' - ), - array( + ], + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', @@ -741,8 +741,8 @@ public function testMixedQueryMultipleDeepMixedFetchJoin() 'a__topic' => 'Getting things done!', 'c__id' => '1', 'c__topic' => 'First!' - ), - array( + ], + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', @@ -751,8 +751,8 @@ public function testMixedQueryMultipleDeepMixedFetchJoin() 'a__topic' => 'ZendCon', 'c__id' => null, 'c__topic' => null - ), - array( + ], + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', @@ -761,8 +761,8 @@ public function testMixedQueryMultipleDeepMixedFetchJoin() 'a__topic' => 'ZendCon', 'c__id' => null, 'c__topic' => null - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'sclr0' => 'JWAGE', @@ -771,8 +771,8 @@ public function testMixedQueryMultipleDeepMixedFetchJoin() 'a__topic' => 'LINQ', 'c__id' => null, 'c__topic' => null - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'sclr0' => 'JWAGE', @@ -781,8 +781,8 @@ public function testMixedQueryMultipleDeepMixedFetchJoin() 'a__topic' => 'PHP7', 'c__id' => null, 'c__topic' => null - ), - ); + ], + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); @@ -863,40 +863,40 @@ public function testEntityQueryCustomResultSetOrder() $rsm->addFieldResult('b', 'b__position', 'position'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'c__id' => '1', 'c__position' => '0', 'c__name' => 'First', 'b__id' => '1', 'b__position' => '0', //'b__category_id' => '1' - ), - array( + ], + [ 'c__id' => '2', 'c__position' => '0', 'c__name' => 'Second', 'b__id' => '2', 'b__position' => '0', //'b__category_id' => '2' - ), - array( + ], + [ 'c__id' => '1', 'c__position' => '0', 'c__name' => 'First', 'b__id' => '3', 'b__position' => '1', //'b__category_id' => '1' - ), - array( + ], + [ 'c__id' => '1', 'c__position' => '0', 'c__name' => 'First', 'b__id' => '4', 'b__position' => '2', //'b__category_id' => '1' - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); @@ -933,33 +933,33 @@ public function testChainedJoinWithScalars($entityKey) $rsm->addScalarResult('c__topic', 'ctopic', 'string'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'a__id' => '1', 'a__topic' => 'The First', 'c__id' => '1', 'c__topic' => 'First Comment' - ), - array( + ], + [ 'u__id' => '1', 'u__status' => 'developer', 'a__id' => '1', 'a__topic' => 'The First', 'c__id' => '2', 'c__topic' => 'Second Comment' - ), - array( + ], + [ 'u__id' => '1', 'u__status' => 'developer', 'a__id' => '42', 'a__topic' => 'The Answer', 'c__id' => null, 'c__topic' => null - ), - ); + ], + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); @@ -999,16 +999,16 @@ public function testResultIteration() $rsm->addFieldResult('u', 'u__name', 'name'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'u__id' => '1', 'u__name' => 'romanb' - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage' - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); @@ -1044,16 +1044,16 @@ public function testResultIterationWithAliasedUserEntity() $rsm->addFieldResult('u', 'u__name', 'name'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'u__id' => '1', 'u__name' => 'romanb' - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage' - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); @@ -1092,13 +1092,13 @@ public function testSkipUnknownColumns() $rsm->addFieldResult('u', 'u__name', 'name'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'u__id' => '1', 'u__name' => 'romanb', 'foo' => 'bar', // unknown! - ), - ); + ], + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); @@ -1127,29 +1127,29 @@ public function testMissingIdForRootEntity($userEntityKey) $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', - ), - array( + ], + [ 'u__id' => null, 'u__status' => null, 'sclr0' => 'ROMANB', - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'sclr0' => 'JWAGE', - ), - array( + ], + [ 'u__id' => null, 'u__status' => null, 'sclr0' => 'JWAGE', - ), - ); + ], + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); @@ -1162,9 +1162,9 @@ public function testMissingIdForRootEntity($userEntityKey) $this->assertEquals('JWAGE', $result[2]['nameUpper']); $this->assertEquals('JWAGE', $result[3]['nameUpper']); - $this->assertEquals(array('id' => 1, 'status' => 'developer'), $result[0][$userEntityKey]); + $this->assertEquals(['id' => 1, 'status' => 'developer'], $result[0][$userEntityKey]); $this->assertNull($result[1][$userEntityKey]); - $this->assertEquals(array('id' => 2, 'status' => 'developer'), $result[2][$userEntityKey]); + $this->assertEquals(['id' => 2, 'status' => 'developer'], $result[2][$userEntityKey]); $this->assertNull($result[3][$userEntityKey]); } @@ -1187,19 +1187,19 @@ public function testIndexByAndMixedResult($userEntityKey) $rsm->addIndexBy('u', 'id'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'sclr0' => 'JWAGE', - ), - ); + ], + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); diff --git a/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php index 22cf3b5985e..7a4c8aaedb6 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php @@ -14,28 +14,28 @@ class ObjectHydratorTest extends HydrationTestCase { public function provideDataForUserEntityResult() { - return array( - array(0), - array('user'), - ); + return [ + [0], + ['user'], + ]; } public function provideDataForMultipleRootEntityResult() { - return array( - array(0, 0), - array('user', 0), - array(0, 'article'), - array('user', 'article'), - ); + return [ + [0, 0], + ['user', 0], + [0, 'article'], + ['user', 'article'], + ]; } public function provideDataForProductEntityResult() { - return array( - array(0), - array('product'), - ); + return [ + [0], + ['product'], + ]; } /** @@ -50,20 +50,20 @@ public function testSimpleEntityQuery() $rsm->addFieldResult('u', 'u__name', 'name'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'u__id' => '1', 'u__name' => 'romanb' - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage' - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $this->assertEquals(2, count($result)); @@ -89,20 +89,20 @@ public function testSimpleEntityQueryWithAliasedUserEntity() $rsm->addFieldResult('u', 'u__name', 'name'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'u__id' => '1', 'u__name' => 'romanb' - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage' - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $this->assertEquals(2, count($result)); @@ -134,24 +134,24 @@ public function testSimpleMultipleRootEntityQuery() $rsm->addFieldResult('a', 'a__topic', 'topic'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'u__id' => '1', 'u__name' => 'romanb', 'a__id' => '1', 'a__topic' => 'Cool things.' - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage', 'a__id' => '2', 'a__topic' => 'Cool things II.' - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $this->assertEquals(4, count($result)); @@ -188,24 +188,24 @@ public function testSimpleMultipleRootEntityQueryWithAliasedUserEntity() $rsm->addFieldResult('a', 'a__topic', 'topic'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'u__id' => '1', 'u__name' => 'romanb', 'a__id' => '1', 'a__topic' => 'Cool things.' - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage', 'a__id' => '2', 'a__topic' => 'Cool things II.' - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $this->assertEquals(4, count($result)); @@ -249,24 +249,24 @@ public function testSimpleMultipleRootEntityQueryWithAliasedArticleEntity() $rsm->addFieldResult('a', 'a__topic', 'topic'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'u__id' => '1', 'u__name' => 'romanb', 'a__id' => '1', 'a__topic' => 'Cool things.' - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage', 'a__id' => '2', 'a__topic' => 'Cool things II.' - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $this->assertEquals(4, count($result)); @@ -310,24 +310,24 @@ public function testSimpleMultipleRootEntityQueryWithAliasedEntities() $rsm->addFieldResult('a', 'a__topic', 'topic'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'u__id' => '1', 'u__name' => 'romanb', 'a__id' => '1', 'a__topic' => 'Cool things.' - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage', 'a__id' => '2', 'a__topic' => 'Cool things II.' - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $this->assertEquals(4, count($result)); @@ -373,23 +373,23 @@ public function testMixedQueryNormalJoin($userEntityKey) $rsm->addScalarResult('sclr0', 'numPhones', 'integer'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => '2', - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'sclr0' => '1', - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $this->assertEquals(2, count($result)); @@ -429,31 +429,31 @@ public function testMixedQueryFetchJoin($userEntityKey) $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'p__phonenumber' => '42', 'sclr0' => 'ROMANB', - ), - array( + ], + [ 'u__id' => '1', 'u__status' => 'developer', 'p__phonenumber' => '43', 'sclr0' => 'ROMANB', - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'p__phonenumber' => '91', 'sclr0' => 'JWAGE', - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $this->assertEquals(2, count($result)); @@ -509,32 +509,32 @@ public function testMixedQueryFetchJoinCustomIndex($userEntityKey) $rsm->addIndexBy('p', 'phonenumber'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', 'p__phonenumber' => '42', - ), - array( + ], + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', 'p__phonenumber' => '43', - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'sclr0' => 'JWAGE', 'p__phonenumber' => '91' - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $this->assertEquals(2, count($result)); @@ -594,61 +594,61 @@ public function testMixedQueryMultipleFetchJoin($userEntityKey) $rsm->addFieldResult('a', 'a__topic', 'topic'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', 'p__phonenumber' => '42', 'a__id' => '1', 'a__topic' => 'Getting things done!' - ), - array( + ], + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', 'p__phonenumber' => '43', 'a__id' => '1', 'a__topic' => 'Getting things done!' - ), - array( + ], + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', 'p__phonenumber' => '42', 'a__id' => '2', 'a__topic' => 'ZendCon' - ), - array( + ], + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', 'p__phonenumber' => '43', 'a__id' => '2', 'a__topic' => 'ZendCon' - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'sclr0' => 'JWAGE', 'p__phonenumber' => '91', 'a__id' => '3', 'a__topic' => 'LINQ' - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'sclr0' => 'JWAGE', 'p__phonenumber' => '91', 'a__id' => '4', 'a__topic' => 'PHP7' - ), - ); + ], + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $this->assertEquals(2, count($result)); @@ -712,9 +712,9 @@ public function testMixedQueryMultipleDeepMixedFetchJoin($userEntityKey) $rsm->addFieldResult('c', 'c__topic', 'topic'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', @@ -723,8 +723,8 @@ public function testMixedQueryMultipleDeepMixedFetchJoin($userEntityKey) 'a__topic' => 'Getting things done!', 'c__id' => '1', 'c__topic' => 'First!' - ), - array( + ], + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', @@ -733,8 +733,8 @@ public function testMixedQueryMultipleDeepMixedFetchJoin($userEntityKey) 'a__topic' => 'Getting things done!', 'c__id' => '1', 'c__topic' => 'First!' - ), - array( + ], + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', @@ -743,8 +743,8 @@ public function testMixedQueryMultipleDeepMixedFetchJoin($userEntityKey) 'a__topic' => 'ZendCon', 'c__id' => null, 'c__topic' => null - ), - array( + ], + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', @@ -753,8 +753,8 @@ public function testMixedQueryMultipleDeepMixedFetchJoin($userEntityKey) 'a__topic' => 'ZendCon', 'c__id' => null, 'c__topic' => null - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'sclr0' => 'JWAGE', @@ -763,8 +763,8 @@ public function testMixedQueryMultipleDeepMixedFetchJoin($userEntityKey) 'a__topic' => 'LINQ', 'c__id' => null, 'c__topic' => null - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'sclr0' => 'JWAGE', @@ -773,12 +773,12 @@ public function testMixedQueryMultipleDeepMixedFetchJoin($userEntityKey) 'a__topic' => 'PHP7', 'c__id' => null, 'c__topic' => null - ), - ); + ], + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $this->assertEquals(2, count($result)); @@ -854,44 +854,44 @@ public function testEntityQueryCustomResultSetOrder() $rsm->addFieldResult('b', 'b__position', 'position'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'c__id' => '1', 'c__position' => '0', 'c__name' => 'First', 'b__id' => '1', 'b__position' => '0', //'b__category_id' => '1' - ), - array( + ], + [ 'c__id' => '2', 'c__position' => '0', 'c__name' => 'Second', 'b__id' => '2', 'b__position' => '0', //'b__category_id' => '2' - ), - array( + ], + [ 'c__id' => '1', 'c__position' => '0', 'c__name' => 'First', 'b__id' => '3', 'b__position' => '1', //'b__category_id' => '1' - ), - array( + ], + [ 'c__id' => '1', 'c__position' => '0', 'c__name' => 'First', 'b__id' => '4', 'b__position' => '2', //'b__category_id' => '1' - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $this->assertEquals(2, count($result)); @@ -924,17 +924,17 @@ public function testSkipUnknownColumns() $rsm->addFieldResult('u', 'u__name', 'name'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'u__id' => '1', 'u__name' => 'romanb', 'foo' => 'bar', // unknown! - ), - ); + ], + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $this->assertEquals(1, count($result)); $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0]); @@ -954,20 +954,20 @@ public function testScalarQueryWithoutResultVariables($userEntityKey) $rsm->addScalarResult('sclr1', 'name', 'string'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'sclr0' => '1', 'sclr1' => 'romanb' - ), - array( + ], + [ 'sclr0' => '2', 'sclr1' => 'jwage' - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $this->assertEquals(2, count($result)); @@ -994,25 +994,25 @@ public function testCreatesProxyForLazyLoadingWithForeignKeys() $rsm->addMetaResult('p', 'p__shipping_id', 'shipping_id', false, 'integer'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'p__id' => '1', 'p__name' => 'Doctrine Book', 'p__shipping_id' => 42 - ) - ); + ] + ]; $proxyInstance = new \Doctrine\Tests\Models\ECommerce\ECommerceShipping(); // mocking the proxy factory $proxyFactory = $this->getMockBuilder(ProxyFactory::class) - ->setMethods(array('getProxy')) + ->setMethods(['getProxy']) ->disableOriginalConstructor() ->getMock(); $proxyFactory->expects($this->once()) ->method('getProxy') - ->with($this->equalTo('Doctrine\Tests\Models\ECommerce\ECommerceShipping'), array('id' => 42)) + ->with($this->equalTo('Doctrine\Tests\Models\ECommerce\ECommerceShipping'), ['id' => 42]) ->will($this->returnValue($proxyInstance)); $this->_em->setProxyFactory($proxyFactory); @@ -1043,25 +1043,25 @@ public function testCreatesProxyForLazyLoadingWithForeignKeysWithAliasedProductE $rsm->addMetaResult('p', 'p__shipping_id', 'shipping_id', false, 'integer'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'p__id' => '1', 'p__name' => 'Doctrine Book', 'p__shipping_id' => 42 - ) - ); + ] + ]; $proxyInstance = new \Doctrine\Tests\Models\ECommerce\ECommerceShipping(); // mocking the proxy factory $proxyFactory = $this->getMockBuilder(ProxyFactory::class) - ->setMethods(array('getProxy')) + ->setMethods(['getProxy']) ->disableOriginalConstructor() ->getMock(); $proxyFactory->expects($this->once()) ->method('getProxy') - ->with($this->equalTo('Doctrine\Tests\Models\ECommerce\ECommerceShipping'), array('id' => 42)) + ->with($this->equalTo('Doctrine\Tests\Models\ECommerce\ECommerceShipping'), ['id' => 42]) ->will($this->returnValue($proxyInstance)); $this->_em->setProxyFactory($proxyFactory); @@ -1110,29 +1110,29 @@ public function testChainedJoinWithEmptyCollections() $rsm->addFieldResult('c', 'c__topic', 'topic'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'a__id' => null, 'a__topic' => null, 'c__id' => null, 'c__topic' => null - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'a__id' => null, 'a__topic' => null, 'c__id' => null, 'c__topic' => null - ), - ); + ], + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $this->assertEquals(2, count($result)); @@ -1173,29 +1173,29 @@ public function testChainedJoinWithEmptyCollectionsWithAliasedUserEntity() $rsm->addFieldResult('c', 'c__topic', 'topic'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'a__id' => null, 'a__topic' => null, 'c__id' => null, 'c__topic' => null - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'a__id' => null, 'a__topic' => null, 'c__id' => null, 'c__topic' => null - ), - ); + ], + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $this->assertEquals(2, count($result)); @@ -1285,20 +1285,20 @@ public function testResultIteration() $rsm->addFieldResult('u', 'u__name', 'name'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'u__id' => '1', 'u__name' => 'romanb' - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage' - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $iterableResult = $hydrator->iterate($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $iterableResult = $hydrator->iterate($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $rowNum = 0; while (($row = $iterableResult->next()) !== false) { @@ -1329,20 +1329,20 @@ public function testResultIterationWithAliasedUserEntity() $rsm->addFieldResult('u', 'u__name', 'name'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'u__id' => '1', 'u__name' => 'romanb' - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage' - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $iterableResult = $hydrator->iterate($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $iterableResult = $hydrator->iterate($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $rowNum = 0; while (($row = $iterableResult->next()) !== false) { @@ -1384,96 +1384,96 @@ public function testManyToManyHydration() $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'u__id' => '1', 'u__name' => 'romanb', 'g__id' => '3', 'g__name' => 'TestGroupB', 'p__phonenumber' => 1111, - ), - array( + ], + [ 'u__id' => '1', 'u__name' => 'romanb', 'g__id' => '5', 'g__name' => 'TestGroupD', 'p__phonenumber' => 1111, - ), - array( + ], + [ 'u__id' => '1', 'u__name' => 'romanb', 'g__id' => '3', 'g__name' => 'TestGroupB', 'p__phonenumber' => 2222, - ), - array( + ], + [ 'u__id' => '1', 'u__name' => 'romanb', 'g__id' => '5', 'g__name' => 'TestGroupD', 'p__phonenumber' => 2222, - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage', 'g__id' => '2', 'g__name' => 'TestGroupA', 'p__phonenumber' => 3333, - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage', 'g__id' => '3', 'g__name' => 'TestGroupB', 'p__phonenumber' => 3333, - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage', 'g__id' => '4', 'g__name' => 'TestGroupC', 'p__phonenumber' => 3333, - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage', 'g__id' => '5', 'g__name' => 'TestGroupD', 'p__phonenumber' => 3333, - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage', 'g__id' => '2', 'g__name' => 'TestGroupA', 'p__phonenumber' => 4444, - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage', 'g__id' => '3', 'g__name' => 'TestGroupB', 'p__phonenumber' => 4444, - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage', 'g__id' => '4', 'g__name' => 'TestGroupC', 'p__phonenumber' => 4444, - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage', 'g__id' => '5', 'g__name' => 'TestGroupD', 'p__phonenumber' => 4444, - ), - ); + ], + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $this->assertEquals(2, count($result)); @@ -1507,96 +1507,96 @@ public function testManyToManyHydrationWithAliasedUserEntity() $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'u__id' => '1', 'u__name' => 'romanb', 'g__id' => '3', 'g__name' => 'TestGroupB', 'p__phonenumber' => 1111, - ), - array( + ], + [ 'u__id' => '1', 'u__name' => 'romanb', 'g__id' => '5', 'g__name' => 'TestGroupD', 'p__phonenumber' => 1111, - ), - array( + ], + [ 'u__id' => '1', 'u__name' => 'romanb', 'g__id' => '3', 'g__name' => 'TestGroupB', 'p__phonenumber' => 2222, - ), - array( + ], + [ 'u__id' => '1', 'u__name' => 'romanb', 'g__id' => '5', 'g__name' => 'TestGroupD', 'p__phonenumber' => 2222, - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage', 'g__id' => '2', 'g__name' => 'TestGroupA', 'p__phonenumber' => 3333, - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage', 'g__id' => '3', 'g__name' => 'TestGroupB', 'p__phonenumber' => 3333, - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage', 'g__id' => '4', 'g__name' => 'TestGroupC', 'p__phonenumber' => 3333, - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage', 'g__id' => '5', 'g__name' => 'TestGroupD', 'p__phonenumber' => 3333, - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage', 'g__id' => '2', 'g__name' => 'TestGroupA', 'p__phonenumber' => 4444, - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage', 'g__id' => '3', 'g__name' => 'TestGroupB', 'p__phonenumber' => 4444, - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage', 'g__id' => '4', 'g__name' => 'TestGroupC', 'p__phonenumber' => 4444, - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage', 'g__id' => '5', 'g__name' => 'TestGroupD', 'p__phonenumber' => 4444, - ), - ); + ], + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $this->assertEquals(2, count($result)); @@ -1628,33 +1628,33 @@ public function testMissingIdForRootEntity($userEntityKey) $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', - ), - array( + ], + [ 'u__id' => null, 'u__status' => null, 'sclr0' => 'ROMANB', - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'sclr0' => 'JWAGE', - ), - array( + ], + [ 'u__id' => null, 'u__status' => null, 'sclr0' => 'JWAGE', - ), - ); + ], + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $this->assertEquals(4, count($result), "Should hydrate four results."); @@ -1694,37 +1694,37 @@ public function testMissingIdForCollectionValuedChildEntity($userEntityKey) $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', 'p__phonenumber' => '42', - ), - array( + ], + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', 'p__phonenumber' => null - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'sclr0' => 'JWAGE', 'p__phonenumber' => '91' - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'sclr0' => 'JWAGE', 'p__phonenumber' => null - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $this->assertEquals(2, count($result)); @@ -1758,27 +1758,27 @@ public function testMissingIdForSingleValuedChildEntity($userEntityKey) $rsm->addMetaResult('a', 'user_id', 'user_id', false, 'string'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', 'a__id' => 1, 'a__city' => 'Berlin', - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'sclr0' => 'BENJAMIN', 'a__id' => null, 'a__city' => null, - ), - ); + ], + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $this->assertEquals(2, count($result)); @@ -1804,23 +1804,23 @@ public function testIndexByAndMixedResult($userEntityKey) $rsm->addIndexBy('u', 'id'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'sclr0' => 'JWAGE', - ), - ); + ], + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $this->assertEquals(2, count($result)); @@ -1846,25 +1846,25 @@ public function testIndexByScalarsOnly($userEntityKey) $rsm->addIndexByScalar('sclr0'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'sclr0' => 'ROMANB', - ), - array( + ], + [ 'sclr0' => 'JWAGE', - ), - ); + ], + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $this->assertEquals( - array( - 'ROMANB' => array('nameUpper' => 'ROMANB'), - 'JWAGE' => array('nameUpper' => 'JWAGE') - ), + [ + 'ROMANB' => ['nameUpper' => 'ROMANB'], + 'JWAGE' => ['nameUpper' => 'JWAGE'] + ], $result ); } @@ -1885,12 +1885,12 @@ public function testMissingMetaMappingException() $rsm->addFieldResult('c', 'c__id', 'id'); $rsm->setDiscriminatorColumn('c', 'c_discr'); - $resultSet = array( - array( + $resultSet = [ + [ 'c__id' => '1', 'c_discr' => 'fix', - ), - ); + ], + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); @@ -1917,14 +1917,14 @@ public function testMissingDiscriminatorColumnException() $rsm->addMetaResult('e ', 'e_discr', 'discr', false, 'string'); $rsm->setDiscriminatorColumn('e', 'e_discr'); - $resultSet = array( - array( + $resultSet = [ + [ 'c__id' => '1', 'c_discr' => 'fix', 'e__id' => '1', 'e__name' => 'Fabio B. Silva' - ), - ); + ], + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); @@ -1947,13 +1947,13 @@ public function testInvalidDiscriminatorValueException() $rsm->addMetaResult('p', 'discr', 'discr', false, 'string'); $rsm->setDiscriminatorColumn('p', 'discr'); - $resultSet = array( - array( + $resultSet = [ + [ 'p__id' => '1', 'p__name' => 'Fabio B. Silva', 'discr' => 'subworker' - ), - ); + ], + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); @@ -1969,12 +1969,12 @@ public function testFetchJoinCollectionValuedAssociationWithDefaultArrayValue() $rsm->addFieldResult('e1', 'a1__id', 'id'); $rsm->addFieldResult('e2', 'e2__id', 'id'); - $resultSet = array( - array( + $resultSet = [ + [ 'a1__id' => '1', 'e2__id' => '1', - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); diff --git a/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php b/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php index 2ce9ae78930..745f30ec098 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php @@ -99,61 +99,68 @@ public function testAddNamedNativeQueryResultSetMapping() $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); - $cm->mapOneToOne(array( + $cm->mapOneToOne( + [ 'fieldName' => 'email', 'targetEntity' => 'Doctrine\Tests\Models\CMS\CmsEmail', - 'cascade' => array('persist'), + 'cascade' => ['persist'], 'inversedBy' => 'user', 'orphanRemoval' => false, - 'joinColumns' => array(array( + 'joinColumns' => [ + [ 'nullable' => true, 'referencedColumnName' => 'id', - ) - ) - )); + ] + ] + ] + ); - $cm->addNamedNativeQuery(array( + $cm->addNamedNativeQuery( + [ 'name' => 'find-all', 'query' => 'SELECT u.id AS user_id, e.id AS email_id, u.name, e.email, u.id + e.id AS scalarColumn FROM cms_users u INNER JOIN cms_emails e ON e.id = u.email_id', 'resultSetMapping' => 'find-all', - )); + ] + ); - $cm->addSqlResultSetMapping(array( + $cm->addSqlResultSetMapping( + [ 'name' => 'find-all', - 'entities' => array( - array( + 'entities' => [ + [ 'entityClass' => '__CLASS__', - 'fields' => array( - array( + 'fields' => [ + [ 'name' => 'id', 'column'=> 'user_id' - ), - array( + ], + [ 'name' => 'name', 'column'=> 'name' - ) - ) - ), - array( + ] + ] + ], + [ 'entityClass' => 'CmsEmail', - 'fields' => array( - array( + 'fields' => [ + [ 'name' => 'id', 'column'=> 'email_id' - ), - array( + ], + [ 'name' => 'email', 'column'=> 'email' - ) - ) - ) - ), - 'columns' => array( - array( + ] + ] + ] + ], + 'columns' => [ + [ 'name' => 'scalarColumn' - ) - ) - )); + ] + ] + ] + ); $queryMapping = $cm->getNamedNativeQuery('find-all'); @@ -184,25 +191,29 @@ public function testAddNamedNativeQueryResultSetMappingWithoutFields() $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); - $cm->addNamedNativeQuery(array( + $cm->addNamedNativeQuery( + [ 'name' => 'find-all', 'query' => 'SELECT u.id AS user_id, e.id AS email_id, u.name, e.email, u.id + e.id AS scalarColumn FROM cms_users u INNER JOIN cms_emails e ON e.id = u.email_id', 'resultSetMapping' => 'find-all', - )); + ] + ); - $cm->addSqlResultSetMapping(array( + $cm->addSqlResultSetMapping( + [ 'name' => 'find-all', - 'entities' => array( - array( + 'entities' => [ + [ 'entityClass' => '__CLASS__', - ) - ), - 'columns' => array( - array( + ] + ], + 'columns' => [ + [ 'name' => 'scalarColumn' - ) - ) - )); + ] + ] + ] + ); $queryMapping = $cm->getNamedNativeQuery('find-all'); $rsm = new \Doctrine\ORM\Query\ResultSetMappingBuilder($this->_em); @@ -230,11 +241,13 @@ public function testAddNamedNativeQueryResultClass() $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); - $cm->addNamedNativeQuery(array( + $cm->addNamedNativeQuery( + [ 'name' => 'find-all', 'resultClass' => '__CLASS__', 'query' => 'SELECT * FROM cms_users', - )); + ] + ); $queryMapping = $cm->getNamedNativeQuery('find-all'); $rsm = new \Doctrine\ORM\Query\ResultSetMappingBuilder($this->_em); diff --git a/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php index 5c5f55f4057..6cce68811c7 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php @@ -18,16 +18,16 @@ public function testNewHydrationSimpleEntityQuery() $rsm->addFieldResult('u', 'u__name', 'name'); // Faked result set - $resultSet = array( - array( + $resultSet = [ + [ 'u__id' => '1', 'u__name' => 'romanb' - ), - array( + ], + [ 'u__id' => '2', 'u__name' => 'jwage' - ) - ); + ] + ]; $stmt = new HydratorMockStatement($resultSet); @@ -53,13 +53,13 @@ public function testHydrateScalarResults() $rsm->addScalarResult('bar2', 'bar', 'string'); $rsm->addScalarResult('baz3', 'baz', 'string'); - $resultSet = array( - array( + $resultSet = [ + [ 'foo1' => 'A', 'bar2' => 'B', 'baz3' => 'C', - ), - ); + ], + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ScalarHydrator($this->_em); @@ -80,16 +80,16 @@ public function testSkipUnknownColumns() $rsm->addScalarResult('bar2', 'bar', 'string'); $rsm->addScalarResult('baz3', 'baz', 'string'); - $resultSet = array( - array( + $resultSet = [ + [ 'u__id' => '1', 'u__name' => 'romanb', 'foo1' => 'A', 'bar2' => 'B', 'baz3' => 'C', 'foo' => 'bar', // Unknown! - ), - ); + ], + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ScalarHydrator($this->_em); diff --git a/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php index d567188342a..d6eaeb10cf3 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php @@ -21,12 +21,12 @@ public function testMissingDiscriminatorColumnException() $rsm->addFieldResult('p', 'p__name', 'name'); $rsm->addMetaResult('p ', 'discr', 'discr', false, 'string'); $rsm->setDiscriminatorColumn('p', 'discr'); - $resultSet = array( - array( + $resultSet = [ + [ 'u__id' => '1', 'u__name' => 'Fabio B. Silva' - ), - ); + ], + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator($this->_em); @@ -39,13 +39,13 @@ public function testExtraFieldInResultSetShouldBeIgnore() $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsAddress', 'a'); $rsm->addFieldResult('a', 'a__id', 'id'); $rsm->addFieldResult('a', 'a__city', 'city'); - $resultSet = array( - array( + $resultSet = [ + [ 'a__id' => '1', 'a__city' => 'Cracow', 'doctrine_rownum' => '1' - ), - ); + ], + ]; $expectedEntity = new \Doctrine\Tests\Models\CMS\CmsAddress(); $expectedEntity->id = 1; @@ -74,13 +74,13 @@ public function testInvalidDiscriminatorValueException() $rsm->addMetaResult('p', 'discr', 'discr', false, 'string'); $rsm->setDiscriminatorColumn('p', 'discr'); - $resultSet = array( - array( + $resultSet = [ + [ 'p__id' => '1', 'p__name' => 'Fabio B. Silva', 'discr' => 'subworker' - ), - ); + ], + ]; $stmt = new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator($this->_em); @@ -98,14 +98,14 @@ public function testNullValueShouldNotOverwriteFieldWithSameNameInJoinedInherita $rsm->addFieldResult('p', 'm__tags', 'tags', 'Doctrine\Tests\Models\Issue5989\Issue5989Manager'); $rsm->addFieldResult('p', 'e__tags', 'tags', 'Doctrine\Tests\Models\Issue5989\Issue5989Employee'); $rsm->addMetaResult('p', 'discr', 'discr', false, 'string'); - $resultSet = array( - array( + $resultSet = [ + [ 'p__id' => '1', 'm__tags' => 'tag1,tag2', 'e__tags' => null, 'discr' => 'manager' - ), - ); + ], + ]; $expectedEntity = new \Doctrine\Tests\Models\Issue5989\Issue5989Manager(); $expectedEntity->id = 1; diff --git a/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php index 219c7384ccc..fa98dd0703c 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php @@ -9,40 +9,48 @@ class SingleScalarHydratorTest extends HydrationTestCase { /** Result set provider for the HYDRATE_SINGLE_SCALAR tests */ public static function singleScalarResultSetProvider() { - return array( + return [ // valid - array('name' => 'result1', - 'resultSet' => array( - array( + [ + 'name' => 'result1', + 'resultSet' => [ + [ 'u__name' => 'romanb' - ) - )), + ] + ] + ], // valid - array('name' => 'result2', - 'resultSet' => array( - array( + [ + 'name' => 'result2', + 'resultSet' => [ + [ 'u__id' => '1' - ) - )), + ] + ] + ], // invalid - array('name' => 'result3', - 'resultSet' => array( - array( + [ + 'name' => 'result3', + 'resultSet' => [ + [ 'u__id' => '1', 'u__name' => 'romanb' - ) - )), + ] + ] + ], // invalid - array('name' => 'result4', - 'resultSet' => array( - array( + [ + 'name' => 'result4', + 'resultSet' => [ + [ 'u__id' => '1' - ), - array( + ], + [ 'u__id' => '2' - ) - )), - ); + ] + ] + ], + ]; } /** diff --git a/tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php b/tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php index 855a9256f61..acc951c1666 100644 --- a/tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php @@ -42,13 +42,13 @@ public function testCorrectIdGeneration() $entity = new AssignedSingleIdEntity; $entity->myId = 1; $id = $this->_assignedGen->generate($this->_em, $entity); - $this->assertEquals(array('myId' => 1), $id); + $this->assertEquals(['myId' => 1], $id); $entity = new AssignedCompositeIdEntity; $entity->myId2 = 2; $entity->myId1 = 4; $id = $this->_assignedGen->generate($this->_em, $entity); - $this->assertEquals(array('myId1' => 4, 'myId2' => 2), $id); + $this->assertEquals(['myId1' => 4, 'myId2' => 2], $id); } } diff --git a/tests/Doctrine/Tests/ORM/Internal/HydrationCompleteHandlerTest.php b/tests/Doctrine/Tests/ORM/Internal/HydrationCompleteHandlerTest.php index 1063b5aca4c..851cc2ae370 100644 --- a/tests/Doctrine/Tests/ORM/Internal/HydrationCompleteHandlerTest.php +++ b/tests/Doctrine/Tests/ORM/Internal/HydrationCompleteHandlerTest.php @@ -158,7 +158,7 @@ public function testDefersMultiplePostLoadOfEntity($listenersFlag) Events::postLoad, $this->logicalOr($entity1, $entity2), $this->callback(function (LifecycleEventArgs $args) use ($entityManager, $entity1, $entity2) { - return in_array($args->getEntity(), array($entity1, $entity2), true) + return in_array($args->getEntity(), [$entity1, $entity2], true) && $entityManager === $args->getObjectManager(); }), $listenersFlag @@ -189,13 +189,13 @@ public function testSkipsDeferredPostLoadOfMetadataWithNoInvokedListeners() public function testGetValidListenerInvocationFlags() { - return array( - array(ListenersInvoker::INVOKE_LISTENERS), - array(ListenersInvoker::INVOKE_CALLBACKS), - array(ListenersInvoker::INVOKE_MANAGER), - array(ListenersInvoker::INVOKE_LISTENERS | ListenersInvoker::INVOKE_CALLBACKS), - array(ListenersInvoker::INVOKE_LISTENERS | ListenersInvoker::INVOKE_MANAGER), - array(ListenersInvoker::INVOKE_LISTENERS | ListenersInvoker::INVOKE_CALLBACKS | ListenersInvoker::INVOKE_MANAGER), - ); + return [ + [ListenersInvoker::INVOKE_LISTENERS], + [ListenersInvoker::INVOKE_CALLBACKS], + [ListenersInvoker::INVOKE_MANAGER], + [ListenersInvoker::INVOKE_LISTENERS | ListenersInvoker::INVOKE_CALLBACKS], + [ListenersInvoker::INVOKE_LISTENERS | ListenersInvoker::INVOKE_MANAGER], + [ListenersInvoker::INVOKE_LISTENERS | ListenersInvoker::INVOKE_CALLBACKS | ListenersInvoker::INVOKE_MANAGER], + ]; } } diff --git a/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php b/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php index 512b21115c9..1f667b4640d 100644 --- a/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php @@ -64,12 +64,12 @@ public function testCountUsesWrappedCollectionWhenInitialized() ->expects($this->once()) ->method('loadCriteria') ->with($this->criteria) - ->will($this->returnValue(array('foo', 'bar', 'baz'))); + ->will($this->returnValue(['foo', 'bar', 'baz'])); // should never call the persister's count $this->persister->expects($this->never())->method('count'); - $this->assertSame(array('foo', 'bar', 'baz'), $this->lazyCriteriaCollection->toArray()); + $this->assertSame(['foo', 'bar', 'baz'], $this->lazyCriteriaCollection->toArray()); $this->assertSame(3, $this->lazyCriteriaCollection->count()); } @@ -89,7 +89,7 @@ public function testMatchingUsesThePersisterOnlyOnce() ->expects($this->once()) ->method('loadCriteria') ->with($this->criteria) - ->will($this->returnValue(array($foo, $bar, $baz))); + ->will($this->returnValue([$foo, $bar, $baz])); $criteria = new Criteria(); @@ -98,9 +98,9 @@ public function testMatchingUsesThePersisterOnlyOnce() $filtered = $this->lazyCriteriaCollection->matching($criteria); $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $filtered); - $this->assertEquals(array($foo), $filtered->toArray()); + $this->assertEquals([$foo], $filtered->toArray()); - $this->assertEquals(array($foo), $this->lazyCriteriaCollection->matching($criteria)->toArray()); + $this->assertEquals([$foo], $this->lazyCriteriaCollection->matching($criteria)->toArray()); } public function testIsEmptyUsesCountWhenNotInitialized() @@ -124,12 +124,12 @@ public function testIsEmptyUsesWrappedCollectionWhenInitialized() ->expects($this->once()) ->method('loadCriteria') ->with($this->criteria) - ->will($this->returnValue(array('foo', 'bar', 'baz'))); + ->will($this->returnValue(['foo', 'bar', 'baz'])); // should never call the persister's count $this->persister->expects($this->never())->method('count'); - $this->assertSame(array('foo', 'bar', 'baz'), $this->lazyCriteriaCollection->toArray()); + $this->assertSame(['foo', 'bar', 'baz'], $this->lazyCriteriaCollection->toArray()); $this->assertFalse($this->lazyCriteriaCollection->isEmpty()); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index c4fd1381dc5..4e9546daa98 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -72,10 +72,11 @@ public function testEntityTableNameAndInheritance($class) public function testEntityIndexes($class) { $this->assertArrayHasKey('indexes', $class->table, 'ClassMetadata should have indexes key in table property.'); - $this->assertEquals(array( - 'name_idx' => array('columns' => array('name')), - 0 => array('columns' => array('user_email')) - ), $class->table['indexes']); + $this->assertEquals( + [ + 'name_idx' => ['columns' => ['name']], + 0 => ['columns' => ['user_email']] + ], $class->table['indexes']); return $class; } @@ -84,13 +85,14 @@ public function testEntityIndexFlagsAndPartialIndexes() { $class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\Comment'); - $this->assertEquals(array( - 0 => array( - 'columns' => array('content'), - 'flags' => array('fulltext'), - 'options' => array('where' => 'content IS NOT NULL'), - ) - ), $class->table['indexes']); + $this->assertEquals( + [ + 0 => [ + 'columns' => ['content'], + 'flags' => ['fulltext'], + 'options' => ['where' => 'content IS NOT NULL'], + ] + ], $class->table['indexes']); } /** @@ -102,9 +104,10 @@ public function testEntityUniqueConstraints($class) $this->assertArrayHasKey('uniqueConstraints', $class->table, 'ClassMetadata should have uniqueConstraints key in table property when Unique Constraints are set.'); - $this->assertEquals(array( - "search_idx" => array("columns" => array("name", "user_email"), 'options' => array('where' => 'name IS NOT NULL')) - ), $class->table['uniqueConstraints']); + $this->assertEquals( + [ + "search_idx" => ["columns" => ["name", "user_email"], 'options' => ['where' => 'name IS NOT NULL']] + ], $class->table['uniqueConstraints']); return $class; } @@ -117,9 +120,10 @@ public function testEntityOptions($class) { $this->assertArrayHasKey('options', $class->table, 'ClassMetadata should have options key in table property.'); - $this->assertEquals(array( - 'foo' => 'bar', 'baz' => array('key' => 'val') - ), $class->table['options']); + $this->assertEquals( + [ + 'foo' => 'bar', 'baz' => ['key' => 'val'] + ], $class->table['options']); return $class; } @@ -132,11 +136,11 @@ public function testEntitySequence($class) { $this->assertInternalType('array', $class->sequenceGeneratorDefinition, 'No Sequence Definition set on this driver.'); $this->assertEquals( - array( + [ 'sequenceName' => 'tablename_seq', 'allocationSize' => 100, 'initialValue' => 1, - ), + ], $class->sequenceGeneratorDefinition ); } @@ -148,7 +152,7 @@ public function testEntityCustomGenerator() $this->assertEquals(ClassMetadata::GENERATOR_TYPE_CUSTOM, $class->generatorType, "Generator Type"); $this->assertEquals( - array("class" => "stdClass"), + ["class" => "stdClass"], $class->customGeneratorDefinition, "Custom Generator Definition"); } @@ -240,7 +244,7 @@ public function testIdFieldOptions($class) */ public function testIdentifier($class) { - $this->assertEquals(array('id'), $class->identifier); + $this->assertEquals(['id'], $class->identifier); $this->assertEquals('integer', $class->fieldMappings['id']['type']); $this->assertEquals(ClassMetadata::GENERATOR_TYPE_AUTO, $class->generatorType, "ID-Generator is not ClassMetadata::GENERATOR_TYPE_AUTO"); @@ -313,7 +317,7 @@ public function testInverseOneToManyAssociation($class) $this->assertTrue($class->associationMappings['phonenumbers']['orphanRemoval']); // Test Order By - $this->assertEquals(array('number' => 'ASC'), $class->associationMappings['phonenumbers']['orderBy']); + $this->assertEquals(['number' => 'ASC'], $class->associationMappings['phonenumbers']['orderBy']); return $class; } @@ -411,7 +415,7 @@ public function testDiscriminatorColumnDefaults() $class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\Animal'); $this->assertEquals( - array('name' => 'discr', 'type' => 'string', 'length' => '32', 'fieldName' => 'discr', 'columnDefinition' => null), + ['name' => 'discr', 'type' => 'string', 'length' => '32', 'fieldName' => 'discr', 'columnDefinition' => null], $class->discriminatorColumn ); } @@ -609,18 +613,18 @@ public function testNamedNativeQuery() $findAllMapping = $class->getSqlResultSetMapping('mapping-find-all'); $this->assertEquals('mapping-find-all', $findAllMapping['name']); $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress', $findAllMapping['entities'][0]['entityClass']); - $this->assertEquals(array('name'=>'id','column'=>'id'), $findAllMapping['entities'][0]['fields'][0]); - $this->assertEquals(array('name'=>'city','column'=>'city'), $findAllMapping['entities'][0]['fields'][1]); - $this->assertEquals(array('name'=>'country','column'=>'country'), $findAllMapping['entities'][0]['fields'][2]); + $this->assertEquals(['name'=>'id','column'=>'id'], $findAllMapping['entities'][0]['fields'][0]); + $this->assertEquals(['name'=>'city','column'=>'city'], $findAllMapping['entities'][0]['fields'][1]); + $this->assertEquals(['name'=>'country','column'=>'country'], $findAllMapping['entities'][0]['fields'][2]); $withoutFieldsMapping = $class->getSqlResultSetMapping('mapping-without-fields'); $this->assertEquals('mapping-without-fields', $withoutFieldsMapping['name']); $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress', $withoutFieldsMapping['entities'][0]['entityClass']); - $this->assertEquals(array(), $withoutFieldsMapping['entities'][0]['fields']); + $this->assertEquals([], $withoutFieldsMapping['entities'][0]['fields']); $countMapping = $class->getSqlResultSetMapping('mapping-count'); $this->assertEquals('mapping-count', $countMapping['name']); - $this->assertEquals(array('name'=>'count'), $countMapping['columns'][0]); + $this->assertEquals(['name'=>'count'], $countMapping['columns'][0]); } @@ -637,61 +641,61 @@ public function testSqlResultSetMapping() $this->assertCount(4, $userMetadata->getSqlResultSetMappings()); $mapping = $userMetadata->getSqlResultSetMapping('mappingJoinedAddress'); - $this->assertEquals(array(),$mapping['columns']); + $this->assertEquals([],$mapping['columns']); $this->assertEquals('mappingJoinedAddress', $mapping['name']); $this->assertNull($mapping['entities'][0]['discriminatorColumn']); - $this->assertEquals(array('name'=>'id','column'=>'id'), $mapping['entities'][0]['fields'][0]); - $this->assertEquals(array('name'=>'name','column'=>'name'), $mapping['entities'][0]['fields'][1]); - $this->assertEquals(array('name'=>'status','column'=>'status'), $mapping['entities'][0]['fields'][2]); - $this->assertEquals(array('name'=>'address.zip','column'=>'zip'), $mapping['entities'][0]['fields'][3]); - $this->assertEquals(array('name'=>'address.city','column'=>'city'), $mapping['entities'][0]['fields'][4]); - $this->assertEquals(array('name'=>'address.country','column'=>'country'), $mapping['entities'][0]['fields'][5]); - $this->assertEquals(array('name'=>'address.id','column'=>'a_id'), $mapping['entities'][0]['fields'][6]); + $this->assertEquals(['name'=>'id','column'=>'id'], $mapping['entities'][0]['fields'][0]); + $this->assertEquals(['name'=>'name','column'=>'name'], $mapping['entities'][0]['fields'][1]); + $this->assertEquals(['name'=>'status','column'=>'status'], $mapping['entities'][0]['fields'][2]); + $this->assertEquals(['name'=>'address.zip','column'=>'zip'], $mapping['entities'][0]['fields'][3]); + $this->assertEquals(['name'=>'address.city','column'=>'city'], $mapping['entities'][0]['fields'][4]); + $this->assertEquals(['name'=>'address.country','column'=>'country'], $mapping['entities'][0]['fields'][5]); + $this->assertEquals(['name'=>'address.id','column'=>'a_id'], $mapping['entities'][0]['fields'][6]); $this->assertEquals($userMetadata->name, $mapping['entities'][0]['entityClass']); $mapping = $userMetadata->getSqlResultSetMapping('mappingJoinedPhonenumber'); - $this->assertEquals(array(),$mapping['columns']); + $this->assertEquals([],$mapping['columns']); $this->assertEquals('mappingJoinedPhonenumber', $mapping['name']); $this->assertNull($mapping['entities'][0]['discriminatorColumn']); - $this->assertEquals(array('name'=>'id','column'=>'id'), $mapping['entities'][0]['fields'][0]); - $this->assertEquals(array('name'=>'name','column'=>'name'), $mapping['entities'][0]['fields'][1]); - $this->assertEquals(array('name'=>'status','column'=>'status'), $mapping['entities'][0]['fields'][2]); - $this->assertEquals(array('name'=>'phonenumbers.phonenumber','column'=>'number'), $mapping['entities'][0]['fields'][3]); + $this->assertEquals(['name'=>'id','column'=>'id'], $mapping['entities'][0]['fields'][0]); + $this->assertEquals(['name'=>'name','column'=>'name'], $mapping['entities'][0]['fields'][1]); + $this->assertEquals(['name'=>'status','column'=>'status'], $mapping['entities'][0]['fields'][2]); + $this->assertEquals(['name'=>'phonenumbers.phonenumber','column'=>'number'], $mapping['entities'][0]['fields'][3]); $this->assertEquals($userMetadata->name, $mapping['entities'][0]['entityClass']); $mapping = $userMetadata->getSqlResultSetMapping('mappingUserPhonenumberCount'); - $this->assertEquals(array('name'=>'numphones'),$mapping['columns'][0]); + $this->assertEquals(['name'=>'numphones'],$mapping['columns'][0]); $this->assertEquals('mappingUserPhonenumberCount', $mapping['name']); $this->assertNull($mapping['entities'][0]['discriminatorColumn']); - $this->assertEquals(array('name'=>'id','column'=>'id'), $mapping['entities'][0]['fields'][0]); - $this->assertEquals(array('name'=>'name','column'=>'name'), $mapping['entities'][0]['fields'][1]); - $this->assertEquals(array('name'=>'status','column'=>'status'), $mapping['entities'][0]['fields'][2]); + $this->assertEquals(['name'=>'id','column'=>'id'], $mapping['entities'][0]['fields'][0]); + $this->assertEquals(['name'=>'name','column'=>'name'], $mapping['entities'][0]['fields'][1]); + $this->assertEquals(['name'=>'status','column'=>'status'], $mapping['entities'][0]['fields'][2]); $this->assertEquals($userMetadata->name, $mapping['entities'][0]['entityClass']); $mapping = $userMetadata->getSqlResultSetMapping('mappingMultipleJoinsEntityResults'); - $this->assertEquals(array('name'=>'numphones'),$mapping['columns'][0]); + $this->assertEquals(['name'=>'numphones'],$mapping['columns'][0]); $this->assertEquals('mappingMultipleJoinsEntityResults', $mapping['name']); $this->assertNull($mapping['entities'][0]['discriminatorColumn']); - $this->assertEquals(array('name'=>'id','column'=>'u_id'), $mapping['entities'][0]['fields'][0]); - $this->assertEquals(array('name'=>'name','column'=>'u_name'), $mapping['entities'][0]['fields'][1]); - $this->assertEquals(array('name'=>'status','column'=>'u_status'), $mapping['entities'][0]['fields'][2]); + $this->assertEquals(['name'=>'id','column'=>'u_id'], $mapping['entities'][0]['fields'][0]); + $this->assertEquals(['name'=>'name','column'=>'u_name'], $mapping['entities'][0]['fields'][1]); + $this->assertEquals(['name'=>'status','column'=>'u_status'], $mapping['entities'][0]['fields'][2]); $this->assertEquals($userMetadata->name, $mapping['entities'][0]['entityClass']); $this->assertNull($mapping['entities'][1]['discriminatorColumn']); - $this->assertEquals(array('name'=>'id','column'=>'a_id'), $mapping['entities'][1]['fields'][0]); - $this->assertEquals(array('name'=>'zip','column'=>'a_zip'), $mapping['entities'][1]['fields'][1]); - $this->assertEquals(array('name'=>'country','column'=>'a_country'), $mapping['entities'][1]['fields'][2]); + $this->assertEquals(['name'=>'id','column'=>'a_id'], $mapping['entities'][1]['fields'][0]); + $this->assertEquals(['name'=>'zip','column'=>'a_zip'], $mapping['entities'][1]['fields'][1]); + $this->assertEquals(['name'=>'country','column'=>'a_country'], $mapping['entities'][1]['fields'][2]); $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress', $mapping['entities'][1]['entityClass']); //person asserts $this->assertCount(1, $personMetadata->getSqlResultSetMappings()); $mapping = $personMetadata->getSqlResultSetMapping('mappingFetchAll'); - $this->assertEquals(array(),$mapping['columns']); + $this->assertEquals([],$mapping['columns']); $this->assertEquals('mappingFetchAll', $mapping['name']); $this->assertEquals('discriminator', $mapping['entities'][0]['discriminatorColumn']); - $this->assertEquals(array('name'=>'id','column'=>'id'), $mapping['entities'][0]['fields'][0]); - $this->assertEquals(array('name'=>'name','column'=>'name'), $mapping['entities'][0]['fields'][1]); + $this->assertEquals(['name'=>'id','column'=>'id'], $mapping['entities'][0]['fields'][0]); + $this->assertEquals(['name'=>'name','column'=>'name'], $mapping['entities'][0]['fields'][1]); $this->assertEquals($personMetadata->name, $mapping['entities'][0]['entityClass']); } @@ -731,18 +735,18 @@ public function testAssociationOverridesMapping() $this->assertEquals('user_id', $guestGroups['joinTable']['joinColumns'][0]['name']); $this->assertEquals('group_id', $guestGroups['joinTable']['inverseJoinColumns'][0]['name']); - $this->assertEquals(array('user_id'=>'id'), $guestGroups['relationToSourceKeyColumns']); - $this->assertEquals(array('group_id'=>'id'), $guestGroups['relationToTargetKeyColumns']); - $this->assertEquals(array('user_id','group_id'), $guestGroups['joinTableColumns']); + $this->assertEquals(['user_id'=>'id'], $guestGroups['relationToSourceKeyColumns']); + $this->assertEquals(['group_id'=>'id'], $guestGroups['relationToTargetKeyColumns']); + $this->assertEquals(['user_id','group_id'], $guestGroups['joinTableColumns']); $this->assertEquals('ddc964_users_admingroups', $adminGroups['joinTable']['name']); $this->assertEquals('adminuser_id', $adminGroups['joinTable']['joinColumns'][0]['name']); $this->assertEquals('admingroup_id', $adminGroups['joinTable']['inverseJoinColumns'][0]['name']); - $this->assertEquals(array('adminuser_id'=>'id'), $adminGroups['relationToSourceKeyColumns']); - $this->assertEquals(array('admingroup_id'=>'id'), $adminGroups['relationToTargetKeyColumns']); - $this->assertEquals(array('adminuser_id','admingroup_id'), $adminGroups['joinTableColumns']); + $this->assertEquals(['adminuser_id'=>'id'], $adminGroups['relationToSourceKeyColumns']); + $this->assertEquals(['admingroup_id'=>'id'], $adminGroups['relationToTargetKeyColumns']); + $this->assertEquals(['adminuser_id','admingroup_id'], $adminGroups['joinTableColumns']); // assert address association mappings @@ -767,15 +771,15 @@ public function testAssociationOverridesMapping() // assert override $this->assertEquals('address_id', $guestAddress['joinColumns'][0]['name']); - $this->assertEquals(array('address_id'=>'id'), $guestAddress['sourceToTargetKeyColumns']); - $this->assertEquals(array('address_id'=>'address_id'), $guestAddress['joinColumnFieldNames']); - $this->assertEquals(array('id'=>'address_id'), $guestAddress['targetToSourceKeyColumns']); + $this->assertEquals(['address_id'=>'id'], $guestAddress['sourceToTargetKeyColumns']); + $this->assertEquals(['address_id'=>'address_id'], $guestAddress['joinColumnFieldNames']); + $this->assertEquals(['id'=>'address_id'], $guestAddress['targetToSourceKeyColumns']); $this->assertEquals('adminaddress_id', $adminAddress['joinColumns'][0]['name']); - $this->assertEquals(array('adminaddress_id'=>'id'), $adminAddress['sourceToTargetKeyColumns']); - $this->assertEquals(array('adminaddress_id'=>'adminaddress_id'), $adminAddress['joinColumnFieldNames']); - $this->assertEquals(array('id'=>'adminaddress_id'), $adminAddress['targetToSourceKeyColumns']); + $this->assertEquals(['adminaddress_id'=>'id'], $adminAddress['sourceToTargetKeyColumns']); + $this->assertEquals(['adminaddress_id'=>'adminaddress_id'], $adminAddress['joinColumnFieldNames']); + $this->assertEquals(['id'=>'adminaddress_id'], $adminAddress['targetToSourceKeyColumns']); } /* @@ -808,8 +812,8 @@ public function testAttributeOverridesMapping() $this->assertTrue($adminMetadata->fieldMappings['id']['id']); $this->assertEquals('id', $adminMetadata->fieldMappings['id']['fieldName']); $this->assertEquals('user_id', $adminMetadata->fieldMappings['id']['columnName']); - $this->assertEquals(array('user_id'=>'id','user_name'=>'name'), $adminMetadata->fieldNames); - $this->assertEquals(array('id'=>'user_id','name'=>'user_name'), $adminMetadata->columnNames); + $this->assertEquals(['user_id'=>'id','user_name'=>'name'], $adminMetadata->fieldNames); + $this->assertEquals(['id'=>'user_id','name'=>'user_name'], $adminMetadata->columnNames); $this->assertEquals(150, $adminMetadata->fieldMappings['id']['length']); @@ -823,8 +827,8 @@ public function testAttributeOverridesMapping() $this->assertTrue($guestMetadata->fieldMappings['id']['id']); $this->assertEquals('guest_id', $guestMetadata->fieldMappings['id']['columnName']); $this->assertEquals('id', $guestMetadata->fieldMappings['id']['fieldName']); - $this->assertEquals(array('guest_id'=>'id','guest_name'=>'name'), $guestMetadata->fieldNames); - $this->assertEquals(array('id'=>'guest_id','name'=>'guest_name'), $guestMetadata->columnNames); + $this->assertEquals(['guest_id'=>'id','guest_name'=>'name'], $guestMetadata->fieldNames); + $this->assertEquals(['id'=>'guest_id','name'=>'guest_name'], $guestMetadata->columnNames); $this->assertEquals(140, $guestMetadata->fieldMappings['id']['length']); $this->assertEquals('name', $guestMetadata->fieldMappings['name']['fieldName']); @@ -1139,126 +1143,144 @@ public function doStuffOnPostPersist() public static function loadMetadata(ClassMetadataInfo $metadata) { $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE); - $metadata->setPrimaryTable(array( + $metadata->setPrimaryTable( + [ 'name' => 'cms_users', - 'options' => array('foo' => 'bar', 'baz' => array('key' => 'val')), - )); + 'options' => ['foo' => 'bar', 'baz' => ['key' => 'val']], + ] + ); $metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT); $metadata->addLifecycleCallback('doStuffOnPrePersist', 'prePersist'); $metadata->addLifecycleCallback('doOtherStuffOnPrePersistToo', 'prePersist'); $metadata->addLifecycleCallback('doStuffOnPostPersist', 'postPersist'); - $metadata->mapField(array( + $metadata->mapField( + [ 'id' => true, 'fieldName' => 'id', 'type' => 'integer', 'columnName' => 'id', - 'options' => array('foo' => 'bar', 'unsigned' => false), - )); - $metadata->mapField(array( + 'options' => ['foo' => 'bar', 'unsigned' => false], + ] + ); + $metadata->mapField( + [ 'fieldName' => 'name', 'type' => 'string', 'length' => 50, 'unique' => true, 'nullable' => true, 'columnName' => 'name', - 'options' => array('foo' => 'bar', 'baz' => array('key' => 'val'), 'fixed' => false), - )); - $metadata->mapField(array( + 'options' => ['foo' => 'bar', 'baz' => ['key' => 'val'], 'fixed' => false], + ] + ); + $metadata->mapField( + [ 'fieldName' => 'email', 'type' => 'string', 'columnName' => 'user_email', 'columnDefinition' => 'CHAR(32) NOT NULL', - )); - $mapping = array('fieldName' => 'version', 'type' => 'integer'); + ] + ); + $mapping = ['fieldName' => 'version', 'type' => 'integer']; $metadata->setVersionMapping($mapping); $metadata->mapField($mapping); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); - $metadata->mapOneToOne(array( + $metadata->mapOneToOne( + [ 'fieldName' => 'address', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Address', 'cascade' => - array( + [ 0 => 'remove', - ), + ], 'mappedBy' => NULL, 'inversedBy' => 'user', 'joinColumns' => - array( + [ 0 => - array( + [ 'name' => 'address_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE', - ), - ), + ], + ], 'orphanRemoval' => false, - )); - $metadata->mapOneToMany(array( + ] + ); + $metadata->mapOneToMany( + [ 'fieldName' => 'phonenumbers', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Phonenumber', 'cascade' => - array( + [ 1 => 'persist', - ), + ], 'mappedBy' => 'user', 'orphanRemoval' => true, 'orderBy' => - array( + [ 'number' => 'ASC', - ), - )); - $metadata->mapManyToMany(array( + ], + ] + ); + $metadata->mapManyToMany( + [ 'fieldName' => 'groups', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Group', 'cascade' => - array( + [ 0 => 'remove', 1 => 'persist', 2 => 'refresh', 3 => 'merge', 4 => 'detach', - ), + ], 'mappedBy' => NULL, 'joinTable' => - array( + [ 'name' => 'cms_users_groups', 'joinColumns' => - array( + [ 0 => - array( + [ 'name' => 'user_id', 'referencedColumnName' => 'id', 'unique' => false, 'nullable' => false, - ), - ), + ], + ], 'inverseJoinColumns' => - array( + [ 0 => - array( + [ 'name' => 'group_id', 'referencedColumnName' => 'id', 'columnDefinition' => 'INT NULL', - ), - ), - ), + ], + ], + ], 'orderBy' => NULL, - )); - $metadata->table['uniqueConstraints'] = array( - 'search_idx' => array('columns' => array('name', 'user_email'), 'options'=> array('where' => 'name IS NOT NULL')), + ] ); - $metadata->table['indexes'] = array( - 'name_idx' => array('columns' => array('name')), 0 => array('columns' => array('user_email')) - ); - $metadata->setSequenceGeneratorDefinition(array( + $metadata->table['uniqueConstraints'] = [ + 'search_idx' => ['columns' => ['name', 'user_email'], 'options'=> ['where' => 'name IS NOT NULL']], + ]; + $metadata->table['indexes'] = [ + 'name_idx' => ['columns' => ['name']], 0 => ['columns' => ['user_email']] + ]; + $metadata->setSequenceGeneratorDefinition( + [ 'sequenceName' => 'tablename_seq', 'allocationSize' => 100, 'initialValue' => 1, - )); - $metadata->addNamedQuery(array( + ] + ); + $metadata->addNamedQuery( + [ 'name' => 'all', 'query' => 'SELECT u FROM __CLASS__ u' - )); + ] + ); } } @@ -1279,7 +1301,7 @@ abstract class Animal public static function loadMetadata(ClassMetadataInfo $metadata) { $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_CUSTOM); - $metadata->setCustomGeneratorDefinition(array("class" => "stdClass")); + $metadata->setCustomGeneratorDefinition(["class" => "stdClass"]); } } @@ -1346,16 +1368,20 @@ public function getValue() public static function loadMetadata(ClassMetadataInfo $metadata) { - $metadata->mapField(array( + $metadata->mapField( + [ 'id' => true, 'fieldName' => 'id', 'columnDefinition' => 'INT unsigned NOT NULL', - )); + ] + ); - $metadata->mapField(array( + $metadata->mapField( + [ 'fieldName' => 'value', 'columnDefinition' => 'VARCHAR(255) NOT NULL' - )); + ] + ); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE); } @@ -1379,16 +1405,20 @@ class DDC807Entity public static function loadMetadata(ClassMetadataInfo $metadata) { - $metadata->mapField(array( + $metadata->mapField( + [ 'id' => true, 'fieldName' => 'id', - )); + ] + ); - $metadata->setDiscriminatorColumn(array( + $metadata->setDiscriminatorColumn( + [ 'name' => "dtype", 'type' => "string", 'columnDefinition' => "ENUM('ONE','TWO')" - )); + ] + ); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE); } @@ -1415,13 +1445,16 @@ class Comment public static function loadMetadata(ClassMetadataInfo $metadata) { $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE); - $metadata->setPrimaryTable(array( - 'indexes' => array( - array('columns' => array('content'), 'flags' => array('fulltext'), 'options' => array('where' => 'content IS NOT NULL')) - ) - )); + $metadata->setPrimaryTable( + [ + 'indexes' => [ + ['columns' => ['content'], 'flags' => ['fulltext'], 'options' => ['where' => 'content IS NOT NULL']] + ] + ] + ); - $metadata->mapField(array( + $metadata->mapField( + [ 'fieldName' => 'content', 'type' => 'text', 'scale' => 0, @@ -1430,7 +1463,8 @@ public static function loadMetadata(ClassMetadataInfo $metadata) 'nullable' => false, 'precision' => 0, 'columnName' => 'content', - )); + ] + ); } } @@ -1453,10 +1487,12 @@ class SingleTableEntityNoDiscriminatorColumnMapping public static function loadMetadata(ClassMetadataInfo $metadata) { - $metadata->mapField(array( + $metadata->mapField( + [ 'id' => true, 'fieldName' => 'id', - )); + ] + ); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE); } @@ -1485,10 +1521,12 @@ class SingleTableEntityIncompleteDiscriminatorColumnMapping public static function loadMetadata(ClassMetadataInfo $metadata) { - $metadata->mapField(array( + $metadata->mapField( + [ 'id' => true, 'fieldName' => 'id', - )); + ] + ); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php index ac17b63a221..e87412d3ec3 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php @@ -111,7 +111,7 @@ public function testGetClassNamesReturnsOnlyTheAppropriateClasses() protected function _loadDriverForCMSModels() { $annotationDriver = $this->_loadDriver(); - $annotationDriver->addPaths(array(__DIR__ . '/../../Models/CMS/')); + $annotationDriver->addPaths([__DIR__ . '/../../Models/CMS/']); return $annotationDriver; } @@ -133,7 +133,7 @@ protected function _ensureIsLoaded($entityClassName) public function testJoinTablesWithMappedSuperclassForAnnotationDriver() { $annotationDriver = $this->_loadDriver(); - $annotationDriver->addPaths(array(__DIR__ . '/../../Models/DirectoryTree/')); + $annotationDriver->addPaths([__DIR__ . '/../../Models/DirectoryTree/']); $em = $this->_getTestEntityManager(); $em->getConfiguration()->setMetadataDriverImpl($annotationDriver); @@ -202,10 +202,10 @@ public function testInheritanceSkipsParentLifecycleCallbacks() $factory->setEntityManager($em); $cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\AnnotationChild'); - $this->assertEquals(array("postLoad" => array("postLoad"), "preUpdate" => array("preUpdate")), $cm->lifecycleCallbacks); + $this->assertEquals(["postLoad" => ["postLoad"], "preUpdate" => ["preUpdate"]], $cm->lifecycleCallbacks); $cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\AnnotationParent'); - $this->assertEquals(array("postLoad" => array("postLoad"), "preUpdate" => array("preUpdate")), $cm->lifecycleCallbacks); + $this->assertEquals(["postLoad" => ["postLoad"], "preUpdate" => ["preUpdate"]], $cm->lifecycleCallbacks); } /** diff --git a/tests/Doctrine/Tests/ORM/Mapping/AnsiQuoteStrategyTest.php b/tests/Doctrine/Tests/ORM/Mapping/AnsiQuoteStrategyTest.php index d5f2a973837..497e2a00581 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AnsiQuoteStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AnsiQuoteStrategyTest.php @@ -48,8 +48,8 @@ private function createClassMetadata($className) public function testGetColumnName() { $class = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); - $class->mapField(array('fieldName' => 'name', 'columnName' => 'name')); - $class->mapField(array('fieldName' => 'id', 'columnName' => 'id', 'id' => true)); + $class->mapField(['fieldName' => 'name', 'columnName' => 'name']); + $class->mapField(['fieldName' => 'id', 'columnName' => 'id', 'id' => true]); $this->assertEquals('id' ,$this->strategy->getColumnName('id', $class, $this->platform)); $this->assertEquals('name' ,$this->strategy->getColumnName('name', $class, $this->platform)); @@ -59,38 +59,42 @@ public function testGetTableName() { $class = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); - $class->setPrimaryTable(array('name'=>'cms_user')); + $class->setPrimaryTable(['name'=>'cms_user']); $this->assertEquals('cms_user' ,$this->strategy->getTableName($class, $this->platform)); } public function testJoinTableName() { $class = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); - - $class->mapManyToMany(array( + + $class->mapManyToMany( + [ 'fieldName' => 'user', 'targetEntity' => 'CmsUser', 'inversedBy' => 'users', - 'joinTable' => array( + 'joinTable' => [ 'name' => 'cmsaddress_cmsuser' - ) - )); - + ] + ] + ); + $this->assertEquals('cmsaddress_cmsuser', $this->strategy->getJoinTableName($class->associationMappings['user'], $class, $this->platform)); - + } public function testIdentifierColumnNames() { $class = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); - $class->mapField(array( + $class->mapField( + [ 'id' => true, 'fieldName' => 'id', 'columnName' => 'id', - )); + ] + ); - $this->assertEquals(array('id'), $this->strategy->getIdentifierColumnNames($class, $this->platform)); + $this->assertEquals(['id'], $this->strategy->getIdentifierColumnNames($class, $this->platform)); } @@ -103,14 +107,18 @@ public function testJoinColumnName() { $class = $this->createClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); - $class->mapOneToOne(array( + $class->mapOneToOne( + [ 'id' => true, 'fieldName' => 'article', 'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', - 'joinColumns' => array(array( + 'joinColumns' => [ + [ 'name' => 'article' - )), - )); + ] + ], + ] + ); $joinColumn = $class->associationMappings['article']['joinColumns'][0]; $this->assertEquals('article',$this->strategy->getJoinColumnName($joinColumn, $class, $this->platform)); @@ -120,14 +128,18 @@ public function testReferencedJoinColumnName() { $cm = $this->createClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); - $cm->mapOneToOne(array( + $cm->mapOneToOne( + [ 'id' => true, 'fieldName' => 'article', 'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', - 'joinColumns' => array(array( + 'joinColumns' => [ + [ 'name' => 'article' - )), - )); + ] + ], + ] + ); $joinColumn = $cm->associationMappings['article']['joinColumns'][0]; $this->assertEquals('id',$this->strategy->getReferencedJoinColumnName($joinColumn, $cm, $this->platform)); @@ -136,14 +148,14 @@ public function testReferencedJoinColumnName() public function testGetSequenceName() { $class = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); - $definition = array( + $definition = [ 'sequenceName' => 'user_id_seq', 'allocationSize' => 1, 'initialValue' => 2 - ); + ]; $class->setSequenceGeneratorDefinition($definition); $this->assertEquals('user_id_seq',$this->strategy->getSequenceName($definition, $class, $this->platform)); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php index be2bee9f58e..7cd1247ddde 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php @@ -156,7 +156,7 @@ public function testGeneratedValueFromMappedSuperclass() $this->assertInstanceOf('Doctrine\ORM\Id\SequenceGenerator', $class->idGenerator); $this->assertEquals( - array('allocationSize' => 1, 'initialValue' => 10, 'sequenceName' => 'foo'), + ['allocationSize' => 1, 'initialValue' => 10, 'sequenceName' => 'foo'], $class->sequenceGeneratorDefinition ); } @@ -172,7 +172,7 @@ public function testSequenceDefinitionInHierarchyWithSandwichMappedSuperclass() $this->assertInstanceOf('Doctrine\ORM\Id\SequenceGenerator', $class->idGenerator); $this->assertEquals( - array('allocationSize' => 1, 'initialValue' => 10, 'sequenceName' => 'foo'), + ['allocationSize' => 1, 'initialValue' => 10, 'sequenceName' => 'foo'], $class->sequenceGeneratorDefinition ); } @@ -188,7 +188,7 @@ public function testMultipleMappedSuperclasses() $this->assertInstanceOf('Doctrine\ORM\Id\SequenceGenerator', $class->idGenerator); $this->assertEquals( - array('allocationSize' => 1, 'initialValue' => 10, 'sequenceName' => 'foo'), + ['allocationSize' => 1, 'initialValue' => 10, 'sequenceName' => 'foo'], $class->sequenceGeneratorDefinition ); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php index da4f4abf58d..e19687c8492 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php @@ -51,14 +51,15 @@ public function testAddEmbeddedWithOnlyRequiredParams() ) ); - $this->assertEquals(array( - 'name' => array( + $this->assertEquals( + [ + 'name' => [ 'class' => 'Doctrine\Tests\Models\ValueObjects\Name', 'columnPrefix' => null, 'declaredField' => null, 'originalField' => null, - ) - ), $this->cm->embeddedClasses); + ] + ], $this->cm->embeddedClasses); } public function testAddEmbeddedWithPrefix() @@ -71,14 +72,15 @@ public function testAddEmbeddedWithPrefix() ) ); - $this->assertEquals(array( - 'name' => array( + $this->assertEquals( + [ + 'name' => [ 'class' => 'Doctrine\Tests\Models\ValueObjects\Name', 'columnPrefix' => 'nm_', 'declaredField' => null, 'originalField' => null, - ) - ), $this->cm->embeddedClasses); + ] + ], $this->cm->embeddedClasses); } public function testCreateEmbeddedWithoutExtraParams() @@ -90,12 +92,12 @@ public function testCreateEmbeddedWithoutExtraParams() $this->assertIsFluent($embeddedBuilder->build()); $this->assertEquals( - array( + [ 'class' => 'Doctrine\Tests\Models\ValueObjects\Name', 'columnPrefix' => null, 'declaredField' => null, 'originalField' => null - ), + ], $this->cm->embeddedClasses['name'] ); } @@ -109,12 +111,12 @@ public function testCreateEmbeddedWithColumnPrefix() $this->assertIsFluent($embeddedBuilder->build()); $this->assertEquals( - array( + [ 'class' => 'Doctrine\Tests\Models\ValueObjects\Name', 'columnPrefix' => 'nm_', 'declaredField' => null, 'originalField' => null - ), + ], $this->cm->embeddedClasses['name'] ); } @@ -139,28 +141,28 @@ public function testSetTable() public function testAddIndex() { - $this->assertIsFluent($this->builder->addIndex(array('username', 'name'), 'users_idx')); - $this->assertEquals(array('users_idx' => array('columns' => array('username', 'name'))), $this->cm->table['indexes']); + $this->assertIsFluent($this->builder->addIndex(['username', 'name'], 'users_idx')); + $this->assertEquals(['users_idx' => ['columns' => ['username', 'name']]], $this->cm->table['indexes']); } public function testAddUniqueConstraint() { - $this->assertIsFluent($this->builder->addUniqueConstraint(array('username', 'name'), 'users_idx')); - $this->assertEquals(array('users_idx' => array('columns' => array('username', 'name'))), $this->cm->table['uniqueConstraints']); + $this->assertIsFluent($this->builder->addUniqueConstraint(['username', 'name'], 'users_idx')); + $this->assertEquals(['users_idx' => ['columns' => ['username', 'name']]], $this->cm->table['uniqueConstraints']); } public function testSetPrimaryTableRelated() { - $this->builder->addUniqueConstraint(array('username', 'name'), 'users_idx'); - $this->builder->addIndex(array('username', 'name'), 'users_idx'); + $this->builder->addUniqueConstraint(['username', 'name'], 'users_idx'); + $this->builder->addIndex(['username', 'name'], 'users_idx'); $this->builder->setTable('users'); $this->assertEquals( - array( + [ 'name' => 'users', - 'indexes' => array('users_idx' => array('columns' => array('username', 'name'))), - 'uniqueConstraints' => array('users_idx' => array('columns' => array('username', 'name'))), - ), + 'indexes' => ['users_idx' => ['columns' => ['username', 'name']]], + 'uniqueConstraints' => ['users_idx' => ['columns' => ['username', 'name']]], + ], $this->cm->table ); } @@ -180,7 +182,7 @@ public function testSetInheritanceSingleTable() public function testSetDiscriminatorColumn() { $this->assertIsFluent($this->builder->setDiscriminatorColumn('discr', 'string', '124')); - $this->assertEquals(array('fieldName' => 'discr', 'name' => 'discr', 'type' => 'string', 'length' => '124'), $this->cm->discriminatorColumn); + $this->assertEquals(['fieldName' => 'discr', 'name' => 'discr', 'type' => 'string', 'length' => '124'], $this->cm->discriminatorColumn); } public function testAddDiscriminatorMapClass() @@ -188,7 +190,8 @@ public function testAddDiscriminatorMapClass() $this->assertIsFluent($this->builder->addDiscriminatorMapClass('test', 'Doctrine\Tests\Models\CMS\CmsUser')); $this->assertIsFluent($this->builder->addDiscriminatorMapClass('test2', 'Doctrine\Tests\Models\CMS\CmsGroup')); - $this->assertEquals(array('test' => 'Doctrine\Tests\Models\CMS\CmsUser', 'test2' => 'Doctrine\Tests\Models\CMS\CmsGroup'), $this->cm->discriminatorMap); + $this->assertEquals( + ['test' => 'Doctrine\Tests\Models\CMS\CmsUser', 'test2' => 'Doctrine\Tests\Models\CMS\CmsGroup'], $this->cm->discriminatorMap); $this->assertEquals('test', $this->cm->discriminatorValue); } @@ -207,7 +210,7 @@ public function testChangeTrackingPolicyNotify() public function testAddField() { $this->assertIsFluent($this->builder->addField('name', 'string')); - $this->assertEquals(array('columnName' => 'name', 'fieldName' => 'name', 'type' => 'string'), $this->cm->fieldMappings['name']); + $this->assertEquals(['columnName' => 'name', 'fieldName' => 'name', 'type' => 'string'], $this->cm->fieldMappings['name']); } public function testCreateField() @@ -217,13 +220,14 @@ public function testCreateField() $this->assertFalse(isset($this->cm->fieldMappings['name'])); $this->assertIsFluent($fieldBuilder->build()); - $this->assertEquals(array('columnName' => 'name', 'fieldName' => 'name', 'type' => 'string'), $this->cm->fieldMappings['name']); + $this->assertEquals(['columnName' => 'name', 'fieldName' => 'name', 'type' => 'string'], $this->cm->fieldMappings['name']); } public function testCreateVersionedField() { $this->builder->createField('name', 'integer')->columnName('username')->length(124)->nullable()->columnDefinition('foobar')->unique()->isVersionField()->build(); - $this->assertEquals(array( + $this->assertEquals( + [ 'columnDefinition' => 'foobar', 'columnName' => 'username', 'default' => 1, @@ -232,29 +236,30 @@ public function testCreateVersionedField() 'type' => 'integer', 'nullable' => true, 'unique' => true, - ), $this->cm->fieldMappings['name']); + ], $this->cm->fieldMappings['name']); } public function testCreatePrimaryField() { $this->builder->createField('id', 'integer')->makePrimaryKey()->generatedValue()->build(); - $this->assertEquals(array('id'), $this->cm->identifier); - $this->assertEquals(array('columnName' => 'id', 'fieldName' => 'id', 'id' => true, 'type' => 'integer'), $this->cm->fieldMappings['id']); + $this->assertEquals(['id'], $this->cm->identifier); + $this->assertEquals(['columnName' => 'id', 'fieldName' => 'id', 'id' => true, 'type' => 'integer'], $this->cm->fieldMappings['id']); } public function testCreateUnsignedOptionField() { $this->builder->createField('state', 'integer')->option('unsigned', true)->build(); - $this->assertEquals(array('fieldName' => 'state', 'type' => 'integer', 'options' => array('unsigned' => true), 'columnName' => 'state'), $this->cm->fieldMappings['state']); + $this->assertEquals( + ['fieldName' => 'state', 'type' => 'integer', 'options' => ['unsigned' => true], 'columnName' => 'state'], $this->cm->fieldMappings['state']); } public function testAddLifecycleEvent() { $this->builder->addLifecycleEvent('getStatus', 'postLoad'); - $this->assertEquals(array('postLoad' => array('getStatus')), $this->cm->lifecycleCallbacks); + $this->assertEquals(['postLoad' => ['getStatus']], $this->cm->lifecycleCallbacks); } public function testCreateManyToOne() @@ -267,28 +272,30 @@ public function testCreateManyToOne() ->build() ); - $this->assertEquals(array('groups' => array ( + $this->assertEquals( + [ + 'groups' => [ 'fieldName' => 'groups', 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsGroup', - 'cascade' => array ( + 'cascade' => [ 0 => 'remove', 1 => 'persist', 2 => 'refresh', 3 => 'merge', 4 => 'detach', - ), + ], 'fetch' => 4, - 'joinColumns' => array ( + 'joinColumns' => [ 0 => - array ( + [ 'name' => 'group_id', 'referencedColumnName' => 'id', 'nullable' => true, 'unique' => false, 'onDelete' => 'CASCADE', 'columnDefinition' => NULL, - ), - ), + ], + ], 'type' => 2, 'mappedBy' => NULL, 'inversedBy' => NULL, @@ -300,20 +307,20 @@ public function testCreateManyToOne() 'isCascadeMerge' => true, 'isCascadeDetach' => true, 'sourceToTargetKeyColumns' => - array ( + [ 'group_id' => 'id', - ), + ], 'joinColumnFieldNames' => - array ( + [ 'group_id' => 'group_id', - ), + ], 'targetToSourceKeyColumns' => - array ( + [ 'id' => 'group_id', - ), + ], 'orphanRemoval' => false, - ), - ), $this->cm->associationMappings); + ], + ], $this->cm->associationMappings); } public function testCreateManyToOneWithIdentity() @@ -330,29 +337,29 @@ public function testCreateManyToOneWithIdentity() ); $this->assertEquals( - array( - 'groups' => array( + [ + 'groups' => [ 'fieldName' => 'groups', 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsGroup', - 'cascade' => array( + 'cascade' => [ 0 => 'remove', 1 => 'persist', 2 => 'refresh', 3 => 'merge', 4 => 'detach', - ), + ], 'fetch' => 4, - 'joinColumns' => array( + 'joinColumns' => [ 0 => - array( + [ 'name' => 'group_id', 'referencedColumnName' => 'id', 'nullable' => true, 'unique' => false, 'onDelete' => 'CASCADE', 'columnDefinition' => NULL, - ), - ), + ], + ], 'type' => 2, 'mappedBy' => NULL, 'inversedBy' => NULL, @@ -364,21 +371,21 @@ public function testCreateManyToOneWithIdentity() 'isCascadeMerge' => true, 'isCascadeDetach' => true, 'sourceToTargetKeyColumns' => - array( + [ 'group_id' => 'id', - ), + ], 'joinColumnFieldNames' => - array( + [ 'group_id' => 'group_id', - ), + ], 'targetToSourceKeyColumns' => - array( + [ 'id' => 'group_id', - ), + ], 'orphanRemoval' => false, 'id' => true - ), - ), + ], + ], $this->cm->associationMappings ); } @@ -393,28 +400,30 @@ public function testCreateOneToOne() ->build() ); - $this->assertEquals(array('groups' => array ( + $this->assertEquals( + [ + 'groups' => [ 'fieldName' => 'groups', 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsGroup', - 'cascade' => array ( + 'cascade' => [ 0 => 'remove', 1 => 'persist', 2 => 'refresh', 3 => 'merge', 4 => 'detach', - ), + ], 'fetch' => 4, - 'joinColumns' => array ( + 'joinColumns' => [ 0 => - array ( + [ 'name' => 'group_id', 'referencedColumnName' => 'id', 'nullable' => true, 'unique' => true, 'onDelete' => 'CASCADE', 'columnDefinition' => NULL, - ), - ), + ], + ], 'type' => 1, 'mappedBy' => NULL, 'inversedBy' => NULL, @@ -426,20 +435,20 @@ public function testCreateOneToOne() 'isCascadeMerge' => true, 'isCascadeDetach' => true, 'sourceToTargetKeyColumns' => - array ( + [ 'group_id' => 'id', - ), + ], 'joinColumnFieldNames' => - array ( + [ 'group_id' => 'group_id', - ), + ], 'targetToSourceKeyColumns' => - array ( + [ 'id' => 'group_id', - ), + ], 'orphanRemoval' => false - ), - ), $this->cm->associationMappings); + ], + ], $this->cm->associationMappings); } public function testCreateOneToOneWithIdentity() @@ -456,30 +465,30 @@ public function testCreateOneToOneWithIdentity() ); $this->assertEquals( - array( - 'groups' => array( + [ + 'groups' => [ 'fieldName' => 'groups', 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsGroup', - 'cascade' => array( + 'cascade' => [ 0 => 'remove', 1 => 'persist', 2 => 'refresh', 3 => 'merge', 4 => 'detach', - ), + ], 'fetch' => 4, 'id' => true, - 'joinColumns' => array( + 'joinColumns' => [ 0 => - array( + [ 'name' => 'group_id', 'referencedColumnName' => 'id', 'nullable' => true, 'unique' => false, 'onDelete' => 'CASCADE', 'columnDefinition' => NULL, - ), - ), + ], + ], 'type' => 1, 'mappedBy' => NULL, 'inversedBy' => NULL, @@ -491,20 +500,20 @@ public function testCreateOneToOneWithIdentity() 'isCascadeMerge' => true, 'isCascadeDetach' => true, 'sourceToTargetKeyColumns' => - array( + [ 'group_id' => 'id', - ), + ], 'joinColumnFieldNames' => - array( + [ 'group_id' => 'group_id', - ), + ], 'targetToSourceKeyColumns' => - array( + [ 'id' => 'group_id', - ), + ], 'orphanRemoval' => false - ), - ), + ], + ], $this->cm->associationMappings ); } @@ -534,48 +543,49 @@ public function testCreateManyToMany() ->build() ); - $this->assertEquals(array( + $this->assertEquals( + [ 'groups' => - array( + [ 'fieldName' => 'groups', 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsGroup', 'cascade' => - array( + [ 0 => 'remove', 1 => 'persist', 2 => 'refresh', 3 => 'merge', 4 => 'detach', - ), + ], 'fetch' => 4, 'joinTable' => - array( + [ 'joinColumns' => - array( + [ 0 => - array( + [ 'name' => 'group_id', 'referencedColumnName' => 'id', 'nullable' => true, 'unique' => false, 'onDelete' => 'CASCADE', 'columnDefinition' => NULL, - ), - ), + ], + ], 'inverseJoinColumns' => - array( + [ 0 => - array( + [ 'name' => 'user_id', 'referencedColumnName' => 'id', 'nullable' => true, 'unique' => false, 'onDelete' => NULL, 'columnDefinition' => NULL, - ), - ), + ], + ], 'name' => 'groups_users', - ), + ], 'type' => 8, 'mappedBy' => NULL, 'inversedBy' => NULL, @@ -588,21 +598,21 @@ public function testCreateManyToMany() 'isCascadeDetach' => true, 'isOnDeleteCascade' => true, 'relationToSourceKeyColumns' => - array( + [ 'group_id' => 'id', - ), + ], 'joinTableColumns' => - array( + [ 0 => 'group_id', 1 => 'user_id', - ), + ], 'relationToTargetKeyColumns' => - array( + [ 'user_id' => 'id', - ), + ], 'orphanRemoval' => false, - ), - ), $this->cm->associationMappings); + ], + ], $this->cm->associationMappings); } public function testThrowsExceptionOnCreateManyToManyWithIdentity() @@ -624,21 +634,22 @@ public function testCreateOneToMany() $this->assertIsFluent( $this->builder->createOneToMany('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') ->mappedBy('test') - ->setOrderBy(array('test')) + ->setOrderBy(['test']) ->setIndexBy('test') ->build() ); - $this->assertEquals(array( + $this->assertEquals( + [ 'groups' => - array( + [ 'fieldName' => 'groups', 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsGroup', 'mappedBy' => 'test', 'orderBy' => - array( + [ 0 => 'test', - ), + ], 'indexBy' => 'test', 'type' => 4, 'inversedBy' => NULL, @@ -646,16 +657,16 @@ public function testCreateOneToMany() 'sourceEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', 'fetch' => 2, 'cascade' => - array( - ), + [ + ], 'isCascadeRemove' => false, 'isCascadePersist' => false, 'isCascadeRefresh' => false, 'isCascadeMerge' => false, 'isCascadeDetach' => false, 'orphanRemoval' => false, - ), - ), $this->cm->associationMappings); + ], + ], $this->cm->associationMappings); } public function testThrowsExceptionOnCreateOneToManyWithIdentity() @@ -665,7 +676,7 @@ public function testThrowsExceptionOnCreateOneToManyWithIdentity() $this->builder->createOneToMany('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') ->makePrimaryKey() ->mappedBy('test') - ->setOrderBy(array('test')) + ->setOrderBy(['test']) ->setIndexBy('test') ->build(); } @@ -680,23 +691,24 @@ public function testOrphanRemovalOnCreateOneToOne() ->build() ); - $this->assertEquals(array( - 'groups' => array( + $this->assertEquals( + [ + 'groups' => [ 'fieldName' => 'groups', 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsGroup', - 'cascade' => array (), + 'cascade' => [], 'fetch' => 2, - 'joinColumns' => array ( + 'joinColumns' => [ 0 => - array ( + [ 'name' => 'group_id', 'referencedColumnName' => 'id', 'nullable' => true, 'unique' => true, 'onDelete' => 'CASCADE', 'columnDefinition' => NULL, - ), - ), + ], + ], 'type' => 1, 'mappedBy' => NULL, 'inversedBy' => NULL, @@ -708,20 +720,20 @@ public function testOrphanRemovalOnCreateOneToOne() 'isCascadeMerge' => false, 'isCascadeDetach' => false, 'sourceToTargetKeyColumns' => - array ( + [ 'group_id' => 'id', - ), + ], 'joinColumnFieldNames' => - array ( + [ 'group_id' => 'group_id', - ), + ], 'targetToSourceKeyColumns' => - array ( + [ 'id' => 'group_id', - ), + ], 'orphanRemoval' => true - ), - ), $this->cm->associationMappings); + ], + ], $this->cm->associationMappings); } public function testOrphanRemovalOnCreateOneToMany() @@ -734,9 +746,10 @@ public function testOrphanRemovalOnCreateOneToMany() ->build() ); - $this->assertEquals(array( + $this->assertEquals( + [ 'groups' => - array( + [ 'fieldName' => 'groups', 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsGroup', 'mappedBy' => 'test', @@ -745,15 +758,15 @@ public function testOrphanRemovalOnCreateOneToMany() 'isOwningSide' => false, 'sourceEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', 'fetch' => 2, - 'cascade' => array(), + 'cascade' => [], 'isCascadeRemove' => true, 'isCascadePersist' => false, 'isCascadeRefresh' => false, 'isCascadeMerge' => false, 'isCascadeDetach' => false, 'orphanRemoval' => true, - ), - ), $this->cm->associationMappings); + ], + ], $this->cm->associationMappings); } public function testExceptionOnOrphanRemovalOnManyToOne() @@ -775,32 +788,33 @@ public function testOrphanRemovalOnManyToMany() ->orphanRemoval() ->build(); - $this->assertEquals(array( - 'groups' => array( + $this->assertEquals( + [ + 'groups' => [ 'fieldName' => 'groups', 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsGroup', - 'cascade' => array(), + 'cascade' => [], 'fetch' => 2, - 'joinTable' => array( - 'joinColumns' => array( - 0 => array( + 'joinTable' => [ + 'joinColumns' => [ + 0 => [ 'name' => 'group_id', 'referencedColumnName' => 'id', 'nullable' => true, 'unique' => false, 'onDelete' => 'CASCADE', 'columnDefinition' => NULL, - ), - ), - 'inverseJoinColumns' => array( - 0 => array( + ], + ], + 'inverseJoinColumns' => [ + 0 => [ 'name' => 'cmsgroup_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE' - ) - ), + ] + ], 'name' => 'cmsuser_cmsgroup', - ), + ], 'type' => 8, 'mappedBy' => NULL, 'inversedBy' => NULL, @@ -812,19 +826,19 @@ public function testOrphanRemovalOnManyToMany() 'isCascadeMerge' => false, 'isCascadeDetach' => false, 'isOnDeleteCascade' => true, - 'relationToSourceKeyColumns' => array( + 'relationToSourceKeyColumns' => [ 'group_id' => 'id', - ), - 'joinTableColumns' => array( + ], + 'joinTableColumns' => [ 0 => 'group_id', 1 => 'cmsgroup_id', - ), - 'relationToTargetKeyColumns' => array( + ], + 'relationToTargetKeyColumns' => [ 'cmsgroup_id' => 'id', - ), + ], 'orphanRemoval' => true, - ), - ), $this->cm->associationMappings); + ], + ], $this->cm->associationMappings); } public function assertIsFluent($ret) diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index f40d657b53c..bdfd6893d48 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -42,7 +42,7 @@ public function testGetMetadataForSingleClass() $cmf->setMetadataFor($cm1->name, $cm1); // Prechecks - $this->assertEquals(array(), $cm1->parentClasses); + $this->assertEquals([], $cm1->parentClasses); $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $cm1->inheritanceType); $this->assertTrue($cm1->hasField('name')); $this->assertEquals(2, count($cm1->associationMappings)); @@ -55,7 +55,7 @@ public function testGetMetadataForSingleClass() $this->assertSame($cm1, $cmMap1); $this->assertEquals('group', $cmMap1->table['name']); $this->assertTrue($cmMap1->table['quoted']); - $this->assertEquals(array(), $cmMap1->parentClasses); + $this->assertEquals([], $cmMap1->parentClasses); $this->assertTrue($cmMap1->hasField('name')); } @@ -63,8 +63,9 @@ public function testGetMetadataFor_ReturnsLoadedCustomIdGenerator() { $cm1 = $this->_createValidClassMetadata(); $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_CUSTOM); - $cm1->customGeneratorDefinition = array( - "class" => "Doctrine\Tests\ORM\Mapping\CustomIdGenerator"); + $cm1->customGeneratorDefinition = [ + "class" => "Doctrine\Tests\ORM\Mapping\CustomIdGenerator" + ]; $cmf = $this->_createTestFactory(); $cmf->setMetadataForClass($cm1->name, $cm1); @@ -80,7 +81,7 @@ public function testGetMetadataFor_ThrowsExceptionOnUnknownCustomGeneratorClass( { $cm1 = $this->_createValidClassMetadata(); $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_CUSTOM); - $cm1->customGeneratorDefinition = array("class" => "NotExistingGenerator"); + $cm1->customGeneratorDefinition = ["class" => "NotExistingGenerator"]; $cmf = $this->_createTestFactory(); $cmf->setMetadataForClass($cm1->name, $cm1); $this->expectException(ORMException::class); @@ -103,7 +104,7 @@ public function testHasGetMetadata_NamespaceSeparatorIsNotNormalized() { require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php"; - $metadataDriver = $this->createAnnotationDriver(array(__DIR__ . '/../../Models/Global/')); + $metadataDriver = $this->createAnnotationDriver([__DIR__ . '/../../Models/Global/']); $entityManager = $this->_createEntityManager($metadataDriver); @@ -166,7 +167,7 @@ public function testIsTransientEntityNamespace() public function testAddDefaultDiscriminatorMap() { $cmf = new ClassMetadataFactory(); - $driver = $this->createAnnotationDriver(array(__DIR__ . '/../../Models/JoinedInheritanceType/')); + $driver = $this->createAnnotationDriver([__DIR__ . '/../../Models/JoinedInheritanceType/']); $em = $this->_createEntityManager($driver); $cmf->setEntityManager($em); @@ -194,7 +195,7 @@ public function testAddDefaultDiscriminatorMap() // ClassMetadataFactory::addDefaultDiscriminatorMap shouldn't be called again, because the // discriminator map is already cached - $cmf = $this->getMockBuilder(ClassMetadataFactory::class)->setMethods(array('addDefaultDiscriminatorMap'))->getMock(); + $cmf = $this->getMockBuilder(ClassMetadataFactory::class)->setMethods(['addDefaultDiscriminatorMap'])->getMock(); $cmf->setEntityManager($em); $cmf->expects($this->never()) ->method('addDefaultDiscriminatorMap'); @@ -219,7 +220,7 @@ public function testGetAllMetadataWorksWithBadConnection() // getting all the metadata should work, even if get DatabasePlatform blows up $metadata = $cmf->getAllMetadata(); // this will just be an empty array - there was no error - $this->assertEquals(array(), $metadata); + $this->assertEquals([], $metadata); } protected function _createEntityManager($metadataDriver, $conn = null) @@ -230,7 +231,7 @@ protected function _createEntityManager($metadataDriver, $conn = null) $config->setProxyNamespace('Doctrine\Tests\Proxies'); $eventManager = new EventManager(); if (!$conn) { - $conn = new ConnectionMock(array(), $driverMock, $config, $eventManager); + $conn = new ConnectionMock([], $driverMock, $config, $eventManager); } $config->setMetadataDriverImpl($metadataDriver); @@ -258,18 +259,20 @@ protected function _createValidClassMetadata() // Self-made metadata $cm1 = new ClassMetadata('Doctrine\Tests\ORM\Mapping\TestEntity1'); $cm1->initializeReflection(new RuntimeReflectionService()); - $cm1->setPrimaryTable(array('name' => '`group`')); + $cm1->setPrimaryTable(['name' => '`group`']); // Add a mapped field - $cm1->mapField(array('fieldName' => 'name', 'type' => 'string')); + $cm1->mapField(['fieldName' => 'name', 'type' => 'string']); // Add a mapped field - $cm1->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true)); + $cm1->mapField(['fieldName' => 'id', 'type' => 'integer', 'id' => true]); // and a mapped association - $cm1->mapOneToOne(array('fieldName' => 'other', 'targetEntity' => 'TestEntity1', 'mappedBy' => 'this')); + $cm1->mapOneToOne(['fieldName' => 'other', 'targetEntity' => 'TestEntity1', 'mappedBy' => 'this']); // and an association on the owning side - $joinColumns = array( - array('name' => 'other_id', 'referencedColumnName' => 'id') + $joinColumns = [ + ['name' => 'other_id', 'referencedColumnName' => 'id'] + ]; + $cm1->mapOneToOne( + ['fieldName' => 'association', 'targetEntity' => 'TestEntity1', 'joinColumns' => $joinColumns] ); - $cm1->mapOneToOne(array('fieldName' => 'association', 'targetEntity' => 'TestEntity1', 'joinColumns' => $joinColumns)); // and an id generator type $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO); return $cm1; @@ -281,7 +284,7 @@ protected function _createValidClassMetadata() public function testQuoteMetadata() { $cmf = new ClassMetadataFactory(); - $driver = $this->createAnnotationDriver(array(__DIR__ . '/../../Models/Quote/')); + $driver = $this->createAnnotationDriver([__DIR__ . '/../../Models/Quote/']); $em = $this->_createEntityManager($driver); $cmf->setEntityManager($em); @@ -368,7 +371,7 @@ public function testFallbackLoadingCausesEventTriggeringThatCanModifyFetchedMeta $cmf = new ClassMetadataFactory(); $mockDriver = new MetadataDriverMock(); $em = $this->_createEntityManager($mockDriver); - $listener = $this->getMockBuilder(\stdClass::class)->setMethods(array('onClassMetadataNotFound'))->getMock(); + $listener = $this->getMockBuilder(\stdClass::class)->setMethods(['onClassMetadataNotFound'])->getMock(); $eventManager = $em->getEventManager(); $cmf->setEntityManager($em); @@ -384,7 +387,7 @@ public function testFallbackLoadingCausesEventTriggeringThatCanModifyFetchedMeta $args->setFoundMetadata($metadata); })); - $eventManager->addEventListener(array(Events::onClassMetadataNotFound), $listener); + $eventManager->addEventListener([Events::onClassMetadataNotFound], $listener); $this->assertSame($metadata, $cmf->getMetadataFor('Foo')); } @@ -412,11 +415,13 @@ public function testRejectsEmbeddableWithoutValidClassName() { $metadata = $this->_createValidClassMetadata(); - $metadata->mapEmbedded(array( + $metadata->mapEmbedded( + [ 'fieldName' => 'embedded', 'class' => '', 'columnPrefix' => false, - )); + ] + ); $cmf = $this->_createTestFactory(); @@ -434,7 +439,7 @@ public function testRejectsEmbeddableWithoutValidClassName() public function testInheritsIdGeneratorMappingFromEmbeddable() { $cmf = new ClassMetadataFactory(); - $driver = $this->createAnnotationDriver(array(__DIR__ . '/../../Models/DDC4006/')); + $driver = $this->createAnnotationDriver([__DIR__ . '/../../Models/DDC4006/']); $em = $this->_createEntityManager($driver); $cmf->setEntityManager($em); @@ -447,8 +452,8 @@ public function testInheritsIdGeneratorMappingFromEmbeddable() /* Test subject class with overridden factory method for mocking purposes */ class ClassMetadataFactoryTestSubject extends ClassMetadataFactory { - private $mockMetadata = array(); - private $requestedClasses = array(); + private $mockMetadata = []; + private $requestedClasses = []; /** @override */ protected function newClassMetadataInstance($className) diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataLoadEventTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataLoadEventTest.php index 04cea38944c..424cafb9468 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataLoadEventTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataLoadEventTest.php @@ -26,11 +26,11 @@ public function testEvent() public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs) { $classMetadata = $eventArgs->getClassMetadata(); - $field = array( + $field = [ 'fieldName' => 'about', 'type' => 'string', 'length' => 255 - ); + ]; $classMetadata->mapField($field); } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php index 44243e11353..bfaec804104 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php @@ -26,19 +26,19 @@ public function testClassMetadataInstanceSerialization() $this->assertInstanceOf('ReflectionClass', $cm->reflClass); $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->name); $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->rootEntityName); - $this->assertEquals(array(), $cm->subClasses); - $this->assertEquals(array(), $cm->parentClasses); + $this->assertEquals([], $cm->subClasses); + $this->assertEquals([], $cm->parentClasses); $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $cm->inheritanceType); // Customize state $cm->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_SINGLE_TABLE); - $cm->setSubclasses(array("One", "Two", "Three")); - $cm->setParentClasses(array("UserParent")); + $cm->setSubclasses(["One", "Two", "Three"]); + $cm->setParentClasses(["UserParent"]); $cm->setCustomRepositoryClass("UserRepository"); - $cm->setDiscriminatorColumn(array('name' => 'disc', 'type' => 'integer')); - $cm->mapOneToOne(array('fieldName' => 'phonenumbers', 'targetEntity' => 'CmsAddress', 'mappedBy' => 'foo')); + $cm->setDiscriminatorColumn(['name' => 'disc', 'type' => 'integer']); + $cm->mapOneToOne(['fieldName' => 'phonenumbers', 'targetEntity' => 'CmsAddress', 'mappedBy' => 'foo']); $cm->markReadOnly(); - $cm->addNamedQuery(array('name' => 'dql', 'query' => 'foo')); + $cm->addNamedQuery(['name' => 'dql', 'query' => 'foo']); $this->assertEquals(1, count($cm->associationMappings)); $serialized = serialize($cm); @@ -51,10 +51,11 @@ public function testClassMetadataInstanceSerialization() $this->assertInstanceOf('ReflectionClass', $cm->reflClass); $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->name); $this->assertEquals('UserParent', $cm->rootEntityName); - $this->assertEquals(array('Doctrine\Tests\Models\CMS\One', 'Doctrine\Tests\Models\CMS\Two', 'Doctrine\Tests\Models\CMS\Three'), $cm->subClasses); - $this->assertEquals(array('UserParent'), $cm->parentClasses); + $this->assertEquals( + ['Doctrine\Tests\Models\CMS\One', 'Doctrine\Tests\Models\CMS\Two', 'Doctrine\Tests\Models\CMS\Three'], $cm->subClasses); + $this->assertEquals(['UserParent'], $cm->parentClasses); $this->assertEquals('Doctrine\Tests\Models\CMS\UserRepository', $cm->customRepositoryClassName); - $this->assertEquals(array('name' => 'disc', 'type' => 'integer', 'fieldName' => 'disc'), $cm->discriminatorColumn); + $this->assertEquals(['name' => 'disc', 'type' => 'integer', 'fieldName' => 'disc'], $cm->discriminatorColumn); $this->assertTrue($cm->associationMappings['phonenumbers']['type'] == ClassMetadata::ONE_TO_ONE); $this->assertEquals(1, count($cm->associationMappings)); $oneOneMapping = $cm->getAssociationMapping('phonenumbers'); @@ -62,7 +63,7 @@ public function testClassMetadataInstanceSerialization() $this->assertEquals('phonenumbers', $oneOneMapping['fieldName']); $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress', $oneOneMapping['targetEntity']); $this->assertTrue($cm->isReadOnly); - $this->assertEquals(array('dql' => array('name'=>'dql','query'=>'foo','dql'=>'foo')), $cm->namedQueries); + $this->assertEquals(['dql' => ['name'=>'dql','query'=>'foo','dql'=>'foo']], $cm->namedQueries); } public function testFieldIsNullable() @@ -71,15 +72,15 @@ public function testFieldIsNullable() $cm->initializeReflection(new RuntimeReflectionService()); // Explicit Nullable - $cm->mapField(array('fieldName' => 'status', 'nullable' => true, 'type' => 'string', 'length' => 50)); + $cm->mapField(['fieldName' => 'status', 'nullable' => true, 'type' => 'string', 'length' => 50]); $this->assertTrue($cm->isNullable('status')); // Explicit Not Nullable - $cm->mapField(array('fieldName' => 'username', 'nullable' => false, 'type' => 'string', 'length' => 50)); + $cm->mapField(['fieldName' => 'username', 'nullable' => false, 'type' => 'string', 'length' => 50]); $this->assertFalse($cm->isNullable('username')); // Implicit Not Nullable - $cm->mapField(array('fieldName' => 'name', 'type' => 'string', 'length' => 50)); + $cm->mapField(['fieldName' => 'name', 'type' => 'string', 'length' => 50]); $this->assertFalse($cm->isNullable('name'), "By default a field should not be nullable."); } @@ -92,15 +93,17 @@ public function testMapAssociationInGlobalNamespace() $cm = new ClassMetadata('DoctrineGlobal_Article'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->mapManyToMany(array( + $cm->mapManyToMany( + [ 'fieldName' => 'author', 'targetEntity' => 'DoctrineGlobal_User', - 'joinTable' => array( + 'joinTable' => [ 'name' => 'bar', - 'joinColumns' => array(array('name' => 'bar_id', 'referencedColumnName' => 'id')), - 'inverseJoinColumns' => array(array('name' => 'baz_id', 'referencedColumnName' => 'id')), - ), - )); + 'joinColumns' => [['name' => 'bar_id', 'referencedColumnName' => 'id']], + 'inverseJoinColumns' => [['name' => 'baz_id', 'referencedColumnName' => 'id']], + ], + ] + ); $this->assertEquals("DoctrineGlobal_User", $cm->associationMappings['author']['targetEntity']); } @@ -110,18 +113,20 @@ public function testMapManyToManyJoinTableDefaults() $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); $cm->mapManyToMany( - array( + [ 'fieldName' => 'groups', 'targetEntity' => 'CmsGroup' - )); + ] + ); $assoc = $cm->associationMappings['groups']; //$this->assertInstanceOf('Doctrine\ORM\Mapping\ManyToManyMapping', $assoc); - $this->assertEquals(array( + $this->assertEquals( + [ 'name' => 'cmsuser_cmsgroup', - 'joinColumns' => array(array('name' => 'cmsuser_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE')), - 'inverseJoinColumns' => array(array('name' => 'cmsgroup_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE')) - ), $assoc['joinTable']); + 'joinColumns' => [['name' => 'cmsuser_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE']], + 'inverseJoinColumns' => [['name' => 'cmsgroup_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE']] + ], $assoc['joinTable']); $this->assertTrue($assoc['isOnDeleteCascade']); } @@ -130,10 +135,11 @@ public function testSerializeManyToManyJoinTableCascade() $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); $cm->mapManyToMany( - array( + [ 'fieldName' => 'groups', 'targetEntity' => 'CmsGroup' - )); + ] + ); /* @var $assoc \Doctrine\ORM\Mapping\ManyToManyMapping */ $assoc = $cm->associationMappings['groups']; @@ -151,7 +157,7 @@ public function testSetDiscriminatorMapInGlobalNamespace() $cm = new ClassMetadata('DoctrineGlobal_User'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->setDiscriminatorMap(array('descr' => 'DoctrineGlobal_Article', 'foo' => 'DoctrineGlobal_User')); + $cm->setDiscriminatorMap(['descr' => 'DoctrineGlobal_Article', 'foo' => 'DoctrineGlobal_User']); $this->assertEquals("DoctrineGlobal_Article", $cm->discriminatorMap['descr']); $this->assertEquals("DoctrineGlobal_User", $cm->discriminatorMap['foo']); @@ -166,7 +172,7 @@ public function testSetSubClassesInGlobalNamespace() $cm = new ClassMetadata('DoctrineGlobal_User'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->setSubclasses(array('DoctrineGlobal_Article')); + $cm->setSubclasses(['DoctrineGlobal_Article']); $this->assertEquals("DoctrineGlobal_Article", $cm->subClasses[0]); } @@ -176,7 +182,7 @@ public function testSetSubClassesInGlobalNamespace() */ public function testSetInvalidVersionMapping_ThrowsException() { - $field = array(); + $field = []; $field['fieldName'] = 'foo'; $field['type'] = 'string'; @@ -202,8 +208,8 @@ public function testDuplicateAssociationMappingException() $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $a1 = array('fieldName' => 'foo', 'sourceEntity' => 'stdClass', 'targetEntity' => 'stdClass', 'mappedBy' => 'foo'); - $a2 = array('fieldName' => 'foo', 'sourceEntity' => 'stdClass', 'targetEntity' => 'stdClass', 'mappedBy' => 'foo'); + $a1 = ['fieldName' => 'foo', 'sourceEntity' => 'stdClass', 'targetEntity' => 'stdClass', 'mappedBy' => 'foo']; + $a2 = ['fieldName' => 'foo', 'sourceEntity' => 'stdClass', 'targetEntity' => 'stdClass', 'mappedBy' => 'foo']; $cm->addInheritedAssociationMapping($a1); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); @@ -215,10 +221,10 @@ public function testDuplicateColumnName_ThrowsMappingException() $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); + $cm->mapField(['fieldName' => 'name', 'columnName' => 'name']); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); - $cm->mapField(array('fieldName' => 'username', 'columnName' => 'name')); + $cm->mapField(['fieldName' => 'username', 'columnName' => 'name']); } public function testDuplicateColumnName_DiscriminatorColumn_ThrowsMappingException() @@ -226,10 +232,10 @@ public function testDuplicateColumnName_DiscriminatorColumn_ThrowsMappingExcepti $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); + $cm->mapField(['fieldName' => 'name', 'columnName' => 'name']); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); - $cm->setDiscriminatorColumn(array('name' => 'name')); + $cm->setDiscriminatorColumn(['name' => 'name']); } public function testDuplicateColumnName_DiscriminatorColumn2_ThrowsMappingException() @@ -237,10 +243,10 @@ public function testDuplicateColumnName_DiscriminatorColumn2_ThrowsMappingExcept $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->setDiscriminatorColumn(array('name' => 'name')); + $cm->setDiscriminatorColumn(['name' => 'name']); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); - $cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); + $cm->mapField(['fieldName' => 'name', 'columnName' => 'name']); } public function testDuplicateFieldAndAssociationMapping1_ThrowsException() @@ -248,10 +254,10 @@ public function testDuplicateFieldAndAssociationMapping1_ThrowsException() $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); + $cm->mapField(['fieldName' => 'name', 'columnName' => 'name']); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); - $cm->mapOneToOne(array('fieldName' => 'name', 'targetEntity' => 'CmsUser')); + $cm->mapOneToOne(['fieldName' => 'name', 'targetEntity' => 'CmsUser']); } public function testDuplicateFieldAndAssociationMapping2_ThrowsException() @@ -259,10 +265,10 @@ public function testDuplicateFieldAndAssociationMapping2_ThrowsException() $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->mapOneToOne(array('fieldName' => 'name', 'targetEntity' => 'CmsUser')); + $cm->mapOneToOne(['fieldName' => 'name', 'targetEntity' => 'CmsUser']); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); - $cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); + $cm->mapField(['fieldName' => 'name', 'columnName' => 'name']); } /** @@ -284,7 +290,7 @@ public function testDefaultTableName() $cm->initializeReflection(new RuntimeReflectionService()); // When table's name is not given - $primaryTable = array(); + $primaryTable = []; $cm->setPrimaryTable($primaryTable); $this->assertEquals('CmsUser', $cm->getTableName()); @@ -293,12 +299,17 @@ public function testDefaultTableName() $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); $cm->initializeReflection(new RuntimeReflectionService()); // When joinTable's name is not given - $cm->mapManyToMany(array( + $cm->mapManyToMany( + [ 'fieldName' => 'user', 'targetEntity' => 'CmsUser', 'inversedBy' => 'users', - 'joinTable' => array('joinColumns' => array(array('referencedColumnName' => 'id')), - 'inverseJoinColumns' => array(array('referencedColumnName' => 'id'))))); + 'joinTable' => [ + 'joinColumns' => [['referencedColumnName' => 'id']], + 'inverseJoinColumns' => [['referencedColumnName' => 'id']] + ] + ] + ); $this->assertEquals('cmsaddress_cmsuser', $cm->associationMappings['user']['joinTable']['name']); } @@ -309,21 +320,29 @@ public function testDefaultJoinColumnName() // this is really dirty, but it's the simplest way to test whether // joinColumn's name will be automatically set to user_id - $cm->mapOneToOne(array( + $cm->mapOneToOne( + [ 'fieldName' => 'user', 'targetEntity' => 'CmsUser', - 'joinColumns' => array(array('referencedColumnName' => 'id')))); + 'joinColumns' => [['referencedColumnName' => 'id']] + ] + ); $this->assertEquals('user_id', $cm->associationMappings['user']['joinColumns'][0]['name']); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->mapManyToMany(array( + $cm->mapManyToMany( + [ 'fieldName' => 'user', 'targetEntity' => 'CmsUser', 'inversedBy' => 'users', - 'joinTable' => array('name' => 'user_CmsUser', - 'joinColumns' => array(array('referencedColumnName' => 'id')), - 'inverseJoinColumns' => array(array('referencedColumnName' => 'id'))))); + 'joinTable' => [ + 'name' => 'user_CmsUser', + 'joinColumns' => [['referencedColumnName' => 'id']], + 'inverseJoinColumns' => [['referencedColumnName' => 'id']] + ] + ] + ); $this->assertEquals('cmsaddress_id', $cm->associationMappings['user']['joinTable']['joinColumns'][0]['name']); $this->assertEquals('cmsuser_id', $cm->associationMappings['user']['joinTable']['inverseJoinColumns'][0]['name']); } @@ -337,19 +356,23 @@ public function testUnderscoreNamingStrategyDefaults() $oneToOneMetadata = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', $namingStrategy); $manyToManyMetadata = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', $namingStrategy); - $oneToOneMetadata->mapOneToOne(array( + $oneToOneMetadata->mapOneToOne( + [ 'fieldName' => 'user', 'targetEntity' => 'CmsUser' - )); + ] + ); - $manyToManyMetadata->mapManyToMany(array( + $manyToManyMetadata->mapManyToMany( + [ 'fieldName' => 'user', 'targetEntity' => 'CmsUser' - )); + ] + ); - $this->assertEquals(array('USER_ID'=>'ID'), $oneToOneMetadata->associationMappings['user']['sourceToTargetKeyColumns']); - $this->assertEquals(array('USER_ID'=>'USER_ID'), $oneToOneMetadata->associationMappings['user']['joinColumnFieldNames']); - $this->assertEquals(array('ID'=>'USER_ID'), $oneToOneMetadata->associationMappings['user']['targetToSourceKeyColumns']); + $this->assertEquals(['USER_ID'=>'ID'], $oneToOneMetadata->associationMappings['user']['sourceToTargetKeyColumns']); + $this->assertEquals(['USER_ID'=>'USER_ID'], $oneToOneMetadata->associationMappings['user']['joinColumnFieldNames']); + $this->assertEquals(['ID'=>'USER_ID'], $oneToOneMetadata->associationMappings['user']['targetToSourceKeyColumns']); $this->assertEquals('USER_ID', $oneToOneMetadata->associationMappings['user']['joinColumns'][0]['name']); $this->assertEquals('ID', $oneToOneMetadata->associationMappings['user']['joinColumns'][0]['referencedColumnName']); @@ -357,9 +380,9 @@ public function testUnderscoreNamingStrategyDefaults() $this->assertEquals('CMS_ADDRESS_CMS_USER', $manyToManyMetadata->associationMappings['user']['joinTable']['name']); - $this->assertEquals(array('CMS_ADDRESS_ID','CMS_USER_ID'), $manyToManyMetadata->associationMappings['user']['joinTableColumns']); - $this->assertEquals(array('CMS_ADDRESS_ID'=>'ID'), $manyToManyMetadata->associationMappings['user']['relationToSourceKeyColumns']); - $this->assertEquals(array('CMS_USER_ID'=>'ID'), $manyToManyMetadata->associationMappings['user']['relationToTargetKeyColumns']); + $this->assertEquals(['CMS_ADDRESS_ID','CMS_USER_ID'], $manyToManyMetadata->associationMappings['user']['joinTableColumns']); + $this->assertEquals(['CMS_ADDRESS_ID'=>'ID'], $manyToManyMetadata->associationMappings['user']['relationToSourceKeyColumns']); + $this->assertEquals(['CMS_USER_ID'=>'ID'], $manyToManyMetadata->associationMappings['user']['relationToTargetKeyColumns']); $this->assertEquals('CMS_ADDRESS_ID', $manyToManyMetadata->associationMappings['user']['joinTable']['joinColumns'][0]['name']); $this->assertEquals('CMS_USER_ID', $manyToManyMetadata->associationMappings['user']['joinTable']['inverseJoinColumns'][0]['name']); @@ -369,7 +392,7 @@ public function testUnderscoreNamingStrategyDefaults() $cm = new ClassMetadata('DoctrineGlobal_Article', $namingStrategy); - $cm->mapManyToMany(array('fieldName' => 'author', 'targetEntity' => 'Doctrine\Tests\Models\CMS\CmsUser')); + $cm->mapManyToMany(['fieldName' => 'author', 'targetEntity' => 'Doctrine\Tests\Models\CMS\CmsUser']); $this->assertEquals('DOCTRINE_GLOBAL_ARTICLE_CMS_USER', $cm->associationMappings['author']['joinTable']['name']); } @@ -381,10 +404,10 @@ public function testSetMultipleIdentifierSetsComposite() $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->mapField(array('fieldName' => 'name')); - $cm->mapField(array('fieldName' => 'username')); + $cm->mapField(['fieldName' => 'name']); + $cm->mapField(['fieldName' => 'username']); - $cm->setIdentifier(array('name', 'username')); + $cm->setIdentifier(['name', 'username']); $this->assertTrue($cm->isIdentifierComposite); } @@ -410,7 +433,7 @@ public function testJoinTableMappingDefaults() $cm = new ClassMetadata('DoctrineGlobal_Article'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->mapManyToMany(array('fieldName' => 'author', 'targetEntity' => 'Doctrine\Tests\Models\CMS\CmsUser')); + $cm->mapManyToMany(['fieldName' => 'author', 'targetEntity' => 'Doctrine\Tests\Models\CMS\CmsUser']); $this->assertEquals('doctrineglobal_article_cmsuser', $cm->associationMappings['author']['joinTable']['name']); } @@ -423,15 +446,17 @@ public function testMapIdentifierAssociation() $cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->mapOneToOne(array( + $cm->mapOneToOne( + [ 'fieldName' => 'article', 'id' => true, 'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', - 'joinColumns' => array(), - )); + 'joinColumns' => [], + ] + ); $this->assertTrue($cm->containsForeignIdentifier, "Identifier Association should set 'containsForeignIdentifier' boolean flag."); - $this->assertEquals(array("article"), $cm->identifier); + $this->assertEquals(["article"], $cm->identifier); } /** @@ -445,13 +470,15 @@ public function testOrphanRemovalIdentifierAssociation() $this->expectException(MappingException::class); $this->expectExceptionMessage('The orphan removal option is not allowed on an association that'); - $cm->mapOneToOne(array( + $cm->mapOneToOne( + [ 'fieldName' => 'article', 'id' => true, 'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', 'orphanRemoval' => true, - 'joinColumns' => array(), - )); + 'joinColumns' => [], + ] + ); } /** @@ -465,13 +492,15 @@ public function testInverseIdentifierAssociation() $this->expectException(MappingException::class); $this->expectExceptionMessage('An inverse association is not allowed to be identifier in'); - $cm->mapOneToOne(array( + $cm->mapOneToOne( + [ 'fieldName' => 'article', 'id' => true, 'mappedBy' => 'details', // INVERSE! 'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', - 'joinColumns' => array(), - )); + 'joinColumns' => [], + ] + ); } /** @@ -485,12 +514,14 @@ public function testIdentifierAssociationManyToMany() $this->expectException(MappingException::class); $this->expectExceptionMessage('Many-to-many or one-to-many associations are not allowed to be identifier in'); - $cm->mapManyToMany(array( + $cm->mapManyToMany( + [ 'fieldName' => 'article', 'id' => true, 'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', - 'joinColumns' => array(), - )); + 'joinColumns' => [], + ] + ); } /** @@ -504,7 +535,7 @@ public function testEmptyFieldNameThrowsException() $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->mapField(array('fieldName' => '')); + $cm->mapField(['fieldName' => '']); } public function testRetrievalOfNamedQueries() @@ -515,10 +546,12 @@ public function testRetrievalOfNamedQueries() $this->assertEquals(0, count($cm->getNamedQueries())); - $cm->addNamedQuery(array( + $cm->addNamedQuery( + [ 'name' => 'userById', 'query' => 'SELECT u FROM __CLASS__ u WHERE u.id = ?1' - )); + ] + ); $this->assertEquals(1, count($cm->getNamedQueries())); } @@ -534,14 +567,16 @@ public function testRetrievalOfResultSetMappings() $this->assertEquals(0, count($cm->getSqlResultSetMappings())); - $cm->addSqlResultSetMapping(array( + $cm->addSqlResultSetMapping( + [ 'name' => 'find-all', - 'entities' => array( - array( + 'entities' => [ + [ 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', - ), - ), - )); + ], + ], + ] + ); $this->assertEquals(1, count($cm->getSqlResultSetMappings())); } @@ -552,10 +587,12 @@ public function testExistanceOfNamedQuery() $cm->initializeReflection(new RuntimeReflectionService()); - $cm->addNamedQuery(array( + $cm->addNamedQuery( + [ 'name' => 'all', 'query' => 'SELECT u FROM __CLASS__ u' - )); + ] + ); $this->assertTrue($cm->hasNamedQuery('all')); $this->assertFalse($cm->hasNamedQuery('userById')); @@ -569,19 +606,23 @@ public function testRetrieveOfNamedNativeQuery() $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->addNamedNativeQuery(array( + $cm->addNamedNativeQuery( + [ 'name' => 'find-all', 'query' => 'SELECT * FROM cms_users', 'resultSetMapping' => 'result-mapping-name', 'resultClass' => 'Doctrine\Tests\Models\CMS\CmsUser', - )); + ] + ); - $cm->addNamedNativeQuery(array( + $cm->addNamedNativeQuery( + [ 'name' => 'find-by-id', 'query' => 'SELECT * FROM cms_users WHERE id = ?', 'resultClass' => '__CLASS__', 'resultSetMapping' => 'result-mapping-name', - )); + ] + ); $mapping = $cm->getNamedNativeQuery('find-all'); $this->assertEquals('SELECT * FROM cms_users', $mapping['query']); @@ -602,52 +643,54 @@ public function testRetrieveOfSqlResultSetMapping() $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->addSqlResultSetMapping(array( + $cm->addSqlResultSetMapping( + [ 'name' => 'find-all', - 'entities' => array( - array( + 'entities' => [ + [ 'entityClass' => '__CLASS__', - 'fields' => array( - array( + 'fields' => [ + [ 'name' => 'id', 'column'=> 'id' - ), - array( + ], + [ 'name' => 'name', 'column'=> 'name' - ) - ) - ), - array( + ] + ] + ], + [ 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsEmail', - 'fields' => array( - array( + 'fields' => [ + [ 'name' => 'id', 'column'=> 'id' - ), - array( + ], + [ 'name' => 'email', 'column'=> 'email' - ) - ) - ) - ), - 'columns' => array( - array( + ] + ] + ] + ], + 'columns' => [ + [ 'name' => 'scalarColumn' - ) - ) - )); + ] + ] + ] + ); $mapping = $cm->getSqlResultSetMapping('find-all'); $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $mapping['entities'][0]['entityClass']); - $this->assertEquals(array('name'=>'id','column'=>'id'), $mapping['entities'][0]['fields'][0]); - $this->assertEquals(array('name'=>'name','column'=>'name'), $mapping['entities'][0]['fields'][1]); + $this->assertEquals(['name'=>'id','column'=>'id'], $mapping['entities'][0]['fields'][0]); + $this->assertEquals(['name'=>'name','column'=>'name'], $mapping['entities'][0]['fields'][1]); $this->assertEquals('Doctrine\Tests\Models\CMS\CmsEmail', $mapping['entities'][1]['entityClass']); - $this->assertEquals(array('name'=>'id','column'=>'id'), $mapping['entities'][1]['fields'][0]); - $this->assertEquals(array('name'=>'email','column'=>'email'), $mapping['entities'][1]['fields'][1]); + $this->assertEquals(['name'=>'id','column'=>'id'], $mapping['entities'][1]['fields'][0]); + $this->assertEquals(['name'=>'email','column'=>'email'], $mapping['entities'][1]['fields'][1]); $this->assertEquals('scalarColumn', $mapping['columns'][0]['name']); } @@ -660,14 +703,16 @@ public function testExistanceOfSqlResultSetMapping() $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->addSqlResultSetMapping(array( + $cm->addSqlResultSetMapping( + [ 'name' => 'find-all', - 'entities' => array( - array( + 'entities' => [ + [ 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', - ), - ), - )); + ], + ], + ] + ); $this->assertTrue($cm->hasSqlResultSetMapping('find-all')); $this->assertFalse($cm->hasSqlResultSetMapping('find-by-id')); @@ -682,12 +727,14 @@ public function testExistanceOfNamedNativeQuery() $cm->initializeReflection(new RuntimeReflectionService()); - $cm->addNamedNativeQuery(array( + $cm->addNamedNativeQuery( + [ 'name' => 'find-all', 'query' => 'SELECT * FROM cms_users', 'resultClass' => 'Doctrine\Tests\Models\CMS\CmsUser', 'resultSetMapping' => 'result-mapping-name' - )); + ] + ); $this->assertTrue($cm->hasNamedNativeQuery('find-all')); $this->assertFalse($cm->hasNamedNativeQuery('find-by-id')); @@ -699,10 +746,12 @@ public function testRetrieveOfNamedQuery() $cm->initializeReflection(new RuntimeReflectionService()); - $cm->addNamedQuery(array( + $cm->addNamedQuery( + [ 'name' => 'userById', 'query' => 'SELECT u FROM __CLASS__ u WHERE u.id = ?1' - )); + ] + ); $this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1', $cm->getNamedQuery('userById')); } @@ -717,12 +766,14 @@ public function testRetrievalOfNamedNativeQueries() $this->assertEquals(0, count($cm->getNamedNativeQueries())); - $cm->addNamedNativeQuery(array( + $cm->addNamedNativeQuery( + [ 'name' => 'find-all', 'query' => 'SELECT * FROM cms_users', 'resultClass' => 'Doctrine\Tests\Models\CMS\CmsUser', 'resultSetMapping' => 'result-mapping-name' - )); + ] + ); $this->assertEquals(1, count($cm->getNamedNativeQueries())); } @@ -753,15 +804,19 @@ public function testNamingCollisionNamedQueryShouldThrowException() $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->addNamedQuery(array( + $cm->addNamedQuery( + [ 'name' => 'userById', 'query' => 'SELECT u FROM __CLASS__ u WHERE u.id = ?1' - )); + ] + ); - $cm->addNamedQuery(array( + $cm->addNamedQuery( + [ 'name' => 'userById', 'query' => 'SELECT u FROM __CLASS__ u WHERE u.id = ?1' - )); + ] + ); } /** @@ -775,19 +830,23 @@ public function testNamingCollisionNamedNativeQueryShouldThrowException() $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->addNamedNativeQuery(array( + $cm->addNamedNativeQuery( + [ 'name' => 'find-all', 'query' => 'SELECT * FROM cms_users', 'resultClass' => 'Doctrine\Tests\Models\CMS\CmsUser', 'resultSetMapping' => 'result-mapping-name' - )); + ] + ); - $cm->addNamedNativeQuery(array( + $cm->addNamedNativeQuery( + [ 'name' => 'find-all', 'query' => 'SELECT * FROM cms_users', 'resultClass' => 'Doctrine\Tests\Models\CMS\CmsUser', 'resultSetMapping' => 'result-mapping-name' - )); + ] + ); } /** @@ -801,23 +860,27 @@ public function testNamingCollisionSqlResultSetMappingShouldThrowException() $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->addSqlResultSetMapping(array( + $cm->addSqlResultSetMapping( + [ 'name' => 'find-all', - 'entities' => array( - array( + 'entities' => [ + [ 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', - ), - ), - )); + ], + ], + ] + ); - $cm->addSqlResultSetMapping(array( + $cm->addSqlResultSetMapping( + [ 'name' => 'find-all', - 'entities' => array( - array( + 'entities' => [ + [ 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', - ), - ), - )); + ], + ], + ] + ); } /** @@ -854,7 +917,7 @@ public function testTargetEntityNotFound() { $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->mapManyToOne(array('fieldName' => 'address', 'targetEntity' => 'UnknownClass')); + $cm->mapManyToOne(['fieldName' => 'address', 'targetEntity' => 'UnknownClass']); $this->expectException(MappingException::class); $this->expectExceptionMessage("The target-entity Doctrine\Tests\Models\CMS\UnknownClass cannot be found in 'Doctrine\Tests\Models\CMS\CmsUser#address'."); @@ -872,9 +935,11 @@ public function testNameIsMandatoryForNamedQueryMappingException() { $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->addNamedQuery(array( + $cm->addNamedQuery( + [ 'query' => 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u', - )); + ] + ); } /** @@ -887,11 +952,13 @@ public function testNameIsMandatoryForNameNativeQueryMappingException() { $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->addNamedQuery(array( + $cm->addNamedQuery( + [ 'query' => 'SELECT * FROM cms_users', 'resultClass' => 'Doctrine\Tests\Models\CMS\CmsUser', 'resultSetMapping' => 'result-mapping-name' - )); + ] + ); } /** @@ -904,14 +971,16 @@ public function testNameIsMandatoryForEntityNameSqlResultSetMappingException() { $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->addSqlResultSetMapping(array( + $cm->addSqlResultSetMapping( + [ 'name' => 'find-all', - 'entities' => array( - array( - 'fields' => array() - ) - ), - )); + 'entities' => [ + [ + 'fields' => [] + ] + ], + ] + ); } /** @@ -922,7 +991,7 @@ public function testNameIsMandatoryForDiscriminatorColumnsMappingException() { $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->setDiscriminatorColumn(array()); + $cm->setDiscriminatorColumn([]); } /** @@ -941,15 +1010,19 @@ public function testFullyQualifiedClassNameShouldBeGivenToNamingStrategy() $articleMetadata->initializeReflection(new RuntimeReflectionService()); $routingMetadata->initializeReflection(new RuntimeReflectionService()); - $addressMetadata->mapManyToMany(array( + $addressMetadata->mapManyToMany( + [ 'fieldName' => 'user', 'targetEntity' => 'CmsUser' - )); + ] + ); - $articleMetadata->mapManyToMany(array( + $articleMetadata->mapManyToMany( + [ 'fieldName' => 'author', 'targetEntity' => 'Doctrine\Tests\Models\CMS\CmsUser' - )); + ] + ); $this->assertEquals('routing_routingleg', $routingMetadata->table['name']); $this->assertEquals('cms_cmsaddress_cms_cmsuser', $addressMetadata->associationMappings['user']['joinTable']['name']); @@ -967,13 +1040,14 @@ public function testFullyQualifiedClassNameShouldBeGivenToNamingStrategyProperty $metadata->initializeReflection(new RuntimeReflectionService()); - $metadata->mapField(array('fieldName'=>'country')); - $metadata->mapField(array('fieldName'=>'city')); + $metadata->mapField(['fieldName'=>'country']); + $metadata->mapField(['fieldName'=>'city']); - $this->assertEquals($metadata->fieldNames, array( + $this->assertEquals($metadata->fieldNames, [ 'cmsaddress_country' => 'country', 'cmsaddress_city' => 'city' - )); + ] + ); } /** @@ -987,7 +1061,7 @@ public function testInvalidCascade() $this->expectException(MappingException::class); $this->expectExceptionMessage("You have specified invalid cascade options for Doctrine\Tests\Models\CMS\CmsUser::\$address: 'invalid'; available options: 'remove', 'persist', 'refresh', 'merge', and 'detach'"); - $cm->mapManyToOne(array('fieldName' => 'address', 'targetEntity' => 'UnknownClass', 'cascade' => array('invalid'))); + $cm->mapManyToOne(['fieldName' => 'address', 'targetEntity' => 'UnknownClass', 'cascade' => ['invalid']]); } /** @@ -999,9 +1073,9 @@ public function testInvalidPropertyAssociationOverrideNameException() { $cm = new ClassMetadata('Doctrine\Tests\Models\DDC964\DDC964Admin'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->mapManyToOne(array('fieldName' => 'address', 'targetEntity' => 'DDC964Address')); + $cm->mapManyToOne(['fieldName' => 'address', 'targetEntity' => 'DDC964Address']); - $cm->setAssociationOverride('invalidPropertyName', array()); + $cm->setAssociationOverride('invalidPropertyName', []); } /** @@ -1013,9 +1087,9 @@ public function testInvalidPropertyAttributeOverrideNameException() { $cm = new ClassMetadata('Doctrine\Tests\Models\DDC964\DDC964Guest'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->mapField(array('fieldName' => 'name')); + $cm->mapField(['fieldName' => 'name']); - $cm->setAttributeOverride('invalidPropertyName', array()); + $cm->setAttributeOverride('invalidPropertyName', []); } /** @@ -1027,9 +1101,9 @@ public function testInvalidOverrideAttributeFieldTypeException() { $cm = new ClassMetadata('Doctrine\Tests\Models\DDC964\DDC964Guest'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->mapField(array('fieldName' => 'name', 'type'=>'string')); + $cm->mapField(['fieldName' => 'name', 'type'=>'string']); - $cm->setAttributeOverride('name', array('type'=>'date')); + $cm->setAttributeOverride('name', ['type'=>'date']); } /** @@ -1065,23 +1139,23 @@ public function testManyToManySelfReferencingNamingStrategyDefaults() $cm = new ClassMetadata('Doctrine\Tests\Models\CustomType\CustomTypeParent'); $cm->initializeReflection(new RuntimeReflectionService()); $cm->mapManyToMany( - array( + [ 'fieldName' => 'friendsWithMe', 'targetEntity' => 'CustomTypeParent' - ) + ] ); $this->assertEquals( - array( + [ 'name' => 'customtypeparent_customtypeparent', - 'joinColumns' => array(array('name' => 'customtypeparent_source', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE')), - 'inverseJoinColumns' => array(array('name' => 'customtypeparent_target', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE')), - ), + 'joinColumns' => [['name' => 'customtypeparent_source', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE']], + 'inverseJoinColumns' => [['name' => 'customtypeparent_target', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE']], + ], $cm->associationMappings['friendsWithMe']['joinTable'] ); - $this->assertEquals(array('customtypeparent_source', 'customtypeparent_target'), $cm->associationMappings['friendsWithMe']['joinTableColumns']); - $this->assertEquals(array('customtypeparent_source' => 'id'), $cm->associationMappings['friendsWithMe']['relationToSourceKeyColumns']); - $this->assertEquals(array('customtypeparent_target' => 'id'), $cm->associationMappings['friendsWithMe']['relationToTargetKeyColumns']); + $this->assertEquals(['customtypeparent_source', 'customtypeparent_target'], $cm->associationMappings['friendsWithMe']['joinTableColumns']); + $this->assertEquals(['customtypeparent_source' => 'id'], $cm->associationMappings['friendsWithMe']['relationToSourceKeyColumns']); + $this->assertEquals(['customtypeparent_target' => 'id'], $cm->associationMappings['friendsWithMe']['relationToTargetKeyColumns']); } /** @@ -1093,7 +1167,7 @@ public function testSetSequenceGeneratorThrowsExceptionWhenSequenceNameIsMissing $cm->initializeReflection(new RuntimeReflectionService()); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); - $cm->setSequenceGeneratorDefinition(array()); + $cm->setSequenceGeneratorDefinition([]); } /** @@ -1104,9 +1178,9 @@ public function testQuotedSequenceName() $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->setSequenceGeneratorDefinition(array('sequenceName' => '`foo`')); + $cm->setSequenceGeneratorDefinition(['sequenceName' => '`foo`']); - $this->assertEquals(array('sequenceName' => 'foo', 'quoted' => true), $cm->sequenceGeneratorDefinition); + $this->assertEquals(['sequenceName' => 'foo', 'quoted' => true], $cm->sequenceGeneratorDefinition); } /** @@ -1146,24 +1220,26 @@ public function testWakeupReflectionWithEmbeddableAndStaticReflectionService() { $classMetadata = new ClassMetadata('Doctrine\Tests\ORM\Mapping\TestEntity1'); - $classMetadata->mapEmbedded(array( + $classMetadata->mapEmbedded( + [ 'fieldName' => 'test', 'class' => 'Doctrine\Tests\ORM\Mapping\TestEntity1', 'columnPrefix' => false, - )); + ] + ); - $field = array( + $field = [ 'fieldName' => 'test.embeddedProperty', 'type' => 'string', 'originalClass' => 'Doctrine\Tests\ORM\Mapping\TestEntity1', 'declaredField' => 'test', 'originalField' => 'embeddedProperty' - ); + ]; $classMetadata->mapField($field); $classMetadata->wakeupReflection(new StaticReflectionService()); - $this->assertEquals(array('test' => null, 'test.embeddedProperty' => null), $classMetadata->getReflectionProperties()); + $this->assertEquals(['test' => null, 'test.embeddedProperty' => null], $classMetadata->getReflectionProperties()); } public function testGetColumnNamesWithGivenFieldNames() @@ -1171,9 +1247,9 @@ public function testGetColumnNamesWithGivenFieldNames() $metadata = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $metadata->initializeReflection(new RuntimeReflectionService()); - $metadata->mapField(array('fieldName' => 'status', 'type' => 'string', 'columnName' => 'foo')); - $metadata->mapField(array('fieldName' => 'username', 'type' => 'string', 'columnName' => 'bar')); - $metadata->mapField(array('fieldName' => 'name', 'type' => 'string', 'columnName' => 'baz')); + $metadata->mapField(['fieldName' => 'status', 'type' => 'string', 'columnName' => 'foo']); + $metadata->mapField(['fieldName' => 'username', 'type' => 'string', 'columnName' => 'bar']); + $metadata->mapField(['fieldName' => 'name', 'type' => 'string', 'columnName' => 'baz']); self::assertSame(['foo', 'baz'], $metadata->getColumnNames(['status', 'name'])); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/NamingStrategyTest.php b/tests/Doctrine/Tests/ORM/Mapping/NamingStrategyTest.php index 6274a146800..220a26363ca 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/NamingStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/NamingStrategyTest.php @@ -44,32 +44,39 @@ static private function underscoreNamingUpper() */ static public function dataClassToTableName() { - return array( + return [ // DefaultNamingStrategy - array(self::defaultNaming(), 'SomeClassName', + [ + self::defaultNaming(), 'SomeClassName', 'SomeClassName' - ), - array(self::defaultNaming(), 'SomeClassName', + ], + [ + self::defaultNaming(), 'SomeClassName', '\SomeClassName' - ), - array(self::defaultNaming(), 'Name', + ], + [ + self::defaultNaming(), 'Name', '\Some\Class\Name' - ), + ], // UnderscoreNamingStrategy - array(self::underscoreNamingLower(), 'some_class_name', + [ + self::underscoreNamingLower(), 'some_class_name', '\Name\Space\SomeClassName' - ), - array(self::underscoreNamingLower(), 'name', + ], + [ + self::underscoreNamingLower(), 'name', '\Some\Class\Name' - ), - array(self::underscoreNamingUpper(), 'SOME_CLASS_NAME', + ], + [ + self::underscoreNamingUpper(), 'SOME_CLASS_NAME', '\Name\Space\SomeClassName' - ), - array(self::underscoreNamingUpper(), 'NAME', + ], + [ + self::underscoreNamingUpper(), 'NAME', '\Some\Class\Name' - ), - ); + ], + ]; } /** @@ -82,39 +89,46 @@ public function testClassToTableName(NamingStrategy $strategy, $expected, $class /** * Data Provider for NamingStrategy#propertyToColumnName - * + * * @return array */ static public function dataPropertyToColumnName() { - return array( + return [ // DefaultNamingStrategy - array(self::defaultNaming(), 'someProperty', + [ + self::defaultNaming(), 'someProperty', 'someProperty' - ), - array(self::defaultNaming(), 'SOME_PROPERTY', + ], + [ + self::defaultNaming(), 'SOME_PROPERTY', 'SOME_PROPERTY' - ), - array(self::defaultNaming(), 'some_property', + ], + [ + self::defaultNaming(), 'some_property', 'some_property' - ), + ], // UnderscoreNamingStrategy - array(self::underscoreNamingLower(), 'some_property', + [ + self::underscoreNamingLower(), 'some_property', 'someProperty' - ), - array(self::underscoreNamingUpper(), 'SOME_PROPERTY', + ], + [ + self::underscoreNamingUpper(), 'SOME_PROPERTY', 'someProperty' - ), - array(self::underscoreNamingUpper(), 'SOME_PROPERTY', + ], + [ + self::underscoreNamingUpper(), 'SOME_PROPERTY', 'some_property' - ), - array(self::underscoreNamingUpper(), 'SOME_PROPERTY', + ], + [ + self::underscoreNamingUpper(), 'SOME_PROPERTY', 'SOME_PROPERTY' - ), - ); + ], + ]; } - + /** * @dataProvider dataPropertyToColumnName * @@ -134,14 +148,14 @@ public function testPropertyToColumnName(NamingStrategy $strategy, $expected, $p */ static public function dataReferenceColumnName() { - return array( + return [ // DefaultNamingStrategy - array(self::defaultNaming(), 'id'), + [self::defaultNaming(), 'id'], // UnderscoreNamingStrategy - array(self::underscoreNamingLower(), 'id'), - array(self::underscoreNamingUpper(), 'ID'), - ); + [self::underscoreNamingLower(), 'id'], + [self::underscoreNamingUpper(), 'ID'], + ]; } /** @@ -162,18 +176,18 @@ public function testReferenceColumnName(NamingStrategy $strategy, $expected) */ static public function dataJoinColumnName() { - return array( + return [ // DefaultNamingStrategy - array(self::defaultNaming(), 'someColumn_id', 'someColumn', null), - array(self::defaultNaming(), 'some_column_id', 'some_column', null), + [self::defaultNaming(), 'someColumn_id', 'someColumn', null], + [self::defaultNaming(), 'some_column_id', 'some_column', null], // UnderscoreNamingStrategy - array(self::underscoreNamingLower(), 'some_column_id', 'someColumn', null), - array(self::underscoreNamingUpper(), 'SOME_COLUMN_ID', 'someColumn', null), + [self::underscoreNamingLower(), 'some_column_id', 'someColumn', null], + [self::underscoreNamingUpper(), 'SOME_COLUMN_ID', 'someColumn', null], // JoinColumnClassNamingStrategy - array(new JoinColumnClassNamingStrategy(), 'classname_someColumn_id', 'someColumn', 'Some\ClassName'), - array(new JoinColumnClassNamingStrategy(), 'classname_some_column_id', 'some_column', 'ClassName'), - ); + [new JoinColumnClassNamingStrategy(), 'classname_someColumn_id', 'someColumn', 'Some\ClassName'], + [new JoinColumnClassNamingStrategy(), 'classname_some_column_id', 'some_column', 'ClassName'], + ]; } /** @@ -195,39 +209,48 @@ public function testJoinColumnName(NamingStrategy $strategy, $expected, $propert */ static public function dataJoinTableName() { - return array( + return [ // DefaultNamingStrategy - array(self::defaultNaming(), 'someclassname_classname', + [ + self::defaultNaming(), 'someclassname_classname', 'SomeClassName', 'Some\ClassName', null, - ), - array(self::defaultNaming(), 'someclassname_classname', + ], + [ + self::defaultNaming(), 'someclassname_classname', '\SomeClassName', 'ClassName', null, - ), - array(self::defaultNaming(), 'name_classname', + ], + [ + self::defaultNaming(), 'name_classname', '\Some\Class\Name', 'ClassName', null, - ), + ], // UnderscoreNamingStrategy - array(self::underscoreNamingLower(), 'some_class_name_class_name', + [ + self::underscoreNamingLower(), 'some_class_name_class_name', 'SomeClassName', 'Some\ClassName', null, - ), - array(self::underscoreNamingLower(), 'some_class_name_class_name', + ], + [ + self::underscoreNamingLower(), 'some_class_name_class_name', '\SomeClassName', 'ClassName', null, - ), - array(self::underscoreNamingLower(), 'name_class_name', + ], + [ + self::underscoreNamingLower(), 'name_class_name', '\Some\Class\Name', 'ClassName', null, - ), + ], - array(self::underscoreNamingUpper(), 'SOME_CLASS_NAME_CLASS_NAME', + [ + self::underscoreNamingUpper(), 'SOME_CLASS_NAME_CLASS_NAME', 'SomeClassName', 'Some\ClassName', null, - ), - array(self::underscoreNamingUpper(), 'SOME_CLASS_NAME_CLASS_NAME', + ], + [ + self::underscoreNamingUpper(), 'SOME_CLASS_NAME_CLASS_NAME', '\SomeClassName', 'ClassName', null, - ), - array(self::underscoreNamingUpper(), 'NAME_CLASS_NAME', + ], + [ + self::underscoreNamingUpper(), 'NAME_CLASS_NAME', '\Some\Class\Name', 'ClassName', null, - ), - ); + ], + ]; } /** @@ -251,30 +274,36 @@ public function testJoinTableName(NamingStrategy $strategy, $expected, $ownerEnt */ static public function dataJoinKeyColumnName() { - return array( + return [ // DefaultNamingStrategy - array(self::defaultNaming(), 'someclassname_id', + [ + self::defaultNaming(), 'someclassname_id', 'SomeClassName', null, null, - ), - array(self::defaultNaming(), 'name_identifier', + ], + [ + self::defaultNaming(), 'name_identifier', '\Some\Class\Name', 'identifier', null, - ), + ], // UnderscoreNamingStrategy - array(self::underscoreNamingLower(), 'some_class_name_id', + [ + self::underscoreNamingLower(), 'some_class_name_id', 'SomeClassName', null, null, - ), - array(self::underscoreNamingLower(), 'class_name_identifier', + ], + [ + self::underscoreNamingLower(), 'class_name_identifier', '\Some\Class\ClassName', 'identifier', null, - ), + ], - array(self::underscoreNamingUpper(), 'SOME_CLASS_NAME_ID', + [ + self::underscoreNamingUpper(), 'SOME_CLASS_NAME_ID', 'SomeClassName', null, null, - ), - array(self::underscoreNamingUpper(), 'CLASS_NAME_IDENTIFIER', + ], + [ + self::underscoreNamingUpper(), 'CLASS_NAME_IDENTIFIER', '\Some\Class\ClassName', 'IDENTIFIER', null, - ), - ); + ], + ]; } /** diff --git a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php index 0b736dd0b59..0afb3698dcd 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php @@ -60,9 +60,9 @@ public function testConfiguration() public function testGetColumnName() { $cm = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); - $cm->mapField(array('fieldName' => 'name', 'columnName' => '`name`')); - $cm->mapField(array('fieldName' => 'id', 'columnName' => 'id')); - + $cm->mapField(['fieldName' => 'name', 'columnName' => '`name`']); + $cm->mapField(['fieldName' => 'id', 'columnName' => 'id']); + $this->assertEquals('id' ,$this->strategy->getColumnName('id', $cm, $this->platform)); $this->assertEquals('"name"' ,$this->strategy->getColumnName('name', $cm, $this->platform)); } @@ -70,42 +70,45 @@ public function testGetColumnName() public function testGetTableName() { $cm = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); - $cm->setPrimaryTable(array('name'=>'`cms_user`')); + $cm->setPrimaryTable(['name'=>'`cms_user`']); $this->assertEquals('"cms_user"' ,$this->strategy->getTableName($cm, $this->platform)); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->setPrimaryTable(array('name'=>'cms_user')); + $cm->setPrimaryTable(['name'=>'cms_user']); $this->assertEquals('cms_user' ,$this->strategy->getTableName($cm, $this->platform)); } - + public function testJoinTableName() { $cm1 = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); $cm2 = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); - - $cm1->mapManyToMany(array( + + $cm1->mapManyToMany( + [ 'fieldName' => 'user', 'targetEntity' => 'CmsUser', 'inversedBy' => 'users', - 'joinTable' => array( + 'joinTable' => [ 'name' => '`cmsaddress_cmsuser`' - ) - )); - - $cm2->mapManyToMany(array( + ] + ] + ); + + $cm2->mapManyToMany( + [ 'fieldName' => 'user', 'targetEntity' => 'CmsUser', 'inversedBy' => 'users', - 'joinTable' => array( + 'joinTable' => [ 'name' => 'cmsaddress_cmsuser' - ) - ) + ] + ] ); $this->assertEquals('"cmsaddress_cmsuser"', $this->strategy->getJoinTableName($cm1->associationMappings['user'], $cm1, $this->platform)); $this->assertEquals('cmsaddress_cmsuser', $this->strategy->getJoinTableName($cm2->associationMappings['user'], $cm2, $this->platform)); - + } public function testIdentifierColumnNames() @@ -113,20 +116,24 @@ public function testIdentifierColumnNames() $cm1 = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); $cm2 = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); - $cm1->mapField(array( + $cm1->mapField( + [ 'id' => true, 'fieldName' => 'id', 'columnName' => '`id`', - )); + ] + ); - $cm2->mapField(array( + $cm2->mapField( + [ 'id' => true, 'fieldName' => 'id', 'columnName' => 'id', - )); + ] + ); - $this->assertEquals(array('"id"'), $this->strategy->getIdentifierColumnNames($cm1, $this->platform)); - $this->assertEquals(array('id'), $this->strategy->getIdentifierColumnNames($cm2, $this->platform)); + $this->assertEquals(['"id"'], $this->strategy->getIdentifierColumnNames($cm1, $this->platform)); + $this->assertEquals(['id'], $this->strategy->getIdentifierColumnNames($cm2, $this->platform)); } @@ -143,30 +150,38 @@ public function testQuoteIdentifierJoinColumns() { $cm = $this->createClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); - $cm->mapOneToOne(array( + $cm->mapOneToOne( + [ 'id' => true, 'fieldName' => 'article', 'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', - 'joinColumns' => array(array( + 'joinColumns' => [ + [ 'name' => '`article`' - )), - )); + ] + ], + ] + ); - $this->assertEquals(array('"article"'), $this->strategy->getIdentifierColumnNames($cm, $this->platform)); + $this->assertEquals(['"article"'], $this->strategy->getIdentifierColumnNames($cm, $this->platform)); } public function testJoinColumnName() { $cm = $this->createClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); - $cm->mapOneToOne(array( + $cm->mapOneToOne( + [ 'id' => true, 'fieldName' => 'article', 'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', - 'joinColumns' => array(array( + 'joinColumns' => [ + [ 'name' => '`article`' - )), - )); + ] + ], + ] + ); $joinColumn = $cm->associationMappings['article']['joinColumns'][0]; $this->assertEquals('"article"',$this->strategy->getJoinColumnName($joinColumn, $cm, $this->platform)); @@ -176,14 +191,18 @@ public function testReferencedJoinColumnName() { $cm = $this->createClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); - $cm->mapOneToOne(array( + $cm->mapOneToOne( + [ 'id' => true, 'fieldName' => 'article', 'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', - 'joinColumns' => array(array( + 'joinColumns' => [ + [ 'name' => '`article`' - )), - )); + ] + ], + ] + ); $joinColumn = $cm->associationMappings['article']['joinColumns'][0]; $this->assertEquals('"id"',$this->strategy->getReferencedJoinColumnName($joinColumn, $cm, $this->platform)); diff --git a/tests/Doctrine/Tests/ORM/Mapping/ReflectionEmbeddedPropertyTest.php b/tests/Doctrine/Tests/ORM/Mapping/ReflectionEmbeddedPropertyTest.php index 9be006e5a27..d6f6291499b 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ReflectionEmbeddedPropertyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ReflectionEmbeddedPropertyTest.php @@ -69,8 +69,8 @@ public function testWillSkipReadingPropertiesFromNullEmbeddable( */ public function getTestedReflectionProperties() { - return array( - array( + return [ + [ $this->getReflectionProperty( 'Doctrine\\Tests\\Models\\Generic\\BooleanModel', 'id' @@ -80,9 +80,9 @@ public function getTestedReflectionProperties() 'id' ), 'Doctrine\\Tests\\Models\\Generic\\BooleanModel' - ), + ], // reflection on embeddables that have properties defined in abstract ancestors: - array( + [ $this->getReflectionProperty( 'Doctrine\\Tests\\Models\\Generic\\BooleanModel', 'id' @@ -92,8 +92,8 @@ public function getTestedReflectionProperties() 'propertyInAbstractClass' ), 'Doctrine\\Tests\\Models\\Reflection\\ConcreteEmbeddable' - ), - array( + ], + [ $this->getReflectionProperty( 'Doctrine\\Tests\\Models\\Generic\\BooleanModel', 'id' @@ -103,9 +103,9 @@ public function getTestedReflectionProperties() 'propertyInConcreteClass' ), 'Doctrine\\Tests\\Models\\Reflection\\ConcreteEmbeddable' - ), + ], // reflection on classes extending internal PHP classes: - array( + [ $this->getReflectionProperty( 'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass', 'publicProperty' @@ -115,8 +115,8 @@ public function getTestedReflectionProperties() 'privateProperty' ), 'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass' - ), - array( + ], + [ $this->getReflectionProperty( 'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass', 'publicProperty' @@ -126,8 +126,8 @@ public function getTestedReflectionProperties() 'protectedProperty' ), 'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass' - ), - array( + ], + [ $this->getReflectionProperty( 'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass', 'publicProperty' @@ -137,8 +137,8 @@ public function getTestedReflectionProperties() 'publicProperty' ), 'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass' - ), - ); + ], + ]; } /** diff --git a/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php index ac8f1d695c2..082ebaf94be 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php @@ -10,10 +10,12 @@ abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase { public function testFindMappingFile() { - $driver = $this->getDriver(array( + $driver = $this->getDriver( + [ 'MyNamespace\MySubnamespace\EntityFoo' => 'foo', 'MyNamespace\MySubnamespace\Entity' => $this->dir, - )); + ] + ); touch($filename = $this->dir.'/Foo'.$this->getFileExtension()); $this->assertEquals($filename, $driver->getLocator()->findMappingFile('MyNamespace\MySubnamespace\Entity\Foo')); @@ -21,9 +23,11 @@ public function testFindMappingFile() public function testFindMappingFileInSubnamespace() { - $driver = $this->getDriver(array( + $driver = $this->getDriver( + [ 'MyNamespace\MySubnamespace\Entity' => $this->dir, - )); + ] + ); touch($filename = $this->dir.'/Foo.Bar'.$this->getFileExtension()); $this->assertEquals($filename, $driver->getLocator()->findMappingFile('MyNamespace\MySubnamespace\Entity\Foo\Bar')); @@ -34,9 +38,11 @@ public function testFindMappingFileNamespacedFoundFileNotFound() $this->expectException(MappingException::class); $this->expectExceptionMessage('No mapping file found named'); - $driver = $this->getDriver(array( + $driver = $this->getDriver( + [ 'MyNamespace\MySubnamespace\Entity' => $this->dir, - )); + ] + ); $driver->getLocator()->findMappingFile('MyNamespace\MySubnamespace\Entity\Foo'); } @@ -46,9 +52,11 @@ public function testFindMappingNamespaceNotFound() $this->expectException(MappingException::class); $this->expectExceptionMessage("No mapping file found named 'Foo" . $this->getFileExtension() . "' for class 'MyOtherNamespace\MySubnamespace\Entity\Foo'."); - $driver = $this->getDriver(array( + $driver = $this->getDriver( + [ 'MyNamespace\MySubnamespace\Entity' => $this->dir, - )); + ] + ); $driver->getLocator()->findMappingFile('MyOtherNamespace\MySubnamespace\Entity\Foo'); } @@ -75,5 +83,5 @@ protected function tearDown() } abstract protected function getFileExtension(); - abstract protected function getDriver(array $paths = array()); + abstract protected function getDriver(array $paths = []); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/Symfony/XmlDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/Symfony/XmlDriverTest.php index f32d9f2ad07..2fa83681316 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/Symfony/XmlDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/Symfony/XmlDriverTest.php @@ -14,7 +14,7 @@ protected function getFileExtension() return '.orm.xml'; } - protected function getDriver(array $paths = array()) + protected function getDriver(array $paths = []) { $driver = new SimplifiedXmlDriver(array_flip($paths)); diff --git a/tests/Doctrine/Tests/ORM/Mapping/Symfony/YamlDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/Symfony/YamlDriverTest.php index 5b7f38eadf0..f9c8a839b04 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/Symfony/YamlDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/Symfony/YamlDriverTest.php @@ -14,7 +14,7 @@ protected function getFileExtension() return '.orm.yml'; } - protected function getDriver(array $paths = array()) + protected function getDriver(array $paths = []) { $driver = new SimplifiedYamlDriver(array_flip($paths)); diff --git a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php index ae188057d26..6d5dde33106 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php @@ -23,11 +23,11 @@ public function testClassTableInheritanceDiscriminatorMap() $class->initializeReflection(new RuntimeReflectionService()); $mappingDriver->loadMetadataForClass($className, $class); - $expectedMap = array( + $expectedMap = [ 'foo' => 'Doctrine\Tests\ORM\Mapping\CTIFoo', 'bar' => 'Doctrine\Tests\ORM\Mapping\CTIBar', 'baz' => 'Doctrine\Tests\ORM\Mapping\CTIBaz', - ); + ]; $this->assertEquals(3, count($class->discriminatorMap)); $this->assertEquals($expectedMap, $class->discriminatorMap); @@ -57,7 +57,7 @@ public function testIdentifierWithAssociationKey() $class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC117\DDC117Translation'); - $this->assertEquals(array('language', 'article'), $class->identifier); + $this->assertEquals(['language', 'article'], $class->identifier); $this->assertArrayHasKey('article', $class->associationMappings); $this->assertArrayHasKey('id', $class->associationMappings['article']); @@ -117,14 +117,14 @@ public function testEmbeddedMapping() $class = $this->createClassMetadata('Doctrine\Tests\Models\ValueObjects\Person'); $this->assertEquals( - array( - 'name' => array( + [ + 'name' => [ 'class' => 'Doctrine\Tests\Models\ValueObjects\Name', 'columnPrefix' => 'nm_', 'declaredField' => null, 'originalField' => null, - ) - ), + ] + ], $class->embeddedClasses ); } @@ -158,16 +158,16 @@ public function testValidateXmlSchema($xmlMappingFile) static public function dataValidSchema() { $list = glob(__DIR__ . '/xml/*.xml'); - $invalid = array( + $invalid = [ 'Doctrine.Tests.Models.DDC889.DDC889Class.dcm' - ); + ]; $list = array_filter($list, function($item) use ($invalid){ return ! in_array(pathinfo($item, PATHINFO_FILENAME), $invalid); }); return array_map(function($item){ - return array($item); + return [$item]; }, $list); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php index c752c6a82ee..a739c2b61b3 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php @@ -25,7 +25,7 @@ protected function _loadDriver() public function testJoinTablesWithMappedSuperclassForYamlDriver() { $yamlDriver = $this->_loadDriver(); - $yamlDriver->getLocator()->addPaths(array(__DIR__ . DIRECTORY_SEPARATOR . 'yaml')); + $yamlDriver->getLocator()->addPaths([__DIR__ . DIRECTORY_SEPARATOR . 'yaml']); $em = $this->_getTestEntityManager(); $em->getConfiguration()->setMetadataDriverImpl($yamlDriver); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsAddress.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsAddress.php index b0ac6cadeb2..2dce0c41628 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsAddress.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsAddress.php @@ -1,91 +1,115 @@ setPrimaryTable(array( +$metadata->setPrimaryTable( + [ 'name' => 'company_person', -)); + ] +); -$metadata->mapField(array ( +$metadata->mapField( + [ 'id' => true, 'fieldName' => 'id', 'type' => 'integer', -)); + ] +); -$metadata->mapField(array ( +$metadata->mapField( + [ 'fieldName' => 'zip', 'length' => 50, -)); + ] +); -$metadata->mapField(array ( +$metadata->mapField( + [ 'fieldName' => 'city', 'length' => 50, -)); + ] +); -$metadata->mapOneToOne(array( +$metadata->mapOneToOne( + [ 'fieldName' => 'user', 'targetEntity' => 'CmsUser', - 'joinColumns' => array(array('referencedColumnName' => 'id')) -)); + 'joinColumns' => [['referencedColumnName' => 'id']] + ] +); -$metadata->addNamedNativeQuery(array ( +$metadata->addNamedNativeQuery( + [ 'name' => 'find-all', 'query' => 'SELECT id, country, city FROM cms_addresses', 'resultSetMapping' => 'mapping-find-all', -)); + ] +); -$metadata->addNamedNativeQuery(array ( +$metadata->addNamedNativeQuery( + [ 'name' => 'find-by-id', 'query' => 'SELECT * FROM cms_addresses WHERE id = ?', 'resultClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsAddress', -)); + ] +); -$metadata->addNamedNativeQuery(array ( +$metadata->addNamedNativeQuery( + [ 'name' => 'count', 'query' => 'SELECT COUNT(*) AS count FROM cms_addresses', 'resultSetMapping' => 'mapping-count', -)); + ] +); -$metadata->addSqlResultSetMapping(array ( +$metadata->addSqlResultSetMapping( + [ 'name' => 'mapping-find-all', - 'columns' => array(), - 'entities' => array ( array ( - 'fields' => array ( - array ( + 'columns' => [], + 'entities' => [ + [ + 'fields' => [ + [ 'name' => 'id', 'column' => 'id', - ), - array ( + ], + [ 'name' => 'city', 'column' => 'city', - ), - array ( + ], + [ 'name' => 'country', 'column' => 'country', - ), - ), + ], + ], 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsAddress', - ), - ), -)); + ], + ], + ] +); -$metadata->addSqlResultSetMapping(array ( +$metadata->addSqlResultSetMapping( + [ 'name' => 'mapping-without-fields', - 'columns' => array(), - 'entities' => array(array ( + 'columns' => [], + 'entities' => [ + [ 'entityClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsAddress', - 'fields' => array() - ) - ) -)); - -$metadata->addSqlResultSetMapping(array ( + 'fields' => [] + ] + ] + ] +); + +$metadata->addSqlResultSetMapping( + [ 'name' => 'mapping-count', - 'columns' =>array ( - array ( + 'columns' => [ + [ 'name' => 'count', - ), - ) -)); + ], + ] + ] +); $metadata->addEntityListener(\Doctrine\ORM\Events::postPersist, 'CmsAddressListener', 'postPersist'); $metadata->addEntityListener(\Doctrine\ORM\Events::prePersist, 'CmsAddressListener', 'prePersist'); @@ -97,4 +121,4 @@ $metadata->addEntityListener(\Doctrine\ORM\Events::preRemove, 'CmsAddressListener', 'preRemove'); $metadata->addEntityListener(\Doctrine\ORM\Events::preFlush, 'CmsAddressListener', 'preFlush'); -$metadata->addEntityListener(\Doctrine\ORM\Events::postLoad, 'CmsAddressListener', 'postLoad'); \ No newline at end of file +$metadata->addEntityListener(\Doctrine\ORM\Events::postLoad, 'CmsAddressListener', 'postLoad'); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsUser.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsUser.php index dfa89851a04..c707f3fdfaf 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsUser.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsUser.php @@ -1,184 +1,210 @@ setPrimaryTable(array( +$metadata->setPrimaryTable( + [ 'name' => 'cms_users', -)); + ] +); -$metadata->addNamedNativeQuery(array ( +$metadata->addNamedNativeQuery( + [ 'name' => 'fetchIdAndUsernameWithResultClass', 'query' => 'SELECT id, username FROM cms_users WHERE username = ?', 'resultClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', -)); + ] +); -$metadata->addNamedNativeQuery(array ( +$metadata->addNamedNativeQuery( + [ 'name' => 'fetchAllColumns', 'query' => 'SELECT * FROM cms_users WHERE username = ?', 'resultClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', -)); + ] +); -$metadata->addNamedNativeQuery(array ( +$metadata->addNamedNativeQuery( + [ 'name' => 'fetchJoinedAddress', 'query' => 'SELECT u.id, u.name, u.status, a.id AS a_id, a.country, a.zip, a.city FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id WHERE u.username = ?', 'resultSetMapping' => 'mappingJoinedAddress', -)); + ] +); -$metadata->addNamedNativeQuery(array ( +$metadata->addNamedNativeQuery( + [ 'name' => 'fetchJoinedPhonenumber', 'query' => 'SELECT id, name, status, phonenumber AS number FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username = ?', 'resultSetMapping' => 'mappingJoinedPhonenumber', -)); + ] +); -$metadata->addNamedNativeQuery(array ( +$metadata->addNamedNativeQuery( + [ 'name' => 'fetchUserPhonenumberCount', 'query' => 'SELECT id, name, status, COUNT(phonenumber) AS numphones FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username IN (?) GROUP BY id, name, status, username ORDER BY username', 'resultSetMapping' => 'mappingUserPhonenumberCount', -)); + ] +); -$metadata->addNamedNativeQuery(array ( +$metadata->addNamedNativeQuery( + [ "name" => "fetchMultipleJoinsEntityResults", "resultSetMapping" => "mappingMultipleJoinsEntityResults", "query" => "SELECT u.id AS u_id, u.name AS u_name, u.status AS u_status, a.id AS a_id, a.zip AS a_zip, a.country AS a_country, COUNT(p.phonenumber) AS numphones FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id INNER JOIN cms_phonenumbers p ON u.id = p.user_id GROUP BY u.id, u.name, u.status, u.username, a.id, a.zip, a.country ORDER BY u.username" -)); + ] +); -$metadata->addSqlResultSetMapping(array ( +$metadata->addSqlResultSetMapping( + [ 'name' => 'mappingJoinedAddress', - 'columns' => array(), - 'entities' => array(array ( - 'fields'=> array ( - array ( + 'columns' => [], + 'entities' => [ + [ + 'fields'=> [ + [ 'name' => 'id', 'column' => 'id', - ), - array ( + ], + [ 'name' => 'name', 'column' => 'name', - ), - array ( + ], + [ 'name' => 'status', 'column' => 'status', - ), - array ( + ], + [ 'name' => 'address.zip', 'column' => 'zip', - ), - array ( + ], + [ 'name' => 'address.city', 'column' => 'city', - ), - array ( + ], + [ 'name' => 'address.country', 'column' => 'country', - ), - array ( + ], + [ 'name' => 'address.id', 'column' => 'a_id', - ), - ), + ], + ], 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', 'discriminatorColumn' => null - ), - ), -)); + ], + ], + ] +); -$metadata->addSqlResultSetMapping(array ( +$metadata->addSqlResultSetMapping( + [ 'name' => 'mappingJoinedPhonenumber', - 'columns' => array(), - 'entities' => array(array( - 'fields'=> array ( - array ( + 'columns' => [], + 'entities' => [ + [ + 'fields'=> [ + [ 'name' => 'id', 'column' => 'id', - ), - array ( + ], + [ 'name' => 'name', 'column' => 'name', - ), - array ( + ], + [ 'name' => 'status', 'column' => 'status', - ), - array ( + ], + [ 'name' => 'phonenumbers.phonenumber', 'column' => 'number', - ), - ), + ], + ], 'entityClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', 'discriminatorColumn' => null - ), - ), -)); + ], + ], + ] +); -$metadata->addSqlResultSetMapping(array ( +$metadata->addSqlResultSetMapping( + [ 'name' => 'mappingUserPhonenumberCount', - 'columns' => array(), - 'entities' => array ( - array( - 'fields' => array ( - array ( + 'columns' => [], + 'entities' => [ + [ + 'fields' => [ + [ 'name' => 'id', 'column' => 'id', - ), - array ( + ], + [ 'name' => 'name', 'column' => 'name', - ), - array ( + ], + [ 'name' => 'status', 'column' => 'status', - ) - ), + ] + ], 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', 'discriminatorColumn' => null - ) - ), - 'columns' => array ( - array ( + ] + ], + 'columns' => [ + [ 'name' => 'numphones', - ) - ) -)); + ] + ] + ] +); -$metadata->addSqlResultSetMapping(array( +$metadata->addSqlResultSetMapping( + [ 'name' => 'mappingMultipleJoinsEntityResults', - 'entities' => array(array( - 'fields' => array( - array( + 'entities' => [ + [ + 'fields' => [ + [ 'name' => 'id', 'column' => 'u_id', - ), - array( + ], + [ 'name' => 'name', 'column' => 'u_name', - ), - array( + ], + [ 'name' => 'status', 'column' => 'u_status', - ) - ), + ] + ], 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', 'discriminatorColumn' => null, - ), - array( - 'fields' => array( - array( + ], + [ + 'fields' => [ + [ 'name' => 'id', 'column' => 'a_id', - ), - array( + ], + [ 'name' => 'zip', 'column' => 'a_zip', - ), - array( + ], + [ 'name' => 'country', 'column' => 'a_country', - ), - ), + ], + ], 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsAddress', 'discriminatorColumn' => null, - ), - ), - 'columns' => array(array( + ], + ], + 'columns' => [ + [ 'name' => 'numphones', - ) - ) -)); \ No newline at end of file + ] + ] + ] +); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Cache.City.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Cache.City.php index 6dd477fa628..4626cd46b06 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Cache.City.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Cache.City.php @@ -3,52 +3,68 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE); -$metadata->setPrimaryTable(array('name' => 'cache_city')); +$metadata->setPrimaryTable(['name' => 'cache_city']); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_IDENTITY); $metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT); -$metadata->enableCache(array( +$metadata->enableCache( + [ 'usage' => ClassMetadataInfo::CACHE_USAGE_READ_ONLY -)); + ] +); -$metadata->mapField(array( +$metadata->mapField( + [ 'fieldName' => 'id', 'type' => 'integer', 'id' => true, - )); + ] +); -$metadata->mapField(array( +$metadata->mapField( + [ 'fieldName' => 'name', 'type' => 'string', -)); + ] +); -$metadata->mapOneToOne(array( +$metadata->mapOneToOne( + [ 'fieldName' => 'state', 'targetEntity' => 'Doctrine\\Tests\\Models\\Cache\\State', 'inversedBy' => 'cities', 'joinColumns' => - array(array( + [ + [ 'name' => 'state_id', 'referencedColumnName' => 'id', - )) -)); -$metadata->enableAssociationCache('state', array( + ] + ] + ] +); +$metadata->enableAssociationCache('state', [ 'usage' => ClassMetadataInfo::CACHE_USAGE_READ_ONLY -)); +] +); -$metadata->mapManyToMany(array( +$metadata->mapManyToMany( + [ 'fieldName' => 'travels', 'targetEntity' => 'Doctrine\\Tests\\Models\\Cache\\Travel', 'mappedBy' => 'visitedCities', -)); + ] +); -$metadata->mapOneToMany(array( +$metadata->mapOneToMany( + [ 'fieldName' => 'attractions', 'targetEntity' => 'Doctrine\\Tests\\Models\\Cache\\Attraction', 'mappedBy' => 'city', - 'orderBy' => array('name' => 'ASC',), -)); -$metadata->enableAssociationCache('attractions', array( + 'orderBy' => ['name' => 'ASC',], + ] +); +$metadata->enableAssociationCache('attractions', [ 'usage' => ClassMetadataInfo::CACHE_USAGE_READ_ONLY -)); \ No newline at end of file +] +); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyContract.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyContract.php index d307ba7f10b..33389ce9530 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyContract.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyContract.php @@ -4,28 +4,36 @@ $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_JOINED); $metadata->setTableName( 'company_contracts'); -$metadata->setDiscriminatorColumn(array( +$metadata->setDiscriminatorColumn( + [ 'name' => 'discr', 'type' => 'string', -)); + ] +); -$metadata->mapField(array( +$metadata->mapField( + [ 'id' => true, 'name' => 'id', 'fieldName' => 'id', -)); + ] +); -$metadata->mapField(array( +$metadata->mapField( + [ 'type' => 'boolean', 'name' => 'completed', 'fieldName' => 'completed', -)); + ] +); -$metadata->setDiscriminatorMap(array( +$metadata->setDiscriminatorMap( + [ "fix" => "CompanyFixContract", "flexible" => "CompanyFlexContract", "flexultra" => "CompanyFlexUltraContract" -)); + ] +); $metadata->addEntityListener(\Doctrine\ORM\Events::postPersist, 'CompanyContractListener', 'postPersistHandler'); $metadata->addEntityListener(\Doctrine\ORM\Events::prePersist, 'CompanyContractListener', 'prePersistHandler'); @@ -37,4 +45,4 @@ $metadata->addEntityListener(\Doctrine\ORM\Events::preRemove, 'CompanyContractListener', 'preRemoveHandler'); $metadata->addEntityListener(\Doctrine\ORM\Events::preFlush, 'CompanyContractListener', 'preFlushHandler'); -$metadata->addEntityListener(\Doctrine\ORM\Events::postLoad, 'CompanyContractListener', 'postLoadHandler'); \ No newline at end of file +$metadata->addEntityListener(\Doctrine\ORM\Events::postLoad, 'CompanyContractListener', 'postLoadHandler'); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyFixContract.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyFixContract.php index 79b117729ed..3ea44ee7399 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyFixContract.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyFixContract.php @@ -1,7 +1,9 @@ mapField(array( +$metadata->mapField( + [ 'type' => 'integer', 'name' => 'fixPrice', 'fieldName' => 'fixPrice', -)); \ No newline at end of file + ] +); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyFlexContract.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyFlexContract.php index 5f1542dde41..7cc2b5504c9 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyFlexContract.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyFlexContract.php @@ -1,13 +1,17 @@ mapField(array( +$metadata->mapField( + [ 'type' => 'integer', 'name' => 'hoursWorked', 'fieldName' => 'hoursWorked', -)); + ] +); -$metadata->mapField(array( +$metadata->mapField( + [ 'type' => 'integer', 'name' => 'pricePerHour', 'fieldName' => 'pricePerHour', -)); + ] +); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyFlexUltraContract.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyFlexUltraContract.php index d16d4f3f547..9e392416ded 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyFlexUltraContract.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyFlexUltraContract.php @@ -1,10 +1,12 @@ mapField(array( +$metadata->mapField( + [ 'type' => 'integer', 'name' => 'maxPrice', 'fieldName' => 'maxPrice', -)); + ] +); $metadata->addEntityListener(\Doctrine\ORM\Events::postPersist, 'CompanyContractListener', 'postPersistHandler'); $metadata->addEntityListener(\Doctrine\ORM\Events::prePersist, 'CompanyContractListener', 'prePersistHandler'); @@ -18,4 +20,4 @@ $metadata->addEntityListener(\Doctrine\ORM\Events::postLoad, 'CompanyContractListener', 'postLoadHandler'); $metadata->addEntityListener(\Doctrine\ORM\Events::prePersist, 'CompanyFlexUltraContractListener', 'prePersistHandler1'); -$metadata->addEntityListener(\Doctrine\ORM\Events::prePersist, 'CompanyFlexUltraContractListener', 'prePersistHandler2'); \ No newline at end of file +$metadata->addEntityListener(\Doctrine\ORM\Events::prePersist, 'CompanyFlexUltraContractListener', 'prePersistHandler2'); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyPerson.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyPerson.php index 32cc813da2e..9402cc1edfd 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyPerson.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyPerson.php @@ -1,37 +1,46 @@ setPrimaryTable(array( +$metadata->setPrimaryTable( + [ 'name' => 'company_person', -)); + ] +); -$metadata->addNamedNativeQuery(array ( +$metadata->addNamedNativeQuery( + [ 'name' => 'fetchAllWithResultClass', 'query' => 'SELECT id, name, discr FROM company_persons ORDER BY name', 'resultClass' => 'Doctrine\\Tests\\Models\\Company\\CompanyPerson', -)); + ] +); -$metadata->addNamedNativeQuery(array ( +$metadata->addNamedNativeQuery( + [ 'name' => 'fetchAllWithSqlResultSetMapping', 'query' => 'SELECT id, name, discr AS discriminator FROM company_persons ORDER BY name', 'resultSetMapping' => 'mappingFetchAll', -)); + ] +); -$metadata->addSqlResultSetMapping(array ( +$metadata->addSqlResultSetMapping( + [ 'name' => 'mappingFetchAll', - 'columns' => array(), - 'entities' => array ( array ( - 'fields' => array ( - array ( + 'columns' => [], + 'entities' => [ + [ + 'fields' => [ + [ 'name' => 'id', 'column' => 'id', - ), - array ( + ], + [ 'name' => 'name', 'column' => 'name', - ), - ), + ], + ], 'entityClass' => 'Doctrine\Tests\Models\Company\CompanyPerson', 'discriminatorColumn' => 'discriminator', - ), - ), -)); \ No newline at end of file + ], + ], + ] +); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC1476.DDC1476EntityWithDefaultFieldType.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC1476.DDC1476EntityWithDefaultFieldType.php index 56a99633a86..62459aad000 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC1476.DDC1476EntityWithDefaultFieldType.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC1476.DDC1476EntityWithDefaultFieldType.php @@ -2,11 +2,15 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; -$metadata->mapField(array( +$metadata->mapField( + [ 'id' => true, 'fieldName' => 'id', -)); -$metadata->mapField(array( + ] +); +$metadata->mapField( + [ 'fieldName' => 'name' -)); -$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE); \ No newline at end of file + ] +); +$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC2825.ExplicitSchemaAndTable.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC2825.ExplicitSchemaAndTable.php index 4a163c9bd01..85128c9ae4a 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC2825.ExplicitSchemaAndTable.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC2825.ExplicitSchemaAndTable.php @@ -4,14 +4,18 @@ /* @var $metadata ClassMetadata */ -$metadata->setPrimaryTable(array( +$metadata->setPrimaryTable( + [ 'name' => 'explicit_table', 'schema' => 'explicit_schema', -)); + ] +); -$metadata->mapField(array( +$metadata->mapField( + [ 'id' => true, 'fieldName' => 'id', -)); + ] +); $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC2825.SchemaAndTableInTableName.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC2825.SchemaAndTableInTableName.php index 045a9785817..fb2edfcfb26 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC2825.SchemaAndTableInTableName.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC2825.SchemaAndTableInTableName.php @@ -4,13 +4,17 @@ /* @var $metadata ClassMetadata */ -$metadata->setPrimaryTable(array( +$metadata->setPrimaryTable( + [ 'name' => 'implicit_schema.implicit_table', -)); + ] +); -$metadata->mapField(array( +$metadata->mapField( + [ 'id' => true, 'fieldName' => 'id', -)); + ] +); $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC3579.DDC3579Admin.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC3579.DDC3579Admin.php index dd59e65faff..9b7c87b3e9b 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC3579.DDC3579Admin.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC3579.DDC3579Admin.php @@ -1,5 +1,6 @@ setAssociationOverride('groups', array( +$metadata->setAssociationOverride('groups', [ 'inversedBy' => 'admins' -)); +] +); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC3579.DDC3579User.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC3579.DDC3579User.php index 1eb3555ecc3..49aeacb1eee 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC3579.DDC3579User.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC3579.DDC3579User.php @@ -2,26 +2,32 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; -$metadata->mapField(array( +$metadata->mapField( + [ 'id' => true, 'fieldName' => 'id', 'type' => 'integer', 'columnName' => 'user_id', 'length' => 150, -)); + ] +); -$metadata->mapField(array( +$metadata->mapField( + [ 'fieldName' => 'name', 'type' => 'string', 'columnName'=> 'user_name', 'nullable' => true, 'unique' => false, 'length' => 250, -)); + ] +); -$metadata->mapManyToMany(array( +$metadata->mapManyToMany( + [ 'fieldName' => 'groups', 'targetEntity' => 'DDC3579Group' -)); + ] +); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.php index ad8b86d9e55..e97e16f9596 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.php @@ -1,5 +1,7 @@ mapField(array( +$metadata->mapField( + [ 'fieldName' => 'serialNumber', 'type' => 'string', -)); \ No newline at end of file + ] +); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.php index 1318333a8f7..de9d8dae0ee 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.php @@ -1,5 +1,7 @@ mapField(array( +$metadata->mapField( + [ 'fieldName' => 'creditCardNumber', 'type' => 'string', -)); \ No newline at end of file + ] +); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869Payment.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869Payment.php index 1d1f551ba35..3a9b84793f5 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869Payment.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869Payment.php @@ -2,16 +2,20 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; -$metadata->mapField(array( +$metadata->mapField( + [ 'id' => true, 'fieldName' => 'id', 'type' => 'integer', 'columnName' => 'id', -)); -$metadata->mapField(array( + ] +); +$metadata->mapField( + [ 'fieldName' => 'value', 'type' => 'float', - )); + ] +); $metadata->isMappedSuperclass = true; $metadata->setCustomRepositoryClass("Doctrine\Tests\Models\DDC869\DDC869PaymentRepository"); -$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); \ No newline at end of file +$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC889.DDC889Class.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC889.DDC889Class.php index 90cfdc10bfd..e1161da1360 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC889.DDC889Class.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC889.DDC889Class.php @@ -2,11 +2,13 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; -$metadata->mapField(array( +$metadata->mapField( + [ 'id' => true, 'fieldName' => 'id', 'type' => 'integer', 'columnName' => 'id', -)); + ] +); -//$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); \ No newline at end of file +//$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC889.DDC889SuperClass.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC889.DDC889SuperClass.php index e56cc9bfdea..c3ee069df57 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC889.DDC889SuperClass.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC889.DDC889SuperClass.php @@ -2,10 +2,12 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; -$metadata->mapField(array( +$metadata->mapField( + [ 'fieldName' => 'name', 'type' => 'string', - )); + ] +); $metadata->isMappedSuperclass = true; $metadata->setCustomRepositoryClass("Doctrine\Tests\Models\DDC889\DDC889SuperClass"); -$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); \ No newline at end of file +$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC964.DDC964Admin.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC964.DDC964Admin.php index bb8920e7676..10175feca96 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC964.DDC964Admin.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC964.DDC964Admin.php @@ -1,21 +1,29 @@ setAssociationOverride('address',array( - 'joinColumns'=>array(array( +$metadata->setAssociationOverride('address', + [ + 'joinColumns'=> [ + [ 'name' => 'adminaddress_id', 'referencedColumnName' => 'id', - )) -)); + ] + ] + ] +); -$metadata->setAssociationOverride('groups',array( - 'joinTable' => array ( +$metadata->setAssociationOverride('groups', + [ + 'joinTable' => [ 'name' => 'ddc964_users_admingroups', - 'joinColumns' => array(array( + 'joinColumns' => [ + [ 'name' => 'adminuser_id', - )), + ] + ], - 'inverseJoinColumns' =>array (array ( + 'inverseJoinColumns' => [[ 'name' => 'admingroup_id', - )) - ) -)); \ No newline at end of file + ]] + ] + ] +); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC964.DDC964Guest.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC964.DDC964Guest.php index 5094ecddf43..28f6f48c592 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC964.DDC964Guest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC964.DDC964Guest.php @@ -1,13 +1,16 @@ setAttributeOverride('id', array( +$metadata->setAttributeOverride('id', [ 'columnName' => 'guest_id', 'type' => 'integer', 'length' => 140, -)); +] +); -$metadata->setAttributeOverride('name',array( +$metadata->setAttributeOverride('name', + [ 'columnName' => 'guest_name', 'nullable' => false, 'unique' => true, 'length' => 240, -)); \ No newline at end of file + ] +); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC964.DDC964User.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC964.DDC964User.php index 7b66deef0c6..dc445f1ca6c 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC964.DDC964User.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC964.DDC964User.php @@ -2,45 +2,57 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; -$metadata->mapField(array( +$metadata->mapField( + [ 'id' => true, 'fieldName' => 'id', 'type' => 'integer', 'columnName' => 'user_id', 'length' => 150, -)); -$metadata->mapField(array( + ] +); +$metadata->mapField( + [ 'fieldName' => 'name', 'type' => 'string', 'columnName'=> 'user_name', 'nullable' => true, 'unique' => false, 'length' => 250, -)); + ] +); -$metadata->mapManyToOne(array( +$metadata->mapManyToOne( + [ 'fieldName' => 'address', 'targetEntity' => 'DDC964Address', - 'cascade' => array('persist','merge'), - 'joinColumn' => array('name'=>'address_id', 'referencedColumnMame'=>'id'), -)); + 'cascade' => ['persist','merge'], + 'joinColumn' => ['name'=>'address_id', 'referencedColumnMame'=>'id'], + ] +); -$metadata->mapManyToMany(array( +$metadata->mapManyToMany( + [ 'fieldName' => 'groups', 'targetEntity' => 'DDC964Group', 'inversedBy' => 'users', - 'cascade' => array('persist','merge','detach'), - 'joinTable' => array( + 'cascade' => ['persist','merge','detach'], + 'joinTable' => [ 'name' => 'ddc964_users_groups', - 'joinColumns' => array(array( + 'joinColumns' => [ + [ 'name'=>'user_id', 'referencedColumnName'=>'id', - )), - 'inverseJoinColumns'=>array(array( + ] + ], + 'inverseJoinColumns'=> [ + [ 'name'=>'group_id', 'referencedColumnName'=>'id', - )) - ) -)); + ] + ] + ] + ] +); -$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); \ No newline at end of file +$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Animal.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Animal.php index 005178eedee..3adc2a7a6ca 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Animal.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Animal.php @@ -4,18 +4,23 @@ /* @var $metadata ClassMetadataInfo */ $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE); -$metadata->setDiscriminatorColumn(array( +$metadata->setDiscriminatorColumn( + [ 'name' => 'dtype', 'type' => 'string', 'length' => 255, 'fieldName' => 'dtype', - )); -$metadata->setDiscriminatorMap(array( + ] +); +$metadata->setDiscriminatorMap( + [ 'cat' => 'Doctrine\\Tests\\ORM\\Mapping\\Cat', 'dog' => 'Doctrine\\Tests\\ORM\\Mapping\\Dog', - )); + ] +); $metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT); -$metadata->mapField(array( +$metadata->mapField( + [ 'fieldName' => 'id', 'type' => 'string', 'length' => NULL, @@ -25,6 +30,7 @@ 'unique' => false, 'id' => true, 'columnName' => 'id', - )); + ] +); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_CUSTOM); -$metadata->setCustomGeneratorDefinition(array("class" => "stdClass")); +$metadata->setCustomGeneratorDefinition(["class" => "stdClass"]); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Comment.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Comment.php index 85cbed4dc58..a33ebbaeb37 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Comment.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Comment.php @@ -3,13 +3,16 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE); -$metadata->setPrimaryTable(array( - 'indexes' => array( - array('columns' => array('content'), 'flags' => array('fulltext'), 'options'=> array('where' => 'content IS NOT NULL')) - ) - )); +$metadata->setPrimaryTable( + [ + 'indexes' => [ + ['columns' => ['content'], 'flags' => ['fulltext'], 'options'=> ['where' => 'content IS NOT NULL']] + ] + ] +); -$metadata->mapField(array( +$metadata->mapField( + [ 'fieldName' => 'content', 'type' => 'text', 'scale' => 0, @@ -18,4 +21,5 @@ 'nullable' => false, 'precision' => 0, 'columnName' => 'content', -)); \ No newline at end of file + ] +); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.DDC1170Entity.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.DDC1170Entity.php index 97f4624bad6..dd442ceb0e4 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.DDC1170Entity.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.DDC1170Entity.php @@ -2,15 +2,19 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; -$metadata->mapField(array( +$metadata->mapField( + [ 'id' => true, 'fieldName' => 'id', 'columnDefinition' => 'INT unsigned NOT NULL', -)); + ] +); -$metadata->mapField(array( +$metadata->mapField( + [ 'fieldName' => 'value', 'columnDefinition' => 'VARCHAR(255) NOT NULL' -)); + ] +); -$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE); \ No newline at end of file +$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.DDC807Entity.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.DDC807Entity.php index 1682d7a0de8..c9d8ad9f29d 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.DDC807Entity.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.DDC807Entity.php @@ -2,14 +2,18 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; -$metadata->mapField(array( +$metadata->mapField( + [ 'id' => true, 'fieldName' => 'id', -)); + ] +); -$metadata->setDiscriminatorColumn(array( +$metadata->setDiscriminatorColumn( + [ 'name' => "dtype", 'columnDefinition' => "ENUM('ONE','TWO')" -)); + ] +); -$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE); \ No newline at end of file +$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.PHPSLC.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.PHPSLC.php index c9341958a67..ad1ed23bfc7 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.PHPSLC.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.PHPSLC.php @@ -2,11 +2,15 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; -$metadata->enableCache(array( +$metadata->enableCache( + [ 'usage' => ClassMetadataInfo::CACHE_USAGE_READ_ONLY -)); -$metadata->mapManyToOne(array( + ] +); +$metadata->mapManyToOne( + [ 'fieldName' => 'foo', 'id' => true, 'targetEntity' => 'PHPSLCFoo' -)); \ No newline at end of file + ] +); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php index 5bcc6d0296f..cc23c399240 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php @@ -3,126 +3,144 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE); -$metadata->setPrimaryTable(array( +$metadata->setPrimaryTable( + [ 'name' => 'cms_users', - )); + ] +); $metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT); $metadata->addLifecycleCallback('doStuffOnPrePersist', 'prePersist'); $metadata->addLifecycleCallback('doOtherStuffOnPrePersistToo', 'prePersist'); $metadata->addLifecycleCallback('doStuffOnPostPersist', 'postPersist'); -$metadata->addNamedQuery(array( +$metadata->addNamedQuery( + [ 'name' => 'all', 'query' => 'SELECT u FROM __CLASS__ u' -)); -$metadata->mapField(array( + ] +); +$metadata->mapField( + [ 'id' => true, 'fieldName' => 'id', 'type' => 'integer', 'columnName' => 'id', - 'options' => array('foo' => 'bar', 'unsigned' => false), - )); -$metadata->mapField(array( + 'options' => ['foo' => 'bar', 'unsigned' => false], + ] +); +$metadata->mapField( + [ 'fieldName' => 'name', 'type' => 'string', 'length' => 50, 'unique' => true, 'nullable' => true, 'columnName' => 'name', - 'options' => array('foo' => 'bar', 'baz' => array('key' => 'val'), 'fixed' => false), - )); -$metadata->mapField(array( + 'options' => ['foo' => 'bar', 'baz' => ['key' => 'val'], 'fixed' => false], + ] +); +$metadata->mapField( + [ 'fieldName' => 'email', 'type' => 'string', 'columnName' => 'user_email', 'columnDefinition' => 'CHAR(32) NOT NULL', - )); -$mapping = array('fieldName' => 'version', 'type' => 'integer'); + ] +); +$mapping = ['fieldName' => 'version', 'type' => 'integer']; $metadata->setVersionMapping($mapping); $metadata->mapField($mapping); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); -$metadata->mapOneToOne(array( +$metadata->mapOneToOne( + [ 'fieldName' => 'address', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Address', 'cascade' => - array( + [ 0 => 'remove', - ), + ], 'mappedBy' => NULL, 'inversedBy' => 'user', 'joinColumns' => - array( + [ 0 => - array( + [ 'name' => 'address_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE', - ), - ), + ], + ], 'orphanRemoval' => false, - )); -$metadata->mapOneToMany(array( + ] +); +$metadata->mapOneToMany( + [ 'fieldName' => 'phonenumbers', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Phonenumber', 'cascade' => - array( + [ 1 => 'persist', - ), + ], 'mappedBy' => 'user', 'orphanRemoval' => true, 'orderBy' => - array( + [ 'number' => 'ASC', - ), - )); -$metadata->mapManyToMany(array( + ], + ] +); +$metadata->mapManyToMany( + [ 'fieldName' => 'groups', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Group', 'cascade' => - array( + [ 0 => 'remove', 1 => 'persist', 2 => 'refresh', 3 => 'merge', 4 => 'detach', - ), + ], 'mappedBy' => NULL, 'joinTable' => - array( + [ 'name' => 'cms_users_groups', 'joinColumns' => - array( + [ 0 => - array( + [ 'name' => 'user_id', 'referencedColumnName' => 'id', 'unique' => false, 'nullable' => false, - ), - ), + ], + ], 'inverseJoinColumns' => - array( + [ 0 => - array( + [ 'name' => 'group_id', 'referencedColumnName' => 'id', 'columnDefinition' => 'INT NULL', - ), - ), - ), + ], + ], + ], 'orderBy' => NULL, - )); -$metadata->table['options'] = array( - 'foo' => 'bar', - 'baz' => array('key' => 'val') -); -$metadata->table['uniqueConstraints'] = array( - 'search_idx' => array('columns' => array('name', 'user_email'), 'options' => array('where' => 'name IS NOT NULL')), + ] ); -$metadata->table['indexes'] = array( - 'name_idx' => array('columns' => array('name')), 0 => array('columns' => array('user_email')) -); -$metadata->setSequenceGeneratorDefinition(array( +$metadata->table['options'] = [ + 'foo' => 'bar', + 'baz' => ['key' => 'val'] +]; +$metadata->table['uniqueConstraints'] = [ + 'search_idx' => ['columns' => ['name', 'user_email'], 'options' => ['where' => 'name IS NOT NULL']], +]; +$metadata->table['indexes'] = [ + 'name_idx' => ['columns' => ['name']], 0 => ['columns' => ['user_email']] +]; +$metadata->setSequenceGeneratorDefinition( + [ 'sequenceName' => 'tablename_seq', 'allocationSize' => 100, 'initialValue' => 1, - )); + ] +); diff --git a/tests/Doctrine/Tests/ORM/Performance/DDC2602Test.php b/tests/Doctrine/Tests/ORM/Performance/DDC2602Test.php index 210f72c80cf..4c992a87047 100644 --- a/tests/Doctrine/Tests/ORM/Performance/DDC2602Test.php +++ b/tests/Doctrine/Tests/ORM/Performance/DDC2602Test.php @@ -17,12 +17,14 @@ protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2602User'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2602Biography'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2602BiographyField'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2602BiographyFieldChoice'), - )); + ] + ); $this->loadFixture(); } @@ -31,18 +33,20 @@ protected function tearDown() { parent::tearDown(); - $this->_schemaTool->dropSchema(array( + $this->_schemaTool->dropSchema( + [ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2602User'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2602Biography'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2602BiographyField'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2602BiographyFieldChoice'), - )); + ] + ); } public function testIssue() { $eventManager = $this->_em->getEventManager(); - $eventManager->addEventListener(array(Events::postLoad), new DDC2602PostLoadListener()); + $eventManager->addEventListener([Events::postLoad], new DDC2602PostLoadListener()); // Set maximum seconds this can run $this->setMaxRunningTime(1); @@ -232,7 +236,7 @@ class DDC2602Biography /** * @var array */ - public $fieldList = array(); + public $fieldList = []; } /** diff --git a/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php index e4d65e1e72d..0846ca4de86 100644 --- a/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php @@ -38,35 +38,35 @@ public function testSimpleQueryScalarHydrationPerformance10000Rows() $rsm->addFieldResult('u', 'u__name', 'name'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'u__username' => 'romanb', 'u__name' => 'Roman', - ), - array( + ], + [ 'u__id' => '1', 'u__status' => 'developer', 'u__username' => 'romanb', 'u__name' => 'Roman', - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'u__username' => 'romanb', 'u__name' => 'Roman', - ) - ); + ] + ]; for ($i = 4; $i < 10000; ++$i) { - $resultSet[] = array( + $resultSet[] = [ 'u__id' => $i, 'u__status' => 'developer', 'u__username' => 'jwage', 'u__name' => 'Jonathan', - ); + ]; } $stmt = new HydratorMockStatement($resultSet); @@ -96,35 +96,35 @@ public function testSimpleQueryArrayHydrationPerformance10000Rows() $rsm->addFieldResult('u', 'u__name', 'name'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'u__username' => 'romanb', 'u__name' => 'Roman', - ), - array( + ], + [ 'u__id' => '1', 'u__status' => 'developer', 'u__username' => 'romanb', 'u__name' => 'Roman', - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'u__username' => 'romanb', 'u__name' => 'Roman', - ) - ); + ] + ]; for ($i = 4; $i < 10000; ++$i) { - $resultSet[] = array( + $resultSet[] = [ 'u__id' => $i, 'u__status' => 'developer', 'u__username' => 'jwage', 'u__name' => 'Jonathan', - ); + ]; } $stmt = new HydratorMockStatement($resultSet); @@ -162,43 +162,43 @@ public function testMixedQueryFetchJoinArrayHydrationPerformance10000Rows() $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'u__username' => 'romanb', 'u__name' => 'Roman', 'sclr0' => 'ROMANB', 'p__phonenumber' => '42', - ), - array( + ], + [ 'u__id' => '1', 'u__status' => 'developer', 'u__username' => 'romanb', 'u__name' => 'Roman', 'sclr0' => 'ROMANB', 'p__phonenumber' => '43', - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'u__username' => 'romanb', 'u__name' => 'Roman', 'sclr0' => 'JWAGE', 'p__phonenumber' => '91' - ) - ); + ] + ]; for ($i = 4; $i < 10000; ++$i) { - $resultSet[] = array( + $resultSet[] = [ 'u__id' => $i, 'u__status' => 'developer', 'u__username' => 'jwage', 'u__name' => 'Jonathan', 'sclr0' => 'JWAGE' . $i, 'p__phonenumber' => '91' - ); + ]; } $stmt = new HydratorMockStatement($resultSet); @@ -226,35 +226,35 @@ public function testSimpleQueryPartialObjectHydrationPerformance10000Rows() $rsm->addFieldResult('u', 'u__name', 'name'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'u__username' => 'romanb', 'u__name' => 'Roman', - ), - array( + ], + [ 'u__id' => '1', 'u__status' => 'developer', 'u__username' => 'romanb', 'u__name' => 'Roman', - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'u__username' => 'romanb', 'u__name' => 'Roman', - ) - ); + ] + ]; for ($i = 4; $i < 10000; ++$i) { - $resultSet[] = array( + $resultSet[] = [ 'u__id' => $i, 'u__status' => 'developer', 'u__username' => 'jwage', 'u__name' => 'Jonathan', - ); + ]; } $stmt = new HydratorMockStatement($resultSet); @@ -262,7 +262,7 @@ public function testSimpleQueryPartialObjectHydrationPerformance10000Rows() $this->setMaxRunningTime(3); $s = microtime(true); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $e = microtime(true); echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL; } @@ -292,25 +292,25 @@ public function testSimpleQueryFullObjectHydrationPerformance10000Rows() //$rsm->addFieldResult('a', 'a__city', 'city'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'u__username' => 'romanb', 'u__name' => 'Roman', 'a__id' => '1' - ) - ); + ] + ]; for ($i = 2; $i < 10000; ++$i) { - $resultSet[] = array( + $resultSet[] = [ 'u__id' => $i, 'u__status' => 'developer', 'u__username' => 'jwage', 'u__name' => 'Jonathan', 'a__id' => $i - ); + ]; } $stmt = new HydratorMockStatement($resultSet); @@ -346,43 +346,43 @@ public function testMixedQueryFetchJoinPartialObjectHydrationPerformance2000Rows $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'u__username' => 'romanb', 'u__name' => 'Roman', 'sclr0' => 'ROMANB', 'p__phonenumber' => '42', - ), - array( + ], + [ 'u__id' => '1', 'u__status' => 'developer', 'u__username' => 'romanb', 'u__name' => 'Roman', 'sclr0' => 'ROMANB', 'p__phonenumber' => '43', - ), - array( + ], + [ 'u__id' => '2', 'u__status' => 'developer', 'u__username' => 'romanb', 'u__name' => 'Roman', 'sclr0' => 'JWAGE', 'p__phonenumber' => '91' - ) - ); + ] + ]; for ($i = 4; $i < 2000; ++$i) { - $resultSet[] = array( + $resultSet[] = [ 'u__id' => $i, 'u__status' => 'developer', 'u__username' => 'jwage', 'u__name' => 'Jonathan', 'sclr0' => 'JWAGE' . $i, 'p__phonenumber' => '91' - ); + ]; } $stmt = new HydratorMockStatement($resultSet); @@ -390,7 +390,7 @@ public function testMixedQueryFetchJoinPartialObjectHydrationPerformance2000Rows $this->setMaxRunningTime(1); $s = microtime(true); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $e = microtime(true); echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL; } @@ -425,9 +425,9 @@ public function testMixedQueryFetchJoinFullObjectHydrationPerformance2000Rows() $rsm->addFieldResult('a', 'a__id', 'id'); // Faked result set - $resultSet = array( + $resultSet = [ //row1 - array( + [ 'u__id' => '1', 'u__status' => 'developer', 'u__username' => 'romanb', @@ -435,11 +435,11 @@ public function testMixedQueryFetchJoinFullObjectHydrationPerformance2000Rows() 'sclr0' => 'ROMANB', 'p__phonenumber' => '42', 'a__id' => '1' - ) - ); + ] + ]; for ($i = 2; $i < 2000; ++$i) { - $resultSet[] = array( + $resultSet[] = [ 'u__id' => $i, 'u__status' => 'developer', 'u__username' => 'jwage', @@ -447,7 +447,7 @@ public function testMixedQueryFetchJoinFullObjectHydrationPerformance2000Rows() 'sclr0' => 'JWAGE' . $i, 'p__phonenumber' => '91', 'a__id' => $i - ); + ]; } $stmt = new HydratorMockStatement($resultSet); diff --git a/tests/Doctrine/Tests/ORM/Performance/PersisterPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/PersisterPerformanceTest.php index db5d0f8ef60..8d66ba601a9 100644 --- a/tests/Doctrine/Tests/ORM/Performance/PersisterPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/PersisterPerformanceTest.php @@ -27,7 +27,7 @@ public function testFindCmsArticle() $author->username = "beberlei"; $this->_em->persist($author); - $ids = array(); + $ids = []; for ($i = 0; $i < 100; $i++) { $article = new CmsArticle(); $article->text = "foo"; diff --git a/tests/Doctrine/Tests/ORM/Performance/ProxyPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/ProxyPerformanceTest.php index bc98c23f6f7..de77aafd826 100644 --- a/tests/Doctrine/Tests/ORM/Performance/ProxyPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/ProxyPerformanceTest.php @@ -21,10 +21,10 @@ class ProxyPerformanceTest extends OrmPerformanceTestCase */ public function entitiesProvider() { - return array( - array('Doctrine\Tests\Models\CMS\CmsEmployee'), - array('Doctrine\Tests\Models\CMS\CmsUser'), - ); + return [ + ['Doctrine\Tests\Models\CMS\CmsEmployee'], + ['Doctrine\Tests\Models\CMS\CmsUser'], + ]; } /** @@ -37,7 +37,7 @@ public function testProxyInstantiationPerformance($entityName) $start = microtime(true); for ($i = 0; $i < 100000; $i += 1) { - $user = $proxyFactory->getProxy($entityName, array('id' => $i)); + $user = $proxyFactory->getProxy($entityName, ['id' => $i]); } echo __FUNCTION__ . " - " . (microtime(true) - $start) . " seconds with " . $entityName . PHP_EOL; @@ -51,7 +51,7 @@ public function testProxyForcedInitializationPerformance($entityName) $em = new MockEntityManager($this->_getEntityManager()); $proxyFactory = $em->getProxyFactory(); /* @var $user \Doctrine\Common\Proxy\Proxy */ - $user = $proxyFactory->getProxy($entityName, array('id' => 1)); + $user = $proxyFactory->getProxy($entityName, ['id' => 1]); $initializer = $user->__getInitializer(); $this->setMaxRunningTime(5); @@ -146,7 +146,7 @@ public function __construct() } /** {@inheritDoc} */ - public function load(array $criteria, $entity = null, $assoc = null, array $hints = array(), $lockMode = 0, $limit = null, array $orderBy = null) + public function load(array $criteria, $entity = null, $assoc = null, array $hints = [], $lockMode = 0, $limit = null, array $orderBy = null) { return $entity; } diff --git a/tests/Doctrine/Tests/ORM/Performance/SecondLevelCacheTest.php b/tests/Doctrine/Tests/ORM/Performance/SecondLevelCacheTest.php index 774945c5aa6..27974091809 100644 --- a/tests/Doctrine/Tests/ORM/Performance/SecondLevelCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/SecondLevelCacheTest.php @@ -159,8 +159,8 @@ public function findEntityOneToMany(EntityManagerInterface $em, $label) { $times = 50; $size = 30; - $states = array(); - $cities = array(); + $states = []; + $cities = []; $startPersist = microtime(true); $country = new Country("Country"); @@ -218,7 +218,7 @@ private function findEntity(EntityManagerInterface $em, $label) { $times = 10; $size = 500; - $countries = array(); + $countries = []; $startPersist = microtime(true); echo PHP_EOL . $label; @@ -279,4 +279,4 @@ private function findAllEntity(EntityManagerInterface $em, $label) printf("\n[%s] find %s countries (%s times)", number_format(microtime(true) - $startFind, 6), $size, $times); printf("\n%s\n", str_repeat('-', 50)); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Performance/UnitOfWorkPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/UnitOfWorkPerformanceTest.php index 93493363598..3d63eb4d844 100644 --- a/tests/Doctrine/Tests/ORM/Performance/UnitOfWorkPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/UnitOfWorkPerformanceTest.php @@ -23,7 +23,7 @@ public function testComputeChanges() { $n = 100; - $users = array(); + $users = []; for ($i=1; $i<=$n; ++$i) { $user = new CmsUser; $user->status = 'user'; diff --git a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeParametersTest.php b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeParametersTest.php index 74d72856ec1..db6fa5c836c 100644 --- a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeParametersTest.php +++ b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeParametersTest.php @@ -43,12 +43,14 @@ public function testExpandParametersWillExpandCompositeEntityKeys() $admin1 = new Admin1(10, "Rome", $country); - list ($values, $types) = $this->_persister->expandParameters(array( + list ($values, $types) = $this->_persister->expandParameters( + [ 'admin1' => $admin1 - )); + ] + ); - $this->assertEquals(array('integer', 'string'), $types); - $this->assertEquals(array(10, 'IT'), $values); + $this->assertEquals(['integer', 'string'], $types); + $this->assertEquals([10, 'IT'], $values); } public function testExpandCriteriaParametersWillExpandCompositeEntityKeys() @@ -62,7 +64,7 @@ public function testExpandCriteriaParametersWillExpandCompositeEntityKeys() list ($values, $types) = $this->_persister->expandCriteriaParameters($criteria); - $this->assertEquals(array('integer', 'string'), $types); - $this->assertEquals(array(10, 'IT'), $values); + $this->assertEquals(['integer', 'string'], $types); + $this->assertEquals([10, 'IT'], $values); } } diff --git a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeSqlTest.php b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeSqlTest.php index e788826d481..441ff010162 100644 --- a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeSqlTest.php +++ b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeSqlTest.php @@ -32,19 +32,19 @@ protected function setUp() public function testSelectConditionStatementEq() { - $statement = $this->_persister->getSelectConditionStatementSQL('admin1', 1, array(), Comparison::EQ); + $statement = $this->_persister->getSelectConditionStatementSQL('admin1', 1, [], Comparison::EQ); $this->assertEquals('t0.admin1 = ? AND t0.country = ?', $statement); } public function testSelectConditionStatementEqNull() { - $statement = $this->_persister->getSelectConditionStatementSQL('admin1', null, array(), Comparison::IS); + $statement = $this->_persister->getSelectConditionStatementSQL('admin1', null, [], Comparison::IS); $this->assertEquals('t0.admin1 IS NULL AND t0.country IS NULL', $statement); } public function testSelectConditionStatementNeqNull() { - $statement = $this->_persister->getSelectConditionStatementSQL('admin1', null, array(), Comparison::NEQ); + $statement = $this->_persister->getSelectConditionStatementSQL('admin1', null, [], Comparison::NEQ); $this->assertEquals('t0.admin1 IS NOT NULL AND t0.country IS NOT NULL', $statement); } @@ -53,6 +53,6 @@ public function testSelectConditionStatementNeqNull() */ public function testSelectConditionStatementIn() { - $this->_persister->getSelectConditionStatementSQL('admin1', array(), array(), Comparison::IN); + $this->_persister->getSelectConditionStatementSQL('admin1', [], [], Comparison::IN); } } diff --git a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php index b617d14da73..c4d747058b8 100644 --- a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php +++ b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php @@ -65,8 +65,8 @@ public function testUpdateUsesTypeValuesSQL() $parent->customInteger = 1; $parent->child = $child; - $this->_em->getUnitOfWork()->registerManaged($parent, array('id' => 1), array('customInteger' => 0, 'child' => null)); - $this->_em->getUnitOfWork()->registerManaged($child, array('id' => 1), array()); + $this->_em->getUnitOfWork()->registerManaged($parent, ['id' => 1], ['customInteger' => 0, 'child' => null]); + $this->_em->getUnitOfWork()->registerManaged($child, ['id' => 1], []); $this->_em->getUnitOfWork()->propertyChanged($parent, 'customInteger', 0, 1); $this->_em->getUnitOfWork()->propertyChanged($parent, 'child', null, $child); @@ -83,7 +83,7 @@ public function testGetSelectConditionSQLUsesTypeValuesSQL() $method = new \ReflectionMethod($this->_persister, 'getSelectConditionSQL'); $method->setAccessible(true); - $sql = $method->invoke($this->_persister, array('customInteger' => 1, 'child' => 1)); + $sql = $method->invoke($this->_persister, ['customInteger' => 1, 'child' => 1]); $this->assertEquals('t0.customInteger = ABS(?) AND t0.child_id = ?', $sql); } @@ -105,19 +105,19 @@ public function testStripNonAlphanumericCharactersFromSelectColumnListSQL() */ public function testSelectConditionStatementIsNull() { - $statement = $this->_persister->getSelectConditionStatementSQL('test', null, array(), Comparison::IS); + $statement = $this->_persister->getSelectConditionStatementSQL('test', null, [], Comparison::IS); $this->assertEquals('test IS NULL', $statement); } public function testSelectConditionStatementEqNull() { - $statement = $this->_persister->getSelectConditionStatementSQL('test', null, array(), Comparison::EQ); + $statement = $this->_persister->getSelectConditionStatementSQL('test', null, [], Comparison::EQ); $this->assertEquals('test IS NULL', $statement); } public function testSelectConditionStatementNeqNull() { - $statement = $this->_persister->getSelectConditionStatementSQL('test', null, array(), Comparison::NEQ); + $statement = $this->_persister->getSelectConditionStatementSQL('test', null, [], Comparison::NEQ); $this->assertEquals('test IS NOT NULL', $statement); } @@ -128,17 +128,17 @@ public function testSelectConditionStatementWithMultipleValuesContainingNull() { $this->assertEquals( '(t0.id IN (?) OR t0.id IS NULL)', - $this->_persister->getSelectConditionStatementSQL('id', array(null)) + $this->_persister->getSelectConditionStatementSQL('id', [null]) ); $this->assertEquals( '(t0.id IN (?) OR t0.id IS NULL)', - $this->_persister->getSelectConditionStatementSQL('id', array(null, 123)) + $this->_persister->getSelectConditionStatementSQL('id', [null, 123]) ); $this->assertEquals( '(t0.id IN (?) OR t0.id IS NULL)', - $this->_persister->getSelectConditionStatementSQL('id', array(123, null)) + $this->_persister->getSelectConditionStatementSQL('id', [123, null]) ); } @@ -147,7 +147,7 @@ public function testCountCondition() $persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata('Doctrine\Tests\Models\Generic\NonAlphaColumnsEntity')); // Using a criteria as array - $statement = $persister->getCountSQL(array('value' => 'bar')); + $statement = $persister->getCountSQL(['value' => 'bar']); $this->assertEquals('SELECT COUNT(*) FROM "not-a-simple-entity" t0 WHERE t0."simple-entity-value" = ?', $statement); // Using a criteria object diff --git a/tests/Doctrine/Tests/ORM/Persisters/JoinedSubclassPersisterTest.php b/tests/Doctrine/Tests/ORM/Persisters/JoinedSubclassPersisterTest.php index 5d4e992f7fc..14deca10034 100644 --- a/tests/Doctrine/Tests/ORM/Persisters/JoinedSubclassPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Persisters/JoinedSubclassPersisterTest.php @@ -42,6 +42,6 @@ protected function setUp() */ public function testExecuteInsertsWillReturnEmptySetWithNoQueuedInserts() { - $this->assertSame(array(), $this->persister->executeInserts()); + $this->assertSame([], $this->persister->executeInserts()); } } diff --git a/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php b/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php index 174daf3c02a..e7da7a463f5 100644 --- a/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php @@ -48,7 +48,7 @@ class ProxyFactoryTest extends OrmTestCase protected function setUp() { parent::setUp(); - $this->connectionMock = new ConnectionMock(array(), new DriverMock()); + $this->connectionMock = new ConnectionMock([], new DriverMock()); $this->emMock = EntityManagerMock::create($this->connectionMock); $this->uowMock = new UnitOfWorkMock($this->emMock); $this->emMock->setUnitOfWork($this->uowMock); @@ -57,9 +57,9 @@ protected function setUp() public function testReferenceProxyDelegatesLoadingToThePersister() { - $identifier = array('id' => 42); + $identifier = ['id' => 42]; $proxyClass = 'Proxies\__CG__\Doctrine\Tests\Models\ECommerce\ECommerceFeature'; - $persister = $this->getMockBuilder(BasicEntityPersister::class)->setMethods(array('load'))->disableOriginalConstructor()->getMock(); + $persister = $this->getMockBuilder(BasicEntityPersister::class)->setMethods(['load'])->disableOriginalConstructor()->getMock(); $this->uowMock->setEntityPersister('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $persister); @@ -83,7 +83,7 @@ public function testSkipAbstractClassesOnGeneration() $cm->initializeReflection(new RuntimeReflectionService()); $this->assertNotNull($cm->reflClass); - $num = $this->proxyFactory->generateProxyClasses(array($cm)); + $num = $this->proxyFactory->generateProxyClasses([$cm]); $this->assertEquals(0, $num, "No proxies generated."); } @@ -93,11 +93,11 @@ public function testSkipAbstractClassesOnGeneration() */ public function testFailedProxyLoadingDoesNotMarkTheProxyAsInitialized() { - $persister = $this->getMockBuilder(BasicEntityPersister::class)->setMethods(array('load'))->disableOriginalConstructor()->getMock(); + $persister = $this->getMockBuilder(BasicEntityPersister::class)->setMethods(['load'])->disableOriginalConstructor()->getMock(); $this->uowMock->setEntityPersister('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $persister); /* @var $proxy \Doctrine\Common\Proxy\Proxy */ - $proxy = $this->proxyFactory->getProxy('Doctrine\Tests\Models\ECommerce\ECommerceFeature', array('id' => 42)); + $proxy = $this->proxyFactory->getProxy('Doctrine\Tests\Models\ECommerce\ECommerceFeature', ['id' => 42]); $persister ->expects($this->atLeastOnce()) @@ -120,11 +120,11 @@ public function testFailedProxyLoadingDoesNotMarkTheProxyAsInitialized() */ public function testFailedProxyCloningDoesNotMarkTheProxyAsInitialized() { - $persister = $this->getMockBuilder(BasicEntityPersister::class)->setMethods(array('load'))->disableOriginalConstructor()->getMock(); + $persister = $this->getMockBuilder(BasicEntityPersister::class)->setMethods(['load'])->disableOriginalConstructor()->getMock(); $this->uowMock->setEntityPersister('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $persister); /* @var $proxy \Doctrine\Common\Proxy\Proxy */ - $proxy = $this->proxyFactory->getProxy('Doctrine\Tests\Models\ECommerce\ECommerceFeature', array('id' => 42)); + $proxy = $this->proxyFactory->getProxy('Doctrine\Tests\Models\ECommerce\ECommerceFeature', ['id' => 42]); $persister ->expects($this->atLeastOnce()) diff --git a/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersJoinTest.php b/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersJoinTest.php index e47c48215c0..bedcd659758 100644 --- a/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersJoinTest.php +++ b/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersJoinTest.php @@ -25,7 +25,7 @@ public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed) { try { $query = $this->em->createQuery($dqlToBeTested); - $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\Tests\ORM\Query\CustomTreeWalkerJoin')) + $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\Tests\ORM\Query\CustomTreeWalkerJoin']) ->useQueryCache(false); $this->assertEquals($sqlToBeConfirmed, $query->getSql()); @@ -59,15 +59,15 @@ public function walkSelectStatement(Query\AST\SelectStatement $selectStatement) { foreach ($selectStatement->fromClause->identificationVariableDeclarations as $identificationVariableDeclaration) { $rangeVariableDecl = $identificationVariableDeclaration->rangeVariableDeclaration; - + if ($rangeVariableDecl->abstractSchemaName !== 'Doctrine\Tests\Models\CMS\CmsUser') { continue; } - + $this->modifySelectStatement($selectStatement, $identificationVariableDeclaration); } } - + private function modifySelectStatement(Query\AST\SelectStatement $selectStatement, $identificationVariableDecl) { $rangeVariableDecl = $identificationVariableDecl->rangeVariableDeclaration; @@ -75,7 +75,7 @@ private function modifySelectStatement(Query\AST\SelectStatement $selectStatemen $joinAssocDeclaration = new Query\AST\JoinAssociationDeclaration($joinAssocPathExpression, $rangeVariableDecl->aliasIdentificationVariable . 'a', null); $join = new Query\AST\Join(Query\AST\Join::JOIN_TYPE_LEFT, $joinAssocDeclaration); $selectExpression = new Query\AST\SelectExpression($rangeVariableDecl->aliasIdentificationVariable . 'a', null, false); - + $identificationVariableDecl->joins[] = $join; $selectStatement->selectClause->selectExpressions[] = $selectExpression; @@ -84,14 +84,14 @@ private function modifySelectStatement(Query\AST\SelectStatement $selectStatemen $addressMetadata = $entityManager->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); $this->setQueryComponent($rangeVariableDecl->aliasIdentificationVariable . 'a', - array( + [ 'metadata' => $addressMetadata, 'parent' => $rangeVariableDecl->aliasIdentificationVariable, 'relation' => $userMetadata->getAssociationMapping('address'), 'map' => null, 'nestingLevel' => 0, 'token' => null, - ) + ] ); } } diff --git a/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersTest.php b/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersTest.php index 4114c4f8b23..d6ae708180a 100644 --- a/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersTest.php +++ b/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersTest.php @@ -36,7 +36,7 @@ public function generateSql($dqlToBeTested, $treeWalkers, $outputWalker) return $query->getSql(); } - public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed, $treeWalkers = array(), $outputWalker = null) + public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed, $treeWalkers = [], $outputWalker = null) { try { $this->assertEquals($sqlToBeConfirmed, $this->generateSql($dqlToBeTested, $treeWalkers, $outputWalker)); @@ -50,7 +50,7 @@ public function testSupportsQueriesWithoutWhere() $this->assertSqlGeneration( 'select u from Doctrine\Tests\Models\CMS\CmsUser u', "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c0_.email_id AS email_id_4 FROM cms_users c0_ WHERE c0_.id = 1", - array('Doctrine\Tests\ORM\Functional\CustomTreeWalker') + ['Doctrine\Tests\ORM\Functional\CustomTreeWalker'] ); } @@ -59,7 +59,7 @@ public function testSupportsQueriesWithMultipleConditionalExpressions() $this->assertSqlGeneration( 'select u from Doctrine\Tests\Models\CMS\CmsUser u where u.name = :name or u.name = :otherName', "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c0_.email_id AS email_id_4 FROM cms_users c0_ WHERE (c0_.name = ? OR c0_.name = ?) AND c0_.id = 1", - array('Doctrine\Tests\ORM\Functional\CustomTreeWalker') + ['Doctrine\Tests\ORM\Functional\CustomTreeWalker'] ); } @@ -68,7 +68,7 @@ public function testSupportsQueriesWithSimpleConditionalExpression() $this->assertSqlGeneration( 'select u from Doctrine\Tests\Models\CMS\CmsUser u where u.name = :name', "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c0_.email_id AS email_id_4 FROM cms_users c0_ WHERE c0_.name = ? AND c0_.id = 1", - array('Doctrine\Tests\ORM\Functional\CustomTreeWalker') + ['Doctrine\Tests\ORM\Functional\CustomTreeWalker'] ); } @@ -79,7 +79,7 @@ public function testSetUnknownQueryComponentThrowsException() $this->generateSql( 'select u from Doctrine\Tests\Models\CMS\CmsUser u', - array(), + [], __NAMESPACE__ . '\\AddUnknownQueryComponentWalker' ); } @@ -89,7 +89,7 @@ public function testSupportsSeveralHintsQueries() $this->assertSqlGeneration( 'select u from Doctrine\Tests\Models\CMS\CmsUser u', "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c1_.id AS id_4, c1_.country AS country_5, c1_.zip AS zip_6, c1_.city AS city_7, c0_.email_id AS email_id_8, c1_.user_id AS user_id_9 FROM cms_users c0_ LEFT JOIN cms_addresses c1_ ON c0_.id = c1_.user_id WHERE c0_.id = 1", - array('Doctrine\Tests\ORM\Functional\CustomTreeWalkerJoin', 'Doctrine\Tests\ORM\Functional\CustomTreeWalker') + ['Doctrine\Tests\ORM\Functional\CustomTreeWalkerJoin', 'Doctrine\Tests\ORM\Functional\CustomTreeWalker'] ); } } @@ -100,7 +100,7 @@ public function walkSelectStatement(Query\AST\SelectStatement $selectStatement) { parent::walkSelectStatement($selectStatement); - $this->setQueryComponent('x', array()); + $this->setQueryComponent('x', []); } } @@ -109,7 +109,7 @@ class CustomTreeWalker extends Query\TreeWalkerAdapter public function walkSelectStatement(Query\AST\SelectStatement $selectStatement) { // Get the DQL aliases of all the classes we want to modify - $dqlAliases = array(); + $dqlAliases = []; foreach ($this->_getQueryComponents() as $dqlAlias => $comp) { // Hard-coded check just for demonstration: We want to modify the query if @@ -120,7 +120,7 @@ public function walkSelectStatement(Query\AST\SelectStatement $selectStatement) } // Create our conditions for all involved classes - $factors = array(); + $factors = []; foreach ($dqlAliases as $alias) { $pathExpr = new Query\AST\PathExpression(Query\AST\PathExpression::TYPE_STATE_FIELD, $alias, 'id'); $pathExpr->type = Query\AST\PathExpression::TYPE_STATE_FIELD; @@ -139,7 +139,7 @@ public function walkSelectStatement(Query\AST\SelectStatement $selectStatement) // Since Phase 1 AST optimizations were included, we need to re-add the ConditionalExpression if ( ! ($condExpr instanceof Query\AST\ConditionalExpression)) { - $condExpr = new Query\AST\ConditionalExpression(array($condExpr)); + $condExpr = new Query\AST\ConditionalExpression([$condExpr]); $whereClause->conditionalExpression = $condExpr; } @@ -153,27 +153,27 @@ public function walkSelectStatement(Query\AST\SelectStatement $selectStatement) $primary = new Query\AST\ConditionalPrimary; $primary->conditionalExpression = new Query\AST\ConditionalExpression($existingTerms); $existingFactor = new Query\AST\ConditionalFactor($primary); - $term = new Query\AST\ConditionalTerm(array_merge(array($existingFactor), $factors)); + $term = new Query\AST\ConditionalTerm(array_merge([$existingFactor], $factors)); - $selectStatement->whereClause->conditionalExpression->conditionalTerms = array($term); + $selectStatement->whereClause->conditionalExpression->conditionalTerms = [$term]; } else { // Just one term so we can simply append our factors to that term $singleTerm = $selectStatement->whereClause->conditionalExpression->conditionalTerms[0]; // Since Phase 1 AST optimizations were included, we need to re-add the ConditionalExpression if ( ! ($singleTerm instanceof Query\AST\ConditionalTerm)) { - $singleTerm = new Query\AST\ConditionalTerm(array($singleTerm)); + $singleTerm = new Query\AST\ConditionalTerm([$singleTerm]); $selectStatement->whereClause->conditionalExpression->conditionalTerms[0] = $singleTerm; } $singleTerm->conditionalFactors = array_merge($singleTerm->conditionalFactors, $factors); - $selectStatement->whereClause->conditionalExpression->conditionalTerms = array($singleTerm); + $selectStatement->whereClause->conditionalExpression->conditionalTerms = [$singleTerm]; } } else { // Create a new WHERE clause with our factors $term = new Query\AST\ConditionalTerm($factors); - $condExpr = new Query\AST\ConditionalExpression(array($term)); + $condExpr = new Query\AST\ConditionalExpression([$term]); $whereClause = new Query\AST\WhereClause($condExpr); $selectStatement->whereClause = $whereClause; } @@ -186,15 +186,15 @@ public function walkSelectStatement(Query\AST\SelectStatement $selectStatement) { foreach ($selectStatement->fromClause->identificationVariableDeclarations as $identificationVariableDeclaration) { $rangeVariableDecl = $identificationVariableDeclaration->rangeVariableDeclaration; - + if ($rangeVariableDecl->abstractSchemaName !== 'Doctrine\Tests\Models\CMS\CmsUser') { continue; } - + $this->modifySelectStatement($selectStatement, $identificationVariableDeclaration); } } - + private function modifySelectStatement(Query\AST\SelectStatement $selectStatement, $identificationVariableDecl) { $rangeVariableDecl = $identificationVariableDecl->rangeVariableDeclaration; @@ -202,7 +202,7 @@ private function modifySelectStatement(Query\AST\SelectStatement $selectStatemen $joinAssocDeclaration = new Query\AST\JoinAssociationDeclaration($joinAssocPathExpression, $rangeVariableDecl->aliasIdentificationVariable . 'a', null); $join = new Query\AST\Join(Query\AST\Join::JOIN_TYPE_LEFT, $joinAssocDeclaration); $selectExpression = new Query\AST\SelectExpression($rangeVariableDecl->aliasIdentificationVariable . 'a', null, false); - + $identificationVariableDecl->joins[] = $join; $selectStatement->selectClause->selectExpressions[] = $selectExpression; @@ -211,14 +211,14 @@ private function modifySelectStatement(Query\AST\SelectStatement $selectStatemen $addressMetadata = $entityManager->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); $this->setQueryComponent($rangeVariableDecl->aliasIdentificationVariable . 'a', - array( + [ 'metadata' => $addressMetadata, 'parent' => $rangeVariableDecl->aliasIdentificationVariable, 'relation' => $userMetadata->getAssociationMapping('address'), 'map' => null, 'nestingLevel' => 0, 'token' => null, - ) + ] ); } } diff --git a/tests/Doctrine/Tests/ORM/Query/ExprTest.php b/tests/Doctrine/Tests/ORM/Query/ExprTest.php index 61def177092..791f2f9b934 100644 --- a/tests/Doctrine/Tests/ORM/Query/ExprTest.php +++ b/tests/Doctrine/Tests/ORM/Query/ExprTest.php @@ -55,7 +55,7 @@ public function testCountDistinctExpr() { $this->assertEquals('COUNT(DISTINCT u.id)', (string) $this->_expr->countDistinct('u.id')); } - + public function testCountDistinctExprMulti() { $this->assertEquals('COUNT(DISTINCT u.id, u.name)', (string) $this->_expr->countDistinct('u.id', 'u.name')); @@ -274,22 +274,22 @@ public function testIsMemberOfExpr() { public function testInExpr() { - $this->assertEquals('u.id IN(1, 2, 3)', (string) $this->_expr->in('u.id', array(1, 2, 3))); + $this->assertEquals('u.id IN(1, 2, 3)', (string) $this->_expr->in('u.id', [1, 2, 3])); } public function testInLiteralExpr() { - $this->assertEquals("u.type IN('foo', 'bar')", (string) $this->_expr->in('u.type', array('foo', 'bar'))); + $this->assertEquals("u.type IN('foo', 'bar')", (string) $this->_expr->in('u.type', ['foo', 'bar'])); } public function testNotInExpr() { - $this->assertEquals('u.id NOT IN(1, 2, 3)', (string) $this->_expr->notIn('u.id', array(1, 2, 3))); + $this->assertEquals('u.id NOT IN(1, 2, 3)', (string) $this->_expr->notIn('u.id', [1, 2, 3])); } public function testNotInLiteralExpr() { - $this->assertEquals("u.type NOT IN('foo', 'bar')", (string) $this->_expr->notIn('u.type', array('foo', 'bar'))); + $this->assertEquals("u.type NOT IN('foo', 'bar')", (string) $this->_expr->notIn('u.type', ['foo', 'bar'])); } public function testAndxOrxExpr() @@ -360,8 +360,8 @@ public function testExpressionGetter() { // Andx - $andx = new Expr\Andx(array('1 = 1', '2 = 2')); - $this->assertEquals(array('1 = 1', '2 = 2'), $andx->getParts()); + $andx = new Expr\Andx(['1 = 1', '2 = 2']); + $this->assertEquals(['1 = 1', '2 = 2'], $andx->getParts()); // Comparison $comparison = new Expr\Comparison('foo', Expr\Comparison::EQ, 'bar'); @@ -376,13 +376,13 @@ public function testExpressionGetter() $this->assertEquals('f.id', $from->getIndexBy()); // Func - $func = new Expr\Func('MAX', array('f.id')); + $func = new Expr\Func('MAX', ['f.id']); $this->assertEquals('MAX', $func->getName()); - $this->assertEquals(array('f.id'), $func->getArguments()); + $this->assertEquals(['f.id'], $func->getArguments()); // GroupBy - $group = new Expr\GroupBy(array('foo DESC', 'bar ASC')); - $this->assertEquals(array('foo DESC', 'bar ASC'), $group->getParts()); + $group = new Expr\GroupBy(['foo DESC', 'bar ASC']); + $this->assertEquals(['foo DESC', 'bar ASC'], $group->getParts()); // Join $join = new Expr\Join(Expr\Join::INNER_JOIN, 'f.bar', 'b', Expr\Join::ON, 'b.bar_id = 1', 'b.bar_id'); @@ -394,8 +394,8 @@ public function testExpressionGetter() $this->assertEquals('b', $join->getAlias()); // Literal - $literal = new Expr\Literal(array('foo')); - $this->assertEquals(array('foo'), $literal->getParts()); + $literal = new Expr\Literal(['foo']); + $this->assertEquals(['foo'], $literal->getParts()); // Math $math = new Expr\Math(10, '+', 20); @@ -405,22 +405,22 @@ public function testExpressionGetter() // OrderBy $order = new Expr\OrderBy('foo', 'DESC'); - $this->assertEquals(array('foo DESC'), $order->getParts()); + $this->assertEquals(['foo DESC'], $order->getParts()); // Andx - $orx = new Expr\Orx(array('foo = 1', 'bar = 2')); - $this->assertEquals(array('foo = 1', 'bar = 2'), $orx->getParts()); + $orx = new Expr\Orx(['foo = 1', 'bar = 2']); + $this->assertEquals(['foo = 1', 'bar = 2'], $orx->getParts()); // Select - $select = new Expr\Select(array('foo', 'bar')); - $this->assertEquals(array('foo', 'bar'), $select->getParts()); + $select = new Expr\Select(['foo', 'bar']); + $this->assertEquals(['foo', 'bar'], $select->getParts()); } public function testAddEmpty() { $andExpr = $this->_expr->andX(); $andExpr->add($this->_expr->andX()); - + $this->assertEquals(0, $andExpr->count()); } @@ -428,7 +428,7 @@ public function testAddNull() { $andExpr = $this->_expr->andX(); $andExpr->add(null); - + $this->assertEquals(0, $andExpr->count()); } } diff --git a/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php b/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php index fe12b3989d4..88fdca9bf45 100644 --- a/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php +++ b/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php @@ -46,7 +46,7 @@ public function assertInvalidDQL($dql, $debug = false) } } - public function parseDql($dql, $hints = array()) + public function parseDql($dql, $hints = []) { $query = $this->_em->createQuery($dql); $query->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true); @@ -86,50 +86,52 @@ public function testRejectsInvalidDQL($dql) { $this->expectException(QueryException::class); - $this->_em->getConfiguration()->setEntityNamespaces(array( + $this->_em->getConfiguration()->setEntityNamespaces( + [ 'Unknown' => 'Unknown', 'CMS' => 'Doctrine\Tests\Models\CMS' - )); + ] + ); $this->parseDql($dql); } public function invalidDQL() { - return array( + return [ - array('SELECT \'foo\' AS foo\bar FROM Doctrine\Tests\Models\CMS\CmsUser u'), + ['SELECT \'foo\' AS foo\bar FROM Doctrine\Tests\Models\CMS\CmsUser u'], /* Checks for invalid IdentificationVariables and AliasIdentificationVariables */ - array('SELECT \foo FROM Doctrine\Tests\Models\CMS\CmsUser \foo'), - array('SELECT foo\ FROM Doctrine\Tests\Models\CMS\CmsUser foo\\'), - array('SELECT foo\bar FROM Doctrine\Tests\Models\CMS\CmsUser foo\bar'), - array('SELECT foo:bar FROM Doctrine\Tests\Models\CMS\CmsUser foo:bar'), - array('SELECT foo: FROM Doctrine\Tests\Models\CMS\CmsUser foo:'), + ['SELECT \foo FROM Doctrine\Tests\Models\CMS\CmsUser \foo'], + ['SELECT foo\ FROM Doctrine\Tests\Models\CMS\CmsUser foo\\'], + ['SELECT foo\bar FROM Doctrine\Tests\Models\CMS\CmsUser foo\bar'], + ['SELECT foo:bar FROM Doctrine\Tests\Models\CMS\CmsUser foo:bar'], + ['SELECT foo: FROM Doctrine\Tests\Models\CMS\CmsUser foo:'], /* Checks for invalid AbstractSchemaName */ - array('SELECT u FROM UnknownClass u'), // unknown - array('SELECT u FROM Unknown\Class u'), // unknown with namespace - array('SELECT u FROM \Unknown\Class u'), // unknown, leading backslash - array('SELECT u FROM Unknown\\\\Class u'), // unknown, syntactically bogus (duplicate \\) - array('SELECT u FROM Unknown\Class\ u'), // unknown, syntactically bogus (trailing \) - array('SELECT u FROM Unknown:Class u'), // unknown, with namespace alias - array('SELECT u FROM Unknown::Class u'), // unknown, with PAAMAYIM_NEKUDOTAYIM - array('SELECT u FROM Unknown:Class:Name u'), // unknown, with invalid namespace alias - array('SELECT u FROM UnknownClass: u'), // unknown, with invalid namespace alias - array('SELECT u FROM Unknown:Class: u'), // unknown, with invalid namespace alias - array('SELECT u FROM Doctrine\Tests\Models\CMS\\\\CmsUser u'), // syntactically bogus (duplicate \\)array('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser\ u'), // syntactically bogus (trailing \) - array('SELECT u FROM CMS::User u'), - array('SELECT u FROM CMS:User: u'), - array('SELECT u FROM CMS:User:Foo u'), + ['SELECT u FROM UnknownClass u'], // unknown + ['SELECT u FROM Unknown\Class u'], // unknown with namespace + ['SELECT u FROM \Unknown\Class u'], // unknown, leading backslash + ['SELECT u FROM Unknown\\\\Class u'], // unknown, syntactically bogus (duplicate \\) + ['SELECT u FROM Unknown\Class\ u'], // unknown, syntactically bogus (trailing \) + ['SELECT u FROM Unknown:Class u'], // unknown, with namespace alias + ['SELECT u FROM Unknown::Class u'], // unknown, with PAAMAYIM_NEKUDOTAYIM + ['SELECT u FROM Unknown:Class:Name u'], // unknown, with invalid namespace alias + ['SELECT u FROM UnknownClass: u'], // unknown, with invalid namespace alias + ['SELECT u FROM Unknown:Class: u'], // unknown, with invalid namespace alias + ['SELECT u FROM Doctrine\Tests\Models\CMS\\\\CmsUser u'], // syntactically bogus (duplicate \\)array('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser\ u'), // syntactically bogus (trailing \) + ['SELECT u FROM CMS::User u'], + ['SELECT u FROM CMS:User: u'], + ['SELECT u FROM CMS:User:Foo u'], /* Checks for invalid AliasResultVariable */ - array('SELECT \'foo\' AS \foo FROM Doctrine\Tests\Models\CMS\CmsUser u'), - array('SELECT \'foo\' AS \foo\bar FROM Doctrine\Tests\Models\CMS\CmsUser u'), - array('SELECT \'foo\' AS foo\ FROM Doctrine\Tests\Models\CMS\CmsUser u'), - array('SELECT \'foo\' AS foo\\\\bar FROM Doctrine\Tests\Models\CMS\CmsUser u'), - array('SELECT \'foo\' AS foo: FROM Doctrine\Tests\Models\CMS\CmsUser u'), - array('SELECT \'foo\' AS foo:bar FROM Doctrine\Tests\Models\CMS\CmsUser u'), - ); + ['SELECT \'foo\' AS \foo FROM Doctrine\Tests\Models\CMS\CmsUser u'], + ['SELECT \'foo\' AS \foo\bar FROM Doctrine\Tests\Models\CMS\CmsUser u'], + ['SELECT \'foo\' AS foo\ FROM Doctrine\Tests\Models\CMS\CmsUser u'], + ['SELECT \'foo\' AS foo\\\\bar FROM Doctrine\Tests\Models\CMS\CmsUser u'], + ['SELECT \'foo\' AS foo: FROM Doctrine\Tests\Models\CMS\CmsUser u'], + ['SELECT \'foo\' AS foo:bar FROM Doctrine\Tests\Models\CMS\CmsUser u'], + ]; } public function testSelectSingleComponentWithMultipleColumns() @@ -671,7 +673,7 @@ public function testHavingSupportIsNullExpression() { $this->assertValidDQL("SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u HAVING u.username IS NULL"); } - + /** * @group DDC-3085 */ diff --git a/tests/Doctrine/Tests/ORM/Query/LexerTest.php b/tests/Doctrine/Tests/ORM/Query/LexerTest.php index 9c4a889f04b..904b8978786 100644 --- a/tests/Doctrine/Tests/ORM/Query/LexerTest.php +++ b/tests/Doctrine/Tests/ORM/Query/LexerTest.php @@ -161,63 +161,63 @@ public function testScannerTokenizesASimpleQueryCorrectly() $dql = "SELECT u FROM My\Namespace\User u WHERE u.name = 'Jack O''Neil'"; $lexer = new Lexer($dql); - $tokens = array( - array( + $tokens = [ + [ 'value' => 'SELECT', 'type' => Lexer::T_SELECT, 'position' => 0 - ), - array( + ], + [ 'value' => 'u', 'type' => Lexer::T_IDENTIFIER, 'position' => 7 - ), - array( + ], + [ 'value' => 'FROM', 'type' => Lexer::T_FROM, 'position' => 9 - ), - array( + ], + [ 'value' => 'My\Namespace\User', 'type' => Lexer::T_FULLY_QUALIFIED_NAME, 'position' => 14 - ), - array( + ], + [ 'value' => 'u', 'type' => Lexer::T_IDENTIFIER, 'position' => 32 - ), - array( + ], + [ 'value' => 'WHERE', 'type' => Lexer::T_WHERE, 'position' => 34 - ), - array( + ], + [ 'value' => 'u', 'type' => Lexer::T_IDENTIFIER, 'position' => 40 - ), - array( + ], + [ 'value' => '.', 'type' => Lexer::T_DOT, 'position' => 41 - ), - array( + ], + [ 'value' => 'name', 'type' => Lexer::T_IDENTIFIER, 'position' => 42 - ), - array( + ], + [ 'value' => '=', 'type' => Lexer::T_EQUALS, 'position' => 47 - ), - array( + ], + [ 'value' => "Jack O'Neil", 'type' => Lexer::T_STRING, 'position' => 49 - ) - ); + ] + ]; foreach ($tokens as $expected) { $lexer->moveNext(); @@ -232,16 +232,16 @@ public function testScannerTokenizesASimpleQueryCorrectly() public function provideTokens() { - return array( - array(Lexer::T_IDENTIFIER, 'u'), // one char - array(Lexer::T_IDENTIFIER, 'someIdentifier'), - array(Lexer::T_IDENTIFIER, 's0m31d3nt1f13r'), // including digits - array(Lexer::T_IDENTIFIER, 'some_identifier'), // including underscore - array(Lexer::T_IDENTIFIER, '_some_identifier'), // starts with underscore - array(Lexer::T_IDENTIFIER, 'comma'), // name of a token class with value < 100 (whitebox test) - array(Lexer::T_FULLY_QUALIFIED_NAME, 'Some\Class'), // DQL class reference - array(Lexer::T_ALIASED_NAME, 'Some:Name'), - array(Lexer::T_ALIASED_NAME, 'Some:Subclassed\Name') - ); + return [ + [Lexer::T_IDENTIFIER, 'u'], // one char + [Lexer::T_IDENTIFIER, 'someIdentifier'], + [Lexer::T_IDENTIFIER, 's0m31d3nt1f13r'], // including digits + [Lexer::T_IDENTIFIER, 'some_identifier'], // including underscore + [Lexer::T_IDENTIFIER, '_some_identifier'], // starts with underscore + [Lexer::T_IDENTIFIER, 'comma'], // name of a token class with value < 100 (whitebox test) + [Lexer::T_FULLY_QUALIFIED_NAME, 'Some\Class'], // DQL class reference + [Lexer::T_ALIASED_NAME, 'Some:Name'], + [Lexer::T_ALIASED_NAME, 'Some:Subclassed\Name'] + ]; } } diff --git a/tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php b/tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php index 640a9131442..b929f8d18a3 100644 --- a/tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php +++ b/tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php @@ -13,20 +13,20 @@ class ParameterTypeInfererTest extends OrmTestCase public function providerParameterTypeInferer() { - $data = array( - array(1, Type::INTEGER), - array("bar", PDO::PARAM_STR), - array("1", PDO::PARAM_STR), - array(new \DateTime, Type::DATETIME), - array(array(2), Connection::PARAM_INT_ARRAY), - array(array("foo"), Connection::PARAM_STR_ARRAY), - array(array("1","2"), Connection::PARAM_STR_ARRAY), - array(array(), Connection::PARAM_STR_ARRAY), - array(true, Type::BOOLEAN), - ); + $data = [ + [1, Type::INTEGER], + ["bar", PDO::PARAM_STR], + ["1", PDO::PARAM_STR], + [new \DateTime, Type::DATETIME], + [[2], Connection::PARAM_INT_ARRAY], + [["foo"], Connection::PARAM_STR_ARRAY], + [["1","2"], Connection::PARAM_STR_ARRAY], + [[], Connection::PARAM_STR_ARRAY], + [true, Type::BOOLEAN], + ]; if (PHP_VERSION_ID >= 50500) { - $data[] = array(new \DateTimeImmutable(), Type::DATETIME); + $data[] = [new \DateTimeImmutable(), Type::DATETIME]; } return $data; diff --git a/tests/Doctrine/Tests/ORM/Query/ParserResultTest.php b/tests/Doctrine/Tests/ORM/Query/ParserResultTest.php index 086e1d43e2a..0a61d7d31d1 100644 --- a/tests/Doctrine/Tests/ORM/Query/ParserResultTest.php +++ b/tests/Doctrine/Tests/ORM/Query/ParserResultTest.php @@ -26,7 +26,7 @@ public function testSetGetSqlExecutor() { $this->assertNull($this->parserResult->getSqlExecutor()); - $executor = $this->getMockBuilder(AbstractSqlExecutor::class)->setMethods(array('execute'))->getMock(); + $executor = $this->getMockBuilder(AbstractSqlExecutor::class)->setMethods(['execute'])->getMock(); $this->parserResult->setSqlExecutor($executor); $this->assertSame($executor, $this->parserResult->getSqlExecutor()); } @@ -35,7 +35,7 @@ public function testGetSqlParameterPosition() { $this->parserResult->addParameterMapping(1, 1); $this->parserResult->addParameterMapping(1, 2); - $this->assertEquals(array(1, 2), $this->parserResult->getSqlParameterPositions(1)); + $this->assertEquals([1, 2], $this->parserResult->getSqlParameterPositions(1)); } public function testGetParameterMappings() @@ -44,6 +44,6 @@ public function testGetParameterMappings() $this->parserResult->addParameterMapping(1, 1); $this->parserResult->addParameterMapping(1, 2); - $this->assertEquals(array(1 => array(1, 2)), $this->parserResult->getParameterMappings()); + $this->assertEquals([1 => [1, 2]], $this->parserResult->getParameterMappings()); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Query/ParserTest.php b/tests/Doctrine/Tests/ORM/Query/ParserTest.php index fb320773eb5..6b898f80b43 100644 --- a/tests/Doctrine/Tests/ORM/Query/ParserTest.php +++ b/tests/Doctrine/Tests/ORM/Query/ParserTest.php @@ -108,28 +108,29 @@ public function validMatches() * The basic checks that tokens are classified correctly do not belong here * but in LexerTest. */ - return array( - array(Lexer::T_WHERE, 'where'), // keyword - array(Lexer::T_DOT, '.'), // token that cannot be an identifier - array(Lexer::T_IDENTIFIER, 'someIdentifier'), - array(Lexer::T_IDENTIFIER, 'from'), // also a terminal string (the "FROM" keyword) as in DDC-505 - array(Lexer::T_IDENTIFIER, 'comma') // not even a terminal string, but the name of a constant in the Lexer (whitebox test) - ); + return [ + [Lexer::T_WHERE, 'where'], // keyword + [Lexer::T_DOT, '.'], // token that cannot be an identifier + [Lexer::T_IDENTIFIER, 'someIdentifier'], + [Lexer::T_IDENTIFIER, 'from'], // also a terminal string (the "FROM" keyword) as in DDC-505 + [Lexer::T_IDENTIFIER, 'comma'] + // not even a terminal string, but the name of a constant in the Lexer (whitebox test) + ]; } public function invalidMatches() { - return array( - array(Lexer::T_DOT, 'ALL'), // ALL is a terminal string (reserved keyword) and also possibly an identifier - array(Lexer::T_DOT, ','), // "," is a token on its own, but cannot be used as identifier - array(Lexer::T_WHERE, 'WITH'), // as in DDC-3697 - array(Lexer::T_WHERE, '.'), + return [ + [Lexer::T_DOT, 'ALL'], // ALL is a terminal string (reserved keyword) and also possibly an identifier + [Lexer::T_DOT, ','], // "," is a token on its own, but cannot be used as identifier + [Lexer::T_WHERE, 'WITH'], // as in DDC-3697 + [Lexer::T_WHERE, '.'], // The following are qualified or aliased names and must not be accepted where only an Identifier is expected - array(Lexer::T_IDENTIFIER, '\\Some\\Class'), - array(Lexer::T_IDENTIFIER, 'Some\\Class'), - array(Lexer::T_IDENTIFIER, 'Some:Name'), - ); + [Lexer::T_IDENTIFIER, '\\Some\\Class'], + [Lexer::T_IDENTIFIER, 'Some\\Class'], + [Lexer::T_IDENTIFIER, 'Some:Name'], + ]; } private function createParser($dql) diff --git a/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php b/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php index b8d688261a7..7653be5ec10 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php @@ -30,7 +30,7 @@ class QueryExpressionVisitorTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { - $this->visitor = new QueryExpressionVisitor(array('o','p')); + $this->visitor = new QueryExpressionVisitor(['o','p']); } /** @@ -44,7 +44,7 @@ public function testWalkComparison(CriteriaComparison $criteriaExpr, $queryExpr, { $this->assertEquals($queryExpr, $this->visitor->walkComparison($criteriaExpr)); if ($parameter) { - $this->assertEquals(new ArrayCollection(array($parameter)), $this->visitor->getParameters()); + $this->assertEquals(new ArrayCollection([$parameter]), $this->visitor->getParameters()); } } @@ -53,30 +53,30 @@ public function comparisonData() $cb = new CriteriaBuilder(); $qb = new QueryBuilder(); - return array( - array($cb->eq('field', 'value'), $qb->eq('o.field', ':field'), new Parameter('field', 'value')), - array($cb->neq('field', 'value'), $qb->neq('o.field', ':field'), new Parameter('field', 'value')), - array($cb->eq('field', null), $qb->isNull('o.field')), - array($cb->neq('field', null), $qb->isNotNull('o.field')), - array($cb->isNull('field'), $qb->isNull('o.field')), + return [ + [$cb->eq('field', 'value'), $qb->eq('o.field', ':field'), new Parameter('field', 'value')], + [$cb->neq('field', 'value'), $qb->neq('o.field', ':field'), new Parameter('field', 'value')], + [$cb->eq('field', null), $qb->isNull('o.field')], + [$cb->neq('field', null), $qb->isNotNull('o.field')], + [$cb->isNull('field'), $qb->isNull('o.field')], - array($cb->gt('field', 'value'), $qb->gt('o.field', ':field'), new Parameter('field', 'value')), - array($cb->gte('field', 'value'), $qb->gte('o.field', ':field'), new Parameter('field', 'value')), - array($cb->lt('field', 'value'), $qb->lt('o.field', ':field'), new Parameter('field', 'value')), - array($cb->lte('field', 'value'), $qb->lte('o.field', ':field'), new Parameter('field', 'value')), + [$cb->gt('field', 'value'), $qb->gt('o.field', ':field'), new Parameter('field', 'value')], + [$cb->gte('field', 'value'), $qb->gte('o.field', ':field'), new Parameter('field', 'value')], + [$cb->lt('field', 'value'), $qb->lt('o.field', ':field'), new Parameter('field', 'value')], + [$cb->lte('field', 'value'), $qb->lte('o.field', ':field'), new Parameter('field', 'value')], - array($cb->in('field', array('value')), $qb->in('o.field', ':field'), new Parameter('field', array('value'))), - array($cb->notIn('field', array('value')), $qb->notIn('o.field', ':field'), new Parameter('field', array('value'))), + [$cb->in('field', ['value']), $qb->in('o.field', ':field'), new Parameter('field', ['value'])], + [$cb->notIn('field', ['value']), $qb->notIn('o.field', ':field'), new Parameter('field', ['value'])], - array($cb->contains('field', 'value'), $qb->like('o.field', ':field'), new Parameter('field', '%value%')), + [$cb->contains('field', 'value'), $qb->like('o.field', ':field'), new Parameter('field', '%value%')], // Test parameter conversion - array($cb->eq('object.field', 'value'), $qb->eq('o.object.field', ':object_field'), new Parameter('object_field', 'value')), + [$cb->eq('object.field', 'value'), $qb->eq('o.object.field', ':object_field'), new Parameter('object_field', 'value')], // Test alternative rootAlias - array($cb->eq('p.field', 'value'), $qb->eq('p.field', ':p_field'), new Parameter('p_field', 'value')), - array($cb->eq('p.object.field', 'value'), $qb->eq('p.object.field', ':p_object_field'), new Parameter('p_object_field', 'value')), - ); + [$cb->eq('p.field', 'value'), $qb->eq('p.field', ':p_field'), new Parameter('p_field', 'value')], + [$cb->eq('p.object.field', 'value'), $qb->eq('p.object.field', ':p_object_field'), new Parameter('p_object_field', 'value')], + ]; } public function testWalkAndCompositeExpression() diff --git a/tests/Doctrine/Tests/ORM/Query/QueryTest.php b/tests/Doctrine/Tests/ORM/Query/QueryTest.php index 7a3687c5216..e646d670a43 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryTest.php @@ -89,7 +89,7 @@ public function testFluentQueryInterface() ->setHint('foo', 'bar') ->setHint('bar', 'baz') ->setParameter(1, 'bar') - ->setParameters(new ArrayCollection(array(new Parameter(2, 'baz')))) + ->setParameters(new ArrayCollection([new Parameter(2, 'baz')])) ->setResultCacheDriver(null) ->setResultCacheId('foo') ->setDQL('foo') @@ -109,7 +109,7 @@ public function testHints() $this->assertEquals('bar', $q->getHint('foo')); $this->assertEquals('baz', $q->getHint('bar')); - $this->assertEquals(array('foo' => 'bar', 'bar' => 'baz'), $q->getHints()); + $this->assertEquals(['foo' => 'bar', 'bar' => 'baz'], $q->getHints()); $this->assertTrue($q->hasHint('foo')); $this->assertFalse($q->hasHint('barFooBaz')); } @@ -154,11 +154,11 @@ public function testIterateWithDistinct() */ public function testCollectionParameters() { - $cities = array( + $cities = [ 0 => "Paris", 3 => "Canne", 9 => "St Julien" - ); + ]; $query = $this->_em ->createQuery("SELECT a FROM Doctrine\Tests\Models\CMS\CmsAddress a WHERE a.city IN (:cities)") @@ -186,11 +186,11 @@ public function testProcessParameterValueClassMetadata() public function testDefaultQueryHints() { $config = $this->_em->getConfiguration(); - $defaultHints = array( + $defaultHints = [ 'hint_name_1' => 'hint_value_1', 'hint_name_2' => 'hint_value_2', 'hint_name_3' => 'hint_value_3', - ); + ]; $config->setDefaultQueryHints($defaultHints); $query = $this->_em->createQuery(); diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 707973495a2..9a074d60ead 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -37,7 +37,8 @@ protected function setUp() * @param array $queryHints * @param array $queryParams */ - public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed, array $queryHints = array(), array $queryParams = array()) + public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed, array $queryHints = [], array $queryParams = [] + ) { try { $query = $this->_em->createQuery($dqlToBeTested); @@ -75,7 +76,8 @@ public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed, array $qu * @param array $queryHints * @param array $queryParams */ - public function assertInvalidSqlGeneration($dqlToBeTested, $expectedException, array $queryHints = array(), array $queryParams = array()) + public function assertInvalidSqlGeneration($dqlToBeTested, $expectedException, array $queryHints = [], array $queryParams = [] + ) { $this->expectException($expectedException); @@ -107,7 +109,7 @@ public function testJoinWithRangeVariablePutsConditionIntoSqlWhereClause() $this->assertSqlGeneration( 'SELECT c.id FROM Doctrine\Tests\Models\Company\CompanyPerson c JOIN Doctrine\Tests\Models\Company\CompanyPerson r WHERE c.spouse = r AND r.id = 42', 'SELECT c0_.id AS id_0 FROM company_persons c0_ INNER JOIN company_persons c1_ WHERE c0_.spouse_id = c1_.id AND c1_.id = 42', - array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => true) + [ORMQuery::HINT_FORCE_PARTIAL_LOAD => true] ); } @@ -124,7 +126,7 @@ public function testJoinWithRangeVariableAndInheritancePutsConditionIntoSqlWhere $this->assertSqlGeneration( 'SELECT c.id FROM Doctrine\Tests\Models\Company\CompanyPerson c JOIN Doctrine\Tests\Models\Company\CompanyPerson r WHERE c.spouse = r AND r.id = 42', 'SELECT c0_.id AS id_0 FROM company_persons c0_ LEFT JOIN company_managers c1_ ON c0_.id = c1_.id LEFT JOIN company_employees c2_ ON c0_.id = c2_.id INNER JOIN company_persons c3_ LEFT JOIN company_managers c4_ ON c3_.id = c4_.id LEFT JOIN company_employees c5_ ON c3_.id = c5_.id WHERE c0_.spouse_id = c3_.id AND c3_.id = 42', - array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => false) + [ORMQuery::HINT_FORCE_PARTIAL_LOAD => false] ); } @@ -554,7 +556,7 @@ public function testSupportsInstanceOfExpressionsUsingInputParameterInWherePart( $this->assertSqlGeneration( "SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF ?1", "SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.discr AS discr_2 FROM company_persons c0_ WHERE c0_.discr IN (?)", - array(), array(1 => $this->_em->getClassMetadata('Doctrine\Tests\Models\Company\CompanyEmployee')) + [], [1 => $this->_em->getClassMetadata('Doctrine\Tests\Models\Company\CompanyEmployee')] ); } @@ -699,7 +701,7 @@ public function testSupportsMemberOfExpressionManyToManyParameterArray() $group->id = 101; $group2 = new CmsGroup(); $group2->id = 105; - $q->setParameter('param', array($group, $group2)); + $q->setParameter('param', [$group, $group2]); $this->assertEquals( 'SELECT c0_.id AS id_0 FROM cms_users c0_ WHERE EXISTS (SELECT 1 FROM cms_users_groups c1_ INNER JOIN cms_groups c2_ ON c1_.group_id = c2_.id WHERE c1_.user_id = c0_.id AND c2_.id IN (?))', @@ -713,7 +715,7 @@ public function testSupportsMemberOfExpressionSelfReferencing() // Tough one: Many-many self-referencing ("friends") with class table inheritance $q = $this->_em->createQuery('SELECT p FROM Doctrine\Tests\Models\Company\CompanyPerson p WHERE :param MEMBER OF p.friends'); $person = new CompanyPerson(); - $this->_em->getClassMetadata(get_class($person))->setIdentifierValues($person, array('id' => 101)); + $this->_em->getClassMetadata(get_class($person))->setIdentifierValues($person, ['id' => 101]); $q->setParameter('param', $person); $this->assertEquals( 'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.title AS title_2, c2_.salary AS salary_3, c2_.department AS department_4, c2_.startDate AS startDate_5, c0_.discr AS discr_6, c0_.spouse_id AS spouse_id_7, c1_.car_id AS car_id_8 FROM company_persons c0_ LEFT JOIN company_managers c1_ ON c0_.id = c1_.id LEFT JOIN company_employees c2_ ON c0_.id = c2_.id WHERE EXISTS (SELECT 1 FROM company_persons_friends c3_ INNER JOIN company_persons c4_ ON c3_.friend_id = c4_.id WHERE c3_.person_id = c0_.id AND c4_.id IN (?))', @@ -1047,7 +1049,7 @@ public function testPessimisticWriteLockQueryHint() "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 'gblanco'", "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 ". "FROM cms_users c0_ WHERE c0_.username = 'gblanco' FOR UPDATE", - array(ORMQuery::HINT_LOCK_MODE => LockMode::PESSIMISTIC_WRITE) + [ORMQuery::HINT_LOCK_MODE => LockMode::PESSIMISTIC_WRITE] ); } @@ -1063,7 +1065,7 @@ public function testPessimisticReadLockQueryHintPostgreSql() "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 'gblanco'", "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 ". "FROM cms_users c0_ WHERE c0_.username = 'gblanco' FOR SHARE", - array(ORMQuery::HINT_LOCK_MODE => LockMode::PESSIMISTIC_READ) + [ORMQuery::HINT_LOCK_MODE => LockMode::PESSIMISTIC_READ] ); } @@ -1077,7 +1079,7 @@ public function testLockModeNoneQueryHint() "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 'gblanco'", "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 ". "FROM cms_users c0_ WHERE c0_.username = 'gblanco'", - array(ORMQuery::HINT_LOCK_MODE => LockMode::NONE) + [ORMQuery::HINT_LOCK_MODE => LockMode::NONE] ); } @@ -1104,7 +1106,7 @@ public function testPessimisticReadLockQueryHintMySql() "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 'gblanco'", "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 ". "FROM cms_users c0_ WHERE c0_.username = 'gblanco' LOCK IN SHARE MODE", - array(ORMQuery::HINT_LOCK_MODE => LockMode::PESSIMISTIC_READ) + [ORMQuery::HINT_LOCK_MODE => LockMode::PESSIMISTIC_READ] ); } @@ -1120,7 +1122,7 @@ public function testPessimisticReadLockQueryHintOracle() "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 'gblanco'", "SELECT c0_.id AS ID_0, c0_.status AS STATUS_1, c0_.username AS USERNAME_2, c0_.name AS NAME_3 ". "FROM cms_users c0_ WHERE c0_.username = 'gblanco' FOR UPDATE", - array(ORMQuery::HINT_LOCK_MODE => LockMode::PESSIMISTIC_READ) + [ORMQuery::HINT_LOCK_MODE => LockMode::PESSIMISTIC_READ] ); } @@ -1137,7 +1139,7 @@ public function testSupportToCustomDQLFunctions() 'SELECT ABS(c0_.phonenumber) AS sclr_0 FROM cms_phonenumbers c0_' ); - $config->setCustomNumericFunctions(array()); + $config->setCustomNumericFunctions([]); } /** @@ -1441,7 +1443,7 @@ public function testInheritanceTypeJoinInRootClassWithDisabledForcePartialLoad() $this->assertSqlGeneration( 'SELECT p FROM Doctrine\Tests\Models\Company\CompanyPerson p', 'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.title AS title_2, c2_.salary AS salary_3, c2_.department AS department_4, c2_.startDate AS startDate_5, c0_.discr AS discr_6, c0_.spouse_id AS spouse_id_7, c1_.car_id AS car_id_8 FROM company_persons c0_ LEFT JOIN company_managers c1_ ON c0_.id = c1_.id LEFT JOIN company_employees c2_ ON c0_.id = c2_.id', - array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => false) + [ORMQuery::HINT_FORCE_PARTIAL_LOAD => false] ); } @@ -1453,7 +1455,7 @@ public function testInheritanceTypeJoinInRootClassWithEnabledForcePartialLoad() $this->assertSqlGeneration( 'SELECT p FROM Doctrine\Tests\Models\Company\CompanyPerson p', 'SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.discr AS discr_2 FROM company_persons c0_', - array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => true) + [ORMQuery::HINT_FORCE_PARTIAL_LOAD => true] ); } @@ -1465,7 +1467,7 @@ public function testInheritanceTypeJoinInChildClassWithDisabledForcePartialLoad( $this->assertSqlGeneration( 'SELECT e FROM Doctrine\Tests\Models\Company\CompanyEmployee e', 'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, c2_.title AS title_5, c0_.discr AS discr_6, c0_.spouse_id AS spouse_id_7, c2_.car_id AS car_id_8 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id LEFT JOIN company_managers c2_ ON c1_.id = c2_.id', - array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => false) + [ORMQuery::HINT_FORCE_PARTIAL_LOAD => false] ); } @@ -1477,7 +1479,7 @@ public function testInheritanceTypeJoinInChildClassWithEnabledForcePartialLoad() $this->assertSqlGeneration( 'SELECT e FROM Doctrine\Tests\Models\Company\CompanyEmployee e', 'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, c0_.discr AS discr_5 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id', - array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => true) + [ORMQuery::HINT_FORCE_PARTIAL_LOAD => true] ); } @@ -1489,7 +1491,7 @@ public function testInheritanceTypeJoinInLeafClassWithDisabledForcePartialLoad() $this->assertSqlGeneration( 'SELECT m FROM Doctrine\Tests\Models\Company\CompanyManager m', 'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, c2_.title AS title_5, c0_.discr AS discr_6, c0_.spouse_id AS spouse_id_7, c2_.car_id AS car_id_8 FROM company_managers c2_ INNER JOIN company_employees c1_ ON c2_.id = c1_.id INNER JOIN company_persons c0_ ON c2_.id = c0_.id', - array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => false) + [ORMQuery::HINT_FORCE_PARTIAL_LOAD => false] ); } @@ -1501,7 +1503,7 @@ public function testInheritanceTypeJoinInLeafClassWithEnabledForcePartialLoad() $this->assertSqlGeneration( 'SELECT m FROM Doctrine\Tests\Models\Company\CompanyManager m', 'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, c2_.title AS title_5, c0_.discr AS discr_6 FROM company_managers c2_ INNER JOIN company_employees c1_ ON c2_.id = c1_.id INNER JOIN company_persons c0_ ON c2_.id = c0_.id', - array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => true) + [ORMQuery::HINT_FORCE_PARTIAL_LOAD => true] ); } @@ -1513,7 +1515,7 @@ public function testInheritanceTypeSingleTableInRootClassWithDisabledForcePartia $this->assertSqlGeneration( 'SELECT c FROM Doctrine\Tests\Models\Company\CompanyContract c', "SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.fixPrice AS fixPrice_2, c0_.hoursWorked AS hoursWorked_3, c0_.pricePerHour AS pricePerHour_4, c0_.maxPrice AS maxPrice_5, c0_.discr AS discr_6, c0_.salesPerson_id AS salesPerson_id_7 FROM company_contracts c0_ WHERE c0_.discr IN ('fix', 'flexible', 'flexultra')", - array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => false) + [ORMQuery::HINT_FORCE_PARTIAL_LOAD => false] ); } @@ -1525,7 +1527,7 @@ public function testInheritanceTypeSingleTableInRootClassWithEnabledForcePartial $this->assertSqlGeneration( 'SELECT c FROM Doctrine\Tests\Models\Company\CompanyContract c', "SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.fixPrice AS fixPrice_2, c0_.hoursWorked AS hoursWorked_3, c0_.pricePerHour AS pricePerHour_4, c0_.maxPrice AS maxPrice_5, c0_.discr AS discr_6 FROM company_contracts c0_ WHERE c0_.discr IN ('fix', 'flexible', 'flexultra')", - array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => true) + [ORMQuery::HINT_FORCE_PARTIAL_LOAD => true] ); } @@ -1537,7 +1539,7 @@ public function testInheritanceTypeSingleTableInChildClassWithDisabledForceParti $this->assertSqlGeneration( 'SELECT fc FROM Doctrine\Tests\Models\Company\CompanyFlexContract fc', "SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.hoursWorked AS hoursWorked_2, c0_.pricePerHour AS pricePerHour_3, c0_.maxPrice AS maxPrice_4, c0_.discr AS discr_5, c0_.salesPerson_id AS salesPerson_id_6 FROM company_contracts c0_ WHERE c0_.discr IN ('flexible', 'flexultra')", - array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => false) + [ORMQuery::HINT_FORCE_PARTIAL_LOAD => false] ); } @@ -1549,7 +1551,7 @@ public function testInheritanceTypeSingleTableInChildClassWithEnabledForcePartia $this->assertSqlGeneration( 'SELECT fc FROM Doctrine\Tests\Models\Company\CompanyFlexContract fc', "SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.hoursWorked AS hoursWorked_2, c0_.pricePerHour AS pricePerHour_3, c0_.maxPrice AS maxPrice_4, c0_.discr AS discr_5 FROM company_contracts c0_ WHERE c0_.discr IN ('flexible', 'flexultra')", - array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => true) + [ORMQuery::HINT_FORCE_PARTIAL_LOAD => true] ); } @@ -1561,7 +1563,7 @@ public function testInheritanceTypeSingleTableInLeafClassWithDisabledForcePartia $this->assertSqlGeneration( 'SELECT fuc FROM Doctrine\Tests\Models\Company\CompanyFlexUltraContract fuc', "SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.hoursWorked AS hoursWorked_2, c0_.pricePerHour AS pricePerHour_3, c0_.maxPrice AS maxPrice_4, c0_.discr AS discr_5, c0_.salesPerson_id AS salesPerson_id_6 FROM company_contracts c0_ WHERE c0_.discr IN ('flexultra')", - array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => false) + [ORMQuery::HINT_FORCE_PARTIAL_LOAD => false] ); } @@ -1573,7 +1575,7 @@ public function testInheritanceTypeSingleTableInLeafClassWithEnabledForcePartial $this->assertSqlGeneration( 'SELECT fuc FROM Doctrine\Tests\Models\Company\CompanyFlexUltraContract fuc', "SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.hoursWorked AS hoursWorked_2, c0_.pricePerHour AS pricePerHour_3, c0_.maxPrice AS maxPrice_4, c0_.discr AS discr_5 FROM company_contracts c0_ WHERE c0_.discr IN ('flexultra')", - array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => true) + [ORMQuery::HINT_FORCE_PARTIAL_LOAD => true] ); } @@ -1585,7 +1587,7 @@ public function testSelfReferenceWithOneToOneDoesNotDuplicateAlias() $this->assertSqlGeneration( 'SELECT p, pp FROM Doctrine\Tests\Models\Company\CompanyPerson p JOIN p.spouse pp', "SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.title AS title_2, c2_.salary AS salary_3, c2_.department AS department_4, c2_.startDate AS startDate_5, c3_.id AS id_6, c3_.name AS name_7, c4_.title AS title_8, c5_.salary AS salary_9, c5_.department AS department_10, c5_.startDate AS startDate_11, c0_.discr AS discr_12, c0_.spouse_id AS spouse_id_13, c1_.car_id AS car_id_14, c3_.discr AS discr_15, c3_.spouse_id AS spouse_id_16, c4_.car_id AS car_id_17 FROM company_persons c0_ LEFT JOIN company_managers c1_ ON c0_.id = c1_.id LEFT JOIN company_employees c2_ ON c0_.id = c2_.id INNER JOIN company_persons c3_ ON c0_.spouse_id = c3_.id LEFT JOIN company_managers c4_ ON c3_.id = c4_.id LEFT JOIN company_employees c5_ ON c3_.id = c5_.id", - array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => false) + [ORMQuery::HINT_FORCE_PARTIAL_LOAD => false] ); } @@ -2145,7 +2147,7 @@ public function testHavingSupportIsNullExpression() 'SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u HAVING u.username IS NULL', 'SELECT c0_.name AS name_0 FROM cms_users c0_ HAVING c0_.username IS NULL' ); - + $this->assertSqlGeneration( 'SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u HAVING MAX(u.name) IS NULL', 'SELECT c0_.name AS name_0 FROM cms_users c0_ HAVING MAX(c0_.name) IS NULL' @@ -2160,7 +2162,7 @@ public function testClassTableInheritanceJoinWithConditionAppliesToBaseTable() $this->assertSqlGeneration( 'SELECT e.id FROM Doctrine\Tests\Models\Company\CompanyOrganization o JOIN o.events e WITH e.id = ?1', 'SELECT c0_.id AS id_0 FROM company_organizations c1_ INNER JOIN (company_events c0_ LEFT JOIN company_auctions c2_ ON c0_.id = c2_.id LEFT JOIN company_raffles c3_ ON c0_.id = c3_.id) ON c1_.id = c0_.org_id AND (c0_.id = ?)', - array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => false) + [ORMQuery::HINT_FORCE_PARTIAL_LOAD => false] ); } @@ -2238,8 +2240,8 @@ public function testSingleTableInheritanceCreatesOnConditionAndWhere() $this->assertSqlGeneration( 'SELECT e, COUNT(c) FROM Doctrine\Tests\Models\Company\CompanyEmployee e JOIN e.contracts c WHERE e.department = :department', "SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, COUNT(c2_.id) AS sclr_5, c0_.discr AS discr_6 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id INNER JOIN company_contract_employees c3_ ON c1_.id = c3_.employee_id INNER JOIN company_contracts c2_ ON c2_.id = c3_.contract_id AND c2_.discr IN ('fix', 'flexible', 'flexultra') WHERE c1_.department = ?", - array(), - array('department' => 'foobar') + [], + ['department' => 'foobar'] ); } @@ -2264,7 +2266,7 @@ public function testHavingSupportResultVariableLikeExpression() "SELECT c0_.name AS name_0 FROM cms_users c0_ HAVING name_0 LIKE '3'" ); } - + /** * @group DDC-3085 */ diff --git a/tests/Doctrine/Tests/ORM/Query/SqlWalkerTest.php b/tests/Doctrine/Tests/ORM/Query/SqlWalkerTest.php index 263cffc567f..e23ee0117f8 100644 --- a/tests/Doctrine/Tests/ORM/Query/SqlWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SqlWalkerTest.php @@ -24,7 +24,7 @@ class SqlWalkerTest extends OrmTestCase */ protected function setUp() { - $this->sqlWalker = new SqlWalker(new Query($this->_getTestEntityManager()), new ParserResult(), array()); + $this->sqlWalker = new SqlWalker(new Query($this->_getTestEntityManager()), new ParserResult(), []); } /** @@ -53,10 +53,10 @@ public function testGetSQLTableAliasIsSameForMultipleCalls($tableName) */ public function getColumnNamesAndSqlAliases() { - return array( - array('aaaaa', 'a0_'), - array('table', 't0_'), - array('çtable', 't0_'), - ); + return [ + ['aaaaa', 'a0_'], + ['table', 't0_'], + ['çtable', 't0_'], + ]; } } diff --git a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php index acf4d08e699..9418028ecbb 100644 --- a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php +++ b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php @@ -285,7 +285,7 @@ public function testAndWhereIn() $qb->select('u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->where('u.id = :uid') - ->andWhere($qb->expr()->in('u.id', array(1, 2, 3))); + ->andWhere($qb->expr()->in('u.id', [1, 2, 3])); $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid AND u.id IN(1, 2, 3)'); } @@ -296,7 +296,7 @@ public function testOrWhereIn() $qb->select('u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->where('u.id = :uid') - ->orWhere($qb->expr()->in('u.id', array(1, 2, 3))); + ->orWhere($qb->expr()->in('u.id', [1, 2, 3])); $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid OR u.id IN(1, 2, 3)'); } @@ -307,7 +307,7 @@ public function testAndWhereNotIn() $qb->select('u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->where('u.id = :uid') - ->andWhere($qb->expr()->notIn('u.id', array(1, 2, 3))); + ->andWhere($qb->expr()->notIn('u.id', [1, 2, 3])); $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid AND u.id NOT IN(1, 2, 3)'); } @@ -318,7 +318,7 @@ public function testOrWhereNotIn() $qb->select('u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->where('u.id = :uid') - ->orWhere($qb->expr()->notIn('u.id', array(1, 2, 3))); + ->orWhere($qb->expr()->notIn('u.id', [1, 2, 3])); $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid OR u.id NOT IN(1, 2, 3)'); } @@ -528,7 +528,7 @@ public function testAddCriteriaOrder() ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $criteria = new Criteria(); - $criteria->orderBy(array('field' => Criteria::DESC)); + $criteria->orderBy(['field' => Criteria::DESC]); $qb->addCriteria($criteria); @@ -547,7 +547,7 @@ public function testAddCriteriaOrderOnJoinAlias() ->join('u.article','a'); $criteria = new Criteria(); - $criteria->orderBy(array('a.field' => Criteria::DESC)); + $criteria->orderBy(['a.field' => Criteria::DESC]); $qb->addCriteria($criteria); @@ -692,7 +692,7 @@ public function testComplexWhere() $qb = $this->_em->createQueryBuilder(); $orExpr = $qb->expr()->orX(); $orExpr->add($qb->expr()->eq('u.id', ':uid3')); - $orExpr->add($qb->expr()->in('u.id', array(1))); + $orExpr->add($qb->expr()->in('u.id', [1])); $qb->select('u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') @@ -706,11 +706,11 @@ public function testWhereInWithStringLiterals() $qb = $this->_em->createQueryBuilder(); $qb->select('u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') - ->where($qb->expr()->in('u.name', array('one', 'two', 'three'))); + ->where($qb->expr()->in('u.name', ['one', 'two', 'three'])); $this->assertValidQueryBuilder($qb, "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name IN('one', 'two', 'three')"); - $qb->where($qb->expr()->in('u.name', array("O'Reilly", "O'Neil", 'Smith'))); + $qb->where($qb->expr()->in('u.name', ["O'Reilly", "O'Neil", 'Smith'])); $this->assertValidQueryBuilder($qb, "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name IN('O''Reilly', 'O''Neil', 'Smith')"); } @@ -721,11 +721,11 @@ public function testWhereInWithObjectLiterals() $expr = $this->_em->getExpressionBuilder(); $qb->select('u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') - ->where($expr->in('u.name', array($expr->literal('one'), $expr->literal('two'), $expr->literal('three')))); + ->where($expr->in('u.name', [$expr->literal('one'), $expr->literal('two'), $expr->literal('three')])); $this->assertValidQueryBuilder($qb, "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name IN('one', 'two', 'three')"); - $qb->where($expr->in('u.name', array($expr->literal("O'Reilly"), $expr->literal("O'Neil"), $expr->literal('Smith')))); + $qb->where($expr->in('u.name', [$expr->literal("O'Reilly"), $expr->literal("O'Neil"), $expr->literal('Smith')])); $this->assertValidQueryBuilder($qb, "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name IN('O''Reilly', 'O''Neil', 'Smith')"); } @@ -735,7 +735,7 @@ public function testNegation() $expr = $this->_em->getExpressionBuilder(); $orExpr = $expr->orX(); $orExpr->add($expr->eq('u.id', ':uid3')); - $orExpr->add($expr->not($expr->in('u.id', array(1)))); + $orExpr->add($expr->not($expr->in('u.id', [1]))); $qb = $this->_em->createQueryBuilder(); $qb->select('u') @@ -839,7 +839,7 @@ public function testResetDQLParts() ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->where('u.username = ?1')->orderBy('u.username'); - $qb->resetDQLParts(array('where', 'orderBy')); + $qb->resetDQLParts(['where', 'orderBy']); $this->assertEquals(1, count($qb->getDQLPart('select'))); $this->assertNull($qb->getDQLPart('where')); @@ -975,7 +975,7 @@ public function testGetRootAliases() ->select('u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u'); - $this->assertEquals(array('u'), $qb->getRootAliases()); + $this->assertEquals(['u'], $qb->getRootAliases()); } public function testGetRootEntities() @@ -984,7 +984,7 @@ public function testGetRootEntities() ->select('u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u'); - $this->assertEquals(array('Doctrine\Tests\Models\CMS\CmsUser'), $qb->getRootEntities()); + $this->assertEquals(['Doctrine\Tests\Models\CMS\CmsUser'], $qb->getRootEntities()); } public function testGetSeveralRootAliases() @@ -994,7 +994,7 @@ public function testGetSeveralRootAliases() ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u2'); - $this->assertEquals(array('u', 'u2'), $qb->getRootAliases()); + $this->assertEquals(['u', 'u2'], $qb->getRootAliases()); $this->assertEquals('u', $qb->getRootAlias()); } @@ -1003,7 +1003,7 @@ public function testBCAddJoinWithoutRootAlias() $qb = $this->_em->createQueryBuilder() ->select('u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') - ->add('join', array('INNER JOIN u.groups g'), true); + ->add('join', ['INNER JOIN u.groups g'], true); $this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.groups g', $qb->getDQL()); } diff --git a/tests/Doctrine/Tests/ORM/Repository/DefaultRepositoryFactoryTest.php b/tests/Doctrine/Tests/ORM/Repository/DefaultRepositoryFactoryTest.php index bdccb4d7efd..182554c9325 100644 --- a/tests/Doctrine/Tests/ORM/Repository/DefaultRepositoryFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Repository/DefaultRepositoryFactoryTest.php @@ -52,7 +52,7 @@ public function testCreatesRepositoryFromDefaultRepositoryClass() ->entityManager ->expects($this->any()) ->method('getClassMetadata') - ->will($this->returnCallback(array($this, 'buildClassMetadata'))); + ->will($this->returnCallback([$this, 'buildClassMetadata'])); $this->assertInstanceOf( 'Doctrine\\Tests\\Models\\DDC869\\DDC869PaymentRepository', @@ -66,7 +66,7 @@ public function testCreatedRepositoriesAreCached() ->entityManager ->expects($this->any()) ->method('getClassMetadata') - ->will($this->returnCallback(array($this, 'buildClassMetadata'))); + ->will($this->returnCallback([$this, 'buildClassMetadata'])); $this->assertSame( $this->repositoryFactory->getRepository($this->entityManager, __CLASS__), @@ -100,11 +100,11 @@ public function testCachesDistinctRepositoriesPerDistinctEntityManager() $em1 ->expects($this->any()) ->method('getClassMetadata') - ->will($this->returnCallback(array($this, 'buildClassMetadata'))); + ->will($this->returnCallback([$this, 'buildClassMetadata'])); $em2 ->expects($this->any()) ->method('getClassMetadata') - ->will($this->returnCallback(array($this, 'buildClassMetadata'))); + ->will($this->returnCallback([$this, 'buildClassMetadata'])); $repo1 = $this->repositoryFactory->getRepository($em1, __CLASS__); $repo2 = $this->repositoryFactory->getRepository($em2, __CLASS__); diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheCollectionRegionCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheCollectionRegionCommandTest.php index 298ca23a9fb..c8e2abca785 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheCollectionRegionCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheCollectionRegionCommandTest.php @@ -32,9 +32,11 @@ protected function setUp() $this->application = new Application(); $this->command = new CollectionRegionCommand(); - $this->application->setHelperSet(new HelperSet(array( + $this->application->setHelperSet(new HelperSet( + [ 'em' => new EntityManagerHelper($this->_em) - ))); + ] + )); $this->application->add($this->command); } @@ -43,10 +45,12 @@ public function testClearAllRegion() { $command = $this->application->find('orm:clear-cache:region:collection'); $tester = new CommandTester($command); - $tester->execute(array( + $tester->execute( + [ 'command' => $command->getName(), '--all' => true, - ), array('decorated' => false)); + ], ['decorated' => false] + ); $this->assertEquals('Clearing all second-level cache collection regions' . PHP_EOL, $tester->getDisplay()); } @@ -55,11 +59,13 @@ public function testClearByOwnerEntityClassName() { $command = $this->application->find('orm:clear-cache:region:collection'); $tester = new CommandTester($command); - $tester->execute(array( + $tester->execute( + [ 'command' => $command->getName(), 'owner-class' => 'Doctrine\Tests\Models\Cache\State', 'association' => 'cities', - ), array('decorated' => false)); + ], ['decorated' => false] + ); $this->assertEquals('Clearing second-level cache for collection "Doctrine\Tests\Models\Cache\State#cities"' . PHP_EOL, $tester->getDisplay()); } @@ -68,12 +74,14 @@ public function testClearCacheEntryName() { $command = $this->application->find('orm:clear-cache:region:collection'); $tester = new CommandTester($command); - $tester->execute(array( + $tester->execute( + [ 'command' => $command->getName(), 'owner-class' => 'Doctrine\Tests\Models\Cache\State', 'association' => 'cities', 'owner-id' => 1, - ), array('decorated' => false)); + ], ['decorated' => false] + ); $this->assertEquals('Clearing second-level cache entry for collection "Doctrine\Tests\Models\Cache\State#cities" owner entity identified by "1"' . PHP_EOL, $tester->getDisplay()); } @@ -82,12 +90,14 @@ public function testFlushRegionName() { $command = $this->application->find('orm:clear-cache:region:collection'); $tester = new CommandTester($command); - $tester->execute(array( + $tester->execute( + [ 'command' => $command->getName(), 'owner-class' => 'Doctrine\Tests\Models\Cache\State', 'association' => 'cities', '--flush' => true, - ), array('decorated' => false)); + ], ['decorated' => false] + ); $this->assertEquals('Flushing cache provider configured for "Doctrine\Tests\Models\Cache\State#cities"' . PHP_EOL, $tester->getDisplay()); } diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheEntityRegionCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheEntityRegionCommandTest.php index d16fa2e7fa2..b579c14d12d 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheEntityRegionCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheEntityRegionCommandTest.php @@ -32,9 +32,11 @@ protected function setUp() $this->application = new Application(); $this->command = new EntityRegionCommand(); - $this->application->setHelperSet(new HelperSet(array( + $this->application->setHelperSet(new HelperSet( + [ 'em' => new EntityManagerHelper($this->_em) - ))); + ] + )); $this->application->add($this->command); } @@ -43,10 +45,12 @@ public function testClearAllRegion() { $command = $this->application->find('orm:clear-cache:region:entity'); $tester = new CommandTester($command); - $tester->execute(array( + $tester->execute( + [ 'command' => $command->getName(), '--all' => true, - ), array('decorated' => false)); + ], ['decorated' => false] + ); $this->assertEquals('Clearing all second-level cache entity regions' . PHP_EOL, $tester->getDisplay()); } @@ -55,10 +59,12 @@ public function testClearByEntityClassName() { $command = $this->application->find('orm:clear-cache:region:entity'); $tester = new CommandTester($command); - $tester->execute(array( + $tester->execute( + [ 'command' => $command->getName(), 'entity-class' => 'Doctrine\Tests\Models\Cache\Country', - ), array('decorated' => false)); + ], ['decorated' => false] + ); $this->assertEquals('Clearing second-level cache for entity "Doctrine\Tests\Models\Cache\Country"' . PHP_EOL, $tester->getDisplay()); } @@ -67,11 +73,13 @@ public function testClearCacheEntryName() { $command = $this->application->find('orm:clear-cache:region:entity'); $tester = new CommandTester($command); - $tester->execute(array( + $tester->execute( + [ 'command' => $command->getName(), 'entity-class' => 'Doctrine\Tests\Models\Cache\Country', 'entity-id' => 1, - ), array('decorated' => false)); + ], ['decorated' => false] + ); $this->assertEquals('Clearing second-level cache entry for entity "Doctrine\Tests\Models\Cache\Country" identified by "1"' . PHP_EOL, $tester->getDisplay()); } @@ -80,11 +88,13 @@ public function testFlushRegionName() { $command = $this->application->find('orm:clear-cache:region:entity'); $tester = new CommandTester($command); - $tester->execute(array( + $tester->execute( + [ 'command' => $command->getName(), 'entity-class' => 'Doctrine\Tests\Models\Cache\Country', '--flush' => true, - ), array('decorated' => false)); + ], ['decorated' => false] + ); $this->assertEquals('Flushing cache provider configured for entity named "Doctrine\Tests\Models\Cache\Country"' . PHP_EOL, $tester->getDisplay()); } diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheQueryRegionCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheQueryRegionCommandTest.php index 4468faf9638..0d296bf553f 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheQueryRegionCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheQueryRegionCommandTest.php @@ -32,9 +32,11 @@ protected function setUp() $this->application = new Application(); $this->command = new QueryRegionCommand(); - $this->application->setHelperSet(new HelperSet(array( + $this->application->setHelperSet(new HelperSet( + [ 'em' => new EntityManagerHelper($this->_em) - ))); + ] + )); $this->application->add($this->command); } @@ -43,10 +45,12 @@ public function testClearAllRegion() { $command = $this->application->find('orm:clear-cache:region:query'); $tester = new CommandTester($command); - $tester->execute(array( + $tester->execute( + [ 'command' => $command->getName(), '--all' => true, - ), array('decorated' => false)); + ], ['decorated' => false] + ); $this->assertEquals('Clearing all second-level cache query regions' . PHP_EOL, $tester->getDisplay()); } @@ -55,10 +59,12 @@ public function testClearDefaultRegionName() { $command = $this->application->find('orm:clear-cache:region:query'); $tester = new CommandTester($command); - $tester->execute(array( + $tester->execute( + [ 'command' => $command->getName(), 'region-name' => null, - ), array('decorated' => false)); + ], ['decorated' => false] + ); $this->assertEquals('Clearing second-level cache query region named "query_cache_region"' . PHP_EOL, $tester->getDisplay()); } @@ -67,10 +73,12 @@ public function testClearByRegionName() { $command = $this->application->find('orm:clear-cache:region:query'); $tester = new CommandTester($command); - $tester->execute(array( + $tester->execute( + [ 'command' => $command->getName(), 'region-name' => 'my_region', - ), array('decorated' => false)); + ], ['decorated' => false] + ); $this->assertEquals('Clearing second-level cache query region named "my_region"' . PHP_EOL, $tester->getDisplay()); } @@ -79,11 +87,13 @@ public function testFlushRegionName() { $command = $this->application->find('orm:clear-cache:region:query'); $tester = new CommandTester($command); - $tester->execute(array( + $tester->execute( + [ 'command' => $command->getName(), 'region-name' => 'my_region', '--flush' => true, - ), array('decorated' => false)); + ], ['decorated' => false] + ); $this->assertEquals('Flushing cache provider configured for second-level cache query region named "my_region"' . PHP_EOL, $tester->getDisplay()); } diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommandTest.php index af89c866dbf..3e6a0e90486 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommandTest.php @@ -20,6 +20,6 @@ public function testExecution() ->method('writeln') ->with($this->equalTo('No Metadata Classes to process.')); - $command->convertDoctrine1Schema(array(), sys_get_temp_dir(), 'annotation', 4, null, $output); + $command->convertDoctrine1Schema([], sys_get_temp_dir(), 'annotation', 4, null, $output); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php index 08ade299929..e306c34b6f4 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php @@ -35,15 +35,19 @@ protected function setUp() $metadataDriver = $this->_em->getConfiguration()->getMetadataDriverImpl(); - $metadataDriver->addPaths(array( + $metadataDriver->addPaths( + [ __DIR__ . '/../../../../Models/DDC3231/' - )); - + ] + ); + $this->application = new Application(); - $this->application->setHelperSet(new HelperSet(array( + $this->application->setHelperSet(new HelperSet( + [ 'em' => new EntityManagerHelper($this->_em) - ))); + ] + )); $this->application->add(new GenerateRepositoriesCommand()); @@ -54,7 +58,7 @@ protected function setUp() */ public function tearDown() { - $dirs = array(); + $dirs = []; $ri = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->path)); foreach ($ri AS $file) { @@ -133,11 +137,13 @@ private function generateRepositories($filter, $defaultRepository = null) $command = $this->application->find('orm:generate-repositories'); $tester = new CommandTester($command); - $tester->execute(array( + $tester->execute( + [ 'command' => $command->getName(), 'dest-path' => $this->path, '--filter' => $filter, - )); + ] + ); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/InfoCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/InfoCommandTest.php index fb63e4f6402..01a4d13db13 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/InfoCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/InfoCommandTest.php @@ -33,9 +33,11 @@ protected function setUp() $this->application = new Application(); $command = new InfoCommand(); - $this->application->setHelperSet(new HelperSet(array( + $this->application->setHelperSet(new HelperSet( + [ 'em' => new EntityManagerHelper($this->_em) - ))); + ] + )); $this->application->add($command); @@ -45,9 +47,11 @@ protected function setUp() public function testListAllClasses() { - $this->tester->execute(array( + $this->tester->execute( + [ 'command' => $this->command->getName(), - )); + ] + ); $this->assertContains('Doctrine\Tests\Models\Cache\AttractionInfo', $this->tester->getDisplay()); $this->assertContains('Doctrine\Tests\Models\Cache\City', $this->tester->getDisplay()); diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/MappingDescribeCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/MappingDescribeCommandTest.php index 017e94aeede..9f1cec7f490 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/MappingDescribeCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/MappingDescribeCommandTest.php @@ -38,9 +38,11 @@ protected function setUp() $this->application = new Application(); $command = new MappingDescribeCommand(); - $this->application->setHelperSet(new HelperSet(array( + $this->application->setHelperSet(new HelperSet( + [ 'em' => new EntityManagerHelper($this->_em) - ))); + ] + )); $this->application->add($command); @@ -50,10 +52,12 @@ protected function setUp() public function testShowSpecificFuzzySingle() { - $this->tester->execute(array( + $this->tester->execute( + [ 'command' => $this->command->getName(), 'entityName' => 'AttractionInfo', - )); + ] + ); $display = $this->tester->getDisplay(); $this->assertContains('Doctrine\Tests\Models\Cache\AttractionInfo', $display); @@ -66,10 +70,12 @@ public function testShowSpecificFuzzySingle() */ public function testShowSpecificFuzzyAmbiguous() { - $this->tester->execute(array( + $this->tester->execute( + [ 'command' => $this->command->getName(), 'entityName' => 'Attraction', - )); + ] + ); } /** @@ -78,10 +84,12 @@ public function testShowSpecificFuzzyAmbiguous() */ public function testShowSpecificNotFound() { - $this->tester->execute(array( + $this->tester->execute( + [ 'command' => $this->command->getName(), 'entityName' => 'AttractionFooBar' - )); + ] + ); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php index 8a78e497035..aa74ce75305 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php @@ -41,9 +41,11 @@ protected function setUp() $this->application = new Application(); $this->command = new RunDqlCommand(); - $this->application->setHelperSet(new HelperSet(array( + $this->application->setHelperSet(new HelperSet( + [ 'em' => new EntityManagerHelper($this->_em) - ))); + ] + )); $this->application->add($this->command); @@ -62,10 +64,12 @@ public function testWillRunQuery() $this->assertSame( 0, - $this->tester->execute(array( + $this->tester->execute( + [ 'command' => $this->command->getName(), 'dql' => 'SELECT e FROM ' . DateTimeModel::CLASSNAME . ' e', - )) + ] + ) ); $this->assertContains(DateTimeModel::CLASSNAME, $this->tester->getDisplay()); @@ -78,11 +82,13 @@ public function testWillShowQuery() $this->assertSame( 0, - $this->tester->execute(array( + $this->tester->execute( + [ 'command' => $this->command->getName(), 'dql' => 'SELECT e FROM ' . DateTimeModel::CLASSNAME . ' e', '--show-sql' => 'true' - )) + ] + ) ); $this->assertStringMatchesFormat('%Astring%sSELECT %a', $this->tester->getDisplay()); diff --git a/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php b/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php index 6c62ca3526c..ca6192faa29 100644 --- a/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php @@ -33,7 +33,7 @@ protected function _createEntityManager($metadataDriver) $config->setProxyDir(__DIR__ . '/../../Proxies'); $config->setProxyNamespace('Doctrine\Tests\Proxies'); $eventManager = new EventManager(); - $conn = new ConnectionMock(array(), $driverMock, $config, $eventManager); + $conn = new ConnectionMock([], $driverMock, $config, $eventManager); $config->setMetadataDriverImpl($metadataDriver); return EntityManagerMock::create($conn, $config, $eventManager); diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index 89c073fd221..e51bb311658 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -54,32 +54,36 @@ public function tearDown() * * @return ClassMetadataInfo */ - public function generateBookEntityFixture(array $embeddedClasses = array()) + public function generateBookEntityFixture(array $embeddedClasses = []) { $metadata = new ClassMetadataInfo($this->_namespace . '\EntityGeneratorBook'); $metadata->namespace = $this->_namespace; $metadata->customRepositoryClassName = $this->_namespace . '\EntityGeneratorBookRepository'; $metadata->table['name'] = 'book'; - $metadata->table['uniqueConstraints']['name_uniq'] = array('columns' => array('name')); - $metadata->table['indexes']['status_idx'] = array('columns' => array('status')); - $metadata->mapField(array('fieldName' => 'name', 'type' => 'string')); - $metadata->mapField(array('fieldName' => 'status', 'type' => 'string', 'options' => array('default' => 'published'))); - $metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true)); - $metadata->mapOneToOne(array('fieldName' => 'author', 'targetEntity' => 'Doctrine\Tests\ORM\Tools\EntityGeneratorAuthor', 'mappedBy' => 'book')); - $joinColumns = array( - array('name' => 'author_id', 'referencedColumnName' => 'id') + $metadata->table['uniqueConstraints']['name_uniq'] = ['columns' => ['name']]; + $metadata->table['indexes']['status_idx'] = ['columns' => ['status']]; + $metadata->mapField(['fieldName' => 'name', 'type' => 'string']); + $metadata->mapField(['fieldName' => 'status', 'type' => 'string', 'options' => ['default' => 'published']]); + $metadata->mapField(['fieldName' => 'id', 'type' => 'integer', 'id' => true]); + $metadata->mapOneToOne( + ['fieldName' => 'author', 'targetEntity' => 'Doctrine\Tests\ORM\Tools\EntityGeneratorAuthor', 'mappedBy' => 'book'] ); - $metadata->mapManyToMany(array( + $joinColumns = [ + ['name' => 'author_id', 'referencedColumnName' => 'id'] + ]; + $metadata->mapManyToMany( + [ 'fieldName' => 'comments', 'targetEntity' => 'Doctrine\Tests\ORM\Tools\EntityGeneratorComment', 'fetch' => ClassMetadataInfo::FETCH_EXTRA_LAZY, - 'joinTable' => array( + 'joinTable' => [ 'name' => 'book_comment', - 'joinColumns' => array(array('name' => 'book_id', 'referencedColumnName' => 'id')), - 'inverseJoinColumns' => array(array('name' => 'comment_id', 'referencedColumnName' => 'id')), - ), - )); + 'joinColumns' => [['name' => 'book_id', 'referencedColumnName' => 'id']], + 'inverseJoinColumns' => [['name' => 'comment_id', 'referencedColumnName' => 'id']], + ], + ] + ); $metadata->addLifecycleCallback('loading', 'postLoad'); $metadata->addLifecycleCallback('willBeRemoved', 'preRemove'); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); @@ -100,12 +104,12 @@ private function generateEntityTypeFixture(array $field) $metadata->namespace = $this->_namespace; $metadata->table['name'] = 'entity_type'; - $metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true)); + $metadata->mapField(['fieldName' => 'id', 'type' => 'integer', 'id' => true]); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); $name = $field['fieldName']; $type = $field['dbType']; - $metadata->mapField(array('fieldName' => $name, 'type' => $type)); + $metadata->mapField(['fieldName' => $name, 'type' => $type]); $this->_generator->writeEntityClass($metadata, $this->_tmpDir); @@ -115,16 +119,16 @@ private function generateEntityTypeFixture(array $field) /** * @return ClassMetadataInfo */ - private function generateIsbnEmbeddableFixture(array $embeddedClasses = array()) + private function generateIsbnEmbeddableFixture(array $embeddedClasses = []) { $metadata = new ClassMetadataInfo($this->_namespace . '\EntityGeneratorIsbn'); $metadata->namespace = $this->_namespace; $metadata->isEmbeddedClass = true; - $metadata->mapField(array('fieldName' => 'prefix', 'type' => 'integer')); - $metadata->mapField(array('fieldName' => 'groupNumber', 'type' => 'integer')); - $metadata->mapField(array('fieldName' => 'publisherNumber', 'type' => 'integer')); - $metadata->mapField(array('fieldName' => 'titleNumber', 'type' => 'integer')); - $metadata->mapField(array('fieldName' => 'checkDigit', 'type' => 'integer')); + $metadata->mapField(['fieldName' => 'prefix', 'type' => 'integer']); + $metadata->mapField(['fieldName' => 'groupNumber', 'type' => 'integer']); + $metadata->mapField(['fieldName' => 'publisherNumber', 'type' => 'integer']); + $metadata->mapField(['fieldName' => 'titleNumber', 'type' => 'integer']); + $metadata->mapField(['fieldName' => 'checkDigit', 'type' => 'integer']); foreach ($embeddedClasses as $fieldName => $embeddedClass) { $this->mapEmbedded($fieldName, $metadata, $embeddedClass); @@ -143,10 +147,10 @@ private function generateTestEmbeddableFixture() $metadata = new ClassMetadataInfo($this->_namespace . '\EntityGeneratorTestEmbeddable'); $metadata->namespace = $this->_namespace; $metadata->isEmbeddedClass = true; - $metadata->mapField(array('fieldName' => 'field1', 'type' => 'integer')); - $metadata->mapField(array('fieldName' => 'field2', 'type' => 'integer', 'nullable' => true)); - $metadata->mapField(array('fieldName' => 'field3', 'type' => 'datetime')); - $metadata->mapField(array('fieldName' => 'field4', 'type' => 'datetime', 'nullable' => true)); + $metadata->mapField(['fieldName' => 'field1', 'type' => 'integer']); + $metadata->mapField(['fieldName' => 'field2', 'type' => 'integer', 'nullable' => true]); + $metadata->mapField(['fieldName' => 'field3', 'type' => 'datetime']); + $metadata->mapField(['fieldName' => 'field4', 'type' => 'datetime', 'nullable' => true]); $this->_generator->writeEntityClass($metadata, $this->_tmpDir); @@ -166,7 +170,7 @@ private function mapEmbedded( $columnPrefix = false ) { $classMetadata->mapEmbedded( - array('fieldName' => $fieldName, 'class' => $embeddableMetadata->name, 'columnPrefix' => $columnPrefix) + ['fieldName' => $fieldName, 'class' => $embeddableMetadata->name, 'columnPrefix' => $columnPrefix] ); } @@ -181,7 +185,8 @@ private function mapNestedEmbedded( ClassMetadataInfo $embeddableMetadata ) { foreach ($embeddableMetadata->embeddedClasses as $property => $embeddableClass) { - $classMetadata->mapEmbedded(array( + $classMetadata->mapEmbedded( + [ 'fieldName' => $fieldName . '.' . $property, 'class' => $embeddableClass['class'], 'columnPrefix' => $embeddableClass['columnPrefix'], @@ -189,7 +194,8 @@ private function mapNestedEmbedded( ? $fieldName . '.' . $embeddableClass['declaredField'] : $fieldName, 'originalField' => $embeddableClass['originalField'] ?: $property, - )); + ] + ); } } @@ -221,8 +227,8 @@ public function newInstance($metadata) public function testGeneratedEntityClass() { $testMetadata = $this->generateTestEmbeddableFixture(); - $isbnMetadata = $this->generateIsbnEmbeddableFixture(array('test' => $testMetadata)); - $metadata = $this->generateBookEntityFixture(array('isbn' => $isbnMetadata)); + $isbnMetadata = $this->generateIsbnEmbeddableFixture(['test' => $testMetadata]); + $metadata = $this->generateBookEntityFixture(['isbn' => $isbnMetadata]); $book = $this->newInstance($metadata); $this->assertTrue(class_exists($metadata->name), "Class does not exist."); @@ -265,9 +271,9 @@ public function testGeneratedEntityClass() $comment = new EntityGeneratorComment(); $this->assertInstanceOf($metadata->name, $book->addComment($comment)); $this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $book->getComments()); - $this->assertEquals(new ArrayCollection(array($comment)), $book->getComments()); + $this->assertEquals(new ArrayCollection([$comment]), $book->getComments()); $this->assertInternalType('boolean', $book->removeComment($comment)); - $this->assertEquals(new ArrayCollection(array()), $book->getComments()); + $this->assertEquals(new ArrayCollection([]), $book->getComments()); $this->newInstance($isbnMetadata); $isbn = new $isbnMetadata->name(); @@ -282,9 +288,9 @@ public function testGeneratedEntityClass() public function testEntityUpdatingWorks() { - $metadata = $this->generateBookEntityFixture(array('isbn' => $this->generateIsbnEmbeddableFixture())); + $metadata = $this->generateBookEntityFixture(['isbn' => $this->generateIsbnEmbeddableFixture()]); - $metadata->mapField(array('fieldName' => 'test', 'type' => 'string')); + $metadata->mapField(['fieldName' => 'test', 'type' => 'string']); $testEmbeddableMetadata = $this->generateTestEmbeddableFixture(); $this->mapEmbedded('testEmbedded', $metadata, $testEmbeddableMetadata); @@ -326,7 +332,7 @@ public function testEntityUpdatingWorks() */ public function testDoesNotRegenerateExistingMethodsWithDifferentCase() { - $metadata = $this->generateBookEntityFixture(array('isbn' => $this->generateIsbnEmbeddableFixture())); + $metadata = $this->generateBookEntityFixture(['isbn' => $this->generateIsbnEmbeddableFixture()]); // Workaround to change existing fields case (just to simulate the use case) $metadata->fieldMappings['status']['fieldName'] = 'STATUS'; @@ -357,7 +363,7 @@ public function testDoesNotRegenerateExistingMethodsWithDifferentCase() public function testMethodDocBlockShouldStartWithBackSlash() { $embeddedMetadata = $this->generateIsbnEmbeddableFixture(); - $metadata = $this->generateBookEntityFixture(array('isbn' => $embeddedMetadata)); + $metadata = $this->generateBookEntityFixture(['isbn' => $embeddedMetadata]); $book = $this->newInstance($metadata); $this->assertPhpDocVarType('\Doctrine\Common\Collections\Collection', new \ReflectionProperty($book, 'comments')); @@ -404,7 +410,7 @@ public function testLifecycleCallbacks() public function testLoadMetadata() { $embeddedMetadata = $this->generateIsbnEmbeddableFixture(); - $metadata = $this->generateBookEntityFixture(array('isbn' => $embeddedMetadata)); + $metadata = $this->generateBookEntityFixture(['isbn' => $embeddedMetadata]); $book = $this->newInstance($metadata); @@ -443,10 +449,10 @@ public function testLoadPrefixedMetadata() { $this->_generator->setAnnotationPrefix('ORM\\'); $embeddedMetadata = $this->generateIsbnEmbeddableFixture(); - $metadata = $this->generateBookEntityFixture(array('isbn' => $embeddedMetadata)); + $metadata = $this->generateBookEntityFixture(['isbn' => $embeddedMetadata]); $reader = new AnnotationReader(); - $driver = new AnnotationDriver($reader, array()); + $driver = new AnnotationDriver($reader, []); $book = $this->newInstance($metadata); @@ -489,7 +495,7 @@ public function testMappedSuperclassAnnotationGeneration() $this->_generator->writeEntityClass($metadata, $this->_tmpDir); $this->newInstance($metadata); // force instantiation (causes autoloading to kick in) - $driver = new AnnotationDriver(new AnnotationReader(), array()); + $driver = new AnnotationDriver(new AnnotationReader(), []); $cm = new ClassMetadataInfo($metadata->name); $cm->initializeReflection(new RuntimeReflectionService); @@ -521,13 +527,15 @@ public function testGenerateEntityWithSequenceGenerator() { $metadata = new ClassMetadataInfo($this->_namespace . '\DDC1784Entity'); $metadata->namespace = $this->_namespace; - $metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true)); + $metadata->mapField(['fieldName' => 'id', 'type' => 'integer', 'id' => true]); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE); - $metadata->setSequenceGeneratorDefinition(array( + $metadata->setSequenceGeneratorDefinition( + [ 'sequenceName' => 'DDC1784_ID_SEQ', 'allocationSize' => 1, 'initialValue' => 2 - )); + ] + ); $this->_generator->writeEntityClass($metadata, $this->_tmpDir); $filename = $this->_tmpDir . DIRECTORY_SEPARATOR @@ -553,23 +561,25 @@ public function testGenerateEntityWithMultipleInverseJoinColumns() { $metadata = new ClassMetadataInfo($this->_namespace . '\DDC2079Entity'); $metadata->namespace = $this->_namespace; - $metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true)); + $metadata->mapField(['fieldName' => 'id', 'type' => 'integer', 'id' => true]); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE); - $metadata->mapManyToMany(array( + $metadata->mapManyToMany( + [ 'fieldName' => 'centroCustos', 'targetEntity' => 'DDC2079CentroCusto', - 'joinTable' => array( + 'joinTable' => [ 'name' => 'unidade_centro_custo', - 'joinColumns' => array( - array('name' => 'idorcamento', 'referencedColumnName' => 'idorcamento'), - array('name' => 'idunidade', 'referencedColumnName' => 'idunidade') - ), - 'inverseJoinColumns' => array( - array('name' => 'idcentrocusto', 'referencedColumnName' => 'idcentrocusto'), - array('name' => 'idpais', 'referencedColumnName' => 'idpais'), - ), - ), - )); + 'joinColumns' => [ + ['name' => 'idorcamento', 'referencedColumnName' => 'idorcamento'], + ['name' => 'idunidade', 'referencedColumnName' => 'idunidade'] + ], + 'inverseJoinColumns' => [ + ['name' => 'idcentrocusto', 'referencedColumnName' => 'idcentrocusto'], + ['name' => 'idpais', 'referencedColumnName' => 'idpais'], + ], + ], + ] + ); $this->_generator->writeEntityClass($metadata, $this->_tmpDir); $filename = $this->_tmpDir . DIRECTORY_SEPARATOR @@ -838,7 +848,7 @@ public function testMethodsAndPropertiesAreNotDuplicatedInChildClasses() public function testGeneratedMutableEmbeddablesClass() { $embeddedMetadata = $this->generateTestEmbeddableFixture(); - $metadata = $this->generateIsbnEmbeddableFixture(array('test' => $embeddedMetadata)); + $metadata = $this->generateIsbnEmbeddableFixture(['test' => $embeddedMetadata]); $isbn = $this->newInstance($metadata); @@ -878,7 +888,7 @@ public function testGeneratedImmutableEmbeddablesClass() { $this->_generator->setEmbeddablesImmutable(true); $embeddedMetadata = $this->generateTestEmbeddableFixture(); - $metadata = $this->generateIsbnEmbeddableFixture(array('test' => $embeddedMetadata)); + $metadata = $this->generateIsbnEmbeddableFixture(['test' => $embeddedMetadata]); $this->loadEntityClass($embeddedMetadata); $this->loadEntityClass($metadata); @@ -968,86 +978,106 @@ public function testRegenerateEntityClass() */ public function getEntityTypeAliasDataProvider() { - return array( - array(array( + return [ + [ + [ 'fieldName' => 'datetimetz', 'phpType' => '\\DateTime', 'dbType' => 'datetimetz', 'value' => new \DateTime - )), - array(array( + ] + ], + [ + [ 'fieldName' => 'datetime', 'phpType' => '\\DateTime', 'dbType' => 'datetime', 'value' => new \DateTime - )), - array(array( + ] + ], + [ + [ 'fieldName' => 'date', 'phpType' => '\\DateTime', 'dbType' => 'date', 'value' => new \DateTime - )), - array(array( + ] + ], + [ + [ 'fieldName' => 'time', 'phpType' => '\DateTime', 'dbType' => 'time', 'value' => new \DateTime - )), - array(array( + ] + ], + [ + [ 'fieldName' => 'object', 'phpType' => '\stdClass', 'dbType' => 'object', 'value' => new \stdClass() - )), - array(array( + ] + ], + [ + [ 'fieldName' => 'bigint', 'phpType' => 'int', 'dbType' => 'bigint', 'value' => 11 - )), - array(array( + ] + ], + [ + [ 'fieldName' => 'smallint', 'phpType' => 'int', 'dbType' => 'smallint', 'value' => 22 - )), - array(array( + ] + ], + [ + [ 'fieldName' => 'text', 'phpType' => 'string', 'dbType' => 'text', 'value' => 'text' - )), - array(array( + ] + ], + [ + [ 'fieldName' => 'blob', 'phpType' => 'string', 'dbType' => 'blob', 'value' => 'blob' - )), - array(array( + ] + ], + [ + [ 'fieldName' => 'decimal', 'phpType' => 'string', 'dbType' => 'decimal', 'value' => '12.34' - ), - )); + ], + ] + ]; } public function getParseTokensInEntityFileData() { - return array( - array( + return [ + [ '_generator->setRegenerateEntityIfExists(false); $this->_generator->setUpdateEntityIfExists(true); $this->_generator->setFieldVisibility(EntityGenerator::FIELD_VISIBLE_PROTECTED); - + $this->_repositoryGenerator = new EntityRepositoryGenerator(); } @@ -47,7 +47,7 @@ public function setUp() */ public function tearDown() { - $dirs = array(); + $dirs = []; $ri = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->_tmpDir)); foreach ($ri AS $file) { @@ -119,9 +119,9 @@ public function testGeneratedEntityRepositoryClassCustomDefaultRepository() $em = $this->_getTestEntityManager(); $ns = $this->_namespace; - + require_once __DIR__ . '/../../Models/DDC3231/DDC3231User2.php'; - + $className = $ns . '\DDC3231User2Tmp'; $this->writeEntityClass('Doctrine\Tests\Models\DDC3231\DDC3231User2', $className); @@ -131,14 +131,14 @@ public function testGeneratedEntityRepositoryClassCustomDefaultRepository() $this->assertFileExists($rpath); require $rpath; - + $repo = new \ReflectionClass($em->getRepository($className)); $this->assertTrue($repo->inNamespace()); $this->assertSame($className . 'Repository', $repo->getName()); $this->assertSame('Doctrine\Tests\Models\DDC3231\DDC3231EntityRepository', $repo->getParentClass()->getName()); - + require_once __DIR__ . '/../../Models/DDC3231/DDC3231User2NoNamespace.php'; $className2 = 'DDC3231User2NoNamespaceTmp'; @@ -188,10 +188,10 @@ private function writeEntityClass($className, $newClassName) private function writeRepositoryClass($className, $defaultRepository = null) { $this->_repositoryGenerator->setDefaultRepositoryName($defaultRepository); - + $this->_repositoryGenerator->writeEntityRepositoryClass($className . 'Repository', $this->_tmpDir); return $this->_tmpDir . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $className) . 'Repository.php'; } - + } diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php index 5edd47b0313..2cf91c39047 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php @@ -39,7 +39,7 @@ protected function _createEntityManager($metadataDriver) $config->setProxyDir(__DIR__ . '/../../Proxies'); $config->setProxyNamespace('Doctrine\Tests\Proxies'); $eventManager = new EventManager(); - $conn = new ConnectionMock(array(), $driverMock, $config, $eventManager); + $conn = new ConnectionMock([], $driverMock, $config, $eventManager); $config->setMetadataDriverImpl($metadataDriver); return EntityManagerMock::create($conn, $config, $eventManager); @@ -47,18 +47,18 @@ protected function _createEntityManager($metadataDriver) protected function _createMetadataDriver($type, $path) { - $mappingDriver = array( + $mappingDriver = [ 'php' => 'Doctrine\Common\Persistence\Mapping\Driver\PHPDriver', 'annotation' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver', 'xml' => 'Doctrine\ORM\Mapping\Driver\XmlDriver', 'yaml' => 'Doctrine\ORM\Mapping\Driver\YamlDriver', - ); + ]; $this->assertArrayHasKey($type, $mappingDriver, "There is no metadata driver for the type '" . $type . "'."); $class = $mappingDriver[$type]; $driver = ($type === 'annotation') - ? $this->createAnnotationDriver(array($path)) + ? $this->createAnnotationDriver([$path]) : new $class($path); return $driver; @@ -140,7 +140,8 @@ public function testExportedMetadataCanBeReadBackIn() public function testTableIsExported($class) { $this->assertEquals('cms_users', $class->table['name']); - $this->assertEquals(array('engine' => 'MyISAM', 'foo' => array('bar' => 'baz')), + $this->assertEquals( + ['engine' => 'MyISAM', 'foo' => ['bar' => 'baz']], $class->table['options']); return $class; @@ -164,7 +165,7 @@ public function testTypeIsExported($class) public function testIdentifierIsExported($class) { $this->assertEquals(ClassMetadataInfo::GENERATOR_TYPE_IDENTITY, $class->generatorType, "Generator Type wrong"); - $this->assertEquals(array('id'), $class->identifier); + $this->assertEquals(['id'], $class->identifier); $this->assertTrue(isset($class->fieldMappings['id']['id']) && $class->fieldMappings['id']['id'] === true); return $class; @@ -259,7 +260,7 @@ public function testOneToManyAssociationsAreExported($class) //$this->assertInstanceOf('Doctrine\ORM\Mapping\OneToManyMapping', $class->associationMappings['phonenumbers']); $this->assertEquals('Doctrine\Tests\ORM\Tools\Export\Phonenumber', $class->associationMappings['phonenumbers']['targetEntity']); $this->assertEquals('user', $class->associationMappings['phonenumbers']['mappedBy']); - $this->assertEquals(array('number' => 'ASC'), $class->associationMappings['phonenumbers']['orderBy']); + $this->assertEquals(['number' => 'ASC'], $class->associationMappings['phonenumbers']['orderBy']); $this->assertTrue($class->associationMappings['phonenumbers']['isCascadeRemove']); $this->assertTrue($class->associationMappings['phonenumbers']['isCascadePersist']); diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/XmlClassMetadataExporterTest.php b/tests/Doctrine/Tests/ORM/Tools/Export/XmlClassMetadataExporterTest.php index 3eca15f9c28..424412882eb 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/XmlClassMetadataExporterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/XmlClassMetadataExporterTest.php @@ -29,19 +29,23 @@ public function testSequenceGenerator() { $exporter = new XmlExporter(); $metadata = new ClassMetadata('entityTest'); - $metadata->mapField(array( + $metadata->mapField( + [ "fieldName" => 'id', "type" => 'integer', "columnName" => 'id', "id" => true, - )); + ] + ); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE); - $metadata->setSequenceGeneratorDefinition(array( + $metadata->setSequenceGeneratorDefinition( + [ 'sequenceName' => 'seq_entity_test_id', 'allocationSize' => 5, 'initialValue' => 1 - )); + ] + ); $expectedFileContent = <<<'XML' @@ -71,15 +75,17 @@ public function testFieldOptionsExport() { $exporter = new XmlExporter(); $metadata = new ClassMetadata('entityTest'); - $metadata->mapField(array( + $metadata->mapField( + [ "fieldName" => 'myField', "type" => 'string', "columnName" => 'my_field', - "options" => array( + "options" => [ "default" => "default_string", "comment" => "The comment for the field", - ), - )); + ], + ] + ); $expectedFileContent = <<<'XML' diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/php/Doctrine.Tests.ORM.Tools.Export.User.php b/tests/Doctrine/Tests/ORM/Tools/Export/php/Doctrine.Tests.ORM.Tools.Export.User.php index 4a379f82e0a..8fe7425d92b 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/php/Doctrine.Tests.ORM.Tools.Export.User.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/php/Doctrine.Tests.ORM.Tools.Export.User.php @@ -3,128 +3,148 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE); -$metadata->setPrimaryTable(array( +$metadata->setPrimaryTable( + [ 'name' => 'cms_users', - 'options' => array('engine' => 'MyISAM', 'foo' => array('bar' => 'baz')), - )); + 'options' => ['engine' => 'MyISAM', 'foo' => ['bar' => 'baz']], + ] +); $metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT); $metadata->addLifecycleCallback('doStuffOnPrePersist', 'prePersist'); $metadata->addLifecycleCallback('doOtherStuffOnPrePersistToo', 'prePersist'); $metadata->addLifecycleCallback('doStuffOnPostPersist', 'postPersist'); -$metadata->mapField(array( +$metadata->mapField( + [ 'id' => true, 'fieldName' => 'id', 'type' => 'integer', 'columnName' => 'id', - )); -$metadata->mapField(array( + ] +); +$metadata->mapField( + [ 'fieldName' => 'name', 'type' => 'string', 'length' => 50, 'unique' => true, 'nullable' => true, 'columnName' => 'name', - )); -$metadata->mapField(array( + ] +); +$metadata->mapField( + [ 'fieldName' => 'email', 'type' => 'string', 'columnName' => 'user_email', 'columnDefinition' => 'CHAR(32) NOT NULL', - )); -$metadata->mapField(array( + ] +); +$metadata->mapField( + [ 'fieldName' => 'age', 'type' => 'integer', - 'options' => array("unsigned"=>true), - )); + 'options' => ["unsigned"=>true], + ] +); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); -$metadata->mapManyToOne(array( +$metadata->mapManyToOne( + [ 'fieldName' => 'mainGroup', 'targetEntity' => 'Doctrine\\Tests\\ORM\Tools\\Export\\Group', -)); -$metadata->mapOneToOne(array( + ] +); +$metadata->mapOneToOne( + [ 'fieldName' => 'address', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\Export\\Address', 'inversedBy' => 'user', 'cascade' => - array( + [ 0 => 'persist', - ), + ], 'mappedBy' => NULL, 'joinColumns' => - array( + [ 0 => - array( + [ 'name' => 'address_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE', - ), - ), + ], + ], 'orphanRemoval' => true, 'fetch' => ClassMetadataInfo::FETCH_EAGER, - )); -$metadata->mapOneToOne(array( + ] +); +$metadata->mapOneToOne( + [ 'fieldName' => 'cart', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\Export\\Cart', 'mappedBy' => 'user', 'cascade' => - array( + [ 0 => 'persist', - ), + ], 'inversedBy' => NULL, 'orphanRemoval' => false, 'fetch' => ClassMetadataInfo::FETCH_EAGER, -)); -$metadata->mapOneToMany(array( + ] +); +$metadata->mapOneToMany( + [ 'fieldName' => 'phonenumbers', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\Export\\Phonenumber', 'cascade' => - array( + [ 1 => 'persist', 2 => 'merge', - ), + ], 'mappedBy' => 'user', 'orphanRemoval' => true, 'fetch' => ClassMetadataInfo::FETCH_LAZY, 'orderBy' => - array( + [ 'number' => 'ASC', - ), - )); -$metadata->mapManyToMany(array( + ], + ] +); +$metadata->mapManyToMany( + [ 'fieldName' => 'groups', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\Export\\Group', 'fetch' => ClassMetadataInfo::FETCH_EXTRA_LAZY, 'cascade' => - array( + [ 0 => 'remove', 1 => 'persist', 2 => 'refresh', 3 => 'merge', 4 => 'detach', - ), + ], 'mappedBy' => NULL, 'joinTable' => - array( + [ 'name' => 'cms_users_groups', 'joinColumns' => - array( + [ 0 => - array( + [ 'name' => 'user_id', 'referencedColumnName' => 'id', 'unique' => false, 'nullable' => false, - ), - ), + ], + ], 'inverseJoinColumns' => - array( + [ 0 => - array( + [ 'name' => 'group_id', 'referencedColumnName' => 'id', 'columnDefinition' => 'INT NULL', - ), - ), - ), + ], + ], + ], 'orderBy' => NULL, - )); + ] +); diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/CountWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/CountWalkerTest.php index a85a5f6f807..cb085124d6c 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/CountWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/CountWalkerTest.php @@ -14,7 +14,7 @@ public function testCountQuery() { $query = $this->entityManager->createQuery( 'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p JOIN p.category c JOIN p.author a'); - $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\CountWalker')); + $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\CountWalker']); $query->setHint(CountWalker::HINT_DISTINCT, true); $query->setFirstResult(null)->setMaxResults(null); @@ -27,7 +27,7 @@ public function testCountQuery_MixedResultsWithName() { $query = $this->entityManager->createQuery( 'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a'); - $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\CountWalker')); + $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\CountWalker']); $query->setHint(CountWalker::HINT_DISTINCT, true); $query->setFirstResult(null)->setMaxResults(null); @@ -40,7 +40,7 @@ public function testCountQuery_KeepsGroupBy() { $query = $this->entityManager->createQuery( 'SELECT b FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost b GROUP BY b.id'); - $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\CountWalker')); + $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\CountWalker']); $query->setHint(CountWalker::HINT_DISTINCT, true); $query->setFirstResult(null)->setMaxResults(null); @@ -53,7 +53,7 @@ public function testCountQuery_RemovesOrderBy() { $query = $this->entityManager->createQuery( 'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p JOIN p.category c JOIN p.author a ORDER BY a.name'); - $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\CountWalker')); + $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\CountWalker']); $query->setHint(CountWalker::HINT_DISTINCT, true); $query->setFirstResult(null)->setMaxResults(null); @@ -66,7 +66,7 @@ public function testCountQuery_RemovesLimits() { $query = $this->entityManager->createQuery( 'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p JOIN p.category c JOIN p.author a'); - $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\CountWalker')); + $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\CountWalker']); $query->setHint(CountWalker::HINT_DISTINCT, true); $query->setFirstResult(null)->setMaxResults(null); @@ -80,7 +80,7 @@ public function testCountQuery_HavingException() $query = $this->entityManager->createQuery( "SELECT g, COUNT(u.id) AS userCount FROM Doctrine\Tests\Models\CMS\CmsGroup g LEFT JOIN g.users u GROUP BY g.id HAVING userCount > 0" ); - $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\CountWalker')); + $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\CountWalker']); $query->setFirstResult(null)->setMaxResults(null); $this->expectException(\RuntimeException::class); @@ -88,15 +88,15 @@ public function testCountQuery_HavingException() $query->getSQL(); } - + /** - * Arbitrary Join + * Arbitrary Join */ public function testCountQueryWithArbitraryJoin() { $query = $this->entityManager->createQuery( 'SELECT p FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p LEFT JOIN Doctrine\Tests\ORM\Tools\Pagination\Category c WITH p.category = c'); - $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\CountWalker')); + $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\CountWalker']); $query->setHint(CountWalker::HINT_DISTINCT, true); $query->setFirstResult(null)->setMaxResults(null); diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php index 30da257891c..5ccec2e757c 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php @@ -14,11 +14,11 @@ public function testLimitSubquery() $dql = 'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category c JOIN p.author a'; $query = $this->entityManager->createQuery($dql); $limitQuery = clone $query; - - $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker')); + + $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker']); $this->assertEquals( - "SELECT DISTINCT m0_.id AS id_0 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON m0_.category_id = c1_.id INNER JOIN Author a2_ ON m0_.author_id = a2_.id", + "SELECT DISTINCT m0_.id AS id_0 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON m0_.category_id = c1_.id INNER JOIN Author a2_ ON m0_.author_id = a2_.id", $limitQuery->getSQL() ); } @@ -28,11 +28,11 @@ public function testLimitSubqueryWithSort() $dql = 'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category c JOIN p.author a ORDER BY p.title'; $query = $this->entityManager->createQuery($dql); $limitQuery = clone $query; - - $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker')); + + $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker']); $this->assertEquals( - "SELECT DISTINCT m0_.id AS id_0, m0_.title AS title_1 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON m0_.category_id = c1_.id INNER JOIN Author a2_ ON m0_.author_id = a2_.id ORDER BY m0_.title ASC", + "SELECT DISTINCT m0_.id AS id_0, m0_.title AS title_1 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON m0_.category_id = c1_.id INNER JOIN Author a2_ ON m0_.author_id = a2_.id ORDER BY m0_.title ASC", $limitQuery->getSQL() ); } @@ -42,11 +42,11 @@ public function testCountQuery_MixedResultsWithName() $dql = 'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a'; $query = $this->entityManager->createQuery($dql); $limitQuery = clone $query; - - $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker')); + + $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker']); $this->assertEquals( - "SELECT DISTINCT a0_.id AS id_0, sum(a0_.name) AS sclr_1 FROM Author a0_", + "SELECT DISTINCT a0_.id AS id_0, sum(a0_.name) AS sclr_1 FROM Author a0_", $limitQuery->getSQL() ); } @@ -59,28 +59,28 @@ public function testLimitSubqueryWithSortOnAssociation() $dql = 'SELECT p FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p ORDER BY p.author'; $query = $this->entityManager->createQuery($dql); $limitQuery = clone $query; - - $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker')); + + $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker']); $this->assertEquals( - "SELECT DISTINCT m0_.id AS id_0, m0_.author_id AS sclr_1 FROM MyBlogPost m0_ ORDER BY m0_.author_id ASC", + "SELECT DISTINCT m0_.id AS id_0, m0_.author_id AS sclr_1 FROM MyBlogPost m0_ ORDER BY m0_.author_id ASC", $limitQuery->getSQL() ); } - + /** - * Arbitrary Join - */ + * Arbitrary Join + */ public function testLimitSubqueryWithArbitraryJoin() { $dql = 'SELECT p, c FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN Doctrine\Tests\ORM\Tools\Pagination\Category c WITH p.category = c'; $query = $this->entityManager->createQuery($dql); $limitQuery = clone $query; - - $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker')); + + $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker']); $this->assertEquals( - "SELECT DISTINCT m0_.id AS id_0 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON (m0_.category_id = c1_.id)", + "SELECT DISTINCT m0_.id AS id_0 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON (m0_.category_id = c1_.id)", $limitQuery->getSQL() ); } @@ -90,11 +90,11 @@ public function testLimitSubqueryWithSortWithArbitraryJoin() $dql = 'SELECT p, c FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN Doctrine\Tests\ORM\Tools\Pagination\Category c WITH p.category = c ORDER BY p.title'; $query = $this->entityManager->createQuery($dql); $limitQuery = clone $query; - - $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker')); + + $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker']); $this->assertEquals( - "SELECT DISTINCT m0_.id AS id_0, m0_.title AS title_1 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON (m0_.category_id = c1_.id) ORDER BY m0_.title ASC", + "SELECT DISTINCT m0_.id AS id_0, m0_.title AS title_1 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON (m0_.category_id = c1_.id) ORDER BY m0_.title ASC", $limitQuery->getSQL() ); } diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/WhereInWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/WhereInWalkerTest.php index f89ea5704d1..bbe2dcea6a4 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/WhereInWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/WhereInWalkerTest.php @@ -16,7 +16,7 @@ public function testWhereInQuery_NoWhere() 'SELECT u, g FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g' ); $whereInQuery = clone $query; - $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\WhereInWalker')); + $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\WhereInWalker']); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); $this->assertEquals( @@ -30,7 +30,7 @@ public function testCountQuery_MixedResultsWithName() 'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a' ); $whereInQuery = clone $query; - $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\WhereInWalker')); + $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\WhereInWalker']); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); $this->assertEquals( @@ -44,7 +44,7 @@ public function testWhereInQuery_SingleWhere() 'SELECT u, g FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g WHERE 1 = 1' ); $whereInQuery = clone $query; - $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\WhereInWalker')); + $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\WhereInWalker']); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); $this->assertEquals( @@ -58,7 +58,7 @@ public function testWhereInQuery_MultipleWhereWithAnd() 'SELECT u, g FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g WHERE 1 = 1 AND 2 = 2' ); $whereInQuery = clone $query; - $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\WhereInWalker')); + $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\WhereInWalker']); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); $this->assertEquals( @@ -72,7 +72,7 @@ public function testWhereInQuery_MultipleWhereWithOr() 'SELECT u, g FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g WHERE 1 = 1 OR 2 = 2' ); $whereInQuery = clone $query; - $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\WhereInWalker')); + $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\WhereInWalker']); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); $this->assertEquals( @@ -86,7 +86,7 @@ public function testWhereInQuery_MultipleWhereWithMixed_1() 'SELECT u, g FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g WHERE (1 = 1 OR 2 = 2) AND 3 = 3' ); $whereInQuery = clone $query; - $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\WhereInWalker')); + $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\WhereInWalker']); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); $this->assertEquals( @@ -100,7 +100,7 @@ public function testWhereInQuery_MultipleWhereWithMixed_2() 'SELECT u, g FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g WHERE 1 = 1 AND 2 = 2 OR 3 = 3' ); $whereInQuery = clone $query; - $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\WhereInWalker')); + $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\WhereInWalker']); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); $this->assertEquals( @@ -114,36 +114,36 @@ public function testWhereInQuery_WhereNot() 'SELECT u, g FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g WHERE NOT 1 = 2' ); $whereInQuery = clone $query; - $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\WhereInWalker')); + $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\WhereInWalker']); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); $this->assertEquals( "SELECT u0_.id AS id_0, g1_.id AS id_1 FROM User u0_ INNER JOIN user_group u2_ ON u0_.id = u2_.user_id INNER JOIN groups g1_ ON g1_.id = u2_.group_id WHERE (NOT 1 = 2) AND u0_.id IN (?)", $whereInQuery->getSQL() ); } - + /** - * Arbitrary Join + * Arbitrary Join */ public function testWhereInQueryWithArbitraryJoin_NoWhere() { $whereInQuery = $this->entityManager->createQuery( 'SELECT p FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p JOIN Doctrine\Tests\ORM\Tools\Pagination\Category c WITH p.category = c' ); - $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\WhereInWalker')); + $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\WhereInWalker']); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); $this->assertEquals( "SELECT b0_.id AS id_0, b0_.author_id AS author_id_1, b0_.category_id AS category_id_2 FROM BlogPost b0_ INNER JOIN Category c1_ ON (b0_.category_id = c1_.id) WHERE b0_.id IN (?)", $whereInQuery->getSQL() ); } - + public function testWhereInQueryWithArbitraryJoin_SingleWhere() { $whereInQuery = $this->entityManager->createQuery( 'SELECT p FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p JOIN Doctrine\Tests\ORM\Tools\Pagination\Category c WITH p.category = c WHERE 1 = 1' ); - $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\WhereInWalker')); + $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\WhereInWalker']); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); $this->assertEquals( diff --git a/tests/Doctrine/Tests/ORM/Tools/ResolveTargetEntityListenerTest.php b/tests/Doctrine/Tests/ORM/Tools/ResolveTargetEntityListenerTest.php index 28753078d48..d089317c917 100644 --- a/tests/Doctrine/Tests/ORM/Tools/ResolveTargetEntityListenerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/ResolveTargetEntityListenerTest.php @@ -43,12 +43,12 @@ public function testResolveTargetEntityListenerCanResolveTargetEntity() $this->listener->addResolveTargetEntity( 'Doctrine\Tests\ORM\Tools\ResolveTargetInterface', 'Doctrine\Tests\ORM\Tools\ResolveTargetEntity', - array() + [] ); $this->listener->addResolveTargetEntity( 'Doctrine\Tests\ORM\Tools\TargetInterface', 'Doctrine\Tests\ORM\Tools\TargetEntity', - array() + [] ); $evm->addEventSubscriber($this->listener); @@ -73,7 +73,7 @@ public function testResolveTargetEntityListenerCanRetrieveTargetEntityByInterfac $this->listener->addResolveTargetEntity( 'Doctrine\Tests\ORM\Tools\ResolveTargetInterface', 'Doctrine\Tests\ORM\Tools\ResolveTargetEntity', - array() + [] ); $this->em->getEventManager()->addEventSubscriber($this->listener); @@ -92,12 +92,12 @@ public function testAssertTableColumnsAreNotAddedInManyToMany() $this->listener->addResolveTargetEntity( 'Doctrine\Tests\ORM\Tools\ResolveTargetInterface', 'Doctrine\Tests\ORM\Tools\ResolveTargetEntity', - array() + [] ); $this->listener->addResolveTargetEntity( 'Doctrine\Tests\ORM\Tools\TargetInterface', 'Doctrine\Tests\ORM\Tools\TargetEntity', - array() + [] ); $evm->addEventListener(Events::loadClassMetadata, $this->listener); @@ -105,7 +105,7 @@ public function testAssertTableColumnsAreNotAddedInManyToMany() $meta = $cm->associationMappings['manyToMany']; $this->assertSame('Doctrine\Tests\ORM\Tools\TargetEntity', $meta['targetEntity']); - $this->assertEquals(array('resolvetargetentity_id', 'targetinterface_id'), $meta['joinTableColumns']); + $this->assertEquals(['resolvetargetentity_id', 'targetinterface_id'], $meta['joinTableColumns']); } /** @@ -120,7 +120,7 @@ public function testDoesResolveTargetEntitiesInDQLAlsoWithInterfaces() $this->listener->addResolveTargetEntity( 'Doctrine\Tests\ORM\Tools\ResolveTargetInterface', 'Doctrine\Tests\ORM\Tools\ResolveTargetEntity', - array() + [] ); $evm->addEventSubscriber($this->listener); diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php index bc54744b9c3..142ddcb2fa7 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php @@ -15,7 +15,7 @@ public function testAddUniqueIndexForUniqueFieldAnnotation() $em = $this->_getTestEntityManager(); $schemaTool = new SchemaTool($em); - $classes = array( + $classes = [ $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'), $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsArticle'), $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsComment'), @@ -23,12 +23,12 @@ public function testAddUniqueIndexForUniqueFieldAnnotation() $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsGroup'), $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), - ); + ]; $schema = $schemaTool->getSchemaFromMetadata($classes); $this->assertTrue($schema->hasTable('cms_users'), "Table cms_users should exist."); - $this->assertTrue($schema->getTable('cms_users')->columnsAreIndexed(array('username')), "username column should be indexed."); + $this->assertTrue($schema->getTable('cms_users')->columnsAreIndexed(['username']), "username column should be indexed."); } public function testAnnotationOptionsAttribute() @@ -36,13 +36,13 @@ public function testAnnotationOptionsAttribute() $em = $this->_getTestEntityManager(); $schemaTool = new SchemaTool($em); - $classes = array( + $classes = [ $em->getClassMetadata(__NAMESPACE__ . '\\TestEntityWithAnnotationOptionsAttribute'), - ); + ]; $schema = $schemaTool->getSchemaFromMetadata($classes); - $expected = array('foo' => 'bar', 'baz' => array('key' => 'val')); + $expected = ['foo' => 'bar', 'baz' => ['key' => 'val']]; $this->assertEquals($expected, $schema->getTable('TestEntityWithAnnotationOptionsAttribute')->getOptions(), "options annotation are passed to the tables options"); $this->assertEquals($expected, $schema->getTable('TestEntityWithAnnotationOptionsAttribute')->getColumn('test')->getCustomSchemaOptions(), "options annotation are passed to the columns customSchemaOptions"); @@ -62,7 +62,7 @@ public function testPassColumnDefinitionToJoinColumn() $avatar->fieldMappings['id']['columnDefinition'] = $customColumnDef; $user = $em->getClassMetadata('Doctrine\Tests\Models\Forum\ForumUser'); - $classes = array($avatar, $user); + $classes = [$avatar, $user]; $schema = $schemaTool->getSchemaFromMetadata($classes); @@ -81,11 +81,11 @@ public function testPostGenerateEvents() $em = $this->_getTestEntityManager(); $em->getEventManager()->addEventListener( - array(ToolEvents::postGenerateSchemaTable, ToolEvents::postGenerateSchema), $listener + [ToolEvents::postGenerateSchemaTable, ToolEvents::postGenerateSchema], $listener ); $schemaTool = new SchemaTool($em); - $classes = array( + $classes = [ $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'), $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsArticle'), $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsComment'), @@ -93,7 +93,7 @@ public function testPostGenerateEvents() $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsGroup'), $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), - ); + ]; $schema = $schemaTool->getSchemaFromMetadata($classes); @@ -106,16 +106,16 @@ public function testNullDefaultNotAddedToCustomSchemaOptions() $em = $this->_getTestEntityManager(); $schemaTool = new SchemaTool($em); - $classes = array( + $classes = [ $em->getClassMetadata('Doctrine\Tests\Models\NullDefault\NullDefaultColumn'), - ); + ]; $customSchemaOptions = $schemaTool->getSchemaFromMetadata($classes) ->getTable('NullDefaultColumn') ->getColumn('nullDefault') ->getCustomSchemaOptions(); - $this->assertSame(array(), $customSchemaOptions); + $this->assertSame([], $customSchemaOptions); } /** @@ -247,4 +247,4 @@ class SecondEntity * @Column(name="name") */ public $name; -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php index a17d92e7f98..627a7b6a6df 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php @@ -26,49 +26,61 @@ public function setUp() public function testCmsModelSet() { - $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths(array( + $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths( + [ __DIR__ . "/../../Models/CMS" - )); + ] + ); $this->validator->validateMapping(); } public function testCompanyModelSet() { - $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths(array( + $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths( + [ __DIR__ . "/../../Models/Company" - )); + ] + ); $this->validator->validateMapping(); } public function testECommerceModelSet() { - $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths(array( + $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths( + [ __DIR__ . "/../../Models/ECommerce" - )); + ] + ); $this->validator->validateMapping(); } public function testForumModelSet() { - $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths(array( + $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths( + [ __DIR__ . "/../../Models/Forum" - )); + ] + ); $this->validator->validateMapping(); } public function testNavigationModelSet() { - $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths(array( + $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths( + [ __DIR__ . "/../../Models/Navigation" - )); + ] + ); $this->validator->validateMapping(); } public function testRoutingModelSet() { - $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths(array( + $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths( + [ __DIR__ . "/../../Models/Routing" - )); + ] + ); $this->validator->validateMapping(); } @@ -83,10 +95,10 @@ public function testInvalidManyToManyJoinColumnSchema() $ce = $this->validator->validateClass($class1); $this->assertEquals( - array( + [ "The inverse join columns of the many-to-many table 'Entity1Entity2' have to contain to ALL identifier columns of the target entity 'Doctrine\Tests\ORM\Tools\InvalidEntity2', however 'key4' are missing.", "The join columns of the many-to-many table 'Entity1Entity2' have to contain to ALL identifier columns of the source entity 'Doctrine\Tests\ORM\Tools\InvalidEntity1', however 'key2' are missing." - ), + ], $ce ); } @@ -102,10 +114,10 @@ public function testInvalidToOneJoinColumnSchema() $ce = $this->validator->validateClass($class2); $this->assertEquals( - array( + [ "The referenced column name 'id' has to be a primary key column on the target entity class 'Doctrine\Tests\ORM\Tools\InvalidEntity1'.", "The join columns of the association 'assoc' have to match to ALL identifier columns of the target entity 'Doctrine\Tests\ORM\Tools\InvalidEntity1', however 'key1, key2' are missing." - ), + ], $ce ); } @@ -120,7 +132,7 @@ public function testValidOneToOneAsIdentifierSchema() $ce = $this->validator->validateClass($class1); - $this->assertEquals(array(), $ce); + $this->assertEquals([], $ce); } /** @@ -131,10 +143,11 @@ public function testInvalidTripleAssociationAsKeyMapping() $classThree = $this->em->getClassMetadata(__NAMESPACE__ . '\DDC1649Three'); $ce = $this->validator->validateClass($classThree); - $this->assertEquals(Array( + $this->assertEquals( + [ "Cannot map association 'Doctrine\Tests\ORM\Tools\DDC1649Three#two as identifier, because the target entity 'Doctrine\Tests\ORM\Tools\DDC1649Two' also maps an association as identifier.", "The referenced column name 'id' has to be a primary key column on the target entity class 'Doctrine\Tests\ORM\Tools\DDC1649Two'." - ), $ce); + ], $ce); } /** @@ -146,11 +159,11 @@ public function testInvalidBiDirectionalRelationMappingMissingInversedByAttribut $ce = $this->validator->validateClass($class); $this->assertEquals( - array( + [ "The field Doctrine\Tests\ORM\Tools\DDC3274One#two is on the inverse side of a bi-directional " . "relationship, but the specified mappedBy association on the target-entity " . "Doctrine\Tests\ORM\Tools\DDC3274Two#one does not contain the required 'inversedBy=\"two\"' attribute." - ), + ], $ce ); } @@ -164,10 +177,10 @@ public function testInvalidOrderByInvalidField() $ce = $this->validator->validateClass($class); $this->assertEquals( - array( + [ "The association Doctrine\Tests\ORM\Tools\DDC3322One#invalidAssoc is ordered by a foreign field " . "invalidField that is not a field on the target entity Doctrine\Tests\ORM\Tools\DDC3322ValidEntity1." - ), + ], $ce ); } @@ -181,10 +194,10 @@ public function testInvalidOrderByCollectionValuedAssociation() $ce = $this->validator->validateClass($class); $this->assertEquals( - array( + [ "The association Doctrine\Tests\ORM\Tools\DDC3322Two#invalidAssoc is ordered by a field oneToMany " . "on Doctrine\Tests\ORM\Tools\DDC3322ValidEntity1 that is a collection-valued association." - ), + ], $ce ); } @@ -198,10 +211,10 @@ public function testInvalidOrderByAssociationInverseSide() $ce = $this->validator->validateClass($class); $this->assertEquals( - array( + [ "The association Doctrine\Tests\ORM\Tools\DDC3322Three#invalidAssoc is ordered by a field oneToOneInverse " . "on Doctrine\Tests\ORM\Tools\DDC3322ValidEntity1 that is the inverse side of an association." - ), + ], $ce ); } diff --git a/tests/Doctrine/Tests/ORM/Tools/SetupTest.php b/tests/Doctrine/Tests/ORM/Tools/SetupTest.php index 06ef2a07a90..0709d525638 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SetupTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SetupTest.php @@ -47,7 +47,7 @@ public function testDirectoryAutoload() public function testAnnotationConfiguration() { - $config = Setup::createAnnotationMetadataConfiguration(array(), true); + $config = Setup::createAnnotationMetadataConfiguration([], true); $this->assertInstanceOf('Doctrine\ORM\Configuration', $config); $this->assertEquals(sys_get_temp_dir(), $config->getProxyDir()); @@ -57,7 +57,7 @@ public function testAnnotationConfiguration() public function testXMLConfiguration() { - $config = Setup::createXMLMetadataConfiguration(array(), true); + $config = Setup::createXMLMetadataConfiguration([], true); $this->assertInstanceOf('Doctrine\ORM\Configuration', $config); $this->assertInstanceOf('Doctrine\ORM\Mapping\Driver\XmlDriver', $config->getMetadataDriverImpl()); @@ -65,7 +65,7 @@ public function testXMLConfiguration() public function testYAMLConfiguration() { - $config = Setup::createYAMLMetadataConfiguration(array(), true); + $config = Setup::createYAMLMetadataConfiguration([], true); $this->assertInstanceOf('Doctrine\ORM\Configuration', $config); $this->assertInstanceOf('Doctrine\ORM\Mapping\Driver\YamlDriver', $config->getMetadataDriverImpl()); @@ -76,7 +76,7 @@ public function testYAMLConfiguration() */ public function testConfigureProxyDir() { - $config = Setup::createAnnotationMetadataConfiguration(array(), true, "/foo"); + $config = Setup::createAnnotationMetadataConfiguration([], true, "/foo"); $this->assertEquals('/foo', $config->getProxyDir()); } @@ -86,7 +86,7 @@ public function testConfigureProxyDir() public function testConfigureCache() { $cache = new ArrayCache(); - $config = Setup::createAnnotationMetadataConfiguration(array(), true, null, $cache); + $config = Setup::createAnnotationMetadataConfiguration([], true, null, $cache); $this->assertSame($cache, $config->getResultCacheImpl()); $this->assertSame($cache, $config->getMetadataCacheImpl()); @@ -99,7 +99,7 @@ public function testConfigureCache() public function testConfigureCacheCustomInstance() { $cache = $this->createMock(Cache::class); - $config = Setup::createConfiguration(array(), true, $cache); + $config = Setup::createConfiguration([], true, $cache); $this->assertSame($cache, $config->getResultCacheImpl()); $this->assertSame($cache, $config->getMetadataCacheImpl()); diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 5a32d2882b9..42aadd431e1 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -52,7 +52,7 @@ class UnitOfWorkTest extends OrmTestCase protected function setUp() { parent::setUp(); - $this->_connectionMock = new ConnectionMock(array(), new DriverMock()); + $this->_connectionMock = new ConnectionMock([], new DriverMock()); $this->_emMock = EntityManagerMock::create($this->_connectionMock); // SUT $this->_unitOfWork = new UnitOfWorkMock($this->_emMock); @@ -168,7 +168,7 @@ public function testChangeTrackingNotify() $this->assertTrue($this->_unitOfWork->isScheduledForDirtyCheck($entity)); - $this->assertEquals(array('data' => array('thedata', 'newdata')), $this->_unitOfWork->getEntityChangeSet($entity)); + $this->assertEquals(['data' => ['thedata', 'newdata']], $this->_unitOfWork->getEntityChangeSet($entity)); $item = new NotifyChangedRelatedItem(); $entity->getItems()->add($item); @@ -215,7 +215,7 @@ public function testGetEntityStateWithAssignedIdentity() $persister->reset(); // if the entity is already managed the exists() check should be skipped - $this->_unitOfWork->registerManaged($ph, array('phonenumber' => '12345'), array()); + $this->_unitOfWork->registerManaged($ph, ['phonenumber' => '12345'], []); $this->assertEquals(UnitOfWork::STATE_MANAGED, $this->_unitOfWork->getEntityState($ph)); $this->assertFalse($persister->isExistsCalled()); $ph2 = new CmsPhonenumber(); @@ -319,7 +319,7 @@ public function testRemovedAndRePersistedEntitiesAreInTheIdentityMapAndAreNotGar $entity = new ForumUser(); $entity->id = 123; - $this->_unitOfWork->registerManaged($entity, array('id' => 123), array()); + $this->_unitOfWork->registerManaged($entity, ['id' => 123], []); $this->assertTrue($this->_unitOfWork->isInIdentityMap($entity)); $this->_unitOfWork->remove($entity); @@ -497,7 +497,7 @@ public function testObjectHashesOfMergedEntitiesAreNotUsedInOriginalEntityDataMa */ class NotifyChangedEntity implements NotifyPropertyChanged { - private $_listeners = array(); + private $_listeners = []; /** * @Id * @Column(type="integer") diff --git a/tests/Doctrine/Tests/ORM/Utility/IdentifierFlattenerTest.php b/tests/Doctrine/Tests/ORM/Utility/IdentifierFlattenerTest.php index dad6ce4b358..384d04328c0 100644 --- a/tests/Doctrine/Tests/ORM/Utility/IdentifierFlattenerTest.php +++ b/tests/Doctrine/Tests/ORM/Utility/IdentifierFlattenerTest.php @@ -36,12 +36,12 @@ protected function setUp() try { $this->_schemaTool->createSchema( - array( + [ $this->_em->getClassMetadata('Doctrine\Tests\Models\VersionedOneToOne\FirstRelatedEntity'), $this->_em->getClassMetadata('Doctrine\Tests\Models\VersionedOneToOne\SecondRelatedEntity'), $this->_em->getClassMetadata('Doctrine\Tests\Models\Cache\Flight'), $this->_em->getClassMetadata('Doctrine\Tests\Models\Cache\City') - ) + ] ); } catch (ORMException $e) { } @@ -66,7 +66,7 @@ public function testFlattenIdentifierWithOneToOneId() $this->_em->flush(); $firstEntity = $this->_em->getRepository('Doctrine\Tests\Models\VersionedOneToOne\FirstRelatedEntity') - ->findOneBy(array('name' => 'Fred')); + ->findOneBy(['name' => 'Fred']); $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\VersionedOneToOne\FirstRelatedEntity'); diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index a6a3bece4ad..b6d2f005ced 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -63,29 +63,29 @@ abstract class OrmFunctionalTestCase extends OrmTestCase * * @var array */ - protected $_usedModelSets = array(); + protected $_usedModelSets = []; /** * Whether the database schema has already been created. * * @var array */ - protected static $_tablesCreated = array(); + protected static $_tablesCreated = []; /** * Array of entity class name to their tables that were created. * * @var array */ - protected static $_entityTablesCreated = array(); + protected static $_entityTablesCreated = []; /** * List of model sets and their classes. * * @var array */ - protected static $_modelSets = array( - 'cms' => array( + protected static $_modelSets = [ + 'cms' => [ 'Doctrine\Tests\Models\CMS\CmsUser', 'Doctrine\Tests\Models\CMS\CmsPhonenumber', 'Doctrine\Tests\Models\CMS\CmsAddress', @@ -94,9 +94,9 @@ abstract class OrmFunctionalTestCase extends OrmTestCase 'Doctrine\Tests\Models\CMS\CmsTag', 'Doctrine\Tests\Models\CMS\CmsArticle', 'Doctrine\Tests\Models\CMS\CmsComment', - ), - 'forum' => array(), - 'company' => array( + ], + 'forum' => [], + 'company' => [ 'Doctrine\Tests\Models\Company\CompanyPerson', 'Doctrine\Tests\Models\Company\CompanyEmployee', 'Doctrine\Tests\Models\Company\CompanyManager', @@ -106,40 +106,40 @@ abstract class OrmFunctionalTestCase extends OrmTestCase 'Doctrine\Tests\Models\Company\CompanyRaffle', 'Doctrine\Tests\Models\Company\CompanyCar', 'Doctrine\Tests\Models\Company\CompanyContract', - ), - 'ecommerce' => array( + ], + 'ecommerce' => [ 'Doctrine\Tests\Models\ECommerce\ECommerceCart', 'Doctrine\Tests\Models\ECommerce\ECommerceCustomer', 'Doctrine\Tests\Models\ECommerce\ECommerceProduct', 'Doctrine\Tests\Models\ECommerce\ECommerceShipping', 'Doctrine\Tests\Models\ECommerce\ECommerceFeature', 'Doctrine\Tests\Models\ECommerce\ECommerceCategory' - ), - 'generic' => array( + ], + 'generic' => [ 'Doctrine\Tests\Models\Generic\BooleanModel', 'Doctrine\Tests\Models\Generic\DateTimeModel', 'Doctrine\Tests\Models\Generic\DecimalModel', 'Doctrine\Tests\Models\Generic\SerializationModel', - ), - 'routing' => array( + ], + 'routing' => [ 'Doctrine\Tests\Models\Routing\RoutingLeg', 'Doctrine\Tests\Models\Routing\RoutingLocation', 'Doctrine\Tests\Models\Routing\RoutingRoute', 'Doctrine\Tests\Models\Routing\RoutingRouteBooking', - ), - 'navigation' => array( + ], + 'navigation' => [ 'Doctrine\Tests\Models\Navigation\NavUser', 'Doctrine\Tests\Models\Navigation\NavCountry', 'Doctrine\Tests\Models\Navigation\NavPhotos', 'Doctrine\Tests\Models\Navigation\NavTour', 'Doctrine\Tests\Models\Navigation\NavPointOfInterest', - ), - 'directorytree' => array( + ], + 'directorytree' => [ 'Doctrine\Tests\Models\DirectoryTree\AbstractContentItem', 'Doctrine\Tests\Models\DirectoryTree\File', 'Doctrine\Tests\Models\DirectoryTree\Directory', - ), - 'ddc117' => array( + ], + 'ddc117' => [ 'Doctrine\Tests\Models\DDC117\DDC117Article', 'Doctrine\Tests\Models\DDC117\DDC117Reference', 'Doctrine\Tests\Models\DDC117\DDC117Translation', @@ -147,42 +147,42 @@ abstract class OrmFunctionalTestCase extends OrmTestCase 'Doctrine\Tests\Models\DDC117\DDC117ApproveChanges', 'Doctrine\Tests\Models\DDC117\DDC117Editor', 'Doctrine\Tests\Models\DDC117\DDC117Link', - ), - 'ddc3699' => array( + ], + 'ddc3699' => [ 'Doctrine\Tests\Models\DDC3699\DDC3699Parent', 'Doctrine\Tests\Models\DDC3699\DDC3699RelationOne', 'Doctrine\Tests\Models\DDC3699\DDC3699RelationMany', 'Doctrine\Tests\Models\DDC3699\DDC3699Child', - ), - 'stockexchange' => array( + ], + 'stockexchange' => [ 'Doctrine\Tests\Models\StockExchange\Bond', 'Doctrine\Tests\Models\StockExchange\Stock', 'Doctrine\Tests\Models\StockExchange\Market', - ), - 'legacy' => array( + ], + 'legacy' => [ 'Doctrine\Tests\Models\Legacy\LegacyUser', 'Doctrine\Tests\Models\Legacy\LegacyUserReference', 'Doctrine\Tests\Models\Legacy\LegacyArticle', 'Doctrine\Tests\Models\Legacy\LegacyCar', - ), - 'customtype' => array( + ], + 'customtype' => [ 'Doctrine\Tests\Models\CustomType\CustomTypeChild', 'Doctrine\Tests\Models\CustomType\CustomTypeParent', 'Doctrine\Tests\Models\CustomType\CustomTypeUpperCase', - ), - 'compositekeyinheritance' => array( + ], + 'compositekeyinheritance' => [ 'Doctrine\Tests\Models\CompositeKeyInheritance\JoinedRootClass', 'Doctrine\Tests\Models\CompositeKeyInheritance\JoinedChildClass', 'Doctrine\Tests\Models\CompositeKeyInheritance\SingleRootClass', 'Doctrine\Tests\Models\CompositeKeyInheritance\SingleChildClass', - ), - 'taxi' => array( + ], + 'taxi' => [ 'Doctrine\Tests\Models\Taxi\PaidRide', 'Doctrine\Tests\Models\Taxi\Ride', 'Doctrine\Tests\Models\Taxi\Car', 'Doctrine\Tests\Models\Taxi\Driver', - ), - 'cache' => array( + ], + 'cache' => [ 'Doctrine\Tests\Models\Cache\Country', 'Doctrine\Tests\Models\Cache\State', 'Doctrine\Tests\Models\Cache\City', @@ -205,102 +205,102 @@ abstract class OrmFunctionalTestCase extends OrmTestCase 'Doctrine\Tests\Models\Cache\AttractionInfo', 'Doctrine\Tests\Models\Cache\AttractionContactInfo', 'Doctrine\Tests\Models\Cache\AttractionLocationInfo' - ), - 'tweet' => array( + ], + 'tweet' => [ 'Doctrine\Tests\Models\Tweet\User', 'Doctrine\Tests\Models\Tweet\Tweet', 'Doctrine\Tests\Models\Tweet\UserList', - ), - 'ddc2504' => array( + ], + 'ddc2504' => [ 'Doctrine\Tests\Models\DDC2504\DDC2504RootClass', 'Doctrine\Tests\Models\DDC2504\DDC2504ChildClass', 'Doctrine\Tests\Models\DDC2504\DDC2504OtherClass', - ), - 'ddc3346' => array( + ], + 'ddc3346' => [ 'Doctrine\Tests\Models\DDC3346\DDC3346Author', 'Doctrine\Tests\Models\DDC3346\DDC3346Article', - ), - 'quote' => array( + ], + 'quote' => [ 'Doctrine\Tests\Models\Quote\Address', 'Doctrine\Tests\Models\Quote\Group', 'Doctrine\Tests\Models\Quote\NumericEntity', 'Doctrine\Tests\Models\Quote\Phone', 'Doctrine\Tests\Models\Quote\User' - ), - 'vct_onetoone' => array( + ], + 'vct_onetoone' => [ 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneEntity', 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneEntity' - ), - 'vct_onetoone_compositeid' => array( + ], + 'vct_onetoone_compositeid' => [ 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdEntity', 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdEntity' - ), - 'vct_onetoone_compositeid_foreignkey' => array( + ], + 'vct_onetoone_compositeid_foreignkey' => [ 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity' - ), - 'vct_onetomany' => array( + ], + 'vct_onetomany' => [ 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyEntity', 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneEntity' - ), - 'vct_onetomany_compositeid' => array( + ], + 'vct_onetomany_compositeid' => [ 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdEntity', 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdEntity' - ), - 'vct_onetomany_compositeid_foreignkey' => array( + ], + 'vct_onetomany_compositeid_foreignkey' => [ 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdForeignKeyEntity' - ), - 'vct_onetomany_extralazy' => array( + ], + 'vct_onetomany_extralazy' => [ 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyExtraLazyEntity', 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneExtraLazyEntity' - ), - 'vct_manytomany' => array( + ], + 'vct_manytomany' => [ 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyEntity', 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyEntity' - ), - 'vct_manytomany_compositeid' => array( + ], + 'vct_manytomany_compositeid' => [ 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdEntity', 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdEntity' - ), - 'vct_manytomany_compositeid_foreignkey' => array( + ], + 'vct_manytomany_compositeid_foreignkey' => [ 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdForeignKeyEntity' - ), - 'vct_manytomany_extralazy' => array( + ], + 'vct_manytomany_extralazy' => [ 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyExtraLazyEntity', 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyExtraLazyEntity' - ), - 'geonames' => array( + ], + 'geonames' => [ 'Doctrine\Tests\Models\GeoNames\Country', 'Doctrine\Tests\Models\GeoNames\Admin1', 'Doctrine\Tests\Models\GeoNames\Admin1AlternateName', 'Doctrine\Tests\Models\GeoNames\City' - ), - 'custom_id_object_type' => array( + ], + 'custom_id_object_type' => [ 'Doctrine\Tests\Models\CustomType\CustomIdObjectTypeParent', 'Doctrine\Tests\Models\CustomType\CustomIdObjectTypeChild', - ), - 'pagination' => array( + ], + 'pagination' => [ 'Doctrine\Tests\Models\Pagination\Company', 'Doctrine\Tests\Models\Pagination\Logo', 'Doctrine\Tests\Models\Pagination\Department', 'Doctrine\Tests\Models\Pagination\User', 'Doctrine\Tests\Models\Pagination\User1', - ), - 'versioned_many_to_one' => array( + ], + 'versioned_many_to_one' => [ 'Doctrine\Tests\Models\VersionedManyToOne\Category', 'Doctrine\Tests\Models\VersionedManyToOne\Article', - ), - 'issue5989' => array( + ], + 'issue5989' => [ 'Doctrine\Tests\Models\Issue5989\Issue5989Person', 'Doctrine\Tests\Models\Issue5989\Issue5989Employee', 'Doctrine\Tests\Models\Issue5989\Issue5989Manager', - ), - ); + ], + ]; /** * @param string $setName @@ -590,7 +590,7 @@ protected function setUpEntitySchema(array $classNames) throw new \RuntimeException("EntityManager not set, you have to call parent::setUp() before invoking this method."); } - $classes = array(); + $classes = []; foreach ($classNames as $className) { if ( ! isset(static::$_entityTablesCreated[$className])) { static::$_entityTablesCreated[$className] = true; @@ -624,7 +624,7 @@ protected function setUp() } if (isset($GLOBALS['DOCTRINE_MARK_SQL_LOGS'])) { - if (in_array(static::$_sharedConn->getDatabasePlatform()->getName(), array("mysql", "postgresql"))) { + if (in_array(static::$_sharedConn->getDatabasePlatform()->getName(), ["mysql", "postgresql"])) { static::$_sharedConn->executeQuery('SELECT 1 /*' . get_class($this) . '*/'); } else if (static::$_sharedConn->getDatabasePlatform()->getName() == "oracle") { static::$_sharedConn->executeQuery('SELECT 1 /*' . get_class($this) . '*/ FROM dual'); @@ -636,7 +636,7 @@ protected function setUp() $this->_schemaTool = new SchemaTool($this->_em); } - $classes = array(); + $classes = []; foreach ($this->_usedModelSets as $setName => $bool) { if ( ! isset(static::$_tablesCreated[$setName])/* || $forceCreateTables*/) { @@ -712,10 +712,11 @@ protected function _getEntityManager($config = null, $eventManager = null) { $this->isSecondLevelCacheEnabled = true; } - $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(array( + $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver( + [ realpath(__DIR__ . '/Models/Cache'), realpath(__DIR__ . '/Models/GeoNames') - ), true)); + ], true)); $conn = static::$_sharedConn; $conn->getConfiguration()->setSQLLogger($this->_sqlLoggerStack); @@ -724,7 +725,7 @@ protected function _getEntityManager($config = null, $eventManager = null) { $evm = $conn->getEventManager(); foreach ($evm->getListeners() AS $event => $listeners) { foreach ($listeners AS $listener) { - $evm->removeEventListener(array($event), $listener); + $evm->removeEventListener([$event], $listener); } } @@ -740,7 +741,7 @@ protected function _getEntityManager($config = null, $eventManager = null) { } if (isset($GLOBALS['debug_uow_listener'])) { - $evm->addEventListener(array('onFlush'), new DebugUnitOfWorkListener()); + $evm->addEventListener(['onFlush'], new DebugUnitOfWorkListener()); } return EntityManager::create($conn, $config); @@ -763,7 +764,8 @@ protected function onNotSuccessfulTest($e) $queries = ""; $last25queries = array_slice(array_reverse($this->_sqlLoggerStack->queries, true), 0, 25, true); foreach ($last25queries as $i => $query) { - $params = array_map(function($p) { if (is_object($p)) return get_class($p); else return var_export($p, true); }, $query['params'] ?: array()); + $params = array_map(function($p) { if (is_object($p)) return get_class($p); else return var_export($p, true); }, $query['params'] ?: [] + ); $queries .= $i.". SQL: '".$query['sql']."' Params: ".implode(", ", $params).PHP_EOL; } diff --git a/tests/Doctrine/Tests/OrmTestCase.php b/tests/Doctrine/Tests/OrmTestCase.php index 200f5345011..9d6e9b5ac6c 100644 --- a/tests/Doctrine/Tests/OrmTestCase.php +++ b/tests/Doctrine/Tests/OrmTestCase.php @@ -62,7 +62,7 @@ abstract class OrmTestCase extends DoctrineTestCase * * @return \Doctrine\ORM\Mapping\Driver\AnnotationDriver */ - protected function createAnnotationDriver($paths = array(), $alias = null) + protected function createAnnotationDriver($paths = [], $alias = null) { if (version_compare(Version::VERSION, '3.0.0', '>=')) { $reader = new Annotations\CachedReader(new Annotations\AnnotationReader(), new ArrayCache()); @@ -125,13 +125,14 @@ protected function _getTestEntityManager($conn = null, $conf = null, $eventManag $config = new Configuration(); $config->setMetadataCacheImpl($metadataCache); - $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(array(), true)); + $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([], true)); $config->setQueryCacheImpl(self::getSharedQueryCacheImpl()); $config->setProxyDir(__DIR__ . '/Proxies'); $config->setProxyNamespace('Doctrine\Tests\Proxies'); - $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(array( + $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver( + [ realpath(__DIR__ . '/Models/Cache') - ), true)); + ], true)); if ($this->isSecondLevelCacheEnabled) { @@ -147,12 +148,12 @@ protected function _getTestEntityManager($conn = null, $conf = null, $eventManag } if ($conn === null) { - $conn = array( + $conn = [ 'driverClass' => 'Doctrine\Tests\Mocks\DriverMock', 'wrapperClass' => 'Doctrine\Tests\Mocks\ConnectionMock', 'user' => 'john', 'password' => 'wayne' - ); + ]; } if (is_array($conn)) { diff --git a/tests/Doctrine/Tests/TestUtil.php b/tests/Doctrine/Tests/TestUtil.php index 8a830f7243e..812961c92e9 100644 --- a/tests/Doctrine/Tests/TestUtil.php +++ b/tests/Doctrine/Tests/TestUtil.php @@ -125,10 +125,10 @@ private static function getSpecifiedConnectionParams() private static function getFallbackConnectionParams() { - $params = array( + $params = [ 'driver' => 'pdo_sqlite', 'memory' => true - ); + ]; if (isset($GLOBALS['db_path'])) { $params['path'] = $GLOBALS['db_path']; @@ -151,14 +151,14 @@ private static function addDbEventSubscribers(Connection $conn) private static function getParamsForTemporaryConnection() { - $connectionParams = array( + $connectionParams = [ 'driver' => $GLOBALS['tmpdb_type'], 'user' => $GLOBALS['tmpdb_username'], 'password' => $GLOBALS['tmpdb_password'], 'host' => $GLOBALS['tmpdb_host'], 'dbname' => null, 'port' => $GLOBALS['tmpdb_port'] - ); + ]; if (isset($GLOBALS['tmpdb_name'])) { $connectionParams['dbname'] = $GLOBALS['tmpdb_name']; @@ -177,14 +177,14 @@ private static function getParamsForTemporaryConnection() private static function getParamsForMainConnection() { - $connectionParams = array( + $connectionParams = [ 'driver' => $GLOBALS['db_type'], 'user' => $GLOBALS['db_username'], 'password' => $GLOBALS['db_password'], 'host' => $GLOBALS['db_host'], 'dbname' => $GLOBALS['db_name'], 'port' => $GLOBALS['db_port'] - ); + ]; if (isset($GLOBALS['db_server'])) { $connectionParams['server'] = $GLOBALS['db_server']; From c609072ce1f82bc30c437a24fbfe19a3f912352a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 7 Dec 2016 23:34:14 +0100 Subject: [PATCH 169/877] Use short-array syntax on "bin" directory --- bin/doctrine.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/doctrine.php b/bin/doctrine.php index 81e0166865a..81d4e7bf279 100644 --- a/bin/doctrine.php +++ b/bin/doctrine.php @@ -20,8 +20,10 @@ use Symfony\Component\Console\Helper\HelperSet; use Doctrine\ORM\Tools\Console\ConsoleRunner; -$autoloadFiles = array(__DIR__ . '/../vendor/autoload.php', - __DIR__ . '/../../../autoload.php'); +$autoloadFiles = [ + __DIR__ . '/../vendor/autoload.php', + __DIR__ . '/../../../autoload.php' +]; foreach ($autoloadFiles as $autoloadFile) { if (file_exists($autoloadFile)) { @@ -30,7 +32,7 @@ } } -$directories = array(getcwd(), getcwd() . DIRECTORY_SEPARATOR . 'config'); +$directories = [getcwd(), getcwd() . DIRECTORY_SEPARATOR . 'config']; $configFile = null; foreach ($directories as $directory) { @@ -51,7 +53,7 @@ exit(1); } -$commands = array(); +$commands = []; $helperSet = require $configFile; From 234989d0693174da9f760d50b5c11ac30eee6fdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Thu, 8 Dec 2016 00:31:12 +0100 Subject: [PATCH 170/877] Use short-array syntax on "lib" directory --- lib/Doctrine/ORM/AbstractQuery.php | 8 +- lib/Doctrine/ORM/Cache/DefaultCache.php | 4 +- .../ORM/Cache/DefaultCacheFactory.php | 6 +- .../ORM/Cache/DefaultCollectionHydrator.php | 6 +- .../ORM/Cache/DefaultEntityHydrator.php | 4 +- lib/Doctrine/ORM/Cache/DefaultQueryCache.php | 31 ++-- .../ORM/Cache/Logging/CacheLoggerChain.php | 2 +- .../Cache/Logging/StatisticsCacheLogger.php | 12 +- .../AbstractCollectionPersister.php | 2 +- ...rictReadWriteCachedCollectionPersister.php | 8 +- .../ReadWriteCachedCollectionPersister.php | 12 +- .../Entity/AbstractEntityPersister.php | 16 +- ...onStrictReadWriteCachedEntityPersister.php | 4 +- .../Entity/ReadWriteCachedEntityPersister.php | 12 +- lib/Doctrine/ORM/Cache/QueryCache.php | 4 +- .../Cache/Region/DefaultMultiGetRegion.php | 4 +- .../ORM/Cache/Region/DefaultRegion.php | 2 +- .../ORM/Cache/RegionsConfiguration.php | 4 +- lib/Doctrine/ORM/Configuration.php | 8 +- lib/Doctrine/ORM/EntityManager.php | 16 +- lib/Doctrine/ORM/EntityNotFoundException.php | 2 +- lib/Doctrine/ORM/EntityRepository.php | 4 +- lib/Doctrine/ORM/Id/AssignedGenerator.php | 2 +- lib/Doctrine/ORM/Id/SequenceGenerator.php | 6 +- lib/Doctrine/ORM/Id/TableGenerator.php | 2 +- .../ORM/Internal/CommitOrderCalculator.php | 12 +- .../Internal/Hydration/AbstractHydrator.php | 42 ++--- .../ORM/Internal/Hydration/ArrayHydrator.php | 22 +-- .../ORM/Internal/Hydration/ObjectHydrator.php | 24 +-- .../ORM/Internal/Hydration/ScalarHydrator.php | 2 +- .../Hydration/SimpleObjectHydrator.php | 4 +- .../ORM/Internal/HydrationCompleteHandler.php | 6 +- .../Mapping/Builder/AssociationBuilder.php | 6 +- .../Mapping/Builder/ClassMetadataBuilder.php | 70 ++++---- .../Mapping/Builder/EntityListenerBuilder.php | 6 +- .../ORM/Mapping/Builder/FieldBuilder.php | 4 +- .../Builder/ManyToManyAssociationBuilder.php | 8 +- .../ORM/Mapping/ClassMetadataFactory.php | 80 +++++---- .../ORM/Mapping/ClassMetadataInfo.php | 102 +++++------ lib/Doctrine/ORM/Mapping/Column.php | 2 +- .../Mapping/DefaultEntityListenerResolver.php | 6 +- .../ORM/Mapping/DefaultQuoteStrategy.php | 2 +- .../ORM/Mapping/Driver/AnnotationDriver.php | 163 +++++++++-------- .../ORM/Mapping/Driver/DatabaseDriver.php | 58 +++--- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 169 ++++++++++-------- .../ORM/Mapping/Driver/YamlDriver.php | 132 +++++++------- lib/Doctrine/ORM/Mapping/EntityListeners.php | 4 +- lib/Doctrine/ORM/Mapping/EntityResult.php | 2 +- lib/Doctrine/ORM/Mapping/JoinTable.php | 4 +- .../ORM/Mapping/NamedNativeQueries.php | 4 +- .../ORM/Mapping/SqlResultSetMapping.php | 8 +- .../ORM/Mapping/SqlResultSetMappings.php | 4 +- lib/Doctrine/ORM/Mapping/Table.php | 2 +- lib/Doctrine/ORM/NativeQuery.php | 4 +- lib/Doctrine/ORM/PersistentCollection.php | 8 +- .../Collection/ManyToManyPersister.php | 64 +++---- .../Collection/OneToManyPersister.php | 12 +- .../Entity/BasicEntityPersister.php | 146 +++++++-------- .../Entity/CachedPersisterContext.php | 2 +- .../ORM/Persisters/Entity/EntityPersister.php | 10 +- .../Entity/JoinedSubclassPersister.php | 36 ++-- .../Entity/SingleTablePersister.php | 2 +- .../ORM/Persisters/SqlExpressionVisitor.php | 4 +- .../ORM/Persisters/SqlValueVisitor.php | 8 +- lib/Doctrine/ORM/Query.php | 14 +- .../ORM/Query/AST/CoalesceExpression.php | 4 +- .../ORM/Query/AST/ConditionalExpression.php | 2 +- .../ORM/Query/AST/ConditionalTerm.php | 2 +- lib/Doctrine/ORM/Query/AST/FromClause.php | 4 +- .../Query/AST/Functions/ConcatFunction.php | 6 +- .../ORM/Query/AST/GeneralCaseExpression.php | 4 +- lib/Doctrine/ORM/Query/AST/GroupByClause.php | 2 +- .../AST/IdentificationVariableDeclaration.php | 2 +- lib/Doctrine/ORM/Query/AST/InExpression.php | 2 +- lib/Doctrine/ORM/Query/AST/OrderByClause.php | 2 +- lib/Doctrine/ORM/Query/AST/SelectClause.php | 2 +- .../Query/AST/SimpleArithmeticExpression.php | 2 +- .../ORM/Query/AST/SimpleCaseExpression.php | 4 +- .../ORM/Query/AST/SubselectFromClause.php | 2 +- lib/Doctrine/ORM/Query/AST/UpdateClause.php | 2 +- .../Query/Exec/MultiTableDeleteExecutor.php | 10 +- .../Query/Exec/MultiTableUpdateExecutor.php | 16 +- lib/Doctrine/ORM/Query/Expr.php | 30 ++-- lib/Doctrine/ORM/Query/Expr/Andx.php | 4 +- lib/Doctrine/ORM/Query/Expr/Base.php | 8 +- lib/Doctrine/ORM/Query/Expr/Composite.php | 2 +- lib/Doctrine/ORM/Query/Expr/OrderBy.php | 4 +- lib/Doctrine/ORM/Query/Expr/Orx.php | 4 +- lib/Doctrine/ORM/Query/Expr/Select.php | 4 +- lib/Doctrine/ORM/Query/Filter/SQLFilter.php | 4 +- lib/Doctrine/ORM/Query/FilterCollection.php | 8 +- lib/Doctrine/ORM/Query/Lexer.php | 6 +- lib/Doctrine/ORM/Query/Parser.php | 128 ++++++------- lib/Doctrine/ORM/Query/ParserResult.php | 2 +- .../ORM/Query/QueryExpressionVisitor.php | 20 +-- lib/Doctrine/ORM/Query/ResultSetMapping.php | 30 ++-- .../ORM/Query/ResultSetMappingBuilder.php | 12 +- lib/Doctrine/ORM/Query/SqlWalker.php | 100 +++++------ lib/Doctrine/ORM/Query/TreeWalkerAdapter.php | 2 +- lib/Doctrine/ORM/Query/TreeWalkerChain.php | 2 +- .../ORM/Query/TreeWalkerChainIterator.php | 2 +- lib/Doctrine/ORM/QueryBuilder.php | 62 +++---- .../Repository/DefaultRepositoryFactory.php | 2 +- .../Tools/AttachEntityListenersListener.php | 6 +- .../Command/ClearCache/MetadataCommand.php | 14 +- .../Command/ClearCache/QueryCommand.php | 16 +- .../Command/ClearCache/ResultCommand.php | 16 +- .../Command/ConvertDoctrine1SchemaCommand.php | 56 +++--- .../Console/Command/ConvertMappingCommand.php | 68 +++---- .../EnsureProductionSettingsCommand.php | 14 +- .../Command/GenerateEntitiesCommand.php | 78 ++++---- .../Command/GenerateProxiesCommand.php | 24 +-- .../Command/GenerateRepositoriesCommand.php | 22 +-- .../Command/MappingDescribeCommand.php | 16 +- .../Tools/Console/Command/RunDqlCommand.php | 52 +++--- .../Command/SchemaTool/CreateCommand.php | 14 +- .../Command/SchemaTool/DropCommand.php | 30 ++-- .../Command/SchemaTool/UpdateCommand.php | 32 ++-- .../ORM/Tools/Console/ConsoleRunner.php | 62 ++++--- .../ORM/Tools/Console/MetadataFilter.php | 2 +- .../ORM/Tools/ConvertDoctrine1Schema.php | 38 ++-- lib/Doctrine/ORM/Tools/EntityGenerator.php | 130 +++++++------- .../ORM/Tools/EntityRepositoryGenerator.php | 14 +- .../Tools/Export/ClassMetadataExporter.php | 4 +- .../Tools/Export/Driver/AbstractExporter.php | 2 +- .../ORM/Tools/Export/Driver/PhpExporter.php | 22 +-- .../ORM/Tools/Export/Driver/XmlExporter.php | 14 +- .../ORM/Tools/Export/Driver/YamlExporter.php | 30 ++-- .../Tools/Pagination/CountOutputWalker.php | 2 +- .../ORM/Tools/Pagination/CountWalker.php | 8 +- .../Tools/Pagination/LimitSubqueryWalker.php | 20 +-- .../ORM/Tools/Pagination/Paginator.php | 2 +- .../ORM/Tools/Pagination/WhereInWalker.php | 42 +++-- .../ORM/Tools/ResolveTargetEntityListener.php | 6 +- lib/Doctrine/ORM/Tools/SchemaTool.php | 58 +++--- lib/Doctrine/ORM/Tools/SchemaValidator.php | 6 +- lib/Doctrine/ORM/UnitOfWork.php | 108 +++++------ .../ORM/Utility/IdentifierFlattener.php | 4 +- lib/Doctrine/ORM/Utility/PersisterHelper.php | 6 +- 139 files changed, 1534 insertions(+), 1447 deletions(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 5f4248b5f26..8d901d51477 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -96,7 +96,7 @@ abstract class AbstractQuery * * @var array */ - protected $_hints = array(); + protected $_hints = []; /** * The hydration mode. @@ -955,7 +955,7 @@ private function executeIgnoreQueryCache($parameters = null, $hydrationMode = nu } if ( ! $result) { - $result = array(); + $result = []; } $setCacheEntry = function($data) use ($cache, $result, $cacheKey, $realCacheKey, $queryCacheProfile) { @@ -1049,7 +1049,7 @@ private function getTimestampKey() */ protected function getHydrationCacheId() { - $parameters = array(); + $parameters = []; foreach ($this->getParameters() as $parameter) { $parameters[$parameter->getName()] = $this->processParameterValue($parameter->getValue()); @@ -1111,7 +1111,7 @@ public function __clone() { $this->parameters = new ArrayCollection(); - $this->_hints = array(); + $this->_hints = []; $this->_hints = $this->_em->getConfiguration()->getDefaultQueryHints(); } diff --git a/lib/Doctrine/ORM/Cache/DefaultCache.php b/lib/Doctrine/ORM/Cache/DefaultCache.php index 2557da4c175..80fbd814388 100644 --- a/lib/Doctrine/ORM/Cache/DefaultCache.php +++ b/lib/Doctrine/ORM/Cache/DefaultCache.php @@ -53,7 +53,7 @@ class DefaultCache implements Cache /** * @var \Doctrine\ORM\Cache\QueryCache[] */ - private $queryCaches = array(); + private $queryCaches = []; /** * @var \Doctrine\ORM\Cache\QueryCache @@ -336,7 +336,7 @@ private function toIdentifierArray(ClassMetadata $metadata, $identifier) } } - return array($metadata->identifier[0] => $identifier); + return [$metadata->identifier[0] => $identifier]; } } diff --git a/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php b/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php index 98ece43c719..1510096324c 100644 --- a/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php +++ b/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php @@ -64,7 +64,7 @@ class DefaultCacheFactory implements CacheFactory /** * @var \Doctrine\ORM\Cache\Region[] */ - private $regions = array(); + private $regions = []; /** * @var string|null @@ -167,10 +167,10 @@ public function buildQueryCache(EntityManagerInterface $em, $regionName = null) return new DefaultQueryCache( $em, $this->getRegion( - array( + [ 'region' => $regionName ?: Cache::DEFAULT_QUERY_REGION_NAME, 'usage' => ClassMetadata::CACHE_USAGE_NONSTRICT_READ_WRITE - ) + ] ) ); } diff --git a/lib/Doctrine/ORM/Cache/DefaultCollectionHydrator.php b/lib/Doctrine/ORM/Cache/DefaultCollectionHydrator.php index f6583cbd2ca..7ff11e4adf1 100644 --- a/lib/Doctrine/ORM/Cache/DefaultCollectionHydrator.php +++ b/lib/Doctrine/ORM/Cache/DefaultCollectionHydrator.php @@ -46,7 +46,7 @@ class DefaultCollectionHydrator implements CollectionHydrator /** * @var array */ - private static $hints = array(Query::HINT_CACHE_ENABLED => true); + private static $hints = [Query::HINT_CACHE_ENABLED => true]; /** * @param \Doctrine\ORM\EntityManagerInterface $em The entity manager. @@ -62,7 +62,7 @@ public function __construct(EntityManagerInterface $em) */ public function buildCacheEntry(ClassMetadata $metadata, CollectionCacheKey $key, $collection) { - $data = array(); + $data = []; foreach ($collection as $index => $entity) { $data[$index] = new EntityCacheKey($metadata->name, $this->uow->getEntityIdentifier($entity)); @@ -79,7 +79,7 @@ public function loadCacheEntry(ClassMetadata $metadata, CollectionCacheKey $key, /* @var $targetPersister \Doctrine\ORM\Cache\Persister\CachedPersister */ $targetPersister = $this->uow->getEntityPersister($assoc['targetEntity']); $targetRegion = $targetPersister->getCacheRegion(); - $list = array(); + $list = []; $entityEntries = $targetRegion->getMultiple($entry); diff --git a/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php b/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php index 9ecb18e9298..99a98bddc77 100644 --- a/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php +++ b/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php @@ -55,7 +55,7 @@ class DefaultEntityHydrator implements EntityHydrator /** * @var array */ - private static $hints = array(Query::HINT_CACHE_ENABLED => true); + private static $hints = [Query::HINT_CACHE_ENABLED => true]; /** * @param \Doctrine\ORM\EntityManagerInterface $em The entity manager. @@ -138,7 +138,7 @@ public function buildCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, $e $data[reset($assoc['joinColumnFieldNames'])] = $targetId; $targetEntity = $this->em->getClassMetadata($assoc['targetEntity']); - $targetId = array($targetEntity->identifier[0] => $targetId); + $targetId = [$targetEntity->identifier[0] => $targetId]; } $data[$name] = new AssociationCacheEntry($assoc['targetEntity'], $targetId); diff --git a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php index dabf1721e0e..88e59421390 100644 --- a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php +++ b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php @@ -66,7 +66,7 @@ class DefaultQueryCache implements QueryCache /** * @var array */ - private static $hints = array(Query::HINT_CACHE_ENABLED => true); + private static $hints = [Query::HINT_CACHE_ENABLED => true]; /** * @param \Doctrine\ORM\EntityManagerInterface $em The entity manager. @@ -86,7 +86,7 @@ public function __construct(EntityManagerInterface $em, Region $region) /** * {@inheritdoc} */ - public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = array()) + public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = []) { if ( ! ($key->cacheMode & Cache::MODE_GET)) { return null; @@ -104,7 +104,7 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = ar return null; } - $result = array(); + $result = []; $entityName = reset($rsm->aliasMap); $hasRelation = ( ! empty($rsm->relationMap)); $persister = $this->uow->getEntityPersister($entityName); @@ -209,7 +209,7 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = ar /** * {@inheritdoc} */ - public function put(QueryCacheKey $key, ResultSetMapping $rsm, $result, array $hints = array()) + public function put(QueryCacheKey $key, ResultSetMapping $rsm, $result, array $hints = []) { if ($rsm->scalarMappings) { throw new CacheException("Second level cache does not support scalar results."); @@ -231,7 +231,7 @@ public function put(QueryCacheKey $key, ResultSetMapping $rsm, $result, array $h return false; } - $data = array(); + $data = []; $entityName = reset($rsm->aliasMap); $rootAlias = key($rsm->aliasMap); $hasRelation = ( ! empty($rsm->relationMap)); @@ -247,7 +247,7 @@ public function put(QueryCacheKey $key, ResultSetMapping $rsm, $result, array $h $identifier = $this->uow->getEntityIdentifier($entity); $entityKey = new EntityCacheKey($entityName, $identifier); $data[$index]['identifier'] = $identifier; - $data[$index]['associations'] = array(); + $data[$index]['associations'] = []; if (($key->cacheMode & Cache::MODE_REFRESH) || ! $region->contains($entityKey)) { // Cancel put result if entity put fail @@ -332,15 +332,15 @@ private function storeAssociationCache(QueryCacheKey $key, array $assoc, $assocV } } - return array( + return [ 'targetEntity' => $assocMetadata->rootEntityName, 'identifier' => $assocIdentifier, 'type' => $assoc['type'] - ); + ]; } // Handle *-to-many associations - $list = array(); + $list = []; foreach ($assocValue as $assocItemIndex => $assocItem) { $assocIdentifier = $this->uow->getEntityIdentifier($assocItem); @@ -356,11 +356,11 @@ private function storeAssociationCache(QueryCacheKey $key, array $assoc, $assocV $list[$assocItemIndex] = $assocIdentifier; } - return array( + return [ 'targetEntity' => $assocMetadata->rootEntityName, 'type' => $assoc['type'], 'list' => $list, - ); + ]; } /** @@ -372,7 +372,7 @@ private function storeAssociationCache(QueryCacheKey $key, array $assoc, $assocV */ private function getAssociationValue(ResultSetMapping $rsm, $assocAlias, $entity) { - $path = array(); + $path = []; $alias = $assocAlias; while (isset($rsm->parentAliasMap[$alias])) { @@ -380,10 +380,11 @@ private function getAssociationValue(ResultSetMapping $rsm, $assocAlias, $entity $field = $rsm->relationMap[$alias]; $class = $rsm->aliasMap[$parent]; - array_unshift($path, array( + array_unshift($path, [ 'field' => $field, 'class' => $class - )); + ] + ); $alias = $parent; } @@ -417,7 +418,7 @@ private function getAssociationPathValue($value, array $path) return $this->getAssociationPathValue($value, $path); } - $values = array(); + $values = []; foreach ($value as $item) { $values[] = $this->getAssociationPathValue($item, $path); diff --git a/lib/Doctrine/ORM/Cache/Logging/CacheLoggerChain.php b/lib/Doctrine/ORM/Cache/Logging/CacheLoggerChain.php index 694b35ca5eb..28a8125c972 100644 --- a/lib/Doctrine/ORM/Cache/Logging/CacheLoggerChain.php +++ b/lib/Doctrine/ORM/Cache/Logging/CacheLoggerChain.php @@ -35,7 +35,7 @@ class CacheLoggerChain implements CacheLogger /** * @var array<\Doctrine\ORM\Cache\Logging\CacheLogger> */ - private $loggers = array(); + private $loggers = []; /** * @param string $name diff --git a/lib/Doctrine/ORM/Cache/Logging/StatisticsCacheLogger.php b/lib/Doctrine/ORM/Cache/Logging/StatisticsCacheLogger.php index 2fbba40bef1..122e3534ac7 100644 --- a/lib/Doctrine/ORM/Cache/Logging/StatisticsCacheLogger.php +++ b/lib/Doctrine/ORM/Cache/Logging/StatisticsCacheLogger.php @@ -35,17 +35,17 @@ class StatisticsCacheLogger implements CacheLogger /** * @var array */ - private $cacheMissCountMap = array(); + private $cacheMissCountMap = []; /** * @var array */ - private $cacheHitCountMap = array(); + private $cacheHitCountMap = []; /** * @var array */ - private $cachePutCountMap = array(); + private $cachePutCountMap = []; /** * {@inheritdoc} @@ -214,9 +214,9 @@ public function clearRegionStats($regionName) */ public function clearStats() { - $this->cachePutCountMap = array(); - $this->cacheHitCountMap = array(); - $this->cacheMissCountMap = array(); + $this->cachePutCountMap = []; + $this->cacheHitCountMap = []; + $this->cacheMissCountMap = []; } /** diff --git a/lib/Doctrine/ORM/Cache/Persister/Collection/AbstractCollectionPersister.php b/lib/Doctrine/ORM/Cache/Persister/Collection/AbstractCollectionPersister.php index abaef17a680..7a10d17d932 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Collection/AbstractCollectionPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Collection/AbstractCollectionPersister.php @@ -70,7 +70,7 @@ abstract class AbstractCollectionPersister implements CachedCollectionPersister /** * @var array */ - protected $queuedCache = array(); + protected $queuedCache = []; /** * @var \Doctrine\ORM\Cache\Region diff --git a/lib/Doctrine/ORM/Cache/Persister/Collection/NonStrictReadWriteCachedCollectionPersister.php b/lib/Doctrine/ORM/Cache/Persister/Collection/NonStrictReadWriteCachedCollectionPersister.php index 86e5c8f9ffd..fbd46f6eafe 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Collection/NonStrictReadWriteCachedCollectionPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Collection/NonStrictReadWriteCachedCollectionPersister.php @@ -46,7 +46,7 @@ public function afterTransactionComplete() } } - $this->queuedCache = array(); + $this->queuedCache = []; } /** @@ -54,7 +54,7 @@ public function afterTransactionComplete() */ public function afterTransactionRolledBack() { - $this->queuedCache = array(); + $this->queuedCache = []; } /** @@ -96,9 +96,9 @@ public function update(PersistentCollection $collection) $this->persister->update($collection); - $this->queuedCache['update'][spl_object_hash($collection)] = array( + $this->queuedCache['update'][spl_object_hash($collection)] = [ 'key' => $key, 'list' => $collection - ); + ]; } } diff --git a/lib/Doctrine/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersister.php b/lib/Doctrine/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersister.php index a92ed20d302..74bb044451b 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersister.php @@ -60,7 +60,7 @@ public function afterTransactionComplete() } } - $this->queuedCache = array(); + $this->queuedCache = []; } /** @@ -80,7 +80,7 @@ public function afterTransactionRolledBack() } } - $this->queuedCache = array(); + $this->queuedCache = []; } /** @@ -98,10 +98,10 @@ public function delete(PersistentCollection $collection) return; } - $this->queuedCache['delete'][spl_object_hash($collection)] = array( + $this->queuedCache['delete'][spl_object_hash($collection)] = [ 'key' => $key, 'lock' => $lock - ); + ]; } /** @@ -126,9 +126,9 @@ public function update(PersistentCollection $collection) return; } - $this->queuedCache['update'][spl_object_hash($collection)] = array( + $this->queuedCache['update'][spl_object_hash($collection)] = [ 'key' => $key, 'lock' => $lock - ); + ]; } } diff --git a/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php b/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php index c1e2d50adbd..a6e2b348036 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php @@ -64,7 +64,7 @@ abstract class AbstractEntityPersister implements CachedEntityPersister /** * @var array */ - protected $queuedCache = array(); + protected $queuedCache = []; /** * @var \Doctrine\ORM\Cache\Region @@ -160,7 +160,7 @@ public function getSelectSQL($criteria, $assoc = null, $lockMode = null, $limit /** * {@inheritDoc} */ - public function getCountSQL($criteria = array()) + public function getCountSQL($criteria = []) { return $this->persister->getCountSQL($criteria); } @@ -249,7 +249,7 @@ public function storeEntityCache($entity, EntityCacheKey $key) private function storeJoinedAssociations($entity) { if ($this->joinedAssociations === null) { - $associations = array(); + $associations = []; foreach ($this->class->associationMappings as $name => $assoc) { if (isset($assoc['cache']) && @@ -360,7 +360,7 @@ public function executeInserts() /** * {@inheritdoc} */ - public function load(array $criteria, $entity = null, $assoc = null, array $hints = array(), $lockMode = null, $limit = null, array $orderBy = null) + public function load(array $criteria, $entity = null, $assoc = null, array $hints = [], $lockMode = null, $limit = null, array $orderBy = null) { if ($entity !== null || $assoc !== null || ! empty($hints) || $lockMode !== null) { return $this->persister->load($criteria, $entity, $assoc, $hints, $lockMode, $limit, $orderBy); @@ -386,7 +386,7 @@ public function load(array $criteria, $entity = null, $assoc = null, array $hint return null; } - $cached = $queryCache->put($queryKey, $rsm, array($result)); + $cached = $queryCache->put($queryKey, $rsm, [$result]); if ($this->cacheLogger) { if ($result) { @@ -404,7 +404,7 @@ public function load(array $criteria, $entity = null, $assoc = null, array $hint /** * {@inheritdoc} */ - public function loadAll(array $criteria = array(), array $orderBy = null, $limit = null, $offset = null) + public function loadAll(array $criteria = [], array $orderBy = null, $limit = null, $offset = null) { $query = $this->persister->getSelectSQL($criteria, null, null, $limit, $offset, $orderBy); $hash = $this->getHash($query, $criteria, null, null, null); @@ -494,7 +494,7 @@ public function loadById(array $identifier, $entity = null) /** * {@inheritDoc} */ - public function count($criteria = array()) + public function count($criteria = []) { return $this->persister->count($criteria); } @@ -612,7 +612,7 @@ public function loadOneToManyCollection(array $assoc, $sourceEntity, PersistentC /** * {@inheritdoc} */ - public function loadOneToOneEntity(array $assoc, $sourceEntity, array $identifier = array()) + public function loadOneToOneEntity(array $assoc, $sourceEntity, array $identifier = []) { return $this->persister->loadOneToOneEntity($assoc, $sourceEntity, $identifier); } diff --git a/lib/Doctrine/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersister.php b/lib/Doctrine/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersister.php index 54c814a9a22..a2844673bee 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersister.php @@ -62,7 +62,7 @@ public function afterTransactionComplete() $this->timestampRegion->update($this->timestampKey); } - $this->queuedCache = array(); + $this->queuedCache = []; } /** @@ -70,7 +70,7 @@ public function afterTransactionComplete() */ public function afterTransactionRolledBack() { - $this->queuedCache = array(); + $this->queuedCache = []; } /** diff --git a/lib/Doctrine/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersister.php b/lib/Doctrine/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersister.php index 07cac510d4c..79a4c8c3dad 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersister.php @@ -73,7 +73,7 @@ public function afterTransactionComplete() $this->timestampRegion->update($this->timestampKey); } - $this->queuedCache = array(); + $this->queuedCache = []; } /** @@ -93,7 +93,7 @@ public function afterTransactionRolledBack() } } - $this->queuedCache = array(); + $this->queuedCache = []; } /** @@ -113,10 +113,10 @@ public function delete($entity) return $deleted; } - $this->queuedCache['delete'][] = array( + $this->queuedCache['delete'][] = [ 'lock' => $lock, 'key' => $key - ); + ]; return $deleted; } @@ -135,9 +135,9 @@ public function update($entity) return; } - $this->queuedCache['update'][] = array( + $this->queuedCache['update'][] = [ 'lock' => $lock, 'key' => $key - ); + ]; } } diff --git a/lib/Doctrine/ORM/Cache/QueryCache.php b/lib/Doctrine/ORM/Cache/QueryCache.php index dd5ef3bf539..de2496253b3 100644 --- a/lib/Doctrine/ORM/Cache/QueryCache.php +++ b/lib/Doctrine/ORM/Cache/QueryCache.php @@ -44,7 +44,7 @@ public function clear(); * * @return boolean */ - public function put(QueryCacheKey $key, ResultSetMapping $rsm, $result, array $hints = array()); + public function put(QueryCacheKey $key, ResultSetMapping $rsm, $result, array $hints = []); /** * @param \Doctrine\ORM\Cache\QueryCacheKey $key @@ -53,7 +53,7 @@ public function put(QueryCacheKey $key, ResultSetMapping $rsm, $result, array $h * * @return array|null */ - public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = array()); + public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = []); /** * @return \Doctrine\ORM\Cache\Region diff --git a/lib/Doctrine/ORM/Cache/Region/DefaultMultiGetRegion.php b/lib/Doctrine/ORM/Cache/Region/DefaultMultiGetRegion.php index 7ecf7331116..1df073c3e52 100644 --- a/lib/Doctrine/ORM/Cache/Region/DefaultMultiGetRegion.php +++ b/lib/Doctrine/ORM/Cache/Region/DefaultMultiGetRegion.php @@ -56,7 +56,7 @@ public function __construct($name, MultiGetCache $cache, $lifetime = 0) */ public function getMultiple(CollectionCacheEntry $collection) { - $keysToRetrieve = array(); + $keysToRetrieve = []; foreach ($collection->identifiers as $index => $key) { $keysToRetrieve[$index] = $this->getCacheEntryKey($key); @@ -67,7 +67,7 @@ public function getMultiple(CollectionCacheEntry $collection) return null; } - $returnableItems = array(); + $returnableItems = []; foreach ($keysToRetrieve as $index => $key) { $returnableItems[$index] = $items[$key]; } diff --git a/lib/Doctrine/ORM/Cache/Region/DefaultRegion.php b/lib/Doctrine/ORM/Cache/Region/DefaultRegion.php index 3f214d0b0e9..be62a6fb957 100644 --- a/lib/Doctrine/ORM/Cache/Region/DefaultRegion.php +++ b/lib/Doctrine/ORM/Cache/Region/DefaultRegion.php @@ -102,7 +102,7 @@ public function get(CacheKey $key) */ public function getMultiple(CollectionCacheEntry $collection) { - $result = array(); + $result = []; foreach ($collection->identifiers as $key) { $entryKey = $this->getCacheEntryKey($key); diff --git a/lib/Doctrine/ORM/Cache/RegionsConfiguration.php b/lib/Doctrine/ORM/Cache/RegionsConfiguration.php index 0d060636cf1..d79c5b1af28 100644 --- a/lib/Doctrine/ORM/Cache/RegionsConfiguration.php +++ b/lib/Doctrine/ORM/Cache/RegionsConfiguration.php @@ -31,12 +31,12 @@ class RegionsConfiguration /** * @var array */ - private $lifetimes = array(); + private $lifetimes = []; /** * @var array */ - private $lockLifetimes = array(); + private $lockLifetimes = []; /** * @var integer diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index 872050cb084..fa1d1dde762 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -149,7 +149,7 @@ public function setMetadataDriverImpl(MappingDriver $driverImpl) * * @return AnnotationDriver */ - public function newDefaultAnnotationDriver($paths = array(), $useSimpleAnnotationReader = true) + public function newDefaultAnnotationDriver($paths = [], $useSimpleAnnotationReader = true) { AnnotationRegistry::registerFile(__DIR__ . '/Mapping/Driver/DoctrineAnnotations.php'); @@ -349,7 +349,7 @@ public function getNamedQuery($name) */ public function addNamedNativeQuery($name, $sql, Query\ResultSetMapping $rsm) { - $this->_attributes['namedNativeQueries'][$name] = array($sql, $rsm); + $this->_attributes['namedNativeQueries'][$name] = [$sql, $rsm]; } /** @@ -590,7 +590,7 @@ public function setCustomDatetimeFunctions(array $functions) */ public function setCustomHydrationModes($modes) { - $this->_attributes['customHydrationModes'] = array(); + $this->_attributes['customHydrationModes'] = []; foreach ($modes as $modeName => $hydrator) { $this->addCustomHydrationMode($modeName, $hydrator); @@ -881,7 +881,7 @@ public function getSecondLevelCacheConfiguration() */ public function getDefaultQueryHints() { - return isset($this->_attributes['defaultQueryHints']) ? $this->_attributes['defaultQueryHints'] : array(); + return isset($this->_attributes['defaultQueryHints']) ? $this->_attributes['defaultQueryHints'] : []; } /** diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index b61a2557ba1..53573c25cd4 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -386,7 +386,7 @@ public function find($entityName, $id, $lockMode = null, $lockVersion = null) throw ORMInvalidArgumentException::invalidCompositeIdentifier(); } - $id = array($class->identifier[0] => $id); + $id = [$class->identifier[0] => $id]; } foreach ($id as $i => $value) { @@ -399,7 +399,7 @@ public function find($entityName, $id, $lockMode = null, $lockVersion = null) } } - $sortedId = array(); + $sortedId = []; foreach ($class->identifier as $identifier) { if ( ! isset($id[$identifier])) { @@ -458,7 +458,7 @@ public function find($entityName, $id, $lockMode = null, $lockVersion = null) throw TransactionRequiredException::transactionRequired(); } - return $persister->load($sortedId, null, null, array(), $lockMode); + return $persister->load($sortedId, null, null, [], $lockMode); default: return $persister->loadById($sortedId); @@ -473,10 +473,10 @@ public function getReference($entityName, $id) $class = $this->metadataFactory->getMetadataFor(ltrim($entityName, '\\')); if ( ! is_array($id)) { - $id = array($class->identifier[0] => $id); + $id = [$class->identifier[0] => $id]; } - $sortedId = array(); + $sortedId = []; foreach ($class->identifier as $identifier) { if ( ! isset($id[$identifier])) { @@ -502,7 +502,7 @@ public function getReference($entityName, $id) $entity = $this->proxyFactory->getProxy($class->name, $sortedId); - $this->unitOfWork->registerManaged($entity, $sortedId, array()); + $this->unitOfWork->registerManaged($entity, $sortedId, []); return $entity; } @@ -520,14 +520,14 @@ public function getPartialReference($entityName, $identifier) } if ( ! is_array($identifier)) { - $identifier = array($class->identifier[0] => $identifier); + $identifier = [$class->identifier[0] => $identifier]; } $entity = $class->newInstance(); $class->setIdentifierValues($entity, $identifier); - $this->unitOfWork->registerManaged($entity, $identifier, array()); + $this->unitOfWork->registerManaged($entity, $identifier, []); $this->unitOfWork->markReadOnly($entity); return $entity; diff --git a/lib/Doctrine/ORM/EntityNotFoundException.php b/lib/Doctrine/ORM/EntityNotFoundException.php index afe2f22426d..5b21e15c276 100644 --- a/lib/Doctrine/ORM/EntityNotFoundException.php +++ b/lib/Doctrine/ORM/EntityNotFoundException.php @@ -37,7 +37,7 @@ class EntityNotFoundException extends ORMException */ public static function fromClassNameAndIdentifier($className, array $id) { - $ids = array(); + $ids = []; foreach ($id as $key => $value) { $ids[] = $key . '(' . $value . ')'; diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index 1934a18d0c7..6be570ba3be 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -161,7 +161,7 @@ public function find($id, $lockMode = null, $lockVersion = null) */ public function findAll() { - return $this->findBy(array()); + return $this->findBy([]); } /** @@ -193,7 +193,7 @@ public function findOneBy(array $criteria, array $orderBy = null) { $persister = $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName); - return $persister->load($criteria, null, null, array(), null, 1, $orderBy); + return $persister->load($criteria, null, null, [], null, 1, $orderBy); } /** diff --git a/lib/Doctrine/ORM/Id/AssignedGenerator.php b/lib/Doctrine/ORM/Id/AssignedGenerator.php index 447dbd6d597..691eaee4221 100644 --- a/lib/Doctrine/ORM/Id/AssignedGenerator.php +++ b/lib/Doctrine/ORM/Id/AssignedGenerator.php @@ -44,7 +44,7 @@ public function generate(EntityManager $em, $entity) { $class = $em->getClassMetadata(get_class($entity)); $idFields = $class->getIdentifierFieldNames(); - $identifier = array(); + $identifier = []; foreach ($idFields as $idField) { $value = $class->getFieldValue($entity, $idField); diff --git a/lib/Doctrine/ORM/Id/SequenceGenerator.php b/lib/Doctrine/ORM/Id/SequenceGenerator.php index 1f3c9541b6c..a27edae9018 100644 --- a/lib/Doctrine/ORM/Id/SequenceGenerator.php +++ b/lib/Doctrine/ORM/Id/SequenceGenerator.php @@ -108,10 +108,12 @@ public function getNextValue() */ public function serialize() { - return serialize(array( + return serialize( + [ 'allocationSize' => $this->_allocationSize, 'sequenceName' => $this->_sequenceName - )); + ] + ); } /** diff --git a/lib/Doctrine/ORM/Id/TableGenerator.php b/lib/Doctrine/ORM/Id/TableGenerator.php index abf3ab8acd3..02385f51158 100644 --- a/lib/Doctrine/ORM/Id/TableGenerator.php +++ b/lib/Doctrine/ORM/Id/TableGenerator.php @@ -92,7 +92,7 @@ public function generate( $this->_tableName, $this->_sequenceName, $this->_allocationSize ); - if ($conn->executeUpdate($updateSql, array(1 => $currentLevel, 2 => $currentLevel+1)) !== 1) { + if ($conn->executeUpdate($updateSql, [1 => $currentLevel, 2 => $currentLevel+1]) !== 1) { // no affected rows, concurrency issue, throw exception } } else { diff --git a/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php b/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php index e1331da4750..067a8c577ba 100644 --- a/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php +++ b/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php @@ -54,14 +54,14 @@ class CommitOrderCalculator * * @var array */ - private $nodeList = array(); + private $nodeList = []; /** * Volatile variable holding calculated nodes during sorting process. * * @var array */ - private $sortedNodeList = array(); + private $sortedNodeList = []; /** * Checks for node (vertex) existence in graph. @@ -90,7 +90,7 @@ public function addNode($hash, $node) $vertex->hash = $hash; $vertex->state = self::NOT_VISITED; $vertex->value = $node; - $vertex->dependencyList = array(); + $vertex->dependencyList = []; $this->nodeList[$hash] = $vertex; } @@ -136,8 +136,8 @@ public function sort() $sortedList = $this->sortedNodeList; - $this->nodeList = array(); - $this->sortedNodeList = array(); + $this->nodeList = []; + $this->sortedNodeList = []; return array_reverse($sortedList); } @@ -162,7 +162,7 @@ private function visit($vertex) break; case self::IN_PROGRESS: - if (isset($adjacentVertex->dependencyList[$vertex->hash]) && + if (isset($adjacentVertex->dependencyList[$vertex->hash]) && $adjacentVertex->dependencyList[$vertex->hash]->weight < $edge->weight) { $adjacentVertex->state = self::VISITED; diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index ff142fc3589..ee9385c8155 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -69,14 +69,14 @@ abstract class AbstractHydrator * * @var array */ - protected $_metadataCache = array(); + protected $_metadataCache = []; /** * The cache used during row-by-row hydration. * * @var array */ - protected $_cache = array(); + protected $_cache = []; /** * The statement that provides the data to hydrate. @@ -113,7 +113,7 @@ public function __construct(EntityManagerInterface $em) * * @return IterableResult */ - public function iterate($stmt, $resultSetMapping, array $hints = array()) + public function iterate($stmt, $resultSetMapping, array $hints = []) { $this->_stmt = $stmt; $this->_rsm = $resultSetMapping; @@ -121,7 +121,7 @@ public function iterate($stmt, $resultSetMapping, array $hints = array()) $evm = $this->_em->getEventManager(); - $evm->addEventListener(array(Events::onClear), $this); + $evm->addEventListener([Events::onClear], $this); $this->prepare(); @@ -137,7 +137,7 @@ public function iterate($stmt, $resultSetMapping, array $hints = array()) * * @return array */ - public function hydrateAll($stmt, $resultSetMapping, array $hints = array()) + public function hydrateAll($stmt, $resultSetMapping, array $hints = []) { $this->_stmt = $stmt; $this->_rsm = $resultSetMapping; @@ -168,7 +168,7 @@ public function hydrateRow() return false; } - $result = array(); + $result = []; $this->hydrateRowData($row, $result); @@ -209,8 +209,8 @@ protected function cleanup() $this->_stmt = null; $this->_rsm = null; - $this->_cache = array(); - $this->_metadataCache = array(); + $this->_cache = []; + $this->_metadataCache = []; } /** @@ -255,7 +255,7 @@ abstract protected function hydrateAllData(); */ protected function gatherRowData(array $data, array &$id, array &$nonemptyComponents) { - $rowData = array('data' => array()); + $rowData = ['data' => []]; foreach ($data as $key => $value) { if (($cacheKeyInfo = $this->hydrateColumnInfo($key)) === null) { @@ -323,7 +323,7 @@ protected function gatherRowData(array $data, array &$id, array &$nonemptyCompon */ protected function gatherScalarRowData(&$data) { - $rowData = array(); + $rowData = []; foreach ($data as $key => $value) { if (($cacheKeyInfo = $this->hydrateColumnInfo($key)) === null) { @@ -369,18 +369,18 @@ protected function hydrateColumnInfo($key) $fieldName = $this->_rsm->fieldMappings[$key]; $fieldMapping = $classMetadata->fieldMappings[$fieldName]; - return $this->_cache[$key] = array( + return $this->_cache[$key] = [ 'isIdentifier' => in_array($fieldName, $classMetadata->identifier), 'fieldName' => $fieldName, 'type' => Type::getType($fieldMapping['type']), 'dqlAlias' => $this->_rsm->columnOwnerMap[$key], - ); + ]; case (isset($this->_rsm->newObjectMappings[$key])): // WARNING: A NEW object is also a scalar, so it must be declared before! $mapping = $this->_rsm->newObjectMappings[$key]; - return $this->_cache[$key] = array( + return $this->_cache[$key] = [ 'isScalar' => true, 'isNewObjectParameter' => true, 'fieldName' => $this->_rsm->scalarMappings[$key], @@ -388,14 +388,14 @@ protected function hydrateColumnInfo($key) 'argIndex' => $mapping['argIndex'], 'objIndex' => $mapping['objIndex'], 'class' => new \ReflectionClass($mapping['className']), - ); + ]; case (isset($this->_rsm->scalarMappings[$key])): - return $this->_cache[$key] = array( + return $this->_cache[$key] = [ 'isScalar' => true, 'fieldName' => $this->_rsm->scalarMappings[$key], 'type' => Type::getType($this->_rsm->typeMappings[$key]), - ); + ]; case (isset($this->_rsm->metaMappings[$key])): // Meta column (has meaning in relational schema only, i.e. foreign keys or discriminator columns). @@ -408,13 +408,13 @@ protected function hydrateColumnInfo($key) // Cache metadata fetch $this->getClassMetadata($this->_rsm->aliasMap[$dqlAlias]); - return $this->_cache[$key] = array( + return $this->_cache[$key] = [ 'isIdentifier' => isset($this->_rsm->isIdentifierColumn[$dqlAlias][$key]), 'isMetaColumn' => true, 'fieldName' => $fieldName, 'type' => $type, 'dqlAlias' => $dqlAlias, - ); + ]; } // this column is a left over, maybe from a LIMIT query hack for example in Oracle or DB2 @@ -452,7 +452,7 @@ protected function getClassMetadata($className) protected function registerManaged(ClassMetadata $class, $entity, array $data) { if ($class->isIdentifierComposite) { - $id = array(); + $id = []; foreach ($class->identifier as $fieldName) { $id[$fieldName] = isset($class->associationMappings[$fieldName]) @@ -461,11 +461,11 @@ protected function registerManaged(ClassMetadata $class, $entity, array $data) } } else { $fieldName = $class->identifier[0]; - $id = array( + $id = [ $fieldName => isset($class->associationMappings[$fieldName]) ? $data[$class->associationMappings[$fieldName]['joinColumns'][0]['name']] : $data[$fieldName] - ); + ]; } $this->_em->getUnitOfWork()->registerManaged($entity, $id, $data); diff --git a/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php index f3e4376f757..c26b99be38c 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php @@ -35,7 +35,7 @@ class ArrayHydrator extends AbstractHydrator /** * @var array */ - private $_rootAliases = array(); + private $_rootAliases = []; /** * @var bool @@ -45,17 +45,17 @@ class ArrayHydrator extends AbstractHydrator /** * @var array */ - private $_identifierMap = array(); + private $_identifierMap = []; /** * @var array */ - private $_resultPointers = array(); + private $_resultPointers = []; /** * @var array */ - private $_idTemplate = array(); + private $_idTemplate = []; /** * @var int @@ -70,8 +70,8 @@ protected function prepare() $this->_isSimpleQuery = count($this->_rsm->aliasMap) <= 1; foreach ($this->_rsm->aliasMap as $dqlAlias => $className) { - $this->_identifierMap[$dqlAlias] = array(); - $this->_resultPointers[$dqlAlias] = array(); + $this->_identifierMap[$dqlAlias] = []; + $this->_resultPointers[$dqlAlias] = []; $this->_idTemplate[$dqlAlias] = ''; } } @@ -81,7 +81,7 @@ protected function prepare() */ protected function hydrateAllData() { - $result = array(); + $result = []; while ($data = $this->_stmt->fetch(PDO::FETCH_ASSOC)) { $this->hydrateRowData($data, $result); @@ -97,7 +97,7 @@ protected function hydrateRowData(array $row, array &$result) { // 1) Initialize $id = $this->_idTemplate; // initialize the id-memory - $nonemptyComponents = array(); + $nonemptyComponents = []; $rowData = $this->gatherRowData($row, $id, $nonemptyComponents); // 2) Now hydrate the data found in the current row. @@ -138,7 +138,7 @@ protected function hydrateRowData(array $row, array &$result) $oneToOne = false; if ( ! isset($baseElement[$relationAlias])) { - $baseElement[$relationAlias] = array(); + $baseElement[$relationAlias] = []; } if (isset($nonemptyComponents[$dqlAlias])) { @@ -187,7 +187,7 @@ protected function hydrateRowData(array $row, array &$result) // if this row has a NULL value for the root result id then make it a null result. if ( ! isset($nonemptyComponents[$dqlAlias]) ) { $result[] = $this->_rsm->isMixed - ? array($entityKey => null) + ? [$entityKey => null] : null; $resultKey = $this->_resultCounter; @@ -199,7 +199,7 @@ protected function hydrateRowData(array $row, array &$result) // Check for an existing element if ($this->_isSimpleQuery || ! isset($this->_identifierMap[$dqlAlias][$id[$dqlAlias]])) { $element = $this->_rsm->isMixed - ? array($entityKey => $data) + ? [$entityKey => $data] : $data; if (isset($this->_rsm->indexByMap[$dqlAlias])) { diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index d2d23a252bf..9d8ee329a44 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -42,17 +42,17 @@ class ObjectHydrator extends AbstractHydrator /** * @var array */ - private $identifierMap = array(); + private $identifierMap = []; /** * @var array */ - private $resultPointers = array(); + private $resultPointers = []; /** * @var array */ - private $idTemplate = array(); + private $idTemplate = []; /** * @var integer @@ -62,17 +62,17 @@ class ObjectHydrator extends AbstractHydrator /** * @var array */ - private $rootAliases = array(); + private $rootAliases = []; /** * @var array */ - private $initializedCollections = array(); + private $initializedCollections = []; /** * @var array */ - private $existingCollections = array(); + private $existingCollections = []; /** * {@inheritdoc} @@ -84,7 +84,7 @@ protected function prepare() } foreach ($this->_rsm->aliasMap as $dqlAlias => $className) { - $this->identifierMap[$dqlAlias] = array(); + $this->identifierMap[$dqlAlias] = []; $this->idTemplate[$dqlAlias] = ''; // Remember which associations are "fetch joined", so that we know where to inject @@ -142,7 +142,7 @@ protected function cleanup() $this->identifierMap = $this->initializedCollections = $this->existingCollections = - $this->resultPointers = array(); + $this->resultPointers = []; if ($eagerLoad) { $this->_uow->triggerEagerLoads(); @@ -156,7 +156,7 @@ protected function cleanup() */ protected function hydrateAllData() { - $result = array(); + $result = []; while ($row = $this->_stmt->fetch(PDO::FETCH_ASSOC)) { $this->hydrateRowData($row, $result); @@ -326,7 +326,7 @@ protected function hydrateRowData(array $row, array &$result) { // Initialize $id = $this->idTemplate; // initialize the id-memory - $nonemptyComponents = array(); + $nonemptyComponents = []; // Split the row data into chunks of class data. $rowData = $this->gatherRowData($row, $id, $nonemptyComponents); @@ -478,7 +478,7 @@ protected function hydrateRowData(array $row, array &$result) // if this row has a NULL value for the root result id then make it a null result. if ( ! isset($nonemptyComponents[$dqlAlias]) ) { if ($this->_rsm->isMixed) { - $result[] = array($entityKey => null); + $result[] = [$entityKey => null]; } else { $result[] = null; } @@ -492,7 +492,7 @@ protected function hydrateRowData(array $row, array &$result) $element = $this->getEntity($data, $dqlAlias); if ($this->_rsm->isMixed) { - $element = array($entityKey => $element); + $element = [$entityKey => $element]; } if (isset($this->_rsm->indexByMap[$dqlAlias])) { diff --git a/lib/Doctrine/ORM/Internal/Hydration/ScalarHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ScalarHydrator.php index 024ee3b6692..093e89c4e13 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ScalarHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ScalarHydrator.php @@ -35,7 +35,7 @@ class ScalarHydrator extends AbstractHydrator */ protected function hydrateAllData() { - $result = array(); + $result = []; while ($data = $this->_stmt->fetch(\PDO::FETCH_ASSOC)) { $this->hydrateRowData($data, $result); diff --git a/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php index 785a2b79680..bf2beaba347 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php @@ -62,7 +62,7 @@ protected function cleanup() */ protected function hydrateAllData() { - $result = array(); + $result = []; while ($row = $this->_stmt->fetch(PDO::FETCH_ASSOC)) { $this->hydrateRowData($row, $result); @@ -79,7 +79,7 @@ protected function hydrateAllData() protected function hydrateRowData(array $sqlResult, array &$result) { $entityName = $this->class->name; - $data = array(); + $data = []; // We need to find the correct entity class name if we have inheritance in resultset if ($this->class->inheritanceType !== ClassMetadata::INHERITANCE_TYPE_NONE) { diff --git a/lib/Doctrine/ORM/Internal/HydrationCompleteHandler.php b/lib/Doctrine/ORM/Internal/HydrationCompleteHandler.php index 4da71cefaf2..72a0c70348e 100644 --- a/lib/Doctrine/ORM/Internal/HydrationCompleteHandler.php +++ b/lib/Doctrine/ORM/Internal/HydrationCompleteHandler.php @@ -47,7 +47,7 @@ final class HydrationCompleteHandler /** * @var array[] */ - private $deferredPostLoadInvocations = array(); + private $deferredPostLoadInvocations = []; /** * Constructor for this object @@ -75,7 +75,7 @@ public function deferPostLoadInvoking(ClassMetadata $class, $entity) return; } - $this->deferredPostLoadInvocations[] = array($class, $invoke, $entity); + $this->deferredPostLoadInvocations[] = [$class, $invoke, $entity]; } /** @@ -86,7 +86,7 @@ public function deferPostLoadInvoking(ClassMetadata $class, $entity) public function hydrationComplete() { $toInvoke = $this->deferredPostLoadInvocations; - $this->deferredPostLoadInvocations = array(); + $this->deferredPostLoadInvocations = []; foreach ($toInvoke as $classAndEntity) { list($class, $invoke, $entity) = $classAndEntity; diff --git a/lib/Doctrine/ORM/Mapping/Builder/AssociationBuilder.php b/lib/Doctrine/ORM/Mapping/Builder/AssociationBuilder.php index 5abfe21bba1..7f4fddc96ba 100644 --- a/lib/Doctrine/ORM/Mapping/Builder/AssociationBuilder.php +++ b/lib/Doctrine/ORM/Mapping/Builder/AssociationBuilder.php @@ -84,7 +84,7 @@ public function inversedBy($fieldName) */ public function cascadeAll() { - $this->mapping['cascade'] = array("ALL"); + $this->mapping['cascade'] = ["ALL"]; return $this; } @@ -183,14 +183,14 @@ public function fetchLazy() */ public function addJoinColumn($columnName, $referencedColumnName, $nullable = true, $unique = false, $onDelete = null, $columnDef = null) { - $this->joinColumns[] = array( + $this->joinColumns[] = [ 'name' => $columnName, 'referencedColumnName' => $referencedColumnName, 'nullable' => $nullable, 'unique' => $unique, 'onDelete' => $onDelete, 'columnDefinition' => $columnDef, - ); + ]; return $this; } diff --git a/lib/Doctrine/ORM/Mapping/Builder/ClassMetadataBuilder.php b/lib/Doctrine/ORM/Mapping/Builder/ClassMetadataBuilder.php index 7d771d3f95a..c08b374feeb 100644 --- a/lib/Doctrine/ORM/Mapping/Builder/ClassMetadataBuilder.php +++ b/lib/Doctrine/ORM/Mapping/Builder/ClassMetadataBuilder.php @@ -91,11 +91,13 @@ public function setEmbeddable() */ public function addEmbedded($fieldName, $class, $columnPrefix = null) { - $this->cm->mapEmbedded(array( - 'fieldName' => $fieldName, - 'class' => $class, - 'columnPrefix' => $columnPrefix - )); + $this->cm->mapEmbedded( + [ + 'fieldName' => $fieldName, + 'class' => $class, + 'columnPrefix' => $columnPrefix + ] + ); return $this; } @@ -135,7 +137,7 @@ public function setReadOnly() */ public function setTable($name) { - $this->cm->setPrimaryTable(array('name' => $name)); + $this->cm->setPrimaryTable(['name' => $name]); return $this; } @@ -151,10 +153,10 @@ public function setTable($name) public function addIndex(array $columns, $name) { if (!isset($this->cm->table['indexes'])) { - $this->cm->table['indexes'] = array(); + $this->cm->table['indexes'] = []; } - $this->cm->table['indexes'][$name] = array('columns' => $columns); + $this->cm->table['indexes'][$name] = ['columns' => $columns]; return $this; } @@ -170,10 +172,10 @@ public function addIndex(array $columns, $name) public function addUniqueConstraint(array $columns, $name) { if ( ! isset($this->cm->table['uniqueConstraints'])) { - $this->cm->table['uniqueConstraints'] = array(); + $this->cm->table['uniqueConstraints'] = []; } - $this->cm->table['uniqueConstraints'][$name] = array('columns' => $columns); + $this->cm->table['uniqueConstraints'][$name] = ['columns' => $columns]; return $this; } @@ -188,10 +190,12 @@ public function addUniqueConstraint(array $columns, $name) */ public function addNamedQuery($name, $dqlQuery) { - $this->cm->addNamedQuery(array( - 'name' => $name, - 'query' => $dqlQuery, - )); + $this->cm->addNamedQuery( + [ + 'name' => $name, + 'query' => $dqlQuery, + ] + ); return $this; } @@ -231,11 +235,13 @@ public function setSingleTableInheritance() */ public function setDiscriminatorColumn($name, $type = 'string', $length = 255) { - $this->cm->setDiscriminatorColumn(array( - 'name' => $name, - 'type' => $type, - 'length' => $length, - )); + $this->cm->setDiscriminatorColumn( + [ + 'name' => $name, + 'type' => $type, + 'length' => $length, + ] + ); return $this; } @@ -303,7 +309,7 @@ public function addLifecycleEvent($methodName, $event) * * @return ClassMetadataBuilder */ - public function addField($name, $type, array $mapping = array()) + public function addField($name, $type, array $mapping = []) { $mapping['fieldName'] = $name; $mapping['type'] = $type; @@ -325,10 +331,10 @@ public function createField($name, $type) { return new FieldBuilder( $this, - array( + [ 'fieldName' => $name, 'type' => $type - ) + ] ); } @@ -344,11 +350,11 @@ public function createEmbedded($fieldName, $class) { return new EmbeddedBuilder( $this, - array( + [ 'fieldName' => $fieldName, 'class' => $class, 'columnPrefix' => null - ) + ] ); } @@ -386,10 +392,10 @@ public function createManyToOne($name, $targetEntity) { return new AssociationBuilder( $this, - array( + [ 'fieldName' => $name, 'targetEntity' => $targetEntity - ), + ], ClassMetadata::MANY_TO_ONE ); } @@ -406,10 +412,10 @@ public function createOneToOne($name, $targetEntity) { return new AssociationBuilder( $this, - array( + [ 'fieldName' => $name, 'targetEntity' => $targetEntity - ), + ], ClassMetadata::ONE_TO_ONE ); } @@ -463,10 +469,10 @@ public function createManyToMany($name, $targetEntity) { return new ManyToManyAssociationBuilder( $this, - array( + [ 'fieldName' => $name, 'targetEntity' => $targetEntity - ), + ], ClassMetadata::MANY_TO_MANY ); } @@ -520,10 +526,10 @@ public function createOneToMany($name, $targetEntity) { return new OneToManyAssociationBuilder( $this, - array( + [ 'fieldName' => $name, 'targetEntity' => $targetEntity - ), + ], ClassMetadata::ONE_TO_MANY ); } diff --git a/lib/Doctrine/ORM/Mapping/Builder/EntityListenerBuilder.php b/lib/Doctrine/ORM/Mapping/Builder/EntityListenerBuilder.php index d17abeac52c..e962726091c 100644 --- a/lib/Doctrine/ORM/Mapping/Builder/EntityListenerBuilder.php +++ b/lib/Doctrine/ORM/Mapping/Builder/EntityListenerBuilder.php @@ -34,7 +34,7 @@ class EntityListenerBuilder /** * @var array Hash-map to handle event names. */ - static private $events = array( + static private $events = [ Events::preRemove => true, Events::postRemove => true, Events::prePersist => true, @@ -43,7 +43,7 @@ class EntityListenerBuilder Events::postUpdate => true, Events::postLoad => true, Events::preFlush => true - ); + ]; /** * Lookup the entity class to find methods that match to event lifecycle names @@ -69,4 +69,4 @@ static public function bindEntityListener(ClassMetadata $metadata, $className) $metadata->addEntityListener($method, $class, $method); } } -} \ No newline at end of file +} diff --git a/lib/Doctrine/ORM/Mapping/Builder/FieldBuilder.php b/lib/Doctrine/ORM/Mapping/Builder/FieldBuilder.php index 5a896678117..d0128d4a933 100644 --- a/lib/Doctrine/ORM/Mapping/Builder/FieldBuilder.php +++ b/lib/Doctrine/ORM/Mapping/Builder/FieldBuilder.php @@ -226,11 +226,11 @@ public function isVersionField() */ public function setSequenceGenerator($sequenceName, $allocationSize = 1, $initialValue = 1) { - $this->sequenceDef = array( + $this->sequenceDef = [ 'sequenceName' => $sequenceName, 'allocationSize' => $allocationSize, 'initialValue' => $initialValue, - ); + ]; return $this; } diff --git a/lib/Doctrine/ORM/Mapping/Builder/ManyToManyAssociationBuilder.php b/lib/Doctrine/ORM/Mapping/Builder/ManyToManyAssociationBuilder.php index 8b167d9964a..a71859dfd38 100644 --- a/lib/Doctrine/ORM/Mapping/Builder/ManyToManyAssociationBuilder.php +++ b/lib/Doctrine/ORM/Mapping/Builder/ManyToManyAssociationBuilder.php @@ -37,7 +37,7 @@ class ManyToManyAssociationBuilder extends OneToManyAssociationBuilder /** * @var array */ - private $inverseJoinColumns = array(); + private $inverseJoinColumns = []; /** * @param string $name @@ -65,14 +65,14 @@ public function setJoinTable($name) */ public function addInverseJoinColumn($columnName, $referencedColumnName, $nullable = true, $unique = false, $onDelete = null, $columnDef = null) { - $this->inverseJoinColumns[] = array( + $this->inverseJoinColumns[] = [ 'name' => $columnName, 'referencedColumnName' => $referencedColumnName, 'nullable' => $nullable, 'unique' => $unique, 'onDelete' => $onDelete, 'columnDefinition' => $columnDef, - ); + ]; return $this; } @@ -83,7 +83,7 @@ public function addInverseJoinColumn($columnName, $referencedColumnName, $nullab public function build() { $mapping = $this->mapping; - $mapping['joinTable'] = array(); + $mapping['joinTable'] = []; if ($this->joinColumns) { $mapping['joinTable']['joinColumns'] = $this->joinColumns; } diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index b42b8b5673d..a1412d2f1ad 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -68,7 +68,7 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory /** * @var array */ - private $embeddablesActiveNesting = array(); + private $embeddablesActiveNesting = []; /** * {@inheritDoc} @@ -350,9 +350,9 @@ private function addDefaultDiscriminatorMap(ClassMetadata $class) { $allClasses = $this->driver->getAllClassNames(); $fqcn = $class->getName(); - $map = array($this->getShortName($class->name) => $fqcn); + $map = [$this->getShortName($class->name) => $fqcn]; - $duplicates = array(); + $duplicates = []; foreach ($allClasses as $subClassCandidate) { if (is_subclass_of($subClassCandidate, $fqcn)) { $shortName = $this->getShortName($subClassCandidate); @@ -475,15 +475,17 @@ private function addNestedEmbeddedClasses(ClassMetadata $subClass, ClassMetadata $embeddableMetadata = $this->getMetadataFor($embeddableClass['class']); - $parentClass->mapEmbedded(array( - 'fieldName' => $prefix . '.' . $property, - 'class' => $embeddableMetadata->name, - 'columnPrefix' => $embeddableClass['columnPrefix'], - 'declaredField' => $embeddableClass['declaredField'] - ? $prefix . '.' . $embeddableClass['declaredField'] - : $prefix, - 'originalField' => $embeddableClass['originalField'] ?: $property, - )); + $parentClass->mapEmbedded( + [ + 'fieldName' => $prefix . '.' . $property, + 'class' => $embeddableMetadata->name, + 'columnPrefix' => $embeddableClass['columnPrefix'], + 'declaredField' => $embeddableClass['declaredField'] + ? $prefix . '.' . $embeddableClass['declaredField'] + : $prefix, + 'originalField' => $embeddableClass['originalField'] ?: $property, + ] + ); } } @@ -501,7 +503,7 @@ private function addInheritedIndexes(ClassMetadata $subClass, ClassMetadata $par return; } - foreach (array('uniqueConstraints', 'indexes') as $indexType) { + foreach (['uniqueConstraints', 'indexes'] as $indexType) { if (isset($parentClass->table[$indexType])) { foreach ($parentClass->table[$indexType] as $indexName => $index) { if (isset($subClass->table[$indexType][$indexName])) { @@ -528,10 +530,12 @@ private function addInheritedNamedQueries(ClassMetadata $subClass, ClassMetadata { foreach ($parentClass->namedQueries as $name => $query) { if ( ! isset ($subClass->namedQueries[$name])) { - $subClass->addNamedQuery(array( - 'name' => $query['name'], - 'query' => $query['query'] - )); + $subClass->addNamedQuery( + [ + 'name' => $query['name'], + 'query' => $query['query'] + ] + ); } } } @@ -550,13 +554,15 @@ private function addInheritedNamedNativeQueries(ClassMetadata $subClass, ClassMe { foreach ($parentClass->namedNativeQueries as $name => $query) { if ( ! isset ($subClass->namedNativeQueries[$name])) { - $subClass->addNamedNativeQuery(array( - 'name' => $query['name'], - 'query' => $query['query'], - 'isSelfClass' => $query['isSelfClass'], - 'resultSetMapping' => $query['resultSetMapping'], - 'resultClass' => $query['isSelfClass'] ? $subClass->name : $query['resultClass'], - )); + $subClass->addNamedNativeQuery( + [ + 'name' => $query['name'], + 'query' => $query['query'], + 'isSelfClass' => $query['isSelfClass'], + 'resultSetMapping' => $query['resultSetMapping'], + 'resultClass' => $query['isSelfClass'] ? $subClass->name : $query['resultClass'], + ] + ); } } } @@ -575,21 +581,23 @@ private function addInheritedSqlResultSetMappings(ClassMetadata $subClass, Class { foreach ($parentClass->sqlResultSetMappings as $name => $mapping) { if ( ! isset ($subClass->sqlResultSetMappings[$name])) { - $entities = array(); + $entities = []; foreach ($mapping['entities'] as $entity) { - $entities[] = array( + $entities[] = [ 'fields' => $entity['fields'], 'isSelfClass' => $entity['isSelfClass'], 'discriminatorColumn' => $entity['discriminatorColumn'], 'entityClass' => $entity['isSelfClass'] ? $subClass->name : $entity['entityClass'], - ); + ]; } - $subClass->addSqlResultSetMapping(array( - 'name' => $mapping['name'], - 'columns' => $mapping['columns'], - 'entities' => $entities, - )); + $subClass->addSqlResultSetMapping( + [ + 'name' => $mapping['name'], + 'columns' => $mapping['columns'], + 'entities' => $entities, + ] + ); } } } @@ -629,9 +637,9 @@ private function completeIdGeneratorMapping(ClassMetadataInfo $class) $quoted = isset($class->fieldMappings[$fieldName]['quoted']) || isset($class->table['quoted']); $sequencePrefix = $class->getSequencePrefix($this->getTargetPlatform()); $sequenceName = $this->getTargetPlatform()->getIdentitySequenceName($sequencePrefix, $columnName); - $definition = array( + $definition = [ 'sequenceName' => $this->getTargetPlatform()->fixSchemaElementName($sequenceName) - ); + ]; if ($quoted) { $definition['quoted'] = true; @@ -661,11 +669,11 @@ private function completeIdGeneratorMapping(ClassMetadataInfo $class) $sequenceName = $class->getSequenceName($this->getTargetPlatform()); $quoted = isset($class->fieldMappings[$fieldName]['quoted']) || isset($class->table['quoted']); - $definition = array( + $definition = [ 'sequenceName' => $this->getTargetPlatform()->fixSchemaElementName($sequenceName), 'allocationSize' => 1, 'initialValue' => 1, - ); + ]; if ($quoted) { $definition['quoted'] = true; diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 3058a2eda14..9a581116391 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -275,28 +275,28 @@ class ClassMetadataInfo implements ClassMetadata * * @var array */ - public $parentClasses = array(); + public $parentClasses = []; /** * READ-ONLY: The names of all subclasses (descendants). * * @var array */ - public $subClasses = array(); + public $subClasses = []; /** * READ-ONLY: The names of all embedded classes based on properties. * * @var array */ - public $embeddedClasses = array(); + public $embeddedClasses = []; /** * READ-ONLY: The named queries allowed to be called directly from Repository. * * @var array */ - public $namedQueries = array(); + public $namedQueries = []; /** * READ-ONLY: The named native queries allowed to be called directly from Repository. @@ -313,7 +313,7 @@ class ClassMetadataInfo implements ClassMetadata * * @var array */ - public $namedNativeQueries = array(); + public $namedNativeQueries = []; /** * READ-ONLY: The mappings of the results of native SQL queries. @@ -329,7 +329,7 @@ class ClassMetadataInfo implements ClassMetadata * * @var array */ - public $sqlResultSetMappings = array(); + public $sqlResultSetMappings = []; /** * READ-ONLY: The field names of all fields that are part of the identifier/primary key @@ -337,7 +337,7 @@ class ClassMetadataInfo implements ClassMetadata * * @var array */ - public $identifier = array(); + public $identifier = []; /** * READ-ONLY: The inheritance mapping type used by the class. @@ -394,7 +394,7 @@ class ClassMetadataInfo implements ClassMetadata * * @var array */ - public $fieldMappings = array(); + public $fieldMappings = []; /** * READ-ONLY: An array of field names. Used to look up field names from column names. @@ -402,7 +402,7 @@ class ClassMetadataInfo implements ClassMetadata * * @var array */ - public $fieldNames = array(); + public $fieldNames = []; /** * READ-ONLY: A map of field names to column names. Keys are field names and values column names. @@ -413,7 +413,7 @@ class ClassMetadataInfo implements ClassMetadata * * @deprecated 3.0 Remove this. */ - public $columnNames = array(); + public $columnNames = []; /** * READ-ONLY: The discriminator value of this class. @@ -437,7 +437,7 @@ class ClassMetadataInfo implements ClassMetadata * * @see discriminatorColumn */ - public $discriminatorMap = array(); + public $discriminatorMap = []; /** * READ-ONLY: The definition of the discriminator column used in JOINED and SINGLE_TABLE @@ -465,14 +465,14 @@ class ClassMetadataInfo implements ClassMetadata * * @var array[] */ - public $lifecycleCallbacks = array(); + public $lifecycleCallbacks = []; /** * READ-ONLY: The registered entity listeners. * * @var array */ - public $entityListeners = array(); + public $entityListeners = []; /** * READ-ONLY: The association mappings of this class. @@ -529,7 +529,7 @@ class ClassMetadataInfo implements ClassMetadata * * @var array */ - public $associationMappings = array(); + public $associationMappings = []; /** * READ-ONLY: Flag indicating whether the identifier/primary key of the class is composite. @@ -642,7 +642,7 @@ class ClassMetadataInfo implements ClassMetadata * * @var \ReflectionProperty[] */ - public $reflFields = array(); + public $reflFields = []; /** * @var \Doctrine\Instantiator\InstantiatorInterface|null @@ -715,7 +715,7 @@ public function getSingleIdReflectionProperty() public function getIdentifierValues($entity) { if ($this->isIdentifierComposite) { - $id = array(); + $id = []; foreach ($this->identifier as $idField) { $value = $this->reflFields[$idField]->getValue($entity); @@ -732,10 +732,10 @@ public function getIdentifierValues($entity) $value = $this->reflFields[$id]->getValue($entity); if (null === $value) { - return array(); + return []; } - return array($id => $value); + return [$id => $value]; } /** @@ -810,7 +810,7 @@ public function __toString() public function __sleep() { // This metadata is always serialized/cached. - $serialized = array( + $serialized = [ 'associationMappings', 'columnNames', //TODO: 3.0 Remove this. Can use fieldMappings[$fieldName]['columnName'] 'fieldMappings', @@ -823,7 +823,7 @@ public function __sleep() 'table', 'rootEntityName', 'idGenerator', //TODO: Does not really need to be serialized. Could be moved to runtime. - ); + ]; // The rest of the metadata is only serialized if necessary. if ($this->changeTrackingPolicy != self::CHANGETRACKING_DEFERRED_IMPLICIT) { @@ -925,7 +925,7 @@ public function wakeupReflection($reflService) $this->reflClass = $reflService->getClass($this->name); $this->instantiator = $this->instantiator ?: new Instantiator(); - $parentReflFields = array(); + $parentReflFields = []; foreach ($this->embeddedClasses as $property => $embeddedClass) { if (isset($embeddedClass['declaredField'])) { @@ -1533,9 +1533,9 @@ protected function _validateAndCompleteAssociationMapping(array $mapping) } // Cascades - $cascades = isset($mapping['cascade']) ? array_map('strtolower', $mapping['cascade']) : array(); + $cascades = isset($mapping['cascade']) ? array_map('strtolower', $mapping['cascade']) : []; - $allCascades = array('remove', 'persist', 'refresh', 'merge', 'detach'); + $allCascades = ['remove', 'persist', 'refresh', 'merge', 'detach']; if (in_array('all', $cascades)) { $cascades = $allCascades; } elseif (count($cascades) !== count(array_intersect($cascades, $allCascades))) { @@ -1577,15 +1577,15 @@ protected function _validateAndCompleteOneToOneMapping(array $mapping) if ($mapping['isOwningSide']) { if (empty($mapping['joinColumns'])) { // Apply default join column - $mapping['joinColumns'] = array( - array( + $mapping['joinColumns'] = [ + [ 'name' => $this->namingStrategy->joinColumnName($mapping['fieldName'], $this->name), 'referencedColumnName' => $this->namingStrategy->referenceColumnName() - ) - ); + ] + ]; } - $uniqueConstraintColumns = array(); + $uniqueConstraintColumns = []; foreach ($mapping['joinColumns'] as &$joinColumn) { if ($mapping['type'] === self::ONE_TO_ONE && ! $this->isInheritanceTypeSingleTable()) { @@ -1627,9 +1627,9 @@ protected function _validateAndCompleteOneToOneMapping(array $mapping) throw new RuntimeException("ClassMetadataInfo::setTable() has to be called before defining a one to one relationship."); } - $this->table['uniqueConstraints'][$mapping['fieldName'] . "_uniq"] = array( + $this->table['uniqueConstraints'][$mapping['fieldName'] . "_uniq"] = [ 'columns' => $uniqueConstraintColumns - ); + ]; } $mapping['targetToSourceKeyColumns'] = array_flip($mapping['sourceToTargetKeyColumns']); @@ -1699,26 +1699,26 @@ protected function _validateAndCompleteManyToManyMapping(array $mapping) && (! (isset($mapping['joinTable']['joinColumns']) || isset($mapping['joinTable']['inverseJoinColumns']))); if ( ! isset($mapping['joinTable']['joinColumns'])) { - $mapping['joinTable']['joinColumns'] = array( - array( + $mapping['joinTable']['joinColumns'] = [ + [ 'name' => $this->namingStrategy->joinKeyColumnName($mapping['sourceEntity'], $selfReferencingEntityWithoutJoinColumns ? 'source' : null), 'referencedColumnName' => $this->namingStrategy->referenceColumnName(), 'onDelete' => 'CASCADE' - ) - ); + ] + ]; } if ( ! isset($mapping['joinTable']['inverseJoinColumns'])) { - $mapping['joinTable']['inverseJoinColumns'] = array( - array( + $mapping['joinTable']['inverseJoinColumns'] = [ + [ 'name' => $this->namingStrategy->joinKeyColumnName($mapping['targetEntity'], $selfReferencingEntityWithoutJoinColumns ? 'target' : null), 'referencedColumnName' => $this->namingStrategy->referenceColumnName(), 'onDelete' => 'CASCADE' - ) - ); + ] + ]; } - $mapping['joinTableColumns'] = array(); + $mapping['joinTableColumns'] = []; foreach ($mapping['joinTable']['joinColumns'] as &$joinColumn) { if (empty($joinColumn['name'])) { @@ -1874,7 +1874,7 @@ public function getColumnNames(array $fieldNames = null) */ public function getIdentifierColumnNames() { - $columnNames = array(); + $columnNames = []; foreach ($this->identifier as $idProperty) { if (isset($this->fieldMappings[$idProperty])) { @@ -2411,11 +2411,11 @@ public function addNamedQuery(array $queryMapping) $query = $queryMapping['query']; $dql = str_replace('__CLASS__', $this->name, $query); - $this->namedQueries[$name] = array( + $this->namedQueries[$name] = [ 'name' => $name, 'query' => $query, 'dql' => $dql, - ); + ]; } /** @@ -2657,7 +2657,7 @@ public function hasLifecycleCallbacks($lifecycleEvent) */ public function getLifecycleCallbacks($event) { - return isset($this->lifecycleCallbacks[$event]) ? $this->lifecycleCallbacks[$event] : array(); + return isset($this->lifecycleCallbacks[$event]) ? $this->lifecycleCallbacks[$event] : []; } /** @@ -2703,10 +2703,10 @@ public function addEntityListener($eventName, $class, $method) { $class = $this->fullyQualifiedClassName($class); - $listener = array( + $listener = [ 'class' => $class, 'method' => $method, - ); + ]; if ( ! class_exists($class)) { throw MappingException::entityListenerClassNotFound($class, $this->name); @@ -2753,7 +2753,7 @@ public function setDiscriminatorColumn($columnDef) $columnDef['type'] = "string"; } - if (in_array($columnDef['type'], array("boolean", "array", "object", "datetime", "time", "date"))) { + if (in_array($columnDef['type'], ["boolean", "array", "object", "datetime", "time", "date"])) { throw MappingException::invalidDiscriminatorColumnType($this->name, $columnDef['type']); } @@ -3021,7 +3021,7 @@ public function setVersionMapping(array &$mapping) $this->versionField = $mapping['fieldName']; if ( ! isset($mapping['default'])) { - if (in_array($mapping['type'], array('integer', 'bigint', 'smallint'))) { + if (in_array($mapping['type'], ['integer', 'bigint', 'smallint'])) { $mapping['default'] = 1; } else if ($mapping['type'] == 'datetime') { $mapping['default'] = 'CURRENT_TIMESTAMP'; @@ -3115,7 +3115,7 @@ public function getName() */ public function getQuotedIdentifierColumnNames($platform) { - $quotedColumnNames = array(); + $quotedColumnNames = []; foreach ($this->identifier as $idProperty) { if (isset($this->fieldMappings[$idProperty])) { @@ -3217,7 +3217,7 @@ public function getAssociationMappedByTargetField($fieldName) */ public function getAssociationsByTargetClass($targetClass) { - $relations = array(); + $relations = []; foreach ($this->associationMappings as $mapping) { if ($mapping['targetEntity'] == $targetClass) { @@ -3273,12 +3273,12 @@ public function mapEmbedded(array $mapping) { $this->assertFieldNotMapped($mapping['fieldName']); - $this->embeddedClasses[$mapping['fieldName']] = array( + $this->embeddedClasses[$mapping['fieldName']] = [ 'class' => $this->fullyQualifiedClassName($mapping['class']), 'columnPrefix' => $mapping['columnPrefix'], 'declaredField' => isset($mapping['declaredField']) ? $mapping['declaredField'] : null, 'originalField' => isset($mapping['originalField']) ? $mapping['originalField'] : null, - ); + ]; } /** diff --git a/lib/Doctrine/ORM/Mapping/Column.php b/lib/Doctrine/ORM/Mapping/Column.php index 70337323f6f..711590be672 100644 --- a/lib/Doctrine/ORM/Mapping/Column.php +++ b/lib/Doctrine/ORM/Mapping/Column.php @@ -67,7 +67,7 @@ final class Column implements Annotation /** * @var array */ - public $options = array(); + public $options = []; /** * @var string diff --git a/lib/Doctrine/ORM/Mapping/DefaultEntityListenerResolver.php b/lib/Doctrine/ORM/Mapping/DefaultEntityListenerResolver.php index 75658547e17..a8ee2dc783d 100644 --- a/lib/Doctrine/ORM/Mapping/DefaultEntityListenerResolver.php +++ b/lib/Doctrine/ORM/Mapping/DefaultEntityListenerResolver.php @@ -31,7 +31,7 @@ class DefaultEntityListenerResolver implements EntityListenerResolver /** * @var array Map to store entity listener instances. */ - private $instances = array(); + private $instances = []; /** * {@inheritdoc} @@ -39,7 +39,7 @@ class DefaultEntityListenerResolver implements EntityListenerResolver public function clear($className = null) { if ($className === null) { - $this->instances = array(); + $this->instances = []; return; } @@ -72,4 +72,4 @@ public function resolve($className) return $this->instances[$className] = new $className(); } -} \ No newline at end of file +} diff --git a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php index dfbded8a4a9..6929edfe452 100644 --- a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php @@ -116,7 +116,7 @@ public function getJoinTableName(array $association, ClassMetadata $class, Abstr */ public function getIdentifierColumnNames(ClassMetadata $class, AbstractPlatform $platform) { - $quotedColumnNames = array(); + $quotedColumnNames = []; foreach ($class->identifier as $fieldName) { if (isset($class->fieldMappings[$fieldName])) { diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index 9dd64bbd33a..0ed36d89568 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -42,10 +42,10 @@ class AnnotationDriver extends AbstractAnnotationDriver /** * {@inheritDoc} */ - protected $entityAnnotationClasses = array( + protected $entityAnnotationClasses = [ 'Doctrine\ORM\Mapping\Entity' => 1, 'Doctrine\ORM\Mapping\MappedSuperclass' => 2, - ); + ]; /** * {@inheritDoc} @@ -97,14 +97,14 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Evaluate Table annotation if (isset($classAnnotations['Doctrine\ORM\Mapping\Table'])) { $tableAnnot = $classAnnotations['Doctrine\ORM\Mapping\Table']; - $primaryTable = array( + $primaryTable = [ 'name' => $tableAnnot->name, 'schema' => $tableAnnot->schema - ); + ]; if ($tableAnnot->indexes !== null) { foreach ($tableAnnot->indexes as $indexAnnot) { - $index = array('columns' => $indexAnnot->columns); + $index = ['columns' => $indexAnnot->columns]; if ( ! empty($indexAnnot->flags)) { $index['flags'] = $indexAnnot->flags; @@ -124,7 +124,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) if ($tableAnnot->uniqueConstraints !== null) { foreach ($tableAnnot->uniqueConstraints as $uniqueConstraintAnnot) { - $uniqueConstraint = array('columns' => $uniqueConstraintAnnot->columns); + $uniqueConstraint = ['columns' => $uniqueConstraintAnnot->columns]; if ( ! empty($uniqueConstraintAnnot->options)) { $uniqueConstraint['options'] = $uniqueConstraintAnnot->options; @@ -148,10 +148,10 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Evaluate @Cache annotation if (isset($classAnnotations['Doctrine\ORM\Mapping\Cache'])) { $cacheAnnot = $classAnnotations['Doctrine\ORM\Mapping\Cache']; - $cacheMap = array( + $cacheMap = [ 'region' => $cacheAnnot->region, 'usage' => constant('Doctrine\ORM\Mapping\ClassMetadata::CACHE_USAGE_' . $cacheAnnot->usage), - ); + ]; $metadata->enableCache($cacheMap); } @@ -161,12 +161,14 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $namedNativeQueriesAnnot = $classAnnotations['Doctrine\ORM\Mapping\NamedNativeQueries']; foreach ($namedNativeQueriesAnnot->value as $namedNativeQuery) { - $metadata->addNamedNativeQuery(array( - 'name' => $namedNativeQuery->name, - 'query' => $namedNativeQuery->query, - 'resultClass' => $namedNativeQuery->resultClass, - 'resultSetMapping' => $namedNativeQuery->resultSetMapping, - )); + $metadata->addNamedNativeQuery( + [ + 'name' => $namedNativeQuery->name, + 'query' => $namedNativeQuery->query, + 'resultClass' => $namedNativeQuery->resultClass, + 'resultSetMapping' => $namedNativeQuery->resultSetMapping, + ] + ); } } @@ -175,36 +177,38 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $sqlResultSetMappingsAnnot = $classAnnotations['Doctrine\ORM\Mapping\SqlResultSetMappings']; foreach ($sqlResultSetMappingsAnnot->value as $resultSetMapping) { - $entities = array(); - $columns = array(); + $entities = []; + $columns = []; foreach ($resultSetMapping->entities as $entityResultAnnot) { - $entityResult = array( - 'fields' => array(), + $entityResult = [ + 'fields' => [], 'entityClass' => $entityResultAnnot->entityClass, 'discriminatorColumn' => $entityResultAnnot->discriminatorColumn, - ); + ]; foreach ($entityResultAnnot->fields as $fieldResultAnnot) { - $entityResult['fields'][] = array( + $entityResult['fields'][] = [ 'name' => $fieldResultAnnot->name, 'column' => $fieldResultAnnot->column - ); + ]; } $entities[] = $entityResult; } foreach ($resultSetMapping->columns as $columnResultAnnot) { - $columns[] = array( + $columns[] = [ 'name' => $columnResultAnnot->name, - ); + ]; } - $metadata->addSqlResultSetMapping(array( - 'name' => $resultSetMapping->name, - 'entities' => $entities, - 'columns' => $columns - )); + $metadata->addSqlResultSetMapping( + [ + 'name' => $resultSetMapping->name, + 'entities' => $entities, + 'columns' => $columns + ] + ); } } @@ -220,10 +224,12 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) if ( ! ($namedQuery instanceof \Doctrine\ORM\Mapping\NamedQuery)) { throw new \UnexpectedValueException("@NamedQueries should contain an array of @NamedQuery annotations."); } - $metadata->addNamedQuery(array( - 'name' => $namedQuery->name, - 'query' => $namedQuery->query - )); + $metadata->addNamedQuery( + [ + 'name' => $namedQuery->name, + 'query' => $namedQuery->query + ] + ); } } @@ -240,14 +246,16 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) if (isset($classAnnotations['Doctrine\ORM\Mapping\DiscriminatorColumn'])) { $discrColumnAnnot = $classAnnotations['Doctrine\ORM\Mapping\DiscriminatorColumn']; - $metadata->setDiscriminatorColumn(array( - 'name' => $discrColumnAnnot->name, - 'type' => $discrColumnAnnot->type ?: 'string', - 'length' => $discrColumnAnnot->length ?: 255, - 'columnDefinition' => $discrColumnAnnot->columnDefinition, - )); + $metadata->setDiscriminatorColumn( + [ + 'name' => $discrColumnAnnot->name, + 'type' => $discrColumnAnnot->type ?: 'string', + 'length' => $discrColumnAnnot->length ?: 255, + 'columnDefinition' => $discrColumnAnnot->columnDefinition, + ] + ); } else { - $metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255)); + $metadata->setDiscriminatorColumn(['name' => 'dtype', 'type' => 'string', 'length' => 255]); } // Evaluate DiscriminatorMap annotation @@ -278,18 +286,21 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) continue; } - $mapping = array(); + $mapping = []; $mapping['fieldName'] = $property->getName(); // Evaluate @Cache annotation if (($cacheAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Cache')) !== null) { - $mapping['cache'] = $metadata->getAssociationCacheDefaults($mapping['fieldName'], array( - 'usage' => constant('Doctrine\ORM\Mapping\ClassMetadata::CACHE_USAGE_' . $cacheAnnot->usage), - 'region' => $cacheAnnot->region, - )); + $mapping['cache'] = $metadata->getAssociationCacheDefaults( + $mapping['fieldName'], + [ + 'usage' => constant('Doctrine\ORM\Mapping\ClassMetadata::CACHE_USAGE_' . $cacheAnnot->usage), + 'region' => $cacheAnnot->region, + ] + ); } // Check for JoinColumn/JoinColumns annotations - $joinColumns = array(); + $joinColumns = []; if ($joinColumnAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinColumn')) { $joinColumns[] = $this->joinColumnToArray($joinColumnAnnot); @@ -324,17 +335,21 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Check for SequenceGenerator/TableGenerator definition if ($seqGeneratorAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\SequenceGenerator')) { - $metadata->setSequenceGeneratorDefinition(array( - 'sequenceName' => $seqGeneratorAnnot->sequenceName, - 'allocationSize' => $seqGeneratorAnnot->allocationSize, - 'initialValue' => $seqGeneratorAnnot->initialValue - )); + $metadata->setSequenceGeneratorDefinition( + [ + 'sequenceName' => $seqGeneratorAnnot->sequenceName, + 'allocationSize' => $seqGeneratorAnnot->allocationSize, + 'initialValue' => $seqGeneratorAnnot->initialValue + ] + ); } else if ($this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\TableGenerator')) { throw MappingException::tableIdGeneratorNotImplemented($className); } else if ($customGeneratorAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\CustomIdGenerator')) { - $metadata->setCustomGeneratorDefinition(array( - 'class' => $customGeneratorAnnot->class - )); + $metadata->setCustomGeneratorDefinition( + [ + 'class' => $customGeneratorAnnot->class + ] + ); } } else if ($oneToOneAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OneToOne')) { if ($idAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) { @@ -374,13 +389,13 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $mapping['fetch'] = $this->getFetchMode($className, $manyToOneAnnot->fetch); $metadata->mapManyToOne($mapping); } else if ($manyToManyAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\ManyToMany')) { - $joinTable = array(); + $joinTable = []; if ($joinTableAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinTable')) { - $joinTable = array( + $joinTable = [ 'name' => $joinTableAnnot->name, 'schema' => $joinTableAnnot->schema - ); + ]; foreach ($joinTableAnnot->joinColumns as $joinColumn) { $joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumn); @@ -418,12 +433,12 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $associationOverridesAnnot = $classAnnotations['Doctrine\ORM\Mapping\AssociationOverrides']; foreach ($associationOverridesAnnot->value as $associationOverride) { - $override = array(); + $override = []; $fieldName = $associationOverride->name; // Check for JoinColumn/JoinColumns annotations if ($associationOverride->joinColumns) { - $joinColumns = array(); + $joinColumns = []; foreach ($associationOverride->joinColumns as $joinColumn) { $joinColumns[] = $this->joinColumnToArray($joinColumn); @@ -435,10 +450,10 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Check for JoinTable annotations if ($associationOverride->joinTable) { $joinTableAnnot = $associationOverride->joinTable; - $joinTable = array( + $joinTable = [ 'name' => $joinTableAnnot->name, 'schema' => $joinTableAnnot->schema - ); + ]; foreach ($joinTableAnnot->joinColumns as $joinColumn) { $joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumn); @@ -542,40 +557,40 @@ private function getFetchMode($className, $fetchMode) */ private function getMethodCallbacks(\ReflectionMethod $method) { - $callbacks = array(); + $callbacks = []; $annotations = $this->reader->getMethodAnnotations($method); foreach ($annotations as $annot) { if ($annot instanceof \Doctrine\ORM\Mapping\PrePersist) { - $callbacks[] = array($method->name, Events::prePersist); + $callbacks[] = [$method->name, Events::prePersist]; } if ($annot instanceof \Doctrine\ORM\Mapping\PostPersist) { - $callbacks[] = array($method->name, Events::postPersist); + $callbacks[] = [$method->name, Events::postPersist]; } if ($annot instanceof \Doctrine\ORM\Mapping\PreUpdate) { - $callbacks[] = array($method->name, Events::preUpdate); + $callbacks[] = [$method->name, Events::preUpdate]; } if ($annot instanceof \Doctrine\ORM\Mapping\PostUpdate) { - $callbacks[] = array($method->name, Events::postUpdate); + $callbacks[] = [$method->name, Events::postUpdate]; } if ($annot instanceof \Doctrine\ORM\Mapping\PreRemove) { - $callbacks[] = array($method->name, Events::preRemove); + $callbacks[] = [$method->name, Events::preRemove]; } if ($annot instanceof \Doctrine\ORM\Mapping\PostRemove) { - $callbacks[] = array($method->name, Events::postRemove); + $callbacks[] = [$method->name, Events::postRemove]; } if ($annot instanceof \Doctrine\ORM\Mapping\PostLoad) { - $callbacks[] = array($method->name, Events::postLoad); + $callbacks[] = [$method->name, Events::postLoad]; } if ($annot instanceof \Doctrine\ORM\Mapping\PreFlush) { - $callbacks[] = array($method->name, Events::preFlush); + $callbacks[] = [$method->name, Events::preFlush]; } } @@ -590,14 +605,14 @@ private function getMethodCallbacks(\ReflectionMethod $method) */ private function joinColumnToArray(JoinColumn $joinColumn) { - return array( + return [ 'name' => $joinColumn->name, 'unique' => $joinColumn->unique, 'nullable' => $joinColumn->nullable, 'onDelete' => $joinColumn->onDelete, 'columnDefinition' => $joinColumn->columnDefinition, 'referencedColumnName' => $joinColumn->referencedColumnName, - ); + ]; } /** @@ -610,7 +625,7 @@ private function joinColumnToArray(JoinColumn $joinColumn) */ private function columnToArray($fieldName, Column $column) { - $mapping = array( + $mapping = [ 'fieldName' => $fieldName, 'type' => $column->type, 'scale' => $column->scale, @@ -618,7 +633,7 @@ private function columnToArray($fieldName, Column $column) 'unique' => $column->unique, 'nullable' => $column->nullable, 'precision' => $column->precision - ); + ]; if ($column->options) { $mapping['options'] = $column->options; @@ -643,7 +658,7 @@ private function columnToArray($fieldName, Column $column) * * @return AnnotationDriver */ - static public function create($paths = array(), AnnotationReader $reader = null) + static public function create($paths = [], AnnotationReader $reader = null) { if ($reader == null) { $reader = new AnnotationReader(); diff --git a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php index d6ddaf2d048..9389feb81ec 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php @@ -54,22 +54,22 @@ class DatabaseDriver implements MappingDriver /** * @var array */ - private $classToTableNames = array(); + private $classToTableNames = []; /** * @var array */ - private $manyToManyTables = array(); + private $manyToManyTables = []; /** * @var array */ - private $classNamesForTables = array(); + private $classNamesForTables = []; /** * @var array */ - private $fieldNamesForColumns = array(); + private $fieldNamesForColumns = []; /** * The namespace for the generated entities. @@ -153,7 +153,7 @@ public function setFieldNameForColumn($tableName, $columnName, $fieldName) */ public function setTables($entityTables, $manyToManyTables) { - $this->tables = $this->manyToManyTables = $this->classToTableNames = array(); + $this->tables = $this->manyToManyTables = $this->classToTableNames = []; foreach ($entityTables as $table) { $className = $this->getClassNameForTable($table->getName()); @@ -212,36 +212,36 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $localColumn = current($myFk->getColumns()); - $associationMapping = array(); + $associationMapping = []; $associationMapping['fieldName'] = $this->getFieldNameForColumn($manyTable->getName(), current($otherFk->getColumns()), true); $associationMapping['targetEntity'] = $this->getClassNameForTable($otherFk->getForeignTableName()); if (current($manyTable->getColumns())->getName() == $localColumn) { $associationMapping['inversedBy'] = $this->getFieldNameForColumn($manyTable->getName(), current($myFk->getColumns()), true); - $associationMapping['joinTable'] = array( + $associationMapping['joinTable'] = [ 'name' => strtolower($manyTable->getName()), - 'joinColumns' => array(), - 'inverseJoinColumns' => array(), - ); + 'joinColumns' => [], + 'inverseJoinColumns' => [], + ]; $fkCols = $myFk->getForeignColumns(); $cols = $myFk->getColumns(); for ($i = 0, $colsCount = count($cols); $i < $colsCount; $i++) { - $associationMapping['joinTable']['joinColumns'][] = array( + $associationMapping['joinTable']['joinColumns'][] = [ 'name' => $cols[$i], 'referencedColumnName' => $fkCols[$i], - ); + ]; } $fkCols = $otherFk->getForeignColumns(); $cols = $otherFk->getColumns(); for ($i = 0, $colsCount = count($cols); $i < $colsCount; $i++) { - $associationMapping['joinTable']['inverseJoinColumns'][] = array( + $associationMapping['joinTable']['inverseJoinColumns'][] = [ 'name' => $cols[$i], 'referencedColumnName' => $fkCols[$i], - ); + ]; } } else { $associationMapping['mappedBy'] = $this->getFieldNameForColumn($manyTable->getName(), current($myFk->getColumns()), true); @@ -265,20 +265,20 @@ private function reverseEngineerMappingFromDatabase() return; } - $tables = array(); + $tables = []; foreach ($this->_sm->listTableNames() as $tableName) { $tables[$tableName] = $this->_sm->listTableDetails($tableName); } - $this->tables = $this->manyToManyTables = $this->classToTableNames = array(); + $this->tables = $this->manyToManyTables = $this->classToTableNames = []; foreach ($tables as $tableName => $table) { $foreignKeys = ($this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) ? $table->getForeignKeys() - : array(); + : []; - $allForeignKeyColumns = array(); + $allForeignKeyColumns = []; foreach ($foreignKeys as $foreignKey) { $allForeignKeyColumns = array_merge($allForeignKeyColumns, $foreignKey->getLocalColumns()); @@ -345,14 +345,14 @@ private function buildFieldMappings(ClassMetadataInfo $metadata) $columns = $this->tables[$tableName]->getColumns(); $primaryKeys = $this->getTablePrimaryKeys($this->tables[$tableName]); $foreignKeys = $this->getTableForeignKeys($this->tables[$tableName]); - $allForeignKeys = array(); + $allForeignKeys = []; foreach ($foreignKeys as $foreignKey) { $allForeignKeys = array_merge($allForeignKeys, $foreignKey->getLocalColumns()); } - $ids = array(); - $fieldMappings = array(); + $ids = []; + $fieldMappings = []; foreach ($columns as $column) { if (in_array($column->getName(), $allForeignKeys)) { @@ -389,12 +389,12 @@ private function buildFieldMappings(ClassMetadataInfo $metadata) */ private function buildFieldMapping($tableName, Column $column) { - $fieldMapping = array( + $fieldMapping = [ 'fieldName' => $this->getFieldNameForColumn($tableName, $column->getName(), false), 'columnName' => $column->getName(), 'type' => $column->getType()->getName(), 'nullable' => ( ! $column->getNotNull()), - ); + ]; // Type specific elements switch ($fieldMapping['type']) { @@ -452,10 +452,10 @@ private function buildToOneAssociationMappings(ClassMetadataInfo $metadata) $fkColumns = $foreignKey->getColumns(); $fkForeignColumns = $foreignKey->getForeignColumns(); $localColumn = current($fkColumns); - $associationMapping = array( + $associationMapping = [ 'fieldName' => $this->getFieldNameForColumn($tableName, $localColumn, true), 'targetEntity' => $this->getClassNameForTable($foreignTableName), - ); + ]; if (isset($metadata->fieldMappings[$associationMapping['fieldName']])) { $associationMapping['fieldName'] .= '2'; // "foo" => "foo2" @@ -466,10 +466,10 @@ private function buildToOneAssociationMappings(ClassMetadataInfo $metadata) } for ($i = 0, $fkColumnsCount = count($fkColumns); $i < $fkColumnsCount; $i++) { - $associationMapping['joinColumns'][] = array( + $associationMapping['joinColumns'][] = [ 'name' => $fkColumns[$i], 'referencedColumnName' => $fkForeignColumns[$i], - ); + ]; } // Here we need to check if $fkColumns are the same as $primaryKeys @@ -492,7 +492,7 @@ private function getTableForeignKeys(Table $table) { return ($this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) ? $table->getForeignKeys() - : array(); + : []; } /** @@ -510,7 +510,7 @@ private function getTablePrimaryKeys(Table $table) // Do nothing } - return array(); + return []; } /** diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 3d849918094..d7099663f4f 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -76,7 +76,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) } // Evaluate attributes - $primaryTable = array(); + $primaryTable = []; if (isset($xmlRoot['table'])) { $primaryTable['name'] = (string) $xmlRoot['table']; @@ -96,44 +96,48 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Evaluate named queries if (isset($xmlRoot->{'named-queries'})) { foreach ($xmlRoot->{'named-queries'}->{'named-query'} as $namedQueryElement) { - $metadata->addNamedQuery(array( - 'name' => (string) $namedQueryElement['name'], - 'query' => (string) $namedQueryElement['query'] - )); + $metadata->addNamedQuery( + [ + 'name' => (string) $namedQueryElement['name'], + 'query' => (string) $namedQueryElement['query'] + ] + ); } } // Evaluate native named queries if (isset($xmlRoot->{'named-native-queries'})) { foreach ($xmlRoot->{'named-native-queries'}->{'named-native-query'} as $nativeQueryElement) { - $metadata->addNamedNativeQuery(array( - 'name' => isset($nativeQueryElement['name']) ? (string) $nativeQueryElement['name'] : null, - 'query' => isset($nativeQueryElement->query) ? (string) $nativeQueryElement->query : null, - 'resultClass' => isset($nativeQueryElement['result-class']) ? (string) $nativeQueryElement['result-class'] : null, - 'resultSetMapping' => isset($nativeQueryElement['result-set-mapping']) ? (string) $nativeQueryElement['result-set-mapping'] : null, - )); + $metadata->addNamedNativeQuery( + [ + 'name' => isset($nativeQueryElement['name']) ? (string) $nativeQueryElement['name'] : null, + 'query' => isset($nativeQueryElement->query) ? (string) $nativeQueryElement->query : null, + 'resultClass' => isset($nativeQueryElement['result-class']) ? (string) $nativeQueryElement['result-class'] : null, + 'resultSetMapping' => isset($nativeQueryElement['result-set-mapping']) ? (string) $nativeQueryElement['result-set-mapping'] : null, + ] + ); } } // Evaluate sql result set mapping if (isset($xmlRoot->{'sql-result-set-mappings'})) { foreach ($xmlRoot->{'sql-result-set-mappings'}->{'sql-result-set-mapping'} as $rsmElement) { - $entities = array(); - $columns = array(); + $entities = []; + $columns = []; foreach ($rsmElement as $entityElement) { // if (isset($entityElement['entity-class'])) { - $entityResult = array( - 'fields' => array(), + $entityResult = [ + 'fields' => [], 'entityClass' => (string) $entityElement['entity-class'], 'discriminatorColumn' => isset($entityElement['discriminator-column']) ? (string) $entityElement['discriminator-column'] : null, - ); + ]; foreach ($entityElement as $fieldElement) { - $entityResult['fields'][] = array( + $entityResult['fields'][] = [ 'name' => isset($fieldElement['name']) ? (string) $fieldElement['name'] : null, 'column' => isset($fieldElement['column']) ? (string) $fieldElement['column'] : null, - ); + ]; } $entities[] = $entityResult; @@ -141,17 +145,19 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // if (isset($entityElement['name'])) { - $columns[] = array( + $columns[] = [ 'name' => (string) $entityElement['name'], - ); + ]; } } - $metadata->addSqlResultSetMapping(array( - 'name' => (string) $rsmElement['name'], - 'entities' => $entities, - 'columns' => $columns - )); + $metadata->addSqlResultSetMapping( + [ + 'name' => (string) $rsmElement['name'], + 'entities' => $entities, + 'columns' => $columns + ] + ); } } @@ -163,19 +169,21 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Evaluate if (isset($xmlRoot->{'discriminator-column'})) { $discrColumn = $xmlRoot->{'discriminator-column'}; - $metadata->setDiscriminatorColumn(array( - 'name' => isset($discrColumn['name']) ? (string) $discrColumn['name'] : null, - 'type' => isset($discrColumn['type']) ? (string) $discrColumn['type'] : 'string', - 'length' => isset($discrColumn['length']) ? (string) $discrColumn['length'] : 255, - 'columnDefinition' => isset($discrColumn['column-definition']) ? (string) $discrColumn['column-definition'] : null - )); + $metadata->setDiscriminatorColumn( + [ + 'name' => isset($discrColumn['name']) ? (string) $discrColumn['name'] : null, + 'type' => isset($discrColumn['type']) ? (string) $discrColumn['type'] : 'string', + 'length' => isset($discrColumn['length']) ? (string) $discrColumn['length'] : 255, + 'columnDefinition' => isset($discrColumn['column-definition']) ? (string) $discrColumn['column-definition'] : null + ] + ); } else { - $metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255)); + $metadata->setDiscriminatorColumn(['name' => 'dtype', 'type' => 'string', 'length' => 255]); } // Evaluate if (isset($xmlRoot->{'discriminator-map'})) { - $map = array(); + $map = []; foreach ($xmlRoot->{'discriminator-map'}->{'discriminator-mapping'} as $discrMapElement) { $map[(string) $discrMapElement['value']] = (string) $discrMapElement['class']; } @@ -193,9 +201,9 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Evaluate if (isset($xmlRoot->indexes)) { - $metadata->table['indexes'] = array(); + $metadata->table['indexes'] = []; foreach ($xmlRoot->indexes->index as $indexXml) { - $index = array('columns' => explode(',', (string) $indexXml['columns'])); + $index = ['columns' => explode(',', (string) $indexXml['columns'])]; if (isset($indexXml['flags'])) { $index['flags'] = explode(',', (string) $indexXml['flags']); @@ -215,10 +223,9 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Evaluate if (isset($xmlRoot->{'unique-constraints'})) { - $metadata->table['uniqueConstraints'] = array(); + $metadata->table['uniqueConstraints'] = []; foreach ($xmlRoot->{'unique-constraints'}->{'unique-constraint'} as $uniqueXml) { - $unique = array('columns' => explode(',', (string) $uniqueXml['columns'])); - + $unique = ['columns' => explode(',', (string) $uniqueXml['columns'])]; if (isset($uniqueXml->options)) { $unique['options'] = $this->_parseOptions($uniqueXml->options->children()); @@ -238,7 +245,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // The mapping assignment is done in 2 times as a bug might occurs on some php/xml lib versions // The internal SimpleXmlIterator get resetted, to this generate a duplicate field exception - $mappings = array(); + $mappings = []; // Evaluate mappings if (isset($xmlRoot->field)) { foreach ($xmlRoot->field as $fieldMapping) { @@ -263,11 +270,11 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) ? $this->evaluateBoolean($embeddedMapping['use-column-prefix']) : true; - $mapping = array( + $mapping = [ 'fieldName' => (string) $embeddedMapping['name'], 'class' => (string) $embeddedMapping['class'], 'columnPrefix' => $useColumnPrefix ? $columnPrefix : false - ); + ]; $metadata->mapEmbedded($mapping); } @@ -282,17 +289,17 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) } // Evaluate mappings - $associationIds = array(); + $associationIds = []; foreach ($xmlRoot->id as $idElement) { if (isset($idElement['association-key']) && $this->evaluateBoolean($idElement['association-key'])) { $associationIds[(string) $idElement['name']] = true; continue; } - $mapping = array( + $mapping = [ 'id' => true, 'fieldName' => (string) $idElement['name'] - ); + ]; if (isset($idElement['type'])) { $mapping['type'] = (string) $idElement['type']; @@ -326,16 +333,20 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Check for SequenceGenerator/TableGenerator definition if (isset($idElement->{'sequence-generator'})) { $seqGenerator = $idElement->{'sequence-generator'}; - $metadata->setSequenceGeneratorDefinition(array( - 'sequenceName' => (string) $seqGenerator['sequence-name'], - 'allocationSize' => (string) $seqGenerator['allocation-size'], - 'initialValue' => (string) $seqGenerator['initial-value'] - )); + $metadata->setSequenceGeneratorDefinition( + [ + 'sequenceName' => (string) $seqGenerator['sequence-name'], + 'allocationSize' => (string) $seqGenerator['allocation-size'], + 'initialValue' => (string) $seqGenerator['initial-value'] + ] + ); } else if (isset($idElement->{'custom-id-generator'})) { $customGenerator = $idElement->{'custom-id-generator'}; - $metadata->setCustomGeneratorDefinition(array( - 'class' => (string) $customGenerator['class'] - )); + $metadata->setCustomGeneratorDefinition( + [ + 'class' => (string) $customGenerator['class'] + ] + ); } else if (isset($idElement->{'table-generator'})) { throw MappingException::tableIdGeneratorNotImplemented($className); } @@ -344,10 +355,10 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Evaluate mappings if (isset($xmlRoot->{'one-to-one'})) { foreach ($xmlRoot->{'one-to-one'} as $oneToOneElement) { - $mapping = array( + $mapping = [ 'fieldName' => (string) $oneToOneElement['field'], 'targetEntity' => (string) $oneToOneElement['target-entity'] - ); + ]; if (isset($associationIds[$mapping['fieldName']])) { $mapping['id'] = true; @@ -363,7 +374,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) if (isset($oneToOneElement['inversed-by'])) { $mapping['inversedBy'] = (string) $oneToOneElement['inversed-by']; } - $joinColumns = array(); + $joinColumns = []; if (isset($oneToOneElement->{'join-column'})) { $joinColumns[] = $this->joinColumnToArray($oneToOneElement->{'join-column'}); @@ -396,11 +407,11 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Evaluate mappings if (isset($xmlRoot->{'one-to-many'})) { foreach ($xmlRoot->{'one-to-many'} as $oneToManyElement) { - $mapping = array( + $mapping = [ 'fieldName' => (string) $oneToManyElement['field'], 'targetEntity' => (string) $oneToManyElement['target-entity'], 'mappedBy' => (string) $oneToManyElement['mapped-by'] - ); + ]; if (isset($oneToManyElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . (string) $oneToManyElement['fetch']); @@ -415,7 +426,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) } if (isset($oneToManyElement->{'order-by'})) { - $orderBy = array(); + $orderBy = []; foreach ($oneToManyElement->{'order-by'}->{'order-by-field'} as $orderByField) { $orderBy[(string) $orderByField['name']] = (string) $orderByField['direction']; } @@ -440,10 +451,10 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Evaluate mappings if (isset($xmlRoot->{'many-to-one'})) { foreach ($xmlRoot->{'many-to-one'} as $manyToOneElement) { - $mapping = array( + $mapping = [ 'fieldName' => (string) $manyToOneElement['field'], 'targetEntity' => (string) $manyToOneElement['target-entity'] - ); + ]; if (isset($associationIds[$mapping['fieldName']])) { $mapping['id'] = true; @@ -457,7 +468,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $mapping['inversedBy'] = (string) $manyToOneElement['inversed-by']; } - $joinColumns = array(); + $joinColumns = []; if (isset($manyToOneElement->{'join-column'})) { $joinColumns[] = $this->joinColumnToArray($manyToOneElement->{'join-column'}); @@ -486,10 +497,10 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Evaluate mappings if (isset($xmlRoot->{'many-to-many'})) { foreach ($xmlRoot->{'many-to-many'} as $manyToManyElement) { - $mapping = array( + $mapping = [ 'fieldName' => (string) $manyToManyElement['field'], 'targetEntity' => (string) $manyToManyElement['target-entity'] - ); + ]; if (isset($manyToManyElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . (string) $manyToManyElement['fetch']); @@ -507,9 +518,9 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) } $joinTableElement = $manyToManyElement->{'join-table'}; - $joinTable = array( + $joinTable = [ 'name' => (string) $joinTableElement['name'] - ); + ]; if (isset($joinTableElement['schema'])) { $joinTable['schema'] = (string) $joinTableElement['schema']; @@ -531,7 +542,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) } if (isset($manyToManyElement->{'order-by'})) { - $orderBy = array(); + $orderBy = []; foreach ($manyToManyElement->{'order-by'}->{'order-by-field'} as $orderByField) { $orderBy[(string) $orderByField['name']] = (string) $orderByField['direction']; } @@ -569,11 +580,11 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) if (isset($xmlRoot->{'association-overrides'})) { foreach ($xmlRoot->{'association-overrides'}->{'association-override'} as $overrideElement) { $fieldName = (string) $overrideElement['name']; - $override = array(); + $override = []; // Check for join-columns if (isset($overrideElement->{'join-columns'})) { - $joinColumns = array(); + $joinColumns = []; foreach ($overrideElement->{'join-columns'}->{'join-column'} as $joinColumnElement) { $joinColumns[] = $this->joinColumnToArray($joinColumnElement); } @@ -585,10 +596,10 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $joinTable = null; $joinTableElement = $overrideElement->{'join-table'}; - $joinTable = array( + $joinTable = [ 'name' => (string) $joinTableElement['name'], 'schema' => (string) $joinTableElement['schema'] - ); + ]; if (isset($joinTableElement->{'join-columns'})) { foreach ($joinTableElement->{'join-columns'}->{'join-column'} as $joinColumnElement) { @@ -651,7 +662,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) */ private function _parseOptions(SimpleXMLElement $options) { - $array = array(); + $array = []; /* @var $option SimpleXMLElement */ foreach ($options as $option) { @@ -686,10 +697,10 @@ private function _parseOptions(SimpleXMLElement $options) */ private function joinColumnToArray(SimpleXMLElement $joinColumnElement) { - $joinColumn = array( + $joinColumn = [ 'name' => (string) $joinColumnElement['name'], 'referencedColumnName' => (string) $joinColumnElement['referenced-column-name'] - ); + ]; if (isset($joinColumnElement['unique'])) { $joinColumn['unique'] = $this->evaluateBoolean($joinColumnElement['unique']); @@ -719,9 +730,9 @@ private function joinColumnToArray(SimpleXMLElement $joinColumnElement) */ private function columnToArray(SimpleXMLElement $fieldMapping) { - $mapping = array( + $mapping = [ 'fieldName' => (string) $fieldMapping['name'], - ); + ]; if (isset($fieldMapping['type'])) { $mapping['type'] = (string) $fieldMapping['type']; @@ -786,10 +797,10 @@ private function cacheToArray(SimpleXMLElement $cacheMapping) $usage = constant('Doctrine\ORM\Mapping\ClassMetadata::CACHE_USAGE_' . $usage); } - return array( + return [ 'usage' => $usage, 'region' => $region, - ); + ]; } /** @@ -801,7 +812,7 @@ private function cacheToArray(SimpleXMLElement $cacheMapping) */ private function _getCascadeMappings(SimpleXMLElement $cascadeElement) { - $cascades = array(); + $cascades = []; /* @var $action SimpleXmlElement */ foreach ($cascadeElement->children() as $action) { // According to the JPA specifications, XML uses "cascade-persist" @@ -820,7 +831,7 @@ private function _getCascadeMappings(SimpleXMLElement $cascadeElement) */ protected function loadMappingFile($file) { - $result = array(); + $result = []; $xmlElement = simplexml_load_file($file); if (isset($xmlElement->entity)) { diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index fe406785f58..8793c070b7b 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -73,7 +73,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) } // Evaluate root level properties - $primaryTable = array(); + $primaryTable = []; if (isset($element['table'])) { $primaryTable['name'] = $element['table']; @@ -94,7 +94,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) if (isset($element['namedQueries'])) { foreach ($element['namedQueries'] as $name => $queryMapping) { if (is_string($queryMapping)) { - $queryMapping = array('query' => $queryMapping); + $queryMapping = ['query' => $queryMapping]; } if ( ! isset($queryMapping['name'])) { @@ -111,12 +111,14 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) if (!isset($mappingElement['name'])) { $mappingElement['name'] = $name; } - $metadata->addNamedNativeQuery(array( - 'name' => $mappingElement['name'], - 'query' => isset($mappingElement['query']) ? $mappingElement['query'] : null, - 'resultClass' => isset($mappingElement['resultClass']) ? $mappingElement['resultClass'] : null, - 'resultSetMapping' => isset($mappingElement['resultSetMapping']) ? $mappingElement['resultSetMapping'] : null, - )); + $metadata->addNamedNativeQuery( + [ + 'name' => $mappingElement['name'], + 'query' => isset($mappingElement['query']) ? $mappingElement['query'] : null, + 'resultClass' => isset($mappingElement['resultClass']) ? $mappingElement['resultClass'] : null, + 'resultSetMapping' => isset($mappingElement['resultSetMapping']) ? $mappingElement['resultSetMapping'] : null, + ] + ); } } @@ -127,22 +129,22 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $resultSetMapping['name'] = $name; } - $entities = array(); - $columns = array(); + $entities = []; + $columns = []; if (isset($resultSetMapping['entityResult'])) { foreach ($resultSetMapping['entityResult'] as $entityResultElement) { - $entityResult = array( - 'fields' => array(), + $entityResult = [ + 'fields' => [], 'entityClass' => isset($entityResultElement['entityClass']) ? $entityResultElement['entityClass'] : null, 'discriminatorColumn' => isset($entityResultElement['discriminatorColumn']) ? $entityResultElement['discriminatorColumn'] : null, - ); + ]; if (isset($entityResultElement['fieldResult'])) { foreach ($entityResultElement['fieldResult'] as $fieldResultElement) { - $entityResult['fields'][] = array( + $entityResult['fields'][] = [ 'name' => isset($fieldResultElement['name']) ? $fieldResultElement['name'] : null, 'column' => isset($fieldResultElement['column']) ? $fieldResultElement['column'] : null, - ); + ]; } } @@ -153,17 +155,19 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) if (isset($resultSetMapping['columnResult'])) { foreach ($resultSetMapping['columnResult'] as $columnResultAnnot) { - $columns[] = array( + $columns[] = [ 'name' => isset($columnResultAnnot['name']) ? $columnResultAnnot['name'] : null, - ); + ]; } } - $metadata->addSqlResultSetMapping(array( - 'name' => $resultSetMapping['name'], - 'entities' => $entities, - 'columns' => $columns - )); + $metadata->addSqlResultSetMapping( + [ + 'name' => $resultSetMapping['name'], + 'entities' => $entities, + 'columns' => $columns + ] + ); } } @@ -174,14 +178,16 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Evaluate discriminatorColumn if (isset($element['discriminatorColumn'])) { $discrColumn = $element['discriminatorColumn']; - $metadata->setDiscriminatorColumn(array( - 'name' => isset($discrColumn['name']) ? (string) $discrColumn['name'] : null, - 'type' => isset($discrColumn['type']) ? (string) $discrColumn['type'] : 'string', - 'length' => isset($discrColumn['length']) ? (string) $discrColumn['length'] : 255, - 'columnDefinition' => isset($discrColumn['columnDefinition']) ? (string) $discrColumn['columnDefinition'] : null - )); + $metadata->setDiscriminatorColumn( + [ + 'name' => isset($discrColumn['name']) ? (string) $discrColumn['name'] : null, + 'type' => isset($discrColumn['type']) ? (string) $discrColumn['type'] : 'string', + 'length' => isset($discrColumn['length']) ? (string) $discrColumn['length'] : 255, + 'columnDefinition' => isset($discrColumn['columnDefinition']) ? (string) $discrColumn['columnDefinition'] : null + ] + ); } else { - $metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255)); + $metadata->setDiscriminatorColumn(['name' => 'dtype', 'type' => 'string', 'length' => 255]); } // Evaluate discriminatorMap @@ -206,9 +212,9 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) } if (is_string($indexYml['columns'])) { - $index = array('columns' => array_map('trim', explode(',', $indexYml['columns']))); + $index = ['columns' => array_map('trim', explode(',', $indexYml['columns']))]; } else { - $index = array('columns' => $indexYml['columns']); + $index = ['columns' => $indexYml['columns']]; } if (isset($indexYml['flags'])) { @@ -235,9 +241,9 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) } if (is_string($uniqueYml['columns'])) { - $unique = array('columns' => array_map('trim', explode(',', $uniqueYml['columns']))); + $unique = ['columns' => array_map('trim', explode(',', $uniqueYml['columns']))]; } else { - $unique = array('columns' => $uniqueYml['columns']); + $unique = ['columns' => $uniqueYml['columns']]; } if (isset($uniqueYml['options'])) { @@ -252,7 +258,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $metadata->table['options'] = $element['options']; } - $associationIds = array(); + $associationIds = []; if (isset($element['id'])) { // Evaluate identifier settings foreach ($element['id'] as $name => $idElement) { @@ -261,10 +267,10 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) continue; } - $mapping = array( + $mapping = [ 'id' => true, 'fieldName' => $name - ); + ]; if (isset($idElement['type'])) { $mapping['type'] = $idElement['type']; @@ -297,9 +303,11 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $metadata->setSequenceGeneratorDefinition($idElement['sequenceGenerator']); } else if (isset($idElement['customIdGenerator'])) { $customGenerator = $idElement['customIdGenerator']; - $metadata->setCustomGeneratorDefinition(array( - 'class' => (string) $customGenerator['class'] - )); + $metadata->setCustomGeneratorDefinition( + [ + 'class' => (string) $customGenerator['class'] + ] + ); } else if (isset($idElement['tableGenerator'])) { throw MappingException::tableIdGeneratorNotImplemented($className); } @@ -331,11 +339,11 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) if (isset($element['embedded'])) { foreach ($element['embedded'] as $name => $embeddedMapping) { - $mapping = array( + $mapping = [ 'fieldName' => $name, 'class' => $embeddedMapping['class'], 'columnPrefix' => isset($embeddedMapping['columnPrefix']) ? $embeddedMapping['columnPrefix'] : null, - ); + ]; $metadata->mapEmbedded($mapping); } } @@ -343,10 +351,10 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Evaluate oneToOne relationships if (isset($element['oneToOne'])) { foreach ($element['oneToOne'] as $name => $oneToOneElement) { - $mapping = array( + $mapping = [ 'fieldName' => $name, 'targetEntity' => $oneToOneElement['targetEntity'] - ); + ]; if (isset($associationIds[$mapping['fieldName']])) { $mapping['id'] = true; @@ -363,7 +371,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $mapping['inversedBy'] = $oneToOneElement['inversedBy']; } - $joinColumns = array(); + $joinColumns = []; if (isset($oneToOneElement['joinColumn'])) { $joinColumns[] = $this->joinColumnToArray($oneToOneElement['joinColumn']); @@ -400,11 +408,11 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Evaluate oneToMany relationships if (isset($element['oneToMany'])) { foreach ($element['oneToMany'] as $name => $oneToManyElement) { - $mapping = array( + $mapping = [ 'fieldName' => $name, 'targetEntity' => $oneToManyElement['targetEntity'], 'mappedBy' => $oneToManyElement['mappedBy'] - ); + ]; if (isset($oneToManyElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . $oneToManyElement['fetch']); @@ -439,10 +447,10 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Evaluate manyToOne relationships if (isset($element['manyToOne'])) { foreach ($element['manyToOne'] as $name => $manyToOneElement) { - $mapping = array( + $mapping = [ 'fieldName' => $name, 'targetEntity' => $manyToOneElement['targetEntity'] - ); + ]; if (isset($associationIds[$mapping['fieldName']])) { $mapping['id'] = true; @@ -456,7 +464,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $mapping['inversedBy'] = $manyToOneElement['inversedBy']; } - $joinColumns = array(); + $joinColumns = []; if (isset($manyToOneElement['joinColumn'])) { $joinColumns[] = $this->joinColumnToArray($manyToOneElement['joinColumn']); @@ -488,10 +496,10 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Evaluate manyToMany relationships if (isset($element['manyToMany'])) { foreach ($element['manyToMany'] as $name => $manyToManyElement) { - $mapping = array( + $mapping = [ 'fieldName' => $name, 'targetEntity' => $manyToManyElement['targetEntity'] - ); + ]; if (isset($manyToManyElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . $manyToManyElement['fetch']); @@ -502,9 +510,9 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) } else if (isset($manyToManyElement['joinTable'])) { $joinTableElement = $manyToManyElement['joinTable']; - $joinTable = array( + $joinTable = [ 'name' => $joinTableElement['name'] - ); + ]; if (isset($joinTableElement['schema'])) { $joinTable['schema'] = $joinTableElement['schema']; @@ -564,11 +572,11 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) if (isset($element['associationOverride']) && is_array($element['associationOverride'])) { foreach ($element['associationOverride'] as $fieldName => $associationOverrideElement) { - $override = array(); + $override = []; // Check for joinColumn if (isset($associationOverrideElement['joinColumn'])) { - $joinColumns = array(); + $joinColumns = []; foreach ($associationOverrideElement['joinColumn'] as $name => $joinColumnElement) { if ( ! isset($joinColumnElement['name'])) { $joinColumnElement['name'] = $name; @@ -582,9 +590,9 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) if (isset($associationOverrideElement['joinTable'])) { $joinTableElement = $associationOverrideElement['joinTable']; - $joinTable = array( + $joinTable = [ 'name' => $joinTableElement['name'] - ); + ]; if (isset($joinTableElement['schema'])) { $joinTable['schema'] = $joinTableElement['schema']; @@ -665,7 +673,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) */ private function joinColumnToArray($joinColumnElement) { - $joinColumn = array(); + $joinColumn = []; if (isset($joinColumnElement['referencedColumnName'])) { $joinColumn['referencedColumnName'] = (string) $joinColumnElement['referencedColumnName']; } @@ -707,9 +715,9 @@ private function joinColumnToArray($joinColumnElement) */ private function columnToArray($fieldName, $column) { - $mapping = array( + $mapping = [ 'fieldName' => $fieldName - ); + ]; if (isset($column['type'])) { $params = explode('(', $column['type']); @@ -781,10 +789,10 @@ private function cacheToArray($cacheMapping) $usage = constant('Doctrine\ORM\Mapping\ClassMetadata::CACHE_USAGE_' . $usage); } - return array( + return [ 'usage' => $usage, 'region' => $region, - ); + ]; } /** diff --git a/lib/Doctrine/ORM/Mapping/EntityListeners.php b/lib/Doctrine/ORM/Mapping/EntityListeners.php index d9478a4979e..ae6c9126bd7 100644 --- a/lib/Doctrine/ORM/Mapping/EntityListeners.php +++ b/lib/Doctrine/ORM/Mapping/EntityListeners.php @@ -37,5 +37,5 @@ final class EntityListeners implements Annotation * * @var array */ - public $value = array(); -} \ No newline at end of file + public $value = []; +} diff --git a/lib/Doctrine/ORM/Mapping/EntityResult.php b/lib/Doctrine/ORM/Mapping/EntityResult.php index 63bbed22fac..d8b05730ae5 100644 --- a/lib/Doctrine/ORM/Mapping/EntityResult.php +++ b/lib/Doctrine/ORM/Mapping/EntityResult.php @@ -45,7 +45,7 @@ final class EntityResult implements Annotation * * @var array<\Doctrine\ORM\Mapping\FieldResult> */ - public $fields = array(); + public $fields = []; /** * Specifies the column name of the column in the SELECT list that is used to determine the type of the entity instance. diff --git a/lib/Doctrine/ORM/Mapping/JoinTable.php b/lib/Doctrine/ORM/Mapping/JoinTable.php index 8a440c6143d..879316a2874 100644 --- a/lib/Doctrine/ORM/Mapping/JoinTable.php +++ b/lib/Doctrine/ORM/Mapping/JoinTable.php @@ -38,10 +38,10 @@ final class JoinTable implements Annotation /** * @var array<\Doctrine\ORM\Mapping\JoinColumn> */ - public $joinColumns = array(); + public $joinColumns = []; /** * @var array<\Doctrine\ORM\Mapping\JoinColumn> */ - public $inverseJoinColumns = array(); + public $inverseJoinColumns = []; } diff --git a/lib/Doctrine/ORM/Mapping/NamedNativeQueries.php b/lib/Doctrine/ORM/Mapping/NamedNativeQueries.php index 7f5460a81e9..2539107afcf 100644 --- a/lib/Doctrine/ORM/Mapping/NamedNativeQueries.php +++ b/lib/Doctrine/ORM/Mapping/NamedNativeQueries.php @@ -25,7 +25,7 @@ * * @author Fabio B. Silva * @since 2.3 - * + * * @Annotation * @Target("CLASS") */ @@ -36,5 +36,5 @@ final class NamedNativeQueries implements Annotation * * @var array<\Doctrine\ORM\Mapping\NamedNativeQuery> */ - public $value = array(); + public $value = []; } diff --git a/lib/Doctrine/ORM/Mapping/SqlResultSetMapping.php b/lib/Doctrine/ORM/Mapping/SqlResultSetMapping.php index f5ead7c0f22..cb78c9a40a5 100644 --- a/lib/Doctrine/ORM/Mapping/SqlResultSetMapping.php +++ b/lib/Doctrine/ORM/Mapping/SqlResultSetMapping.php @@ -33,22 +33,22 @@ final class SqlResultSetMapping implements Annotation { /** * The name given to the result set mapping, and used to refer to it in the methods of the Query API. - * + * * @var string */ public $name; /** * Specifies the result set mapping to entities. - * + * * @var array<\Doctrine\ORM\Mapping\EntityResult> */ - public $entities = array(); + public $entities = []; /** * Specifies the result set mapping to scalar values. * * @var array<\Doctrine\ORM\Mapping\ColumnResult> */ - public $columns = array(); + public $columns = []; } diff --git a/lib/Doctrine/ORM/Mapping/SqlResultSetMappings.php b/lib/Doctrine/ORM/Mapping/SqlResultSetMappings.php index c21b2ab820b..0b74f2d9598 100644 --- a/lib/Doctrine/ORM/Mapping/SqlResultSetMappings.php +++ b/lib/Doctrine/ORM/Mapping/SqlResultSetMappings.php @@ -25,7 +25,7 @@ * * @author Fabio B. Silva * @since 2.3 - * + * * @Annotation * @Target("CLASS") */ @@ -36,5 +36,5 @@ final class SqlResultSetMappings implements Annotation * * @var array<\Doctrine\ORM\Mapping\SqlResultSetMapping> */ - public $value = array(); + public $value = []; } diff --git a/lib/Doctrine/ORM/Mapping/Table.php b/lib/Doctrine/ORM/Mapping/Table.php index f9f8d4a656d..6ed703750be 100644 --- a/lib/Doctrine/ORM/Mapping/Table.php +++ b/lib/Doctrine/ORM/Mapping/Table.php @@ -48,5 +48,5 @@ final class Table implements Annotation /** * @var array */ - public $options = array(); + public $options = []; } diff --git a/lib/Doctrine/ORM/NativeQuery.php b/lib/Doctrine/ORM/NativeQuery.php index b19f8180564..ddc5418d672 100644 --- a/lib/Doctrine/ORM/NativeQuery.php +++ b/lib/Doctrine/ORM/NativeQuery.php @@ -63,8 +63,8 @@ public function getSQL() */ protected function _doExecute() { - $parameters = array(); - $types = array(); + $parameters = []; + $types = []; foreach ($this->getParameters() as $parameter) { $name = $parameter->getName(); diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index b5948149a2f..11205df04f7 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -49,7 +49,7 @@ final class PersistentCollection extends AbstractLazyCollection implements Selec * * @var array */ - private $snapshot = array(); + private $snapshot = []; /** * The entity that owns this collection. @@ -585,7 +585,7 @@ public function clear() */ public function __sleep() { - return array('collection', 'initialized'); + return ['collection', 'initialized']; } /** @@ -633,7 +633,7 @@ public function __clone() $this->initialize(); $this->owner = null; - $this->snapshot = array(); + $this->snapshot = []; $this->changed(); } @@ -695,7 +695,7 @@ public function unwrap() protected function doInitialize() { // Has NEW objects added through add(). Remember them. - $newObjects = array(); + $newObjects = []; if ($this->isDirty) { $newObjects = $this->collection->toArray(); diff --git a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php index 525ab34b322..ca8575d2a40 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php @@ -47,7 +47,7 @@ public function delete(PersistentCollection $collection) return; // ignore inverse side } - $types = array(); + $types = []; $class = $this->em->getClassMetadata($mapping['sourceEntity']); foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) { @@ -104,7 +104,7 @@ public function get(PersistentCollection $collection, $index) ? $mapping['inversedBy'] : $mapping['mappedBy']; - return $persister->load(array($mappedKey => $collection->getOwner(), $mapping['indexBy'] => $index), null, $mapping, array(), 0, 1); + return $persister->load([$mappedKey => $collection->getOwner(), $mapping['indexBy'] => $index], null, $mapping, [], 0, 1); } /** @@ -112,9 +112,9 @@ public function get(PersistentCollection $collection, $index) */ public function count(PersistentCollection $collection) { - $conditions = array(); - $params = array(); - $types = array(); + $conditions = []; + $params = []; + $types = []; $mapping = $collection->getMapping(); $id = $this->uow->getEntityIdentifier($collection->getOwner()); $sourceClass = $this->em->getClassMetadata($mapping['sourceEntity']); @@ -238,7 +238,7 @@ public function loadCriteria(PersistentCollection $collection, Criteria $criteri $id = $this->uow->getEntityIdentifier($owner); $targetClass = $this->em->getClassMetadata($mapping['targetEntity']); $onConditions = $this->getOnConditionSQL($mapping); - $whereClauses = $params = array(); + $whereClauses = $params = []; if ( ! $mapping['isOwningSide']) { $associationSourceClass = $targetClass; @@ -311,7 +311,7 @@ public function getFilterSql($mapping) $filterSql = $this->generateFilterConditionSQL($rootClass, 'te'); if ('' === $filterSql) { - return array('', ''); + return ['', '']; } // A join is needed if there is filtering on the target entity @@ -319,7 +319,7 @@ public function getFilterSql($mapping) $joinSql = ' JOIN ' . $tableName . ' te' . ' ON' . implode(' AND ', $this->getOnConditionSQL($mapping)); - return array($joinSql, $filterSql); + return [$joinSql, $filterSql]; } /** @@ -332,7 +332,7 @@ public function getFilterSql($mapping) */ protected function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias) { - $filterClauses = array(); + $filterClauses = []; foreach ($this->em->getFilters()->getEnabledFilters() as $filter) { if ($filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { @@ -363,7 +363,7 @@ protected function getOnConditionSQL($mapping) ? $association['joinTable']['inverseJoinColumns'] : $association['joinTable']['joinColumns']; - $conditions = array(); + $conditions = []; foreach ($joinColumns as $joinColumn) { $joinColumnName = $this->quoteStrategy->getJoinColumnName($joinColumn, $targetClass, $this->platform); @@ -382,7 +382,7 @@ protected function getOnConditionSQL($mapping) */ protected function getDeleteSQL(PersistentCollection $collection) { - $columns = array(); + $columns = []; $mapping = $collection->getMapping(); $class = $this->em->getClassMetadata(get_class($collection->getOwner())); $joinTable = $this->quoteStrategy->getJoinTableName($mapping, $class, $this->platform); @@ -408,12 +408,12 @@ protected function getDeleteSQLParameters(PersistentCollection $collection) // Optimization for single column identifier if (count($mapping['relationToSourceKeyColumns']) === 1) { - return array(reset($identifier)); + return [reset($identifier)]; } // Composite identifier $sourceClass = $this->em->getClassMetadata($mapping['sourceEntity']); - $params = array(); + $params = []; foreach ($mapping['relationToSourceKeyColumns'] as $columnName => $refColumnName) { $params[] = isset($sourceClass->fieldNames[$refColumnName]) @@ -437,8 +437,8 @@ protected function getDeleteRowSQL(PersistentCollection $collection) $mapping = $collection->getMapping(); $class = $this->em->getClassMetadata($mapping['sourceEntity']); $targetClass = $this->em->getClassMetadata($mapping['targetEntity']); - $columns = array(); - $types = array(); + $columns = []; + $types = []; foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) { $columns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform); @@ -450,11 +450,11 @@ protected function getDeleteRowSQL(PersistentCollection $collection) $types[] = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em); } - return array( + return [ 'DELETE FROM ' . $this->quoteStrategy->getJoinTableName($mapping, $class, $this->platform) . ' WHERE ' . implode(' = ? AND ', $columns) . ' = ?', $types, - ); + ]; } /** @@ -483,8 +483,8 @@ protected function getDeleteRowSQLParameters(PersistentCollection $collection, $ */ protected function getInsertRowSQL(PersistentCollection $collection) { - $columns = array(); - $types = array(); + $columns = []; + $types = []; $mapping = $collection->getMapping(); $class = $this->em->getClassMetadata($mapping['sourceEntity']); $targetClass = $this->em->getClassMetadata($mapping['targetEntity']); @@ -499,13 +499,13 @@ protected function getInsertRowSQL(PersistentCollection $collection) $types[] = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em); } - return array( + return [ 'INSERT INTO ' . $this->quoteStrategy->getJoinTableName($mapping, $class, $this->platform) . ' (' . implode(', ', $columns) . ')' . ' VALUES' . ' (' . implode(', ', array_fill(0, count($columns), '?')) . ')', $types, - ); + ]; } /** @@ -535,7 +535,7 @@ protected function getInsertRowSQLParameters(PersistentCollection $collection, $ */ private function collectJoinTableColumnParameters(PersistentCollection $collection, $element) { - $params = array(); + $params = []; $mapping = $collection->getMapping(); $isComposite = count($mapping['joinTableColumns']) > 2; @@ -602,14 +602,14 @@ private function getJoinTableRestrictionsWithKey(PersistentCollection $collectio } $quotedJoinTable = $this->quoteStrategy->getJoinTableName($mapping, $associationSourceClass, $this->platform). ' t'; - $whereClauses = array(); - $params = array(); - $types = array(); + $whereClauses = []; + $params = []; + $types = []; $joinNeeded = ! in_array($indexBy, $targetClass->identifier); if ($joinNeeded) { // extra join needed if indexBy is not a @id - $joinConditions = array(); + $joinConditions = []; foreach ($joinColumns as $joinTableColumn) { $joinConditions[] = 't.' . $joinTableColumn['name'] . ' = tr.' . $joinTableColumn['referencedColumnName']; @@ -650,7 +650,7 @@ private function getJoinTableRestrictionsWithKey(PersistentCollection $collectio } } - return array($quotedJoinTable, $whereClauses, $params, $types); + return [$quotedJoinTable, $whereClauses, $params, $types]; } /** @@ -684,9 +684,9 @@ private function getJoinTableRestrictions(PersistentCollection $collection, $ele } $quotedJoinTable = $this->quoteStrategy->getJoinTableName($mapping, $sourceClass, $this->platform); - $whereClauses = array(); - $params = array(); - $types = array(); + $whereClauses = []; + $params = []; + $types = []; foreach ($mapping['joinTableColumns'] as $joinTableColumn) { $whereClauses[] = ($addFilters ? 't.' : '') . $joinTableColumn . ' = ?'; @@ -716,7 +716,7 @@ private function getJoinTableRestrictions(PersistentCollection $collection, $ele } } - return array($quotedJoinTable, $whereClauses, $params, $types); + return [$quotedJoinTable, $whereClauses, $params, $types]; } /** @@ -732,7 +732,7 @@ private function expandCriteriaParameters(Criteria $criteria) $expression = $criteria->getWhereExpression(); if ($expression === null) { - return array(); + return []; } $valueVisitor = new SqlValueVisitor(); diff --git a/lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php index 0e2fda86815..82115071f35 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php @@ -83,13 +83,13 @@ public function get(PersistentCollection $collection, $index) $persister = $this->uow->getEntityPersister($mapping['targetEntity']); return $persister->load( - array( + [ $mapping['mappedBy'] => $collection->getOwner(), $mapping['indexBy'] => $index - ), + ], null, $mapping, - array(), + [], null, 1 ); @@ -249,10 +249,10 @@ private function deleteJoinedEntityCollection(PersistentCollection $collection) $columnDefinitions = []; foreach ($idColumnNames as $idColumnName) { - $columnDefinitions[$idColumnName] = array( + $columnDefinitions[$idColumnName] = [ 'notnull' => true, 'type' => Type::getType(PersisterHelper::getTypeOfColumn($idColumnName, $rootClass, $this->em)), - ); + ]; } $statement = $this->platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable @@ -271,7 +271,7 @@ private function deleteJoinedEntityCollection(PersistentCollection $collection) $numDeleted = $this->conn->executeUpdate($statement, $parameters); // 3) Delete records on each table in the hierarchy - $classNames = array_merge($targetClass->parentClasses, array($targetClass->name), $targetClass->subClasses); + $classNames = array_merge($targetClass->parentClasses, [$targetClass->name], $targetClass->subClasses); foreach (array_reverse($classNames) as $className) { $tableName = $this->quoteStrategy->getTableName($this->em->getClassMetadata($className), $this->platform); diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index d577df6d9a5..e3d0a165f9c 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -86,7 +86,7 @@ class BasicEntityPersister implements EntityPersister /** * @var array */ - static private $comparisonMap = array( + static private $comparisonMap = [ Comparison::EQ => '= %s', Comparison::IS => '= %s', Comparison::NEQ => '!= %s', @@ -97,7 +97,7 @@ class BasicEntityPersister implements EntityPersister Comparison::IN => 'IN (%s)', Comparison::NIN => 'NOT IN (%s)', Comparison::CONTAINS => 'LIKE %s', - ); + ]; /** * Metadata object that describes the mapping of the mapped entity class. @@ -132,7 +132,7 @@ class BasicEntityPersister implements EntityPersister * * @var array */ - protected $queuedInserts = array(); + protected $queuedInserts = []; /** * The map of column names to DBAL mapping types of all prepared columns used @@ -143,7 +143,7 @@ class BasicEntityPersister implements EntityPersister * @see prepareInsertData($entity) * @see prepareUpdateData($entity) */ - protected $columnTypes = array(); + protected $columnTypes = []; /** * The map of quoted column names. @@ -153,7 +153,7 @@ class BasicEntityPersister implements EntityPersister * @see prepareInsertData($entity) * @see prepareUpdateData($entity) */ - protected $quotedColumns = array(); + protected $quotedColumns = []; /** * The INSERT SQL statement used for entities handled by this persister. @@ -257,10 +257,10 @@ public function getInserts() public function executeInserts() { if ( ! $this->queuedInserts) { - return array(); + return []; } - $postInsertIds = array(); + $postInsertIds = []; $idGenerator = $this->class->idGenerator; $isPostInsertId = $idGenerator->isPostInsertGenerator(); @@ -282,13 +282,13 @@ public function executeInserts() if ($isPostInsertId) { $generatedId = $idGenerator->generate($this->em, $entity); - $id = array( + $id = [ $this->class->identifier[0] => $generatedId - ); - $postInsertIds[] = array( + ]; + $postInsertIds[] = [ 'generatedId' => $generatedId, 'entity' => $entity, - ); + ]; } else { $id = $this->class->getIdentifierValues($entity); } @@ -299,7 +299,7 @@ public function executeInserts() } $stmt->closeCursor(); - $this->queuedInserts = array(); + $this->queuedInserts = []; return $postInsertIds; } @@ -389,9 +389,9 @@ public function update($entity) */ protected final function updateTable($entity, $quotedTableName, array $updateData, $versioned = false) { - $set = array(); - $types = array(); - $params = array(); + $set = []; + $types = []; + $params = []; foreach ($updateData as $columnName => $value) { $placeholder = '?'; @@ -420,7 +420,7 @@ protected final function updateTable($entity, $quotedTableName, array $updateDat $types[] = $this->columnTypes[$columnName]; } - $where = array(); + $where = []; $identifier = $this->em->getUnitOfWork()->getEntityIdentifier($entity); foreach ($this->class->identifier as $idField) { @@ -503,9 +503,9 @@ protected function deleteJoinTableRecords($identifier) $selfReferential = ($mapping['targetEntity'] == $mapping['sourceEntity']); $class = $this->class; $association = $mapping; - $otherColumns = array(); - $otherKeys = array(); - $keys = array(); + $otherColumns = []; + $otherKeys = []; + $keys = []; if ( ! $mapping['isOwningSide']) { $class = $this->em->getClassMetadata($mapping['targetEntity']); @@ -603,7 +603,7 @@ public function delete($entity) protected function prepareUpdateData($entity) { $versionField = null; - $result = array(); + $result = []; $uow = $this->em->getUnitOfWork(); if (($versioned = $this->class->isVersioned) != false) { @@ -646,7 +646,7 @@ protected function prepareUpdateData($entity) // The associated entity $newVal is not yet persisted, so we must // set $newVal = null, in order to insert a null value and schedule an // extra update on the UnitOfWork. - $uow->scheduleExtraUpdate($entity, array($field => array(null, $newVal))); + $uow->scheduleExtraUpdate($entity, [$field => [null, $newVal]]); $newVal = null; } @@ -705,7 +705,7 @@ public function getOwningTable($fieldName) /** * {@inheritdoc} */ - public function load(array $criteria, $entity = null, $assoc = null, array $hints = array(), $lockMode = null, $limit = null, array $orderBy = null) + public function load(array $criteria, $entity = null, $assoc = null, array $hints = [], $lockMode = null, $limit = null, array $orderBy = null) { $this->switchPersisterContext(null, $limit); @@ -735,7 +735,7 @@ public function loadById(array $identifier, $entity = null) /** * {@inheritdoc} */ - public function loadOneToOneEntity(array $assoc, $sourceEntity, array $identifier = array()) + public function loadOneToOneEntity(array $assoc, $sourceEntity, array $identifier = []) { if (($foundEntity = $this->em->getUnitOfWork()->tryGetById($identifier, $assoc['targetEntity'])) != false) { return $foundEntity; @@ -748,7 +748,7 @@ public function loadOneToOneEntity(array $assoc, $sourceEntity, array $identifie // Mark inverse side as fetched in the hints, otherwise the UoW would // try to load it in a separate query (remember: to-one inverse sides can not be lazy). - $hints = array(); + $hints = []; if ($isInverseSingleValued) { $hints['fetched']["r"][$assoc['inversedBy']] = true; @@ -808,13 +808,13 @@ public function refresh(array $id, $entity, $lockMode = null) $stmt = $this->conn->executeQuery($sql, $params, $types); $hydrator = $this->em->newHydrator(Query::HYDRATE_OBJECT); - $hydrator->hydrateAll($stmt, $this->currentPersisterContext->rsm, array(Query::HINT_REFRESH => true)); + $hydrator->hydrateAll($stmt, $this->currentPersisterContext->rsm, [Query::HINT_REFRESH => true]); } /** * {@inheritDoc} */ - public function count($criteria = array()) + public function count($criteria = []) { $sql = $this->getCountSQL($criteria); @@ -840,7 +840,8 @@ public function loadCriteria(Criteria $criteria) $stmt = $this->conn->executeQuery($query, $params, $types); $hydrator = $this->em->newHydrator(($this->currentPersisterContext->selectJoinSql) ? Query::HYDRATE_OBJECT : Query::HYDRATE_SIMPLEOBJECT); - return $hydrator->hydrateAll($stmt, $this->currentPersisterContext->rsm, array(UnitOfWork::HINT_DEFEREAGERLOAD => true)); + return $hydrator->hydrateAll($stmt, $this->currentPersisterContext->rsm, [UnitOfWork::HINT_DEFEREAGERLOAD => true] + ); } /** @@ -849,11 +850,11 @@ public function loadCriteria(Criteria $criteria) public function expandCriteriaParameters(Criteria $criteria) { $expression = $criteria->getWhereExpression(); - $sqlParams = array(); - $sqlTypes = array(); + $sqlParams = []; + $sqlTypes = []; if ($expression === null) { - return array($sqlParams, $sqlTypes); + return [$sqlParams, $sqlTypes]; } $valueVisitor = new SqlValueVisitor(); @@ -871,13 +872,13 @@ public function expandCriteriaParameters(Criteria $criteria) $sqlTypes = array_merge($sqlTypes, $this->getTypes($field, $value, $this->class)); } - return array($sqlParams, $sqlTypes); + return [$sqlParams, $sqlTypes]; } /** * {@inheritdoc} */ - public function loadAll(array $criteria = array(), array $orderBy = null, $limit = null, $offset = null) + public function loadAll(array $criteria = [], array $orderBy = null, $limit = null, $offset = null) { $this->switchPersisterContext($offset, $limit); @@ -887,7 +888,8 @@ public function loadAll(array $criteria = array(), array $orderBy = null, $limit $hydrator = $this->em->newHydrator(($this->currentPersisterContext->selectJoinSql) ? Query::HYDRATE_OBJECT : Query::HYDRATE_SIMPLEOBJECT); - return $hydrator->hydrateAll($stmt, $this->currentPersisterContext->rsm, array(UnitOfWork::HINT_DEFEREAGERLOAD => true)); + return $hydrator->hydrateAll($stmt, $this->currentPersisterContext->rsm, [UnitOfWork::HINT_DEFEREAGERLOAD => true] + ); } /** @@ -913,7 +915,7 @@ public function getManyToManyCollection(array $assoc, $sourceEntity, $offset = n private function loadArrayFromStatement($assoc, $stmt) { $rsm = $this->currentPersisterContext->rsm; - $hints = array(UnitOfWork::HINT_DEFEREAGERLOAD => true); + $hints = [UnitOfWork::HINT_DEFEREAGERLOAD => true]; if (isset($assoc['indexBy'])) { $rsm = clone ($this->currentPersisterContext->rsm); // this is necessary because the "default rsm" should be changed. @@ -935,10 +937,10 @@ private function loadArrayFromStatement($assoc, $stmt) private function loadCollectionFromStatement($assoc, $stmt, $coll) { $rsm = $this->currentPersisterContext->rsm; - $hints = array( + $hints = [ UnitOfWork::HINT_DEFEREAGERLOAD => true, 'collection' => $coll - ); + ]; if (isset($assoc['indexBy'])) { $rsm = clone ($this->currentPersisterContext->rsm); // this is necessary because the "default rsm" should be changed. @@ -975,8 +977,8 @@ private function getManyToManyStatement(array $assoc, $sourceEntity, $offset = n $sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']); $class = $sourceClass; $association = $assoc; - $criteria = array(); - $parameters = array(); + $criteria = []; + $parameters = []; if ( ! $assoc['isOwningSide']) { $class = $this->em->getClassMetadata($assoc['targetEntity']); @@ -1018,11 +1020,11 @@ private function getManyToManyStatement(array $assoc, $sourceEntity, $offset = n } $criteria[$quotedJoinTable . '.' . $quotedKeyColumn] = $value; - $parameters[] = array( + $parameters[] = [ 'value' => $value, 'field' => $field, 'class' => $sourceClass, - ); + ]; } $sql = $this->getSelectSQL($criteria, $assoc, null, $limit, $offset); @@ -1096,7 +1098,7 @@ public function getSelectSQL($criteria, $assoc = null, $lockMode = null, $limit /** * {@inheritDoc} */ - public function getCountSQL($criteria = array()) + public function getCountSQL($criteria = []) { $tableName = $this->quoteStrategy->getTableName($this->class, $this->platform); $tableAlias = $this->getSQLTableAlias($this->class->name); @@ -1132,7 +1134,7 @@ public function getCountSQL($criteria = array()) */ protected final function getOrderBySQL(array $orderBy, $baseTableAlias) { - $orderByList = array(); + $orderByList = []; foreach ($orderBy as $fieldName => $orientation) { @@ -1194,7 +1196,7 @@ protected function getSelectColumnsSQL() return $this->currentPersisterContext->selectColumnListSql; } - $columnList = array(); + $columnList = []; $this->currentPersisterContext->rsm->addEntityResult($this->class->name, 'r'); // r for root // Add regular columns to select list @@ -1247,7 +1249,7 @@ protected function getSelectColumnsSQL() } $association = $assoc; - $joinCondition = array(); + $joinCondition = []; if (isset($assoc['indexBy'])) { $this->currentPersisterContext->rsm->addIndexBy($assocAlias, $assoc['indexBy']); @@ -1315,7 +1317,7 @@ protected function getSelectColumnAssociationSQL($field, $assoc, ClassMetadata $ return ''; } - $columnList = array(); + $columnList = []; $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); $isIdentifier = isset($assoc['id']) && $assoc['id'] === true; $sqlTableAlias = $this->getSQLTableAlias($class->name, ($alias == 'r' ? '' : $alias)); @@ -1343,7 +1345,7 @@ protected function getSelectColumnAssociationSQL($field, $assoc, ClassMetadata $ */ protected function getSelectManyToManyJoinSQL(array $manyToMany) { - $conditions = array(); + $conditions = []; $association = $manyToMany; $sourceTableAlias = $this->getSQLTableAlias($this->class->name); @@ -1385,7 +1387,7 @@ public function getInsertSQL() return $this->insertSql; } - $values = array(); + $values = []; $columns = array_unique($columns); foreach ($columns as $column) { @@ -1419,7 +1421,7 @@ public function getInsertSQL() */ protected function getInsertColumnList() { - $columns = array(); + $columns = []; foreach ($this->class->reflFields as $name => $field) { if ($this->class->isVersioned && $this->class->versionField == $name) { @@ -1579,7 +1581,7 @@ protected function getSelectConditionCriteriaSQL(Criteria $criteria) */ public function getSelectConditionStatementSQL($field, $value, $assoc = null, $comparison = null) { - $selectedColumns = array(); + $selectedColumns = []; $columns = $this->getSelectConditionStatementColumnSQL($field, $assoc); if (count($columns) > 1 && $comparison === Comparison::IN) { @@ -1660,13 +1662,13 @@ private function getSelectConditionStatementColumnSQL($field, $assoc = null) ? $this->class->fieldMappings[$field]['inherited'] : $this->class->name; - return array($this->getSQLTableAlias($className) . '.' . $this->quoteStrategy->getColumnName($field, $this->class, $this->platform)); + return [$this->getSQLTableAlias($className) . '.' . $this->quoteStrategy->getColumnName($field, $this->class, $this->platform)]; } if (isset($this->class->associationMappings[$field])) { $association = $this->class->associationMappings[$field]; // Many-To-Many requires join table check for joinColumn - $columns = array(); + $columns = []; $class = $this->class; if ($association['type'] === ClassMetadata::MANY_TO_MANY) { @@ -1705,7 +1707,7 @@ private function getSelectConditionStatementColumnSQL($field, $assoc = null) // therefore checking for spaces and function calls which are not allowed. // found a join column condition, not really a "field" - return array($field); + return [$field]; } throw ORMException::unrecognizedField($field); @@ -1725,7 +1727,7 @@ private function getSelectConditionStatementColumnSQL($field, $assoc = null) */ protected function getSelectConditionSQL(array $criteria, $assoc = null) { - $conditions = array(); + $conditions = []; foreach ($criteria as $field => $value) { $conditions[] = $this->getSelectConditionStatementSQL($field, $value, $assoc); @@ -1770,8 +1772,8 @@ private function getOneToManyStatement(array $assoc, $sourceEntity, $offset = nu { $this->switchPersisterContext($offset, $limit); - $criteria = array(); - $parameters = array(); + $criteria = []; + $parameters = []; $owningAssoc = $this->class->associationMappings[$assoc['mappedBy']]; $sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']); $tableAlias = $this->getSQLTableAlias(isset($owningAssoc['inherited']) ? $owningAssoc['inherited'] : $this->class->name); @@ -1787,11 +1789,11 @@ private function getOneToManyStatement(array $assoc, $sourceEntity, $offset = nu } $criteria[$tableAlias . "." . $targetKeyColumn] = $value; - $parameters[] = array( + $parameters[] = [ 'value' => $value, 'field' => $field, 'class' => $sourceClass, - ); + ]; continue; } @@ -1800,11 +1802,11 @@ private function getOneToManyStatement(array $assoc, $sourceEntity, $offset = nu $value = $sourceClass->reflFields[$field]->getValue($sourceEntity); $criteria[$tableAlias . "." . $targetKeyColumn] = $value; - $parameters[] = array( + $parameters[] = [ 'value' => $value, 'field' => $field, 'class' => $sourceClass, - ); + ]; } @@ -1819,8 +1821,8 @@ private function getOneToManyStatement(array $assoc, $sourceEntity, $offset = nu */ public function expandParameters($criteria) { - $params = array(); - $types = array(); + $params = []; + $types = []; foreach ($criteria as $field => $value) { if ($value === null) { @@ -1831,7 +1833,7 @@ public function expandParameters($criteria) $params = array_merge($params, $this->getValues($value)); } - return array($params, $types); + return [$params, $types]; } /** @@ -1848,8 +1850,8 @@ public function expandParameters($criteria) */ private function expandToManyParameters($criteria) { - $params = array(); - $types = array(); + $params = []; + $types = []; foreach ($criteria as $criterion) { if ($criterion['value'] === null) { @@ -1860,7 +1862,7 @@ private function expandToManyParameters($criteria) $params = array_merge($params, $this->getValues($criterion['value'])); } - return array($params, $types); + return [$params, $types]; } /** @@ -1875,11 +1877,11 @@ private function expandToManyParameters($criteria) */ private function getTypes($field, $value, ClassMetadata $class) { - $types = array(); + $types = []; switch (true) { case (isset($class->fieldMappings[$field])): - $types = array_merge($types, array($class->fieldMappings[$field]['type'])); + $types = array_merge($types, [$class->fieldMappings[$field]['type']]); break; case (isset($class->associationMappings[$field])): @@ -1926,19 +1928,19 @@ private function getTypes($field, $value, ClassMetadata $class) private function getValues($value) { if (is_array($value)) { - $newValue = array(); + $newValue = []; foreach ($value as $itemValue) { $newValue = array_merge($newValue, $this->getValues($itemValue)); } - return array($newValue); + return [$newValue]; } if (is_object($value) && $this->em->getMetadataFactory()->hasMetadataFor(ClassUtils::getClass($value))) { $class = $this->em->getClassMetadata(get_class($value)); if ($class->isIdentifierComposite) { - $newValue = array(); + $newValue = []; foreach ($class->getIdentifierValues($value) as $innerValue) { $newValue = array_merge($newValue, $this->getValues($innerValue)); @@ -1948,7 +1950,7 @@ private function getValues($value) } } - return array($this->getIndividualValue($value)); + return [$this->getIndividualValue($value)]; } /** @@ -2038,7 +2040,7 @@ public function getSQLColumnAlias($columnName) */ protected function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias) { - $filterClauses = array(); + $filterClauses = []; foreach ($this->em->getFilters()->getEnabledFilters() as $filter) { if ('' !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { diff --git a/lib/Doctrine/ORM/Persisters/Entity/CachedPersisterContext.php b/lib/Doctrine/ORM/Persisters/Entity/CachedPersisterContext.php index 81fde938b3e..132dac7e4de 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/CachedPersisterContext.php +++ b/lib/Doctrine/ORM/Persisters/Entity/CachedPersisterContext.php @@ -76,7 +76,7 @@ class CachedPersisterContext * * @var array */ - public $sqlTableAliases = array(); + public $sqlTableAliases = []; /** * Whether this persistent context is considering limit operations applied to the selection queries diff --git a/lib/Doctrine/ORM/Persisters/Entity/EntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/EntityPersister.php index ff018a05007..9ac63166832 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/EntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/EntityPersister.php @@ -81,7 +81,7 @@ public function getSelectSQL($criteria, $assoc = null, $lockMode = null, $limit * * @return string */ - public function getCountSQL($criteria = array()); + public function getCountSQL($criteria = []); /** * Expands the parameters from the given criteria and use the correct binding types if found. @@ -165,7 +165,7 @@ public function delete($entity); * * @return int */ - public function count($criteria = array()); + public function count($criteria = []); /** * Gets the name of the table that owns the column the given field is mapped to. @@ -197,7 +197,7 @@ public function getOwningTable($fieldName); * * @todo Check identity map? loadById method? Try to guess whether $criteria is the id? */ - public function load(array $criteria, $entity = null, $assoc = null, array $hints = array(), $lockMode = null, $limit = null, array $orderBy = null); + public function load(array $criteria, $entity = null, $assoc = null, array $hints = [], $lockMode = null, $limit = null, array $orderBy = null); /** * Loads an entity by identifier. @@ -225,7 +225,7 @@ public function loadById(array $identifier, $entity = null); * * @throws \Doctrine\ORM\Mapping\MappingException */ - public function loadOneToOneEntity(array $assoc, $sourceEntity, array $identifier = array()); + public function loadOneToOneEntity(array $assoc, $sourceEntity, array $identifier = []); /** * Refreshes a managed entity. @@ -260,7 +260,7 @@ public function loadCriteria(Criteria $criteria); * * @return array */ - public function loadAll(array $criteria = array(), array $orderBy = null, $limit = null, $offset = null); + public function loadAll(array $criteria = [], array $orderBy = null, $limit = null, $offset = null); /** * Gets (sliced or full) elements of the given collection. diff --git a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php index 0975cf56ef1..e3e7d2b4322 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php @@ -45,14 +45,14 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister * * @var array */ - private $owningTableMap = array(); + private $owningTableMap = []; /** * Map of table to quoted table names. * * @var array */ - private $quotedTableMap = array(); + private $quotedTableMap = []; /** * {@inheritdoc} @@ -127,10 +127,10 @@ public function getOwningTable($fieldName) public function executeInserts() { if ( ! $this->queuedInserts) { - return array(); + return []; } - $postInsertIds = array(); + $postInsertIds = []; $idGenerator = $this->class->idGenerator; $isPostInsertId = $idGenerator->isPostInsertGenerator(); $rootClass = ($this->class->name !== $this->class->rootEntityName) @@ -143,7 +143,7 @@ public function executeInserts() $rootTableStmt = $this->conn->prepare($rootPersister->getInsertSQL()); // Prepare statements for sub tables. - $subTableStmts = array(); + $subTableStmts = []; if ($rootClass !== $this->class) { $subTableStmts[$this->class->getTableName()] = $this->conn->prepare($this->getInsertSQL()); @@ -176,13 +176,13 @@ public function executeInserts() if ($isPostInsertId) { $generatedId = $idGenerator->generate($this->em, $entity); - $id = array( + $id = [ $this->class->identifier[0] => $generatedId - ); - $postInsertIds[] = array( + ]; + $postInsertIds[] = [ 'generatedId' => $generatedId, 'entity' => $entity, - ); + ]; } else { $id = $this->em->getUnitOfWork()->getEntityIdentifier($entity); } @@ -198,7 +198,7 @@ public function executeInserts() $paramIndex = 1; $data = isset($insertData[$tableName]) ? $insertData[$tableName] - : array(); + : []; foreach ((array) $id as $idName => $idVal) { $type = isset($this->columnTypes[$idName]) ? $this->columnTypes[$idName] : Type::STRING; @@ -222,7 +222,7 @@ public function executeInserts() $stmt->closeCursor(); } - $this->queuedInserts = array(); + $this->queuedInserts = []; return $postInsertIds; } @@ -258,7 +258,7 @@ public function update($entity) if ( ! isset($updateData[$versionedTable])) { $tableName = $this->quoteStrategy->getTableName($versionedClass, $this->platform); - $this->updateTable($entity, $tableName, array(), true); + $this->updateTable($entity, $tableName, [], true); } $identifiers = $this->em->getUnitOfWork()->getEntityIdentifier($entity); @@ -369,7 +369,7 @@ public function getSelectSQL($criteria, $assoc = null, $lockMode = null, $limit /** * {@inheritDoc} */ - public function getCountSQL($criteria = array()) + public function getCountSQL($criteria = []) { $tableName = $this->quoteStrategy->getTableName($this->class, $this->platform); $baseTableAlias = $this->getSQLTableAlias($this->class->name); @@ -406,7 +406,7 @@ protected function getLockTablesSql($lockMode) // INNER JOIN parent tables foreach ($this->class->parentClasses as $parentClassName) { - $conditions = array(); + $conditions = []; $tableAlias = $this->getSQLTableAlias($parentClassName); $parentClass = $this->em->getClassMetadata($parentClassName); $joinSql .= ' INNER JOIN ' . $this->quoteStrategy->getTableName($parentClass, $this->platform) . ' ' . $tableAlias . ' ON '; @@ -433,7 +433,7 @@ protected function getSelectColumnsSQL() return $this->currentPersisterContext->selectColumnListSql; } - $columnList = array(); + $columnList = []; $discrColumn = $this->class->discriminatorColumn['name']; $discrColumnType = $this->class->discriminatorColumn['type']; $baseTableAlias = $this->getSQLTableAlias($this->class->name); @@ -545,7 +545,7 @@ protected function getInsertColumnList() // Identifier columns must always come first in the column list of subclasses. $columns = $this->class->parentClasses ? $this->class->getIdentifierColumnNames() - : array(); + : []; foreach ($this->class->reflFields as $name => $field) { if (isset($this->class->fieldMappings[$name]['inherited']) @@ -599,7 +599,7 @@ private function getJoinSql($baseTableAlias) // INNER JOIN parent tables foreach ($this->class->parentClasses as $parentClassName) { - $conditions = array(); + $conditions = []; $parentClass = $this->em->getClassMetadata($parentClassName); $tableAlias = $this->getSQLTableAlias($parentClassName); $joinSql .= ' INNER JOIN ' . $this->quoteStrategy->getTableName($parentClass, $this->platform) . ' ' . $tableAlias . ' ON '; @@ -614,7 +614,7 @@ private function getJoinSql($baseTableAlias) // OUTER JOIN sub tables foreach ($this->class->subClasses as $subClassName) { - $conditions = array(); + $conditions = []; $subClass = $this->em->getClassMetadata($subClassName); $tableAlias = $this->getSQLTableAlias($subClassName); $joinSql .= ' LEFT JOIN ' . $this->quoteStrategy->getTableName($subClass, $this->platform) . ' ' . $tableAlias . ' ON '; diff --git a/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php b/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php index 8dc71bb1d8c..d3eb5d8acde 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php @@ -164,7 +164,7 @@ protected function getSelectConditionCriteriaSQL(Criteria $criteria) */ protected function getSelectConditionDiscriminatorValueSQL() { - $values = array(); + $values = []; if ($this->class->discriminatorValue !== null) { // discriminators can be 0 $values[] = $this->conn->quote($this->class->discriminatorValue); diff --git a/lib/Doctrine/ORM/Persisters/SqlExpressionVisitor.php b/lib/Doctrine/ORM/Persisters/SqlExpressionVisitor.php index f23bfa3da9a..476ecaba81e 100644 --- a/lib/Doctrine/ORM/Persisters/SqlExpressionVisitor.php +++ b/lib/Doctrine/ORM/Persisters/SqlExpressionVisitor.php @@ -70,7 +70,7 @@ public function walkComparison(Comparison $comparison) if (isset($this->classMetadata->associationMappings[$field]) && $value !== null && ! is_object($value) && - ! in_array($comparison->getOperator(), array(Comparison::IN, Comparison::NIN))) { + ! in_array($comparison->getOperator(), [Comparison::IN, Comparison::NIN])) { throw PersisterException::matchingAssocationFieldRequiresObject($this->classMetadata->name, $field); } @@ -89,7 +89,7 @@ public function walkComparison(Comparison $comparison) */ public function walkCompositeExpression(CompositeExpression $expr) { - $expressionList = array(); + $expressionList = []; foreach ($expr->getExpressionList() as $child) { $expressionList[] = $this->dispatch($child); diff --git a/lib/Doctrine/ORM/Persisters/SqlValueVisitor.php b/lib/Doctrine/ORM/Persisters/SqlValueVisitor.php index 0e680ad078d..2b3bdedc440 100644 --- a/lib/Doctrine/ORM/Persisters/SqlValueVisitor.php +++ b/lib/Doctrine/ORM/Persisters/SqlValueVisitor.php @@ -34,12 +34,12 @@ class SqlValueVisitor extends ExpressionVisitor /** * @var array */ - private $values = array(); + private $values = []; /** * @var array */ - private $types = array(); + private $types = []; /** * Converts a comparison expression into the target query language output. @@ -61,7 +61,7 @@ public function walkComparison(Comparison $comparison) } $this->values[] = $value; - $this->types[] = array($field, $value); + $this->types[] = [$field, $value]; } /** @@ -97,7 +97,7 @@ public function walkValue(Value $value) */ public function getParamsAndTypes() { - return array($this->values, $this->types); + return [$this->values, $this->types]; } /** diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 6a8a50ae0a0..12fb3f560ec 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -135,7 +135,7 @@ final class Query extends AbstractQuery * * @var array */ - private $_parsedTypes = array(); + private $_parsedTypes = []; /** * Cached DQL query. @@ -241,7 +241,7 @@ protected function getResultSetMapping() */ private function _parse() { - $types = array(); + $types = []; foreach ($this->parameters as $parameter) { /** @var Query\Parameter $parameter */ @@ -354,8 +354,8 @@ private function evictEntityCacheRegion() */ private function processParameterMappings($paramMappings) { - $sqlParams = array(); - $types = array(); + $sqlParams = []; + $types = []; foreach ($this->parameters as $parameter) { $key = $parameter->getName(); @@ -383,7 +383,7 @@ private function processParameterMappings($paramMappings) // optimized multi value sql positions away for now, // they are not allowed in DQL anyways. - $value = array($value); + $value = [$value]; $countValue = count($value); for ($i = 0, $l = count($sqlPositions); $i < $l; $i++) { @@ -403,7 +403,7 @@ private function processParameterMappings($paramMappings) $types = array_values($types); } - return array($sqlParams, $types); + return [$sqlParams, $types]; } /** @@ -667,7 +667,7 @@ public function setHydrationMode($hydrationMode) */ public function setLockMode($lockMode) { - if (in_array($lockMode, array(LockMode::NONE, LockMode::PESSIMISTIC_READ, LockMode::PESSIMISTIC_WRITE), true)) { + if (in_array($lockMode, [LockMode::NONE, LockMode::PESSIMISTIC_READ, LockMode::PESSIMISTIC_WRITE], true)) { if ( ! $this->_em->getConnection()->isTransactionActive()) { throw TransactionRequiredException::transactionRequired(); } diff --git a/lib/Doctrine/ORM/Query/AST/CoalesceExpression.php b/lib/Doctrine/ORM/Query/AST/CoalesceExpression.php index 194f9ace55f..9e3b4c526fb 100644 --- a/lib/Doctrine/ORM/Query/AST/CoalesceExpression.php +++ b/lib/Doctrine/ORM/Query/AST/CoalesceExpression.php @@ -23,7 +23,7 @@ * CoalesceExpression ::= "COALESCE" "(" ScalarExpression {"," ScalarExpression}* ")" * * @since 2.1 - * + * * @link www.doctrine-project.org * @author Benjamin Eberlei * @author Guilherme Blanco @@ -35,7 +35,7 @@ class CoalesceExpression extends Node /** * @var array */ - public $scalarExpressions = array(); + public $scalarExpressions = []; /** * @param array $scalarExpressions diff --git a/lib/Doctrine/ORM/Query/AST/ConditionalExpression.php b/lib/Doctrine/ORM/Query/AST/ConditionalExpression.php index 62c7b2bca26..bf823629b69 100644 --- a/lib/Doctrine/ORM/Query/AST/ConditionalExpression.php +++ b/lib/Doctrine/ORM/Query/AST/ConditionalExpression.php @@ -33,7 +33,7 @@ class ConditionalExpression extends Node /** * @var array */ - public $conditionalTerms = array(); + public $conditionalTerms = []; /** * @param array $conditionalTerms diff --git a/lib/Doctrine/ORM/Query/AST/ConditionalTerm.php b/lib/Doctrine/ORM/Query/AST/ConditionalTerm.php index bb92db119bf..7122c9c6822 100644 --- a/lib/Doctrine/ORM/Query/AST/ConditionalTerm.php +++ b/lib/Doctrine/ORM/Query/AST/ConditionalTerm.php @@ -32,7 +32,7 @@ class ConditionalTerm extends Node /** * @var array */ - public $conditionalFactors = array(); + public $conditionalFactors = []; /** * @param array $conditionalFactors diff --git a/lib/Doctrine/ORM/Query/AST/FromClause.php b/lib/Doctrine/ORM/Query/AST/FromClause.php index b1d8dfe6b8f..fdb61ca373a 100644 --- a/lib/Doctrine/ORM/Query/AST/FromClause.php +++ b/lib/Doctrine/ORM/Query/AST/FromClause.php @@ -22,7 +22,7 @@ /** * FromClause ::= "FROM" IdentificationVariableDeclaration {"," IdentificationVariableDeclaration} * - * + * * @link www.doctrine-project.org * @since 2.0 * @author Guilherme Blanco @@ -34,7 +34,7 @@ class FromClause extends Node /** * @var array */ - public $identificationVariableDeclarations = array(); + public $identificationVariableDeclarations = []; /** * @param array $identificationVariableDeclarations diff --git a/lib/Doctrine/ORM/Query/AST/Functions/ConcatFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/ConcatFunction.php index 1c58f6cbdd6..71da374dfcd 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/ConcatFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/ConcatFunction.php @@ -38,7 +38,7 @@ class ConcatFunction extends FunctionNode public $secondStringPrimary; - public $concatExpressions = array(); + public $concatExpressions = []; /** * @override @@ -47,13 +47,13 @@ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { $platform = $sqlWalker->getConnection()->getDatabasePlatform(); - $args = array(); + $args = []; foreach ($this->concatExpressions as $expression) { $args[] = $sqlWalker->walkStringPrimary($expression); } - return call_user_func_array(array($platform,'getConcatExpression'), $args); + return call_user_func_array([$platform,'getConcatExpression'], $args); } /** diff --git a/lib/Doctrine/ORM/Query/AST/GeneralCaseExpression.php b/lib/Doctrine/ORM/Query/AST/GeneralCaseExpression.php index a74eed599dc..e7937d60d2e 100644 --- a/lib/Doctrine/ORM/Query/AST/GeneralCaseExpression.php +++ b/lib/Doctrine/ORM/Query/AST/GeneralCaseExpression.php @@ -23,7 +23,7 @@ * GeneralCaseExpression ::= "CASE" WhenClause {WhenClause}* "ELSE" ScalarExpression "END" * * @since 2.2 - * + * * @link www.doctrine-project.org * @author Benjamin Eberlei * @author Guilherme Blanco @@ -35,7 +35,7 @@ class GeneralCaseExpression extends Node /** * @var array */ - public $whenClauses = array(); + public $whenClauses = []; /** * @var mixed diff --git a/lib/Doctrine/ORM/Query/AST/GroupByClause.php b/lib/Doctrine/ORM/Query/AST/GroupByClause.php index c05fa5863d0..687512a4c73 100644 --- a/lib/Doctrine/ORM/Query/AST/GroupByClause.php +++ b/lib/Doctrine/ORM/Query/AST/GroupByClause.php @@ -33,7 +33,7 @@ class GroupByClause extends Node /** * @var array */ - public $groupByItems = array(); + public $groupByItems = []; /** * @param array $groupByItems diff --git a/lib/Doctrine/ORM/Query/AST/IdentificationVariableDeclaration.php b/lib/Doctrine/ORM/Query/AST/IdentificationVariableDeclaration.php index a8f7f6d350e..2e2032ca341 100644 --- a/lib/Doctrine/ORM/Query/AST/IdentificationVariableDeclaration.php +++ b/lib/Doctrine/ORM/Query/AST/IdentificationVariableDeclaration.php @@ -43,7 +43,7 @@ class IdentificationVariableDeclaration extends Node /** * @var array */ - public $joins = array(); + public $joins = []; /** * @param RangeVariableDeclaration|null $rangeVariableDecl diff --git a/lib/Doctrine/ORM/Query/AST/InExpression.php b/lib/Doctrine/ORM/Query/AST/InExpression.php index 9d0a8b54ee8..64ef1340573 100644 --- a/lib/Doctrine/ORM/Query/AST/InExpression.php +++ b/lib/Doctrine/ORM/Query/AST/InExpression.php @@ -42,7 +42,7 @@ class InExpression extends Node /** * @var array */ - public $literals = array(); + public $literals = []; /** * @var Subselect|null diff --git a/lib/Doctrine/ORM/Query/AST/OrderByClause.php b/lib/Doctrine/ORM/Query/AST/OrderByClause.php index 75d16c7319d..e0e30e9d997 100644 --- a/lib/Doctrine/ORM/Query/AST/OrderByClause.php +++ b/lib/Doctrine/ORM/Query/AST/OrderByClause.php @@ -33,7 +33,7 @@ class OrderByClause extends Node /** * @var array */ - public $orderByItems = array(); + public $orderByItems = []; /** * @param array $orderByItems diff --git a/lib/Doctrine/ORM/Query/AST/SelectClause.php b/lib/Doctrine/ORM/Query/AST/SelectClause.php index 1df143677be..f8e6f472a1e 100644 --- a/lib/Doctrine/ORM/Query/AST/SelectClause.php +++ b/lib/Doctrine/ORM/Query/AST/SelectClause.php @@ -38,7 +38,7 @@ class SelectClause extends Node /** * @var array */ - public $selectExpressions = array(); + public $selectExpressions = []; /** * @param array $selectExpressions diff --git a/lib/Doctrine/ORM/Query/AST/SimpleArithmeticExpression.php b/lib/Doctrine/ORM/Query/AST/SimpleArithmeticExpression.php index 9bd485045f3..80ecd15ce57 100644 --- a/lib/Doctrine/ORM/Query/AST/SimpleArithmeticExpression.php +++ b/lib/Doctrine/ORM/Query/AST/SimpleArithmeticExpression.php @@ -33,7 +33,7 @@ class SimpleArithmeticExpression extends Node /** * @var array */ - public $arithmeticTerms = array(); + public $arithmeticTerms = []; /** * @param array $arithmeticTerms diff --git a/lib/Doctrine/ORM/Query/AST/SimpleCaseExpression.php b/lib/Doctrine/ORM/Query/AST/SimpleCaseExpression.php index 5272f3962a8..67e354e5569 100644 --- a/lib/Doctrine/ORM/Query/AST/SimpleCaseExpression.php +++ b/lib/Doctrine/ORM/Query/AST/SimpleCaseExpression.php @@ -23,7 +23,7 @@ * SimpleCaseExpression ::= "CASE" CaseOperand SimpleWhenClause {SimpleWhenClause}* "ELSE" ScalarExpression "END" * * @since 2.2 - * + * * @link www.doctrine-project.org * @author Benjamin Eberlei * @author Guilherme Blanco @@ -40,7 +40,7 @@ class SimpleCaseExpression extends Node /** * @var array */ - public $simpleWhenClauses = array(); + public $simpleWhenClauses = []; /** * @var mixed diff --git a/lib/Doctrine/ORM/Query/AST/SubselectFromClause.php b/lib/Doctrine/ORM/Query/AST/SubselectFromClause.php index 8d009fcfdc1..9704061e8cd 100644 --- a/lib/Doctrine/ORM/Query/AST/SubselectFromClause.php +++ b/lib/Doctrine/ORM/Query/AST/SubselectFromClause.php @@ -33,7 +33,7 @@ class SubselectFromClause extends Node /** * @var array */ - public $identificationVariableDeclarations = array(); + public $identificationVariableDeclarations = []; /** * @param array $identificationVariableDeclarations diff --git a/lib/Doctrine/ORM/Query/AST/UpdateClause.php b/lib/Doctrine/ORM/Query/AST/UpdateClause.php index 430ed14eb93..23c722a62b2 100644 --- a/lib/Doctrine/ORM/Query/AST/UpdateClause.php +++ b/lib/Doctrine/ORM/Query/AST/UpdateClause.php @@ -43,7 +43,7 @@ class UpdateClause extends Node /** * @var array */ - public $updateItems = array(); + public $updateItems = []; /** * @param string $abstractSchemaName diff --git a/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php b/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php index b14ddb53422..aaf94d7ff90 100644 --- a/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php @@ -81,7 +81,7 @@ public function __construct(AST\Node $AST, $sqlWalker) . ' SELECT t0.' . implode(', t0.', $idColumnNames); $rangeDecl = new AST\RangeVariableDeclaration($primaryClass->name, $primaryDqlAlias); - $fromClause = new AST\FromClause(array(new AST\IdentificationVariableDeclaration($rangeDecl, null, array()))); + $fromClause = new AST\FromClause([new AST\IdentificationVariableDeclaration($rangeDecl, null, [])]); $this->_insertSql .= $sqlWalker->walkFromClause($fromClause); // Append WHERE clause, if there is one. @@ -93,7 +93,7 @@ public function __construct(AST\Node $AST, $sqlWalker) $idSubselect = 'SELECT ' . $idColumnList . ' FROM ' . $tempTable; // 3. Create and store DELETE statements - $classNames = array_merge($primaryClass->parentClasses, array($primaryClass->name), $primaryClass->subClasses); + $classNames = array_merge($primaryClass->parentClasses, [$primaryClass->name], $primaryClass->subClasses); foreach (array_reverse($classNames) as $className) { $tableName = $quoteStrategy->getTableName($em->getClassMetadata($className), $platform); $this->_sqlStatements[] = 'DELETE FROM ' . $tableName @@ -101,12 +101,12 @@ public function __construct(AST\Node $AST, $sqlWalker) } // 4. Store DDL for temporary identifier table. - $columnDefinitions = array(); + $columnDefinitions = []; foreach ($idColumnNames as $idColumnName) { - $columnDefinitions[$idColumnName] = array( + $columnDefinitions[$idColumnName] = [ 'notnull' => true, 'type' => Type::getType(PersisterHelper::getTypeOfColumn($idColumnName, $rootClass, $em)), - ); + ]; } $this->_createTempTableSql = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' (' . $platform->getColumnDeclarationListSQL($columnDefinitions) . ')'; diff --git a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php index 995f9cad12c..acad25a924b 100644 --- a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php @@ -52,7 +52,7 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor /** * @var array */ - private $_sqlParameters = array(); + private $_sqlParameters = []; /** * @var int @@ -92,7 +92,7 @@ public function __construct(AST\Node $AST, $sqlWalker) . ' SELECT t0.' . implode(', t0.', $idColumnNames); $rangeDecl = new AST\RangeVariableDeclaration($primaryClass->name, $updateClause->aliasIdentificationVariable); - $fromClause = new AST\FromClause(array(new AST\IdentificationVariableDeclaration($rangeDecl, null, array()))); + $fromClause = new AST\FromClause([new AST\IdentificationVariableDeclaration($rangeDecl, null, [])]); $this->_insertSql .= $sqlWalker->walkFromClause($fromClause); @@ -100,7 +100,7 @@ public function __construct(AST\Node $AST, $sqlWalker) $idSubselect = 'SELECT ' . $idColumnList . ' FROM ' . $tempTable; // 3. Create and store UPDATE statements - $classNames = array_merge($primaryClass->parentClasses, array($primaryClass->name), $primaryClass->subClasses); + $classNames = array_merge($primaryClass->parentClasses, [$primaryClass->name], $primaryClass->subClasses); $i = -1; foreach (array_reverse($classNames) as $className) { @@ -143,13 +143,13 @@ public function __construct(AST\Node $AST, $sqlWalker) } // 4. Store DDL for temporary identifier table. - $columnDefinitions = array(); + $columnDefinitions = []; foreach ($idColumnNames as $idColumnName) { - $columnDefinitions[$idColumnName] = array( + $columnDefinitions[$idColumnName] = [ 'notnull' => true, 'type' => Type::getType(PersisterHelper::getTypeOfColumn($idColumnName, $rootClass, $em)), - ); + ]; } $this->_createTempTableSql = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' (' @@ -176,8 +176,8 @@ public function execute(Connection $conn, array $params, array $types) // Execute UPDATE statements foreach ($this->_sqlStatements as $key => $statement) { - $paramValues = array(); - $paramTypes = array(); + $paramValues = []; + $paramTypes = []; if (isset($this->_sqlParameters[$key])) { foreach ($this->_sqlParameters[$key] as $parameterKey => $parameterName) { diff --git a/lib/Doctrine/ORM/Query/Expr.php b/lib/Doctrine/ORM/Query/Expr.php index 70f9ac9e271..eada610580d 100644 --- a/lib/Doctrine/ORM/Query/Expr.php +++ b/lib/Doctrine/ORM/Query/Expr.php @@ -220,7 +220,7 @@ public function gte($x, $y) */ public function avg($x) { - return new Expr\Func('AVG', array($x)); + return new Expr\Func('AVG', [$x]); } /** @@ -232,7 +232,7 @@ public function avg($x) */ public function max($x) { - return new Expr\Func('MAX', array($x)); + return new Expr\Func('MAX', [$x]); } /** @@ -244,7 +244,7 @@ public function max($x) */ public function min($x) { - return new Expr\Func('MIN', array($x)); + return new Expr\Func('MIN', [$x]); } /** @@ -256,7 +256,7 @@ public function min($x) */ public function count($x) { - return new Expr\Func('COUNT', array($x)); + return new Expr\Func('COUNT', [$x]); } /** @@ -280,7 +280,7 @@ public function countDistinct($x) */ public function exists($subquery) { - return new Expr\Func('EXISTS', array($subquery)); + return new Expr\Func('EXISTS', [$subquery]); } /** @@ -292,7 +292,7 @@ public function exists($subquery) */ public function all($subquery) { - return new Expr\Func('ALL', array($subquery)); + return new Expr\Func('ALL', [$subquery]); } /** @@ -304,7 +304,7 @@ public function all($subquery) */ public function some($subquery) { - return new Expr\Func('SOME', array($subquery)); + return new Expr\Func('SOME', [$subquery]); } /** @@ -316,7 +316,7 @@ public function some($subquery) */ public function any($subquery) { - return new Expr\Func('ANY', array($subquery)); + return new Expr\Func('ANY', [$subquery]); } /** @@ -328,7 +328,7 @@ public function any($subquery) */ public function not($restriction) { - return new Expr\Func('NOT', array($restriction)); + return new Expr\Func('NOT', [$restriction]); } /** @@ -340,7 +340,7 @@ public function not($restriction) */ public function abs($x) { - return new Expr\Func('ABS', array($x)); + return new Expr\Func('ABS', [$x]); } /** @@ -429,7 +429,7 @@ public function quot($x, $y) */ public function sqrt($x) { - return new Expr\Func('SQRT', array($x)); + return new Expr\Func('SQRT', [$x]); } /** @@ -548,7 +548,7 @@ public function concat($x, $y) */ public function substring($x, $from, $len = null) { - $args = array($x, $from); + $args = [$x, $from]; if (null !== $len) { $args[] = $len; } @@ -565,7 +565,7 @@ public function substring($x, $from, $len = null) */ public function lower($x) { - return new Expr\Func('LOWER', array($x)); + return new Expr\Func('LOWER', [$x]); } /** @@ -577,7 +577,7 @@ public function lower($x) */ public function upper($x) { - return new Expr\Func('UPPER', array($x)); + return new Expr\Func('UPPER', [$x]); } /** @@ -589,7 +589,7 @@ public function upper($x) */ public function length($x) { - return new Expr\Func('LENGTH', array($x)); + return new Expr\Func('LENGTH', [$x]); } /** diff --git a/lib/Doctrine/ORM/Query/Expr/Andx.php b/lib/Doctrine/ORM/Query/Expr/Andx.php index 432f714f6d9..cc64ab1a85a 100644 --- a/lib/Doctrine/ORM/Query/Expr/Andx.php +++ b/lib/Doctrine/ORM/Query/Expr/Andx.php @@ -38,12 +38,12 @@ class Andx extends Composite /** * @var array */ - protected $allowedClasses = array( + protected $allowedClasses = [ 'Doctrine\ORM\Query\Expr\Comparison', 'Doctrine\ORM\Query\Expr\Func', 'Doctrine\ORM\Query\Expr\Orx', 'Doctrine\ORM\Query\Expr\Andx', - ); + ]; /** * @return array diff --git a/lib/Doctrine/ORM/Query/Expr/Base.php b/lib/Doctrine/ORM/Query/Expr/Base.php index 6eac70a27c6..d1303138360 100644 --- a/lib/Doctrine/ORM/Query/Expr/Base.php +++ b/lib/Doctrine/ORM/Query/Expr/Base.php @@ -48,17 +48,17 @@ abstract class Base /** * @var array */ - protected $allowedClasses = array(); + protected $allowedClasses = []; /** * @var array */ - protected $parts = array(); + protected $parts = []; /** * @param array $args */ - public function __construct($args = array()) + public function __construct($args = []) { $this->addMultiple($args); } @@ -68,7 +68,7 @@ public function __construct($args = array()) * * @return Base */ - public function addMultiple($args = array()) + public function addMultiple($args = []) { foreach ((array) $args as $arg) { $this->add($arg); diff --git a/lib/Doctrine/ORM/Query/Expr/Composite.php b/lib/Doctrine/ORM/Query/Expr/Composite.php index 4d9a251986c..6b8a04fa5cf 100644 --- a/lib/Doctrine/ORM/Query/Expr/Composite.php +++ b/lib/Doctrine/ORM/Query/Expr/Composite.php @@ -39,7 +39,7 @@ public function __toString() return (string) $this->parts[0]; } - $components = array(); + $components = []; foreach ($this->parts as $part) { $components[] = $this->processQueryPart($part); diff --git a/lib/Doctrine/ORM/Query/Expr/OrderBy.php b/lib/Doctrine/ORM/Query/Expr/OrderBy.php index 932548bd603..b9da73b985f 100644 --- a/lib/Doctrine/ORM/Query/Expr/OrderBy.php +++ b/lib/Doctrine/ORM/Query/Expr/OrderBy.php @@ -48,12 +48,12 @@ class OrderBy /** * @var array */ - protected $allowedClasses = array(); + protected $allowedClasses = []; /** * @var array */ - protected $parts = array(); + protected $parts = []; /** * @param string|null $sort diff --git a/lib/Doctrine/ORM/Query/Expr/Orx.php b/lib/Doctrine/ORM/Query/Expr/Orx.php index c4ff7ae30d0..35f88e831cf 100644 --- a/lib/Doctrine/ORM/Query/Expr/Orx.php +++ b/lib/Doctrine/ORM/Query/Expr/Orx.php @@ -38,12 +38,12 @@ class Orx extends Composite /** * @var array */ - protected $allowedClasses = array( + protected $allowedClasses = [ 'Doctrine\ORM\Query\Expr\Comparison', 'Doctrine\ORM\Query\Expr\Func', 'Doctrine\ORM\Query\Expr\Andx', 'Doctrine\ORM\Query\Expr\Orx', - ); + ]; /** * @return array diff --git a/lib/Doctrine/ORM/Query/Expr/Select.php b/lib/Doctrine/ORM/Query/Expr/Select.php index 21df6c735d4..00bdc94f30a 100644 --- a/lib/Doctrine/ORM/Query/Expr/Select.php +++ b/lib/Doctrine/ORM/Query/Expr/Select.php @@ -43,9 +43,7 @@ class Select extends Base /** * @var array */ - protected $allowedClasses = array( - 'Doctrine\ORM\Query\Expr\Func' - ); + protected $allowedClasses = ['Doctrine\ORM\Query\Expr\Func']; /** * @return array diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php index b0248fbac15..c48edd43faf 100644 --- a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php +++ b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php @@ -75,7 +75,7 @@ final public function setParameter($name, $value, $type = null) $type = ParameterTypeInferer::inferType($value); } - $this->parameters[$name] = array('value' => $value, 'type' => $type); + $this->parameters[$name] = ['value' => $value, 'type' => $type]; // Keep the parameters sorted for the hash ksort($this->parameters); @@ -122,7 +122,7 @@ final public function hasParameter($name) return true; } - + /** * Returns as string representation of the SQLFilter parameters (the state). * diff --git a/lib/Doctrine/ORM/Query/FilterCollection.php b/lib/Doctrine/ORM/Query/FilterCollection.php index ffbaeaf1293..ca7f1ac3289 100644 --- a/lib/Doctrine/ORM/Query/FilterCollection.php +++ b/lib/Doctrine/ORM/Query/FilterCollection.php @@ -59,7 +59,7 @@ class FilterCollection * * @var \Doctrine\ORM\Query\Filter\SQLFilter[] */ - private $enabledFilters = array(); + private $enabledFilters = []; /** * @var string The filter hash from the last time the query was parsed. @@ -176,16 +176,16 @@ public function has($name) /** * Checks if a filter is enabled. - * + * * @param string $name Name of the filter. - * + * * @return boolean True if the filter is enabled, false otherwise. */ public function isEnabled($name) { return isset($this->enabledFilters[$name]); } - + /** * @return boolean True, if the filter collection is clean. */ diff --git a/lib/Doctrine/ORM/Query/Lexer.php b/lib/Doctrine/ORM/Query/Lexer.php index b31b93b8716..b889ecfaea6 100644 --- a/lib/Doctrine/ORM/Query/Lexer.php +++ b/lib/Doctrine/ORM/Query/Lexer.php @@ -129,13 +129,13 @@ public function __construct($input) */ protected function getCatchablePatterns() { - return array( + return [ '[a-z_][a-z0-9_]*\:[a-z_][a-z0-9_]*(?:\\\[a-z_][a-z0-9_]*)*', // aliased name '[a-z_\\\][a-z0-9_]*(?:\\\[a-z_][a-z0-9_]*)*', // identifier or qualified name '(?:[0-9]+(?:[\.][0-9]+)*)(?:e[+-]?[0-9]+)?', // numbers "'(?:[^']|'')*'", // quoted strings '\?[0-9]*|:[a-z_][a-z0-9_]*' // parameters - ); + ]; } /** @@ -143,7 +143,7 @@ protected function getCatchablePatterns() */ protected function getNonCatchablePatterns() { - return array('\s+', '(.)'); + return ['\s+', '(.)']; } /** diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 6f8eda51469..ae8fcd3ebd7 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -40,21 +40,21 @@ class Parser * * @var array */ - private static $_STRING_FUNCTIONS = array( + private static $_STRING_FUNCTIONS = [ 'concat' => 'Doctrine\ORM\Query\AST\Functions\ConcatFunction', 'substring' => 'Doctrine\ORM\Query\AST\Functions\SubstringFunction', 'trim' => 'Doctrine\ORM\Query\AST\Functions\TrimFunction', 'lower' => 'Doctrine\ORM\Query\AST\Functions\LowerFunction', 'upper' => 'Doctrine\ORM\Query\AST\Functions\UpperFunction', 'identity' => 'Doctrine\ORM\Query\AST\Functions\IdentityFunction', - ); + ]; /** * READ-ONLY: Maps BUILT-IN numeric function names to AST class names. * * @var array */ - private static $_NUMERIC_FUNCTIONS = array( + private static $_NUMERIC_FUNCTIONS = [ 'length' => 'Doctrine\ORM\Query\AST\Functions\LengthFunction', 'locate' => 'Doctrine\ORM\Query\AST\Functions\LocateFunction', 'abs' => 'Doctrine\ORM\Query\AST\Functions\AbsFunction', @@ -64,20 +64,20 @@ class Parser 'date_diff' => 'Doctrine\ORM\Query\AST\Functions\DateDiffFunction', 'bit_and' => 'Doctrine\ORM\Query\AST\Functions\BitAndFunction', 'bit_or' => 'Doctrine\ORM\Query\AST\Functions\BitOrFunction', - ); + ]; /** * READ-ONLY: Maps BUILT-IN datetime function names to AST class names. * * @var array */ - private static $_DATETIME_FUNCTIONS = array( + private static $_DATETIME_FUNCTIONS = [ 'current_date' => 'Doctrine\ORM\Query\AST\Functions\CurrentDateFunction', 'current_time' => 'Doctrine\ORM\Query\AST\Functions\CurrentTimeFunction', 'current_timestamp' => 'Doctrine\ORM\Query\AST\Functions\CurrentTimestampFunction', 'date_add' => 'Doctrine\ORM\Query\AST\Functions\DateAddFunction', 'date_sub' => 'Doctrine\ORM\Query\AST\Functions\DateSubFunction', - ); + ]; /* * Expressions that were encountered during parsing of identifiers and expressions @@ -87,27 +87,27 @@ class Parser /** * @var array */ - private $deferredIdentificationVariables = array(); + private $deferredIdentificationVariables = []; /** * @var array */ - private $deferredPartialObjectExpressions = array(); + private $deferredPartialObjectExpressions = []; /** * @var array */ - private $deferredPathExpressions = array(); + private $deferredPathExpressions = []; /** * @var array */ - private $deferredResultVariables = array(); + private $deferredResultVariables = []; /** * @var array */ - private $deferredNewObjectExpressions = array(); + private $deferredNewObjectExpressions = []; /** * The lexer. @@ -142,7 +142,7 @@ class Parser * * @var array */ - private $queryComponents = array(); + private $queryComponents = []; /** * Keeps the nesting level of defined ResultVariables. @@ -156,7 +156,7 @@ class Parser * * @var array */ - private $customTreeWalkers = array(); + private $customTreeWalkers = []; /** * The custom last tree walker, if any, that is responsible for producing the output. @@ -168,7 +168,7 @@ class Parser /** * @var array */ - private $identVariableExpressions = array(); + private $identVariableExpressions = []; /** * Checks if a function is internally defined. Used to prevent overwriting @@ -541,7 +541,7 @@ private function peekBeyondClosingParenthesis($resetPeek = true) */ private function isMathOperator($token) { - return in_array($token['type'], array(Lexer::T_PLUS, Lexer::T_MINUS, Lexer::T_DIVIDE, Lexer::T_MULTIPLY)); + return in_array($token['type'], [Lexer::T_PLUS, Lexer::T_MINUS, Lexer::T_DIVIDE, Lexer::T_MULTIPLY]); } /** @@ -568,7 +568,7 @@ private function isFunction() */ private function isAggregateFunction($tokenType) { - return in_array($tokenType, array(Lexer::T_AVG, Lexer::T_MIN, Lexer::T_MAX, Lexer::T_SUM, Lexer::T_COUNT)); + return in_array($tokenType, [Lexer::T_AVG, Lexer::T_MIN, Lexer::T_MAX, Lexer::T_SUM, Lexer::T_COUNT]); } /** @@ -578,7 +578,7 @@ private function isAggregateFunction($tokenType) */ private function isNextAllAnySome() { - return in_array($this->lexer->lookahead['type'], array(Lexer::T_ALL, Lexer::T_ANY, Lexer::T_SOME)); + return in_array($this->lexer->lookahead['type'], [Lexer::T_ALL, Lexer::T_ANY, Lexer::T_SOME]); } /** @@ -787,7 +787,7 @@ private function processDeferredPathExpressions($AST) if ( ! ($expectedType & $fieldType)) { // We need to recognize which was expected type(s) - $expectedStringTypes = array(); + $expectedStringTypes = []; // Validate state field type if ($expectedType & AST\PathExpression::TYPE_STATE_FIELD) { @@ -929,11 +929,11 @@ public function IdentificationVariable() $identVariable = $this->lexer->token['value']; - $this->deferredIdentificationVariables[] = array( + $this->deferredIdentificationVariables[] = [ 'expression' => $identVariable, 'nestingLevel' => $this->nestingLevel, 'token' => $this->lexer->token, - ); + ]; return $identVariable; } @@ -1028,11 +1028,11 @@ public function ResultVariable() $resultVariable = $this->lexer->token['value']; // Defer ResultVariable validation - $this->deferredResultVariables[] = array( + $this->deferredResultVariables[] = [ 'expression' => $resultVariable, 'nestingLevel' => $this->nestingLevel, 'token' => $this->lexer->token, - ); + ]; return $resultVariable; } @@ -1100,11 +1100,11 @@ public function PathExpression($expectedTypes) $pathExpr = new AST\PathExpression($expectedTypes, $identVariable, $field); // Defer PathExpression validation if requested to be deferred - $this->deferredPathExpressions[] = array( + $this->deferredPathExpressions[] = [ 'expression' => $pathExpr, 'nestingLevel' => $this->nestingLevel, 'token' => $this->lexer->token, - ); + ]; return $pathExpr; } @@ -1183,7 +1183,7 @@ public function SelectClause() } // Process SelectExpressions (1..N) - $selectExpressions = array(); + $selectExpressions = []; $selectExpressions[] = $this->SelectExpression(); while ($this->lexer->isNextToken(Lexer::T_COMMA)) { @@ -1237,20 +1237,20 @@ public function UpdateClause() $class = $this->em->getClassMetadata($abstractSchemaName); // Building queryComponent - $queryComponent = array( + $queryComponent = [ 'metadata' => $class, 'parent' => null, 'relation' => null, 'map' => null, 'nestingLevel' => $this->nestingLevel, 'token' => $token, - ); + ]; $this->queryComponents[$aliasIdentificationVariable] = $queryComponent; $this->match(Lexer::T_SET); - $updateItems = array(); + $updateItems = []; $updateItems[] = $this->UpdateItem(); while ($this->lexer->isNextToken(Lexer::T_COMMA)) { @@ -1295,14 +1295,14 @@ public function DeleteClause() $class = $this->em->getClassMetadata($deleteClause->abstractSchemaName); // Building queryComponent - $queryComponent = array( + $queryComponent = [ 'metadata' => $class, 'parent' => null, 'relation' => null, 'map' => null, 'nestingLevel' => $this->nestingLevel, 'token' => $token, - ); + ]; $this->queryComponents[$aliasIdentificationVariable] = $queryComponent; @@ -1318,7 +1318,7 @@ public function FromClause() { $this->match(Lexer::T_FROM); - $identificationVariableDeclarations = array(); + $identificationVariableDeclarations = []; $identificationVariableDeclarations[] = $this->IdentificationVariableDeclaration(); while ($this->lexer->isNextToken(Lexer::T_COMMA)) { @@ -1339,7 +1339,7 @@ public function SubselectFromClause() { $this->match(Lexer::T_FROM); - $identificationVariables = array(); + $identificationVariables = []; $identificationVariables[] = $this->SubselectIdentificationVariableDeclaration(); while ($this->lexer->isNextToken(Lexer::T_COMMA)) { @@ -1385,7 +1385,7 @@ public function GroupByClause() $this->match(Lexer::T_GROUP); $this->match(Lexer::T_BY); - $groupByItems = array($this->GroupByItem()); + $groupByItems = [$this->GroupByItem()]; while ($this->lexer->isNextToken(Lexer::T_COMMA)) { $this->match(Lexer::T_COMMA); @@ -1406,7 +1406,7 @@ public function OrderByClause() $this->match(Lexer::T_ORDER); $this->match(Lexer::T_BY); - $orderByItems = array(); + $orderByItems = []; $orderByItems[] = $this->OrderByItem(); while ($this->lexer->isNextToken(Lexer::T_COMMA)) { @@ -1583,7 +1583,7 @@ public function NewValue() */ public function IdentificationVariableDeclaration() { - $joins = array(); + $joins = []; $rangeVariableDeclaration = $this->RangeVariableDeclaration(); $indexBy = $this->lexer->isNextToken(Lexer::T_INDEX) ? $this->IndexBy() @@ -1739,14 +1739,14 @@ public function RangeVariableDeclaration() $classMetadata = $this->em->getClassMetadata($abstractSchemaName); // Building queryComponent - $queryComponent = array( + $queryComponent = [ 'metadata' => $classMetadata, 'parent' => null, 'relation' => null, 'map' => null, 'nestingLevel' => $this->nestingLevel, 'token' => $token - ); + ]; $this->queryComponents[$aliasIdentificationVariable] = $queryComponent; @@ -1776,14 +1776,14 @@ public function JoinAssociationDeclaration() $targetClass = $this->em->getClassMetadata($class->associationMappings[$field]['targetEntity']); // Building queryComponent - $joinQueryComponent = array( + $joinQueryComponent = [ 'metadata' => $targetClass, 'parent' => $joinAssociationPathExpression->identificationVariable, 'relation' => $class->getAssociationMapping($field), 'map' => null, 'nestingLevel' => $this->nestingLevel, 'token' => $this->lexer->lookahead - ); + ]; $this->queryComponents[$aliasIdentificationVariable] = $joinQueryComponent; @@ -1800,7 +1800,7 @@ public function PartialObjectExpression() { $this->match(Lexer::T_PARTIAL); - $partialFieldSet = array(); + $partialFieldSet = []; $identificationVariable = $this->IdentificationVariable(); @@ -1822,15 +1822,15 @@ public function PartialObjectExpression() while ($this->lexer->isNextToken(Lexer::T_COMMA)) { $this->match(Lexer::T_COMMA); $this->match(Lexer::T_IDENTIFIER); - + $field = $this->lexer->token['value']; - + while ($this->lexer->isNextToken(Lexer::T_DOT)) { $this->match(Lexer::T_DOT); $this->match(Lexer::T_IDENTIFIER); $field .= '.'.$this->lexer->token['value']; } - + $partialFieldSet[] = $field; } @@ -1839,11 +1839,11 @@ public function PartialObjectExpression() $partialObjectExpression = new AST\PartialObjectExpression($identificationVariable, $partialFieldSet); // Defer PartialObjectExpression validation - $this->deferredPartialObjectExpressions[] = array( + $this->deferredPartialObjectExpressions[] = [ 'expression' => $partialObjectExpression, 'nestingLevel' => $this->nestingLevel, 'token' => $this->lexer->token, - ); + ]; return $partialObjectExpression; } @@ -1875,11 +1875,11 @@ public function NewObjectExpression() $expression = new AST\NewObjectExpression($className, $args); // Defer NewObjectExpression validation - $this->deferredNewObjectExpressions[] = array( + $this->deferredNewObjectExpressions[] = [ 'token' => $token, 'expression' => $expression, 'nestingLevel' => $this->nestingLevel, - ); + ]; return $expression; } @@ -2058,7 +2058,7 @@ public function CoalesceExpression() $this->match(Lexer::T_OPEN_PARENTHESIS); // Process ScalarExpressions (1..N) - $scalarExpressions = array(); + $scalarExpressions = []; $scalarExpressions[] = $this->ScalarExpression(); while ($this->lexer->isNextToken(Lexer::T_COMMA)) { @@ -2101,7 +2101,7 @@ public function GeneralCaseExpression() $this->match(Lexer::T_CASE); // Process WhenClause (1..N) - $whenClauses = array(); + $whenClauses = []; do { $whenClauses[] = $this->WhenClause(); @@ -2126,7 +2126,7 @@ public function SimpleCaseExpression() $caseOperand = $this->StateFieldPathExpression(); // Process SimpleWhenClause (1..N) - $simpleWhenClauses = array(); + $simpleWhenClauses = []; do { $simpleWhenClauses[] = $this->SimpleWhenClause(); @@ -2283,11 +2283,11 @@ public function SelectExpression() $aliasResultVariable = $this->AliasResultVariable(); // Include AliasResultVariable in query components. - $this->queryComponents[$aliasResultVariable] = array( + $this->queryComponents[$aliasResultVariable] = [ 'resultVariable' => $expression, 'nestingLevel' => $this->nestingLevel, 'token' => $token, - ); + ]; } // AST @@ -2377,11 +2377,11 @@ public function SimpleSelectExpression() $expr->fieldIdentificationVariable = $resultVariable; // Include AliasResultVariable in query components. - $this->queryComponents[$resultVariable] = array( + $this->queryComponents[$resultVariable] = [ 'resultvariable' => $expr, 'nestingLevel' => $this->nestingLevel, 'token' => $token, - ); + ]; } return $expr; @@ -2394,7 +2394,7 @@ public function SimpleSelectExpression() */ public function ConditionalExpression() { - $conditionalTerms = array(); + $conditionalTerms = []; $conditionalTerms[] = $this->ConditionalTerm(); while ($this->lexer->isNextToken(Lexer::T_OR)) { @@ -2419,7 +2419,7 @@ public function ConditionalExpression() */ public function ConditionalTerm() { - $conditionalFactors = array(); + $conditionalFactors = []; $conditionalFactors[] = $this->ConditionalFactor(); while ($this->lexer->isNextToken(Lexer::T_AND)) { @@ -2484,8 +2484,8 @@ public function ConditionalPrimary() // Peek beyond the matching closing parenthesis ')' $peek = $this->peekBeyondClosingParenthesis(); - if (in_array($peek['value'], array("=", "<", "<=", "<>", ">", ">=", "!=")) || - in_array($peek['type'], array(Lexer::T_NOT, Lexer::T_BETWEEN, Lexer::T_LIKE, Lexer::T_IN, Lexer::T_IS, Lexer::T_EXISTS)) || + if (in_array($peek['value'], ["=", "<", "<=", "<>", ">", ">=", "!="]) || + in_array($peek['type'], [Lexer::T_NOT, Lexer::T_BETWEEN, Lexer::T_LIKE, Lexer::T_IN, Lexer::T_IS, Lexer::T_EXISTS]) || $this->isMathOperator($peek)) { $condPrimary->simpleConditionalExpression = $this->SimpleConditionalExpression(); @@ -2741,7 +2741,7 @@ public function ArithmeticExpression() */ public function SimpleArithmeticExpression() { - $terms = array(); + $terms = []; $terms[] = $this->ArithmeticTerm(); while (($isPlus = $this->lexer->isNextToken(Lexer::T_PLUS)) || $this->lexer->isNextToken(Lexer::T_MINUS)) { @@ -2767,7 +2767,7 @@ public function SimpleArithmeticExpression() */ public function ArithmeticTerm() { - $factors = array(); + $factors = []; $factors[] = $this->ArithmeticFactor(); while (($isMult = $this->lexer->isNextToken(Lexer::T_MULTIPLY)) || $this->lexer->isNextToken(Lexer::T_DIVIDE)) { @@ -2988,7 +2988,7 @@ public function AggregateExpression() $lookaheadType = $this->lexer->lookahead['type']; $isDistinct = false; - if ( ! in_array($lookaheadType, array(Lexer::T_COUNT, Lexer::T_AVG, Lexer::T_MAX, Lexer::T_MIN, Lexer::T_SUM))) { + if ( ! in_array($lookaheadType, [Lexer::T_COUNT, Lexer::T_AVG, Lexer::T_MAX, Lexer::T_MIN, Lexer::T_SUM])) { $this->syntaxError('One of: MAX, MIN, AVG, SUM, COUNT'); } @@ -3018,7 +3018,7 @@ public function QuantifiedExpression() $lookaheadType = $this->lexer->lookahead['type']; $value = $this->lexer->lookahead['value']; - if ( ! in_array($lookaheadType, array(Lexer::T_ALL, Lexer::T_ANY, Lexer::T_SOME))) { + if ( ! in_array($lookaheadType, [Lexer::T_ALL, Lexer::T_ANY, Lexer::T_SOME])) { $this->syntaxError('ALL, ANY or SOME'); } @@ -3097,7 +3097,7 @@ public function InExpression() if ($this->lexer->isNextToken(Lexer::T_SELECT)) { $inExpression->subselect = $this->Subselect(); } else { - $literals = array(); + $literals = []; $literals[] = $this->InParameter(); while ($this->lexer->isNextToken(Lexer::T_COMMA)) { @@ -3130,7 +3130,7 @@ public function InstanceOfExpression() $this->match(Lexer::T_INSTANCE); $this->match(Lexer::T_OF); - $exprValues = array(); + $exprValues = []; if ($this->lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) { $this->match(Lexer::T_OPEN_PARENTHESIS); diff --git a/lib/Doctrine/ORM/Query/ParserResult.php b/lib/Doctrine/ORM/Query/ParserResult.php index dfc7361f8ba..84ad17822bc 100644 --- a/lib/Doctrine/ORM/Query/ParserResult.php +++ b/lib/Doctrine/ORM/Query/ParserResult.php @@ -51,7 +51,7 @@ class ParserResult * * @var array */ - private $_parameterMappings = array(); + private $_parameterMappings = []; /** * Initializes a new instance of the ParserResult class. diff --git a/lib/Doctrine/ORM/Query/QueryExpressionVisitor.php b/lib/Doctrine/ORM/Query/QueryExpressionVisitor.php index 73a1b4dd140..dbdaeb40cb3 100644 --- a/lib/Doctrine/ORM/Query/QueryExpressionVisitor.php +++ b/lib/Doctrine/ORM/Query/QueryExpressionVisitor.php @@ -37,12 +37,12 @@ class QueryExpressionVisitor extends ExpressionVisitor /** * @var array */ - private static $operatorMap = array( + private static $operatorMap = [ Comparison::GT => Expr\Comparison::GT, Comparison::GTE => Expr\Comparison::GTE, Comparison::LT => Expr\Comparison::LT, Comparison::LTE => Expr\Comparison::LTE - ); + ]; /** * @var array @@ -57,7 +57,7 @@ class QueryExpressionVisitor extends ExpressionVisitor /** * @var array */ - private $parameters = array(); + private $parameters = []; /** * Constructor @@ -88,7 +88,7 @@ public function getParameters() */ public function clearParameters() { - $this->parameters = array(); + $this->parameters = []; } /** @@ -108,7 +108,7 @@ private static function convertComparisonOperator($criteriaOperator) */ public function walkCompositeExpression(CompositeExpression $expr) { - $expressionList = array(); + $expressionList = []; foreach ($expr->getExpressionList() as $child) { $expressionList[] = $this->dispatch($child); @@ -160,11 +160,11 @@ public function walkComparison(Comparison $comparison) switch ($comparison->getOperator()) { case Comparison::IN: $this->parameters[] = $parameter; - + return $this->expr->in($field, $placeholder); case Comparison::NIN: $this->parameters[] = $parameter; - + return $this->expr->notIn($field, $placeholder); case Comparison::EQ: case Comparison::IS: @@ -172,19 +172,19 @@ public function walkComparison(Comparison $comparison) return $this->expr->isNull($field); } $this->parameters[] = $parameter; - + return $this->expr->eq($field, $placeholder); case Comparison::NEQ: if ($this->walkValue($comparison->getValue()) === null) { return $this->expr->isNotNull($field); } $this->parameters[] = $parameter; - + return $this->expr->neq($field, $placeholder); case Comparison::CONTAINS: $parameter->setValue('%' . $parameter->getValue() . '%', $parameter->getType()); $this->parameters[] = $parameter; - + return $this->expr->like($field, $placeholder); default: $operator = self::convertComparisonOperator($comparison->getOperator()); diff --git a/lib/Doctrine/ORM/Query/ResultSetMapping.php b/lib/Doctrine/ORM/Query/ResultSetMapping.php index b80acf0cc42..5c4550980e1 100644 --- a/lib/Doctrine/ORM/Query/ResultSetMapping.php +++ b/lib/Doctrine/ORM/Query/ResultSetMapping.php @@ -57,7 +57,7 @@ class ResultSetMapping * @ignore * @var array */ - public $aliasMap = array(); + public $aliasMap = []; /** * Maps alias names to related association field names. @@ -65,7 +65,7 @@ class ResultSetMapping * @ignore * @var array */ - public $relationMap = array(); + public $relationMap = []; /** * Maps alias names to parent alias names. @@ -73,7 +73,7 @@ class ResultSetMapping * @ignore * @var array */ - public $parentAliasMap = array(); + public $parentAliasMap = []; /** * Maps column names in the result set to field names for each class. @@ -81,7 +81,7 @@ class ResultSetMapping * @ignore * @var array */ - public $fieldMappings = array(); + public $fieldMappings = []; /** * Maps column names in the result set to the alias/field name to use in the mapped result. @@ -89,7 +89,7 @@ class ResultSetMapping * @ignore * @var array */ - public $scalarMappings = array(); + public $scalarMappings = []; /** * Maps column names in the result set to the alias/field type to use in the mapped result. @@ -97,7 +97,7 @@ class ResultSetMapping * @ignore * @var array */ - public $typeMappings = array(); + public $typeMappings = []; /** * Maps entities in the result set to the alias name to use in the mapped result. @@ -105,7 +105,7 @@ class ResultSetMapping * @ignore * @var array */ - public $entityMappings = array(); + public $entityMappings = []; /** * Maps column names of meta columns (foreign keys, discriminator columns, ...) to field names. @@ -113,7 +113,7 @@ class ResultSetMapping * @ignore * @var array */ - public $metaMappings = array(); + public $metaMappings = []; /** * Maps column names in the result set to the alias they belong to. @@ -121,7 +121,7 @@ class ResultSetMapping * @ignore * @var array */ - public $columnOwnerMap = array(); + public $columnOwnerMap = []; /** * List of columns in the result set that are used as discriminator columns. @@ -129,7 +129,7 @@ class ResultSetMapping * @ignore * @var array */ - public $discriminatorColumns = array(); + public $discriminatorColumns = []; /** * Maps alias names to field names that should be used for indexing. @@ -137,7 +137,7 @@ class ResultSetMapping * @ignore * @var array */ - public $indexByMap = array(); + public $indexByMap = []; /** * Map from column names to class names that declare the field the column is mapped to. @@ -145,28 +145,28 @@ class ResultSetMapping * @ignore * @var array */ - public $declaringClasses = array(); + public $declaringClasses = []; /** * This is necessary to hydrate derivate foreign keys correctly. * * @var array */ - public $isIdentifierColumn = array(); + public $isIdentifierColumn = []; /** * Maps column names in the result set to field names for each new object expression. * * @var array */ - public $newObjectMappings = array(); + public $newObjectMappings = []; /** * Maps metadata parameter names to the metadata attribute. * * @var array */ - public $metadataParameterMapping = array(); + public $metadataParameterMapping = []; /** * Adds an entity result to this ResultSetMapping. diff --git a/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php b/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php index 73eb5ae5aa6..887d02c6f5a 100644 --- a/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php +++ b/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php @@ -97,7 +97,7 @@ public function __construct(EntityManagerInterface $em, $defaultRenameMode = sel * * @return void */ - public function addRootEntityFromClassMetadata($class, $alias, $renamedColumns = array(), $renameMode = null) + public function addRootEntityFromClassMetadata($class, $alias, $renamedColumns = [], $renameMode = null) { $renameMode = $renameMode ?: $this->defaultRenameMode; $columnAliasMap = $this->getColumnAliasMap($class, $renameMode, $renamedColumns); @@ -119,7 +119,7 @@ public function addRootEntityFromClassMetadata($class, $alias, $renamedColumns = * * @return void */ - public function addJoinedEntityFromClassMetadata($class, $alias, $parentAlias, $relation, $renamedColumns = array(), $renameMode = null) + public function addJoinedEntityFromClassMetadata($class, $alias, $parentAlias, $relation, $renamedColumns = [], $renameMode = null) { $renameMode = $renameMode ?: $this->defaultRenameMode; $columnAliasMap = $this->getColumnAliasMap($class, $renameMode, $renamedColumns); @@ -139,7 +139,7 @@ public function addJoinedEntityFromClassMetadata($class, $alias, $parentAlias, $ * * @throws \InvalidArgumentException */ - protected function addAllClassFields($class, $alias, $columnAliasMap = array()) + protected function addAllClassFields($class, $alias, $columnAliasMap = []) { $classMetadata = $this->em->getClassMetadata($class); $platform = $this->em->getConnection()->getDatabasePlatform(); @@ -232,7 +232,7 @@ private function getColumnAliasMap($className, $mode, array $customRenameColumns $mode = self::COLUMN_RENAMING_CUSTOM; } - $columnAlias = array(); + $columnAlias = []; $class = $this->em->getClassMetadata($className); foreach ($class->getColumnNames() as $columnName) { @@ -436,7 +436,7 @@ public function addNamedNativeQueryEntityResultMapping(ClassMetadataInfo $classM * * @return string */ - public function generateSelectClause($tableAliases = array()) + public function generateSelectClause($tableAliases = []) { $sql = ""; @@ -470,6 +470,6 @@ public function generateSelectClause($tableAliases = array()) */ public function __toString() { - return $this->generateSelectClause(array()); + return $this->generateSelectClause([]); } } diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 6e607ffa9e9..fb6efb9c7cf 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -109,28 +109,28 @@ class SqlWalker implements TreeWalker /** * @var array */ - private $tableAliasMap = array(); + private $tableAliasMap = []; /** * Map from result variable names to their SQL column alias names. * * @var array */ - private $scalarResultAliasMap = array(); + private $scalarResultAliasMap = []; /** * Map from Table-Alias + Column-Name to OrderBy-Direction. * * @var array */ - private $orderedColumnsMap = array(); + private $orderedColumnsMap = []; /** * Map from DQL-Alias + Field-Name to SQL Column Alias. * * @var array */ - private $scalarFields = array(); + private $scalarFields = []; /** * Map of all components/classes that appear in the DQL query. @@ -144,14 +144,14 @@ class SqlWalker implements TreeWalker * * @var array */ - private $selectedClasses = array(); + private $selectedClasses = []; /** * The DQL alias of the root class of the currently traversed query. * * @var array */ - private $rootAliases = array(); + private $rootAliases = []; /** * Flag that indicates whether to generate SQL table aliases in the SQL. @@ -245,7 +245,7 @@ public function getQueryComponents() */ public function setQueryComponent($dqlAlias, array $queryComponent) { - $requiredKeys = array('metadata', 'parent', 'relation', 'map', 'nestingLevel', 'token'); + $requiredKeys = ['metadata', 'parent', 'relation', 'map', 'nestingLevel', 'token']; if (array_diff($requiredKeys, array_keys($queryComponent))) { throw QueryException::invalidQueryComponent($dqlAlias); @@ -354,7 +354,7 @@ private function _generateClassTableInheritanceJoins($class, $dqlAlias) $sql .= isset($this->queryComponents[$dqlAlias]['relation']) ? ' LEFT ' : ' INNER '; $sql .= 'JOIN ' . $this->quoteStrategy->getTableName($parentClass, $this->platform) . ' ' . $tableAlias . ' ON '; - $sqlParts = array(); + $sqlParts = []; foreach ($this->quoteStrategy->getIdentifierColumnNames($class, $this->platform) as $columnName) { $sqlParts[] = $baseTableAlias . '.' . $columnName . ' = ' . $tableAlias . '.' . $columnName; @@ -380,7 +380,7 @@ private function _generateClassTableInheritanceJoins($class, $dqlAlias) $sql .= ' LEFT JOIN ' . $this->quoteStrategy->getTableName($subClass, $this->platform) . ' ' . $tableAlias . ' ON '; - $sqlParts = array(); + $sqlParts = []; foreach ($this->quoteStrategy->getIdentifierColumnNames($subClass, $this->platform) as $columnName) { $sqlParts[] = $baseTableAlias . '.' . $columnName . ' = ' . $tableAlias . '.' . $columnName; @@ -397,7 +397,7 @@ private function _generateClassTableInheritanceJoins($class, $dqlAlias) */ private function _generateOrderedCollectionOrderByItems() { - $orderedColumns = array(); + $orderedColumns = []; foreach ($this->selectedClasses as $selectedClass) { $dqlAlias = $selectedClass['dqlAlias']; @@ -439,7 +439,7 @@ private function _generateOrderedCollectionOrderByItems() */ private function _generateDiscriminatorColumnConditionSQL(array $dqlAliases) { - $sqlParts = array(); + $sqlParts = []; foreach ($dqlAliases as $dqlAlias) { $class = $this->queryComponents[$dqlAlias]['metadata']; @@ -447,7 +447,7 @@ private function _generateDiscriminatorColumnConditionSQL(array $dqlAliases) if ( ! $class->isInheritanceTypeSingleTable()) continue; $conn = $this->em->getConnection(); - $values = array(); + $values = []; if ($class->discriminatorValue !== null) { // discriminators can be 0 $values[] = $conn->quote($class->discriminatorValue); @@ -503,7 +503,7 @@ private function generateFilterConditionSQL(ClassMetadata $targetEntity, $target return ''; } - $filterClauses = array(); + $filterClauses = []; foreach ($this->em->getFilters()->getEnabledFilters() as $filter) { if ('' !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { $filterClauses[] = '(' . $filterExpr . ')'; @@ -606,7 +606,7 @@ public function walkEntityIdentificationVariable($identVariable) { $class = $this->queryComponents[$identVariable]['metadata']; $tableAlias = $this->getSQLTableAlias($class->getTableName(), $identVariable); - $sqlParts = array(); + $sqlParts = []; foreach ($this->quoteStrategy->getIdentifierColumnNames($class, $this->platform) as $columnName) { $sqlParts[] = $tableAlias . '.' . $columnName; @@ -699,7 +699,7 @@ public function walkPathExpression($pathExpr) public function walkSelectClause($selectClause) { $sql = 'SELECT ' . (($selectClause->isDistinct) ? 'DISTINCT ' : ''); - $sqlSelectExpressions = array_filter(array_map(array($this, 'walkSelectExpression'), $selectClause->selectExpressions)); + $sqlSelectExpressions = array_filter(array_map([$this, 'walkSelectExpression'], $selectClause->selectExpressions)); if ($this->query->getHint(Query::HINT_INTERNAL_ITERATION) == true && $selectClause->isDistinct) { $this->query->setHint(self::HINT_DISTINCT, true); @@ -812,7 +812,7 @@ public function walkSelectClause($selectClause) public function walkFromClause($fromClause) { $identificationVarDecls = $fromClause->identificationVariableDeclarations; - $sqlParts = array(); + $sqlParts = []; foreach ($identificationVarDecls as $identificationVariableDecl) { $sqlParts[] = $this->walkIdentificationVariableDeclaration($identificationVariableDecl); @@ -937,7 +937,7 @@ public function walkJoinAssociationDeclaration($joinAssociationDeclaration, $joi // The owning side is necessary at this point because only it contains the JoinColumn information. switch (true) { case ($assoc['type'] & ClassMetadata::TO_ONE): - $conditions = array(); + $conditions = []; foreach ($assoc['joinColumns'] as $joinColumn) { $quotedSourceColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $targetClass, $this->platform); @@ -953,7 +953,7 @@ public function walkJoinAssociationDeclaration($joinAssociationDeclaration, $joi } // Apply remaining inheritance restrictions - $discrSql = $this->_generateDiscriminatorColumnConditionSQL(array($joinedDqlAlias)); + $discrSql = $this->_generateDiscriminatorColumnConditionSQL([$joinedDqlAlias]); if ($discrSql) { $conditions[] = $discrSql; @@ -966,10 +966,10 @@ public function walkJoinAssociationDeclaration($joinAssociationDeclaration, $joi $conditions[] = $filterExpr; } - $targetTableJoin = array( + $targetTableJoin = [ 'table' => $targetTableName . ' ' . $targetTableAlias, 'condition' => implode(' AND ', $conditions), - ); + ]; break; case ($assoc['type'] == ClassMetadata::MANY_TO_MANY): @@ -978,7 +978,7 @@ public function walkJoinAssociationDeclaration($joinAssociationDeclaration, $joi $joinTableAlias = $this->getSQLTableAlias($joinTable['name'], $joinedDqlAlias); $joinTableName = $this->quoteStrategy->getJoinTableName($assoc, $sourceClass, $this->platform); - $conditions = array(); + $conditions = []; $relationColumns = ($relation['isOwningSide']) ? $assoc['joinTable']['joinColumns'] : $assoc['joinTable']['inverseJoinColumns']; @@ -995,7 +995,7 @@ public function walkJoinAssociationDeclaration($joinAssociationDeclaration, $joi // Join target table $sql .= ($joinType == AST\Join::JOIN_TYPE_LEFT || $joinType == AST\Join::JOIN_TYPE_LEFTOUTER) ? ' LEFT JOIN ' : ' INNER JOIN '; - $conditions = array(); + $conditions = []; $relationColumns = ($relation['isOwningSide']) ? $assoc['joinTable']['inverseJoinColumns'] : $assoc['joinTable']['joinColumns']; @@ -1008,7 +1008,7 @@ public function walkJoinAssociationDeclaration($joinAssociationDeclaration, $joi } // Apply remaining inheritance restrictions - $discrSql = $this->_generateDiscriminatorColumnConditionSQL(array($joinedDqlAlias)); + $discrSql = $this->_generateDiscriminatorColumnConditionSQL([$joinedDqlAlias]); if ($discrSql) { $conditions[] = $discrSql; @@ -1021,10 +1021,10 @@ public function walkJoinAssociationDeclaration($joinAssociationDeclaration, $joi $conditions[] = $filterExpr; } - $targetTableJoin = array( + $targetTableJoin = [ 'table' => $targetTableName . ' ' . $targetTableAlias, 'condition' => implode(' AND ', $conditions), - ); + ]; break; default: @@ -1074,7 +1074,7 @@ public function walkFunction($function) */ public function walkOrderByClause($orderByClause) { - $orderByItems = array_map(array($this, 'walkOrderByItem'), $orderByClause->orderByItems); + $orderByItems = array_map([$this, 'walkOrderByItem'], $orderByClause->orderByItems); if (($collectionOrderByItems = $this->_generateOrderedCollectionOrderByItems()) !== '') { $orderByItems = array_merge($orderByItems, (array) $collectionOrderByItems); @@ -1141,7 +1141,7 @@ public function walkJoin($join) $sql .= $this->walkRangeVariableDeclaration($joinDeclaration); // Apply remaining inheritance restrictions - $discrSql = $this->_generateDiscriminatorColumnConditionSQL(array($dqlAlias)); + $discrSql = $this->_generateDiscriminatorColumnConditionSQL([$dqlAlias]); if ($discrSql) { $conditions[] = $discrSql; @@ -1206,7 +1206,7 @@ public function walkCoalesceExpression($coalesceExpression) { $sql = 'COALESCE('; - $scalarExpressions = array(); + $scalarExpressions = []; foreach ($coalesceExpression->scalarExpressions as $scalarExpression) { $scalarExpressions[] = $this->walkSimpleArithmeticExpression($scalarExpression); @@ -1375,7 +1375,7 @@ public function walkSelectExpression($selectExpression) $partialFieldSet = $expr->partialFieldSet; } else { $dqlAlias = $expr; - $partialFieldSet = array(); + $partialFieldSet = []; } $queryComp = $this->queryComponents[$dqlAlias]; @@ -1383,14 +1383,14 @@ public function walkSelectExpression($selectExpression) $resultAlias = $selectExpression->fieldIdentificationVariable ?: null; if ( ! isset($this->selectedClasses[$dqlAlias])) { - $this->selectedClasses[$dqlAlias] = array( + $this->selectedClasses[$dqlAlias] = [ 'class' => $class, 'dqlAlias' => $dqlAlias, 'resultAlias' => $resultAlias - ); + ]; } - $sqlParts = array(); + $sqlParts = []; // Select all fields from the queried class foreach ($class->fieldMappings as $fieldName => $mapping) { @@ -1475,7 +1475,7 @@ public function walkSubselect($subselect) $useAliasesBefore = $this->useSqlTableAliases; $rootAliasesBefore = $this->rootAliases; - $this->rootAliases = array(); // reset the rootAliases for the subselect + $this->rootAliases = []; // reset the rootAliases for the subselect $this->useSqlTableAliases = true; $sql = $this->walkSimpleSelectClause($subselect->simpleSelectClause); @@ -1498,7 +1498,7 @@ public function walkSubselect($subselect) public function walkSubselectFromClause($subselectFromClause) { $identificationVarDecls = $subselectFromClause->identificationVariableDeclarations; - $sqlParts = array (); + $sqlParts = []; foreach ($identificationVarDecls as $subselectIdVarDecl) { $sqlParts[] = $this->walkIdentificationVariableDeclaration($subselectIdVarDecl); @@ -1533,7 +1533,7 @@ public function walkParenthesisExpression(AST\ParenthesisExpression $parenthesis */ public function walkNewObject($newObjectExpression, $newObjectResultAlias=null) { - $sqlSelectExpressions = array(); + $sqlSelectExpressions = []; $objIndex = $newObjectResultAlias?:$this->newObjectCounter++; foreach ($newObjectExpression->args as $argIndex => $e) { @@ -1581,11 +1581,11 @@ public function walkNewObject($newObjectExpression, $newObjectResultAlias=null) $this->scalarResultAliasMap[$resultAlias] = $columnAlias; $this->rsm->addScalarResult($columnAlias, $resultAlias, $fieldType); - $this->rsm->newObjectMappings[$columnAlias] = array( + $this->rsm->newObjectMappings[$columnAlias] = [ 'className' => $newObjectExpression->className, 'objIndex' => $objIndex, 'argIndex' => $argIndex - ); + ]; } return implode(', ', $sqlSelectExpressions); @@ -1662,7 +1662,7 @@ public function walkAggregateExpression($aggExpression) */ public function walkGroupByClause($groupByClause) { - $sqlParts = array(); + $sqlParts = []; foreach ($groupByClause->groupByItems as $groupByItem) { $sqlParts[] = $this->walkGroupByItem($groupByItem); @@ -1697,7 +1697,7 @@ public function walkGroupByItem($groupByItem) } // IdentificationVariable - $sqlParts = array(); + $sqlParts = []; foreach ($this->queryComponents[$groupByItem]['metadata']->fieldNames as $field) { $item = new AST\PathExpression(AST\PathExpression::TYPE_STATE_FIELD, $groupByItem, $field); @@ -1745,7 +1745,7 @@ public function walkUpdateClause($updateClause) $this->setSQLTableAlias($tableName, $tableName, $updateClause->aliasIdentificationVariable); $this->rootAliases[] = $updateClause->aliasIdentificationVariable; - $sql .= ' SET ' . implode(', ', array_map(array($this, 'walkUpdateItem'), $updateClause->updateItems)); + $sql .= ' SET ' . implode(', ', array_map([$this, 'walkUpdateItem'], $updateClause->updateItems)); return $sql; } @@ -1789,7 +1789,7 @@ public function walkWhereClause($whereClause) $discrSql = $this->_generateDiscriminatorColumnConditionSql($this->rootAliases); if ($this->em->hasFilters()) { - $filterClauses = array(); + $filterClauses = []; foreach ($this->rootAliases as $dqlAlias) { $class = $this->queryComponents[$dqlAlias]['metadata']; $tableAlias = $this->getSQLTableAlias($class->table['name'], $dqlAlias); @@ -1830,7 +1830,7 @@ public function walkConditionalExpression($condExpr) return $this->walkConditionalTerm($condExpr); } - return implode(' OR ', array_map(array($this, 'walkConditionalTerm'), $condExpr->conditionalTerms)); + return implode(' OR ', array_map([$this, 'walkConditionalTerm'], $condExpr->conditionalTerms)); } /** @@ -1844,7 +1844,7 @@ public function walkConditionalTerm($condTerm) return $this->walkConditionalFactor($condTerm); } - return implode(' AND ', array_map(array($this, 'walkConditionalFactor'), $condTerm->conditionalFactors)); + return implode(' AND ', array_map([$this, 'walkConditionalFactor'], $condTerm->conditionalFactors)); } /** @@ -1929,7 +1929,7 @@ public function walkCollectionMemberExpression($collMemberExpr) $sql .= $this->quoteStrategy->getTableName($targetClass, $this->platform) . ' ' . $targetTableAlias . ' WHERE '; $owningAssoc = $targetClass->associationMappings[$assoc['mappedBy']]; - $sqlParts = array(); + $sqlParts = []; foreach ($owningAssoc['targetToSourceKeyColumns'] as $targetColumn => $sourceColumn) { $targetColumn = $this->quoteStrategy->getColumnName($class->fieldNames[$targetColumn], $class, $this->platform); @@ -1963,7 +1963,7 @@ public function walkCollectionMemberExpression($collMemberExpr) // join conditions $joinColumns = $assoc['isOwningSide'] ? $joinTable['inverseJoinColumns'] : $joinTable['joinColumns']; - $joinSqlParts = array(); + $joinSqlParts = []; foreach ($joinColumns as $joinColumn) { $targetColumn = $this->quoteStrategy->getColumnName($targetClass->fieldNames[$joinColumn['referencedColumnName']], $targetClass, $this->platform); @@ -1975,7 +1975,7 @@ public function walkCollectionMemberExpression($collMemberExpr) $sql .= ' WHERE '; $joinColumns = $assoc['isOwningSide'] ? $joinTable['joinColumns'] : $joinTable['inverseJoinColumns']; - $sqlParts = array(); + $sqlParts = []; foreach ($joinColumns as $joinColumn) { $targetColumn = $this->quoteStrategy->getColumnName($class->fieldNames[$joinColumn['referencedColumnName']], $class, $this->platform); @@ -2038,7 +2038,7 @@ public function walkInExpression($inExpr) $sql .= ($inExpr->subselect) ? $this->walkSubselect($inExpr->subselect) - : implode(', ', array_map(array($this, 'walkInParameter'), $inExpr->literals)); + : implode(', ', array_map([$this, 'walkInParameter'], $inExpr->literals)); $sql .= ')'; @@ -2065,7 +2065,7 @@ public function walkInstanceOfExpression($instanceOfExpr) $sql .= $class->discriminatorColumn['name'] . ($instanceOfExpr->not ? ' NOT IN ' : ' IN '); - $sqlParameterList = array(); + $sqlParameterList = []; foreach ($instanceOfExpr->value as $parameter) { if ($parameter instanceof AST\InputParameter) { @@ -2239,7 +2239,7 @@ public function walkSimpleArithmeticExpression($simpleArithmeticExpr) return $this->walkArithmeticTerm($simpleArithmeticExpr); } - return implode(' ', array_map(array($this, 'walkArithmeticTerm'), $simpleArithmeticExpr->arithmeticTerms)); + return implode(' ', array_map([$this, 'walkArithmeticTerm'], $simpleArithmeticExpr->arithmeticTerms)); } /** @@ -2259,7 +2259,7 @@ public function walkArithmeticTerm($term) return $this->walkArithmeticFactor($term); } - return implode(' ', array_map(array($this, 'walkArithmeticFactor'), $term->arithmeticFactors)); + return implode(' ', array_map([$this, 'walkArithmeticFactor'], $term->arithmeticFactors)); } /** diff --git a/lib/Doctrine/ORM/Query/TreeWalkerAdapter.php b/lib/Doctrine/ORM/Query/TreeWalkerAdapter.php index 529d855aa02..deee03ab53d 100644 --- a/lib/Doctrine/ORM/Query/TreeWalkerAdapter.php +++ b/lib/Doctrine/ORM/Query/TreeWalkerAdapter.php @@ -72,7 +72,7 @@ public function getQueryComponents() */ public function setQueryComponent($dqlAlias, array $queryComponent) { - $requiredKeys = array('metadata', 'parent', 'relation', 'map', 'nestingLevel', 'token'); + $requiredKeys = ['metadata', 'parent', 'relation', 'map', 'nestingLevel', 'token']; if (array_diff($requiredKeys, array_keys($queryComponent))) { throw QueryException::invalidQueryComponent($dqlAlias); diff --git a/lib/Doctrine/ORM/Query/TreeWalkerChain.php b/lib/Doctrine/ORM/Query/TreeWalkerChain.php index 573ef88ffce..074aa938709 100644 --- a/lib/Doctrine/ORM/Query/TreeWalkerChain.php +++ b/lib/Doctrine/ORM/Query/TreeWalkerChain.php @@ -72,7 +72,7 @@ public function getQueryComponents() */ public function setQueryComponent($dqlAlias, array $queryComponent) { - $requiredKeys = array('metadata', 'parent', 'relation', 'map', 'nestingLevel', 'token'); + $requiredKeys = ['metadata', 'parent', 'relation', 'map', 'nestingLevel', 'token']; if (array_diff($requiredKeys, array_keys($queryComponent))) { throw QueryException::invalidQueryComponent($dqlAlias); diff --git a/lib/Doctrine/ORM/Query/TreeWalkerChainIterator.php b/lib/Doctrine/ORM/Query/TreeWalkerChainIterator.php index 30db0817505..e72e1d4dc4a 100644 --- a/lib/Doctrine/ORM/Query/TreeWalkerChainIterator.php +++ b/lib/Doctrine/ORM/Query/TreeWalkerChainIterator.php @@ -27,7 +27,7 @@ class TreeWalkerChainIterator implements \Iterator, \ArrayAccess /** * @var TreeWalker[] */ - private $walkers = array(); + private $walkers = []; /** * @var TreeWalkerChain */ diff --git a/lib/Doctrine/ORM/QueryBuilder.php b/lib/Doctrine/ORM/QueryBuilder.php index 455e39ab38c..70b55f17d5c 100644 --- a/lib/Doctrine/ORM/QueryBuilder.php +++ b/lib/Doctrine/ORM/QueryBuilder.php @@ -57,17 +57,17 @@ class QueryBuilder * * @var array */ - private $_dqlParts = array( + private $_dqlParts = [ 'distinct' => false, - 'select' => array(), - 'from' => array(), - 'join' => array(), - 'set' => array(), + 'select' => [], + 'from' => [], + 'join' => [], + 'set' => [], 'where' => null, - 'groupBy' => array(), + 'groupBy' => [], 'having' => null, - 'orderBy' => array() - ); + 'orderBy' => [] + ]; /** * The type of query this is. Can be select, update or delete. @@ -116,7 +116,7 @@ class QueryBuilder * * @var array */ - private $joinRootAliases = array(); + private $joinRootAliases = []; /** * Whether to use second level cache, if available. @@ -444,7 +444,7 @@ public function getRootAlias() */ public function getRootAliases() { - $aliases = array(); + $aliases = []; foreach ($this->_dqlParts['from'] as &$fromClause) { if (is_string($fromClause)) { @@ -496,7 +496,7 @@ public function getAllAliases() */ public function getRootEntities() { - $entities = array(); + $entities = []; foreach ($this->_dqlParts['from'] as &$fromClause) { if (is_string($fromClause)) { @@ -707,7 +707,7 @@ public function add($dqlPartName, $dqlPart, $append = false) // This is introduced for backwards compatibility reasons. // TODO: Remove for 3.0 if ($dqlPartName == 'join') { - $newDqlPart = array(); + $newDqlPart = []; foreach ($dqlPart as $k => $v) { $k = is_numeric($k) ? $this->getRootAlias() : $k; @@ -727,7 +727,7 @@ public function add($dqlPartName, $dqlPart, $append = false) $this->_dqlParts[$dqlPartName][] = $dqlPart; } } else { - $this->_dqlParts[$dqlPartName] = ($isMultiple) ? array($dqlPart) : $dqlPart; + $this->_dqlParts[$dqlPartName] = ($isMultiple) ? [$dqlPart] : $dqlPart; } $this->_state = self::STATE_DIRTY; @@ -990,7 +990,7 @@ public function innerJoin($join, $alias, $conditionType = null, $condition = nul Expr\Join::INNER_JOIN, $join, $alias, $conditionType, $condition, $indexBy ); - return $this->add('join', array($rootAlias => $join), true); + return $this->add('join', [$rootAlias => $join], true); } /** @@ -1025,7 +1025,7 @@ public function leftJoin($join, $alias, $conditionType = null, $condition = null Expr\Join::LEFT_JOIN, $join, $alias, $conditionType, $condition, $indexBy ); - return $this->add('join', array($rootAlias => $join), true); + return $this->add('join', [$rootAlias => $join], true); } /** @@ -1374,9 +1374,9 @@ public function getDQLParts() private function _getDQLForDelete() { return 'DELETE' - . $this->_getReducedDQLQueryPart('from', array('pre' => ' ', 'separator' => ', ')) - . $this->_getReducedDQLQueryPart('where', array('pre' => ' WHERE ')) - . $this->_getReducedDQLQueryPart('orderBy', array('pre' => ' ORDER BY ', 'separator' => ', ')); + . $this->_getReducedDQLQueryPart('from', ['pre' => ' ', 'separator' => ', ']) + . $this->_getReducedDQLQueryPart('where', ['pre' => ' WHERE ']) + . $this->_getReducedDQLQueryPart('orderBy', ['pre' => ' ORDER BY ', 'separator' => ', ']); } /** @@ -1385,10 +1385,10 @@ private function _getDQLForDelete() private function _getDQLForUpdate() { return 'UPDATE' - . $this->_getReducedDQLQueryPart('from', array('pre' => ' ', 'separator' => ', ')) - . $this->_getReducedDQLQueryPart('set', array('pre' => ' SET ', 'separator' => ', ')) - . $this->_getReducedDQLQueryPart('where', array('pre' => ' WHERE ')) - . $this->_getReducedDQLQueryPart('orderBy', array('pre' => ' ORDER BY ', 'separator' => ', ')); + . $this->_getReducedDQLQueryPart('from', ['pre' => ' ', 'separator' => ', ']) + . $this->_getReducedDQLQueryPart('set', ['pre' => ' SET ', 'separator' => ', ']) + . $this->_getReducedDQLQueryPart('where', ['pre' => ' WHERE ']) + . $this->_getReducedDQLQueryPart('orderBy', ['pre' => ' ORDER BY ', 'separator' => ', ']); } /** @@ -1398,11 +1398,11 @@ private function _getDQLForSelect() { $dql = 'SELECT' . ($this->_dqlParts['distinct']===true ? ' DISTINCT' : '') - . $this->_getReducedDQLQueryPart('select', array('pre' => ' ', 'separator' => ', ')); + . $this->_getReducedDQLQueryPart('select', ['pre' => ' ', 'separator' => ', ']); $fromParts = $this->getDQLPart('from'); $joinParts = $this->getDQLPart('join'); - $fromClauses = array(); + $fromClauses = []; // Loop through all FROM clauses if ( ! empty($fromParts)) { @@ -1422,10 +1422,10 @@ private function _getDQLForSelect() } $dql .= implode(', ', $fromClauses) - . $this->_getReducedDQLQueryPart('where', array('pre' => ' WHERE ')) - . $this->_getReducedDQLQueryPart('groupBy', array('pre' => ' GROUP BY ', 'separator' => ', ')) - . $this->_getReducedDQLQueryPart('having', array('pre' => ' HAVING ')) - . $this->_getReducedDQLQueryPart('orderBy', array('pre' => ' ORDER BY ', 'separator' => ', ')); + . $this->_getReducedDQLQueryPart('where', ['pre' => ' WHERE ']) + . $this->_getReducedDQLQueryPart('groupBy', ['pre' => ' GROUP BY ', 'separator' => ', ']) + . $this->_getReducedDQLQueryPart('having', ['pre' => ' HAVING ']) + . $this->_getReducedDQLQueryPart('orderBy', ['pre' => ' ORDER BY ', 'separator' => ', ']); return $dql; } @@ -1436,7 +1436,7 @@ private function _getDQLForSelect() * * @return string */ - private function _getReducedDQLQueryPart($queryPartName, $options = array()) + private function _getReducedDQLQueryPart($queryPartName, $options = []) { $queryPart = $this->getDQLPart($queryPartName); @@ -1478,7 +1478,7 @@ public function resetDQLParts($parts = null) */ public function resetDQLPart($part) { - $this->_dqlParts[$part] = is_array($this->_dqlParts[$part]) ? array() : null; + $this->_dqlParts[$part] = is_array($this->_dqlParts[$part]) ? [] : null; $this->_state = self::STATE_DIRTY; return $this; @@ -1514,7 +1514,7 @@ public function __clone() } } - $parameters = array(); + $parameters = []; foreach ($this->parameters as $parameter) { $parameters[] = clone $parameter; diff --git a/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php b/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php index 12163eff615..680962413fc 100644 --- a/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php +++ b/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php @@ -34,7 +34,7 @@ final class DefaultRepositoryFactory implements RepositoryFactory * * @var \Doctrine\Common\Persistence\ObjectRepository[] */ - private $repositoryList = array(); + private $repositoryList = []; /** * {@inheritdoc} diff --git a/lib/Doctrine/ORM/Tools/AttachEntityListenersListener.php b/lib/Doctrine/ORM/Tools/AttachEntityListenersListener.php index bb0ca81b226..cf7cc8b8b95 100644 --- a/lib/Doctrine/ORM/Tools/AttachEntityListenersListener.php +++ b/lib/Doctrine/ORM/Tools/AttachEntityListenersListener.php @@ -33,7 +33,7 @@ class AttachEntityListenersListener /** * @var array[] */ - private $entityListeners = array(); + private $entityListeners = []; /** * Adds a entity listener for a specific entity. @@ -47,11 +47,11 @@ class AttachEntityListenersListener */ public function addEntityListener($entityClass, $listenerClass, $eventName, $listenerCallback = null) { - $this->entityListeners[ltrim($entityClass, '\\')][] = array( + $this->entityListeners[ltrim($entityClass, '\\')][] = [ 'event' => $eventName, 'class' => $listenerClass, 'method' => $listenerCallback ?: $eventName - ); + ]; } /** diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/MetadataCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/MetadataCommand.php index e23d36b24c1..5bc0c859d63 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/MetadataCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/MetadataCommand.php @@ -46,12 +46,14 @@ protected function configure() $this ->setName('orm:clear-cache:metadata') ->setDescription('Clear all metadata cache of the various cache drivers.') - ->setDefinition(array( - new InputOption( - 'flush', null, InputOption::VALUE_NONE, - 'If defined, cache entries will be flushed instead of deleted/invalidated.' - ) - )); + ->setDefinition( + [ + new InputOption( + 'flush', null, InputOption::VALUE_NONE, + 'If defined, cache entries will be flushed instead of deleted/invalidated.' + ) + ] + ); $this->setHelp(<<%command.name% command is meant to clear the metadata cache of associated Entity Manager. diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php index f1be98d30fa..5828d077163 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php @@ -46,12 +46,14 @@ protected function configure() $this ->setName('orm:clear-cache:query') ->setDescription('Clear all query cache of the various cache drivers.') - ->setDefinition(array( - new InputOption( - 'flush', null, InputOption::VALUE_NONE, - 'If defined, cache entries will be flushed instead of deleted/invalidated.' - ) - )); + ->setDefinition( + [ + new InputOption( + 'flush', null, InputOption::VALUE_NONE, + 'If defined, cache entries will be flushed instead of deleted/invalidated.' + ) + ] + ); $this->setHelp(<<%command.name% command is meant to clear the query cache of associated Entity Manager. @@ -91,7 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($cacheDriver instanceof XcacheCache) { throw new \LogicException("Cannot clear XCache Cache from Console, its shared in the Webserver memory and not accessible from the CLI."); } - + $output->write('Clearing ALL Query cache entries' . PHP_EOL); $result = $cacheDriver->deleteAll(); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/ResultCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/ResultCommand.php index c21f5545270..55b89efa8eb 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/ResultCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/ResultCommand.php @@ -46,12 +46,14 @@ protected function configure() $this ->setName('orm:clear-cache:result') ->setDescription('Clear all result cache of the various cache drivers.') - ->setDefinition(array( - new InputOption( - 'flush', null, InputOption::VALUE_NONE, - 'If defined, cache entries will be flushed instead of deleted/invalidated.' - ) - )); + ->setDefinition( + [ + new InputOption( + 'flush', null, InputOption::VALUE_NONE, + 'If defined, cache entries will be flushed instead of deleted/invalidated.' + ) + ] + ); $this->setHelp(<<%command.name% command is meant to clear the result cache of associated Entity Manager. @@ -92,7 +94,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($cacheDriver instanceof XcacheCache) { throw new \LogicException("Cannot clear XCache Cache from Console, its shared in the Webserver memory and not accessible from the CLI."); } - + $output->writeln('Clearing ALL Result cache entries'); $result = $cacheDriver->deleteAll(); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php index 71d72deb84d..ee370dd0f08 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php @@ -102,33 +102,35 @@ protected function configure() { $this ->setName('orm:convert-d1-schema') - ->setAliases(array('orm:convert:d1-schema')) + ->setAliases(['orm:convert:d1-schema']) ->setDescription('Converts Doctrine 1.X schema into a Doctrine 2.X schema.') - ->setDefinition(array( - new InputArgument( - 'from-path', InputArgument::REQUIRED, 'The path of Doctrine 1.X schema information.' - ), - new InputArgument( - 'to-type', InputArgument::REQUIRED, 'The destination Doctrine 2.X mapping type.' - ), - new InputArgument( - 'dest-path', InputArgument::REQUIRED, - 'The path to generate your Doctrine 2.X mapping information.' - ), - new InputOption( - 'from', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, - 'Optional paths of Doctrine 1.X schema information.', - array() - ), - new InputOption( - 'extend', null, InputOption::VALUE_OPTIONAL, - 'Defines a base class to be extended by generated entity classes.' - ), - new InputOption( - 'num-spaces', null, InputOption::VALUE_OPTIONAL, - 'Defines the number of indentation spaces', 4 - ) - )) + ->setDefinition( + [ + new InputArgument( + 'from-path', InputArgument::REQUIRED, 'The path of Doctrine 1.X schema information.' + ), + new InputArgument( + 'to-type', InputArgument::REQUIRED, 'The destination Doctrine 2.X mapping type.' + ), + new InputArgument( + 'dest-path', InputArgument::REQUIRED, + 'The path to generate your Doctrine 2.X mapping information.' + ), + new InputOption( + 'from', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, + 'Optional paths of Doctrine 1.X schema information.', + [] + ), + new InputOption( + 'extend', null, InputOption::VALUE_OPTIONAL, + 'Defines a base class to be extended by generated entity classes.' + ), + new InputOption( + 'num-spaces', null, InputOption::VALUE_OPTIONAL, + 'Defines the number of indentation spaces', 4 + ) + ] + ) ->setHelp(<<getArgument('from-path')), $input->getOption('from')); + $fromPaths = array_merge([$input->getArgument('from-path')], $input->getOption('from')); // Process destination directory $destPath = realpath($input->getArgument('dest-path')); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php index b229f4a6c08..798dbe72858 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php @@ -49,40 +49,42 @@ protected function configure() { $this ->setName('orm:convert-mapping') - ->setAliases(array('orm:convert:mapping')) + ->setAliases(['orm:convert:mapping']) ->setDescription('Convert mapping information between supported formats.') - ->setDefinition(array( - new InputOption( - 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, - 'A string pattern used to match entities that should be processed.' - ), - new InputArgument( - 'to-type', InputArgument::REQUIRED, 'The mapping type to be converted.' - ), - new InputArgument( - 'dest-path', InputArgument::REQUIRED, - 'The path to generate your entities classes.' - ), - new InputOption( - 'force', 'f', InputOption::VALUE_NONE, - 'Force to overwrite existing mapping files.' - ), - new InputOption( - 'from-database', null, null, 'Whether or not to convert mapping information from existing database.' - ), - new InputOption( - 'extend', null, InputOption::VALUE_OPTIONAL, - 'Defines a base class to be extended by generated entity classes.' - ), - new InputOption( - 'num-spaces', null, InputOption::VALUE_OPTIONAL, - 'Defines the number of indentation spaces', 4 - ), - new InputOption( - 'namespace', null, InputOption::VALUE_OPTIONAL, - 'Defines a namespace for the generated entity classes, if converted from database.' - ), - )) + ->setDefinition( + [ + new InputOption( + 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, + 'A string pattern used to match entities that should be processed.' + ), + new InputArgument( + 'to-type', InputArgument::REQUIRED, 'The mapping type to be converted.' + ), + new InputArgument( + 'dest-path', InputArgument::REQUIRED, + 'The path to generate your entities classes.' + ), + new InputOption( + 'force', 'f', InputOption::VALUE_NONE, + 'Force to overwrite existing mapping files.' + ), + new InputOption( + 'from-database', null, null, 'Whether or not to convert mapping information from existing database.' + ), + new InputOption( + 'extend', null, InputOption::VALUE_OPTIONAL, + 'Defines a base class to be extended by generated entity classes.' + ), + new InputOption( + 'num-spaces', null, InputOption::VALUE_OPTIONAL, + 'Defines the number of indentation spaces', 4 + ), + new InputOption( + 'namespace', null, InputOption::VALUE_OPTIONAL, + 'Defines a namespace for the generated entity classes, if converted from database.' + ), + ] + ) ->setHelp(<<setName('orm:ensure-production-settings') ->setDescription('Verify that Doctrine is properly configured for a production environment.') - ->setDefinition(array( - new InputOption( - 'complete', null, InputOption::VALUE_NONE, - 'Flag to also inspect database connection existence.' - ) - )) + ->setDefinition( + [ + new InputOption( + 'complete', null, InputOption::VALUE_NONE, + 'Flag to also inspect database connection existence.' + ) + ] + ) ->setHelp(<<setName('orm:generate-entities') - ->setAliases(array('orm:generate:entities')) + ->setAliases(['orm:generate:entities']) ->setDescription('Generate entity classes and method stubs from your mapping information.') - ->setDefinition(array( - new InputOption( - 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, - 'A string pattern used to match entities that should be processed.' - ), - new InputArgument( - 'dest-path', InputArgument::REQUIRED, 'The path to generate your entity classes.' - ), - new InputOption( - 'generate-annotations', null, InputOption::VALUE_OPTIONAL, - 'Flag to define if generator should generate annotation metadata on entities.', false - ), - new InputOption( - 'generate-methods', null, InputOption::VALUE_OPTIONAL, - 'Flag to define if generator should generate stub methods on entities.', true - ), - new InputOption( - 'regenerate-entities', null, InputOption::VALUE_OPTIONAL, - 'Flag to define if generator should regenerate entity if it exists.', false - ), - new InputOption( - 'update-entities', null, InputOption::VALUE_OPTIONAL, - 'Flag to define if generator should only update entity if it exists.', true - ), - new InputOption( - 'extend', null, InputOption::VALUE_REQUIRED, - 'Defines a base class to be extended by generated entity classes.' - ), - new InputOption( - 'num-spaces', null, InputOption::VALUE_REQUIRED, - 'Defines the number of indentation spaces', 4 - ), - new InputOption( - 'no-backup', null, InputOption::VALUE_NONE, - 'Flag to define if generator should avoid backuping existing entity file if it exists.' - ) - )) + ->setDefinition( + [ + new InputOption( + 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, + 'A string pattern used to match entities that should be processed.' + ), + new InputArgument( + 'dest-path', InputArgument::REQUIRED, 'The path to generate your entity classes.' + ), + new InputOption( + 'generate-annotations', null, InputOption::VALUE_OPTIONAL, + 'Flag to define if generator should generate annotation metadata on entities.', false + ), + new InputOption( + 'generate-methods', null, InputOption::VALUE_OPTIONAL, + 'Flag to define if generator should generate stub methods on entities.', true + ), + new InputOption( + 'regenerate-entities', null, InputOption::VALUE_OPTIONAL, + 'Flag to define if generator should regenerate entity if it exists.', false + ), + new InputOption( + 'update-entities', null, InputOption::VALUE_OPTIONAL, + 'Flag to define if generator should only update entity if it exists.', true + ), + new InputOption( + 'extend', null, InputOption::VALUE_REQUIRED, + 'Defines a base class to be extended by generated entity classes.' + ), + new InputOption( + 'num-spaces', null, InputOption::VALUE_REQUIRED, + 'Defines the number of indentation spaces', 4 + ), + new InputOption( + 'no-backup', null, InputOption::VALUE_NONE, + 'Flag to define if generator should avoid backuping existing entity file if it exists.' + ) + ] + ) ->setHelp(<<setName('orm:generate-proxies') - ->setAliases(array('orm:generate:proxies')) + ->setAliases(['orm:generate:proxies']) ->setDescription('Generates proxy classes for entity classes.') - ->setDefinition(array( - new InputOption( - 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, - 'A string pattern used to match entities that should be processed.' - ), - new InputArgument( - 'dest-path', InputArgument::OPTIONAL, - 'The path to generate your proxy classes. If none is provided, it will attempt to grab from configuration.' - ), - )) + ->setDefinition( + [ + new InputOption( + 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, + 'A string pattern used to match entities that should be processed.' + ), + new InputArgument( + 'dest-path', InputArgument::OPTIONAL, + 'The path to generate your proxy classes. If none is provided, it will attempt to grab from configuration.' + ), + ] + ) ->setHelp(<<setName('orm:generate-repositories') - ->setAliases(array('orm:generate:repositories')) + ->setAliases(['orm:generate:repositories']) ->setDescription('Generate repository classes from your mapping information.') - ->setDefinition(array( - new InputOption( - 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, - 'A string pattern used to match entities that should be processed.' - ), - new InputArgument( - 'dest-path', InputArgument::REQUIRED, 'The path to generate your repository classes.' - ) - )) + ->setDefinition( + [ + new InputOption( + 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, + 'A string pattern used to match entities that should be processed.' + ), + new InputArgument( + 'dest-path', InputArgument::REQUIRED, 'The path to generate your repository classes.' + ) + ] + ) ->setHelp(<<setHeaders(array('Field', 'Value')); + $table->setHeaders(['Field', 'Value']); $metadata = $this->getClassMetadata($entityName, $entityManager); array_map( - array($table, 'addRow'), + [$table, 'addRow'], array_merge( - array( + [ $this->formatField('Name', $metadata->name), $this->formatField('Root entity name', $metadata->rootEntityName), $this->formatField('Custom generator definition', $metadata->customGeneratorDefinition), @@ -118,10 +118,10 @@ private function displayEntity($entityName, EntityManagerInterface $entityManage $this->formatField('Read only?', $metadata->isReadOnly), $this->formatEntityListeners($metadata->entityListeners), - ), - array($this->formatField('Association mappings:', '')), + ], + [$this->formatField('Association mappings:', '')], $this->formatMappings($metadata->associationMappings), - array($this->formatField('Field mappings:', '')), + [$this->formatField('Field mappings:', '')], $this->formatMappings($metadata->fieldMappings) ) ); @@ -251,7 +251,7 @@ private function formatField($label, $value) $value = 'None'; } - return array(sprintf('%s', $label), $this->formatValue($value)); + return [sprintf('%s', $label), $this->formatValue($value)]; } /** @@ -263,7 +263,7 @@ private function formatField($label, $value) */ private function formatMappings(array $propertyMappings) { - $output = array(); + $output = []; foreach ($propertyMappings as $propertyName => $mapping) { $output[] = $this->formatField(sprintf(' %s', $propertyName), ''); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php index abd999aef09..b246850a9c1 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php @@ -46,30 +46,32 @@ protected function configure() $this ->setName('orm:run-dql') ->setDescription('Executes arbitrary DQL directly from the command line.') - ->setDefinition(array( - new InputArgument('dql', InputArgument::REQUIRED, 'The DQL to execute.'), - new InputOption( - 'hydrate', null, InputOption::VALUE_REQUIRED, - 'Hydration mode of result set. Should be either: object, array, scalar or single-scalar.', - 'object' - ), - new InputOption( - 'first-result', null, InputOption::VALUE_REQUIRED, - 'The first result in the result set.' - ), - new InputOption( - 'max-result', null, InputOption::VALUE_REQUIRED, - 'The maximum number of results in the result set.' - ), - new InputOption( - 'depth', null, InputOption::VALUE_REQUIRED, - 'Dumping depth of Entity graph.', 7 - ), - new InputOption( - 'show-sql', null, InputOption::VALUE_NONE, - 'Dump generated SQL instead of executing query' - ) - )) + ->setDefinition( + [ + new InputArgument('dql', InputArgument::REQUIRED, 'The DQL to execute.'), + new InputOption( + 'hydrate', null, InputOption::VALUE_REQUIRED, + 'Hydration mode of result set. Should be either: object, array, scalar or single-scalar.', + 'object' + ), + new InputOption( + 'first-result', null, InputOption::VALUE_REQUIRED, + 'The first result in the result set.' + ), + new InputOption( + 'max-result', null, InputOption::VALUE_REQUIRED, + 'The maximum number of results in the result set.' + ), + new InputOption( + 'depth', null, InputOption::VALUE_REQUIRED, + 'Dumping depth of Entity graph.', 7 + ), + new InputOption( + 'show-sql', null, InputOption::VALUE_NONE, + 'Dump generated SQL instead of executing query' + ) + ] + ) ->setHelp(<<execute(array(), constant($hydrationMode)); + $resultSet = $query->execute([], constant($hydrationMode)); $output->writeln(Debug::dump($resultSet, $input->getOption('depth'), true, false)); } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/CreateCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/CreateCommand.php index b2af0ca2cfd..73fbcbabbc7 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/CreateCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/CreateCommand.php @@ -46,12 +46,14 @@ protected function configure() ->setDescription( 'Processes the schema and either create it directly on EntityManager Storage Connection or generate the SQL output.' ) - ->setDefinition(array( - new InputOption( - 'dump-sql', null, InputOption::VALUE_NONE, - 'Instead of trying to apply generated SQLs into EntityManager Storage Connection, output them.' - ) - )) + ->setDefinition( + [ + new InputOption( + 'dump-sql', null, InputOption::VALUE_NONE, + 'Instead of trying to apply generated SQLs into EntityManager Storage Connection, output them.' + ) + ] + ) ->setHelp(<<setDescription( 'Drop the complete database schema of EntityManager Storage Connection or generate the corresponding SQL output.' ) - ->setDefinition(array( - new InputOption( - 'dump-sql', null, InputOption::VALUE_NONE, - 'Instead of trying to apply generated SQLs into EntityManager Storage Connection, output them.' - ), - new InputOption( - 'force', 'f', InputOption::VALUE_NONE, - "Don't ask for the deletion of the database, but force the operation to run." - ), - new InputOption( - 'full-database', null, InputOption::VALUE_NONE, - 'Instead of using the Class Metadata to detect the database table schema, drop ALL assets that the database contains.' - ), - )) + ->setDefinition( + [ + new InputOption( + 'dump-sql', null, InputOption::VALUE_NONE, + 'Instead of trying to apply generated SQLs into EntityManager Storage Connection, output them.' + ), + new InputOption( + 'force', 'f', InputOption::VALUE_NONE, + "Don't ask for the deletion of the database, but force the operation to run." + ), + new InputOption( + 'full-database', null, InputOption::VALUE_NONE, + 'Instead of using the Class Metadata to detect the database table schema, drop ALL assets that the database contains.' + ), + ] + ) ->setHelp(<<setDescription( 'Executes (or dumps) the SQL needed to update the database schema to match the current mapping metadata.' ) - ->setDefinition(array( - new InputOption( - 'complete', null, InputOption::VALUE_NONE, - 'If defined, all assets of the database which are not relevant to the current metadata will be dropped.' - ), - - new InputOption( - 'dump-sql', null, InputOption::VALUE_NONE, - 'Dumps the generated SQL statements to the screen (does not execute them).' - ), - new InputOption( - 'force', 'f', InputOption::VALUE_NONE, - 'Causes the generated SQL statements to be physically executed against your database.' - ), - )); + ->setDefinition( + [ + new InputOption( + 'complete', null, InputOption::VALUE_NONE, + 'If defined, all assets of the database which are not relevant to the current metadata will be dropped.' + ), + + new InputOption( + 'dump-sql', null, InputOption::VALUE_NONE, + 'Dumps the generated SQL statements to the screen (does not execute them).' + ), + new InputOption( + 'force', 'f', InputOption::VALUE_NONE, + 'Causes the generated SQL statements to be physically executed against your database.' + ), + ] + ); $this->setHelp(<<%command.name% command generates the SQL needed to diff --git a/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php b/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php index 64f2abe693c..706d99d33e6 100644 --- a/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php +++ b/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php @@ -40,10 +40,12 @@ class ConsoleRunner */ public static function createHelperSet(EntityManagerInterface $entityManager) { - return new HelperSet(array( - 'db' => new ConnectionHelper($entityManager->getConnection()), - 'em' => new EntityManagerHelper($entityManager) - )); + return new HelperSet( + [ + 'db' => new ConnectionHelper($entityManager->getConnection()), + 'em' => new EntityManagerHelper($entityManager) + ] + ); } /** @@ -54,7 +56,7 @@ public static function createHelperSet(EntityManagerInterface $entityManager) * * @return void */ - static public function run(HelperSet $helperSet, $commands = array()) + static public function run(HelperSet $helperSet, $commands = []) { $cli = self::createApplication($helperSet, $commands); $cli->run(); @@ -69,7 +71,7 @@ static public function run(HelperSet $helperSet, $commands = array()) * * @return \Symfony\Component\Console\Application */ - static public function createApplication(HelperSet $helperSet, $commands = array()) + static public function createApplication(HelperSet $helperSet, $commands = []) { $cli = new Application('Doctrine Command Line Interface', Version::VERSION); $cli->setCatchExceptions(true); @@ -87,29 +89,31 @@ static public function createApplication(HelperSet $helperSet, $commands = array */ static public function addCommands(Application $cli) { - $cli->addCommands(array( - // DBAL Commands - new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(), - new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(), - - // ORM Commands - new \Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand(), - new \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand(), - new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand(), - new \Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand(), - new \Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand(), - new \Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand(), - new \Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand(), - new \Doctrine\ORM\Tools\Console\Command\ConvertDoctrine1SchemaCommand(), - new \Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand(), - new \Doctrine\ORM\Tools\Console\Command\GenerateEntitiesCommand(), - new \Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand(), - new \Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand(), - new \Doctrine\ORM\Tools\Console\Command\RunDqlCommand(), - new \Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand(), - new \Doctrine\ORM\Tools\Console\Command\InfoCommand(), - new \Doctrine\ORM\Tools\Console\Command\MappingDescribeCommand(), - )); + $cli->addCommands( + [ + // DBAL Commands + new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(), + new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(), + + // ORM Commands + new \Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand(), + new \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand(), + new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand(), + new \Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand(), + new \Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand(), + new \Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand(), + new \Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand(), + new \Doctrine\ORM\Tools\Console\Command\ConvertDoctrine1SchemaCommand(), + new \Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand(), + new \Doctrine\ORM\Tools\Console\Command\GenerateEntitiesCommand(), + new \Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand(), + new \Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand(), + new \Doctrine\ORM\Tools\Console\Command\RunDqlCommand(), + new \Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand(), + new \Doctrine\ORM\Tools\Console\Command\InfoCommand(), + new \Doctrine\ORM\Tools\Console\Command\MappingDescribeCommand(), + ] + ); } static public function printCliConfigTemplate() diff --git a/lib/Doctrine/ORM/Tools/Console/MetadataFilter.php b/lib/Doctrine/ORM/Tools/Console/MetadataFilter.php index 5a72b7d6d00..f480c306302 100644 --- a/lib/Doctrine/ORM/Tools/Console/MetadataFilter.php +++ b/lib/Doctrine/ORM/Tools/Console/MetadataFilter.php @@ -35,7 +35,7 @@ class MetadataFilter extends \FilterIterator implements \Countable /** * @var array */ - private $filter = array(); + private $filter = []; /** * Filter Metadatas by one or more filter options. diff --git a/lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php b/lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php index 52f3c92b972..408cb52d238 100644 --- a/lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php +++ b/lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php @@ -44,12 +44,12 @@ class ConvertDoctrine1Schema /** * @var array */ - private $legacyTypeMap = array( + private $legacyTypeMap = [ // TODO: This list may need to be updated 'clob' => 'text', 'timestamp' => 'datetime', 'enum' => 'string' - ); + ]; /** * Constructor passes the directory or array of directories @@ -72,7 +72,7 @@ public function __construct($from) */ public function getMetadata() { - $schema = array(); + $schema = []; foreach ($this->from as $path) { if (is_dir($path)) { $files = glob($path . '/*.yml'); @@ -84,7 +84,7 @@ public function getMetadata() } } - $metadatas = array(); + $metadatas = []; foreach ($schema as $className => $mappingInformation) { $metadatas[] = $this->convertToClassMetadataInfo($className, $mappingInformation); } @@ -153,12 +153,12 @@ private function convertColumns($className, array $model, ClassMetadataInfo $met } if ( ! $id) { - $fieldMapping = array( + $fieldMapping = [ 'fieldName' => 'id', 'columnName' => 'id', 'type' => 'integer', 'id' => true - ); + ]; $metadata->mapField($fieldMapping); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); } @@ -178,7 +178,7 @@ private function convertColumn($className, $name, $column, ClassMetadataInfo $me { if (is_string($column)) { $string = $column; - $column = array(); + $column = []; $column['type'] = $string; } @@ -208,7 +208,7 @@ private function convertColumn($className, $name, $column, ClassMetadataInfo $me throw ToolsException::couldNotMapDoctrine1Type($column['type']); } - $fieldMapping = array(); + $fieldMapping = []; if (isset($column['primary'])) { $fieldMapping['id'] = true; @@ -222,7 +222,7 @@ private function convertColumn($className, $name, $column, ClassMetadataInfo $me $fieldMapping['length'] = $column['length']; } - $allowed = array('precision', 'scale', 'unique', 'options', 'notnull', 'version'); + $allowed = ['precision', 'scale', 'unique', 'options', 'notnull', 'version']; foreach ($column as $key => $value) { if (in_array($key, $allowed)) { @@ -237,9 +237,9 @@ private function convertColumn($className, $name, $column, ClassMetadataInfo $me } elseif (isset($column['sequence'])) { $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE); - $definition = array( + $definition = [ 'sequenceName' => is_array($column['sequence']) ? $column['sequence']['name']:$column['sequence'] - ); + ]; if (isset($column['sequence']['size'])) { $definition['allocationSize'] = $column['sequence']['size']; @@ -272,9 +272,9 @@ private function convertIndexes($className, array $model, ClassMetadataInfo $met $type = (isset($index['type']) && $index['type'] == 'unique') ? 'uniqueConstraints' : 'indexes'; - $metadata->table[$type][$name] = array( + $metadata->table[$type][$name] = [ 'columns' => $index['fields'] - ); + ]; } } @@ -311,17 +311,17 @@ private function convertRelations($className, array $model, ClassMetadataInfo $m if (isset($relation['refClass'])) { $type = 'many'; $foreignType = 'many'; - $joinColumns = array(); + $joinColumns = []; } else { $type = isset($relation['type']) ? $relation['type'] : 'one'; $foreignType = isset($relation['foreignType']) ? $relation['foreignType'] : 'many'; - $joinColumns = array( - array( + $joinColumns = [ + [ 'name' => $relation['local'], 'referencedColumnName' => $relation['foreign'], 'onDelete' => isset($relation['onDelete']) ? $relation['onDelete'] : null, - ) - ); + ] + ]; } if ($type == 'one' && $foreignType == 'one') { @@ -332,7 +332,7 @@ private function convertRelations($className, array $model, ClassMetadataInfo $m $method = 'mapOneToMany'; } - $associationMapping = array(); + $associationMapping = []; $associationMapping['fieldName'] = $relation['alias']; $associationMapping['targetEntity'] = $relation['class']; $associationMapping['mappedBy'] = $relation['foreignAlias']; diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 22d5b412a82..03e96481742 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -78,7 +78,7 @@ class EntityGenerator /** * @var array */ - protected $staticReflection = array(); + protected $staticReflection = []; /** * Number of spaces to use for indention in generated code. @@ -151,7 +151,7 @@ class EntityGenerator * * @var array */ - protected $typeAlias = array( + protected $typeAlias = [ Type::DATETIMETZ => '\DateTime', Type::DATETIME => '\DateTime', Type::DATE => '\DateTime', @@ -166,14 +166,14 @@ class EntityGenerator Type::JSON_ARRAY => 'array', Type::SIMPLE_ARRAY => 'array', Type::BOOLEAN => 'bool', - ); + ]; /** * Hash-map to handle generator types string. * * @var array */ - protected static $generatorStrategyMap = array( + protected static $generatorStrategyMap = [ ClassMetadataInfo::GENERATOR_TYPE_AUTO => 'AUTO', ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE => 'SEQUENCE', ClassMetadataInfo::GENERATOR_TYPE_TABLE => 'TABLE', @@ -181,30 +181,30 @@ class EntityGenerator ClassMetadataInfo::GENERATOR_TYPE_NONE => 'NONE', ClassMetadataInfo::GENERATOR_TYPE_UUID => 'UUID', ClassMetadataInfo::GENERATOR_TYPE_CUSTOM => 'CUSTOM' - ); + ]; /** * Hash-map to handle the change tracking policy string. * * @var array */ - protected static $changeTrackingPolicyMap = array( + protected static $changeTrackingPolicyMap = [ ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT => 'DEFERRED_IMPLICIT', ClassMetadataInfo::CHANGETRACKING_DEFERRED_EXPLICIT => 'DEFERRED_EXPLICIT', ClassMetadataInfo::CHANGETRACKING_NOTIFY => 'NOTIFY', - ); + ]; /** * Hash-map to handle the inheritance type string. * * @var array */ - protected static $inheritanceTypeMap = array( + protected static $inheritanceTypeMap = [ ClassMetadataInfo::INHERITANCE_TYPE_NONE => 'NONE', ClassMetadataInfo::INHERITANCE_TYPE_JOINED => 'JOINED', ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE => 'SINGLE_TABLE', ClassMetadataInfo::INHERITANCE_TYPE_TABLE_PER_CLASS => 'TABLE_PER_CLASS', - ); + ]; /** * @var string @@ -376,7 +376,7 @@ public function writeEntityClass(ClassMetadataInfo $metadata, $outputDirectory) if ( ! $this->isNew) { $this->parseTokensInEntityFile(file_get_contents($path)); } else { - $this->staticReflection[$metadata->name] = array('properties' => array(), 'methods' => array()); + $this->staticReflection[$metadata->name] = ['properties' => [], 'methods' => []]; } if ($this->backupExisting && file_exists($path)) { @@ -405,21 +405,21 @@ public function writeEntityClass(ClassMetadataInfo $metadata, $outputDirectory) */ public function generateEntityClass(ClassMetadataInfo $metadata) { - $placeHolders = array( + $placeHolders = [ '', '', '', '', '' - ); + ]; - $replacements = array( + $replacements = [ $this->generateEntityNamespace($metadata), $this->generateEntityUse(), $this->generateEntityDocBlock($metadata), $this->generateEntityClassName($metadata), $this->generateEntityBody($metadata) - ); + ]; $code = str_replace($placeHolders, $replacements, static::$classTemplate) . "\n"; @@ -641,7 +641,7 @@ protected function generateEntityBody(ClassMetadataInfo $metadata) $stubMethods = $this->generateEntityStubMethods ? $this->generateEntityStubMethods($metadata) : null; $lifecycleCallbackMethods = $this->generateEntityLifecycleCallbackMethods($metadata); - $code = array(); + $code = []; if ($fieldMappingProperties) { $code[] = $fieldMappingProperties; @@ -683,7 +683,7 @@ protected function generateEntityConstructor(ClassMetadataInfo $metadata) return $this->generateEmbeddableConstructor($metadata); } - $collections = array(); + $collections = []; foreach ($metadata->associationMappings as $mapping) { if ($mapping['type'] & ClassMetadataInfo::TO_MANY) { @@ -705,14 +705,14 @@ protected function generateEntityConstructor(ClassMetadataInfo $metadata) */ private function generateEmbeddableConstructor(ClassMetadataInfo $metadata) { - $paramTypes = array(); - $paramVariables = array(); - $params = array(); - $fields = array(); + $paramTypes = []; + $paramVariables = []; + $params = []; + $fields = []; // Resort fields to put optional fields at the end of the method signature. - $requiredFields = array(); - $optionalFields = array(); + $requiredFields = []; + $optionalFields = []; foreach ($metadata->fieldMappings as $fieldMapping) { if (empty($fieldMapping['nullable'])) { @@ -777,11 +777,11 @@ function ($type, $variable) use ($maxParamTypeLength) { $params = implode(', ', $params); } - $replacements = array( + $replacements = [ '' => implode("\n * ", $paramTags), '' => $params, '' => implode("\n" . $this->spaces, $fields), - ); + ]; $constructor = str_replace( array_keys($replacements), @@ -811,14 +811,14 @@ protected function parseTokensInEntityFile($src) for ($i = 0; $i < $tokensCount; $i++) { $token = $tokens[$i]; - if (in_array($token[0], array(T_WHITESPACE, T_COMMENT, T_DOC_COMMENT), true)) { + if (in_array($token[0], [T_WHITESPACE, T_COMMENT, T_DOC_COMMENT], true)) { continue; } if ($inNamespace) { - if (in_array($token[0], array(T_NS_SEPARATOR, T_STRING), true)) { + if (in_array($token[0], [T_NS_SEPARATOR, T_STRING], true)) { $lastSeenNamespace .= $token[1]; - } elseif (is_string($token) && in_array($token, array(';', '{'), true)) { + } elseif (is_string($token) && in_array($token, [';', '{'], true)) { $inNamespace = false; } } @@ -826,8 +826,8 @@ protected function parseTokensInEntityFile($src) if ($inClass) { $inClass = false; $lastSeenClass = $lastSeenNamespace . ($lastSeenNamespace ? '\\' : '') . $token[1]; - $this->staticReflection[$lastSeenClass]['properties'] = array(); - $this->staticReflection[$lastSeenClass]['methods'] = array(); + $this->staticReflection[$lastSeenClass]['properties'] = []; + $this->staticReflection[$lastSeenClass]['methods'] = []; } if (T_NAMESPACE === $token[0]) { @@ -841,7 +841,7 @@ protected function parseTokensInEntityFile($src) } elseif ($tokens[$i+2] == '&' && T_STRING === $tokens[$i+3][0]) { $this->staticReflection[$lastSeenClass]['methods'][] = strtolower($tokens[$i+3][1]); } - } elseif (in_array($token[0], array(T_VAR, T_PUBLIC, T_PRIVATE, T_PROTECTED), true) && T_FUNCTION !== $tokens[$i+2][0]) { + } elseif (in_array($token[0], [T_VAR, T_PUBLIC, T_PRIVATE, T_PROTECTED], true) && T_FUNCTION !== $tokens[$i+2][0]) { $this->staticReflection[$lastSeenClass]['properties'][] = substr($tokens[$i+2][1], 1); } } @@ -921,7 +921,7 @@ protected function getTraits(ClassMetadataInfo $metadata) ? new \ReflectionClass($metadata->name) : $metadata->reflClass; - $traits = array(); + $traits = []; while ($reflClass !== false) { $traits = array_merge($traits, $reflClass->getTraits()); @@ -996,20 +996,20 @@ protected function getNamespace(ClassMetadataInfo $metadata) */ protected function generateEntityDocBlock(ClassMetadataInfo $metadata) { - $lines = array(); + $lines = []; $lines[] = '/**'; $lines[] = ' * ' . $this->getClassName($metadata); if ($this->generateAnnotations) { $lines[] = ' *'; - $methods = array( + $methods = [ 'generateTableAnnotation', 'generateInheritanceAnnotation', 'generateDiscriminatorColumnAnnotation', 'generateDiscriminatorMapAnnotation', 'generateEntityAnnotation', - ); + ]; foreach ($methods as $method) { if ($code = $this->$method($metadata)) { @@ -1058,7 +1058,7 @@ protected function generateTableAnnotation(ClassMetadataInfo $metadata) return ''; } - $table = array(); + $table = []; if (isset($metadata->table['schema'])) { $table[] = 'schema="' . $metadata->table['schema'] . '"'; @@ -1093,9 +1093,9 @@ protected function generateTableAnnotation(ClassMetadataInfo $metadata) */ protected function generateTableConstraints($constraintName, array $constraints) { - $annotations = array(); + $annotations = []; foreach ($constraints as $name => $constraint) { - $columns = array(); + $columns = []; foreach ($constraint['columns'] as $column) { $columns[] = '"' . $column . '"'; } @@ -1142,7 +1142,7 @@ protected function generateDiscriminatorColumnAnnotation(ClassMetadataInfo $meta protected function generateDiscriminatorMapAnnotation(ClassMetadataInfo $metadata) { if ($metadata->inheritanceType != ClassMetadataInfo::INHERITANCE_TYPE_NONE) { - $inheritanceClassMap = array(); + $inheritanceClassMap = []; foreach ($metadata->discriminatorMap as $type => $class) { $inheritanceClassMap[] .= '"' . $type . '" = "' . $class . '"'; @@ -1159,7 +1159,7 @@ protected function generateDiscriminatorMapAnnotation(ClassMetadataInfo $metadat */ protected function generateEntityStubMethods(ClassMetadataInfo $metadata) { - $methods = array(); + $methods = []; foreach ($metadata->fieldMappings as $fieldMapping) { if (isset($fieldMapping['declaredField']) && @@ -1240,7 +1240,7 @@ protected function isAssociationIsNullable(array $associationMapping) $joinColumns = $associationMapping['joinColumns']; } else { //@todo there is no way to retrieve targetEntity metadata - $joinColumns = array(); + $joinColumns = []; } foreach ($joinColumns as $joinColumn) { @@ -1281,7 +1281,7 @@ protected function generateEntityLifecycleCallbackMethods(ClassMetadataInfo $met */ protected function generateEntityAssociationMappingProperties(ClassMetadataInfo $metadata) { - $lines = array(); + $lines = []; foreach ($metadata->associationMappings as $associationMapping) { if ($this->hasProperty($associationMapping['fieldName'], $metadata)) { @@ -1303,7 +1303,7 @@ protected function generateEntityAssociationMappingProperties(ClassMetadataInfo */ protected function generateEntityFieldMappingProperties(ClassMetadataInfo $metadata) { - $lines = array(); + $lines = []; foreach ($metadata->fieldMappings as $fieldMapping) { if ($this->hasProperty($fieldMapping['fieldName'], $metadata) || @@ -1331,7 +1331,7 @@ protected function generateEntityFieldMappingProperties(ClassMetadataInfo $metad */ protected function generateEntityEmbeddedProperties(ClassMetadataInfo $metadata) { - $lines = array(); + $lines = []; foreach ($metadata->embeddedClasses as $fieldName => $embeddedClass) { if (isset($embeddedClass['declaredField']) || $this->hasProperty($fieldName, $metadata)) { @@ -1358,7 +1358,7 @@ protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, { $methodName = $type . Inflector::classify($fieldName); $variableName = Inflector::camelize($fieldName); - if (in_array($type, array("add", "remove"))) { + if (in_array($type, ["add", "remove"])) { $methodName = Inflector::singularize($methodName); $variableName = Inflector::singularize($variableName); } @@ -1380,7 +1380,7 @@ protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $methodTypeHint = '\\' . $typeHint . ' '; } - $replacements = array( + $replacements = [ '' => ucfirst($type) . ' ' . $variableName . '.', '' => $methodTypeHint, '' => $variableType . (null !== $defaultValue ? ('|' . $defaultValue) : ''), @@ -1389,7 +1389,7 @@ protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, '' => $fieldName, '' => ($defaultValue !== null ) ? (' = ' . $defaultValue) : '', '' => $this->getClassName($metadata) - ); + ]; $method = str_replace( array_keys($replacements), @@ -1414,10 +1414,10 @@ protected function generateLifecycleCallbackMethod($name, $methodName, ClassMeta } $this->staticReflection[$metadata->name]['methods'][] = $methodName; - $replacements = array( + $replacements = [ '' => $this->annotationsPrefix . ucfirst($name), '' => $methodName, - ); + ]; $method = str_replace( array_keys($replacements), @@ -1435,7 +1435,7 @@ protected function generateLifecycleCallbackMethod($name, $methodName, ClassMeta */ protected function generateJoinColumnAnnotation(array $joinColumn) { - $joinColumnAnnot = array(); + $joinColumnAnnot = []; if (isset($joinColumn['name'])) { $joinColumnAnnot[] = 'name="' . $joinColumn['name'] . '"'; @@ -1472,7 +1472,7 @@ protected function generateJoinColumnAnnotation(array $joinColumn) */ protected function generateAssociationMappingPropertyDocBlock(array $associationMapping, ClassMetadataInfo $metadata) { - $lines = array(); + $lines = []; $lines[] = $this->spaces . '/**'; if ($associationMapping['type'] & ClassMetadataInfo::TO_MANY) { @@ -1507,7 +1507,7 @@ protected function generateAssociationMappingPropertyDocBlock(array $association $type = 'ManyToMany'; break; } - $typeOptions = array(); + $typeOptions = []; if (isset($associationMapping['targetEntity'])) { $typeOptions[] = 'targetEntity="' . $associationMapping['targetEntity'] . '"'; @@ -1522,7 +1522,7 @@ protected function generateAssociationMappingPropertyDocBlock(array $association } if ($associationMapping['cascade']) { - $cascades = array(); + $cascades = []; if ($associationMapping['isCascadePersist']) $cascades[] = '"persist"'; if ($associationMapping['isCascadeRemove']) $cascades[] = '"remove"'; @@ -1531,7 +1531,7 @@ protected function generateAssociationMappingPropertyDocBlock(array $association if ($associationMapping['isCascadeRefresh']) $cascades[] = '"refresh"'; if (count($cascades) === 5) { - $cascades = array('"all"'); + $cascades = ['"all"']; } $typeOptions[] = 'cascade={' . implode(',', $cascades) . '}'; @@ -1542,10 +1542,10 @@ protected function generateAssociationMappingPropertyDocBlock(array $association } if (isset($associationMapping['fetch']) && $associationMapping['fetch'] !== ClassMetadataInfo::FETCH_LAZY) { - $fetchMap = array( + $fetchMap = [ ClassMetadataInfo::FETCH_EXTRA_LAZY => 'EXTRA_LAZY', ClassMetadataInfo::FETCH_EAGER => 'EAGER', - ); + ]; $typeOptions[] = 'fetch="' . $fetchMap[$associationMapping['fetch']] . '"'; } @@ -1555,7 +1555,7 @@ protected function generateAssociationMappingPropertyDocBlock(array $association if (isset($associationMapping['joinColumns']) && $associationMapping['joinColumns']) { $lines[] = $this->spaces . ' * @' . $this->annotationsPrefix . 'JoinColumns({'; - $joinColumnsLines = array(); + $joinColumnsLines = []; foreach ($associationMapping['joinColumns'] as $joinColumn) { if ($joinColumnAnnot = $this->generateJoinColumnAnnotation($joinColumn)) { @@ -1568,7 +1568,7 @@ protected function generateAssociationMappingPropertyDocBlock(array $association } if (isset($associationMapping['joinTable']) && $associationMapping['joinTable']) { - $joinTable = array(); + $joinTable = []; $joinTable[] = 'name="' . $associationMapping['joinTable']['name'] . '"'; if (isset($associationMapping['joinTable']['schema'])) { @@ -1578,7 +1578,7 @@ protected function generateAssociationMappingPropertyDocBlock(array $association $lines[] = $this->spaces . ' * @' . $this->annotationsPrefix . 'JoinTable(' . implode(', ', $joinTable) . ','; $lines[] = $this->spaces . ' * joinColumns={'; - $joinColumnsLines = array(); + $joinColumnsLines = []; foreach ($associationMapping['joinTable']['joinColumns'] as $joinColumn) { $joinColumnsLines[] = $this->spaces . ' * ' . $this->generateJoinColumnAnnotation($joinColumn); @@ -1588,7 +1588,7 @@ protected function generateAssociationMappingPropertyDocBlock(array $association $lines[] = $this->spaces . ' * },'; $lines[] = $this->spaces . ' * inverseJoinColumns={'; - $inverseJoinColumnsLines = array(); + $inverseJoinColumnsLines = []; foreach ($associationMapping['joinTable']['inverseJoinColumns'] as $joinColumn) { $inverseJoinColumnsLines[] = $this->spaces . ' * ' . $this->generateJoinColumnAnnotation($joinColumn); @@ -1624,7 +1624,7 @@ protected function generateAssociationMappingPropertyDocBlock(array $association */ protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, ClassMetadataInfo $metadata) { - $lines = array(); + $lines = []; $lines[] = $this->spaces . '/**'; $lines[] = $this->spaces . ' * @var ' . $this->getType($fieldMapping['type']) @@ -1633,7 +1633,7 @@ protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, Cla if ($this->generateAnnotations) { $lines[] = $this->spaces . ' *'; - $column = array(); + $column = []; if (isset($fieldMapping['columnName'])) { $column[] = 'name="' . $fieldMapping['columnName'] . '"'; } @@ -1686,7 +1686,7 @@ protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, Cla } if ($metadata->sequenceGeneratorDefinition) { - $sequenceGenerator = array(); + $sequenceGenerator = []; if (isset($metadata->sequenceGeneratorDefinition['sequenceName'])) { $sequenceGenerator[] = 'sequenceName="' . $metadata->sequenceGeneratorDefinition['sequenceName'] . '"'; @@ -1721,14 +1721,14 @@ protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, Cla */ protected function generateEmbeddedPropertyDocBlock(array $embeddedClass) { - $lines = array(); + $lines = []; $lines[] = $this->spaces . '/**'; $lines[] = $this->spaces . ' * @var \\' . ltrim($embeddedClass['class'], '\\'); if ($this->generateAnnotations) { $lines[] = $this->spaces . ' *'; - $embedded = array('class="' . $embeddedClass['class'] . '"'); + $embedded = ['class="' . $embeddedClass['class'] . '"']; if (isset($fieldMapping['columnPrefix'])) { $embedded[] = 'columnPrefix=' . var_export($embeddedClass['columnPrefix'], true); @@ -1833,7 +1833,7 @@ private function nullableFieldExpression(array $fieldMapping) */ private function exportTableOptions(array $options) { - $optionsStr = array(); + $optionsStr = []; foreach ($options as $name => $option) { if (is_array($option)) { diff --git a/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php b/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php index f431588fb09..927738cba28 100644 --- a/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php @@ -57,11 +57,11 @@ class extends */ public function generateEntityRepositoryClass($fullClassName) { - $variables = array( + $variables = [ '' => $this->generateEntityRepositoryNamespace($fullClassName), '' => $this->generateEntityRepositoryName($fullClassName), '' => $this->generateClassName($fullClassName) - ); + ]; return str_replace(array_keys($variables), array_values($variables), self::$_template); } @@ -70,7 +70,7 @@ public function generateEntityRepositoryClass($fullClassName) * Generates the namespace, if class do not have namespace, return empty string instead. * * @param string $fullClassName - * + * * @return string $namespace */ private function getClassNamespace($fullClassName) @@ -82,9 +82,9 @@ private function getClassNamespace($fullClassName) /** * Generates the class name - * + * * @param string $fullClassName - * + * * @return string */ private function generateClassName($fullClassName) @@ -102,7 +102,7 @@ private function generateClassName($fullClassName) /** * Generates the namespace statement, if class do not have namespace, return empty string instead. - * + * * @param string $fullClassName The full repository class name. * * @return string $namespace @@ -158,7 +158,7 @@ public function writeEntityRepositoryClass($fullClassName, $outputDirectory) /** * @param string $repositoryName - * + * * @return \Doctrine\ORM\Tools\EntityRepositoryGenerator */ public function setDefaultRepositoryName($repositoryName) diff --git a/lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php b/lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php index 1ea2a3735a9..94c781bef08 100644 --- a/lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php @@ -32,13 +32,13 @@ class ClassMetadataExporter /** * @var array */ - private static $_exporterDrivers = array( + private static $_exporterDrivers = [ 'xml' => 'Doctrine\ORM\Tools\Export\Driver\XmlExporter', 'yaml' => 'Doctrine\ORM\Tools\Export\Driver\YamlExporter', 'yml' => 'Doctrine\ORM\Tools\Export\Driver\YamlExporter', 'php' => 'Doctrine\ORM\Tools\Export\Driver\PhpExporter', 'annotation' => 'Doctrine\ORM\Tools\Export\Driver\AnnotationExporter' - ); + ]; /** * Registers a new exporter driver class under a specified name. diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php index ae8650525e1..100e16fd00f 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php @@ -35,7 +35,7 @@ abstract class AbstractExporter /** * @var array */ - protected $_metadata = array(); + protected $_metadata = []; /** * @var string|null diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php index 5d88901a56a..00a4be59660 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php @@ -40,7 +40,7 @@ class PhpExporter extends AbstractExporter */ public function exportClassMetadata(ClassMetadataInfo $metadata) { - $lines = array(); + $lines = []; $lines[] = 'associationMappings as $associationMapping) { - $cascade = array('remove', 'persist', 'refresh', 'merge', 'detach'); + $cascade = ['remove', 'persist', 'refresh', 'merge', 'detach']; foreach ($cascade as $key => $value) { if ( ! $associationMapping['isCascade'.ucfirst($value)]) { unset($cascade[$key]); @@ -99,14 +99,14 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) } if (count($cascade) === 5) { - $cascade = array('all'); + $cascade = ['all']; } - $associationMappingArray = array( + $associationMappingArray = [ 'fieldName' => $associationMapping['fieldName'], 'targetEntity' => $associationMapping['targetEntity'], 'cascade' => $cascade, - ); + ]; if (isset($associationMapping['fetch'])) { $associationMappingArray['fetch'] = $associationMapping['fetch']; @@ -114,21 +114,21 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) if ($associationMapping['type'] & ClassMetadataInfo::TO_ONE) { $method = 'mapOneToOne'; - $oneToOneMappingArray = array( + $oneToOneMappingArray = [ 'mappedBy' => $associationMapping['mappedBy'], 'inversedBy' => $associationMapping['inversedBy'], 'joinColumns' => $associationMapping['isOwningSide'] ? $associationMapping['joinColumns'] : [], 'orphanRemoval' => $associationMapping['orphanRemoval'], - ); + ]; $associationMappingArray = array_merge($associationMappingArray, $oneToOneMappingArray); } elseif ($associationMapping['type'] == ClassMetadataInfo::ONE_TO_MANY) { $method = 'mapOneToMany'; - $potentialAssociationMappingIndexes = array( + $potentialAssociationMappingIndexes = [ 'mappedBy', 'orphanRemoval', 'orderBy', - ); + ]; foreach ($potentialAssociationMappingIndexes as $index) { if (isset($associationMapping[$index])) { $oneToManyMappingArray[$index] = $associationMapping[$index]; @@ -137,11 +137,11 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) $associationMappingArray = array_merge($associationMappingArray, $oneToManyMappingArray); } elseif ($associationMapping['type'] == ClassMetadataInfo::MANY_TO_MANY) { $method = 'mapManyToMany'; - $potentialAssociationMappingIndexes = array( + $potentialAssociationMappingIndexes = [ 'mappedBy', 'joinTable', 'orderBy', - ); + ]; foreach ($potentialAssociationMappingIndexes as $index) { if (isset($associationMapping[$index])) { $manyToManyMappingArray[$index] = $associationMapping[$index]; diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php index ba41d99862f..fbcbf42d1c0 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php @@ -126,7 +126,7 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) $fields = $metadata->fieldMappings; - $id = array(); + $id = []; foreach ($fields as $name => $field) { if (isset($field['id']) && $field['id']) { $id[$name] = $field; @@ -136,10 +136,10 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) foreach ($metadata->associationMappings as $name => $assoc) { if (isset($assoc['id']) && $assoc['id']) { - $id[$name] = array( + $id[$name] = [ 'fieldName' => $name, 'associationKey' => true - ); + ]; } } @@ -225,12 +225,12 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) } } - $orderMap = array( + $orderMap = [ ClassMetadataInfo::ONE_TO_ONE, ClassMetadataInfo::ONE_TO_MANY, ClassMetadataInfo::MANY_TO_ONE, ClassMetadataInfo::MANY_TO_MANY, - ); + ]; uasort($metadata->associationMappings, function($m1, $m2) use (&$orderMap){ $a1 = array_search($m1['type'], $orderMap); @@ -273,7 +273,7 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) $associationMappingXml->addAttribute('fetch', $this->_getFetchModeString($associationMapping['fetch'])); } - $cascade = array(); + $cascade = []; if ($associationMapping['isCascadeRemove']) { $cascade[] = 'cascade-remove'; } @@ -295,7 +295,7 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) } if (count($cascade) === 5) { - $cascade = array('cascade-all'); + $cascade = ['cascade-all']; } if ($cascade) { diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php index 7677ad9501e..b9a38f9046f 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php @@ -41,7 +41,7 @@ class YamlExporter extends AbstractExporter */ public function exportClassMetadata(ClassMetadataInfo $metadata) { - $array = array(); + $array = []; if ($metadata->isMappedSuperclass) { $array['type'] = 'mappedSuperclass'; @@ -91,7 +91,7 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) $fieldMappings = $metadata->fieldMappings; - $ids = array(); + $ids = []; foreach ($fieldMappings as $name => $fieldMapping) { $fieldMapping['column'] = $fieldMapping['columnName']; @@ -118,13 +118,13 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) if ($fieldMappings) { if ( ! isset($array['fields'])) { - $array['fields'] = array(); + $array['fields'] = []; } $array['fields'] = array_merge($array['fields'], $fieldMappings); } foreach ($metadata->associationMappings as $name => $associationMapping) { - $cascade = array(); + $cascade = []; if ($associationMapping['isCascadeRemove']) { $cascade[] = 'remove'; @@ -146,13 +146,13 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) $cascade[] = 'detach'; } if (count($cascade) === 5) { - $cascade = array('all'); + $cascade = ['all']; } - $associationMappingArray = array( + $associationMappingArray = [ 'targetEntity' => $associationMapping['targetEntity'], 'cascade' => $cascade, - ); + ]; if (isset($associationMapping['fetch'])) { $associationMappingArray['fetch'] = $this->_getFetchModeString($associationMapping['fetch']); @@ -164,7 +164,7 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) if ($associationMapping['type'] & ClassMetadataInfo::TO_ONE) { $joinColumns = $associationMapping['isOwningSide'] ? $associationMapping['joinColumns'] : []; - $newJoinColumns = array(); + $newJoinColumns = []; foreach ($joinColumns as $joinColumn) { $newJoinColumns[$joinColumn['name']]['referencedColumnName'] = $joinColumn['referencedColumnName']; @@ -174,12 +174,12 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) } } - $oneToOneMappingArray = array( + $oneToOneMappingArray = [ 'mappedBy' => $associationMapping['mappedBy'], 'inversedBy' => $associationMapping['inversedBy'], 'joinColumns' => $newJoinColumns, 'orphanRemoval' => $associationMapping['orphanRemoval'], - ); + ]; $associationMappingArray = array_merge($associationMappingArray, $oneToOneMappingArray); @@ -189,22 +189,22 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) $array['manyToOne'][$name] = $associationMappingArray; } } elseif ($associationMapping['type'] == ClassMetadataInfo::ONE_TO_MANY) { - $oneToManyMappingArray = array( + $oneToManyMappingArray = [ 'mappedBy' => $associationMapping['mappedBy'], 'inversedBy' => $associationMapping['inversedBy'], 'orphanRemoval' => $associationMapping['orphanRemoval'], 'orderBy' => isset($associationMapping['orderBy']) ? $associationMapping['orderBy'] : null - ); + ]; $associationMappingArray = array_merge($associationMappingArray, $oneToManyMappingArray); $array['oneToMany'][$name] = $associationMappingArray; } elseif ($associationMapping['type'] == ClassMetadataInfo::MANY_TO_MANY) { - $manyToManyMappingArray = array( + $manyToManyMappingArray = [ 'mappedBy' => $associationMapping['mappedBy'], 'inversedBy' => $associationMapping['inversedBy'], 'joinTable' => isset($associationMapping['joinTable']) ? $associationMapping['joinTable'] : null, 'orderBy' => isset($associationMapping['orderBy']) ? $associationMapping['orderBy'] : null - ); + ]; $associationMappingArray = array_merge($associationMappingArray, $manyToManyMappingArray); $array['manyToMany'][$name] = $associationMappingArray; @@ -214,7 +214,7 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) $array['lifecycleCallbacks'] = $metadata->lifecycleCallbacks; } - return $this->yamlDump(array($metadata->name => $array), 10); + return $this->yamlDump([$metadata->name => $array], 10); } /** diff --git a/lib/Doctrine/ORM/Tools/Pagination/CountOutputWalker.php b/lib/Doctrine/ORM/Tools/Pagination/CountOutputWalker.php index 2cfd029df2c..8d3163043ab 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/CountOutputWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/CountOutputWalker.php @@ -108,7 +108,7 @@ public function walkSelectStatement(SelectStatement $AST) $rootIdentifier = $rootClass->identifier; // For every identifier, find out the SQL alias by combing through the ResultSetMapping - $sqlIdentifier = array(); + $sqlIdentifier = []; foreach ($rootIdentifier as $property) { if (isset($rootClass->fieldMappings[$property])) { foreach (array_keys($this->rsm->fieldMappings, $property) as $alias) { diff --git a/lib/Doctrine/ORM/Tools/Pagination/CountWalker.php b/lib/Doctrine/ORM/Tools/Pagination/CountWalker.php index 628bd4cd138..a8f26001aba 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/CountWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/CountWalker.php @@ -59,11 +59,11 @@ public function walkSelectStatement(SelectStatement $AST) $queryComponents = $this->_getQueryComponents(); // Get the root entity and alias from the AST fromClause $from = $AST->fromClause->identificationVariableDeclarations; - + if (count($from) > 1) { throw new \RuntimeException("Cannot count query which selects two FROM components, cannot make distinction"); } - + $fromRoot = reset($from); $rootAlias = $fromRoot->rangeVariableDeclaration->aliasIdentificationVariable; $rootClass = $queryComponents[$rootAlias]['metadata']; @@ -81,11 +81,11 @@ public function walkSelectStatement(SelectStatement $AST) $pathExpression->type = $pathType; $distinct = $this->_getQuery()->getHint(self::HINT_DISTINCT); - $AST->selectClause->selectExpressions = array( + $AST->selectClause->selectExpressions = [ new SelectExpression( new AggregateExpression('count', $pathExpression, $distinct), null ) - ); + ]; // ORDER BY is not needed, only increases query execution through unnecessary sorting. $AST->orderByClause = null; diff --git a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php index b2a292ad9af..1874eb88dde 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php @@ -69,7 +69,7 @@ public function walkSelectStatement(SelectStatement $AST) $fromRoot = reset($from); $rootAlias = $fromRoot->rangeVariableDeclaration->aliasIdentificationVariable; $rootClass = $queryComponents[$rootAlias]['metadata']; - $selectExpressions = array(); + $selectExpressions = []; $this->validate($AST); @@ -80,9 +80,9 @@ public function walkSelectStatement(SelectStatement $AST) continue; } } - + $identifier = $rootClass->getSingleIdentifierFieldName(); - + if (isset($rootClass->associationMappings[$identifier])) { throw new \RuntimeException("Paginating an entity with foreign key as identifier only works when using the Output Walkers. Call Paginator#setUseOutputWalkers(true) before iterating the paginator."); } @@ -109,7 +109,7 @@ public function walkSelectStatement(SelectStatement $AST) if ( ! $item->expression instanceof PathExpression) { continue; } - + $AST->selectClause->selectExpressions[] = new SelectExpression( $this->createSelectExpressionItem($item->expression), '_dctrn_ord' . $this->_aliasCounter++ @@ -154,24 +154,24 @@ private function validate(SelectStatement $AST) } } } - + /** * Retrieve either an IdentityFunction (IDENTITY(u.assoc)) or a state field (u.name). - * + * * @param \Doctrine\ORM\Query\AST\PathExpression $pathExpression - * + * * @return \Doctrine\ORM\Query\AST\Functions\IdentityFunction */ private function createSelectExpressionItem(PathExpression $pathExpression) { if ($pathExpression->type === PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION) { $identity = new IdentityFunction('identity'); - + $identity->pathExpression = clone $pathExpression; - + return $identity; } - + return clone $pathExpression; } } diff --git a/lib/Doctrine/ORM/Tools/Pagination/Paginator.php b/lib/Doctrine/ORM/Tools/Pagination/Paginator.php index 449aae1cac6..aa2a22365da 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/Paginator.php +++ b/lib/Doctrine/ORM/Tools/Pagination/Paginator.php @@ -225,7 +225,7 @@ private function appendTreeWalker(Query $query, $walkerClass) $hints = $query->getHint(Query::HINT_CUSTOM_TREE_WALKERS); if ($hints === false) { - $hints = array(); + $hints = []; } $hints[] = $walkerClass; diff --git a/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php b/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php index 1f54da10052..5fa4e2d94c4 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php @@ -76,11 +76,11 @@ public function walkSelectStatement(SelectStatement $AST) $queryComponents = $this->_getQueryComponents(); // Get the root entity and alias from the AST fromClause $from = $AST->fromClause->identificationVariableDeclarations; - + if (count($from) > 1) { throw new \RuntimeException("Cannot count query which selects two FROM components, cannot make distinction"); } - + $fromRoot = reset($from); $rootAlias = $fromRoot->rangeVariableDeclaration->aliasIdentificationVariable; $rootClass = $queryComponents[$rootAlias]['metadata']; @@ -99,7 +99,7 @@ public function walkSelectStatement(SelectStatement $AST) if ($count > 0) { $arithmeticExpression = new ArithmeticExpression(); $arithmeticExpression->simpleArithmeticExpression = new SimpleArithmeticExpression( - array($pathExpression) + [$pathExpression] ); $expression = new InExpression($arithmeticExpression); $expression->literals[] = new InputParameter(":" . self::PAGINATOR_ID_ALIAS); @@ -115,29 +115,35 @@ public function walkSelectStatement(SelectStatement $AST) if ($AST->whereClause->conditionalExpression instanceof ConditionalTerm) { $AST->whereClause->conditionalExpression->conditionalFactors[] = $conditionalPrimary; } elseif ($AST->whereClause->conditionalExpression instanceof ConditionalPrimary) { - $AST->whereClause->conditionalExpression = new ConditionalExpression(array( - new ConditionalTerm(array( - $AST->whereClause->conditionalExpression, - $conditionalPrimary - )) - )); + $AST->whereClause->conditionalExpression = new ConditionalExpression( + [ + new ConditionalTerm( + [ + $AST->whereClause->conditionalExpression, + $conditionalPrimary + ] + ) + ] + ); } elseif ($AST->whereClause->conditionalExpression instanceof ConditionalExpression || $AST->whereClause->conditionalExpression instanceof ConditionalFactor ) { $tmpPrimary = new ConditionalPrimary; $tmpPrimary->conditionalExpression = $AST->whereClause->conditionalExpression; - $AST->whereClause->conditionalExpression = new ConditionalTerm(array( - $tmpPrimary, - $conditionalPrimary - )); + $AST->whereClause->conditionalExpression = new ConditionalTerm( + [ + $tmpPrimary, + $conditionalPrimary + ] + ); } } else { $AST->whereClause = new WhereClause( - new ConditionalExpression(array( - new ConditionalTerm(array( - $conditionalPrimary - )) - )) + new ConditionalExpression( + [ + new ConditionalTerm([$conditionalPrimary]) + ] + ) ); } } diff --git a/lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php b/lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php index 574c9c28e12..46488bf97d7 100644 --- a/lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php +++ b/lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php @@ -39,17 +39,17 @@ class ResolveTargetEntityListener implements EventSubscriber /** * @var array[] indexed by original entity name */ - private $resolveTargetEntities = array(); + private $resolveTargetEntities = []; /** * {@inheritDoc} */ public function getSubscribedEvents() { - return array( + return [ Events::loadClassMetadata, Events::onClassMetadataNotFound - ); + ]; } /** diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index da1a291d317..627f7b5736a 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -143,16 +143,16 @@ private function processingNotRequired($class, array $processedClasses) public function getSchemaFromMetadata(array $classes) { // Reminder for processed classes, used for hierarchies - $processedClasses = array(); + $processedClasses = []; $eventManager = $this->em->getEventManager(); $schemaManager = $this->em->getConnection()->getSchemaManager(); $metadataSchemaConfig = $schemaManager->createSchemaConfig(); $metadataSchemaConfig->setExplicitForeignKeyIndexes(false); - $schema = new Schema(array(), array(), $metadataSchemaConfig); + $schema = new Schema([], [], $metadataSchemaConfig); - $addedFks = array(); - $blacklistedFks = array(); + $addedFks = []; + $blacklistedFks = []; foreach ($classes as $class) { /** @var \Doctrine\ORM\Mapping\ClassMetadata $class */ @@ -183,7 +183,7 @@ public function getSchemaFromMetadata(array $classes) } } elseif ($class->isInheritanceTypeJoined()) { // Add all non-inherited fields as columns - $pkColumns = array(); + $pkColumns = []; foreach ($class->fieldMappings as $fieldName => $mapping) { if ( ! isset($mapping['inherited'])) { $columnName = $this->quoteStrategy->getColumnName( @@ -206,7 +206,7 @@ public function getSchemaFromMetadata(array $classes) $this->addDiscriminatorColumnDefinition($class, $table); } else { // Add an ID FK column to child tables - $inheritedKeyColumns = array(); + $inheritedKeyColumns = []; foreach ($class->identifier as $identifierField) { $idMapping = $class->fieldMappings[$identifierField]; if (isset($idMapping['inherited'])) { @@ -232,7 +232,7 @@ public function getSchemaFromMetadata(array $classes) ), $inheritedKeyColumns, $inheritedKeyColumns, - array('onDelete' => 'CASCADE') + ['onDelete' => 'CASCADE'] ); } @@ -247,7 +247,7 @@ public function getSchemaFromMetadata(array $classes) $this->gatherRelationsSql($class, $table, $schema, $addedFks, $blacklistedFks); } - $pkColumns = array(); + $pkColumns = []; foreach ($class->identifier as $identifierField) { if (isset($class->fieldMappings[$identifierField])) { @@ -280,10 +280,10 @@ public function getSchemaFromMetadata(array $classes) if (isset($class->table['indexes'])) { foreach ($class->table['indexes'] as $indexName => $indexData) { if ( ! isset($indexData['flags'])) { - $indexData['flags'] = array(); + $indexData['flags'] = []; } - $table->addIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName, (array) $indexData['flags'], isset($indexData['options']) ? $indexData['options'] : array()); + $table->addIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName, (array) $indexData['flags'], isset($indexData['options']) ? $indexData['options'] : []); } } @@ -298,7 +298,7 @@ public function getSchemaFromMetadata(array $classes) } } - $table->addUniqueIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName, isset($indexData['options']) ? $indexData['options'] : array()); + $table->addUniqueIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName, isset($indexData['options']) ? $indexData['options'] : []); } } @@ -365,10 +365,10 @@ private function addDiscriminatorColumnDefinition($class, Table $table) $discrColumn['length'] = 255; } - $options = array( + $options = [ 'length' => isset($discrColumn['length']) ? $discrColumn['length'] : null, 'notnull' => true - ); + ]; if (isset($discrColumn['columnDefinition'])) { $options['columnDefinition'] = $discrColumn['columnDefinition']; @@ -388,7 +388,7 @@ private function addDiscriminatorColumnDefinition($class, Table $table) */ private function gatherColumns($class, Table $table) { - $pkColumns = array(); + $pkColumns = []; foreach ($class->fieldMappings as $mapping) { if ($class->isInheritanceTypeSingleTable() && isset($mapping['inherited'])) { @@ -423,14 +423,14 @@ private function gatherColumn($class, array $mapping, Table $table) $columnName = $this->quoteStrategy->getColumnName($mapping['fieldName'], $class, $this->platform); $columnType = $mapping['type']; - $options = array(); + $options = []; $options['length'] = isset($mapping['length']) ? $mapping['length'] : null; $options['notnull'] = isset($mapping['nullable']) ? ! $mapping['nullable'] : true; if ($class->isInheritanceTypeSingleTable() && $class->parentClasses) { $options['notnull'] = false; } - $options['platformOptions'] = array(); + $options['platformOptions'] = []; $options['platformOptions']['version'] = $class->isVersioned && $class->versionField === $mapping['fieldName']; if (strtolower($columnType) === 'string' && null === $options['length']) { @@ -454,7 +454,7 @@ private function gatherColumn($class, array $mapping, Table $table) } if (isset($mapping['options'])) { - $knownOptions = array('comment', 'unsigned', 'fixed', 'default'); + $knownOptions = ['comment', 'unsigned', 'fixed', 'default']; foreach ($knownOptions as $knownOption) { if (array_key_exists($knownOption, $mapping['options'])) { @@ -467,7 +467,7 @@ private function gatherColumn($class, array $mapping, Table $table) $options['customSchemaOptions'] = $mapping['options']; } - if ($class->isIdGeneratorIdentity() && $class->getIdentifierFieldNames() == array($mapping['fieldName'])) { + if ($class->isIdGeneratorIdentity() && $class->getIdentifierFieldNames() == [$mapping['fieldName']]) { $options['autoincrement'] = true; } if ($class->isInheritanceTypeJoined() && $class->name !== $class->rootEntityName) { @@ -483,7 +483,7 @@ private function gatherColumn($class, array $mapping, Table $table) $isUnique = isset($mapping['unique']) ? $mapping['unique'] : false; if ($isUnique) { - $table->addUniqueIndex(array($columnName)); + $table->addUniqueIndex([$columnName]); } } @@ -511,7 +511,7 @@ private function gatherRelationsSql($class, $table, $schema, &$addedFks, &$black $foreignClass = $this->em->getClassMetadata($mapping['targetEntity']); if ($mapping['type'] & ClassMetadata::TO_ONE && $mapping['isOwningSide']) { - $primaryKeyColumns = array(); // PK is unnecessary for this relation-type + $primaryKeyColumns = []; // PK is unnecessary for this relation-type $this->gatherRelationJoinColumns( $mapping['joinColumns'], @@ -533,7 +533,7 @@ private function gatherRelationsSql($class, $table, $schema, &$addedFks, &$black $this->quoteStrategy->getJoinTableName($mapping, $foreignClass, $this->platform) ); - $primaryKeyColumns = array(); + $primaryKeyColumns = []; // Build first FK constraint (relation table => source table) $this->gatherRelationJoinColumns( @@ -581,7 +581,7 @@ private function getDefiningClass($class, $referencedColumnName) $referencedFieldName = $class->getFieldName($referencedColumnName); if ($class->hasField($referencedFieldName)) { - return array($class, $referencedFieldName); + return [$class, $referencedFieldName]; } if (in_array($referencedColumnName, $class->getIdentifierColumnNames())) { @@ -625,11 +625,11 @@ private function gatherRelationJoinColumns( &$blacklistedFks ) { - $localColumns = array(); - $foreignColumns = array(); - $fkOptions = array(); + $localColumns = []; + $foreignColumns = []; + $fkOptions = []; $foreignTableName = $this->quoteStrategy->getTableName($class, $this->platform); - $uniqueConstraints = array(); + $uniqueConstraints = []; foreach ($joinColumns as $joinColumn) { @@ -670,7 +670,7 @@ private function gatherRelationJoinColumns( $columnDef = $fieldMapping['columnDefinition']; } - $columnOptions = array('notnull' => false, 'columnDefinition' => $columnDef); + $columnOptions = ['notnull' => false, 'columnDefinition' => $columnDef]; if (isset($joinColumn['nullable'])) { $columnOptions['notnull'] = !$joinColumn['nullable']; @@ -691,7 +691,7 @@ private function gatherRelationJoinColumns( } if (isset($joinColumn['unique']) && $joinColumn['unique'] == true) { - $uniqueConstraints[] = array('columns' => array($quotedColumnName)); + $uniqueConstraints[] = ['columns' => [$quotedColumnName]]; } if (isset($joinColumn['onDelete'])) { @@ -721,7 +721,7 @@ private function gatherRelationJoinColumns( } $blacklistedFks[$compositeName] = true; } elseif (!isset($blacklistedFks[$compositeName])) { - $addedFks[$compositeName] = array('foreignTableName' => $foreignTableName, 'foreignColumns' => $foreignColumns); + $addedFks[$compositeName] = ['foreignTableName' => $foreignTableName, 'foreignColumns' => $foreignColumns]; $theJoinTable->addUnnamedForeignKeyConstraint( $foreignTableName, $localColumns, diff --git a/lib/Doctrine/ORM/Tools/SchemaValidator.php b/lib/Doctrine/ORM/Tools/SchemaValidator.php index 3f5799a4de1..4119b9d6003 100644 --- a/lib/Doctrine/ORM/Tools/SchemaValidator.php +++ b/lib/Doctrine/ORM/Tools/SchemaValidator.php @@ -63,7 +63,7 @@ public function __construct(EntityManagerInterface $em) */ public function validateMapping() { - $errors = array(); + $errors = []; $cmf = $this->em->getMetadataFactory(); $classes = $cmf->getAllMetadata(); @@ -85,7 +85,7 @@ public function validateMapping() */ public function validateClass(ClassMetadataInfo $class) { - $ce = array(); + $ce = []; $cmf = $this->em->getMetadataFactory(); foreach ($class->fieldMappings as $fieldName => $mapping) { @@ -212,7 +212,7 @@ public function validateClass(ClassMetadataInfo $class) } if (count($identifierColumns) != count($assoc['joinColumns'])) { - $ids = array(); + $ids = []; foreach ($assoc['joinColumns'] as $joinColumn) { $ids[] = $joinColumn['name']; diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 368fdfd6397..00a41e6dffc 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -102,7 +102,7 @@ class UnitOfWork implements PropertyChangedListener * * @var array */ - private $identityMap = array(); + private $identityMap = []; /** * Map of all identifiers of managed entities. @@ -110,7 +110,7 @@ class UnitOfWork implements PropertyChangedListener * * @var array */ - private $entityIdentifiers = array(); + private $entityIdentifiers = []; /** * Map of the original entity data of managed entities. @@ -123,7 +123,7 @@ class UnitOfWork implements PropertyChangedListener * * @var array */ - private $originalEntityData = array(); + private $originalEntityData = []; /** * Map of entity changes. Keys are object ids (spl_object_hash). @@ -131,7 +131,7 @@ class UnitOfWork implements PropertyChangedListener * * @var array */ - private $entityChangeSets = array(); + private $entityChangeSets = []; /** * The (cached) states of any known entities. @@ -139,7 +139,7 @@ class UnitOfWork implements PropertyChangedListener * * @var array */ - private $entityStates = array(); + private $entityStates = []; /** * Map of entities that are scheduled for dirty checking at commit time. @@ -148,49 +148,49 @@ class UnitOfWork implements PropertyChangedListener * * @var array */ - private $scheduledForSynchronization = array(); + private $scheduledForSynchronization = []; /** * A list of all pending entity insertions. * * @var array */ - private $entityInsertions = array(); + private $entityInsertions = []; /** * A list of all pending entity updates. * * @var array */ - private $entityUpdates = array(); + private $entityUpdates = []; /** * Any pending extra updates that have been scheduled by persisters. * * @var array */ - private $extraUpdates = array(); + private $extraUpdates = []; /** * A list of all pending entity deletions. * * @var array */ - private $entityDeletions = array(); + private $entityDeletions = []; /** * All pending collection deletions. * * @var array */ - private $collectionDeletions = array(); + private $collectionDeletions = []; /** * All pending collection updates. * * @var array */ - private $collectionUpdates = array(); + private $collectionUpdates = []; /** * List of collections visited during changeset calculation on a commit-phase of a UnitOfWork. @@ -199,7 +199,7 @@ class UnitOfWork implements PropertyChangedListener * * @var array */ - private $visitedCollections = array(); + private $visitedCollections = []; /** * The EntityManager that "owns" this UnitOfWork instance. @@ -213,14 +213,14 @@ class UnitOfWork implements PropertyChangedListener * * @var array */ - private $persisters = array(); + private $persisters = []; /** * The collection persister instances used to persist collections. * * @var array */ - private $collectionPersisters = array(); + private $collectionPersisters = []; /** * The EventManager used for dispatching events. @@ -248,21 +248,21 @@ class UnitOfWork implements PropertyChangedListener * * @var array */ - private $orphanRemovals = array(); + private $orphanRemovals = []; /** * Read-Only objects are never evaluated * * @var array */ - private $readOnlyObjects = array(); + private $readOnlyObjects = []; /** * Map of Entity Class-Names and corresponding IDs that should eager loaded when requested. * * @var array */ - private $eagerLoadingEntities = array(); + private $eagerLoadingEntities = []; /** * @var boolean @@ -424,7 +424,7 @@ public function commit($entity = null) $this->collectionDeletions = $this->visitedCollections = $this->scheduledForSynchronization = - $this->orphanRemovals = array(); + $this->orphanRemovals = []; } /** @@ -501,7 +501,7 @@ private function executeExtraUpdates() $this->getEntityPersister(get_class($entity))->update($entity); } - $this->extraUpdates = array(); + $this->extraUpdates = []; } /** @@ -514,7 +514,7 @@ private function executeExtraUpdates() public function & getEntityChangeSet($entity) { $oid = spl_object_hash($entity); - $data = array(); + $data = []; if (!isset($this->entityChangeSets[$oid])) { return $data; @@ -575,7 +575,7 @@ public function computeChangeSet(ClassMetadata $class, $entity) $this->listenersInvoker->invoke($class, Events::preFlush, $entity, new PreFlushEventArgs($this->em), $invoke); } - $actualData = array(); + $actualData = []; foreach ($class->reflFields as $name => $refProp) { $value = $refProp->getValue($entity); @@ -619,11 +619,11 @@ public function computeChangeSet(ClassMetadata $class, $entity) // Entity is either NEW or MANAGED but not yet fully persisted (only has an id). // These result in an INSERT. $this->originalEntityData[$oid] = $actualData; - $changeSet = array(); + $changeSet = []; foreach ($actualData as $propName => $actualValue) { if ( ! isset($class->associationMappings[$propName])) { - $changeSet[$propName] = array(null, $actualValue); + $changeSet[$propName] = [null, $actualValue]; continue; } @@ -631,7 +631,7 @@ public function computeChangeSet(ClassMetadata $class, $entity) $assoc = $class->associationMappings[$propName]; if ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE) { - $changeSet[$propName] = array(null, $actualValue); + $changeSet[$propName] = [null, $actualValue]; } } @@ -643,7 +643,7 @@ public function computeChangeSet(ClassMetadata $class, $entity) $isChangeTrackingNotify = $class->isChangeTrackingNotify(); $changeSet = ($isChangeTrackingNotify && isset($this->entityChangeSets[$oid])) ? $this->entityChangeSets[$oid] - : array(); + : []; foreach ($actualData as $propName => $actualValue) { // skip field, its a partially omitted one! @@ -664,7 +664,7 @@ public function computeChangeSet(ClassMetadata $class, $entity) continue; } - $changeSet[$propName] = array($orgValue, $actualValue); + $changeSet[$propName] = [$orgValue, $actualValue]; continue; } @@ -704,7 +704,7 @@ public function computeChangeSet(ClassMetadata $class, $entity) if ($assoc['type'] & ClassMetadata::TO_ONE) { if ($assoc['isOwningSide']) { - $changeSet[$propName] = array($orgValue, $actualValue); + $changeSet[$propName] = [$orgValue, $actualValue]; } if ($orgValue !== null && $assoc['orphanRemoval']) { @@ -734,7 +734,7 @@ public function computeChangeSet(ClassMetadata $class, $entity) $val instanceof PersistentCollection && $val->isDirty()) { - $this->entityChangeSets[$oid] = array(); + $this->entityChangeSets[$oid] = []; $this->originalEntityData[$oid] = $actualData; $this->entityUpdates[$oid] = $entity; } @@ -774,7 +774,7 @@ public function computeChangeSets() break; default: - $entitiesToProcess = array(); + $entitiesToProcess = []; } @@ -821,7 +821,7 @@ private function computeAssociationChanges($assoc, $value) // Look through the entities, and in any of their associations, // for transient (new) entities, recursively. ("Persistence by reachability") // Unwrap. Uninitialized collections will simply be empty. - $unwrappedValue = ($assoc['type'] & ClassMetadata::TO_ONE) ? array($value) : $value->unwrap(); + $unwrappedValue = ($assoc['type'] & ClassMetadata::TO_ONE) ? [$value] : $value->unwrap(); $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); foreach ($unwrappedValue as $key => $entry) { @@ -935,7 +935,7 @@ public function recomputeSingleEntityChangeSet(ClassMetadata $class, $entity) $class = $this->em->getClassMetadata(get_class($entity)); } - $actualData = array(); + $actualData = []; foreach ($class->reflFields as $name => $refProp) { if (( ! $class->isIdentifier($name) || ! $class->isIdGeneratorIdentity()) @@ -950,13 +950,13 @@ public function recomputeSingleEntityChangeSet(ClassMetadata $class, $entity) } $originalData = $this->originalEntityData[$oid]; - $changeSet = array(); + $changeSet = []; foreach ($actualData as $propName => $actualValue) { $orgValue = isset($originalData[$propName]) ? $originalData[$propName] : null; if ($orgValue !== $actualValue) { - $changeSet[$propName] = array($orgValue, $actualValue); + $changeSet[$propName] = [$orgValue, $actualValue]; } } @@ -980,7 +980,7 @@ public function recomputeSingleEntityChangeSet(ClassMetadata $class, $entity) */ private function executeInserts($class) { - $entities = array(); + $entities = []; $className = $class->name; $persister = $this->getEntityPersister($className); $invoke = $this->listenersInvoker->getSubscribedSystems($class, Events::postPersist); @@ -1013,7 +1013,7 @@ private function executeInserts($class) $class->reflFields[$idField]->setValue($entity, $idValue); - $this->entityIdentifiers[$oid] = array($idField => $idValue); + $this->entityIdentifiers[$oid] = [$idField => $idValue]; $this->entityStates[$oid] = self::STATE_MANAGED; $this->originalEntityData[$oid][$idField] = $idValue; @@ -1123,7 +1123,7 @@ private function getCommitOrder(array $entityChangeSet = null) // We have to inspect changeSet to be able to correctly build dependencies. // It is not possible to use IdentityMap here because post inserted ids // are not yet available. - $newNodes = array(); + $newNodes = []; foreach ($entityChangeSet as $entity) { $class = $this->em->getClassMetadata(get_class($entity)); @@ -1274,12 +1274,12 @@ public function scheduleForUpdate($entity) public function scheduleExtraUpdate($entity, array $changeset) { $oid = spl_object_hash($entity); - $extraUpdate = array($entity, $changeset); + $extraUpdate = [$entity, $changeset]; if (isset($this->extraUpdates[$oid])) { list(, $changeset2) = $this->extraUpdates[$oid]; - $extraUpdate = array($entity, $changeset + $changeset2); + $extraUpdate = [$entity, $changeset + $changeset2]; } $this->extraUpdates[$oid] = $extraUpdate; @@ -1615,7 +1615,7 @@ public function containsIdHash($idHash, $rootClassName) */ public function persist($entity) { - $visited = array(); + $visited = []; $this->doPersist($entity, $visited); } @@ -1692,7 +1692,7 @@ private function doPersist($entity, array &$visited) */ public function remove($entity) { - $visited = array(); + $visited = []; $this->doRemove($entity, $visited); } @@ -1766,7 +1766,7 @@ private function doRemove($entity, array &$visited) */ public function merge($entity) { - $visited = array(); + $visited = []; return $this->doMerge($entity, $visited); } @@ -1942,7 +1942,7 @@ private function updateAssociationWithMergedEntity($entity, array $association, */ public function detach($entity) { - $visited = array(); + $visited = []; $this->doDetach($entity, $visited); } @@ -2003,7 +2003,7 @@ private function doDetach($entity, array &$visited, $noCascade = false) */ public function refresh($entity) { - $visited = array(); + $visited = []; $this->doRefresh($entity, $visited); } @@ -2245,7 +2245,7 @@ private function cascadeRemove($entity, array &$visited) function ($assoc) { return $assoc['isCascadeRemove']; } ); - $entitiesToCascade = array(); + $entitiesToCascade = []; foreach ($associationMappings as $assoc) { if ($entity instanceof Proxy && !$entity->__isInitialized__) { @@ -2380,7 +2380,7 @@ public function clear($entityName = null) $this->extraUpdates = $this->readOnlyObjects = $this->visitedCollections = - $this->orphanRemovals = array(); + $this->orphanRemovals = []; } else { $this->clearIdentityMapForEntityName($entityName); $this->clearEntityInsertionsForEntityName($entityName); @@ -2484,7 +2484,7 @@ private function newInstance($class) * * @todo Rename: getOrCreateEntity */ - public function createEntity($className, array $data, &$hints = array()) + public function createEntity($className, array $data, &$hints = []) { $class = $this->em->getClassMetadata($className); //$isReadOnly = isset($hints[Query::HINT_READ_ONLY]); @@ -2615,7 +2615,7 @@ public function createEntity($className, array $data, &$hints = array()) continue; } - $associatedId = array(); + $associatedId = []; // TODO: Is this even computed right in all cases of composite keys? foreach ($assoc['targetToSourceKeyColumns'] as $targetColumn => $srcColumn) { @@ -2631,7 +2631,7 @@ public function createEntity($className, array $data, &$hints = array()) && in_array($targetClass->getFieldForColumn($targetColumn), $targetClass->identifier, true) ) { // the missing key is part of target's entity primary key - $associatedId = array(); + $associatedId = []; break; } } @@ -2780,7 +2780,7 @@ public function triggerEagerLoads() // avoid infinite recursion $eagerLoadingEntities = $this->eagerLoadingEntities; - $this->eagerLoadingEntities = array(); + $this->eagerLoadingEntities = []; foreach ($eagerLoadingEntities as $entityName => $ids) { if ( ! $ids) { @@ -2790,7 +2790,7 @@ public function triggerEagerLoads() $class = $this->em->getClassMetadata($entityName); $this->getEntityPersister($entityName)->loadAll( - array_combine($class->identifier, array(array_values($ids))) + array_combine($class->identifier, [array_values($ids)]) ); } } @@ -3088,7 +3088,7 @@ public function registerManaged($entity, array $id, array $data) */ public function clearEntityChangeSet($oid) { - $this->entityChangeSets[$oid] = array(); + $this->entityChangeSets[$oid] = []; } /* PropertyChangedListener implementation */ @@ -3115,7 +3115,7 @@ public function propertyChanged($entity, $propertyName, $oldValue, $newValue) } // Update changeset and mark entity for synchronization - $this->entityChangeSets[$oid][$propertyName] = array($oldValue, $newValue); + $this->entityChangeSets[$oid][$propertyName] = [$oldValue, $newValue]; if ( ! isset($this->scheduledForSynchronization[$class->rootEntityName][$oid])) { $this->scheduleForDirtyCheck($entity); @@ -3374,7 +3374,7 @@ private function mergeEntityStateIntoManagedCopy($entity, $managedCopy) $assoc2['targetEntity'], $relatedId ); - $this->registerManaged($other, $relatedId, array()); + $this->registerManaged($other, $relatedId, []); } } diff --git a/lib/Doctrine/ORM/Utility/IdentifierFlattener.php b/lib/Doctrine/ORM/Utility/IdentifierFlattener.php index 4a60385bd61..a283a683492 100644 --- a/lib/Doctrine/ORM/Utility/IdentifierFlattener.php +++ b/lib/Doctrine/ORM/Utility/IdentifierFlattener.php @@ -68,7 +68,7 @@ public function __construct(UnitOfWork $unitOfWork, ClassMetadataFactory $metada */ public function flattenIdentifier(ClassMetadata $class, array $id) { - $flatId = array(); + $flatId = []; foreach ($class->identifier as $field) { if (isset($class->associationMappings[$field]) && isset($id[$field]) && is_object($id[$field])) { @@ -85,7 +85,7 @@ public function flattenIdentifier(ClassMetadata $class, array $id) $flatId[$field] = implode(' ', $associatedId); } elseif (isset($class->associationMappings[$field])) { - $associatedId = array(); + $associatedId = []; foreach ($class->associationMappings[$field]['joinColumns'] as $joinColumn) { $associatedId[] = $id[$joinColumn['name']]; diff --git a/lib/Doctrine/ORM/Utility/PersisterHelper.php b/lib/Doctrine/ORM/Utility/PersisterHelper.php index ad99a7ea83d..d72dc3e19c0 100644 --- a/lib/Doctrine/ORM/Utility/PersisterHelper.php +++ b/lib/Doctrine/ORM/Utility/PersisterHelper.php @@ -46,11 +46,11 @@ class PersisterHelper public static function getTypeOfField($fieldName, ClassMetadata $class, EntityManagerInterface $em) { if (isset($class->fieldMappings[$fieldName])) { - return array($class->fieldMappings[$fieldName]['type']); + return [$class->fieldMappings[$fieldName]['type']]; } if ( ! isset($class->associationMappings[$fieldName])) { - return array(); + return []; } $assoc = $class->associationMappings[$fieldName]; @@ -65,7 +65,7 @@ public static function getTypeOfField($fieldName, ClassMetadata $class, EntityMa $joinData = $assoc; } - $types = array(); + $types = []; $targetClass = $em->getClassMetadata($assoc['targetEntity']); foreach ($joinData['joinColumns'] as $joinColumn) { From 512aa8a3c7cd1100d05fc8912cdef485ebfec416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Thu, 8 Dec 2016 17:09:35 +0100 Subject: [PATCH 171/877] Use "::class" syntax on "lib" directory --- lib/Doctrine/ORM/Configuration.php | 10 +- .../ORM/Mapping/Driver/AnnotationDriver.php | 137 +++++++++--------- .../ORM/Mapping/Driver/DatabaseDriver.php | 2 +- lib/Doctrine/ORM/Proxy/ProxyFactory.php | 2 +- lib/Doctrine/ORM/Query/Expr/Andx.php | 8 +- lib/Doctrine/ORM/Query/Expr/Orx.php | 8 +- lib/Doctrine/ORM/Query/Expr/Select.php | 2 +- lib/Doctrine/ORM/Query/Parser.php | 45 +++--- lib/Doctrine/ORM/Tools/EntityGenerator.php | 5 +- .../ORM/Tools/EntityRepositoryGenerator.php | 6 +- .../Tools/Export/ClassMetadataExporter.php | 10 +- .../ORM/Tools/Pagination/Paginator.php | 12 +- 12 files changed, 126 insertions(+), 121 deletions(-) diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index fa1d1dde762..104a4f4b231 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -25,9 +25,11 @@ use Doctrine\Common\Annotations\SimpleAnnotationReader; use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\Cache\Cache as CacheDriver; +use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; +use Doctrine\Common\Persistence\ObjectRepository; use Doctrine\Common\Proxy\AbstractProxyFactory; use Doctrine\ORM\Cache\CacheConfiguration; -use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; +use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\DefaultEntityListenerResolver; use Doctrine\ORM\Mapping\DefaultNamingStrategy; use Doctrine\ORM\Mapping\DefaultQuoteStrategy; @@ -642,7 +644,7 @@ public function setClassMetadataFactoryName($cmfName) public function getClassMetadataFactoryName() { if ( ! isset($this->_attributes['classMetadataFactoryName'])) { - $this->_attributes['classMetadataFactoryName'] = 'Doctrine\ORM\Mapping\ClassMetadataFactory'; + $this->_attributes['classMetadataFactoryName'] = ClassMetadataFactory::class; } return $this->_attributes['classMetadataFactoryName']; @@ -689,7 +691,7 @@ public function setDefaultRepositoryClassName($className) { $reflectionClass = new \ReflectionClass($className); - if ( ! $reflectionClass->implementsInterface('Doctrine\Common\Persistence\ObjectRepository')) { + if ( ! $reflectionClass->implementsInterface(ObjectRepository::class)) { throw ORMException::invalidEntityRepository($className); } @@ -707,7 +709,7 @@ public function getDefaultRepositoryClassName() { return isset($this->_attributes['defaultRepositoryClassName']) ? $this->_attributes['defaultRepositoryClassName'] - : 'Doctrine\ORM\EntityRepository'; + : EntityRepository::class; } /** diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index 0ed36d89568..b5a5b714cbc 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -20,13 +20,12 @@ namespace Doctrine\ORM\Mapping\Driver; use Doctrine\Common\Annotations\AnnotationReader; -use Doctrine\ORM\Mapping\MappingException; -use Doctrine\ORM\Mapping\JoinColumn; -use Doctrine\ORM\Mapping\Column; -use Doctrine\ORM\Mapping\Builder\EntityListenerBuilder; use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver as AbstractAnnotationDriver; use Doctrine\ORM\Events; +use Doctrine\ORM\Mapping; +use Doctrine\ORM\Mapping\Builder\EntityListenerBuilder; +use Doctrine\ORM\Mapping\MappingException; /** * The AnnotationDriver reads the mapping metadata from docblock annotations. @@ -43,8 +42,8 @@ class AnnotationDriver extends AbstractAnnotationDriver * {@inheritDoc} */ protected $entityAnnotationClasses = [ - 'Doctrine\ORM\Mapping\Entity' => 1, - 'Doctrine\ORM\Mapping\MappedSuperclass' => 2, + Mapping\Entity::class => 1, + Mapping\MappedSuperclass::class => 2, ]; /** @@ -74,8 +73,8 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) } // Evaluate Entity annotation - if (isset($classAnnotations['Doctrine\ORM\Mapping\Entity'])) { - $entityAnnot = $classAnnotations['Doctrine\ORM\Mapping\Entity']; + if (isset($classAnnotations[Mapping\Entity::class])) { + $entityAnnot = $classAnnotations[Mapping\Entity::class]; if ($entityAnnot->repositoryClass !== null) { $metadata->setCustomRepositoryClass($entityAnnot->repositoryClass); } @@ -83,20 +82,20 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) if ($entityAnnot->readOnly) { $metadata->markReadOnly(); } - } else if (isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass'])) { - $mappedSuperclassAnnot = $classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass']; + } else if (isset($classAnnotations[Mapping\MappedSuperclass::class])) { + $mappedSuperclassAnnot = $classAnnotations[Mapping\MappedSuperclass::class]; $metadata->setCustomRepositoryClass($mappedSuperclassAnnot->repositoryClass); $metadata->isMappedSuperclass = true; - } else if (isset($classAnnotations['Doctrine\ORM\Mapping\Embeddable'])) { + } else if (isset($classAnnotations[Mapping\Embeddable::class])) { $metadata->isEmbeddedClass = true; } else { throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className); } // Evaluate Table annotation - if (isset($classAnnotations['Doctrine\ORM\Mapping\Table'])) { - $tableAnnot = $classAnnotations['Doctrine\ORM\Mapping\Table']; + if (isset($classAnnotations[Mapping\Table::class])) { + $tableAnnot = $classAnnotations[Mapping\Table::class]; $primaryTable = [ 'name' => $tableAnnot->name, 'schema' => $tableAnnot->schema @@ -146,8 +145,8 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) } // Evaluate @Cache annotation - if (isset($classAnnotations['Doctrine\ORM\Mapping\Cache'])) { - $cacheAnnot = $classAnnotations['Doctrine\ORM\Mapping\Cache']; + if (isset($classAnnotations[Mapping\Cache::class])) { + $cacheAnnot = $classAnnotations[Mapping\Cache::class]; $cacheMap = [ 'region' => $cacheAnnot->region, 'usage' => constant('Doctrine\ORM\Mapping\ClassMetadata::CACHE_USAGE_' . $cacheAnnot->usage), @@ -157,8 +156,8 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) } // Evaluate NamedNativeQueries annotation - if (isset($classAnnotations['Doctrine\ORM\Mapping\NamedNativeQueries'])) { - $namedNativeQueriesAnnot = $classAnnotations['Doctrine\ORM\Mapping\NamedNativeQueries']; + if (isset($classAnnotations[Mapping\NamedNativeQueries::class])) { + $namedNativeQueriesAnnot = $classAnnotations[Mapping\NamedNativeQueries::class]; foreach ($namedNativeQueriesAnnot->value as $namedNativeQuery) { $metadata->addNamedNativeQuery( @@ -173,8 +172,8 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) } // Evaluate SqlResultSetMappings annotation - if (isset($classAnnotations['Doctrine\ORM\Mapping\SqlResultSetMappings'])) { - $sqlResultSetMappingsAnnot = $classAnnotations['Doctrine\ORM\Mapping\SqlResultSetMappings']; + if (isset($classAnnotations[Mapping\SqlResultSetMappings::class])) { + $sqlResultSetMappingsAnnot = $classAnnotations[Mapping\SqlResultSetMappings::class]; foreach ($sqlResultSetMappingsAnnot->value as $resultSetMapping) { $entities = []; @@ -213,15 +212,15 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) } // Evaluate NamedQueries annotation - if (isset($classAnnotations['Doctrine\ORM\Mapping\NamedQueries'])) { - $namedQueriesAnnot = $classAnnotations['Doctrine\ORM\Mapping\NamedQueries']; + if (isset($classAnnotations[Mapping\NamedQueries::class])) { + $namedQueriesAnnot = $classAnnotations[Mapping\NamedQueries::class]; if ( ! is_array($namedQueriesAnnot->value)) { throw new \UnexpectedValueException("@NamedQueries should contain an array of @NamedQuery annotations."); } foreach ($namedQueriesAnnot->value as $namedQuery) { - if ( ! ($namedQuery instanceof \Doctrine\ORM\Mapping\NamedQuery)) { + if ( ! ($namedQuery instanceof Mapping\NamedQuery)) { throw new \UnexpectedValueException("@NamedQueries should contain an array of @NamedQuery annotations."); } $metadata->addNamedQuery( @@ -234,17 +233,17 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) } // Evaluate InheritanceType annotation - if (isset($classAnnotations['Doctrine\ORM\Mapping\InheritanceType'])) { - $inheritanceTypeAnnot = $classAnnotations['Doctrine\ORM\Mapping\InheritanceType']; + if (isset($classAnnotations[Mapping\InheritanceType::class])) { + $inheritanceTypeAnnot = $classAnnotations[Mapping\InheritanceType::class]; $metadata->setInheritanceType( constant('Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceTypeAnnot->value) ); - if ($metadata->inheritanceType != \Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_NONE) { + if ($metadata->inheritanceType != Mapping\ClassMetadata::INHERITANCE_TYPE_NONE) { // Evaluate DiscriminatorColumn annotation - if (isset($classAnnotations['Doctrine\ORM\Mapping\DiscriminatorColumn'])) { - $discrColumnAnnot = $classAnnotations['Doctrine\ORM\Mapping\DiscriminatorColumn']; + if (isset($classAnnotations[Mapping\DiscriminatorColumn::class])) { + $discrColumnAnnot = $classAnnotations[Mapping\DiscriminatorColumn::class]; $metadata->setDiscriminatorColumn( [ @@ -259,8 +258,8 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) } // Evaluate DiscriminatorMap annotation - if (isset($classAnnotations['Doctrine\ORM\Mapping\DiscriminatorMap'])) { - $discrMapAnnot = $classAnnotations['Doctrine\ORM\Mapping\DiscriminatorMap']; + if (isset($classAnnotations[Mapping\DiscriminatorMap::class])) { + $discrMapAnnot = $classAnnotations[Mapping\DiscriminatorMap::class]; $metadata->setDiscriminatorMap($discrMapAnnot->value); } } @@ -268,8 +267,8 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Evaluate DoctrineChangeTrackingPolicy annotation - if (isset($classAnnotations['Doctrine\ORM\Mapping\ChangeTrackingPolicy'])) { - $changeTrackingAnnot = $classAnnotations['Doctrine\ORM\Mapping\ChangeTrackingPolicy']; + if (isset($classAnnotations[Mapping\ChangeTrackingPolicy::class])) { + $changeTrackingAnnot = $classAnnotations[Mapping\ChangeTrackingPolicy::class]; $metadata->setChangeTrackingPolicy(constant('Doctrine\ORM\Mapping\ClassMetadata::CHANGETRACKING_' . $changeTrackingAnnot->value)); } @@ -290,7 +289,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $mapping['fieldName'] = $property->getName(); // Evaluate @Cache annotation - if (($cacheAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Cache')) !== null) { + if (($cacheAnnot = $this->reader->getPropertyAnnotation($property, Mapping\Cache::class)) !== null) { $mapping['cache'] = $metadata->getAssociationCacheDefaults( $mapping['fieldName'], [ @@ -302,9 +301,9 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Check for JoinColumn/JoinColumns annotations $joinColumns = []; - if ($joinColumnAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinColumn')) { + if ($joinColumnAnnot = $this->reader->getPropertyAnnotation($property, Mapping\JoinColumn::class)) { $joinColumns[] = $this->joinColumnToArray($joinColumnAnnot); - } else if ($joinColumnsAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinColumns')) { + } else if ($joinColumnsAnnot = $this->reader->getPropertyAnnotation($property, Mapping\JoinColumns::class)) { foreach ($joinColumnsAnnot->value as $joinColumn) { $joinColumns[] = $this->joinColumnToArray($joinColumn); } @@ -312,29 +311,29 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Field can only be annotated with one of: // @Column, @OneToOne, @OneToMany, @ManyToOne, @ManyToMany - if ($columnAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Column')) { + if ($columnAnnot = $this->reader->getPropertyAnnotation($property, Mapping\Column::class)) { if ($columnAnnot->type == null) { throw MappingException::propertyTypeIsRequired($className, $property->getName()); } $mapping = $this->columnToArray($property->getName(), $columnAnnot); - if ($idAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) { + if ($idAnnot = $this->reader->getPropertyAnnotation($property, Mapping\Id::class)) { $mapping['id'] = true; } - if ($generatedValueAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\GeneratedValue')) { + if ($generatedValueAnnot = $this->reader->getPropertyAnnotation($property, Mapping\GeneratedValue::class)) { $metadata->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_' . $generatedValueAnnot->strategy)); } - if ($this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Version')) { + if ($this->reader->getPropertyAnnotation($property, Mapping\Version::class)) { $metadata->setVersionMapping($mapping); } $metadata->mapField($mapping); // Check for SequenceGenerator/TableGenerator definition - if ($seqGeneratorAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\SequenceGenerator')) { + if ($seqGeneratorAnnot = $this->reader->getPropertyAnnotation($property, Mapping\SequenceGenerator::class)) { $metadata->setSequenceGeneratorDefinition( [ 'sequenceName' => $seqGeneratorAnnot->sequenceName, @@ -344,15 +343,15 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) ); } else if ($this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\TableGenerator')) { throw MappingException::tableIdGeneratorNotImplemented($className); - } else if ($customGeneratorAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\CustomIdGenerator')) { + } else if ($customGeneratorAnnot = $this->reader->getPropertyAnnotation($property, Mapping\CustomIdGenerator::class)) { $metadata->setCustomGeneratorDefinition( [ 'class' => $customGeneratorAnnot->class ] ); } - } else if ($oneToOneAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OneToOne')) { - if ($idAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) { + } else if ($oneToOneAnnot = $this->reader->getPropertyAnnotation($property, Mapping\OneToOne::class)) { + if ($idAnnot = $this->reader->getPropertyAnnotation($property, Mapping\Id::class)) { $mapping['id'] = true; } @@ -364,7 +363,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $mapping['orphanRemoval'] = $oneToOneAnnot->orphanRemoval; $mapping['fetch'] = $this->getFetchMode($className, $oneToOneAnnot->fetch); $metadata->mapOneToOne($mapping); - } else if ($oneToManyAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OneToMany')) { + } else if ($oneToManyAnnot = $this->reader->getPropertyAnnotation($property, Mapping\OneToMany::class)) { $mapping['mappedBy'] = $oneToManyAnnot->mappedBy; $mapping['targetEntity'] = $oneToManyAnnot->targetEntity; $mapping['cascade'] = $oneToManyAnnot->cascade; @@ -372,13 +371,13 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $mapping['orphanRemoval'] = $oneToManyAnnot->orphanRemoval; $mapping['fetch'] = $this->getFetchMode($className, $oneToManyAnnot->fetch); - if ($orderByAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OrderBy')) { + if ($orderByAnnot = $this->reader->getPropertyAnnotation($property, Mapping\OrderBy::class)) { $mapping['orderBy'] = $orderByAnnot->value; } $metadata->mapOneToMany($mapping); - } else if ($manyToOneAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\ManyToOne')) { - if ($idAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) { + } else if ($manyToOneAnnot = $this->reader->getPropertyAnnotation($property, Mapping\ManyToOne::class)) { + if ($idAnnot = $this->reader->getPropertyAnnotation($property, Mapping\Id::class)) { $mapping['id'] = true; } @@ -388,10 +387,10 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $mapping['targetEntity'] = $manyToOneAnnot->targetEntity; $mapping['fetch'] = $this->getFetchMode($className, $manyToOneAnnot->fetch); $metadata->mapManyToOne($mapping); - } else if ($manyToManyAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\ManyToMany')) { + } else if ($manyToManyAnnot = $this->reader->getPropertyAnnotation($property, Mapping\ManyToMany::class)) { $joinTable = []; - if ($joinTableAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\JoinTable')) { + if ($joinTableAnnot = $this->reader->getPropertyAnnotation($property, Mapping\JoinTable::class)) { $joinTable = [ 'name' => $joinTableAnnot->name, 'schema' => $joinTableAnnot->schema @@ -415,12 +414,12 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $mapping['orphanRemoval'] = $manyToManyAnnot->orphanRemoval; $mapping['fetch'] = $this->getFetchMode($className, $manyToManyAnnot->fetch); - if ($orderByAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OrderBy')) { + if ($orderByAnnot = $this->reader->getPropertyAnnotation($property, Mapping\OrderBy::class)) { $mapping['orderBy'] = $orderByAnnot->value; } $metadata->mapManyToMany($mapping); - } else if ($embeddedAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Embedded')) { + } else if ($embeddedAnnot = $this->reader->getPropertyAnnotation($property, Mapping\Embedded::class)) { $mapping['class'] = $embeddedAnnot->class; $mapping['columnPrefix'] = $embeddedAnnot->columnPrefix; @@ -429,8 +428,8 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) } // Evaluate AssociationOverrides annotation - if (isset($classAnnotations['Doctrine\ORM\Mapping\AssociationOverrides'])) { - $associationOverridesAnnot = $classAnnotations['Doctrine\ORM\Mapping\AssociationOverrides']; + if (isset($classAnnotations[Mapping\AssociationOverrides::class])) { + $associationOverridesAnnot = $classAnnotations[Mapping\AssociationOverrides::class]; foreach ($associationOverridesAnnot->value as $associationOverride) { $override = []; @@ -476,8 +475,8 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) } // Evaluate AttributeOverrides annotation - if (isset($classAnnotations['Doctrine\ORM\Mapping\AttributeOverrides'])) { - $attributeOverridesAnnot = $classAnnotations['Doctrine\ORM\Mapping\AttributeOverrides']; + if (isset($classAnnotations[Mapping\AttributeOverrides::class])) { + $attributeOverridesAnnot = $classAnnotations[Mapping\AttributeOverrides::class]; foreach ($attributeOverridesAnnot->value as $attributeOverrideAnnot) { $attributeOverride = $this->columnToArray($attributeOverrideAnnot->name, $attributeOverrideAnnot->column); @@ -487,8 +486,8 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) } // Evaluate EntityListeners annotation - if (isset($classAnnotations['Doctrine\ORM\Mapping\EntityListeners'])) { - $entityListenersAnnot = $classAnnotations['Doctrine\ORM\Mapping\EntityListeners']; + if (isset($classAnnotations[Mapping\EntityListeners::class])) { + $entityListenersAnnot = $classAnnotations[Mapping\EntityListeners::class]; foreach ($entityListenersAnnot->value as $item) { $listenerClassName = $metadata->fullyQualifiedClassName($item); @@ -519,7 +518,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) } // Evaluate @HasLifecycleCallbacks annotation - if (isset($classAnnotations['Doctrine\ORM\Mapping\HasLifecycleCallbacks'])) { + if (isset($classAnnotations[Mapping\HasLifecycleCallbacks::class])) { /* @var $method \ReflectionMethod */ foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { foreach ($this->getMethodCallbacks($method) as $value) { @@ -561,35 +560,35 @@ private function getMethodCallbacks(\ReflectionMethod $method) $annotations = $this->reader->getMethodAnnotations($method); foreach ($annotations as $annot) { - if ($annot instanceof \Doctrine\ORM\Mapping\PrePersist) { + if ($annot instanceof Mapping\PrePersist) { $callbacks[] = [$method->name, Events::prePersist]; } - if ($annot instanceof \Doctrine\ORM\Mapping\PostPersist) { + if ($annot instanceof Mapping\PostPersist) { $callbacks[] = [$method->name, Events::postPersist]; } - if ($annot instanceof \Doctrine\ORM\Mapping\PreUpdate) { + if ($annot instanceof Mapping\PreUpdate) { $callbacks[] = [$method->name, Events::preUpdate]; } - if ($annot instanceof \Doctrine\ORM\Mapping\PostUpdate) { + if ($annot instanceof Mapping\PostUpdate) { $callbacks[] = [$method->name, Events::postUpdate]; } - if ($annot instanceof \Doctrine\ORM\Mapping\PreRemove) { + if ($annot instanceof Mapping\PreRemove) { $callbacks[] = [$method->name, Events::preRemove]; } - if ($annot instanceof \Doctrine\ORM\Mapping\PostRemove) { + if ($annot instanceof Mapping\PostRemove) { $callbacks[] = [$method->name, Events::postRemove]; } - if ($annot instanceof \Doctrine\ORM\Mapping\PostLoad) { + if ($annot instanceof Mapping\PostLoad) { $callbacks[] = [$method->name, Events::postLoad]; } - if ($annot instanceof \Doctrine\ORM\Mapping\PreFlush) { + if ($annot instanceof Mapping\PreFlush) { $callbacks[] = [$method->name, Events::preFlush]; } } @@ -600,10 +599,10 @@ private function getMethodCallbacks(\ReflectionMethod $method) /** * Parse the given JoinColumn as array * - * @param JoinColumn $joinColumn + * @param Mapping\JoinColumn $joinColumn * @return array */ - private function joinColumnToArray(JoinColumn $joinColumn) + private function joinColumnToArray(Mapping\JoinColumn $joinColumn) { return [ 'name' => $joinColumn->name, @@ -619,11 +618,11 @@ private function joinColumnToArray(JoinColumn $joinColumn) * Parse the given Column as array * * @param string $fieldName - * @param Column $column + * @param Mapping\Column $column * * @return array */ - private function columnToArray($fieldName, Column $column) + private function columnToArray($fieldName, Mapping\Column $column) { $mapping = [ 'fieldName' => $fieldName, diff --git a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php index 9389feb81ec..41c740ec4e5 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php @@ -496,7 +496,7 @@ private function getTableForeignKeys(Table $table) } /** - * Retreive schema table definition primary keys. + * Retrieve schema table definition primary keys. * * @param \Doctrine\DBAL\Schema\Table $table * diff --git a/lib/Doctrine/ORM/Proxy/ProxyFactory.php b/lib/Doctrine/ORM/Proxy/ProxyFactory.php index 58dfc0932e5..6bc7dc5272a 100644 --- a/lib/Doctrine/ORM/Proxy/ProxyFactory.php +++ b/lib/Doctrine/ORM/Proxy/ProxyFactory.php @@ -76,7 +76,7 @@ public function __construct(EntityManagerInterface $em, $proxyDir, $proxyNs, $au { $proxyGenerator = new ProxyGenerator($proxyDir, $proxyNs); - $proxyGenerator->setPlaceholder('baseProxyInterface', 'Doctrine\ORM\Proxy\Proxy'); + $proxyGenerator->setPlaceholder('baseProxyInterface', Proxy::class); parent::__construct($proxyGenerator, $em->getMetadataFactory(), $autoGenerate); $this->em = $em; diff --git a/lib/Doctrine/ORM/Query/Expr/Andx.php b/lib/Doctrine/ORM/Query/Expr/Andx.php index cc64ab1a85a..dd91916a671 100644 --- a/lib/Doctrine/ORM/Query/Expr/Andx.php +++ b/lib/Doctrine/ORM/Query/Expr/Andx.php @@ -39,10 +39,10 @@ class Andx extends Composite * @var array */ protected $allowedClasses = [ - 'Doctrine\ORM\Query\Expr\Comparison', - 'Doctrine\ORM\Query\Expr\Func', - 'Doctrine\ORM\Query\Expr\Orx', - 'Doctrine\ORM\Query\Expr\Andx', + Comparison::class, + Func::class, + Orx::class, + Andx::class, ]; /** diff --git a/lib/Doctrine/ORM/Query/Expr/Orx.php b/lib/Doctrine/ORM/Query/Expr/Orx.php index 35f88e831cf..d36abfa922c 100644 --- a/lib/Doctrine/ORM/Query/Expr/Orx.php +++ b/lib/Doctrine/ORM/Query/Expr/Orx.php @@ -39,10 +39,10 @@ class Orx extends Composite * @var array */ protected $allowedClasses = [ - 'Doctrine\ORM\Query\Expr\Comparison', - 'Doctrine\ORM\Query\Expr\Func', - 'Doctrine\ORM\Query\Expr\Andx', - 'Doctrine\ORM\Query\Expr\Orx', + Comparison::class, + Func::class, + Andx::class, + Orx::class, ]; /** diff --git a/lib/Doctrine/ORM/Query/Expr/Select.php b/lib/Doctrine/ORM/Query/Expr/Select.php index 00bdc94f30a..8ab5153f1f6 100644 --- a/lib/Doctrine/ORM/Query/Expr/Select.php +++ b/lib/Doctrine/ORM/Query/Expr/Select.php @@ -43,7 +43,7 @@ class Select extends Base /** * @var array */ - protected $allowedClasses = ['Doctrine\ORM\Query\Expr\Func']; + protected $allowedClasses = [Func::class]; /** * @return array diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index ae8fcd3ebd7..65b8374bdb1 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -19,8 +19,9 @@ namespace Doctrine\ORM\Query; -use Doctrine\ORM\Query; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Query; +use Doctrine\ORM\Query\AST\Functions; /** * An LL(*) recursive-descent parser for the context-free grammar of the Doctrine Query Language. @@ -41,12 +42,12 @@ class Parser * @var array */ private static $_STRING_FUNCTIONS = [ - 'concat' => 'Doctrine\ORM\Query\AST\Functions\ConcatFunction', - 'substring' => 'Doctrine\ORM\Query\AST\Functions\SubstringFunction', - 'trim' => 'Doctrine\ORM\Query\AST\Functions\TrimFunction', - 'lower' => 'Doctrine\ORM\Query\AST\Functions\LowerFunction', - 'upper' => 'Doctrine\ORM\Query\AST\Functions\UpperFunction', - 'identity' => 'Doctrine\ORM\Query\AST\Functions\IdentityFunction', + 'concat' => Functions\ConcatFunction::class, + 'substring' => Functions\SubstringFunction::class, + 'trim' => Functions\TrimFunction::class, + 'lower' => Functions\LowerFunction::class, + 'upper' => Functions\UpperFunction::class, + 'identity' => Functions\IdentityFunction::class, ]; /** @@ -55,15 +56,15 @@ class Parser * @var array */ private static $_NUMERIC_FUNCTIONS = [ - 'length' => 'Doctrine\ORM\Query\AST\Functions\LengthFunction', - 'locate' => 'Doctrine\ORM\Query\AST\Functions\LocateFunction', - 'abs' => 'Doctrine\ORM\Query\AST\Functions\AbsFunction', - 'sqrt' => 'Doctrine\ORM\Query\AST\Functions\SqrtFunction', - 'mod' => 'Doctrine\ORM\Query\AST\Functions\ModFunction', - 'size' => 'Doctrine\ORM\Query\AST\Functions\SizeFunction', - 'date_diff' => 'Doctrine\ORM\Query\AST\Functions\DateDiffFunction', - 'bit_and' => 'Doctrine\ORM\Query\AST\Functions\BitAndFunction', - 'bit_or' => 'Doctrine\ORM\Query\AST\Functions\BitOrFunction', + 'length' => Functions\LengthFunction::class, + 'locate' => Functions\LocateFunction::class, + 'abs' => Functions\AbsFunction::class, + 'sqrt' => Functions\SqrtFunction::class, + 'mod' => Functions\ModFunction::class, + 'size' => Functions\SizeFunction::class, + 'date_diff' => Functions\DateDiffFunction::class, + 'bit_and' => Functions\BitAndFunction::class, + 'bit_or' => Functions\BitOrFunction::class, ]; /** @@ -72,11 +73,11 @@ class Parser * @var array */ private static $_DATETIME_FUNCTIONS = [ - 'current_date' => 'Doctrine\ORM\Query\AST\Functions\CurrentDateFunction', - 'current_time' => 'Doctrine\ORM\Query\AST\Functions\CurrentTimeFunction', - 'current_timestamp' => 'Doctrine\ORM\Query\AST\Functions\CurrentTimestampFunction', - 'date_add' => 'Doctrine\ORM\Query\AST\Functions\DateAddFunction', - 'date_sub' => 'Doctrine\ORM\Query\AST\Functions\DateSubFunction', + 'current_date' => Functions\CurrentDateFunction::class, + 'current_time' => Functions\CurrentTimeFunction::class, + 'current_timestamp' => Functions\CurrentTimestampFunction::class, + 'date_add' => Functions\DateAddFunction::class, + 'date_sub' => Functions\DateSubFunction::class, ]; /* @@ -396,7 +397,7 @@ public function parse() $this->queryComponents = $treeWalkerChain->getQueryComponents(); } - $outputWalkerClass = $this->customOutputWalker ?: __NAMESPACE__ . '\SqlWalker'; + $outputWalkerClass = $this->customOutputWalker ?: SqlWalker::class; $outputWalker = new $outputWalkerClass($this->query, $this->parserResult, $this->queryComponents); // Assign an SQL executor to the parser result diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 03e96481742..61143634371 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -19,9 +19,10 @@ namespace Doctrine\ORM\Tools; -use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\Common\Collections\Collection; use Doctrine\Common\Util\Inflector; use Doctrine\DBAL\Types\Type; +use Doctrine\ORM\Mapping\ClassMetadataInfo; /** * Generic class used to generate PHP5 entity classes from ClassMetadataInfo instances. @@ -1216,7 +1217,7 @@ protected function generateEntityStubMethods(ClassMetadataInfo $metadata) if ($code = $this->generateEntityStubMethod($metadata, 'remove', $associationMapping['fieldName'], $associationMapping['targetEntity'])) { $methods[] = $code; } - if ($code = $this->generateEntityStubMethod($metadata, 'get', $associationMapping['fieldName'], 'Doctrine\Common\Collections\Collection')) { + if ($code = $this->generateEntityStubMethod($metadata, 'get', $associationMapping['fieldName'], Collection::class)) { $methods[] = $code; } } diff --git a/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php b/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php index 927738cba28..dbfcbc6d49f 100644 --- a/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php @@ -19,6 +19,8 @@ namespace Doctrine\ORM\Tools; +use Doctrine\ORM\EntityRepository; + /** * Class to generate entity repository classes * @@ -116,14 +118,14 @@ private function generateEntityRepositoryNamespace($fullClassName) /** * @param string $fullClassName - * + * * @return string $repositoryName */ private function generateEntityRepositoryName($fullClassName) { $namespace = $this->getClassNamespace($fullClassName); - $repositoryName = $this->repositoryName ?: 'Doctrine\ORM\EntityRepository'; + $repositoryName = $this->repositoryName ?: EntityRepository::class; if ($namespace && $repositoryName[0] !== '\\') { $repositoryName = '\\' . $repositoryName; diff --git a/lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php b/lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php index 94c781bef08..ab44263cdf4 100644 --- a/lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php @@ -33,11 +33,11 @@ class ClassMetadataExporter * @var array */ private static $_exporterDrivers = [ - 'xml' => 'Doctrine\ORM\Tools\Export\Driver\XmlExporter', - 'yaml' => 'Doctrine\ORM\Tools\Export\Driver\YamlExporter', - 'yml' => 'Doctrine\ORM\Tools\Export\Driver\YamlExporter', - 'php' => 'Doctrine\ORM\Tools\Export\Driver\PhpExporter', - 'annotation' => 'Doctrine\ORM\Tools\Export\Driver\AnnotationExporter' + 'xml' => Driver\XmlExporter::class, + 'yaml' => Driver\YamlExporter::class, + 'yml' => Driver\YamlExporter::class, + 'php' => Driver\PhpExporter::class, + 'annotation' => Driver\AnnotationExporter::class ]; /** diff --git a/lib/Doctrine/ORM/Tools/Pagination/Paginator.php b/lib/Doctrine/ORM/Tools/Pagination/Paginator.php index aa2a22365da..250df071f92 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/Paginator.php +++ b/lib/Doctrine/ORM/Tools/Pagination/Paginator.php @@ -142,9 +142,9 @@ public function getIterator() $subQuery = $this->cloneQuery($this->query); if ($this->useOutputWalker($subQuery)) { - $subQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $subQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); } else { - $this->appendTreeWalker($subQuery, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker'); + $this->appendTreeWalker($subQuery, LimitSubqueryWalker::class); } $subQuery->setFirstResult($offset)->setMaxResults($length); @@ -154,10 +154,10 @@ public function getIterator() $whereInQuery = $this->cloneQuery($this->query); // don't do this for an empty id array if (count($ids) === 0) { - return new \ArrayIterator(array()); + return new \ArrayIterator([]); } - $this->appendTreeWalker($whereInQuery, 'Doctrine\ORM\Tools\Pagination\WhereInWalker'); + $this->appendTreeWalker($whereInQuery, WhereInWalker::class); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, count($ids)); $whereInQuery->setFirstResult(null)->setMaxResults(null); $whereInQuery->setParameter(WhereInWalker::PAGINATOR_ID_ALIAS, $ids); @@ -252,10 +252,10 @@ private function getCountQuery() $rsm = new ResultSetMapping(); $rsm->addScalarResult($platform->getSQLResultCasing('dctrn_count'), 'count'); - $countQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\CountOutputWalker'); + $countQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, CountOutputWalker::class); $countQuery->setResultSetMapping($rsm); } else { - $this->appendTreeWalker($countQuery, 'Doctrine\ORM\Tools\Pagination\CountWalker'); + $this->appendTreeWalker($countQuery, CountWalker::class); } $countQuery->setFirstResult(null)->setMaxResults(null); From fda6fdd9fba9034298fedf4afdf11113478b0ac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Thu, 8 Dec 2016 18:01:04 +0100 Subject: [PATCH 172/877] Use "::class" syntax on "tests" directory --- .../Doctrine/Tests/Models/CMS/CmsAddress.php | 6 +- tests/Doctrine/Tests/Models/CMS/CmsUser.php | 14 +- .../Tests/Models/Cache/Attraction.php | 2 +- .../Models/Cache/AttractionContactInfo.php | 2 +- .../Tests/Models/Cache/AttractionInfo.php | 2 +- .../Models/Cache/AttractionLocationInfo.php | 2 +- tests/Doctrine/Tests/Models/Cache/City.php | 2 +- tests/Doctrine/Tests/Models/Cache/Country.php | 2 +- tests/Doctrine/Tests/Models/Cache/Flight.php | 2 +- tests/Doctrine/Tests/Models/Cache/State.php | 2 +- tests/Doctrine/Tests/Models/Cache/Travel.php | 2 +- .../Tests/Models/Cache/TravelerProfile.php | 2 +- .../Models/Cache/TravelerProfileInfo.php | 2 +- .../Tests/Models/Company/CompanyPerson.php | 4 +- .../Tests/Models/DDC3597/DDC3597Image.php | 2 +- .../Tests/Models/DDC3597/DDC3597Media.php | 2 +- .../Tests/Models/DDC3597/DDC3597Root.php | 2 +- .../Tests/Models/DDC3699/DDC3699Child.php | 2 +- .../Tests/Models/DDC869/DDC869Payment.php | 2 +- .../Tests/Models/Generic/DateTimeModel.php | 2 +- .../CompositeToOneKeyState.php | 2 +- .../Tests/ORM/Cache/CacheConfigTest.php | 3 +- .../Tests/ORM/Cache/CacheLoggerChainTest.php | 4 +- .../ORM/Cache/DefaultCacheFactoryTest.php | 94 +++--- .../Tests/ORM/Cache/DefaultCacheTest.php | 84 ++--- .../Cache/DefaultCollectionHydratorTest.php | 34 +- .../ORM/Cache/DefaultEntityHydratorTest.php | 54 +-- .../Tests/ORM/Cache/DefaultQueryCacheTest.php | 189 +++++------ .../Tests/ORM/Cache/FileLockRegionTest.php | 20 +- .../AbstractCollectionPersisterTest.php | 12 +- ...ReadWriteCachedCollectionPersisterTest.php | 32 +- .../Entity/AbstractEntityPersisterTest.php | 30 +- ...rictReadWriteCachedEntityPersisterTest.php | 10 +- .../ReadWriteCachedEntityPersisterTest.php | 24 +- .../ORM/Cache/StatisticsCacheLoggerTest.php | 8 +- .../Tests/ORM/CommitOrderCalculatorTest.php | 14 +- .../Doctrine/Tests/ORM/ConfigurationTest.php | 43 +-- .../Decorator/EntityManagerDecoratorTest.php | 6 +- .../Doctrine/Tests/ORM/EntityManagerTest.php | 35 +- .../Tests/ORM/EntityNotFoundExceptionTest.php | 7 +- .../Functional/AdvancedAssociationTest.php | 32 +- .../ORM/Functional/BasicFunctionalTest.php | 44 +-- .../ORM/Functional/CascadeRemoveOrderTest.php | 12 +- .../Functional/ClassTableInheritanceTest.php | 62 ++-- .../Functional/ClassTableInheritanceTest2.php | 19 +- .../Functional/CompositePrimaryKeyTest.php | 20 +- ...ompositePrimaryKeyWithAssociationsTest.php | 4 +- .../ORM/Functional/CustomIdObjectTypeTest.php | 10 +- .../ORM/Functional/DefaultValuesTest.php | 11 +- .../ORM/Functional/DetachedEntityTest.php | 17 +- .../ORM/Functional/EntityListenersTest.php | 110 ++---- .../EntityRepositoryCriteriaTest.php | 15 +- .../ORM/Functional/EntityRepositoryTest.php | 189 ++++++----- .../Functional/ExtraLazyCollectionTest.php | 188 +++++------ .../ORM/Functional/IndexByAssociationTest.php | 6 +- .../JoinedTableCompositeKeyTest.php | 3 +- .../ORM/Functional/LifecycleCallbackTest.php | 61 +--- .../Functional/Locking/GearmanLockTest.php | 34 +- .../ORM/Functional/Locking/OptimisticTest.php | 14 +- .../ManyToManyBasicAssociationTest.php | 21 +- ...ManyToManyBidirectionalAssociationTest.php | 20 +- ...nyToManySelfReferentialAssociationTest.php | 10 +- ...anyToManyUnidirectionalAssociationTest.php | 10 +- .../ORM/Functional/MappedSuperclassTest.php | 8 +- .../Functional/MergeCompositeToOneKeyTest.php | 8 +- .../Tests/ORM/Functional/MergeProxiesTest.php | 25 +- .../Functional/MergeSharedEntitiesTest.php | 4 +- .../Tests/ORM/Functional/NativeQueryTest.php | 157 ++++----- .../Tests/ORM/Functional/NewOperatorTest.php | 170 +++++----- .../Tests/ORM/Functional/NotifyPolicyTest.php | 14 +- .../OneToManyBidirectionalAssociationTest.php | 40 +-- .../Functional/OneToManyOrphanRemovalTest.php | 14 +- ...neToManySelfReferentialAssociationTest.php | 12 +- .../OneToOneBidirectionalAssociationTest.php | 21 +- .../Functional/OneToOneEagerLoadingTest.php | 21 +- .../Functional/OneToOneOrphanRemovalTest.php | 10 +- ...OneToOneSelfReferentialAssociationTest.php | 17 +- .../OneToOneSingleTableInheritanceTest.php | 12 +- .../OneToOneUnidirectionalAssociationTest.php | 10 +- .../ORM/Functional/OrderedCollectionTest.php | 8 +- ...edJoinedTableInheritanceCollectionTest.php | 6 +- .../Tests/ORM/Functional/PaginationTest.php | 11 +- .../PersistentCollectionCriteriaTest.php | 8 +- .../Functional/PersistentCollectionTest.php | 12 +- .../ORM/Functional/PersistentObjectTest.php | 8 +- .../ORM/Functional/PostLoadEventTest.php | 24 +- .../Functional/ProxiesLikeEntitiesTest.php | 58 ++-- .../Tests/ORM/Functional/QueryCacheTest.php | 5 +- .../Tests/ORM/Functional/QueryTest.php | 39 +-- .../Tests/ORM/Functional/ReadOnlyTest.php | 5 +- .../ORM/Functional/ReferenceProxyTest.php | 54 +-- .../Tests/ORM/Functional/ResultCacheTest.php | 2 +- .../Tests/ORM/Functional/SQLFilterTest.php | 153 ++++----- .../SchemaTool/CompanySchemaTest.php | 3 +- .../ORM/Functional/SchemaTool/DBAL483Test.php | 2 +- .../ORM/Functional/SchemaTool/DDC214Test.php | 29 +- .../SchemaTool/MySqlSchemaToolTest.php | 19 +- .../SchemaTool/PostgreSqlSchemaToolTest.php | 23 +- ...econdLevelCacheCompositePrimaryKeyTest.php | 80 ++--- ...ompositePrimaryKeyWithAssociationsTest.php | 6 +- .../SecondLevelCacheConcurrentTest.php | 46 +-- .../SecondLevelCacheCriteriaTest.php | 31 +- ...econdLevelCacheExtraLazyCollectionTest.php | 26 +- ...condLevelCacheJoinTableInheritanceTest.php | 83 ++--- .../SecondLevelCacheManyToManyTest.php | 132 ++++---- .../SecondLevelCacheManyToOneTest.php | 131 +++---- .../SecondLevelCacheOneToManyTest.php | 195 +++++------ .../SecondLevelCacheOneToOneTest.php | 163 ++++----- .../SecondLevelCacheQueryCacheTest.php | 319 +++++++++--------- .../SecondLevelCacheRepositoryTest.php | 105 +++--- ...ndLevelCacheSingleTableInheritanceTest.php | 101 +++--- .../ORM/Functional/SecondLevelCacheTest.php | 148 ++++---- .../SequenceEmulatedIdentityStrategyTest.php | 2 +- .../ORM/Functional/SequenceGeneratorTest.php | 2 +- .../SingleTableCompositeKeyTest.php | 8 +- .../Functional/SingleTableInheritanceTest.php | 74 ++-- .../StandardEntityPersisterTest.php | 19 +- .../ORM/Functional/Ticket/DDC1041Test.php | 10 +- .../ORM/Functional/Ticket/DDC1043Test.php | 2 +- .../ORM/Functional/Ticket/DDC1050Test.php | 2 +- .../ORM/Functional/Ticket/DDC1080Test.php | 8 +- .../ORM/Functional/Ticket/DDC1113Test.php | 8 +- .../ORM/Functional/Ticket/DDC1129Test.php | 6 +- .../ORM/Functional/Ticket/DDC1151Test.php | 4 +- .../ORM/Functional/Ticket/DDC1163Test.php | 26 +- .../ORM/Functional/Ticket/DDC117Test.php | 108 +++--- .../ORM/Functional/Ticket/DDC1181Test.php | 6 +- .../ORM/Functional/Ticket/DDC1193Test.php | 6 +- .../ORM/Functional/Ticket/DDC1209Test.php | 6 +- .../ORM/Functional/Ticket/DDC1225Test.php | 6 +- .../ORM/Functional/Ticket/DDC1228Test.php | 12 +- .../ORM/Functional/Ticket/DDC1238Test.php | 8 +- .../ORM/Functional/Ticket/DDC1250Test.php | 4 +- .../ORM/Functional/Ticket/DDC1276Test.php | 4 +- .../ORM/Functional/Ticket/DDC1300Test.php | 4 +- .../ORM/Functional/Ticket/DDC1301Test.php | 31 +- .../ORM/Functional/Ticket/DDC1335Test.php | 10 +- .../ORM/Functional/Ticket/DDC1360Test.php | 2 +- .../ORM/Functional/Ticket/DDC1383Test.php | 4 +- .../ORM/Functional/Ticket/DDC1392Test.php | 6 +- .../ORM/Functional/Ticket/DDC1400Test.php | 8 +- .../ORM/Functional/Ticket/DDC1404Test.php | 6 +- .../ORM/Functional/Ticket/DDC142Test.php | 25 +- .../ORM/Functional/Ticket/DDC1430Test.php | 10 +- .../ORM/Functional/Ticket/DDC1436Test.php | 12 +- .../ORM/Functional/Ticket/DDC144Test.php | 4 +- .../ORM/Functional/Ticket/DDC1452Test.php | 17 +- .../ORM/Functional/Ticket/DDC1454Test.php | 4 +- .../ORM/Functional/Ticket/DDC1458Test.php | 6 +- .../ORM/Functional/Ticket/DDC1461Test.php | 4 +- .../ORM/Functional/Ticket/DDC1509Test.php | 6 +- .../ORM/Functional/Ticket/DDC1514Test.php | 6 +- .../ORM/Functional/Ticket/DDC1515Test.php | 8 +- .../ORM/Functional/Ticket/DDC1526Test.php | 2 +- .../ORM/Functional/Ticket/DDC1545Test.php | 14 +- .../ORM/Functional/Ticket/DDC1548Test.php | 8 +- .../ORM/Functional/Ticket/DDC1595Test.php | 8 +- .../ORM/Functional/Ticket/DDC1654Test.php | 14 +- .../ORM/Functional/Ticket/DDC1655Test.php | 10 +- .../ORM/Functional/Ticket/DDC1685Test.php | 4 +- .../ORM/Functional/Ticket/DDC168Test.php | 10 +- .../ORM/Functional/Ticket/DDC1690Test.php | 23 +- .../ORM/Functional/Ticket/DDC1707Test.php | 6 +- .../ORM/Functional/Ticket/DDC1719Test.php | 24 +- .../ORM/Functional/Ticket/DDC1734Test.php | 7 +- .../ORM/Functional/Ticket/DDC1757Test.php | 4 +- .../ORM/Functional/Ticket/DDC1778Test.php | 10 +- .../ORM/Functional/Ticket/DDC1787Test.php | 4 +- .../ORM/Functional/Ticket/DDC1843Test.php | 51 +-- .../ORM/Functional/Ticket/DDC1884Test.php | 16 +- .../ORM/Functional/Ticket/DDC1885Test.php | 57 ++-- .../ORM/Functional/Ticket/DDC1925Test.php | 4 +- .../ORM/Functional/Ticket/DDC192Test.php | 4 +- .../ORM/Functional/Ticket/DDC1995Test.php | 18 +- .../ORM/Functional/Ticket/DDC1998Test.php | 10 +- .../ORM/Functional/Ticket/DDC199Test.php | 12 +- .../ORM/Functional/Ticket/DDC2012Test.php | 10 +- .../ORM/Functional/Ticket/DDC2074Test.php | 6 +- .../ORM/Functional/Ticket/DDC2090Test.php | 17 +- .../ORM/Functional/Ticket/DDC2106Test.php | 4 +- .../ORM/Functional/Ticket/DDC211Test.php | 4 +- .../ORM/Functional/Ticket/DDC2138Test.php | 10 +- .../ORM/Functional/Ticket/DDC2175Test.php | 2 +- .../ORM/Functional/Ticket/DDC2182Test.php | 4 +- .../ORM/Functional/Ticket/DDC2214Test.php | 6 +- .../ORM/Functional/Ticket/DDC2224Test.php | 2 +- .../ORM/Functional/Ticket/DDC2230Test.php | 15 +- .../ORM/Functional/Ticket/DDC2231Test.php | 5 +- .../ORM/Functional/Ticket/DDC2252Test.php | 25 +- .../ORM/Functional/Ticket/DDC2256Test.php | 6 +- .../ORM/Functional/Ticket/DDC2306Test.php | 17 +- .../ORM/Functional/Ticket/DDC2346Test.php | 8 +- .../ORM/Functional/Ticket/DDC2350Test.php | 6 +- .../ORM/Functional/Ticket/DDC2359Test.php | 2 +- .../ORM/Functional/Ticket/DDC237Test.php | 14 +- .../ORM/Functional/Ticket/DDC2409Test.php | 6 +- .../ORM/Functional/Ticket/DDC2415Test.php | 16 +- .../ORM/Functional/Ticket/DDC2494Test.php | 12 +- .../ORM/Functional/Ticket/DDC2519Test.php | 25 +- .../ORM/Functional/Ticket/DDC2575Test.php | 8 +- .../ORM/Functional/Ticket/DDC2579Test.php | 12 +- .../ORM/Functional/Ticket/DDC258Test.php | 14 +- .../ORM/Functional/Ticket/DDC2660Test.php | 14 +- .../ORM/Functional/Ticket/DDC2692Test.php | 2 +- .../ORM/Functional/Ticket/DDC2759Test.php | 10 +- .../ORM/Functional/Ticket/DDC2775Test.php | 10 +- .../ORM/Functional/Ticket/DDC279Test.php | 8 +- .../ORM/Functional/Ticket/DDC2825Test.php | 6 +- .../ORM/Functional/Ticket/DDC2862Test.php | 54 +-- .../ORM/Functional/Ticket/DDC2895Test.php | 4 +- .../ORM/Functional/Ticket/DDC2931Test.php | 4 +- .../ORM/Functional/Ticket/DDC2943Test.php | 4 +- .../ORM/Functional/Ticket/DDC2984Test.php | 4 +- .../ORM/Functional/Ticket/DDC2996Test.php | 6 +- .../ORM/Functional/Ticket/DDC3033Test.php | 4 +- .../ORM/Functional/Ticket/DDC3042Test.php | 4 +- .../ORM/Functional/Ticket/DDC3068Test.php | 8 +- .../ORM/Functional/Ticket/DDC309Test.php | 4 +- .../ORM/Functional/Ticket/DDC3103Test.php | 5 +- .../ORM/Functional/Ticket/DDC3170Test.php | 12 +- .../ORM/Functional/Ticket/DDC3192Test.php | 10 +- .../ORM/Functional/Ticket/DDC3223Test.php | 10 +- .../ORM/Functional/Ticket/DDC3300Test.php | 14 +- .../ORM/Functional/Ticket/DDC3330Test.php | 4 +- .../ORM/Functional/Ticket/DDC3346Test.php | 6 +- .../ORM/Functional/Ticket/DDC345Test.php | 6 +- .../ORM/Functional/Ticket/DDC353Test.php | 10 +- .../ORM/Functional/Ticket/DDC3582Test.php | 10 +- .../ORM/Functional/Ticket/DDC3597Test.php | 12 +- .../ORM/Functional/Ticket/DDC3634Test.php | 8 +- .../ORM/Functional/Ticket/DDC3644Test.php | 20 +- .../ORM/Functional/Ticket/DDC3699Test.php | 10 +- .../ORM/Functional/Ticket/DDC3711Test.php | 5 +- .../ORM/Functional/Ticket/DDC371Test.php | 7 +- .../ORM/Functional/Ticket/DDC3785Test.php | 8 +- .../ORM/Functional/Ticket/DDC381Test.php | 4 +- .../ORM/Functional/Ticket/DDC3967Test.php | 6 +- .../ORM/Functional/Ticket/DDC4003Test.php | 2 +- .../ORM/Functional/Ticket/DDC422Test.php | 10 +- .../ORM/Functional/Ticket/DDC425Test.php | 2 +- .../ORM/Functional/Ticket/DDC440Test.php | 10 +- .../ORM/Functional/Ticket/DDC444Test.php | 4 +- .../ORM/Functional/Ticket/DDC448Test.php | 6 +- .../ORM/Functional/Ticket/DDC493Test.php | 6 +- .../ORM/Functional/Ticket/DDC501Test.php | 2 +- .../ORM/Functional/Ticket/DDC512Test.php | 14 +- .../ORM/Functional/Ticket/DDC513Test.php | 6 +- .../ORM/Functional/Ticket/DDC522Test.php | 16 +- .../ORM/Functional/Ticket/DDC531Test.php | 14 +- .../ORM/Functional/Ticket/DDC5684Test.php | 18 +- .../ORM/Functional/Ticket/DDC588Test.php | 2 +- .../ORM/Functional/Ticket/DDC599Test.php | 10 +- .../ORM/Functional/Ticket/DDC618Test.php | 16 +- .../ORM/Functional/Ticket/DDC633Test.php | 12 +- .../ORM/Functional/Ticket/DDC656Test.php | 2 +- .../ORM/Functional/Ticket/DDC657Test.php | 14 +- .../ORM/Functional/Ticket/DDC698Test.php | 4 +- .../ORM/Functional/Ticket/DDC719Test.php | 2 +- .../ORM/Functional/Ticket/DDC729Test.php | 19 +- .../ORM/Functional/Ticket/DDC735Test.php | 6 +- .../ORM/Functional/Ticket/DDC736Test.php | 14 +- .../ORM/Functional/Ticket/DDC742Test.php | 8 +- .../ORM/Functional/Ticket/DDC748Test.php | 9 +- .../ORM/Functional/Ticket/DDC758Test.php | 16 +- .../ORM/Functional/Ticket/DDC809Test.php | 6 +- .../ORM/Functional/Ticket/DDC832Test.php | 6 +- .../ORM/Functional/Ticket/DDC837Test.php | 24 +- .../ORM/Functional/Ticket/DDC849Test.php | 2 +- .../ORM/Functional/Ticket/DDC881Test.php | 19 +- .../ORM/Functional/Ticket/DDC949Test.php | 14 +- .../ORM/Functional/Ticket/DDC960Test.php | 4 +- .../ORM/Functional/Ticket/DDC992Test.php | 6 +- .../ORM/Functional/Ticket/Ticket2481Test.php | 2 +- .../Tests/ORM/Functional/Ticket/Ticket69.php | 12 +- .../Tests/ORM/Functional/TypeTest.php | 15 +- .../Tests/ORM/Functional/TypeValueSqlTest.php | 8 +- .../ORM/Functional/UUIDGeneratorTest.php | 2 +- .../ManyToManyCompositeIdForeignKeyTest.php | 31 +- .../ManyToManyCompositeIdTest.php | 19 +- .../ManyToManyExtraLazyTest.php | 21 +- .../ValueConversionType/ManyToManyTest.php | 19 +- .../OneToManyCompositeIdForeignKeyTest.php | 29 +- .../OneToManyCompositeIdTest.php | 17 +- .../OneToManyExtraLazyTest.php | 11 +- .../ValueConversionType/OneToManyTest.php | 17 +- .../OneToOneCompositeIdForeignKeyTest.php | 31 +- .../OneToOneCompositeIdTest.php | 19 +- .../ValueConversionType/OneToOneTest.php | 19 +- .../Tests/ORM/Functional/ValueObjectsTest.php | 46 +-- .../ORM/Functional/VersionedOneToOneTest.php | 8 +- .../Tests/ORM/Hydration/ArrayHydratorTest.php | 70 ++-- .../ORM/Hydration/CustomHydratorTest.php | 7 +- .../ORM/Hydration/ObjectHydratorTest.php | 302 +++++++++-------- .../ORM/Hydration/ResultSetMappingTest.php | 61 ++-- .../ORM/Hydration/ScalarHydratorTest.php | 5 +- .../Hydration/SimpleObjectHydratorTest.php | 21 +- .../Hydration/SingleScalarHydratorTest.php | 3 +- .../Tests/ORM/LazyCriteriaCollectionTest.php | 3 +- .../ORM/Mapping/AbstractMappingDriverTest.php | 157 +++++---- .../ORM/Mapping/AnnotationDriverTest.php | 52 +-- .../ORM/Mapping/AnsiQuoteStrategyTest.php | 22 +- .../Mapping/BasicInheritanceMappingTest.php | 45 +-- .../ORM/Mapping/ClassMetadataBuilderTest.php | 106 +++--- .../ORM/Mapping/ClassMetadataFactoryTest.php | 64 ++-- .../Mapping/ClassMetadataLoadEventTest.php | 2 +- .../Tests/ORM/Mapping/ClassMetadataTest.php | 245 +++++++------- .../ORM/Mapping/DefaultQuoteStrategyTest.php | 7 +- .../Tests/ORM/Mapping/FieldBuilderTest.php | 3 +- .../ORM/Mapping/PHPMappingDriverTest.php | 13 +- .../Tests/ORM/Mapping/QuoteStrategyTest.php | 45 +-- .../ReflectionPropertiesGetterTest.php | 30 +- .../ReflectionEmbeddedPropertyTest.php | 76 ++--- .../Mapping/StaticPHPMappingDriverTest.php | 3 +- .../ORM/Mapping/XmlMappingDriverTest.php | 41 +-- .../ORM/Mapping/YamlMappingDriverTest.php | 26 +- .../Doctrine.Tests.Models.CMS.CmsAddress.php | 25 +- .../php/Doctrine.Tests.Models.CMS.CmsUser.php | 17 +- .../php/Doctrine.Tests.Models.Cache.City.php | 9 +- ...ine.Tests.Models.Company.CompanyPerson.php | 6 +- ...rine.Tests.Models.DDC869.DDC869Payment.php | 3 +- ...e.Tests.Models.DDC889.DDC889SuperClass.php | 3 +- .../php/Doctrine.Tests.ORM.Mapping.Animal.php | 6 +- .../php/Doctrine.Tests.ORM.Mapping.User.php | 9 +- .../Tests/ORM/Performance/DDC2602Test.php | 16 +- .../Performance/HydrationPerformanceTest.php | 43 +-- .../InheritancePersisterPerformanceTest.php | 5 +- .../Performance/PersisterPerformanceTest.php | 16 +- .../ORM/Performance/ProxyPerformanceTest.php | 12 +- .../ORM/Performance/SecondLevelCacheTest.php | 6 +- .../Tests/ORM/PersistentCollectionTest.php | 4 +- ...tyPersisterCompositeTypeParametersTest.php | 17 +- ...sicEntityPersisterCompositeTypeSqlTest.php | 4 +- .../BasicEntityPersisterTypeValueSqlTest.php | 11 +- .../JoinedSubclassPersisterTest.php | 7 +- .../Tests/ORM/Proxy/ProxyFactoryTest.php | 17 +- .../ORM/Query/CustomTreeWalkersJoinTest.php | 10 +- .../Tests/ORM/Query/CustomTreeWalkersTest.php | 20 +- tests/Doctrine/Tests/ORM/Query/ExprTest.php | 4 +- .../Tests/ORM/Query/FilterCollectionTest.php | 13 +- .../ORM/Query/LanguageRecognitionTest.php | 5 +- .../Tests/ORM/Query/ParserResultTest.php | 6 +- tests/Doctrine/Tests/ORM/Query/ParserTest.php | 17 +- .../ORM/Query/QueryExpressionVisitorTest.php | 11 +- tests/Doctrine/Tests/ORM/Query/QueryTest.php | 5 +- .../ORM/Query/SelectSqlGenerationTest.php | 30 +- .../ORM/Query/UpdateSqlGenerationTest.php | 5 +- tests/Doctrine/Tests/ORM/QueryBuilderTest.php | 187 +++++----- .../DefaultRepositoryFactoryTest.php | 33 +- .../AttachEntityListenersListenerTest.php | 36 +- .../ClearCacheCollectionRegionCommandTest.php | 13 +- .../ClearCacheEntityRegionCommandTest.php | 13 +- .../GenerateRepositoriesCommandTest.php | 12 +- .../Tools/Console/Command/InfoCommandTest.php | 20 +- .../Command/MappingDescribeCommandTest.php | 3 +- .../Console/Command/RunDqlCommandTest.php | 6 +- .../Tests/ORM/Tools/EntityGeneratorTest.php | 6 +- .../Tools/EntityRepositoryGeneratorTest.php | 32 +- .../AbstractClassMetadataExporterTest.php | 47 +-- .../Doctrine.Tests.ORM.Tools.Export.User.php | 11 +- .../Pagination/CountOutputWalkerTest.php | 9 +- .../ORM/Tools/Pagination/CountWalkerTest.php | 14 +- .../LimitSubqueryOutputWalkerTest.php | 51 +-- .../Pagination/LimitSubqueryWalkerTest.php | 13 +- .../Tools/Pagination/WhereInWalkerTest.php | 20 +- .../Tools/ResolveTargetEntityListenerTest.php | 56 +-- .../Tests/ORM/Tools/SchemaToolTest.php | 60 ++-- .../Tests/ORM/Tools/SchemaValidatorTest.php | 22 +- tests/Doctrine/Tests/ORM/Tools/SetupTest.php | 20 +- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 42 ++- .../ORM/Utility/IdentifierFlattenerTest.php | 14 +- .../Doctrine/Tests/OrmFunctionalTestCase.php | 298 ++++++++-------- tests/Doctrine/Tests/OrmTestCase.php | 8 +- 372 files changed, 4584 insertions(+), 4530 deletions(-) diff --git a/tests/Doctrine/Tests/Models/CMS/CmsAddress.php b/tests/Doctrine/Tests/Models/CMS/CmsAddress.php index c896866432f..f5c0b9af766 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsAddress.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsAddress.php @@ -172,7 +172,7 @@ public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $met [ 'name' => 'find-by-id', 'query' => 'SELECT * FROM cms_addresses WHERE id = ?', - 'resultClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsAddress', + 'resultClass' => CmsAddress::class, ] ); @@ -204,7 +204,7 @@ public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $met 'column' => 'country', ], ], - 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsAddress', + 'entityClass' => CmsAddress::class, ], ], ] @@ -216,7 +216,7 @@ public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $met 'columns' => [], 'entities' => [ [ - 'entityClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsAddress', + 'entityClass' => CmsAddress::class, 'fields' => [] ] ] diff --git a/tests/Doctrine/Tests/Models/CMS/CmsUser.php b/tests/Doctrine/Tests/Models/CMS/CmsUser.php index de23216f71b..153033605bd 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsUser.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsUser.php @@ -281,7 +281,7 @@ public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $met [ 'name' => 'fetchIdAndUsernameWithResultClass', 'query' => 'SELECT id, username FROM cms_users WHERE username = ?', - 'resultClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', + 'resultClass' => CmsUser::class, ] ); @@ -289,7 +289,7 @@ public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $met [ 'name' => 'fetchAllColumns', 'query' => 'SELECT * FROM cms_users WHERE username = ?', - 'resultClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', + 'resultClass' => CmsUser::class, ] ); @@ -361,7 +361,7 @@ public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $met 'column' => 'a_id', ], ], - 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', + 'entityClass' => CmsUser::class, 'discriminatorColumn' => null ], ], @@ -392,7 +392,7 @@ public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $met 'column' => 'number', ], ], - 'entityClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', + 'entityClass' => CmsUser::class, 'discriminatorColumn' => null ], ], @@ -419,7 +419,7 @@ public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $met 'column' => 'status', ] ], - 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', + 'entityClass' => CmsUser::class, 'discriminatorColumn' => null ] ], @@ -450,7 +450,7 @@ public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $met 'column' => 'u_status', ] ], - 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', + 'entityClass' => CmsUser::class, 'discriminatorColumn' => null, ], [ @@ -468,7 +468,7 @@ public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $met 'column' => 'a_country', ], ], - 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsAddress', + 'entityClass' => CmsAddress::class, 'discriminatorColumn' => null, ], ], diff --git a/tests/Doctrine/Tests/Models/Cache/Attraction.php b/tests/Doctrine/Tests/Models/Cache/Attraction.php index cbd62f84163..31f3d3069ba 100644 --- a/tests/Doctrine/Tests/Models/Cache/Attraction.php +++ b/tests/Doctrine/Tests/Models/Cache/Attraction.php @@ -92,4 +92,4 @@ public function addInfo(AttractionInfo $info) $this->infos->add($info); } } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/Cache/AttractionContactInfo.php b/tests/Doctrine/Tests/Models/Cache/AttractionContactInfo.php index 76ef305a41c..4b4b37f3b1c 100644 --- a/tests/Doctrine/Tests/Models/Cache/AttractionContactInfo.php +++ b/tests/Doctrine/Tests/Models/Cache/AttractionContactInfo.php @@ -30,4 +30,4 @@ public function setFone($fone) { $this->fone = $fone; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/Cache/AttractionInfo.php b/tests/Doctrine/Tests/Models/Cache/AttractionInfo.php index 418ef49b06c..d257a53f3ad 100644 --- a/tests/Doctrine/Tests/Models/Cache/AttractionInfo.php +++ b/tests/Doctrine/Tests/Models/Cache/AttractionInfo.php @@ -51,4 +51,4 @@ public function setAttraction(Attraction $attraction) $attraction->addInfo($this); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/Cache/AttractionLocationInfo.php b/tests/Doctrine/Tests/Models/Cache/AttractionLocationInfo.php index ebdb592aea9..66f2633f5d9 100644 --- a/tests/Doctrine/Tests/Models/Cache/AttractionLocationInfo.php +++ b/tests/Doctrine/Tests/Models/Cache/AttractionLocationInfo.php @@ -30,4 +30,4 @@ public function setAddress($address) { $this->address = $address; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/Cache/City.php b/tests/Doctrine/Tests/Models/Cache/City.php index f755e07aec9..40369728da9 100644 --- a/tests/Doctrine/Tests/Models/Cache/City.php +++ b/tests/Doctrine/Tests/Models/Cache/City.php @@ -106,4 +106,4 @@ public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $met { include __DIR__ . '/../../ORM/Mapping/php/Doctrine.Tests.Models.Cache.City.php'; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/Cache/Country.php b/tests/Doctrine/Tests/Models/Cache/Country.php index 33a9cf40cfd..11d09403808 100644 --- a/tests/Doctrine/Tests/Models/Cache/Country.php +++ b/tests/Doctrine/Tests/Models/Cache/Country.php @@ -47,4 +47,4 @@ public function setName($name) { $this->name = $name; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/Cache/Flight.php b/tests/Doctrine/Tests/Models/Cache/Flight.php index a95caab241c..ce2f3476fc8 100644 --- a/tests/Doctrine/Tests/Models/Cache/Flight.php +++ b/tests/Doctrine/Tests/Models/Cache/Flight.php @@ -62,4 +62,4 @@ public function setDeparture($departure) { $this->departure = $departure; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/Cache/State.php b/tests/Doctrine/Tests/Models/Cache/State.php index 0d37e4d8faa..e59ecb2b181 100644 --- a/tests/Doctrine/Tests/Models/Cache/State.php +++ b/tests/Doctrine/Tests/Models/Cache/State.php @@ -89,4 +89,4 @@ public function addCity(City $city) { $this->cities[] = $city; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/Cache/Travel.php b/tests/Doctrine/Tests/Models/Cache/Travel.php index 75e3275a489..b25744dd63d 100644 --- a/tests/Doctrine/Tests/Models/Cache/Travel.php +++ b/tests/Doctrine/Tests/Models/Cache/Travel.php @@ -109,4 +109,4 @@ public function getCreatedAt() { return $this->createdAt; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/Cache/TravelerProfile.php b/tests/Doctrine/Tests/Models/Cache/TravelerProfile.php index d4bea245714..fbffa8b70a9 100644 --- a/tests/Doctrine/Tests/Models/Cache/TravelerProfile.php +++ b/tests/Doctrine/Tests/Models/Cache/TravelerProfile.php @@ -63,4 +63,4 @@ public function setInfo(TravelerProfileInfo $info) { $this->info = $info; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/Cache/TravelerProfileInfo.php b/tests/Doctrine/Tests/Models/Cache/TravelerProfileInfo.php index b7a23bea002..e781628498e 100644 --- a/tests/Doctrine/Tests/Models/Cache/TravelerProfileInfo.php +++ b/tests/Doctrine/Tests/Models/Cache/TravelerProfileInfo.php @@ -65,4 +65,4 @@ public function setProfile(TravelerProfile $profile) { $this->profile = $profile; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/Company/CompanyPerson.php b/tests/Doctrine/Tests/Models/Company/CompanyPerson.php index 529c0e10949..ca80c953dcb 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyPerson.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyPerson.php @@ -130,7 +130,7 @@ public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $met [ 'name' => 'fetchAllWithResultClass', 'query' => 'SELECT id, name, discr FROM company_persons ORDER BY name', - 'resultClass' => 'Doctrine\\Tests\\Models\\Company\\CompanyPerson', + 'resultClass' => CompanyPerson::class, ] ); @@ -158,7 +158,7 @@ public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $met 'column' => 'name', ], ], - 'entityClass' => 'Doctrine\Tests\Models\Company\CompanyPerson', + 'entityClass' => CompanyPerson::class, 'discriminatorColumn' => 'discriminator', ], ], diff --git a/tests/Doctrine/Tests/Models/DDC3597/DDC3597Image.php b/tests/Doctrine/Tests/Models/DDC3597/DDC3597Image.php index 2254b4243a9..cc0b92cfb17 100644 --- a/tests/Doctrine/Tests/Models/DDC3597/DDC3597Image.php +++ b/tests/Doctrine/Tests/Models/DDC3597/DDC3597Image.php @@ -34,4 +34,4 @@ function __construct($distributionHash) { public function getDimension() { return $this->dimension; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DDC3597/DDC3597Media.php b/tests/Doctrine/Tests/Models/DDC3597/DDC3597Media.php index 751f7dac170..da6f60cd080 100644 --- a/tests/Doctrine/Tests/Models/DDC3597/DDC3597Media.php +++ b/tests/Doctrine/Tests/Models/DDC3597/DDC3597Media.php @@ -73,4 +73,4 @@ public function setFormat($format) { -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DDC3597/DDC3597Root.php b/tests/Doctrine/Tests/Models/DDC3597/DDC3597Root.php index d7f86dfba6a..2f24c933af7 100644 --- a/tests/Doctrine/Tests/Models/DDC3597/DDC3597Root.php +++ b/tests/Doctrine/Tests/Models/DDC3597/DDC3597Root.php @@ -77,4 +77,4 @@ public function getCreatedAt() { public function getUpdatedAt() { return $this->updatedAt; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DDC3699/DDC3699Child.php b/tests/Doctrine/Tests/Models/DDC3699/DDC3699Child.php index 320f73138eb..dc2222ef156 100644 --- a/tests/Doctrine/Tests/Models/DDC3699/DDC3699Child.php +++ b/tests/Doctrine/Tests/Models/DDC3699/DDC3699Child.php @@ -18,4 +18,4 @@ class DDC3699Child extends DDC3699Parent /** @OneToMany(targetEntity="DDC3699RelationMany", mappedBy="child") */ public $relations; -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php b/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php index f689a82ea4d..992c53ae27a 100644 --- a/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php @@ -36,7 +36,7 @@ public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $met ] ); $metadata->isMappedSuperclass = true; - $metadata->setCustomRepositoryClass("Doctrine\Tests\Models\DDC869\DDC869PaymentRepository"); + $metadata->setCustomRepositoryClass(DDC869PaymentRepository::class); $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_AUTO); } diff --git a/tests/Doctrine/Tests/Models/Generic/DateTimeModel.php b/tests/Doctrine/Tests/Models/Generic/DateTimeModel.php index 92ebe5e5deb..c7035ff6856 100644 --- a/tests/Doctrine/Tests/Models/Generic/DateTimeModel.php +++ b/tests/Doctrine/Tests/Models/Generic/DateTimeModel.php @@ -27,4 +27,4 @@ class DateTimeModel * @Column(name="col_time", type="time", nullable=true) */ public $time; -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/MixedToOneIdentity/CompositeToOneKeyState.php b/tests/Doctrine/Tests/Models/MixedToOneIdentity/CompositeToOneKeyState.php index b4b02e158c3..1ff5830585f 100644 --- a/tests/Doctrine/Tests/Models/MixedToOneIdentity/CompositeToOneKeyState.php +++ b/tests/Doctrine/Tests/Models/MixedToOneIdentity/CompositeToOneKeyState.php @@ -20,4 +20,4 @@ class CompositeToOneKeyState * @JoinColumn(referencedColumnName="country") */ public $country; -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Cache/CacheConfigTest.php b/tests/Doctrine/Tests/ORM/Cache/CacheConfigTest.php index 0de086387a0..4c016df1fc7 100644 --- a/tests/Doctrine/Tests/ORM/Cache/CacheConfigTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/CacheConfigTest.php @@ -6,6 +6,7 @@ use Doctrine\ORM\Cache\CacheFactory; use Doctrine\ORM\Cache\QueryCacheValidator; use Doctrine\ORM\Cache\Logging\CacheLogger; +use Doctrine\ORM\Cache\TimestampQueryCacheValidator; use Doctrine\ORM\Cache\TimestampRegion; use Doctrine\Tests\DoctrineTestCase; @@ -75,7 +76,7 @@ public function testSetGetQueryValidator() $validator = $this->createMock(QueryCacheValidator::class); - $this->assertInstanceOf('Doctrine\ORM\Cache\TimestampQueryCacheValidator', $this->config->getQueryValidator()); + $this->assertInstanceOf(TimestampQueryCacheValidator::class, $this->config->getQueryValidator()); $this->config->setQueryValidator($validator); diff --git a/tests/Doctrine/Tests/ORM/Cache/CacheLoggerChainTest.php b/tests/Doctrine/Tests/ORM/Cache/CacheLoggerChainTest.php index 625b0586733..a070237a200 100644 --- a/tests/Doctrine/Tests/ORM/Cache/CacheLoggerChainTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/CacheLoggerChainTest.php @@ -48,7 +48,7 @@ public function testGetAndSetLogger() public function testEntityCacheChain() { $name = 'my_entity_region'; - $key = new EntityCacheKey(State::CLASSNAME, ['id' => 1]); + $key = new EntityCacheKey(State::class, ['id' => 1]); $this->logger->setLogger('mock', $this->mock); @@ -72,7 +72,7 @@ public function testEntityCacheChain() public function testCollectionCacheChain() { $name = 'my_collection_region'; - $key = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id' => 1]); + $key = new CollectionCacheKey(State::class, 'cities', ['id' => 1]); $this->logger->setLogger('mock', $this->mock); diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php index a948676d79d..2047e05b379 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php @@ -4,14 +4,28 @@ use Doctrine\Common\Cache\Cache; use Doctrine\Common\Cache\CacheProvider; -use \Doctrine\Tests\OrmTestCase; -use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Cache\CacheFactory; use Doctrine\ORM\Cache\DefaultCacheFactory; +use Doctrine\ORM\Cache\Persister\Collection\CachedCollectionPersister; +use Doctrine\ORM\Cache\Persister\Collection\NonStrictReadWriteCachedCollectionPersister; +use Doctrine\ORM\Cache\Persister\Collection\ReadOnlyCachedCollectionPersister; +use Doctrine\ORM\Cache\Persister\Collection\ReadWriteCachedCollectionPersister; +use Doctrine\ORM\Cache\Persister\Entity\CachedEntityPersister; +use Doctrine\ORM\Cache\Persister\Entity\NonStrictReadWriteCachedEntityPersister; +use Doctrine\ORM\Cache\Persister\Entity\ReadOnlyCachedEntityPersister; +use Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister; +use Doctrine\ORM\Cache\Region\DefaultMultiGetRegion; use Doctrine\ORM\Cache\Region\DefaultRegion; -use Doctrine\Tests\Mocks\ConcurrentRegionMock; -use Doctrine\ORM\Persisters\Entity\BasicEntityPersister; -use Doctrine\ORM\Persisters\Collection\OneToManyPersister; use Doctrine\ORM\Cache\RegionsConfiguration; +use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Persisters\Collection\OneToManyPersister; +use Doctrine\ORM\Persisters\Entity\BasicEntityPersister; +use Doctrine\Tests\Mocks\ConcurrentRegionMock; +use Doctrine\Tests\Models\Cache\AttractionContactInfo; +use Doctrine\Tests\Models\Cache\AttractionLocationInfo; +use Doctrine\Tests\Models\Cache\City; +use Doctrine\Tests\Models\Cache\State; +use Doctrine\Tests\OrmTestCase; /** * @group DDC-2183 @@ -49,14 +63,13 @@ protected function setUp() public function testImplementsCacheFactory() { - $this->assertInstanceOf('Doctrine\ORM\Cache\CacheFactory', $this->factory); + $this->assertInstanceOf(CacheFactory::class, $this->factory); } public function testBuildCachedEntityPersisterReadOnly() { $em = $this->em; - $entityName = 'Doctrine\Tests\Models\Cache\State'; - $metadata = clone $em->getClassMetadata($entityName); + $metadata = clone $em->getClassMetadata(State::class); $persister = new BasicEntityPersister($em, $metadata); $region = new ConcurrentRegionMock(new DefaultRegion('regionName', $this->getSharedSecondLevelCacheDriverImpl())); @@ -69,15 +82,14 @@ public function testBuildCachedEntityPersisterReadOnly() $cachedPersister = $this->factory->buildCachedEntityPersister($em, $persister, $metadata); - $this->assertInstanceOf('Doctrine\ORM\Cache\Persister\Entity\CachedEntityPersister', $cachedPersister); - $this->assertInstanceOf('Doctrine\ORM\Cache\Persister\Entity\ReadOnlyCachedEntityPersister', $cachedPersister); + $this->assertInstanceOf(CachedEntityPersister::class, $cachedPersister); + $this->assertInstanceOf(ReadOnlyCachedEntityPersister::class, $cachedPersister); } public function testBuildCachedEntityPersisterReadWrite() { $em = $this->em; - $entityName = 'Doctrine\Tests\Models\Cache\State'; - $metadata = clone $em->getClassMetadata($entityName); + $metadata = clone $em->getClassMetadata(State::class); $persister = new BasicEntityPersister($em, $metadata); $region = new ConcurrentRegionMock(new DefaultRegion('regionName', $this->getSharedSecondLevelCacheDriverImpl())); @@ -90,15 +102,14 @@ public function testBuildCachedEntityPersisterReadWrite() $cachedPersister = $this->factory->buildCachedEntityPersister($em, $persister, $metadata); - $this->assertInstanceOf('Doctrine\ORM\Cache\Persister\Entity\CachedEntityPersister', $cachedPersister); - $this->assertInstanceOf('Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister', $cachedPersister); + $this->assertInstanceOf(CachedEntityPersister::class, $cachedPersister); + $this->assertInstanceOf(ReadWriteCachedEntityPersister::class, $cachedPersister); } public function testBuildCachedEntityPersisterNonStrictReadWrite() { $em = $this->em; - $entityName = 'Doctrine\Tests\Models\Cache\State'; - $metadata = clone $em->getClassMetadata($entityName); + $metadata = clone $em->getClassMetadata(State::class); $persister = new BasicEntityPersister($em, $metadata); $region = new ConcurrentRegionMock(new DefaultRegion('regionName', $this->getSharedSecondLevelCacheDriverImpl())); @@ -111,15 +122,14 @@ public function testBuildCachedEntityPersisterNonStrictReadWrite() $cachedPersister = $this->factory->buildCachedEntityPersister($em, $persister, $metadata); - $this->assertInstanceOf('Doctrine\ORM\Cache\Persister\Entity\CachedEntityPersister', $cachedPersister); - $this->assertInstanceOf('Doctrine\ORM\Cache\Persister\Entity\NonStrictReadWriteCachedEntityPersister', $cachedPersister); + $this->assertInstanceOf(CachedEntityPersister::class, $cachedPersister); + $this->assertInstanceOf(NonStrictReadWriteCachedEntityPersister::class, $cachedPersister); } public function testBuildCachedCollectionPersisterReadOnly() { $em = $this->em; - $entityName = 'Doctrine\Tests\Models\Cache\State'; - $metadata = $em->getClassMetadata($entityName); + $metadata = $em->getClassMetadata(State::class); $mapping = $metadata->associationMappings['cities']; $persister = new OneToManyPersister($em); $region = new ConcurrentRegionMock(new DefaultRegion('regionName', $this->getSharedSecondLevelCacheDriverImpl())); @@ -134,15 +144,14 @@ public function testBuildCachedCollectionPersisterReadOnly() $cachedPersister = $this->factory->buildCachedCollectionPersister($em, $persister, $mapping); - $this->assertInstanceOf('Doctrine\ORM\Cache\Persister\Collection\CachedCollectionPersister', $cachedPersister); - $this->assertInstanceOf('Doctrine\ORM\Cache\Persister\Collection\ReadOnlyCachedCollectionPersister', $cachedPersister); + $this->assertInstanceOf(CachedCollectionPersister::class, $cachedPersister); + $this->assertInstanceOf(ReadOnlyCachedCollectionPersister::class, $cachedPersister); } public function testBuildCachedCollectionPersisterReadWrite() { $em = $this->em; - $entityName = 'Doctrine\Tests\Models\Cache\State'; - $metadata = $em->getClassMetadata($entityName); + $metadata = $em->getClassMetadata(State::class); $mapping = $metadata->associationMappings['cities']; $persister = new OneToManyPersister($em); $region = new ConcurrentRegionMock(new DefaultRegion('regionName', $this->getSharedSecondLevelCacheDriverImpl())); @@ -156,15 +165,14 @@ public function testBuildCachedCollectionPersisterReadWrite() $cachedPersister = $this->factory->buildCachedCollectionPersister($em, $persister, $mapping); - $this->assertInstanceOf('Doctrine\ORM\Cache\Persister\Collection\CachedCollectionPersister', $cachedPersister); - $this->assertInstanceOf('Doctrine\ORM\Cache\Persister\Collection\ReadWriteCachedCollectionPersister', $cachedPersister); + $this->assertInstanceOf(CachedCollectionPersister::class, $cachedPersister); + $this->assertInstanceOf(ReadWriteCachedCollectionPersister::class, $cachedPersister); } public function testBuildCachedCollectionPersisterNonStrictReadWrite() { $em = $this->em; - $entityName = 'Doctrine\Tests\Models\Cache\State'; - $metadata = $em->getClassMetadata($entityName); + $metadata = $em->getClassMetadata(State::class); $mapping = $metadata->associationMappings['cities']; $persister = new OneToManyPersister($em); $region = new ConcurrentRegionMock(new DefaultRegion('regionName', $this->getSharedSecondLevelCacheDriverImpl())); @@ -178,15 +186,15 @@ public function testBuildCachedCollectionPersisterNonStrictReadWrite() $cachedPersister = $this->factory->buildCachedCollectionPersister($em, $persister, $mapping); - $this->assertInstanceOf('Doctrine\ORM\Cache\Persister\Collection\CachedCollectionPersister', $cachedPersister); - $this->assertInstanceOf('Doctrine\ORM\Cache\Persister\Collection\NonStrictReadWriteCachedCollectionPersister', $cachedPersister); + $this->assertInstanceOf(CachedCollectionPersister::class, $cachedPersister); + $this->assertInstanceOf(NonStrictReadWriteCachedCollectionPersister::class, $cachedPersister); } public function testInheritedEntityCacheRegion() { $em = $this->em; - $metadata1 = clone $em->getClassMetadata('Doctrine\Tests\Models\Cache\AttractionContactInfo'); - $metadata2 = clone $em->getClassMetadata('Doctrine\Tests\Models\Cache\AttractionLocationInfo'); + $metadata1 = clone $em->getClassMetadata(AttractionContactInfo::class); + $metadata2 = clone $em->getClassMetadata(AttractionLocationInfo::class); $persister1 = new BasicEntityPersister($em, $metadata1); $persister2 = new BasicEntityPersister($em, $metadata2); $factory = new DefaultCacheFactory($this->regionsConfig, $this->getSharedSecondLevelCacheDriverImpl()); @@ -194,8 +202,8 @@ public function testInheritedEntityCacheRegion() $cachedPersister1 = $factory->buildCachedEntityPersister($em, $persister1, $metadata1); $cachedPersister2 = $factory->buildCachedEntityPersister($em, $persister2, $metadata2); - $this->assertInstanceOf('Doctrine\ORM\Cache\Persister\Entity\CachedEntityPersister', $cachedPersister1); - $this->assertInstanceOf('Doctrine\ORM\Cache\Persister\Entity\CachedEntityPersister', $cachedPersister2); + $this->assertInstanceOf(CachedEntityPersister::class, $cachedPersister1); + $this->assertInstanceOf(CachedEntityPersister::class, $cachedPersister2); $this->assertNotSame($cachedPersister1, $cachedPersister2); $this->assertSame($cachedPersister1->getCacheRegion(), $cachedPersister2->getCacheRegion()); @@ -204,8 +212,8 @@ public function testInheritedEntityCacheRegion() public function testCreateNewCacheDriver() { $em = $this->em; - $metadata1 = clone $em->getClassMetadata('Doctrine\Tests\Models\Cache\State'); - $metadata2 = clone $em->getClassMetadata('Doctrine\Tests\Models\Cache\City'); + $metadata1 = clone $em->getClassMetadata(State::class); + $metadata2 = clone $em->getClassMetadata(City::class); $persister1 = new BasicEntityPersister($em, $metadata1); $persister2 = new BasicEntityPersister($em, $metadata2); $factory = new DefaultCacheFactory($this->regionsConfig, $this->getSharedSecondLevelCacheDriverImpl()); @@ -213,8 +221,8 @@ public function testCreateNewCacheDriver() $cachedPersister1 = $factory->buildCachedEntityPersister($em, $persister1, $metadata1); $cachedPersister2 = $factory->buildCachedEntityPersister($em, $persister2, $metadata2); - $this->assertInstanceOf('Doctrine\ORM\Cache\Persister\Entity\CachedEntityPersister', $cachedPersister1); - $this->assertInstanceOf('Doctrine\ORM\Cache\Persister\Entity\CachedEntityPersister', $cachedPersister2); + $this->assertInstanceOf(CachedEntityPersister::class, $cachedPersister1); + $this->assertInstanceOf(CachedEntityPersister::class, $cachedPersister2); $this->assertNotSame($cachedPersister1, $cachedPersister2); $this->assertNotSame($cachedPersister1->getCacheRegion(), $cachedPersister2->getCacheRegion()); @@ -227,8 +235,7 @@ public function testCreateNewCacheDriver() public function testBuildCachedEntityPersisterNonStrictException() { $em = $this->em; - $entityName = 'Doctrine\Tests\Models\Cache\State'; - $metadata = clone $em->getClassMetadata($entityName); + $metadata = clone $em->getClassMetadata(State::class); $persister = new BasicEntityPersister($em, $metadata); $metadata->cache['usage'] = -1; @@ -243,8 +250,7 @@ public function testBuildCachedEntityPersisterNonStrictException() public function testBuildCachedCollectionPersisterException() { $em = $this->em; - $entityName = 'Doctrine\Tests\Models\Cache\State'; - $metadata = $em->getClassMetadata($entityName); + $metadata = $em->getClassMetadata(State::class); $mapping = $metadata->associationMappings['cities']; $persister = new OneToManyPersister($em); @@ -298,7 +304,7 @@ public function testBuildsDefaultCacheRegionFromGenericCacheRegion() $factory = new DefaultCacheFactory($this->regionsConfig, $cache); $this->assertInstanceOf( - 'Doctrine\ORM\Cache\Region\DefaultRegion', + DefaultRegion::class, $factory->getRegion( [ 'region' => 'bar', @@ -316,7 +322,7 @@ public function testBuildsMultiGetCacheRegionFromGenericCacheRegion() $factory = new DefaultCacheFactory($this->regionsConfig, $cache); $this->assertInstanceOf( - 'Doctrine\ORM\Cache\Region\DefaultMultiGetRegion', + DefaultMultiGetRegion::class, $factory->getRegion( [ 'region' => 'bar', diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheTest.php index 866153fbbec..cbc9d8e8b73 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheTest.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\ORM\Cache; +use Doctrine\ORM\Cache; +use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\OrmTestCase; use Doctrine\ORM\Cache\DefaultCache; use Doctrine\Tests\Models\Cache\State; @@ -26,8 +28,6 @@ class DefaultCacheTest extends OrmTestCase */ private $em; - const NON_CACHEABLE_ENTITY = 'Doctrine\Tests\Models\CMS\CmsUser'; - protected function setUp() { parent::enableSecondLevelCache(); @@ -70,104 +70,104 @@ private function putCollectionCacheEntry($className, $association, array $ownerI public function testImplementsCache() { - $this->assertInstanceOf('Doctrine\ORM\Cache', $this->cache); + $this->assertInstanceOf(Cache::class, $this->cache); } public function testGetEntityCacheRegionAccess() { - $this->assertInstanceOf('Doctrine\ORM\Cache\Region', $this->cache->getEntityCacheRegion(State::CLASSNAME)); - $this->assertNull($this->cache->getEntityCacheRegion(self::NON_CACHEABLE_ENTITY)); + $this->assertInstanceOf(Cache\Region::class, $this->cache->getEntityCacheRegion(State::class)); + $this->assertNull($this->cache->getEntityCacheRegion(CmsUser::class)); } public function testGetCollectionCacheRegionAccess() { - $this->assertInstanceOf('Doctrine\ORM\Cache\Region', $this->cache->getCollectionCacheRegion(State::CLASSNAME, 'cities')); - $this->assertNull($this->cache->getCollectionCacheRegion(self::NON_CACHEABLE_ENTITY, 'phonenumbers')); + $this->assertInstanceOf(Cache\Region::class, $this->cache->getCollectionCacheRegion(State::class, 'cities')); + $this->assertNull($this->cache->getCollectionCacheRegion(CmsUser::class, 'phonenumbers')); } public function testContainsEntity() { $identifier = ['id'=>1]; - $className = Country::CLASSNAME; + $className = Country::class; $cacheEntry = array_merge($identifier, ['name' => 'Brazil']); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, 1)); + $this->assertFalse($this->cache->containsEntity(Country::class, 1)); $this->putEntityCacheEntry($className, $identifier, $cacheEntry); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, 1)); - $this->assertFalse($this->cache->containsEntity(self::NON_CACHEABLE_ENTITY, 1)); + $this->assertTrue($this->cache->containsEntity(Country::class, 1)); + $this->assertFalse($this->cache->containsEntity(CmsUser::class, 1)); } public function testEvictEntity() { $identifier = ['id'=>1]; - $className = Country::CLASSNAME; + $className = Country::class; $cacheEntry = array_merge($identifier, ['name' => 'Brazil']); $this->putEntityCacheEntry($className, $identifier, $cacheEntry); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, 1)); + $this->assertTrue($this->cache->containsEntity(Country::class, 1)); - $this->cache->evictEntity(Country::CLASSNAME, 1); - $this->cache->evictEntity(self::NON_CACHEABLE_ENTITY, 1); + $this->cache->evictEntity(Country::class, 1); + $this->cache->evictEntity(CmsUser::class, 1); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, 1)); + $this->assertFalse($this->cache->containsEntity(Country::class, 1)); } public function testEvictEntityRegion() { $identifier = ['id'=>1]; - $className = Country::CLASSNAME; + $className = Country::class; $cacheEntry = array_merge($identifier, ['name' => 'Brazil']); $this->putEntityCacheEntry($className, $identifier, $cacheEntry); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, 1)); + $this->assertTrue($this->cache->containsEntity(Country::class, 1)); - $this->cache->evictEntityRegion(Country::CLASSNAME); - $this->cache->evictEntityRegion(self::NON_CACHEABLE_ENTITY); + $this->cache->evictEntityRegion(Country::class); + $this->cache->evictEntityRegion(CmsUser::class); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, 1)); + $this->assertFalse($this->cache->containsEntity(Country::class, 1)); } public function testEvictEntityRegions() { $identifier = ['id'=>1]; - $className = Country::CLASSNAME; + $className = Country::class; $cacheEntry = array_merge($identifier, ['name' => 'Brazil']); $this->putEntityCacheEntry($className, $identifier, $cacheEntry); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, 1)); + $this->assertTrue($this->cache->containsEntity(Country::class, 1)); $this->cache->evictEntityRegions(); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, 1)); + $this->assertFalse($this->cache->containsEntity(Country::class, 1)); } public function testContainsCollection() { $ownerId = ['id'=>1]; - $className = State::CLASSNAME; + $className = State::class; $association = 'cities'; $cacheEntry = [ ['id' => 11], ['id' => 12], ]; - $this->assertFalse($this->cache->containsCollection(State::CLASSNAME, $association, 1)); + $this->assertFalse($this->cache->containsCollection(State::class, $association, 1)); $this->putCollectionCacheEntry($className, $association, $ownerId, $cacheEntry); - $this->assertTrue($this->cache->containsCollection(State::CLASSNAME, $association, 1)); - $this->assertFalse($this->cache->containsCollection(self::NON_CACHEABLE_ENTITY, 'phonenumbers', 1)); + $this->assertTrue($this->cache->containsCollection(State::class, $association, 1)); + $this->assertFalse($this->cache->containsCollection(CmsUser::class, 'phonenumbers', 1)); } public function testEvictCollection() { $ownerId = ['id'=>1]; - $className = State::CLASSNAME; + $className = State::class; $association = 'cities'; $cacheEntry = [ ['id' => 11], @@ -176,18 +176,18 @@ public function testEvictCollection() $this->putCollectionCacheEntry($className, $association, $ownerId, $cacheEntry); - $this->assertTrue($this->cache->containsCollection(State::CLASSNAME, $association, 1)); + $this->assertTrue($this->cache->containsCollection(State::class, $association, 1)); $this->cache->evictCollection($className, $association, $ownerId); - $this->cache->evictCollection(self::NON_CACHEABLE_ENTITY, 'phonenumbers', 1); + $this->cache->evictCollection(CmsUser::class, 'phonenumbers', 1); - $this->assertFalse($this->cache->containsCollection(State::CLASSNAME, $association, 1)); + $this->assertFalse($this->cache->containsCollection(State::class, $association, 1)); } public function testEvictCollectionRegion() { $ownerId = ['id'=>1]; - $className = State::CLASSNAME; + $className = State::class; $association = 'cities'; $cacheEntry = [ ['id' => 11], @@ -196,18 +196,18 @@ public function testEvictCollectionRegion() $this->putCollectionCacheEntry($className, $association, $ownerId, $cacheEntry); - $this->assertTrue($this->cache->containsCollection(State::CLASSNAME, $association, 1)); + $this->assertTrue($this->cache->containsCollection(State::class, $association, 1)); $this->cache->evictCollectionRegion($className, $association); - $this->cache->evictCollectionRegion(self::NON_CACHEABLE_ENTITY, 'phonenumbers'); + $this->cache->evictCollectionRegion(CmsUser::class, 'phonenumbers'); - $this->assertFalse($this->cache->containsCollection(State::CLASSNAME, $association, 1)); + $this->assertFalse($this->cache->containsCollection(State::class, $association, 1)); } public function testEvictCollectionRegions() { $ownerId = ['id'=>1]; - $className = State::CLASSNAME; + $className = State::class; $association = 'cities'; $cacheEntry = [ ['id' => 11], @@ -216,11 +216,11 @@ public function testEvictCollectionRegions() $this->putCollectionCacheEntry($className, $association, $ownerId, $cacheEntry); - $this->assertTrue($this->cache->containsCollection(State::CLASSNAME, $association, 1)); + $this->assertTrue($this->cache->containsCollection(State::class, $association, 1)); $this->cache->evictCollectionRegions(); - $this->assertFalse($this->cache->containsCollection(State::CLASSNAME, $association, 1)); + $this->assertFalse($this->cache->containsCollection(State::class, $association, 1)); } public function testQueryCache() @@ -230,8 +230,8 @@ public function testQueryCache() $defaultQueryCache = $this->cache->getQueryCache(); $fooQueryCache = $this->cache->getQueryCache('foo'); - $this->assertInstanceOf('Doctrine\ORM\Cache\QueryCache', $defaultQueryCache); - $this->assertInstanceOf('Doctrine\ORM\Cache\QueryCache', $fooQueryCache); + $this->assertInstanceOf(Cache\QueryCache::class, $defaultQueryCache); + $this->assertInstanceOf(Cache\QueryCache::class, $fooQueryCache); $this->assertSame($defaultQueryCache, $this->cache->getQueryCache()); $this->assertSame($fooQueryCache, $this->cache->getQueryCache('foo')); @@ -249,7 +249,7 @@ public function testToIdentifierArrayShouldLookupForEntityIdentifier() { $identifier = 123; $entity = new Country('Foo'); - $metadata = $this->em->getClassMetadata(Country::CLASSNAME); + $metadata = $this->em->getClassMetadata(Country::class); $method = new \ReflectionMethod($this->cache, 'toIdentifierArray'); $property = new \ReflectionProperty($entity, 'id'); diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultCollectionHydratorTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultCollectionHydratorTest.php index e3c4d785bf5..f2a35b16a95 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultCollectionHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultCollectionHydratorTest.php @@ -2,17 +2,17 @@ namespace Doctrine\Tests\ORM\Cache; -use Doctrine\ORM\UnitOfWork; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\ORM\Cache\CollectionCacheEntry; +use Doctrine\ORM\Cache\CollectionCacheKey; +use Doctrine\ORM\Cache\DefaultCollectionHydrator; +use Doctrine\ORM\Cache\EntityCacheEntry; +use Doctrine\ORM\Cache\EntityCacheKey; use Doctrine\ORM\PersistentCollection; -use Doctrine\Tests\Models\Cache\State; +use Doctrine\ORM\UnitOfWork; use Doctrine\Tests\Models\Cache\City; +use Doctrine\Tests\Models\Cache\State; use Doctrine\Tests\OrmFunctionalTestCase; -use Doctrine\ORM\Cache\EntityCacheKey; -use Doctrine\ORM\Cache\EntityCacheEntry; -use Doctrine\ORM\Cache\CollectionCacheKey; -use Doctrine\ORM\Cache\CollectionCacheEntry; -use Doctrine\Common\Collections\ArrayCollection; -use Doctrine\ORM\Cache\DefaultCollectionHydrator; /** * @group DDC-2183 @@ -29,32 +29,32 @@ protected function setUp() $this->enableSecondLevelCache(); parent::setUp(); - $targetPersister = $this->_em->getUnitOfWork()->getEntityPersister(City::CLASSNAME); + $targetPersister = $this->_em->getUnitOfWork()->getEntityPersister(City::class); $this->structure = new DefaultCollectionHydrator($this->_em, $targetPersister); } public function testImplementsCollectionEntryStructure() { - $this->assertInstanceOf('Doctrine\ORM\Cache\DefaultCollectionHydrator', $this->structure); + $this->assertInstanceOf(DefaultCollectionHydrator::class, $this->structure); } public function testLoadCacheCollection() { - $targetRegion = $this->_em->getCache()->getEntityCacheRegion(City::CLASSNAME); + $targetRegion = $this->_em->getCache()->getEntityCacheRegion(City::class); $entry = new CollectionCacheEntry( [ - new EntityCacheKey(City::CLASSNAME, ['id'=>31]), - new EntityCacheKey(City::CLASSNAME, ['id'=>32]), + new EntityCacheKey(City::class, ['id'=>31]), + new EntityCacheKey(City::class, ['id'=>32]), ] ); - $targetRegion->put(new EntityCacheKey(City::CLASSNAME, ['id'=>31]), new EntityCacheEntry(City::CLASSNAME, ['id'=>31, 'name'=>'Foo'] + $targetRegion->put(new EntityCacheKey(City::class, ['id'=>31]), new EntityCacheEntry(City::class, ['id'=>31, 'name'=>'Foo'] )); - $targetRegion->put(new EntityCacheKey(City::CLASSNAME, ['id'=>32]), new EntityCacheEntry(City::CLASSNAME, ['id'=>32, 'name'=>'Bar'] + $targetRegion->put(new EntityCacheKey(City::class, ['id'=>32]), new EntityCacheEntry(City::class, ['id'=>32, 'name'=>'Bar'] )); - $sourceClass = $this->_em->getClassMetadata(State::CLASSNAME); - $targetClass = $this->_em->getClassMetadata(City::CLASSNAME); + $sourceClass = $this->_em->getClassMetadata(State::class); + $targetClass = $this->_em->getClassMetadata(City::class); $key = new CollectionCacheKey($sourceClass->name, 'cities', ['id'=>21]); $collection = new PersistentCollection($this->_em, $targetClass, new ArrayCollection()); $list = $this->structure->loadCacheEntry($sourceClass, $key, $entry, $collection); diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultEntityHydratorTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultEntityHydratorTest.php index e7fdb617b7a..d58ab8a0527 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultEntityHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultEntityHydratorTest.php @@ -2,15 +2,15 @@ namespace Doctrine\Tests\ORM\Cache; -use Doctrine\Tests\OrmTestCase; -use Doctrine\Tests\Models\Cache\State; -use Doctrine\Tests\Models\Cache\Country; - -use Doctrine\ORM\UnitOfWork; -use Doctrine\ORM\Cache\EntityCacheKey; -use Doctrine\ORM\Cache\EntityCacheEntry; -use Doctrine\ORM\Cache\DefaultEntityHydrator; use Doctrine\ORM\Cache\AssociationCacheEntry; +use Doctrine\ORM\Cache\CacheEntry; +use Doctrine\ORM\Cache\DefaultEntityHydrator; +use Doctrine\ORM\Cache\EntityCacheEntry; +use Doctrine\ORM\Cache\EntityCacheKey; +use Doctrine\ORM\UnitOfWork; +use Doctrine\Tests\Models\Cache\Country; +use Doctrine\Tests\Models\Cache\State; +use Doctrine\Tests\OrmTestCase; /** * @group DDC-2183 @@ -42,7 +42,7 @@ public function testImplementsEntityEntryStructure() public function testCreateEntity() { - $metadata = $this->em->getClassMetadata(Country::CLASSNAME); + $metadata = $this->em->getClassMetadata(Country::class); $key = new EntityCacheKey($metadata->name, ['id'=>1]); $entry = new EntityCacheEntry($metadata->name, ['id'=>1, 'name'=>'Foo']); $entity = $this->structure->loadCacheEntry($metadata, $key, $entry); @@ -56,7 +56,7 @@ public function testCreateEntity() public function testLoadProxy() { - $metadata = $this->em->getClassMetadata(Country::CLASSNAME); + $metadata = $this->em->getClassMetadata(Country::class); $key = new EntityCacheKey($metadata->name, ['id'=>1]); $entry = new EntityCacheEntry($metadata->name, ['id'=>1, 'name'=>'Foo']); $proxy = $this->em->getReference($metadata->name, $key->identifier); @@ -75,7 +75,7 @@ public function testBuildCacheEntry() $entity = new Country('Foo'); $uow = $this->em->getUnitOfWork(); $data = ['id'=>1, 'name'=>'Foo']; - $metadata = $this->em->getClassMetadata(Country::CLASSNAME); + $metadata = $this->em->getClassMetadata(Country::class); $key = new EntityCacheKey($metadata->name, ['id'=>1]); $entity->setId(1); @@ -83,8 +83,8 @@ public function testBuildCacheEntry() $cache = $this->structure->buildCacheEntry($metadata, $key, $entity); - $this->assertInstanceOf('Doctrine\ORM\Cache\CacheEntry', $cache); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheEntry', $cache); + $this->assertInstanceOf(CacheEntry::class, $cache); + $this->assertInstanceOf(EntityCacheEntry::class, $cache); $this->assertArrayHasKey('id', $cache->data); $this->assertArrayHasKey('name', $cache->data); @@ -102,7 +102,7 @@ public function testBuildCacheEntryAssociation() $uow = $this->em->getUnitOfWork(); $countryData = ['id'=>11, 'name'=>'Foo']; $stateData = ['id'=>12, 'name'=>'Bar', 'country' => $country]; - $metadata = $this->em->getClassMetadata(State::CLASSNAME); + $metadata = $this->em->getClassMetadata(State::class); $key = new EntityCacheKey($metadata->name, ['id'=>11]); $country->setId(11); @@ -113,8 +113,8 @@ public function testBuildCacheEntryAssociation() $cache = $this->structure->buildCacheEntry($metadata, $key, $state); - $this->assertInstanceOf('Doctrine\ORM\Cache\CacheEntry', $cache); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheEntry', $cache); + $this->assertInstanceOf(CacheEntry::class, $cache); + $this->assertInstanceOf(EntityCacheEntry::class, $cache); $this->assertArrayHasKey('id', $cache->data); $this->assertArrayHasKey('name', $cache->data); @@ -123,17 +123,17 @@ public function testBuildCacheEntryAssociation() [ 'id' => 12, 'name' => 'Bar', - 'country' => new AssociationCacheEntry(Country::CLASSNAME, ['id' => 11]), + 'country' => new AssociationCacheEntry(Country::class, ['id' => 11]), ], $cache->data); } public function testBuildCacheEntryNonInitializedAssocProxy() { - $proxy = $this->em->getReference(Country::CLASSNAME, 11); + $proxy = $this->em->getReference(Country::class, 11); $entity = new State('Bat', $proxy); $uow = $this->em->getUnitOfWork(); $entityData = ['id'=>12, 'name'=>'Bar', 'country' => $proxy]; - $metadata = $this->em->getClassMetadata(State::CLASSNAME); + $metadata = $this->em->getClassMetadata(State::class); $key = new EntityCacheKey($metadata->name, ['id'=>11]); $entity->setId(12); @@ -142,8 +142,8 @@ public function testBuildCacheEntryNonInitializedAssocProxy() $cache = $this->structure->buildCacheEntry($metadata, $key, $entity); - $this->assertInstanceOf('Doctrine\ORM\Cache\CacheEntry', $cache); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheEntry', $cache); + $this->assertInstanceOf(CacheEntry::class, $cache); + $this->assertInstanceOf(EntityCacheEntry::class, $cache); $this->assertArrayHasKey('id', $cache->data); $this->assertArrayHasKey('name', $cache->data); @@ -152,17 +152,17 @@ public function testBuildCacheEntryNonInitializedAssocProxy() [ 'id' => 12, 'name' => 'Bar', - 'country' => new AssociationCacheEntry(Country::CLASSNAME, ['id' => 11]), + 'country' => new AssociationCacheEntry(Country::class, ['id' => 11]), ], $cache->data); } public function testCacheEntryWithWrongIdentifierType() { - $proxy = $this->em->getReference(Country::CLASSNAME, 11); + $proxy = $this->em->getReference(Country::class, 11); $entity = new State('Bat', $proxy); $uow = $this->em->getUnitOfWork(); $entityData = ['id'=> 12, 'name'=>'Bar', 'country' => $proxy]; - $metadata = $this->em->getClassMetadata(State::CLASSNAME); + $metadata = $this->em->getClassMetadata(State::class); $key = new EntityCacheKey($metadata->name, ['id'=>'12']); $entity->setId(12); @@ -171,8 +171,8 @@ public function testCacheEntryWithWrongIdentifierType() $cache = $this->structure->buildCacheEntry($metadata, $key, $entity); - $this->assertInstanceOf('Doctrine\ORM\Cache\CacheEntry', $cache); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheEntry', $cache); + $this->assertInstanceOf(CacheEntry::class, $cache); + $this->assertInstanceOf(EntityCacheEntry::class, $cache); $this->assertArrayHasKey('id', $cache->data); $this->assertArrayHasKey('name', $cache->data); @@ -182,7 +182,7 @@ public function testCacheEntryWithWrongIdentifierType() [ 'id' => 12, 'name' => 'Bar', - 'country' => new AssociationCacheEntry(Country::CLASSNAME, ['id' => 11]), + 'country' => new AssociationCacheEntry(Country::class, ['id' => 11]), ], $cache->data); } diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php index f9b11bee8d3..cfd9142094a 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php @@ -2,6 +2,9 @@ namespace Doctrine\Tests\ORM\Cache; +use Doctrine\Common\Collections\Collection; +use Doctrine\ORM\Cache\EntityCacheKey; +use Doctrine\ORM\Cache\QueryCache; use Doctrine\Tests\Mocks\TimestampRegionMock; use Doctrine\Tests\OrmTestCase; use Doctrine\Tests\Mocks\CacheRegionMock; @@ -61,7 +64,7 @@ protected function setUp() public function testImplementQueryCache() { - $this->assertInstanceOf('Doctrine\ORM\Cache\QueryCache', $this->queryCache); + $this->assertInstanceOf(QueryCache::class, $this->queryCache); } public function testGetRegion() @@ -82,9 +85,9 @@ public function testPutBasicQueryResult() $result = []; $key = new QueryCacheKey('query.key1', 0); $rsm = new ResultSetMappingBuilder($this->em); - $metadata = $this->em->getClassMetadata(Country::CLASSNAME); + $metadata = $this->em->getClassMetadata(Country::class); - $rsm->addRootEntityFromClassMetadata(Country::CLASSNAME, 'c'); + $rsm->addRootEntityFromClassMetadata(Country::class, 'c'); for ($i = 0; $i < 4; $i++) { $name = "Country $i"; @@ -99,17 +102,17 @@ public function testPutBasicQueryResult() $this->assertArrayHasKey('put', $this->region->calls); $this->assertCount(5, $this->region->calls['put']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][0]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][1]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][2]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][3]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\QueryCacheKey', $this->region->calls['put'][4]['key']); - - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheEntry', $this->region->calls['put'][0]['entry']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheEntry', $this->region->calls['put'][1]['entry']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheEntry', $this->region->calls['put'][2]['entry']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheEntry', $this->region->calls['put'][3]['entry']); - $this->assertInstanceOf('Doctrine\ORM\Cache\QueryCacheEntry', $this->region->calls['put'][4]['entry']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][0]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][1]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][2]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][3]['key']); + $this->assertInstanceOf(QueryCacheKey::class, $this->region->calls['put'][4]['key']); + + $this->assertInstanceOf(EntityCacheEntry::class, $this->region->calls['put'][0]['entry']); + $this->assertInstanceOf(EntityCacheEntry::class, $this->region->calls['put'][1]['entry']); + $this->assertInstanceOf(EntityCacheEntry::class, $this->region->calls['put'][2]['entry']); + $this->assertInstanceOf(EntityCacheEntry::class, $this->region->calls['put'][3]['entry']); + $this->assertInstanceOf(QueryCacheEntry::class, $this->region->calls['put'][4]['entry']); } public function testPutToOneAssociationQueryResult() @@ -118,11 +121,11 @@ public function testPutToOneAssociationQueryResult() $uow = $this->em->getUnitOfWork(); $key = new QueryCacheKey('query.key1', 0); $rsm = new ResultSetMappingBuilder($this->em); - $cityClass = $this->em->getClassMetadata(City::CLASSNAME); - $stateClass = $this->em->getClassMetadata(State::CLASSNAME); + $cityClass = $this->em->getClassMetadata(City::class); + $stateClass = $this->em->getClassMetadata(State::class); - $rsm->addRootEntityFromClassMetadata(City::CLASSNAME, 'c'); - $rsm->addJoinedEntityFromClassMetadata(State::CLASSNAME, 's', 'c', 'state', ['id'=>'state_id', 'name'=>'state_name'] + $rsm->addRootEntityFromClassMetadata(City::class, 'c'); + $rsm->addJoinedEntityFromClassMetadata(State::class, 's', 'c', 'state', ['id'=>'state_id', 'name'=>'state_name'] ); for ($i = 0; $i < 4; $i++) { @@ -141,15 +144,15 @@ public function testPutToOneAssociationQueryResult() $this->assertArrayHasKey('put', $this->region->calls); $this->assertCount(9, $this->region->calls['put']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][0]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][1]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][2]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][3]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][4]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][5]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][6]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][7]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\QueryCacheKey', $this->region->calls['put'][8]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][0]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][1]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][2]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][3]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][4]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][5]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][6]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][7]['key']); + $this->assertInstanceOf(QueryCacheKey::class, $this->region->calls['put'][8]['key']); } public function testPutToOneAssociation2LevelsQueryResult() @@ -158,14 +161,14 @@ public function testPutToOneAssociation2LevelsQueryResult() $uow = $this->em->getUnitOfWork(); $key = new QueryCacheKey('query.key1', 0); $rsm = new ResultSetMappingBuilder($this->em); - $cityClass = $this->em->getClassMetadata(City::CLASSNAME); - $stateClass = $this->em->getClassMetadata(State::CLASSNAME); - $countryClass = $this->em->getClassMetadata(Country::CLASSNAME); + $cityClass = $this->em->getClassMetadata(City::class); + $stateClass = $this->em->getClassMetadata(State::class); + $countryClass = $this->em->getClassMetadata(Country::class); - $rsm->addRootEntityFromClassMetadata(City::CLASSNAME, 'c'); - $rsm->addJoinedEntityFromClassMetadata(State::CLASSNAME, 's', 'c', 'state', ['id'=>'state_id', 'name'=>'state_name'] + $rsm->addRootEntityFromClassMetadata(City::class, 'c'); + $rsm->addJoinedEntityFromClassMetadata(State::class, 's', 'c', 'state', ['id'=>'state_id', 'name'=>'state_name'] ); - $rsm->addJoinedEntityFromClassMetadata(Country::CLASSNAME, 'co', 's', 'country', ['id'=>'country_id', 'name'=>'country_name'] + $rsm->addJoinedEntityFromClassMetadata(Country::class, 'co', 's', 'country', ['id'=>'country_id', 'name'=>'country_name'] ); for ($i = 0; $i < 4; $i++) { @@ -189,19 +192,19 @@ public function testPutToOneAssociation2LevelsQueryResult() $this->assertArrayHasKey('put', $this->region->calls); $this->assertCount(13, $this->region->calls['put']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][0]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][1]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][2]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][3]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][4]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][5]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][6]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][7]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][8]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][9]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][10]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][11]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\QueryCacheKey', $this->region->calls['put'][12]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][0]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][1]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][2]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][3]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][4]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][5]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][6]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][7]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][8]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][9]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][10]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][11]['key']); + $this->assertInstanceOf(QueryCacheKey::class, $this->region->calls['put'][12]['key']); } public function testPutToOneAssociationNullQueryResult() @@ -210,10 +213,10 @@ public function testPutToOneAssociationNullQueryResult() $uow = $this->em->getUnitOfWork(); $key = new QueryCacheKey('query.key1', 0); $rsm = new ResultSetMappingBuilder($this->em); - $cityClass = $this->em->getClassMetadata(City::CLASSNAME); + $cityClass = $this->em->getClassMetadata(City::class); - $rsm->addRootEntityFromClassMetadata(City::CLASSNAME, 'c'); - $rsm->addJoinedEntityFromClassMetadata(State::CLASSNAME, 's', 'c', 'state', ['id'=>'state_id', 'name'=>'state_name'] + $rsm->addRootEntityFromClassMetadata(City::class, 'c'); + $rsm->addJoinedEntityFromClassMetadata(State::class, 's', 'c', 'state', ['id'=>'state_id', 'name'=>'state_name'] ); for ($i = 0; $i < 4; $i++) { @@ -229,11 +232,11 @@ public function testPutToOneAssociationNullQueryResult() $this->assertArrayHasKey('put', $this->region->calls); $this->assertCount(5, $this->region->calls['put']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][0]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][1]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][2]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][3]['key']); - $this->assertInstanceOf('Doctrine\ORM\Cache\QueryCacheKey', $this->region->calls['put'][4]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][0]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][1]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][2]['key']); + $this->assertInstanceOf(EntityCacheKey::class, $this->region->calls['put'][3]['key']); + $this->assertInstanceOf(QueryCacheKey::class, $this->region->calls['put'][4]['key']); } public function testPutToManyAssociationQueryResult() @@ -242,11 +245,11 @@ public function testPutToManyAssociationQueryResult() $uow = $this->em->getUnitOfWork(); $key = new QueryCacheKey('query.key1', 0); $rsm = new ResultSetMappingBuilder($this->em); - $cityClass = $this->em->getClassMetadata(City::CLASSNAME); - $stateClass = $this->em->getClassMetadata(State::CLASSNAME); + $cityClass = $this->em->getClassMetadata(City::class); + $stateClass = $this->em->getClassMetadata(State::class); - $rsm->addRootEntityFromClassMetadata(State::CLASSNAME, 's'); - $rsm->addJoinedEntityFromClassMetadata(City::CLASSNAME, 'c', 's', 'cities', ['id'=>'c_id', 'name'=>'c_name']); + $rsm->addRootEntityFromClassMetadata(State::class, 's'); + $rsm->addJoinedEntityFromClassMetadata(City::class, 'c', 's', 'cities', ['id'=>'c_id', 'name'=>'c_name']); for ($i = 0; $i < 4; $i++) { $state = new State("State $i"); @@ -291,16 +294,16 @@ public function testGetBasicQueryResult() ]; $this->region->addReturn('get', $entry); - $this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $data[0])); - $this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $data[1])); + $this->region->addReturn('get', new EntityCacheEntry(Country::class, $data[0])); + $this->region->addReturn('get', new EntityCacheEntry(Country::class, $data[1])); - $rsm->addRootEntityFromClassMetadata(Country::CLASSNAME, 'c'); + $rsm->addRootEntityFromClassMetadata(Country::class, 'c'); $result = $this->queryCache->get($key, $rsm); $this->assertCount(2, $result); - $this->assertInstanceOf(Country::CLASSNAME, $result[0]); - $this->assertInstanceOf(Country::CLASSNAME, $result[1]); + $this->assertInstanceOf(Country::class, $result[0]); + $this->assertInstanceOf(Country::class, $result[1]); $this->assertEquals(1, $result[0]->getId()); $this->assertEquals(2, $result[1]->getId()); $this->assertEquals('Foo', $result[0]->getName()); @@ -312,9 +315,9 @@ public function testCancelPutResultIfEntityPutFails() $result = []; $key = new QueryCacheKey('query.key1', 0); $rsm = new ResultSetMappingBuilder($this->em); - $metadata = $this->em->getClassMetadata(Country::CLASSNAME); + $metadata = $this->em->getClassMetadata(Country::class); - $rsm->addRootEntityFromClassMetadata(Country::CLASSNAME, 'c'); + $rsm->addRootEntityFromClassMetadata(Country::class, 'c'); for ($i = 0; $i < 4; $i++) { $name = "Country $i"; @@ -338,11 +341,11 @@ public function testCancelPutResultIfAssociationEntityPutFails() $uow = $this->em->getUnitOfWork(); $key = new QueryCacheKey('query.key1', 0); $rsm = new ResultSetMappingBuilder($this->em); - $cityClass = $this->em->getClassMetadata(City::CLASSNAME); - $stateClass = $this->em->getClassMetadata(State::CLASSNAME); + $cityClass = $this->em->getClassMetadata(City::class); + $stateClass = $this->em->getClassMetadata(State::class); - $rsm->addRootEntityFromClassMetadata(City::CLASSNAME, 'c'); - $rsm->addJoinedEntityFromClassMetadata(State::CLASSNAME, 's', 'c', 'state', ['id'=>'state_id', 'name'=>'state_name'] + $rsm->addRootEntityFromClassMetadata(City::class, 'c'); + $rsm->addJoinedEntityFromClassMetadata(State::class, 's', 'c', 'state', ['id'=>'state_id', 'name'=>'state_name'] ); $state = new State("State 1"); @@ -367,11 +370,11 @@ public function testCancelPutToManyAssociationQueryResult() $uow = $this->em->getUnitOfWork(); $key = new QueryCacheKey('query.key1', 0); $rsm = new ResultSetMappingBuilder($this->em); - $cityClass = $this->em->getClassMetadata(City::CLASSNAME); - $stateClass = $this->em->getClassMetadata(State::CLASSNAME); + $cityClass = $this->em->getClassMetadata(City::class); + $stateClass = $this->em->getClassMetadata(State::class); - $rsm->addRootEntityFromClassMetadata(State::CLASSNAME, 's'); - $rsm->addJoinedEntityFromClassMetadata(City::CLASSNAME, 'c', 's', 'cities', ['id'=>'c_id', 'name'=>'c_name']); + $rsm->addRootEntityFromClassMetadata(State::class, 's'); + $rsm->addJoinedEntityFromClassMetadata(City::class, 'c', 's', 'cities', ['id'=>'c_id', 'name'=>'c_name']); $state = new State("State"); $city1 = new City("City 1", $state); @@ -409,7 +412,7 @@ public function testIgnoreCacheNonGetMode() ] ); - $rsm->addRootEntityFromClassMetadata(Country::CLASSNAME, 'c'); + $rsm->addRootEntityFromClassMetadata(Country::class, 'c'); $this->region->addReturn('get', $entry); @@ -420,10 +423,10 @@ public function testIgnoreCacheNonPutMode() { $result = []; $rsm = new ResultSetMappingBuilder($this->em); - $metadata = $this->em->getClassMetadata(Country::CLASSNAME); + $metadata = $this->em->getClassMetadata(Country::class); $key = new QueryCacheKey('query.key1', 0, Cache::MODE_GET); - $rsm->addRootEntityFromClassMetadata(Country::CLASSNAME, 'c'); + $rsm->addRootEntityFromClassMetadata(Country::class, 'c'); for ($i = 0; $i < 4; $i++) { $name = "Country $i"; @@ -455,10 +458,10 @@ public function testGetShouldIgnoreOldQueryCacheEntryResult() $entry->time = microtime(true) - 100; $this->region->addReturn('get', $entry); - $this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $entities[0])); - $this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $entities[1])); + $this->region->addReturn('get', new EntityCacheEntry(Country::class, $entities[0])); + $this->region->addReturn('get', new EntityCacheEntry(Country::class, $entities[1])); - $rsm->addRootEntityFromClassMetadata(Country::CLASSNAME, 'c'); + $rsm->addRootEntityFromClassMetadata(Country::class, 'c'); $this->assertNull($this->queryCache->get($key, $rsm)); } @@ -480,10 +483,10 @@ public function testGetShouldIgnoreNonQueryCacheEntryResult() ]; $this->region->addReturn('get', $entry); - $this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $data[0])); - $this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $data[1])); + $this->region->addReturn('get', new EntityCacheEntry(Country::class, $data[0])); + $this->region->addReturn('get', new EntityCacheEntry(Country::class, $data[1])); - $rsm->addRootEntityFromClassMetadata(Country::CLASSNAME, 'c'); + $rsm->addRootEntityFromClassMetadata(Country::class, 'c'); $this->assertNull($this->queryCache->get($key, $rsm)); } @@ -502,7 +505,7 @@ public function testGetShouldIgnoreMissingEntityQueryCacheEntry() $this->region->addReturn('get', $entry); $this->region->addReturn('get', null); - $rsm->addRootEntityFromClassMetadata(Country::CLASSNAME, 'c'); + $rsm->addRootEntityFromClassMetadata(Country::class, 'c'); $this->assertNull($this->queryCache->get($key, $rsm)); } @@ -527,13 +530,13 @@ public function testGetAssociationValue() $munich->addAttraction(new Restaurant('Schneider Weisse', $munich)); $wurzburg->addAttraction(new Restaurant('Fischers Fritz', $wurzburg)); - $rsm->addRootEntityFromClassMetadata(State::CLASSNAME, 's'); - $rsm->addJoinedEntityFromClassMetadata(City::CLASSNAME, 'c', 's', 'cities', [ + $rsm->addRootEntityFromClassMetadata(State::class, 's'); + $rsm->addJoinedEntityFromClassMetadata(City::class, 'c', 's', 'cities', [ 'id' => 'c_id', 'name' => 'c_name' ] ); - $rsm->addJoinedEntityFromClassMetadata(Restaurant::CLASSNAME, 'a', 'c', 'attractions', [ + $rsm->addJoinedEntityFromClassMetadata(Restaurant::class, 'a', 'c', 'attractions', [ 'id' => 'a_id', 'name' => 'a_name' ] @@ -545,9 +548,9 @@ public function testGetAssociationValue() $this->assertCount(2, $cities); $this->assertCount(2, $attractions); - $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $cities); - $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $attractions[0]); - $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $attractions[1]); + $this->assertInstanceOf(Collection::class, $cities); + $this->assertInstanceOf(Collection::class, $attractions[0]); + $this->assertInstanceOf(Collection::class, $attractions[1]); $this->assertCount(2, $attractions[0]); $this->assertCount(1, $attractions[1]); @@ -578,8 +581,8 @@ public function testSupportMultipleRootEntitiesException() $key = new QueryCacheKey('query.key1', 0); $rsm = new ResultSetMappingBuilder($this->em); - $rsm->addEntityResult('Doctrine\Tests\Models\Cache\City', 'e1'); - $rsm->addEntityResult('Doctrine\Tests\Models\Cache\State', 'e2'); + $rsm->addEntityResult(City::class, 'e1'); + $rsm->addEntityResult(State::class, 'e2'); $this->queryCache->put($key, $rsm, $result); } @@ -593,9 +596,7 @@ public function testNotCacheableEntityException() $result = []; $key = new QueryCacheKey('query.key1', 0); $rsm = new ResultSetMappingBuilder($this->em); - $className = 'Doctrine\Tests\Models\Generic\BooleanModel'; - - $rsm->addRootEntityFromClassMetadata($className, 'c'); + $rsm->addRootEntityFromClassMetadata(BooleanModel::class, 'c'); for ($i = 0; $i < 4; $i++) { $entity = new BooleanModel(); diff --git a/tests/Doctrine/Tests/ORM/Cache/FileLockRegionTest.php b/tests/Doctrine/Tests/ORM/Cache/FileLockRegionTest.php index 5bb771ce756..1162f3c6aa6 100644 --- a/tests/Doctrine/Tests/ORM/Cache/FileLockRegionTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/FileLockRegionTest.php @@ -2,15 +2,15 @@ namespace Doctrine\Tests\ORM\Cache; +use Doctrine\ORM\Cache\CacheKey; +use Doctrine\ORM\Cache\ConcurrentRegion; +use Doctrine\ORM\Cache\Lock; use Doctrine\ORM\Cache\Region\DefaultRegion; use Doctrine\ORM\Cache\Region\FileLockRegion; -use Doctrine\ORM\Cache\ConcurrentRegion; use Doctrine\Tests\Mocks\CacheEntryMock; use Doctrine\Tests\Mocks\CacheKeyMock; -use Doctrine\ORM\Cache\CacheKey; - -use RecursiveIteratorIterator; use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; /** * @group DDC-2183 @@ -77,7 +77,7 @@ public function testLockAndUnlock() $lock = $this->region->lock($key); $this->assertFileExists($file); - $this->assertInstanceOf('Doctrine\ORM\Cache\Lock', $lock); + $this->assertInstanceOf(Lock::class, $lock); $this->assertEquals($lock->value, file_get_contents($file)); // should be not available after lock @@ -121,7 +121,7 @@ public function testUnlockWithExistingLock() $this->assertTrue($this->region->put($key, $entry)); $this->assertTrue($this->region->contains($key)); - $this->assertInstanceOf('Doctrine\ORM\Cache\Lock', $lock = $this->region->lock($key)); + $this->assertInstanceOf(Lock::class, $lock = $this->region->lock($key)); $this->assertEquals($lock->value, file_get_contents($file)); $this->assertFileExists($file); @@ -173,7 +173,7 @@ public function testLockedEvict() $this->assertTrue($this->region->put($key, $entry)); $this->assertTrue($this->region->contains($key)); - $this->assertInstanceOf('Doctrine\ORM\Cache\Lock', $lock = $this->region->lock($key)); + $this->assertInstanceOf(Lock::class, $lock = $this->region->lock($key)); $this->assertEquals($lock->value, file_get_contents($file)); $this->assertFileExists($file); @@ -201,8 +201,8 @@ public function testLockedEvictAll() $this->assertTrue($this->region->put($key2, $entry2)); $this->assertTrue($this->region->contains($key2)); - $this->assertInstanceOf('Doctrine\ORM\Cache\Lock', $lock1 = $this->region->lock($key1)); - $this->assertInstanceOf('Doctrine\ORM\Cache\Lock', $lock2 = $this->region->lock($key2)); + $this->assertInstanceOf(Lock::class, $lock1 = $this->region->lock($key1)); + $this->assertInstanceOf(Lock::class, $lock2 = $this->region->lock($key2)); $this->assertEquals($lock2->value, file_get_contents($file2)); $this->assertEquals($lock1->value, file_get_contents($file1)); @@ -233,7 +233,7 @@ public function testLockLifetime() $this->assertTrue($this->region->put($key, $entry)); $this->assertTrue($this->region->contains($key)); - $this->assertInstanceOf('Doctrine\ORM\Cache\Lock', $lock = $this->region->lock($key)); + $this->assertInstanceOf(Lock::class, $lock = $this->region->lock($key)); $this->assertEquals($lock->value, file_get_contents($file)); $this->assertFileExists($file); diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/AbstractCollectionPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/AbstractCollectionPersisterTest.php index 681b43f0b19..c950cea70df 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/AbstractCollectionPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/AbstractCollectionPersisterTest.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\ORM\Cache\Persister\Collection; +use Doctrine\ORM\Cache\Persister\CachedPersister; +use Doctrine\ORM\Cache\Persister\Collection\CachedCollectionPersister; use Doctrine\ORM\PersistentCollection; use Doctrine\Tests\OrmTestCase; @@ -101,7 +103,7 @@ protected function createRegion() protected function createCollection($owner, $assoc = null, $class = null, $elements = null) { $em = $this->em; - $class = $class ?: $this->em->getClassMetadata('Doctrine\Tests\Models\Cache\State'); + $class = $class ?: $this->em->getClassMetadata(State::class); $assoc = $assoc ?: $class->associationMappings['cities']; $coll = new PersistentCollection($em, $class, $elements ?: new ArrayCollection); @@ -113,7 +115,7 @@ protected function createCollection($owner, $assoc = null, $class = null, $eleme protected function createPersisterDefault() { - $assoc = $this->em->getClassMetadata('Doctrine\Tests\Models\Cache\State')->associationMappings['cities']; + $assoc = $this->em->getClassMetadata(State::class)->associationMappings['cities']; return $this->createPersister($this->em, $this->collectionPersister, $this->region, $assoc); } @@ -122,9 +124,9 @@ public function testImplementsEntityPersister() { $persister = $this->createPersisterDefault(); - $this->assertInstanceOf('Doctrine\ORM\Persisters\Collection\CollectionPersister', $persister); - $this->assertInstanceOf('Doctrine\ORM\Cache\Persister\CachedPersister', $persister); - $this->assertInstanceOf('Doctrine\ORM\Cache\Persister\Collection\CachedCollectionPersister', $persister); + $this->assertInstanceOf(CollectionPersister::class, $persister); + $this->assertInstanceOf(CachedPersister::class, $persister); + $this->assertInstanceOf(CachedCollectionPersister::class, $persister); } public function testInvokeDelete() diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersisterTest.php index 1c1e12b6dfd..6b7be1f751f 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersisterTest.php @@ -52,7 +52,7 @@ public function testDeleteShouldLockItem() $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $key = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id'=>1]); + $key = new CollectionCacheKey(State::class, 'cities', ['id'=>1]); $this->region->expects($this->once()) ->method('lock') @@ -70,7 +70,7 @@ public function testUpdateShouldLockItem() $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $key = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id'=>1]); + $key = new CollectionCacheKey(State::class, 'cities', ['id'=>1]); $this->region->expects($this->once()) ->method('lock') @@ -88,7 +88,7 @@ public function testUpdateTransactionRollBackShouldEvictItem() $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $key = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id'=>1]); + $key = new CollectionCacheKey(State::class, 'cities', ['id'=>1]); $this->region->expects($this->once()) ->method('lock') @@ -112,7 +112,7 @@ public function testDeleteTransactionRollBackShouldEvictItem() $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $key = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id'=>1]); + $key = new CollectionCacheKey(State::class, 'cities', ['id'=>1]); $this->region->expects($this->once()) ->method('lock') @@ -135,8 +135,8 @@ public function testTransactionRollBackDeleteShouldClearQueue() $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $key = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id'=>1]); - $property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Collection\ReadWriteCachedCollectionPersister', 'queuedCache'); + $key = new CollectionCacheKey(State::class, 'cities', ['id'=>1]); + $property = new \ReflectionProperty(ReadWriteCachedCollectionPersister::class, 'queuedCache'); $property->setAccessible(true); @@ -166,8 +166,8 @@ public function testTransactionRollBackUpdateShouldClearQueue() $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $key = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id'=>1]); - $property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Collection\ReadWriteCachedCollectionPersister', 'queuedCache'); + $key = new CollectionCacheKey(State::class, 'cities', ['id'=>1]); + $property = new \ReflectionProperty(ReadWriteCachedCollectionPersister::class, 'queuedCache'); $property->setAccessible(true); @@ -197,8 +197,8 @@ public function testTransactionRollCommitDeleteShouldClearQueue() $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $key = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id'=>1]); - $property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Collection\ReadWriteCachedCollectionPersister', 'queuedCache'); + $key = new CollectionCacheKey(State::class, 'cities', ['id'=>1]); + $property = new \ReflectionProperty(ReadWriteCachedCollectionPersister::class, 'queuedCache'); $property->setAccessible(true); @@ -228,8 +228,8 @@ public function testTransactionRollCommitUpdateShouldClearQueue() $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $key = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id'=>1]); - $property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Collection\ReadWriteCachedCollectionPersister', 'queuedCache'); + $key = new CollectionCacheKey(State::class, 'cities', ['id'=>1]); + $property = new \ReflectionProperty(ReadWriteCachedCollectionPersister::class, 'queuedCache'); $property->setAccessible(true); @@ -258,8 +258,8 @@ public function testDeleteLockFailureShouldIgnoreQueue() $entity = new State("Foo"); $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $key = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id'=>1]); - $property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Collection\ReadWriteCachedCollectionPersister', 'queuedCache'); + $key = new CollectionCacheKey(State::class, 'cities', ['id'=>1]); + $property = new \ReflectionProperty(ReadWriteCachedCollectionPersister::class, 'queuedCache'); $property->setAccessible(true); @@ -283,8 +283,8 @@ public function testUpdateLockFailureShouldIgnoreQueue() $entity = new State("Foo"); $persister = $this->createPersisterDefault(); $collection = $this->createCollection($entity); - $key = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id'=>1]); - $property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Collection\ReadWriteCachedCollectionPersister', 'queuedCache'); + $key = new CollectionCacheKey(State::class, 'cities', ['id'=>1]); + $property = new \ReflectionProperty(ReadWriteCachedCollectionPersister::class, 'queuedCache'); $property->setAccessible(true); diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/AbstractEntityPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/AbstractEntityPersisterTest.php index 7e4d83663c7..09c7221f522 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/AbstractEntityPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/AbstractEntityPersisterTest.php @@ -2,18 +2,18 @@ namespace Doctrine\Tests\ORM\Cache\Persister\Entity; -use Doctrine\Tests\OrmTestCase; - +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Criteria; +use Doctrine\ORM\Cache\Persister\CachedPersister; +use Doctrine\ORM\Cache\Persister\Entity\CachedEntityPersister; use Doctrine\ORM\Cache\Region; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\PersistentCollection; use Doctrine\ORM\Persisters\Entity\EntityPersister; - -use Doctrine\Tests\Models\Cache\Country; -use Doctrine\Common\Collections\Criteria; -use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Query\ResultSetMappingBuilder; -use Doctrine\ORM\PersistentCollection; +use Doctrine\Tests\Models\Cache\Country; +use Doctrine\Tests\OrmTestCase; /** * @group DDC-2183 @@ -119,16 +119,16 @@ protected function createRegion() */ protected function createPersisterDefault() { - return $this->createPersister($this->em, $this->entityPersister, $this->region, $this->em->getClassMetadata('Doctrine\Tests\Models\Cache\Country')); + return $this->createPersister($this->em, $this->entityPersister, $this->region, $this->em->getClassMetadata(Country::class)); } public function testImplementsEntityPersister() { $persister = $this->createPersisterDefault(); - $this->assertInstanceOf('Doctrine\ORM\Persisters\Entity\EntityPersister', $persister); - $this->assertInstanceOf('Doctrine\ORM\Cache\Persister\CachedPersister', $persister); - $this->assertInstanceOf('Doctrine\ORM\Cache\Persister\Entity\CachedEntityPersister', $persister); + $this->assertInstanceOf(EntityPersister::class, $persister); + $this->assertInstanceOf(CachedPersister::class, $persister); + $this->assertInstanceOf(CachedEntityPersister::class, $persister); } public function testInvokeAddInsert() @@ -293,7 +293,7 @@ public function testInvokeLoadAll() $persister = $this->createPersisterDefault(); $entity = new Country("Foo"); - $rsm->addEntityResult(Country::CLASSNAME, 'c'); + $rsm->addEntityResult(Country::class, 'c'); $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); @@ -356,7 +356,7 @@ public function testInvokeLoadCriteria() $criteria = new Criteria(); $this->em->getUnitOfWork()->registerManaged($entity, ['id'=>1], ['id'=>1, 'name'=>'Foo']); - $rsm->addEntityResult(Country::CLASSNAME, 'c'); + $rsm->addEntityResult(Country::class, 'c'); $this->entityPersister->expects($this->once()) ->method('getResultSetMapping') @@ -398,7 +398,7 @@ public function testInvokeGetOneToManyCollection() public function testInvokeLoadManyToManyCollection() { - $mapping = $this->em->getClassMetadata('Doctrine\Tests\Models\Cache\Country'); + $mapping = $this->em->getClassMetadata(Country::class); $assoc = ['type' => 1]; $coll = new PersistentCollection($this->em, $mapping, new ArrayCollection()); $persister = $this->createPersisterDefault(); @@ -414,7 +414,7 @@ public function testInvokeLoadManyToManyCollection() public function testInvokeLoadOneToManyCollection() { - $mapping = $this->em->getClassMetadata('Doctrine\Tests\Models\Cache\Country'); + $mapping = $this->em->getClassMetadata(Country::class); $assoc = ['type' => 1]; $coll = new PersistentCollection($this->em, $mapping, new ArrayCollection()); $persister = $this->createPersisterDefault(); diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersisterTest.php index ad05020e6b8..0f1e67b0f63 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersisterTest.php @@ -48,8 +48,8 @@ public function testInsertTransactionCommitShouldPutCache() { $entity = new Country("Foo"); $persister = $this->createPersisterDefault(); - $key = new EntityCacheKey(Country::CLASSNAME, ['id'=>1]); - $entry = new EntityCacheEntry(Country::CLASSNAME, ['id'=>1, 'name'=>'Foo']); + $key = new EntityCacheKey(Country::class, ['id'=>1]); + $entry = new EntityCacheEntry(Country::class, ['id'=>1, 'name'=>'Foo']); $property = new \ReflectionProperty($persister, 'queuedCache'); $property->setAccessible(true); @@ -85,8 +85,8 @@ public function testUpdateTransactionCommitShouldPutCache() { $entity = new Country("Foo"); $persister = $this->createPersisterDefault(); - $key = new EntityCacheKey(Country::CLASSNAME, ['id'=>1]); - $entry = new EntityCacheEntry(Country::CLASSNAME, ['id'=>1, 'name'=>'Foo']); + $key = new EntityCacheKey(Country::class, ['id'=>1]); + $entry = new EntityCacheEntry(Country::class, ['id'=>1, 'name'=>'Foo']); $property = new \ReflectionProperty($persister, 'queuedCache'); $property->setAccessible(true); @@ -114,7 +114,7 @@ public function testDeleteTransactionCommitShouldEvictCache() { $entity = new Country("Foo"); $persister = $this->createPersisterDefault(); - $key = new EntityCacheKey(Country::CLASSNAME, ['id'=>1]); + $key = new EntityCacheKey(Country::class, ['id'=>1]); $property = new \ReflectionProperty($persister, 'queuedCache'); $property->setAccessible(true); diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersisterTest.php index d90fd678b39..06748282c73 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersisterTest.php @@ -52,7 +52,7 @@ public function testDeleteShouldLockItem() $entity = new Country("Foo"); $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); - $key = new EntityCacheKey(Country::CLASSNAME, ['id'=>1]); + $key = new EntityCacheKey(Country::class, ['id'=>1]); $this->region->expects($this->once()) ->method('lock') @@ -69,7 +69,7 @@ public function testUpdateShouldLockItem() $entity = new Country("Foo"); $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); - $key = new EntityCacheKey(Country::CLASSNAME, ['id'=>1]); + $key = new EntityCacheKey(Country::class, ['id'=>1]); $this->region->expects($this->once()) ->method('lock') @@ -86,7 +86,7 @@ public function testUpdateTransactionRollBackShouldEvictItem() $entity = new Country("Foo"); $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); - $key = new EntityCacheKey(Country::CLASSNAME, ['id'=>1]); + $key = new EntityCacheKey(Country::class, ['id'=>1]); $this->region->expects($this->once()) ->method('lock') @@ -109,7 +109,7 @@ public function testDeleteTransactionRollBackShouldEvictItem() $entity = new Country("Foo"); $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); - $key = new EntityCacheKey(Country::CLASSNAME, ['id'=>1]); + $key = new EntityCacheKey(Country::class, ['id'=>1]); $this->region->expects($this->once()) ->method('lock') @@ -131,8 +131,8 @@ public function testTransactionRollBackShouldClearQueue() $entity = new Country("Foo"); $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); - $key = new EntityCacheKey(Country::CLASSNAME, ['id'=>1]); - $property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister', 'queuedCache'); + $key = new EntityCacheKey(Country::class, ['id'=>1]); + $property = new \ReflectionProperty(ReadWriteCachedEntityPersister::class, 'queuedCache'); $property->setAccessible(true); @@ -162,8 +162,8 @@ public function testTransactionCommitShouldClearQueue() $entity = new Country("Foo"); $lock = Lock::createLockRead(); $persister = $this->createPersisterDefault(); - $key = new EntityCacheKey(Country::CLASSNAME, ['id'=>1]); - $property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister', 'queuedCache'); + $key = new EntityCacheKey(Country::class, ['id'=>1]); + $property = new \ReflectionProperty(ReadWriteCachedEntityPersister::class, 'queuedCache'); $property->setAccessible(true); @@ -192,8 +192,8 @@ public function testDeleteLockFailureShouldIgnoreQueue() { $entity = new Country("Foo"); $persister = $this->createPersisterDefault(); - $key = new EntityCacheKey(Country::CLASSNAME, ['id'=>1]); - $property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister', 'queuedCache'); + $key = new EntityCacheKey(Country::class, ['id'=>1]); + $property = new \ReflectionProperty(ReadWriteCachedEntityPersister::class, 'queuedCache'); $property->setAccessible(true); @@ -216,8 +216,8 @@ public function testUpdateLockFailureShouldIgnoreQueue() { $entity = new Country("Foo"); $persister = $this->createPersisterDefault(); - $key = new EntityCacheKey(Country::CLASSNAME, ['id'=>1]); - $property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister', 'queuedCache'); + $key = new EntityCacheKey(Country::class, ['id'=>1]); + $property = new \ReflectionProperty(ReadWriteCachedEntityPersister::class, 'queuedCache'); $property->setAccessible(true); diff --git a/tests/Doctrine/Tests/ORM/Cache/StatisticsCacheLoggerTest.php b/tests/Doctrine/Tests/ORM/Cache/StatisticsCacheLoggerTest.php index 0d5a7223719..e9f04f350ed 100644 --- a/tests/Doctrine/Tests/ORM/Cache/StatisticsCacheLoggerTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/StatisticsCacheLoggerTest.php @@ -29,7 +29,7 @@ protected function setUp() public function testEntityCache() { $name = 'my_entity_region'; - $key = new EntityCacheKey(State::CLASSNAME, ['id' => 1]); + $key = new EntityCacheKey(State::class, ['id' => 1]); $this->logger->entityCacheHit($name, $key); $this->logger->entityCachePut($name, $key); @@ -46,7 +46,7 @@ public function testEntityCache() public function testCollectionCache() { $name = 'my_collection_region'; - $key = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id' => 1]); + $key = new CollectionCacheKey(State::class, 'cities', ['id' => 1]); $this->logger->collectionCacheHit($name, $key); $this->logger->collectionCachePut($name, $key); @@ -83,8 +83,8 @@ public function testMultipleCaches() $entityRegion = 'my_entity_region'; $queryRegion = 'my_query_region'; - $coolKey = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id' => 1]); - $entityKey = new EntityCacheKey(State::CLASSNAME, ['id' => 1]); + $coolKey = new CollectionCacheKey(State::class, 'cities', ['id' => 1]); + $entityKey = new EntityCacheKey(State::class, ['id' => 1]); $queryKey = new QueryCacheKey('my_query_hash'); $this->logger->queryCacheHit($queryRegion, $queryKey); diff --git a/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php b/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php index dba00d524a6..8c9ec26c44d 100644 --- a/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php +++ b/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php @@ -24,11 +24,11 @@ protected function setUp() public function testCommitOrdering1() { - $class1 = new ClassMetadata(__NAMESPACE__ . '\NodeClass1'); - $class2 = new ClassMetadata(__NAMESPACE__ . '\NodeClass2'); - $class3 = new ClassMetadata(__NAMESPACE__ . '\NodeClass3'); - $class4 = new ClassMetadata(__NAMESPACE__ . '\NodeClass4'); - $class5 = new ClassMetadata(__NAMESPACE__ . '\NodeClass5'); + $class1 = new ClassMetadata(NodeClass1::class); + $class2 = new ClassMetadata(NodeClass2::class); + $class3 = new ClassMetadata(NodeClass3::class); + $class4 = new ClassMetadata(NodeClass4::class); + $class5 = new ClassMetadata(NodeClass5::class); $this->_calc->addNode($class1->name, $class1); $this->_calc->addNode($class2->name, $class2); @@ -51,8 +51,8 @@ public function testCommitOrdering1() public function testCommitOrdering2() { - $class1 = new ClassMetadata(__NAMESPACE__ . '\NodeClass1'); - $class2 = new ClassMetadata(__NAMESPACE__ . '\NodeClass2'); + $class1 = new ClassMetadata(NodeClass1::class); + $class2 = new ClassMetadata(NodeClass2::class); $this->_calc->addNode($class1->name, $class1); $this->_calc->addNode($class2->name, $class2); diff --git a/tests/Doctrine/Tests/ORM/ConfigurationTest.php b/tests/Doctrine/Tests/ORM/ConfigurationTest.php index 4988ac9b24c..1b0042064f3 100644 --- a/tests/Doctrine/Tests/ORM/ConfigurationTest.php +++ b/tests/Doctrine/Tests/ORM/ConfigurationTest.php @@ -7,6 +7,7 @@ use Doctrine\Common\Proxy\AbstractProxyFactory; use Doctrine\Common\Cache\ArrayCache; use Doctrine\ORM\Cache\CacheConfiguration; +use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Mapping as AnnotationNamespace; use Doctrine\ORM\Configuration; use Doctrine\ORM\Mapping\EntityListenerResolver; @@ -14,6 +15,7 @@ use Doctrine\ORM\Mapping\QuoteStrategy; use Doctrine\ORM\ORMException; use Doctrine\ORM\Query\ResultSetMapping; +use Doctrine\Tests\Models\DDC753\DDC753CustomRepository; use ReflectionClass; use PHPUnit_Framework_TestCase; @@ -76,23 +78,23 @@ public function testSetGetMetadataDriverImpl() public function testNewDefaultAnnotationDriver() { $paths = [__DIR__]; - $reflectionClass = new ReflectionClass(__NAMESPACE__ . '\ConfigurationTestAnnotationReaderChecker'); + $reflectionClass = new ReflectionClass(ConfigurationTestAnnotationReaderChecker::class); $annotationDriver = $this->configuration->newDefaultAnnotationDriver($paths, false); $reader = $annotationDriver->getReader(); $annotation = $reader->getMethodAnnotation( $reflectionClass->getMethod('namespacedAnnotationMethod'), - 'Doctrine\ORM\Mapping\PrePersist' + AnnotationNamespace\PrePersist::class ); - $this->assertInstanceOf('Doctrine\ORM\Mapping\PrePersist', $annotation); + $this->assertInstanceOf(AnnotationNamespace\PrePersist::class, $annotation); $annotationDriver = $this->configuration->newDefaultAnnotationDriver($paths); $reader = $annotationDriver->getReader(); $annotation = $reader->getMethodAnnotation( $reflectionClass->getMethod('simpleAnnotationMethod'), - 'Doctrine\ORM\Mapping\PrePersist' + AnnotationNamespace\PrePersist::class ); - $this->assertInstanceOf('Doctrine\ORM\Mapping\PrePersist', $annotation); + $this->assertInstanceOf(AnnotationNamespace\PrePersist::class, $annotation); } public function testSetGetEntityNamespace() @@ -102,7 +104,7 @@ public function testSetGetEntityNamespace() $namespaces = ['OtherNamespace' => __NAMESPACE__]; $this->configuration->setEntityNamespaces($namespaces); $this->assertSame($namespaces, $this->configuration->getEntityNamespaces()); - $this->expectException(\Doctrine\ORM\ORMException::class); + $this->expectException(ORMException::class); $this->configuration->getEntityNamespace('NonExistingNamespace'); } @@ -135,7 +137,7 @@ public function testAddGetNamedQuery() $dql = 'SELECT u FROM User u'; $this->configuration->addNamedQuery('QueryName', $dql); $this->assertSame($dql, $this->configuration->getNamedQuery('QueryName')); - $this->expectException(\Doctrine\ORM\ORMException::class); + $this->expectException(ORMException::class); $this->expectExceptionMessage('a named query'); $this->configuration->getNamedQuery('NonExistingQuery'); } @@ -148,7 +150,7 @@ public function testAddGetNamedNativeQuery() $fetched = $this->configuration->getNamedNativeQuery('QueryName'); $this->assertSame($sql, $fetched[0]); $this->assertSame($rsm, $fetched[1]); - $this->expectException(\Doctrine\ORM\ORMException::class); + $this->expectException(ORMException::class); $this->expectExceptionMessage('a named native query'); $this->configuration->getNamedNativeQuery('NonExistingQuery'); } @@ -261,7 +263,7 @@ public function testAddGetCustomStringFunction() $this->assertSame(null, $this->configuration->getCustomStringFunction('NonExistingFunction')); $this->configuration->setCustomStringFunctions(['OtherFunctionName' => __CLASS__]); $this->assertSame(__CLASS__, $this->configuration->getCustomStringFunction('OtherFunctionName')); - $this->expectException(\Doctrine\ORM\ORMException::class); + $this->expectException(ORMException::class); $this->configuration->addCustomStringFunction('concat', __CLASS__); } @@ -272,7 +274,7 @@ public function testAddGetCustomNumericFunction() $this->assertSame(null, $this->configuration->getCustomNumericFunction('NonExistingFunction')); $this->configuration->setCustomNumericFunctions(['OtherFunctionName' => __CLASS__]); $this->assertSame(__CLASS__, $this->configuration->getCustomNumericFunction('OtherFunctionName')); - $this->expectException(\Doctrine\ORM\ORMException::class); + $this->expectException(ORMException::class); $this->configuration->addCustomNumericFunction('abs', __CLASS__); } @@ -283,7 +285,7 @@ public function testAddGetCustomDatetimeFunction() $this->assertSame(null, $this->configuration->getCustomDatetimeFunction('NonExistingFunction')); $this->configuration->setCustomDatetimeFunctions(['OtherFunctionName' => __CLASS__]); $this->assertSame(__CLASS__, $this->configuration->getCustomDatetimeFunction('OtherFunctionName')); - $this->expectException(\Doctrine\ORM\ORMException::class); + $this->expectException(ORMException::class); $this->configuration->addCustomDatetimeFunction('date_add', __CLASS__); } @@ -311,7 +313,7 @@ public function testSetCustomHydrationModes() public function testSetGetClassMetadataFactoryName() { - $this->assertSame('Doctrine\ORM\Mapping\ClassMetadataFactory', $this->configuration->getClassMetadataFactoryName()); + $this->assertSame(AnnotationNamespace\ClassMetadataFactory::class, $this->configuration->getClassMetadataFactoryName()); $this->configuration->setClassMetadataFactoryName(__CLASS__); $this->assertSame(__CLASS__, $this->configuration->getClassMetadataFactoryName()); } @@ -325,17 +327,16 @@ public function testAddGetFilters() public function setDefaultRepositoryClassName() { - $this->assertSame('Doctrine\ORM\EntityRepository', $this->configuration->getDefaultRepositoryClassName()); - $repositoryClass = 'Doctrine\Tests\Models\DDC753\DDC753CustomRepository'; - $this->configuration->setDefaultRepositoryClassName($repositoryClass); - $this->assertSame($repositoryClass, $this->configuration->getDefaultRepositoryClassName()); - $this->expectException(\Doctrine\ORM\ORMException::class); + $this->assertSame(EntityRepository::class, $this->configuration->getDefaultRepositoryClassName()); + $this->configuration->setDefaultRepositoryClassName(DDC753CustomRepository::class); + $this->assertSame(DDC753CustomRepository::class, $this->configuration->getDefaultRepositoryClassName()); + $this->expectException(ORMException::class); $this->configuration->setDefaultRepositoryClassName(__CLASS__); } public function testSetGetNamingStrategy() { - $this->assertInstanceOf('Doctrine\ORM\Mapping\NamingStrategy', $this->configuration->getNamingStrategy()); + $this->assertInstanceOf(NamingStrategy::class, $this->configuration->getNamingStrategy()); $namingStrategy = $this->createMock(NamingStrategy::class); $this->configuration->setNamingStrategy($namingStrategy); $this->assertSame($namingStrategy, $this->configuration->getNamingStrategy()); @@ -343,7 +344,7 @@ public function testSetGetNamingStrategy() public function testSetGetQuoteStrategy() { - $this->assertInstanceOf('Doctrine\ORM\Mapping\QuoteStrategy', $this->configuration->getQuoteStrategy()); + $this->assertInstanceOf(QuoteStrategy::class, $this->configuration->getQuoteStrategy()); $quoteStrategy = $this->createMock(QuoteStrategy::class); $this->configuration->setQuoteStrategy($quoteStrategy); $this->assertSame($quoteStrategy, $this->configuration->getQuoteStrategy()); @@ -354,8 +355,8 @@ public function testSetGetQuoteStrategy() */ public function testSetGetEntityListenerResolver() { - $this->assertInstanceOf('Doctrine\ORM\Mapping\EntityListenerResolver', $this->configuration->getEntityListenerResolver()); - $this->assertInstanceOf('Doctrine\ORM\Mapping\DefaultEntityListenerResolver', $this->configuration->getEntityListenerResolver()); + $this->assertInstanceOf(EntityListenerResolver::class, $this->configuration->getEntityListenerResolver()); + $this->assertInstanceOf(AnnotationNamespace\DefaultEntityListenerResolver::class, $this->configuration->getEntityListenerResolver()); $resolver = $this->createMock(EntityListenerResolver::class); $this->configuration->setEntityListenerResolver($resolver); $this->assertSame($resolver, $this->configuration->getEntityListenerResolver()); diff --git a/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php b/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php index 933580af014..70841b1e7b9 100644 --- a/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php +++ b/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\ORM\Decorator; +use Doctrine\ORM\Decorator\EntityManagerDecorator; +use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query\ResultSetMapping; @@ -13,7 +15,7 @@ class EntityManagerDecoratorTest extends \PHPUnit_Framework_TestCase public function setUp() { $this->wrapped = $this->createMock(EntityManagerInterface::class); - $this->decorator = $this->getMockBuilder('Doctrine\ORM\Decorator\EntityManagerDecorator') + $this->decorator = $this->getMockBuilder(EntityManagerDecorator::class) ->setConstructorArgs([$this->wrapped]) ->setMethods(null) ->getMock(); @@ -21,7 +23,7 @@ public function setUp() public function getMethodParameters() { - $class = new \ReflectionClass('Doctrine\ORM\EntityManager'); + $class = new \ReflectionClass(EntityManager::class); $methods = []; foreach ($class->getMethods() as $method) { diff --git a/tests/Doctrine/Tests/ORM/EntityManagerTest.php b/tests/Doctrine/Tests/ORM/EntityManagerTest.php index 43471b643f5..7f36bb285b1 100644 --- a/tests/Doctrine/Tests/ORM/EntityManagerTest.php +++ b/tests/Doctrine/Tests/ORM/EntityManagerTest.php @@ -2,13 +2,22 @@ namespace Doctrine\Tests\ORM; +use Doctrine\Common\EventManager; use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; use Doctrine\Common\Persistence\Mapping\MappingException; +use Doctrine\DBAL\Connection; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; +use Doctrine\ORM\Mapping\ClassMetadataFactory; +use Doctrine\ORM\NativeQuery; use Doctrine\ORM\ORMException; use Doctrine\ORM\ORMInvalidArgumentException; +use Doctrine\ORM\Proxy\ProxyFactory; +use Doctrine\ORM\Query; use Doctrine\ORM\Query\ResultSetMapping; +use Doctrine\ORM\QueryBuilder; +use Doctrine\ORM\UnitOfWork; +use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\GeoNames\Country; use Doctrine\Tests\OrmTestCase; @@ -37,32 +46,32 @@ public function testIsOpen() public function testGetConnection() { - $this->assertInstanceOf('Doctrine\DBAL\Connection', $this->_em->getConnection()); + $this->assertInstanceOf(Connection::class, $this->_em->getConnection()); } public function testGetMetadataFactory() { - $this->assertInstanceOf('Doctrine\ORM\Mapping\ClassMetadataFactory', $this->_em->getMetadataFactory()); + $this->assertInstanceOf(ClassMetadataFactory::class, $this->_em->getMetadataFactory()); } public function testGetConfiguration() { - $this->assertInstanceOf('Doctrine\ORM\Configuration', $this->_em->getConfiguration()); + $this->assertInstanceOf(Configuration::class, $this->_em->getConfiguration()); } public function testGetUnitOfWork() { - $this->assertInstanceOf('Doctrine\ORM\UnitOfWork', $this->_em->getUnitOfWork()); + $this->assertInstanceOf(UnitOfWork::class, $this->_em->getUnitOfWork()); } public function testGetProxyFactory() { - $this->assertInstanceOf('Doctrine\ORM\Proxy\ProxyFactory', $this->_em->getProxyFactory()); + $this->assertInstanceOf(ProxyFactory::class, $this->_em->getProxyFactory()); } public function testGetEventManager() { - $this->assertInstanceOf('Doctrine\Common\EventManager', $this->_em->getEventManager()); + $this->assertInstanceOf(EventManager::class, $this->_em->getEventManager()); } public function testCreateNativeQuery() @@ -83,18 +92,18 @@ public function testCreateNamedNativeQuery() $query = $this->_em->createNamedNativeQuery('foo'); - $this->assertInstanceOf('Doctrine\ORM\NativeQuery', $query); + $this->assertInstanceOf(NativeQuery::class, $query); } public function testCreateQueryBuilder() { - $this->assertInstanceOf('Doctrine\ORM\QueryBuilder', $this->_em->createQueryBuilder()); + $this->assertInstanceOf(QueryBuilder::class, $this->_em->createQueryBuilder()); } public function testCreateQueryBuilderAliasValid() { $q = $this->_em->createQueryBuilder() - ->select('u')->from('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + ->select('u')->from(CmsUser::class, 'u'); $q2 = clone $q; $this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u', $q->getQuery()->getDql()); @@ -107,12 +116,12 @@ public function testCreateQueryBuilderAliasValid() public function testCreateQuery_DqlIsOptional() { - $this->assertInstanceOf('Doctrine\ORM\Query', $this->_em->createQuery()); + $this->assertInstanceOf(Query::class, $this->_em->createQuery()); } public function testGetPartialReference() { - $user = $this->_em->getPartialReference('Doctrine\Tests\Models\CMS\CmsUser', 42); + $user = $this->_em->getPartialReference(CmsUser::class, 42); $this->assertTrue($this->_em->contains($user)); $this->assertEquals(42, $user->id); $this->assertNull($user->getName()); @@ -121,7 +130,7 @@ public function testGetPartialReference() public function testCreateQuery() { $q = $this->_em->createQuery('SELECT 1'); - $this->assertInstanceOf('Doctrine\ORM\Query', $q); + $this->assertInstanceOf(Query::class, $q); $this->assertEquals('SELECT 1', $q->getDql()); } @@ -133,7 +142,7 @@ public function testCreateNamedQuery() $this->_em->getConfiguration()->addNamedQuery('foo', 'SELECT 1'); $query = $this->_em->createNamedQuery('foo'); - $this->assertInstanceOf('Doctrine\ORM\Query', $query); + $this->assertInstanceOf(Query::class, $query); $this->assertEquals('SELECT 1', $query->getDql()); } diff --git a/tests/Doctrine/Tests/ORM/EntityNotFoundExceptionTest.php b/tests/Doctrine/Tests/ORM/EntityNotFoundExceptionTest.php index 2da4d568f01..bc4979000e8 100644 --- a/tests/Doctrine/Tests/ORM/EntityNotFoundExceptionTest.php +++ b/tests/Doctrine/Tests/ORM/EntityNotFoundExceptionTest.php @@ -3,14 +3,13 @@ namespace Doctrine\Tests\ORM; use Doctrine\ORM\EntityNotFoundException; -use PHPUnit_Framework_TestCase; /** * Tests for {@see \Doctrine\ORM\EntityNotFoundException} * * @covers \Doctrine\ORM\EntityNotFoundException */ -class EntityNotFoundExceptionTest extends PHPUnit_Framework_TestCase +class EntityNotFoundExceptionTest extends \PHPUnit_Framework_TestCase { public function testFromClassNameAndIdentifier() { @@ -19,7 +18,7 @@ public function testFromClassNameAndIdentifier() ['foo' => 'bar'] ); - $this->assertInstanceOf('Doctrine\ORM\EntityNotFoundException', $exception); + $this->assertInstanceOf(EntityNotFoundException::class, $exception); $this->assertSame('Entity of type \'foo\' for IDs foo(bar) was not found', $exception->getMessage()); $exception = EntityNotFoundException::fromClassNameAndIdentifier( @@ -27,7 +26,7 @@ public function testFromClassNameAndIdentifier() [] ); - $this->assertInstanceOf('Doctrine\ORM\EntityNotFoundException', $exception); + $this->assertInstanceOf(EntityNotFoundException::class, $exception); $this->assertSame('Entity of type \'foo\' was not found', $exception->getMessage()); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/AdvancedAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/AdvancedAssociationTest.php index e54a23115ee..e6714500cd5 100644 --- a/tests/Doctrine/Tests/ORM/Functional/AdvancedAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/AdvancedAssociationTest.php @@ -3,7 +3,7 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Common\Collections\ArrayCollection; -use Doctrine\ORM\Query; +use Doctrine\ORM\PersistentCollection; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -18,11 +18,11 @@ protected function setUp() { try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Phrase'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\PhraseType'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Definition'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Lemma'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Type') + $this->_em->getClassMetadata(Phrase::class), + $this->_em->getClassMetadata(PhraseType::class), + $this->_em->getClassMetadata(Definition::class), + $this->_em->getClassMetadata(Lemma::class), + $this->_em->getClassMetadata(Type::class) ] ); } catch (\Exception $e) { @@ -57,7 +57,7 @@ public function testIssue() //end setup // test1 - lazy-loading many-to-one after find() - $phrase2 = $this->_em->find('Doctrine\Tests\ORM\Functional\Phrase', $phrase->getId()); + $phrase2 = $this->_em->find(Phrase::class, $phrase->getId()); $this->assertTrue(is_numeric($phrase2->getType()->getId())); $this->_em->clear(); @@ -66,8 +66,8 @@ public function testIssue() $query = $this->_em->createQuery("SELECT p,t FROM Doctrine\Tests\ORM\Functional\Phrase p JOIN p.type t"); $res = $query->getResult(); $this->assertEquals(1, count($res)); - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\PhraseType', $res[0]->getType()); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $res[0]->getType()->getPhrases()); + $this->assertInstanceOf(PhraseType::class, $res[0]->getType()); + $this->assertInstanceOf(PersistentCollection::class, $res[0]->getType()->getPhrases()); $this->assertFalse($res[0]->getType()->getPhrases()->isInitialized()); $this->_em->clear(); @@ -76,17 +76,17 @@ public function testIssue() $query = $this->_em->createQuery("SELECT p,t,pp FROM Doctrine\Tests\ORM\Functional\Phrase p JOIN p.type t JOIN t.phrases pp"); $res = $query->getResult(); $this->assertEquals(1, count($res)); - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\PhraseType', $res[0]->getType()); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $res[0]->getType()->getPhrases()); + $this->assertInstanceOf(PhraseType::class, $res[0]->getType()); + $this->assertInstanceOf(PersistentCollection::class, $res[0]->getType()->getPhrases()); $this->assertTrue($res[0]->getType()->getPhrases()->isInitialized()); $this->_em->clear(); // test3 - lazy-loading one-to-many after find() - $phrase3 = $this->_em->find('Doctrine\Tests\ORM\Functional\Phrase', $phrase->getId()); + $phrase3 = $this->_em->find(Phrase::class, $phrase->getId()); $definitions = $phrase3->getDefinitions(); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $definitions); - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Definition', $definitions[0]); + $this->assertInstanceOf(PersistentCollection::class, $definitions); + $this->assertInstanceOf(Definition::class, $definitions[0]); $this->_em->clear(); @@ -97,7 +97,7 @@ public function testIssue() $this->assertEquals(1, count($res)); - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Definition', $definitions[0]); + $this->assertInstanceOf(Definition::class, $definitions[0]); $this->assertEquals(2, $definitions->count()); } @@ -121,7 +121,7 @@ public function testManyToMany() $res = $query->getResult(); $types = $res[0]->getTypes(); - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Type', $types[0]); + $this->assertInstanceOf(Type::class, $types[0]); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php index af62cb6d5a9..a0ac9a3a7b7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php @@ -6,13 +6,15 @@ use Doctrine\ORM\EntityNotFoundException; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\ORMInvalidArgumentException; +use Doctrine\ORM\PersistentCollection; +use Doctrine\ORM\Proxy\Proxy; use Doctrine\ORM\Query; use Doctrine\ORM\UnitOfWork; -use Doctrine\Tests\Models\CMS\CmsUser; -use Doctrine\Tests\Models\CMS\CmsPhonenumber; use Doctrine\Tests\Models\CMS\CmsAddress; use Doctrine\Tests\Models\CMS\CmsArticle; use Doctrine\Tests\Models\CMS\CmsComment; +use Doctrine\Tests\Models\CMS\CmsPhonenumber; +use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\OrmFunctionalTestCase; class BasicFunctionalTest extends OrmFunctionalTestCase @@ -38,7 +40,7 @@ public function testBasicUnitsOfWorkWithOneToManyAssociation() $this->assertTrue($this->_em->contains($user)); // Read - $user2 = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $user->id); + $user2 = $this->_em->find(CmsUser::class, $user->id); $this->assertTrue($user === $user2); // Add a phonenumber @@ -138,8 +140,8 @@ public function testBasicOneToOne() ->getSingleResult(); // Address has been eager-loaded because it cant be lazy - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress', $user2->address); - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $user2->address); + $this->assertInstanceOf(CmsAddress::class, $user2->address); + $this->assertNotInstanceOf(Proxy::class, $user2->address); } /** @@ -173,7 +175,7 @@ public function testRemove() $this->assertEquals(UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($user), "State should be UnitOfWork::STATE_NEW"); - $this->assertNull($this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $id)); + $this->assertNull($this->_em->find(CmsUser::class, $id)); } public function testOneToManyOrphanRemoval() @@ -278,7 +280,7 @@ public function testBasicOneToManyLeftJoin() $this->assertEquals('Guilherme', $users[0]->name); $this->assertEquals('gblanco', $users[0]->username); $this->assertEquals('developer', $users[0]->status); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $users[0]->phonenumbers); + $this->assertInstanceOf(PersistentCollection::class, $users[0]->phonenumbers); $this->assertTrue($users[0]->phonenumbers->isInitialized()); $this->assertEquals(0, $users[0]->phonenumbers->count()); //$this->assertNull($users[0]->articles); @@ -395,7 +397,7 @@ public function testCreateEntityOfProxy() $this->_em->clear(); $userId = $user->id; - $user = $this->_em->getReference('Doctrine\Tests\Models\CMS\CmsUser', $user->id); + $user = $this->_em->getReference(CmsUser::class, $user->id); $dql = "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1"; $user = $this->_em->createQuery($dql) @@ -508,7 +510,7 @@ public function testSetSetAssociationWithGetReference() // Assume we only got the identifier of the address and now want to attach // that address to the user without actually loading it, using getReference(). - $addressRef = $this->_em->getReference('Doctrine\Tests\Models\CMS\CmsAddress', $address->getId()); + $addressRef = $this->_em->getReference(CmsAddress::class, $address->getId()); //$addressRef->getId(); //\Doctrine\Common\Util\Debug::dump($addressRef); @@ -522,8 +524,8 @@ public function testSetSetAssociationWithGetReference() $query = $this->_em->createQuery("select u, a from Doctrine\Tests\Models\CMS\CmsUser u join u.address a where u.username='gblanco'"); $gblanco = $query->getSingleResult(); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $gblanco); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress', $gblanco->getAddress()); + $this->assertInstanceOf(CmsUser::class, $gblanco); + $this->assertInstanceOf(CmsAddress::class, $gblanco->getAddress()); $this->assertEquals('Berlin', $gblanco->getAddress()->getCity()); } @@ -594,7 +596,7 @@ public function testTextColumnSaveAndRetrieve() $this->_em->flush(); $this->_em->clear(); - $articleNew = $this->_em->find('Doctrine\Tests\Models\CMS\CmsArticle', $articleId); + $articleNew = $this->_em->find(CmsArticle::class, $articleId); $this->assertEquals("Lorem ipsum dolor sunt. And stuff!", $articleNew->text); $this->assertTrue($this->_em->contains($articleNew)); } @@ -631,7 +633,7 @@ public function testFlushDoesNotIssueUnnecessaryUpdates() $user2 = $query->getSingleResult(); $this->assertEquals(1, count($user2->articles)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress', $user2->address); + $this->assertInstanceOf(CmsAddress::class, $user2->address); $oldLogger = $this->_em->getConnection()->getConfiguration()->getSQLLogger(); $debugStack = new DebugStack(); @@ -656,7 +658,7 @@ public function testRemoveEntityByReference() $this->_em->flush(); $this->_em->clear(); - $userRef = $this->_em->getReference('Doctrine\Tests\Models\CMS\CmsUser', $user->getId()); + $userRef = $this->_em->getReference(CmsUser::class, $user->getId()); $this->_em->remove($userRef); $this->_em->flush(); $this->_em->clear(); @@ -687,12 +689,12 @@ public function testQueryEntityByReference() //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - $userRef = $this->_em->getReference('Doctrine\Tests\Models\CMS\CmsUser', $user->getId()); + $userRef = $this->_em->getReference(CmsUser::class, $user->getId()); $address2 = $this->_em->createQuery('select a from Doctrine\Tests\Models\CMS\CmsAddress a where a.user = :user') ->setParameter('user', $userRef) ->getSingleResult(); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $address2->getUser()); + $this->assertInstanceOf(Proxy::class, $address2->getUser()); $this->assertTrue($userRef === $address2->getUser()); $this->assertFalse($userRef->__isInitialized__); $this->assertEquals('Germany', $address2->country); @@ -872,7 +874,7 @@ public function testGetPartialReferenceToUpdateObjectWithoutLoadingIt() $userId = $user->id; $this->_em->clear(); - $user = $this->_em->getPartialReference('Doctrine\Tests\Models\CMS\CmsUser', $userId); + $user = $this->_em->getPartialReference(CmsUser::class, $userId); $this->assertTrue($this->_em->contains($user)); $this->assertNull($user->getName()); $this->assertEquals($userId, $user->id); @@ -904,7 +906,7 @@ public function testMergePersistsNewEntities() $this->_em->clear(); $user2 = $this->_em->find(get_class($managedUser), $userId); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $user2); + $this->assertInstanceOf(CmsUser::class, $user2); } public function testMergeNonPersistedProperties() @@ -1001,9 +1003,9 @@ public function testManyToOneFetchModeQuery() $dql = "SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.id = ?1"; $article = $this->_em->createQuery($dql) ->setParameter(1, $article->id) - ->setFetchMode('Doctrine\Tests\Models\CMS\CmsArticle', 'user', ClassMetadata::FETCH_EAGER) + ->setFetchMode(CmsArticle::class, 'user', ClassMetadata::FETCH_EAGER) ->getSingleResult(); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $article->user, "It IS a proxy, ..."); + $this->assertInstanceOf(Proxy::class, $article->user, "It IS a proxy, ..."); $this->assertTrue($article->user->__isInitialized__, "...but its initialized!"); $this->assertEquals($qc+2, $this->getCurrentQueryCount()); } @@ -1045,7 +1047,7 @@ public function testClearWithEntityName() $unitOfWork = $this->_em->getUnitOfWork(); - $this->_em->clear('Doctrine\Tests\Models\CMS\CmsUser'); + $this->_em->clear(CmsUser::class); $this->assertEquals(UnitOfWork::STATE_DETACHED, $unitOfWork->getEntityState($user)); $this->assertEquals(UnitOfWork::STATE_DETACHED, $unitOfWork->getEntityState($article1)); diff --git a/tests/Doctrine/Tests/ORM/Functional/CascadeRemoveOrderTest.php b/tests/Doctrine/Tests/ORM/Functional/CascadeRemoveOrderTest.php index c552139af1c..cb19c2bcf66 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CascadeRemoveOrderTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CascadeRemoveOrderTest.php @@ -16,8 +16,8 @@ protected function setUp() $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\CascadeRemoveOrderEntityO'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\CascadeRemoveOrderEntityG'), + $this->_em->getClassMetadata(CascadeRemoveOrderEntityO::class), + $this->_em->getClassMetadata(CascadeRemoveOrderEntityG::class), ] ); } @@ -28,8 +28,8 @@ protected function tearDown() $this->_schemaTool->dropSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\CascadeRemoveOrderEntityO'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\CascadeRemoveOrderEntityG'), + $this->_em->getClassMetadata(CascadeRemoveOrderEntityO::class), + $this->_em->getClassMetadata(CascadeRemoveOrderEntityG::class), ] ); } @@ -43,7 +43,7 @@ public function testSingle() $this->_em->flush(); $this->_em->clear(); - $eOloaded = $this->_em->find('Doctrine\Tests\ORM\Functional\CascadeRemoveOrderEntityO', $eO->getId()); + $eOloaded = $this->_em->find(CascadeRemoveOrderEntityO::class, $eO->getId()); $this->_em->remove($eOloaded); $this->_em->flush(); @@ -62,7 +62,7 @@ public function testMany() $this->_em->flush(); $this->_em->clear(); - $eOloaded = $this->_em->find('Doctrine\Tests\ORM\Functional\CascadeRemoveOrderEntityO', $eO->getId()); + $eOloaded = $this->_em->find(CascadeRemoveOrderEntityO::class, $eO->getId()); $this->_em->remove($eOloaded); $this->_em->flush(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php index 9d594e8c92b..3553f9ad225 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\ORM\PersistentCollection; +use Doctrine\ORM\Proxy\Proxy; use Doctrine\Tests\Models\Company\CompanyPerson, Doctrine\Tests\Models\Company\CompanyEmployee, Doctrine\Tests\Models\Company\CompanyManager, @@ -50,8 +52,8 @@ public function testCRUD() $entities = $query->getResult(); $this->assertEquals(2, count($entities)); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyPerson', $entities[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $entities[1]); + $this->assertInstanceOf(CompanyPerson::class, $entities[0]); + $this->assertInstanceOf(CompanyEmployee::class, $entities[1]); $this->assertTrue(is_numeric($entities[0]->getId())); $this->assertTrue(is_numeric($entities[1]->getId())); $this->assertEquals('Roman S. Borschel', $entities[0]->getName()); @@ -65,7 +67,7 @@ public function testCRUD() $entities = $query->getResult(); $this->assertEquals(1, count($entities)); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $entities[0]); + $this->assertInstanceOf(CompanyEmployee::class, $entities[0]); $this->assertTrue(is_numeric($entities[0]->getId())); $this->assertEquals('Guilherme Blanco', $entities[0]->getName()); $this->assertEquals(100000, $entities[0]->getSalary()); @@ -73,7 +75,7 @@ public function testCRUD() $this->_em->clear(); $guilherme = $this->_em->getRepository(get_class($employee))->findOneBy(['name' => 'Guilherme Blanco']); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $guilherme); + $this->assertInstanceOf(CompanyEmployee::class, $guilherme); $this->assertEquals('Guilherme Blanco', $guilherme->getName()); $this->_em->clear(); @@ -108,9 +110,9 @@ public function testMultiLevelUpdateAndFind() { $this->_em->clear(); - $manager = $this->_em->find('Doctrine\Tests\Models\Company\CompanyManager', $manager->getId()); + $manager = $this->_em->find(CompanyManager::class, $manager->getId()); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyManager', $manager); + $this->assertInstanceOf(CompanyManager::class, $manager); $this->assertEquals('Roman B.', $manager->getName()); $this->assertEquals(119000, $manager->getSalary()); $this->assertEquals('CEO', $manager->getTitle()); @@ -128,9 +130,9 @@ public function testFindOnBaseClass() { $this->_em->clear(); - $person = $this->_em->find('Doctrine\Tests\Models\Company\CompanyPerson', $manager->getId()); + $person = $this->_em->find(CompanyPerson::class, $manager->getId()); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyManager', $person); + $this->assertInstanceOf(CompanyManager::class, $person); $this->assertEquals('Roman S. Borschel', $person->getName()); $this->assertEquals(100000, $person->getSalary()); $this->assertEquals('CTO', $person->getTitle()); @@ -167,9 +169,9 @@ public function testSelfReferencingOneToOne() { $result = $query->getResult(); $this->assertEquals(1, count($result)); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyPerson', $result[0]); + $this->assertInstanceOf(CompanyPerson::class, $result[0]); $this->assertEquals('Mary Smith', $result[0]->getName()); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $result[0]->getSpouse()); + $this->assertInstanceOf(CompanyEmployee::class, $result[0]->getSpouse()); $this->assertEquals('John Smith', $result[0]->getSpouse()->getName()); $this->assertSame($result[0], $result[0]->getSpouse()->getSpouse()); } @@ -229,20 +231,20 @@ public function testLazyLoading1() $result = $q->getResult(); $this->assertEquals(1, count($result)); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyOrganization', $result[0]); + $this->assertInstanceOf(CompanyOrganization::class, $result[0]); $this->assertNull($result[0]->getMainEvent()); $events = $result[0]->getEvents(); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $events); + $this->assertInstanceOf(PersistentCollection::class, $events); $this->assertFalse($events->isInitialized()); $this->assertEquals(2, count($events)); if ($events[0] instanceof CompanyAuction) { - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyRaffle', $events[1]); + $this->assertInstanceOf(CompanyRaffle::class, $events[1]); } else { - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyRaffle', $events[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyAuction', $events[1]); + $this->assertInstanceOf(CompanyRaffle::class, $events[0]); + $this->assertInstanceOf(CompanyAuction::class, $events[1]); } } @@ -263,7 +265,7 @@ public function testLazyLoading2() $result = $q->getResult(); $this->assertEquals(1, count($result)); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyAuction', $result[0], sprintf("Is of class %s",get_class($result[0]))); + $this->assertInstanceOf(CompanyAuction::class, $result[0], sprintf("Is of class %s",get_class($result[0]))); $this->_em->clear(); @@ -273,12 +275,12 @@ public function testLazyLoading2() $result = $q->getResult(); $this->assertEquals(1, count($result)); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyOrganization', $result[0]); + $this->assertInstanceOf(CompanyOrganization::class, $result[0]); $mainEvent = $result[0]->getMainEvent(); // mainEvent should have been loaded because it can't be lazy - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyAuction', $mainEvent); - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $mainEvent); + $this->assertInstanceOf(CompanyAuction::class, $mainEvent); + $this->assertNotInstanceOf(Proxy::class, $mainEvent); } /** @@ -388,12 +390,12 @@ public function testFindByAssociation() $this->_em->flush(); $this->_em->clear(); - $repos = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager'); + $repos = $this->_em->getRepository(CompanyManager::class); $pmanager = $repos->findOneBy(['spouse' => $person->getId()]); $this->assertEquals($manager->getId(), $pmanager->getId()); - $repos = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyPerson'); + $repos = $this->_em->getRepository(CompanyPerson::class); $pmanager = $repos->findOneBy(['spouse' => $person->getId()]); $this->assertEquals($manager->getId(), $pmanager->getId()); @@ -414,14 +416,14 @@ public function testGetReferenceEntityWithSubclasses() $this->_em->flush(); $this->_em->clear(); - $ref = $this->_em->getReference('Doctrine\Tests\Models\Company\CompanyPerson', $manager->getId()); - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $ref, "Cannot Request a proxy from a class that has subclasses."); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyPerson', $ref); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $ref, "Direct fetch of the reference has to load the child class Employee directly."); + $ref = $this->_em->getReference(CompanyPerson::class, $manager->getId()); + $this->assertNotInstanceOf(Proxy::class, $ref, "Cannot Request a proxy from a class that has subclasses."); + $this->assertInstanceOf(CompanyPerson::class, $ref); + $this->assertInstanceOf(CompanyEmployee::class, $ref, "Direct fetch of the reference has to load the child class Employee directly."); $this->_em->clear(); - $ref = $this->_em->getReference('Doctrine\Tests\Models\Company\CompanyManager', $manager->getId()); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $ref, "A proxy can be generated only if no subclasses exists for the requested reference."); + $ref = $this->_em->getReference(CompanyManager::class, $manager->getId()); + $this->assertInstanceOf(Proxy::class, $ref, "A proxy can be generated only if no subclasses exists for the requested reference."); } /** @@ -445,7 +447,7 @@ public function testGetSubClassManyToManyCollection() $this->_em->flush(); $this->_em->clear(); - $manager = $this->_em->find('Doctrine\Tests\Models\Company\CompanyManager', $manager->getId()); + $manager = $this->_em->find(CompanyManager::class, $manager->getId()); $this->assertEquals(1, count($manager->getFriends())); } @@ -482,13 +484,13 @@ public function testMatching() $this->_em->persist($manager); $this->_em->flush(); - $repository = $this->_em->getRepository("Doctrine\Tests\Models\Company\CompanyEmployee"); + $repository = $this->_em->getRepository(CompanyEmployee::class); $users = $repository->matching(new Criteria( Criteria::expr()->eq('department', 'IT') )); $this->assertEquals(1, count($users)); - $repository = $this->_em->getRepository("Doctrine\Tests\Models\Company\CompanyManager"); + $repository = $this->_em->getRepository(CompanyManager::class); $users = $repository->matching(new Criteria( Criteria::expr()->eq('department', 'IT') )); diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest2.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest2.php index b7988054d23..84949a6e3ed 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest2.php +++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest2.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\ORM\Proxy\Proxy; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -17,10 +18,10 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\CTIParent'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\CTIChild'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\CTIRelated'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\CTIRelated2') + $this->_em->getClassMetadata(CTIParent::class), + $this->_em->getClassMetadata(CTIChild::class), + $this->_em->getClassMetadata(CTIRelated::class), + $this->_em->getClassMetadata(CTIRelated2::class) ] ); } catch (\Exception $ignored) { @@ -44,11 +45,11 @@ public function testOneToOneAssocToBaseTypeBidirectional() $relatedId = $related->getId(); - $related2 = $this->_em->find('Doctrine\Tests\ORM\Functional\CTIRelated', $relatedId); + $related2 = $this->_em->find(CTIRelated::class, $relatedId); - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\CTIRelated', $related2); - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\CTIChild', $related2->getCTIParent()); - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $related2->getCTIParent()); + $this->assertInstanceOf(CTIRelated::class, $related2); + $this->assertInstanceOf(CTIChild::class, $related2->getCTIParent()); + $this->assertNotInstanceOf(Proxy::class, $related2->getCTIParent()); $this->assertEquals('hello', $related2->getCTIParent()->getData()); $this->assertSame($related2, $related2->getCTIParent()->getRelated()); @@ -72,7 +73,7 @@ public function testManyToManyToCTIHierarchy() $this->assertFalse($mmrel2->getCTIChildren()->isInitialized()); $this->assertEquals(1, count($mmrel2->getCTIChildren())); $this->assertTrue($mmrel2->getCTIChildren()->isInitialized()); - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\CTIChild', $mmrel2->getCTIChildren()->get(0)); + $this->assertInstanceOf(CTIChild::class, $mmrel2->getCTIChildren()->get(0)); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php index a461fea19f8..03bde6ba7cb 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php @@ -30,7 +30,7 @@ public function putGermanysBrandenburderTor() public function putTripAroundEurope() { - $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', ['lat' => 100, 'long' => 200]); + $poi = $this->_em->find(NavPointOfInterest::class, ['lat' => 100, 'long' => 200]); $tour = new NavTour("Trip around Europe"); $tour->addPointOfInterest($poi); @@ -46,9 +46,9 @@ public function testPersistCompositePkEntity() { $this->putGermanysBrandenburderTor(); - $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', ['lat' => 100, 'long' => 200]); + $poi = $this->_em->find(NavPointOfInterest::class, ['lat' => 100, 'long' => 200]); - $this->assertInstanceOf('Doctrine\Tests\Models\Navigation\NavPointOfInterest', $poi); + $this->assertInstanceOf(NavPointOfInterest::class, $poi); $this->assertEquals(100, $poi->getLat()); $this->assertEquals(200, $poi->getLong()); $this->assertEquals('Brandenburger Tor', $poi->getName()); @@ -61,7 +61,7 @@ public function testSetParameterCompositeKeyObject() { $this->putGermanysBrandenburderTor(); - $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', ['lat' => 100, 'long' => 200]); + $poi = $this->_em->find(NavPointOfInterest::class, ['lat' => 100, 'long' => 200]); $photo = new NavPhotos($poi, "asdf"); $this->_em->persist($photo); $this->_em->flush(); @@ -79,7 +79,7 @@ public function testIdentityFunctionWithCompositePrimaryKey() { $this->putGermanysBrandenburderTor(); - $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', ['lat' => 100, 'long' => 200]); + $poi = $this->_em->find(NavPointOfInterest::class, ['lat' => 100, 'long' => 200]); $photo = new NavPhotos($poi, "asdf"); $this->_em->persist($photo); $this->_em->flush(); @@ -98,7 +98,7 @@ public function testManyToManyCompositeRelation() $this->putGermanysBrandenburderTor(); $tour = $this->putTripAroundEurope(); - $tour = $this->_em->find('Doctrine\Tests\Models\Navigation\NavTour', $tour->getId()); + $tour = $this->_em->find(NavTour::class, $tour->getId()); $this->assertEquals(1, count($tour->getPointOfInterests())); } @@ -140,7 +140,7 @@ public function testSpecifyUnknownIdentifierPrimaryKeyFails() $this->expectException(ORMException::class); $this->expectExceptionMessage('The identifier long is missing for a query of Doctrine\Tests\Models\Navigation\NavPointOfInterest'); - $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', ['key1' => 100]); + $poi = $this->_em->find(NavPointOfInterest::class, ['key1' => 100]); } public function testUnrecognizedIdentifierFieldsOnGetReference() @@ -148,7 +148,7 @@ public function testUnrecognizedIdentifierFieldsOnGetReference() $this->expectException(ORMException::class); $this->expectExceptionMessage("Unrecognized identifier fields: 'key1'"); - $poi = $this->_em->getReference('Doctrine\Tests\Models\Navigation\NavPointOfInterest', ['lat' => 10, 'long' => 20, 'key1' => 100] + $poi = $this->_em->getReference(NavPointOfInterest::class, ['lat' => 10, 'long' => 20, 'key1' => 100] ); } @@ -159,7 +159,7 @@ public function testDeleteCompositePersistentCollection() { $this->putGermanysBrandenburderTor(); - $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', ['lat' => 100, 'long' => 200]); + $poi = $this->_em->find(NavPointOfInterest::class, ['lat' => 100, 'long' => 200]); $poi->addVisitor(new NavUser("test1")); $poi->addVisitor(new NavUser("test2")); @@ -170,7 +170,7 @@ public function testDeleteCompositePersistentCollection() $this->_em->flush(); $this->_em->clear(); - $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', ['lat' => 100, 'long' => 200]); + $poi = $this->_em->find(NavPointOfInterest::class, ['lat' => 100, 'long' => 200]); $this->assertEquals(0, count($poi->getVisitors())); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyWithAssociationsTest.php b/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyWithAssociationsTest.php index 3b5427f0559..533f611d402 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyWithAssociationsTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyWithAssociationsTest.php @@ -41,8 +41,8 @@ public function setUp() public function testFindByAbleToGetCompositeEntitiesWithMixedTypeIdentifiers() { - $admin1Repo = $this->_em->getRepository('Doctrine\Tests\Models\GeoNames\Admin1'); - $admin1NamesRepo = $this->_em->getRepository('Doctrine\Tests\Models\GeoNames\Admin1AlternateName'); + $admin1Repo = $this->_em->getRepository(Admin1::class); + $admin1NamesRepo = $this->_em->getRepository(Admin1AlternateName::class); $admin1Rome = $admin1Repo->findOneBy(['country' => 'IT', 'id' => 1]); diff --git a/tests/Doctrine/Tests/ORM/Functional/CustomIdObjectTypeTest.php b/tests/Doctrine/Tests/ORM/Functional/CustomIdObjectTypeTest.php index ea6fdfafffb..08d89fa8ec2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CustomIdObjectTypeTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CustomIdObjectTypeTest.php @@ -14,9 +14,9 @@ class CustomIdObjectTypeTest extends OrmFunctionalTestCase protected function setUp() { if (DBALType::hasType(CustomIdObjectType::NAME)) { - DBALType::overrideType(CustomIdObjectType::NAME, CustomIdObjectType::CLASSNAME); + DBALType::overrideType(CustomIdObjectType::NAME, CustomIdObjectType::class); } else { - DBALType::addType(CustomIdObjectType::NAME, CustomIdObjectType::CLASSNAME); + DBALType::addType(CustomIdObjectType::NAME, CustomIdObjectType::class); } $this->useModelSet('custom_id_object_type'); @@ -31,7 +31,7 @@ public function testFindByCustomIdObject() $this->_em->persist($parent); $this->_em->flush(); - $result = $this->_em->find(CustomIdObjectTypeParent::CLASSNAME, $parent->id); + $result = $this->_em->find(CustomIdObjectTypeParent::class, $parent->id); $this->assertSame($parent, $result); } @@ -53,7 +53,7 @@ public function testFetchJoinCustomIdObject() ->_em ->createQuery( 'SELECT parent, children FROM ' - . CustomIdObjectTypeParent::CLASSNAME + . CustomIdObjectTypeParent::class . ' parent LEFT JOIN parent.children children' ) ->getResult(); @@ -80,7 +80,7 @@ public function testFetchJoinWhereCustomIdObject() ->_em ->createQuery( 'SELECT parent, children FROM ' - . CustomIdObjectTypeParent::CLASSNAME + . CustomIdObjectTypeParent::class . ' parent LEFT JOIN parent.children children ' . 'WHERE children.id = ?1' ) diff --git a/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php b/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php index 75c0a20e642..2797ba8337b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php @@ -1,6 +1,7 @@ _schemaTool->createSchema( [ - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\DefaultValueUser'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\DefaultValueAddress') + $this->_em->getClassMetadata(DefaultValueUser::class), + $this->_em->getClassMetadata(DefaultValueAddress::class) ] ); } catch (\Exception $e) { @@ -55,7 +56,7 @@ public function testSimpleDetachMerge() { $this->_em->clear(); $a2 = $this->_em->find(get_class($a), $a->id); - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\DefaultValueUser', $a2->getUser()); + $this->assertInstanceOf(DefaultValueUser::class, $a2->getUser()); $this->assertEquals($userId, $a2->getUser()->getId()); $this->assertEquals('Poweruser', $a2->getUser()->type); } @@ -73,13 +74,13 @@ public function testGetPartialReferenceWithDefaultValueNotEvaluatedInFlush() $this->_em->flush(); $this->_em->clear(); - $user = $this->_em->getPartialReference('Doctrine\Tests\ORM\Functional\DefaultValueUser', $user->id); + $user = $this->_em->getPartialReference(DefaultValueUser::class, $user->id); $this->assertTrue($this->_em->getUnitOfWork()->isReadOnly($user)); $this->_em->flush(); $this->_em->clear(); - $user = $this->_em->find('Doctrine\Tests\ORM\Functional\DefaultValueUser', $user->id); + $user = $this->_em->find(DefaultValueUser::class, $user->id); $this->assertEquals('Normaluser', $user->type); } diff --git a/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php b/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php index d067836f7b1..b0326e5429d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\ORM\OptimisticLockException; +use Doctrine\ORM\Proxy\Proxy; use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\CMS\CmsPhonenumber; use Doctrine\Tests\Models\CMS\CmsAddress; @@ -90,8 +91,8 @@ public function testSerializeUnserializeModifyMerge() // Merge back in $user = $this->_em->merge($user); // merge cascaded to phonenumbers - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $user->phonenumbers[0]->user); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $user->phonenumbers[1]->user); + $this->assertInstanceOf(CmsUser::class, $user->phonenumbers[0]->user); + $this->assertInstanceOf(CmsUser::class, $user->phonenumbers[1]->user); $im = $this->_em->getUnitOfWork()->getIdentityMap(); $this->_em->flush(); @@ -100,10 +101,10 @@ public function testSerializeUnserializeModifyMerge() $this->assertNotSame($oldPhonenumbers, $phonenumbers, "Merge should replace the Detached Collection with a new PersistentCollection."); $this->assertEquals(2, count($phonenumbers), "Failed to assert that two phonenumbers are contained in the merged users phonenumber collection."); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsPhonenumber', $phonenumbers[1]); + $this->assertInstanceOf(CmsPhonenumber::class, $phonenumbers[1]); $this->assertTrue($this->_em->contains($phonenumbers[1]), "Failed to assert that second phonenumber in collection is contained inside EntityManager persistence context."); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsPhonenumber', $phonenumbers[0]); + $this->assertInstanceOf(CmsPhonenumber::class, $phonenumbers[0]); $this->assertTrue($this->_em->getUnitOfWork()->isInIdentityMap($phonenumbers[0])); $this->assertTrue($this->_em->contains($phonenumbers[0]), "Failed to assert that first phonenumber in collection is contained inside EntityManager persistence context."); } @@ -145,14 +146,14 @@ public function testUninitializedLazyAssociationsAreIgnoredOnMerge() $this->_em->clear(); $address2 = $this->_em->find(get_class($address), $address->id); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $address2->user); + $this->assertInstanceOf(Proxy::class, $address2->user); $this->assertFalse($address2->user->__isInitialized__); $detachedAddress2 = unserialize(serialize($address2)); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $detachedAddress2->user); + $this->assertInstanceOf(Proxy::class, $detachedAddress2->user); $this->assertFalse($detachedAddress2->user->__isInitialized__); $managedAddress2 = $this->_em->merge($detachedAddress2); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $managedAddress2->user); + $this->assertInstanceOf(Proxy::class, $managedAddress2->user); $this->assertFalse($managedAddress2->user === $detachedAddress2->user); $this->assertFalse($managedAddress2->user->__isInitialized__); } @@ -178,7 +179,7 @@ public function testUseDetachedEntityAsQueryParameter() $newUser = $query->getSingleResult(); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $newUser); + $this->assertInstanceOf(CmsUser::class, $newUser); $this->assertEquals('gblanco', $newUser->username); } diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityListenersTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityListenersTest.php index 64bc31770da..98457dd49db 100644 --- a/tests/Doctrine/Tests/ORM/Functional/EntityListenersTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/EntityListenersTest.php @@ -2,6 +2,10 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\Common\Persistence\Event\LifecycleEventArgs; +use Doctrine\ORM\Event\PreFlushEventArgs; +use Doctrine\ORM\Event\PreUpdateEventArgs; +use Doctrine\Tests\Models\Company\CompanyContractListener; use Doctrine\Tests\Models\Company\CompanyFixContract; use Doctrine\Tests\OrmFunctionalTestCase; @@ -23,7 +27,7 @@ protected function setUp() $this->listener = $this->_em->getConfiguration() ->getEntityListenerResolver() - ->resolve('Doctrine\Tests\Models\Company\CompanyContractListener'); + ->resolve(CompanyContractListener::class); } public function testPreFlushListeners() @@ -37,18 +41,9 @@ public function testPreFlushListeners() $this->_em->flush(); $this->assertCount(1,$this->listener->preFlushCalls); - $this->assertSame($fix, $this->listener->preFlushCalls[0][0]); - - $this->assertInstanceOf( - 'Doctrine\Tests\Models\Company\CompanyFixContract', - $this->listener->preFlushCalls[0][0] - ); - - $this->assertInstanceOf( - 'Doctrine\ORM\Event\PreFlushEventArgs', - $this->listener->preFlushCalls[0][1] - ); + $this->assertInstanceOf(CompanyFixContract::class, $this->listener->preFlushCalls[0][0]); + $this->assertInstanceOf(PreFlushEventArgs::class, $this->listener->preFlushCalls[0][1]); } public function testPostLoadListeners() @@ -66,18 +61,9 @@ public function testPostLoadListeners() $fix = $this->_em->createQuery($dql)->setParameter(1, $fix->getId())->getSingleResult(); $this->assertCount(1,$this->listener->postLoadCalls); - $this->assertSame($fix, $this->listener->postLoadCalls[0][0]); - - $this->assertInstanceOf( - 'Doctrine\Tests\Models\Company\CompanyFixContract', - $this->listener->postLoadCalls[0][0] - ); - - $this->assertInstanceOf( - 'Doctrine\ORM\Event\LifecycleEventArgs', - $this->listener->postLoadCalls[0][1] - ); + $this->assertInstanceOf(CompanyFixContract::class, $this->listener->postLoadCalls[0][0]); + $this->assertInstanceOf(LifecycleEventArgs::class, $this->listener->postLoadCalls[0][1]); } public function testPrePersistListeners() @@ -91,18 +77,9 @@ public function testPrePersistListeners() $this->_em->flush(); $this->assertCount(1,$this->listener->prePersistCalls); - $this->assertSame($fix, $this->listener->prePersistCalls[0][0]); - - $this->assertInstanceOf( - 'Doctrine\Tests\Models\Company\CompanyFixContract', - $this->listener->prePersistCalls[0][0] - ); - - $this->assertInstanceOf( - 'Doctrine\ORM\Event\LifecycleEventArgs', - $this->listener->prePersistCalls[0][1] - ); + $this->assertInstanceOf(CompanyFixContract::class, $this->listener->prePersistCalls[0][0]); + $this->assertInstanceOf(LifecycleEventArgs::class, $this->listener->prePersistCalls[0][1]); } public function testPostPersistListeners() @@ -116,18 +93,9 @@ public function testPostPersistListeners() $this->_em->flush(); $this->assertCount(1,$this->listener->postPersistCalls); - $this->assertSame($fix, $this->listener->postPersistCalls[0][0]); - - $this->assertInstanceOf( - 'Doctrine\Tests\Models\Company\CompanyFixContract', - $this->listener->postPersistCalls[0][0] - ); - - $this->assertInstanceOf( - 'Doctrine\ORM\Event\LifecycleEventArgs', - $this->listener->postPersistCalls[0][1] - ); + $this->assertInstanceOf(CompanyFixContract::class, $this->listener->postPersistCalls[0][0]); + $this->assertInstanceOf(LifecycleEventArgs::class, $this->listener->postPersistCalls[0][1]); } public function testPreUpdateListeners() @@ -146,18 +114,9 @@ public function testPreUpdateListeners() $this->_em->flush(); $this->assertCount(1,$this->listener->preUpdateCalls); - $this->assertSame($fix, $this->listener->preUpdateCalls[0][0]); - - $this->assertInstanceOf( - 'Doctrine\Tests\Models\Company\CompanyFixContract', - $this->listener->preUpdateCalls[0][0] - ); - - $this->assertInstanceOf( - 'Doctrine\ORM\Event\PreUpdateEventArgs', - $this->listener->preUpdateCalls[0][1] - ); + $this->assertInstanceOf(CompanyFixContract::class, $this->listener->preUpdateCalls[0][0]); + $this->assertInstanceOf(PreUpdateEventArgs::class, $this->listener->preUpdateCalls[0][1]); } public function testPostUpdateListeners() @@ -176,18 +135,9 @@ public function testPostUpdateListeners() $this->_em->flush(); $this->assertCount(1,$this->listener->postUpdateCalls); - $this->assertSame($fix, $this->listener->postUpdateCalls[0][0]); - - $this->assertInstanceOf( - 'Doctrine\Tests\Models\Company\CompanyFixContract', - $this->listener->postUpdateCalls[0][0] - ); - - $this->assertInstanceOf( - 'Doctrine\ORM\Event\LifecycleEventArgs', - $this->listener->postUpdateCalls[0][1] - ); + $this->assertInstanceOf(CompanyFixContract::class, $this->listener->postUpdateCalls[0][0]); + $this->assertInstanceOf(LifecycleEventArgs::class, $this->listener->postUpdateCalls[0][1]); } public function testPreRemoveListeners() @@ -204,18 +154,9 @@ public function testPreRemoveListeners() $this->_em->flush(); $this->assertCount(1,$this->listener->preRemoveCalls); - $this->assertSame($fix, $this->listener->preRemoveCalls[0][0]); - - $this->assertInstanceOf( - 'Doctrine\Tests\Models\Company\CompanyFixContract', - $this->listener->preRemoveCalls[0][0] - ); - - $this->assertInstanceOf( - 'Doctrine\ORM\Event\LifecycleEventArgs', - $this->listener->preRemoveCalls[0][1] - ); + $this->assertInstanceOf(CompanyFixContract::class, $this->listener->preRemoveCalls[0][0]); + $this->assertInstanceOf(LifecycleEventArgs::class, $this->listener->preRemoveCalls[0][1]); } public function testPostRemoveListeners() @@ -232,17 +173,8 @@ public function testPostRemoveListeners() $this->_em->flush(); $this->assertCount(1,$this->listener->postRemoveCalls); - $this->assertSame($fix, $this->listener->postRemoveCalls[0][0]); - - $this->assertInstanceOf( - 'Doctrine\Tests\Models\Company\CompanyFixContract', - $this->listener->postRemoveCalls[0][0] - ); - - $this->assertInstanceOf( - 'Doctrine\ORM\Event\LifecycleEventArgs', - $this->listener->postRemoveCalls[0][1] - ); + $this->assertInstanceOf(CompanyFixContract::class, $this->listener->postRemoveCalls[0][0]); + $this->assertInstanceOf(LifecycleEventArgs::class, $this->listener->postRemoveCalls[0][1]); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryCriteriaTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryCriteriaTest.php index 694ad66dab7..700964b97da 100644 --- a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryCriteriaTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryCriteriaTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\ORM\LazyCriteriaCollection; use Doctrine\Tests\Models\Generic\DateTimeModel; use Doctrine\Common\Collections\Criteria; use Doctrine\Tests\Models\Tweet\Tweet; @@ -64,7 +65,7 @@ public function testLteDateComparison() { $this->loadFixture(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\Generic\DateTimeModel'); + $repository = $this->_em->getRepository(DateTimeModel::class); $dates = $repository->matching(new Criteria( Criteria::expr()->lte('datetime', new \DateTime('today')) )); @@ -95,7 +96,7 @@ private function loadNullFieldFixtures() public function testIsNullComparison() { $this->loadNullFieldFixtures(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\Generic\DateTimeModel'); + $repository = $this->_em->getRepository(DateTimeModel::class); $dates = $repository->matching(new Criteria( Criteria::expr()->isNull('time') @@ -107,7 +108,7 @@ public function testIsNullComparison() public function testEqNullComparison() { $this->loadNullFieldFixtures(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\Generic\DateTimeModel'); + $repository = $this->_em->getRepository(DateTimeModel::class); $dates = $repository->matching(new Criteria( Criteria::expr()->eq('time', null) @@ -119,7 +120,7 @@ public function testEqNullComparison() public function testNotEqNullComparison() { $this->loadNullFieldFixtures(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\Generic\DateTimeModel'); + $repository = $this->_em->getRepository(DateTimeModel::class); $dates = $repository->matching(new Criteria( Criteria::expr()->neq('time', null) @@ -131,7 +132,7 @@ public function testNotEqNullComparison() public function testCanCountWithoutLoadingCollection() { $this->loadFixture(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\Generic\DateTimeModel'); + $repository = $this->_em->getRepository(DateTimeModel::class); $dates = $repository->matching(new Criteria()); @@ -171,10 +172,10 @@ public function testCanContainsWithoutLoadingCollection() $criteria = new Criteria(); $criteria->andWhere($criteria->expr()->contains('content', 'Criteria')); - $user = $this->_em->find('Doctrine\Tests\Models\Tweet\User', $user->id); + $user = $this->_em->find(User::class, $user->id); $tweets = $user->tweets->matching($criteria); - $this->assertInstanceOf('Doctrine\ORM\LazyCriteriaCollection', $tweets); + $this->assertInstanceOf(LazyCriteriaCollection::class, $tweets); $this->assertFalse($tweets->isInitialized()); $tweets->contains($tweet); diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php index 2aa25b8c784..d329b8556e3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php @@ -2,16 +2,23 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Criteria; use Doctrine\DBAL\Connection; use Doctrine\DBAL\LockMode; +use Doctrine\ORM\EntityRepository; use Doctrine\ORM\OptimisticLockException; use Doctrine\ORM\ORMException; +use Doctrine\ORM\Query; use Doctrine\ORM\TransactionRequiredException; -use Doctrine\Tests\Models\CMS\CmsUser; -use Doctrine\Tests\Models\CMS\CmsEmail; use Doctrine\Tests\Models\CMS\CmsAddress; -use Doctrine\Common\Collections\Criteria; -use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Tests\Models\CMS\CmsEmail; +use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\Models\DDC753\DDC753CustomRepository; +use Doctrine\Tests\Models\DDC753\DDC753DefaultRepository; +use Doctrine\Tests\Models\DDC753\DDC753EntityWithCustomRepository; +use Doctrine\Tests\Models\DDC753\DDC753EntityWithDefaultCustomRepository; +use Doctrine\Tests\Models\DDC753\DDC753InvalidRepository; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -170,10 +177,10 @@ public function buildAddress($country, $city, $street, $zip) public function testBasicFind() { $user1Id = $this->loadFixture(); - $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repos = $this->_em->getRepository(CmsUser::class); $user = $repos->find($user1Id); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser',$user); + $this->assertInstanceOf(CmsUser::class,$user); $this->assertEquals('Roman', $user->name); $this->assertEquals('freak', $user->status); } @@ -181,11 +188,11 @@ public function testBasicFind() public function testFindByField() { $user1Id = $this->loadFixture(); - $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repos = $this->_em->getRepository(CmsUser::class); $users = $repos->findBy(['status' => 'dev']); $this->assertEquals(2, count($users)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser',$users[0]); + $this->assertInstanceOf(CmsUser::class,$users[0]); $this->assertEquals('Guilherme', $users[0]->name); $this->assertEquals('dev', $users[0]->status); } @@ -207,11 +214,11 @@ public function testFindByAssociationWithIntegerAsParameter() $this->_em->clear(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsAddress'); + $repository = $this->_em->getRepository(CmsAddress::class); $addresses = $repository->findBy(['user' => [$user1->getId(), $user2->getId()]]); $this->assertEquals(2, count($addresses)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress',$addresses[0]); + $this->assertInstanceOf(CmsAddress::class,$addresses[0]); } public function testFindByAssociationWithObjectAsParameter() @@ -231,21 +238,21 @@ public function testFindByAssociationWithObjectAsParameter() $this->_em->clear(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsAddress'); + $repository = $this->_em->getRepository(CmsAddress::class); $addresses = $repository->findBy(['user' => [$user1, $user2]]); $this->assertEquals(2, count($addresses)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress',$addresses[0]); + $this->assertInstanceOf(CmsAddress::class,$addresses[0]); } public function testFindFieldByMagicCall() { $user1Id = $this->loadFixture(); - $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repos = $this->_em->getRepository(CmsUser::class); $users = $repos->findByStatus('dev'); $this->assertEquals(2, count($users)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser',$users[0]); + $this->assertInstanceOf(CmsUser::class,$users[0]); $this->assertEquals('Guilherme', $users[0]->name); $this->assertEquals('dev', $users[0]->status); } @@ -253,7 +260,7 @@ public function testFindFieldByMagicCall() public function testFindAll() { $user1Id = $this->loadFixture(); - $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repos = $this->_em->getRepository(CmsUser::class); $users = $repos->findAll(); $this->assertEquals(4, count($users)); @@ -262,7 +269,7 @@ public function testFindAll() public function testFindByAlias() { $user1Id = $this->loadFixture(); - $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repos = $this->_em->getRepository(CmsUser::class); $this->_em->getConfiguration()->addEntityNamespace('CMS', 'Doctrine\Tests\Models\CMS'); @@ -300,7 +307,7 @@ public function testCountBy() * @expectedException \Doctrine\ORM\ORMException */ public function testExceptionIsThrownWhenCallingFindByWithoutParameter() { - $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser') + $this->_em->getRepository(CmsUser::class) ->findByStatus(); } @@ -308,7 +315,7 @@ public function testExceptionIsThrownWhenCallingFindByWithoutParameter() { * @expectedException \Doctrine\ORM\ORMException */ public function testExceptionIsThrownWhenUsingInvalidFieldName() { - $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser') + $this->_em->getRepository(CmsUser::class) ->findByThisFieldDoesNotExist('testvalue'); } @@ -320,7 +327,7 @@ public function testPessimisticReadLockWithoutTransaction_ThrowsException() { $this->expectException(TransactionRequiredException::class); - $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser') + $this->_em->getRepository(CmsUser::class) ->find(1, LockMode::PESSIMISTIC_READ); } @@ -332,7 +339,7 @@ public function testPessimisticWriteLockWithoutTransaction_ThrowsException() { $this->expectException(TransactionRequiredException::class); - $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser') + $this->_em->getRepository(CmsUser::class) ->find(1, LockMode::PESSIMISTIC_WRITE); } @@ -344,7 +351,7 @@ public function testOptimisticLockUnversionedEntity_ThrowsException() { $this->expectException(OptimisticLockException::class); - $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser') + $this->_em->getRepository(CmsUser::class) ->find(1, LockMode::OPTIMISTIC); } @@ -363,11 +370,11 @@ public function testIdentityMappedOptimisticLockUnversionedEntity_ThrowsExceptio $userId = $user->id; - $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $userId); + $this->_em->find(CmsUser::class, $userId); $this->expectException(OptimisticLockException::class); - $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $userId, LockMode::OPTIMISTIC); + $this->_em->find(CmsUser::class, $userId, LockMode::OPTIMISTIC); } /** @@ -377,7 +384,7 @@ public function testFindMagicCallByNullValue() { $this->loadFixture(); - $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repos = $this->_em->getRepository(CmsUser::class); $users = $repos->findByStatus(null); $this->assertEquals(1, count($users)); @@ -390,7 +397,7 @@ public function testInvalidMagicCall() { $this->expectException(\BadMethodCallException::class); - $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repos = $this->_em->getRepository(CmsUser::class); $repos->foo(); } @@ -400,7 +407,7 @@ public function testInvalidMagicCall() public function testFindByAssociationKey_ExceptionOnInverseSide() { list($userId, $addressId) = $this->loadAssociatedFixture(); - $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repos = $this->_em->getRepository(CmsUser::class); $this->expectException(ORMException::class); $this->expectExceptionMessage("You cannot search for the association field 'Doctrine\Tests\Models\CMS\CmsUser#address', because it is the inverse side of an association. Find methods only work on owning side associations."); @@ -414,10 +421,10 @@ public function testFindByAssociationKey_ExceptionOnInverseSide() public function testFindOneByAssociationKey() { list($userId, $addressId) = $this->loadAssociatedFixture(); - $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsAddress'); + $repos = $this->_em->getRepository(CmsAddress::class); $address = $repos->findOneBy(['user' => $userId]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress', $address); + $this->assertInstanceOf(CmsAddress::class, $address); $this->assertEquals($addressId, $address->id); } @@ -428,7 +435,7 @@ public function testFindOneByOrderBy() { $this->loadFixture(); - $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repos = $this->_em->getRepository(CmsUser::class); $userAsc = $repos->findOneBy([], ["username" => "ASC"]); $userDesc = $repos->findOneBy([], ["username" => "DESC"]); @@ -441,10 +448,10 @@ public function testFindOneByOrderBy() public function testFindByAssociationKey() { list($userId, $addressId) = $this->loadAssociatedFixture(); - $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsAddress'); + $repos = $this->_em->getRepository(CmsAddress::class); $addresses = $repos->findBy(['user' => $userId]); - $this->assertContainsOnly('Doctrine\Tests\Models\CMS\CmsAddress', $addresses); + $this->assertContainsOnly(CmsAddress::class, $addresses); $this->assertEquals(1, count($addresses)); $this->assertEquals($addressId, $addresses[0]->id); } @@ -455,10 +462,10 @@ public function testFindByAssociationKey() public function testFindAssociationByMagicCall() { list($userId, $addressId) = $this->loadAssociatedFixture(); - $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsAddress'); + $repos = $this->_em->getRepository(CmsAddress::class); $addresses = $repos->findByUser($userId); - $this->assertContainsOnly('Doctrine\Tests\Models\CMS\CmsAddress', $addresses); + $this->assertContainsOnly(CmsAddress::class, $addresses); $this->assertEquals(1, count($addresses)); $this->assertEquals($addressId, $addresses[0]->id); } @@ -469,26 +476,26 @@ public function testFindAssociationByMagicCall() public function testFindOneAssociationByMagicCall() { list($userId, $addressId) = $this->loadAssociatedFixture(); - $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsAddress'); + $repos = $this->_em->getRepository(CmsAddress::class); $address = $repos->findOneByUser($userId); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress', $address); + $this->assertInstanceOf(CmsAddress::class, $address); $this->assertEquals($addressId, $address->id); } public function testValidNamedQueryRetrieval() { - $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repos = $this->_em->getRepository(CmsUser::class); $query = $repos->createNamedQuery('all'); - $this->assertInstanceOf('Doctrine\ORM\Query', $query); + $this->assertInstanceOf(Query::class, $query); $this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u', $query->getDQL()); } public function testInvalidNamedQueryRetrieval() { - $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repos = $this->_em->getRepository(CmsUser::class); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); @@ -500,7 +507,7 @@ public function testInvalidNamedQueryRetrieval() */ public function testIsNullCriteriaDoesNotGenerateAParameter() { - $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repos = $this->_em->getRepository(CmsUser::class); $users = $repos->findBy(['status' => null, 'username' => 'romanb']); $params = $this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['params']; @@ -512,7 +519,7 @@ public function testIsNullCriteria() { $this->loadFixture(); - $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repos = $this->_em->getRepository(CmsUser::class); $users = $repos->findBy(['status' => null]); $this->assertEquals(1, count($users)); @@ -525,7 +532,7 @@ public function testFindByLimitOffset() { $this->loadFixture(); - $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repos = $this->_em->getRepository(CmsUser::class); $users1 = $repos->findBy([], null, 1, 0); $users2 = $repos->findBy([], null, 1, 1); @@ -543,7 +550,7 @@ public function testFindByOrderBy() { $this->loadFixture(); - $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repos = $this->_em->getRepository(CmsUser::class); $usersAsc = $repos->findBy([], ["username" => "ASC"]); $usersDesc = $repos->findBy([], ["username" => "DESC"]); @@ -560,7 +567,7 @@ public function testFindByOrderByAssociation() { $this->loadFixtureUserEmail(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repository = $this->_em->getRepository(CmsUser::class); $resultAsc = $repository->findBy([], ['email' => 'ASC']); $resultDesc = $repository->findBy([], ['email' => 'DESC']); @@ -577,7 +584,7 @@ public function testFindByOrderByAssociation() public function testFindFieldByMagicCallOrderBy() { $this->loadFixture(); - $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repos = $this->_em->getRepository(CmsUser::class); $usersAsc = $repos->findByStatus('dev', ['username' => "ASC"]); $usersDesc = $repos->findByStatus('dev', ['username' => "DESC"]); @@ -585,7 +592,7 @@ public function testFindFieldByMagicCallOrderBy() $this->assertEquals(2, count($usersAsc)); $this->assertEquals(2, count($usersDesc)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser',$usersAsc[0]); + $this->assertInstanceOf(CmsUser::class,$usersAsc[0]); $this->assertEquals('Alexander', $usersAsc[0]->name); $this->assertEquals('dev', $usersAsc[0]->status); @@ -599,7 +606,7 @@ public function testFindFieldByMagicCallOrderBy() public function testFindFieldByMagicCallLimitOffset() { $this->loadFixture(); - $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repos = $this->_em->getRepository(CmsUser::class); $users1 = $repos->findByStatus('dev', [], 1, 0); $users2 = $repos->findByStatus('dev', [], 1, 1); @@ -614,22 +621,22 @@ public function testFindFieldByMagicCallLimitOffset() */ public function testDefaultRepositoryClassName() { - $this->assertEquals($this->_em->getConfiguration()->getDefaultRepositoryClassName(), "Doctrine\ORM\EntityRepository"); - $this->_em->getConfiguration()->setDefaultRepositoryClassName("Doctrine\Tests\Models\DDC753\DDC753DefaultRepository"); - $this->assertEquals($this->_em->getConfiguration()->getDefaultRepositoryClassName(), "Doctrine\Tests\Models\DDC753\DDC753DefaultRepository"); + $this->assertEquals($this->_em->getConfiguration()->getDefaultRepositoryClassName(), EntityRepository::class); + $this->_em->getConfiguration()->setDefaultRepositoryClassName(DDC753DefaultRepository::class); + $this->assertEquals($this->_em->getConfiguration()->getDefaultRepositoryClassName(), DDC753DefaultRepository::class); - $repos = $this->_em->getRepository('Doctrine\Tests\Models\DDC753\DDC753EntityWithDefaultCustomRepository'); - $this->assertInstanceOf("Doctrine\Tests\Models\DDC753\DDC753DefaultRepository", $repos); + $repos = $this->_em->getRepository(DDC753EntityWithDefaultCustomRepository::class); + $this->assertInstanceOf(DDC753DefaultRepository::class, $repos); $this->assertTrue($repos->isDefaultRepository()); - $repos = $this->_em->getRepository('Doctrine\Tests\Models\DDC753\DDC753EntityWithCustomRepository'); - $this->assertInstanceOf("Doctrine\Tests\Models\DDC753\DDC753CustomRepository", $repos); + $repos = $this->_em->getRepository(DDC753EntityWithCustomRepository::class); + $this->assertInstanceOf(DDC753CustomRepository::class, $repos); $this->assertTrue($repos->isCustomRepository()); - $this->assertEquals($this->_em->getConfiguration()->getDefaultRepositoryClassName(), "Doctrine\Tests\Models\DDC753\DDC753DefaultRepository"); - $this->_em->getConfiguration()->setDefaultRepositoryClassName("Doctrine\ORM\EntityRepository"); - $this->assertEquals($this->_em->getConfiguration()->getDefaultRepositoryClassName(), "Doctrine\ORM\EntityRepository"); + $this->assertEquals($this->_em->getConfiguration()->getDefaultRepositoryClassName(), DDC753DefaultRepository::class); + $this->_em->getConfiguration()->setDefaultRepositoryClassName(EntityRepository::class); + $this->assertEquals($this->_em->getConfiguration()->getDefaultRepositoryClassName(), EntityRepository::class); } @@ -640,8 +647,8 @@ public function testDefaultRepositoryClassName() */ public function testSetDefaultRepositoryInvalidClassError() { - $this->assertEquals($this->_em->getConfiguration()->getDefaultRepositoryClassName(), "Doctrine\ORM\EntityRepository"); - $this->_em->getConfiguration()->setDefaultRepositoryClassName("Doctrine\Tests\Models\DDC753\DDC753InvalidRepository"); + $this->assertEquals($this->_em->getConfiguration()->getDefaultRepositoryClassName(), EntityRepository::class); + $this->_em->getConfiguration()->setDefaultRepositoryClassName(DDC753InvalidRepository::class); } /** @@ -654,7 +661,7 @@ public function testSingleRepositoryInstanceForDifferentEntityAliases() $config->addEntityNamespace('Aliased', 'Doctrine\Tests\Models\CMS'); $config->addEntityNamespace('AliasedAgain', 'Doctrine\Tests\Models\CMS'); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repository = $this->_em->getRepository(CmsUser::class); $this->assertSame($repository, $this->_em->getRepository('Aliased:CmsUser')); $this->assertSame($repository, $this->_em->getRepository('AliasedAgain:CmsUser')); @@ -666,8 +673,8 @@ public function testSingleRepositoryInstanceForDifferentEntityAliases() public function testCanRetrieveRepositoryFromClassNameWithLeadingBackslash() { $this->assertSame( - $this->_em->getRepository('\\Doctrine\\Tests\\Models\\CMS\\CmsUser'), - $this->_em->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser') + $this->_em->getRepository('\\' . CmsUser::class), + $this->_em->getRepository(CmsUser::class) ); } @@ -679,7 +686,7 @@ public function testCanRetrieveRepositoryFromClassNameWithLeadingBackslash() */ public function testInvalidOrderByAssociation() { - $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser') + $this->_em->getRepository(CmsUser::class) ->findBy(['status' => 'test'], ['address' => 'ASC']); } @@ -691,7 +698,7 @@ public function testInvalidOrientation() $this->expectException(ORMException::class); $this->expectExceptionMessage('Invalid order by orientation specified for Doctrine\Tests\Models\CMS\CmsUser#username'); - $repo = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repo = $this->_em->getRepository(CmsUser::class); $repo->findBy(['status' => 'test'], ['username' => 'INVALID']); } @@ -700,7 +707,7 @@ public function testInvalidOrientation() */ public function testFindByAssociationArray() { - $repo = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsArticle'); + $repo = $this->_em->getRepository(CmsAddress::class); $data = $repo->findBy(['user' => [1, 2, 3]]); $query = array_pop($this->_sqlLoggerStack->queries); @@ -715,7 +722,7 @@ public function testMatchingEmptyCriteria() { $this->loadFixture(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repository = $this->_em->getRepository(CmsUser::class); $users = $repository->matching(new Criteria()); $this->assertEquals(4, count($users)); @@ -728,7 +735,7 @@ public function testMatchingCriteriaEqComparison() { $this->loadFixture(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repository = $this->_em->getRepository(CmsUser::class); $users = $repository->matching(new Criteria( Criteria::expr()->eq('username', 'beberlei') )); @@ -743,7 +750,7 @@ public function testMatchingCriteriaNeqComparison() { $this->loadFixture(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repository = $this->_em->getRepository(CmsUser::class); $users = $repository->matching(new Criteria( Criteria::expr()->neq('username', 'beberlei') )); @@ -758,7 +765,7 @@ public function testMatchingCriteriaInComparison() { $this->loadFixture(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repository = $this->_em->getRepository(CmsUser::class); $users = $repository->matching(new Criteria( Criteria::expr()->in('username', ['beberlei', 'gblanco']) )); @@ -773,7 +780,7 @@ public function testMatchingCriteriaNotInComparison() { $this->loadFixture(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repository = $this->_em->getRepository(CmsUser::class); $users = $repository->matching(new Criteria( Criteria::expr()->notIn('username', ['beberlei', 'gblanco', 'asm89']) )); @@ -788,7 +795,7 @@ public function testMatchingCriteriaLtComparison() { $firstUserId = $this->loadFixture(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repository = $this->_em->getRepository(CmsUser::class); $users = $repository->matching(new Criteria( Criteria::expr()->lt('id', $firstUserId + 1) )); @@ -803,7 +810,7 @@ public function testMatchingCriteriaLeComparison() { $firstUserId = $this->loadFixture(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repository = $this->_em->getRepository(CmsUser::class); $users = $repository->matching(new Criteria( Criteria::expr()->lte('id', $firstUserId + 1) )); @@ -818,7 +825,7 @@ public function testMatchingCriteriaGtComparison() { $firstUserId = $this->loadFixture(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repository = $this->_em->getRepository(CmsUser::class); $users = $repository->matching(new Criteria( Criteria::expr()->gt('id', $firstUserId) )); @@ -833,7 +840,7 @@ public function testMatchingCriteriaGteComparison() { $firstUserId = $this->loadFixture(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repository = $this->_em->getRepository(CmsUser::class); $users = $repository->matching(new Criteria( Criteria::expr()->gte('id', $firstUserId) )); @@ -848,13 +855,13 @@ public function testMatchingCriteriaAssocationByObjectInMemory() { list($userId, $addressId) = $this->loadAssociatedFixture(); - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $userId); + $user = $this->_em->find(CmsUser::class, $userId); $criteria = new Criteria( Criteria::expr()->eq('user', $user) ); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsAddress'); + $repository = $this->_em->getRepository(CmsAddress::class); $addresses = $repository->matching($criteria); $this->assertEquals(1, count($addresses)); @@ -871,13 +878,13 @@ public function testMatchingCriteriaAssocationInWithArray() { list($userId, $addressId) = $this->loadAssociatedFixture(); - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $userId); + $user = $this->_em->find(CmsUser::class, $userId); $criteria = new Criteria( Criteria::expr()->in('user', [$user]) ); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsAddress'); + $repository = $this->_em->getRepository(CmsAddress::class); $addresses = $repository->matching($criteria); $this->assertEquals(1, count($addresses)); @@ -891,7 +898,7 @@ public function testMatchingCriteriaContainsComparison() { $this->loadFixture(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repository = $this->_em->getRepository(CmsUser::class); $users = $repository->matching(new Criteria(Criteria::expr()->contains('name', 'Foobar'))); $this->assertEquals(0, count($users)); @@ -910,7 +917,7 @@ public function testMatchingCriteriaNullAssocComparison() { $fixtures = $this->loadFixtureUserEmail(); $user = $this->_em->merge($fixtures[0]); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repository = $this->_em->getRepository(CmsUser::class); $criteriaIsNull = Criteria::create()->where(Criteria::expr()->isNull('email')); $criteriaEqNull = Criteria::create()->where(Criteria::expr()->eq('email', null)); @@ -925,8 +932,8 @@ public function testMatchingCriteriaNullAssocComparison() $this->assertCount(1, $usersIsNull); $this->assertCount(1, $usersEqNull); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $usersIsNull[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $usersEqNull[0]); + $this->assertInstanceOf(CmsUser::class, $usersIsNull[0]); + $this->assertInstanceOf(CmsUser::class, $usersEqNull[0]); $this->assertNull($usersIsNull[0]->getEmail()); $this->assertNull($usersEqNull[0]->getEmail()); @@ -937,11 +944,11 @@ public function testMatchingCriteriaNullAssocComparison() */ public function testCreateResultSetMappingBuilder() { - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repository = $this->_em->getRepository(CmsUser::class); $rsm = $repository->createResultSetMappingBuilder('u'); - $this->assertInstanceOf('Doctrine\ORM\Query\ResultSetMappingBuilder', $rsm); - $this->assertEquals(['u' => 'Doctrine\Tests\Models\CMS\CmsUser'], $rsm->aliasMap); + $this->assertInstanceOf(Query\ResultSetMappingBuilder::class, $rsm); + $this->assertEquals(['u' => CmsUser::class], $rsm->aliasMap); } /** @@ -952,7 +959,7 @@ public function testFindByFieldInjectionPrevented() $this->expectException(ORMException::class); $this->expectExceptionMessage('Unrecognized field: '); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repository = $this->_em->getRepository(CmsUser::class); $repository->findBy(['username = ?; DELETE FROM cms_users; SELECT 1 WHERE 1' => 'test']); } @@ -964,7 +971,7 @@ public function testFindOneByFieldInjectionPrevented() $this->expectException(ORMException::class); $this->expectExceptionMessage('Unrecognized field: '); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repository = $this->_em->getRepository(CmsUser::class); $repository->findOneBy(['username = ?; DELETE FROM cms_users; SELECT 1 WHERE 1' => 'test']); } @@ -976,7 +983,7 @@ public function testMatchingInjectionPrevented() $this->expectException(ORMException::class); $this->expectExceptionMessage('Unrecognized field: '); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repository = $this->_em->getRepository(CmsUser::class); $result = $repository->matching(new Criteria( Criteria::expr()->eq('username = ?; DELETE FROM cms_users; SELECT 1 WHERE 1', 'beberlei') )); @@ -993,7 +1000,7 @@ public function testFindInjectionPrevented() $this->expectException(ORMException::class); $this->expectExceptionMessage('Unrecognized identifier fields: '); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repository = $this->_em->getRepository(CmsUser::class); $repository->find(['username = ?; DELETE FROM cms_users; SELECT 1 WHERE 1' => 'test', 'id' => 1]); } @@ -1016,7 +1023,7 @@ public function testFindByNullValueInInCondition() $this->_em->persist($user2); $this->_em->flush(); - $users = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findBy(['status' => [null]]); + $users = $this->_em->getRepository(CmsUser::class)->findBy(['status' => [null]]); $this->assertCount(1, $users); $this->assertSame($user1, reset($users)); @@ -1043,7 +1050,7 @@ public function testFindByNullValueInMultipleInCriteriaValues() $users = $this ->_em - ->getRepository('Doctrine\Tests\Models\CMS\CmsUser') + ->getRepository(CmsUser::class) ->findBy(['status' => ['foo', null]]); $this->assertCount(1, $users); @@ -1071,7 +1078,7 @@ public function testFindMultipleByNullValueInMultipleInCriteriaValues() $users = $this ->_em - ->getRepository('Doctrine\Tests\Models\CMS\CmsUser') + ->getRepository(CmsUser::class) ->findBy(['status' => ['dbal maintainer', null]]); $this->assertCount(2, $users); diff --git a/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php index c0afab02175..dc090a05552 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php @@ -40,7 +40,7 @@ public function setUp() $this->useModelSet('ddc2504'); parent::setUp(); - $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $class = $this->_em->getClassMetadata(CmsUser::class); $class->associationMappings['groups']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY; $class->associationMappings['groups']['indexBy'] = 'name'; $class->associationMappings['articles']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY; @@ -52,7 +52,7 @@ public function setUp() unset($class->associationMappings['articles']['cache']); unset($class->associationMappings['users']['cache']); - $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsGroup'); + $class = $this->_em->getClassMetadata(CmsGroup::class); $class->associationMappings['users']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY; $class->associationMappings['users']['indexBy'] = 'username'; @@ -63,7 +63,7 @@ public function tearDown() { parent::tearDown(); - $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $class = $this->_em->getClassMetadata(CmsUser::class); $class->associationMappings['groups']['fetch'] = ClassMetadataInfo::FETCH_LAZY; $class->associationMappings['articles']['fetch'] = ClassMetadataInfo::FETCH_LAZY; $class->associationMappings['phonenumbers']['fetch'] = ClassMetadataInfo::FETCH_LAZY; @@ -72,7 +72,7 @@ public function tearDown() unset($class->associationMappings['articles']['indexBy']); unset($class->associationMappings['phonenumbers']['indexBy']); - $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsGroup'); + $class = $this->_em->getClassMetadata(CmsGroup::class); $class->associationMappings['users']['fetch'] = ClassMetadataInfo::FETCH_LAZY; unset($class->associationMappings['users']['indexBy']); @@ -84,7 +84,7 @@ public function tearDown() */ public function testCountNotInitializesCollection() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $queryCount = $this->getCurrentQueryCount(); $this->assertFalse($user->groups->isInitialized()); @@ -101,7 +101,7 @@ public function testCountNotInitializesCollection() */ public function testCountWhenNewEntityPresent() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $newGroup = new CmsGroup(); $newGroup->name = "Test4"; @@ -120,7 +120,7 @@ public function testCountWhenNewEntityPresent() */ public function testCountWhenInitialized() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $queryCount = $this->getCurrentQueryCount(); foreach ($user->groups AS $group) { } @@ -135,7 +135,7 @@ public function testCountWhenInitialized() */ public function testCountInverseCollection() { - $group = $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId); + $group = $this->_em->find(CmsGroup::class, $this->groupId); $this->assertFalse($group->users->isInitialized(), "Pre-Condition"); $this->assertEquals(4, count($group->users)); @@ -147,7 +147,7 @@ public function testCountInverseCollection() */ public function testCountOneToMany() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $this->assertFalse($user->groups->isInitialized(), "Pre-Condition"); $this->assertEquals(2, count($user->articles)); @@ -158,7 +158,7 @@ public function testCountOneToMany() */ public function testCountOneToManyJoinedInheritance() { - $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId); + $otherClass = $this->_em->find(DDC2504OtherClass::class, $this->ddc2504OtherClassId); $this->assertFalse($otherClass->childClasses->isInitialized(), "Pre-Condition"); $this->assertEquals(2, count($otherClass->childClasses)); @@ -169,7 +169,7 @@ public function testCountOneToManyJoinedInheritance() */ public function testFullSlice() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $this->assertFalse($user->groups->isInitialized(), "Pre-Condition: Collection is not initialized."); $someGroups = $user->groups->slice(null); @@ -182,20 +182,20 @@ public function testFullSlice() */ public function testSlice() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $this->assertFalse($user->groups->isInitialized(), "Pre-Condition: Collection is not initialized."); $queryCount = $this->getCurrentQueryCount(); $someGroups = $user->groups->slice(0, 2); - $this->assertContainsOnly('Doctrine\Tests\Models\CMS\CmsGroup', $someGroups); + $this->assertContainsOnly(CmsGroup::class, $someGroups); $this->assertEquals(2, count($someGroups)); $this->assertFalse($user->groups->isInitialized(), "Slice should not initialize the collection if it wasn't before!"); $otherGroup = $user->groups->slice(2, 1); - $this->assertContainsOnly('Doctrine\Tests\Models\CMS\CmsGroup', $otherGroup); + $this->assertContainsOnly(CmsGroup::class, $otherGroup); $this->assertEquals(1, count($otherGroup)); $this->assertFalse($user->groups->isInitialized()); @@ -213,7 +213,7 @@ public function testSlice() */ public function testSliceInitializedCollection() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $queryCount = $this->getCurrentQueryCount(); foreach ($user->groups AS $group) { } @@ -232,15 +232,15 @@ public function testSliceInitializedCollection() */ public function testSliceInverseCollection() { - $group = $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId); + $group = $this->_em->find(CmsGroup::class, $this->groupId); $this->assertFalse($group->users->isInitialized(), "Pre-Condition"); $queryCount = $this->getCurrentQueryCount(); $someUsers = $group->users->slice(0, 2); $otherUsers = $group->users->slice(2, 2); - $this->assertContainsOnly('Doctrine\Tests\Models\CMS\CmsUser', $someUsers); - $this->assertContainsOnly('Doctrine\Tests\Models\CMS\CmsUser', $otherUsers); + $this->assertContainsOnly(CmsUser::class, $someUsers); + $this->assertContainsOnly(CmsUser::class, $otherUsers); $this->assertEquals(2, count($someUsers)); $this->assertEquals(2, count($otherUsers)); @@ -253,7 +253,7 @@ public function testSliceInverseCollection() */ public function testSliceOneToMany() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $this->assertFalse($user->articles->isInitialized(), "Pre-Condition: Collection is not initialized."); $queryCount = $this->getCurrentQueryCount(); @@ -269,11 +269,11 @@ public function testSliceOneToMany() */ public function testContainsOneToMany() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $this->assertFalse($user->articles->isInitialized(), "Pre-Condition: Collection is not initialized."); // Test One to Many existence retrieved from DB - $article = $this->_em->find('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId); + $article = $this->_em->find(CmsArticle::class, $this->articleId); $queryCount = $this->getCurrentQueryCount(); $this->assertTrue($user->articles->contains($article)); @@ -317,7 +317,7 @@ public function testContainsOneToMany() */ public function testLazyOneToManyJoinedInheritanceIsLazilyInitialized() { - $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId); + $otherClass = $this->_em->find(DDC2504OtherClass::class, $this->ddc2504OtherClassId); $this->assertFalse($otherClass->childClasses->isInitialized(), 'Collection is not initialized.'); } @@ -327,10 +327,10 @@ public function testLazyOneToManyJoinedInheritanceIsLazilyInitialized() */ public function testContainsOnOneToManyJoinedInheritanceWillNotInitializeCollectionWhenMatchingItemIsFound() { - $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId); + $otherClass = $this->_em->find(DDC2504OtherClass::class, $this->ddc2504OtherClassId); // Test One to Many existence retrieved from DB - $childClass = $this->_em->find(DDC2504ChildClass::CLASSNAME, $this->ddc2504ChildClassId); + $childClass = $this->_em->find(DDC2504ChildClass::class, $this->ddc2504ChildClassId); $queryCount = $this->getCurrentQueryCount(); $this->assertTrue($otherClass->childClasses->contains($childClass)); @@ -343,7 +343,7 @@ public function testContainsOnOneToManyJoinedInheritanceWillNotInitializeCollect */ public function testContainsOnOneToManyJoinedInheritanceWillNotCauseQueriesWhenNonPersistentItemIsMatched() { - $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId); + $otherClass = $this->_em->find(DDC2504OtherClass::class, $this->ddc2504OtherClassId); $queryCount = $this->getCurrentQueryCount(); $this->assertFalse($otherClass->childClasses->contains(new DDC2504ChildClass())); @@ -359,7 +359,7 @@ public function testContainsOnOneToManyJoinedInheritanceWillNotCauseQueriesWhenN */ public function testContainsOnOneToManyJoinedInheritanceWillNotInitializeCollectionWithClearStateMatchingItem() { - $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId); + $otherClass = $this->_em->find(DDC2504OtherClass::class, $this->ddc2504OtherClassId); $childClass = new DDC2504ChildClass(); // Test One to Many existence with state clear @@ -377,7 +377,7 @@ public function testContainsOnOneToManyJoinedInheritanceWillNotInitializeCollect */ public function testContainsOnOneToManyJoinedInheritanceWillNotInitializeCollectionWithNewStateNotMatchingItem() { - $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId); + $otherClass = $this->_em->find(DDC2504OtherClass::class, $this->ddc2504OtherClassId); $childClass = new DDC2504ChildClass(); $this->_em->persist($childClass); @@ -394,7 +394,7 @@ public function testContainsOnOneToManyJoinedInheritanceWillNotInitializeCollect */ public function testCountingOnOneToManyJoinedInheritanceWillNotInitializeCollection() { - $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId); + $otherClass = $this->_em->find(DDC2504OtherClass::class, $this->ddc2504OtherClassId); $this->assertEquals(2, count($otherClass->childClasses)); @@ -406,11 +406,11 @@ public function testCountingOnOneToManyJoinedInheritanceWillNotInitializeCollect */ public function testContainsManyToMany() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $this->assertFalse($user->groups->isInitialized(), "Pre-Condition: Collection is not initialized."); // Test Many to Many existence retrieved from DB - $group = $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId); + $group = $this->_em->find(CmsGroup::class, $this->groupId); $queryCount = $this->getCurrentQueryCount(); $this->assertTrue($user->groups->contains($group)); @@ -455,10 +455,10 @@ public function testContainsManyToMany() */ public function testContainsManyToManyInverse() { - $group = $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId); + $group = $this->_em->find(CmsGroup::class, $this->groupId); $this->assertFalse($group->users->isInitialized(), "Pre-Condition: Collection is not initialized."); - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $queryCount = $this->getCurrentQueryCount(); $this->assertTrue($group->users->contains($user)); @@ -479,11 +479,11 @@ public function testContainsManyToManyInverse() */ public function testRemoveElementOneToMany() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $this->assertFalse($user->articles->isInitialized(), "Pre-Condition: Collection is not initialized."); // Test One to Many removal with Entity retrieved from DB - $article = $this->_em->find('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId); + $article = $this->_em->find(CmsArticle::class, $this->articleId); $queryCount = $this->getCurrentQueryCount(); $user->articles->removeElement($article); @@ -533,9 +533,9 @@ public function testRemoveElementOneToMany() public function testRemovalOfManagedElementFromOneToManyJoinedInheritanceCollectionDoesNotInitializeIt() { /* @var $otherClass DDC2504OtherClass */ - $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId); + $otherClass = $this->_em->find(DDC2504OtherClass::class, $this->ddc2504OtherClassId); /* @var $childClass DDC2504ChildClass */ - $childClass = $this->_em->find(DDC2504ChildClass::CLASSNAME, $this->ddc2504ChildClassId); + $childClass = $this->_em->find(DDC2504ChildClass::class, $this->ddc2504ChildClassId); $queryCount = $this->getCurrentQueryCount(); @@ -571,7 +571,7 @@ public function testRemovalOfManagedElementFromOneToManyJoinedInheritanceCollect public function testRemovalOfNonManagedElementFromOneToManyJoinedInheritanceCollectionDoesNotInitializeIt() { /* @var $otherClass DDC2504OtherClass */ - $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId); + $otherClass = $this->_em->find(DDC2504OtherClass::class, $this->ddc2504OtherClassId); $queryCount = $this->getCurrentQueryCount(); $otherClass->childClasses->removeElement(new DDC2504ChildClass()); @@ -589,7 +589,7 @@ public function testRemovalOfNonManagedElementFromOneToManyJoinedInheritanceColl public function testRemovalOfNewElementFromOneToManyJoinedInheritanceCollectionDoesNotInitializeIt() { /* @var $otherClass DDC2504OtherClass */ - $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId); + $otherClass = $this->_em->find(DDC2504OtherClass::class, $this->ddc2504OtherClassId); $childClass = new DDC2504ChildClass(); $this->_em->persist($childClass); @@ -610,7 +610,7 @@ public function testRemovalOfNewElementFromOneToManyJoinedInheritanceCollectionD */ public function testRemovalOfNewManagedElementFromOneToManyJoinedInheritanceCollectionDoesNotInitializeIt() { - $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId); + $otherClass = $this->_em->find(DDC2504OtherClass::class, $this->ddc2504OtherClassId); $childClass = new DDC2504ChildClass(); $this->_em->persist($childClass); @@ -633,11 +633,11 @@ public function testRemovalOfNewManagedElementFromOneToManyJoinedInheritanceColl */ public function testRemoveElementManyToMany() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $this->assertFalse($user->groups->isInitialized(), "Pre-Condition: Collection is not initialized."); // Test Many to Many removal with Entity retrieved from DB - $group = $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId); + $group = $this->_em->find(CmsGroup::class, $this->groupId); $queryCount = $this->getCurrentQueryCount(); $user->groups->removeElement($group); @@ -686,10 +686,10 @@ public function testRemoveElementManyToMany() */ public function testRemoveElementManyToManyInverse() { - $group = $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId); + $group = $this->_em->find(CmsGroup::class, $this->groupId); $this->assertFalse($group->users->isInitialized(), "Pre-Condition: Collection is not initialized."); - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $queryCount = $this->getCurrentQueryCount(); $group->users->removeElement($user); @@ -713,7 +713,7 @@ public function testRemoveElementManyToManyInverse() */ public function testCountAfterAddThenFlush() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $newGroup = new CmsGroup(); $newGroup->name = "Test4"; @@ -736,7 +736,7 @@ public function testCountAfterAddThenFlush() */ public function testSliceOnDirtyCollection() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); /* @var $user CmsUser */ $newGroup = new CmsGroup(); @@ -758,7 +758,7 @@ public function testSliceOnDirtyCollection() */ public function testGetIndexByIdentifier() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); /* @var $user CmsUser */ $queryCount = $this->getCurrentQueryCount(); @@ -766,7 +766,7 @@ public function testGetIndexByIdentifier() $this->assertFalse($user->phonenumbers->isInitialized()); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); - $this->assertSame($phonenumber, $this->_em->find('Doctrine\Tests\Models\CMS\CmsPhonenumber', $this->phonenumber)); + $this->assertSame($phonenumber, $this->_em->find(CmsPhonenumber::class, $this->phonenumber)); $article = $user->phonenumbers->get($this->phonenumber); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Getting the same entity should not cause an extra query to be executed"); @@ -777,7 +777,7 @@ public function testGetIndexByIdentifier() */ public function testGetIndexByOneToMany() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); /* @var $user CmsUser */ $queryCount = $this->getCurrentQueryCount(); @@ -786,7 +786,7 @@ public function testGetIndexByOneToMany() $this->assertFalse($user->articles->isInitialized()); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); - $this->assertSame($article, $this->_em->find('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId)); + $this->assertSame($article, $this->_em->find(CmsArticle::class, $this->articleId)); } /** @@ -794,7 +794,7 @@ public function testGetIndexByOneToMany() */ public function testGetIndexByManyToManyInverseSide() { - $group = $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId); + $group = $this->_em->find(CmsGroup::class, $this->groupId); /* @var $group CmsGroup */ $queryCount = $this->getCurrentQueryCount(); @@ -803,7 +803,7 @@ public function testGetIndexByManyToManyInverseSide() $this->assertFalse($group->users->isInitialized()); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); - $this->assertSame($user, $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId)); + $this->assertSame($user, $this->_em->find(CmsUser::class, $this->userId)); } /** @@ -811,7 +811,7 @@ public function testGetIndexByManyToManyInverseSide() */ public function testGetIndexByManyToManyOwningSide() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); /* @var $user CmsUser */ $queryCount = $this->getCurrentQueryCount(); @@ -820,7 +820,7 @@ public function testGetIndexByManyToManyOwningSide() $this->assertFalse($user->groups->isInitialized()); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); - $this->assertSame($group, $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId)); + $this->assertSame($group, $this->_em->find(CmsGroup::class, $this->groupId)); } /** @@ -828,14 +828,14 @@ public function testGetIndexByManyToManyOwningSide() */ public function testGetNonExistentIndexBy() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $this->assertNull($user->articles->get(-1)); $this->assertNull($user->groups->get(-1)); } public function testContainsKeyIndexByOneToMany() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); /* @var $user CmsUser */ $queryCount = $this->getCurrentQueryCount(); @@ -849,10 +849,10 @@ public function testContainsKeyIndexByOneToMany() public function testContainsKeyIndexByOneToManyJoinedInheritance() { - $class = $this->_em->getClassMetadata(DDC2504OtherClass::CLASSNAME); + $class = $this->_em->getClassMetadata(DDC2504OtherClass::class); $class->associationMappings['childClasses']['indexBy'] = 'id'; - $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId); + $otherClass = $this->_em->find(DDC2504OtherClass::class, $this->ddc2504OtherClassId); $queryCount = $this->getCurrentQueryCount(); @@ -865,9 +865,9 @@ public function testContainsKeyIndexByOneToManyJoinedInheritance() public function testContainsKeyIndexByManyToMany() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId2); + $user = $this->_em->find(CmsUser::class, $this->userId2); - $group = $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId); + $group = $this->_em->find(CmsGroup::class, $this->groupId); $queryCount = $this->getCurrentQueryCount(); @@ -879,8 +879,8 @@ public function testContainsKeyIndexByManyToMany() } public function testContainsKeyIndexByManyToManyNonOwning() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId2); - $group = $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId); + $user = $this->_em->find(CmsUser::class, $this->userId2); + $group = $this->_em->find(CmsGroup::class, $this->groupId); $queryCount = $this->getCurrentQueryCount(); @@ -893,10 +893,10 @@ public function testContainsKeyIndexByManyToManyNonOwning() public function testContainsKeyIndexByWithPkManyToMany() { - $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $class = $this->_em->getClassMetadata(CmsUser::class); $class->associationMappings['groups']['indexBy'] = 'id'; - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId2); + $user = $this->_em->find(CmsUser::class, $this->userId2); $queryCount = $this->getCurrentQueryCount(); @@ -908,10 +908,10 @@ public function testContainsKeyIndexByWithPkManyToMany() } public function testContainsKeyIndexByWithPkManyToManyNonOwning() { - $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsGroup'); + $class = $this->_em->getClassMetadata(CmsGroup::class); $class->associationMappings['users']['indexBy'] = 'id'; - $group = $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId); + $group = $this->_em->find(CmsGroup::class, $this->groupId); $queryCount = $this->getCurrentQueryCount(); @@ -924,7 +924,7 @@ public function testContainsKeyIndexByWithPkManyToManyNonOwning() public function testContainsKeyNonExistentIndexByOneToMany() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId2); + $user = $this->_em->find(CmsUser::class, $this->userId2); $queryCount = $this->getCurrentQueryCount(); @@ -937,7 +937,7 @@ public function testContainsKeyNonExistentIndexByOneToMany() public function testContainsKeyNonExistentIndexByManyToMany() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId2); + $user = $this->_em->find(CmsUser::class, $this->userId2); $queryCount = $this->getCurrentQueryCount(); @@ -1061,14 +1061,14 @@ public function testRemoveManagedElementFromOneToManyExtraLazyCollectionIsNoOp() list($userId, $tweetId) = $this->loadTweetFixture(); /* @var $user User */ - $user = $this->_em->find(User::CLASSNAME, $userId); + $user = $this->_em->find(User::class, $userId); - $user->tweets->removeElement($this->_em->find(Tweet::CLASSNAME, $tweetId)); + $user->tweets->removeElement($this->_em->find(Tweet::class, $tweetId)); $this->_em->clear(); /* @var $user User */ - $user = $this->_em->find(User::CLASSNAME, $userId); + $user = $this->_em->find(User::class, $userId); $this->assertCount(1, $user->tweets, 'Element was not removed - need to update the owning side first'); } @@ -1081,23 +1081,23 @@ public function testRemoveManagedElementFromOneToManyExtraLazyCollectionWithoutD list($userId, $tweetId) = $this->loadTweetFixture(); /* @var $user User */ - $user = $this->_em->find(User::CLASSNAME, $userId); - $tweet = $this->_em->find(Tweet::CLASSNAME, $tweetId); + $user = $this->_em->find(User::class, $userId); + $tweet = $this->_em->find(Tweet::class, $tweetId); $user->tweets->removeElement($tweet); $this->_em->clear(); /* @var $tweet Tweet */ - $tweet = $this->_em->find(Tweet::CLASSNAME, $tweetId); + $tweet = $this->_em->find(Tweet::class, $tweetId); $this->assertInstanceOf( - Tweet::CLASSNAME, + Tweet::class, $tweet, 'Even though the collection is extra lazy, the tweet should not have been deleted' ); $this->assertInstanceOf( - User::CLASSNAME, + User::class, $tweet->author, 'Tweet author link has not been removed - need to update the owning side first' ); @@ -1111,25 +1111,25 @@ public function testRemovingManagedLazyProxyFromExtraLazyOneToManyDoesRemoveTheA list($userId, $tweetId) = $this->loadTweetFixture(); /* @var $user User */ - $user = $this->_em->find(User::CLASSNAME, $userId); - $tweet = $this->_em->getReference(Tweet::CLASSNAME, $tweetId); + $user = $this->_em->find(User::class, $userId); + $tweet = $this->_em->getReference(Tweet::class, $tweetId); - $user->tweets->removeElement($this->_em->getReference(Tweet::CLASSNAME, $tweetId)); + $user->tweets->removeElement($this->_em->getReference(Tweet::class, $tweetId)); $this->_em->clear(); /* @var $tweet Tweet */ - $tweet = $this->_em->find(Tweet::CLASSNAME, $tweet->id); + $tweet = $this->_em->find(Tweet::class, $tweet->id); $this->assertInstanceOf( - Tweet::CLASSNAME, + Tweet::class, $tweet, 'Even though the collection is extra lazy, the tweet should not have been deleted' ); - $this->assertInstanceOf(User::CLASSNAME, $tweet->author); + $this->assertInstanceOf(User::class, $tweet->author); /* @var $user User */ - $user = $this->_em->find(User::CLASSNAME, $userId); + $user = $this->_em->find(User::class, $userId); $this->assertCount(1, $user->tweets, 'Element was not removed - need to update the owning side first'); } @@ -1142,18 +1142,18 @@ public function testRemoveOrphanedManagedElementFromOneToManyExtraLazyCollection list($userId, $userListId) = $this->loadUserListFixture(); /* @var $user User */ - $user = $this->_em->find(User::CLASSNAME, $userId); + $user = $this->_em->find(User::class, $userId); - $user->userLists->removeElement($this->_em->find(UserList::CLASSNAME, $userListId)); + $user->userLists->removeElement($this->_em->find(UserList::class, $userListId)); $this->_em->clear(); /* @var $user User */ - $user = $this->_em->find(User::CLASSNAME, $userId); + $user = $this->_em->find(User::class, $userId); $this->assertCount(0, $user->userLists, 'Element was removed from association due to orphan removal'); $this->assertNull( - $this->_em->find(UserList::CLASSNAME, $userListId), + $this->_em->find(UserList::class, $userListId), 'Element was deleted due to orphan removal' ); } @@ -1166,22 +1166,22 @@ public function testRemoveOrphanedUnManagedElementFromOneToManyExtraLazyCollecti list($userId, $userListId) = $this->loadUserListFixture(); /* @var $user User */ - $user = $this->_em->find(User::CLASSNAME, $userId); + $user = $this->_em->find(User::class, $userId); $user->userLists->removeElement(new UserList()); $this->_em->clear(); /* @var $userList UserList */ - $userList = $this->_em->find(UserList::CLASSNAME, $userListId); + $userList = $this->_em->find(UserList::class, $userListId); $this->assertInstanceOf( - UserList::CLASSNAME, + UserList::class, $userList, 'Even though the collection is extra lazy + orphan removal, the user list should not have been deleted' ); $this->assertInstanceOf( - User::CLASSNAME, + User::class, $userList->owner, 'User list to owner link has not been removed' ); @@ -1195,18 +1195,18 @@ public function testRemoveOrphanedManagedLazyProxyFromExtraLazyOneToMany() list($userId, $userListId) = $this->loadUserListFixture(); /* @var $user User */ - $user = $this->_em->find(User::CLASSNAME, $userId); + $user = $this->_em->find(User::class, $userId); - $user->userLists->removeElement($this->_em->getReference(UserList::CLASSNAME, $userListId)); + $user->userLists->removeElement($this->_em->getReference(UserList::class, $userListId)); $this->_em->clear(); /* @var $user User */ - $user = $this->_em->find(User::CLASSNAME, $userId); + $user = $this->_em->find(User::class, $userId); $this->assertCount(0, $user->userLists, 'Element was removed from association due to orphan removal'); $this->assertNull( - $this->_em->find(UserList::CLASSNAME, $userListId), + $this->_em->find(UserList::class, $userListId), 'Element was deleted due to orphan removal' ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/IndexByAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/IndexByAssociationTest.php index 9dac4155ded..289e55807f8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/IndexByAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/IndexByAssociationTest.php @@ -46,8 +46,8 @@ public function loadFixture() public function testManyToOneFinder() { - /* @var $market Doctrine\Tests\Models\StockExchange\Market */ - $market = $this->_em->find('Doctrine\Tests\Models\StockExchange\Market', $this->market->getId()); + /* @var $market Market */ + $market = $this->_em->find(Market::class, $this->market->getId()); $this->assertEquals(2, count($market->stocks)); $this->assertTrue(isset($market->stocks['AAPL']), "AAPL symbol has to be key in indexed association."); @@ -70,7 +70,7 @@ public function testManyToOneDQL() public function testManyToMany() { - $bond = $this->_em->find('Doctrine\Tests\Models\StockExchange\Bond', $this->bond->getId()); + $bond = $this->_em->find(Bond::class, $this->bond->getId()); $this->assertEquals(2, count($bond->stocks)); $this->assertTrue(isset($bond->stocks['AAPL']), "AAPL symbol has to be key in indexed association."); diff --git a/tests/Doctrine/Tests/ORM/Functional/JoinedTableCompositeKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/JoinedTableCompositeKeyTest.php index 21f7cabde1d..ab5c394e020 100644 --- a/tests/Doctrine/Tests/ORM/Functional/JoinedTableCompositeKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/JoinedTableCompositeKeyTest.php @@ -1,6 +1,7 @@ _em->find( - 'Doctrine\Tests\Models\CompositeKeyInheritance\JoinedRootClass', + JoinedRootClass::class, ['keyPart1' => 'part-1', 'keyPart2' => 'part-2'] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php b/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php index 3a31f9c52c4..ca7f8c7d718 100644 --- a/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php @@ -17,10 +17,10 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\LifecycleCallbackEventArgEntity'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\LifecycleCallbackTestEntity'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\LifecycleCallbackTestUser'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\LifecycleCallbackCascader'), + $this->_em->getClassMetadata(LifecycleCallbackEventArgEntity::class), + $this->_em->getClassMetadata(LifecycleCallbackTestEntity::class), + $this->_em->getClassMetadata(LifecycleCallbackTestUser::class), + $this->_em->getClassMetadata(LifecycleCallbackCascader::class), ] ); } catch (\Exception $e) { @@ -106,7 +106,7 @@ public function testGetReferenceWithPostLoadEventIsDelayedUntilProxyTrigger() $this->_em->clear(); - $reference = $this->_em->getReference('Doctrine\Tests\ORM\Functional\LifecycleCallbackTestEntity', $id); + $reference = $this->_em->getReference(LifecycleCallbackTestEntity::class, $id); $this->assertFalse($reference->postLoadCallbackInvoked); $reference->getValue(); // trigger proxy load @@ -126,7 +126,7 @@ public function testPostLoadTriggeredOnRefresh() $this->_em->clear(); - $reference = $this->_em->find('Doctrine\Tests\ORM\Functional\LifecycleCallbackTestEntity', $id); + $reference = $this->_em->find(LifecycleCallbackTestEntity::class, $id); $this->assertTrue($reference->postLoadCallbackInvoked); $reference->postLoadCallbackInvoked = false; @@ -271,7 +271,7 @@ public function testCascadedEntitiesNotLoadedInPostLoadDuringIterationWithSimple public function testLifecycleCallbacksGetInherited() { - $childMeta = $this->_em->getClassMetadata(__NAMESPACE__ . '\LifecycleCallbackChildEntity'); + $childMeta = $this->_em->getClassMetadata(LifecycleCallbackChildEntity::class); $this->assertEquals(['prePersist' => [0 => 'doStuff']], $childMeta->lifecycleCallbacks); } @@ -331,45 +331,14 @@ public function testLifecycleCallbackEventArgs() $this->assertArrayHasKey('preRemoveHandler', $e->calls); $this->assertArrayHasKey('postRemoveHandler', $e->calls); - $this->assertInstanceOf( - 'Doctrine\ORM\Event\PreFlushEventArgs', - $e->calls['preFlushHandler'] - ); - - $this->assertInstanceOf( - 'Doctrine\ORM\Event\LifecycleEventArgs', - $e->calls['postLoadHandler'] - ); - - $this->assertInstanceOf( - 'Doctrine\ORM\Event\LifecycleEventArgs', - $e->calls['prePersistHandler'] - ); - - $this->assertInstanceOf( - 'Doctrine\ORM\Event\LifecycleEventArgs', - $e->calls['postPersistHandler'] - ); - - $this->assertInstanceOf( - 'Doctrine\ORM\Event\PreUpdateEventArgs', - $e->calls['preUpdateHandler'] - ); - - $this->assertInstanceOf( - 'Doctrine\ORM\Event\LifecycleEventArgs', - $e->calls['postUpdateHandler'] - ); - - $this->assertInstanceOf( - 'Doctrine\ORM\Event\LifecycleEventArgs', - $e->calls['preRemoveHandler'] - ); - - $this->assertInstanceOf( - 'Doctrine\ORM\Event\LifecycleEventArgs', - $e->calls['postRemoveHandler'] - ); + $this->assertInstanceOf(PreFlushEventArgs::class, $e->calls['preFlushHandler']); + $this->assertInstanceOf(LifecycleEventArgs::class, $e->calls['postLoadHandler']); + $this->assertInstanceOf(LifecycleEventArgs::class, $e->calls['prePersistHandler']); + $this->assertInstanceOf(LifecycleEventArgs::class, $e->calls['postPersistHandler']); + $this->assertInstanceOf(PreUpdateEventArgs::class, $e->calls['preUpdateHandler']); + $this->assertInstanceOf(LifecycleEventArgs::class, $e->calls['postUpdateHandler']); + $this->assertInstanceOf(LifecycleEventArgs::class, $e->calls['preRemoveHandler']); + $this->assertInstanceOf(LifecycleEventArgs::class, $e->calls['postRemoveHandler']); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php index b1ace3513aa..43a3cbf5b19 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php @@ -46,32 +46,32 @@ public function gearmanTaskCompleted($task) public function testFindWithLock() { - $this->asyncFindWithLock('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId, LockMode::PESSIMISTIC_WRITE); - $this->asyncFindWithLock('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId, LockMode::PESSIMISTIC_WRITE); + $this->asyncFindWithLock(CmsArticle::class, $this->articleId, LockMode::PESSIMISTIC_WRITE); + $this->asyncFindWithLock(CmsArticle::class, $this->articleId, LockMode::PESSIMISTIC_WRITE); $this->assertLockWorked(); } public function testFindWithWriteThenReadLock() { - $this->asyncFindWithLock('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId, LockMode::PESSIMISTIC_WRITE); - $this->asyncFindWithLock('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId, LockMode::PESSIMISTIC_READ); + $this->asyncFindWithLock(CmsArticle::class, $this->articleId, LockMode::PESSIMISTIC_WRITE); + $this->asyncFindWithLock(CmsArticle::class, $this->articleId, LockMode::PESSIMISTIC_READ); $this->assertLockWorked(); } public function testFindWithReadThenWriteLock() { - $this->asyncFindWithLock('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId, LockMode::PESSIMISTIC_READ); - $this->asyncFindWithLock('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId, LockMode::PESSIMISTIC_WRITE); + $this->asyncFindWithLock(CmsArticle::class, $this->articleId, LockMode::PESSIMISTIC_READ); + $this->asyncFindWithLock(CmsArticle::class, $this->articleId, LockMode::PESSIMISTIC_WRITE); $this->assertLockWorked(); } public function testFindWithOneLock() { - $this->asyncFindWithLock('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId, LockMode::PESSIMISTIC_WRITE); - $this->asyncFindWithLock('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId, LockMode::NONE); + $this->asyncFindWithLock(CmsArticle::class, $this->articleId, LockMode::PESSIMISTIC_WRITE); + $this->asyncFindWithLock(CmsArticle::class, $this->articleId, LockMode::NONE); $this->assertLockDoesNotBlock(); } @@ -79,39 +79,39 @@ public function testFindWithOneLock() public function testDqlWithLock() { $this->asyncDqlWithLock('SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a', [], LockMode::PESSIMISTIC_WRITE); - $this->asyncFindWithLock('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId, LockMode::PESSIMISTIC_WRITE); + $this->asyncFindWithLock(CmsArticle::class, $this->articleId, LockMode::PESSIMISTIC_WRITE); $this->assertLockWorked(); } public function testLock() { - $this->asyncFindWithLock('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId, LockMode::PESSIMISTIC_WRITE); - $this->asyncLock('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId, LockMode::PESSIMISTIC_WRITE); + $this->asyncFindWithLock(CmsArticle::class, $this->articleId, LockMode::PESSIMISTIC_WRITE); + $this->asyncLock(CmsArticle::class, $this->articleId, LockMode::PESSIMISTIC_WRITE); $this->assertLockWorked(); } public function testLock2() { - $this->asyncFindWithLock('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId, LockMode::PESSIMISTIC_WRITE); - $this->asyncLock('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId, LockMode::PESSIMISTIC_READ); + $this->asyncFindWithLock(CmsArticle::class, $this->articleId, LockMode::PESSIMISTIC_WRITE); + $this->asyncLock(CmsArticle::class, $this->articleId, LockMode::PESSIMISTIC_READ); $this->assertLockWorked(); } public function testLock3() { - $this->asyncFindWithLock('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId, LockMode::PESSIMISTIC_READ); - $this->asyncLock('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId, LockMode::PESSIMISTIC_WRITE); + $this->asyncFindWithLock(CmsArticle::class, $this->articleId, LockMode::PESSIMISTIC_READ); + $this->asyncLock(CmsArticle::class, $this->articleId, LockMode::PESSIMISTIC_WRITE); $this->assertLockWorked(); } public function testLock4() { - $this->asyncFindWithLock('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId, LockMode::NONE); - $this->asyncLock('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId, LockMode::PESSIMISTIC_WRITE); + $this->asyncFindWithLock(CmsArticle::class, $this->articleId, LockMode::NONE); + $this->asyncLock(CmsArticle::class, $this->articleId, LockMode::PESSIMISTIC_WRITE); $this->assertLockDoesNotBlock(); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php index ff1502daace..b5aa9c0ecb1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php @@ -2,9 +2,9 @@ namespace Doctrine\Tests\ORM\Functional\Locking; -use Doctrine\ORM\OptimisticLockException; -use Doctrine\DBAL\LockMode; use DateTime; +use Doctrine\DBAL\LockMode; +use Doctrine\ORM\OptimisticLockException; use Doctrine\Tests\OrmFunctionalTestCase; class OptimisticTest extends OrmFunctionalTestCase @@ -16,10 +16,10 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Locking\OptimisticJoinedParent'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Locking\OptimisticJoinedChild'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Locking\OptimisticStandard'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Locking\OptimisticTimestamp') + $this->_em->getClassMetadata(OptimisticJoinedParent::class), + $this->_em->getClassMetadata(OptimisticJoinedChild::class), + $this->_em->getClassMetadata(OptimisticStandard::class), + $this->_em->getClassMetadata(OptimisticTimestamp::class) ] ); } catch (\Exception $e) { @@ -175,7 +175,7 @@ public function testLockWorksWithProxy() $this->_em->flush(); $this->_em->clear(); - $proxy = $this->_em->getReference('Doctrine\Tests\ORM\Functional\Locking\OptimisticStandard', $test->id); + $proxy = $this->_em->getReference(OptimisticStandard::class, $test->id); $this->_em->lock($proxy, LockMode::OPTIMISTIC, 1); } diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php index b6d5957a23e..9aa044f5d99 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php @@ -2,12 +2,13 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Criteria; +use Doctrine\ORM\PersistentCollection; use Doctrine\ORM\UnitOfWork; +use Doctrine\Tests\Models\CMS\CmsGroup; use Doctrine\Tests\Models\CMS\CmsTag; -use Doctrine\Tests\Models\CMS\CmsUser, - Doctrine\Tests\Models\CMS\CmsGroup, - Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -49,7 +50,7 @@ public function testBasicManyToManyJoin() $result = $query->getResult(); $this->assertEquals(2, $this->_em->getUnitOfWork()->size()); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0]); + $this->assertInstanceOf(CmsUser::class, $result[0]); $this->assertEquals('Guilherme', $result[0]->name); $this->assertEquals(1, $result[0]->getGroups()->count()); $groups = $result[0]->getGroups(); @@ -58,8 +59,8 @@ public function testBasicManyToManyJoin() $this->assertEquals(UnitOfWork::STATE_MANAGED, $this->_em->getUnitOfWork()->getEntityState($result[0])); $this->assertEquals(UnitOfWork::STATE_MANAGED, $this->_em->getUnitOfWork()->getEntityState($groups[0])); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $groups); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $groups[0]->getUsers()); + $this->assertInstanceOf(PersistentCollection::class, $groups); + $this->assertInstanceOf(PersistentCollection::class, $groups[0]->getUsers()); $groups[0]->getUsers()->clear(); $groups->clear(); @@ -152,7 +153,7 @@ public function testManyToManyCollectionClearAndAdd() $user->groups[] = $group; } - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $user->groups); + $this->assertInstanceOf(PersistentCollection::class, $user->groups); $this->assertTrue($user->groups->isDirty()); $this->assertEquals($groupCount, count($user->groups), "There should be 10 groups in the collection."); @@ -187,7 +188,7 @@ public function testRetrieveManyToManyAndAddMore() $this->_em->clear(); /* @var $freshUser CmsUser */ - $freshUser = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $user->getId()); + $freshUser = $this->_em->find(CmsUser::class, $user->getId()); $newGroup = new CmsGroup(); $newGroup->setName('12Monkeys'); $freshUser->addGroup($newGroup); @@ -202,7 +203,7 @@ public function testRetrieveManyToManyAndAddMore() $this->_em->clear(); - $freshUser = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $user->getId()); + $freshUser = $this->_em->find(CmsUser::class, $user->getId()); $this->assertEquals(3, count($freshUser->getGroups())); } @@ -333,7 +334,7 @@ public function testClearAndResetCollection() $coll = new ArrayCollection([$group1, $group2]); $user->groups = $coll; $this->_em->flush(); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $user->groups, + $this->assertInstanceOf(PersistentCollection::class, $user->groups, "UnitOfWork should have replaced ArrayCollection with PersistentCollection."); $this->_em->flush(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBidirectionalAssociationTest.php index 51121b09abc..9c70ab7f6aa 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBidirectionalAssociationTest.php @@ -115,8 +115,8 @@ protected function _findCategories() //$query->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true); $result = $query->getResult(); $this->assertEquals(2, count($result)); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCategory', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCategory', $result[1]); + $this->assertInstanceOf(ECommerceCategory::class, $result[0]); + $this->assertInstanceOf(ECommerceCategory::class, $result[1]); $prods1 = $result[0]->getProducts(); $prods2 = $result[1]->getProducts(); $this->assertTrue($prods1->isInitialized()); @@ -155,10 +155,10 @@ public function assertLazyLoadFromInverseSide($products) $this->assertEquals(2, count($secondCategoryProducts)); // lazy-load $this->assertTrue($secondCategoryProducts->isInitialized()); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $firstCategoryProducts[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $firstCategoryProducts[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $secondCategoryProducts[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $secondCategoryProducts[1]); + $this->assertInstanceOf(ECommerceProduct::class, $firstCategoryProducts[0]); + $this->assertInstanceOf(ECommerceProduct::class, $firstCategoryProducts[1]); + $this->assertInstanceOf(ECommerceProduct::class, $secondCategoryProducts[0]); + $this->assertInstanceOf(ECommerceProduct::class, $secondCategoryProducts[1]); $this->assertCollectionEquals($firstCategoryProducts, $secondCategoryProducts); } @@ -190,10 +190,10 @@ public function assertLazyLoadFromOwningSide($categories) $this->assertEquals(2, count($secondProductCategories)); // lazy-load $this->assertTrue($secondProductCategories->isInitialized()); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCategory', $firstProductCategories[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCategory', $firstProductCategories[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCategory', $secondProductCategories[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCategory', $secondProductCategories[1]); + $this->assertInstanceOf(ECommerceCategory::class, $firstProductCategories[0]); + $this->assertInstanceOf(ECommerceCategory::class, $firstProductCategories[1]); + $this->assertInstanceOf(ECommerceCategory::class, $secondProductCategories[0]); + $this->assertInstanceOf(ECommerceCategory::class, $secondProductCategories[1]); $this->assertCollectionEquals($firstProductCategories, $secondProductCategories); } diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToManySelfReferentialAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToManySelfReferentialAssociationTest.php index 3ad4068803a..559cd4ba662 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManySelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManySelfReferentialAssociationTest.php @@ -72,7 +72,7 @@ public function testLazyLoadsOwningSide() { $this->_createLoadingFixture(); - $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceProduct'); + $metadata = $this->_em->getClassMetadata(ECommerceProduct::class); $metadata->associationMappings['related']['fetch'] = ClassMetadata::FETCH_LAZY; $query = $this->_em->createQuery('SELECT p FROM Doctrine\Tests\Models\ECommerce\ECommerceProduct p'); @@ -93,10 +93,10 @@ public function assertLoadingOfOwningSide($products) $this->assertEquals(2, count($firstRelatedBy)); $this->assertEquals(2, count($secondRelatedBy)); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $firstRelatedBy[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $firstRelatedBy[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $secondRelatedBy[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $secondRelatedBy[1]); + $this->assertInstanceOf(ECommerceProduct::class, $firstRelatedBy[0]); + $this->assertInstanceOf(ECommerceProduct::class, $firstRelatedBy[1]); + $this->assertInstanceOf(ECommerceProduct::class, $secondRelatedBy[0]); + $this->assertInstanceOf(ECommerceProduct::class, $secondRelatedBy[1]); $this->assertCollectionEquals($firstRelatedBy, $secondRelatedBy); } diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToManyUnidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToManyUnidirectionalAssociationTest.php index 241b3c2fb06..20e31db00df 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManyUnidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManyUnidirectionalAssociationTest.php @@ -67,8 +67,8 @@ public function testEagerLoad() $products = $firstCart->getProducts(); $secondCart = $result[1]; - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $products[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $products[1]); + $this->assertInstanceOf(ECommerceProduct::class, $products[0]); + $this->assertInstanceOf(ECommerceProduct::class, $products[1]); $this->assertCollectionEquals($products, $secondCart->getProducts()); //$this->assertEquals("Doctrine 1.x Manual", $products[0]->getName()); //$this->assertEquals("Doctrine 2.x Manual", $products[1]->getName()); @@ -77,7 +77,7 @@ public function testEagerLoad() public function testLazyLoadsCollection() { $this->_createFixture(); - $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceCart'); + $metadata = $this->_em->getClassMetadata(ECommerceCart::class); $metadata->associationMappings['products']['fetch'] = ClassMetadata::FETCH_LAZY; $query = $this->_em->createQuery('SELECT c FROM Doctrine\Tests\Models\ECommerce\ECommerceCart c'); @@ -86,8 +86,8 @@ public function testLazyLoadsCollection() $products = $firstCart->getProducts(); $secondCart = $result[1]; - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $products[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $products[1]); + $this->assertInstanceOf(ECommerceProduct::class, $products[0]); + $this->assertInstanceOf(ECommerceProduct::class, $products[1]); $this->assertCollectionEquals($products, $secondCart->getProducts()); } diff --git a/tests/Doctrine/Tests/ORM/Functional/MappedSuperclassTest.php b/tests/Doctrine/Tests/ORM/Functional/MappedSuperclassTest.php index fb7f0a7249d..97c34bba335 100644 --- a/tests/Doctrine/Tests/ORM/Functional/MappedSuperclassTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/MappedSuperclassTest.php @@ -1,6 +1,8 @@ _em->find(get_class($file), $file->getId()); - $this->assertInstanceOf('Doctrine\Tests\Models\DirectoryTree\Directory', $cleanFile->getParent()); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $cleanFile->getParent()); + $this->assertInstanceOf(Directory::class, $cleanFile->getParent()); + $this->assertInstanceOf(Proxy::class, $cleanFile->getParent()); $this->assertEquals($directory->getId(), $cleanFile->getParent()->getId()); - $this->assertInstanceOf('Doctrine\Tests\Models\DirectoryTree\Directory', $cleanFile->getParent()->getParent()); + $this->assertInstanceOf(Directory::class, $cleanFile->getParent()->getParent()); $this->assertEquals($root->getId(), $cleanFile->getParent()->getParent()->getId()); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/MergeCompositeToOneKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/MergeCompositeToOneKeyTest.php index 48263f3c45a..fab94a9066c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/MergeCompositeToOneKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/MergeCompositeToOneKeyTest.php @@ -17,8 +17,8 @@ protected function setUp() $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(Country::CLASSNAME), - $this->_em->getClassMetadata(CompositeToOneKeyState::CLASSNAME), + $this->_em->getClassMetadata(Country::class), + $this->_em->getClassMetadata(CompositeToOneKeyState::class), ] ); } @@ -39,9 +39,9 @@ public function testMergingOfEntityWithCompositeIdentifierContainingToOneAssocia /* @var $merged CompositeToOneKeyState */ $merged = $this->_em->merge($state); - $this->assertInstanceOf(CompositeToOneKeyState::CLASSNAME, $state); + $this->assertInstanceOf(CompositeToOneKeyState::class, $state); $this->assertNotSame($state, $merged); - $this->assertInstanceOf(Country::CLASSNAME, $merged->country); + $this->assertInstanceOf(Country::class, $merged->country); $this->assertNotSame($country, $merged->country); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php b/tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php index e32b0385cde..3d0acd1f898 100644 --- a/tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\Logging\SQLLogger; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; +use Doctrine\ORM\Proxy\Proxy; use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Tests\Models\Generic\DateTimeModel; use Doctrine\Tests\OrmFunctionalTestCase; @@ -31,11 +32,11 @@ protected function setUp() */ public function testMergeDetachedUnInitializedProxy() { - $detachedUninitialized = $this->_em->getReference(DateTimeModel::CLASSNAME, 123); + $detachedUninitialized = $this->_em->getReference(DateTimeModel::class, 123); $this->_em->clear(); - $managed = $this->_em->getReference(DateTimeModel::CLASSNAME, 123); + $managed = $this->_em->getReference(DateTimeModel::class, 123); $this->assertSame($managed, $this->_em->merge($detachedUninitialized)); @@ -51,11 +52,11 @@ public function testMergeDetachedUnInitializedProxy() */ public function testMergeUnserializedUnInitializedProxy() { - $detachedUninitialized = $this->_em->getReference(DateTimeModel::CLASSNAME, 123); + $detachedUninitialized = $this->_em->getReference(DateTimeModel::class, 123); $this->_em->clear(); - $managed = $this->_em->getReference(DateTimeModel::CLASSNAME, 123); + $managed = $this->_em->getReference(DateTimeModel::class, 123); $this->assertSame( $managed, @@ -74,7 +75,7 @@ public function testMergeUnserializedUnInitializedProxy() */ public function testMergeManagedProxy() { - $managed = $this->_em->getReference(DateTimeModel::CLASSNAME, 123); + $managed = $this->_em->getReference(DateTimeModel::class, 123); $this->assertSame($managed, $this->_em->merge($managed)); @@ -98,9 +99,9 @@ public function testMergeWithExistingUninitializedManagedProxy() $this->_em->flush($date); $this->_em->clear(); - $managed = $this->_em->getReference(DateTimeModel::CLASSNAME, $date->id); + $managed = $this->_em->getReference(DateTimeModel::class, $date->id); - $this->assertInstanceOf('Doctrine\Common\Proxy\Proxy', $managed); + $this->assertInstanceOf(Proxy::class, $managed); $this->assertFalse($managed->__isInitialized()); $date->date = $dateTime = new \DateTime(); @@ -134,8 +135,8 @@ public function testMergingProxyFromDifferentEntityManagerWithExistingManagedIns $queryCount1 = count($logger1->queries); $queryCount2 = count($logger2->queries); - $proxy1 = $em1->getReference(DateTimeModel::CLASSNAME, $file1->id); - $proxy2 = $em2->getReference(DateTimeModel::CLASSNAME, $file1->id); + $proxy1 = $em1->getReference(DateTimeModel::class, $file1->id); + $proxy2 = $em2->getReference(DateTimeModel::class, $file1->id); $merged2 = $em2->merge($proxy1); $this->assertNotSame($proxy1, $merged2); @@ -195,10 +196,10 @@ public function testMergingUnInitializedProxyDoesNotInitializeIt() $queryCount1 = count($logger1->queries); $queryCount2 = count($logger1->queries); - $unManagedProxy = $em1->getReference(DateTimeModel::CLASSNAME, $file1->id); + $unManagedProxy = $em1->getReference(DateTimeModel::class, $file1->id); $mergedInstance = $em2->merge($unManagedProxy); - $this->assertNotInstanceOf('Doctrine\Common\Proxy\Proxy', $mergedInstance); + $this->assertNotInstanceOf(Proxy::class, $mergedInstance); $this->assertNotSame($unManagedProxy, $mergedInstance); $this->assertFalse($unManagedProxy->__isInitialized()); @@ -258,7 +259,7 @@ private function createEntityManager(SQLLogger $logger) $entityManager = EntityManager::create($connection, $config); - (new SchemaTool($entityManager))->createSchema([$entityManager->getClassMetadata(DateTimeModel::CLASSNAME)]); + (new SchemaTool($entityManager))->createSchema([$entityManager->getClassMetadata(DateTimeModel::class)]); return $entityManager; } diff --git a/tests/Doctrine/Tests/ORM/Functional/MergeSharedEntitiesTest.php b/tests/Doctrine/Tests/ORM/Functional/MergeSharedEntitiesTest.php index e77b396947b..b549a420108 100644 --- a/tests/Doctrine/Tests/ORM/Functional/MergeSharedEntitiesTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/MergeSharedEntitiesTest.php @@ -17,8 +17,8 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\MSEFile'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\MSEPicture'), + $this->_em->getClassMetadata(MSEFile::class), + $this->_em->getClassMetadata(MSEPicture::class), ] ); } catch (ToolsException $ignored) { diff --git a/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php b/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php index 9d9eb233d08..93eab26678d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php @@ -3,17 +3,22 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Common\Collections\ArrayCollection; - use Doctrine\ORM\Internal\Hydration\HydrationException; +use Doctrine\ORM\PersistentCollection; +use Doctrine\ORM\Query\Parameter; use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\ORM\Query\ResultSetMappingBuilder; -use Doctrine\ORM\Query\Parameter; -use Doctrine\Tests\Models\CMS\CmsUser; -use Doctrine\Tests\Models\CMS\CmsPhonenumber; use Doctrine\Tests\Models\CMS\CmsAddress; use Doctrine\Tests\Models\CMS\CmsEmail; +use Doctrine\Tests\Models\CMS\CmsPhonenumber; +use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\Models\Company\CompanyContract; use Doctrine\Tests\Models\Company\CompanyEmployee; +use Doctrine\Tests\Models\Company\CompanyFixContract; +use Doctrine\Tests\Models\Company\CompanyFlexContract; use Doctrine\Tests\Models\Company\CompanyPerson; +use Doctrine\Tests\Models\DDC3899\DDC3899FixContract; +use Doctrine\Tests\Models\DDC3899\DDC3899User; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -45,7 +50,7 @@ public function testBasicNativeQuery() $this->_em->clear(); $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addEntityResult(CmsUser::class, 'u'); $rsm->addFieldResult('u', $this->platform->getSQLResultCasing('id'), 'id'); $rsm->addFieldResult('u', $this->platform->getSQLResultCasing('name'), 'name'); @@ -55,7 +60,7 @@ public function testBasicNativeQuery() $users = $query->getResult(); $this->assertEquals(1, count($users)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[0]); + $this->assertInstanceOf(CmsUser::class, $users[0]); $this->assertEquals('Roman', $users[0]->name); } @@ -80,7 +85,7 @@ public function testBasicNativeQueryWithMetaResult() $this->_em->clear(); $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsAddress', 'a'); + $rsm->addEntityResult(CmsAddress::class, 'a'); $rsm->addFieldResult('a', $this->platform->getSQLResultCasing('id'), 'id'); $rsm->addFieldResult('a', $this->platform->getSQLResultCasing('country'), 'country'); $rsm->addFieldResult('a', $this->platform->getSQLResultCasing('zip'), 'zip'); @@ -119,11 +124,11 @@ public function testJoinedOneToManyNativeQuery() $this->_em->clear(); $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addEntityResult(CmsUser::class, 'u'); $rsm->addFieldResult('u', $this->platform->getSQLResultCasing('id'), 'id'); $rsm->addFieldResult('u', $this->platform->getSQLResultCasing('name'), 'name'); $rsm->addFieldResult('u', $this->platform->getSQLResultCasing('status'), 'status'); - $rsm->addJoinedEntityResult('Doctrine\Tests\Models\CMS\CmsPhonenumber', 'p', 'u', 'phonenumbers'); + $rsm->addJoinedEntityResult(CmsPhonenumber::class, 'p', 'u', 'phonenumbers'); $rsm->addFieldResult('p', $this->platform->getSQLResultCasing('phonenumber'), 'phonenumber'); $query = $this->_em->createNativeQuery('SELECT id, name, status, phonenumber FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username = ?', $rsm); @@ -131,9 +136,9 @@ public function testJoinedOneToManyNativeQuery() $users = $query->getResult(); $this->assertEquals(1, count($users)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[0]); + $this->assertInstanceOf(CmsUser::class, $users[0]); $this->assertEquals('Roman', $users[0]->name); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $users[0]->getPhonenumbers()); + $this->assertInstanceOf(PersistentCollection::class, $users[0]->getPhonenumbers()); $this->assertTrue($users[0]->getPhonenumbers()->isInitialized()); $this->assertEquals(1, count($users[0]->getPhonenumbers())); $phones = $users[0]->getPhonenumbers(); @@ -164,11 +169,11 @@ public function testJoinedOneToOneNativeQuery() $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addEntityResult(CmsUser::class, 'u'); $rsm->addFieldResult('u', $this->platform->getSQLResultCasing('id'), 'id'); $rsm->addFieldResult('u', $this->platform->getSQLResultCasing('name'), 'name'); $rsm->addFieldResult('u', $this->platform->getSQLResultCasing('status'), 'status'); - $rsm->addJoinedEntityResult('Doctrine\Tests\Models\CMS\CmsAddress', 'a', 'u', 'address'); + $rsm->addJoinedEntityResult(CmsAddress::class, 'a', 'u', 'address'); $rsm->addFieldResult('a', $this->platform->getSQLResultCasing('a_id'), 'id'); $rsm->addFieldResult('a', $this->platform->getSQLResultCasing('country'), 'country'); $rsm->addFieldResult('a', $this->platform->getSQLResultCasing('zip'), 'zip'); @@ -180,11 +185,11 @@ public function testJoinedOneToOneNativeQuery() $users = $query->getResult(); $this->assertEquals(1, count($users)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[0]); + $this->assertInstanceOf(CmsUser::class, $users[0]); $this->assertEquals('Roman', $users[0]->name); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $users[0]->getPhonenumbers()); + $this->assertInstanceOf(PersistentCollection::class, $users[0]->getPhonenumbers()); $this->assertFalse($users[0]->getPhonenumbers()->isInitialized()); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress', $users[0]->getAddress()); + $this->assertInstanceOf(CmsAddress::class, $users[0]->getAddress()); $this->assertTrue($users[0]->getAddress()->getUser() == $users[0]); $this->assertEquals('germany', $users[0]->getAddress()->getCountry()); $this->assertEquals(10827, $users[0]->getAddress()->getZipCode()); @@ -230,16 +235,16 @@ public function testJoinedOneToManyNativeQueryWithRSMBuilder() $this->_em->clear(); $rsm = new ResultSetMappingBuilder($this->_em); - $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsUser', 'u'); - $rsm->addJoinedEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber', 'p', 'u', 'phonenumbers'); + $rsm->addRootEntityFromClassMetadata(CmsUser::class, 'u'); + $rsm->addJoinedEntityFromClassMetadata(CmsPhonenumber::class, 'p', 'u', 'phonenumbers'); $query = $this->_em->createNativeQuery('SELECT u.*, p.* FROM cms_users u LEFT JOIN cms_phonenumbers p ON u.id = p.user_id WHERE username = ?', $rsm); $query->setParameter(1, 'romanb'); $users = $query->getResult(); $this->assertEquals(1, count($users)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[0]); + $this->assertInstanceOf(CmsUser::class, $users[0]); $this->assertEquals('Roman', $users[0]->name); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $users[0]->getPhonenumbers()); + $this->assertInstanceOf(PersistentCollection::class, $users[0]->getPhonenumbers()); $this->assertTrue($users[0]->getPhonenumbers()->isInitialized()); $this->assertEquals(1, count($users[0]->getPhonenumbers())); $phones = $users[0]->getPhonenumbers(); @@ -249,7 +254,7 @@ public function testJoinedOneToManyNativeQueryWithRSMBuilder() $this->_em->clear(); $rsm = new ResultSetMappingBuilder($this->_em); - $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber', 'p'); + $rsm->addRootEntityFromClassMetadata(CmsPhonenumber::class, 'p'); $query = $this->_em->createNativeQuery('SELECT p.* FROM cms_phonenumbers p WHERE p.phonenumber = ?', $rsm); $query->setParameter(1, $phone->phonenumber); $phone = $query->getSingleResult(); @@ -280,8 +285,8 @@ public function testJoinedOneToOneNativeQueryWithRSMBuilder() $rsm = new ResultSetMappingBuilder($this->_em); - $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsUser', 'u'); - $rsm->addJoinedEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', 'a', 'u', 'address', ['id' => 'a_id'] + $rsm->addRootEntityFromClassMetadata(CmsUser::class, 'u'); + $rsm->addJoinedEntityFromClassMetadata(CmsAddress::class, 'a', 'u', 'address', ['id' => 'a_id'] ); $query = $this->_em->createNativeQuery('SELECT u.*, a.*, a.id AS a_id FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id WHERE u.username = ?', $rsm); @@ -290,11 +295,11 @@ public function testJoinedOneToOneNativeQueryWithRSMBuilder() $users = $query->getResult(); $this->assertEquals(1, count($users)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[0]); + $this->assertInstanceOf(CmsUser::class, $users[0]); $this->assertEquals('Roman', $users[0]->name); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $users[0]->getPhonenumbers()); + $this->assertInstanceOf(PersistentCollection::class, $users[0]->getPhonenumbers()); $this->assertFalse($users[0]->getPhonenumbers()->isInitialized()); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress', $users[0]->getAddress()); + $this->assertInstanceOf(CmsAddress::class, $users[0]->getAddress()); $this->assertTrue($users[0]->getAddress()->getUser() == $users[0]); $this->assertEquals('germany', $users[0]->getAddress()->getCountry()); $this->assertEquals(10827, $users[0]->getAddress()->getZipCode()); @@ -303,7 +308,7 @@ public function testJoinedOneToOneNativeQueryWithRSMBuilder() $this->_em->clear(); $rsm = new ResultSetMappingBuilder($this->_em); - $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', 'a'); + $rsm->addRootEntityFromClassMetadata(CmsAddress::class, 'a'); $query = $this->_em->createNativeQuery('SELECT a.* FROM cms_addresses a WHERE a.id = ?', $rsm); $query->setParameter(1, $addr->getId()); $address = $query->getSingleResult(); @@ -318,7 +323,7 @@ public function testJoinedOneToOneNativeQueryWithRSMBuilder() public function testConcreteClassInSingleTableInheritanceSchemaWithRSMBuilderIsFine() { $rsm = new ResultSetMappingBuilder($this->_em); - $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\Company\CompanyFixContract', 'c'); + $rsm->addRootEntityFromClassMetadata(CompanyFixContract::class, 'c'); } /** @@ -330,7 +335,7 @@ public function testAbstractClassInSingleTableInheritanceSchemaWithRSMBuilderThr $this->expectExceptionMessage('ResultSetMapping builder does not currently support your inheritance scheme.'); $rsm = new ResultSetMappingBuilder($this->_em); - $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\Company\CompanyContract', 'c'); + $rsm->addRootEntityFromClassMetadata(CompanyContract::class, 'c'); } /** @@ -339,8 +344,8 @@ public function testAbstractClassInSingleTableInheritanceSchemaWithRSMBuilderThr public function testRSMBuilderThrowsExceptionOnColumnConflict() { $rsm = new ResultSetMappingBuilder($this->_em); - $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsUser', 'u'); - $rsm->addJoinedEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', 'a', 'u', 'address'); + $rsm->addRootEntityFromClassMetadata(CmsUser::class, 'u'); + $rsm->addJoinedEntityFromClassMetadata(CmsAddress::class, 'a', 'u', 'address'); } /** @@ -349,8 +354,8 @@ public function testRSMBuilderThrowsExceptionOnColumnConflict() public function testUnknownParentAliasThrowsException() { $rsm = new ResultSetMappingBuilder($this->_em); - $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsUser', 'u'); - $rsm->addJoinedEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', 'a', 'un', 'address', ['id' => 'a_id'] + $rsm->addRootEntityFromClassMetadata(CmsUser::class, 'u'); + $rsm->addJoinedEntityFromClassMetadata(CmsAddress::class, 'a', 'un', 'address', ['id' => 'a_id'] ); $query = $this->_em->createNativeQuery('SELECT u.*, a.*, a.id AS a_id FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id WHERE u.username = ?', $rsm); @@ -387,12 +392,12 @@ public function testBasicNativeNamedQueryWithSqlResultSetMapping() $this->_em->clear(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsAddress'); + $repository = $this->_em->getRepository(CmsAddress::class); $query = $repository->createNativeNamedQuery('find-all'); $result = $query->getResult(); $this->assertCount(1, $result); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress', $result[0]); + $this->assertInstanceOf(CmsAddress::class, $result[0]); $this->assertEquals($addr->id, $result[0]->id); $this->assertEquals($addr->city, $result[0]->city); $this->assertEquals($addr->country, $result[0]->country); @@ -419,14 +424,14 @@ public function testBasicNativeNamedQueryWithResultClass() $this->_em->clear(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repository = $this->_em->getRepository(CmsUser::class); $result = $repository->createNativeNamedQuery('fetchIdAndUsernameWithResultClass') ->setParameter(1, 'FabioBatSilva')->getResult(); $this->assertEquals(1, count($result)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0]); + $this->assertInstanceOf(CmsUser::class, $result[0]); $this->assertNull($result[0]->name); $this->assertNull($result[0]->email); $this->assertEquals($user->id, $result[0]->id); @@ -439,12 +444,12 @@ public function testBasicNativeNamedQueryWithResultClass() ->setParameter(1, 'FabioBatSilva')->getResult(); $this->assertEquals(1, count($result)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0]); + $this->assertInstanceOf(CmsUser::class, $result[0]); $this->assertEquals($user->id, $result[0]->id); $this->assertEquals('Fabio B. Silva', $result[0]->name); $this->assertEquals('FabioBatSilva', $result[0]->username); $this->assertEquals('dev', $result[0]->status); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsEmail', $result[0]->email); + $this->assertInstanceOf(CmsEmail::class, $result[0]->email); } @@ -471,18 +476,18 @@ public function testJoinedOneToOneNativeNamedQueryWithResultSetMapping() $this->_em->clear(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repository = $this->_em->getRepository(CmsUser::class); $result = $repository->createNativeNamedQuery('fetchJoinedAddress') ->setParameter(1, 'FabioBatSilva')->getResult(); $this->assertEquals(1, count($result)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0]); + $this->assertInstanceOf(CmsUser::class, $result[0]); $this->assertEquals('Fabio B. Silva', $result[0]->name); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[0]->getPhonenumbers()); + $this->assertInstanceOf(PersistentCollection::class, $result[0]->getPhonenumbers()); $this->assertFalse($result[0]->getPhonenumbers()->isInitialized()); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress', $result[0]->getAddress()); + $this->assertInstanceOf(CmsAddress::class, $result[0]->getAddress()); $this->assertTrue($result[0]->getAddress()->getUser() == $result[0]); $this->assertEquals('Brazil', $result[0]->getAddress()->getCountry()); $this->assertEquals(10827, $result[0]->getAddress()->getZipCode()); @@ -509,15 +514,15 @@ public function testJoinedOneToManyNativeNamedQueryWithResultSetMapping() $this->_em->clear(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repository = $this->_em->getRepository(CmsUser::class); $result = $repository->createNativeNamedQuery('fetchJoinedPhonenumber') ->setParameter(1, 'FabioBatSilva')->getResult(); $this->assertEquals(1, count($result)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0]); + $this->assertInstanceOf(CmsUser::class, $result[0]); $this->assertEquals('Fabio B. Silva', $result[0]->name); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[0]->getPhonenumbers()); + $this->assertInstanceOf(PersistentCollection::class, $result[0]->getPhonenumbers()); $this->assertTrue($result[0]->getPhonenumbers()->isInitialized()); $this->assertEquals(1, count($result[0]->getPhonenumbers())); $phones = $result[0]->getPhonenumbers(); @@ -557,7 +562,7 @@ public function testMixedNativeNamedQueryNormalJoin() $this->_em->clear(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repository = $this->_em->getRepository(CmsUser::class); $result = $repository->createNativeNamedQuery('fetchUserPhonenumberCount') ->setParameter(1, ['test','FabioBatSilva'])->getResult(); @@ -567,12 +572,12 @@ public function testMixedNativeNamedQueryNormalJoin() $this->assertTrue(is_array($result[1])); // first user => 2 phonenumbers - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0][0]); + $this->assertInstanceOf(CmsUser::class, $result[0][0]); $this->assertEquals('Fabio B. Silva', $result[0][0]->name); $this->assertEquals(2, $result[0]['numphones']); // second user => 1 phonenumbers - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[1][0]); + $this->assertInstanceOf(CmsUser::class, $result[1][0]); $this->assertEquals('test tester', $result[1][0]->name); $this->assertEquals(1, $result[1]['numphones']); } @@ -596,14 +601,14 @@ public function testNativeNamedQueryInheritance() $this->_em->flush(); $this->_em->clear(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyPerson'); + $repository = $this->_em->getRepository(CompanyPerson::class); $result = $repository->createNativeNamedQuery('fetchAllWithSqlResultSetMapping') ->getResult(); $this->assertEquals(2, count($result)); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyPerson', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $result[1]); + $this->assertInstanceOf(CompanyPerson::class, $result[0]); + $this->assertInstanceOf(CompanyEmployee::class, $result[1]); $this->assertTrue(is_numeric($result[0]->getId())); $this->assertTrue(is_numeric($result[1]->getId())); $this->assertEquals('Fabio B. Silva', $result[0]->getName()); @@ -617,8 +622,8 @@ public function testNativeNamedQueryInheritance() ->getResult(); $this->assertEquals(2, count($result)); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyPerson', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $result[1]); + $this->assertInstanceOf(CompanyPerson::class, $result[0]); + $this->assertInstanceOf(CompanyEmployee::class, $result[1]); $this->assertTrue(is_numeric($result[0]->getId())); $this->assertTrue(is_numeric($result[1]->getId())); $this->assertEquals('Fabio B. Silva', $result[0]->getName()); @@ -657,7 +662,7 @@ public function testMultipleEntityResults() $this->_em->clear(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repository = $this->_em->getRepository(CmsUser::class); $query = $repository->createNativeNamedQuery('fetchMultipleJoinsEntityResults'); $result = $query->getResult(); @@ -665,9 +670,9 @@ public function testMultipleEntityResults() $this->assertEquals(1, count($result)); $this->assertTrue(is_array($result[0])); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0][0]); + $this->assertInstanceOf(CmsUser::class, $result[0][0]); $this->assertEquals('Fabio B. Silva', $result[0][0]->name); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress', $result[0][0]->getAddress()); + $this->assertInstanceOf(CmsAddress::class, $result[0][0]->getAddress()); $this->assertTrue($result[0][0]->getAddress()->getUser() == $result[0][0]); $this->assertEquals('Brazil', $result[0][0]->getAddress()->getCountry()); $this->assertEquals(10827, $result[0][0]->getAddress()->getZipCode()); @@ -681,8 +686,8 @@ public function testMultipleEntityResults() */ public function testNamedNativeQueryInheritance() { - $contractMetadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\Company\CompanyContract'); - $flexMetadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\Company\CompanyFlexContract'); + $contractMetadata = $this->_em->getClassMetadata(CompanyContract::class); + $flexMetadata = $this->_em->getClassMetadata(CompanyFlexContract::class); $contractQueries = $contractMetadata->getNamedNativeQueries(); $flexQueries = $flexMetadata->getNamedNativeQueries(); @@ -693,39 +698,39 @@ public function testNamedNativeQueryInheritance() // contract queries $this->assertEquals('all-contracts', $contractQueries['all-contracts']['name']); - $this->assertEquals('Doctrine\Tests\Models\Company\CompanyContract', $contractQueries['all-contracts']['resultClass']); + $this->assertEquals(CompanyContract::class, $contractQueries['all-contracts']['resultClass']); $this->assertEquals('all', $contractQueries['all']['name']); - $this->assertEquals('Doctrine\Tests\Models\Company\CompanyContract', $contractQueries['all']['resultClass']); + $this->assertEquals(CompanyContract::class, $contractQueries['all']['resultClass']); // flex contract queries $this->assertEquals('all-contracts', $flexQueries['all-contracts']['name']); - $this->assertEquals('Doctrine\Tests\Models\Company\CompanyFlexContract', $flexQueries['all-contracts']['resultClass']); + $this->assertEquals(CompanyFlexContract::class, $flexQueries['all-contracts']['resultClass']); $this->assertEquals('all-flex', $flexQueries['all-flex']['name']); - $this->assertEquals('Doctrine\Tests\Models\Company\CompanyFlexContract', $flexQueries['all-flex']['resultClass']); + $this->assertEquals(CompanyFlexContract::class, $flexQueries['all-flex']['resultClass']); $this->assertEquals('all', $flexQueries['all']['name']); - $this->assertEquals('Doctrine\Tests\Models\Company\CompanyFlexContract', $flexQueries['all']['resultClass']); + $this->assertEquals(CompanyFlexContract::class, $flexQueries['all']['resultClass']); // contract result mapping $this->assertEquals('mapping-all-contracts', $contractMappings['mapping-all-contracts']['name']); - $this->assertEquals('Doctrine\Tests\Models\Company\CompanyContract', $contractMappings['mapping-all-contracts']['entities'][0]['entityClass']); + $this->assertEquals(CompanyContract::class, $contractMappings['mapping-all-contracts']['entities'][0]['entityClass']); $this->assertEquals('mapping-all', $contractMappings['mapping-all']['name']); - $this->assertEquals('Doctrine\Tests\Models\Company\CompanyContract', $contractMappings['mapping-all-contracts']['entities'][0]['entityClass']); + $this->assertEquals(CompanyContract::class, $contractMappings['mapping-all-contracts']['entities'][0]['entityClass']); // flex contract result mapping $this->assertEquals('mapping-all-contracts', $flexMappings['mapping-all-contracts']['name']); - $this->assertEquals('Doctrine\Tests\Models\Company\CompanyFlexContract', $flexMappings['mapping-all-contracts']['entities'][0]['entityClass']); + $this->assertEquals(CompanyFlexContract::class, $flexMappings['mapping-all-contracts']['entities'][0]['entityClass']); $this->assertEquals('mapping-all', $flexMappings['mapping-all']['name']); - $this->assertEquals('Doctrine\Tests\Models\Company\CompanyFlexContract', $flexMappings['mapping-all']['entities'][0]['entityClass']); + $this->assertEquals(CompanyFlexContract::class, $flexMappings['mapping-all']['entities'][0]['entityClass']); $this->assertEquals('mapping-all-flex', $flexMappings['mapping-all-flex']['name']); - $this->assertEquals('Doctrine\Tests\Models\Company\CompanyFlexContract', $flexMappings['mapping-all-flex']['entities'][0]['entityClass']); + $this->assertEquals(CompanyFlexContract::class, $flexMappings['mapping-all-flex']['entities'][0]['entityClass']); } @@ -735,7 +740,7 @@ public function testNamedNativeQueryInheritance() public function testGenerateSelectClauseNoRenameSingleEntity() { $rsm = new ResultSetMappingBuilder($this->_em); - $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addRootEntityFromClassMetadata(CmsUser::class, 'u'); $selectClause = $rsm->generateSelectClause(); @@ -748,7 +753,7 @@ public function testGenerateSelectClauseNoRenameSingleEntity() public function testGenerateSelectClauseCustomRenames() { $rsm = new ResultSetMappingBuilder($this->_em); - $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsUser', 'u', [ + $rsm->addRootEntityFromClassMetadata(CmsUser::class, 'u', [ 'id' => 'id1', 'username' => 'username2' ] @@ -765,7 +770,7 @@ public function testGenerateSelectClauseCustomRenames() public function testGenerateSelectClauseRenameTableAlias() { $rsm = new ResultSetMappingBuilder($this->_em); - $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addRootEntityFromClassMetadata(CmsUser::class, 'u'); $selectClause = $rsm->generateSelectClause(['u' => 'u1']); @@ -778,7 +783,7 @@ public function testGenerateSelectClauseRenameTableAlias() public function testGenerateSelectClauseIncrement() { $rsm = new ResultSetMappingBuilder($this->_em, ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT); - $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addRootEntityFromClassMetadata(CmsUser::class, 'u'); $selectClause = $rsm->generateSelectClause(); @@ -791,7 +796,7 @@ public function testGenerateSelectClauseIncrement() public function testGenerateSelectClauseToString() { $rsm = new ResultSetMappingBuilder($this->_em, ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT); - $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addRootEntityFromClassMetadata(CmsUser::class, 'u'); $this->assertSQLEquals('u.id AS id0, u.status AS status1, u.username AS username2, u.name AS name3, u.email_id AS email_id4', (string)$rsm); } @@ -802,8 +807,8 @@ public function testGenerateSelectClauseToString() public function testGenerateSelectClauseWithDiscriminatorColumn() { $rsm = new ResultSetMappingBuilder($this->_em, ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT); - $rsm->addEntityResult('Doctrine\Tests\Models\DDC3899\DDC3899User', 'u'); - $rsm->addJoinedEntityResult('Doctrine\Tests\Models\DDC3899\DDC3899FixContract', 'c', 'u', 'contracts'); + $rsm->addEntityResult(DDC3899User::class, 'u'); + $rsm->addJoinedEntityResult(DDC3899FixContract::class, 'c', 'u', 'contracts'); $rsm->addFieldResult('u', $this->platform->getSQLResultCasing('id'), 'id'); $rsm->setDiscriminatorColumn('c', $this->platform->getSQLResultCasing('discr')); diff --git a/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php b/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php index 972412199de..1422dcd9a2c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php @@ -3,10 +3,12 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\ORM\Query; +use Doctrine\Tests\Models\CMS\CmsAddressDTO; use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\CMS\CmsEmail; use Doctrine\Tests\Models\CMS\CmsAddress; use Doctrine\Tests\Models\CMS\CmsPhonenumber; +use Doctrine\Tests\Models\CMS\CmsUserDTO; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -122,9 +124,9 @@ public function testShouldSupportsBasicUsage($hydrationMode) $this->assertCount(3, $result); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]); + $this->assertInstanceOf(CmsUserDTO::class, $result[0]); + $this->assertInstanceOf(CmsUserDTO::class, $result[1]); + $this->assertInstanceOf(CmsUserDTO::class, $result[2]); $this->assertEquals($this->fixtures[0]->name, $result[0]->name); $this->assertEquals($this->fixtures[1]->name, $result[1]->name); @@ -165,9 +167,9 @@ public function testShouldIgnoreAliasesForSingleObject($hydrationMode) $this->assertCount(3, $result); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]); + $this->assertInstanceOf(CmsUserDTO::class, $result[0]); + $this->assertInstanceOf(CmsUserDTO::class, $result[1]); + $this->assertInstanceOf(CmsUserDTO::class, $result[2]); $this->assertEquals($this->fixtures[0]->name, $result[0]->name); $this->assertEquals($this->fixtures[1]->name, $result[1]->name); @@ -201,9 +203,9 @@ public function testShouldAssumeFromEntityNamespaceWhenNotGiven() $this->assertCount(3, $result); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]); + $this->assertInstanceOf(CmsUserDTO::class, $result[0]); + $this->assertInstanceOf(CmsUserDTO::class, $result[1]); + $this->assertInstanceOf(CmsUserDTO::class, $result[2]); } public function testShouldSupportFromEntityNamespaceAlias() @@ -229,9 +231,9 @@ public function testShouldSupportFromEntityNamespaceAlias() $this->assertCount(3, $result); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]); + $this->assertInstanceOf(CmsUserDTO::class, $result[0]); + $this->assertInstanceOf(CmsUserDTO::class, $result[1]); + $this->assertInstanceOf(CmsUserDTO::class, $result[2]); } public function testShouldSupportValueObjectNamespaceAlias() @@ -257,9 +259,9 @@ public function testShouldSupportValueObjectNamespaceAlias() $this->assertCount(3, $result); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]); + $this->assertInstanceOf(CmsUserDTO::class, $result[0]); + $this->assertInstanceOf(CmsUserDTO::class, $result[1]); + $this->assertInstanceOf(CmsUserDTO::class, $result[2]); } public function testShouldSupportLiteralExpression() @@ -290,9 +292,9 @@ public function testShouldSupportLiteralExpression() $this->assertCount(3, $result); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]); + $this->assertInstanceOf(CmsUserDTO::class, $result[0]); + $this->assertInstanceOf(CmsUserDTO::class, $result[1]); + $this->assertInstanceOf(CmsUserDTO::class, $result[2]); $this->assertEquals($this->fixtures[0]->name, $result[0]->name); @@ -338,9 +340,9 @@ public function testShouldSupportCaseExpression() $this->assertCount(3, $result); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]); + $this->assertInstanceOf(CmsUserDTO::class, $result[0]); + $this->assertInstanceOf(CmsUserDTO::class, $result[1]); + $this->assertInstanceOf(CmsUserDTO::class, $result[2]); $this->assertEquals($this->fixtures[0]->name, $result[0]->name); @@ -380,9 +382,9 @@ public function testShouldSupportSimpleArithmeticExpression() $this->assertCount(3, $result); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]); + $this->assertInstanceOf(CmsUserDTO::class, $result[0]); + $this->assertInstanceOf(CmsUserDTO::class, $result[1]); + $this->assertInstanceOf(CmsUserDTO::class, $result[2]); $this->assertEquals($this->fixtures[0]->name, $result[0]->name); $this->assertEquals($this->fixtures[1]->name, $result[1]->name); @@ -440,9 +442,9 @@ public function testShouldSupportAggregateFunctions() $this->assertCount(3, $result); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]); + $this->assertInstanceOf(CmsUserDTO::class, $result[0]); + $this->assertInstanceOf(CmsUserDTO::class, $result[1]); + $this->assertInstanceOf(CmsUserDTO::class, $result[2]); $this->assertEquals($this->fixtures[0]->name, $result[0]->name); $this->assertEquals($this->fixtures[1]->name, $result[1]->name); @@ -500,9 +502,9 @@ public function testShouldSupportArithmeticExpression() $this->assertCount(3, $result); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]); + $this->assertInstanceOf(CmsUserDTO::class, $result[0]); + $this->assertInstanceOf(CmsUserDTO::class, $result[1]); + $this->assertInstanceOf(CmsUserDTO::class, $result[2]); $this->assertEquals($this->fixtures[0]->name, $result[0]->name); $this->assertEquals($this->fixtures[1]->name, $result[1]->name); @@ -558,13 +560,13 @@ public function testShouldSupportMultipleNewOperators() $this->assertCount(3, $result); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0][0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1][0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2][0]); + $this->assertInstanceOf(CmsUserDTO::class, $result[0][0]); + $this->assertInstanceOf(CmsUserDTO::class, $result[1][0]); + $this->assertInstanceOf(CmsUserDTO::class, $result[2][0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[0][1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[1][1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[2][1]); + $this->assertInstanceOf(CmsAddressDTO::class, $result[0][1]); + $this->assertInstanceOf(CmsAddressDTO::class, $result[1][1]); + $this->assertInstanceOf(CmsAddressDTO::class, $result[2][1]); $this->assertEquals($this->fixtures[0]->name, $result[0][0]->name); $this->assertEquals($this->fixtures[1]->name, $result[1][0]->name); @@ -610,13 +612,13 @@ public function testShouldSupportMultipleNewOperatorsWithAliases() $this->assertCount(3, $result); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0]['cmsUser']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1]['cmsUser']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]['cmsUser']); + $this->assertInstanceOf(CmsUserDTO::class, $result[0]['cmsUser']); + $this->assertInstanceOf(CmsUserDTO::class, $result[1]['cmsUser']); + $this->assertInstanceOf(CmsUserDTO::class, $result[2]['cmsUser']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[0]['cmsAddress']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[1]['cmsAddress']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[2]['cmsAddress']); + $this->assertInstanceOf(CmsAddressDTO::class, $result[0]['cmsAddress']); + $this->assertInstanceOf(CmsAddressDTO::class, $result[1]['cmsAddress']); + $this->assertInstanceOf(CmsAddressDTO::class, $result[2]['cmsAddress']); $this->assertEquals($this->fixtures[0]->name, $result[0]['cmsUser']->name); $this->assertEquals($this->fixtures[1]->name, $result[1]['cmsUser']->name); @@ -662,13 +664,13 @@ public function testShouldSupportMultipleNewOperatorsWithAndWithoutAliases() $this->assertCount(3, $result); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0]['cmsUser']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1]['cmsUser']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]['cmsUser']); + $this->assertInstanceOf(CmsUserDTO::class, $result[0]['cmsUser']); + $this->assertInstanceOf(CmsUserDTO::class, $result[1]['cmsUser']); + $this->assertInstanceOf(CmsUserDTO::class, $result[2]['cmsUser']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[0][0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[1][0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[2][0]); + $this->assertInstanceOf(CmsAddressDTO::class, $result[0][0]); + $this->assertInstanceOf(CmsAddressDTO::class, $result[1][0]); + $this->assertInstanceOf(CmsAddressDTO::class, $result[2][0]); $this->assertEquals($this->fixtures[0]->name, $result[0]['cmsUser']->name); $this->assertEquals($this->fixtures[1]->name, $result[1]['cmsUser']->name); @@ -715,13 +717,13 @@ public function testShouldSupportMultipleNewOperatorsAndSingleScalar() $this->assertCount(3, $result); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0][0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1][0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2][0]); + $this->assertInstanceOf(CmsUserDTO::class, $result[0][0]); + $this->assertInstanceOf(CmsUserDTO::class, $result[1][0]); + $this->assertInstanceOf(CmsUserDTO::class, $result[2][0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[0][1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[1][1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[2][1]); + $this->assertInstanceOf(CmsAddressDTO::class, $result[0][1]); + $this->assertInstanceOf(CmsAddressDTO::class, $result[1][1]); + $this->assertInstanceOf(CmsAddressDTO::class, $result[2][1]); $this->assertEquals($this->fixtures[0]->name, $result[0][0]->name); $this->assertEquals($this->fixtures[1]->name, $result[1][0]->name); @@ -772,13 +774,13 @@ public function testShouldSupportMultipleNewOperatorsAndSingleScalarWithAliases( $this->assertCount(3, $result); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0]['cmsUser']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1]['cmsUser']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]['cmsUser']); + $this->assertInstanceOf(CmsUserDTO::class, $result[0]['cmsUser']); + $this->assertInstanceOf(CmsUserDTO::class, $result[1]['cmsUser']); + $this->assertInstanceOf(CmsUserDTO::class, $result[2]['cmsUser']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[0]['cmsAddress']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[1]['cmsAddress']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[2]['cmsAddress']); + $this->assertInstanceOf(CmsAddressDTO::class, $result[0]['cmsAddress']); + $this->assertInstanceOf(CmsAddressDTO::class, $result[1]['cmsAddress']); + $this->assertInstanceOf(CmsAddressDTO::class, $result[2]['cmsAddress']); $this->assertEquals($this->fixtures[0]->name, $result[0]['cmsUser']->name); $this->assertEquals($this->fixtures[1]->name, $result[1]['cmsUser']->name); @@ -829,13 +831,13 @@ public function testShouldSupportMultipleNewOperatorsAndSingleScalarWithAndWitho $this->assertCount(3, $result); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0]['cmsUser']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1]['cmsUser']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]['cmsUser']); + $this->assertInstanceOf(CmsUserDTO::class, $result[0]['cmsUser']); + $this->assertInstanceOf(CmsUserDTO::class, $result[1]['cmsUser']); + $this->assertInstanceOf(CmsUserDTO::class, $result[2]['cmsUser']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[0][0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[1][0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[2][0]); + $this->assertInstanceOf(CmsAddressDTO::class, $result[0][0]); + $this->assertInstanceOf(CmsAddressDTO::class, $result[1][0]); + $this->assertInstanceOf(CmsAddressDTO::class, $result[2][0]); $this->assertEquals($this->fixtures[0]->name, $result[0]['cmsUser']->name); $this->assertEquals($this->fixtures[1]->name, $result[1]['cmsUser']->name); @@ -887,13 +889,13 @@ public function testShouldSupportMultipleNewOperatorsAndMultipleScalars() $this->assertCount(3, $result); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0][0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1][0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2][0]); + $this->assertInstanceOf(CmsUserDTO::class, $result[0][0]); + $this->assertInstanceOf(CmsUserDTO::class, $result[1][0]); + $this->assertInstanceOf(CmsUserDTO::class, $result[2][0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[0][1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[1][1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[2][1]); + $this->assertInstanceOf(CmsAddressDTO::class, $result[0][1]); + $this->assertInstanceOf(CmsAddressDTO::class, $result[1][1]); + $this->assertInstanceOf(CmsAddressDTO::class, $result[2][1]); $this->assertEquals($this->fixtures[0]->name, $result[0][0]->name); $this->assertEquals($this->fixtures[1]->name, $result[1][0]->name); @@ -949,13 +951,13 @@ public function testShouldSupportMultipleNewOperatorsAndMultipleScalarsWithAlias $this->assertCount(3, $result); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0]['cmsUser']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1]['cmsUser']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]['cmsUser']); + $this->assertInstanceOf(CmsUserDTO::class, $result[0]['cmsUser']); + $this->assertInstanceOf(CmsUserDTO::class, $result[1]['cmsUser']); + $this->assertInstanceOf(CmsUserDTO::class, $result[2]['cmsUser']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[0]['cmsAddress']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[1]['cmsAddress']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[2]['cmsAddress']); + $this->assertInstanceOf(CmsAddressDTO::class, $result[0]['cmsAddress']); + $this->assertInstanceOf(CmsAddressDTO::class, $result[1]['cmsAddress']); + $this->assertInstanceOf(CmsAddressDTO::class, $result[2]['cmsAddress']); $this->assertEquals($this->fixtures[0]->name, $result[0]['cmsUser']->name); $this->assertEquals($this->fixtures[1]->name, $result[1]['cmsUser']->name); @@ -1011,13 +1013,13 @@ public function testShouldSupportMultipleNewOperatorsAndMultipleScalarsWithAndWi $this->assertCount(3, $result); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0]['cmsUser']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1]['cmsUser']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]['cmsUser']); + $this->assertInstanceOf(CmsUserDTO::class, $result[0]['cmsUser']); + $this->assertInstanceOf(CmsUserDTO::class, $result[1]['cmsUser']); + $this->assertInstanceOf(CmsUserDTO::class, $result[2]['cmsUser']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[0][0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[1][0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddressDTO', $result[2][0]); + $this->assertInstanceOf(CmsAddressDTO::class, $result[0][0]); + $this->assertInstanceOf(CmsAddressDTO::class, $result[1][0]); + $this->assertInstanceOf(CmsAddressDTO::class, $result[2][0]); $this->assertEquals($this->fixtures[0]->name, $result[0]['cmsUser']->name); $this->assertEquals($this->fixtures[1]->name, $result[1]['cmsUser']->name); diff --git a/tests/Doctrine/Tests/ORM/Functional/NotifyPolicyTest.php b/tests/Doctrine/Tests/ORM/Functional/NotifyPolicyTest.php index a289ef9dd80..24dc6fd2468 100644 --- a/tests/Doctrine/Tests/ORM/Functional/NotifyPolicyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/NotifyPolicyTest.php @@ -20,8 +20,8 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\NotifyUser'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\NotifyGroup') + $this->_em->getClassMetadata(NotifyUser::class), + $this->_em->getClassMetadata(NotifyGroup::class) ] ); } catch (\Exception $e) { @@ -57,9 +57,9 @@ public function testChangeTracking() $groupId = $group->getId(); unset($user, $group); - $user = $this->_em->find(__NAMESPACE__.'\NotifyUser', $userId); + $user = $this->_em->find(NotifyUser::class, $userId); $this->assertEquals(1, $user->getGroups()->count()); - $group = $this->_em->find(__NAMESPACE__.'\NotifyGroup', $groupId); + $group = $this->_em->find(NotifyGroup::class, $groupId); $this->assertEquals(1, $group->getUsers()->count()); $this->assertEquals(1, count($user->listeners)); @@ -82,11 +82,11 @@ public function testChangeTracking() $group2Id = $group2->getId(); unset($group2, $user); - $user = $this->_em->find(__NAMESPACE__.'\NotifyUser', $userId); + $user = $this->_em->find(NotifyUser::class, $userId); $this->assertEquals(2, $user->getGroups()->count()); - $group2 = $this->_em->find(__NAMESPACE__.'\NotifyGroup', $group2Id); + $group2 = $this->_em->find(NotifyGroup::class, $group2Id); $this->assertEquals(1, $group2->getUsers()->count()); - $group = $this->_em->find(__NAMESPACE__.'\NotifyGroup', $groupId); + $group = $this->_em->find(NotifyGroup::class, $groupId); $this->assertEquals(1, $group->getUsers()->count()); $this->assertEquals('geeks', $group->getName()); } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php index ddc7378f7a1..95309c60579 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php @@ -2,9 +2,11 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\Tests\Models\ECommerce\ECommerceProduct; -use Doctrine\Tests\Models\ECommerce\ECommerceFeature; +use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Criteria; +use Doctrine\ORM\Proxy\Proxy; +use Doctrine\Tests\Models\ECommerce\ECommerceFeature; +use Doctrine\Tests\Models\ECommerce\ECommerceProduct; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -76,13 +78,13 @@ public function testEagerLoadsOneToManyAssociation() $features = $product->getFeatures(); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $features[0]); - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $features[0]->getProduct()); + $this->assertInstanceOf(ECommerceFeature::class, $features[0]); + $this->assertNotInstanceOf(Proxy::class, $features[0]->getProduct()); $this->assertSame($product, $features[0]->getProduct()); $this->assertEquals('Model writing tutorial', $features[0]->getDescription()); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $features[1]); + $this->assertInstanceOf(ECommerceFeature::class, $features[1]); $this->assertSame($product, $features[1]->getProduct()); - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $features[1]->getProduct()); + $this->assertNotInstanceOf(Proxy::class, $features[1]->getProduct()); $this->assertEquals('Annotations examples', $features[1]->getDescription()); } @@ -96,11 +98,11 @@ public function testLazyLoadsObjectsOnTheOwningSide() $features = $product->getFeatures(); $this->assertFalse($features->isInitialized()); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $features[0]); + $this->assertInstanceOf(ECommerceFeature::class, $features[0]); $this->assertTrue($features->isInitialized()); $this->assertSame($product, $features[0]->getProduct()); $this->assertEquals('Model writing tutorial', $features[0]->getDescription()); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $features[1]); + $this->assertInstanceOf(ECommerceFeature::class, $features[1]); $this->assertSame($product, $features[1]->getProduct()); $this->assertEquals('Annotations examples', $features[1]->getDescription()); } @@ -113,8 +115,8 @@ public function testLazyLoadsObjectsOnTheInverseSide() $features = $query->getResult(); $product = $features[0]->getProduct(); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $product); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $product); + $this->assertInstanceOf(Proxy::class, $product); + $this->assertInstanceOf(ECommerceProduct::class, $product); $this->assertFalse($product->__isInitialized__); $this->assertSame('Doctrine Cookbook', $product->getName()); $this->assertTrue($product->__isInitialized__); @@ -129,8 +131,8 @@ public function testLazyLoadsObjectsOnTheInverseSide2() $features = $query->getResult(); $product = $features[0]->getProduct(); - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $product); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $product); + $this->assertNotInstanceOf(Proxy::class, $product); + $this->assertInstanceOf(ECommerceProduct::class, $product); $this->assertSame('Doctrine Cookbook', $product->getName()); $this->assertFalse($product->getFeatures()->isInitialized()); @@ -157,19 +159,19 @@ public function testMatching() { $this->_createFixture(); - $product = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $this->product->getId()); + $product = $this->_em->find(ECommerceProduct::class, $this->product->getId()); $features = $product->getFeatures(); $results = $features->matching(new Criteria( Criteria::expr()->eq('description', 'Model writing tutorial') )); - $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $results); + $this->assertInstanceOf(Collection::class, $results); $this->assertEquals(1, count($results)); $results = $features->matching(new Criteria()); - $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $results); + $this->assertInstanceOf(Collection::class, $results); $this->assertEquals(2, count($results)); } @@ -180,7 +182,7 @@ public function testMatchingOnDirtyCollection() { $this->_createFixture(); - $product = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $this->product->getId()); + $product = $this->_em->find(ECommerceProduct::class, $this->product->getId()); $thirdFeature = new ECommerceFeature(); $thirdFeature->setDescription('Model writing tutorial'); @@ -199,7 +201,7 @@ public function testMatchingBis() { $this->_createFixture(); - $product = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $this->product->getId()); + $product = $this->_em->find(ECommerceProduct::class, $this->product->getId()); $features = $product->getFeatures(); $thirdFeature = new ECommerceFeature(); @@ -210,12 +212,12 @@ public function testMatchingBis() Criteria::expr()->eq('description', 'Third feature') )); - $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $results); + $this->assertInstanceOf(Collection::class, $results); $this->assertCount(1, $results); $results = $features->matching(new Criteria()); - $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $results); + $this->assertInstanceOf(Collection::class, $results); $this->assertCount(3, $results); } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManyOrphanRemovalTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManyOrphanRemovalTest.php index d22dbd4e2c3..da70672b6d2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToManyOrphanRemovalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToManyOrphanRemovalTest.php @@ -2,8 +2,8 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\Tests\Models\CMS\CmsUser, - Doctrine\Tests\Models\CMS\CmsPhonenumber; +use Doctrine\Tests\Models\CMS\CmsPhonenumber; +use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -42,7 +42,7 @@ protected function setUp() public function testOrphanRemoval() { - $userProxy = $this->_em->getReference('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $userProxy = $this->_em->getReference(CmsUser::class, $this->userId); $this->_em->remove($userProxy); $this->_em->flush(); @@ -64,7 +64,7 @@ public function testOrphanRemoval() */ public function testOrphanRemovalRemoveFromCollection() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $phonenumber = $user->getPhonenumbers()->remove(0); @@ -82,7 +82,7 @@ public function testOrphanRemovalRemoveFromCollection() */ public function testOrphanRemovalClearCollectionAndReAdd() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $phone1 = $user->getPhonenumbers()->first(); @@ -102,7 +102,7 @@ public function testOrphanRemovalClearCollectionAndReAdd() */ public function testOrphanRemovalClearCollectionAndAddNew() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $newPhone = new CmsPhonenumber(); $newPhone->phonenumber = '654321'; @@ -123,7 +123,7 @@ public function testOrphanRemovalClearCollectionAndAddNew() */ public function testOrphanRemovalUnitializedCollection() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $user->phonenumbers->clear(); $this->_em->flush(); diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php index f6b64b5eb0a..c9f42237d19 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php @@ -2,9 +2,9 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\Tests\Models\ECommerce\ECommerceCategory; use Doctrine\ORM\Mapping\AssociationMapping; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\Tests\Models\ECommerce\ECommerceCategory; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -78,10 +78,10 @@ public function testEagerLoadsOneToManyAssociation() $parent = $result[0]; $children = $parent->getChildren(); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCategory', $children[0]); + $this->assertInstanceOf(ECommerceCategory::class, $children[0]); $this->assertSame($parent, $children[0]->getParent()); $this->assertEquals(' books', strstr($children[0]->getName(), ' books')); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCategory', $children[1]); + $this->assertInstanceOf(ECommerceCategory::class, $children[1]); $this->assertSame($parent, $children[1]->getParent()); $this->assertEquals(' books', strstr($children[1]->getName(), ' books')); } @@ -89,7 +89,7 @@ public function testEagerLoadsOneToManyAssociation() public function testLazyLoadsOneToManyAssociation() { $this->_createFixture(); - $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceCategory'); + $metadata = $this->_em->getClassMetadata(ECommerceCategory::class); $metadata->associationMappings['children']['fetch'] = ClassMetadata::FETCH_LAZY; $query = $this->_em->createQuery('select c from Doctrine\Tests\Models\ECommerce\ECommerceCategory c order by c.id asc'); @@ -97,10 +97,10 @@ public function testLazyLoadsOneToManyAssociation() $parent = $result[0]; $children = $parent->getChildren(); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCategory', $children[0]); + $this->assertInstanceOf(ECommerceCategory::class, $children[0]); $this->assertSame($parent, $children[0]->getParent()); $this->assertEquals(' books', strstr($children[0]->getName(), ' books')); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCategory', $children[1]); + $this->assertInstanceOf(ECommerceCategory::class, $children[1]); $this->assertSame($parent, $children[1]->getParent()); $this->assertEquals(' books', strstr($children[1]->getName(), ' books')); } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php index d2880ee81c3..c989e126c44 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php @@ -2,10 +2,11 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\Tests\Models\ECommerce\ECommerceCart; -use Doctrine\Tests\Models\ECommerce\ECommerceCustomer; use Doctrine\ORM\Mapping\AssociationMapping; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Proxy\Proxy; +use Doctrine\Tests\Models\ECommerce\ECommerceCart; +use Doctrine\Tests\Models\ECommerce\ECommerceCustomer; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -61,27 +62,27 @@ public function testEagerLoad() $result = $query->getResult(); $customer = $result[0]; - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCart', $customer->getCart()); + $this->assertInstanceOf(ECommerceCart::class, $customer->getCart()); $this->assertEquals('paypal', $customer->getCart()->getPayment()); } public function testLazyLoadsObjectsOnTheOwningSide() { $this->_createFixture(); - $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceCart'); + $metadata = $this->_em->getClassMetadata(ECommerceCart::class); $metadata->associationMappings['customer']['fetchMode'] = ClassMetadata::FETCH_LAZY; $query = $this->_em->createQuery('select c from Doctrine\Tests\Models\ECommerce\ECommerceCart c'); $result = $query->getResult(); $cart = $result[0]; - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCustomer', $cart->getCustomer()); + $this->assertInstanceOf(ECommerceCustomer::class, $cart->getCustomer()); $this->assertEquals('Giorgio', $cart->getCustomer()->getName()); } public function testInverseSideIsNeverLazy() { $this->_createFixture(); - $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceCustomer'); + $metadata = $this->_em->getClassMetadata(ECommerceCustomer::class); $metadata->associationMappings['mentor']['fetch'] = ClassMetadata::FETCH_EAGER; $query = $this->_em->createQuery('select c from Doctrine\Tests\Models\ECommerce\ECommerceCustomer c'); @@ -89,8 +90,8 @@ public function testInverseSideIsNeverLazy() $customer = $result[0]; $this->assertNull($customer->getMentor()); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCart', $customer->getCart()); - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $customer->getCart()); + $this->assertInstanceOf(ECommerceCart::class, $customer->getCart()); + $this->assertNotInstanceOf(Proxy::class, $customer->getCart()); $this->assertEquals('paypal', $customer->getCart()->getPayment()); } @@ -106,7 +107,7 @@ public function testUpdateWithProxyObject() $this->_em->flush(); $this->_em->clear(); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCart', $cust->getCart()); + $this->assertInstanceOf(ECommerceCart::class, $cust->getCart()); $this->assertEquals('Roman', $cust->getName()); $this->assertSame($cust, $cart->getCustomer()); @@ -125,7 +126,7 @@ public function testUpdateWithProxyObject() $cart3 = $query2->getSingleResult(); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCustomer', $cart3->getCustomer()); + $this->assertInstanceOf(ECommerceCustomer::class, $cart3->getCustomer()); $this->assertEquals('Roman', $cart3->getCustomer()->getName()); } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php index 8a99210020a..5b4cdffdfe5 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\ORM\Proxy\Proxy; use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Tests\OrmFunctionalTestCase; @@ -17,11 +18,11 @@ protected function setUp() try { $schemaTool->createSchema( [ - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Train'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\TrainDriver'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\TrainOwner'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Waggon'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\TrainOrder'), + $this->_em->getClassMetadata(Train::class), + $this->_em->getClassMetadata(TrainDriver::class), + $this->_em->getClassMetadata(TrainOwner::class), + $this->_em->getClassMetadata(Waggon::class), + $this->_em->getClassMetadata(TrainOrder::class), ] ); } catch(\Exception $e) {} @@ -46,7 +47,7 @@ public function testEagerLoadOneToOneOwningSide() $sqlCount = count($this->_sqlLoggerStack->queries); $train = $this->_em->find(get_class($train), $train->id); - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $train->driver); + $this->assertNotInstanceOf(Proxy::class, $train->driver); $this->assertEquals("Benjamin", $train->driver->name); $this->assertEquals($sqlCount + 1, count($this->_sqlLoggerStack->queries)); @@ -66,7 +67,7 @@ public function testEagerLoadOneToOneNullOwningSide() $sqlCount = count($this->_sqlLoggerStack->queries); $train = $this->_em->find(get_class($train), $train->id); - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $train->driver); + $this->assertNotInstanceOf(Proxy::class, $train->driver); $this->assertNull($train->driver); $this->assertEquals($sqlCount + 1, count($this->_sqlLoggerStack->queries)); @@ -87,7 +88,7 @@ public function testEagerLoadOneToOneInverseSide() $sqlCount = count($this->_sqlLoggerStack->queries); $driver = $this->_em->find(get_class($owner), $owner->id); - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $owner->train); + $this->assertNotInstanceOf(Proxy::class, $owner->train); $this->assertNotNull($owner->train); $this->assertEquals($sqlCount + 1, count($this->_sqlLoggerStack->queries)); @@ -109,7 +110,7 @@ public function testEagerLoadOneToOneNullInverseSide() $sqlCount = count($this->_sqlLoggerStack->queries); $driver = $this->_em->find(get_class($driver), $driver->id); - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $driver->train); + $this->assertNotInstanceOf(Proxy::class, $driver->train); $this->assertNull($driver->train); $this->assertEquals($sqlCount + 1, count($this->_sqlLoggerStack->queries)); @@ -126,7 +127,7 @@ public function testEagerLoadManyToOne() $this->_em->clear(); $waggon = $this->_em->find(get_class($waggon), $waggon->id); - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $waggon->train); + $this->assertNotInstanceOf(Proxy::class, $waggon->train); $this->assertNotNull($waggon->train); } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneOrphanRemovalTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneOrphanRemovalTest.php index 34bbc8c55b9..09ef64e021f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneOrphanRemovalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneOrphanRemovalTest.php @@ -2,9 +2,9 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\Tests\Models\CMS\CmsUser, - Doctrine\Tests\Models\CMS\CmsEmail, - Doctrine\Tests\Models\CMS\CmsAddress; +use Doctrine\Tests\Models\CMS\CmsAddress; +use Doctrine\Tests\Models\CMS\CmsEmail; +use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -40,7 +40,7 @@ public function testOrphanRemoval() $this->_em->clear(); - $userProxy = $this->_em->getReference('Doctrine\Tests\Models\CMS\CmsUser', $userId); + $userProxy = $this->_em->getReference(CmsUser::class, $userId); $this->_em->remove($userProxy); $this->_em->flush(); @@ -76,7 +76,7 @@ public function testOrphanRemovalWhenUnlink() $this->_em->clear(); - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $userId); + $user = $this->_em->find(CmsUser::class, $userId); $user->setEmail(null); diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php index bc7897f6a54..0011e8c8c40 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php @@ -2,9 +2,10 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\Tests\Models\ECommerce\ECommerceCustomer; use Doctrine\ORM\Mapping\AssociationMapping; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Proxy\Proxy; +use Doctrine\Tests\Models\ECommerce\ECommerceCustomer; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -52,8 +53,8 @@ public function testFind() { $id = $this->_createFixture(); - $customer = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceCustomer', $id); - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $customer->getMentor()); + $customer = $this->_em->find(ECommerceCustomer::class, $id); + $this->assertNotInstanceOf(Proxy::class, $customer->getMentor()); } public function testEagerLoadsAssociation() @@ -74,7 +75,7 @@ public function testLazyLoadsAssociation() { $this->_createFixture(); - $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceCustomer'); + $metadata = $this->_em->getClassMetadata(ECommerceCustomer::class); $metadata->associationMappings['mentor']['fetch'] = ClassMetadata::FETCH_LAZY; $query = $this->_em->createQuery("select c from Doctrine\Tests\Models\ECommerce\ECommerceCustomer c where c.name='Luke Skywalker'"); @@ -88,7 +89,7 @@ public function testMultiSelfReference() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\MultiSelfReference') + $this->_em->getClassMetadata(MultiSelfReference::class) ] ); } catch (\Exception $e) { @@ -105,8 +106,8 @@ public function testMultiSelfReference() $entity2 = $this->_em->find(get_class($entity1), $entity1->getId()); - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\MultiSelfReference', $entity2->getOther1()); - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\MultiSelfReference', $entity2->getOther2()); + $this->assertInstanceOf(MultiSelfReference::class, $entity2->getOther1()); + $this->assertInstanceOf(MultiSelfReference::class, $entity2->getOther2()); $this->assertNull($entity2->getOther1()->getOther1()); $this->assertNull($entity2->getOther1()->getOther2()); $this->assertNull($entity2->getOther2()->getOther1()); @@ -115,7 +116,7 @@ public function testMultiSelfReference() public function assertLoadingOfAssociation($customer) { - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCustomer', $customer->getMentor()); + $this->assertInstanceOf(ECommerceCustomer::class, $customer->getMentor()); $this->assertEquals('Obi-wan Kenobi', $customer->getMentor()->getName()); } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneSingleTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneSingleTableInheritanceTest.php index b677df624d1..3e9a291f00b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneSingleTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneSingleTableInheritanceTest.php @@ -15,9 +15,9 @@ protected function setUp() parent::setUp(); $this->_schemaTool->createSchema([ - $this->_em->getClassMetadata(Pet::CLASSNAME), - $this->_em->getClassMetadata(Cat::CLASSNAME), - $this->_em->getClassMetadata(LitterBox::CLASSNAME), + $this->_em->getClassMetadata(Pet::class), + $this->_em->getClassMetadata(Cat::class), + $this->_em->getClassMetadata(LitterBox::class), ]); } @@ -38,11 +38,11 @@ public function testFindFromOneToOneOwningSideJoinedTableInheritance() $this->_em->clear(); /* @var $foundCat Cat */ - $foundCat = $this->_em->find(Pet::CLASSNAME, $cat->id); + $foundCat = $this->_em->find(Pet::class, $cat->id); - $this->assertInstanceOf(Cat::CLASSNAME, $foundCat); + $this->assertInstanceOf(Cat::class, $foundCat); $this->assertSame($cat->id, $foundCat->id); - $this->assertInstanceOf(LitterBox::CLASSNAME, $foundCat->litterBox); + $this->assertInstanceOf(LitterBox::class, $foundCat->litterBox); $this->assertSame($cat->litterBox->id, $foundCat->litterBox->id); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php index 2ffbfa44330..797a38517d0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php @@ -2,11 +2,11 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\Tests\Models\ECommerce\ECommerceProduct; -use Doctrine\Tests\Models\ECommerce\ECommerceShipping; use Doctrine\ORM\Mapping\AssociationMapping; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Query; +use Doctrine\Tests\Models\ECommerce\ECommerceProduct; +use Doctrine\Tests\Models\ECommerce\ECommerceShipping; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -55,20 +55,20 @@ public function _testEagerLoad() $result = $query->getResult(); $product = $result[0]; - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceShipping', $product->getShipping()); + $this->assertInstanceOf(ECommerceShipping::class, $product->getShipping()); $this->assertEquals(1, $product->getShipping()->getDays()); } public function testLazyLoadsObjects() { $this->_createFixture(); - $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceProduct'); + $metadata = $this->_em->getClassMetadata(ECommerceProduct::class); $metadata->associationMappings['shipping']['fetch'] = ClassMetadata::FETCH_LAZY; $query = $this->_em->createQuery('select p from Doctrine\Tests\Models\ECommerce\ECommerceProduct p'); $result = $query->getResult(); $product = $result[0]; - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceShipping', $product->getShipping()); + $this->assertInstanceOf(ECommerceShipping::class, $product->getShipping()); $this->assertEquals(1, $product->getShipping()->getDays()); } diff --git a/tests/Doctrine/Tests/ORM/Functional/OrderedCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/OrderedCollectionTest.php index 5d5c54e24e4..aa4fb1da0f6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OrderedCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OrderedCollectionTest.php @@ -2,9 +2,9 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\Tests\Models\Routing\RoutingRoute; -use Doctrine\Tests\Models\Routing\RoutingLocation; use Doctrine\Tests\Models\Routing\RoutingLeg; +use Doctrine\Tests\Models\Routing\RoutingLocation; +use Doctrine\Tests\Models\Routing\RoutingRoute; use Doctrine\Tests\Models\Routing\RoutingRouteBooking; use Doctrine\Tests\OrmFunctionalTestCase; @@ -59,7 +59,7 @@ public function testLazyManyToManyCollection_IsRetrievedWithOrderByClause() { $routeId = $this->createPersistedRouteWithLegs(); - $route = $this->_em->find('Doctrine\Tests\Models\Routing\RoutingRoute', $routeId); + $route = $this->_em->find(RoutingRoute::class, $routeId); $this->assertEquals(2, count($route->legs)); $this->assertEquals("Berlin", $route->legs[0]->fromLocation->getName()); @@ -90,7 +90,7 @@ public function testLazyOneToManyCollection_IsRetrievedWithOrderByClause() $this->_em->flush(); $this->_em->clear(); - $route = $this->_em->find('Doctrine\Tests\Models\Routing\RoutingRoute', $routeId); + $route = $this->_em->find(RoutingRoute::class, $routeId); $this->assertEquals(2, count($route->bookings)); $this->assertEquals('Benjamin', $route->bookings[0]->getPassengerName()); diff --git a/tests/Doctrine/Tests/ORM/Functional/OrderedJoinedTableInheritanceCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/OrderedJoinedTableInheritanceCollectionTest.php index d71bfb0b4c8..30531bae98d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OrderedJoinedTableInheritanceCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OrderedJoinedTableInheritanceCollectionTest.php @@ -18,9 +18,9 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\OJTIC_Pet'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\OJTIC_Cat'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\OJTIC_Dog'), + $this->_em->getClassMetadata(OJTIC_Pet::class), + $this->_em->getClassMetadata(OJTIC_Cat::class), + $this->_em->getClassMetadata(OJTIC_Dog::class), ] ); } catch (\Exception $e) { diff --git a/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php b/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php index dcf44ce4565..58a88dbd764 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php @@ -3,11 +3,11 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\ORM\Query; +use Doctrine\ORM\Tools\Pagination\Paginator; use Doctrine\Tests\Models\CMS\CmsArticle; use Doctrine\Tests\Models\CMS\CmsEmail; -use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\CMS\CmsGroup; -use Doctrine\ORM\Tools\Pagination\Paginator; +use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\Company\CompanyManager; use Doctrine\Tests\Models\Pagination\Company; use Doctrine\Tests\Models\Pagination\Department; @@ -595,7 +595,7 @@ public function testDetectOutputWalker() // If the Paginator detects the custom output walker it should fall back to using the // Tree walkers for pagination, which leads to an exception. If the query works, the output walkers were used - $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Query\SqlWalker'); + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, Query\SqlWalker::class); $paginator = new Paginator($query); $this->expectException(\RuntimeException::class); @@ -633,8 +633,7 @@ public function testQueryWalkerIsKept() { $dql = 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u'; $query = $this->_em->createQuery($dql); - $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\Tests\ORM\Functional\CustomPaginationTestTreeWalker'] - ); + $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [CustomPaginationTestTreeWalker::class]); $paginator = new Paginator($query, true); $paginator->setUseOutputWalkers(false); @@ -662,7 +661,7 @@ public function testCountQueryStripsParametersInSelect() $this->assertCount(2, $getCountQuery->invoke($paginator)->getParameters()); $this->assertCount(9, $paginator); - $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Query\SqlWalker'); + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, Query\SqlWalker::class); $paginator = new Paginator($query); diff --git a/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php b/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php index 99a04d52b6c..a02f4091a15 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php @@ -3,9 +3,11 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Common\Collections\Criteria; +use Doctrine\ORM\LazyCriteriaCollection; use Doctrine\Tests\Models\Quote\Group; use Doctrine\Tests\Models\Quote\User as QuoteUser; use Doctrine\Tests\Models\Tweet\Tweet; +use Doctrine\Tests\Models\Tweet\User; use Doctrine\Tests\Models\Tweet\User as TweetUser; use Doctrine\Tests\OrmFunctionalTestCase; @@ -73,12 +75,12 @@ public function testCanCountWithoutLoadingPersistentCollection() { $this->loadTweetFixture(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\Tweet\User'); + $repository = $this->_em->getRepository(User::class); $user = $repository->findOneBy(['name' => 'ngal']); $tweets = $user->tweets->matching(new Criteria()); - $this->assertInstanceOf('Doctrine\ORM\LazyCriteriaCollection', $tweets); + $this->assertInstanceOf(LazyCriteriaCollection::class, $tweets); $this->assertFalse($tweets->isInitialized()); $this->assertCount(2, $tweets); $this->assertFalse($tweets->isInitialized()); @@ -88,7 +90,7 @@ public function testCanCountWithoutLoadingPersistentCollection() Criteria::expr()->eq('content', 'Foo') )); - $this->assertInstanceOf('Doctrine\ORM\LazyCriteriaCollection', $tweets); + $this->assertInstanceOf(LazyCriteriaCollection::class, $tweets); $this->assertFalse($tweets->isInitialized()); $this->assertCount(1, $tweets); $this->assertFalse($tweets->isInitialized()); diff --git a/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php index 3eac4263cee..b1751455f34 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php @@ -15,8 +15,8 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\PersistentCollectionHolder'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\PersistentCollectionContent'), + $this->_em->getClassMetadata(PersistentCollectionHolder::class), + $this->_em->getClassMetadata(PersistentCollectionContent::class), ] ); } catch (\Exception $e) { @@ -35,7 +35,7 @@ public function testPersist() $this->_em->flush(); $this->_em->clear(); - $collectionHolder = $this->_em->find(__NAMESPACE__ . '\PersistentCollectionHolder', $collectionHolder->getId()); + $collectionHolder = $this->_em->find(PersistentCollectionHolder::class, $collectionHolder->getId()); $collectionHolder->getCollection(); $content = new PersistentCollectionContent('second element'); @@ -55,7 +55,7 @@ public function testExtraLazyIsEmptyDoesNotInitializeCollection() $this->_em->flush(); $this->_em->clear(); - $collectionHolder = $this->_em->find(__NAMESPACE__ . '\PersistentCollectionHolder', $collectionHolder->getId()); + $collectionHolder = $this->_em->find(PersistentCollectionHolder::class, $collectionHolder->getId()); $collection = $collectionHolder->getRawCollection(); $this->assertTrue($collection->isEmpty()); @@ -66,7 +66,7 @@ public function testExtraLazyIsEmptyDoesNotInitializeCollection() $this->_em->flush(); $this->_em->clear(); - $collectionHolder = $this->_em->find(__NAMESPACE__ . '\PersistentCollectionHolder', $collectionHolder->getId()); + $collectionHolder = $this->_em->find(PersistentCollectionHolder::class, $collectionHolder->getId()); $collection = $collectionHolder->getRawCollection(); $this->assertFalse($collection->isEmpty()); @@ -87,7 +87,7 @@ public function testMatchingDoesNotModifyTheGivenCriteria() $criteria = new Criteria(); - $collectionHolder = $this->_em->find(__NAMESPACE__ . '\PersistentCollectionHolder', $collectionHolder->getId()); + $collectionHolder = $this->_em->find(PersistentCollectionHolder::class, $collectionHolder->getId()); $collectionHolder->getCollection()->matching($criteria); $this->assertEmpty($criteria->getWhereExpression()); diff --git a/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php b/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php index 459c0549c3e..9f73bf5e8e4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php @@ -19,7 +19,7 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\PersistentEntity'), + $this->_em->getClassMetadata(PersistentEntity::class), ] ); } catch (\Exception $e) { @@ -46,7 +46,7 @@ public function testFind() $this->_em->flush(); $this->_em->clear(); - $entity = $this->_em->find(__NAMESPACE__ . '\PersistentEntity', $entity->getId()); + $entity = $this->_em->find(PersistentEntity::class, $entity->getId()); $this->assertEquals('test', $entity->getName()); $entity->setName('foobar'); @@ -63,7 +63,7 @@ public function testGetReference() $this->_em->flush(); $this->_em->clear(); - $entity = $this->_em->getReference(__NAMESPACE__ . '\PersistentEntity', $entity->getId()); + $entity = $this->_em->getReference(PersistentEntity::class, $entity->getId()); $this->assertEquals('test', $entity->getName()); } @@ -78,7 +78,7 @@ public function testSetAssociation() $this->_em->flush(); $this->_em->clear(); - $entity = $this->_em->getReference(__NAMESPACE__ . '\PersistentEntity', $entity->getId()); + $entity = $this->_em->getReference(PersistentEntity::class, $entity->getId()); $this->assertSame($entity, $entity->getParent()); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/PostLoadEventTest.php b/tests/Doctrine/Tests/ORM/Functional/PostLoadEventTest.php index 0debc2ca6c8..02a08666673 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PostLoadEventTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PostLoadEventTest.php @@ -2,12 +2,12 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Common\Util\ClassUtils; -use Doctrine\Tests\Models\CMS\CmsUser; -use Doctrine\Tests\Models\CMS\CmsPhonenumber; -use Doctrine\Tests\Models\CMS\CmsAddress; -use Doctrine\Tests\Models\CMS\CmsEmail; use Doctrine\ORM\Event\LifecycleEventArgs; use Doctrine\ORM\Events; +use Doctrine\Tests\Models\CMS\CmsAddress; +use Doctrine\Tests\Models\CMS\CmsEmail; +use Doctrine\Tests\Models\CMS\CmsPhonenumber; +use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -48,7 +48,7 @@ public function testLoadedEntityUsingFindShouldTriggerEvent() $eventManager->addEventListener([Events::postLoad], $mockListener); - $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $this->_em->find(CmsUser::class, $this->userId); } public function testLoadedEntityUsingQueryShouldTriggerEvent() @@ -125,7 +125,7 @@ public function testLoadedProxyEntityShouldTriggerEvent() $eventManager->addEventListener([Events::postLoad], $mockListener); - $userProxy = $this->_em->getReference('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $userProxy = $this->_em->getReference(CmsUser::class, $this->userId); // Now deactivate original listener and attach new one $eventManager->removeEventListener([Events::postLoad], $mockListener); @@ -165,7 +165,7 @@ public function testLoadedProxyPartialShouldTriggerEvent() public function testLoadedProxyAssociationToOneShouldTriggerEvent() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $mockListener = $this->createMock(PostLoadListener::class); @@ -186,7 +186,7 @@ public function testLoadedProxyAssociationToOneShouldTriggerEvent() public function testLoadedProxyAssociationToManyShouldTriggerEvent() { - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $mockListener = $this->createMock(PostLoadListener::class); @@ -213,7 +213,7 @@ public function testAssociationsArePopulatedWhenEventIsFired() $checkerListener = new PostLoadListenerCheckAssociationsArePopulated(); $this->_em->getEventManager()->addEventListener([Events::postLoad], $checkerListener); - $qb = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->createQueryBuilder('u'); + $qb = $this->_em->getRepository(CmsUser::class)->createQueryBuilder('u'); $qb->leftJoin('u.email', 'email'); $qb->addSelect('email'); $qb->getQuery()->getSingleResult(); @@ -231,9 +231,9 @@ public function testEventRaisedCorrectTimesWhenOtherEntityLoadedInEventHandler() $listener = new PostLoadListenerLoadEntityInEventHandler(); $eventManager->addEventListener([Events::postLoad], $listener); - $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); - $this->assertSame(1, $listener->countHandledEvents('Doctrine\Tests\Models\CMS\CmsUser'), 'Doctrine\Tests\Models\CMS\CmsUser should be handled once!'); - $this->assertSame(1, $listener->countHandledEvents('Doctrine\Tests\Models\CMS\CmsEmail'), '\Doctrine\Tests\Models\CMS\CmsEmail should be handled once!'); + $this->_em->find(CmsUser::class, $this->userId); + $this->assertSame(1, $listener->countHandledEvents(CmsUser::class), CmsUser::class . ' should be handled once!'); + $this->assertSame(1, $listener->countHandledEvents(CmsEmail::class), CmsEmail::class . ' should be handled once!'); } private function loadFixture() diff --git a/tests/Doctrine/Tests/ORM/Functional/ProxiesLikeEntitiesTest.php b/tests/Doctrine/Tests/ORM/Functional/ProxiesLikeEntitiesTest.php index 7d9fbce9d0f..c88eff4ab70 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ProxiesLikeEntitiesTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ProxiesLikeEntitiesTest.php @@ -2,8 +2,15 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\Tests\Models\CMS\CmsAddress; +use Doctrine\Tests\Models\CMS\CmsArticle; +use Doctrine\Tests\Models\CMS\CmsEmail; +use Doctrine\Tests\Models\CMS\CmsGroup; +use Doctrine\Tests\Models\CMS\CmsPhonenumber; +use Doctrine\Tests\Models\CMS\CmsTag; use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\OrmFunctionalTestCase; +use Doctrine\Tests\Proxies\__CG__\Doctrine\Tests\Models\CMS\CmsUser as CmsUserProxy; /** * Test that Doctrine ORM correctly works with proxy instances exactly like with ordinary Entities @@ -26,12 +33,13 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsArticle'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsEmail'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsGroup'), + $this->_em->getClassMetadata(CmsUser::class), + $this->_em->getClassMetadata(CmsTag::class), + $this->_em->getClassMetadata(CmsPhonenumber::class), + $this->_em->getClassMetadata(CmsArticle::class), + $this->_em->getClassMetadata(CmsAddress::class), + $this->_em->getClassMetadata(CmsEmail::class), + $this->_em->getClassMetadata(CmsGroup::class), ] ); } catch (\Exception $e) { @@ -50,7 +58,7 @@ protected function setUp() public function testPersistUpdate() { // Considering case (a) - $proxy = $this->_em->getProxyFactory()->getProxy('Doctrine\Tests\Models\CMS\CmsUser', ['id' => 123]); + $proxy = $this->_em->getProxyFactory()->getProxy(CmsUser::class, ['id' => 123]); $proxy->__isInitialized__ = true; $proxy->id = null; $proxy->username = 'ocra'; @@ -59,12 +67,10 @@ public function testPersistUpdate() $this->_em->flush(); $this->assertNotNull($proxy->getId()); $proxy->name = 'Marco Pivetta'; - $this - ->_em - ->getUnitOfWork() - ->computeChangeSet($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), $proxy); + $this->_em->getUnitOfWork() + ->computeChangeSet($this->_em->getClassMetadata(CmsUser::class), $proxy); $this->assertNotEmpty($this->_em->getUnitOfWork()->getEntityChangeSet($proxy)); - $this->assertEquals('Marco Pivetta', $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $proxy->getId())->name); + $this->assertEquals('Marco Pivetta', $this->_em->find(CmsUser::class, $proxy->getId())->name); $this->_em->remove($proxy); $this->_em->flush(); } @@ -72,9 +78,9 @@ public function testPersistUpdate() public function testEntityWithIdentifier() { $userId = $this->user->getId(); - /* @var $uninitializedProxy \Doctrine\Tests\Proxies\__CG__\Doctrine\Tests\Models\CMS\CmsUser */ - $uninitializedProxy = $this->_em->getReference('Doctrine\Tests\Models\CMS\CmsUser', $userId); - $this->assertInstanceOf('Doctrine\Tests\Proxies\__CG__\Doctrine\Tests\Models\CMS\CmsUser', $uninitializedProxy); + /* @var $uninitializedProxy CmsUserProxy */ + $uninitializedProxy = $this->_em->getReference(CmsUser::class, $userId); + $this->assertInstanceOf(CmsUserProxy::class, $uninitializedProxy); $this->_em->persist($uninitializedProxy); $this->_em->flush($uninitializedProxy); @@ -89,7 +95,7 @@ public function testEntityWithIdentifier() */ public function testProxyAsDqlParameterPersist() { - $proxy = $this->_em->getProxyFactory()->getProxy('Doctrine\Tests\Models\CMS\CmsUser', ['id' => $this->user->getId()] + $proxy = $this->_em->getProxyFactory()->getProxy(CmsUser::class, ['id' => $this->user->getId()] ); $proxy->id = $this->user->getId(); $result = $this @@ -107,27 +113,23 @@ public function testProxyAsDqlParameterPersist() */ public function testFindWithProxyName() { - $result = $this - ->_em - ->find('Doctrine\Tests\Proxies\__CG__\Doctrine\Tests\Models\CMS\CmsUser', $this->user->getId()); + $result = $this->_em->find(CmsUserProxy::class, $this->user->getId()); $this->assertSame($this->user->getId(), $result->getId()); $this->_em->clear(); - $result = $this - ->_em - ->getReference('Doctrine\Tests\Proxies\__CG__\Doctrine\Tests\Models\CMS\CmsUser', $this->user->getId()); + + $result = $this->_em->getReference(CmsUserProxy::class, $this->user->getId()); $this->assertSame($this->user->getId(), $result->getId()); $this->_em->clear(); - $result = $this - ->_em - ->getRepository('Doctrine\Tests\Proxies\__CG__\Doctrine\Tests\Models\CMS\CmsUser') - ->findOneBy(['username' => $this->user->username]); + + $result = $this->_em->getRepository(CmsUserProxy::class)->findOneBy(['username' => $this->user->username]); $this->assertSame($this->user->getId(), $result->getId()); $this->_em->clear(); - $result = $this - ->_em + + $result = $this->_em ->createQuery('SELECT u FROM Doctrine\Tests\Proxies\__CG__\Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1') ->setParameter(1, $this->user->getId()) ->getSingleResult(); + $this->assertSame($this->user->getId(), $result->getId()); $this->_em->clear(); } diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php index 6eec3609fa3..a307ad13786 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php @@ -23,7 +23,7 @@ class QueryCacheTest extends OrmFunctionalTestCase protected function setUp() { - $this->cacheDataReflection = new \ReflectionProperty("Doctrine\Common\Cache\ArrayCache", "data"); + $this->cacheDataReflection = new \ReflectionProperty(ArrayCache::class, "data"); $this->cacheDataReflection->setAccessible(true); $this->useModelSet('cms'); @@ -116,7 +116,7 @@ public function testQueryCache_NoHitSaveParserResult() $cache ->expects(self::once()) ->method('save') - ->with(self::isType('string'), self::isInstanceOf('Doctrine\ORM\Query\ParserResult')); + ->with(self::isType('string'), self::isInstanceOf(ParserResult::class)); $query->getResult(); } @@ -151,6 +151,7 @@ public function testQueryCache_HitDoesNotSaveParserResult() ->method('doFetch') ->with($this->isType('string')) ->will($this->returnValue($parserResultMock)); + $cache->expects($this->never()) ->method('doSave'); diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php index 8d0ad2d8dc1..805478bdfc7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php @@ -5,6 +5,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\NonUniqueResultException; +use Doctrine\ORM\Proxy\Proxy; use Doctrine\ORM\Query\QueryException; use Doctrine\ORM\UnexpectedResultException; use Doctrine\Tests\Models\CMS\CmsUser, @@ -43,7 +44,7 @@ public function testSimpleQueries() $result = $query->getResult(); $this->assertEquals(1, count($result)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0][0]); + $this->assertInstanceOf(CmsUser::class, $result[0][0]); $this->assertEquals('Guilherme', $result[0][0]->name); $this->assertEquals('gblanco', $result[0][0]->username); $this->assertEquals('developer', $result[0][0]->status); @@ -95,7 +96,7 @@ public function testJoinQueries() $query = $this->_em->createQuery("select u, a from Doctrine\Tests\Models\CMS\CmsUser u join u.articles a ORDER BY a.topic"); $users = $query->getResult(); $this->assertEquals(1, count($users)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[0]); + $this->assertInstanceOf(CmsUser::class, $users[0]); $this->assertEquals(2, count($users[0]->articles)); $this->assertEquals('Doctrine 2', $users[0]->articles[0]->topic); $this->assertEquals('Symfony 2', $users[0]->articles[1]->topic); @@ -239,7 +240,7 @@ public function testIterateResult_IterativelyBuildUpUnitOfWork() $topics[] = $article->topic; $identityMap = $this->_em->getUnitOfWork()->getIdentityMap(); - $identityMapCount = count($identityMap['Doctrine\Tests\Models\CMS\CmsArticle']); + $identityMapCount = count($identityMap[CmsArticle::class]); $this->assertTrue($identityMapCount>$iteratedCount); $iteratedCount++; @@ -417,14 +418,14 @@ public function testEntityParameters() $this->_em->clear(); //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); $q = $this->_em->createQuery("select a from Doctrine\Tests\Models\CMS\CmsArticle a where a.topic = :topic and a.user = :user") - ->setParameter("user", $this->_em->getReference('Doctrine\Tests\Models\CMS\CmsUser', $author->id)) + ->setParameter("user", $this->_em->getReference(CmsUser::class, $author->id)) ->setParameter("topic", "dr. dolittle"); $result = $q->getResult(); $this->assertEquals(1, count($result)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[0]); + $this->assertInstanceOf(CmsArticle::class, $result[0]); $this->assertEquals("dr. dolittle", $result[0]->topic); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $result[0]->user); + $this->assertInstanceOf(Proxy::class, $result[0]->user); $this->assertFalse($result[0]->user->__isInitialized__); } @@ -449,12 +450,12 @@ public function testEnableFetchEagerMode() $this->_em->clear(); $articles = $this->_em->createQuery('select a from Doctrine\Tests\Models\CMS\CmsArticle a') - ->setFetchMode('Doctrine\Tests\Models\CMS\CmsArticle', 'user', ClassMetadata::FETCH_EAGER) + ->setFetchMode(CmsArticle::class, 'user', ClassMetadata::FETCH_EAGER) ->getResult(); $this->assertEquals(10, count($articles)); foreach ($articles AS $article) { - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $article); + $this->assertNotInstanceOf(Proxy::class, $article); } } @@ -474,7 +475,7 @@ public function testgetOneOrNullResult() $query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = 'gblanco'"); $fetchedUser = $query->getOneOrNullResult(); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $fetchedUser); + $this->assertInstanceOf(CmsUser::class, $fetchedUser); $this->assertEquals('gblanco', $fetchedUser->username); $query = $this->_em->createQuery("select u.username from Doctrine\Tests\Models\CMS\CmsUser u where u.username = 'gblanco'"); @@ -592,7 +593,7 @@ public function testQueryBuilderWithStringWhereClauseContainingOrAndConditionalP { $qb = $this->_em->createQueryBuilder(); $qb->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->innerJoin('u.articles', 'a') ->where('(u.id = 0) OR (u.id IS NULL)'); @@ -661,7 +662,7 @@ public function testQueryWithHiddenAsSelectExpression() $users = $query->execute(); $this->assertEquals(3, count($users)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[0]); + $this->assertInstanceOf(CmsUser::class, $users[0]); } /** @@ -724,9 +725,9 @@ public function testSetCollectionParameterBindingSingleIdentifierObject() $users = $q->execute(); $this->assertEquals(3, count($users)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[2]); + $this->assertInstanceOf(CmsUser::class, $users[0]); + $this->assertInstanceOf(CmsUser::class, $users[1]); + $this->assertInstanceOf(CmsUser::class, $users[2]); $resultUser1 = $users[0]; $resultUser2 = $users[1]; @@ -802,8 +803,8 @@ public function testMultipleJoinComponentsUsingInnerJoin() $users = $query->execute(); $this->assertEquals(2, count($users)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsPhonenumber', $users[1]); + $this->assertInstanceOf(CmsUser::class, $users[0]); + $this->assertInstanceOf(CmsPhonenumber::class, $users[1]); } public function testMultipleJoinComponentsUsingLeftJoin() @@ -835,9 +836,9 @@ public function testMultipleJoinComponentsUsingLeftJoin() $users = $query->execute(); $this->assertEquals(4, count($users)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsPhonenumber', $users[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[2]); + $this->assertInstanceOf(CmsUser::class, $users[0]); + $this->assertInstanceOf(CmsPhonenumber::class, $users[1]); + $this->assertInstanceOf(CmsUser::class, $users[2]); $this->assertNull($users[3]); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/ReadOnlyTest.php b/tests/Doctrine/Tests/ORM/Functional/ReadOnlyTest.php index 9eacc7a9c3c..a664a4df252 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ReadOnlyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ReadOnlyTest.php @@ -1,6 +1,7 @@ _schemaTool->createSchema( [ - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\ReadOnlyEntity'), + $this->_em->getClassMetadata(ReadOnlyEntity::class), ] ); } catch(\Exception $e) { @@ -36,7 +37,7 @@ public function testReadOnlyEntityNeverChangeTracked() $this->_em->flush(); $this->_em->clear(); - $dbReadOnly = $this->_em->find('Doctrine\Tests\ORM\Functional\ReadOnlyEntity', $readOnly->id); + $dbReadOnly = $this->_em->find(ReadOnlyEntity::class, $readOnly->id); $this->assertEquals("Test1", $dbReadOnly->name); $this->assertEquals(1234, $dbReadOnly->numericValue); } diff --git a/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php b/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php index b7116a3cd7c..5e1cb2fb223 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php @@ -2,12 +2,12 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\Common\Persistence\Proxy; use Doctrine\Common\Util\ClassUtils; use Doctrine\ORM\Proxy\ProxyFactory; -use Doctrine\ORM\Proxy\ProxyClassGenerator; +use Doctrine\Tests\Models\Company\CompanyAuction; use Doctrine\Tests\Models\ECommerce\ECommerceProduct; use Doctrine\Tests\Models\ECommerce\ECommerceShipping; -use Doctrine\Tests\Models\Company\CompanyAuction; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -57,7 +57,7 @@ public function testLazyLoadsFieldValuesFromDatabase() { $id = $this->createProduct(); - $productProxy = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct', ['id' => $id]); + $productProxy = $this->_em->getReference(ECommerceProduct::class, ['id' => $id]); $this->assertEquals('Doctrine Cookbook', $productProxy->getName()); } @@ -68,10 +68,10 @@ public function testAccessMetatadaForProxy() { $id = $this->createProduct(); - $entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id); + $entity = $this->_em->getReference(ECommerceProduct::class , $id); $class = $this->_em->getClassMetadata(get_class($entity)); - $this->assertEquals('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $class->name); + $this->assertEquals(ECommerceProduct::class, $class->name); } /** @@ -81,8 +81,8 @@ public function testReferenceFind() { $id = $this->createProduct(); - $entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id); - $entity2 = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id); + $entity = $this->_em->getReference(ECommerceProduct::class , $id); + $entity2 = $this->_em->find(ECommerceProduct::class , $id); $this->assertSame($entity, $entity2); $this->assertEquals('Doctrine Cookbook', $entity2->getName()); @@ -95,10 +95,10 @@ public function testCloneProxy() { $id = $this->createProduct(); - /* @var $entity Doctrine\Tests\Models\ECommerce\ECommerceProduct */ - $entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id); + /* @var $entity ECommerceProduct */ + $entity = $this->_em->getReference(ECommerceProduct::class , $id); - /* @var $clone Doctrine\Tests\Models\ECommerce\ECommerceProduct */ + /* @var $clone ECommerceProduct */ $clone = clone $entity; $this->assertEquals($id, $entity->getId()); @@ -120,8 +120,8 @@ public function testInitializeProxy() { $id = $this->createProduct(); - /* @var $entity Doctrine\Tests\Models\ECommerce\ECommerceProduct */ - $entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id); + /* @var $entity ECommerceProduct */ + $entity = $this->_em->getReference(ECommerceProduct::class , $id); $this->assertFalse($entity->__isInitialized__, "Pre-Condition: Object is unitialized proxy."); $this->_em->getUnitOfWork()->initializeObject($entity); @@ -135,14 +135,14 @@ public function testInitializeChangeAndFlushProxy() { $id = $this->createProduct(); - /* @var $entity Doctrine\Tests\Models\ECommerce\ECommerceProduct */ - $entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id); + /* @var $entity ECommerceProduct */ + $entity = $this->_em->getReference(ECommerceProduct::class , $id); $entity->setName('Doctrine 2 Cookbook'); $this->_em->flush(); $this->_em->clear(); - $entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id); + $entity = $this->_em->getReference(ECommerceProduct::class , $id); $this->assertEquals('Doctrine 2 Cookbook', $entity->getName()); } @@ -153,8 +153,8 @@ public function testWakeupCalledOnProxy() { $id = $this->createProduct(); - /* @var $entity Doctrine\Tests\Models\ECommerce\ECommerceProduct */ - $entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id); + /* @var $entity ECommerceProduct */ + $entity = $this->_em->getReference(ECommerceProduct::class , $id); $this->assertFalse($entity->wakeUp); @@ -167,8 +167,8 @@ public function testDoNotInitializeProxyOnGettingTheIdentifier() { $id = $this->createProduct(); - /* @var $entity Doctrine\Tests\Models\ECommerce\ECommerceProduct */ - $entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id); + /* @var $entity ECommerceProduct */ + $entity = $this->_em->getReference(ECommerceProduct::class , $id); $this->assertFalse($entity->__isInitialized__, "Pre-Condition: Object is unitialized proxy."); $this->assertEquals($id, $entity->getId()); @@ -182,8 +182,8 @@ public function testDoNotInitializeProxyOnGettingTheIdentifier_DDC_1625() { $id = $this->createAuction(); - /* @var $entity Doctrine\Tests\Models\Company\CompanyAuction */ - $entity = $this->_em->getReference('Doctrine\Tests\Models\Company\CompanyAuction' , $id); + /* @var $entity CompanyAuction */ + $entity = $this->_em->getReference(CompanyAuction::class , $id); $this->assertFalse($entity->__isInitialized__, "Pre-Condition: Object is unitialized proxy."); $this->assertEquals($id, $entity->getId()); @@ -204,7 +204,7 @@ public function testDoNotInitializeProxyOnGettingTheIdentifierAndReturnTheRightT $id = $shipping->getId(); - $product = $this->_em->getRepository('Doctrine\Tests\Models\ECommerce\ECommerceProduct')->find($product->getId()); + $product = $this->_em->getRepository(ECommerceProduct::class)->find($product->getId()); $entity = $product->getShipping(); $this->assertFalse($entity->__isInitialized__, "Pre-Condition: Object is unitialized proxy."); @@ -217,8 +217,8 @@ public function testInitializeProxyOnGettingSomethingOtherThanTheIdentifier() { $id = $this->createProduct(); - /* @var $entity Doctrine\Tests\Models\ECommerce\ECommerceProduct */ - $entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id); + /* @var $entity ECommerceProduct */ + $entity = $this->_em->getReference(ECommerceProduct::class , $id); $this->assertFalse($entity->__isInitialized__, "Pre-Condition: Object is unitialized proxy."); $this->assertEquals('Doctrine Cookbook', $entity->getName()); @@ -233,12 +233,12 @@ public function testCommonPersistenceProxy() $id = $this->createProduct(); /* @var $entity ECommerceProduct */ - $entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id); + $entity = $this->_em->getReference(ECommerceProduct::class , $id); $className = ClassUtils::getClass($entity); - $this->assertInstanceOf('Doctrine\Common\Persistence\Proxy', $entity); + $this->assertInstanceOf(Proxy::class, $entity); $this->assertFalse($entity->__isInitialized()); - $this->assertEquals('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $className); + $this->assertEquals(ECommerceProduct::class, $className); $restName = str_replace($this->_em->getConfiguration()->getProxyNamespace(), "", get_class($entity)); $restName = substr(get_class($entity), strlen($this->_em->getConfiguration()->getProxyNamespace()) +1); diff --git a/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php index e1bd93ed792..bfadf2c2543 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php @@ -22,7 +22,7 @@ class ResultCacheTest extends OrmFunctionalTestCase private $cacheDataReflection; protected function setUp() { - $this->cacheDataReflection = new \ReflectionProperty("Doctrine\Common\Cache\ArrayCache", "data"); + $this->cacheDataReflection = new \ReflectionProperty(ArrayCache::class, "data"); $this->cacheDataReflection->setAccessible(true); $this->useModelSet('cms'); parent::setUp(); diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index 42db029060d..c35036b6e3c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -2,26 +2,27 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\Common\Cache\ArrayCache; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\ORM\Configuration; -use Doctrine\ORM\Query\Filter\SQLFilter; +use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\ClassMetadata; -use Doctrine\Common\Cache\ArrayCache; - use Doctrine\ORM\Mapping\ClassMetadataInfo; - -use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\ORM\Query\Filter\SQLFilter; +use Doctrine\ORM\Query\FilterCollection; use Doctrine\Tests\Models\CMS\CmsAddress; -use Doctrine\Tests\Models\CMS\CmsGroup; use Doctrine\Tests\Models\CMS\CmsArticle; - -use Doctrine\Tests\Models\Company\CompanyPerson; -use Doctrine\Tests\Models\Company\CompanyManager; -use Doctrine\Tests\Models\Company\CompanyOrganization; +use Doctrine\Tests\Models\CMS\CmsGroup; +use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\Company\CompanyAuction; - +use Doctrine\Tests\Models\Company\CompanyContract; +use Doctrine\Tests\Models\Company\CompanyEvent; use Doctrine\Tests\Models\Company\CompanyFlexContract; use Doctrine\Tests\Models\Company\CompanyFlexUltraContract; +use Doctrine\Tests\Models\Company\CompanyManager; +use Doctrine\Tests\Models\Company\CompanyOrganization; +use Doctrine\Tests\Models\Company\CompanyPerson; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -49,7 +50,7 @@ public function tearDown() { parent::tearDown(); - $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $class = $this->_em->getClassMetadata(CmsUser::class); $class->associationMappings['groups']['fetch'] = ClassMetadataInfo::FETCH_LAZY; $class->associationMappings['articles']['fetch'] = ClassMetadataInfo::FETCH_LAZY; } @@ -186,7 +187,7 @@ protected function configureFilters($em) protected function getMockConnection() { // Setup connection mock - $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') + $conn = $this->getMockBuilder(Connection::class) ->disableOriginalConstructor() ->getMock(); @@ -196,7 +197,7 @@ protected function getMockConnection() protected function getMockEntityManager() { // Setup connection mock - $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + $em = $this->getMockBuilder(EntityManager::class) ->disableOriginalConstructor() ->getMock(); @@ -205,7 +206,7 @@ protected function getMockEntityManager() protected function addMockFilterCollection($em) { - $filterCollection = $this->getMockBuilder('Doctrine\ORM\Query\FilterCollection') + $filterCollection = $this->getMockBuilder(FilterCollection::class) ->disableOriginalConstructor() ->getMock(); @@ -258,7 +259,7 @@ public function testSQLFilterGetConnection() $filter = new MyLocaleFilter($em); - $reflMethod = new \ReflectionMethod('Doctrine\ORM\Query\Filter\SQLFilter', 'getConnection'); + $reflMethod = new \ReflectionMethod(SQLFilter::class, 'getConnection'); $reflMethod->setAccessible(true); $this->assertSame($conn, $reflMethod->invoke($filter)); @@ -293,7 +294,7 @@ public function testSQLFilterSetParameterInfersType() public function testSQLFilterAddConstraint() { // Set up metadata mock - $targetEntity = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata') + $targetEntity = $this->getMockBuilder(ClassMetadata::class) ->disableOriginalConstructor() ->getMock(); @@ -333,7 +334,7 @@ public function testSQLFilterToString() public function testQueryCache_DependsOnFilters() { - $cacheDataReflection = new \ReflectionProperty("Doctrine\Common\Cache\ArrayCache", "data"); + $cacheDataReflection = new \ReflectionProperty(ArrayCache::class, "data"); $cacheDataReflection->setAccessible(true); $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); @@ -373,40 +374,40 @@ public function testRepositoryFind() { $this->loadFixtureData(); - $this->assertNotNull($this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->find($this->groupId)); - $this->assertNotNull($this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->find($this->groupId2)); + $this->assertNotNull($this->_em->getRepository(CmsGroup::class)->find($this->groupId)); + $this->assertNotNull($this->_em->getRepository(CmsGroup::class)->find($this->groupId2)); $this->useCMSGroupPrefixFilter(); $this->_em->clear(); - $this->assertNotNull($this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->find($this->groupId)); - $this->assertNull($this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->find($this->groupId2)); + $this->assertNotNull($this->_em->getRepository(CmsGroup::class)->find($this->groupId)); + $this->assertNull($this->_em->getRepository(CmsGroup::class)->find($this->groupId2)); } public function testRepositoryFindAll() { $this->loadFixtureData(); - $this->assertCount(2, $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findAll()); + $this->assertCount(2, $this->_em->getRepository(CmsGroup::class)->findAll()); $this->useCMSGroupPrefixFilter(); $this->_em->clear(); - $this->assertCount(1, $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findAll()); + $this->assertCount(1, $this->_em->getRepository(CmsGroup::class)->findAll()); } public function testRepositoryFindBy() { $this->loadFixtureData(); - $this->assertCount(1, $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findBy( + $this->assertCount(1, $this->_em->getRepository(CmsGroup::class)->findBy( ['id' => $this->groupId2] )); $this->useCMSGroupPrefixFilter(); $this->_em->clear(); - $this->assertCount(0, $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findBy( + $this->assertCount(0, $this->_em->getRepository(CmsGroup::class)->findBy( ['id' => $this->groupId2] )); } @@ -415,26 +416,26 @@ public function testRepositoryFindByX() { $this->loadFixtureData(); - $this->assertCount(1, $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findById($this->groupId2)); + $this->assertCount(1, $this->_em->getRepository(CmsGroup::class)->findById($this->groupId2)); $this->useCMSGroupPrefixFilter(); $this->_em->clear(); - $this->assertCount(0, $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findById($this->groupId2)); + $this->assertCount(0, $this->_em->getRepository(CmsGroup::class)->findById($this->groupId2)); } public function testRepositoryFindOneBy() { $this->loadFixtureData(); - $this->assertNotNull($this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findOneBy( + $this->assertNotNull($this->_em->getRepository(CmsGroup::class)->findOneBy( ['id' => $this->groupId2] )); $this->useCMSGroupPrefixFilter(); $this->_em->clear(); - $this->assertNull($this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findOneBy( + $this->assertNull($this->_em->getRepository(CmsGroup::class)->findOneBy( ['id' => $this->groupId2] )); } @@ -443,12 +444,12 @@ public function testRepositoryFindOneByX() { $this->loadFixtureData(); - $this->assertNotNull($this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findOneById($this->groupId2)); + $this->assertNotNull($this->_em->getRepository(CmsGroup::class)->findOneById($this->groupId2)); $this->useCMSGroupPrefixFilter(); $this->_em->clear(); - $this->assertNull($this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findOneById($this->groupId2)); + $this->assertNull($this->_em->getRepository(CmsGroup::class)->findOneById($this->groupId2)); } public function testToOneFilter() @@ -521,7 +522,7 @@ public function testWhereOrFilter() private function loadLazyFixtureData() { - $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $class = $this->_em->getClassMetadata(CmsUser::class); $class->associationMappings['articles']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY; $class->associationMappings['groups']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY; $this->loadFixtureData(); @@ -537,7 +538,7 @@ private function useCMSArticleTopicFilter() public function testOneToMany_ExtraLazyCountWithFilter() { $this->loadLazyFixtureData(); - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $this->assertFalse($user->articles->isInitialized()); $this->assertEquals(2, count($user->articles)); @@ -550,8 +551,8 @@ public function testOneToMany_ExtraLazyCountWithFilter() public function testOneToMany_ExtraLazyContainsWithFilter() { $this->loadLazyFixtureData(); - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); - $filteredArticle = $this->_em->find('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId2); + $user = $this->_em->find(CmsUser::class, $this->userId); + $filteredArticle = $this->_em->find(CmsArticle::class, $this->articleId2); $this->assertFalse($user->articles->isInitialized()); $this->assertTrue($user->articles->contains($filteredArticle)); @@ -564,7 +565,7 @@ public function testOneToMany_ExtraLazyContainsWithFilter() public function testOneToMany_ExtraLazySliceWithFilter() { $this->loadLazyFixtureData(); - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $this->assertFalse($user->articles->isInitialized()); $this->assertEquals(2, count($user->articles->slice(0,10))); @@ -585,7 +586,7 @@ public function testManyToMany_ExtraLazyCountWithFilter() { $this->loadLazyFixtureData(); - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId2); + $user = $this->_em->find(CmsUser::class, $this->userId2); $this->assertFalse($user->groups->isInitialized()); $this->assertEquals(2, count($user->groups)); @@ -598,8 +599,8 @@ public function testManyToMany_ExtraLazyCountWithFilter() public function testManyToMany_ExtraLazyContainsWithFilter() { $this->loadLazyFixtureData(); - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId2); - $filteredArticle = $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId2); + $user = $this->_em->find(CmsUser::class, $this->userId2); + $filteredArticle = $this->_em->find(CmsGroup::class, $this->groupId2); $this->assertFalse($user->groups->isInitialized()); $this->assertTrue($user->groups->contains($filteredArticle)); @@ -612,7 +613,7 @@ public function testManyToMany_ExtraLazyContainsWithFilter() public function testManyToMany_ExtraLazySliceWithFilter() { $this->loadLazyFixtureData(); - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId2); + $user = $this->_em->find(CmsUser::class, $this->userId2); $this->assertFalse($user->groups->isInitialized()); $this->assertEquals(2, count($user->groups->slice(0,10))); @@ -690,14 +691,14 @@ public function testJoinSubclassPersister_FilterOnlyOnRootTableWhenFetchingSubEn { $this->loadCompanyJoinedSubclassFixtureData(); // Persister - $this->assertEquals(2, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll())); + $this->assertEquals(2, count($this->_em->getRepository(CompanyManager::class)->findAll())); // SQLWalker $this->assertEquals(2, count($this->_em->createQuery("SELECT cm FROM Doctrine\Tests\Models\Company\CompanyManager cm")->getResult())); // Enable the filter $this->usePersonNameFilter('Guilh%'); - $managers = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll(); + $managers = $this->_em->getRepository(CompanyManager::class)->findAll(); $this->assertEquals(1, count($managers)); $this->assertEquals("Guilherme", $managers[0]->getName()); @@ -707,13 +708,13 @@ public function testJoinSubclassPersister_FilterOnlyOnRootTableWhenFetchingSubEn public function testJoinSubclassPersister_FilterOnlyOnRootTableWhenFetchingRootEntity() { $this->loadCompanyJoinedSubclassFixtureData(); - $this->assertEquals(3, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyPerson')->findAll())); + $this->assertEquals(3, count($this->_em->getRepository(CompanyPerson::class)->findAll())); $this->assertEquals(3, count($this->_em->createQuery("SELECT cp FROM Doctrine\Tests\Models\Company\CompanyPerson cp")->getResult())); // Enable the filter $this->usePersonNameFilter('Guilh%'); - $persons = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyPerson')->findAll(); + $persons = $this->_em->getRepository(CompanyPerson::class)->findAll(); $this->assertEquals(1, count($persons)); $this->assertEquals("Guilherme", $persons[0]->getName()); @@ -748,7 +749,7 @@ public function testSingleTableInheritance_FilterOnlyOnRootTableWhenFetchingSubE { $this->loadCompanySingleTableInheritanceFixtureData(); // Persister - $this->assertEquals(2, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyFlexUltraContract')->findAll())); + $this->assertEquals(2, count($this->_em->getRepository(CompanyFlexUltraContract::class)->findAll())); // SQLWalker $this->assertEquals(2, count($this->_em->createQuery("SELECT cfc FROM Doctrine\Tests\Models\Company\CompanyFlexUltraContract cfc")->getResult())); @@ -759,14 +760,14 @@ public function testSingleTableInheritance_FilterOnlyOnRootTableWhenFetchingSubE ->enable("completed_contract") ->setParameter("completed", true, DBALType::BOOLEAN); - $this->assertEquals(1, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyFlexUltraContract')->findAll())); + $this->assertEquals(1, count($this->_em->getRepository(CompanyFlexUltraContract::class)->findAll())); $this->assertEquals(1, count($this->_em->createQuery("SELECT cfc FROM Doctrine\Tests\Models\Company\CompanyFlexUltraContract cfc")->getResult())); } public function testSingleTableInheritance_FilterOnlyOnRootTableWhenFetchingRootEntity() { $this->loadCompanySingleTableInheritanceFixtureData(); - $this->assertEquals(4, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyFlexContract')->findAll())); + $this->assertEquals(4, count($this->_em->getRepository(CompanyFlexContract::class)->findAll())); $this->assertEquals(4, count($this->_em->createQuery("SELECT cfc FROM Doctrine\Tests\Models\Company\CompanyFlexContract cfc")->getResult())); // Enable the filter @@ -776,7 +777,7 @@ public function testSingleTableInheritance_FilterOnlyOnRootTableWhenFetchingRoot ->enable("completed_contract") ->setParameter("completed", true, DBALType::BOOLEAN); - $this->assertEquals(2, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyFlexContract')->findAll())); + $this->assertEquals(2, count($this->_em->getRepository(CompanyFlexContract::class)->findAll())); $this->assertEquals(2, count($this->_em->createQuery("SELECT cfc FROM Doctrine\Tests\Models\Company\CompanyFlexContract cfc")->getResult())); } @@ -840,7 +841,7 @@ public function testManyToMany_ExtraLazyCountWithFilterOnSTI() { $this->loadCompanySingleTableInheritanceFixtureData(); - $manager = $this->_em->find('Doctrine\Tests\Models\Company\CompanyManager', $this->managerId); + $manager = $this->_em->find(CompanyManager::class, $this->managerId); $this->assertFalse($manager->managedContracts->isInitialized()); $this->assertEquals(4, count($manager->managedContracts)); @@ -856,9 +857,9 @@ public function testManyToMany_ExtraLazyContainsWithFilterOnSTI() { $this->loadCompanySingleTableInheritanceFixtureData(); - $manager = $this->_em->find('Doctrine\Tests\Models\Company\CompanyManager', $this->managerId); - $contract1 = $this->_em->find('Doctrine\Tests\Models\Company\CompanyContract', $this->contractId1); - $contract2 = $this->_em->find('Doctrine\Tests\Models\Company\CompanyContract', $this->contractId2); + $manager = $this->_em->find(CompanyManager::class, $this->managerId); + $contract1 = $this->_em->find(CompanyContract::class, $this->contractId1); + $contract2 = $this->_em->find(CompanyContract::class, $this->contractId2); $this->assertFalse($manager->managedContracts->isInitialized()); $this->assertTrue($manager->managedContracts->contains($contract1)); @@ -876,7 +877,7 @@ public function testManyToMany_ExtraLazySliceWithFilterOnSTI() { $this->loadCompanySingleTableInheritanceFixtureData(); - $manager = $this->_em->find('Doctrine\Tests\Models\Company\CompanyManager', $this->managerId); + $manager = $this->_em->find(CompanyManager::class, $this->managerId); $this->assertFalse($manager->managedContracts->isInitialized()); $this->assertEquals(4, count($manager->managedContracts->slice(0, 10))); @@ -902,7 +903,7 @@ public function testManyToMany_ExtraLazyCountWithFilterOnCTI() { $this->loadCompanySingleTableInheritanceFixtureData(); - $contract = $this->_em->find('Doctrine\Tests\Models\Company\CompanyFlexUltraContract', $this->contractId1); + $contract = $this->_em->find(CompanyFlexUltraContract::class, $this->contractId1); $this->assertFalse($contract->managers->isInitialized()); $this->assertEquals(2, count($contract->managers)); @@ -918,9 +919,9 @@ public function testManyToMany_ExtraLazyContainsWithFilterOnCTI() { $this->loadCompanySingleTableInheritanceFixtureData(); - $contract = $this->_em->find('Doctrine\Tests\Models\Company\CompanyFlexUltraContract', $this->contractId1); - $manager1 = $this->_em->find('Doctrine\Tests\Models\Company\CompanyManager', $this->managerId); - $manager2 = $this->_em->find('Doctrine\Tests\Models\Company\CompanyManager', $this->managerId2); + $contract = $this->_em->find(CompanyFlexUltraContract::class, $this->contractId1); + $manager1 = $this->_em->find(CompanyManager::class, $this->managerId); + $manager2 = $this->_em->find(CompanyManager::class, $this->managerId2); $this->assertFalse($contract->managers->isInitialized()); $this->assertTrue($contract->managers->contains($manager1)); @@ -938,7 +939,7 @@ public function testManyToMany_ExtraLazySliceWithFilterOnCTI() { $this->loadCompanySingleTableInheritanceFixtureData(); - $contract = $this->_em->find('Doctrine\Tests\Models\Company\CompanyFlexUltraContract', $this->contractId1); + $contract = $this->_em->find(CompanyFlexUltraContract::class, $this->contractId1); $this->assertFalse($contract->managers->isInitialized()); $this->assertEquals(2, count($contract->managers->slice(0, 10))); @@ -954,7 +955,7 @@ public function testOneToMany_ExtraLazyCountWithFilterOnSTI() { $this->loadCompanySingleTableInheritanceFixtureData(); - $manager = $this->_em->find('Doctrine\Tests\Models\Company\CompanyManager', $this->managerId); + $manager = $this->_em->find(CompanyManager::class, $this->managerId); $this->assertFalse($manager->soldContracts->isInitialized()); $this->assertEquals(2, count($manager->soldContracts)); @@ -970,9 +971,9 @@ public function testOneToMany_ExtraLazyContainsWithFilterOnSTI() { $this->loadCompanySingleTableInheritanceFixtureData(); - $manager = $this->_em->find('Doctrine\Tests\Models\Company\CompanyManager', $this->managerId); - $contract1 = $this->_em->find('Doctrine\Tests\Models\Company\CompanyContract', $this->contractId1); - $contract2 = $this->_em->find('Doctrine\Tests\Models\Company\CompanyContract', $this->contractId2); + $manager = $this->_em->find(CompanyManager::class, $this->managerId); + $contract1 = $this->_em->find(CompanyContract::class, $this->contractId1); + $contract2 = $this->_em->find(CompanyContract::class, $this->contractId2); $this->assertFalse($manager->soldContracts->isInitialized()); $this->assertTrue($manager->soldContracts->contains($contract1)); @@ -991,7 +992,7 @@ public function testOneToMany_ExtraLazySliceWithFilterOnSTI() $this->loadCompanySingleTableInheritanceFixtureData(); - $manager = $this->_em->find('Doctrine\Tests\Models\Company\CompanyManager', $this->managerId); + $manager = $this->_em->find(CompanyManager::class, $this->managerId); $this->assertFalse($manager->soldContracts->isInitialized()); $this->assertEquals(2, count($manager->soldContracts->slice(0, 10))); @@ -1028,7 +1029,7 @@ private function useCompanyEventIdFilter() { // Enable the filter $conf = $this->_em->getConfiguration(); - $conf->addFilter("event_id", "\Doctrine\Tests\ORM\Functional\CompanyEventFilter"); + $conf->addFilter("event_id", CompanyEventFilter::class); $this->_em->getFilters() ->enable("event_id") ->setParameter("id", $this->eventId2); @@ -1039,7 +1040,7 @@ public function testOneToMany_ExtraLazyCountWithFilterOnCTI() { $this->loadCompanyOrganizationEventJoinedSubclassFixtureData(); - $organization = $this->_em->find('Doctrine\Tests\Models\Company\CompanyOrganization', $this->organizationId); + $organization = $this->_em->find(CompanyOrganization::class, $this->organizationId); $this->assertFalse($organization->events->isInitialized()); $this->assertEquals(2, count($organization->events)); @@ -1055,10 +1056,10 @@ public function testOneToMany_ExtraLazyContainsWithFilterOnCTI() { $this->loadCompanyOrganizationEventJoinedSubclassFixtureData(); - $organization = $this->_em->find('Doctrine\Tests\Models\Company\CompanyOrganization', $this->organizationId); + $organization = $this->_em->find(CompanyOrganization::class, $this->organizationId); - $event1 = $this->_em->find('Doctrine\Tests\Models\Company\CompanyEvent', $this->eventId1); - $event2 = $this->_em->find('Doctrine\Tests\Models\Company\CompanyEvent', $this->eventId2); + $event1 = $this->_em->find(CompanyEvent::class, $this->eventId1); + $event2 = $this->_em->find(CompanyEvent::class, $this->eventId2); $this->assertFalse($organization->events->isInitialized()); $this->assertTrue($organization->events->contains($event1)); @@ -1076,7 +1077,7 @@ public function testOneToMany_ExtraLazySliceWithFilterOnCTI() { $this->loadCompanyOrganizationEventJoinedSubclassFixtureData(); - $organization = $this->_em->find('Doctrine\Tests\Models\Company\CompanyOrganization', $this->organizationId); + $organization = $this->_em->find(CompanyOrganization::class, $this->organizationId); $this->assertFalse($organization->events->isInitialized()); $this->assertEquals(2, count($organization->events->slice(0, 10))); @@ -1117,7 +1118,7 @@ class CMSCountryFilter extends SQLFilter { public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) { - if ($targetEntity->name != "Doctrine\Tests\Models\CMS\CmsAddress") { + if ($targetEntity->name != CmsAddress::class) { return ""; } @@ -1129,7 +1130,7 @@ class CMSGroupPrefixFilter extends SQLFilter { public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) { - if ($targetEntity->name != "Doctrine\Tests\Models\CMS\CmsGroup") { + if ($targetEntity->name != CmsGroup::class) { return ""; } @@ -1141,7 +1142,7 @@ class CMSArticleTopicFilter extends SQLFilter { public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) { - if ($targetEntity->name != "Doctrine\Tests\Models\CMS\CmsArticle") { + if ($targetEntity->name != CmsArticle::class) { return ""; } @@ -1153,7 +1154,7 @@ class CompanyPersonNameFilter extends SQLFilter { public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') { - if ($targetEntity->name != "Doctrine\Tests\Models\Company\CompanyPerson") { + if ($targetEntity->name != CompanyPerson::class) { return ""; } @@ -1165,7 +1166,7 @@ class CompletedContractFilter extends SQLFilter { public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') { - if ($targetEntity->name != "Doctrine\Tests\Models\Company\CompanyContract") { + if ($targetEntity->name != CompanyContract::class) { return ""; } @@ -1177,7 +1178,7 @@ class CompanyEventFilter extends SQLFilter { public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') { - if ($targetEntity->name != "Doctrine\Tests\Models\Company\CompanyEvent") { + if ($targetEntity->name != CompanyEvent::class) { return ""; } diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/CompanySchemaTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/CompanySchemaTest.php index 66eee731af4..1a36591cf53 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/CompanySchemaTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/CompanySchemaTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM\Functional\SchemaTool; use Doctrine\DBAL\Schema\Schema; +use Doctrine\Tests\Models\Company\CompanyManager; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -61,7 +62,7 @@ public function testDropPartSchemaWithForeignKeys() $sql = $this->_schemaTool->getDropSchemaSQL( [ - $this->_em->getClassMetadata('Doctrine\Tests\Models\Company\CompanyManager'), + $this->_em->getClassMetadata(CompanyManager::class), ] ); $this->assertEquals(4, count($sql)); diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DBAL483Test.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DBAL483Test.php index 54caeb34a6d..8a874c478a7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DBAL483Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DBAL483Test.php @@ -21,7 +21,7 @@ public function setUp() */ public function testDefaultValueIsComparedCorrectly() { - $class = $this->_em->getClassMetadata(__NAMESPACE__ . '\\DBAL483Default'); + $class = $this->_em->getClassMetadata(DBAL483Default::class); $this->schemaTool->createSchema([$class]); diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php index 3ca501ae0dc..8c414b119a3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Schema\Comparator; use Doctrine\ORM\Tools; +use Doctrine\Tests\Models; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -32,12 +33,12 @@ public function setUp() public function testCmsAddressModel() { $this->classes = [ - 'Doctrine\Tests\Models\CMS\CmsUser', - 'Doctrine\Tests\Models\CMS\CmsPhonenumber', - 'Doctrine\Tests\Models\CMS\CmsAddress', - 'Doctrine\Tests\Models\CMS\CmsGroup', - 'Doctrine\Tests\Models\CMS\CmsArticle', - 'Doctrine\Tests\Models\CMS\CmsEmail', + Models\CMS\CmsUser::class, + Models\CMS\CmsPhonenumber::class, + Models\CMS\CmsAddress::class, + Models\CMS\CmsGroup::class, + Models\CMS\CmsArticle::class, + Models\CMS\CmsEmail::class, ]; $this->assertCreatedSchemaNeedsNoUpdates($this->classes); @@ -49,14 +50,14 @@ public function testCmsAddressModel() public function testCompanyModel() { $this->classes = [ - 'Doctrine\Tests\Models\Company\CompanyPerson', - 'Doctrine\Tests\Models\Company\CompanyEmployee', - 'Doctrine\Tests\Models\Company\CompanyManager', - 'Doctrine\Tests\Models\Company\CompanyOrganization', - 'Doctrine\Tests\Models\Company\CompanyEvent', - 'Doctrine\Tests\Models\Company\CompanyAuction', - 'Doctrine\Tests\Models\Company\CompanyRaffle', - 'Doctrine\Tests\Models\Company\CompanyCar' + Models\Company\CompanyPerson::class, + Models\Company\CompanyEmployee::class, + Models\Company\CompanyManager::class, + Models\Company\CompanyOrganization::class, + Models\Company\CompanyEvent::class, + Models\Company\CompanyAuction::class, + Models\Company\CompanyRaffle::class, + Models\Company\CompanyCar::class ]; $this->assertCreatedSchemaNeedsNoUpdates($this->classes); diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php index 9df372c9102..2deedb37aa6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php @@ -4,6 +4,7 @@ use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Tests\OrmFunctionalTestCase; +use Doctrine\Tests\Models; class MySqlSchemaToolTest extends OrmFunctionalTestCase { @@ -17,12 +18,12 @@ protected function setUp() { public function testGetCreateSchemaSql() { $classes = [ - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsGroup'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsTag'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsEmail'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), + $this->_em->getClassMetadata(Models\CMS\CmsGroup::class), + $this->_em->getClassMetadata(Models\CMS\CmsUser::class), + $this->_em->getClassMetadata(Models\CMS\CmsTag::class), + $this->_em->getClassMetadata(Models\CMS\CmsAddress::class), + $this->_em->getClassMetadata(Models\CMS\CmsEmail::class), + $this->_em->getClassMetadata(Models\CMS\CmsPhonenumber::class), ]; $tool = new SchemaTool($this->_em); @@ -50,7 +51,7 @@ public function testGetCreateSchemaSql() public function testGetCreateSchemaSql2() { $classes = [ - $this->_em->getClassMetadata('Doctrine\Tests\Models\Generic\DecimalModel') + $this->_em->getClassMetadata(Models\Generic\DecimalModel::class) ]; $tool = new SchemaTool($this->_em); @@ -63,7 +64,7 @@ public function testGetCreateSchemaSql2() public function testGetCreateSchemaSql3() { $classes = [ - $this->_em->getClassMetadata('Doctrine\Tests\Models\Generic\BooleanModel') + $this->_em->getClassMetadata(Models\Generic\BooleanModel::class) ]; $tool = new SchemaTool($this->_em); @@ -79,7 +80,7 @@ public function testGetCreateSchemaSql3() public function testGetCreateSchemaSql4() { $classes = [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\\MysqlSchemaNamespacedEntity') + $this->_em->getClassMetadata(MysqlSchemaNamespacedEntity::class) ]; $tool = new SchemaTool($this->_em); diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php index f71bfe9ceaa..5ebf84c5644 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM\Functional\SchemaTool; use Doctrine\ORM\Tools\SchemaTool; +use Doctrine\Tests\Models; use Doctrine\Tests\OrmFunctionalTestCase; class PostgreSqlSchemaToolTest extends OrmFunctionalTestCase @@ -18,7 +19,7 @@ protected function setUp() public function testPostgresMetadataSequenceIncrementedBy10() { - $address = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); + $address = $this->_em->getClassMetadata(Models\CMS\CmsAddress::class); $this->assertEquals(1, $address->sequenceGeneratorDefinition['allocationSize']); } @@ -26,9 +27,9 @@ public function testPostgresMetadataSequenceIncrementedBy10() public function testGetCreateSchemaSql() { $classes = [ - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), + $this->_em->getClassMetadata(Models\CMS\CmsAddress::class), + $this->_em->getClassMetadata(Models\CMS\CmsUser::class), + $this->_em->getClassMetadata(Models\CMS\CmsPhonenumber::class), ]; $tool = new SchemaTool($this->_em); @@ -65,7 +66,7 @@ public function testGetCreateSchemaSql() public function testGetCreateSchemaSql2() { $classes = [ - $this->_em->getClassMetadata('Doctrine\Tests\Models\Generic\DecimalModel') + $this->_em->getClassMetadata(Models\Generic\DecimalModel::class) ]; $tool = new SchemaTool($this->_em); @@ -80,7 +81,7 @@ public function testGetCreateSchemaSql2() public function testGetCreateSchemaSql3() { $classes = [ - $this->_em->getClassMetadata('Doctrine\Tests\Models\Generic\BooleanModel') + $this->_em->getClassMetadata(Models\Generic\BooleanModel::class) ]; $tool = new SchemaTool($this->_em); @@ -94,9 +95,9 @@ public function testGetCreateSchemaSql3() public function testGetDropSchemaSql() { $classes = [ - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), + $this->_em->getClassMetadata(Models\CMS\CmsAddress::class), + $this->_em->getClassMetadata(Models\CMS\CmsUser::class), + $this->_em->getClassMetadata(Models\CMS\CmsPhonenumber::class), ]; $tool = new SchemaTool($this->_em); @@ -120,8 +121,8 @@ public function testGetDropSchemaSql() public function testUpdateSchemaWithPostgreSQLSchema() { $classes = [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1657Screen'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1657Avatar'), + $this->_em->getClassMetadata(DDC1657Screen::class), + $this->_em->getClassMetadata(DDC1657Avatar::class), ]; $tool = new SchemaTool($this->_em); diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheCompositePrimaryKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheCompositePrimaryKeyTest.php index efa8f9f4dc9..9dff7df1d1c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheCompositePrimaryKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheCompositePrimaryKeyTest.php @@ -21,8 +21,8 @@ public function testPutAndLoadCompositPrimaryKeyEntities() $leavingFromId = $this->cities[0]->getId(); $goingToId = $this->cities[1]->getId(); - $leavingFrom = $this->_em->find(City::CLASSNAME, $leavingFromId); - $goingTo = $this->_em->find(City::CLASSNAME, $goingToId); + $leavingFrom = $this->_em->find(City::class, $leavingFromId); + $goingTo = $this->_em->find(City::class, $goingToId); $flight = new Flight($leavingFrom, $goingTo); $id = [ 'leavingFrom' => $leavingFromId, @@ -31,25 +31,25 @@ public function testPutAndLoadCompositPrimaryKeyEntities() $flight->setDeparture(new \DateTime('tomorrow')); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[0]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[1]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[0]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[1]->getId())); $this->_em->persist($flight); $this->_em->flush(); $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(Flight::CLASSNAME, $id)); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[0]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Flight::class, $id)); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[0]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[1]->getId())); $queryCount = $this->getCurrentQueryCount(); - $flight = $this->_em->find(Flight::CLASSNAME, $id); + $flight = $this->_em->find(Flight::class, $id); $leavingFrom = $flight->getLeavingFrom(); $goingTo = $flight->getGoingTo(); - $this->assertInstanceOf(Flight::CLASSNAME, $flight); - $this->assertInstanceOf(City::CLASSNAME, $goingTo); - $this->assertInstanceOf(City::CLASSNAME, $leavingFrom); + $this->assertInstanceOf(Flight::class, $flight); + $this->assertInstanceOf(City::class, $goingTo); + $this->assertInstanceOf(City::class, $leavingFrom); $this->assertEquals($goingTo->getId(), $goingToId); $this->assertEquals($leavingFrom->getId(), $leavingFromId); @@ -67,8 +67,8 @@ public function testRemoveCompositPrimaryKeyEntities() $leavingFromId = $this->cities[0]->getId(); $goingToId = $this->cities[1]->getId(); - $leavingFrom = $this->_em->find(City::CLASSNAME, $leavingFromId); - $goingTo = $this->_em->find(City::CLASSNAME, $goingToId); + $leavingFrom = $this->_em->find(City::class, $leavingFromId); + $goingTo = $this->_em->find(City::class, $goingToId); $flight = new Flight($leavingFrom, $goingTo); $id = [ 'leavingFrom' => $leavingFromId, @@ -77,25 +77,25 @@ public function testRemoveCompositPrimaryKeyEntities() $flight->setDeparture(new \DateTime('tomorrow')); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[0]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[1]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[0]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[1]->getId())); $this->_em->persist($flight); $this->_em->flush(); - $this->assertTrue($this->cache->containsEntity(Flight::CLASSNAME, $id)); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[0]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Flight::class, $id)); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[0]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[1]->getId())); $this->_em->remove($flight); $this->_em->flush(); $this->_em->clear(); - $this->assertFalse($this->cache->containsEntity(Flight::CLASSNAME, $id)); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[0]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[1]->getId())); + $this->assertFalse($this->cache->containsEntity(Flight::class, $id)); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[0]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[1]->getId())); - $this->assertNull($this->_em->find(Flight::CLASSNAME, $id)); + $this->assertNull($this->_em->find(Flight::class, $id)); } public function testUpdateCompositPrimaryKeyEntities() @@ -111,8 +111,8 @@ public function testUpdateCompositPrimaryKeyEntities() $tomorrow = new \DateTime('tomorrow'); $leavingFromId = $this->cities[0]->getId(); $goingToId = $this->cities[1]->getId(); - $leavingFrom = $this->_em->find(City::CLASSNAME, $leavingFromId); - $goingTo = $this->_em->find(City::CLASSNAME, $goingToId); + $leavingFrom = $this->_em->find(City::class, $leavingFromId); + $goingTo = $this->_em->find(City::class, $goingToId); $flight = new Flight($leavingFrom, $goingTo); $id = [ 'leavingFrom' => $leavingFromId, @@ -121,25 +121,25 @@ public function testUpdateCompositPrimaryKeyEntities() $flight->setDeparture($now); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[0]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[1]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[0]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[1]->getId())); $this->_em->persist($flight); $this->_em->flush(); $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(Flight::CLASSNAME, $id)); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[0]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Flight::class, $id)); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[0]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[1]->getId())); $queryCount = $this->getCurrentQueryCount(); - $flight = $this->_em->find(Flight::CLASSNAME, $id); + $flight = $this->_em->find(Flight::class, $id); $leavingFrom = $flight->getLeavingFrom(); $goingTo = $flight->getGoingTo(); - $this->assertInstanceOf(Flight::CLASSNAME, $flight); - $this->assertInstanceOf(City::CLASSNAME, $goingTo); - $this->assertInstanceOf(City::CLASSNAME, $leavingFrom); + $this->assertInstanceOf(Flight::class, $flight); + $this->assertInstanceOf(City::class, $goingTo); + $this->assertInstanceOf(City::class, $leavingFrom); $this->assertEquals($goingTo->getId(), $goingToId); $this->assertEquals($flight->getDeparture(), $now); @@ -153,18 +153,18 @@ public function testUpdateCompositPrimaryKeyEntities() $this->_em->flush(); $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(Flight::CLASSNAME, $id)); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[0]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Flight::class, $id)); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[0]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[1]->getId())); $queryCount = $this->getCurrentQueryCount(); - $flight = $this->_em->find(Flight::CLASSNAME, $id); + $flight = $this->_em->find(Flight::class, $id); $leavingFrom = $flight->getLeavingFrom(); $goingTo = $flight->getGoingTo(); - $this->assertInstanceOf(Flight::CLASSNAME, $flight); - $this->assertInstanceOf(City::CLASSNAME, $goingTo); - $this->assertInstanceOf(City::CLASSNAME, $leavingFrom); + $this->assertInstanceOf(Flight::class, $flight); + $this->assertInstanceOf(City::class, $goingTo); + $this->assertInstanceOf(City::class, $leavingFrom); $this->assertEquals($goingTo->getId(), $goingToId); $this->assertEquals($flight->getDeparture(), $tomorrow); diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheCompositePrimaryKeyWithAssociationsTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheCompositePrimaryKeyWithAssociationsTest.php index 0fc7ae415f2..8af09c9bf0d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheCompositePrimaryKeyWithAssociationsTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheCompositePrimaryKeyWithAssociationsTest.php @@ -2,10 +2,10 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\Tests\OrmFunctionalTestCase; -use Doctrine\Tests\Models\GeoNames\Country; use Doctrine\Tests\Models\GeoNames\Admin1; use Doctrine\Tests\Models\GeoNames\Admin1AlternateName; +use Doctrine\Tests\Models\GeoNames\Country; +use Doctrine\Tests\OrmFunctionalTestCase; class SecondLevelCacheCompositePrimaryKeyWithAssociationsTest extends OrmFunctionalTestCase { @@ -51,7 +51,7 @@ public function setUp() public function testFindByReturnsCachedEntity() { - $admin1Repo = $this->_em->getRepository('Doctrine\Tests\Models\GeoNames\Admin1'); + $admin1Repo = $this->_em->getRepository(Admin1::class); $queries = $this->getCurrentQueryCount(); diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheConcurrentTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheConcurrentTest.php index ee5aa3fbdbb..0f4ca383284 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheConcurrentTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheConcurrentTest.php @@ -37,19 +37,19 @@ protected function setUp() ->getSecondLevelCacheConfiguration() ->setCacheFactory($this->cacheFactory); - $this->countryMetadata = $this->_em->getClassMetadata(Country::CLASSNAME); + $this->countryMetadata = $this->_em->getClassMetadata(Country::class); $countryMetadata = clone $this->countryMetadata; $countryMetadata->cache['usage'] = ClassMetadata::CACHE_USAGE_NONSTRICT_READ_WRITE; - $this->_em->getMetadataFactory()->setMetadataFor(Country::CLASSNAME, $countryMetadata); + $this->_em->getMetadataFactory()->setMetadataFor(Country::class, $countryMetadata); } protected function tearDown() { parent::tearDown(); - $this->_em->getMetadataFactory()->setMetadataFor(Country::CLASSNAME, $this->countryMetadata); + $this->_em->getMetadataFactory()->setMetadataFor(Country::class, $this->countryMetadata); } public function testBasicConcurrentEntityReadLock() @@ -58,22 +58,22 @@ public function testBasicConcurrentEntityReadLock() $this->_em->clear(); $countryId = $this->countries[0]->getId(); - $cacheId = new EntityCacheKey(Country::CLASSNAME, ['id'=>$countryId]); - $region = $this->_em->getCache()->getEntityCacheRegion(Country::CLASSNAME); + $cacheId = new EntityCacheKey(Country::class, ['id'=>$countryId]); + $region = $this->_em->getCache()->getEntityCacheRegion(Country::class); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $countryId)); + $this->assertTrue($this->cache->containsEntity(Country::class, $countryId)); /** @var \Doctrine\Tests\Mocks\ConcurrentRegionMock */ $region->setLock($cacheId, Lock::createLockRead()); // another proc lock the entity cache - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $countryId)); + $this->assertFalse($this->cache->containsEntity(Country::class, $countryId)); $queryCount = $this->getCurrentQueryCount(); - $country = $this->_em->find(Country::CLASSNAME, $countryId); + $country = $this->_em->find(Country::class, $countryId); - $this->assertInstanceOf(Country::CLASSNAME, $country); + $this->assertInstanceOf(Country::class, $country); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $countryId)); + $this->assertFalse($this->cache->containsEntity(Country::class, $countryId)); } public function testBasicConcurrentCollectionReadLock() @@ -86,10 +86,10 @@ public function testBasicConcurrentCollectionReadLock() $this->evictRegions(); $stateId = $this->states[0]->getId(); - $state = $this->_em->find(State::CLASSNAME, $stateId); + $state = $this->_em->find(State::class, $stateId); - $this->assertInstanceOf(State::CLASSNAME, $state); - $this->assertInstanceOf(Country::CLASSNAME, $state->getCountry()); + $this->assertInstanceOf(State::class, $state); + $this->assertInstanceOf(Country::class, $state->getCountry()); $this->assertNotNull($state->getCountry()->getName()); $this->assertCount(2, $state->getCities()); @@ -97,34 +97,34 @@ public function testBasicConcurrentCollectionReadLock() $this->secondLevelCacheLogger->clearStats(); $stateId = $this->states[0]->getId(); - $cacheId = new CollectionCacheKey(State::CLASSNAME, 'cities', ['id'=>$stateId]); - $region = $this->_em->getCache()->getCollectionCacheRegion(State::CLASSNAME, 'cities'); + $cacheId = new CollectionCacheKey(State::class, 'cities', ['id'=>$stateId]); + $region = $this->_em->getCache()->getCollectionCacheRegion(State::class, 'cities'); - $this->assertTrue($this->cache->containsCollection(State::CLASSNAME, 'cities', $stateId)); + $this->assertTrue($this->cache->containsCollection(State::class, 'cities', $stateId)); /* @var $region \Doctrine\Tests\Mocks\ConcurrentRegionMock */ $region->setLock($cacheId, Lock::createLockRead()); // another proc lock the entity cache - $this->assertFalse($this->cache->containsCollection(State::CLASSNAME, 'cities', $stateId)); + $this->assertFalse($this->cache->containsCollection(State::class, 'cities', $stateId)); $queryCount = $this->getCurrentQueryCount(); - $state = $this->_em->find(State::CLASSNAME, $stateId); + $state = $this->_em->find(State::class, $stateId); $this->assertEquals(0, $this->secondLevelCacheLogger->getMissCount()); $this->assertEquals(1, $this->secondLevelCacheLogger->getHitCount()); - $this->assertEquals(0, $this->secondLevelCacheLogger->getRegionMissCount($this->getEntityRegion(State::CLASSNAME))); - $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionHitCount($this->getEntityRegion(State::CLASSNAME))); + $this->assertEquals(0, $this->secondLevelCacheLogger->getRegionMissCount($this->getEntityRegion(State::class))); + $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionHitCount($this->getEntityRegion(State::class))); - $this->assertInstanceOf(State::CLASSNAME, $state); + $this->assertInstanceOf(State::class, $state); $this->assertCount(2, $state->getCities()); $this->assertEquals(1, $this->secondLevelCacheLogger->getMissCount()); $this->assertEquals(1, $this->secondLevelCacheLogger->getHitCount()); - $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionMissCount($this->getCollectionRegion(State::CLASSNAME, 'cities'))); + $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionMissCount($this->getCollectionRegion(State::class, 'cities'))); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); - $this->assertFalse($this->cache->containsCollection(State::CLASSNAME, 'cities', $stateId)); + $this->assertFalse($this->cache->containsCollection(State::class, 'cities', $stateId)); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheCriteriaTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheCriteriaTest.php index 2096c520ce8..17d0ac7fc7e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheCriteriaTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheCriteriaTest.php @@ -2,9 +2,10 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\Tests\Models\Cache\State; -use Doctrine\Tests\Models\Cache\Country; +use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Criteria; +use Doctrine\Tests\Models\Cache\Country; +use Doctrine\Tests\Models\Cache\State; /** * @group DDC-2183 @@ -19,9 +20,9 @@ public function testMatchingPut() $this->evictRegions(); $this->_em->clear(); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); - $repository = $this->_em->getRepository(Country::CLASSNAME); + $repository = $this->_em->getRepository(Country::class); $queryCount = $this->getCurrentQueryCount(); $name = $this->countries[0]->getName(); $result1 = $repository->matching(new Criteria( @@ -35,7 +36,7 @@ public function testMatchingPut() $this->assertEquals($this->countries[0]->getId(), $result1[0]->getId()); $this->assertEquals($this->countries[0]->getName(), $result1[0]->getName()); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); $this->_em->clear(); @@ -46,7 +47,7 @@ public function testMatchingPut() $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); $this->assertCount(1, $result2); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\Country', $result2[0]); + $this->assertInstanceOf(Country::class, $result2[0]); $this->assertEquals($result1[0]->getId(), $result2[0]->getId()); $this->assertEquals($result1[0]->getName(), $result2[0]->getName()); @@ -59,9 +60,9 @@ public function testRepositoryMatching() $this->loadFixturesCountries(); $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); - $repository = $this->_em->getRepository(Country::CLASSNAME); + $repository = $this->_em->getRepository(Country::class); $queryCount = $this->getCurrentQueryCount(); $result1 = $repository->matching(new Criteria( Criteria::expr()->eq('name', $this->countries[0]->getName()) @@ -87,7 +88,7 @@ public function testRepositoryMatching() $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); $this->assertCount(1, $result2); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\Country', $result2[0]); + $this->assertInstanceOf(Country::class, $result2[0]); $this->assertEquals($this->countries[0]->getId(), $result2[0]->getId()); $this->assertEquals($this->countries[0]->getName(), $result2[0]->getName()); @@ -102,7 +103,7 @@ public function testRepositoryMatching() $this->assertEquals($queryCount + 2, $this->getCurrentQueryCount()); $this->assertCount(1, $result3); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\Country', $result3[0]); + $this->assertInstanceOf(Country::class, $result3[0]); $this->assertEquals($this->countries[1]->getId(), $result3[0]->getId()); $this->assertEquals($this->countries[1]->getName(), $result3[0]->getName()); @@ -114,7 +115,7 @@ public function testRepositoryMatching() $this->assertEquals($queryCount + 2, $this->getCurrentQueryCount()); $this->assertCount(1, $result4); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\Country', $result4[0]); + $this->assertInstanceOf(Country::class, $result4[0]); $this->assertEquals($this->countries[1]->getId(), $result4[0]->getId()); $this->assertEquals($this->countries[1]->getName(), $result4[0]->getName()); @@ -128,7 +129,7 @@ public function testCollectionMatching() $this->_em->clear(); $this->secondLevelCacheLogger->clearStats(); - $entity = $this->_em->find(State::CLASSNAME, $this->states[0]->getId()); + $entity = $this->_em->find(State::class, $this->states[0]->getId()); $itemName = $this->states[0]->getCities()->get(0)->getName(); $queryCount = $this->getCurrentQueryCount(); $collection = $entity->getCities(); @@ -137,12 +138,12 @@ public function testCollectionMatching() )); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); - $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $matching); + $this->assertInstanceOf(Collection::class, $matching); $this->assertCount(1, $matching); $this->_em->clear(); - $entity = $this->_em->find(State::CLASSNAME, $this->states[0]->getId()); + $entity = $this->_em->find(State::class, $this->states[0]->getId()); $queryCount = $this->getCurrentQueryCount(); $collection = $entity->getCities(); $matching = $collection->matching(new Criteria( @@ -150,7 +151,7 @@ public function testCollectionMatching() )); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); - $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $matching); + $this->assertInstanceOf(Collection::class, $matching); $this->assertCount(1, $matching); } diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheExtraLazyCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheExtraLazyCollectionTest.php index 366f846f81f..75499ac302c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheExtraLazyCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheExtraLazyCollectionTest.php @@ -16,8 +16,8 @@ public function setUp() { parent::setUp(); - $sourceEntity = $this->_em->getClassMetadata(Travel::CLASSNAME); - $targetEntity = $this->_em->getClassMetadata(City::CLASSNAME); + $sourceEntity = $this->_em->getClassMetadata(Travel::class); + $targetEntity = $this->_em->getClassMetadata(City::class); $sourceEntity->associationMappings['visitedCities']['fetch'] = ClassMetadata::FETCH_EXTRA_LAZY; $targetEntity->associationMappings['travels']['fetch'] = ClassMetadata::FETCH_EXTRA_LAZY; @@ -27,13 +27,13 @@ public function tearDown() { parent::tearDown(); - $sourceEntity = $this->_em->getClassMetadata(Travel::CLASSNAME); - $targetEntity = $this->_em->getClassMetadata(City::CLASSNAME); + $sourceEntity = $this->_em->getClassMetadata(Travel::class); + $targetEntity = $this->_em->getClassMetadata(City::class); $sourceEntity->associationMappings['visitedCities']['fetch'] = ClassMetadata::FETCH_LAZY; $targetEntity->associationMappings['travels']['fetch'] = ClassMetadata::FETCH_LAZY; } - + public function testCacheCountAfterAddThenFlush() { $this->loadFixturesCountries(); @@ -45,11 +45,11 @@ public function testCacheCountAfterAddThenFlush() $this->_em->clear(); $ownerId = $this->travels[0]->getId(); - $owner = $this->_em->find(Travel::CLASSNAME, $ownerId); - $ref = $this->_em->find(State::CLASSNAME, $this->states[1]->getId()); - - $this->assertTrue($this->cache->containsEntity(Travel::CLASSNAME, $ownerId)); - $this->assertTrue($this->cache->containsCollection(Travel::CLASSNAME, 'visitedCities', $ownerId)); + $owner = $this->_em->find(Travel::class, $ownerId); + $ref = $this->_em->find(State::class, $this->states[1]->getId()); + + $this->assertTrue($this->cache->containsEntity(Travel::class, $ownerId)); + $this->assertTrue($this->cache->containsCollection(Travel::class, 'visitedCities', $ownerId)); $newItem = new City("New City", $ref); $owner->getVisitedCities()->add($newItem); @@ -67,15 +67,15 @@ public function testCacheCountAfterAddThenFlush() $this->_em->flush(); $this->assertFalse($owner->getVisitedCities()->isInitialized()); - $this->assertFalse($this->cache->containsCollection(Travel::CLASSNAME, 'visitedCities', $ownerId)); + $this->assertFalse($this->cache->containsCollection(Travel::class, 'visitedCities', $ownerId)); $this->_em->clear(); $queryCount = $this->getCurrentQueryCount(); - $owner = $this->_em->find(Travel::CLASSNAME, $ownerId); + $owner = $this->_em->find(Travel::class, $ownerId); $this->assertEquals(4, $owner->getVisitedCities()->count()); $this->assertFalse($owner->getVisitedCities()->isInitialized()); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheJoinTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheJoinTableInheritanceTest.php index 9864172fab4..f9b9542444e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheJoinTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheJoinTableInheritanceTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\ORM\PersistentCollection; use Doctrine\Tests\Models\Cache\Attraction; use Doctrine\Tests\Models\Cache\AttractionContactInfo; use Doctrine\Tests\Models\Cache\AttractionInfo; @@ -14,9 +15,9 @@ class SecondLevelCacheJoinTableInheritanceTest extends SecondLevelCacheAbstractT { public function testUseSameRegion() { - $infoRegion = $this->cache->getEntityCacheRegion(AttractionInfo::CLASSNAME); - $contactRegion = $this->cache->getEntityCacheRegion(AttractionContactInfo::CLASSNAME); - $locationRegion = $this->cache->getEntityCacheRegion(AttractionLocationInfo::CLASSNAME); + $infoRegion = $this->cache->getEntityCacheRegion(AttractionInfo::class); + $contactRegion = $this->cache->getEntityCacheRegion(AttractionContactInfo::class); + $locationRegion = $this->cache->getEntityCacheRegion(AttractionLocationInfo::class); $this->assertEquals($infoRegion->getName(), $contactRegion->getName()); $this->assertEquals($infoRegion->getName(), $locationRegion->getName()); @@ -32,10 +33,10 @@ public function testPutOnPersistJoinTableInheritance() $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(AttractionInfo::CLASSNAME, $this->attractionsInfo[0]->getId())); - $this->assertTrue($this->cache->containsEntity(AttractionInfo::CLASSNAME, $this->attractionsInfo[1]->getId())); - $this->assertTrue($this->cache->containsEntity(AttractionInfo::CLASSNAME, $this->attractionsInfo[2]->getId())); - $this->assertTrue($this->cache->containsEntity(AttractionInfo::CLASSNAME, $this->attractionsInfo[3]->getId())); + $this->assertTrue($this->cache->containsEntity(AttractionInfo::class, $this->attractionsInfo[0]->getId())); + $this->assertTrue($this->cache->containsEntity(AttractionInfo::class, $this->attractionsInfo[1]->getId())); + $this->assertTrue($this->cache->containsEntity(AttractionInfo::class, $this->attractionsInfo[2]->getId())); + $this->assertTrue($this->cache->containsEntity(AttractionInfo::class, $this->attractionsInfo[3]->getId())); } public function testJoinTableCountaisRootClass() @@ -49,7 +50,7 @@ public function testJoinTableCountaisRootClass() $this->_em->clear(); foreach ($this->attractionsInfo as $info) { - $this->assertTrue($this->cache->containsEntity(AttractionInfo::CLASSNAME, $info->getId())); + $this->assertTrue($this->cache->containsEntity(AttractionInfo::class, $info->getId())); $this->assertTrue($this->cache->containsEntity(get_class($info), $info->getId())); } } @@ -64,32 +65,32 @@ public function testPutAndLoadJoinTableEntities() $this->_em->clear(); - $this->cache->evictEntityRegion(AttractionInfo::CLASSNAME); + $this->cache->evictEntityRegion(AttractionInfo::class); $entityId1 = $this->attractionsInfo[0]->getId(); $entityId2 = $this->attractionsInfo[1]->getId(); - $this->assertFalse($this->cache->containsEntity(AttractionInfo::CLASSNAME, $entityId1)); - $this->assertFalse($this->cache->containsEntity(AttractionInfo::CLASSNAME, $entityId2)); - $this->assertFalse($this->cache->containsEntity(AttractionContactInfo::CLASSNAME, $entityId1)); - $this->assertFalse($this->cache->containsEntity(AttractionContactInfo::CLASSNAME, $entityId2)); + $this->assertFalse($this->cache->containsEntity(AttractionInfo::class, $entityId1)); + $this->assertFalse($this->cache->containsEntity(AttractionInfo::class, $entityId2)); + $this->assertFalse($this->cache->containsEntity(AttractionContactInfo::class, $entityId1)); + $this->assertFalse($this->cache->containsEntity(AttractionContactInfo::class, $entityId2)); $queryCount = $this->getCurrentQueryCount(); - $entity1 = $this->_em->find(AttractionInfo::CLASSNAME, $entityId1); - $entity2 = $this->_em->find(AttractionInfo::CLASSNAME, $entityId2); + $entity1 = $this->_em->find(AttractionInfo::class, $entityId1); + $entity2 = $this->_em->find(AttractionInfo::class, $entityId2); //load entity and relation whit sub classes $this->assertEquals($queryCount + 4, $this->getCurrentQueryCount()); - $this->assertTrue($this->cache->containsEntity(AttractionInfo::CLASSNAME, $entityId1)); - $this->assertTrue($this->cache->containsEntity(AttractionInfo::CLASSNAME, $entityId2)); - $this->assertTrue($this->cache->containsEntity(AttractionContactInfo::CLASSNAME, $entityId1)); - $this->assertTrue($this->cache->containsEntity(AttractionContactInfo::CLASSNAME, $entityId2)); + $this->assertTrue($this->cache->containsEntity(AttractionInfo::class, $entityId1)); + $this->assertTrue($this->cache->containsEntity(AttractionInfo::class, $entityId2)); + $this->assertTrue($this->cache->containsEntity(AttractionContactInfo::class, $entityId1)); + $this->assertTrue($this->cache->containsEntity(AttractionContactInfo::class, $entityId2)); - $this->assertInstanceOf(AttractionInfo::CLASSNAME, $entity1); - $this->assertInstanceOf(AttractionInfo::CLASSNAME, $entity2); - $this->assertInstanceOf(AttractionContactInfo::CLASSNAME, $entity1); - $this->assertInstanceOf(AttractionContactInfo::CLASSNAME, $entity2); + $this->assertInstanceOf(AttractionInfo::class, $entity1); + $this->assertInstanceOf(AttractionInfo::class, $entity2); + $this->assertInstanceOf(AttractionContactInfo::class, $entity1); + $this->assertInstanceOf(AttractionContactInfo::class, $entity2); $this->assertEquals($this->attractionsInfo[0]->getId(), $entity1->getId()); $this->assertEquals($this->attractionsInfo[0]->getFone(), $entity1->getFone()); @@ -100,15 +101,15 @@ public function testPutAndLoadJoinTableEntities() $this->_em->clear(); $queryCount = $this->getCurrentQueryCount(); - $entity3 = $this->_em->find(AttractionInfo::CLASSNAME, $entityId1); - $entity4 = $this->_em->find(AttractionInfo::CLASSNAME, $entityId2); + $entity3 = $this->_em->find(AttractionInfo::class, $entityId1); + $entity4 = $this->_em->find(AttractionInfo::class, $entityId2); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); - $this->assertInstanceOf(AttractionInfo::CLASSNAME, $entity3); - $this->assertInstanceOf(AttractionInfo::CLASSNAME, $entity4); - $this->assertInstanceOf(AttractionContactInfo::CLASSNAME, $entity3); - $this->assertInstanceOf(AttractionContactInfo::CLASSNAME, $entity4); + $this->assertInstanceOf(AttractionInfo::class, $entity3); + $this->assertInstanceOf(AttractionInfo::class, $entity4); + $this->assertInstanceOf(AttractionContactInfo::class, $entity3); + $this->assertInstanceOf(AttractionContactInfo::class, $entity4); $this->assertNotSame($entity1, $entity3); $this->assertEquals($entity1->getId(), $entity3->getId()); @@ -148,7 +149,7 @@ public function testQueryCacheFindAllJoinTableEntities() $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); foreach ($result2 as $entity) { - $this->assertInstanceOf(AttractionInfo::CLASSNAME, $entity); + $this->assertInstanceOf(AttractionInfo::class, $entity); } } @@ -162,30 +163,30 @@ public function testOneToManyRelationJoinTable() $this->evictRegions(); $this->_em->clear(); - $entity = $this->_em->find(Attraction::CLASSNAME, $this->attractions[0]->getId()); + $entity = $this->_em->find(Attraction::class, $this->attractions[0]->getId()); - $this->assertInstanceOf(Attraction::CLASSNAME, $entity); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $entity->getInfos()); + $this->assertInstanceOf(Attraction::class, $entity); + $this->assertInstanceOf(PersistentCollection::class, $entity->getInfos()); $this->assertCount(1, $entity->getInfos()); $ownerId = $this->attractions[0]->getId(); $queryCount = $this->getCurrentQueryCount(); - $this->assertTrue($this->cache->containsEntity(Attraction::CLASSNAME, $ownerId)); - $this->assertTrue($this->cache->containsCollection(Attraction::CLASSNAME, 'infos', $ownerId)); + $this->assertTrue($this->cache->containsEntity(Attraction::class, $ownerId)); + $this->assertTrue($this->cache->containsCollection(Attraction::class, 'infos', $ownerId)); - $this->assertInstanceOf(AttractionContactInfo::CLASSNAME, $entity->getInfos()->get(0)); + $this->assertInstanceOf(AttractionContactInfo::class, $entity->getInfos()->get(0)); $this->assertEquals($this->attractionsInfo[0]->getFone(), $entity->getInfos()->get(0)->getFone()); $this->_em->clear(); - $entity = $this->_em->find(Attraction::CLASSNAME, $this->attractions[0]->getId()); + $entity = $this->_em->find(Attraction::class, $this->attractions[0]->getId()); - $this->assertInstanceOf(Attraction::CLASSNAME, $entity); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $entity->getInfos()); + $this->assertInstanceOf(Attraction::class, $entity); + $this->assertInstanceOf(PersistentCollection::class, $entity->getInfos()); $this->assertCount(1, $entity->getInfos()); - $this->assertInstanceOf(AttractionContactInfo::CLASSNAME, $entity->getInfos()->get(0)); + $this->assertInstanceOf(AttractionContactInfo::class, $entity->getInfos()->get(0)); $this->assertEquals($this->attractionsInfo[0]->getFone(), $entity->getInfos()->get(0)->getFone()); } @@ -228,7 +229,7 @@ public function testQueryCacheShouldBeEvictedOnTimestampUpdate() $this->assertEquals($queryCount + 6, $this->getCurrentQueryCount()); foreach ($result2 as $entity) { - $this->assertInstanceOf(AttractionInfo::CLASSNAME, $entity); + $this->assertInstanceOf(AttractionInfo::class, $entity); } } } diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToManyTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToManyTest.php index 0db9e1cbcdb..efe19f3e074 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToManyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToManyTest.php @@ -23,16 +23,16 @@ public function testShouldPutManyToManyCollectionOwningSideOnPersist() $this->loadFixturesTravels(); $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(Travel::CLASSNAME, $this->travels[0]->getId())); - $this->assertTrue($this->cache->containsEntity(Travel::CLASSNAME, $this->travels[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Travel::class, $this->travels[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Travel::class, $this->travels[1]->getId())); - $this->assertTrue($this->cache->containsCollection(Travel::CLASSNAME, 'visitedCities', $this->travels[0]->getId())); - $this->assertTrue($this->cache->containsCollection(Travel::CLASSNAME, 'visitedCities', $this->travels[1]->getId())); + $this->assertTrue($this->cache->containsCollection(Travel::class, 'visitedCities', $this->travels[0]->getId())); + $this->assertTrue($this->cache->containsCollection(Travel::class, 'visitedCities', $this->travels[1]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[0]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[1]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[2]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[3]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[0]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[1]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[2]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[3]->getId())); } public function testPutAndLoadManyToManyRelation() @@ -46,30 +46,30 @@ public function testPutAndLoadManyToManyRelation() $this->loadFixturesTravels(); $this->_em->clear(); - $this->cache->evictEntityRegion(City::CLASSNAME); - $this->cache->evictEntityRegion(Travel::CLASSNAME); - $this->cache->evictCollectionRegion(Travel::CLASSNAME, 'visitedCities'); + $this->cache->evictEntityRegion(City::class); + $this->cache->evictEntityRegion(Travel::class); + $this->cache->evictCollectionRegion(Travel::class, 'visitedCities'); $this->secondLevelCacheLogger->clearStats(); - $this->assertFalse($this->cache->containsEntity(Travel::CLASSNAME, $this->travels[0]->getId())); - $this->assertFalse($this->cache->containsEntity(Travel::CLASSNAME, $this->travels[1]->getId())); + $this->assertFalse($this->cache->containsEntity(Travel::class, $this->travels[0]->getId())); + $this->assertFalse($this->cache->containsEntity(Travel::class, $this->travels[1]->getId())); - $this->assertFalse($this->cache->containsCollection(Travel::CLASSNAME, 'visitedCities', $this->travels[0]->getId())); - $this->assertFalse($this->cache->containsCollection(Travel::CLASSNAME, 'visitedCities', $this->travels[1]->getId())); + $this->assertFalse($this->cache->containsCollection(Travel::class, 'visitedCities', $this->travels[0]->getId())); + $this->assertFalse($this->cache->containsCollection(Travel::class, 'visitedCities', $this->travels[1]->getId())); - $this->assertFalse($this->cache->containsEntity(City::CLASSNAME, $this->cities[0]->getId())); - $this->assertFalse($this->cache->containsEntity(City::CLASSNAME, $this->cities[1]->getId())); - $this->assertFalse($this->cache->containsEntity(City::CLASSNAME, $this->cities[2]->getId())); - $this->assertFalse($this->cache->containsEntity(City::CLASSNAME, $this->cities[3]->getId())); + $this->assertFalse($this->cache->containsEntity(City::class, $this->cities[0]->getId())); + $this->assertFalse($this->cache->containsEntity(City::class, $this->cities[1]->getId())); + $this->assertFalse($this->cache->containsEntity(City::class, $this->cities[2]->getId())); + $this->assertFalse($this->cache->containsEntity(City::class, $this->cities[3]->getId())); - $t1 = $this->_em->find(Travel::CLASSNAME, $this->travels[0]->getId()); - $t2 = $this->_em->find(Travel::CLASSNAME, $this->travels[1]->getId()); + $t1 = $this->_em->find(Travel::class, $this->travels[0]->getId()); + $t2 = $this->_em->find(Travel::class, $this->travels[1]->getId()); $this->assertEquals(2, $this->secondLevelCacheLogger->getPutCount()); $this->assertEquals(2, $this->secondLevelCacheLogger->getMissCount()); - $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(Travel::CLASSNAME))); - $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionMissCount($this->getEntityRegion(Travel::CLASSNAME))); + $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(Travel::class))); + $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionMissCount($this->getEntityRegion(Travel::class))); //trigger lazy load $this->assertCount(3, $t1->getVisitedCities()); @@ -77,49 +77,49 @@ public function testPutAndLoadManyToManyRelation() $this->assertEquals(4, $this->secondLevelCacheLogger->getPutCount()); $this->assertEquals(4, $this->secondLevelCacheLogger->getMissCount()); - $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getCollectionRegion(Travel::CLASSNAME, 'visitedCities'))); - $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionMissCount($this->getCollectionRegion(Travel::CLASSNAME, 'visitedCities'))); + $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getCollectionRegion(Travel::class, 'visitedCities'))); + $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionMissCount($this->getCollectionRegion(Travel::class, 'visitedCities'))); - $this->assertInstanceOf(City::CLASSNAME, $t1->getVisitedCities()->get(0)); - $this->assertInstanceOf(City::CLASSNAME, $t1->getVisitedCities()->get(1)); - $this->assertInstanceOf(City::CLASSNAME, $t1->getVisitedCities()->get(2)); + $this->assertInstanceOf(City::class, $t1->getVisitedCities()->get(0)); + $this->assertInstanceOf(City::class, $t1->getVisitedCities()->get(1)); + $this->assertInstanceOf(City::class, $t1->getVisitedCities()->get(2)); - $this->assertInstanceOf(City::CLASSNAME, $t2->getVisitedCities()->get(0)); - $this->assertInstanceOf(City::CLASSNAME, $t2->getVisitedCities()->get(1)); + $this->assertInstanceOf(City::class, $t2->getVisitedCities()->get(0)); + $this->assertInstanceOf(City::class, $t2->getVisitedCities()->get(1)); - $this->assertTrue($this->cache->containsEntity(Travel::CLASSNAME, $this->travels[0]->getId())); - $this->assertTrue($this->cache->containsEntity(Travel::CLASSNAME, $this->travels[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Travel::class, $this->travels[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Travel::class, $this->travels[1]->getId())); - $this->assertTrue($this->cache->containsCollection(Travel::CLASSNAME, 'visitedCities', $this->travels[0]->getId())); - $this->assertTrue($this->cache->containsCollection(Travel::CLASSNAME, 'visitedCities', $this->travels[1]->getId())); + $this->assertTrue($this->cache->containsCollection(Travel::class, 'visitedCities', $this->travels[0]->getId())); + $this->assertTrue($this->cache->containsCollection(Travel::class, 'visitedCities', $this->travels[1]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[0]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[1]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[2]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[3]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[0]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[1]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[2]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[3]->getId())); $this->_em->clear(); $this->secondLevelCacheLogger->clearStats(); $queryCount = $this->getCurrentQueryCount(); - $t3 = $this->_em->find(Travel::CLASSNAME, $this->travels[0]->getId()); - $t4 = $this->_em->find(Travel::CLASSNAME, $this->travels[1]->getId()); + $t3 = $this->_em->find(Travel::class, $this->travels[0]->getId()); + $t4 = $this->_em->find(Travel::class, $this->travels[1]->getId()); //trigger lazy load from cache $this->assertCount(3, $t3->getVisitedCities()); $this->assertCount(2, $t4->getVisitedCities()); - $this->assertInstanceOf(City::CLASSNAME, $t3->getVisitedCities()->get(0)); - $this->assertInstanceOf(City::CLASSNAME, $t3->getVisitedCities()->get(1)); - $this->assertInstanceOf(City::CLASSNAME, $t3->getVisitedCities()->get(2)); + $this->assertInstanceOf(City::class, $t3->getVisitedCities()->get(0)); + $this->assertInstanceOf(City::class, $t3->getVisitedCities()->get(1)); + $this->assertInstanceOf(City::class, $t3->getVisitedCities()->get(2)); - $this->assertInstanceOf(City::CLASSNAME, $t4->getVisitedCities()->get(0)); - $this->assertInstanceOf(City::CLASSNAME, $t4->getVisitedCities()->get(1)); + $this->assertInstanceOf(City::class, $t4->getVisitedCities()->get(0)); + $this->assertInstanceOf(City::class, $t4->getVisitedCities()->get(1)); $this->assertEquals(4, $this->secondLevelCacheLogger->getHitCount()); - $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionHitCount($this->getEntityRegion(Travel::CLASSNAME))); - $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionHitCount($this->getCollectionRegion(Travel::CLASSNAME, 'visitedCities'))); + $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionHitCount($this->getEntityRegion(Travel::class))); + $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionHitCount($this->getCollectionRegion(Travel::class, 'visitedCities'))); $this->assertNotSame($t1->getVisitedCities()->get(0), $t3->getVisitedCities()->get(0)); $this->assertEquals($t1->getVisitedCities()->get(0)->getId(), $t3->getVisitedCities()->get(0)->getId()); @@ -153,11 +153,11 @@ public function testStoreManyToManyAssociationWhitCascade() $this->loadFixturesStates(); $this->loadFixturesCities(); - $this->cache->evictEntityRegion(City::CLASSNAME); - $this->cache->evictEntityRegion(Traveler::CLASSNAME); - $this->cache->evictEntityRegion(Travel::CLASSNAME); - $this->cache->evictCollectionRegion(State::CLASSNAME, 'cities'); - $this->cache->evictCollectionRegion(Traveler::CLASSNAME, 'travels'); + $this->cache->evictEntityRegion(City::class); + $this->cache->evictEntityRegion(Traveler::class); + $this->cache->evictEntityRegion(Travel::class); + $this->cache->evictCollectionRegion(State::class, 'cities'); + $this->cache->evictCollectionRegion(Traveler::class, 'travels'); $traveler = new Traveler('Doctrine Bot'); $travel = new Travel($traveler); @@ -171,17 +171,17 @@ public function testStoreManyToManyAssociationWhitCascade() $this->_em->flush(); $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(Travel::CLASSNAME, $travel->getId())); - $this->assertTrue($this->cache->containsEntity(Traveler::CLASSNAME, $traveler->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[0]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[1]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[3]->getId())); - $this->assertTrue($this->cache->containsCollection(Travel::CLASSNAME, 'visitedCities', $travel->getId())); + $this->assertTrue($this->cache->containsEntity(Travel::class, $travel->getId())); + $this->assertTrue($this->cache->containsEntity(Traveler::class, $traveler->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[0]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[1]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[3]->getId())); + $this->assertTrue($this->cache->containsCollection(Travel::class, 'visitedCities', $travel->getId())); $queryCount1 = $this->getCurrentQueryCount(); - $t1 = $this->_em->find(Travel::CLASSNAME, $travel->getId()); + $t1 = $this->_em->find(Travel::class, $travel->getId()); - $this->assertInstanceOf(Travel::CLASSNAME, $t1); + $this->assertInstanceOf(Travel::class, $t1); $this->assertCount(3, $t1->getVisitedCities()); $this->assertEquals($queryCount1, $this->getCurrentQueryCount()); } @@ -202,10 +202,10 @@ public function testReadOnlyCollection() $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(Travel::CLASSNAME, $this->travels[0]->getId())); - $this->assertTrue($this->cache->containsCollection(Travel::CLASSNAME, 'visitedCities', $this->travels[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Travel::class, $this->travels[0]->getId())); + $this->assertTrue($this->cache->containsCollection(Travel::class, 'visitedCities', $this->travels[0]->getId())); - $travel = $this->_em->find(Travel::CLASSNAME, $this->travels[0]->getId()); + $travel = $this->_em->find(Travel::class, $this->travels[0]->getId()); $this->assertCount(3, $travel->getVisitedCities()); @@ -229,18 +229,18 @@ public function testManyToManyWithEmptyRelation() $queryCount = $this->getCurrentQueryCount(); $entitiId = $this->travels[2]->getId(); //empty travel - $entity = $this->_em->find(Travel::CLASSNAME, $entitiId); + $entity = $this->_em->find(Travel::class, $entitiId); $this->assertEquals(0, $entity->getVisitedCities()->count()); $this->assertEquals($queryCount+2, $this->getCurrentQueryCount()); $this->_em->clear(); - $entity = $this->_em->find(Travel::CLASSNAME, $entitiId); + $entity = $this->_em->find(Travel::class, $entitiId); $queryCount = $this->getCurrentQueryCount(); $this->assertEquals(0, $entity->getVisitedCities()->count()); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php index 57215f8e000..7af52f741c2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php @@ -2,12 +2,13 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\ORM\Cache\Region; +use Doctrine\Tests\Models\Cache\Action; use Doctrine\Tests\Models\Cache\City; use Doctrine\Tests\Models\Cache\ComplexAction; use Doctrine\Tests\Models\Cache\Country; use Doctrine\Tests\Models\Cache\State; use Doctrine\Tests\Models\Cache\Token; -use Doctrine\Tests\Models\Cache\Action; /** * @group DDC-2183 @@ -20,10 +21,10 @@ public function testPutOnPersist() $this->loadFixturesStates(); $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->states[0]->getCountry()->getId())); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->states[1]->getCountry()->getId())); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $this->states[0]->getId())); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $this->states[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->states[0]->getCountry()->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->states[1]->getCountry()->getId())); + $this->assertTrue($this->cache->containsEntity(State::class, $this->states[0]->getId())); + $this->assertTrue($this->cache->containsEntity(State::class, $this->states[1]->getId())); } public function testPutAndLoadManyToOneRelation() @@ -32,30 +33,30 @@ public function testPutAndLoadManyToOneRelation() $this->loadFixturesStates(); $this->_em->clear(); - $this->cache->evictEntityRegion(State::CLASSNAME); - $this->cache->evictEntityRegion(Country::CLASSNAME); + $this->cache->evictEntityRegion(State::class); + $this->cache->evictEntityRegion(Country::class); - $this->assertFalse($this->cache->containsEntity(State::CLASSNAME, $this->states[0]->getId())); - $this->assertFalse($this->cache->containsEntity(State::CLASSNAME, $this->states[1]->getId())); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $this->states[0]->getCountry()->getId())); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $this->states[1]->getCountry()->getId())); + $this->assertFalse($this->cache->containsEntity(State::class, $this->states[0]->getId())); + $this->assertFalse($this->cache->containsEntity(State::class, $this->states[1]->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->states[0]->getCountry()->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->states[1]->getCountry()->getId())); - $c1 = $this->_em->find(State::CLASSNAME, $this->states[0]->getId()); - $c2 = $this->_em->find(State::CLASSNAME, $this->states[1]->getId()); + $c1 = $this->_em->find(State::class, $this->states[0]->getId()); + $c2 = $this->_em->find(State::class, $this->states[1]->getId()); //trigger lazy load $this->assertNotNull($c1->getCountry()->getName()); $this->assertNotNull($c2->getCountry()->getName()); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->states[0]->getCountry()->getId())); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->states[1]->getCountry()->getId())); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $this->states[0]->getId())); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $this->states[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->states[0]->getCountry()->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->states[1]->getCountry()->getId())); + $this->assertTrue($this->cache->containsEntity(State::class, $this->states[0]->getId())); + $this->assertTrue($this->cache->containsEntity(State::class, $this->states[1]->getId())); - $this->assertInstanceOf(State::CLASSNAME, $c1); - $this->assertInstanceOf(State::CLASSNAME, $c2); - $this->assertInstanceOf(Country::CLASSNAME, $c1->getCountry()); - $this->assertInstanceOf(Country::CLASSNAME, $c2->getCountry()); + $this->assertInstanceOf(State::class, $c1); + $this->assertInstanceOf(State::class, $c2); + $this->assertInstanceOf(Country::class, $c1->getCountry()); + $this->assertInstanceOf(Country::class, $c2->getCountry()); $this->assertEquals($this->states[0]->getId(), $c1->getId()); $this->assertEquals($this->states[0]->getName(), $c1->getName()); @@ -71,8 +72,8 @@ public function testPutAndLoadManyToOneRelation() $queryCount = $this->getCurrentQueryCount(); - $c3 = $this->_em->find(State::CLASSNAME, $this->states[0]->getId()); - $c4 = $this->_em->find(State::CLASSNAME, $this->states[1]->getId()); + $c3 = $this->_em->find(State::class, $this->states[0]->getId()); + $c4 = $this->_em->find(State::class, $this->states[1]->getId()); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); @@ -80,10 +81,10 @@ public function testPutAndLoadManyToOneRelation() $this->assertNotNull($c3->getCountry()->getName()); $this->assertNotNull($c4->getCountry()->getName()); - $this->assertInstanceOf(State::CLASSNAME, $c3); - $this->assertInstanceOf(State::CLASSNAME, $c4); - $this->assertInstanceOf(Country::CLASSNAME, $c3->getCountry()); - $this->assertInstanceOf(Country::CLASSNAME, $c4->getCountry()); + $this->assertInstanceOf(State::class, $c3); + $this->assertInstanceOf(State::class, $c4); + $this->assertInstanceOf(Country::class, $c3->getCountry()); + $this->assertInstanceOf(Country::class, $c4->getCountry()); $this->assertEquals($c1->getId(), $c3->getId()); $this->assertEquals($c1->getName(), $c3->getName()); @@ -105,11 +106,11 @@ public function testInverseSidePutShouldEvictCollection() $this->_em->clear(); - $this->cache->evictEntityRegion(State::CLASSNAME); - $this->cache->evictEntityRegion(Country::CLASSNAME); + $this->cache->evictEntityRegion(State::class); + $this->cache->evictEntityRegion(Country::class); //evict collection on add - $c3 = $this->_em->find(State::CLASSNAME, $this->states[0]->getId()); + $c3 = $this->_em->find(State::class, $this->states[0]->getId()); $prev = $c3->getCities(); $count = $prev->count(); $city = new City("Buenos Aires", $c3); @@ -121,7 +122,7 @@ public function testInverseSidePutShouldEvictCollection() $this->_em->flush(); $this->_em->clear(); - $state = $this->_em->find(State::CLASSNAME, $c3->getId()); + $state = $this->_em->find(State::class, $c3->getId()); $queryCount = $this->getCurrentQueryCount(); // Association was cleared from EM @@ -144,29 +145,29 @@ public function testShouldNotReloadWhenAssociationIsMissing() $countryId1 = $this->states[0]->getCountry()->getId(); $countryId2 = $this->states[3]->getCountry()->getId(); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $countryId1)); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $countryId2)); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $stateId1)); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $stateId2)); + $this->assertTrue($this->cache->containsEntity(Country::class, $countryId1)); + $this->assertTrue($this->cache->containsEntity(Country::class, $countryId2)); + $this->assertTrue($this->cache->containsEntity(State::class, $stateId1)); + $this->assertTrue($this->cache->containsEntity(State::class, $stateId2)); - $this->cache->evictEntityRegion(Country::CLASSNAME); + $this->cache->evictEntityRegion(Country::class); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $countryId1)); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $countryId2)); + $this->assertFalse($this->cache->containsEntity(Country::class, $countryId1)); + $this->assertFalse($this->cache->containsEntity(Country::class, $countryId2)); $this->_em->clear(); $queryCount = $this->getCurrentQueryCount(); - $state1 = $this->_em->find(State::CLASSNAME, $stateId1); - $state2 = $this->_em->find(State::CLASSNAME, $stateId2); + $state1 = $this->_em->find(State::class, $stateId1); + $state2 = $this->_em->find(State::class, $stateId2); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); - $this->assertInstanceOf(State::CLASSNAME, $state1); - $this->assertInstanceOf(State::CLASSNAME, $state2); - $this->assertInstanceOf(Country::CLASSNAME, $state1->getCountry()); - $this->assertInstanceOf(Country::CLASSNAME, $state2->getCountry()); + $this->assertInstanceOf(State::class, $state1); + $this->assertInstanceOf(State::class, $state2); + $this->assertInstanceOf(Country::class, $state1->getCountry()); + $this->assertInstanceOf(Country::class, $state2->getCountry()); $queryCount = $this->getCurrentQueryCount(); @@ -180,8 +181,8 @@ public function testShouldNotReloadWhenAssociationIsMissing() public function testPutAndLoadNonCacheableManyToOne() { - $this->assertNull($this->cache->getEntityCacheRegion(Action::CLASSNAME)); - $this->assertInstanceOf('Doctrine\ORM\Cache\Region', $this->cache->getEntityCacheRegion(Token::CLASSNAME)); + $this->assertNull($this->cache->getEntityCacheRegion(Action::class)); + $this->assertInstanceOf(Region::class, $this->cache->getEntityCacheRegion(Token::class)); $token = new Token('token-hash'); $action = new Action('exec'); @@ -192,16 +193,16 @@ public function testPutAndLoadNonCacheableManyToOne() $this->_em->flush(); $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(Token::CLASSNAME, $token->token)); - $this->assertFalse($this->cache->containsEntity(Token::CLASSNAME, $action->name)); + $this->assertTrue($this->cache->containsEntity(Token::class, $token->token)); + $this->assertFalse($this->cache->containsEntity(Token::class, $action->name)); $queryCount = $this->getCurrentQueryCount(); - $entity = $this->_em->find(Token::CLASSNAME, $token->token); + $entity = $this->_em->find(Token::class, $token->token); - $this->assertInstanceOf(Token::CLASSNAME, $entity); + $this->assertInstanceOf(Token::class, $entity); $this->assertEquals('token-hash', $entity->token); - $this->assertInstanceOf(Action::CLASSNAME, $entity->getAction()); + $this->assertInstanceOf(Action::class, $entity->getAction()); $this->assertEquals('exec', $entity->getAction()->name); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); @@ -209,9 +210,9 @@ public function testPutAndLoadNonCacheableManyToOne() public function testPutAndLoadNonCacheableCompositeManyToOne() { - $this->assertNull($this->cache->getEntityCacheRegion(Action::CLASSNAME)); - $this->assertNull($this->cache->getEntityCacheRegion(ComplexAction::CLASSNAME)); - $this->assertInstanceOf('Doctrine\ORM\Cache\Region', $this->cache->getEntityCacheRegion(Token::CLASSNAME)); + $this->assertNull($this->cache->getEntityCacheRegion(Action::class)); + $this->assertNull($this->cache->getEntityCacheRegion(ComplexAction::class)); + $this->assertInstanceOf(Region::class, $this->cache->getEntityCacheRegion(Token::class)); $token = new Token('token-hash'); @@ -230,28 +231,28 @@ public function testPutAndLoadNonCacheableCompositeManyToOne() $this->_em->flush(); $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(Token::CLASSNAME, $token->token)); - $this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action1->name)); - $this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action2->name)); - $this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action3->name)); + $this->assertTrue($this->cache->containsEntity(Token::class, $token->token)); + $this->assertFalse($this->cache->containsEntity(Action::class, $action1->name)); + $this->assertFalse($this->cache->containsEntity(Action::class, $action2->name)); + $this->assertFalse($this->cache->containsEntity(Action::class, $action3->name)); $queryCount = $this->getCurrentQueryCount(); /** * @var $entity Token */ - $entity = $this->_em->find(Token::CLASSNAME, $token->token); + $entity = $this->_em->find(Token::class, $token->token); - $this->assertInstanceOf(Token::CLASSNAME, $entity); + $this->assertInstanceOf(Token::class, $entity); $this->assertEquals('token-hash', $entity->token); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); - $this->assertInstanceOf(Action::CLASSNAME, $entity->getAction()); - $this->assertInstanceOf(ComplexAction::CLASSNAME, $entity->getComplexAction()); + $this->assertInstanceOf(Action::class, $entity->getAction()); + $this->assertInstanceOf(ComplexAction::class, $entity->getComplexAction()); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); - $this->assertInstanceOf(Action::CLASSNAME, $entity->getComplexAction()->getAction1()); - $this->assertInstanceOf(Action::CLASSNAME, $entity->getComplexAction()->getAction2()); + $this->assertInstanceOf(Action::class, $entity->getComplexAction()->getAction1()); + $this->assertInstanceOf(Action::class, $entity->getComplexAction()->getAction2()); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); $this->assertEquals('login', $entity->getComplexAction()->getAction1()->name); @@ -259,4 +260,4 @@ public function testPutAndLoadNonCacheableCompositeManyToOne() $this->assertEquals('rememberme', $entity->getComplexAction()->getAction2()->name); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToManyTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToManyTest.php index 829cc4056b6..9f347cc5ba1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToManyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToManyTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\ORM\Cache\Region; use Doctrine\Tests\Models\Cache\City; use Doctrine\Tests\Models\Cache\Login; use Doctrine\Tests\Models\Cache\State; @@ -22,10 +23,10 @@ public function testShouldPutCollectionInverseSideOnPersist() $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $this->states[0]->getId())); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $this->states[1]->getId())); - $this->assertTrue($this->cache->containsCollection(State::CLASSNAME, 'cities', $this->states[0]->getId())); - $this->assertTrue($this->cache->containsCollection(State::CLASSNAME, 'cities', $this->states[1]->getId())); + $this->assertTrue($this->cache->containsEntity(State::class, $this->states[0]->getId())); + $this->assertTrue($this->cache->containsEntity(State::class, $this->states[1]->getId())); + $this->assertTrue($this->cache->containsCollection(State::class, 'cities', $this->states[0]->getId())); + $this->assertTrue($this->cache->containsCollection(State::class, 'cities', $this->states[1]->getId())); } public function testPutAndLoadOneToManyRelation() @@ -36,28 +37,28 @@ public function testPutAndLoadOneToManyRelation() $this->_em->clear(); $this->secondLevelCacheLogger->clearStats(); - $this->cache->evictEntityRegion(State::CLASSNAME); - $this->cache->evictEntityRegion(City::CLASSNAME); - $this->cache->evictCollectionRegion(State::CLASSNAME, 'cities'); + $this->cache->evictEntityRegion(State::class); + $this->cache->evictEntityRegion(City::class); + $this->cache->evictCollectionRegion(State::class, 'cities'); - $this->assertFalse($this->cache->containsEntity(State::CLASSNAME, $this->states[0]->getId())); - $this->assertFalse($this->cache->containsEntity(State::CLASSNAME, $this->states[1]->getId())); + $this->assertFalse($this->cache->containsEntity(State::class, $this->states[0]->getId())); + $this->assertFalse($this->cache->containsEntity(State::class, $this->states[1]->getId())); - $this->assertFalse($this->cache->containsCollection(State::CLASSNAME, 'cities', $this->states[0]->getId())); - $this->assertFalse($this->cache->containsCollection(State::CLASSNAME, 'cities', $this->states[1]->getId())); + $this->assertFalse($this->cache->containsCollection(State::class, 'cities', $this->states[0]->getId())); + $this->assertFalse($this->cache->containsCollection(State::class, 'cities', $this->states[1]->getId())); - $this->assertFalse($this->cache->containsEntity(City::CLASSNAME, $this->states[0]->getCities()->get(0)->getId())); - $this->assertFalse($this->cache->containsEntity(City::CLASSNAME, $this->states[0]->getCities()->get(1)->getId())); - $this->assertFalse($this->cache->containsEntity(City::CLASSNAME, $this->states[1]->getCities()->get(0)->getId())); - $this->assertFalse($this->cache->containsEntity(City::CLASSNAME, $this->states[1]->getCities()->get(1)->getId())); + $this->assertFalse($this->cache->containsEntity(City::class, $this->states[0]->getCities()->get(0)->getId())); + $this->assertFalse($this->cache->containsEntity(City::class, $this->states[0]->getCities()->get(1)->getId())); + $this->assertFalse($this->cache->containsEntity(City::class, $this->states[1]->getCities()->get(0)->getId())); + $this->assertFalse($this->cache->containsEntity(City::class, $this->states[1]->getCities()->get(1)->getId())); - $s1 = $this->_em->find(State::CLASSNAME, $this->states[0]->getId()); - $s2 = $this->_em->find(State::CLASSNAME, $this->states[1]->getId()); + $s1 = $this->_em->find(State::class, $this->states[0]->getId()); + $s2 = $this->_em->find(State::class, $this->states[1]->getId()); $this->assertEquals(2, $this->secondLevelCacheLogger->getPutCount()); $this->assertEquals(2, $this->secondLevelCacheLogger->getMissCount()); - $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(State::CLASSNAME))); - $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionMissCount($this->getEntityRegion(State::CLASSNAME))); + $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(State::class))); + $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionMissCount($this->getEntityRegion(State::class))); //trigger lazy load $this->assertCount(2, $s1->getCities()); @@ -65,46 +66,46 @@ public function testPutAndLoadOneToManyRelation() $this->assertEquals(4, $this->secondLevelCacheLogger->getPutCount()); $this->assertEquals(4, $this->secondLevelCacheLogger->getMissCount()); - $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getCollectionRegion(State::CLASSNAME, 'cities'))); - $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionMissCount($this->getCollectionRegion(State::CLASSNAME, 'cities'))); + $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getCollectionRegion(State::class, 'cities'))); + $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionMissCount($this->getCollectionRegion(State::class, 'cities'))); - $this->assertInstanceOf(City::CLASSNAME, $s1->getCities()->get(0)); - $this->assertInstanceOf(City::CLASSNAME, $s1->getCities()->get(1)); + $this->assertInstanceOf(City::class, $s1->getCities()->get(0)); + $this->assertInstanceOf(City::class, $s1->getCities()->get(1)); - $this->assertInstanceOf(City::CLASSNAME, $s2->getCities()->get(0)); - $this->assertInstanceOf(City::CLASSNAME, $s2->getCities()->get(1)); + $this->assertInstanceOf(City::class, $s2->getCities()->get(0)); + $this->assertInstanceOf(City::class, $s2->getCities()->get(1)); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $this->states[0]->getId())); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $this->states[1]->getId())); + $this->assertTrue($this->cache->containsEntity(State::class, $this->states[0]->getId())); + $this->assertTrue($this->cache->containsEntity(State::class, $this->states[1]->getId())); - $this->assertTrue($this->cache->containsCollection(State::CLASSNAME, 'cities', $this->states[0]->getId())); - $this->assertTrue($this->cache->containsCollection(State::CLASSNAME, 'cities', $this->states[1]->getId())); + $this->assertTrue($this->cache->containsCollection(State::class, 'cities', $this->states[0]->getId())); + $this->assertTrue($this->cache->containsCollection(State::class, 'cities', $this->states[1]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->states[0]->getCities()->get(0)->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->states[0]->getCities()->get(1)->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->states[1]->getCities()->get(0)->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->states[1]->getCities()->get(1)->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->states[0]->getCities()->get(0)->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->states[0]->getCities()->get(1)->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->states[1]->getCities()->get(0)->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->states[1]->getCities()->get(1)->getId())); $this->_em->clear(); $this->secondLevelCacheLogger->clearStats(); $queryCount = $this->getCurrentQueryCount(); - $s3 = $this->_em->find(State::CLASSNAME, $this->states[0]->getId()); - $s4 = $this->_em->find(State::CLASSNAME, $this->states[1]->getId()); + $s3 = $this->_em->find(State::class, $this->states[0]->getId()); + $s4 = $this->_em->find(State::class, $this->states[1]->getId()); //trigger lazy load from cache $this->assertCount(2, $s3->getCities()); $this->assertCount(2, $s4->getCities()); $this->assertEquals(4, $this->secondLevelCacheLogger->getHitCount()); - $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionHitCount($this->getEntityRegion(State::CLASSNAME))); - $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionHitCount($this->getCollectionRegion(State::CLASSNAME, 'cities'))); + $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionHitCount($this->getEntityRegion(State::class))); + $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionHitCount($this->getCollectionRegion(State::class, 'cities'))); - $this->assertInstanceOf(City::CLASSNAME, $s3->getCities()->get(0)); - $this->assertInstanceOf(City::CLASSNAME, $s3->getCities()->get(1)); - $this->assertInstanceOf(City::CLASSNAME, $s4->getCities()->get(0)); - $this->assertInstanceOf(City::CLASSNAME, $s4->getCities()->get(1)); + $this->assertInstanceOf(City::class, $s3->getCities()->get(0)); + $this->assertInstanceOf(City::class, $s3->getCities()->get(1)); + $this->assertInstanceOf(City::class, $s4->getCities()->get(0)); + $this->assertInstanceOf(City::class, $s4->getCities()->get(1)); $this->assertNotSame($s1->getCities()->get(0), $s3->getCities()->get(0)); $this->assertEquals($s1->getCities()->get(0)->getId(), $s3->getCities()->get(0)->getId()); @@ -134,32 +135,32 @@ public function testLoadOneToManyCollectionFromDatabaseWhenEntityMissing() $this->_em->clear(); //trigger lazy load from database - $this->assertCount(2, $this->_em->find(State::CLASSNAME, $this->states[0]->getId())->getCities()); + $this->assertCount(2, $this->_em->find(State::class, $this->states[0]->getId())->getCities()); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $this->states[0]->getId())); - $this->assertTrue($this->cache->containsCollection(State::CLASSNAME, 'cities', $this->states[0]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->states[0]->getCities()->get(0)->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->states[0]->getCities()->get(1)->getId())); + $this->assertTrue($this->cache->containsEntity(State::class, $this->states[0]->getId())); + $this->assertTrue($this->cache->containsCollection(State::class, 'cities', $this->states[0]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->states[0]->getCities()->get(0)->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->states[0]->getCities()->get(1)->getId())); $queryCount = $this->getCurrentQueryCount(); $stateId = $this->states[0]->getId(); - $state = $this->_em->find(State::CLASSNAME, $stateId); + $state = $this->_em->find(State::class, $stateId); $cityId = $this->states[0]->getCities()->get(1)->getId(); //trigger lazy load from cache $this->assertCount(2, $state->getCities()); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $cityId)); + $this->assertTrue($this->cache->containsEntity(City::class, $cityId)); - $this->cache->evictEntity(City::CLASSNAME, $cityId); + $this->cache->evictEntity(City::class, $cityId); - $this->assertFalse($this->cache->containsEntity(City::CLASSNAME, $cityId)); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $stateId)); - $this->assertTrue($this->cache->containsCollection(State::CLASSNAME, 'cities', $stateId)); + $this->assertFalse($this->cache->containsEntity(City::class, $cityId)); + $this->assertTrue($this->cache->containsEntity(State::class, $stateId)); + $this->assertTrue($this->cache->containsCollection(State::class, 'cities', $stateId)); $this->_em->clear(); - $state = $this->_em->find(State::CLASSNAME, $stateId); + $state = $this->_em->find(State::class, $stateId); //trigger lazy load from database $this->assertCount(2, $state->getCities()); @@ -178,8 +179,8 @@ public function testShoudNotPutOneToManyRelationOnPersist() $this->_em->flush(); $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $state->getId())); - $this->assertFalse($this->cache->containsCollection(State::CLASSNAME, 'cities', $state->getId())); + $this->assertTrue($this->cache->containsEntity(State::class, $state->getId())); + $this->assertFalse($this->cache->containsCollection(State::class, 'cities', $state->getId())); } public function testOneToManyRemove() @@ -191,51 +192,51 @@ public function testOneToManyRemove() $this->_em->clear(); $this->secondLevelCacheLogger->clearStats(); - $this->cache->evictEntityRegion(State::CLASSNAME); - $this->cache->evictEntityRegion(City::CLASSNAME); - $this->cache->evictCollectionRegion(State::CLASSNAME, 'cities'); + $this->cache->evictEntityRegion(State::class); + $this->cache->evictEntityRegion(City::class); + $this->cache->evictCollectionRegion(State::class, 'cities'); - $this->assertFalse($this->cache->containsEntity(State::CLASSNAME, $this->states[0]->getId())); - $this->assertFalse($this->cache->containsCollection(State::CLASSNAME, 'cities', $this->states[0]->getId())); - $this->assertFalse($this->cache->containsEntity(City::CLASSNAME, $this->states[0]->getCities()->get(0)->getId())); - $this->assertFalse($this->cache->containsEntity(City::CLASSNAME, $this->states[0]->getCities()->get(1)->getId())); + $this->assertFalse($this->cache->containsEntity(State::class, $this->states[0]->getId())); + $this->assertFalse($this->cache->containsCollection(State::class, 'cities', $this->states[0]->getId())); + $this->assertFalse($this->cache->containsEntity(City::class, $this->states[0]->getCities()->get(0)->getId())); + $this->assertFalse($this->cache->containsEntity(City::class, $this->states[0]->getCities()->get(1)->getId())); - $entity = $this->_em->find(State::CLASSNAME, $this->states[0]->getId()); + $entity = $this->_em->find(State::class, $this->states[0]->getId()); $this->assertEquals(1, $this->secondLevelCacheLogger->getPutCount()); $this->assertEquals(1, $this->secondLevelCacheLogger->getMissCount()); - $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(State::CLASSNAME))); - $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionMissCount($this->getEntityRegion(State::CLASSNAME))); + $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(State::class))); + $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionMissCount($this->getEntityRegion(State::class))); //trigger lazy load $this->assertCount(2, $entity->getCities()); $this->assertEquals(2, $this->secondLevelCacheLogger->getPutCount()); $this->assertEquals(2, $this->secondLevelCacheLogger->getMissCount()); - $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionPutCount($this->getCollectionRegion(State::CLASSNAME, 'cities'))); - $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionMissCount($this->getCollectionRegion(State::CLASSNAME, 'cities'))); + $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionPutCount($this->getCollectionRegion(State::class, 'cities'))); + $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionMissCount($this->getCollectionRegion(State::class, 'cities'))); - $this->assertInstanceOf(City::CLASSNAME, $entity->getCities()->get(0)); - $this->assertInstanceOf(City::CLASSNAME, $entity->getCities()->get(1)); + $this->assertInstanceOf(City::class, $entity->getCities()->get(0)); + $this->assertInstanceOf(City::class, $entity->getCities()->get(1)); $this->_em->clear(); $this->secondLevelCacheLogger->clearStats(); $queryCount = $this->getCurrentQueryCount(); - $state = $this->_em->find(State::CLASSNAME, $this->states[0]->getId()); + $state = $this->_em->find(State::class, $this->states[0]->getId()); //trigger lazy load from cache $this->assertCount(2, $state->getCities()); $this->assertEquals(2, $this->secondLevelCacheLogger->getHitCount()); - $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionHitCount($this->getEntityRegion(State::CLASSNAME))); - $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionHitCount($this->getCollectionRegion(State::CLASSNAME, 'cities'))); + $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionHitCount($this->getEntityRegion(State::class))); + $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionHitCount($this->getCollectionRegion(State::class, 'cities'))); $city0 = $state->getCities()->get(0); $city1 = $state->getCities()->get(1); - $this->assertInstanceOf(City::CLASSNAME, $city0); - $this->assertInstanceOf(City::CLASSNAME, $city1); + $this->assertInstanceOf(City::class, $city0); + $this->assertInstanceOf(City::class, $city1); $this->assertEquals($entity->getCities()->get(0)->getName(), $city0->getName()); $this->assertEquals($entity->getCities()->get(1)->getName(), $city1->getName()); @@ -253,18 +254,18 @@ public function testOneToManyRemove() $this->secondLevelCacheLogger->clearStats(); $queryCount = $this->getCurrentQueryCount(); - $state = $this->_em->find(State::CLASSNAME, $this->states[0]->getId()); + $state = $this->_em->find(State::class, $this->states[0]->getId()); //trigger lazy load from cache $this->assertCount(1, $state->getCities()); $city1 = $state->getCities()->get(0); - $this->assertInstanceOf(City::CLASSNAME, $city1); + $this->assertInstanceOf(City::class, $city1); $this->assertEquals($entity->getCities()->get(1)->getName(), $city1->getName()); $this->assertEquals(2, $this->secondLevelCacheLogger->getHitCount()); - $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionHitCount($this->getEntityRegion(State::CLASSNAME))); - $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionHitCount($this->getCollectionRegion(State::CLASSNAME, 'cities'))); + $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionHitCount($this->getEntityRegion(State::class))); + $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionHitCount($this->getCollectionRegion(State::class, 'cities'))); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); @@ -278,13 +279,13 @@ public function testOneToManyRemove() $this->secondLevelCacheLogger->clearStats(); $queryCount = $this->getCurrentQueryCount(); - $state = $this->_em->find(State::CLASSNAME, $this->states[0]->getId()); + $state = $this->_em->find(State::class, $this->states[0]->getId()); $this->assertCount(0, $state->getCities()); $this->assertEquals(2, $this->secondLevelCacheLogger->getHitCount()); - $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionHitCount($this->getEntityRegion(State::CLASSNAME))); - $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionHitCount($this->getCollectionRegion(State::CLASSNAME, 'cities'))); + $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionHitCount($this->getEntityRegion(State::class))); + $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionHitCount($this->getCollectionRegion(State::class, 'cities'))); } public function testOneToManyWithEmptyRelation() @@ -294,14 +295,14 @@ public function testOneToManyWithEmptyRelation() $this->loadFixturesCities(); $this->secondLevelCacheLogger->clearStats(); - $this->cache->evictEntityRegion(City::CLASSNAME); - $this->cache->evictEntityRegion(State::CLASSNAME); - $this->cache->evictCollectionRegion(State::CLASSNAME, 'cities'); + $this->cache->evictEntityRegion(City::class); + $this->cache->evictEntityRegion(State::class); + $this->cache->evictCollectionRegion(State::class, 'cities'); $this->_em->clear(); $entitiId = $this->states[2]->getId(); // bavaria (cities count = 0) $queryCount = $this->getCurrentQueryCount(); - $entity = $this->_em->find(State::CLASSNAME, $entitiId); + $entity = $this->_em->find(State::class, $entitiId); $this->assertEquals(0, $entity->getCities()->count()); $this->assertEquals($queryCount + 2, $this->getCurrentQueryCount()); @@ -309,7 +310,7 @@ public function testOneToManyWithEmptyRelation() $this->_em->clear(); $queryCount = $this->getCurrentQueryCount(); - $entity = $this->_em->find(State::CLASSNAME, $entitiId); + $entity = $this->_em->find(State::class, $entitiId); $this->assertEquals(0, $entity->getCities()->count()); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); @@ -323,14 +324,14 @@ public function testOneToManyCount() $this->loadFixturesCities(); $this->secondLevelCacheLogger->clearStats(); - $this->cache->evictEntityRegion(City::CLASSNAME); - $this->cache->evictEntityRegion(State::CLASSNAME); - $this->cache->evictCollectionRegion(State::CLASSNAME, 'cities'); + $this->cache->evictEntityRegion(City::class); + $this->cache->evictEntityRegion(State::class); + $this->cache->evictCollectionRegion(State::class, 'cities'); $this->_em->clear(); $entityId = $this->states[0]->getId(); $queryCount = $this->getCurrentQueryCount(); - $entity = $this->_em->find(State::CLASSNAME, $entityId); + $entity = $this->_em->find(State::class, $entityId); $this->assertEquals(2, $entity->getCities()->count()); $this->assertEquals($queryCount + 2, $this->getCurrentQueryCount()); @@ -338,7 +339,7 @@ public function testOneToManyCount() $this->_em->clear(); $queryCount = $this->getCurrentQueryCount(); - $entity = $this->_em->find(State::CLASSNAME, $entityId); + $entity = $this->_em->find(State::class, $entityId); $this->assertEquals(2, $entity->getCities()->count()); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); @@ -364,7 +365,7 @@ public function testCacheInitializeCollectionWithNewObjects() $travelerId = $traveler->getId(); $queryCount = $this->getCurrentQueryCount(); - $entity = $this->_em->find(Traveler::CLASSNAME, $travelerId); + $entity = $this->_em->find(Traveler::class, $travelerId); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); $this->assertFalse($entity->getTravels()->isInitialized()); @@ -388,8 +389,8 @@ public function testCacheInitializeCollectionWithNewObjects() public function testPutAndLoadNonCacheableOneToMany() { - $this->assertNull($this->cache->getEntityCacheRegion(Login::CLASSNAME)); - $this->assertInstanceOf('Doctrine\ORM\Cache\Region', $this->cache->getEntityCacheRegion(Token::CLASSNAME)); + $this->assertNull($this->cache->getEntityCacheRegion(Login::class)); + $this->assertInstanceOf(Region::class, $this->cache->getEntityCacheRegion(Token::class)); $l1 = new Login('session1'); $l2 = new Login('session2'); @@ -401,13 +402,13 @@ public function testPutAndLoadNonCacheableOneToMany() $this->_em->flush(); $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(Token::CLASSNAME, $token->token)); + $this->assertTrue($this->cache->containsEntity(Token::class, $token->token)); $queryCount = $this->getCurrentQueryCount(); - $entity = $this->_em->find(Token::CLASSNAME, $token->token); + $entity = $this->_em->find(Token::class, $token->token); - $this->assertInstanceOf(Token::CLASSNAME, $entity); + $this->assertInstanceOf(Token::class, $entity); $this->assertEquals('token-hash', $entity->token); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToOneTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToOneTest.php index 316620f82d2..6e428814d3f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToOneTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToOneTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\ORM\Cache\Region; use Doctrine\Tests\Models\Cache\Address; use Doctrine\Tests\Models\Cache\Client; use Doctrine\Tests\Models\Cache\Person; @@ -27,10 +28,10 @@ public function testPutOneToOneOnUnidirectionalPersist() $entity1 = $this->travelersWithProfile[0]; $entity2 = $this->travelersWithProfile[1]; - $this->assertTrue($this->cache->containsEntity(Traveler::CLASSNAME, $entity1->getId())); - $this->assertTrue($this->cache->containsEntity(Traveler::CLASSNAME, $entity2->getId())); - $this->assertTrue($this->cache->containsEntity(TravelerProfile::CLASSNAME, $entity1->getProfile()->getId())); - $this->assertTrue($this->cache->containsEntity(TravelerProfile::CLASSNAME, $entity2->getProfile()->getId())); + $this->assertTrue($this->cache->containsEntity(Traveler::class, $entity1->getId())); + $this->assertTrue($this->cache->containsEntity(Traveler::class, $entity2->getId())); + $this->assertTrue($this->cache->containsEntity(TravelerProfile::class, $entity1->getProfile()->getId())); + $this->assertTrue($this->cache->containsEntity(TravelerProfile::class, $entity2->getProfile()->getId())); } public function testPutOneToOneOnBidirectionalPersist() @@ -46,12 +47,12 @@ public function testPutOneToOneOnBidirectionalPersist() $entity1 = $this->travelersWithProfile[0]; $entity2 = $this->travelersWithProfile[1]; - $this->assertTrue($this->cache->containsEntity(Traveler::CLASSNAME, $entity1->getId())); - $this->assertTrue($this->cache->containsEntity(Traveler::CLASSNAME, $entity2->getId())); - $this->assertTrue($this->cache->containsEntity(TravelerProfile::CLASSNAME, $entity1->getProfile()->getId())); - $this->assertTrue($this->cache->containsEntity(TravelerProfile::CLASSNAME, $entity2->getProfile()->getId())); - $this->assertTrue($this->cache->containsEntity(TravelerProfileInfo::CLASSNAME, $entity1->getProfile()->getInfo()->getId())); - $this->assertTrue($this->cache->containsEntity(TravelerProfileInfo::CLASSNAME, $entity2->getProfile()->getInfo()->getId())); + $this->assertTrue($this->cache->containsEntity(Traveler::class, $entity1->getId())); + $this->assertTrue($this->cache->containsEntity(Traveler::class, $entity2->getId())); + $this->assertTrue($this->cache->containsEntity(TravelerProfile::class, $entity1->getProfile()->getId())); + $this->assertTrue($this->cache->containsEntity(TravelerProfile::class, $entity2->getProfile()->getId())); + $this->assertTrue($this->cache->containsEntity(TravelerProfileInfo::class, $entity1->getProfile()->getInfo()->getId())); + $this->assertTrue($this->cache->containsEntity(TravelerProfileInfo::class, $entity2->getProfile()->getInfo()->getId())); } public function testPutAndLoadOneToOneUnidirectionalRelation() @@ -64,30 +65,30 @@ public function testPutAndLoadOneToOneUnidirectionalRelation() $this->_em->clear(); - $this->cache->evictEntityRegion(Traveler::CLASSNAME); - $this->cache->evictEntityRegion(TravelerProfile::CLASSNAME); + $this->cache->evictEntityRegion(Traveler::class); + $this->cache->evictEntityRegion(TravelerProfile::class); $entity1 = $this->travelersWithProfile[0]; $entity2 = $this->travelersWithProfile[1]; - $this->assertFalse($this->cache->containsEntity(Traveler::CLASSNAME, $entity1->getId())); - $this->assertFalse($this->cache->containsEntity(Traveler::CLASSNAME, $entity2->getId())); - $this->assertFalse($this->cache->containsEntity(TravelerProfile::CLASSNAME, $entity1->getProfile()->getId())); - $this->assertFalse($this->cache->containsEntity(TravelerProfile::CLASSNAME, $entity2->getProfile()->getId())); + $this->assertFalse($this->cache->containsEntity(Traveler::class, $entity1->getId())); + $this->assertFalse($this->cache->containsEntity(Traveler::class, $entity2->getId())); + $this->assertFalse($this->cache->containsEntity(TravelerProfile::class, $entity1->getProfile()->getId())); + $this->assertFalse($this->cache->containsEntity(TravelerProfile::class, $entity2->getProfile()->getId())); - $t1 = $this->_em->find(Traveler::CLASSNAME, $entity1->getId()); - $t2 = $this->_em->find(Traveler::CLASSNAME, $entity2->getId()); + $t1 = $this->_em->find(Traveler::class, $entity1->getId()); + $t2 = $this->_em->find(Traveler::class, $entity2->getId()); - $this->assertTrue($this->cache->containsEntity(Traveler::CLASSNAME, $entity1->getId())); - $this->assertTrue($this->cache->containsEntity(Traveler::CLASSNAME, $entity2->getId())); + $this->assertTrue($this->cache->containsEntity(Traveler::class, $entity1->getId())); + $this->assertTrue($this->cache->containsEntity(Traveler::class, $entity2->getId())); // The inverse side its not cached - $this->assertFalse($this->cache->containsEntity(TravelerProfile::CLASSNAME, $entity1->getProfile()->getId())); - $this->assertFalse($this->cache->containsEntity(TravelerProfile::CLASSNAME, $entity2->getProfile()->getId())); + $this->assertFalse($this->cache->containsEntity(TravelerProfile::class, $entity1->getProfile()->getId())); + $this->assertFalse($this->cache->containsEntity(TravelerProfile::class, $entity2->getProfile()->getId())); - $this->assertInstanceOf(Traveler::CLASSNAME, $t1); - $this->assertInstanceOf(Traveler::CLASSNAME, $t2); - $this->assertInstanceOf(TravelerProfile::CLASSNAME, $t1->getProfile()); - $this->assertInstanceOf(TravelerProfile::CLASSNAME, $t2->getProfile()); + $this->assertInstanceOf(Traveler::class, $t1); + $this->assertInstanceOf(Traveler::class, $t2); + $this->assertInstanceOf(TravelerProfile::class, $t1->getProfile()); + $this->assertInstanceOf(TravelerProfile::class, $t2->getProfile()); $this->assertEquals($entity1->getId(), $t1->getId()); $this->assertEquals($entity1->getName(), $t1->getName()); @@ -100,22 +101,22 @@ public function testPutAndLoadOneToOneUnidirectionalRelation() $this->assertEquals($entity2->getProfile()->getName(), $t2->getProfile()->getName()); // its all cached now - $this->assertTrue($this->cache->containsEntity(Traveler::CLASSNAME, $entity1->getId())); - $this->assertTrue($this->cache->containsEntity(Traveler::CLASSNAME, $entity2->getId())); - $this->assertTrue($this->cache->containsEntity(TravelerProfile::CLASSNAME, $entity1->getProfile()->getId())); - $this->assertTrue($this->cache->containsEntity(TravelerProfile::CLASSNAME, $entity1->getProfile()->getId())); + $this->assertTrue($this->cache->containsEntity(Traveler::class, $entity1->getId())); + $this->assertTrue($this->cache->containsEntity(Traveler::class, $entity2->getId())); + $this->assertTrue($this->cache->containsEntity(TravelerProfile::class, $entity1->getProfile()->getId())); + $this->assertTrue($this->cache->containsEntity(TravelerProfile::class, $entity1->getProfile()->getId())); $this->_em->clear(); $queryCount = $this->getCurrentQueryCount(); // load from cache - $t3 = $this->_em->find(Traveler::CLASSNAME, $entity1->getId()); - $t4 = $this->_em->find(Traveler::CLASSNAME, $entity2->getId()); + $t3 = $this->_em->find(Traveler::class, $entity1->getId()); + $t4 = $this->_em->find(Traveler::class, $entity2->getId()); - $this->assertInstanceOf(Traveler::CLASSNAME, $t3); - $this->assertInstanceOf(Traveler::CLASSNAME, $t4); - $this->assertInstanceOf(TravelerProfile::CLASSNAME, $t3->getProfile()); - $this->assertInstanceOf(TravelerProfile::CLASSNAME, $t4->getProfile()); + $this->assertInstanceOf(Traveler::class, $t3); + $this->assertInstanceOf(Traveler::class, $t4); + $this->assertInstanceOf(TravelerProfile::class, $t3->getProfile()); + $this->assertInstanceOf(TravelerProfile::class, $t4->getProfile()); $this->assertEquals($entity1->getProfile()->getId(), $t3->getProfile()->getId()); $this->assertEquals($entity2->getProfile()->getId(), $t4->getProfile()->getId()); @@ -136,20 +137,20 @@ public function testPutAndLoadOneToOneBidirectionalRelation() $this->_em->clear(); - $this->cache->evictEntityRegion(Traveler::CLASSNAME); - $this->cache->evictEntityRegion(TravelerProfile::CLASSNAME); - $this->cache->evictEntityRegion(TravelerProfileInfo::CLASSNAME); + $this->cache->evictEntityRegion(Traveler::class); + $this->cache->evictEntityRegion(TravelerProfile::class); + $this->cache->evictEntityRegion(TravelerProfileInfo::class); $entity1 = $this->travelersWithProfile[0]->getProfile(); $entity2 = $this->travelersWithProfile[1]->getProfile(); - $this->assertFalse($this->cache->containsEntity(TravelerProfile::CLASSNAME, $entity1->getId())); - $this->assertFalse($this->cache->containsEntity(TravelerProfile::CLASSNAME, $entity2->getId())); - $this->assertFalse($this->cache->containsEntity(TravelerProfileInfo::CLASSNAME, $entity1->getInfo()->getId())); - $this->assertFalse($this->cache->containsEntity(TravelerProfileInfo::CLASSNAME, $entity2->getInfo()->getId())); + $this->assertFalse($this->cache->containsEntity(TravelerProfile::class, $entity1->getId())); + $this->assertFalse($this->cache->containsEntity(TravelerProfile::class, $entity2->getId())); + $this->assertFalse($this->cache->containsEntity(TravelerProfileInfo::class, $entity1->getInfo()->getId())); + $this->assertFalse($this->cache->containsEntity(TravelerProfileInfo::class, $entity2->getInfo()->getId())); - $p1 = $this->_em->find(TravelerProfile::CLASSNAME, $entity1->getId()); - $p2 = $this->_em->find(TravelerProfile::CLASSNAME, $entity2->getId()); + $p1 = $this->_em->find(TravelerProfile::class, $entity1->getId()); + $p2 = $this->_em->find(TravelerProfile::class, $entity2->getId()); $this->assertEquals($entity1->getId(), $p1->getId()); $this->assertEquals($entity1->getName(), $p1->getName()); @@ -161,22 +162,22 @@ public function testPutAndLoadOneToOneBidirectionalRelation() $this->assertEquals($entity2->getInfo()->getId(), $p2->getInfo()->getId()); $this->assertEquals($entity2->getInfo()->getDescription(), $p2->getInfo()->getDescription()); - $this->assertTrue($this->cache->containsEntity(TravelerProfile::CLASSNAME, $entity1->getId())); - $this->assertTrue($this->cache->containsEntity(TravelerProfile::CLASSNAME, $entity2->getId())); - $this->assertTrue($this->cache->containsEntity(TravelerProfileInfo::CLASSNAME, $entity1->getInfo()->getId())); - $this->assertTrue($this->cache->containsEntity(TravelerProfileInfo::CLASSNAME, $entity2->getInfo()->getId())); + $this->assertTrue($this->cache->containsEntity(TravelerProfile::class, $entity1->getId())); + $this->assertTrue($this->cache->containsEntity(TravelerProfile::class, $entity2->getId())); + $this->assertTrue($this->cache->containsEntity(TravelerProfileInfo::class, $entity1->getInfo()->getId())); + $this->assertTrue($this->cache->containsEntity(TravelerProfileInfo::class, $entity2->getInfo()->getId())); $this->_em->clear(); $queryCount = $this->getCurrentQueryCount(); - $p3 = $this->_em->find(TravelerProfile::CLASSNAME, $entity1->getId()); - $p4 = $this->_em->find(TravelerProfile::CLASSNAME, $entity2->getId()); + $p3 = $this->_em->find(TravelerProfile::class, $entity1->getId()); + $p4 = $this->_em->find(TravelerProfile::class, $entity2->getId()); - $this->assertInstanceOf(TravelerProfile::CLASSNAME, $p3); - $this->assertInstanceOf(TravelerProfile::CLASSNAME, $p4); - $this->assertInstanceOf(TravelerProfileInfo::CLASSNAME, $p3->getInfo()); - $this->assertInstanceOf(TravelerProfileInfo::CLASSNAME, $p4->getInfo()); + $this->assertInstanceOf(TravelerProfile::class, $p3); + $this->assertInstanceOf(TravelerProfile::class, $p4); + $this->assertInstanceOf(TravelerProfileInfo::class, $p3->getInfo()); + $this->assertInstanceOf(TravelerProfileInfo::class, $p4->getInfo()); $this->assertEquals($entity1->getId(), $p3->getId()); $this->assertEquals($entity1->getName(), $p3->getName()); @@ -197,19 +198,19 @@ public function testInverseSidePutAndLoadOneToOneBidirectionalRelation() $this->_em->clear(); - $this->cache->evictEntityRegion(Person::CLASSNAME); - $this->cache->evictEntityRegion(Address::CLASSNAME); + $this->cache->evictEntityRegion(Person::class); + $this->cache->evictEntityRegion(Address::class); $entity1 = $this->addresses[0]->person; $entity2 = $this->addresses[1]->person; - $this->assertFalse($this->cache->containsEntity(Person::CLASSNAME, $entity1->id)); - $this->assertFalse($this->cache->containsEntity(Person::CLASSNAME, $entity2->id)); - $this->assertFalse($this->cache->containsEntity(Address::CLASSNAME, $entity1->address->id)); - $this->assertFalse($this->cache->containsEntity(Address::CLASSNAME, $entity2->address->id)); + $this->assertFalse($this->cache->containsEntity(Person::class, $entity1->id)); + $this->assertFalse($this->cache->containsEntity(Person::class, $entity2->id)); + $this->assertFalse($this->cache->containsEntity(Address::class, $entity1->address->id)); + $this->assertFalse($this->cache->containsEntity(Address::class, $entity2->address->id)); - $p1 = $this->_em->find(Person::CLASSNAME, $entity1->id); - $p2 = $this->_em->find(Person::CLASSNAME, $entity2->id); + $p1 = $this->_em->find(Person::class, $entity1->id); + $p2 = $this->_em->find(Person::class, $entity2->id); $this->assertEquals($entity1->id, $p1->id); $this->assertEquals($entity1->name, $p1->name); @@ -221,23 +222,23 @@ public function testInverseSidePutAndLoadOneToOneBidirectionalRelation() $this->assertEquals($entity2->address->id, $p2->address->id); $this->assertEquals($entity2->address->location, $p2->address->location); - $this->assertTrue($this->cache->containsEntity(Person::CLASSNAME, $entity1->id)); - $this->assertTrue($this->cache->containsEntity(Person::CLASSNAME, $entity2->id)); + $this->assertTrue($this->cache->containsEntity(Person::class, $entity1->id)); + $this->assertTrue($this->cache->containsEntity(Person::class, $entity2->id)); // The inverse side its not cached - $this->assertFalse($this->cache->containsEntity(Address::CLASSNAME, $entity1->address->id)); - $this->assertFalse($this->cache->containsEntity(Address::CLASSNAME, $entity2->address->id)); + $this->assertFalse($this->cache->containsEntity(Address::class, $entity1->address->id)); + $this->assertFalse($this->cache->containsEntity(Address::class, $entity2->address->id)); $this->_em->clear(); $queryCount = $this->getCurrentQueryCount(); - $p3 = $this->_em->find(Person::CLASSNAME, $entity1->id); - $p4 = $this->_em->find(Person::CLASSNAME, $entity2->id); + $p3 = $this->_em->find(Person::class, $entity1->id); + $p4 = $this->_em->find(Person::class, $entity2->id); - $this->assertInstanceOf(Person::CLASSNAME, $p3); - $this->assertInstanceOf(Person::CLASSNAME, $p4); - $this->assertInstanceOf(Address::CLASSNAME, $p3->address); - $this->assertInstanceOf(Address::CLASSNAME, $p4->address); + $this->assertInstanceOf(Person::class, $p3); + $this->assertInstanceOf(Person::class, $p4); + $this->assertInstanceOf(Address::class, $p3->address); + $this->assertInstanceOf(Address::class, $p4->address); $this->assertEquals($entity1->id, $p3->id); $this->assertEquals($entity1->name, $p3->name); @@ -254,8 +255,8 @@ public function testInverseSidePutAndLoadOneToOneBidirectionalRelation() public function testPutAndLoadNonCacheableOneToOne() { - $this->assertNull($this->cache->getEntityCacheRegion(Client::CLASSNAME)); - $this->assertInstanceOf('Doctrine\ORM\Cache\Region', $this->cache->getEntityCacheRegion(Token::CLASSNAME)); + $this->assertNull($this->cache->getEntityCacheRegion(Client::class)); + $this->assertInstanceOf(Region::class, $this->cache->getEntityCacheRegion(Token::class)); $client = new Client('FabioBatSilva'); $token = new Token('token-hash', $client); @@ -267,17 +268,17 @@ public function testPutAndLoadNonCacheableOneToOne() $queryCount = $this->getCurrentQueryCount(); - $this->assertTrue($this->cache->containsEntity(Token::CLASSNAME, $token->token)); - $this->assertFalse($this->cache->containsEntity(Client::CLASSNAME, $client->id)); + $this->assertTrue($this->cache->containsEntity(Token::class, $token->token)); + $this->assertFalse($this->cache->containsEntity(Client::class, $client->id)); - $entity = $this->_em->find(Token::CLASSNAME, $token->token); + $entity = $this->_em->find(Token::class, $token->token); - $this->assertInstanceOf(Token::CLASSNAME, $entity); - $this->assertInstanceOf(Client::CLASSNAME, $entity->getClient()); + $this->assertInstanceOf(Token::class, $entity); + $this->assertInstanceOf(Client::class, $entity->getClient()); $this->assertEquals('token-hash', $entity->token); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); $this->assertEquals('FabioBatSilva', $entity->getClient()->name); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheQueryCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheQueryCacheTest.php index 51a93417b4e..0a32886dd0f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheQueryCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheQueryCacheTest.php @@ -3,16 +3,17 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\ORM\AbstractQuery; +use Doctrine\ORM\Cache; +use Doctrine\ORM\Cache\EntityCacheEntry; +use Doctrine\ORM\Cache\EntityCacheKey; +use Doctrine\ORM\Cache\QueryCacheKey; +use Doctrine\ORM\Proxy\Proxy; +use Doctrine\ORM\Query; use Doctrine\ORM\Query\ResultSetMapping; +use Doctrine\Tests\Models\Cache\Attraction; use Doctrine\Tests\Models\Cache\City; -use Doctrine\Tests\Models\Cache\State; use Doctrine\Tests\Models\Cache\Country; -use Doctrine\Tests\Models\Cache\Attraction; -use Doctrine\ORM\Cache\QueryCacheKey; -use Doctrine\ORM\Cache\EntityCacheKey; -use Doctrine\ORM\Cache\EntityCacheEntry; -use Doctrine\ORM\Query; -use Doctrine\ORM\Cache; +use Doctrine\Tests\Models\Cache\State; /** * @group DDC-2183 @@ -27,8 +28,8 @@ public function testBasicQueryCache() $this->secondLevelCacheLogger->clearStats(); $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); $queryCount = $this->getCurrentQueryCount(); $dql = 'SELECT c FROM Doctrine\Tests\Models\Cache\Country c'; @@ -63,8 +64,8 @@ public function testBasicQueryCache() $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionHitCount($this->getDefaultQueryRegionName())); $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionMissCount($this->getDefaultQueryRegionName())); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\Country', $result2[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\Country', $result2[1]); + $this->assertInstanceOf(Country::class, $result2[0]); + $this->assertInstanceOf(Country::class, $result2[1]); $this->assertEquals($result1[0]->getId(), $result2[0]->getId()); $this->assertEquals($result1[1]->getId(), $result2[1]->getId()); @@ -90,8 +91,8 @@ public function testQueryCacheModeGet() $this->secondLevelCacheLogger->clearStats(); $this->_em->clear(); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $this->countries[1]->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); $queryCount = $this->getCurrentQueryCount(); $dql = 'SELECT c FROM Doctrine\Tests\Models\Cache\Country c'; @@ -113,8 +114,8 @@ public function testQueryCacheModeGet() $this->assertCount(2, $result); $this->assertEquals($queryCount + 3, $this->getCurrentQueryCount()); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); // MODE_GET should read items if exists. $this->assertCount(2, $queryGet->getResult()); @@ -130,8 +131,8 @@ public function testQueryCacheModePut() $this->secondLevelCacheLogger->clearStats(); $this->_em->clear(); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $this->countries[1]->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); $queryCount = $this->getCurrentQueryCount(); $dql = 'SELECT c FROM Doctrine\Tests\Models\Cache\Country c'; @@ -139,8 +140,8 @@ public function testQueryCacheModePut() ->setCacheable(true) ->getResult(); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); $this->assertCount(2, $result); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); @@ -152,13 +153,13 @@ public function testQueryCacheModePut() // MODE_PUT should never read itens from cache. $this->assertCount(2, $queryPut->getResult()); $this->assertEquals($queryCount + 2, $this->getCurrentQueryCount()); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); $this->assertCount(2, $queryPut->getResult()); $this->assertEquals($queryCount + 3, $this->getCurrentQueryCount()); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); } public function testQueryCacheModeRefresh() @@ -170,18 +171,18 @@ public function testQueryCacheModeRefresh() $this->secondLevelCacheLogger->clearStats(); $this->_em->clear(); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $this->countries[1]->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); - $region = $this->cache->getEntityCacheRegion(Country::CLASSNAME); + $region = $this->cache->getEntityCacheRegion(Country::class); $queryCount = $this->getCurrentQueryCount(); $dql = 'SELECT c FROM Doctrine\Tests\Models\Cache\Country c'; $result = $this->_em->createQuery($dql) ->setCacheable(true) ->getResult(); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); $this->assertCount(2, $result); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); @@ -191,10 +192,10 @@ public function testQueryCacheModeRefresh() $countryName1 = $this->countries[0]->getName(); $countryName2 = $this->countries[1]->getName(); - $key1 = new EntityCacheKey(Country::CLASSNAME, ['id'=>$countryId1]); - $key2 = new EntityCacheKey(Country::CLASSNAME, ['id'=>$countryId2]); - $entry1 = new EntityCacheEntry(Country::CLASSNAME, ['id'=>$countryId1, 'name'=>'outdated']); - $entry2 = new EntityCacheEntry(Country::CLASSNAME, ['id'=>$countryId2, 'name'=>'outdated']); + $key1 = new EntityCacheKey(Country::class, ['id'=>$countryId1]); + $key2 = new EntityCacheKey(Country::class, ['id'=>$countryId2]); + $entry1 = new EntityCacheEntry(Country::class, ['id'=>$countryId1, 'name'=>'outdated']); + $entry2 = new EntityCacheEntry(Country::class, ['id'=>$countryId2, 'name'=>'outdated']); $region->put($key1, $entry1); $region->put($key2, $entry2); @@ -240,14 +241,14 @@ public function testBasicQueryCachePutEntityCache() $this->assertEquals($this->countries[0]->getName(), $result1[0]->getName()); $this->assertEquals($this->countries[1]->getName(), $result1[1]->getName()); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); $this->assertEquals(3, $this->secondLevelCacheLogger->getPutCount()); $this->assertEquals(1, $this->secondLevelCacheLogger->getMissCount()); $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionPutCount($this->getDefaultQueryRegionName())); $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionMissCount($this->getDefaultQueryRegionName())); - $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(Country::CLASSNAME))); + $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(Country::class))); $this->_em->clear(); @@ -266,8 +267,8 @@ public function testBasicQueryCachePutEntityCache() $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionHitCount($this->getDefaultQueryRegionName())); $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionMissCount($this->getDefaultQueryRegionName())); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\Country', $result2[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\Country', $result2[1]); + $this->assertInstanceOf(Country::class, $result2[0]); + $this->assertInstanceOf(Country::class, $result2[1]); $this->assertEquals($result1[0]->getId(), $result2[0]->getId()); $this->assertEquals($result1[1]->getId(), $result2[1]->getId()); @@ -295,9 +296,9 @@ public function testMultipleNestedDQLAliases() $this->loadFixturesAttractions(); $queryRegionName = $this->getDefaultQueryRegionName(); - $cityRegionName = $this->getEntityRegion(City::CLASSNAME); - $stateRegionName = $this->getEntityRegion(State::CLASSNAME); - $attractionRegionName = $this->getEntityRegion(Attraction::CLASSNAME); + $cityRegionName = $this->getEntityRegion(City::class); + $stateRegionName = $this->getEntityRegion(State::class); + $attractionRegionName = $this->getEntityRegion(Attraction::class); $this->secondLevelCacheLogger->clearStats(); $this->evictRegions(); @@ -312,29 +313,29 @@ public function testMultipleNestedDQLAliases() $this->assertCount(2, $result1); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $this->states[0]->getId())); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $this->states[1]->getId())); + $this->assertTrue($this->cache->containsEntity(State::class, $this->states[0]->getId())); + $this->assertTrue($this->cache->containsEntity(State::class, $this->states[1]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[0]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[1]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[2]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $this->cities[3]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[0]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[1]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[2]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $this->cities[3]->getId())); - $this->assertTrue($this->cache->containsEntity(Attraction::CLASSNAME, $this->attractions[0]->getId())); - $this->assertTrue($this->cache->containsEntity(Attraction::CLASSNAME, $this->attractions[1]->getId())); - $this->assertTrue($this->cache->containsEntity(Attraction::CLASSNAME, $this->attractions[2]->getId())); - $this->assertTrue($this->cache->containsEntity(Attraction::CLASSNAME, $this->attractions[3]->getId())); + $this->assertTrue($this->cache->containsEntity(Attraction::class, $this->attractions[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Attraction::class, $this->attractions[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Attraction::class, $this->attractions[2]->getId())); + $this->assertTrue($this->cache->containsEntity(Attraction::class, $this->attractions[3]->getId())); - $this->assertInstanceOf(State::CLASSNAME, $result1[0]); - $this->assertInstanceOf(State::CLASSNAME, $result1[1]); + $this->assertInstanceOf(State::class, $result1[0]); + $this->assertInstanceOf(State::class, $result1[1]); $this->assertCount(2, $result1[0]->getCities()); $this->assertCount(2, $result1[1]->getCities()); - $this->assertInstanceOf(City::CLASSNAME, $result1[0]->getCities()->get(0)); - $this->assertInstanceOf(City::CLASSNAME, $result1[0]->getCities()->get(1)); - $this->assertInstanceOf(City::CLASSNAME, $result1[1]->getCities()->get(0)); - $this->assertInstanceOf(City::CLASSNAME, $result1[1]->getCities()->get(1)); + $this->assertInstanceOf(City::class, $result1[0]->getCities()->get(0)); + $this->assertInstanceOf(City::class, $result1[0]->getCities()->get(1)); + $this->assertInstanceOf(City::class, $result1[1]->getCities()->get(0)); + $this->assertInstanceOf(City::class, $result1[1]->getCities()->get(1)); $this->assertCount(2, $result1[0]->getCities()->get(0)->getAttractions()); $this->assertCount(2, $result1[0]->getCities()->get(1)->getAttractions()); @@ -350,16 +351,16 @@ public function testMultipleNestedDQLAliases() $this->assertCount(2, $result2); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); - $this->assertInstanceOf(State::CLASSNAME, $result2[0]); - $this->assertInstanceOf(State::CLASSNAME, $result2[1]); + $this->assertInstanceOf(State::class, $result2[0]); + $this->assertInstanceOf(State::class, $result2[1]); $this->assertCount(2, $result2[0]->getCities()); $this->assertCount(2, $result2[1]->getCities()); - $this->assertInstanceOf(City::CLASSNAME, $result2[0]->getCities()->get(0)); - $this->assertInstanceOf(City::CLASSNAME, $result2[0]->getCities()->get(1)); - $this->assertInstanceOf(City::CLASSNAME, $result2[1]->getCities()->get(0)); - $this->assertInstanceOf(City::CLASSNAME, $result2[1]->getCities()->get(1)); + $this->assertInstanceOf(City::class, $result2[0]->getCities()->get(0)); + $this->assertInstanceOf(City::class, $result2[0]->getCities()->get(1)); + $this->assertInstanceOf(City::class, $result2[1]->getCities()->get(0)); + $this->assertInstanceOf(City::class, $result2[1]->getCities()->get(1)); $this->assertCount(2, $result2[0]->getCities()->get(0)->getAttractions()); $this->assertCount(2, $result2[0]->getCities()->get(1)->getAttractions()); @@ -374,8 +375,8 @@ public function testBasicQueryParams() $this->loadFixturesCountries(); $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); $queryCount = $this->getCurrentQueryCount(); $name = $this->countries[0]->getName(); @@ -398,7 +399,7 @@ public function testBasicQueryParams() $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); $this->assertCount(1, $result2); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\Country', $result2[0]); + $this->assertInstanceOf(Country::class, $result2[0]); $this->assertEquals($result1[0]->getId(), $result2[0]->getId()); $this->assertEquals($result1[0]->getName(), $result2[0]->getName()); @@ -411,8 +412,8 @@ public function testLoadFromDatabaseWhenEntityMissing() $this->loadFixturesCountries(); $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); $queryCount = $this->getCurrentQueryCount(); $dql = 'SELECT c FROM Doctrine\Tests\Models\Cache\Country c'; @@ -430,8 +431,8 @@ public function testLoadFromDatabaseWhenEntityMissing() $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionPutCount($this->getDefaultQueryRegionName())); $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionMissCount($this->getDefaultQueryRegionName())); - $this->cache->evictEntity(Country::CLASSNAME, $result1[0]->getId()); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $result1[0]->getId())); + $this->cache->evictEntity(Country::class, $result1[0]->getId()); + $this->assertFalse($this->cache->containsEntity(Country::class, $result1[0]->getId())); $this->_em->clear(); @@ -447,8 +448,8 @@ public function testLoadFromDatabaseWhenEntityMissing() $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getDefaultQueryRegionName())); $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionMissCount($this->getDefaultQueryRegionName())); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\Country', $result2[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\Country', $result2[1]); + $this->assertInstanceOf(Country::class, $result2[0]); + $this->assertInstanceOf(Country::class, $result2[1]); $this->assertEquals($result1[0]->getId(), $result2[0]->getId()); $this->assertEquals($result1[1]->getId(), $result2[1]->getId()); @@ -475,15 +476,15 @@ public function testBasicQueryFetchJoinsOneToMany() ->getResult(); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); - $this->assertInstanceOf(State::CLASSNAME, $result1[0]); - $this->assertInstanceOf(State::CLASSNAME, $result1[1]); + $this->assertInstanceOf(State::class, $result1[0]); + $this->assertInstanceOf(State::class, $result1[1]); $this->assertCount(2, $result1[0]->getCities()); $this->assertCount(2, $result1[1]->getCities()); - $this->assertInstanceOf(City::CLASSNAME, $result1[0]->getCities()->get(0)); - $this->assertInstanceOf(City::CLASSNAME, $result1[0]->getCities()->get(1)); - $this->assertInstanceOf(City::CLASSNAME, $result1[1]->getCities()->get(0)); - $this->assertInstanceOf(City::CLASSNAME, $result1[1]->getCities()->get(1)); + $this->assertInstanceOf(City::class, $result1[0]->getCities()->get(0)); + $this->assertInstanceOf(City::class, $result1[0]->getCities()->get(1)); + $this->assertInstanceOf(City::class, $result1[1]->getCities()->get(0)); + $this->assertInstanceOf(City::class, $result1[1]->getCities()->get(1)); $this->assertNotNull($result1[0]->getCities()->get(0)->getId()); $this->assertNotNull($result1[0]->getCities()->get(1)->getId()); @@ -501,15 +502,15 @@ public function testBasicQueryFetchJoinsOneToMany() ->setCacheable(true) ->getResult(); - $this->assertInstanceOf(State::CLASSNAME, $result2[0]); - $this->assertInstanceOf(State::CLASSNAME, $result2[1]); + $this->assertInstanceOf(State::class, $result2[0]); + $this->assertInstanceOf(State::class, $result2[1]); $this->assertCount(2, $result2[0]->getCities()); $this->assertCount(2, $result2[1]->getCities()); - $this->assertInstanceOf(City::CLASSNAME, $result2[0]->getCities()->get(0)); - $this->assertInstanceOf(City::CLASSNAME, $result2[0]->getCities()->get(1)); - $this->assertInstanceOf(City::CLASSNAME, $result2[1]->getCities()->get(0)); - $this->assertInstanceOf(City::CLASSNAME, $result2[1]->getCities()->get(1)); + $this->assertInstanceOf(City::class, $result2[0]->getCities()->get(0)); + $this->assertInstanceOf(City::class, $result2[0]->getCities()->get(1)); + $this->assertInstanceOf(City::class, $result2[1]->getCities()->get(0)); + $this->assertInstanceOf(City::class, $result2[1]->getCities()->get(1)); $this->assertNotNull($result2[0]->getCities()->get(0)->getId()); $this->assertNotNull($result2[0]->getCities()->get(1)->getId()); @@ -541,22 +542,22 @@ public function testBasicQueryFetchJoinsManyToOne() ->getResult(); $this->assertCount(4, $result1); - $this->assertInstanceOf(City::CLASSNAME, $result1[0]); - $this->assertInstanceOf(City::CLASSNAME, $result1[1]); - $this->assertInstanceOf(State::CLASSNAME, $result1[0]->getState()); - $this->assertInstanceOf(State::CLASSNAME, $result1[1]->getState()); + $this->assertInstanceOf(City::class, $result1[0]); + $this->assertInstanceOf(City::class, $result1[1]); + $this->assertInstanceOf(State::class, $result1[0]->getState()); + $this->assertInstanceOf(State::class, $result1[1]->getState()); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $result1[0]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $result1[1]->getId())); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $result1[0]->getState()->getId())); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $result1[1]->getState()->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $result1[0]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $result1[1]->getId())); + $this->assertTrue($this->cache->containsEntity(State::class, $result1[0]->getState()->getId())); + $this->assertTrue($this->cache->containsEntity(State::class, $result1[1]->getState()->getId())); $this->assertEquals(7, $this->secondLevelCacheLogger->getPutCount()); $this->assertEquals(1, $this->secondLevelCacheLogger->getMissCount()); $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionPutCount($this->getDefaultQueryRegionName())); $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionMissCount($this->getDefaultQueryRegionName())); - $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(State::CLASSNAME))); - $this->assertEquals(4, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(City::CLASSNAME))); + $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(State::class))); + $this->assertEquals(4, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(City::class))); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); @@ -568,10 +569,10 @@ public function testBasicQueryFetchJoinsManyToOne() ->getResult(); $this->assertCount(4, $result1); - $this->assertInstanceOf(City::CLASSNAME, $result2[0]); - $this->assertInstanceOf(City::CLASSNAME, $result2[1]); - $this->assertInstanceOf(State::CLASSNAME, $result2[0]->getState()); - $this->assertInstanceOf(State::CLASSNAME, $result2[1]->getState()); + $this->assertInstanceOf(City::class, $result2[0]); + $this->assertInstanceOf(City::class, $result2[1]); + $this->assertInstanceOf(State::class, $result2[0]->getState()); + $this->assertInstanceOf(State::class, $result2[1]->getState()); $this->assertNotNull($result2[0]->getId()); $this->assertNotNull($result2[0]->getId()); @@ -608,30 +609,30 @@ public function testReloadQueryIfToOneIsNotFound() ->getResult(); $this->assertCount(4, $result1); - $this->assertInstanceOf(City::CLASSNAME, $result1[0]); - $this->assertInstanceOf(City::CLASSNAME, $result1[1]); - $this->assertInstanceOf(State::CLASSNAME, $result1[0]->getState()); - $this->assertInstanceOf(State::CLASSNAME, $result1[1]->getState()); - - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $result1[0]->getId())); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $result1[1]->getId())); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $result1[0]->getState()->getId())); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $result1[1]->getState()->getId())); + $this->assertInstanceOf(City::class, $result1[0]); + $this->assertInstanceOf(City::class, $result1[1]); + $this->assertInstanceOf(State::class, $result1[0]->getState()); + $this->assertInstanceOf(State::class, $result1[1]->getState()); + + $this->assertTrue($this->cache->containsEntity(City::class, $result1[0]->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $result1[1]->getId())); + $this->assertTrue($this->cache->containsEntity(State::class, $result1[0]->getState()->getId())); + $this->assertTrue($this->cache->containsEntity(State::class, $result1[1]->getState()->getId())); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); $this->_em->clear(); - $this->cache->evictEntityRegion(State::CLASSNAME); + $this->cache->evictEntityRegion(State::class); $result2 = $this->_em->createQuery($dql) ->setCacheable(true) ->getResult(); $this->assertCount(4, $result1); - $this->assertInstanceOf(City::CLASSNAME, $result2[0]); - $this->assertInstanceOf(City::CLASSNAME, $result2[1]); - $this->assertInstanceOf(State::CLASSNAME, $result2[0]->getState()); - $this->assertInstanceOf(State::CLASSNAME, $result2[1]->getState()); + $this->assertInstanceOf(City::class, $result2[0]); + $this->assertInstanceOf(City::class, $result2[1]); + $this->assertInstanceOf(State::class, $result2[0]->getState()); + $this->assertInstanceOf(State::class, $result2[1]->getState()); $this->assertEquals($queryCount + 2, $this->getCurrentQueryCount()); } @@ -652,33 +653,33 @@ public function testReloadQueryIfToManyAssociationItemIsNotFound() ->getResult(); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); - $this->assertInstanceOf(State::CLASSNAME, $result1[0]); - $this->assertInstanceOf(State::CLASSNAME, $result1[1]); + $this->assertInstanceOf(State::class, $result1[0]); + $this->assertInstanceOf(State::class, $result1[1]); $this->assertCount(2, $result1[0]->getCities()); $this->assertCount(2, $result1[1]->getCities()); - $this->assertInstanceOf(City::CLASSNAME, $result1[0]->getCities()->get(0)); - $this->assertInstanceOf(City::CLASSNAME, $result1[0]->getCities()->get(1)); - $this->assertInstanceOf(City::CLASSNAME, $result1[1]->getCities()->get(0)); - $this->assertInstanceOf(City::CLASSNAME, $result1[1]->getCities()->get(1)); + $this->assertInstanceOf(City::class, $result1[0]->getCities()->get(0)); + $this->assertInstanceOf(City::class, $result1[0]->getCities()->get(1)); + $this->assertInstanceOf(City::class, $result1[1]->getCities()->get(0)); + $this->assertInstanceOf(City::class, $result1[1]->getCities()->get(1)); $this->_em->clear(); - $this->cache->evictEntityRegion(City::CLASSNAME); + $this->cache->evictEntityRegion(City::class); $result2 = $this->_em->createQuery($dql) ->setCacheable(true) ->getResult(); - $this->assertInstanceOf(State::CLASSNAME, $result2[0]); - $this->assertInstanceOf(State::CLASSNAME, $result2[1]); + $this->assertInstanceOf(State::class, $result2[0]); + $this->assertInstanceOf(State::class, $result2[1]); $this->assertCount(2, $result2[0]->getCities()); $this->assertCount(2, $result2[1]->getCities()); - $this->assertInstanceOf(City::CLASSNAME, $result2[0]->getCities()->get(0)); - $this->assertInstanceOf(City::CLASSNAME, $result2[0]->getCities()->get(1)); - $this->assertInstanceOf(City::CLASSNAME, $result2[1]->getCities()->get(0)); - $this->assertInstanceOf(City::CLASSNAME, $result2[1]->getCities()->get(1)); + $this->assertInstanceOf(City::class, $result2[0]->getCities()->get(0)); + $this->assertInstanceOf(City::class, $result2[0]->getCities()->get(1)); + $this->assertInstanceOf(City::class, $result2[1]->getCities()->get(0)); + $this->assertInstanceOf(City::class, $result2[1]->getCities()->get(1)); $this->assertEquals($queryCount + 2, $this->getCurrentQueryCount()); } @@ -691,11 +692,11 @@ public function testBasicNativeQueryCache() $this->secondLevelCacheLogger->clearStats(); $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); $rsm = new ResultSetMapping; - $rsm->addEntityResult(Country::CLASSNAME, 'c'); + $rsm->addEntityResult(Country::class, 'c'); $rsm->addFieldResult('c', 'name', 'name'); $rsm->addFieldResult('c', 'id', 'id'); @@ -732,8 +733,8 @@ public function testBasicNativeQueryCache() $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionHitCount($this->getDefaultQueryRegionName())); $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionMissCount($this->getDefaultQueryRegionName())); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\Country', $result2[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\Country', $result2[1]); + $this->assertInstanceOf(Country::class, $result2[0]); + $this->assertInstanceOf(Country::class, $result2[1]); $this->assertEquals($result1[0]->getId(), $result2[0]->getId()); $this->assertEquals($result1[1]->getId(), $result2[1]->getId()); @@ -827,7 +828,7 @@ public function testQueryCacheLifetime() ->getRegion() ->get($key); - $this->assertInstanceOf('Doctrine\ORM\Cache\QueryCacheEntry', $entry); + $this->assertInstanceOf(Cache\QueryCacheEntry::class, $entry); $entry->time = $entry->time / 2; $this->cache->getQueryCache() @@ -936,8 +937,8 @@ public function testResolveAssociationCacheEntry() $this->assertNotNull($state1); $this->assertNotNull($state1->getCountry()); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\State', $state1); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $state1->getCountry()); + $this->assertInstanceOf(State::class, $state1); + $this->assertInstanceOf(Proxy::class, $state1->getCountry()); $this->assertEquals($countryName, $state1->getCountry()->getName()); $this->assertEquals($stateId, $state1->getId()); @@ -954,8 +955,8 @@ public function testResolveAssociationCacheEntry() $this->assertNotNull($state2); $this->assertNotNull($state2->getCountry()); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\State', $state2); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $state2->getCountry()); + $this->assertInstanceOf(State::class, $state2); + $this->assertInstanceOf(Proxy::class, $state2->getCountry()); $this->assertEquals($countryName, $state2->getCountry()->getName()); $this->assertEquals($stateId, $state2->getId()); } @@ -983,10 +984,10 @@ public function testResolveToOneAssociationCacheEntry() ->getSingleResult(); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\City', $city1); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\State', $city1->getState()); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\City', $city1->getState()->getCities()->get(0)); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\State', $city1->getState()->getCities()->get(0)->getState()); + $this->assertInstanceOf(City::class, $city1); + $this->assertInstanceOf(State::class, $city1->getState()); + $this->assertInstanceOf(City::class, $city1->getState()->getCities()->get(0)); + $this->assertInstanceOf(State::class, $city1->getState()->getCities()->get(0)->getState()); $this->_em->clear(); @@ -999,10 +1000,10 @@ public function testResolveToOneAssociationCacheEntry() ->getSingleResult(); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\City', $city2); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\State', $city2->getState()); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\City', $city2->getState()->getCities()->get(0)); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\State', $city2->getState()->getCities()->get(0)->getState()); + $this->assertInstanceOf(City::class, $city2); + $this->assertInstanceOf(State::class, $city2->getState()); + $this->assertInstanceOf(City::class, $city2->getState()->getCities()->get(0)); + $this->assertInstanceOf(State::class, $city2->getState()->getCities()->get(0)->getState()); } public function testResolveToManyAssociationCacheEntry() @@ -1028,10 +1029,10 @@ public function testResolveToManyAssociationCacheEntry() ->getSingleResult(); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\State', $state1); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $state1->getCountry()); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\City', $state1->getCities()->get(0)); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\State', $state1->getCities()->get(0)->getState()); + $this->assertInstanceOf(State::class, $state1); + $this->assertInstanceOf(Proxy::class, $state1->getCountry()); + $this->assertInstanceOf(City::class, $state1->getCities()->get(0)); + $this->assertInstanceOf(State::class, $state1->getCities()->get(0)->getState()); $this->assertSame($state1, $state1->getCities()->get(0)->getState()); $this->_em->clear(); @@ -1045,10 +1046,10 @@ public function testResolveToManyAssociationCacheEntry() ->getSingleResult(); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\State', $state2); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $state2->getCountry()); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\City', $state2->getCities()->get(0)); - $this->assertInstanceOf('Doctrine\Tests\Models\Cache\State', $state2->getCities()->get(0)->getState()); + $this->assertInstanceOf(State::class, $state2); + $this->assertInstanceOf(Proxy::class, $state2->getCountry()); + $this->assertInstanceOf(City::class, $state2->getCities()->get(0)); + $this->assertInstanceOf(State::class, $state2->getCities()->get(0)->getState()); $this->assertSame($state2, $state2->getCities()->get(0)->getState()); } @@ -1057,15 +1058,15 @@ public function testHintClearEntityRegionUpdateStatement() $this->evictRegions(); $this->loadFixturesCountries(); - $this->assertTrue($this->cache->containsEntity('Doctrine\Tests\Models\Cache\Country', $this->countries[0]->getId())); - $this->assertTrue($this->cache->containsEntity('Doctrine\Tests\Models\Cache\Country', $this->countries[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); $this->_em->createQuery('DELETE Doctrine\Tests\Models\Cache\Country u WHERE u.id = 4') ->setHint(Query::HINT_CACHE_EVICT, true) ->execute(); - $this->assertFalse($this->cache->containsEntity('Doctrine\Tests\Models\Cache\Country', $this->countries[0]->getId())); - $this->assertFalse($this->cache->containsEntity('Doctrine\Tests\Models\Cache\Country', $this->countries[1]->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); } public function testHintClearEntityRegionDeleteStatement() @@ -1073,15 +1074,15 @@ public function testHintClearEntityRegionDeleteStatement() $this->evictRegions(); $this->loadFixturesCountries(); - $this->assertTrue($this->cache->containsEntity('Doctrine\Tests\Models\Cache\Country', $this->countries[0]->getId())); - $this->assertTrue($this->cache->containsEntity('Doctrine\Tests\Models\Cache\Country', $this->countries[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); $this->_em->createQuery("UPDATE Doctrine\Tests\Models\Cache\Country u SET u.name = 'foo' WHERE u.id = 1") ->setHint(Query::HINT_CACHE_EVICT, true) ->execute(); - $this->assertFalse($this->cache->containsEntity('Doctrine\Tests\Models\Cache\Country', $this->countries[0]->getId())); - $this->assertFalse($this->cache->containsEntity('Doctrine\Tests\Models\Cache\Country', $this->countries[1]->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); } /** @@ -1150,7 +1151,7 @@ public function testQueryCacheShouldBeEvictedOnTimestampUpdate() $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); foreach ($result2 as $entity) { - $this->assertInstanceOf(Country::CLASSNAME, $entity); + $this->assertInstanceOf(Country::class, $entity); } } } diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheRepositoryTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheRepositoryTest.php index 8e37dd9600f..c8c4303c4da 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheRepositoryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheRepositoryTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\ORM\Proxy\Proxy; use Doctrine\Tests\Models\Cache\Country; use Doctrine\Tests\Models\Cache\State; @@ -18,22 +19,22 @@ public function testRepositoryCacheFind() $this->secondLevelCacheLogger->clearStats(); $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); $queryCount = $this->getCurrentQueryCount(); - $repository = $this->_em->getRepository(Country::CLASSNAME); + $repository = $this->_em->getRepository(Country::class); $country1 = $repository->find($this->countries[0]->getId()); $country2 = $repository->find($this->countries[1]->getId()); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); - $this->assertInstanceOf(Country::CLASSNAME, $country1); - $this->assertInstanceOf(Country::CLASSNAME, $country2); + $this->assertInstanceOf(Country::class, $country1); + $this->assertInstanceOf(Country::class, $country2); $this->assertEquals(2, $this->secondLevelCacheLogger->getHitCount()); $this->assertEquals(0, $this->secondLevelCacheLogger->getMissCount()); - $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionHitCount($this->getEntityRegion(Country::CLASSNAME))); + $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionHitCount($this->getEntityRegion(Country::class))); } @@ -44,10 +45,10 @@ public function testRepositoryCacheFindAll() $this->secondLevelCacheLogger->clearStats(); $this->_em->clear(); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $this->countries[1]->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); - $repository = $this->_em->getRepository(Country::CLASSNAME); + $repository = $this->_em->getRepository(Country::class); $queryCount = $this->getCurrentQueryCount(); $this->assertCount(2, $repository->findAll()); @@ -58,14 +59,14 @@ public function testRepositoryCacheFindAll() $this->assertEquals($queryCount, $this->getCurrentQueryCount()); - $this->assertInstanceOf(Country::CLASSNAME, $countries[0]); - $this->assertInstanceOf(Country::CLASSNAME, $countries[1]); + $this->assertInstanceOf(Country::class, $countries[0]); + $this->assertInstanceOf(Country::class, $countries[1]); $this->assertEquals(3, $this->secondLevelCacheLogger->getHitCount()); $this->assertEquals(1, $this->secondLevelCacheLogger->getMissCount()); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); } public function testRepositoryCacheFindAllInvalidation() @@ -75,10 +76,10 @@ public function testRepositoryCacheFindAllInvalidation() $this->secondLevelCacheLogger->clearStats(); $this->_em->clear(); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $this->countries[1]->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); - $repository = $this->_em->getRepository(Country::CLASSNAME); + $repository = $this->_em->getRepository(Country::class); $queryCount = $this->getCurrentQueryCount(); $this->assertCount(2, $repository->findAll()); @@ -90,8 +91,8 @@ public function testRepositoryCacheFindAllInvalidation() $this->assertEquals($queryCount, $this->getCurrentQueryCount()); $this->assertCount(2, $countries); - $this->assertInstanceOf(Country::CLASSNAME, $countries[0]); - $this->assertInstanceOf(Country::CLASSNAME, $countries[1]); + $this->assertInstanceOf(Country::class, $countries[0]); + $this->assertInstanceOf(Country::class, $countries[1]); $country = new Country('foo'); @@ -123,10 +124,10 @@ public function testRepositoryCacheFindBy() $this->secondLevelCacheLogger->clearStats(); $this->_em->clear(); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); $criteria = ['name'=>$this->countries[0]->getName()]; - $repository = $this->_em->getRepository(Country::CLASSNAME); + $repository = $this->_em->getRepository(Country::class); $queryCount = $this->getCurrentQueryCount(); $this->assertCount(1, $repository->findBy($criteria)); @@ -138,12 +139,12 @@ public function testRepositoryCacheFindBy() $this->assertEquals($queryCount, $this->getCurrentQueryCount()); $this->assertCount(1, $countries); - $this->assertInstanceOf(Country::CLASSNAME, $countries[0]); + $this->assertInstanceOf(Country::class, $countries[0]); $this->assertEquals(2, $this->secondLevelCacheLogger->getHitCount()); $this->assertEquals(1, $this->secondLevelCacheLogger->getMissCount()); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); } public function testRepositoryCacheFindOneBy() @@ -153,10 +154,10 @@ public function testRepositoryCacheFindOneBy() $this->secondLevelCacheLogger->clearStats(); $this->_em->clear(); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); $criteria = ['name'=>$this->countries[0]->getName()]; - $repository = $this->_em->getRepository(Country::CLASSNAME); + $repository = $this->_em->getRepository(Country::class); $queryCount = $this->getCurrentQueryCount(); $this->assertNotNull($repository->findOneBy($criteria)); @@ -167,12 +168,12 @@ public function testRepositoryCacheFindOneBy() $this->assertEquals($queryCount, $this->getCurrentQueryCount()); - $this->assertInstanceOf(Country::CLASSNAME, $country); + $this->assertInstanceOf(Country::class, $country); $this->assertEquals(2, $this->secondLevelCacheLogger->getHitCount()); $this->assertEquals(1, $this->secondLevelCacheLogger->getMissCount()); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); } public function testRepositoryCacheFindAllToOneAssociation() @@ -186,19 +187,19 @@ public function testRepositoryCacheFindAllToOneAssociation() $this->_em->clear(); // load from database - $repository = $this->_em->getRepository(State::CLASSNAME); + $repository = $this->_em->getRepository(State::class); $queryCount = $this->getCurrentQueryCount(); $entities = $repository->findAll(); $this->assertCount(4, $entities); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); - $this->assertInstanceOf(State::CLASSNAME, $entities[0]); - $this->assertInstanceOf(State::CLASSNAME, $entities[1]); - $this->assertInstanceOf(Country::CLASSNAME, $entities[0]->getCountry()); - $this->assertInstanceOf(Country::CLASSNAME, $entities[0]->getCountry()); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $entities[0]->getCountry()); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $entities[1]->getCountry()); + $this->assertInstanceOf(State::class, $entities[0]); + $this->assertInstanceOf(State::class, $entities[1]); + $this->assertInstanceOf(Country::class, $entities[0]->getCountry()); + $this->assertInstanceOf(Country::class, $entities[0]->getCountry()); + $this->assertInstanceOf(Proxy::class, $entities[0]->getCountry()); + $this->assertInstanceOf(Proxy::class, $entities[1]->getCountry()); // load from cache $queryCount = $this->getCurrentQueryCount(); @@ -207,15 +208,15 @@ public function testRepositoryCacheFindAllToOneAssociation() $this->assertCount(4, $entities); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); - $this->assertInstanceOf(State::CLASSNAME, $entities[0]); - $this->assertInstanceOf(State::CLASSNAME, $entities[1]); - $this->assertInstanceOf(Country::CLASSNAME, $entities[0]->getCountry()); - $this->assertInstanceOf(Country::CLASSNAME, $entities[1]->getCountry()); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $entities[0]->getCountry()); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $entities[1]->getCountry()); + $this->assertInstanceOf(State::class, $entities[0]); + $this->assertInstanceOf(State::class, $entities[1]); + $this->assertInstanceOf(Country::class, $entities[0]->getCountry()); + $this->assertInstanceOf(Country::class, $entities[1]->getCountry()); + $this->assertInstanceOf(Proxy::class, $entities[0]->getCountry()); + $this->assertInstanceOf(Proxy::class, $entities[1]->getCountry()); // invalidate cache - $this->_em->persist(new State('foo', $this->_em->find(Country::CLASSNAME, $this->countries[0]->getId()))); + $this->_em->persist(new State('foo', $this->_em->find(Country::class, $this->countries[0]->getId()))); $this->_em->flush(); $this->_em->clear(); @@ -226,12 +227,12 @@ public function testRepositoryCacheFindAllToOneAssociation() $this->assertCount(5, $entities); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); - $this->assertInstanceOf(State::CLASSNAME, $entities[0]); - $this->assertInstanceOf(State::CLASSNAME, $entities[1]); - $this->assertInstanceOf(Country::CLASSNAME, $entities[0]->getCountry()); - $this->assertInstanceOf(Country::CLASSNAME, $entities[1]->getCountry()); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $entities[0]->getCountry()); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $entities[1]->getCountry()); + $this->assertInstanceOf(State::class, $entities[0]); + $this->assertInstanceOf(State::class, $entities[1]); + $this->assertInstanceOf(Country::class, $entities[0]->getCountry()); + $this->assertInstanceOf(Country::class, $entities[1]->getCountry()); + $this->assertInstanceOf(Proxy::class, $entities[0]->getCountry()); + $this->assertInstanceOf(Proxy::class, $entities[1]->getCountry()); // load from cache $queryCount = $this->getCurrentQueryCount(); @@ -240,11 +241,11 @@ public function testRepositoryCacheFindAllToOneAssociation() $this->assertCount(5, $entities); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); - $this->assertInstanceOf(State::CLASSNAME, $entities[0]); - $this->assertInstanceOf(State::CLASSNAME, $entities[1]); - $this->assertInstanceOf(Country::CLASSNAME, $entities[0]->getCountry()); - $this->assertInstanceOf(Country::CLASSNAME, $entities[1]->getCountry()); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $entities[0]->getCountry()); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $entities[1]->getCountry()); + $this->assertInstanceOf(State::class, $entities[0]); + $this->assertInstanceOf(State::class, $entities[1]); + $this->assertInstanceOf(Country::class, $entities[0]->getCountry()); + $this->assertInstanceOf(Country::class, $entities[1]->getCountry()); + $this->assertInstanceOf(Proxy::class, $entities[0]->getCountry()); + $this->assertInstanceOf(Proxy::class, $entities[1]->getCountry()); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheSingleTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheSingleTableInheritanceTest.php index 0ee1df176fd..858adb3a19c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheSingleTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheSingleTableInheritanceTest.php @@ -2,11 +2,12 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\ORM\PersistentCollection; use Doctrine\Tests\Models\Cache\Attraction; -use Doctrine\Tests\Models\Cache\Restaurant; +use Doctrine\Tests\Models\Cache\Bar; use Doctrine\Tests\Models\Cache\Beach; use Doctrine\Tests\Models\Cache\City; -use Doctrine\Tests\Models\Cache\Bar; +use Doctrine\Tests\Models\Cache\Restaurant; /** * @group DDC-2183 @@ -15,10 +16,10 @@ class SecondLevelCacheSingleTableInheritanceTest extends SecondLevelCacheAbstrac { public function testUseSameRegion() { - $attractionRegion = $this->cache->getEntityCacheRegion(Attraction::CLASSNAME); - $restaurantRegion = $this->cache->getEntityCacheRegion(Restaurant::CLASSNAME); - $beachRegion = $this->cache->getEntityCacheRegion(Beach::CLASSNAME); - $barRegion = $this->cache->getEntityCacheRegion(Bar::CLASSNAME); + $attractionRegion = $this->cache->getEntityCacheRegion(Attraction::class); + $restaurantRegion = $this->cache->getEntityCacheRegion(Restaurant::class); + $beachRegion = $this->cache->getEntityCacheRegion(Beach::class); + $barRegion = $this->cache->getEntityCacheRegion(Bar::class); $this->assertEquals($attractionRegion->getName(), $restaurantRegion->getName()); $this->assertEquals($attractionRegion->getName(), $beachRegion->getName()); @@ -34,8 +35,8 @@ public function testPutOnPersistSingleTableInheritance() $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(Bar::CLASSNAME, $this->attractions[0]->getId())); - $this->assertTrue($this->cache->containsEntity(Bar::CLASSNAME, $this->attractions[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Bar::class, $this->attractions[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Bar::class, $this->attractions[1]->getId())); } public function testCountaisRootClass() @@ -48,7 +49,7 @@ public function testCountaisRootClass() $this->_em->clear(); foreach ($this->attractions as $attraction) { - $this->assertTrue($this->cache->containsEntity(Attraction::CLASSNAME, $attraction->getId())); + $this->assertTrue($this->cache->containsEntity(Attraction::class, $attraction->getId())); $this->assertTrue($this->cache->containsEntity(get_class($attraction), $attraction->getId())); } } @@ -62,28 +63,28 @@ public function testPutAndLoadEntities() $this->_em->clear(); - $this->cache->evictEntityRegion(Attraction::CLASSNAME); + $this->cache->evictEntityRegion(Attraction::class); $entityId1 = $this->attractions[0]->getId(); $entityId2 = $this->attractions[1]->getId(); - $this->assertFalse($this->cache->containsEntity(Attraction::CLASSNAME, $entityId1)); - $this->assertFalse($this->cache->containsEntity(Attraction::CLASSNAME, $entityId2)); - $this->assertFalse($this->cache->containsEntity(Bar::CLASSNAME, $entityId1)); - $this->assertFalse($this->cache->containsEntity(Bar::CLASSNAME, $entityId2)); + $this->assertFalse($this->cache->containsEntity(Attraction::class, $entityId1)); + $this->assertFalse($this->cache->containsEntity(Attraction::class, $entityId2)); + $this->assertFalse($this->cache->containsEntity(Bar::class, $entityId1)); + $this->assertFalse($this->cache->containsEntity(Bar::class, $entityId2)); - $entity1 = $this->_em->find(Attraction::CLASSNAME, $entityId1); - $entity2 = $this->_em->find(Attraction::CLASSNAME, $entityId2); + $entity1 = $this->_em->find(Attraction::class, $entityId1); + $entity2 = $this->_em->find(Attraction::class, $entityId2); - $this->assertTrue($this->cache->containsEntity(Attraction::CLASSNAME, $entityId1)); - $this->assertTrue($this->cache->containsEntity(Attraction::CLASSNAME, $entityId2)); - $this->assertTrue($this->cache->containsEntity(Bar::CLASSNAME, $entityId1)); - $this->assertTrue($this->cache->containsEntity(Bar::CLASSNAME, $entityId2)); + $this->assertTrue($this->cache->containsEntity(Attraction::class, $entityId1)); + $this->assertTrue($this->cache->containsEntity(Attraction::class, $entityId2)); + $this->assertTrue($this->cache->containsEntity(Bar::class, $entityId1)); + $this->assertTrue($this->cache->containsEntity(Bar::class, $entityId2)); - $this->assertInstanceOf(Attraction::CLASSNAME, $entity1); - $this->assertInstanceOf(Attraction::CLASSNAME, $entity2); - $this->assertInstanceOf(Bar::CLASSNAME, $entity1); - $this->assertInstanceOf(Bar::CLASSNAME, $entity2); + $this->assertInstanceOf(Attraction::class, $entity1); + $this->assertInstanceOf(Attraction::class, $entity2); + $this->assertInstanceOf(Bar::class, $entity1); + $this->assertInstanceOf(Bar::class, $entity2); $this->assertEquals($this->attractions[0]->getId(), $entity1->getId()); $this->assertEquals($this->attractions[0]->getName(), $entity1->getName()); @@ -95,15 +96,15 @@ public function testPutAndLoadEntities() $queryCount = $this->getCurrentQueryCount(); - $entity3 = $this->_em->find(Attraction::CLASSNAME, $entityId1); - $entity4 = $this->_em->find(Attraction::CLASSNAME, $entityId2); + $entity3 = $this->_em->find(Attraction::class, $entityId1); + $entity4 = $this->_em->find(Attraction::class, $entityId2); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); - $this->assertInstanceOf(Attraction::CLASSNAME, $entity3); - $this->assertInstanceOf(Attraction::CLASSNAME, $entity4); - $this->assertInstanceOf(Bar::CLASSNAME, $entity3); - $this->assertInstanceOf(Bar::CLASSNAME, $entity4); + $this->assertInstanceOf(Attraction::class, $entity3); + $this->assertInstanceOf(Attraction::class, $entity4); + $this->assertInstanceOf(Bar::class, $entity3); + $this->assertInstanceOf(Bar::class, $entity4); $this->assertNotSame($entity1, $entity3); $this->assertEquals($entity1->getId(), $entity3->getId()); @@ -142,7 +143,7 @@ public function testQueryCacheFindAll() $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); foreach ($result2 as $entity) { - $this->assertInstanceOf(Attraction::CLASSNAME, $entity); + $this->assertInstanceOf(Attraction::class, $entity); } } @@ -156,12 +157,12 @@ public function testShouldNotPutOneToManyRelationOnPersist() $this->_em->clear(); foreach ($this->cities as $city) { - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $city->getId())); - $this->assertFalse($this->cache->containsCollection(City::CLASSNAME, 'attractions', $city->getId())); + $this->assertTrue($this->cache->containsEntity(City::class, $city->getId())); + $this->assertFalse($this->cache->containsCollection(City::class, 'attractions', $city->getId())); } foreach ($this->attractions as $attraction) { - $this->assertTrue($this->cache->containsEntity(Attraction::CLASSNAME, $attraction->getId())); + $this->assertTrue($this->cache->containsEntity(Attraction::class, $attraction->getId())); } } @@ -172,41 +173,41 @@ public function testOneToManyRelationSingleTable() $this->loadFixturesCities(); $this->loadFixturesAttractions(); - $this->cache->evictEntityRegion(City::CLASSNAME); - $this->cache->evictEntityRegion(Attraction::CLASSNAME); - $this->cache->evictCollectionRegion(City::CLASSNAME, 'attractions'); + $this->cache->evictEntityRegion(City::class); + $this->cache->evictEntityRegion(Attraction::class); + $this->cache->evictCollectionRegion(City::class, 'attractions'); $this->_em->clear(); - $entity = $this->_em->find(City::CLASSNAME, $this->cities[0]->getId()); + $entity = $this->_em->find(City::class, $this->cities[0]->getId()); - $this->assertInstanceOf(City::CLASSNAME, $entity); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $entity->getAttractions()); + $this->assertInstanceOf(City::class, $entity); + $this->assertInstanceOf(PersistentCollection::class, $entity->getAttractions()); $this->assertCount(2, $entity->getAttractions()); $ownerId = $this->cities[0]->getId(); $queryCount = $this->getCurrentQueryCount(); - $this->assertTrue($this->cache->containsEntity(City::CLASSNAME, $ownerId)); - $this->assertTrue($this->cache->containsCollection(City::CLASSNAME, 'attractions', $ownerId)); + $this->assertTrue($this->cache->containsEntity(City::class, $ownerId)); + $this->assertTrue($this->cache->containsCollection(City::class, 'attractions', $ownerId)); - $this->assertInstanceOf(Bar::CLASSNAME, $entity->getAttractions()->get(0)); - $this->assertInstanceOf(Bar::CLASSNAME, $entity->getAttractions()->get(1)); + $this->assertInstanceOf(Bar::class, $entity->getAttractions()->get(0)); + $this->assertInstanceOf(Bar::class, $entity->getAttractions()->get(1)); $this->assertEquals($this->attractions[0]->getName(), $entity->getAttractions()->get(0)->getName()); $this->assertEquals($this->attractions[1]->getName(), $entity->getAttractions()->get(1)->getName()); $this->_em->clear(); - $entity = $this->_em->find(City::CLASSNAME, $ownerId); + $entity = $this->_em->find(City::class, $ownerId); - $this->assertInstanceOf(City::CLASSNAME, $entity); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $entity->getAttractions()); + $this->assertInstanceOf(City::class, $entity); + $this->assertInstanceOf(PersistentCollection::class, $entity->getAttractions()); $this->assertCount(2, $entity->getAttractions()); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); - $this->assertInstanceOf(Bar::CLASSNAME, $entity->getAttractions()->get(0)); - $this->assertInstanceOf(Bar::CLASSNAME, $entity->getAttractions()->get(1)); + $this->assertInstanceOf(Bar::class, $entity->getAttractions()->get(0)); + $this->assertInstanceOf(Bar::class, $entity->getAttractions()->get(1)); $this->assertEquals($this->attractions[0]->getName(), $entity->getAttractions()->get(0)->getName()); $this->assertEquals($this->attractions[1]->getName(), $entity->getAttractions()->get(1)->getName()); } @@ -248,7 +249,7 @@ public function testQueryCacheShouldBeEvictedOnTimestampUpdate() $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); foreach ($result2 as $entity) { - $this->assertInstanceOf(Attraction::CLASSNAME, $entity); + $this->assertInstanceOf(Attraction::class, $entity); } } } diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheTest.php index 79044395a8f..32047dda39b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheTest.php @@ -16,10 +16,10 @@ public function testPutOnPersist() $this->loadFixturesCountries(); $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); $this->assertEquals(2, $this->secondLevelCacheLogger->getPutCount()); - $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(Country::CLASSNAME))); + $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(Country::class))); } public function testPutAndLoadEntities() @@ -28,21 +28,21 @@ public function testPutAndLoadEntities() $this->_em->clear(); $this->assertEquals(2, $this->secondLevelCacheLogger->getPutCount()); - $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(Country::CLASSNAME))); + $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(Country::class))); - $this->cache->evictEntityRegion(Country::CLASSNAME); + $this->cache->evictEntityRegion(Country::class); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $this->countries[1]->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); - $c1 = $this->_em->find(Country::CLASSNAME, $this->countries[0]->getId()); - $c2 = $this->_em->find(Country::CLASSNAME, $this->countries[1]->getId()); + $c1 = $this->_em->find(Country::class, $this->countries[0]->getId()); + $c2 = $this->_em->find(Country::class, $this->countries[1]->getId()); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); - $this->assertInstanceOf(Country::CLASSNAME, $c1); - $this->assertInstanceOf(Country::CLASSNAME, $c2); + $this->assertInstanceOf(Country::class, $c1); + $this->assertInstanceOf(Country::class, $c2); $this->assertEquals($this->countries[0]->getId(), $c1->getId()); $this->assertEquals($this->countries[0]->getName(), $c1->getName()); @@ -54,15 +54,15 @@ public function testPutAndLoadEntities() $queryCount = $this->getCurrentQueryCount(); - $c3 = $this->_em->find(Country::CLASSNAME, $this->countries[0]->getId()); - $c4 = $this->_em->find(Country::CLASSNAME, $this->countries[1]->getId()); + $c3 = $this->_em->find(Country::class, $this->countries[0]->getId()); + $c4 = $this->_em->find(Country::class, $this->countries[1]->getId()); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); $this->assertEquals(2, $this->secondLevelCacheLogger->getHitCount()); - $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionHitCount($this->getEntityRegion(Country::CLASSNAME))); + $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionHitCount($this->getEntityRegion(Country::class))); - $this->assertInstanceOf(Country::CLASSNAME, $c3); - $this->assertInstanceOf(Country::CLASSNAME, $c4); + $this->assertInstanceOf(Country::class, $c3); + $this->assertInstanceOf(Country::class, $c4); $this->assertEquals($c1->getId(), $c3->getId()); $this->assertEquals($c1->getName(), $c3->getName()); @@ -78,23 +78,23 @@ public function testRemoveEntities() $this->assertEquals(2, $this->secondLevelCacheLogger->getPutCount()); - $this->cache->evictEntityRegion(Country::CLASSNAME); - $this->secondLevelCacheLogger->clearRegionStats($this->getEntityRegion(Country::CLASSNAME)); + $this->cache->evictEntityRegion(Country::class); + $this->secondLevelCacheLogger->clearRegionStats($this->getEntityRegion(Country::class)); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $this->countries[1]->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); - $c1 = $this->_em->find(Country::CLASSNAME, $this->countries[0]->getId()); - $c2 = $this->_em->find(Country::CLASSNAME, $this->countries[1]->getId()); + $c1 = $this->_em->find(Country::class, $this->countries[0]->getId()); + $c2 = $this->_em->find(Country::class, $this->countries[1]->getId()); $this->assertEquals(2, $this->secondLevelCacheLogger->getPutCount()); $this->assertEquals(2, $this->secondLevelCacheLogger->getMissCount()); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $this->countries[1]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); - $this->assertInstanceOf(Country::CLASSNAME, $c1); - $this->assertInstanceOf(Country::CLASSNAME, $c2); + $this->assertInstanceOf(Country::class, $c1); + $this->assertInstanceOf(Country::class, $c2); $this->assertEquals($this->countries[0]->getId(), $c1->getId()); $this->assertEquals($this->countries[0]->getName(), $c1->getName()); @@ -107,11 +107,11 @@ public function testRemoveEntities() $this->_em->flush(); $this->_em->clear(); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $this->countries[0]->getId())); - $this->assertFalse($this->cache->containsEntity(Country::CLASSNAME, $this->countries[1]->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->countries[0]->getId())); + $this->assertFalse($this->cache->containsEntity(Country::class, $this->countries[1]->getId())); - $this->assertNull($this->_em->find(Country::CLASSNAME, $this->countries[0]->getId())); - $this->assertNull($this->_em->find(Country::CLASSNAME, $this->countries[1]->getId())); + $this->assertNull($this->_em->find(Country::class, $this->countries[0]->getId())); + $this->assertNull($this->_em->find(Country::class, $this->countries[1]->getId())); $this->assertEquals(2, $this->secondLevelCacheLogger->getPutCount()); $this->assertEquals(2, $this->secondLevelCacheLogger->getMissCount()); @@ -124,27 +124,27 @@ public function testUpdateEntities() $this->_em->clear(); $this->assertEquals(6, $this->secondLevelCacheLogger->getPutCount()); - $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(Country::CLASSNAME))); - $this->assertEquals(4, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(State::CLASSNAME))); + $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(Country::class))); + $this->assertEquals(4, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(State::class))); - $this->cache->evictEntityRegion(State::CLASSNAME); - $this->secondLevelCacheLogger->clearRegionStats($this->getEntityRegion(State::CLASSNAME)); + $this->cache->evictEntityRegion(State::class); + $this->secondLevelCacheLogger->clearRegionStats($this->getEntityRegion(State::class)); - $this->assertFalse($this->cache->containsEntity(State::CLASSNAME, $this->states[0]->getId())); - $this->assertFalse($this->cache->containsEntity(State::CLASSNAME, $this->states[1]->getId())); + $this->assertFalse($this->cache->containsEntity(State::class, $this->states[0]->getId())); + $this->assertFalse($this->cache->containsEntity(State::class, $this->states[1]->getId())); - $s1 = $this->_em->find(State::CLASSNAME, $this->states[0]->getId()); - $s2 = $this->_em->find(State::CLASSNAME, $this->states[1]->getId()); + $s1 = $this->_em->find(State::class, $this->states[0]->getId()); + $s2 = $this->_em->find(State::class, $this->states[1]->getId()); $this->assertEquals(4, $this->secondLevelCacheLogger->getPutCount()); - $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(Country::CLASSNAME))); - $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(State::CLASSNAME))); + $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(Country::class))); + $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(State::class))); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $this->states[0]->getId())); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $this->states[1]->getId())); + $this->assertTrue($this->cache->containsEntity(State::class, $this->states[0]->getId())); + $this->assertTrue($this->cache->containsEntity(State::class, $this->states[1]->getId())); - $this->assertInstanceOf(State::CLASSNAME, $s1); - $this->assertInstanceOf(State::CLASSNAME, $s2); + $this->assertInstanceOf(State::class, $s1); + $this->assertInstanceOf(State::class, $s2); $this->assertEquals($this->states[0]->getId(), $s1->getId()); $this->assertEquals($this->states[0]->getName(), $s1->getName()); @@ -160,28 +160,28 @@ public function testUpdateEntities() $this->_em->flush(); $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $this->states[0]->getId())); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $this->states[1]->getId())); + $this->assertTrue($this->cache->containsEntity(State::class, $this->states[0]->getId())); + $this->assertTrue($this->cache->containsEntity(State::class, $this->states[1]->getId())); $this->assertEquals(6, $this->secondLevelCacheLogger->getPutCount()); - $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(Country::CLASSNAME))); - $this->assertEquals(4, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(State::CLASSNAME))); + $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(Country::class))); + $this->assertEquals(4, $this->secondLevelCacheLogger->getRegionPutCount($this->getEntityRegion(State::class))); $queryCount = $this->getCurrentQueryCount(); - $c3 = $this->_em->find(State::CLASSNAME, $this->states[0]->getId()); - $c4 = $this->_em->find(State::CLASSNAME, $this->states[1]->getId()); + $c3 = $this->_em->find(State::class, $this->states[0]->getId()); + $c4 = $this->_em->find(State::class, $this->states[1]->getId()); $this->assertEquals(2, $this->secondLevelCacheLogger->getHitCount()); - $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionHitCount($this->getEntityRegion(State::CLASSNAME))); + $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionHitCount($this->getEntityRegion(State::class))); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $this->states[0]->getId())); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $this->states[1]->getId())); + $this->assertTrue($this->cache->containsEntity(State::class, $this->states[0]->getId())); + $this->assertTrue($this->cache->containsEntity(State::class, $this->states[1]->getId())); - $this->assertInstanceOf(State::CLASSNAME, $c3); - $this->assertInstanceOf(State::CLASSNAME, $c4); + $this->assertInstanceOf(State::class, $c3); + $this->assertInstanceOf(State::class, $c4); $this->assertEquals($s1->getId(), $c3->getId()); $this->assertEquals("NEW NAME 1", $c3->getName()); @@ -190,7 +190,7 @@ public function testUpdateEntities() $this->assertEquals("NEW NAME 2", $c4->getName()); $this->assertEquals(2, $this->secondLevelCacheLogger->getHitCount()); - $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionHitCount($this->getEntityRegion(State::CLASSNAME))); + $this->assertEquals(2, $this->secondLevelCacheLogger->getRegionHitCount($this->getEntityRegion(State::class))); } public function testPostFlushFailure() @@ -208,7 +208,7 @@ public function testPostFlushFailure() $country = new Country("Brazil"); - $this->cache->evictEntityRegion(Country::CLASSNAME); + $this->cache->evictEntityRegion(Country::class); try { @@ -219,7 +219,7 @@ public function testPostFlushFailure() } catch (\RuntimeException $exc) { $this->assertNotNull($country->getId()); $this->assertEquals('post flush failure', $exc->getMessage()); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $country->getId())); + $this->assertTrue($this->cache->containsEntity(Country::class, $country->getId())); } } @@ -240,14 +240,14 @@ public function testPostUpdateFailure() $this->_em->getEventManager() ->addEventListener(Events::postUpdate, $listener); - $this->cache->evictEntityRegion(State::CLASSNAME); + $this->cache->evictEntityRegion(State::class); $stateId = $this->states[0]->getId(); $stateName = $this->states[0]->getName(); - $state = $this->_em->find(State::CLASSNAME, $stateId); + $state = $this->_em->find(State::class, $stateId); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $stateId)); - $this->assertInstanceOf(State::CLASSNAME, $state); + $this->assertTrue($this->cache->containsEntity(State::class, $stateId)); + $this->assertInstanceOf(State::class, $state); $this->assertEquals($stateName, $state->getName()); $state->setName($stateName . uniqid()); @@ -264,11 +264,11 @@ public function testPostUpdateFailure() $this->_em->clear(); - $this->assertTrue($this->cache->containsEntity(State::CLASSNAME, $stateId)); + $this->assertTrue($this->cache->containsEntity(State::class, $stateId)); - $state = $this->_em->find(State::CLASSNAME, $stateId); + $state = $this->_em->find(State::class, $stateId); - $this->assertInstanceOf(State::CLASSNAME, $state); + $this->assertInstanceOf(State::class, $state); $this->assertEquals($stateName, $state->getName()); } @@ -288,13 +288,13 @@ public function testPostRemoveFailure() $this->_em->getEventManager() ->addEventListener(Events::postRemove, $listener); - $this->cache->evictEntityRegion(Country::CLASSNAME); + $this->cache->evictEntityRegion(Country::class); $countryId = $this->countries[0]->getId(); - $country = $this->_em->find(Country::CLASSNAME, $countryId); + $country = $this->_em->find(Country::class, $countryId); - $this->assertTrue($this->cache->containsEntity(Country::CLASSNAME, $countryId)); - $this->assertInstanceOf(Country::CLASSNAME, $country); + $this->assertTrue($this->cache->containsEntity(Country::class, $countryId)); + $this->assertInstanceOf(Country::class, $country); $this->_em->remove($country); @@ -309,18 +309,18 @@ public function testPostRemoveFailure() $this->_em->clear(); $this->assertFalse( - $this->cache->containsEntity(Country::CLASSNAME, $countryId), + $this->cache->containsEntity(Country::class, $countryId), 'Removal attempts should clear the cache entry corresponding to the entity' ); - $this->assertInstanceOf(Country::CLASSNAME, $this->_em->find(Country::CLASSNAME, $countryId)); + $this->assertInstanceOf(Country::class, $this->_em->find(Country::class, $countryId)); } public function testCachedNewEntityExists() { $this->loadFixturesCountries(); - $persister = $this->_em->getUnitOfWork()->getEntityPersister(Country::CLASSNAME); + $persister = $this->_em->getUnitOfWork()->getEntityPersister(Country::class); $queryCount = $this->getCurrentQueryCount(); $this->assertTrue($persister->exists($this->countries[0])); diff --git a/tests/Doctrine/Tests/ORM/Functional/SequenceEmulatedIdentityStrategyTest.php b/tests/Doctrine/Tests/ORM/Functional/SequenceEmulatedIdentityStrategyTest.php index 812d56d31d2..d425936f5bd 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SequenceEmulatedIdentityStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SequenceEmulatedIdentityStrategyTest.php @@ -21,7 +21,7 @@ protected function setUp() } else { try { $this->_schemaTool->createSchema( - [$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\SequenceEmulatedIdentityEntity')] + [$this->_em->getClassMetadata(SequenceEmulatedIdentityEntity::class)] ); } catch (\Exception $e) { // Swallow all exceptions. We do not test the schema tool here. diff --git a/tests/Doctrine/Tests/ORM/Functional/SequenceGeneratorTest.php b/tests/Doctrine/Tests/ORM/Functional/SequenceGeneratorTest.php index f77e1b0daad..13091c5e50b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SequenceGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SequenceGeneratorTest.php @@ -21,7 +21,7 @@ public function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\SequenceEntity'), + $this->_em->getClassMetadata(SequenceEntity::class), ] ); } catch(\Exception $e) { diff --git a/tests/Doctrine/Tests/ORM/Functional/SingleTableCompositeKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/SingleTableCompositeKeyTest.php index 80cf1596f53..091c79f5412 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SingleTableCompositeKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SingleTableCompositeKeyTest.php @@ -1,8 +1,9 @@ _em->find( - 'Doctrine\Tests\Models\CompositeKeyInheritance\SingleRootClass', - ['keyPart1' => 'part-1', 'keyPart2' => 'part-2'] - ); + return $this->_em->find(SingleRootClass::class, ['keyPart1' => 'part-1', 'keyPart2' => 'part-2']); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php index 380f84b8bc7..5bafffd790f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php @@ -2,9 +2,11 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\Common\Collections\Criteria; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Persisters\PersisterException; +use Doctrine\ORM\Proxy\Proxy; +use Doctrine\Tests\Models\Company\CompanyContract; use Doctrine\Tests\Models\Company\CompanyEmployee; use Doctrine\Tests\Models\Company\CompanyFixContract; use Doctrine\Tests\Models\Company\CompanyFlexContract; @@ -110,9 +112,9 @@ public function testPersistChildOfBaseClass() $this->_em->flush(); $this->_em->clear(); - $contract = $this->_em->find('Doctrine\Tests\Models\Company\CompanyFixContract', $fixContract->getId()); + $contract = $this->_em->find(CompanyFixContract::class, $fixContract->getId()); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyFixContract', $contract); + $this->assertInstanceOf(CompanyFixContract::class, $contract); $this->assertEquals(1000, $contract->getFixPrice()); $this->assertEquals($this->salesPerson->getId(), $contract->getSalesPerson()->getId()); } @@ -131,9 +133,9 @@ public function testPersistDeepChildOfBaseClass() $this->_em->flush(); $this->_em->clear(); - $contract = $this->_em->find('Doctrine\Tests\Models\Company\CompanyFlexUltraContract', $ultraContract->getId()); + $contract = $this->_em->find(CompanyFlexUltraContract::class, $ultraContract->getId()); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyFlexUltraContract', $contract); + $this->assertInstanceOf(CompanyFlexUltraContract::class, $contract); $this->assertEquals(7000, $contract->getMaxPrice()); $this->assertEquals(100, $contract->getHoursWorked()); $this->assertEquals(50, $contract->getPricePerHour()); @@ -143,13 +145,13 @@ public function testChildClassLifecycleUpdate() { $this->loadFullFixture(); - $fix = $this->_em->find('Doctrine\Tests\Models\Company\CompanyContract', $this->fix->getId()); + $fix = $this->_em->find(CompanyContract::class, $this->fix->getId()); $fix->setFixPrice(2500); $this->_em->flush(); $this->_em->clear(); - $newFix = $this->_em->find('Doctrine\Tests\Models\Company\CompanyContract', $this->fix->getId()); + $newFix = $this->_em->find(CompanyContract::class, $this->fix->getId()); $this->assertEquals(2500, $newFix->getFixPrice()); } @@ -157,38 +159,38 @@ public function testChildClassLifecycleRemove() { $this->loadFullFixture(); - $fix = $this->_em->find('Doctrine\Tests\Models\Company\CompanyContract', $this->fix->getId()); + $fix = $this->_em->find(CompanyContract::class, $this->fix->getId()); $this->_em->remove($fix); $this->_em->flush(); - $this->assertNull($this->_em->find('Doctrine\Tests\Models\Company\CompanyContract', $this->fix->getId())); + $this->assertNull($this->_em->find(CompanyContract::class, $this->fix->getId())); } public function testFindAllForAbstractBaseClass() { $this->loadFullFixture(); - $contracts = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyContract')->findAll(); + $contracts = $this->_em->getRepository(CompanyContract::class)->findAll(); $this->assertEquals(3, count($contracts)); - $this->assertContainsOnly('Doctrine\Tests\Models\Company\CompanyContract', $contracts); + $this->assertContainsOnly(CompanyContract::class, $contracts); } public function testFindAllForChildClass() { $this->loadFullFixture(); - $this->assertEquals(1, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyFixContract')->findAll())); - $this->assertEquals(2, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyFlexContract')->findAll())); - $this->assertEquals(1, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyFlexUltraContract')->findAll())); + $this->assertEquals(1, count($this->_em->getRepository(CompanyFixContract::class)->findAll())); + $this->assertEquals(2, count($this->_em->getRepository(CompanyFlexContract::class)->findAll())); + $this->assertEquals(1, count($this->_em->getRepository(CompanyFlexUltraContract::class)->findAll())); } public function testFindForAbstractBaseClass() { $this->loadFullFixture(); - $contract = $this->_em->find('Doctrine\Tests\Models\Company\CompanyContract', $this->fix->getId()); + $contract = $this->_em->find(CompanyContract::class, $this->fix->getId()); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyFixContract', $contract); + $this->assertInstanceOf(CompanyFixContract::class, $contract); $this->assertEquals(1000, $contract->getFixPrice()); } @@ -199,7 +201,7 @@ public function testQueryForAbstractBaseClass() $contracts = $this->_em->createQuery('SELECT c FROM Doctrine\Tests\Models\Company\CompanyContract c')->getResult(); $this->assertEquals(3, count($contracts)); - $this->assertContainsOnly('Doctrine\Tests\Models\Company\CompanyContract', $contracts); + $this->assertContainsOnly(CompanyContract::class, $contracts); } public function testQueryForChildClass() @@ -217,7 +219,7 @@ public function testQueryBaseClassWithJoin() $contracts = $this->_em->createQuery('SELECT c, p FROM Doctrine\Tests\Models\Company\CompanyContract c JOIN c.salesPerson p')->getResult(); $this->assertEquals(3, count($contracts)); - $this->assertContainsOnly('Doctrine\Tests\Models\Company\CompanyContract', $contracts); + $this->assertContainsOnly(CompanyContract::class, $contracts); } public function testQueryScalarWithDiscriminatorValue() @@ -242,7 +244,7 @@ public function testQueryChildClassWithCondition() $dql = 'SELECT c FROM Doctrine\Tests\Models\Company\CompanyFixContract c WHERE c.fixPrice = ?1'; $contract = $this->_em->createQuery($dql)->setParameter(1, 1000)->getSingleResult(); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyFixContract', $contract); + $this->assertInstanceOf(CompanyFixContract::class, $contract); $this->assertEquals(1000, $contract->getFixPrice()); } @@ -258,8 +260,8 @@ public function testUpdateChildClassWithCondition() $this->assertEquals(1, $affected); - $flexContract = $this->_em->find('Doctrine\Tests\Models\Company\CompanyContract', $this->flex->getId()); - $ultraContract = $this->_em->find('Doctrine\Tests\Models\Company\CompanyContract', $this->ultra->getId()); + $flexContract = $this->_em->find(CompanyContract::class, $this->flex->getId()); + $ultraContract = $this->_em->find(CompanyContract::class, $this->ultra->getId()); $this->assertEquals(300, $ultraContract->getHoursWorked()); $this->assertEquals(100, $flexContract->getHoursWorked()); @@ -326,19 +328,19 @@ public function testFindByAssociation() { $this->loadFullFixture(); - $repos = $this->_em->getRepository("Doctrine\Tests\Models\Company\CompanyContract"); + $repos = $this->_em->getRepository(CompanyContract::class); $contracts = $repos->findBy(['salesPerson' => $this->salesPerson->getId()]); $this->assertEquals(3, count($contracts), "There should be 3 entities related to " . $this->salesPerson->getId() . " for 'Doctrine\Tests\Models\Company\CompanyContract'"); - $repos = $this->_em->getRepository("Doctrine\Tests\Models\Company\CompanyFixContract"); + $repos = $this->_em->getRepository(CompanyFixContract::class); $contracts = $repos->findBy(['salesPerson' => $this->salesPerson->getId()]); $this->assertEquals(1, count($contracts), "There should be 1 entities related to " . $this->salesPerson->getId() . " for 'Doctrine\Tests\Models\Company\CompanyFixContract'"); - $repos = $this->_em->getRepository("Doctrine\Tests\Models\Company\CompanyFlexContract"); + $repos = $this->_em->getRepository(CompanyFlexContract::class); $contracts = $repos->findBy(['salesPerson' => $this->salesPerson->getId()]); $this->assertEquals(2, count($contracts), "There should be 2 entities related to " . $this->salesPerson->getId() . " for 'Doctrine\Tests\Models\Company\CompanyFlexContract'"); - $repos = $this->_em->getRepository("Doctrine\Tests\Models\Company\CompanyFlexUltraContract"); + $repos = $this->_em->getRepository(CompanyFlexUltraContract::class); $contracts = $repos->findBy(['salesPerson' => $this->salesPerson->getId()]); $this->assertEquals(1, count($contracts), "There should be 1 entities related to " . $this->salesPerson->getId() . " for 'Doctrine\Tests\Models\Company\CompanyFlexUltraContract'"); } @@ -350,13 +352,13 @@ public function testInheritanceMatching() { $this->loadFullFixture(); - $repository = $this->_em->getRepository("Doctrine\Tests\Models\Company\CompanyContract"); + $repository = $this->_em->getRepository(CompanyContract::class); $contracts = $repository->matching(new Criteria( Criteria::expr()->eq('salesPerson', $this->salesPerson) )); $this->assertEquals(3, count($contracts)); - $repository = $this->_em->getRepository("Doctrine\Tests\Models\Company\CompanyFixContract"); + $repository = $this->_em->getRepository(CompanyFixContract::class); $contracts = $repository->matching(new Criteria( Criteria::expr()->eq('salesPerson', $this->salesPerson) )); @@ -370,7 +372,7 @@ public function testMatchingNonObjectOnAssocationThrowsException() { $this->loadFullFixture(); - $repository = $this->_em->getRepository("Doctrine\Tests\Models\Company\CompanyContract"); + $repository = $this->_em->getRepository(CompanyContract::class); $this->expectException(PersisterException::class); $this->expectExceptionMessage('annot match on Doctrine\Tests\Models\Company\CompanyContract::salesPerson with a non-object value.'); @@ -390,14 +392,14 @@ public function testGetReferenceEntityWithSubclasses() { $this->loadFullFixture(); - $ref = $this->_em->getReference('Doctrine\Tests\Models\Company\CompanyContract', $this->fix->getId()); - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $ref, "Cannot Request a proxy from a class that has subclasses."); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyContract', $ref); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyFixContract', $ref, "Direct fetch of the reference has to load the child class Employee directly."); + $ref = $this->_em->getReference(CompanyContract::class, $this->fix->getId()); + $this->assertNotInstanceOf(Proxy::class, $ref, "Cannot Request a proxy from a class that has subclasses."); + $this->assertInstanceOf(CompanyContract::class, $ref); + $this->assertInstanceOf(CompanyFixContract::class, $ref, "Direct fetch of the reference has to load the child class Employee directly."); $this->_em->clear(); - $ref = $this->_em->getReference('Doctrine\Tests\Models\Company\CompanyFixContract', $this->fix->getId()); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $ref, "A proxy can be generated only if no subclasses exists for the requested reference."); + $ref = $this->_em->getReference(CompanyFixContract::class, $this->fix->getId()); + $this->assertInstanceOf(Proxy::class, $ref, "A proxy can be generated only if no subclasses exists for the requested reference."); } /** @@ -409,10 +411,10 @@ public function testEagerLoadInheritanceHierarchy() $dql = 'SELECT f FROM Doctrine\Tests\Models\Company\CompanyFixContract f WHERE f.id = ?1'; $contract = $this->_em->createQuery($dql) - ->setFetchMode('Doctrine\Tests\Models\Company\CompanyFixContract', 'salesPerson', ClassMetadata::FETCH_EAGER) + ->setFetchMode(CompanyFixContract::class, 'salesPerson', ClassMetadata::FETCH_EAGER) ->setParameter(1, $this->fix->getId()) ->getSingleResult(); - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $contract->getSalesPerson()); + $this->assertNotInstanceOf(Proxy::class, $contract->getSalesPerson()); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php b/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php index f7f651f1edb..bef1f768212 100644 --- a/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php @@ -2,12 +2,11 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\Tests\Models\ECommerce\ECommerceCart, - Doctrine\Tests\Models\ECommerce\ECommerceFeature, - Doctrine\Tests\Models\ECommerce\ECommerceCustomer, - Doctrine\Tests\Models\ECommerce\ECommerceProduct; - -use Doctrine\ORM\Mapping\AssociationMapping; +use Doctrine\ORM\PersistentCollection; +use Doctrine\Tests\Models\ECommerce\ECommerceCart; +use Doctrine\Tests\Models\ECommerce\ECommerceCustomer; +use Doctrine\Tests\Models\ECommerce\ECommerceFeature; +use Doctrine\Tests\Models\ECommerce\ECommerceProduct; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -35,9 +34,9 @@ public function testAcceptsForeignKeysAsCriteria() $cardId = $cart->getId(); unset($cart); - $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceCart'); + $class = $this->_em->getClassMetadata(ECommerceCart::class); - $persister = $this->_em->getUnitOfWork()->getEntityPersister('Doctrine\Tests\Models\ECommerce\ECommerceCart'); + $persister = $this->_em->getUnitOfWork()->getEntityPersister(ECommerceCart::class); $newCart = new ECommerceCart(); $this->_em->getUnitOfWork()->registerManaged($newCart, ['id' => $cardId], []); $persister->load(['customer_id' => $customer->getId()], $newCart, $class->associationMappings['customer']); @@ -63,7 +62,7 @@ public function testAddPersistRetrieve() $this->_em->flush(); $this->assertEquals(2, count($p->getFeatures())); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $p->getFeatures()); + $this->assertInstanceOf(PersistentCollection::class, $p->getFeatures()); $q = $this->_em->createQuery( 'SELECT p, f @@ -74,7 +73,7 @@ public function testAddPersistRetrieve() $res = $q->getResult(); $this->assertEquals(2, count($p->getFeatures())); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $p->getFeatures()); + $this->assertInstanceOf(PersistentCollection::class, $p->getFeatures()); // Check that the features are the same instances still foreach ($p->getFeatures() as $feature) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1041Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1041Test.php index ee1218187bc..ed27ed10044 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1041Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1041Test.php @@ -2,7 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Tests\Models\Company\CompanyFixContract; +use Doctrine\Tests\Models; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -18,7 +18,7 @@ public function setUp() public function testGrabWrongSubtypeReturnsNull() { - $fix = new CompanyFixContract(); + $fix = new Models\Company\CompanyFixContract(); $fix->setFixPrice(2000); $this->_em->persist($fix); @@ -26,8 +26,8 @@ public function testGrabWrongSubtypeReturnsNull() $id = $fix->getId(); - $this->assertNull($this->_em->find('Doctrine\Tests\Models\Company\CompanyFlexContract', $id)); - $this->assertNull($this->_em->getReference('Doctrine\Tests\Models\Company\CompanyFlexContract', $id)); - $this->assertNull($this->_em->getPartialReference('Doctrine\Tests\Models\Company\CompanyFlexContract', $id)); + $this->assertNull($this->_em->find(Models\Company\CompanyFlexContract::class, $id)); + $this->assertNull($this->_em->getReference(Models\Company\CompanyFlexContract::class, $id)); + $this->assertNull($this->_em->getPartialReference(Models\Company\CompanyFlexContract::class, $id)); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1043Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1043Test.php index f3e255042c9..9b35eb006c2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1043Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1043Test.php @@ -30,7 +30,7 @@ public function testChangeSetPlusWeirdPHPCastingIntCastingRule() $this->_em->flush(); $this->_em->clear(); - $user = $this->_em->find("Doctrine\Tests\Models\CMS\CmsUser", $user->id); + $user = $this->_em->find(CmsUser::class, $user->id); $this->assertSame("44", $user->status); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1050Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1050Test.php index fccb0fd4cdf..12c3898d858 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1050Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1050Test.php @@ -32,7 +32,7 @@ public function testPerformance() $this->_em->clear(); $s = microtime(true); - $users = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findAll(); + $users = $this->_em->getRepository(CmsUser::class)->findAll(); $e = microtime(true); echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1080Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1080Test.php index 637b42cdfb5..59ee4bb58ff 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1080Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1080Test.php @@ -13,9 +13,9 @@ public function testHydration() { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1080Foo'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1080Bar'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1080FooBar'), + $this->_em->getClassMetadata(DDC1080Foo::class), + $this->_em->getClassMetadata(DDC1080Bar::class), + $this->_em->getClassMetadata(DDC1080FooBar::class), ] ); @@ -59,7 +59,7 @@ public function testHydration() $this->_em->flush(); $this->_em->clear(); - $foo = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC1080Foo', $foo1->getFooID()); + $foo = $this->_em->find(DDC1080Foo::class, $foo1->getFooID()); $fooBars = $foo->getFooBars(); $this->assertEquals(3, count($fooBars), "Should return three foobars."); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1113Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1113Test.php index 9ff8882b5ae..f3b399f98ca 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1113Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1113Test.php @@ -15,10 +15,10 @@ public function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1113Engine'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1113Vehicle'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1113Car'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1113Bus'), + $this->_em->getClassMetadata(DDC1113Engine::class), + $this->_em->getClassMetadata(DDC1113Vehicle::class), + $this->_em->getClassMetadata(DDC1113Car::class), + $this->_em->getClassMetadata(DDC1113Bus::class), ] ); } catch (\Exception $e) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1129Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1129Test.php index 1f59d07baeb..81c95010298 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1129Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1129Test.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\Tests\Models\CMS\CmsArticle; + /** * @group DDC-1129 */ @@ -15,7 +17,7 @@ public function setUp() public function testVersionFieldIgnoredInChangesetComputation() { - $article = new \Doctrine\Tests\Models\CMS\CmsArticle(); + $article = new CmsArticle(); $article->text = "I don't know."; $article->topic = "Who is John Galt?"; @@ -24,7 +26,7 @@ public function testVersionFieldIgnoredInChangesetComputation() $this->assertEquals(1, $article->version); - $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsArticle'); + $class = $this->_em->getClassMetadata(CmsArticle::class); $uow = $this->_em->getUnitOfWork(); $uow->computeChangeSet($class, $article); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1151Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1151Test.php index 053586bc96e..5677801b408 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1151Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1151Test.php @@ -15,8 +15,8 @@ public function testQuoteForeignKey() $sql = $this->_schemaTool->getCreateSchemaSql( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1151User'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1151Group'), + $this->_em->getClassMetadata(DDC1151User::class), + $this->_em->getClassMetadata(DDC1151Group::class), ] ); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php index 8e8fcdb8bb0..f287034925a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\ORM\Proxy\Proxy; + /** * @group DDC-1163 */ @@ -13,10 +15,10 @@ protected function setUp() //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1163Product'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1163SpecialProduct'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1163ProxyHolder'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1163Tag'), + $this->_em->getClassMetadata(DDC1163Product::class), + $this->_em->getClassMetadata(DDC1163SpecialProduct::class), + $this->_em->getClassMetadata(DDC1163ProxyHolder::class), + $this->_em->getClassMetadata(DDC1163Tag::class), ] ); } @@ -59,25 +61,25 @@ private function createSpecialProductAndProxyHolderReferencingIt() */ private function createProxyForSpecialProduct() { - /* @var $proxyHolder ProxyHolder */ - $proxyHolder = $this->_em->find(__NAMESPACE__ . '\\DDC1163ProxyHolder', $this->proxyHolderId); + /* @var $proxyHolder DDC1163ProxyHolder */ + $proxyHolder = $this->_em->find(DDC1163ProxyHolder::class, $this->proxyHolderId); - $this->assertInstanceOf(__NAMESPACE__.'\\DDC1163SpecialProduct', $proxyHolder->getSpecialProduct()); + $this->assertInstanceOf(DDC1163SpecialProduct::class, $proxyHolder->getSpecialProduct()); } private function setPropertyAndAssignTagToSpecialProduct() { - /* @var $specialProduct SpecialProduct */ - $specialProduct = $this->_em->find(__NAMESPACE__ . '\\DDC1163SpecialProduct', $this->productId); + /* @var $specialProduct DDC1163SpecialProduct */ + $specialProduct = $this->_em->find(DDC1163SpecialProduct::class, $this->productId); - $this->assertInstanceOf(__NAMESPACE__.'\\DDC1163SpecialProduct', $specialProduct); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $specialProduct); + $this->assertInstanceOf(DDC1163SpecialProduct::class, $specialProduct); + $this->assertInstanceOf(Proxy::class, $specialProduct); $specialProduct->setSubclassProperty('foobar'); // this screams violation of law of demeter ;) $this->assertEquals( - __NAMESPACE__.'\\DDC1163SpecialProduct', + DDC1163SpecialProduct::class, $this->_em->getUnitOfWork()->getEntityPersister(get_class($specialProduct))->getClassMetadata()->name ); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php index 51141b4e67b..9c6740c3367 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php @@ -55,33 +55,33 @@ public function testAssociationOnlyCompositeKey() { $idCriteria = ['source' => $this->article1->id(), 'target' => $this->article2->id()]; - $mapRef = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria); - $this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Reference", $mapRef); - $this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Article", $mapRef->target()); - $this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Article", $mapRef->source()); - $this->assertSame($mapRef, $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria)); + $mapRef = $this->_em->find(DDC117Reference::class, $idCriteria); + $this->assertInstanceOf(DDC117Reference::class, $mapRef); + $this->assertInstanceOf(DDC117Article::class, $mapRef->target()); + $this->assertInstanceOf(DDC117Article::class, $mapRef->source()); + $this->assertSame($mapRef, $this->_em->find(DDC117Reference::class, $idCriteria)); $this->_em->clear(); - $dql = "SELECT r, s FROM "."Doctrine\Tests\Models\DDC117\DDC117Reference r JOIN r.source s WHERE r.source = ?1"; + $dql = "SELECT r, s FROM Doctrine\Tests\Models\DDC117\DDC117Reference r JOIN r.source s WHERE r.source = ?1"; $dqlRef = $this->_em->createQuery($dql)->setParameter(1, 1)->getSingleResult(); - $this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Reference", $mapRef); - $this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Article", $mapRef->target()); - $this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Article", $mapRef->source()); - $this->assertSame($dqlRef, $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria)); + $this->assertInstanceOf(DDC117Reference::class, $mapRef); + $this->assertInstanceOf(DDC117Article::class, $mapRef->target()); + $this->assertInstanceOf(DDC117Article::class, $mapRef->source()); + $this->assertSame($dqlRef, $this->_em->find(DDC117Reference::class, $idCriteria)); $this->_em->clear(); - $dql = "SELECT r, s FROM "."Doctrine\Tests\Models\DDC117\DDC117Reference r JOIN r.source s WHERE s.title = ?1"; + $dql = "SELECT r, s FROM Doctrine\Tests\Models\DDC117\DDC117Reference r JOIN r.source s WHERE s.title = ?1"; $dqlRef = $this->_em->createQuery($dql)->setParameter(1, 'Foo')->getSingleResult(); - $this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Reference", $dqlRef); - $this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Article", $dqlRef->target()); - $this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Article", $dqlRef->source()); - $this->assertSame($dqlRef, $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria)); + $this->assertInstanceOf(DDC117Reference::class, $dqlRef); + $this->assertInstanceOf(DDC117Article::class, $dqlRef->target()); + $this->assertInstanceOf(DDC117Article::class, $dqlRef->source()); + $this->assertSame($dqlRef, $this->_em->find(DDC117Reference::class, $idCriteria)); - $dql = "SELECT r, s FROM "."Doctrine\Tests\Models\DDC117\DDC117Reference r JOIN r.source s WHERE s.title = ?1"; + $dql = "SELECT r, s FROM Doctrine\Tests\Models\DDC117\DDC117Reference r JOIN r.source s WHERE s.title = ?1"; $dqlRef = $this->_em->createQuery($dql)->setParameter(1, 'Foo')->getSingleResult(); $this->_em->contains($dqlRef); @@ -94,13 +94,13 @@ public function testUpdateAssociationEntity() { $idCriteria = ['source' => $this->article1->id(), 'target' => $this->article2->id()]; - $mapRef = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria); + $mapRef = $this->_em->find(DDC117Reference::class, $idCriteria); $this->assertNotNull($mapRef); $mapRef->setDescription("New Description!!"); $this->_em->flush(); $this->_em->clear(); - $mapRef = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria); + $mapRef = $this->_em->find(DDC117Reference::class, $idCriteria); $this->assertEquals('New Description!!', $mapRef->getDescription()); } @@ -110,13 +110,13 @@ public function testUpdateAssociationEntity() */ public function testFetchDql() { - $dql = "SELECT r, s FROM "."Doctrine\Tests\Models\DDC117\DDC117Reference r JOIN r.source s WHERE s.title = ?1"; + $dql = "SELECT r, s FROM Doctrine\Tests\Models\DDC117\DDC117Reference r JOIN r.source s WHERE s.title = ?1"; $refs = $this->_em->createQuery($dql)->setParameter(1, 'Foo')->getResult(); $this->assertTrue(count($refs) > 0, "Has to contain at least one Reference."); foreach ($refs AS $ref) { - $this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Reference", $ref, "Contains only Reference instances."); + $this->assertInstanceOf(DDC117Reference::class, $ref, "Contains only Reference instances."); $this->assertTrue($this->_em->contains($ref), "Contains Reference in the IdentityMap."); } } @@ -128,13 +128,13 @@ public function testRemoveCompositeElement() { $idCriteria = ['source' => $this->article1->id(), 'target' => $this->article2->id()]; - $refRep = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria); + $refRep = $this->_em->find(DDC117Reference::class, $idCriteria); $this->_em->remove($refRep); $this->_em->flush(); $this->_em->clear(); - $this->assertNull($this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria)); + $this->assertNull($this->_em->find(DDC117Reference::class, $idCriteria)); } /** @@ -145,13 +145,13 @@ public function testDqlRemoveCompositeElement() { $idCriteria = ['source' => $this->article1->id(), 'target' => $this->article2->id()]; - $dql = "DELETE "."Doctrine\Tests\Models\DDC117\DDC117Reference r WHERE r.source = ?1 AND r.target = ?2"; + $dql = "DELETE Doctrine\Tests\Models\DDC117\DDC117Reference r WHERE r.source = ?1 AND r.target = ?2"; $this->_em->createQuery($dql) ->setParameter(1, $this->article1->id()) ->setParameter(2, $this->article2->id()) ->execute(); - $this->assertNull($this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria)); + $this->assertNull($this->_em->find(DDC117Reference::class, $idCriteria)); } /** @@ -159,18 +159,18 @@ public function testDqlRemoveCompositeElement() */ public function testInverseSideAccess() { - $this->article1 = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Article", $this->article1->id()); + $this->article1 = $this->_em->find(DDC117Article::class, $this->article1->id()); $this->assertEquals(1, count($this->article1->references())); foreach ($this->article1->references() AS $this->reference) { - $this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Reference", $this->reference); + $this->assertInstanceOf(DDC117Reference::class, $this->reference); $this->assertSame($this->article1, $this->reference->source()); } $this->_em->clear(); - $dql = 'SELECT a, r FROM '. 'Doctrine\Tests\Models\DDC117\DDC117Article a INNER JOIN a.references r WHERE a.id = ?1'; + $dql = 'SELECT a, r FROM Doctrine\Tests\Models\DDC117\DDC117Article a INNER JOIN a.references r WHERE a.id = ?1'; $articleDql = $this->_em->createQuery($dql) ->setParameter(1, $this->article1->id()) ->getSingleResult(); @@ -178,7 +178,7 @@ public function testInverseSideAccess() $this->assertEquals(1, count($this->article1->references())); foreach ($this->article1->references() AS $this->reference) { - $this->assertInstanceOf("Doctrine\Tests\Models\DDC117\DDC117Reference", $this->reference); + $this->assertInstanceOf(DDC117Reference::class, $this->reference); $this->assertSame($this->article1, $this->reference->source()); } } @@ -190,20 +190,20 @@ public function testMixedCompositeKey() { $idCriteria = ['article' => $this->article1->id(), 'language' => 'en']; - $this->translation = $this->_em->find('Doctrine\Tests\Models\DDC117\DDC117Translation', $idCriteria); - $this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117Translation', $this->translation); + $this->translation = $this->_em->find(DDC117Translation::class, $idCriteria); + $this->assertInstanceOf(DDC117Translation::class, $this->translation); - $this->assertSame($this->translation, $this->_em->find('Doctrine\Tests\Models\DDC117\DDC117Translation', $idCriteria)); + $this->assertSame($this->translation, $this->_em->find(DDC117Translation::class, $idCriteria)); $this->_em->clear(); - $dql = 'SELECT t, a FROM ' . 'Doctrine\Tests\Models\DDC117\DDC117Translation t JOIN t.article a WHERE t.article = ?1 AND t.language = ?2'; + $dql = 'SELECT t, a FROM Doctrine\Tests\Models\DDC117\DDC117Translation t JOIN t.article a WHERE t.article = ?1 AND t.language = ?2'; $dqlTrans = $this->_em->createQuery($dql) ->setParameter(1, $this->article1->id()) ->setParameter(2, 'en') ->getSingleResult(); - $this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117Translation', $this->translation); + $this->assertInstanceOf(DDC117Translation::class, $this->translation); } /** @@ -211,7 +211,7 @@ public function testMixedCompositeKey() */ public function testMixedCompositeKeyViolateUniqueness() { - $this->article1 = $this->_em->find('Doctrine\Tests\Models\DDC117\DDC117Article', $this->article1->id()); + $this->article1 = $this->_em->find(DDC117Article::class, $this->article1->id()); $this->article1->addTranslation('en', 'Bar'); $this->article1->addTranslation('en', 'Baz'); @@ -283,21 +283,21 @@ public function testOneToOneCascadePersist() public function testReferencesToForeignKeyEntities() { $idCriteria = ['source' => $this->article1->id(), 'target' => $this->article2->id()]; - $reference = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria); + $reference = $this->_em->find(DDC117Reference::class, $idCriteria); $idCriteria = ['article' => $this->article1->id(), 'language' => 'en']; - $translation = $this->_em->find('Doctrine\Tests\Models\DDC117\DDC117Translation', $idCriteria); + $translation = $this->_em->find(DDC117Translation::class, $idCriteria); $approveChanges = new DDC117ApproveChanges($reference->source()->getDetails(), $reference, $translation); $this->_em->persist($approveChanges); $this->_em->flush(); $this->_em->clear(); - $approveChanges = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117ApproveChanges", $approveChanges->getId()); + $approveChanges = $this->_em->find(DDC117ApproveChanges::class, $approveChanges->getId()); - $this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails', $approveChanges->getArticleDetails()); - $this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117Reference', $approveChanges->getReference()); - $this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117Translation', $approveChanges->getTranslation()); + $this->assertInstanceOf(DDC117ArticleDetails::class, $approveChanges->getArticleDetails()); + $this->assertInstanceOf(DDC117Reference::class, $approveChanges->getReference()); + $this->assertInstanceOf(DDC117Translation::class, $approveChanges->getTranslation()); } /** @@ -310,7 +310,7 @@ public function testLoadOneToManyCollectionOfForeignKeyEntities() $translations = $article->getTranslations(); $this->assertFalse($translations->isInitialized()); - $this->assertContainsOnly('Doctrine\Tests\Models\DDC117\DDC117Translation', $translations); + $this->assertContainsOnly(DDC117Translation::class, $translations); $this->assertTrue($translations->isInitialized()); } @@ -322,7 +322,7 @@ public function testLoadManyToManyCollectionOfForeignKeyEntities() $editor = $this->loadEditorFixture(); $this->assertFalse($editor->reviewingTranslations->isInitialized()); - $this->assertContainsOnly("Doctrine\Tests\Models\DDC117\DDC117Translation", $editor->reviewingTranslations); + $this->assertContainsOnly(DDC117Translation::class, $editor->reviewingTranslations); $this->assertTrue($editor->reviewingTranslations->isInitialized()); $this->_em->clear(); @@ -330,7 +330,7 @@ public function testLoadManyToManyCollectionOfForeignKeyEntities() $dql = "SELECT e, t FROM Doctrine\Tests\Models\DDC117\DDC117Editor e JOIN e.reviewingTranslations t WHERE e.id = ?1"; $editor = $this->_em->createQuery($dql)->setParameter(1, $editor->id)->getSingleResult(); $this->assertTrue($editor->reviewingTranslations->isInitialized()); - $this->assertContainsOnly("Doctrine\Tests\Models\DDC117\DDC117Translation", $editor->reviewingTranslations); + $this->assertContainsOnly(DDC117Translation::class, $editor->reviewingTranslations); } /** @@ -356,7 +356,7 @@ public function testLoadInverseManyToManyCollection() { $editor = $this->loadEditorFixture(); - $this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117Translation', $editor->reviewingTranslations[0]); + $this->assertInstanceOf(DDC117Translation::class, $editor->reviewingTranslations[0]); $reviewedBy = $editor->reviewingTranslations[0]->getReviewedByEditors(); $this->assertEquals(1, count($reviewedBy)); @@ -371,8 +371,8 @@ public function testLoadInverseManyToManyCollection() ->setParameter(2, $this->translation->getLanguage()) ->getSingleResult(); - $this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117Translation', $trans); - $this->assertContainsOnly('Doctrine\Tests\Models\DDC117\DDC117Editor', $trans->reviewedByEditors); + $this->assertInstanceOf(DDC117Translation::class, $trans); + $this->assertContainsOnly(DDC117Editor::class, $trans->reviewedByEditors); $this->assertEquals(1, count($trans->reviewedByEditors)); } @@ -431,7 +431,7 @@ public function testMergeForeignKeyIdentifierEntity() { $idCriteria = ['source' => $this->article1->id(), 'target' => $this->article2->id()]; - $refRep = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria); + $refRep = $this->_em->find(DDC117Reference::class, $idCriteria); $this->_em->detach($refRep); $refRep = $this->_em->merge($refRep); @@ -448,8 +448,8 @@ public function testArrayHydrationWithCompositeKey() $dql = "SELECT r,s,t FROM Doctrine\Tests\Models\DDC117\DDC117Reference r INNER JOIN r.source s INNER JOIN r.target t"; $before = count($this->_em->createQuery($dql)->getResult()); - $this->article1 = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Article", $this->article1->id()); - $this->article2 = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Article", $this->article2->id()); + $this->article1 = $this->_em->find(DDC117Article::class, $this->article1->id()); + $this->article2 = $this->_em->find(DDC117Article::class, $this->article2->id()); $this->reference = new DDC117Reference($this->article2, $this->article1, "Test-Description"); $this->_em->persist($this->reference); @@ -477,15 +477,15 @@ public function testGetEntityState() $this->markTestIncomplete('Second level cache - not supported yet'); } - $this->article1 = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Article", $this->article1->id()); - $this->article2 = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Article", $this->article2->id()); + $this->article1 = $this->_em->find(DDC117Article::class, $this->article1->id()); + $this->article2 = $this->_em->find(DDC117Article::class, $this->article2->id()); $this->reference = new DDC117Reference($this->article2, $this->article1, "Test-Description"); $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($this->reference)); $idCriteria = ['source' => $this->article1->id(), 'target' => $this->article2->id()]; - $reference = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria); + $reference = $this->_em->find(DDC117Reference::class, $idCriteria); $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_MANAGED, $this->_em->getUnitOfWork()->getEntityState($reference)); } @@ -494,9 +494,9 @@ public function testGetEntityState() */ public function testIndexByOnCompositeKeyField() { - $article = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Article", $this->article1->id()); + $article = $this->_em->find(DDC117Article::class, $this->article1->id()); - $this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117Article', $article); + $this->assertInstanceOf(DDC117Article::class, $article); $this->assertEquals(1, count($article->getLinks())); $this->assertTrue($article->getLinks()->offsetExists($this->article2->id())); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php index 8cf1ebe150f..d72a960f78e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php @@ -11,9 +11,9 @@ public function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1181Hotel'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1181Booking'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1181Room'), + $this->_em->getClassMetadata(DDC1181Hotel::class), + $this->_em->getClassMetadata(DDC1181Booking::class), + $this->_em->getClassMetadata(DDC1181Room::class), ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php index 00d0a35a4b6..f4d98cb23a4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php @@ -12,9 +12,9 @@ protected function setUp() //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1193Company'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1193Person'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1193Account') + $this->_em->getClassMetadata(DDC1193Company::class), + $this->_em->getClassMetadata(DDC1193Person::class), + $this->_em->getClassMetadata(DDC1193Account::class) ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php index 7700aa0a5bf..77cde326245 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php @@ -12,9 +12,9 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1209_1'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1209_2'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1209_3') + $this->_em->getClassMetadata(DDC1209_1::class), + $this->_em->getClassMetadata(DDC1209_2::class), + $this->_em->getClassMetadata(DDC1209_3::class) ] ); } catch(\Exception $e) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1225Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1225Test.php index 105ae9f9042..1bfd6b91e15 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1225Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1225Test.php @@ -13,8 +13,8 @@ public function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1225_TestEntity1'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1225_TestEntity2'), + $this->_em->getClassMetadata(DDC1225_TestEntity1::class), + $this->_em->getClassMetadata(DDC1225_TestEntity2::class), ] ); } catch(\PDOException $e) { @@ -25,7 +25,7 @@ public function setUp() public function testIssue() { $qb = $this->_em->createQueryBuilder(); - $qb->from('Doctrine\Tests\ORM\Functional\Ticket\DDC1225_TestEntity1', 'te1') + $qb->from(DDC1225_TestEntity1::class, 'te1') ->select('te1') ->where('te1.testEntity2 = ?1') ->setParameter(1, 0); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1228Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1228Test.php index 8a9f252df0e..b4de087a359 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1228Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1228Test.php @@ -14,8 +14,8 @@ public function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1228User'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1228Profile'), + $this->_em->getClassMetadata(DDC1228User::class), + $this->_em->getClassMetadata(DDC1228Profile::class), ] ); } catch(\Exception $e) { @@ -35,7 +35,7 @@ public function testOneToOnePersist() $this->_em->flush(); $this->_em->clear(); - $user = $this->_em->find(__NAMESPACE__ . '\\DDC1228User', $user->id); + $user = $this->_em->find(DDC1228User::class, $user->id); $this->assertFalse($user->getProfile()->__isInitialized__, "Proxy is not initialized"); $user->getProfile()->setName("Bar"); @@ -47,7 +47,7 @@ public function testOneToOnePersist() $this->_em->flush(); $this->_em->clear(); - $user = $this->_em->find(__NAMESPACE__ . '\\DDC1228User', $user->id); + $user = $this->_em->find(DDC1228User::class, $user->id); $this->assertEquals("Bar", $user->getProfile()->getName()); } @@ -63,14 +63,14 @@ public function testRefresh() $this->_em->flush(); $this->_em->clear(); - $user = $this->_em->getReference(__NAMESPACE__ . '\\DDC1228User', $user->id); + $user = $this->_em->getReference(DDC1228User::class, $user->id); $this->_em->refresh($user); $user->name = "Baz"; $this->_em->flush(); $this->_em->clear(); - $user = $this->_em->find(__NAMESPACE__ . '\\DDC1228User', $user->id); + $user = $this->_em->find(DDC1228User::class, $user->id); $this->assertEquals("Baz", $user->name); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1238Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1238Test.php index 6c24b2f5583..00c621eeeef 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1238Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1238Test.php @@ -13,7 +13,7 @@ public function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1238User'), + $this->_em->getClassMetadata(DDC1238User::class), ] ); } catch(\Exception $e) { @@ -33,7 +33,7 @@ public function testIssue() $userId = $user->getId(); $this->_em->clear(); - $user = $this->_em->getReference(__NAMESPACE__ . '\\DDC1238User', $userId); + $user = $this->_em->getReference(DDC1238User::class, $userId); $this->_em->clear(); $userId2 = $user->getId(); @@ -54,10 +54,10 @@ public function testIssueProxyClear() $userId = $user->getId(); $this->_em->clear(); - $user = $this->_em->getReference(__NAMESPACE__ . '\\DDC1238User', $userId); + $user = $this->_em->getReference(DDC1238User::class, $userId); $this->_em->clear(); - $user2 = $this->_em->getReference(__NAMESPACE__ . '\\DDC1238User', $userId); + $user2 = $this->_em->getReference(DDC1238User::class, $userId); // force proxy load, getId() doesn't work anymore $user->getName(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1250Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1250Test.php index ed54ec681cd..a09b1761fea 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1250Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1250Test.php @@ -13,7 +13,7 @@ public function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1250ClientHistory'), + $this->_em->getClassMetadata(DDC1250ClientHistory::class), ] ); } catch(\PDOException $e) { @@ -38,7 +38,7 @@ public function testIssue() $history = $this->_em->createQuery('SELECT h FROM ' . __NAMESPACE__ . '\\DDC1250ClientHistory h WHERE h.id = ?1') ->setParameter(1, $c2->id)->getSingleResult(); - $this->assertInstanceOf(__NAMESPACE__ . '\\DDC1250ClientHistory', $history); + $this->assertInstanceOf(DDC1250ClientHistory::class, $history); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1276Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1276Test.php index 197d3a2aa48..eeaa870ae4d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1276Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1276Test.php @@ -2,8 +2,8 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\CMS\CmsGroup; +use Doctrine\Tests\Models\CMS\CmsUser; /** * @group DDC-1276 @@ -33,7 +33,7 @@ public function testIssue() $this->_em->flush(); $this->_em->clear(); - $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $user->id); + $user = $this->_em->find(CmsUser::class, $user->id); $cloned = clone $user; $this->assertSame($user->groups, $cloned->groups); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1300Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1300Test.php index 97fd33b2a25..4f0038b1c89 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1300Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1300Test.php @@ -12,8 +12,8 @@ public function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1300Foo'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1300FooLocale'), + $this->_em->getClassMetadata(DDC1300Foo::class), + $this->_em->getClassMetadata(DDC1300FooLocale::class), ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1301Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1301Test.php index f8ccc5a3e95..785b22187ed 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1301Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1301Test.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\Tests\Models; /** * @author asm89 @@ -19,7 +20,7 @@ public function setUp() $this->useModelSet('legacy'); parent::setUp(); - $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\Legacy\LegacyUser'); + $class = $this->_em->getClassMetadata(Models\Legacy\LegacyUser::class); $class->associationMappings['_articles']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY; $class->associationMappings['_references']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY; $class->associationMappings['_cars']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY; @@ -31,7 +32,7 @@ public function tearDown() { parent::tearDown(); - $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\Legacy\LegacyUser'); + $class = $this->_em->getClassMetadata(Models\Legacy\LegacyUser::class); $class->associationMappings['_articles']['fetch'] = ClassMetadataInfo::FETCH_LAZY; $class->associationMappings['_references']['fetch'] = ClassMetadataInfo::FETCH_LAZY; $class->associationMappings['_cars']['fetch'] = ClassMetadataInfo::FETCH_LAZY; @@ -39,7 +40,7 @@ public function tearDown() public function testCountNotInitializesLegacyCollection() { - $user = $this->_em->find('Doctrine\Tests\Models\Legacy\LegacyUser', $this->userId); + $user = $this->_em->find(Models\Legacy\LegacyUser::class, $this->userId); $queryCount = $this->getCurrentQueryCount(); $this->assertFalse($user->_articles->isInitialized()); @@ -53,7 +54,7 @@ public function testCountNotInitializesLegacyCollection() public function testCountNotInitializesLegacyCollectionWithForeignIdentifier() { - $user = $this->_em->find('Doctrine\Tests\Models\Legacy\LegacyUser', $this->userId); + $user = $this->_em->find(Models\Legacy\LegacyUser::class, $this->userId); $queryCount = $this->getCurrentQueryCount(); $this->assertFalse($user->_references->isInitialized()); @@ -67,7 +68,7 @@ public function testCountNotInitializesLegacyCollectionWithForeignIdentifier() public function testCountNotInitializesLegacyManyToManyCollection() { - $user = $this->_em->find('Doctrine\Tests\Models\Legacy\LegacyUser', $this->userId); + $user = $this->_em->find(Models\Legacy\LegacyUser::class, $this->userId); $queryCount = $this->getCurrentQueryCount(); $this->assertFalse($user->_cars->isInitialized()); @@ -81,17 +82,17 @@ public function testCountNotInitializesLegacyManyToManyCollection() public function loadFixture() { - $user1 = new \Doctrine\Tests\Models\Legacy\LegacyUser(); + $user1 = new Models\Legacy\LegacyUser(); $user1->_username = "beberlei"; $user1->_name = "Benjamin"; $user1->_status = "active"; - $user2 = new \Doctrine\Tests\Models\Legacy\LegacyUser(); + $user2 = new Models\Legacy\LegacyUser(); $user2->_username = "jwage"; $user2->_name = "Jonathan"; $user2->_status = "active"; - $user3 = new \Doctrine\Tests\Models\Legacy\LegacyUser(); + $user3 = new Models\Legacy\LegacyUser(); $user3->_username = "romanb"; $user3->_name = "Roman"; $user3->_status = "active"; @@ -100,12 +101,12 @@ public function loadFixture() $this->_em->persist($user2); $this->_em->persist($user3); - $article1 = new \Doctrine\Tests\Models\Legacy\LegacyArticle(); + $article1 = new Models\Legacy\LegacyArticle(); $article1->_topic = "Test"; $article1->_text = "Test"; $article1->setAuthor($user1); - $article2 = new \Doctrine\Tests\Models\Legacy\LegacyArticle(); + $article2 = new Models\Legacy\LegacyArticle(); $article2->_topic = "Test"; $article2->_text = "Test"; $article2->setAuthor($user1); @@ -113,13 +114,13 @@ public function loadFixture() $this->_em->persist($article1); $this->_em->persist($article2); - $car1 = new \Doctrine\Tests\Models\Legacy\LegacyCar(); + $car1 = new Models\Legacy\LegacyCar(); $car1->_description = "Test1"; - $car2 = new \Doctrine\Tests\Models\Legacy\LegacyCar(); + $car2 = new Models\Legacy\LegacyCar(); $car2->_description = "Test2"; - $car3 = new \Doctrine\Tests\Models\Legacy\LegacyCar(); + $car3 = new Models\Legacy\LegacyCar(); $car3->_description = "Test3"; $user1->addCar($car1); @@ -135,8 +136,8 @@ public function loadFixture() $this->_em->flush(); - $detail1 = new \Doctrine\Tests\Models\Legacy\LegacyUserReference($user1, $user2, "foo"); - $detail2 = new \Doctrine\Tests\Models\Legacy\LegacyUserReference($user1, $user3, "bar"); + $detail1 = new Models\Legacy\LegacyUserReference($user1, $user2, "foo"); + $detail2 = new Models\Legacy\LegacyUserReference($user1, $user3, "bar"); $this->_em->persist($detail1); $this->_em->persist($detail2); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1335Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1335Test.php index d92a32781e7..dd475559472 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1335Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1335Test.php @@ -13,8 +13,8 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1335User'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1335Phone'), + $this->_em->getClassMetadata(DDC1335User::class), + $this->_em->getClassMetadata(DDC1335Phone::class), ] ); $this->loadFixture(); @@ -67,7 +67,7 @@ public function testDql() public function testTicket() { $builder = $this->_em->createQueryBuilder(); - $builder->select('u')->from(__NAMESPACE__ . '\DDC1335User', 'u', 'u.id'); + $builder->select('u')->from(DDC1335User::class, 'u', 'u.id'); $dql = $builder->getQuery()->getDQL(); $result = $builder->getQuery()->getResult(); @@ -82,7 +82,7 @@ public function testTicket() public function testIndexByUnique() { $builder = $this->_em->createQueryBuilder(); - $builder->select('u')->from(__NAMESPACE__ . '\DDC1335User', 'u', 'u.email'); + $builder->select('u')->from(DDC1335User::class, 'u', 'u.email'); $dql = $builder->getQuery()->getDQL(); $result = $builder->getQuery()->getResult(); @@ -98,7 +98,7 @@ public function testIndexWithJoin() { $builder = $this->_em->createQueryBuilder(); $builder->select('u','p') - ->from(__NAMESPACE__ . '\DDC1335User', 'u', 'u.email') + ->from(DDC1335User::class, 'u', 'u.email') ->join('u.phones', 'p', null, null, 'p.id'); $dql = $builder->getQuery()->getDQL(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1360Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1360Test.php index 05a99b7cbb4..6e71e6fc742 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1360Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1360Test.php @@ -17,7 +17,7 @@ public function testSchemaDoubleQuotedCreate() $sql = $this->_schemaTool->getCreateSchemaSql( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1360DoubleQuote') + $this->_em->getClassMetadata(DDC1360DoubleQuote::class) ] ); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1383Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1383Test.php index a84fd715464..7a13d7ac9bc 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1383Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1383Test.php @@ -14,8 +14,8 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1383AbstractEntity'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1383Entity'), + $this->_em->getClassMetadata(DDC1383AbstractEntity::class), + $this->_em->getClassMetadata(DDC1383Entity::class), ] ); } catch(\Exception $ignored) {} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1392Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1392Test.php index 5fe34f6ccbf..806e61de4da 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1392Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1392Test.php @@ -16,8 +16,8 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1392File'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1392Picture'), + $this->_em->getClassMetadata(DDC1392File::class), + $this->_em->getClassMetadata(DDC1392Picture::class), ] ); } catch (\Exception $ignored) { @@ -41,7 +41,7 @@ public function testFailingCase() $this->assertTrue($fileId > 0); - $picture = $em->find(__NAMESPACE__ . '\DDC1392Picture', $pictureId); + $picture = $em->find(DDC1392Picture::class, $pictureId); $this->assertEquals(UnitOfWork::STATE_MANAGED, $em->getUnitOfWork()->getEntityState($picture->getFile()), "Lazy Proxy should be marked MANAGED."); $file = $picture->getFile(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php index 22fd282ce24..4ac78d9b77e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php @@ -14,9 +14,9 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1400Article'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1400User'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1400UserState'), + $this->_em->getClassMetadata(DDC1400Article::class), + $this->_em->getClassMetadata(DDC1400User::class), + $this->_em->getClassMetadata(DDC1400UserState::class), ] ); } catch (\Exception $ignored) { @@ -52,7 +52,7 @@ public function testFailingCase() $this->_em->flush(); $this->_em->clear(); - $user1 = $this->_em->getReference(__NAMESPACE__.'\DDC1400User', $user1->id); + $user1 = $this->_em->getReference(DDC1400User::class, $user1->id); $q = $this->_em->createQuery("SELECT a, s FROM ".__NAMESPACE__."\DDC1400Article a JOIN a.userStates s WITH s.user = :activeUser"); $q->setParameter('activeUser', $user1); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1404Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1404Test.php index e4d0a47f2ce..b3a1a939d21 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1404Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1404Test.php @@ -15,8 +15,8 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1404ParentEntity'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1404ChildEntity'), + $this->_em->getClassMetadata(DDC1404ParentEntity::class), + $this->_em->getClassMetadata(DDC1404ChildEntity::class), ] ); @@ -28,7 +28,7 @@ protected function setUp() public function testTicket() { - $repository = $this->_em->getRepository(__NAMESPACE__ . '\DDC1404ChildEntity'); + $repository = $this->_em->getRepository(DDC1404ChildEntity::class); $queryAll = $repository->createNamedQuery('all'); $queryFirst = $repository->createNamedQuery('first'); $querySecond = $repository->createNamedQuery('second'); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC142Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC142Test.php index 6f08cf80c11..287b73dec3b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC142Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC142Test.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\Tests\Models\Quote\Group; +use Doctrine\Tests\Models\Quote\Phone; use Doctrine\Tests\Models\Quote\User; use Doctrine\Tests\Models\Quote\Address; @@ -11,7 +13,6 @@ */ class DDC142Test extends \Doctrine\Tests\OrmFunctionalTestCase { - protected function setUp() { parent::setUp(); @@ -19,10 +20,10 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\User'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Group'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Phone'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Address'), + $this->_em->getClassMetadata(User::class), + $this->_em->getClassMetadata(Group::class), + $this->_em->getClassMetadata(Phone::class), + $this->_em->getClassMetadata(Address::class), ] ); } catch(\Exception $e) { @@ -42,7 +43,7 @@ public function testCreateRetrieveUpdateDelete() $this->_em->flush(); - $addressRef = $this->_em->getReference('Doctrine\Tests\Models\Quote\Address', $address->getId()); + $addressRef = $this->_em->getReference(Address::class, $address->getId()); $user->setAddress($addressRef); @@ -53,11 +54,11 @@ public function testCreateRetrieveUpdateDelete() $this->assertNotNull($id); - $user = $this->_em->find('Doctrine\Tests\Models\Quote\User', $id); + $user = $this->_em->find(User::class, $id); $address = $user->getAddress(); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\User', $user); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Address', $user->getAddress()); + $this->assertInstanceOf(User::class, $user); + $this->assertInstanceOf(Address::class, $user->getAddress()); $this->assertEquals('FabioBatSilva', $user->name); $this->assertEquals('12345', $address->zip); @@ -72,8 +73,8 @@ public function testCreateRetrieveUpdateDelete() $this->_em->clear(); - $user = $this->_em->find('Doctrine\Tests\Models\Quote\User', $id); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\User', $user); + $user = $this->_em->find(User::class, $id); + $this->assertInstanceOf(User::class, $user); $this->assertNull($user->getAddress()); $this->assertEquals('FabioBatSilva1', $user->name); @@ -83,7 +84,7 @@ public function testCreateRetrieveUpdateDelete() $this->_em->flush(); $this->_em->clear(); - $this->assertNull($this->_em->find('Doctrine\Tests\Models\Quote\User', $id)); + $this->assertNull($this->_em->find(User::class, $id)); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1430Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1430Test.php index 3356d426809..6b08a832675 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1430Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1430Test.php @@ -15,8 +15,8 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1430Order'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1430OrderProduct'), + $this->_em->getClassMetadata(DDC1430Order::class), + $this->_em->getClassMetadata(DDC1430OrderProduct::class), ] ); $this->loadFixtures(); @@ -27,7 +27,7 @@ protected function setUp() public function testOrderByFields() { - $repository = $this->_em->getRepository(__NAMESPACE__ . '\DDC1430Order'); + $repository = $this->_em->getRepository(DDC1430Order::class); $builder = $repository->createQueryBuilder('o'); $query = $builder->select('o.id, o.date, COUNT(p.id) AS p_count') ->leftJoin('o.products', 'p') @@ -58,7 +58,7 @@ public function testOrderByFields() public function testOrderByAllObjectFields() { - $repository = $this->_em->getRepository(__NAMESPACE__ . '\DDC1430Order'); + $repository = $this->_em->getRepository(DDC1430Order::class); $builder = $repository->createQueryBuilder('o'); $query = $builder->select('o, COUNT(p.id) AS p_count') ->leftJoin('o.products', 'p') @@ -87,7 +87,7 @@ public function testOrderByAllObjectFields() public function testTicket() { - $repository = $this->_em->getRepository(__NAMESPACE__ . '\DDC1430Order'); + $repository = $this->_em->getRepository(DDC1430Order::class); $builder = $repository->createQueryBuilder('o'); $query = $builder->select('o, COUNT(p.id) AS p_count') ->leftJoin('o.products', 'p') diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1436Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1436Test.php index cd9ff6b3258..9ffa497cd4d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1436Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1436Test.php @@ -14,7 +14,7 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1436Page'), + $this->_em->getClassMetadata(DDC1436Page::class), ] ); } catch (\Exception $ignored) { @@ -42,13 +42,13 @@ public function testIdentityMap() ->setParameter('id', $id) ->getOneOrNullResult(); - $this->assertInstanceOf(__NAMESPACE__ . '\DDC1436Page', $page); + $this->assertInstanceOf(DDC1436Page::class, $page); // step 2 - $page = $this->_em->find(__NAMESPACE__ . '\DDC1436Page', $id); - $this->assertInstanceOf(__NAMESPACE__ . '\DDC1436Page', $page); - $this->assertInstanceOf(__NAMESPACE__ . '\DDC1436Page', $page->getParent()); - $this->assertInstanceOf(__NAMESPACE__ . '\DDC1436Page', $page->getParent()->getParent()); + $page = $this->_em->find(DDC1436Page::class, $id); + $this->assertInstanceOf(DDC1436Page::class, $page); + $this->assertInstanceOf(DDC1436Page::class, $page->getParent()); + $this->assertInstanceOf(DDC1436Page::class, $page->getParent()->getParent()); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php index d7b280f009c..78276f0ddc8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php @@ -12,9 +12,9 @@ protected function setUp() { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC144FlowElement'), + $this->_em->getClassMetadata(DDC144FlowElement::class), // $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC144Expression'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC144Operand'), + $this->_em->getClassMetadata(DDC144Operand::class), ] ); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1452Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1452Test.php index 4dd486c1e8c..7e7ecc4f841 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1452Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1452Test.php @@ -3,6 +3,9 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; +use Doctrine\ORM\Proxy\Proxy; +use Doctrine\Tests\Models\CMS\CmsUser; /** * @group DDC-1452 @@ -17,8 +20,8 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1452EntityA'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1452EntityB'), + $this->_em->getClassMetadata(DDC1452EntityA::class), + $this->_em->getClassMetadata(DDC1452EntityB::class), ] ); } catch (\Exception $ignored) { @@ -47,8 +50,8 @@ public function testIssue() $results = $this->_em->createQuery($dql)->setMaxResults(1)->getResult(); $this->assertSame($results[0], $results[0]->entitiesB[0]->entityAFrom); - $this->assertFalse( $results[0]->entitiesB[0]->entityATo instanceof \Doctrine\ORM\Proxy\Proxy ); - $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $results[0]->entitiesB[0]->entityATo->getEntitiesB()); + $this->assertFalse( $results[0]->entitiesB[0]->entityATo instanceof Proxy); + $this->assertInstanceOf(Collection::class, $results[0]->entitiesB[0]->entityATo->getEntitiesB()); } public function testFetchJoinOneToOneFromInverse() @@ -59,7 +62,7 @@ public function testFetchJoinOneToOneFromInverse() $address->street = "Somestreet"; $address->zip = 12345; - $user = new \Doctrine\Tests\Models\CMS\CmsUser(); + $user = new CmsUser(); $user->name = "beberlei"; $user->username = "beberlei"; $user->status = "active"; @@ -75,12 +78,12 @@ public function testFetchJoinOneToOneFromInverse() $data = $this->_em->createQuery($dql)->getResult(); $this->_em->clear(); - $this->assertFalse($data[0]->user instanceof \Doctrine\ORM\Proxy\Proxy); + $this->assertFalse($data[0]->user instanceof Proxy); $dql = "SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.address a"; $data = $this->_em->createQuery($dql)->getResult(); - $this->assertFalse($data[0]->address instanceof \Doctrine\ORM\Proxy\Proxy); + $this->assertFalse($data[0]->address instanceof Proxy); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1454Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1454Test.php index f4b456e65a1..54d5dbd20a6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1454Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1454Test.php @@ -14,8 +14,8 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1454File'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1454Picture'), + $this->_em->getClassMetadata(DDC1454File::class), + $this->_em->getClassMetadata(DDC1454Picture::class), ] ); } catch (\Exception $ignored) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1458Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1458Test.php index 6f2d80afb4d..72d79cd432f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1458Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1458Test.php @@ -11,8 +11,8 @@ public function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\TestEntity'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\TestAdditionalEntity') + $this->_em->getClassMetadata(TestEntity::class), + $this->_em->getClassMetadata(TestAdditionalEntity::class) ] ); } @@ -29,7 +29,7 @@ public function testIssue() // So here the value is 3 $this->assertEquals(3, $testEntity->getValue()); - $test = $this->_em->getRepository(__NAMESPACE__ . '\TestEntity')->find(1); + $test = $this->_em->getRepository(TestEntity::class)->find(1); // New value is set $test->setValue(5); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1461Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1461Test.php index fd419d74352..da7100d683e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1461Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1461Test.php @@ -14,8 +14,8 @@ public function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1461TwitterAccount'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1461User') + $this->_em->getClassMetadata(DDC1461TwitterAccount::class), + $this->_em->getClassMetadata(DDC1461User::class) ] ); } catch(\Exception $e) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1509Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1509Test.php index 351a963c496..17cfdf78dc7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1509Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1509Test.php @@ -15,9 +15,9 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1509AbstractFile'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1509File'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1509Picture'), + $this->_em->getClassMetadata(DDC1509AbstractFile::class), + $this->_em->getClassMetadata(DDC1509File::class), + $this->_em->getClassMetadata(DDC1509Picture::class), ] ); } catch (\Exception $ignored) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1514Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1514Test.php index 36dd46748c9..1fc8a06efad 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1514Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1514Test.php @@ -16,9 +16,9 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1514EntityA'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1514EntityB'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1514EntityC'), + $this->_em->getClassMetadata(DDC1514EntityA::class), + $this->_em->getClassMetadata(DDC1514EntityB::class), + $this->_em->getClassMetadata(DDC1514EntityC::class), ] ); } catch (\Exception $ignored) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1515Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1515Test.php index 2ceaaa1043e..294ae87388f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1515Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1515Test.php @@ -13,8 +13,8 @@ public function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1515Foo'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1515Bar'), + $this->_em->getClassMetadata(DDC1515Foo::class), + $this->_em->getClassMetadata(DDC1515Bar::class), ] ); } @@ -31,8 +31,8 @@ public function testIssue() $this->_em->flush(); $this->_em->clear(); - $bar = $this->_em->find(__NAMESPACE__ . '\DDC1515Bar', $bar->id); - $this->assertInstanceOf(__NAMESPACE__.'\DDC1515Foo', $bar->foo); + $bar = $this->_em->find(DDC1515Bar::class, $bar->id); + $this->assertInstanceOf(DDC1515Foo::class, $bar->foo); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1526Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1526Test.php index c33549afb5d..7a76e3fb938 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1526Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1526Test.php @@ -12,7 +12,7 @@ public function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1526Menu'), + $this->_em->getClassMetadata(DDC1526Menu::class), ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1545Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1545Test.php index 7f79ac96ee7..20ebe424c5c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1545Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1545Test.php @@ -58,9 +58,9 @@ public function testLinkObjects() $this->initDb(false); // don't join association - $article = $this->_em->find('Doctrine\Tests\Models\Cms\CmsArticle', $this->articleId); + $article = $this->_em->find(CmsArticle::class, $this->articleId); - $user = $this->_em->find('Doctrine\Tests\Models\Cms\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $article->user = $user; @@ -86,7 +86,7 @@ public function testLinkObjectsWithAssociationLoaded() ->setParameter('id', $this->articleId) ->getOneOrNullResult(); - $user = $this->_em->find('Doctrine\Tests\Models\Cms\CmsUser', $this->userId); + $user = $this->_em->find(CmsUser::class, $this->userId); $article->user = $user; @@ -107,7 +107,7 @@ public function testUnlinkObjects() $this->initDb(true); // don't join association - $article = $this->_em->find('Doctrine\Tests\Models\Cms\CmsArticle', $this->articleId); + $article = $this->_em->find(CmsArticle::class, $this->articleId); $article->user = null; @@ -150,9 +150,9 @@ public function testChangeLink() $this->initDb(false); // don't join association - $article = $this->_em->find('Doctrine\Tests\Models\Cms\CmsArticle', $this->articleId); + $article = $this->_em->find(CmsArticle::class, $this->articleId); - $user2 = $this->_em->find('Doctrine\Tests\Models\Cms\CmsUser', $this->user2Id); + $user2 = $this->_em->find(CmsUser::class, $this->user2Id); $article->user = $user2; @@ -178,7 +178,7 @@ public function testChangeLinkWithAssociationLoaded() ->setParameter('id', $this->articleId) ->getOneOrNullResult(); - $user2 = $this->_em->find('Doctrine\Tests\Models\Cms\CmsUser', $this->user2Id); + $user2 = $this->_em->find(CmsUser::class, $this->user2Id); $article->user = $user2; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1548Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1548Test.php index 179d4914c30..6628586cc91 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1548Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1548Test.php @@ -12,9 +12,9 @@ public function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1548E1'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1548E2'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1548Rel'), + $this->_em->getClassMetadata(DDC1548E1::class), + $this->_em->getClassMetadata(DDC1548E2::class), + $this->_em->getClassMetadata(DDC1548Rel::class), ] ); } @@ -31,7 +31,7 @@ public function testIssue() $this->_em->flush(); $this->_em->clear(); - $obt = $this->_em->find(__NAMESPACE__ . '\DDC1548Rel', $rel->id); + $obt = $this->_em->find(DDC1548Rel::class, $rel->id); $this->assertNull($obt->e2); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1595Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1595Test.php index c44896b8585..5f0e128b5c0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1595Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1595Test.php @@ -17,9 +17,9 @@ public function setUp() $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1595BaseInheritance'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1595InheritedEntity1'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1595InheritedEntity2'), + $this->_em->getClassMetadata(DDC1595BaseInheritance::class), + $this->_em->getClassMetadata(DDC1595InheritedEntity1::class), + $this->_em->getClassMetadata(DDC1595InheritedEntity2::class), ] ); } @@ -33,7 +33,7 @@ public function testIssue() $this->_em->clear(); $sqlLogger = $this->_em->getConnection()->getConfiguration()->getSQLLogger(); - $repository = $this->_em->getRepository(__NAMESPACE__ . '\\DDC1595InheritedEntity1'); + $repository = $this->_em->getRepository(DDC1595InheritedEntity1::class); $entity1 = $repository->find($e1->id); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1654Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1654Test.php index aad2902d96e..a5a620f63da 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1654Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1654Test.php @@ -12,8 +12,8 @@ public function setUp() parent::setUp(); $this->setUpEntitySchema( [ - __NAMESPACE__ . '\\DDC1654Post', - __NAMESPACE__ . '\\DDC1654Comment', + DDC1654Post::class, + DDC1654Comment::class, ] ); } @@ -41,7 +41,7 @@ public function testManyToManyRemoveFromCollectionOrphanRemoval() $this->_em->flush(); $this->_em->clear(); - $comments = $this->_em->getRepository(__NAMESPACE__ . '\\DDC1654Comment')->findAll(); + $comments = $this->_em->getRepository(DDC1654Comment::class)->findAll(); $this->assertEquals(0, count($comments)); } @@ -60,7 +60,7 @@ public function testManyToManyRemoveElementFromCollectionOrphanRemoval() $this->_em->flush(); $this->_em->clear(); - $comments = $this->_em->getRepository(__NAMESPACE__ . '\\DDC1654Comment')->findAll(); + $comments = $this->_em->getRepository(DDC1654Comment::class)->findAll(); $this->assertEquals(0, count($comments)); } @@ -83,7 +83,7 @@ public function testManyToManyRemoveElementFromReAddToCollectionOrphanRemoval() $this->_em->flush(); $this->_em->clear(); - $comments = $this->_em->getRepository(__NAMESPACE__ . '\\DDC1654Comment')->findAll(); + $comments = $this->_em->getRepository(DDC1654Comment::class)->findAll(); $this->assertEquals(2, count($comments)); } @@ -101,7 +101,7 @@ public function testManyToManyClearCollectionOrphanRemoval() $this->_em->flush(); $this->_em->clear(); - $comments = $this->_em->getRepository(__NAMESPACE__ . '\\DDC1654Comment')->findAll(); + $comments = $this->_em->getRepository(DDC1654Comment::class)->findAll(); $this->assertEquals(0, count($comments)); } @@ -125,7 +125,7 @@ public function testManyToManyClearCollectionReAddOrphanRemoval() $this->_em->flush(); $this->_em->clear(); - $comments = $this->_em->getRepository(__NAMESPACE__ . '\\DDC1654Comment')->findAll(); + $comments = $this->_em->getRepository(DDC1654Comment::class)->findAll(); $this->assertEquals(1, count($comments)); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1655Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1655Test.php index 3b24b4d91ad..a63d3635fe5 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1655Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1655Test.php @@ -16,9 +16,9 @@ public function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1655Foo'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1655Bar'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1655Baz'), + $this->_em->getClassMetadata(DDC1655Foo::class), + $this->_em->getClassMetadata(DDC1655Bar::class), + $this->_em->getClassMetadata(DDC1655Baz::class), ] ); } catch(\Exception $e) { @@ -27,10 +27,10 @@ public function setUp() public function testPostLoadOneToManyInheritance() { - $cm = $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1655Foo'); + $cm = $this->_em->getClassMetadata(DDC1655Foo::class); $this->assertEquals(["postLoad" => ["postLoad"]], $cm->lifecycleCallbacks); - $cm = $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1655Bar'); + $cm = $this->_em->getClassMetadata(DDC1655Bar::class); $this->assertEquals(["postLoad" => ["postLoad", "postSubLoaded"]], $cm->lifecycleCallbacks); $baz = new DDC1655Baz(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1685Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1685Test.php index 52e02839460..576b4e28628 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1685Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1685Test.php @@ -41,7 +41,7 @@ public function testPaginateCount() public function testPaginateIterate() { foreach ($this->paginator as $ad) { - $this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails', $ad); + $this->assertInstanceOf(DDC117ArticleDetails::class, $ad); } } @@ -59,7 +59,7 @@ public function testPaginateIterateNoOutputWalkers() $this->expectExceptionMessage('Paginating an entity with foreign key as identifier only works when using the Output Walkers. Call Paginator#setUseOutputWalkers(true) before iterating the paginator.'); foreach ($this->paginator as $ad) { - $this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails', $ad); + $this->assertInstanceOf(DDC117ArticleDetails::class, $ad); } } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC168Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC168Test.php index 75924f135aa..ddaa83d80eb 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC168Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC168Test.php @@ -12,16 +12,16 @@ protected function setUp() { $this->useModelSet('company'); parent::setUp(); - $this->oldMetadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\Company\CompanyEmployee'); + $this->oldMetadata = $this->_em->getClassMetadata(CompanyEmployee::class); $metadata = clone $this->oldMetadata; ksort($metadata->reflFields); - $this->_em->getMetadataFactory()->setMetadataFor('Doctrine\Tests\Models\Company\CompanyEmployee', $metadata); + $this->_em->getMetadataFactory()->setMetadataFor(CompanyEmployee::class, $metadata); } public function tearDown() { - $this->_em->getMetadataFactory()->setMetadataFor('Doctrine\Tests\Models\Company\CompanyEmployee', $this->oldMetadata); + $this->_em->getMetadataFactory()->setMetadataFor(CompanyEmployee::class, $this->oldMetadata); parent::tearDown(); } @@ -56,7 +56,7 @@ public function testJoinedSubclassPersisterRequiresSpecificOrderOfMetadataReflFi $this->assertEquals("bar", $theEmployee->getDepartment()); $this->assertEquals("Foo", $theEmployee->getName()); $this->assertEquals(1000, $theEmployee->getSalary()); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $theEmployee); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $theEmployee->getSpouse()); + $this->assertInstanceOf(CompanyEmployee::class, $theEmployee); + $this->assertInstanceOf(CompanyEmployee::class, $theEmployee->getSpouse()); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1690Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1690Test.php index a108f81b860..47e79ed7aee 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1690Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1690Test.php @@ -2,8 +2,9 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Common\NotifyPropertyChanged, - Doctrine\Common\PropertyChangedListener; +use Doctrine\Common\NotifyPropertyChanged; +use Doctrine\Common\PropertyChangedListener; +use Doctrine\ORM\Proxy\Proxy; class DDC1690Test extends \Doctrine\Tests\OrmFunctionalTestCase { @@ -12,8 +13,8 @@ protected function setUp() { try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1690Parent'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1690Child') + $this->_em->getClassMetadata(DDC1690Parent::class), + $this->_em->getClassMetadata(DDC1690Child::class) ] ); } catch (\Exception $e) { @@ -47,28 +48,24 @@ public function testChangeTracking() $childId = $child->getId(); unset($parent, $child); - $parent = $this->_em->find(__NAMESPACE__.'\DDC1690Parent', $parentId); - $child = $this->_em->find(__NAMESPACE__.'\DDC1690Child', $childId); + $parent = $this->_em->find(DDC1690Parent::class, $parentId); + $child = $this->_em->find(DDC1690Child::class, $childId); $this->assertEquals(1, count($parent->listeners)); - $this->assertInstanceOf( - 'Doctrine\\ORM\\Proxy\\Proxy', - $child, - 'Verifying that $child is a proxy before using proxy API' - ); + $this->assertInstanceOf(Proxy::class, $child, 'Verifying that $child is a proxy before using proxy API'); $this->assertCount(0, $child->listeners); $child->__load(); $this->assertCount(1, $child->listeners); unset($parent, $child); - $parent = $this->_em->find(__NAMESPACE__.'\DDC1690Parent', $parentId); + $parent = $this->_em->find(DDC1690Parent::class, $parentId); $child = $parent->getChild(); $this->assertEquals(1, count($parent->listeners)); $this->assertEquals(1, count($child->listeners)); unset($parent, $child); - $child = $this->_em->find(__NAMESPACE__.'\DDC1690Child', $childId); + $child = $this->_em->find(DDC1690Child::class, $childId); $parent = $child->getParent(); $this->assertEquals(1, count($parent->listeners)); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1707Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1707Test.php index dd6dcaeebfd..54b52a57bd1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1707Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1707Test.php @@ -17,8 +17,8 @@ public function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1509File'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1509Picture'), + $this->_em->getClassMetadata(DDC1509File::class), + $this->_em->getClassMetadata(DDC1509Picture::class), ] ); } catch (\Exception $ignored) { @@ -28,7 +28,7 @@ public function setUp() public function testPostLoadOnChild() { - $class = $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1707Child'); + $class = $this->_em->getClassMetadata(DDC1707Child::class); $entity = new DDC1707Child(); $class->invokeLifecycleCallbacks(Events::postLoad, $entity); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php index fe5a0de65b5..b3784ff8a7c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php @@ -2,22 +2,18 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Tests\Models\Quote\SimpleEntity; - /** * @group DDC-1719 */ class DDC1719Test extends \Doctrine\Tests\OrmFunctionalTestCase { - const CLASS_NAME = 'Doctrine\Tests\ORM\Functional\Ticket\DDC1719SimpleEntity'; - protected function setUp() { parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(self::CLASS_NAME), + $this->_em->getClassMetadata(DDC1719SimpleEntity::class), ] ); } @@ -28,7 +24,7 @@ protected function tearDown() $this->_schemaTool->dropSchema( [ - $this->_em->getClassMetadata(self::CLASS_NAME), + $this->_em->getClassMetadata(DDC1719SimpleEntity::class), ] ); } @@ -48,11 +44,11 @@ public function testCreateRetrieveUpdateDelete() $e2Id = $e2->id; // Retrieve - $e1 = $this->_em->find(self::CLASS_NAME, $e1Id); - $e2 = $this->_em->find(self::CLASS_NAME, $e2Id); + $e1 = $this->_em->find(DDC1719SimpleEntity::class, $e1Id); + $e2 = $this->_em->find(DDC1719SimpleEntity::class, $e2Id); - $this->assertInstanceOf(self::CLASS_NAME, $e1); - $this->assertInstanceOf(self::CLASS_NAME, $e2); + $this->assertInstanceOf(DDC1719SimpleEntity::class, $e1); + $this->assertInstanceOf(DDC1719SimpleEntity::class, $e2); $this->assertEquals($e1Id, $e1->id); $this->assertEquals($e2Id, $e2->id); @@ -71,8 +67,8 @@ public function testCreateRetrieveUpdateDelete() $this->assertEquals('Bar 2', $e1->value); $this->assertEquals('Foo 2', $e2->value); - $this->assertInstanceOf(self::CLASS_NAME, $e1); - $this->assertInstanceOf(self::CLASS_NAME, $e2); + $this->assertInstanceOf(DDC1719SimpleEntity::class, $e1); + $this->assertInstanceOf(DDC1719SimpleEntity::class, $e2); $this->assertEquals($e1Id, $e1->id); $this->assertEquals($e2Id, $e2->id); @@ -86,8 +82,8 @@ public function testCreateRetrieveUpdateDelete() $this->_em->flush(); - $e1 = $this->_em->find(self::CLASS_NAME, $e1Id); - $e2 = $this->_em->find(self::CLASS_NAME, $e2Id); + $e1 = $this->_em->find(DDC1719SimpleEntity::class, $e1Id); + $e2 = $this->_em->find(DDC1719SimpleEntity::class, $e2Id); $this->assertNull($e1); $this->assertNull($e2); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1734Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1734Test.php index f0abda67ddb..cfca544ae81 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1734Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1734Test.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\ORM\Proxy\Proxy; use Doctrine\Tests\Models\CMS\CmsGroup; class DDC1734Test extends \Doctrine\Tests\OrmFunctionalTestCase @@ -31,7 +32,7 @@ public function testMergeWorksOnNonSerializedProxies() $proxy = $this->getProxy($group); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $proxy); + $this->assertInstanceOf(Proxy::class, $proxy); $this->assertFalse($proxy->__isInitialized()); $this->_em->detach($proxy); @@ -61,7 +62,7 @@ public function testMergeWorksOnSerializedProxies() $proxy = $this->getProxy($group); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $proxy); + $this->assertInstanceOf(Proxy::class, $proxy); $this->assertFalse($proxy->__isInitialized()); $this->_em->detach($proxy); @@ -86,4 +87,4 @@ private function getProxy($object) return $this->_em->getProxyFactory()->getProxy($className, $identifier); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php index 13b1868d532..54245368a26 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php @@ -12,8 +12,8 @@ public function testFailingCase() /* @var $qb \Doctrine\ORM\QueryBuilder */ $qb->select('_a') - ->from(__NAMESPACE__ . '\DDC1757A', '_a') - ->from(__NAMESPACE__ . '\DDC1757B', '_b') + ->from(DDC1757A::class, '_a') + ->from(DDC1757B::class, '_b') ->join('_b.c', '_c') ->join('_c.d', '_d'); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1778Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1778Test.php index b2e02c26be1..09623f13535 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1778Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1778Test.php @@ -32,8 +32,8 @@ public function setUp() $this->_em->flush(); $this->_em->clear(); - $this->user = $this->_em->find('Doctrine\\Tests\\Models\\CMS\\CmsUser', $this->user->getId()); - $this->phone = $this->_em->find('Doctrine\\Tests\\Models\\CMS\\CmsPhonenumber', $this->phone->phonenumber); + $this->user = $this->_em->find(CmsUser::class, $this->user->getId()); + $this->phone = $this->_em->find(CmsPhonenumber::class, $this->phone->phonenumber); } public function testClear() @@ -43,7 +43,7 @@ public function testClear() $this->_em->flush(); $this->_em->clear(); - $this->user = $this->_em->find('Doctrine\\Tests\\Models\\CMS\\CmsUser', $this->user->getId()); + $this->user = $this->_em->find(CmsUser::class, $this->user->getId()); $this->assertCount(1, $this->user->getPhonenumbers()); } @@ -55,7 +55,7 @@ public function testRemove() $this->_em->flush(); $this->_em->clear(); - $this->user = $this->_em->find('Doctrine\\Tests\\Models\\CMS\\CmsUser', $this->user->getId()); + $this->user = $this->_em->find(CmsUser::class, $this->user->getId()); $this->assertCount(1, $this->user->getPhonenumbers()); } @@ -67,7 +67,7 @@ public function testRemoveElement() $this->_em->flush(); $this->_em->clear(); - $this->user = $this->_em->find('Doctrine\\Tests\\Models\\CMS\\CmsUser', $this->user->getId()); + $this->user = $this->_em->find(CmsUser::class, $this->user->getId()); $this->assertCount(1, $this->user->getPhonenumbers()); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1787Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1787Test.php index 13410803050..17f28658a5d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1787Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1787Test.php @@ -12,8 +12,8 @@ public function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1787Foo'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1787Bar'), + $this->_em->getClassMetadata(DDC1787Foo::class), + $this->_em->getClassMetadata(DDC1787Bar::class), ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php index 6cf8c68c4c4..4273a36b6af 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php @@ -2,7 +2,10 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\Tests\Models\Quote\Address; use Doctrine\Tests\Models\Quote\Group; +use Doctrine\Tests\Models\Quote\Phone; +use Doctrine\Tests\Models\Quote\User; /** * @group DDC-1845 @@ -18,10 +21,10 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\User'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Group'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Phone'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Address'), + $this->_em->getClassMetadata(User::class), + $this->_em->getClassMetadata(Group::class), + $this->_em->getClassMetadata(Phone::class), + $this->_em->getClassMetadata(Address::class), ] ); } catch(\Exception $e) { @@ -53,15 +56,15 @@ public function testCreateRetrieveUpdateDelete() $e4Id = $e4->id; // Retrieve - $e1 = $this->_em->find('Doctrine\Tests\Models\Quote\Group', $e1Id); - $e2 = $this->_em->find('Doctrine\Tests\Models\Quote\Group', $e2Id); - $e3 = $this->_em->find('Doctrine\Tests\Models\Quote\Group', $e3Id); - $e4 = $this->_em->find('Doctrine\Tests\Models\Quote\Group', $e4Id); + $e1 = $this->_em->find(Group::class, $e1Id); + $e2 = $this->_em->find(Group::class, $e2Id); + $e3 = $this->_em->find(Group::class, $e3Id); + $e4 = $this->_em->find(Group::class, $e4Id); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $e1); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $e2); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $e3); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $e4); + $this->assertInstanceOf(Group::class, $e1); + $this->assertInstanceOf(Group::class, $e2); + $this->assertInstanceOf(Group::class, $e3); + $this->assertInstanceOf(Group::class, $e4); $this->assertEquals($e1Id, $e1->id); $this->assertEquals($e2Id, $e2->id); @@ -91,10 +94,10 @@ public function testCreateRetrieveUpdateDelete() $this->assertEquals('Bar 33', $e3->name); $this->assertEquals('Foo 44', $e4->name); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $e1); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $e2); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $e3); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $e4); + $this->assertInstanceOf(Group::class, $e1); + $this->assertInstanceOf(Group::class, $e2); + $this->assertInstanceOf(Group::class, $e3); + $this->assertInstanceOf(Group::class, $e4); $this->assertEquals($e1Id, $e1->id); $this->assertEquals($e2Id, $e2->id); @@ -116,16 +119,16 @@ public function testCreateRetrieveUpdateDelete() $this->_em->clear(); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $e1); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $e2); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $e3); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $e4); + $this->assertInstanceOf(Group::class, $e1); + $this->assertInstanceOf(Group::class, $e2); + $this->assertInstanceOf(Group::class, $e3); + $this->assertInstanceOf(Group::class, $e4); // Retrieve - $e1 = $this->_em->find('Doctrine\Tests\Models\Quote\Group', $e1Id); - $e2 = $this->_em->find('Doctrine\Tests\Models\Quote\Group', $e2Id); - $e3 = $this->_em->find('Doctrine\Tests\Models\Quote\Group', $e3Id); - $e4 = $this->_em->find('Doctrine\Tests\Models\Quote\Group', $e4Id); + $e1 = $this->_em->find(Group::class, $e1Id); + $e2 = $this->_em->find(Group::class, $e2Id); + $e3 = $this->_em->find(Group::class, $e3Id); + $e4 = $this->_em->find(Group::class, $e4Id); $this->assertNull($e1); $this->assertNull($e2); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1884Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1884Test.php index 2e638278d93..938459ad465 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1884Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1884Test.php @@ -1,8 +1,10 @@ useModelSet('taxi'); parent::setUp(); - list($bimmer, $crysler, $merc, $volvo) = $this->createCars('Doctrine\Tests\Models\Taxi\Car'); - list($john, $foo) = $this->createDrivers('Doctrine\Tests\Models\Taxi\Driver'); + list($bimmer, $crysler, $merc, $volvo) = $this->createCars(Car::class); + list($john, $foo) = $this->createDrivers(Driver::class); $this->_em->flush(); $ride1 = new Ride($john, $bimmer); @@ -98,7 +100,7 @@ public function testSelectFromInverseSideWithCompositePkAndSolelyIdentifierColum $qb = $this->_em->createQueryBuilder(); $result = $qb->select('d, dr, c') - ->from('Doctrine\Tests\Models\Taxi\Driver', 'd') + ->from(Driver::class, 'd') ->leftJoin('d.freeDriverRides', 'dr') ->leftJoin('dr.car', 'c') ->where('d.name = ?1') @@ -120,7 +122,7 @@ public function testSelectFromInverseSideWithCompositePkUsingFetchJoins() $qb = $this->_em->createQueryBuilder(); $result = $qb->select('d, dr, c') - ->from('Doctrine\Tests\Models\Taxi\Driver', 'd') + ->from(Driver::class, 'd') ->leftJoin('d.driverRides', 'dr') ->leftJoin('dr.car', 'c') ->where('d.name = ?1') @@ -140,7 +142,7 @@ public function testSelectFromOwningSideUsingFetchJoins() $qb = $this->_em->createQueryBuilder(); $result = $qb->select('r, d, c') - ->from('Doctrine\Tests\Models\Taxi\PaidRide', 'r') + ->from(PaidRide::class, 'r') ->leftJoin('r.driver', 'd') ->leftJoin('r.car', 'c') ->where('d.name = ?1') diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1885Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1885Test.php index 356a2c881d0..283340b820a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1885Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1885Test.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\Tests\Models\Quote\Address; use Doctrine\Tests\Models\Quote\Group; use Doctrine\Tests\Models\Quote\User; @@ -24,9 +25,9 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\User'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Group'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Address'), + $this->_em->getClassMetadata(User::class), + $this->_em->getClassMetadata(Group::class), + $this->_em->getClassMetadata(Address::class), ] ); } catch(\Exception $e) { @@ -57,9 +58,9 @@ public function testCreateRetrieveUpdateDelete() $g2Id = $g2->id; // Retrieve - $user = $this->_em->find('Doctrine\Tests\Models\Quote\User', $u1Id); + $user = $this->_em->find(User::class, $u1Id); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\User', $user); + $this->assertInstanceOf(User::class, $user); $this->assertEquals('FabioBatSilva', $user->name); $this->assertEquals($u1Id, $user->id); @@ -68,8 +69,8 @@ public function testCreateRetrieveUpdateDelete() $g1 = $user->getGroups()->get(0); $g2 = $user->getGroups()->get(1); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $g1); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $g2); + $this->assertInstanceOf(Group::class, $g1); + $this->assertInstanceOf(Group::class, $g2); $g1->name = 'Bar 11'; $g2->name = 'Foo 22'; @@ -79,9 +80,9 @@ public function testCreateRetrieveUpdateDelete() $this->_em->flush(); $this->_em->clear(); - $user = $this->_em->find('Doctrine\Tests\Models\Quote\User', $u1Id); + $user = $this->_em->find(User::class, $u1Id); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\User', $user); + $this->assertInstanceOf(User::class, $user); $this->assertEquals('FabioBatSilva', $user->name); $this->assertEquals($u1Id, $user->id); @@ -91,24 +92,24 @@ public function testCreateRetrieveUpdateDelete() $this->_em->flush(); $this->_em->clear(); - $this->assertNull($this->_em->find('Doctrine\Tests\Models\Quote\User', $u1Id)); - $this->assertNull($this->_em->find('Doctrine\Tests\Models\Quote\Group', $g1Id)); - $this->assertNull($this->_em->find('Doctrine\Tests\Models\Quote\Group', $g2Id)); + $this->assertNull($this->_em->find(User::class, $u1Id)); + $this->assertNull($this->_em->find(Group::class, $g1Id)); + $this->assertNull($this->_em->find(Group::class, $g2Id)); } public function testRemoveItem() { $user = $this->user; $u1Id = $user->id; - $user = $this->_em->find('Doctrine\Tests\Models\Quote\User', $u1Id); + $user = $this->_em->find(User::class, $u1Id); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\User', $user); + $this->assertInstanceOf(User::class, $user); $this->assertEquals('FabioBatSilva', $user->name); $this->assertEquals($u1Id, $user->id); $this->assertCount(2, $user->groups); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $user->getGroups()->get(0)); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $user->getGroups()->get(1)); + $this->assertInstanceOf(Group::class, $user->getGroups()->get(0)); + $this->assertInstanceOf(Group::class, $user->getGroups()->get(1)); $user->getGroups()->remove(0); @@ -117,9 +118,9 @@ public function testRemoveItem() $this->_em->flush(); $this->_em->clear(); - $user = $this->_em->find('Doctrine\Tests\Models\Quote\User', $u1Id); + $user = $this->_em->find(User::class, $u1Id); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\User', $user); + $this->assertInstanceOf(User::class, $user); $this->assertEquals('FabioBatSilva', $user->name); $this->assertEquals($u1Id, $user->id); @@ -130,15 +131,15 @@ public function testClearAll() { $user = $this->user; $u1Id = $user->id; - $user = $this->_em->find('Doctrine\Tests\Models\Quote\User', $u1Id); + $user = $this->_em->find(User::class, $u1Id); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\User', $user); + $this->assertInstanceOf(User::class, $user); $this->assertEquals('FabioBatSilva', $user->name); $this->assertEquals($u1Id, $user->id); $this->assertCount(2, $user->groups); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $user->getGroups()->get(0)); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $user->getGroups()->get(1)); + $this->assertInstanceOf(Group::class, $user->getGroups()->get(0)); + $this->assertInstanceOf(Group::class, $user->getGroups()->get(1)); $user->getGroups()->clear(); @@ -147,9 +148,9 @@ public function testClearAll() $this->_em->flush(); $this->_em->clear(); - $user = $this->_em->find('Doctrine\Tests\Models\Quote\User', $u1Id); + $user = $this->_em->find(User::class, $u1Id); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\User', $user); + $this->assertInstanceOf(User::class, $user); $this->assertEquals('FabioBatSilva', $user->name); $this->assertEquals($u1Id, $user->id); @@ -160,14 +161,14 @@ public function testCountExtraLazy() { $user = $this->user; $u1Id = $user->id; - $user = $this->_em->find('Doctrine\Tests\Models\Quote\User', $u1Id); + $user = $this->_em->find(User::class, $u1Id); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\User', $user); + $this->assertInstanceOf(User::class, $user); $this->assertEquals('FabioBatSilva', $user->name); $this->assertEquals($u1Id, $user->id); $this->assertCount(2, $user->groups); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $user->getGroups()->get(0)); - $this->assertInstanceOf('Doctrine\Tests\Models\Quote\Group', $user->getGroups()->get(1)); + $this->assertInstanceOf(Group::class, $user->getGroups()->get(0)); + $this->assertInstanceOf(Group::class, $user->getGroups()->get(1)); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1925Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1925Test.php index f42a3655f74..c61fae9c6a1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1925Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1925Test.php @@ -14,8 +14,8 @@ public function testIssue() { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1925User'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1925Product'), + $this->_em->getClassMetadata(DDC1925User::class), + $this->_em->getClassMetadata(DDC1925Product::class), ] ); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC192Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC192Test.php index 2627a17d803..f6f0f173d1c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC192Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC192Test.php @@ -10,8 +10,8 @@ public function testSchemaCreation() { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC192User'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC192Phonenumber') + $this->_em->getClassMetadata(DDC192User::class), + $this->_em->getClassMetadata(DDC192Phonenumber::class) ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1995Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1995Test.php index 0bfd73960b2..fb32b99fe51 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1995Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1995Test.php @@ -15,7 +15,7 @@ public function setUp() $this->useModelSet('company'); parent::setUp(); } - + public function testIssue() { $person = new CompanyPerson; @@ -32,14 +32,14 @@ public function testIssue() $this->_em->clear(); $dql = 'SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF ?1'; - $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\Company\CompanyEmployee'); + $class = $this->_em->getClassMetadata(CompanyEmployee::class); $result = $this->_em->createQuery($dql) ->setParameter(1, $class) ->getResult(); $this->assertCount(1, $result); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $result[0]); + $this->assertInstanceOf(CompanyEmployee::class, $result[0]); } public function testQueryCache() @@ -58,8 +58,8 @@ public function testQueryCache() $this->_em->clear(); $dql = 'SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF :type'; - $class1 = $this->_em->getClassMetadata('Doctrine\Tests\Models\Company\CompanyEmployee'); - $class2 = $this->_em->getClassMetadata('Doctrine\Tests\Models\Company\CompanyPerson'); + $class1 = $this->_em->getClassMetadata(CompanyEmployee::class); + $class2 = $this->_em->getClassMetadata(CompanyPerson::class); $result1 = $this->_em->createQuery($dql) ->setParameter('type', $class1) @@ -74,8 +74,8 @@ public function testQueryCache() $this->assertCount(1, $result1); $this->assertCount(1, $result2); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $result1[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyPerson', $result2[0]); - $this->assertNotInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $result2[0]); + $this->assertInstanceOf(CompanyEmployee::class, $result1[0]); + $this->assertInstanceOf(CompanyPerson::class, $result2[0]); + $this->assertNotInstanceOf(CompanyEmployee::class, $result2[0]); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1998Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1998Test.php index bc2fe26cfc1..74ea2fd8889 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1998Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1998Test.php @@ -13,11 +13,11 @@ class DDC1998Test extends \Doctrine\Tests\OrmFunctionalTestCase { public function testSqlConversionAsIdentifier() { - Type::addType('ddc1998', __NAMESPACE__ . '\\DDC1998Type'); + Type::addType('ddc1998', DDC1998Type::class); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1998Entity'), + $this->_em->getClassMetadata(DDC1998Entity::class), ] ); @@ -36,13 +36,13 @@ public function testSqlConversionAsIdentifier() $this->_em->clear(); - $found = $this->_em->find(__NAMESPACE__ . '\\DDC1998Entity', $entity->id); + $found = $this->_em->find(DDC1998Entity::class, $entity->id); $this->assertNull($found); - $found = $this->_em->find(__NAMESPACE__ . '\\DDC1998Entity', "foo"); + $found = $this->_em->find(DDC1998Entity::class, "foo"); $this->assertNull($found); - $this->assertEquals(0, count($this->_em->getRepository(__NAMESPACE__ . '\\DDC1998Entity')->findAll())); + $this->assertEquals(0, count($this->_em->getRepository(DDC1998Entity::class)->findAll())); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php index 9db6dad961a..2fb3acd33bd 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php @@ -11,9 +11,9 @@ protected function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC199ParentClass'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC199ChildClass'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC199RelatedClass') + $this->_em->getClassMetadata(DDC199ParentClass::class), + $this->_em->getClassMetadata(DDC199ChildClass::class), + $this->_em->getClassMetadata(DDC199RelatedClass::class) ] ); } @@ -42,11 +42,11 @@ public function testPolymorphicLoading() $result = $query->getResult(); $this->assertEquals(1, count($result)); - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC199ParentClass', $result[0]); + $this->assertInstanceOf(DDC199ParentClass::class, $result[0]); $this->assertTrue($result[0]->relatedEntities->isInitialized()); $this->assertEquals(2, $result[0]->relatedEntities->count()); - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC199RelatedClass', $result[0]->relatedEntities[0]); - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC199RelatedClass', $result[0]->relatedEntities[1]); + $this->assertInstanceOf(DDC199RelatedClass::class, $result[0]->relatedEntities[0]); + $this->assertInstanceOf(DDC199RelatedClass::class, $result[0]->relatedEntities[1]); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2012Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2012Test.php index 5d2be3bbc8d..3882408081e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2012Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2012Test.php @@ -15,14 +15,14 @@ protected function setUp() { parent::setUp(); - Type::addType(DDC2012TsVectorType::MYTYPE, __NAMESPACE__ . '\DDC2012TsVectorType'); + Type::addType(DDC2012TsVectorType::MYTYPE, DDC2012TsVectorType::class); DDC2012TsVectorType::$calls = []; $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2012Item'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2012ItemPerson'), + $this->_em->getClassMetadata(DDC2012Item::class), + $this->_em->getClassMetadata(DDC2012ItemPerson::class), ] ); } @@ -46,7 +46,7 @@ public function testIssue() $this->assertCount(1, DDC2012TsVectorType::$calls['convertToDatabaseValue']); $this->assertCount(1, DDC2012TsVectorType::$calls['convertToPHPValue']); - $this->assertInstanceOf(__NAMESPACE__ . '\DDC2012Item', $item); + $this->assertInstanceOf(DDC2012Item::class, $item); $this->assertEquals(['word1', 'word2', 'word3'], $item->tsv); @@ -62,7 +62,7 @@ public function testIssue() $this->assertCount(2, DDC2012TsVectorType::$calls['convertToDatabaseValue']); $this->assertCount(2, DDC2012TsVectorType::$calls['convertToPHPValue']); - $this->assertInstanceOf(__NAMESPACE__ . '\DDC2012Item', $item); + $this->assertInstanceOf(DDC2012Item::class, $item); $this->assertEquals(['word1', 'word2'], $item->tsv); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2074Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2074Test.php index b0ae37e0e74..ed77ba13468 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2074Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2074Test.php @@ -20,7 +20,7 @@ public function setUp() public function testShouldNotScheduleDeletionOnClonedInstances() { - $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceProduct'); + $class = $this->_em->getClassMetadata(ECommerceProduct::class); $product = new ECommerceProduct(); $category = new ECommerceCategory(); $collection = new PersistentCollection($this->_em, $class, new ArrayCollection([$category])); @@ -50,8 +50,8 @@ public function testSavingClonedPersistentCollection() $this->_em->flush(); $this->_em->clear(); - $product1 = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $product->getId()); - $product2 = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $newProduct->getId()); + $product1 = $this->_em->find(ECommerceProduct::class, $product->getId()); + $product2 = $this->_em->find(ECommerceProduct::class, $newProduct->getId()); $this->assertCount(1, $product1->getCategories()); $this->assertCount(1, $product2->getCategories()); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2090Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2090Test.php index dc7563c6600..174fee2b288 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2090Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2090Test.php @@ -18,7 +18,6 @@ public function setUp() public function testIssue() { - $className = 'Doctrine\Tests\Models\Company\CompanyEmployee'; $date1 = new \DateTime('2011-11-11 11:11:11'); $date2 = new \DateTime('2012-12-12 12:12:12'); $employee1 = new CompanyEmployee; @@ -40,7 +39,7 @@ public function testIssue() $this->_em->clear(); $this->_em->createQueryBuilder() - ->update($className, 'e') + ->update(CompanyEmployee::class, 'e') ->set('e.startDate', ':date') ->set('e.salary', ':salary') ->where('e = :e') @@ -56,7 +55,7 @@ public function testIssue() ->execute(); $this->_em->createQueryBuilder() - ->update($className, 'e') + ->update(CompanyEmployee::class, 'e') ->set('e.startDate', ':date') ->set('e.salary', ':salary') ->where('e = :e') @@ -73,8 +72,8 @@ public function testIssue() $this->_em->clear(); - $e1 = $this->_em->find($className, $employee1->getId()); - $e2 = $this->_em->find($className, $employee2->getId()); + $e1 = $this->_em->find(CompanyEmployee::class, $employee1->getId()); + $e2 = $this->_em->find(CompanyEmployee::class, $employee2->getId()); $this->assertEquals(101, $e1->getSalary()); $this->assertEquals(102, $e2->getSalary()); @@ -82,7 +81,7 @@ public function testIssue() $this->assertEquals($date2, $e2->getStartDate()); $this->_em->createQueryBuilder() - ->update($className, 'e') + ->update(CompanyEmployee::class, 'e') ->set('e.startDate', '?1') ->set('e.salary', '?2') ->where('e = ?0') @@ -92,7 +91,7 @@ public function testIssue() ->execute(); $this->_em->createQueryBuilder() - ->update($className, 'e') + ->update(CompanyEmployee::class, 'e') ->set('e.startDate', '?1') ->set('e.salary', '?2') ->where('e = ?0') @@ -104,8 +103,8 @@ public function testIssue() $this->_em->clear(); - $e1 = $this->_em->find($className, $employee1->getId()); - $e2 = $this->_em->find($className, $employee2->getId()); + $e1 = $this->_em->find(CompanyEmployee::class, $employee1->getId()); + $e2 = $this->_em->find(CompanyEmployee::class, $employee2->getId()); $this->assertEquals(101, $e1->getSalary()); $this->assertEquals(102, $e2->getSalary()); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php index 3e3e8670f11..0fdc7f84d3e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php @@ -14,7 +14,7 @@ protected function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2106Entity'), + $this->_em->getClassMetadata(DDC2106Entity::class), ] ); } @@ -26,7 +26,7 @@ public function testDetachedEntityAsId() $this->_em->persist($entity); $this->_em->flush(); $this->_em->detach($entity); - $entity = $this->_em->getRepository(__NAMESPACE__ . '\DDC2106Entity')->findOneBy([]); + $entity = $this->_em->getRepository(DDC2106Entity::class)->findOneBy([]); // ... and a managed entity without id $entityWithoutId = new DDC2106Entity(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC211Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC211Test.php index cd94f75a5f7..9ac27f3cf94 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC211Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC211Test.php @@ -11,8 +11,8 @@ protected function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC211User'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC211Group') + $this->_em->getClassMetadata(DDC211User::class), + $this->_em->getClassMetadata(DDC211Group::class) ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2138Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2138Test.php index a0abb675410..960395e9c70 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2138Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2138Test.php @@ -17,11 +17,11 @@ public function testForeignKeyOnSTIWithMultipleMapping() $schemaTool = new SchemaTool($em); $classes = [ - $em->getClassMetadata(__NAMESPACE__ . '\DDC2138User'), - $em->getClassMetadata(__NAMESPACE__ . '\DDC2138Structure'), - $em->getClassMetadata(__NAMESPACE__ . '\DDC2138UserFollowedObject'), - $em->getClassMetadata(__NAMESPACE__ . '\DDC2138UserFollowedStructure'), - $em->getClassMetadata(__NAMESPACE__ . '\DDC2138UserFollowedUser') + $em->getClassMetadata(DDC2138User::class), + $em->getClassMetadata(DDC2138Structure::class), + $em->getClassMetadata(DDC2138UserFollowedObject::class), + $em->getClassMetadata(DDC2138UserFollowedStructure::class), + $em->getClassMetadata(DDC2138UserFollowedUser::class) ]; $schema = $schemaTool->getSchemaFromMetadata($classes); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2175Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2175Test.php index d1a2e27a9ae..d6b3c603b8f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2175Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2175Test.php @@ -12,7 +12,7 @@ protected function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2175Entity'), + $this->_em->getClassMetadata(DDC2175Entity::class), ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2182Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2182Test.php index 47e6671e8d3..590b7cd5f58 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2182Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2182Test.php @@ -12,8 +12,8 @@ public function testPassColumnOptionsToJoinColumns() $sql = $this->_schemaTool->getCreateSchemaSql( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2182OptionParent'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2182OptionChild'), + $this->_em->getClassMetadata(DDC2182OptionParent::class), + $this->_em->getClassMetadata(DDC2182OptionChild::class), ] ); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2214Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2214Test.php index 03d9b8f5df4..87101fff1da 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2214Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2214Test.php @@ -19,8 +19,8 @@ protected function setUp() $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2214Foo'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2214Bar'), + $this->_em->getClassMetadata(DDC2214Foo::class), + $this->_em->getClassMetadata(DDC2214Bar::class), ] ); } @@ -38,7 +38,7 @@ public function testIssue() $this->_em->clear(); /* @var $foo \Doctrine\Tests\ORM\Functional\Ticket\DDC2214Foo */ - $foo = $this->_em->find(__NAMESPACE__ . '\\DDC2214Foo', $foo->id); + $foo = $this->_em->find(DDC2214Foo::class, $foo->id); $bar = $foo->bar; $logger = $this->_em->getConnection()->getConfiguration()->getSQLLogger(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2224Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2224Test.php index 781d644ff4e..3529fa35640 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2224Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2224Test.php @@ -14,7 +14,7 @@ class DDC2224Test extends \Doctrine\Tests\OrmFunctionalTestCase { public static function setUpBeforeClass() { - \Doctrine\DBAL\Types\Type::addType('DDC2224Type', __NAMESPACE__ . '\DDC2224Type'); + \Doctrine\DBAL\Types\Type::addType('DDC2224Type', DDC2224Type::class); } public function testIssue() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2230Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2230Test.php index accb24a7ab3..4ced4df4dc7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2230Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2230Test.php @@ -4,6 +4,7 @@ use Doctrine\Common\NotifyPropertyChanged; use Doctrine\Common\PropertyChangedListener; +use Doctrine\Common\Proxy\Proxy; use Doctrine\ORM\Tools\ToolsException; use Doctrine\Tests\OrmFunctionalTestCase; @@ -19,8 +20,8 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2230User'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2230Address'), + $this->_em->getClassMetadata(DDC2230User::class), + $this->_em->getClassMetadata(DDC2230Address::class), ] ); } catch (ToolsException $e) {} @@ -36,16 +37,16 @@ public function testNotifyTrackingNotCalledOnUninitializedProxies() $this->_em->flush(); $this->_em->clear(); - $user = $this->_em->find(__NAMESPACE__ . '\\DDC2230User', $insertedUser->id); + $user = $this->_em->find(DDC2230User::class, $insertedUser->id); $this->_em->clear(); $mergedUser = $this->_em->merge($user); - /* @var $address \Doctrine\Common\Proxy\Proxy */ + /* @var $address Proxy */ $address = $mergedUser->address; - $this->assertInstanceOf('Doctrine\\ORM\\Proxy\\Proxy', $address); + $this->assertInstanceOf(Proxy::class, $address); $this->assertFalse($address->__isInitialized()); } @@ -57,9 +58,9 @@ public function testNotifyTrackingCalledOnProxyInitialization() $this->_em->flush(); $this->_em->clear(); - $addressProxy = $this->_em->getReference(__NAMESPACE__ . '\\DDC2230Address', $insertedAddress->id); + $addressProxy = $this->_em->getReference(DDC2230Address::class, $insertedAddress->id); - /* @var $addressProxy \Doctrine\Common\Proxy\Proxy|\Doctrine\Tests\ORM\Functional\Ticket\DDC2230Address */ + /* @var $addressProxy Proxy|\Doctrine\Tests\ORM\Functional\Ticket\DDC2230Address */ $this->assertFalse($addressProxy->__isInitialized()); $this->assertNull($addressProxy->listener); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2231Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2231Test.php index 1caeffcc7f8..6bfd8d823d0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2231Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2231Test.php @@ -5,6 +5,7 @@ use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\Persistence\ObjectManagerAware; +use Doctrine\ORM\Proxy\Proxy; /** * @group DDC-2231 @@ -16,7 +17,7 @@ protected function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2231EntityY'), + $this->_em->getClassMetadata(DDC2231EntityY::class), ] ); } @@ -32,7 +33,7 @@ public function testInjectObjectManagerInProxyIfInitializedInUow() $y1ref = $this->_em->getReference(get_class($y1), $y1->id); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $y1ref); + $this->assertInstanceOf(Proxy::class, $y1ref); $this->assertFalse($y1ref->__isInitialized__); $id = $y1ref->doSomething(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2252Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2252Test.php index 643c054ab8d..e4b60196622 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2252Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2252Test.php @@ -20,10 +20,10 @@ protected function setUp() $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\DDC2252User'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\DDC2252Privilege'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\DDC2252Membership'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\DDC2252MerchantAccount'), + $this->_em->getClassMetadata(DDC2252User::class), + $this->_em->getClassMetadata(DDC2252Privilege::class), + $this->_em->getClassMetadata(DDC2252Membership::class), + $this->_em->getClassMetadata(DDC2252MerchantAccount::class), ] ); @@ -63,10 +63,9 @@ public function testIssue() 'userAccount' => $this->user->getUid(), ]; - $class = 'Doctrine\Tests\ORM\Functional\Ticket\DDC2252Membership'; - $membership = $this->_em->find($class, $identifier); + $membership = $this->_em->find(DDC2252Membership::class, $identifier); - $this->assertInstanceOf($class, $membership); + $this->assertInstanceOf(DDC2252Membership::class, $membership); $this->assertCount(3, $membership->getPrivileges()); $membership->getPrivileges()->remove(2); @@ -74,9 +73,9 @@ public function testIssue() $this->_em->flush(); $this->_em->clear(); - $membership = $this->_em->find($class, $identifier); + $membership = $this->_em->find(DDC2252Membership::class, $identifier); - $this->assertInstanceOf($class, $membership); + $this->assertInstanceOf(DDC2252Membership::class, $membership); $this->assertCount(2, $membership->getPrivileges()); $membership->getPrivileges()->clear(); @@ -84,9 +83,9 @@ public function testIssue() $this->_em->flush(); $this->_em->clear(); - $membership = $this->_em->find($class, $identifier); + $membership = $this->_em->find(DDC2252Membership::class, $identifier); - $this->assertInstanceOf($class, $membership); + $this->assertInstanceOf(DDC2252Membership::class, $membership); $this->assertCount(0, $membership->getPrivileges()); $membership->addPrivilege($privilege3 = new DDC2252Privilege); @@ -95,9 +94,9 @@ public function testIssue() $this->_em->flush(); $this->_em->clear(); - $membership = $this->_em->find($class, $identifier); + $membership = $this->_em->find(DDC2252Membership::class, $identifier); - $this->assertInstanceOf($class, $membership); + $this->assertInstanceOf(DDC2252Membership::class, $membership); $this->assertCount(1, $membership->getPrivileges()); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2256Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2256Test.php index 2ec88f9f374..681210159ef 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2256Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2256Test.php @@ -15,8 +15,8 @@ protected function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2256User'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2256Group') + $this->_em->getClassMetadata(DDC2256User::class), + $this->_em->getClassMetadata(DDC2256Group::class) ] ); } @@ -24,7 +24,7 @@ protected function setUp() public function testIssue() { $config = $this->_em->getConfiguration(); - $config->addEntityNamespace('MyNamespace', 'Doctrine\Tests\ORM\Functional\Ticket'); + $config->addEntityNamespace('MyNamespace', __NAMESPACE__); $user = new DDC2256User(); $user->name = 'user'; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2306Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2306Test.php index 81844369813..24807db029a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2306Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2306Test.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\ORM\Proxy\Proxy; /** * @group DDC-2306 @@ -18,10 +19,10 @@ protected function setUp() $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2306Zone'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2306User'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2306Address'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2306UserAddress'), + $this->_em->getClassMetadata(DDC2306Zone::class), + $this->_em->getClassMetadata(DDC2306User::class), + $this->_em->getClassMetadata(DDC2306Address::class), + $this->_em->getClassMetadata(DDC2306UserAddress::class), ] ); } @@ -55,12 +56,12 @@ public function testIssue() $this->_em->clear(); /* @var $address DDC2306Address */ - $address = $this->_em->find(__NAMESPACE__ . '\\DDC2306Address', $address->id); - /* @var $user DDC2306User|\Doctrine\ORM\Proxy\Proxy */ + $address = $this->_em->find(DDC2306Address::class, $address->id); + /* @var $user DDC2306User|Proxy */ $user = $address->users->first()->user; - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $user); - $this->assertInstanceOf(__NAMESPACE__ . '\\DDC2306User', $user); + $this->assertInstanceOf(Proxy::class, $user); + $this->assertInstanceOf(DDC2306User::class, $user); $userId = $user->id; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2346Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2346Test.php index 9172904c8f6..a1cac08eaf3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2346Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2346Test.php @@ -24,9 +24,9 @@ protected function setUp() $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2346Foo'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2346Bar'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2346Baz'), + $this->_em->getClassMetadata(DDC2346Foo::class), + $this->_em->getClassMetadata(DDC2346Bar::class), + $this->_em->getClassMetadata(DDC2346Baz::class), ] ); @@ -60,7 +60,7 @@ public function testIssue() $this->_em->getConnection()->getConfiguration()->setSQLLogger($this->logger); - $fetchedBazs = $this->_em->getRepository(__NAMESPACE__ . '\\DDC2346Baz')->findAll(); + $fetchedBazs = $this->_em->getRepository(DDC2346Baz::class)->findAll(); $this->assertCount(2, $fetchedBazs); $this->assertCount(2, $this->logger->queries, 'The total number of executed queries is 2, and not n+1'); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2350Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2350Test.php index 919f74cf787..1d3a4117ad0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2350Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2350Test.php @@ -16,8 +16,8 @@ protected function setUp() $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2350User'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2350Bug'), + $this->_em->getClassMetadata(DDC2350User::class), + $this->_em->getClassMetadata(DDC2350Bug::class), ] ); } @@ -38,7 +38,7 @@ public function testEagerCollectionsAreOnlyRetrievedOnce() $this->_em->clear(); $cnt = $this->getCurrentQueryCount(); - $user = $this->_em->find(__NAMESPACE__ . '\DDC2350User', $user->id); + $user = $this->_em->find(DDC2350User::class, $user->id); $this->assertEquals($cnt + 1, $this->getCurrentQueryCount()); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2359Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2359Test.php index af51a2d7cf3..ba8a621d59b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2359Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2359Test.php @@ -53,7 +53,7 @@ public function testIssue() $metadataFactory->setEntityManager($entityManager); - $this->assertSame($mockMetadata, $metadataFactory->getMetadataFor(__NAMESPACE__ . '\\DDC2359Foo')); + $this->assertSame($mockMetadata, $metadataFactory->getMetadataFor(DDC2359Foo::class)); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php index 22536973994..eac219c7280 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\ORM\Proxy\Proxy; + class DDC237Test extends \Doctrine\Tests\OrmFunctionalTestCase { protected function setUp() @@ -9,9 +11,9 @@ protected function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC237EntityX'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC237EntityY'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC237EntityZ') + $this->_em->getClassMetadata(DDC237EntityX::class), + $this->_em->getClassMetadata(DDC237EntityY::class), + $this->_em->getClassMetadata(DDC237EntityZ::class) ] ); } @@ -37,7 +39,7 @@ public function testUninitializedProxyIsInitializedOnFetchJoin() $this->_em->clear(); $x2 = $this->_em->find(get_class($x), $x->id); // proxy injected for Y - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $x2->y); + $this->assertInstanceOf(Proxy::class, $x2->y); $this->assertFalse($x2->y->__isInitialized__); // proxy for Y is in identity map @@ -45,7 +47,7 @@ public function testUninitializedProxyIsInitializedOnFetchJoin() $z2 = $this->_em->createQuery('select z,y from ' . get_class($z) . ' z join z.y y where z.id = ?1') ->setParameter(1, $z->id) ->getSingleResult(); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $z2->y); + $this->assertInstanceOf(Proxy::class, $z2->y); $this->assertTrue($z2->y->__isInitialized__); $this->assertEquals('Y', $z2->y->data); $this->assertEquals($y->id, $z2->y->id); @@ -56,7 +58,7 @@ public function testUninitializedProxyIsInitializedOnFetchJoin() $this->assertNotSame($x, $x2); $this->assertNotSame($z, $z2); $this->assertSame($z2->y, $x2->y); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $z2->y); + $this->assertInstanceOf(Proxy::class, $z2->y); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2409Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2409Test.php index c8b85f24fc3..94d39b99446 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2409Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2409Test.php @@ -21,7 +21,7 @@ public function testIssue() { $em = $this->_em; $uow = $em->getUnitOfWork(); - + $originalArticle = new CmsArticle(); $originalUser = new CmsUser(); @@ -39,7 +39,7 @@ public function testIssue() $em->flush(); $em->clear(); - $article = $em->find('Doctrine\Tests\Models\CMS\CmsArticle', $originalArticle->id); + $article = $em->find(CmsArticle::class, $originalArticle->id); $user = new CmsUser(); $user->name = 'Doctrine Bot 2.0'; @@ -69,4 +69,4 @@ public function testIssue() $this->assertNotSame($userMerged, $articleMerged->user); $this->assertSame($user, $articleMerged->user); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2415Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2415Test.php index aa29b9fea34..fb1f0ec273a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2415Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2415Test.php @@ -20,20 +20,20 @@ protected function setUp() $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2415ParentEntity'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2415ChildEntity'), + $this->_em->getClassMetadata(DDC2415ParentEntity::class), + $this->_em->getClassMetadata(DDC2415ChildEntity::class), ] ); } public function testTicket() { - $parentMetadata = $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2415ParentEntity'); - $childMetadata = $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2415ChildEntity'); + $parentMetadata = $this->_em->getClassMetadata(DDC2415ParentEntity::class); + $childMetadata = $this->_em->getClassMetadata(DDC2415ChildEntity::class); $this->assertEquals($parentMetadata->generatorType, $childMetadata->generatorType); $this->assertEquals($parentMetadata->customGeneratorDefinition, $childMetadata->customGeneratorDefinition); - $this->assertEquals('Doctrine\Tests\ORM\Functional\Ticket\DDC2415Generator', $parentMetadata->customGeneratorDefinition['class']); + $this->assertEquals(DDC2415Generator::class, $parentMetadata->customGeneratorDefinition['class']); $e1 = new DDC2415ChildEntity("ChildEntity 1"); $e2 = new DDC2415ChildEntity("ChildEntity 2"); @@ -68,11 +68,7 @@ public static function loadMetadata(ClassMetadataInfo $metadata) ); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_CUSTOM); - $metadata->setCustomGeneratorDefinition( - [ - 'class' => 'Doctrine\Tests\ORM\Functional\Ticket\DDC2415Generator' - ] - ); + $metadata->setCustomGeneratorDefinition(['class' => DDC2415Generator::class]); $metadata->isMappedSuperclass = true; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2494Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2494Test.php index 7590a14f1e0..33109ddd761 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2494Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2494Test.php @@ -17,12 +17,12 @@ protected function setUp() DDC2494TinyIntType::$calls = []; - Type::addType('ddc2494_tinyint', __NAMESPACE__ . '\DDC2494TinyIntType'); + Type::addType('ddc2494_tinyint', DDC2494TinyIntType::class); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(DDC2494Currency::CLASSNAME), - $this->_em->getClassMetadata(DDC2494Campaign::CLASSNAME), + $this->_em->getClassMetadata(DDC2494Currency::class), + $this->_em->getClassMetadata(DDC2494Campaign::class), ] ); } @@ -43,10 +43,10 @@ public function testIssue() $this->assertArrayHasKey('convertToDatabaseValue', DDC2494TinyIntType::$calls); $this->assertCount(3, DDC2494TinyIntType::$calls['convertToDatabaseValue']); - $item = $this->_em->find(DDC2494Campaign::CLASSNAME, $campaign->getId()); + $item = $this->_em->find(DDC2494Campaign::class, $campaign->getId()); - $this->assertInstanceOf(DDC2494Campaign::CLASSNAME, $item); - $this->assertInstanceOf(DDC2494Currency::CLASSNAME, $item->getCurrency()); + $this->assertInstanceOf(DDC2494Campaign::class, $item); + $this->assertInstanceOf(DDC2494Currency::class, $item->getCurrency()); $queryCount = $this->getCurrentQueryCount(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2519Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2519Test.php index d6ea115b5ac..cc12d044dc0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2519Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2519Test.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\ORM\Proxy\Proxy; use Doctrine\Tests\Models\Legacy\LegacyUser; use Doctrine\Tests\Models\Legacy\LegacyUserReference; @@ -29,18 +30,18 @@ public function testIssue() $result = $this->_em->createQuery($dql)->getResult(); $this->assertCount(2, $result); - $this->assertInstanceOf('Doctrine\Tests\Models\Legacy\LegacyUserReference', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\Legacy\LegacyUserReference', $result[1]); - - $this->assertInstanceOf('Doctrine\Tests\Models\Legacy\LegacyUser', $result[0]->source()); - $this->assertInstanceOf('Doctrine\Tests\Models\Legacy\LegacyUser', $result[0]->target()); - $this->assertInstanceOf('Doctrine\Tests\Models\Legacy\LegacyUser', $result[1]->source()); - $this->assertInstanceOf('Doctrine\Tests\Models\Legacy\LegacyUser', $result[1]->target()); - - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $result[0]->source()); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $result[0]->target()); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $result[1]->source()); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $result[1]->target()); + $this->assertInstanceOf(LegacyUserReference::class, $result[0]); + $this->assertInstanceOf(LegacyUserReference::class, $result[1]); + + $this->assertInstanceOf(LegacyUser::class, $result[0]->source()); + $this->assertInstanceOf(LegacyUser::class, $result[0]->target()); + $this->assertInstanceOf(LegacyUser::class, $result[1]->source()); + $this->assertInstanceOf(LegacyUser::class, $result[1]->target()); + + $this->assertInstanceOf(Proxy::class, $result[0]->source()); + $this->assertInstanceOf(Proxy::class, $result[0]->target()); + $this->assertInstanceOf(Proxy::class, $result[1]->source()); + $this->assertInstanceOf(Proxy::class, $result[1]->target()); $this->assertFalse($result[0]->target()->__isInitialized()); $this->assertFalse($result[0]->source()->__isInitialized()); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2575Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2575Test.php index 771b8b8012d..e3652e55c04 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2575Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2575Test.php @@ -17,9 +17,9 @@ protected function setUp() $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2575Root'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2575A'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2575B'), + $this->_em->getClassMetadata(DDC2575Root::class), + $this->_em->getClassMetadata(DDC2575A::class), + $this->_em->getClassMetadata(DDC2575B::class), ] ); @@ -55,7 +55,7 @@ protected function setUp() public function testHydrationIssue() { - $repository = $this->_em->getRepository(__NAMESPACE__ . '\DDC2575Root'); + $repository = $this->_em->getRepository(DDC2575Root::class); $qb = $repository->createQueryBuilder('r') ->select('r, a, b') ->leftJoin('r.aRelation', 'a') diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2579Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2579Test.php index f80eba96c80..53ab6550b2a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2579Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2579Test.php @@ -15,13 +15,13 @@ protected function setUp() { parent::setUp(); - Type::addType(DDC2579Type::NAME, DDC2579Type::CLASSNAME); + Type::addType(DDC2579Type::NAME, DDC2579Type::class); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(DDC2579Entity::CLASSNAME), - $this->_em->getClassMetadata(DDC2579EntityAssoc::CLASSNAME), - $this->_em->getClassMetadata(DDC2579AssocAssoc::CLASSNAME), + $this->_em->getClassMetadata(DDC2579Entity::class), + $this->_em->getClassMetadata(DDC2579EntityAssoc::class), + $this->_em->getClassMetadata(DDC2579AssocAssoc::class), ] ); } @@ -32,7 +32,7 @@ public function testIssue() $assoc = new DDC2579AssocAssoc($id); $assocAssoc = new DDC2579EntityAssoc($assoc); $entity = new DDC2579Entity($assocAssoc); - $repository = $this->_em->getRepository(DDC2579Entity::CLASSNAME); + $repository = $this->_em->getRepository(DDC2579Entity::class); $this->_em->persist($assoc); $this->_em->persist($assocAssoc); @@ -50,7 +50,7 @@ public function testIssue() $criteria = ['assoc' => $assoc, 'id' => $id]; $entity = $repository->findOneBy($criteria); - $this->assertInstanceOf(DDC2579Entity::CLASSNAME, $entity); + $this->assertInstanceOf(DDC2579Entity::class, $entity); $this->assertEquals($value, $entity->value); $this->_em->remove($entity); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC258Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC258Test.php index e0cd3257b9a..fb7ce673e3e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC258Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC258Test.php @@ -11,10 +11,10 @@ protected function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC258Super'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC258Class1'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC258Class2'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC258Class3'), + $this->_em->getClassMetadata(DDC258Super::class), + $this->_em->getClassMetadata(DDC258Class1::class), + $this->_em->getClassMetadata(DDC258Class2::class), + $this->_em->getClassMetadata(DDC258Class3::class), ] ); } @@ -45,14 +45,14 @@ public function testIssue() $this->_em->flush(); $this->_em->clear(); - $e2 = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC258Super', $c2->id); + $e2 = $this->_em->find(DDC258Super::class, $c2->id); - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC258Class2', $e2); + $this->assertInstanceOf(DDC258Class2::class, $e2); $this->assertEquals('Bar', $e2->title); $this->assertEquals('Bar', $e2->description); $this->assertEquals('Bar', $e2->text); - $all = $this->_em->getRepository(__NAMESPACE__.'\DDC258Super')->findAll(); + $all = $this->_em->getRepository(DDC258Super::class)->findAll(); foreach ($all as $obj) { if ($obj instanceof DDC258Class1) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2660Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2660Test.php index 0a542b1af7f..18854bcb8e0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2660Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2660Test.php @@ -19,9 +19,9 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2660Product'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2660Customer'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2660CustomerOrder') + $this->_em->getClassMetadata(DDC2660Product::class), + $this->_em->getClassMetadata(DDC2660Customer::class), + $this->_em->getClassMetadata(DDC2660CustomerOrder::class) ] ); } catch(\Exception $e) { @@ -49,7 +49,7 @@ public function testIssueWithExtraColumn() $sql = "SELECT o.product_id, o.customer_id, o.name FROM ddc_2660_customer_order o"; $rsm = new ResultSetMappingBuilder($this->_getEntityManager()); - $rsm->addRootEntityFromClassMetadata(__NAMESPACE__ . '\DDC2660CustomerOrder', 'c'); + $rsm->addRootEntityFromClassMetadata(DDC2660CustomerOrder::class, 'c'); $query = $this->_em->createNativeQuery($sql, $rsm); $result = $query->getResult(); @@ -58,7 +58,7 @@ public function testIssueWithExtraColumn() foreach ($result as $order) { $this->assertNotNull($order); - $this->assertInstanceOf(__NAMESPACE__ . '\\DDC2660CustomerOrder', $order); + $this->assertInstanceOf(DDC2660CustomerOrder::class, $order); } } @@ -67,7 +67,7 @@ public function testIssueWithoutExtraColumn() $sql = "SELECT o.product_id, o.customer_id FROM ddc_2660_customer_order o"; $rsm = new ResultSetMappingBuilder($this->_getEntityManager()); - $rsm->addRootEntityFromClassMetadata(__NAMESPACE__ . '\DDC2660CustomerOrder', 'c'); + $rsm->addRootEntityFromClassMetadata(DDC2660CustomerOrder::class, 'c'); $query = $this->_em->createNativeQuery($sql, $rsm); $result = $query->getResult(); @@ -76,7 +76,7 @@ public function testIssueWithoutExtraColumn() foreach ($result as $order) { $this->assertNotNull($order); - $this->assertInstanceOf(__NAMESPACE__ . '\\DDC2660CustomerOrder', $order); + $this->assertInstanceOf(DDC2660CustomerOrder::class, $order); } } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2692Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2692Test.php index ff4739e48f9..1e9f05e4768 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2692Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2692Test.php @@ -20,7 +20,7 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2692Foo'), + $this->_em->getClassMetadata(DDC2692Foo::class), ] ); } catch(\Exception $e) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2759Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2759Test.php index 1ebb4e9c13f..10d3e68ae91 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2759Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2759Test.php @@ -17,10 +17,10 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2759Qualification'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2759Category'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2759QualificationMetadata'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2759MetadataCategory'), + $this->_em->getClassMetadata(DDC2759Qualification::class), + $this->_em->getClassMetadata(DDC2759Category::class), + $this->_em->getClassMetadata(DDC2759QualificationMetadata::class), + $this->_em->getClassMetadata(DDC2759MetadataCategory::class), ] ); } catch(\Exception $e) { @@ -51,7 +51,7 @@ protected function setUp() public function testCorrectNumberOfAssociationsIsReturned() { - $repository = $this->_em->getRepository(__NAMESPACE__ . '\DDC2759Qualification'); + $repository = $this->_em->getRepository(DDC2759Qualification::class); $builder = $repository->createQueryBuilder('q') ->select('q, qm, qmc') diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2775Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2775Test.php index efc7a628692..025ee763315 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2775Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2775Test.php @@ -17,10 +17,10 @@ protected function setUp() $this->setUpEntitySchema( [ - 'Doctrine\Tests\ORM\Functional\Ticket\User', - 'Doctrine\Tests\ORM\Functional\Ticket\Role', - 'Doctrine\Tests\ORM\Functional\Ticket\AdminRole', - 'Doctrine\Tests\ORM\Functional\Ticket\Authorization', + User::class, + Role::class, + AdminRole::class, + Authorization::class, ] ); } @@ -45,7 +45,7 @@ public function testIssueCascadeRemove() // Need to clear so that associations are lazy-loaded $this->_em->clear(); - $user = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\User', $user->id); + $user = $this->_em->find(User::class, $user->id); $this->_em->remove($user); $this->_em->flush(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC279Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC279Test.php index 499b85b68a4..f09e2e68ccd 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC279Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC279Test.php @@ -9,10 +9,10 @@ protected function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC279EntityXAbstract'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC279EntityX'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC279EntityY'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC279EntityZ'), + $this->_em->getClassMetadata(DDC279EntityXAbstract::class), + $this->_em->getClassMetadata(DDC279EntityX::class), + $this->_em->getClassMetadata(DDC279EntityY::class), + $this->_em->getClassMetadata(DDC279EntityZ::class), ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php index d5b287a7333..179fff8d0e3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php @@ -87,9 +87,9 @@ public function testPersistenceOfEntityWithSchemaMapping($className) public function getTestedClasses() { return [ - [ExplicitSchemaAndTable::CLASSNAME, 'explicit_schema', 'explicit_table'], - [SchemaAndTableInTableName::CLASSNAME, 'implicit_schema', 'implicit_table'], - [DDC2825ClassWithImplicitlyDefinedSchemaAndQuotedTableName::CLASSNAME, 'myschema', 'order'], + [ExplicitSchemaAndTable::class, 'explicit_schema', 'explicit_table'], + [SchemaAndTableInTableName::class, 'implicit_schema', 'implicit_table'], + [DDC2825ClassWithImplicitlyDefinedSchemaAndQuotedTableName::class, 'myschema', 'order'], ]; } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2862Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2862Test.php index d772e441ca3..9a5bccd585f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2862Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2862Test.php @@ -18,8 +18,8 @@ public function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(DDC2862User::CLASSNAME), - $this->_em->getClassMetadata(DDC2862Driver::CLASSNAME), + $this->_em->getClassMetadata(DDC2862User::class), + $this->_em->getClassMetadata(DDC2862Driver::class), ] ); } catch (ToolsException $exc) { @@ -36,30 +36,30 @@ public function testIssue() $this->_em->flush(); $this->_em->clear(); - $this->assertTrue($this->_em->getCache()->containsEntity(DDC2862User::CLASSNAME, ['id' => $user1->getId()])); - $this->assertTrue($this->_em->getCache()->containsEntity(DDC2862Driver::CLASSNAME, ['id' => $driver1->getId()])); + $this->assertTrue($this->_em->getCache()->containsEntity(DDC2862User::class, ['id' => $user1->getId()])); + $this->assertTrue($this->_em->getCache()->containsEntity(DDC2862Driver::class, ['id' => $driver1->getId()])); $queryCount = $this->getCurrentQueryCount(); - $driver2 = $this->_em->find(DDC2862Driver::CLASSNAME, $driver1->getId()); + $driver2 = $this->_em->find(DDC2862Driver::class, $driver1->getId()); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); - $this->assertInstanceOf(DDC2862Driver::CLASSNAME, $driver2); - $this->assertInstanceOf(DDC2862User::CLASSNAME, $driver2->getUserProfile()); + $this->assertInstanceOf(DDC2862Driver::class, $driver2); + $this->assertInstanceOf(DDC2862User::class, $driver2->getUserProfile()); $driver2->setName('Franta'); $this->_em->flush(); $this->_em->clear(); - $this->assertTrue($this->_em->getCache()->containsEntity(DDC2862User::CLASSNAME, ['id' => $user1->getId()])); - $this->assertTrue($this->_em->getCache()->containsEntity(DDC2862Driver::CLASSNAME, ['id' => $driver1->getId()])); + $this->assertTrue($this->_em->getCache()->containsEntity(DDC2862User::class, ['id' => $user1->getId()])); + $this->assertTrue($this->_em->getCache()->containsEntity(DDC2862Driver::class, ['id' => $driver1->getId()])); $queryCount = $this->getCurrentQueryCount(); - $driver3 = $this->_em->find(DDC2862Driver::CLASSNAME, $driver1->getId()); + $driver3 = $this->_em->find(DDC2862Driver::class, $driver1->getId()); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); - $this->assertInstanceOf(DDC2862Driver::CLASSNAME, $driver3); - $this->assertInstanceOf(DDC2862User::CLASSNAME, $driver3->getUserProfile()); + $this->assertInstanceOf(DDC2862Driver::class, $driver3); + $this->assertInstanceOf(DDC2862User::class, $driver3->getUserProfile()); $this->assertEquals('Franta', $driver3->getName()); $this->assertEquals('Foo', $driver3->getUserProfile()->getName()); } @@ -74,38 +74,38 @@ public function testIssueReopened() $this->_em->flush(); $this->_em->clear(); - $this->_em->getCache()->evictEntityRegion(DDC2862User::CLASSNAME); - $this->_em->getCache()->evictEntityRegion(DDC2862Driver::CLASSNAME); + $this->_em->getCache()->evictEntityRegion(DDC2862User::class); + $this->_em->getCache()->evictEntityRegion(DDC2862Driver::class); - $this->assertFalse($this->_em->getCache()->containsEntity(DDC2862User::CLASSNAME, ['id' => $user1->getId()])); - $this->assertFalse($this->_em->getCache()->containsEntity(DDC2862Driver::CLASSNAME, ['id' => $driver1->getId()])); + $this->assertFalse($this->_em->getCache()->containsEntity(DDC2862User::class, ['id' => $user1->getId()])); + $this->assertFalse($this->_em->getCache()->containsEntity(DDC2862Driver::class, ['id' => $driver1->getId()])); $queryCount = $this->getCurrentQueryCount(); - $driver2 = $this->_em->find(DDC2862Driver::CLASSNAME, $driver1->getId()); + $driver2 = $this->_em->find(DDC2862Driver::class, $driver1->getId()); - $this->assertInstanceOf(DDC2862Driver::CLASSNAME, $driver2); - $this->assertInstanceOf(DDC2862User::CLASSNAME, $driver2->getUserProfile()); + $this->assertInstanceOf(DDC2862Driver::class, $driver2); + $this->assertInstanceOf(DDC2862User::class, $driver2->getUserProfile()); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); $this->_em->clear(); - $this->assertFalse($this->_em->getCache()->containsEntity(DDC2862User::CLASSNAME, ['id' => $user1->getId()])); - $this->assertTrue($this->_em->getCache()->containsEntity(DDC2862Driver::CLASSNAME, ['id' => $driver1->getId()])); + $this->assertFalse($this->_em->getCache()->containsEntity(DDC2862User::class, ['id' => $user1->getId()])); + $this->assertTrue($this->_em->getCache()->containsEntity(DDC2862Driver::class, ['id' => $driver1->getId()])); $queryCount = $this->getCurrentQueryCount(); - $driver3 = $this->_em->find(DDC2862Driver::CLASSNAME, $driver1->getId()); + $driver3 = $this->_em->find(DDC2862Driver::class, $driver1->getId()); - $this->assertInstanceOf(DDC2862Driver::CLASSNAME, $driver3); - $this->assertInstanceOf(DDC2862User::CLASSNAME, $driver3->getUserProfile()); + $this->assertInstanceOf(DDC2862Driver::class, $driver3); + $this->assertInstanceOf(DDC2862User::class, $driver3->getUserProfile()); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); $this->assertEquals('Foo', $driver3->getUserProfile()->getName()); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); $queryCount = $this->getCurrentQueryCount(); - $driver4 = $this->_em->find(DDC2862Driver::CLASSNAME, $driver1->getId()); + $driver4 = $this->_em->find(DDC2862Driver::class, $driver1->getId()); - $this->assertInstanceOf(DDC2862Driver::CLASSNAME, $driver4); - $this->assertInstanceOf(DDC2862User::CLASSNAME, $driver4->getUserProfile()); + $this->assertInstanceOf(DDC2862Driver::class, $driver4); + $this->assertInstanceOf(DDC2862User::class, $driver4->getUserProfile()); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); $this->assertEquals('Foo', $driver4->getUserProfile()->getName()); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2895Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2895Test.php index 7f8451a29f1..397c7acd380 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2895Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2895Test.php @@ -15,7 +15,7 @@ public function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC2895'), + $this->_em->getClassMetadata(DDC2895::class), ] ); } catch(\Exception $e) { @@ -25,7 +25,7 @@ public function setUp() public function testPostLoadOneToManyInheritance() { - $cm = $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC2895'); + $cm = $this->_em->getClassMetadata(DDC2895::class); $this->assertEquals( [ diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2931Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2931Test.php index ff494225fee..927856a1c6e 100755 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2931Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2931Test.php @@ -16,7 +16,7 @@ public function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2931User'), + $this->_em->getClassMetadata(DDC2931User::class), ] ); } catch (\Exception $e) { @@ -40,7 +40,7 @@ public function testIssue() $this->_em->flush(); $this->_em->clear(); - $second = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC2931User', $second->id); + $second = $this->_em->find(DDC2931User::class, $second->id); $this->assertSame(2, $second->getRank()); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2943Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2943Test.php index 7ae6ef5f31d..553bc98f528 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2943Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2943Test.php @@ -33,7 +33,7 @@ public function testIssue() { $this->loadFixtures(); - $region = $this->_em->getCache()->getEntityCacheRegion(Country::CLASSNAME); + $region = $this->_em->getCache()->getEntityCacheRegion(Country::class); $dql = 'SELECT c FROM Doctrine\Tests\Models\Cache\Country c'; $query = $this->_em->createQuery($dql) ->setCacheable(true) @@ -52,7 +52,7 @@ public function testIssueNonFetchJoin() { $this->loadFixtures(); - $region = $this->_em->getCache()->getEntityCacheRegion(Country::CLASSNAME); + $region = $this->_em->getCache()->getEntityCacheRegion(Country::class); $dql = 'SELECT c FROM Doctrine\Tests\Models\Cache\Country c'; $query = $this->_em->createQuery($dql) ->setCacheable(true) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2984Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2984Test.php index bf685328f2c..69f4d01c0c5 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2984Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2984Test.php @@ -19,14 +19,14 @@ public function setUp() if ( ! Type::hasType('ddc2984_domain_user_id')) { Type::addType( 'ddc2984_domain_user_id', - __NAMESPACE__ . '\DDC2984UserIdCustomDbalType' + DDC2984UserIdCustomDbalType::class ); } try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2984User'), + $this->_em->getClassMetadata(DDC2984User::class), ] ); } catch (\Exception $e) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2996Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2996Test.php index 897d3bfdf35..4a2436330f0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2996Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2996Test.php @@ -11,8 +11,8 @@ public function testIssue() { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC2996User'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC2996UserPreference'), + $this->_em->getClassMetadata(DDC2996User::class), + $this->_em->getClassMetadata(DDC2996UserPreference::class), ] ); @@ -31,7 +31,7 @@ public function testIssue() $this->_em->clear(); - $pref = $this->_em->find(__NAMESPACE__ . '\\DDC2996UserPreference', $pref->id); + $pref = $this->_em->find(DDC2996UserPreference::class, $pref->id); $this->assertEquals(1, $pref->user->counter); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3033Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3033Test.php index 153457805a8..b25686dce10 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3033Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3033Test.php @@ -14,8 +14,8 @@ public function testIssue() { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC3033User'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC3033Product'), + $this->_em->getClassMetadata(DDC3033User::class), + $this->_em->getClassMetadata(DDC3033Product::class), ] ); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3042Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3042Test.php index 222b30fc027..940989bb713 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3042Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3042Test.php @@ -15,8 +15,8 @@ protected function setUp() $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3042Foo'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3042Bar'), + $this->_em->getClassMetadata(DDC3042Foo::class), + $this->_em->getClassMetadata(DDC3042Bar::class), ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3068Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3068Test.php index 83eb50aa95b..90a3f3ed80e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3068Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3068Test.php @@ -40,21 +40,21 @@ protected function setUp() public function testFindUsingAnArrayOfObjectAsPrimaryKey() { - $ride1 = $this->_em->find('Doctrine\Tests\Models\Taxi\Ride', [ + $ride1 = $this->_em->find(Ride::class, [ 'driver' => $this->foo->getId(), 'car' => $this->merc->getBrand() ] ); - $this->assertInstanceOf('Doctrine\Tests\Models\Taxi\Ride', $ride1); + $this->assertInstanceOf(Ride::class, $ride1); - $ride2 = $this->_em->find('Doctrine\Tests\Models\Taxi\Ride', [ + $ride2 = $this->_em->find(Ride::class, [ 'driver' => $this->foo, 'car' => $this->merc ] ); - $this->assertInstanceOf('Doctrine\Tests\Models\Taxi\Ride', $ride2); + $this->assertInstanceOf(Ride::class, $ride2); $this->assertSame($ride1, $ride2); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC309Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC309Test.php index 4d5583c7507..15454b48269 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC309Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC309Test.php @@ -11,8 +11,8 @@ protected function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC309Country'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC309User'), + $this->_em->getClassMetadata(DDC309Country::class), + $this->_em->getClassMetadata(DDC309User::class), ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3103Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3103Test.php index bb9ccde1758..fe8329345ca 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3103Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3103Test.php @@ -14,10 +14,9 @@ class DDC3103Test extends \Doctrine\Tests\OrmFunctionalTestCase */ public function testIssue() { - $className = __NAMESPACE__ . '\\DDC3103ArticleId'; - $classMetadata = new ClassMetadata($className); + $classMetadata = new ClassMetadata(DDC3103ArticleId::class); - $this->createAnnotationDriver()->loadMetadataForClass($className, $classMetadata); + $this->createAnnotationDriver()->loadMetadataForClass(DDC3103ArticleId::class, $classMetadata); $this->assertTrue( $classMetadata->isEmbeddedClass, diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php index 92f2c1b27ef..ac3f10be61f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php @@ -19,10 +19,10 @@ protected function setUp() $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3170AbstractEntityJoined'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3170ProductJoined'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3170AbstractEntitySingleTable'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3170ProductSingleTable'), + $this->_em->getClassMetadata(DDC3170AbstractEntityJoined::class), + $this->_em->getClassMetadata(DDC3170ProductJoined::class), + $this->_em->getClassMetadata(DDC3170AbstractEntitySingleTable::class), + $this->_em->getClassMetadata(DDC3170ProductSingleTable::class), ] ); } @@ -50,7 +50,7 @@ public function testIssue() try { $this->_em->createQueryBuilder() ->select('p') - ->from(__NAMESPACE__ . '\\DDC3170ProductJoined', 'p') + ->from(DDC3170ProductJoined::class, 'p') ->getQuery() ->getResult(AbstractQuery::HYDRATE_SIMPLEOBJECT); } catch (HydrationException $e) // Thrown by SimpleObjectHydrator @@ -61,7 +61,7 @@ public function testIssue() try { $this->_em->createQueryBuilder() ->select('p') - ->from(__NAMESPACE__ . '\\DDC3170ProductSingleTable', 'p') + ->from(DDC3170ProductSingleTable::class, 'p') ->getQuery() ->getResult(AbstractQuery::HYDRATE_SIMPLEOBJECT); } catch (HydrationException $e) // Thrown by SimpleObjectHydrator diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3192Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3192Test.php index 79dd4267eb5..0c4def0456e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3192Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3192Test.php @@ -23,12 +23,12 @@ protected function setUp() ); } - Type::addType('ddc3192_currency_code', __NAMESPACE__ . '\DDC3192CurrencyCode'); + Type::addType('ddc3192_currency_code', DDC3192CurrencyCode::class); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(DDC3192Currency::CLASSNAME), - $this->_em->getClassMetadata(DDC3192Transaction::CLASSNAME), + $this->_em->getClassMetadata(DDC3192Currency::class), + $this->_em->getClassMetadata(DDC3192Transaction::class), ] ); } @@ -47,7 +47,7 @@ public function testIssue() $this->_em->flush(); $this->_em->close(); - $resultByPersister = $this->_em->find(DDC3192Transaction::CLASSNAME, $transaction->id); + $resultByPersister = $this->_em->find(DDC3192Transaction::class, $transaction->id); // This works: DDC2494 makes persister set type mapping info to ResultSetMapping $this->assertEquals('BYR', $resultByPersister->currency->code); @@ -55,7 +55,7 @@ public function testIssue() $this->_em->close(); $query = $this->_em->createQuery(); - $query->setDQL('SELECT t FROM ' . DDC3192Transaction::CLASSNAME . ' t WHERE t.id = ?1'); + $query->setDQL('SELECT t FROM ' . DDC3192Transaction::class . ' t WHERE t.id = ?1'); $query->setParameter(1, $transaction->id); $resultByQuery = $query->getSingleResult(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3223Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3223Test.php index be2c5861719..0f98adca1fa 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3223Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3223Test.php @@ -17,10 +17,10 @@ protected function setUp() $this->setUpEntitySchema( [ - 'Doctrine\Tests\ORM\Functional\Ticket\Journalist', - 'Doctrine\Tests\ORM\Functional\Ticket\Participant', - 'Doctrine\Tests\ORM\Functional\Ticket\Status', - 'Doctrine\Tests\ORM\Functional\Ticket\ProfileStatus', + Journalist::class, + Participant::class, + Status::class, + ProfileStatus::class, ] ); } @@ -37,7 +37,7 @@ public function testIssueGetId() $this->_em->flush(); $this->_em->clear(); - $participant = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\Participant', $participant->id); + $participant = $this->_em->find(Participant::class, $participant->id); $profileStatus = clone $participant->profileStatus; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3300Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3300Test.php index 8014ae6f873..0f31ecedfe0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3300Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3300Test.php @@ -14,14 +14,14 @@ public function testResolveTargetEntitiesChangesDiscriminatorMapValues() $resolveTargetEntity = new ResolveTargetEntityListener(); $resolveTargetEntity->addResolveTargetEntity( - DDC3300BossInterface::INTERFACENAME, - DDC3300Boss::CLASSNAME, + DDC3300BossInterface::class, + DDC3300Boss::class, [] ); $resolveTargetEntity->addResolveTargetEntity( - DDC3300EmployeeInterface::INTERFACENAME, - DDC3300Employee::CLASSNAME, + DDC3300EmployeeInterface::class, + DDC3300Employee::class, [] ); @@ -29,7 +29,7 @@ public function testResolveTargetEntitiesChangesDiscriminatorMapValues() $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(DDC3300Person::CLASSNAME), + $this->_em->getClassMetadata(DDC3300Person::class), ] ); @@ -42,8 +42,8 @@ public function testResolveTargetEntitiesChangesDiscriminatorMapValues() $this->_em->flush(); $this->_em->clear(); - $this->assertEquals($boss, $this->_em->find(DDC3300BossInterface::INTERFACENAME, $boss->id)); - $this->assertEquals($employee, $this->_em->find(DDC3300EmployeeInterface::INTERFACENAME, $employee->id)); + $this->assertEquals($boss, $this->_em->find(DDC3300BossInterface::class, $boss->id)); + $this->assertEquals($employee, $this->_em->find(DDC3300EmployeeInterface::class, $employee->id)); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3330Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3330Test.php index 9edf5817007..c6a2f4ab1c2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3330Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3330Test.php @@ -18,8 +18,8 @@ protected function setUp() $this->setUpEntitySchema( [ - 'Doctrine\Tests\ORM\Functional\Ticket\DDC3330_Building', - 'Doctrine\Tests\ORM\Functional\Ticket\DDC3330_Hall', + DDC3330_Building::class, + DDC3330_Hall::class, ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3346Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3346Test.php index 85b2086c7c3..3865767604e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3346Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3346Test.php @@ -22,7 +22,7 @@ public function setUp() public function testFindOneWithEagerFetchWillNotHydrateLimitedCollection() { /* @var DDC3346Author $author */ - $author = $this->_em->getRepository(DDC3346Author::CLASSNAME)->findOneBy( + $author = $this->_em->getRepository(DDC3346Author::class)->findOneBy( ['username' => 'bwoogy'] ); @@ -32,7 +32,7 @@ public function testFindOneWithEagerFetchWillNotHydrateLimitedCollection() public function testFindLimitedWithEagerFetchWillNotHydrateLimitedCollection() { /* @var DDC3346Author[] $authors */ - $authors = $this->_em->getRepository(DDC3346Author::CLASSNAME)->findBy( + $authors = $this->_em->getRepository(DDC3346Author::class)->findBy( ['username' => 'bwoogy'], null, 1 @@ -45,7 +45,7 @@ public function testFindLimitedWithEagerFetchWillNotHydrateLimitedCollection() public function testFindWithEagerFetchAndOffsetWillNotHydrateLimitedCollection() { /* @var DDC3346Author[] $authors */ - $authors = $this->_em->getRepository(DDC3346Author::CLASSNAME)->findBy( + $authors = $this->_em->getRepository(DDC3346Author::class)->findBy( ['username' => 'bwoogy'], null, null, diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php index ea4c37722b0..20b4236c304 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php @@ -10,9 +10,9 @@ protected function setUp() //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC345User'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC345Group'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC345Membership'), + $this->_em->getClassMetadata(DDC345User::class), + $this->_em->getClassMetadata(DDC345Group::class), + $this->_em->getClassMetadata(DDC345Membership::class), ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC353Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC353Test.php index 5d9e8a01429..dcb782bd4f8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC353Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC353Test.php @@ -12,8 +12,8 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC353File'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC353Picture'), + $this->_em->getClassMetadata(DDC353File::class), + $this->_em->getClassMetadata(DDC353Picture::class), ] ); } catch(\Exception $ignored) {} @@ -34,10 +34,10 @@ public function testWorkingCase() $fileId = $file->getFileId(); $this->assertTrue($fileId > 0); - $file = $em->getReference('Doctrine\Tests\ORM\Functional\Ticket\DDC353File', $fileId); + $file = $em->getReference(DDC353File::class, $fileId); $this->assertEquals(UnitOfWork::STATE_MANAGED, $em->getUnitOfWork()->getEntityState($file), "Reference Proxy should be marked MANAGED."); - $picture = $em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC353Picture', $picture->getPictureId()); + $picture = $em->find(DDC353Picture::class, $picture->getPictureId()); $this->assertEquals(UnitOfWork::STATE_MANAGED, $em->getUnitOfWork()->getEntityState($picture->getFile()), "Lazy Proxy should be marked MANAGED."); $em->remove($picture); @@ -61,7 +61,7 @@ public function testFailingCase() $this->assertTrue($fileId > 0); - $picture = $em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC353Picture', $pictureId); + $picture = $em->find(DDC353Picture::class, $pictureId); $this->assertEquals(UnitOfWork::STATE_MANAGED, $em->getUnitOfWork()->getEntityState($picture->getFile()), "Lazy Proxy should be marked MANAGED."); $em->remove($picture); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3582Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3582Test.php index 4c07046f6fa..2f10adcee32 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3582Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3582Test.php @@ -6,17 +6,17 @@ class DDC3582Test extends \Doctrine\Tests\OrmFunctionalTestCase { function testNestedEmbeddablesAreHydratedWithProperClass() { - $this->_schemaTool->createSchema([$this->_em->getClassMetadata(DDC3582Entity::CLASSNAME)]); + $this->_schemaTool->createSchema([$this->_em->getClassMetadata(DDC3582Entity::class)]); $this->_em->persist(new DDC3582Entity('foo')); $this->_em->flush(); $this->_em->clear(); /** @var DDC3582Entity $entity */ - $entity = $this->_em->find(DDC3582Entity::CLASSNAME, 'foo'); + $entity = $this->_em->find(DDC3582Entity::class, 'foo'); - $this->assertInstanceOf(DDC3582Embeddable1::CLASSNAME, $entity->embeddable1); - $this->assertInstanceOf(DDC3582Embeddable2::CLASSNAME, $entity->embeddable1->embeddable2); - $this->assertInstanceOf(DDC3582Embeddable3::CLASSNAME, $entity->embeddable1->embeddable2->embeddable3); + $this->assertInstanceOf(DDC3582Embeddable1::class, $entity->embeddable1); + $this->assertInstanceOf(DDC3582Embeddable2::class, $entity->embeddable1->embeddable2); + $this->assertInstanceOf(DDC3582Embeddable3::class, $entity->embeddable1->embeddable2->embeddable3); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3597Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3597Test.php index b4bb7891ccf..6d59fd6f70c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3597Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3597Test.php @@ -15,9 +15,9 @@ protected function setUp() { parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(DDC3597Root::CLASSNAME), - $this->_em->getClassMetadata(DDC3597Media::CLASSNAME), - $this->_em->getClassMetadata(DDC3597Image::CLASSNAME) + $this->_em->getClassMetadata(DDC3597Root::class), + $this->_em->getClassMetadata(DDC3597Media::class), + $this->_em->getClassMetadata(DDC3597Image::class) ] ); } @@ -38,8 +38,8 @@ public function testSaveImageEntity() { $this->_em->clear(); //request entity - $imageEntity = $this->_em->find(DDC3597Image::CLASSNAME, $imageEntity->getId()); - $this->assertInstanceOf(DDC3597Image::CLASSNAME, $imageEntity); + $imageEntity = $this->_em->find(DDC3597Image::class, $imageEntity->getId()); + $this->assertInstanceOf(DDC3597Image::class, $imageEntity); //cleanup $this->_em->remove($imageEntity); @@ -47,7 +47,7 @@ public function testSaveImageEntity() { $this->_em->clear(); //check delete - $imageEntity = $this->_em->find(DDC3597Image::CLASSNAME, $imageEntity->getId()); + $imageEntity = $this->_em->find(DDC3597Image::class, $imageEntity->getId()); $this->assertNull($imageEntity); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php index 679ab559c97..2f499f2d292 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php @@ -16,7 +16,7 @@ class DDC3634Test extends OrmFunctionalTestCase { protected function setUp() { parent::setUp(); - $metadata = $this->_em->getClassMetadata(DDC3634Entity::CLASSNAME); + $metadata = $this->_em->getClassMetadata(DDC3634Entity::class); if ( ! $metadata->idGenerator->isPostInsertGenerator()) { $this->markTestSkipped('Need a post-insert ID generator in order to make this test work correctly'); @@ -25,8 +25,8 @@ protected function setUp() { try { $this->_schemaTool->createSchema([ $metadata, - $this->_em->getClassMetadata(DDC3634JTIBaseEntity::CLASSNAME), - $this->_em->getClassMetadata(DDC3634JTIChildEntity::CLASSNAME), + $this->_em->getClassMetadata(DDC3634JTIBaseEntity::class), + $this->_em->getClassMetadata(DDC3634JTIChildEntity::class), ]); } catch (ToolsException $e) { // schema already in place @@ -425,4 +425,4 @@ public function ping() { return $this->forwardCall(); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3644Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3644Test.php index f4e338eace8..968c44d721b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3644Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3644Test.php @@ -18,10 +18,10 @@ protected function setUp() $this->setUpEntitySchema( [ - 'Doctrine\Tests\ORM\Functional\Ticket\DDC3644User', - 'Doctrine\Tests\ORM\Functional\Ticket\DDC3644Address', - 'Doctrine\Tests\ORM\Functional\Ticket\DDC3644Animal', - 'Doctrine\Tests\ORM\Functional\Ticket\DDC3644Pet', + DDC3644User::class, + DDC3644Address::class, + DDC3644Animal::class, + DDC3644Pet::class, ] ); } @@ -56,7 +56,7 @@ public function testIssueWithRegularEntity() // Replace entire collection (this should trigger OneToManyPersister::remove()) $current = new DDC3644Address('Toronto, ON, Canada'); $addresses = new ArrayCollection([$current]); - $user = $this->_em->find(__NAMESPACE__ . '\DDC3644User', $userId); + $user = $this->_em->find(DDC3644User::class, $userId); $user->setAddresses($addresses); @@ -67,12 +67,12 @@ public function testIssueWithRegularEntity() $this->_em->clear(); // We should only have 1 item in the collection list now - $user = $this->_em->find(__NAMESPACE__ . '\DDC3644User', $userId); + $user = $this->_em->find(DDC3644User::class, $userId); $this->assertCount(1, $user->addresses); // We should only have 1 item in the addresses table too - $repository = $this->_em->getRepository(__NAMESPACE__ . '\DDC3644Address'); + $repository = $this->_em->getRepository(DDC3644Address::class); $addresses = $repository->findAll(); $this->assertCount(1, $addresses); @@ -106,7 +106,7 @@ public function testIssueWithJoinedEntity() // Replace entire collection (this should trigger OneToManyPersister::remove()) $actual = new DDC3644Pet('Valentina'); $pets = new ArrayCollection([$actual]); - $user = $this->_em->find(__NAMESPACE__ . '\DDC3644User', $userId); + $user = $this->_em->find(DDC3644User::class, $userId); $user->setPets($pets); @@ -117,12 +117,12 @@ public function testIssueWithJoinedEntity() $this->_em->clear(); // We should only have 1 item in the collection list now - $user = $this->_em->find(__NAMESPACE__ . '\DDC3644User', $userId); + $user = $this->_em->find(DDC3644User::class, $userId); $this->assertCount(1, $user->pets); // We should only have 1 item in the pets table too - $repository = $this->_em->getRepository(__NAMESPACE__ . '\DDC3644Pet'); + $repository = $this->_em->getRepository(DDC3644Pet::class); $pets = $repository->findAll(); $this->assertCount(1, $pets); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3699Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3699Test.php index b33f9a4487e..fd284e5b11d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3699Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3699Test.php @@ -42,12 +42,12 @@ public function testMergingParentClassFieldsDoesNotStopMergingScalarFieldsForToO // fixtures loaded /* @var $unManagedChild DDC3699Child */ - $unManagedChild = $this->_em->find(DDC3699Child::CLASSNAME, $id); + $unManagedChild = $this->_em->find(DDC3699Child::class, $id); $this->_em->detach($unManagedChild); // make it managed again - $this->_em->find(DDC3699Child::CLASSNAME, $id); + $this->_em->find(DDC3699Child::class, $id); $unManagedChild->childField = 'modifiedChildValue'; $unManagedChild->parentField = 'modifiedParentValue'; @@ -84,11 +84,11 @@ public function testMergingParentClassFieldsDoesNotStopMergingScalarFieldsForToM $this->_em->clear(); /* @var $unmanagedChild DDC3699Child */ - $unmanagedChild = $this->_em->find(DDC3699Child::CLASSNAME, $id); + $unmanagedChild = $this->_em->find(DDC3699Child::class, $id); $this->_em->detach($unmanagedChild); // make it managed again - $this->_em->find(DDC3699Child::CLASSNAME, $id); + $this->_em->find(DDC3699Child::class, $id); $unmanagedChild->childField = 'modifiedChildValue'; $unmanagedChild->parentField = 'modifiedParentValue'; @@ -99,4 +99,4 @@ public function testMergingParentClassFieldsDoesNotStopMergingScalarFieldsForToM $this->assertSame($mergedChild->childField, 'modifiedChildValue'); $this->assertSame($mergedChild->parentField, 'modifiedParentValue'); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3711Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3711Test.php index 6a08b49bcd0..3fc4c856bd9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3711Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3711Test.php @@ -4,6 +4,7 @@ use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\Tests\Models\DDC3711\DDC3711EntityA; use Doctrine\Tests\ORM\Mapping\YamlMappingDriverTest; /** @@ -20,8 +21,8 @@ public function testCompositeKeyForJoinTableInManyToManyCreation() $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory(); $factory->setEntityManager($em); - $entityA = new ClassMetadata('Doctrine\Tests\Models\DDC3711\DDC3711EntityA'); - $entityA = $factory->getMetadataFor('Doctrine\Tests\Models\DDC3711\DDC3711EntityA'); + $entityA = new ClassMetadata(DDC3711EntityA::class); + $entityA = $factory->getMetadataFor(DDC3711EntityA::class); $this->assertEquals(['link_a_id1' => "id1", 'link_a_id2' => "id2"], $entityA->associationMappings['entityB']['relationToSourceKeyColumns']); $this->assertEquals(['link_b_id1' => "id1", 'link_b_id2' => "id2"], $entityA->associationMappings['entityB']['relationToTargetKeyColumns']); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php index f7013d6d802..3fe5c4b80d3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php @@ -1,6 +1,7 @@ _em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC371Parent'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC371Child') + $this->_em->getClassMetadata(DDC371Parent::class), + $this->_em->getClassMetadata(DDC371Child::class) ] ); } @@ -44,7 +45,7 @@ public function testIssue() ->getResult(); $this->assertEquals(1, count($children)); - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $children[0]->parent); + $this->assertNotInstanceOf(Proxy::class, $children[0]->parent); $this->assertFalse($children[0]->parent->children->isInitialized()); $this->assertEquals(0, $children[0]->parent->children->unwrap()->count()); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3785Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3785Test.php index f5b8cac01ab..05498db774a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3785Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3785Test.php @@ -12,14 +12,14 @@ protected function setUp() { parent::setUp(); - Type::addType('ddc3785_asset_id', __NAMESPACE__ . '\\DDC3785_AssetIdType'); + Type::addType('ddc3785_asset_id', DDC3785_AssetIdType::class); try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC3785_Asset'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC3785_AssetId'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC3785_Attribute') + $this->_em->getClassMetadata(DDC3785_Asset::class), + $this->_em->getClassMetadata(DDC3785_AssetId::class), + $this->_em->getClassMetadata(DDC3785_Attribute::class) ] ); } catch(\Exception $e) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC381Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC381Test.php index 2bf52eb340e..bbfd6974e21 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC381Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC381Test.php @@ -11,7 +11,7 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC381Entity'), + $this->_em->getClassMetadata(DDC381Entity::class), ] ); } catch(\Exception $e) { @@ -28,7 +28,7 @@ public function testCallUnserializedProxyMethods() $this->_em->clear(); $persistedId = $entity->getId(); - $entity = $this->_em->getReference('Doctrine\Tests\ORM\Functional\Ticket\DDC381Entity', $persistedId); + $entity = $this->_em->getReference(DDC381Entity::class, $persistedId); // explicitly load proxy (getId() does not trigger reload of proxy) $id = $entity->getOtherMethod(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3967Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3967Test.php index d5c3dd554ff..72a9cfe168a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3967Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3967Test.php @@ -12,7 +12,7 @@ protected function setUp() parent::setUp(); $this->loadFixturesCountries(); - $this->_em->getCache()->evictEntityRegion(Country::CLASSNAME); + $this->_em->getCache()->evictEntityRegion(Country::class); $this->_em->clear(); } @@ -22,12 +22,12 @@ public function testIdentifierCachedWithProperType() $id = $country->getId(); // First time, loaded from database - $this->_em->find(Country::CLASSNAME, "$id"); + $this->_em->find(Country::class, "$id"); $this->_em->clear(); // Second time, loaded from cache /** @var Country $country */ - $country = $this->_em->find(Country::CLASSNAME, "$id"); + $country = $this->_em->find(Country::class, "$id"); // Identifier type should be integer $this->assertSame($country->getId(), $id); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC4003Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC4003Test.php index 1c286781a24..6764bc9bf75 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC4003Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC4003Test.php @@ -17,7 +17,7 @@ public function test_reads_through_repository_same_data_that_it_wrote_in_cache() // Get the id of the first bar $id = $this->attractions[0]->getId(); - $repository = $this->_em->getRepository(Bar::CLASSNAME); + $repository = $this->_em->getRepository(Bar::class); /** * This instance is fresh new, no QueryCache, so the full entity gets loaded from DB. diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC422Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC422Test.php index 0325e117538..6ace5e74943 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC422Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC422Test.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\ORM\PersistentCollection; + class DDC422Test extends \Doctrine\Tests\OrmFunctionalTestCase { protected function setUp() @@ -10,9 +12,9 @@ protected function setUp() //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC422Guest'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC422Customer'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC422Contact') + $this->_em->getClassMetadata(DDC422Guest::class), + $this->_em->getClassMetadata(DDC422Customer::class), + $this->_em->getClassMetadata(DDC422Contact::class) ] ); } @@ -29,7 +31,7 @@ public function testIssue() $customer = $this->_em->find(get_class($customer), $customer->id); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $customer->contacts); + $this->assertInstanceOf(PersistentCollection::class, $customer->contacts); $this->assertFalse($customer->contacts->isInitialized()); $contact = new DDC422Contact; $customer->contacts->add($contact); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC425Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC425Test.php index e6389ebf976..9c06160c7a4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC425Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC425Test.php @@ -10,7 +10,7 @@ protected function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC425Entity'), + $this->_em->getClassMetadata(DDC425Entity::class), //$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC425Other') ] ); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC440Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC440Test.php index 7fa7b58bded..30d2ca6b9cd 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC440Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC440Test.php @@ -11,8 +11,8 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\DDC440Phone'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\DDC440Client') + $this->_em->getClassMetadata(DDC440Phone::class), + $this->_em->getClassMetadata(DDC440Client::class) ] ); } catch (\Exception $e) { @@ -58,7 +58,7 @@ public function testOriginalEntityDataEmptyWhenProxyLoadedFromTwoAssociations() $this->_em->clear(); $uw = $this->_em->getUnitOfWork(); - $client = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC440Client', $id); + $client = $this->_em->find(DDC440Client::class, $id); $clientPhones = $client->getPhones(); $p1 = $clientPhones[1]; @@ -67,13 +67,13 @@ public function testOriginalEntityDataEmptyWhenProxyLoadedFromTwoAssociations() // Test the first phone. The assertion actually failed because original entity data is not set properly. // This was because it is also set as MainPhone and that one is created as a proxy, not the // original object when the find on Client is called. However loading proxies did not work correctly. - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC440Phone', $p1); + $this->assertInstanceOf(DDC440Phone::class, $p1); $originalData = $uw->getOriginalEntityData($p1); $this->assertEquals($phone->getNumber(), $originalData['number']); //If you comment out previous test, this one should pass - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC440Phone', $p2); + $this->assertInstanceOf(DDC440Phone::class, $p2); $originalData = $uw->getOriginalEntityData($p2); $this->assertEquals($phone2->getNumber(), $originalData['number']); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC444Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC444Test.php index 2615e37c6dd..41d7e1270ec 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC444Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC444Test.php @@ -10,14 +10,14 @@ public function setUp() //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC444User'), + $this->_em->getClassMetadata(DDC444User::class), ] ); } public function testExplicitPolicy() { - $classname = __NAMESPACE__ . "\DDC444User"; + $classname = DDC444User::class; $u = new $classname; $u->name = "Initial value"; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC448Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC448Test.php index 41d1fdee67c..31e03e33732 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC448Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC448Test.php @@ -11,9 +11,9 @@ protected function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC448MainTable'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC448ConnectedClass'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC448SubTable'), + $this->_em->getClassMetadata(DDC448MainTable::class), + $this->_em->getClassMetadata(DDC448ConnectedClass::class), + $this->_em->getClassMetadata(DDC448SubTable::class), ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC493Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC493Test.php index 5aebed10753..536a8b49b52 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC493Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC493Test.php @@ -9,9 +9,9 @@ protected function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC493Customer'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC493Distributor'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC493Contact') + $this->_em->getClassMetadata(DDC493Customer::class), + $this->_em->getClassMetadata(DDC493Distributor::class), + $this->_em->getClassMetadata(DDC493Contact::class) ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC501Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC501Test.php index 3763b15d77a..5b2996aab2f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC501Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC501Test.php @@ -46,7 +46,7 @@ public function testMergeUnitializedManyToManyAndOneToManyCollections() // freeze and unfreeze $userClone = unserialize(serialize($userReloaded)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $userClone); + $this->assertInstanceOf(CmsUser::class, $userClone); // detached user can't know about his phonenumbers $this->assertEquals(0, count($userClone->getPhonenumbers())); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC512Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC512Test.php index 4cc5aee8c70..6f3c3cfb01b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC512Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC512Test.php @@ -11,9 +11,9 @@ protected function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC512Customer'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC512OfferItem'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC512Item'), + $this->_em->getClassMetadata(DDC512Customer::class), + $this->_em->getClassMetadata(DDC512OfferItem::class), + $this->_em->getClassMetadata(DDC512Item::class), ] ); } @@ -35,14 +35,14 @@ public function testIssue() $result = $q->getResult(); $this->assertEquals(2, count($result)); - $this->assertInstanceOf(__NAMESPACE__ . '\DDC512Customer', $result[0]); - $this->assertInstanceOf(__NAMESPACE__ . '\DDC512Customer', $result[1]); + $this->assertInstanceOf(DDC512Customer::class, $result[0]); + $this->assertInstanceOf(DDC512Customer::class, $result[1]); if ($result[0]->id == $customer1->id) { - $this->assertInstanceOf(__NAMESPACE__ . '\DDC512OfferItem', $result[0]->item); + $this->assertInstanceOf(DDC512OfferItem::class, $result[0]->item); $this->assertEquals($item->id, $result[0]->item->id); $this->assertNull($result[1]->item); } else { - $this->assertInstanceOf(__NAMESPACE__ . '\DDC512OfferItem', $result[1]->item); + $this->assertInstanceOf(DDC512OfferItem::class, $result[1]->item); $this->assertNull($result[0]->item); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC513Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC513Test.php index 11a7d2f6f17..800c442a398 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC513Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC513Test.php @@ -9,9 +9,9 @@ protected function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC513OfferItem'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC513Item'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC513Price'), + $this->_em->getClassMetadata(DDC513OfferItem::class), + $this->_em->getClassMetadata(DDC513Item::class), + $this->_em->getClassMetadata(DDC513Price::class), ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php index d8592b482d4..91860e8b0d1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\ORM\Proxy\Proxy; + /** * Tests that join columns (foreign keys) can be named the same as the association * fields they're used on without causing issues. @@ -14,9 +16,9 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC522Customer'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC522Cart'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC522ForeignKeyTest') + $this->_em->getClassMetadata(DDC522Customer::class), + $this->_em->getClassMetadata(DDC522Cart::class), + $this->_em->getClassMetadata(DDC522ForeignKeyTest::class) ] ); } catch(\Exception $e) { @@ -46,9 +48,9 @@ public function testJoinColumnWithSameNameAsAssociationField() $r = $this->_em->createQuery("select ca,c from ".get_class($cart)." ca join ca.customer c") ->getResult(); - $this->assertInstanceOf(__NAMESPACE__ . '\DDC522Cart', $r[0]); - $this->assertInstanceOf(__NAMESPACE__ . '\DDC522Customer', $r[0]->customer); - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $r[0]->customer); + $this->assertInstanceOf(DDC522Cart::class, $r[0]); + $this->assertInstanceOf(DDC522Customer::class, $r[0]->customer); + $this->assertNotInstanceOf(Proxy::class, $r[0]->customer); $this->assertEquals('name', $r[0]->customer->name); $fkt = new DDC522ForeignKeyTest(); @@ -60,7 +62,7 @@ public function testJoinColumnWithSameNameAsAssociationField() $fkt2 = $this->_em->find(get_class($fkt), $fkt->id); $this->assertEquals($fkt->cart->id, $fkt2->cartId); - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $fkt2->cart); + $this->assertInstanceOf(Proxy::class, $fkt2->cart); $this->assertFalse($fkt2->cart->__isInitialized__); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC531Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC531Test.php index f205ae69757..33d88c6be1f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC531Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC531Test.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\ORM\Proxy\Proxy; + class DDC531Test extends \Doctrine\Tests\OrmFunctionalTestCase { protected function setUp() @@ -9,8 +11,8 @@ protected function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC531Item'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC531SubItem'), + $this->_em->getClassMetadata(DDC531Item::class), + $this->_em->getClassMetadata(DDC531SubItem::class), ] ); } @@ -26,12 +28,12 @@ public function testIssue() $this->_em->flush(); $this->_em->clear(); - $item3 = $this->_em->find(__NAMESPACE__ . '\DDC531Item', $item2->id); // Load child item first (id 2) + $item3 = $this->_em->find(DDC531Item::class, $item2->id); // Load child item first (id 2) // parent will already be loaded, cannot be lazy because it has mapped subclasses and we would not // know which proxy type to put in. - $this->assertInstanceOf(__NAMESPACE__ . '\DDC531Item', $item3->parent); - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $item3->parent); - $item4 = $this->_em->find(__NAMESPACE__ . '\DDC531Item', $item1->id); // Load parent item (id 1) + $this->assertInstanceOf(DDC531Item::class, $item3->parent); + $this->assertNotInstanceOf(Proxy::class, $item3->parent); + $item4 = $this->_em->find(DDC531Item::class, $item1->id); // Load parent item (id 1) $this->assertNull($item4->parent); $this->assertNotNull($item4->getChildren()); $this->assertTrue($item4->getChildren()->contains($item3)); // lazy-loads children diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC5684Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC5684Test.php index a25178de210..2e9fb8a8c70 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC5684Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC5684Test.php @@ -18,18 +18,18 @@ protected function setUp() { parent::setUp(); - if (DBALTypes\Type::hasType(DDC5684ObjectIdType::CLASSNAME)) { - DBALTypes\Type::overrideType(DDC5684ObjectIdType::CLASSNAME, DDC5684ObjectIdType::CLASSNAME); + if (DBALTypes\Type::hasType(DDC5684ObjectIdType::class)) { + DBALTypes\Type::overrideType(DDC5684ObjectIdType::class, DDC5684ObjectIdType::class); } else { - DBALTypes\Type::addType(DDC5684ObjectIdType::CLASSNAME, DDC5684ObjectIdType::CLASSNAME); + DBALTypes\Type::addType(DDC5684ObjectIdType::class, DDC5684ObjectIdType::class); } - $this->_schemaTool->createSchema([$this->_em->getClassMetadata(DDC5684Object::CLASSNAME)]); + $this->_schemaTool->createSchema([$this->_em->getClassMetadata(DDC5684Object::class)]); } protected function tearDown() { - $this->_schemaTool->dropSchema([$this->_em->getClassMetadata(DDC5684Object::CLASSNAME)]); + $this->_schemaTool->dropSchema([$this->_em->getClassMetadata(DDC5684Object::class)]); parent::tearDown(); } @@ -40,7 +40,7 @@ public function testAutoIncrementIdWithCustomType() $this->_em->persist($object); $this->_em->flush(); - $this->assertInstanceOf(DDC5684ObjectId::CLASSNAME, $object->id); + $this->assertInstanceOf(DDC5684ObjectId::class, $object->id); } public function testFetchObjectWithAutoIncrementedCustomType() @@ -51,9 +51,9 @@ public function testFetchObjectWithAutoIncrementedCustomType() $this->_em->clear(); $rawId = $object->id->value; - $object = $this->_em->find(DDC5684Object::CLASSNAME, new DDC5684ObjectId($rawId)); + $object = $this->_em->find(DDC5684Object::class, new DDC5684ObjectId($rawId)); - $this->assertInstanceOf(DDC5684ObjectId::CLASSNAME, $object->id); + $this->assertInstanceOf(DDC5684ObjectId::class, $object->id); $this->assertEquals($rawId, $object->id->value); } } @@ -74,7 +74,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) public function getName() { - return self::CLASSNAME; + return self::class; } public function requiresSQLCommentHint(AbstractPlatform $platform) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC588Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC588Test.php index 05543835924..021e582e667 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC588Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC588Test.php @@ -9,7 +9,7 @@ protected function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC588Site'), + $this->_em->getClassMetadata(DDC588Site::class), ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC599Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC599Test.php index fb596da525d..842ccdd1a73 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC599Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC599Test.php @@ -11,9 +11,9 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC599Item'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC599Subitem'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC599Child'), + $this->_em->getClassMetadata(DDC599Item::class), + $this->_em->getClassMetadata(DDC599Subitem::class), + $this->_em->getClassMetadata(DDC599Child::class), ] ); } catch (\Exception $ignored) {} @@ -31,7 +31,7 @@ public function testCascadeRemoveOnInheritanceHierarchy() $this->_em->flush(); $this->_em->clear(); - $item = $this->_em->find(__NAMESPACE__ . '\DDC599Item', $item->id); + $item = $this->_em->find(DDC599Item::class, $item->id); $this->_em->remove($item); $this->_em->flush(); // Should not fail @@ -64,7 +64,7 @@ public function testCascadeRemoveOnInheritanceHierarchy() public function testCascadeRemoveOnChildren() { - $class = $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC599Subitem'); + $class = $this->_em->getClassMetadata(DDC599Subitem::class); $this->assertArrayHasKey('children', $class->associationMappings); $this->assertTrue($class->associationMappings['children']['isCascadeRemove']); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC618Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC618Test.php index 5d5a6ac1ecc..5e359863e91 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC618Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC618Test.php @@ -13,8 +13,8 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC618Author'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC618Book') + $this->_em->getClassMetadata(DDC618Author::class), + $this->_em->getClassMetadata(DDC618Book::class) ] ); @@ -46,8 +46,8 @@ public function testIndexByHydrateObject() $dql = 'SELECT A FROM Doctrine\Tests\ORM\Functional\Ticket\DDC618Author A INDEX BY A.name ORDER BY A.name ASC'; $result = $this->_em->createQuery($dql)->getResult(\Doctrine\ORM\Query::HYDRATE_OBJECT); - $joe = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC618Author', 10); - $alice = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC618Author', 11); + $joe = $this->_em->find(DDC618Author::class, 10); + $alice = $this->_em->find(DDC618Author::class, 11); $this->assertArrayHasKey('Joe', $result, "INDEX BY A.name should return an index by the name of 'Joe'."); $this->assertArrayHasKey('Alice', $result, "INDEX BY A.name should return an index by the name of 'Alice'."); @@ -58,8 +58,8 @@ public function testIndexByHydrateArray() $dql = 'SELECT A FROM Doctrine\Tests\ORM\Functional\Ticket\DDC618Author A INDEX BY A.name ORDER BY A.name ASC'; $result = $this->_em->createQuery($dql)->getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY); - $joe = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC618Author', 10); - $alice = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC618Author', 11); + $joe = $this->_em->find(DDC618Author::class, 10); + $alice = $this->_em->find(DDC618Author::class, 11); $this->assertArrayHasKey('Joe', $result, "INDEX BY A.name should return an index by the name of 'Joe'."); $this->assertArrayHasKey('Alice', $result, "INDEX BY A.name should return an index by the name of 'Alice'."); @@ -98,8 +98,8 @@ public function testIndexByToOneJoinSilentlyIgnored() 'INNER JOIN B.author A INDEX BY A.name ORDER BY A.name ASC'; $result = $this->_em->createQuery($dql)->getResult(\Doctrine\ORM\Query::HYDRATE_OBJECT); - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC618Book', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC618Author', $result[0]->author); + $this->assertInstanceOf(DDC618Book::class, $result[0]); + $this->assertInstanceOf(DDC618Author::class, $result[0]->author); $dql = 'SELECT B, A FROM Doctrine\Tests\ORM\Functional\Ticket\DDC618Book B '. 'INNER JOIN B.author A INDEX BY A.name ORDER BY A.name ASC'; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php index b88b1b15441..2ed53ed354f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\ORM\Proxy\Proxy; + class DDC633Test extends \Doctrine\Tests\OrmFunctionalTestCase { protected function setUp() @@ -10,8 +12,8 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC633Patient'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC633Appointment'), + $this->_em->getClassMetadata(DDC633Patient::class), + $this->_em->getClassMetadata(DDC633Appointment::class), ] ); } catch(\Exception $e) { @@ -36,10 +38,10 @@ public function testOneToOneEager() $this->_em->flush(); $this->_em->clear(); - $eagerAppointment = $this->_em->find(__NAMESPACE__ . '\DDC633Appointment', $app->id); + $eagerAppointment = $this->_em->find(DDC633Appointment::class, $app->id); // Eager loading of one to one leads to fetch-join - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $eagerAppointment->patient); + $this->assertNotInstanceOf(Proxy::class, $eagerAppointment->patient); $this->assertTrue($this->_em->contains($eagerAppointment->patient)); } @@ -64,7 +66,7 @@ public function testDQLDeferredEagerLoad() $appointments = $this->_em->createQuery("SELECT a FROM " . __NAMESPACE__ . "\DDC633Appointment a")->getResult(); foreach ($appointments AS $eagerAppointment) { - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $eagerAppointment->patient); + $this->assertInstanceOf(Proxy::class, $eagerAppointment->patient); $this->assertTrue($eagerAppointment->patient->__isInitialized__, "Proxy should already be initialized due to eager loading!"); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC656Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC656Test.php index 2ebffe3400d..1f94a3953a9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC656Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC656Test.php @@ -10,7 +10,7 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC656Entity') + $this->_em->getClassMetadata(DDC656Entity::class) ] ); } catch(\Exception $e) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC657Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC657Test.php index f2fe56f7bf4..759464a5f0e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC657Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC657Test.php @@ -9,8 +9,6 @@ */ class DDC657Test extends \Doctrine\Tests\OrmFunctionalTestCase { - const NS = 'Doctrine\Tests\Models\Generic'; - protected function setUp() { $this->useModelSet('generic'); @@ -21,10 +19,10 @@ protected function setUp() public function testEntitySingleResult() { - $query = $this->_em->createQuery('SELECT d FROM ' . self::NS . '\DateTimeModel d'); + $query = $this->_em->createQuery('SELECT d FROM ' . DateTimeModel::class . ' d'); $datetime = $query->setMaxResults(1)->getSingleResult(); - $this->assertInstanceOf('Doctrine\Tests\Models\Generic\DateTimeModel', $datetime); + $this->assertInstanceOf(DateTimeModel::class, $datetime); $this->assertInstanceOf('DateTime', $datetime->datetime); $this->assertInstanceOf('DateTime', $datetime->time); @@ -33,7 +31,7 @@ public function testEntitySingleResult() public function testScalarResult() { - $query = $this->_em->createQuery('SELECT d.id, d.time, d.date, d.datetime FROM ' . self::NS . '\DateTimeModel d ORDER BY d.date ASC'); + $query = $this->_em->createQuery('SELECT d.id, d.time, d.date, d.datetime FROM ' . DateTimeModel::class . ' d ORDER BY d.date ASC'); $result = $query->getScalarResult(); $this->assertCount(2,$result); @@ -49,7 +47,7 @@ public function testScalarResult() public function testaTicketEntityArrayResult() { - $query = $this->_em->createQuery('SELECT d FROM ' . self::NS . '\DateTimeModel d ORDER BY d.date ASC'); + $query = $this->_em->createQuery('SELECT d FROM ' . DateTimeModel::class . ' d ORDER BY d.date ASC'); $result = $query->getArrayResult(); $this->assertCount(2,$result); @@ -65,7 +63,7 @@ public function testaTicketEntityArrayResult() public function testTicketSingleResult() { - $query = $this->_em->createQuery('SELECT d.id, d.time, d.date, d.datetime FROM ' . self::NS . '\DateTimeModel d ORDER BY d.date ASC'); + $query = $this->_em->createQuery('SELECT d.id, d.time, d.date, d.datetime FROM ' . DateTimeModel::class . ' d ORDER BY d.date ASC'); $datetime = $query->setMaxResults(1)->getSingleResult(); $this->assertTrue(is_array($datetime)); @@ -77,7 +75,7 @@ public function testTicketSingleResult() public function testTicketResult() { - $query = $this->_em->createQuery('SELECT d.id, d.time, d.date, d.datetime FROM ' . self::NS . '\DateTimeModel d ORDER BY d.date ASC'); + $query = $this->_em->createQuery('SELECT d.id, d.time, d.date, d.datetime FROM ' . DateTimeModel::class . ' d ORDER BY d.date ASC'); $result = $query->getResult(); $this->assertCount(2,$result); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC698Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC698Test.php index c9bb3f09e5d..f21d6de6936 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC698Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC698Test.php @@ -10,8 +10,8 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC698Role'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC698Privilege') + $this->_em->getClassMetadata(DDC698Role::class), + $this->_em->getClassMetadata(DDC698Privilege::class) ] ); } catch(\Exception $e) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC719Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC719Test.php index 1ae26394cac..c6f1a2254cb 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC719Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC719Test.php @@ -10,7 +10,7 @@ protected function setUp() //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC719Group'), + $this->_em->getClassMetadata(DDC719Group::class), ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC729Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC729Test.php index 730eb99eebc..af4c9634c12 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC729Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC729Test.php @@ -2,6 +2,9 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\ORM\PersistentCollection; + class DDC729Test extends \Doctrine\Tests\OrmFunctionalTestCase { public function setUp() @@ -12,8 +15,8 @@ public function setUp() $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->_em); $schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC729A'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC729B'), + $this->_em->getClassMetadata(DDC729A::class), + $this->_em->getClassMetadata(DDC729B::class), ] ); } catch(\Exception $e) { @@ -36,11 +39,11 @@ public function testMergeManyToMany() $a = new DDC729A(); $a->id = $aId; - $this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $a->related); + $this->assertInstanceOf(ArrayCollection::class, $a->related); $a = $this->_em->merge($a); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $a->related); + $this->assertInstanceOf(PersistentCollection::class, $a->related); $this->assertFalse($a->related->isInitialized(), "Collection should not be marked initialized."); $this->assertFalse($a->related->isDirty(), "Collection should not be marked as dirty."); @@ -48,7 +51,7 @@ public function testMergeManyToMany() $this->_em->flush(); $this->_em->clear(); - $a = $this->_em->find(__NAMESPACE__ . '\DDC729A', $aId); + $a = $this->_em->find(DDC729A::class, $aId); $this->assertEquals(1, count($a->related)); } @@ -78,7 +81,7 @@ public function testUnidirectionalMergeManyToMany() $this->_em->flush(); $this->_em->clear(); - $a = $this->_em->find(__NAMESPACE__ . '\DDC729A', $aId); + $a = $this->_em->find(DDC729A::class, $aId); $this->assertEquals(2, count($a->related)); } @@ -110,7 +113,7 @@ public function testBidirectionalMergeManyToMany() $this->_em->flush(); $this->_em->clear(); - $a = $this->_em->find(__NAMESPACE__ . '\DDC729A', $aId); + $a = $this->_em->find(DDC729A::class, $aId); $this->assertEquals(2, count($a->related)); } @@ -142,7 +145,7 @@ public function testBidirectionalMultiMergeManyToMany() $this->_em->flush(); $this->_em->clear(); - $a = $this->_em->find(__NAMESPACE__ . '\DDC729A', $aId); + $a = $this->_em->find(DDC729A::class, $aId); $this->assertEquals(2, count($a->related)); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC735Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC735Test.php index 61babe8e63b..afae6973bf7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC735Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC735Test.php @@ -12,8 +12,8 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC735Product'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC735Review') + $this->_em->getClassMetadata(DDC735Product::class), + $this->_em->getClassMetadata(DDC735Review::class) ] ); } catch(\Exception $e) { @@ -49,7 +49,7 @@ public function testRemoveElement_AppliesOrphanRemoval() $this->assertEquals(0, count($product->getReviews()), 'count($reviews) should still be 0 after the refresh'); // Review should also not be available anymore - $this->assertNull($this->_em->find(__NAMESPACE__.'\DDC735Review', $reviewId)); + $this->assertNull($this->_em->find(DDC735Review::class, $reviewId)); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC736Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC736Test.php index 5141e9f3a95..932731bf6f5 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC736Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC736Test.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\ORM\Proxy\Proxy; use Doctrine\Tests\Models\ECommerce\ECommerceCart; use Doctrine\Tests\Models\ECommerce\ECommerceCustomer; use Doctrine\ORM\Query; @@ -38,9 +39,9 @@ public function testReorderEntityFetchJoinForHydration() $cart2 = $result[0]; unset($result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCart', $cart2); - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $cart2->getCustomer()); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCustomer', $cart2->getCustomer()); + $this->assertInstanceOf(ECommerceCart::class, $cart2); + $this->assertNotInstanceOf(Proxy::class, $cart2->getCustomer()); + $this->assertInstanceOf(ECommerceCustomer::class, $cart2->getCustomer()); $this->assertEquals(['name' => 'roman', 'payment' => 'cash'], $result); } @@ -65,13 +66,12 @@ public function testDqlTreeWalkerReordering() $dql = "select c, c.name, ca, ca.payment from Doctrine\Tests\Models\ECommerce\ECommerceCart ca join ca.customer c"; $result = $this->_em->createQuery($dql) - ->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\Tests\ORM\Functional\Ticket\DisableFetchJoinTreeWalker'] - ) + ->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [DisableFetchJoinTreeWalker::class]) ->getResult(); - /* @var $cart2 Doctrine\Tests\Models\ECommerce\ECommerceCart */ + /* @var $cart2 ECommerceCart */ $cart2 = $result[0][0]; - $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $cart2->getCustomer()); + $this->assertInstanceOf(Proxy::class, $cart2->getCustomer()); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC742Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC742Test.php index 773ad06a859..4d03bca2a01 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC742Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC742Test.php @@ -27,16 +27,16 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC742User'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC742Comment') + $this->_em->getClassMetadata(DDC742User::class), + $this->_em->getClassMetadata(DDC742Comment::class) ] ); } catch(\Exception $e) { } // make sure classes will be deserialized from caches - $this->_em->getMetadataFactory()->setMetadataFor(__NAMESPACE__ . '\DDC742User', null); - $this->_em->getMetadataFactory()->setMetadataFor(__NAMESPACE__ . '\DDC742Comment', null); + $this->_em->getMetadataFactory()->setMetadataFor(DDC742User::class, null); + $this->_em->getMetadataFactory()->setMetadataFor(DDC742Comment::class, null); } public function testIssue() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC748Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC748Test.php index b71ae5cde8f..cfafc66dd64 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC748Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC748Test.php @@ -2,9 +2,10 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Tests\Models\CMS\CmsUser; -use Doctrine\Tests\Models\CMS\CmsArticle; +use Doctrine\Common\Collections\Collection; use Doctrine\Tests\Models\CMS\CmsAddress; +use Doctrine\Tests\Models\CMS\CmsArticle; +use Doctrine\Tests\Models\CMS\CmsUser; class DDC748Test extends \Doctrine\Tests\OrmFunctionalTestCase { @@ -30,10 +31,10 @@ public function testRefreshWithManyToOne() $this->_em->persist($article); $this->_em->flush(); - $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $user->articles); + $this->assertInstanceOf(Collection::class, $user->articles); $this->_em->refresh($article); $this->assertTrue($article !== $user->articles, "The article should not be replaced on the inverse side of the relation."); - $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $user->articles); + $this->assertInstanceOf(Collection::class, $user->articles); } public function testRefreshOneToOne() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC758Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC758Test.php index 295542aab1c..a5707f233e3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC758Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC758Test.php @@ -38,8 +38,8 @@ private function setCascadeMergeFor($class) */ public function testManyToManyMergeAssociationAdds() { - $this->setCascadeMergeFor('Doctrine\Tests\Models\CMS\CmsUser'); - $this->setCascadeMergeFor('Doctrine\Tests\Models\CMS\CmsGroup'); + $this->setCascadeMergeFor(CmsUser::class); + $this->setCascadeMergeFor(CmsGroup::class); // Put entities in the database $cmsUser = new CmsUser(); @@ -91,8 +91,8 @@ public function testManyToManyMergeAssociationAdds() $this->_em->clear(); - $cmsUsers = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findAll(); - $cmsGroups = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findAll(); + $cmsUsers = $this->_em->getRepository(CmsUser::class)->findAll(); + $cmsGroups = $this->_em->getRepository(CmsGroup::class)->findAll(); // Check the entities are in the database $this->assertEquals(1, sizeof($cmsUsers)); @@ -115,8 +115,8 @@ public function testManyToManyMergeAssociationAdds() */ public function testManyToManyMergeAssociationRemoves() { - $this->setCascadeMergeFor('Doctrine\Tests\Models\CMS\CmsUser'); - $this->setCascadeMergeFor('Doctrine\Tests\Models\CMS\CmsGroup'); + $this->setCascadeMergeFor(CmsUser::class); + $this->setCascadeMergeFor(CmsGroup::class); $cmsUser = new CmsUser(); $cmsUser->username = "dave"; @@ -167,8 +167,8 @@ public function testManyToManyMergeAssociationRemoves() $this->_em->clear(); - $cmsUsers = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findAll(); - $cmsGroups = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findAll(); + $cmsUsers = $this->_em->getRepository(CmsUser::class)->findAll(); + $cmsGroups = $this->_em->getRepository(CmsGroup::class)->findAll(); // Check the entities are in the database $this->assertEquals(1, sizeof($cmsUsers)); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php index f6d7b95b991..4c6464a188b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php @@ -9,8 +9,8 @@ public function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC809Variant'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC809SpecificationValue') + $this->_em->getClassMetadata(DDC809Variant::class), + $this->_em->getClassMetadata(DDC809SpecificationValue::class) ] ); @@ -43,7 +43,7 @@ public function testIssue() { $result = $this->_em->createQueryBuilder() ->select('Variant, SpecificationValue') - ->from('Doctrine\Tests\ORM\Functional\Ticket\DDC809Variant', 'Variant') + ->from(DDC809Variant::class, 'Variant') ->leftJoin('Variant.SpecificationValues', 'SpecificationValue') ->getQuery() ->getResult(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php index 6e7d4ea2c0b..9e674e3cab2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php @@ -16,9 +16,9 @@ public function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC832JoinedIndex'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC832JoinedTreeIndex'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC832Like'), + $this->_em->getClassMetadata(DDC832JoinedIndex::class), + $this->_em->getClassMetadata(DDC832JoinedTreeIndex::class), + $this->_em->getClassMetadata(DDC832Like::class), ] ); } catch(\Exception $e) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC837Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC837Test.php index 5cb8f925ae6..4721a6b18be 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC837Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC837Test.php @@ -9,11 +9,11 @@ protected function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC837Super'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC837Class1'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC837Class2'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC837Class3'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC837Aggregate'), + $this->_em->getClassMetadata(DDC837Super::class), + $this->_em->getClassMetadata(DDC837Class1::class), + $this->_em->getClassMetadata(DDC837Class2::class), + $this->_em->getClassMetadata(DDC837Class3::class), + $this->_em->getClassMetadata(DDC837Aggregate::class), ] ); } @@ -51,25 +51,25 @@ public function testIssue() $this->_em->clear(); // Test Class1 - $e1 = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC837Super', $c1->id); + $e1 = $this->_em->find(DDC837Super::class, $c1->id); - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC837Class1', $e1); + $this->assertInstanceOf(DDC837Class1::class, $e1); $this->assertEquals('Foo', $e1->title); $this->assertEquals('Foo', $e1->description); - $this->assertInstanceOf(__NAMESPACE__ . '\DDC837Aggregate', $e1->aggregate); + $this->assertInstanceOf(DDC837Aggregate::class, $e1->aggregate); $this->assertEquals('test1', $e1->aggregate->getSysname()); // Test Class 2 - $e2 = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC837Super', $c2->id); + $e2 = $this->_em->find(DDC837Super::class, $c2->id); - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC837Class2', $e2); + $this->assertInstanceOf(DDC837Class2::class, $e2); $this->assertEquals('Bar', $e2->title); $this->assertEquals('Bar', $e2->description); $this->assertEquals('Bar', $e2->text); - $this->assertInstanceOf(__NAMESPACE__ . '\DDC837Aggregate', $e2->aggregate); + $this->assertInstanceOf(DDC837Aggregate::class, $e2->aggregate); $this->assertEquals('test2', $e2->aggregate->getSysname()); - $all = $this->_em->getRepository(__NAMESPACE__.'\DDC837Super')->findAll(); + $all = $this->_em->getRepository(DDC837Super::class)->findAll(); foreach ($all as $obj) { if ($obj instanceof DDC837Class1) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC849Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC849Test.php index bab38f0be38..1844b316f37 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC849Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC849Test.php @@ -36,7 +36,7 @@ public function setUp() $this->_em->flush(); $this->_em->clear(); - $this->user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->user->getId()); + $this->user = $this->_em->find(CmsUser::class, $this->user->getId()); } public function testRemoveContains() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php index 5bbeca21001..3df61f7165c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php @@ -2,6 +2,9 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\ORM\PersistentCollection; +use Doctrine\ORM\Proxy\Proxy; + class DDC881Test extends \Doctrine\Tests\OrmFunctionalTestCase { @@ -12,9 +15,9 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC881User'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC881Phonenumber'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC881Phonecall'), + $this->_em->getClassMetadata(DDC881User::class), + $this->_em->getClassMetadata(DDC881Phonenumber::class), + $this->_em->getClassMetadata(DDC881Phonecall::class), ] ); } catch (\Exception $e) { @@ -77,18 +80,18 @@ public function testIssue() $this->_em->clear(); // fetch-join that foreign-key/primary-key entity association - $dql = "SELECT c, p FROM " . __NAMESPACE__ . "\DDC881PhoneCall c JOIN c.phonenumber p"; + $dql = "SELECT c, p FROM " . DDC881PhoneCall::class . " c JOIN c.phonenumber p"; $calls = $this->_em->createQuery($dql)->getResult(); $this->assertEquals(2, count($calls)); - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $calls[0]->getPhoneNumber()); - $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $calls[1]->getPhoneNumber()); + $this->assertNotInstanceOf(Proxy::class, $calls[0]->getPhoneNumber()); + $this->assertNotInstanceOf(Proxy::class, $calls[1]->getPhoneNumber()); - $dql = "SELECT p, c FROM " . __NAMESPACE__ . "\DDC881PhoneNumber p JOIN p.calls c"; + $dql = "SELECT p, c FROM " . DDC881PhoneNumber::class . " p JOIN p.calls c"; $numbers = $this->_em->createQuery($dql)->getResult(); $this->assertEquals(2, count($numbers)); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $numbers[0]->getCalls()); + $this->assertInstanceOf(PersistentCollection::class, $numbers[0]->getCalls()); $this->assertTrue($numbers[0]->getCalls()->isInitialized()); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC949Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC949Test.php index 7e10c2c2cab..8c3162df364 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC949Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC949Test.php @@ -29,17 +29,13 @@ public function testBooleanThroughRepository() $this->_em->flush(); $this->_em->clear(); - $true = $this->_em->getRepository('Doctrine\Tests\Models\Generic\BooleanModel')->findOneBy( - ['booleanField' => true] - ); - $false = $this->_em->getRepository('Doctrine\Tests\Models\Generic\BooleanModel')->findOneBy( - ['booleanField' => false] - ); - - $this->assertInstanceOf('Doctrine\Tests\Models\Generic\BooleanModel', $true, "True model not found"); + $true = $this->_em->getRepository(BooleanModel::class)->findOneBy(['booleanField' => true]); + $false = $this->_em->getRepository(BooleanModel::class)->findOneBy(['booleanField' => false]); + + $this->assertInstanceOf(BooleanModel::class, $true, "True model not found"); $this->assertTrue($true->booleanField, "True Boolean Model should be true."); - $this->assertInstanceOf('Doctrine\Tests\Models\Generic\BooleanModel', $false, "False model not found"); + $this->assertInstanceOf(BooleanModel::class, $false, "False model not found"); $this->assertFalse($false->booleanField, "False Boolean Model should be false."); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC960Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC960Test.php index 7f9167601c9..730a70bce8c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC960Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC960Test.php @@ -12,8 +12,8 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC960Root'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC960Child') + $this->_em->getClassMetadata(DDC960Root::class), + $this->_em->getClassMetadata(DDC960Child::class) ] ); } catch(\Exception $e) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC992Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC992Test.php index e8849e10f0a..77780486bd4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC992Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC992Test.php @@ -15,9 +15,9 @@ public function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC992Role'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC992Parent'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC992Child'), + $this->_em->getClassMetadata(DDC992Role::class), + $this->_em->getClassMetadata(DDC992Parent::class), + $this->_em->getClassMetadata(DDC992Child::class), ] ); } catch(\Exception $e) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket2481Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket2481Test.php index 86a7d641f5d..ebedf0c869f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket2481Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket2481Test.php @@ -11,7 +11,7 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\Ticket2481Product') + $this->_em->getClassMetadata(Ticket2481Product::class) ] ); } catch (\Exception $e) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket69.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket69.php index d04ac27305e..ccc8bce120c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket69.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket69.php @@ -2,8 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\ORM\Query; - /** * Functional tests for the Single Table Inheritance mapping strategy. * @@ -16,9 +14,9 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\Lemma'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\Relation'), - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\RelationType') + $this->_em->getClassMetadata(Lemma::class), + $this->_em->getClassMetadata(Relation::class), + $this->_em->getClassMetadata(RelationType::class) ] ); } catch (\Exception $e) { @@ -85,11 +83,11 @@ public function testIssue() $lemma = $res[0]; $this->assertEquals('foo', $lemma->getLemma()); - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\Lemma', $lemma); + $this->assertInstanceOf(Lemma::class, $lemma); $relations = $lemma->getRelations(); foreach($relations as $relation) { - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\Relation', $relation); + $this->assertInstanceOf(Relation::class, $relation); $this->assertTrue($relation->getType()->getType() != ''); } diff --git a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php index a8afcf8caf7..05200201457 100644 --- a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php @@ -2,13 +2,12 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\DBAL\Types\Type as DBALType; +use Doctrine\ORM\Mapping\AssociationMapping; use Doctrine\Tests\Models\Generic\BooleanModel; use Doctrine\Tests\Models\Generic\DateTimeModel; use Doctrine\Tests\Models\Generic\DecimalModel; use Doctrine\Tests\Models\Generic\SerializationModel; - -use Doctrine\ORM\Mapping\AssociationMapping; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\OrmFunctionalTestCase; class TypeTest extends OrmFunctionalTestCase @@ -105,7 +104,7 @@ public function testDate() $this->_em->flush(); $this->_em->clear(); - $dateTimeDb = $this->_em->find('Doctrine\Tests\Models\Generic\DateTimeModel', $dateTime->id); + $dateTimeDb = $this->_em->find(DateTimeModel::class, $dateTime->id); $this->assertInstanceOf('DateTime', $dateTimeDb->date); $this->assertEquals('2009-10-01', $dateTimeDb->date->format('Y-m-d')); @@ -120,12 +119,12 @@ public function testDateTime() $this->_em->flush(); $this->_em->clear(); - $dateTimeDb = $this->_em->find('Doctrine\Tests\Models\Generic\DateTimeModel', $dateTime->id); + $dateTimeDb = $this->_em->find(DateTimeModel::class, $dateTime->id); $this->assertInstanceOf('DateTime', $dateTimeDb->datetime); $this->assertEquals('2009-10-02 20:10:52', $dateTimeDb->datetime->format('Y-m-d H:i:s')); - $articles = $this->_em->getRepository( 'Doctrine\Tests\Models\Generic\DateTimeModel' )->findBy( ['datetime' => new \DateTime( "now" )] + $articles = $this->_em->getRepository( DateTimeModel::class )->findBy( ['datetime' => new \DateTime( "now" )] ); $this->assertEquals( 0, count( $articles ) ); } @@ -159,7 +158,7 @@ public function testDqlQueryBuilderBindDateTimeInstance() $dateTimeDb = $this->_em->createQueryBuilder() ->select('d') - ->from('Doctrine\Tests\Models\Generic\DateTimeModel', 'd') + ->from(DateTimeModel::class, 'd') ->where('d.datetime = ?1') ->setParameter(1, $date, DBALType::DATETIME) ->getQuery()->getSingleResult(); @@ -174,7 +173,7 @@ public function testTime() $this->_em->flush(); $this->_em->clear(); - $dateTimeDb = $this->_em->find('Doctrine\Tests\Models\Generic\DateTimeModel', $dateTime->id); + $dateTimeDb = $this->_em->find(DateTimeModel::class, $dateTime->id); $this->assertInstanceOf('DateTime', $dateTime->time); $this->assertEquals('19:27:20', $dateTime->time->format('H:i:s')); diff --git a/tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php b/tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php index 8e305d1f13c..971af91703f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php @@ -2,10 +2,10 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\CustomType\CustomTypeChild; use Doctrine\Tests\Models\CustomType\CustomTypeParent; use Doctrine\Tests\Models\CustomType\CustomTypeUpperCase; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\OrmFunctionalTestCase; class TypeValueSqlTest extends OrmFunctionalTestCase @@ -51,7 +51,7 @@ public function testUpperCaseStringType() */ public function testUpperCaseStringTypeWhenColumnNameIsDefined() { - + $entity = new CustomTypeUpperCase(); $entity->lowerCaseString = 'Some Value'; $entity->namedLowerCaseString = 'foo'; @@ -104,7 +104,7 @@ public function testTypeValueSqlWithAssociations() $this->_em->clear(); - $entity = $this->_em->find('Doctrine\Tests\Models\CustomType\CustomTypeParent', $parentId); + $entity = $this->_em->find(CustomTypeParent::class, $parentId); $this->assertTrue($entity->customInteger < 0, 'Fetched customInteger negative'); $this->assertEquals(1, $this->_em->getConnection()->fetchColumn("select customInteger from customtype_parents where id=".$entity->id.""), 'Database has stored customInteger positive'); @@ -131,7 +131,7 @@ public function testSelectDQL() $result = $query->getResult(); $this->assertEquals(1, count($result)); - $this->assertInstanceOf('Doctrine\Tests\Models\CustomType\CustomTypeParent', $result[0][0]); + $this->assertInstanceOf(CustomTypeParent::class, $result[0][0]); $this->assertEquals(-1, $result[0][0]->customInteger); $this->assertEquals(-1, $result[0]['customInteger']); diff --git a/tests/Doctrine/Tests/ORM/Functional/UUIDGeneratorTest.php b/tests/Doctrine/Tests/ORM/Functional/UUIDGeneratorTest.php index c722771da32..ff352ba1f11 100644 --- a/tests/Doctrine/Tests/ORM/Functional/UUIDGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/UUIDGeneratorTest.php @@ -17,7 +17,7 @@ public function setUp() $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\\UUIDEntity') + $this->_em->getClassMetadata(UUIDEntity::class) ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php index 1094da877a7..108ba743737 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; +use Doctrine\Tests\Models; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -75,23 +76,23 @@ public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() public function testThatEntitiesAreFetchedFromTheDatabase() { $auxiliary = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', + Models\ValueConversionType\AuxiliaryEntity::class, 'abc' ); $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', + Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity::class, ['id1' => 'def', 'foreignEntity' => 'abc'] ); $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdForeignKeyEntity', + Models\ValueConversionType\OwningManyToManyCompositeIdForeignKeyEntity::class, 'ghi' ); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', $auxiliary); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', $inversed); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdForeignKeyEntity', $owning); + $this->assertInstanceOf(Models\ValueConversionType\AuxiliaryEntity::class, $auxiliary); + $this->assertInstanceOf(Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity::class, $inversed); + $this->assertInstanceOf(Models\ValueConversionType\OwningManyToManyCompositeIdForeignKeyEntity::class, $owning); } /** @@ -100,17 +101,17 @@ public function testThatEntitiesAreFetchedFromTheDatabase() public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFromTheDatabase() { $auxiliary = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', + Models\ValueConversionType\AuxiliaryEntity::class, 'abc' ); $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', + Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity::class, ['id1' => 'def', 'foreignEntity' => 'abc'] ); $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdForeignKeyEntity', + Models\ValueConversionType\OwningManyToManyCompositeIdForeignKeyEntity::class, 'ghi' ); @@ -126,16 +127,16 @@ public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFr public function testThatInversedEntityIsFetchedFromTheDatabaseUsingAuxiliaryEntityAsId() { $auxiliary = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', + Models\ValueConversionType\AuxiliaryEntity::class, 'abc' ); $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', + Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity::class, ['id1' => 'def', 'foreignEntity' => $auxiliary] ); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', $inversed); + $this->assertInstanceOf(Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity::class, $inversed); } /** @@ -144,7 +145,7 @@ public function testThatInversedEntityIsFetchedFromTheDatabaseUsingAuxiliaryEnti public function testThatTheCollectionFromOwningToInversedIsLoaded() { $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdForeignKeyEntity', + Models\ValueConversionType\OwningManyToManyCompositeIdForeignKeyEntity::class, 'ghi' ); @@ -157,7 +158,7 @@ public function testThatTheCollectionFromOwningToInversedIsLoaded() public function testThatTheCollectionFromInversedToOwningIsLoaded() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', + Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity::class, ['id1' => 'def', 'foreignEntity' => 'abc'] ); @@ -175,7 +176,7 @@ public function testThatTheJoinTableRowsAreRemovedWhenRemovingTheAssociation() // remove association $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', + Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity::class, ['id1' => 'def', 'foreignEntity' => 'abc'] ); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php index c7470a1987e..4403f2bf959 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; +use Doctrine\Tests\Models; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -67,17 +68,17 @@ public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() public function testThatEntitiesAreFetchedFromTheDatabase() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdEntity', + Models\ValueConversionType\InversedManyToManyCompositeIdEntity::class, ['id1' => 'abc', 'id2' => 'def'] ); $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdEntity', + Models\ValueConversionType\OwningManyToManyCompositeIdEntity::class, 'ghi' ); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdEntity', $inversed); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdEntity', $owning); + $this->assertInstanceOf(Models\ValueConversionType\InversedManyToManyCompositeIdEntity::class, $inversed); + $this->assertInstanceOf(Models\ValueConversionType\OwningManyToManyCompositeIdEntity::class, $owning); } /** @@ -86,12 +87,12 @@ public function testThatEntitiesAreFetchedFromTheDatabase() public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFromTheDatabase() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdEntity', + Models\ValueConversionType\InversedManyToManyCompositeIdEntity::class, ['id1' => 'abc', 'id2' => 'def'] ); $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdEntity', + Models\ValueConversionType\OwningManyToManyCompositeIdEntity::class, 'ghi' ); @@ -106,7 +107,7 @@ public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFr public function testThatTheCollectionFromOwningToInversedIsLoaded() { $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdEntity', + Models\ValueConversionType\OwningManyToManyCompositeIdEntity::class, 'ghi' ); @@ -119,7 +120,7 @@ public function testThatTheCollectionFromOwningToInversedIsLoaded() public function testThatTheCollectionFromInversedToOwningIsLoaded() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdEntity', + Models\ValueConversionType\InversedManyToManyCompositeIdEntity::class, ['id1' => 'abc', 'id2' => 'def'] ); @@ -137,7 +138,7 @@ public function testThatTheJoinTableRowsAreRemovedWhenRemovingTheAssociation() // remove association $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdEntity', + Models\ValueConversionType\InversedManyToManyCompositeIdEntity::class, ['id1' => 'abc', 'id2' => 'def'] ); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php index a8ea389c9f9..af1d99de3f9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; +use Doctrine\Tests\Models; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -64,7 +65,7 @@ public static function tearDownAfterClass() public function testThatTheExtraLazyCollectionFromOwningToInversedIsCounted() { $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyExtraLazyEntity', + Models\ValueConversionType\OwningManyToManyExtraLazyEntity::class, 'ghi' ); @@ -74,7 +75,7 @@ public function testThatTheExtraLazyCollectionFromOwningToInversedIsCounted() public function testThatTheExtraLazyCollectionFromInversedToOwningIsCounted() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyExtraLazyEntity', + Models\ValueConversionType\InversedManyToManyExtraLazyEntity::class, 'abc' ); @@ -84,12 +85,12 @@ public function testThatTheExtraLazyCollectionFromInversedToOwningIsCounted() public function testThatTheExtraLazyCollectionFromOwningToInversedContainsAnEntity() { $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyExtraLazyEntity', + Models\ValueConversionType\OwningManyToManyExtraLazyEntity::class, 'ghi' ); $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyExtraLazyEntity', + Models\ValueConversionType\InversedManyToManyExtraLazyEntity::class, 'abc' ); @@ -99,12 +100,12 @@ public function testThatTheExtraLazyCollectionFromOwningToInversedContainsAnEnti public function testThatTheExtraLazyCollectionFromInversedToOwningContainsAnEntity() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyExtraLazyEntity', + Models\ValueConversionType\InversedManyToManyExtraLazyEntity::class, 'abc' ); $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyExtraLazyEntity', + Models\ValueConversionType\OwningManyToManyExtraLazyEntity::class, 'ghi' ); @@ -114,7 +115,7 @@ public function testThatTheExtraLazyCollectionFromInversedToOwningContainsAnEnti public function testThatTheExtraLazyCollectionFromOwningToInversedContainsAnIndexByKey() { $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyExtraLazyEntity', + Models\ValueConversionType\OwningManyToManyExtraLazyEntity::class, 'ghi' ); @@ -124,7 +125,7 @@ public function testThatTheExtraLazyCollectionFromOwningToInversedContainsAnInde public function testThatTheExtraLazyCollectionFromInversedToOwningContainsAnIndexByKey() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyExtraLazyEntity', + Models\ValueConversionType\InversedManyToManyExtraLazyEntity::class, 'abc' ); @@ -134,7 +135,7 @@ public function testThatTheExtraLazyCollectionFromInversedToOwningContainsAnInde public function testThatASliceOfTheExtraLazyCollectionFromOwningToInversedIsLoaded() { $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyExtraLazyEntity', + Models\ValueConversionType\OwningManyToManyExtraLazyEntity::class, 'ghi' ); @@ -144,7 +145,7 @@ public function testThatASliceOfTheExtraLazyCollectionFromOwningToInversedIsLoad public function testThatASliceOfTheExtraLazyCollectionFromInversedToOwningIsLoaded() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyExtraLazyEntity', + Models\ValueConversionType\InversedManyToManyExtraLazyEntity::class, 'abc' ); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php index 2c51d6cd215..4532ee9d5fc 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; +use Doctrine\Tests\Models; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -64,17 +65,17 @@ public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() public function testThatEntitiesAreFetchedFromTheDatabase() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyEntity', + Models\ValueConversionType\InversedManyToManyEntity::class, 'abc' ); $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyEntity', + Models\ValueConversionType\OwningManyToManyEntity::class, 'def' ); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedManyToManyEntity', $inversed); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningManyToManyEntity', $owning); + $this->assertInstanceOf(Models\ValueConversionType\InversedManyToManyEntity::class, $inversed); + $this->assertInstanceOf(Models\ValueConversionType\OwningManyToManyEntity::class, $owning); } /** @@ -83,12 +84,12 @@ public function testThatEntitiesAreFetchedFromTheDatabase() public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFromTheDatabase() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyEntity', + Models\ValueConversionType\InversedManyToManyEntity::class, 'abc' ); $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyEntity', + Models\ValueConversionType\OwningManyToManyEntity::class, 'def' ); @@ -102,7 +103,7 @@ public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFr public function testThatTheCollectionFromOwningToInversedIsLoaded() { $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyEntity', + Models\ValueConversionType\OwningManyToManyEntity::class, 'def' ); @@ -115,7 +116,7 @@ public function testThatTheCollectionFromOwningToInversedIsLoaded() public function testThatTheCollectionFromInversedToOwningIsLoaded() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyEntity', + Models\ValueConversionType\InversedManyToManyEntity::class, 'abc' ); @@ -133,7 +134,7 @@ public function testThatTheJoinTableRowsAreRemovedWhenRemovingTheAssociation() // remove association $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyEntity', + Models\ValueConversionType\InversedManyToManyEntity::class, 'abc' ); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php index eb3de5f1229..b76687bc4b3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; +use Doctrine\Tests\Models; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -73,23 +74,23 @@ public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() public function testThatEntitiesAreFetchedFromTheDatabase() { $auxiliary = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', + Models\ValueConversionType\AuxiliaryEntity::class, 'abc' ); $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', + Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity::class, ['id1' => 'def', 'foreignEntity' => 'abc'] ); $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdForeignKeyEntity', + Models\ValueConversionType\OwningManyToOneCompositeIdForeignKeyEntity::class, 'ghi' ); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', $auxiliary); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', $inversed); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdForeignKeyEntity', $owning); + $this->assertInstanceOf(Models\ValueConversionType\AuxiliaryEntity::class, $auxiliary); + $this->assertInstanceOf(Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity::class, $inversed); + $this->assertInstanceOf(Models\ValueConversionType\OwningManyToOneCompositeIdForeignKeyEntity::class, $owning); } /** @@ -98,17 +99,17 @@ public function testThatEntitiesAreFetchedFromTheDatabase() public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFromTheDatabase() { $auxiliary = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', + Models\ValueConversionType\AuxiliaryEntity::class, 'abc' ); $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', + Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity::class, ['id1' => 'def', 'foreignEntity' => 'abc'] ); $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdForeignKeyEntity', + Models\ValueConversionType\OwningManyToOneCompositeIdForeignKeyEntity::class, 'ghi' ); @@ -124,16 +125,16 @@ public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFr public function testThatInversedEntityIsFetchedFromTheDatabaseUsingAuxiliaryEntityAsId() { $auxiliary = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', + Models\ValueConversionType\AuxiliaryEntity::class, 'abc' ); $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', + Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity::class, ['id1' => 'def', 'foreignEntity' => $auxiliary] ); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', $inversed); + $this->assertInstanceOf(Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity::class, $inversed); } /** @@ -142,7 +143,7 @@ public function testThatInversedEntityIsFetchedFromTheDatabaseUsingAuxiliaryEnti public function testThatTheProxyFromOwningToInversedIsLoaded() { $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdForeignKeyEntity', + Models\ValueConversionType\OwningManyToOneCompositeIdForeignKeyEntity::class, 'ghi' ); @@ -159,7 +160,7 @@ public function testThatTheProxyFromOwningToInversedIsLoaded() public function testThatTheCollectionFromInversedToOwningIsLoaded() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', + Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity::class, ['id1' => 'def', 'foreignEntity' => 'abc'] ); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php index f68084eb520..266a382e760 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; +use Doctrine\Tests\Models; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -65,17 +66,17 @@ public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() public function testThatEntitiesAreFetchedFromTheDatabase() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdEntity', + Models\ValueConversionType\InversedOneToManyCompositeIdEntity::class, ['id1' => 'abc', 'id2' => 'def'] ); $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdEntity', + Models\ValueConversionType\OwningManyToOneCompositeIdEntity::class, 'ghi' ); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdEntity', $inversed); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdEntity', $owning); + $this->assertInstanceOf(Models\ValueConversionType\InversedOneToManyCompositeIdEntity::class, $inversed); + $this->assertInstanceOf(Models\ValueConversionType\OwningManyToOneCompositeIdEntity::class, $owning); } /** @@ -84,12 +85,12 @@ public function testThatEntitiesAreFetchedFromTheDatabase() public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFromTheDatabase() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdEntity', + Models\ValueConversionType\InversedOneToManyCompositeIdEntity::class, ['id1' => 'abc', 'id2' => 'def'] ); $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdEntity', + Models\ValueConversionType\OwningManyToOneCompositeIdEntity::class, 'ghi' ); @@ -104,7 +105,7 @@ public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFr public function testThatTheProxyFromOwningToInversedIsLoaded() { $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdEntity', + Models\ValueConversionType\OwningManyToOneCompositeIdEntity::class, 'ghi' ); @@ -119,7 +120,7 @@ public function testThatTheProxyFromOwningToInversedIsLoaded() public function testThatTheCollectionFromInversedToOwningIsLoaded() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdEntity', + Models\ValueConversionType\InversedOneToManyCompositeIdEntity::class, ['id1' => 'abc', 'id2' => 'def'] ); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php index 75b5403fe55..9da341467a4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; +use Doctrine\Tests\Models; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -61,7 +62,7 @@ public static function tearDownAfterClass() public function testThatExtraLazyCollectionIsCounted() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyExtraLazyEntity', + Models\ValueConversionType\InversedOneToManyExtraLazyEntity::class, 'abc' ); @@ -71,12 +72,12 @@ public function testThatExtraLazyCollectionIsCounted() public function testThatExtraLazyCollectionContainsAnEntity() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyExtraLazyEntity', + Models\ValueConversionType\InversedOneToManyExtraLazyEntity::class, 'abc' ); $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneExtraLazyEntity', + Models\ValueConversionType\OwningManyToOneExtraLazyEntity::class, 'def' ); @@ -86,7 +87,7 @@ public function testThatExtraLazyCollectionContainsAnEntity() public function testThatExtraLazyCollectionContainsAnIndexbyKey() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyExtraLazyEntity', + Models\ValueConversionType\InversedOneToManyExtraLazyEntity::class, 'abc' ); @@ -96,7 +97,7 @@ public function testThatExtraLazyCollectionContainsAnIndexbyKey() public function testThatASliceOfTheExtraLazyCollectionIsLoaded() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyExtraLazyEntity', + Models\ValueConversionType\InversedOneToManyExtraLazyEntity::class, 'abc' ); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php index 137a5eaa963..6a10296a7f9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; +use Doctrine\Tests\Models; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -62,17 +63,17 @@ public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() public function testThatEntitiesAreFetchedFromTheDatabase() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyEntity', + Models\ValueConversionType\InversedOneToManyEntity::class, 'abc' ); $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneEntity', + Models\ValueConversionType\OwningManyToOneEntity::class, 'def' ); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedOneToManyEntity', $inversed); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningManyToOneEntity', $owning); + $this->assertInstanceOf(Models\ValueConversionType\InversedOneToManyEntity::class, $inversed); + $this->assertInstanceOf(Models\ValueConversionType\OwningManyToOneEntity::class, $owning); } /** @@ -81,12 +82,12 @@ public function testThatEntitiesAreFetchedFromTheDatabase() public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFromTheDatabase() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyEntity', + Models\ValueConversionType\InversedOneToManyEntity::class, 'abc' ); $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneEntity', + Models\ValueConversionType\OwningManyToOneEntity::class, 'def' ); @@ -100,7 +101,7 @@ public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFr public function testThatTheProxyFromOwningToInversedIsLoaded() { $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneEntity', + Models\ValueConversionType\OwningManyToOneEntity::class, 'def' ); @@ -115,7 +116,7 @@ public function testThatTheProxyFromOwningToInversedIsLoaded() public function testThatTheCollectionFromInversedToOwningIsLoaded() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyEntity', + Models\ValueConversionType\InversedOneToManyEntity::class, 'abc' ); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php index e527ee2ef17..206ca7e3258 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; +use Doctrine\Tests\Models; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -72,23 +73,23 @@ public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() public function testThatEntitiesAreFetchedFromTheDatabase() { $auxiliary = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', + Models\ValueConversionType\AuxiliaryEntity::class, 'abc' ); $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', + Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity::class, ['id1' => 'def', 'foreignEntity' => 'abc'] ); $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity', + Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity::class, 'ghi' ); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', $auxiliary); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', $inversed); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity', $owning); + $this->assertInstanceOf(Models\ValueConversionType\AuxiliaryEntity::class, $auxiliary); + $this->assertInstanceOf(Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity::class, $inversed); + $this->assertInstanceOf(Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity::class, $owning); } /** @@ -97,17 +98,17 @@ public function testThatEntitiesAreFetchedFromTheDatabase() public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFromTheDatabase() { $auxiliary = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', + Models\ValueConversionType\AuxiliaryEntity::class, 'abc' ); $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', + Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity::class, ['id1' => 'def', 'foreignEntity' => 'abc'] ); $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity', + Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity::class, 'ghi' ); @@ -123,16 +124,16 @@ public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFr public function testThatInversedEntityIsFetchedFromTheDatabaseUsingAuxiliaryEntityAsId() { $auxiliary = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', + Models\ValueConversionType\AuxiliaryEntity::class, 'abc' ); $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', + Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity::class, ['id1' => 'def', 'foreignEntity' => $auxiliary] ); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', $inversed); + $this->assertInstanceOf(Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity::class, $inversed); } /** @@ -141,7 +142,7 @@ public function testThatInversedEntityIsFetchedFromTheDatabaseUsingAuxiliaryEnti public function testThatTheProxyFromOwningToInversedIsLoaded() { $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity', + Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity::class, 'ghi' ); @@ -156,10 +157,10 @@ public function testThatTheProxyFromOwningToInversedIsLoaded() public function testThatTheEntityFromInversedToOwningIsEagerLoaded() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', + Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity::class, ['id1' => 'def', 'foreignEntity' => 'abc'] ); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity', $inversed->associatedEntity); + $this->assertInstanceOf(Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity::class, $inversed->associatedEntity); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php index 2f944f2356a..428fe80c6c5 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; +use Doctrine\Tests\Models; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -64,17 +65,17 @@ public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() public function testThatEntitiesAreFetchedFromTheDatabase() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdEntity', + Models\ValueConversionType\InversedOneToOneCompositeIdEntity::class, ['id1' => 'abc', 'id2' => 'def'] ); $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdEntity', + Models\ValueConversionType\OwningOneToOneCompositeIdEntity::class, 'ghi' ); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdEntity', $inversed); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdEntity', $owning); + $this->assertInstanceOf(Models\ValueConversionType\InversedOneToOneCompositeIdEntity::class, $inversed); + $this->assertInstanceOf(Models\ValueConversionType\OwningOneToOneCompositeIdEntity::class, $owning); } /** @@ -83,12 +84,12 @@ public function testThatEntitiesAreFetchedFromTheDatabase() public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFromTheDatabase() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdEntity', + Models\ValueConversionType\InversedOneToOneCompositeIdEntity::class, ['id1' => 'abc', 'id2' => 'def'] ); $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdEntity', + Models\ValueConversionType\OwningOneToOneCompositeIdEntity::class, 'ghi' ); @@ -103,7 +104,7 @@ public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFr public function testThatTheProxyFromOwningToInversedIsLoaded() { $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdEntity', + Models\ValueConversionType\OwningOneToOneCompositeIdEntity::class, 'ghi' ); @@ -118,10 +119,10 @@ public function testThatTheProxyFromOwningToInversedIsLoaded() public function testThatTheEntityFromInversedToOwningIsEagerLoaded() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdEntity', + Models\ValueConversionType\InversedOneToOneCompositeIdEntity::class, ['id1' => 'abc', 'id2' => 'def'] ); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdEntity', $inversed->associatedEntity); + $this->assertInstanceOf(Models\ValueConversionType\OwningOneToOneCompositeIdEntity::class, $inversed->associatedEntity); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php index 0de217e361c..8ca8eebe56d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; +use Doctrine\Tests\Models; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -62,17 +63,17 @@ public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() public function testThatEntitiesAreFetchedFromTheDatabase() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneEntity', + Models\ValueConversionType\InversedOneToOneEntity::class, 'abc' ); $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneEntity', + Models\ValueConversionType\OwningOneToOneEntity::class, 'def' ); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedOneToOneEntity', $inversed); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningOneToOneEntity', $owning); + $this->assertInstanceOf(Models\ValueConversionType\InversedOneToOneEntity::class, $inversed); + $this->assertInstanceOf(Models\ValueConversionType\OwningOneToOneEntity::class, $owning); } /** @@ -81,12 +82,12 @@ public function testThatEntitiesAreFetchedFromTheDatabase() public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFromTheDatabase() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneEntity', + Models\ValueConversionType\InversedOneToOneEntity::class, 'abc' ); $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneEntity', + Models\ValueConversionType\OwningOneToOneEntity::class, 'def' ); @@ -100,7 +101,7 @@ public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFr public function testThatTheProxyFromOwningToInversedIsLoaded() { $owning = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneEntity', + Models\ValueConversionType\OwningOneToOneEntity::class, 'def' ); @@ -115,10 +116,10 @@ public function testThatTheProxyFromOwningToInversedIsLoaded() public function testThatTheEntityFromInversedToOwningIsEagerLoaded() { $inversed = $this->_em->find( - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneEntity', + Models\ValueConversionType\InversedOneToOneEntity::class, 'abc' ); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningOneToOneEntity', $inversed->associatedEntity); + $this->assertInstanceOf(Models\ValueConversionType\OwningOneToOneEntity::class, $inversed->associatedEntity); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php index 02b4748beed..7df4171b42c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php @@ -1,7 +1,9 @@ _schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC93Person'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC93Address'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC93Vehicle'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC93Car'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3027Animal'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3027Dog'), + $this->_em->getClassMetadata(DDC93Person::class), + $this->_em->getClassMetadata(DDC93Address::class), + $this->_em->getClassMetadata(DDC93Vehicle::class), + $this->_em->getClassMetadata(DDC93Car::class), + $this->_em->getClassMetadata(DDC3027Animal::class), + $this->_em->getClassMetadata(DDC3027Dog::class), ] ); } catch(\Exception $e) { @@ -31,10 +33,10 @@ public function setUp() public function testMetadataHasReflectionEmbeddablesAccessible() { - $classMetadata = $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC93Person'); + $classMetadata = $this->_em->getClassMetadata(DDC93Person::class); - $this->assertInstanceOf('Doctrine\Common\Reflection\RuntimePublicReflectionProperty', $classMetadata->getReflectionProperty('address')); - $this->assertInstanceOf('Doctrine\ORM\Mapping\ReflectionEmbeddedProperty', $classMetadata->getReflectionProperty('address.street')); + $this->assertInstanceOf(RuntimePublicReflectionProperty::class, $classMetadata->getReflectionProperty('address')); + $this->assertInstanceOf(ReflectionEmbeddedProperty::class, $classMetadata->getReflectionProperty('address.street')); } public function testCRUD() @@ -54,13 +56,13 @@ public function testCRUD() $this->_em->clear(); // 2. check loading value objects works - $person = $this->_em->find(DDC93Person::CLASSNAME, $person->id); + $person = $this->_em->find(DDC93Person::class, $person->id); - $this->assertInstanceOf(DDC93Address::CLASSNAME, $person->address); + $this->assertInstanceOf(DDC93Address::class, $person->address); $this->assertEquals('United States of Tara Street', $person->address->street); $this->assertEquals('12345', $person->address->zip); $this->assertEquals('funkytown', $person->address->city); - $this->assertInstanceOf(DDC93Country::CLASSNAME, $person->address->country); + $this->assertInstanceOf(DDC93Country::class, $person->address->country); $this->assertEquals('Germany', $person->address->country->name); // 3. check changing value objects works @@ -72,7 +74,7 @@ public function testCRUD() $this->_em->clear(); - $person = $this->_em->find(DDC93Person::CLASSNAME, $person->id); + $person = $this->_em->find(DDC93Person::class, $person->id); $this->assertEquals('Street', $person->address->street); $this->assertEquals('54321', $person->address->zip); @@ -84,7 +86,7 @@ public function testCRUD() $this->_em->remove($person); $this->_em->flush(); - $this->assertNull($this->_em->find(DDC93Person::CLASSNAME, $personId)); + $this->assertNull($this->_em->find(DDC93Person::class, $personId)); } public function testLoadDql() @@ -109,11 +111,11 @@ public function testLoadDql() $this->assertCount(3, $persons); foreach ($persons as $person) { - $this->assertInstanceOf(DDC93Address::CLASSNAME, $person->address); + $this->assertInstanceOf(DDC93Address::class, $person->address); $this->assertEquals('Tree', $person->address->street); $this->assertEquals('12345', $person->address->zip); $this->assertEquals('funkytown', $person->address->city); - $this->assertInstanceOf(DDC93Country::CLASSNAME, $person->address->country); + $this->assertInstanceOf(DDC93Country::class, $person->address->country); $this->assertEquals('United States of America', $person->address->country->name); } @@ -175,7 +177,7 @@ public function testDqlOnEmbeddedObjectsField() ->execute(); $this->_em->clear(); - $this->assertNull($this->_em->find(__NAMESPACE__.'\\DDC93Person', $person->id)); + $this->assertNull($this->_em->find(DDC93Person::class, $person->id)); } public function testPartialDqlOnEmbeddedObjectsField() @@ -254,13 +256,13 @@ public function testEmbeddableWithInheritance() $this->_em->persist($car); $this->_em->flush($car); - $reloadedCar = $this->_em->find(__NAMESPACE__.'\\DDC93Car', $car->id); + $reloadedCar = $this->_em->find(DDC93Car::class, $car->id); $this->assertEquals($car, $reloadedCar); } public function testInlineEmbeddableWithPrefix() { - $metadata = $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3028PersonWithPrefix'); + $metadata = $this->_em->getClassMetadata(DDC3028PersonWithPrefix::class); $this->assertEquals('foobar_id', $metadata->getColumnName('id.id')); $this->assertEquals('bloo_foo_id', $metadata->getColumnName('nested.nestedWithPrefix.id')); @@ -270,7 +272,7 @@ public function testInlineEmbeddableWithPrefix() public function testInlineEmbeddableEmptyPrefix() { - $metadata = $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3028PersonEmptyPrefix'); + $metadata = $this->_em->getClassMetadata(DDC3028PersonEmptyPrefix::class); $this->assertEquals('id_id', $metadata->getColumnName('id.id')); $this->assertEquals('nested_foo_id', $metadata->getColumnName('nested.nestedWithPrefix.id')); @@ -283,7 +285,7 @@ public function testInlineEmbeddablePrefixFalse() $expectedColumnName = 'id'; $actualColumnName = $this->_em - ->getClassMetadata(__NAMESPACE__ . '\DDC3028PersonPrefixFalse') + ->getClassMetadata(DDC3028PersonPrefixFalse::class) ->getColumnName('id.id'); $this->assertEquals($expectedColumnName, $actualColumnName); @@ -292,7 +294,7 @@ public function testInlineEmbeddablePrefixFalse() public function testInlineEmbeddableInMappedSuperClass() { $isFieldMapped = $this->_em - ->getClassMetadata(__NAMESPACE__ . '\DDC3027Dog') + ->getClassMetadata(DDC3027Dog::class) ->hasField('address.street'); $this->assertTrue($isFieldMapped); diff --git a/tests/Doctrine/Tests/ORM/Functional/VersionedOneToOneTest.php b/tests/Doctrine/Tests/ORM/Functional/VersionedOneToOneTest.php index 0fef61a483b..f8062f9954e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/VersionedOneToOneTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/VersionedOneToOneTest.php @@ -23,8 +23,8 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata('Doctrine\Tests\Models\VersionedOneToOne\FirstRelatedEntity'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\VersionedOneToOne\SecondRelatedEntity') + $this->_em->getClassMetadata(FirstRelatedEntity::class), + $this->_em->getClassMetadata(SecondRelatedEntity::class) ] ); } catch (ORMException $e) { @@ -50,10 +50,10 @@ public function testSetVersionOnCreate() $this->_em->persist($firstRelatedEntity); $this->_em->flush(); - $firstEntity = $this->_em->getRepository('Doctrine\Tests\Models\VersionedOneToOne\FirstRelatedEntity') + $firstEntity = $this->_em->getRepository(FirstRelatedEntity::class) ->findOneBy(['name' => 'Fred']); - $secondEntity = $this->_em->getRepository('Doctrine\Tests\Models\VersionedOneToOne\SecondRelatedEntity') + $secondEntity = $this->_em->getRepository(SecondRelatedEntity::class) ->findOneBy(['name' => 'Bob']); $this->assertSame($firstRelatedEntity, $firstEntity); diff --git a/tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php index 4763ded58ef..6c0b30ef655 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php @@ -2,8 +2,14 @@ namespace Doctrine\Tests\ORM\Hydration; -use Doctrine\Tests\Mocks\HydratorMockStatement; use Doctrine\ORM\Query\ResultSetMapping; +use Doctrine\Tests\Mocks\HydratorMockStatement; +use Doctrine\Tests\Models\CMS\CmsArticle; +use Doctrine\Tests\Models\CMS\CmsComment; +use Doctrine\Tests\Models\CMS\CmsPhonenumber; +use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\Models\Forum\ForumBoard; +use Doctrine\Tests\Models\Forum\ForumCategory; class ArrayHydratorTest extends HydrationTestCase { @@ -25,7 +31,7 @@ public function testSimpleEntityQuery() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addEntityResult(CmsUser::class, 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); @@ -66,7 +72,7 @@ public function testSimpleEntityWithScalarQuery($userEntityKey) $alias = $userEntityKey ?: 'u'; $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', $alias); + $rsm->addEntityResult(CmsUser::class, $alias); $rsm->addFieldResult($alias, 's__id', 'id'); $rsm->addFieldResult($alias, 's__name', 'name'); $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); @@ -117,7 +123,7 @@ public function testSimpleEntityQueryWithAliasedUserEntity() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', 'user'); + $rsm->addEntityResult(CmsUser::class, 'u', 'user'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); @@ -157,8 +163,8 @@ public function testSimpleMultipleRootEntityQuery() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsArticle', 'a'); + $rsm->addEntityResult(CmsUser::class, 'u'); + $rsm->addEntityResult(CmsArticle::class, 'a'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); $rsm->addFieldResult('a', 'a__id', 'id'); @@ -207,8 +213,8 @@ public function testSimpleMultipleRootEntityQueryWithAliasedUserEntity() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', 'user'); - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsArticle', 'a'); + $rsm->addEntityResult(CmsUser::class, 'u', 'user'); + $rsm->addEntityResult(CmsArticle::class, 'a'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); $rsm->addFieldResult('a', 'a__id', 'id'); @@ -261,8 +267,8 @@ public function testSimpleMultipleRootEntityQueryWithAliasedArticleEntity() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsArticle', 'a', 'article'); + $rsm->addEntityResult(CmsUser::class, 'u'); + $rsm->addEntityResult(CmsArticle::class, 'a', 'article'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); $rsm->addFieldResult('a', 'a__id', 'id'); @@ -315,8 +321,8 @@ public function testSimpleMultipleRootEntityQueryWithAliasedEntities() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', 'user'); - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsArticle', 'a', 'article'); + $rsm->addEntityResult(CmsUser::class, 'u', 'user'); + $rsm->addEntityResult(CmsArticle::class, 'a', 'article'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); $rsm->addFieldResult('a', 'a__id', 'id'); @@ -373,7 +379,7 @@ public function testMixedQueryNormalJoin($userEntityKey) { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); + $rsm->addEntityResult(CmsUser::class, 'u', $userEntityKey ?: null); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); $rsm->addScalarResult('sclr0', 'numPhones', 'integer'); @@ -422,9 +428,9 @@ public function testMixedQueryFetchJoin($userEntityKey) { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); + $rsm->addEntityResult(CmsUser::class, 'u', $userEntityKey ?: null); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsPhonenumber', + CmsPhonenumber::class, 'p', 'u', 'phonenumbers' @@ -493,9 +499,9 @@ public function testMixedQueryFetchJoinCustomIndex($userEntityKey) { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); + $rsm->addEntityResult(CmsUser::class, 'u', $userEntityKey ?: null); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsPhonenumber', + CmsPhonenumber::class, 'p', 'u', 'phonenumbers' @@ -572,15 +578,15 @@ public function testMixedQueryMultipleFetchJoin() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addEntityResult(CmsUser::class, 'u'); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsPhonenumber', + CmsPhonenumber::class, 'p', 'u', 'phonenumbers' ); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsArticle', + CmsArticle::class, 'a', 'u', 'articles' @@ -691,21 +697,21 @@ public function testMixedQueryMultipleDeepMixedFetchJoin() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addEntityResult(CmsUser::class, 'u'); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsPhonenumber', + CmsPhonenumber::class, 'p', 'u', 'phonenumbers' ); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsArticle', + CmsArticle::class, 'a', 'u', 'articles' ); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsComment', + CmsComment::class, 'c', 'a', 'comments' @@ -848,9 +854,9 @@ public function testEntityQueryCustomResultSetOrder() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\Forum\ForumCategory', 'c'); + $rsm->addEntityResult(ForumCategory::class, 'c'); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\Forum\ForumBoard', + ForumBoard::class, 'b', 'c', 'boards' @@ -924,7 +930,7 @@ public function testChainedJoinWithScalars($entityKey) { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $entityKey ?: null); + $rsm->addEntityResult(CmsUser::class, 'u', $entityKey ?: null); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); $rsm->addScalarResult('a__id', 'id', 'integer'); @@ -994,7 +1000,7 @@ public function testResultIteration() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addEntityResult(CmsUser::class, 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); @@ -1039,7 +1045,7 @@ public function testResultIterationWithAliasedUserEntity() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', 'user'); + $rsm->addEntityResult(CmsUser::class, 'u', 'user'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); @@ -1087,7 +1093,7 @@ public function testSkipUnknownColumns() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addEntityResult(CmsUser::class, 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); @@ -1121,7 +1127,7 @@ public function testMissingIdForRootEntity($userEntityKey) { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); + $rsm->addEntityResult(CmsUser::class, 'u', $userEntityKey ?: null); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); @@ -1180,7 +1186,7 @@ public function testIndexByAndMixedResult($userEntityKey) { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); + $rsm->addEntityResult(CmsUser::class, 'u', $userEntityKey ?: null); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); diff --git a/tests/Doctrine/Tests/ORM/Hydration/CustomHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/CustomHydratorTest.php index 1135e988d5d..7342b942f4f 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/CustomHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/CustomHydratorTest.php @@ -2,7 +2,8 @@ namespace Doctrine\Tests\ORM\Hydration; -use PDO, Doctrine\ORM\Internal\Hydration\AbstractHydrator; +use Doctrine\ORM\Internal\Hydration\AbstractHydrator; +use PDO; class CustomHydratorTest extends HydrationTestCase { @@ -10,10 +11,10 @@ public function testCustomHydrator() { $em = $this->_getTestEntityManager(); $config = $em->getConfiguration(); - $config->addCustomHydrationMode('CustomHydrator', 'Doctrine\Tests\ORM\Hydration\CustomHydrator'); + $config->addCustomHydrationMode('CustomHydrator', CustomHydrator::class); $hydrator = $em->newHydrator('CustomHydrator'); - $this->assertInstanceOf('Doctrine\Tests\ORM\Hydration\CustomHydrator', $hydrator); + $this->assertInstanceOf(CustomHydrator::class, $hydrator); $this->assertNull($config->getCustomHydrationMode('does not exist')); } } diff --git a/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php index 7a4c8aaedb6..83e398836d8 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php @@ -2,11 +2,25 @@ namespace Doctrine\Tests\ORM\Hydration; -use Doctrine\ORM\Proxy\ProxyFactory; -use Doctrine\Tests\Mocks\HydratorMockStatement; -use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\PersistentCollection; +use Doctrine\ORM\Proxy\ProxyFactory; use Doctrine\ORM\Query; +use Doctrine\ORM\Query\ResultSetMapping; +use Doctrine\Tests\Mocks\HydratorMockStatement; +use Doctrine\Tests\Models\CMS\CmsAddress; +use Doctrine\Tests\Models\CMS\CmsArticle; +use Doctrine\Tests\Models\CMS\CmsComment; +use Doctrine\Tests\Models\CMS\CmsGroup; +use Doctrine\Tests\Models\CMS\CmsPhonenumber; +use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\Models\Company\CompanyEmployee; +use Doctrine\Tests\Models\Company\CompanyFixContract; +use Doctrine\Tests\Models\Company\CompanyPerson; +use Doctrine\Tests\Models\ECommerce\ECommerceProduct; +use Doctrine\Tests\Models\ECommerce\ECommerceShipping; +use Doctrine\Tests\Models\Forum\ForumBoard; +use Doctrine\Tests\Models\Forum\ForumCategory; use Doctrine\Tests\Models\Hydration\EntityWithArrayDefaultArrayValueM2M; use Doctrine\Tests\Models\Hydration\SimpleEntity; @@ -45,7 +59,7 @@ public function provideDataForProductEntityResult() public function testSimpleEntityQuery() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addEntityResult(CmsUser::class, 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); @@ -67,8 +81,8 @@ public function testSimpleEntityQuery() $this->assertEquals(2, count($result)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[1]); + $this->assertInstanceOf(CmsUser::class, $result[0]); + $this->assertInstanceOf(CmsUser::class, $result[1]); $this->assertEquals(1, $result[0]->id); $this->assertEquals('romanb', $result[0]->name); @@ -84,7 +98,7 @@ public function testSimpleEntityQuery() public function testSimpleEntityQueryWithAliasedUserEntity() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', 'user'); + $rsm->addEntityResult(CmsUser::class, 'u', 'user'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); @@ -107,10 +121,10 @@ public function testSimpleEntityQueryWithAliasedUserEntity() $this->assertEquals(2, count($result)); $this->assertArrayHasKey('user', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0]['user']); + $this->assertInstanceOf(CmsUser::class, $result[0]['user']); $this->assertArrayHasKey('user', $result[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[1]['user']); + $this->assertInstanceOf(CmsUser::class, $result[1]['user']); $this->assertEquals(1, $result[0]['user']->id); $this->assertEquals('romanb', $result[0]['user']->name); @@ -126,8 +140,8 @@ public function testSimpleEntityQueryWithAliasedUserEntity() public function testSimpleMultipleRootEntityQuery() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsArticle', 'a'); + $rsm->addEntityResult(CmsUser::class, 'u'); + $rsm->addEntityResult(CmsArticle::class, 'a'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); $rsm->addFieldResult('a', 'a__id', 'id'); @@ -155,10 +169,10 @@ public function testSimpleMultipleRootEntityQuery() $this->assertEquals(4, count($result)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[2]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[3]); + $this->assertInstanceOf(CmsUser::class, $result[0]); + $this->assertInstanceOf(CmsArticle::class, $result[1]); + $this->assertInstanceOf(CmsUser::class, $result[2]); + $this->assertInstanceOf(CmsArticle::class, $result[3]); $this->assertEquals(1, $result[0]->id); $this->assertEquals('romanb', $result[0]->name); @@ -180,8 +194,8 @@ public function testSimpleMultipleRootEntityQuery() public function testSimpleMultipleRootEntityQueryWithAliasedUserEntity() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', 'user'); - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsArticle', 'a'); + $rsm->addEntityResult(CmsUser::class, 'u', 'user'); + $rsm->addEntityResult(CmsArticle::class, 'a'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); $rsm->addFieldResult('a', 'a__id', 'id'); @@ -211,25 +225,25 @@ public function testSimpleMultipleRootEntityQueryWithAliasedUserEntity() $this->assertArrayHasKey('user', $result[0]); $this->assertArrayNotHasKey(0, $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0]['user']); + $this->assertInstanceOf(CmsUser::class, $result[0]['user']); $this->assertEquals(1, $result[0]['user']->id); $this->assertEquals('romanb', $result[0]['user']->name); $this->assertArrayHasKey(0, $result[1]); $this->assertArrayNotHasKey('user', $result[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[1][0]); + $this->assertInstanceOf(CmsArticle::class, $result[1][0]); $this->assertEquals(1, $result[1][0]->id); $this->assertEquals('Cool things.', $result[1][0]->topic); $this->assertArrayHasKey('user', $result[2]); $this->assertArrayNotHasKey(0, $result[2]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[2]['user']); + $this->assertInstanceOf(CmsUser::class, $result[2]['user']); $this->assertEquals(2, $result[2]['user']->id); $this->assertEquals('jwage', $result[2]['user']->name); $this->assertArrayHasKey(0, $result[3]); $this->assertArrayNotHasKey('user', $result[3]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[3][0]); + $this->assertInstanceOf(CmsArticle::class, $result[3][0]); $this->assertEquals(2, $result[3][0]->id); $this->assertEquals('Cool things II.', $result[3][0]->topic); } @@ -241,8 +255,8 @@ public function testSimpleMultipleRootEntityQueryWithAliasedUserEntity() public function testSimpleMultipleRootEntityQueryWithAliasedArticleEntity() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsArticle', 'a', 'article'); + $rsm->addEntityResult(CmsUser::class, 'u'); + $rsm->addEntityResult(CmsArticle::class, 'a', 'article'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); $rsm->addFieldResult('a', 'a__id', 'id'); @@ -272,25 +286,25 @@ public function testSimpleMultipleRootEntityQueryWithAliasedArticleEntity() $this->assertArrayHasKey(0, $result[0]); $this->assertArrayNotHasKey('article', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0][0]); + $this->assertInstanceOf(CmsUser::class, $result[0][0]); $this->assertEquals(1, $result[0][0]->id); $this->assertEquals('romanb', $result[0][0]->name); $this->assertArrayHasKey('article', $result[1]); $this->assertArrayNotHasKey(0, $result[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[1]['article']); + $this->assertInstanceOf(CmsArticle::class, $result[1]['article']); $this->assertEquals(1, $result[1]['article']->id); $this->assertEquals('Cool things.', $result[1]['article']->topic); $this->assertArrayHasKey(0, $result[2]); $this->assertArrayNotHasKey('article', $result[2]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[2][0]); + $this->assertInstanceOf(CmsUser::class, $result[2][0]); $this->assertEquals(2, $result[2][0]->id); $this->assertEquals('jwage', $result[2][0]->name); $this->assertArrayHasKey('article', $result[3]); $this->assertArrayNotHasKey(0, $result[3]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[3]['article']); + $this->assertInstanceOf(CmsArticle::class, $result[3]['article']); $this->assertEquals(2, $result[3]['article']->id); $this->assertEquals('Cool things II.', $result[3]['article']->topic); } @@ -302,8 +316,8 @@ public function testSimpleMultipleRootEntityQueryWithAliasedArticleEntity() public function testSimpleMultipleRootEntityQueryWithAliasedEntities() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', 'user'); - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsArticle', 'a', 'article'); + $rsm->addEntityResult(CmsUser::class, 'u', 'user'); + $rsm->addEntityResult(CmsArticle::class, 'a', 'article'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); $rsm->addFieldResult('a', 'a__id', 'id'); @@ -333,25 +347,25 @@ public function testSimpleMultipleRootEntityQueryWithAliasedEntities() $this->assertArrayHasKey('user', $result[0]); $this->assertArrayNotHasKey('article', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0]['user']); + $this->assertInstanceOf(CmsUser::class, $result[0]['user']); $this->assertEquals(1, $result[0]['user']->id); $this->assertEquals('romanb', $result[0]['user']->name); $this->assertArrayHasKey('article', $result[1]); $this->assertArrayNotHasKey('user', $result[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[1]['article']); + $this->assertInstanceOf(CmsArticle::class, $result[1]['article']); $this->assertEquals(1, $result[1]['article']->id); $this->assertEquals('Cool things.', $result[1]['article']->topic); $this->assertArrayHasKey('user', $result[2]); $this->assertArrayNotHasKey('article', $result[2]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[2]['user']); + $this->assertInstanceOf(CmsUser::class, $result[2]['user']); $this->assertEquals(2, $result[2]['user']->id); $this->assertEquals('jwage', $result[2]['user']->name); $this->assertArrayHasKey('article', $result[3]); $this->assertArrayNotHasKey('user', $result[3]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[3]['article']); + $this->assertInstanceOf(CmsArticle::class, $result[3]['article']); $this->assertEquals(2, $result[3]['article']->id); $this->assertEquals('Cool things II.', $result[3]['article']->topic); } @@ -367,7 +381,7 @@ public function testSimpleMultipleRootEntityQueryWithAliasedEntities() public function testMixedQueryNormalJoin($userEntityKey) { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); + $rsm->addEntityResult(CmsUser::class, 'u', $userEntityKey ?: null); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); $rsm->addScalarResult('sclr0', 'numPhones', 'integer'); @@ -399,11 +413,11 @@ public function testMixedQueryNormalJoin($userEntityKey) // first user => 2 phonenumbers $this->assertEquals(2, $result[0]['numPhones']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0][$userEntityKey]); + $this->assertInstanceOf(CmsUser::class, $result[0][$userEntityKey]); // second user => 1 phonenumber $this->assertEquals(1, $result[1]['numPhones']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[1][$userEntityKey]); + $this->assertInstanceOf(CmsUser::class, $result[1][$userEntityKey]); } /** @@ -416,9 +430,9 @@ public function testMixedQueryNormalJoin($userEntityKey) public function testMixedQueryFetchJoin($userEntityKey) { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); + $rsm->addEntityResult(CmsUser::class, 'u', $userEntityKey ?: null); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsPhonenumber', + CmsPhonenumber::class, 'p', 'u', 'phonenumbers' @@ -461,13 +475,13 @@ public function testMixedQueryFetchJoin($userEntityKey) $this->assertInternalType('array', $result[0]); $this->assertInternalType('array', $result[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0][$userEntityKey]); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[0][$userEntityKey]->phonenumbers); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsPhonenumber', $result[0][$userEntityKey]->phonenumbers[0]); + $this->assertInstanceOf(CmsUser::class, $result[0][$userEntityKey]); + $this->assertInstanceOf(PersistentCollection::class, $result[0][$userEntityKey]->phonenumbers); + $this->assertInstanceOf(CmsPhonenumber::class, $result[0][$userEntityKey]->phonenumbers[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[1][$userEntityKey]); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[1][$userEntityKey]->phonenumbers); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsPhonenumber', $result[0][$userEntityKey]->phonenumbers[1]); + $this->assertInstanceOf(CmsUser::class, $result[1][$userEntityKey]); + $this->assertInstanceOf(PersistentCollection::class, $result[1][$userEntityKey]->phonenumbers); + $this->assertInstanceOf(CmsPhonenumber::class, $result[0][$userEntityKey]->phonenumbers[1]); // first user => 2 phonenumbers $this->assertEquals(2, count($result[0][$userEntityKey]->phonenumbers)); @@ -494,9 +508,9 @@ public function testMixedQueryFetchJoin($userEntityKey) public function testMixedQueryFetchJoinCustomIndex($userEntityKey) { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); + $rsm->addEntityResult(CmsUser::class, 'u', $userEntityKey ?: null); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsPhonenumber', + CmsPhonenumber::class, 'p', 'u', 'phonenumbers' @@ -546,9 +560,9 @@ public function testMixedQueryFetchJoinCustomIndex($userEntityKey) $this->assertEquals('ROMANB', $result[1]['nameUpper']); $this->assertEquals('JWAGE', $result[2]['nameUpper']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[1][$userEntityKey]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[2][$userEntityKey]); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[1][$userEntityKey]->phonenumbers); + $this->assertInstanceOf(CmsUser::class, $result[1][$userEntityKey]); + $this->assertInstanceOf(CmsUser::class, $result[2][$userEntityKey]); + $this->assertInstanceOf(PersistentCollection::class, $result[1][$userEntityKey]->phonenumbers); // first user => 2 phonenumbers. notice the custom indexing by user id $this->assertEquals(2, count($result[1][$userEntityKey]->phonenumbers)); @@ -573,15 +587,15 @@ public function testMixedQueryFetchJoinCustomIndex($userEntityKey) public function testMixedQueryMultipleFetchJoin($userEntityKey) { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); + $rsm->addEntityResult(CmsUser::class, 'u', $userEntityKey ?: null); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsPhonenumber', + CmsPhonenumber::class, 'p', 'u', 'phonenumbers' ); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsArticle', + CmsArticle::class, 'a', 'u', 'articles' @@ -656,19 +670,19 @@ public function testMixedQueryMultipleFetchJoin($userEntityKey) $this->assertTrue(is_array($result[0])); $this->assertTrue(is_array($result[1])); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0][$userEntityKey]); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[0][$userEntityKey]->phonenumbers); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsPhonenumber', $result[0][$userEntityKey]->phonenumbers[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsPhonenumber', $result[0][$userEntityKey]->phonenumbers[1]); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[0][$userEntityKey]->articles); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[0][$userEntityKey]->articles[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[0][$userEntityKey]->articles[1]); - - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[1][$userEntityKey]); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[1][$userEntityKey]->phonenumbers); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsPhonenumber', $result[1][$userEntityKey]->phonenumbers[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[1][$userEntityKey]->articles[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[1][$userEntityKey]->articles[1]); + $this->assertInstanceOf(CmsUser::class, $result[0][$userEntityKey]); + $this->assertInstanceOf(PersistentCollection::class, $result[0][$userEntityKey]->phonenumbers); + $this->assertInstanceOf(CmsPhonenumber::class, $result[0][$userEntityKey]->phonenumbers[0]); + $this->assertInstanceOf(CmsPhonenumber::class, $result[0][$userEntityKey]->phonenumbers[1]); + $this->assertInstanceOf(PersistentCollection::class, $result[0][$userEntityKey]->articles); + $this->assertInstanceOf(CmsArticle::class, $result[0][$userEntityKey]->articles[0]); + $this->assertInstanceOf(CmsArticle::class, $result[0][$userEntityKey]->articles[1]); + + $this->assertInstanceOf(CmsUser::class, $result[1][$userEntityKey]); + $this->assertInstanceOf(PersistentCollection::class, $result[1][$userEntityKey]->phonenumbers); + $this->assertInstanceOf(CmsPhonenumber::class, $result[1][$userEntityKey]->phonenumbers[0]); + $this->assertInstanceOf(CmsArticle::class, $result[1][$userEntityKey]->articles[0]); + $this->assertInstanceOf(CmsArticle::class, $result[1][$userEntityKey]->articles[1]); } /** @@ -683,21 +697,21 @@ public function testMixedQueryMultipleFetchJoin($userEntityKey) public function testMixedQueryMultipleDeepMixedFetchJoin($userEntityKey) { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); + $rsm->addEntityResult(CmsUser::class, 'u', $userEntityKey ?: null); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsPhonenumber', + CmsPhonenumber::class, 'p', 'u', 'phonenumbers' ); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsArticle', + CmsArticle::class, 'a', 'u', 'articles' ); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsComment', + CmsComment::class, 'c', 'a', 'comments' @@ -786,36 +800,36 @@ public function testMixedQueryMultipleDeepMixedFetchJoin($userEntityKey) $this->assertTrue(is_array($result[0])); $this->assertTrue(is_array($result[1])); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0][$userEntityKey]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[1][$userEntityKey]); + $this->assertInstanceOf(CmsUser::class, $result[0][$userEntityKey]); + $this->assertInstanceOf(CmsUser::class, $result[1][$userEntityKey]); // phonenumbers - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[0][$userEntityKey]->phonenumbers); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsPhonenumber', $result[0][$userEntityKey]->phonenumbers[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsPhonenumber', $result[0][$userEntityKey]->phonenumbers[1]); + $this->assertInstanceOf(PersistentCollection::class, $result[0][$userEntityKey]->phonenumbers); + $this->assertInstanceOf(CmsPhonenumber::class, $result[0][$userEntityKey]->phonenumbers[0]); + $this->assertInstanceOf(CmsPhonenumber::class, $result[0][$userEntityKey]->phonenumbers[1]); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[1][$userEntityKey]->phonenumbers); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsPhonenumber', $result[1][$userEntityKey]->phonenumbers[0]); + $this->assertInstanceOf(PersistentCollection::class, $result[1][$userEntityKey]->phonenumbers); + $this->assertInstanceOf(CmsPhonenumber::class, $result[1][$userEntityKey]->phonenumbers[0]); // articles - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[0][$userEntityKey]->articles); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[0][$userEntityKey]->articles[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[0][$userEntityKey]->articles[1]); + $this->assertInstanceOf(PersistentCollection::class, $result[0][$userEntityKey]->articles); + $this->assertInstanceOf(CmsArticle::class, $result[0][$userEntityKey]->articles[0]); + $this->assertInstanceOf(CmsArticle::class, $result[0][$userEntityKey]->articles[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[1][$userEntityKey]->articles[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[1][$userEntityKey]->articles[1]); + $this->assertInstanceOf(CmsArticle::class, $result[1][$userEntityKey]->articles[0]); + $this->assertInstanceOf(CmsArticle::class, $result[1][$userEntityKey]->articles[1]); // article comments - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[0][$userEntityKey]->articles[0]->comments); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsComment', $result[0][$userEntityKey]->articles[0]->comments[0]); + $this->assertInstanceOf(PersistentCollection::class, $result[0][$userEntityKey]->articles[0]->comments); + $this->assertInstanceOf(CmsComment::class, $result[0][$userEntityKey]->articles[0]->comments[0]); // empty comment collections - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[0][$userEntityKey]->articles[1]->comments); + $this->assertInstanceOf(PersistentCollection::class, $result[0][$userEntityKey]->articles[1]->comments); $this->assertEquals(0, count($result[0][$userEntityKey]->articles[1]->comments)); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[1][$userEntityKey]->articles[0]->comments); + $this->assertInstanceOf(PersistentCollection::class, $result[1][$userEntityKey]->articles[0]->comments); $this->assertEquals(0, count($result[1][$userEntityKey]->articles[0]->comments)); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[1][$userEntityKey]->articles[1]->comments); + $this->assertInstanceOf(PersistentCollection::class, $result[1][$userEntityKey]->articles[1]->comments); $this->assertEquals(0, count($result[1][$userEntityKey]->articles[1]->comments)); } @@ -840,9 +854,9 @@ public function testMixedQueryMultipleDeepMixedFetchJoin($userEntityKey) public function testEntityQueryCustomResultSetOrder() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\Forum\ForumCategory', 'c'); + $rsm->addEntityResult(ForumCategory::class, 'c'); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\Forum\ForumBoard', + ForumBoard::class, 'b', 'c', 'boards' @@ -895,8 +909,8 @@ public function testEntityQueryCustomResultSetOrder() $this->assertEquals(2, count($result)); - $this->assertInstanceOf('Doctrine\Tests\Models\Forum\ForumCategory', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\Forum\ForumCategory', $result[1]); + $this->assertInstanceOf(ForumCategory::class, $result[0]); + $this->assertInstanceOf(ForumCategory::class, $result[1]); $this->assertTrue($result[0] !== $result[1]); @@ -919,7 +933,7 @@ public function testEntityQueryCustomResultSetOrder() public function testSkipUnknownColumns() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addEntityResult(CmsUser::class, 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); @@ -937,7 +951,7 @@ public function testSkipUnknownColumns() $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); $this->assertEquals(1, count($result)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0]); + $this->assertInstanceOf(CmsUser::class, $result[0]); } /** @@ -949,7 +963,7 @@ public function testSkipUnknownColumns() public function testScalarQueryWithoutResultVariables($userEntityKey) { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); + $rsm->addEntityResult(CmsUser::class, 'u', $userEntityKey ?: null); $rsm->addScalarResult('sclr0', 'id', 'integer'); $rsm->addScalarResult('sclr1', 'name', 'string'); @@ -988,7 +1002,7 @@ public function testScalarQueryWithoutResultVariables($userEntityKey) public function testCreatesProxyForLazyLoadingWithForeignKeys() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\ECommerce\ECommerceProduct', 'p'); + $rsm->addEntityResult(ECommerceProduct::class, 'p'); $rsm->addFieldResult('p', 'p__id', 'id'); $rsm->addFieldResult('p', 'p__name', 'name'); $rsm->addMetaResult('p', 'p__shipping_id', 'shipping_id', false, 'integer'); @@ -1012,13 +1026,13 @@ public function testCreatesProxyForLazyLoadingWithForeignKeys() $proxyFactory->expects($this->once()) ->method('getProxy') - ->with($this->equalTo('Doctrine\Tests\Models\ECommerce\ECommerceShipping'), ['id' => 42]) + ->with($this->equalTo(ECommerceShipping::class), ['id' => 42]) ->will($this->returnValue($proxyInstance)); $this->_em->setProxyFactory($proxyFactory); // configuring lazy loading - $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceProduct'); + $metadata = $this->_em->getClassMetadata(ECommerceProduct::class); $metadata->associationMappings['shipping']['fetch'] = ClassMetadata::FETCH_LAZY; $stmt = new HydratorMockStatement($resultSet); @@ -1027,7 +1041,7 @@ public function testCreatesProxyForLazyLoadingWithForeignKeys() $this->assertEquals(1, count($result)); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $result[0]); + $this->assertInstanceOf(ECommerceProduct::class, $result[0]); } /** @@ -1037,7 +1051,7 @@ public function testCreatesProxyForLazyLoadingWithForeignKeys() public function testCreatesProxyForLazyLoadingWithForeignKeysWithAliasedProductEntity() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\ECommerce\ECommerceProduct', 'p', 'product'); + $rsm->addEntityResult(ECommerceProduct::class, 'p', 'product'); $rsm->addFieldResult('p', 'p__id', 'id'); $rsm->addFieldResult('p', 'p__name', 'name'); $rsm->addMetaResult('p', 'p__shipping_id', 'shipping_id', false, 'integer'); @@ -1061,13 +1075,13 @@ public function testCreatesProxyForLazyLoadingWithForeignKeysWithAliasedProductE $proxyFactory->expects($this->once()) ->method('getProxy') - ->with($this->equalTo('Doctrine\Tests\Models\ECommerce\ECommerceShipping'), ['id' => 42]) + ->with($this->equalTo(ECommerceShipping::class), ['id' => 42]) ->will($this->returnValue($proxyInstance)); $this->_em->setProxyFactory($proxyFactory); // configuring lazy loading - $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceProduct'); + $metadata = $this->_em->getClassMetadata(ECommerceProduct::class); $metadata->associationMappings['shipping']['fetch'] = ClassMetadata::FETCH_LAZY; $stmt = new HydratorMockStatement($resultSet); @@ -1077,7 +1091,7 @@ public function testCreatesProxyForLazyLoadingWithForeignKeysWithAliasedProductE $this->assertEquals(1, count($result)); $this->assertInternalType('array', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $result[0]['product']); + $this->assertInstanceOf(ECommerceProduct::class, $result[0]['product']); } /** @@ -1089,15 +1103,15 @@ public function testCreatesProxyForLazyLoadingWithForeignKeysWithAliasedProductE public function testChainedJoinWithEmptyCollections() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addEntityResult(CmsUser::class, 'u'); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsArticle', + CmsArticle::class, 'a', 'u', 'articles' ); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsComment', + CmsComment::class, 'c', 'a', 'comments' @@ -1136,8 +1150,8 @@ public function testChainedJoinWithEmptyCollections() $this->assertEquals(2, count($result)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[1]); + $this->assertInstanceOf(CmsUser::class, $result[0]); + $this->assertInstanceOf(CmsUser::class, $result[1]); $this->assertEquals(0, $result[0]->articles->count()); $this->assertEquals(0, $result[1]->articles->count()); @@ -1152,15 +1166,15 @@ public function testChainedJoinWithEmptyCollections() public function testChainedJoinWithEmptyCollectionsWithAliasedUserEntity() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', 'user'); + $rsm->addEntityResult(CmsUser::class, 'u', 'user'); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsArticle', + CmsArticle::class, 'a', 'u', 'articles' ); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsComment', + CmsComment::class, 'c', 'a', 'comments' @@ -1200,10 +1214,10 @@ public function testChainedJoinWithEmptyCollectionsWithAliasedUserEntity() $this->assertEquals(2, count($result)); $this->assertInternalType('array', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0]['user']); + $this->assertInstanceOf(CmsUser::class, $result[0]['user']); $this->assertInternalType('array', $result[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[1]['user']); + $this->assertInstanceOf(CmsUser::class, $result[1]['user']); $this->assertEquals(0, $result[0]['user']->articles->count()); $this->assertEquals(0, $result[1]['user']->articles->count()); @@ -1280,7 +1294,7 @@ public function testChainedJoinWithEmptyCollectionsWithAliasedUserEntity() public function testResultIteration() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addEntityResult(CmsUser::class, 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); @@ -1303,7 +1317,7 @@ public function testResultIteration() while (($row = $iterableResult->next()) !== false) { $this->assertEquals(1, count($row)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $row[0]); + $this->assertInstanceOf(CmsUser::class, $row[0]); if ($rowNum == 0) { $this->assertEquals(1, $row[0]->id); @@ -1324,7 +1338,7 @@ public function testResultIteration() public function testResultIterationWithAliasedUserEntity() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', 'user'); + $rsm->addEntityResult(CmsUser::class, 'u', 'user'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); @@ -1349,7 +1363,7 @@ public function testResultIterationWithAliasedUserEntity() $this->assertEquals(1, count($row)); $this->assertArrayHasKey(0, $row); $this->assertArrayHasKey('user', $row[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $row[0]['user']); + $this->assertInstanceOf(CmsUser::class, $row[0]['user']); if ($rowNum == 0) { $this->assertEquals(1, $row[0]['user']->id); @@ -1374,13 +1388,13 @@ public function testResultIterationWithAliasedUserEntity() public function testManyToManyHydration() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addEntityResult(CmsUser::class, 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); - $rsm->addJoinedEntityResult('Doctrine\Tests\Models\CMS\CmsGroup', 'g', 'u', 'groups'); + $rsm->addJoinedEntityResult(CmsGroup::class, 'g', 'u', 'groups'); $rsm->addFieldResult('g', 'g__id', 'id'); $rsm->addFieldResult('g', 'g__name', 'name'); - $rsm->addJoinedEntityResult('Doctrine\Tests\Models\CMS\CmsPhonenumber', 'p', 'u', 'phonenumbers'); + $rsm->addJoinedEntityResult(CmsPhonenumber::class, 'p', 'u', 'phonenumbers'); $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); // Faked result set @@ -1477,7 +1491,7 @@ public function testManyToManyHydration() $this->assertEquals(2, count($result)); - $this->assertContainsOnly('Doctrine\Tests\Models\CMS\CmsUser', $result); + $this->assertContainsOnly(CmsUser::class, $result); $this->assertEquals(2, count($result[0]->groups)); $this->assertEquals(2, count($result[0]->phonenumbers)); @@ -1497,13 +1511,13 @@ public function testManyToManyHydration() public function testManyToManyHydrationWithAliasedUserEntity() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', 'user'); + $rsm->addEntityResult(CmsUser::class, 'u', 'user'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); - $rsm->addJoinedEntityResult('Doctrine\Tests\Models\CMS\CmsGroup', 'g', 'u', 'groups'); + $rsm->addJoinedEntityResult(CmsGroup::class, 'g', 'u', 'groups'); $rsm->addFieldResult('g', 'g__id', 'id'); $rsm->addFieldResult('g', 'g__name', 'name'); - $rsm->addJoinedEntityResult('Doctrine\Tests\Models\CMS\CmsPhonenumber', 'p', 'u', 'phonenumbers'); + $rsm->addJoinedEntityResult(CmsPhonenumber::class, 'p', 'u', 'phonenumbers'); $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); // Faked result set @@ -1601,9 +1615,9 @@ public function testManyToManyHydrationWithAliasedUserEntity() $this->assertEquals(2, count($result)); $this->assertInternalType('array', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0]['user']); + $this->assertInstanceOf(CmsUser::class, $result[0]['user']); $this->assertInternalType('array', $result[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[1]['user']); + $this->assertInstanceOf(CmsUser::class, $result[1]['user']); $this->assertEquals(2, count($result[0]['user']->groups)); $this->assertEquals(2, count($result[0]['user']->phonenumbers)); @@ -1622,7 +1636,7 @@ public function testManyToManyHydrationWithAliasedUserEntity() public function testMissingIdForRootEntity($userEntityKey) { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); + $rsm->addEntityResult(CmsUser::class, 'u', $userEntityKey ?: null); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); @@ -1663,10 +1677,10 @@ public function testMissingIdForRootEntity($userEntityKey) $this->assertEquals('JWAGE', $result[2]['nameUpper']); $this->assertEquals('JWAGE', $result[3]['nameUpper']); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0][$userEntityKey]); + $this->assertInstanceOf(CmsUser::class, $result[0][$userEntityKey]); $this->assertNull($result[1][$userEntityKey]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[2][$userEntityKey]); + $this->assertInstanceOf(CmsUser::class, $result[2][$userEntityKey]); $this->assertNull($result[3][$userEntityKey]); } @@ -1681,9 +1695,9 @@ public function testMissingIdForRootEntity($userEntityKey) public function testMissingIdForCollectionValuedChildEntity($userEntityKey) { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); + $rsm->addEntityResult(CmsUser::class, 'u', $userEntityKey ?: null); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsPhonenumber', + CmsPhonenumber::class, 'p', 'u', 'phonenumbers' @@ -1743,9 +1757,9 @@ public function testMissingIdForCollectionValuedChildEntity($userEntityKey) public function testMissingIdForSingleValuedChildEntity($userEntityKey) { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); + $rsm->addEntityResult(CmsUser::class, 'u', $userEntityKey ?: null); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsAddress', + CmsAddress::class, 'a', 'u', 'address' @@ -1782,7 +1796,7 @@ public function testMissingIdForSingleValuedChildEntity($userEntityKey) $this->assertEquals(2, count($result)); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress', $result[0][$userEntityKey]->address); + $this->assertInstanceOf(CmsAddress::class, $result[0][$userEntityKey]->address); $this->assertNull($result[1][$userEntityKey]->address); } @@ -1797,7 +1811,7 @@ public function testMissingIdForSingleValuedChildEntity($userEntityKey) public function testIndexByAndMixedResult($userEntityKey) { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); + $rsm->addEntityResult(CmsUser::class, 'u', $userEntityKey ?: null); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); @@ -1841,7 +1855,7 @@ public function testIndexByAndMixedResult($userEntityKey) public function testIndexByScalarsOnly($userEntityKey) { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); + $rsm->addEntityResult(CmsUser::class, 'u', $userEntityKey ?: null); $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); $rsm->addIndexByScalar('sclr0'); @@ -1880,8 +1894,8 @@ public function testMissingMetaMappingException() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\Company\CompanyFixContract', 'c'); - $rsm->addJoinedEntityResult('Doctrine\Tests\Models\Company\CompanyEmployee', 'e', 'c', 'salesPerson'); + $rsm->addEntityResult(CompanyFixContract::class, 'c'); + $rsm->addJoinedEntityResult(CompanyEmployee::class, 'e', 'c', 'salesPerson'); $rsm->addFieldResult('c', 'c__id', 'id'); $rsm->setDiscriminatorColumn('c', 'c_discr'); @@ -1907,8 +1921,8 @@ public function testMissingDiscriminatorColumnException() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\Company\CompanyFixContract', 'c'); - $rsm->addJoinedEntityResult('Doctrine\Tests\Models\Company\CompanyEmployee', 'e', 'c', 'salesPerson'); + $rsm->addEntityResult(CompanyFixContract::class, 'c'); + $rsm->addJoinedEntityResult(CompanyEmployee::class, 'e', 'c', 'salesPerson'); $rsm->addFieldResult('c', 'c__id', 'id'); $rsm->addMetaResult('c', 'c_discr', 'discr', false, 'string'); $rsm->setDiscriminatorColumn('c', 'c_discr'); @@ -1941,7 +1955,7 @@ public function testInvalidDiscriminatorValueException() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\Company\CompanyPerson', 'p'); + $rsm->addEntityResult(CompanyPerson::class, 'p'); $rsm->addFieldResult('p', 'p__id', 'id'); $rsm->addFieldResult('p', 'p__name', 'name'); $rsm->addMetaResult('p', 'discr', 'discr', false, 'string'); @@ -1964,8 +1978,8 @@ public function testFetchJoinCollectionValuedAssociationWithDefaultArrayValue() { $rsm = new ResultSetMapping; - $rsm->addEntityResult(EntityWithArrayDefaultArrayValueM2M::CLASSNAME, 'e1', null); - $rsm->addJoinedEntityResult(SimpleEntity::CLASSNAME, 'e2', 'e1', 'collection'); + $rsm->addEntityResult(EntityWithArrayDefaultArrayValueM2M::class, 'e1', null); + $rsm->addJoinedEntityResult(SimpleEntity::class, 'e2', 'e1', 'collection'); $rsm->addFieldResult('e1', 'a1__id', 'id'); $rsm->addFieldResult('e2', 'e2__id', 'id'); @@ -1981,9 +1995,9 @@ public function testFetchJoinCollectionValuedAssociationWithDefaultArrayValue() $result = $hydrator->hydrateAll($stmt, $rsm); $this->assertCount(1, $result); - $this->assertInstanceOf(EntityWithArrayDefaultArrayValueM2M::CLASSNAME, $result[0]); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[0]->collection); + $this->assertInstanceOf(EntityWithArrayDefaultArrayValueM2M::class, $result[0]); + $this->assertInstanceOf(PersistentCollection::class, $result[0]->collection); $this->assertCount(1, $result[0]->collection); - $this->assertInstanceOf(SimpleEntity::CLASSNAME, $result[0]->collection[0]); + $this->assertInstanceOf(SimpleEntity::class, $result[0]->collection[0]); } } diff --git a/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php b/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php index 745f30ec098..30352b365a3 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php @@ -2,8 +2,13 @@ namespace Doctrine\Tests\ORM\Hydration; -use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Query\ResultSetMapping; +use Doctrine\Tests\Models\CMS\CmsEmail; +use Doctrine\Tests\Models\CMS\CmsPhonenumber; +use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\Models\Legacy\LegacyUser; +use Doctrine\Tests\Models\Legacy\LegacyUserReference; /** * Description of ResultSetMappingTest @@ -34,7 +39,7 @@ protected function setUp() { public function testBasicResultSetMapping() { $this->_rsm->addEntityResult( - 'Doctrine\Tests\Models\CMS\CmsUser', + CmsUser::class, 'u' ); $this->_rsm->addFieldResult('u', 'id', 'id'); @@ -47,9 +52,9 @@ public function testBasicResultSetMapping() $this->assertFalse($this->_rsm->isScalarResult('username')); $this->assertFalse($this->_rsm->isScalarResult('name')); - $this->assertTrue($this->_rsm->getClassName('u') == 'Doctrine\Tests\Models\CMS\CmsUser'); + $this->assertTrue($this->_rsm->getClassName('u') == CmsUser::class); $class = $this->_rsm->getDeclaringClass('id'); - $this->assertTrue($class == 'Doctrine\Tests\Models\CMS\CmsUser'); + $this->assertTrue($class == CmsUser::class); $this->assertEquals('u', $this->_rsm->getEntityAlias('id')); $this->assertEquals('u', $this->_rsm->getEntityAlias('status')); @@ -71,8 +76,8 @@ public function testFluentInterface() { $rms = $this->_rsm; - $this->_rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser','u'); - $this->_rsm->addJoinedEntityResult('Doctrine\Tests\Models\CMS\CmsPhonenumber','p','u','phonenumbers'); + $this->_rsm->addEntityResult(CmsUser::class,'u'); + $this->_rsm->addJoinedEntityResult(CmsPhonenumber::class,'p','u','phonenumbers'); $this->_rsm->addFieldResult('u', 'id', 'id'); $this->_rsm->addFieldResult('u', 'name', 'name'); $this->_rsm->setDiscriminatorColumn('name', 'name'); @@ -96,13 +101,13 @@ public function testFluentInterface() */ public function testAddNamedNativeQueryResultSetMapping() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CmsUser::class); $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); $cm->mapOneToOne( [ 'fieldName' => 'email', - 'targetEntity' => 'Doctrine\Tests\Models\CMS\CmsEmail', + 'targetEntity' => CmsEmail::class, 'cascade' => ['persist'], 'inversedBy' => 'user', 'orphanRemoval' => false, @@ -171,16 +176,16 @@ public function testAddNamedNativeQueryResultSetMapping() $this->assertEquals('c0', $rsm->getEntityAlias('user_id')); $this->assertEquals('c0', $rsm->getEntityAlias('name')); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $rsm->getClassName('c0')); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $rsm->getDeclaringClass('name')); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $rsm->getDeclaringClass('user_id')); + $this->assertEquals(CmsUser::class, $rsm->getClassName('c0')); + $this->assertEquals(CmsUser::class, $rsm->getDeclaringClass('name')); + $this->assertEquals(CmsUser::class, $rsm->getDeclaringClass('user_id')); $this->assertEquals('c1', $rsm->getEntityAlias('email_id')); $this->assertEquals('c1', $rsm->getEntityAlias('email')); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsEmail', $rsm->getClassName('c1')); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsEmail', $rsm->getDeclaringClass('email')); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsEmail', $rsm->getDeclaringClass('email_id')); + $this->assertEquals(CmsEmail::class, $rsm->getClassName('c1')); + $this->assertEquals(CmsEmail::class, $rsm->getDeclaringClass('email')); + $this->assertEquals(CmsEmail::class, $rsm->getDeclaringClass('email_id')); } /** @@ -188,7 +193,7 @@ public function testAddNamedNativeQueryResultSetMapping() */ public function testAddNamedNativeQueryResultSetMappingWithoutFields() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CmsUser::class); $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); $cm->addNamedNativeQuery( @@ -225,11 +230,11 @@ public function testAddNamedNativeQueryResultSetMappingWithoutFields() $this->assertEquals('c0', $rsm->getEntityAlias('name')); $this->assertEquals('c0', $rsm->getEntityAlias('status')); $this->assertEquals('c0', $rsm->getEntityAlias('username')); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $rsm->getClassName('c0')); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $rsm->getDeclaringClass('id')); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $rsm->getDeclaringClass('name')); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $rsm->getDeclaringClass('status')); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $rsm->getDeclaringClass('username')); + $this->assertEquals(CmsUser::class, $rsm->getClassName('c0')); + $this->assertEquals(CmsUser::class, $rsm->getDeclaringClass('id')); + $this->assertEquals(CmsUser::class, $rsm->getDeclaringClass('name')); + $this->assertEquals(CmsUser::class, $rsm->getDeclaringClass('status')); + $this->assertEquals(CmsUser::class, $rsm->getDeclaringClass('username')); } /** @@ -237,7 +242,7 @@ public function testAddNamedNativeQueryResultSetMappingWithoutFields() */ public function testAddNamedNativeQueryResultClass() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CmsUser::class); $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); @@ -258,19 +263,19 @@ public function testAddNamedNativeQueryResultClass() $this->assertEquals('c0', $rsm->getEntityAlias('name')); $this->assertEquals('c0', $rsm->getEntityAlias('status')); $this->assertEquals('c0', $rsm->getEntityAlias('username')); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $rsm->getClassName('c0')); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $rsm->getDeclaringClass('id')); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $rsm->getDeclaringClass('name')); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $rsm->getDeclaringClass('status')); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $rsm->getDeclaringClass('username')); + $this->assertEquals(CmsUser::class, $rsm->getClassName('c0')); + $this->assertEquals(CmsUser::class, $rsm->getDeclaringClass('id')); + $this->assertEquals(CmsUser::class, $rsm->getDeclaringClass('name')); + $this->assertEquals(CmsUser::class, $rsm->getDeclaringClass('status')); + $this->assertEquals(CmsUser::class, $rsm->getDeclaringClass('username')); } /** * @group DDC-117 */ public function testIndexByMetadataColumn() { - $this->_rsm->addEntityResult('Doctrine\Tests\Models\Legacy\LegacyUser', 'u'); - $this->_rsm->addJoinedEntityResult('Doctrine\Tests\Models\LegacyUserReference', 'lu', 'u', '_references'); + $this->_rsm->addEntityResult(LegacyUser::class, 'u'); + $this->_rsm->addJoinedEntityResult(LegacyUserReference::class, 'lu', 'u', '_references'); $this->_rsm->addMetaResult('lu', '_source', '_source', true, 'integer'); $this->_rsm->addMetaResult('lu', '_target', '_target', true, 'integer'); $this->_rsm->addIndexBy('lu', '_source'); diff --git a/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php index 6cce68811c7..2ad9461ff04 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php @@ -4,6 +4,7 @@ use Doctrine\Tests\Mocks\HydratorMockStatement; use Doctrine\ORM\Query\ResultSetMapping; +use Doctrine\Tests\Models\CMS\CmsUser; class ScalarHydratorTest extends HydrationTestCase { @@ -13,7 +14,7 @@ class ScalarHydratorTest extends HydrationTestCase public function testNewHydrationSimpleEntityQuery() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addEntityResult(CmsUser::class, 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); @@ -73,7 +74,7 @@ public function testHydrateScalarResults() public function testSkipUnknownColumns() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addEntityResult(CmsUser::class, 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); $rsm->addScalarResult('foo1', 'foo', 'string'); diff --git a/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php index d6eaeb10cf3..ffcd81e3571 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php @@ -2,8 +2,13 @@ namespace Doctrine\Tests\ORM\Hydration; -use Doctrine\Tests\Mocks\HydratorMockStatement; use Doctrine\ORM\Query\ResultSetMapping; +use Doctrine\Tests\Mocks\HydratorMockStatement; +use Doctrine\Tests\Models\CMS\CmsAddress; +use Doctrine\Tests\Models\Company\CompanyPerson; +use Doctrine\Tests\Models\Issue5989\Issue5989Employee; +use Doctrine\Tests\Models\Issue5989\Issue5989Manager; +use Doctrine\Tests\Models\Issue5989\Issue5989Person; class SimpleObjectHydratorTest extends HydrationTestCase { @@ -16,7 +21,7 @@ class SimpleObjectHydratorTest extends HydrationTestCase public function testMissingDiscriminatorColumnException() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\Company\CompanyPerson', 'p'); + $rsm->addEntityResult(CompanyPerson::class, 'p'); $rsm->addFieldResult('p', 'p__id', 'id'); $rsm->addFieldResult('p', 'p__name', 'name'); $rsm->addMetaResult('p ', 'discr', 'discr', false, 'string'); @@ -36,7 +41,7 @@ public function testMissingDiscriminatorColumnException() public function testExtraFieldInResultSetShouldBeIgnore() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsAddress', 'a'); + $rsm->addEntityResult(CmsAddress::class, 'a'); $rsm->addFieldResult('a', 'a__id', 'id'); $rsm->addFieldResult('a', 'a__city', 'city'); $resultSet = [ @@ -67,7 +72,7 @@ public function testInvalidDiscriminatorValueException() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\Company\CompanyPerson', 'p'); + $rsm->addEntityResult(CompanyPerson::class, 'p'); $rsm->addFieldResult('p', 'p__id', 'id'); $rsm->addFieldResult('p', 'p__name', 'name'); @@ -93,10 +98,10 @@ public function testInvalidDiscriminatorValueException() public function testNullValueShouldNotOverwriteFieldWithSameNameInJoinedInheritance() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\Issue5989\Issue5989Person', 'p'); + $rsm->addEntityResult(Issue5989Person::class, 'p'); $rsm->addFieldResult('p', 'p__id', 'id'); - $rsm->addFieldResult('p', 'm__tags', 'tags', 'Doctrine\Tests\Models\Issue5989\Issue5989Manager'); - $rsm->addFieldResult('p', 'e__tags', 'tags', 'Doctrine\Tests\Models\Issue5989\Issue5989Employee'); + $rsm->addFieldResult('p', 'm__tags', 'tags', Issue5989Manager::class); + $rsm->addFieldResult('p', 'e__tags', 'tags', Issue5989Employee::class); $rsm->addMetaResult('p', 'discr', 'discr', false, 'string'); $resultSet = [ [ @@ -107,7 +112,7 @@ public function testNullValueShouldNotOverwriteFieldWithSameNameInJoinedInherita ], ]; - $expectedEntity = new \Doctrine\Tests\Models\Issue5989\Issue5989Manager(); + $expectedEntity = new Issue5989Manager(); $expectedEntity->id = 1; $expectedEntity->tags = ['tag1', 'tag2']; diff --git a/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php index fa98dd0703c..d0cebbc494f 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php @@ -4,6 +4,7 @@ use Doctrine\Tests\Mocks\HydratorMockStatement; use Doctrine\ORM\Query\ResultSetMapping; +use Doctrine\Tests\Models\CMS\CmsUser; class SingleScalarHydratorTest extends HydrationTestCase { @@ -61,7 +62,7 @@ public static function singleScalarResultSetProvider() { public function testHydrateSingleScalar($name, $resultSet) { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addEntityResult(CmsUser::class, 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); diff --git a/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php b/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php index 1f667b4640d..3015341d951 100644 --- a/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM; +use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\LazyCriteriaCollection; use Doctrine\ORM\Persisters\Entity\EntityPersister; @@ -97,7 +98,7 @@ public function testMatchingUsesThePersisterOnlyOnce() $filtered = $this->lazyCriteriaCollection->matching($criteria); - $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $filtered); + $this->assertInstanceOf(Collection::class, $filtered); $this->assertEquals([$foo], $filtered->toArray()); $this->assertEquals([$foo], $this->lazyCriteriaCollection->matching($criteria)->toArray()); diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 4e9546daa98..4e19c987c16 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -5,16 +5,36 @@ use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Events; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataFactory; +use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\ORM\Mapping\DefaultNamingStrategy; use Doctrine\ORM\Mapping\DiscriminatorColumn; use Doctrine\ORM\Mapping\Id; use Doctrine\ORM\Mapping\MappingException; use Doctrine\ORM\Mapping\UnderscoreNamingStrategy; use Doctrine\Tests\Models\Cache\City; -use Doctrine\ORM\Mapping\ClassMetadata; -use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\Tests\Models\CMS\CmsAddress; +use Doctrine\Tests\Models\CMS\CmsAddressListener; +use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\Models\Company\CompanyContract; +use Doctrine\Tests\Models\Company\CompanyContractListener; +use Doctrine\Tests\Models\Company\CompanyFixContract; +use Doctrine\Tests\Models\Company\CompanyFlexContract; +use Doctrine\Tests\Models\Company\CompanyFlexUltraContract; +use Doctrine\Tests\Models\Company\CompanyFlexUltraContractListener; +use Doctrine\Tests\Models\Company\CompanyPerson; +use Doctrine\Tests\Models\DDC1476\DDC1476EntityWithDefaultFieldType; use Doctrine\Tests\Models\DDC2825\ExplicitSchemaAndTable; use Doctrine\Tests\Models\DDC2825\SchemaAndTableInTableName; +use Doctrine\Tests\Models\DDC3579\DDC3579Admin; +use Doctrine\Tests\Models\DDC869\DDC869ChequePayment; +use Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment; +use Doctrine\Tests\Models\DDC869\DDC869PaymentRepository; +use Doctrine\Tests\Models\DDC889\DDC889Class; +use Doctrine\Tests\Models\DDC889\DDC889Entity; +use Doctrine\Tests\Models\DDC964\DDC964Admin; +use Doctrine\Tests\Models\DDC964\DDC964Guest; use Doctrine\Tests\OrmTestCase; abstract class AbstractMappingDriverTest extends OrmTestCase @@ -49,8 +69,7 @@ protected function createClassMetadataFactory(EntityManager $em = null) public function testLoadMapping() { - $entityClassName = 'Doctrine\Tests\ORM\Mapping\User'; - return $this->createClassMetadata($entityClassName); + return $this->createClassMetadata(User::class); } /** @@ -83,7 +102,7 @@ public function testEntityIndexes($class) public function testEntityIndexFlagsAndPartialIndexes() { - $class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\Comment'); + $class = $this->createClassMetadata(Comment::class); $this->assertEquals( [ @@ -147,7 +166,7 @@ public function testEntitySequence($class) public function testEntityCustomGenerator() { - $class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\Animal'); + $class = $this->createClassMetadata(Animal::class); $this->assertEquals(ClassMetadata::GENERATOR_TYPE_CUSTOM, $class->generatorType, "Generator Type"); @@ -412,7 +431,7 @@ public function testDiscriminatorColumnDefaults() $this->markTestSkipped('PHP Mapping Drivers have no defaults.'); } - $class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\Animal'); + $class = $this->createClassMetadata(Animal::class); $this->assertEquals( ['name' => 'discr', 'type' => 'string', 'length' => '32', 'fieldName' => 'discr', 'columnDefinition' => null], @@ -429,27 +448,25 @@ public function testMappedSuperclassWithRepository() $factory = $this->createClassMetadataFactory($em); - $class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment'); + $class = $factory->getMetadataFor(DDC869CreditCardPayment::class); $this->assertTrue(isset($class->fieldMappings['id'])); $this->assertTrue(isset($class->fieldMappings['value'])); $this->assertTrue(isset($class->fieldMappings['creditCardNumber'])); - $this->assertEquals($class->customRepositoryClassName, "Doctrine\Tests\Models\DDC869\DDC869PaymentRepository"); - $this->assertInstanceOf("Doctrine\Tests\Models\DDC869\DDC869PaymentRepository", - $em->getRepository("Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment")); - $this->assertTrue($em->getRepository("Doctrine\Tests\Models\DDC869\DDC869ChequePayment")->isTrue()); + $this->assertEquals($class->customRepositoryClassName, DDC869PaymentRepository::class); + $this->assertInstanceOf(DDC869PaymentRepository::class, $em->getRepository(DDC869CreditCardPayment::class)); + $this->assertTrue($em->getRepository(DDC869ChequePayment::class)->isTrue()); - $class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869ChequePayment'); + $class = $factory->getMetadataFor(DDC869ChequePayment::class); $this->assertTrue(isset($class->fieldMappings['id'])); $this->assertTrue(isset($class->fieldMappings['value'])); $this->assertTrue(isset($class->fieldMappings['serialNumber'])); - $this->assertEquals($class->customRepositoryClassName, "Doctrine\Tests\Models\DDC869\DDC869PaymentRepository"); - $this->assertInstanceOf("Doctrine\Tests\Models\DDC869\DDC869PaymentRepository", - $em->getRepository("Doctrine\Tests\Models\DDC869\DDC869ChequePayment")); - $this->assertTrue($em->getRepository("Doctrine\Tests\Models\DDC869\DDC869ChequePayment")->isTrue()); + $this->assertEquals($class->customRepositoryClassName, DDC869PaymentRepository::class); + $this->assertInstanceOf(DDC869PaymentRepository::class, $em->getRepository(DDC869ChequePayment::class)); + $this->assertTrue($em->getRepository(DDC869ChequePayment::class)->isTrue()); } /** @@ -458,7 +475,7 @@ public function testMappedSuperclassWithRepository() public function testDefaultFieldType() { $factory = $this->createClassMetadataFactory(); - $class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC1476\DDC1476EntityWithDefaultFieldType'); + $class = $factory->getMetadataFor(DDC1476EntityWithDefaultFieldType::class); $this->assertArrayHasKey('id', $class->fieldMappings); @@ -495,7 +512,7 @@ public function testDefaultFieldType() */ public function testIdentifierColumnDefinition() { - $class = $this->createClassMetadata(__NAMESPACE__ . '\DDC1170Entity'); + $class = $this->createClassMetadata(DDC1170Entity::class); $this->assertArrayHasKey('id', $class->fieldMappings); @@ -517,11 +534,11 @@ public function testNamingStrategy() $factory = $this->createClassMetadataFactory($em); - $this->assertInstanceOf('Doctrine\ORM\Mapping\DefaultNamingStrategy', $em->getConfiguration()->getNamingStrategy()); + $this->assertInstanceOf(DefaultNamingStrategy::class, $em->getConfiguration()->getNamingStrategy()); $em->getConfiguration()->setNamingStrategy(new UnderscoreNamingStrategy(CASE_UPPER)); - $this->assertInstanceOf('Doctrine\ORM\Mapping\UnderscoreNamingStrategy', $em->getConfiguration()->getNamingStrategy()); + $this->assertInstanceOf(UnderscoreNamingStrategy::class, $em->getConfiguration()->getNamingStrategy()); - $class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC1476\DDC1476EntityWithDefaultFieldType'); + $class = $factory->getMetadataFor(DDC1476EntityWithDefaultFieldType::class); $this->assertEquals('ID', $class->getColumnName('id')); $this->assertEquals('NAME', $class->getColumnName('name')); @@ -534,7 +551,7 @@ public function testNamingStrategy() */ public function testDiscriminatorColumnDefinition() { - $class = $this->createClassMetadata(__NAMESPACE__ . '\DDC807Entity'); + $class = $this->createClassMetadata(DDC807Entity::class); $this->assertArrayHasKey('columnDefinition', $class->discriminatorColumn); $this->assertArrayHasKey('name', $class->discriminatorColumn); @@ -551,7 +568,7 @@ public function testInvalidEntityOrMappedSuperClassShouldMentionParentClasses() $this->expectException(MappingException::class); $this->expectExceptionMessage('Class "Doctrine\Tests\Models\DDC889\DDC889Class" sub class of "Doctrine\Tests\Models\DDC889\DDC889SuperClass" is not a valid entity or mapped super class.'); - $this->createClassMetadata('Doctrine\Tests\Models\DDC889\DDC889Class'); + $this->createClassMetadata(DDC889Class::class); } /** @@ -564,13 +581,13 @@ public function testIdentifierRequiredShouldMentionParentClasses() $this->expectException(MappingException::class); $this->expectExceptionMessage('No identifier/primary key specified for Entity "Doctrine\Tests\Models\DDC889\DDC889Entity" sub class of "Doctrine\Tests\Models\DDC889\DDC889SuperClass". Every Entity must have an identifier/primary key.'); - $factory->getMetadataFor('Doctrine\Tests\Models\DDC889\DDC889Entity'); + $factory->getMetadataFor(DDC889Entity::class); } public function testNamedQuery() { $driver = $this->_loadDriver(); - $class = $this->createClassMetadata(__NAMESPACE__.'\User'); + $class = $this->createClassMetadata(User::class); $this->assertCount(1, $class->getNamedQueries(), sprintf("Named queries not processed correctly by driver %s", get_class($driver))); } @@ -581,7 +598,7 @@ public function testNamedQuery() public function testNamedNativeQuery() { - $class = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); + $class = $this->createClassMetadata(CmsAddress::class); //named native query $this->assertCount(3, $class->namedNativeQueries); @@ -596,7 +613,7 @@ public function testNamedNativeQuery() $findByIdQuery = $class->getNamedNativeQuery('find-by-id'); $this->assertEquals('find-by-id', $findByIdQuery['name']); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress',$findByIdQuery['resultClass']); + $this->assertEquals(CmsAddress::class,$findByIdQuery['resultClass']); $this->assertEquals('SELECT * FROM cms_addresses WHERE id = ?', $findByIdQuery['query']); $countQuery = $class->getNamedNativeQuery('count'); @@ -612,14 +629,14 @@ public function testNamedNativeQuery() $findAllMapping = $class->getSqlResultSetMapping('mapping-find-all'); $this->assertEquals('mapping-find-all', $findAllMapping['name']); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress', $findAllMapping['entities'][0]['entityClass']); + $this->assertEquals(CmsAddress::class, $findAllMapping['entities'][0]['entityClass']); $this->assertEquals(['name'=>'id','column'=>'id'], $findAllMapping['entities'][0]['fields'][0]); $this->assertEquals(['name'=>'city','column'=>'city'], $findAllMapping['entities'][0]['fields'][1]); $this->assertEquals(['name'=>'country','column'=>'country'], $findAllMapping['entities'][0]['fields'][2]); $withoutFieldsMapping = $class->getSqlResultSetMapping('mapping-without-fields'); $this->assertEquals('mapping-without-fields', $withoutFieldsMapping['name']); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress', $withoutFieldsMapping['entities'][0]['entityClass']); + $this->assertEquals(CmsAddress::class, $withoutFieldsMapping['entities'][0]['entityClass']); $this->assertEquals([], $withoutFieldsMapping['entities'][0]['fields']); $countMapping = $class->getSqlResultSetMapping('mapping-count'); @@ -634,8 +651,8 @@ public function testNamedNativeQuery() public function testSqlResultSetMapping() { - $userMetadata = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); - $personMetadata = $this->createClassMetadata('Doctrine\Tests\Models\Company\CompanyPerson'); + $userMetadata = $this->createClassMetadata(CmsUser::class); + $personMetadata = $this->createClassMetadata(CompanyPerson::class); // user asserts $this->assertCount(4, $userMetadata->getSqlResultSetMappings()); @@ -685,7 +702,7 @@ public function testSqlResultSetMapping() $this->assertEquals(['name'=>'id','column'=>'a_id'], $mapping['entities'][1]['fields'][0]); $this->assertEquals(['name'=>'zip','column'=>'a_zip'], $mapping['entities'][1]['fields'][1]); $this->assertEquals(['name'=>'country','column'=>'a_country'], $mapping['entities'][1]['fields'][2]); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress', $mapping['entities'][1]['entityClass']); + $this->assertEquals(CmsAddress::class, $mapping['entities'][1]['entityClass']); //person asserts $this->assertCount(1, $personMetadata->getSqlResultSetMappings()); @@ -706,8 +723,8 @@ public function testAssociationOverridesMapping() { $factory = $this->createClassMetadataFactory(); - $adminMetadata = $factory->getMetadataFor('Doctrine\Tests\Models\DDC964\DDC964Admin'); - $guestMetadata = $factory->getMetadataFor('Doctrine\Tests\Models\DDC964\DDC964Guest'); + $adminMetadata = $factory->getMetadataFor(DDC964Admin::class); + $guestMetadata = $factory->getMetadataFor(DDC964Guest::class); // assert groups association mappings @@ -789,7 +806,7 @@ public function testInversedByOverrideMapping() { $factory = $this->createClassMetadataFactory(); - $adminMetadata = $factory->getMetadataFor('Doctrine\Tests\Models\DDC3579\DDC3579Admin'); + $adminMetadata = $factory->getMetadataFor(DDC3579Admin::class); // assert groups association mappings $this->assertArrayHasKey('groups', $adminMetadata->associationMappings); @@ -806,8 +823,8 @@ public function testAttributeOverridesMapping() { $factory = $this->createClassMetadataFactory(); - $guestMetadata = $factory->getMetadataFor('Doctrine\Tests\Models\DDC964\DDC964Guest'); - $adminMetadata = $factory->getMetadataFor('Doctrine\Tests\Models\DDC964\DDC964Admin'); + $guestMetadata = $factory->getMetadataFor(DDC964Guest::class); + $adminMetadata = $factory->getMetadataFor(DDC964Admin::class); $this->assertTrue($adminMetadata->fieldMappings['id']['id']); $this->assertEquals('id', $adminMetadata->fieldMappings['id']['fieldName']); @@ -845,10 +862,10 @@ public function testEntityListeners() { $em = $this->_getTestEntityManager(); $factory = $this->createClassMetadataFactory($em); - $superClass = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyContract'); - $flexClass = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyFixContract'); - $fixClass = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyFlexContract'); - $ultraClass = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyFlexUltraContract'); + $superClass = $factory->getMetadataFor(CompanyContract::class); + $flexClass = $factory->getMetadataFor(CompanyFixContract::class); + $fixClass = $factory->getMetadataFor(CompanyFlexContract::class); + $ultraClass = $factory->getMetadataFor(CompanyFlexUltraContract::class); $this->assertArrayHasKey(Events::prePersist, $superClass->entityListeners); $this->assertArrayHasKey(Events::postPersist, $superClass->entityListeners); @@ -859,8 +876,8 @@ public function testEntityListeners() $postPersist = $superClass->entityListeners[Events::postPersist][0]; $prePersist = $superClass->entityListeners[Events::prePersist][0]; - $this->assertEquals('Doctrine\Tests\Models\Company\CompanyContractListener', $postPersist['class']); - $this->assertEquals('Doctrine\Tests\Models\Company\CompanyContractListener', $prePersist['class']); + $this->assertEquals(CompanyContractListener::class, $postPersist['class']); + $this->assertEquals(CompanyContractListener::class, $prePersist['class']); $this->assertEquals('postPersistHandler', $postPersist['method']); $this->assertEquals('prePersistHandler', $prePersist['method']); @@ -876,7 +893,7 @@ public function testEntityListenersOverride() { $em = $this->_getTestEntityManager(); $factory = $this->createClassMetadataFactory($em); - $ultraClass = $factory->getMetadataFor('Doctrine\Tests\Models\Company\CompanyFlexUltraContract'); + $ultraClass = $factory->getMetadataFor(CompanyFlexUltraContract::class); //overridden listeners $this->assertArrayHasKey(Events::postPersist, $ultraClass->entityListeners); @@ -888,17 +905,17 @@ public function testEntityListenersOverride() $postPersist = $ultraClass->entityListeners[Events::postPersist][0]; $prePersist = $ultraClass->entityListeners[Events::prePersist][0]; - $this->assertEquals('Doctrine\Tests\Models\Company\CompanyContractListener', $postPersist['class']); - $this->assertEquals('Doctrine\Tests\Models\Company\CompanyContractListener', $prePersist['class']); + $this->assertEquals(CompanyContractListener::class, $postPersist['class']); + $this->assertEquals(CompanyContractListener::class, $prePersist['class']); $this->assertEquals('postPersistHandler', $postPersist['method']); $this->assertEquals('prePersistHandler', $prePersist['method']); $prePersist = $ultraClass->entityListeners[Events::prePersist][1]; - $this->assertEquals('Doctrine\Tests\Models\Company\CompanyFlexUltraContractListener', $prePersist['class']); + $this->assertEquals(CompanyFlexUltraContractListener::class, $prePersist['class']); $this->assertEquals('prePersistHandler1', $prePersist['method']); $prePersist = $ultraClass->entityListeners[Events::prePersist][2]; - $this->assertEquals('Doctrine\Tests\Models\Company\CompanyFlexUltraContractListener', $prePersist['class']); + $this->assertEquals(CompanyFlexUltraContractListener::class, $prePersist['class']); $this->assertEquals('prePersistHandler2', $prePersist['method']); } @@ -910,7 +927,7 @@ public function testEntityListenersNamingConvention() { $em = $this->_getTestEntityManager(); $factory = $this->createClassMetadataFactory($em); - $metadata = $factory->getMetadataFor('Doctrine\Tests\Models\CMS\CmsAddress'); + $metadata = $factory->getMetadataFor(CmsAddress::class); $this->assertArrayHasKey(Events::postPersist, $metadata->entityListeners); $this->assertArrayHasKey(Events::prePersist, $metadata->entityListeners); @@ -940,14 +957,14 @@ public function testEntityListenersNamingConvention() $preFlush = $metadata->entityListeners[Events::preFlush][0]; - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $postPersist['class']); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $prePersist['class']); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $postUpdate['class']); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $preUpdate['class']); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $postRemove['class']); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $preRemove['class']); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $postLoad['class']); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddressListener', $preFlush['class']); + $this->assertEquals(CmsAddressListener::class, $postPersist['class']); + $this->assertEquals(CmsAddressListener::class, $prePersist['class']); + $this->assertEquals(CmsAddressListener::class, $postUpdate['class']); + $this->assertEquals(CmsAddressListener::class, $preUpdate['class']); + $this->assertEquals(CmsAddressListener::class, $postRemove['class']); + $this->assertEquals(CmsAddressListener::class, $preRemove['class']); + $this->assertEquals(CmsAddressListener::class, $postLoad['class']); + $this->assertEquals(CmsAddressListener::class, $preFlush['class']); $this->assertEquals(Events::postPersist, $postPersist['method']); $this->assertEquals(Events::prePersist, $prePersist['method']); @@ -966,7 +983,7 @@ public function testSecondLevelCacheMapping() { $em = $this->_getTestEntityManager(); $factory = $this->createClassMetadataFactory($em); - $class = $factory->getMetadataFor(City::CLASSNAME); + $class = $factory->getMetadataFor(City::class); $this->assertArrayHasKey('usage', $class->cache); $this->assertArrayHasKey('region', $class->cache); $this->assertEquals(ClassMetadata::CACHE_USAGE_READ_ONLY, $class->cache['usage']); @@ -994,7 +1011,7 @@ public function testSecondLevelCacheMapping() public function testSchemaDefinitionViaExplicitTableSchemaAnnotationProperty() { /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */ - $metadata = $this->createClassMetadataFactory()->getMetadataFor(ExplicitSchemaAndTable::CLASSNAME); + $metadata = $this->createClassMetadataFactory()->getMetadataFor(ExplicitSchemaAndTable::class); $this->assertSame('explicit_schema', $metadata->getSchemaName()); $this->assertSame('explicit_table', $metadata->getTableName()); @@ -1007,7 +1024,7 @@ public function testSchemaDefinitionViaExplicitTableSchemaAnnotationProperty() public function testSchemaDefinitionViaSchemaDefinedInTableNameInTableAnnotationProperty() { /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */ - $metadata = $this->createClassMetadataFactory()->getMetadataFor(SchemaAndTableInTableName::CLASSNAME); + $metadata = $this->createClassMetadataFactory()->getMetadataFor(SchemaAndTableInTableName::class); $this->assertSame('implicit_schema', $metadata->getSchemaName()); $this->assertSame('implicit_table', $metadata->getTableName()); @@ -1022,9 +1039,9 @@ public function testDiscriminatorColumnDefaultLength() if (strpos(get_class($this), 'PHPMappingDriver') !== false) { $this->markTestSkipped('PHP Mapping Drivers have no defaults.'); } - $class = $this->createClassMetadata(__NAMESPACE__ . '\SingleTableEntityNoDiscriminatorColumnMapping'); + $class = $this->createClassMetadata(SingleTableEntityNoDiscriminatorColumnMapping::class); $this->assertEquals(255, $class->discriminatorColumn['length']); - $class = $this->createClassMetadata(__NAMESPACE__ . '\SingleTableEntityIncompleteDiscriminatorColumnMapping'); + $class = $this->createClassMetadata(SingleTableEntityIncompleteDiscriminatorColumnMapping::class); $this->assertEquals(255, $class->discriminatorColumn['length']); } @@ -1037,9 +1054,9 @@ public function testDiscriminatorColumnDefaultType() if (strpos(get_class($this), 'PHPMappingDriver') !== false) { $this->markTestSkipped('PHP Mapping Drivers have no defaults.'); } - $class = $this->createClassMetadata(__NAMESPACE__ . '\SingleTableEntityNoDiscriminatorColumnMapping'); + $class = $this->createClassMetadata(SingleTableEntityNoDiscriminatorColumnMapping::class); $this->assertEquals('string', $class->discriminatorColumn['type']); - $class = $this->createClassMetadata(__NAMESPACE__ . '\SingleTableEntityIncompleteDiscriminatorColumnMapping'); + $class = $this->createClassMetadata(SingleTableEntityIncompleteDiscriminatorColumnMapping::class); $this->assertEquals('string', $class->discriminatorColumn['type']); } @@ -1052,9 +1069,9 @@ public function testDiscriminatorColumnDefaultName() if (strpos(get_class($this), 'PHPMappingDriver') !== false) { $this->markTestSkipped('PHP Mapping Drivers have no defaults.'); } - $class = $this->createClassMetadata(__NAMESPACE__ . '\SingleTableEntityNoDiscriminatorColumnMapping'); + $class = $this->createClassMetadata(SingleTableEntityNoDiscriminatorColumnMapping::class); $this->assertEquals('dtype', $class->discriminatorColumn['name']); - $class = $this->createClassMetadata(__NAMESPACE__ . '\SingleTableEntityIncompleteDiscriminatorColumnMapping'); + $class = $this->createClassMetadata(SingleTableEntityIncompleteDiscriminatorColumnMapping::class); $this->assertEquals('dtype', $class->discriminatorColumn['name']); } @@ -1188,7 +1205,7 @@ public static function loadMetadata(ClassMetadataInfo $metadata) $metadata->mapOneToOne( [ 'fieldName' => 'address', - 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Address', + 'targetEntity' => Address::class, 'cascade' => [ 0 => 'remove', @@ -1210,7 +1227,7 @@ public static function loadMetadata(ClassMetadataInfo $metadata) $metadata->mapOneToMany( [ 'fieldName' => 'phonenumbers', - 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Phonenumber', + 'targetEntity' => Phonenumber::class, 'cascade' => [ 1 => 'persist', @@ -1226,7 +1243,7 @@ public static function loadMetadata(ClassMetadataInfo $metadata) $metadata->mapManyToMany( [ 'fieldName' => 'groups', - 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Group', + 'targetEntity' => Group::class, 'cascade' => [ 0 => 'remove', diff --git a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php index e87412d3ec3..89951f9715d 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php @@ -5,10 +5,17 @@ use Doctrine\Common\Annotations\AnnotationException; use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; +use Doctrine\ORM\Mapping; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\MappingException; +use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\Models\DDC1872\DDC1872ExampleEntityWithoutOverride; +use Doctrine\Tests\Models\DDC1872\DDC1872ExampleEntityWithOverride; +use Doctrine\Tests\Models\DirectoryTree\Directory; +use Doctrine\Tests\Models\DirectoryTree\File; +use Doctrine\Tests\Models\ECommerce\ECommerceCart; class AnnotationDriverTest extends AbstractMappingDriverTest { @@ -32,11 +39,10 @@ public function testLoadMetadataForNonEntityThrowsException() */ public function testFailingSecondLevelCacheAssociation() { - $className = 'Doctrine\Tests\ORM\Mapping\AnnotationSLC'; $mappingDriver = $this->_loadDriver(); - $class = new ClassMetadata($className); - $mappingDriver->loadMetadataForClass($className, $class); + $class = new ClassMetadata(AnnotationSLC::class); + $mappingDriver->loadMetadataForClass(AnnotationSLC::class, $class); } /** @@ -44,11 +50,11 @@ public function testFailingSecondLevelCacheAssociation() */ public function testColumnWithMissingTypeDefaultsToString() { - $cm = new ClassMetadata('Doctrine\Tests\ORM\Mapping\ColumnWithoutType'); + $cm = new ClassMetadata(ColumnWithoutType::class); $cm->initializeReflection(new RuntimeReflectionService()); $annotationDriver = $this->_loadDriver(); - $annotationDriver->loadMetadataForClass('Doctrine\Tests\ORM\Mapping\InvalidColumn', $cm); + $annotationDriver->loadMetadataForClass(Mapping\InvalidColumn::class, $cm); $this->assertEquals('string', $cm->fieldMappings['id']['type']); } @@ -85,13 +91,12 @@ public function testGetAllClassNamesIsIdempotentEvenWithDifferentDriverInstances */ public function testGetAllClassNamesReturnsAlreadyLoadedClassesIfAppropriate() { - $rightClassName = 'Doctrine\Tests\Models\CMS\CmsUser'; - $this->_ensureIsLoaded($rightClassName); + $this->_ensureIsLoaded(CmsUser::class); $annotationDriver = $this->_loadDriverForCMSModels(); $classes = $annotationDriver->getAllClassNames(); - $this->assertContains($rightClassName, $classes); + $this->assertContains(CmsUser::class, $classes); } /** @@ -99,13 +104,12 @@ public function testGetAllClassNamesReturnsAlreadyLoadedClassesIfAppropriate() */ public function testGetClassNamesReturnsOnlyTheAppropriateClasses() { - $extraneousClassName = 'Doctrine\Tests\Models\ECommerce\ECommerceCart'; - $this->_ensureIsLoaded($extraneousClassName); + $this->_ensureIsLoaded(ECommerceCart::class); $annotationDriver = $this->_loadDriverForCMSModels(); $classes = $annotationDriver->getAllClassNames(); - $this->assertNotContains($extraneousClassName, $classes); + $this->assertNotContains(ECommerceCart::class, $classes); } protected function _loadDriverForCMSModels() @@ -140,11 +144,11 @@ public function testJoinTablesWithMappedSuperclassForAnnotationDriver() $factory = new ClassMetadataFactory(); $factory->setEntityManager($em); - $classPage = $factory->getMetadataFor('Doctrine\Tests\Models\DirectoryTree\File'); - $this->assertEquals('Doctrine\Tests\Models\DirectoryTree\File', $classPage->associationMappings['parentDirectory']['sourceEntity']); + $classPage = $factory->getMetadataFor(File::class); + $this->assertEquals(File::class, $classPage->associationMappings['parentDirectory']['sourceEntity']); - $classDirectory = $factory->getMetadataFor('Doctrine\Tests\Models\DirectoryTree\Directory'); - $this->assertEquals('Doctrine\Tests\Models\DirectoryTree\Directory', $classDirectory->associationMappings['parentDirectory']['sourceEntity']); + $classDirectory = $factory->getMetadataFor(Directory::class); + $this->assertEquals(Directory::class, $classDirectory->associationMappings['parentDirectory']['sourceEntity']); } /** @@ -165,7 +169,7 @@ public function testInvalidMappedSuperClassWithManyToManyAssociation() "mapped superclass 'Doctrine\Tests\ORM\Mapping\InvalidMappedSuperClass#users'" ); - $usingInvalidMsc = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\UsingInvalidMappedSuperClass'); + $usingInvalidMsc = $factory->getMetadataFor(UsingInvalidMappedSuperClass::class); } /** @@ -183,10 +187,10 @@ public function testInvalidMappedSuperClassWithInheritanceInformation() $this->expectException(MappingException::class); $this->expectExceptionMessage( "It is not supported to define inheritance information on a mapped " . - "superclass 'Doctrine\Tests\ORM\Mapping\MappedSuperClassInheritence'." + "superclass '" . MappedSuperClassInheritence::class . "'." ); - $usingInvalidMsc = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\MappedSuperClassInheritence'); + $usingInvalidMsc = $factory->getMetadataFor(MappedSuperClassInheritence::class); } /** @@ -201,10 +205,10 @@ public function testInheritanceSkipsParentLifecycleCallbacks() $factory = new ClassMetadataFactory(); $factory->setEntityManager($em); - $cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\AnnotationChild'); + $cm = $factory->getMetadataFor(AnnotationChild::class); $this->assertEquals(["postLoad" => ["postLoad"], "preUpdate" => ["preUpdate"]], $cm->lifecycleCallbacks); - $cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\AnnotationParent'); + $cm = $factory->getMetadataFor(AnnotationParent::class); $this->assertEquals(["postLoad" => ["postLoad"], "preUpdate" => ["preUpdate"]], $cm->lifecycleCallbacks); } @@ -220,7 +224,7 @@ public function testMappedSuperclassInMiddleOfInheritanceHierarchy() $factory = new ClassMetadataFactory(); $factory->setEntityManager($em); - $cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\ChildEntity'); + $cm = $factory->getMetadataFor(ChildEntity::class); } public function testInvalidFetchOptionThrowsException() @@ -235,15 +239,15 @@ public function testInvalidFetchOptionThrowsException() $this->expectException(AnnotationException::class); $this->expectExceptionMessage('[Enum Error] Attribute "fetch" of @Doctrine\ORM\Mapping\OneToMany declared on property Doctrine\Tests\ORM\Mapping\InvalidFetchOption::$collection accept only [LAZY, EAGER, EXTRA_LAZY], but got eager.'); - $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\InvalidFetchOption'); + $factory->getMetadataFor(InvalidFetchOption::class); } public function testAttributeOverridesMappingWithTrait() { $factory = $this->createClassMetadataFactory(); - $metadataWithoutOverride = $factory->getMetadataFor('Doctrine\Tests\Models\DDC1872\DDC1872ExampleEntityWithoutOverride'); - $metadataWithOverride = $factory->getMetadataFor('Doctrine\Tests\Models\DDC1872\DDC1872ExampleEntityWithOverride'); + $metadataWithoutOverride = $factory->getMetadataFor(DDC1872ExampleEntityWithoutOverride::class); + $metadataWithOverride = $factory->getMetadataFor(DDC1872ExampleEntityWithOverride::class); $this->assertEquals('trait_foo', $metadataWithoutOverride->fieldMappings['foo']['columnName']); $this->assertEquals('foo_overridden', $metadataWithOverride->fieldMappings['foo']['columnName']); diff --git a/tests/Doctrine/Tests/ORM/Mapping/AnsiQuoteStrategyTest.php b/tests/Doctrine/Tests/ORM/Mapping/AnsiQuoteStrategyTest.php index 497e2a00581..a0b422c0f76 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AnsiQuoteStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AnsiQuoteStrategyTest.php @@ -5,6 +5,10 @@ use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; use Doctrine\ORM\Mapping\AnsiQuoteStrategy; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\Tests\Models\CMS\CmsAddress; +use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\Models\DDC117\DDC117Article; +use Doctrine\Tests\Models\DDC117\DDC117ArticleDetails; use Doctrine\Tests\OrmTestCase; /** @@ -47,7 +51,7 @@ private function createClassMetadata($className) public function testGetColumnName() { - $class = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $class = $this->createClassMetadata(CmsUser::class); $class->mapField(['fieldName' => 'name', 'columnName' => 'name']); $class->mapField(['fieldName' => 'id', 'columnName' => 'id', 'id' => true]); @@ -57,7 +61,7 @@ public function testGetColumnName() public function testGetTableName() { - $class = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $class = $this->createClassMetadata(CmsUser::class); $class->setPrimaryTable(['name'=>'cms_user']); $this->assertEquals('cms_user' ,$this->strategy->getTableName($class, $this->platform)); @@ -65,7 +69,7 @@ public function testGetTableName() public function testJoinTableName() { - $class = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); + $class = $this->createClassMetadata(CmsAddress::class); $class->mapManyToMany( [ @@ -84,7 +88,7 @@ public function testJoinTableName() public function testIdentifierColumnNames() { - $class = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); + $class = $this->createClassMetadata(CmsAddress::class); $class->mapField( [ @@ -105,13 +109,13 @@ public function testColumnAlias() public function testJoinColumnName() { - $class = $this->createClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); + $class = $this->createClassMetadata(DDC117ArticleDetails::class); $class->mapOneToOne( [ 'id' => true, 'fieldName' => 'article', - 'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', + 'targetEntity' => DDC117Article::class, 'joinColumns' => [ [ 'name' => 'article' @@ -126,13 +130,13 @@ public function testJoinColumnName() public function testReferencedJoinColumnName() { - $cm = $this->createClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); + $cm = $this->createClassMetadata(DDC117ArticleDetails::class); $cm->mapOneToOne( [ 'id' => true, 'fieldName' => 'article', - 'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', + 'targetEntity' => DDC117Article::class, 'joinColumns' => [ [ 'name' => 'article' @@ -147,7 +151,7 @@ public function testReferencedJoinColumnName() public function testGetSequenceName() { - $class = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $class = $this->createClassMetadata(CmsUser::class); $definition = [ 'sequenceName' => 'user_id_seq', 'allocationSize' => 1, diff --git a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php index 7cd1247ddde..292954506a4 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php @@ -3,10 +3,15 @@ namespace Doctrine\Tests\ORM\Mapping; use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; +use Doctrine\ORM\EntityRepository; +use Doctrine\ORM\Id\SequenceGenerator; use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Mapping\MappingException; +use Doctrine\Tests\Models\DDC869\DDC869ChequePayment; +use Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment; use Doctrine\Tests\Models\DDC869\DDC869Payment; +use Doctrine\Tests\Models\DDC869\DDC869PaymentRepository; use Doctrine\Tests\OrmTestCase; class BasicInheritanceMappingTest extends OrmTestCase @@ -29,12 +34,12 @@ public function testGetMetadataForTransientClassThrowsException() { $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); - $this->cmf->getMetadataFor('Doctrine\Tests\ORM\Mapping\TransientBaseClass'); + $this->cmf->getMetadataFor(TransientBaseClass::class); } public function testGetMetadataForSubclassWithTransientBaseClass() { - $class = $this->cmf->getMetadataFor('Doctrine\Tests\ORM\Mapping\EntitySubClass'); + $class = $this->cmf->getMetadataFor(EntitySubClass::class); $this->assertEmpty($class->subClasses); $this->assertEmpty($class->parentClasses); @@ -44,7 +49,7 @@ public function testGetMetadataForSubclassWithTransientBaseClass() public function testGetMetadataForSubclassWithMappedSuperclass() { - $class = $this->cmf->getMetadataFor('Doctrine\Tests\ORM\Mapping\EntitySubClass2'); + $class = $this->cmf->getMetadataFor(EntitySubClass2::class); $this->assertEmpty($class->subClasses); $this->assertEmpty($class->parentClasses); @@ -66,28 +71,28 @@ public function testGetMetadataForSubclassWithMappedSuperclass() */ public function testGetMetadataForSubclassWithMappedSuperclassWithRepository() { - $class = $this->cmf->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment'); + $class = $this->cmf->getMetadataFor(DDC869CreditCardPayment::class); $this->assertArrayHasKey('id', $class->fieldMappings); $this->assertArrayHasKey('value', $class->fieldMappings); $this->assertArrayHasKey('creditCardNumber', $class->fieldMappings); - $this->assertEquals($class->customRepositoryClassName, 'Doctrine\Tests\Models\DDC869\DDC869PaymentRepository'); + $this->assertEquals($class->customRepositoryClassName, DDC869PaymentRepository::class); - $class = $this->cmf->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869ChequePayment'); + $class = $this->cmf->getMetadataFor(DDC869ChequePayment::class); $this->assertArrayHasKey('id', $class->fieldMappings); $this->assertArrayHasKey('value', $class->fieldMappings); $this->assertArrayHasKey('serialNumber', $class->fieldMappings); - $this->assertEquals($class->customRepositoryClassName, 'Doctrine\Tests\Models\DDC869\DDC869PaymentRepository'); + $this->assertEquals($class->customRepositoryClassName, DDC869PaymentRepository::class); // override repositoryClass - $class = $this->cmf->getMetadataFor('Doctrine\Tests\ORM\Mapping\SubclassWithRepository'); + $class = $this->cmf->getMetadataFor(SubclassWithRepository::class); $this->assertArrayHasKey('id', $class->fieldMappings); $this->assertArrayHasKey('value', $class->fieldMappings); - $this->assertEquals($class->customRepositoryClassName, 'Doctrine\ORM\EntityRepository'); + $this->assertEquals($class->customRepositoryClassName, EntityRepository::class); } /** @@ -96,7 +101,7 @@ public function testGetMetadataForSubclassWithMappedSuperclassWithRepository() public function testSerializationWithPrivateFieldsFromMappedSuperclass() { - $class = $this->cmf->getMetadataFor(__NAMESPACE__ . '\\EntitySubClass2'); + $class = $this->cmf->getMetadataFor(EntitySubClass2::class); $class2 = unserialize(serialize($class)); $class2->wakeupReflection(new RuntimeReflectionService); @@ -111,7 +116,7 @@ public function testSerializationWithPrivateFieldsFromMappedSuperclass() */ public function testUnmappedSuperclassInHierarchy() { - $class = $this->cmf->getMetadataFor(__NAMESPACE__ . '\\HierarchyD'); + $class = $this->cmf->getMetadataFor(HierarchyD::class); $this->assertArrayHasKey('id', $class->fieldMappings); $this->assertArrayHasKey('a', $class->fieldMappings); @@ -131,7 +136,7 @@ public function testUnmappedEntityInHierarchy() . ' avoid this exception from occurring.' ); - $this->cmf->getMetadataFor(__NAMESPACE__ . '\\HierarchyE'); + $this->cmf->getMetadataFor(HierarchyE::class); } /** @@ -140,7 +145,7 @@ public function testUnmappedEntityInHierarchy() */ public function testMappedSuperclassWithId() { - $class = $this->cmf->getMetadataFor(__NAMESPACE__ . '\\SuperclassEntity'); + $class = $this->cmf->getMetadataFor(SuperclassEntity::class); $this->assertArrayHasKey('id', $class->fieldMappings); } @@ -151,10 +156,10 @@ public function testMappedSuperclassWithId() */ public function testGeneratedValueFromMappedSuperclass() { - $class = $this->cmf->getMetadataFor(__NAMESPACE__ . '\\SuperclassEntity'); + $class = $this->cmf->getMetadataFor(SuperclassEntity::class); /* @var $class ClassMetadataInfo */ - $this->assertInstanceOf('Doctrine\ORM\Id\SequenceGenerator', $class->idGenerator); + $this->assertInstanceOf(SequenceGenerator::class, $class->idGenerator); $this->assertEquals( ['allocationSize' => 1, 'initialValue' => 10, 'sequenceName' => 'foo'], $class->sequenceGeneratorDefinition @@ -167,10 +172,10 @@ public function testGeneratedValueFromMappedSuperclass() */ public function testSequenceDefinitionInHierarchyWithSandwichMappedSuperclass() { - $class = $this->cmf->getMetadataFor(__NAMESPACE__ . '\\HierarchyD'); + $class = $this->cmf->getMetadataFor(HierarchyD::class); /* @var $class ClassMetadataInfo */ - $this->assertInstanceOf('Doctrine\ORM\Id\SequenceGenerator', $class->idGenerator); + $this->assertInstanceOf(SequenceGenerator::class, $class->idGenerator); $this->assertEquals( ['allocationSize' => 1, 'initialValue' => 10, 'sequenceName' => 'foo'], $class->sequenceGeneratorDefinition @@ -183,10 +188,10 @@ public function testSequenceDefinitionInHierarchyWithSandwichMappedSuperclass() */ public function testMultipleMappedSuperclasses() { - $class = $this->cmf->getMetadataFor(__NAMESPACE__ . '\\MediumSuperclassEntity'); + $class = $this->cmf->getMetadataFor(MediumSuperclassEntity::class); /* @var $class ClassMetadataInfo */ - $this->assertInstanceOf('Doctrine\ORM\Id\SequenceGenerator', $class->idGenerator); + $this->assertInstanceOf(SequenceGenerator::class, $class->idGenerator); $this->assertEquals( ['allocationSize' => 1, 'initialValue' => 10, 'sequenceName' => 'foo'], $class->sequenceGeneratorDefinition @@ -200,7 +205,7 @@ public function testMultipleMappedSuperclasses() */ public function testMappedSuperclassIndex() { - $class = $this->cmf->getMetadataFor(__NAMESPACE__ . '\\EntityIndexSubClass'); + $class = $this->cmf->getMetadataFor(EntityIndexSubClass::class); /* @var $class ClassMetadataInfo */ $this->assertArrayHasKey('mapped1', $class->fieldMappings); diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php index e19687c8492..657ad65b474 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php @@ -3,8 +3,13 @@ namespace Doctrine\Tests\ORM\Mapping; use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; -use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder; +use Doctrine\ORM\Mapping\Builder\EmbeddedBuilder; +use Doctrine\ORM\Mapping\Builder\FieldBuilder; +use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\Tests\Models\CMS\CmsGroup; +use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\Models\ValueObjects\Name; use Doctrine\Tests\OrmTestCase; /** @@ -23,7 +28,7 @@ class ClassMetadataBuilderTest extends OrmTestCase public function setUp() { - $this->cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $this->cm = new ClassMetadata(CmsUser::class); $this->cm->initializeReflection(new RuntimeReflectionService()); $this->builder = new ClassMetadataBuilder($this->cm); } @@ -44,17 +49,12 @@ public function testSetEmbedable() public function testAddEmbeddedWithOnlyRequiredParams() { - $this->assertIsFluent( - $this->builder->addEmbedded( - 'name', - 'Doctrine\Tests\Models\ValueObjects\Name' - ) - ); + $this->assertIsFluent($this->builder->addEmbedded('name', Name::class)); $this->assertEquals( [ 'name' => [ - 'class' => 'Doctrine\Tests\Models\ValueObjects\Name', + 'class' => Name::class, 'columnPrefix' => null, 'declaredField' => null, 'originalField' => null, @@ -67,7 +67,7 @@ public function testAddEmbeddedWithPrefix() $this->assertIsFluent( $this->builder->addEmbedded( 'name', - 'Doctrine\Tests\Models\ValueObjects\Name', + Name::class, 'nm_' ) ); @@ -75,7 +75,7 @@ public function testAddEmbeddedWithPrefix() $this->assertEquals( [ 'name' => [ - 'class' => 'Doctrine\Tests\Models\ValueObjects\Name', + 'class' => Name::class, 'columnPrefix' => 'nm_', 'declaredField' => null, 'originalField' => null, @@ -85,15 +85,15 @@ public function testAddEmbeddedWithPrefix() public function testCreateEmbeddedWithoutExtraParams() { - $embeddedBuilder = ($this->builder->createEmbedded('name', 'Doctrine\Tests\Models\ValueObjects\Name')); - $this->assertInstanceOf('Doctrine\ORM\Mapping\Builder\EmbeddedBuilder', $embeddedBuilder); + $embeddedBuilder = ($this->builder->createEmbedded('name', Name::class)); + $this->assertInstanceOf(EmbeddedBuilder::class, $embeddedBuilder); $this->assertFalse(isset($this->cm->embeddedClasses['name'])); $this->assertIsFluent($embeddedBuilder->build()); $this->assertEquals( [ - 'class' => 'Doctrine\Tests\Models\ValueObjects\Name', + 'class' => Name::class, 'columnPrefix' => null, 'declaredField' => null, 'originalField' => null @@ -104,7 +104,7 @@ public function testCreateEmbeddedWithoutExtraParams() public function testCreateEmbeddedWithColumnPrefix() { - $embeddedBuilder = ($this->builder->createEmbedded('name', 'Doctrine\Tests\Models\ValueObjects\Name')); + $embeddedBuilder = ($this->builder->createEmbedded('name', Name::class)); $this->assertEquals($embeddedBuilder, $embeddedBuilder->setColumnPrefix('nm_')); @@ -112,7 +112,7 @@ public function testCreateEmbeddedWithColumnPrefix() $this->assertEquals( [ - 'class' => 'Doctrine\Tests\Models\ValueObjects\Name', + 'class' => Name::class, 'columnPrefix' => 'nm_', 'declaredField' => null, 'originalField' => null @@ -123,8 +123,8 @@ public function testCreateEmbeddedWithColumnPrefix() public function testSetCustomRepositoryClass() { - $this->assertIsFluent($this->builder->setCustomRepositoryClass('Doctrine\Tests\Models\CMS\CmsGroup')); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsGroup', $this->cm->customRepositoryClassName); + $this->assertIsFluent($this->builder->setCustomRepositoryClass(CmsGroup::class)); + $this->assertEquals(CmsGroup::class, $this->cm->customRepositoryClassName); } public function testSetReadOnly() @@ -187,11 +187,11 @@ public function testSetDiscriminatorColumn() public function testAddDiscriminatorMapClass() { - $this->assertIsFluent($this->builder->addDiscriminatorMapClass('test', 'Doctrine\Tests\Models\CMS\CmsUser')); - $this->assertIsFluent($this->builder->addDiscriminatorMapClass('test2', 'Doctrine\Tests\Models\CMS\CmsGroup')); + $this->assertIsFluent($this->builder->addDiscriminatorMapClass('test', CmsUser::class)); + $this->assertIsFluent($this->builder->addDiscriminatorMapClass('test2', CmsGroup::class)); $this->assertEquals( - ['test' => 'Doctrine\Tests\Models\CMS\CmsUser', 'test2' => 'Doctrine\Tests\Models\CMS\CmsGroup'], $this->cm->discriminatorMap); + ['test' => CmsUser::class, 'test2' => CmsGroup::class], $this->cm->discriminatorMap); $this->assertEquals('test', $this->cm->discriminatorValue); } @@ -216,7 +216,7 @@ public function testAddField() public function testCreateField() { $fieldBuilder = ($this->builder->createField('name', 'string')); - $this->assertInstanceOf('Doctrine\ORM\Mapping\Builder\FieldBuilder', $fieldBuilder); + $this->assertInstanceOf(FieldBuilder::class, $fieldBuilder); $this->assertFalse(isset($this->cm->fieldMappings['name'])); $this->assertIsFluent($fieldBuilder->build()); @@ -265,7 +265,7 @@ public function testAddLifecycleEvent() public function testCreateManyToOne() { $this->assertIsFluent( - $this->builder->createManyToOne('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') + $this->builder->createManyToOne('groups', CmsGroup::class) ->addJoinColumn('group_id', 'id', true, false, 'CASCADE') ->cascadeAll() ->fetchExtraLazy() @@ -276,7 +276,7 @@ public function testCreateManyToOne() [ 'groups' => [ 'fieldName' => 'groups', - 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsGroup', + 'targetEntity' => CmsGroup::class, 'cascade' => [ 0 => 'remove', 1 => 'persist', @@ -300,7 +300,7 @@ public function testCreateManyToOne() 'mappedBy' => NULL, 'inversedBy' => NULL, 'isOwningSide' => true, - 'sourceEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', + 'sourceEntity' => CmsUser::class, 'isCascadeRemove' => true, 'isCascadePersist' => true, 'isCascadeRefresh' => true, @@ -328,7 +328,7 @@ public function testCreateManyToOneWithIdentity() $this->assertIsFluent( $this ->builder - ->createManyToOne('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') + ->createManyToOne('groups', CmsGroup::class) ->addJoinColumn('group_id', 'id', true, false, 'CASCADE') ->cascadeAll() ->fetchExtraLazy() @@ -340,7 +340,7 @@ public function testCreateManyToOneWithIdentity() [ 'groups' => [ 'fieldName' => 'groups', - 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsGroup', + 'targetEntity' => CmsGroup::class, 'cascade' => [ 0 => 'remove', 1 => 'persist', @@ -364,7 +364,7 @@ public function testCreateManyToOneWithIdentity() 'mappedBy' => NULL, 'inversedBy' => NULL, 'isOwningSide' => true, - 'sourceEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', + 'sourceEntity' => CmsUser::class, 'isCascadeRemove' => true, 'isCascadePersist' => true, 'isCascadeRefresh' => true, @@ -393,7 +393,7 @@ public function testCreateManyToOneWithIdentity() public function testCreateOneToOne() { $this->assertIsFluent( - $this->builder->createOneToOne('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') + $this->builder->createOneToOne('groups', CmsGroup::class) ->addJoinColumn('group_id', 'id', true, false, 'CASCADE') ->cascadeAll() ->fetchExtraLazy() @@ -404,7 +404,7 @@ public function testCreateOneToOne() [ 'groups' => [ 'fieldName' => 'groups', - 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsGroup', + 'targetEntity' => CmsGroup::class, 'cascade' => [ 0 => 'remove', 1 => 'persist', @@ -428,7 +428,7 @@ public function testCreateOneToOne() 'mappedBy' => NULL, 'inversedBy' => NULL, 'isOwningSide' => true, - 'sourceEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', + 'sourceEntity' => CmsUser::class, 'isCascadeRemove' => true, 'isCascadePersist' => true, 'isCascadeRefresh' => true, @@ -456,7 +456,7 @@ public function testCreateOneToOneWithIdentity() $this->assertIsFluent( $this ->builder - ->createOneToOne('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') + ->createOneToOne('groups', CmsGroup::class) ->addJoinColumn('group_id', 'id', true, false, 'CASCADE') ->cascadeAll() ->fetchExtraLazy() @@ -468,7 +468,7 @@ public function testCreateOneToOneWithIdentity() [ 'groups' => [ 'fieldName' => 'groups', - 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsGroup', + 'targetEntity' => CmsGroup::class, 'cascade' => [ 0 => 'remove', 1 => 'persist', @@ -493,7 +493,7 @@ public function testCreateOneToOneWithIdentity() 'mappedBy' => NULL, 'inversedBy' => NULL, 'isOwningSide' => true, - 'sourceEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', + 'sourceEntity' => CmsUser::class, 'isCascadeRemove' => true, 'isCascadePersist' => true, 'isCascadeRefresh' => true, @@ -524,7 +524,7 @@ public function testThrowsExceptionOnCreateOneToOneWithIdentityOnInverseSide() $this ->builder - ->createOneToOne('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') + ->createOneToOne('groups', CmsGroup::class) ->mappedBy('test') ->fetchExtraLazy() ->makePrimaryKey() @@ -534,7 +534,7 @@ public function testThrowsExceptionOnCreateOneToOneWithIdentityOnInverseSide() public function testCreateManyToMany() { $this->assertIsFluent( - $this->builder->createManyToMany('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') + $this->builder->createManyToMany('groups', CmsGroup::class) ->setJoinTable('groups_users') ->addJoinColumn('group_id', 'id', true, false, 'CASCADE') ->addInverseJoinColumn('user_id', 'id') @@ -548,7 +548,7 @@ public function testCreateManyToMany() 'groups' => [ 'fieldName' => 'groups', - 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsGroup', + 'targetEntity' => CmsGroup::class, 'cascade' => [ 0 => 'remove', @@ -590,7 +590,7 @@ public function testCreateManyToMany() 'mappedBy' => NULL, 'inversedBy' => NULL, 'isOwningSide' => true, - 'sourceEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', + 'sourceEntity' => CmsUser::class, 'isCascadeRemove' => true, 'isCascadePersist' => true, 'isCascadeRefresh' => true, @@ -619,7 +619,7 @@ public function testThrowsExceptionOnCreateManyToManyWithIdentity() { $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); - $this->builder->createManyToMany('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') + $this->builder->createManyToMany('groups', CmsGroup::class) ->makePrimaryKey() ->setJoinTable('groups_users') ->addJoinColumn('group_id', 'id', true, false, 'CASCADE') @@ -632,7 +632,7 @@ public function testThrowsExceptionOnCreateManyToManyWithIdentity() public function testCreateOneToMany() { $this->assertIsFluent( - $this->builder->createOneToMany('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') + $this->builder->createOneToMany('groups', CmsGroup::class) ->mappedBy('test') ->setOrderBy(['test']) ->setIndexBy('test') @@ -644,7 +644,7 @@ public function testCreateOneToMany() 'groups' => [ 'fieldName' => 'groups', - 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsGroup', + 'targetEntity' => CmsGroup::class, 'mappedBy' => 'test', 'orderBy' => [ @@ -654,7 +654,7 @@ public function testCreateOneToMany() 'type' => 4, 'inversedBy' => NULL, 'isOwningSide' => false, - 'sourceEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', + 'sourceEntity' => CmsUser::class, 'fetch' => 2, 'cascade' => [ @@ -673,7 +673,7 @@ public function testThrowsExceptionOnCreateOneToManyWithIdentity() { $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); - $this->builder->createOneToMany('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') + $this->builder->createOneToMany('groups', CmsGroup::class) ->makePrimaryKey() ->mappedBy('test') ->setOrderBy(['test']) @@ -685,7 +685,7 @@ public function testOrphanRemovalOnCreateOneToOne() { $this->assertIsFluent( $this->builder - ->createOneToOne('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') + ->createOneToOne('groups', CmsGroup::class) ->addJoinColumn('group_id', 'id', true, false, 'CASCADE') ->orphanRemoval() ->build() @@ -695,7 +695,7 @@ public function testOrphanRemovalOnCreateOneToOne() [ 'groups' => [ 'fieldName' => 'groups', - 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsGroup', + 'targetEntity' => CmsGroup::class, 'cascade' => [], 'fetch' => 2, 'joinColumns' => [ @@ -713,7 +713,7 @@ public function testOrphanRemovalOnCreateOneToOne() 'mappedBy' => NULL, 'inversedBy' => NULL, 'isOwningSide' => true, - 'sourceEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', + 'sourceEntity' => CmsUser::class, 'isCascadeRemove' => true, 'isCascadePersist' => false, 'isCascadeRefresh' => false, @@ -740,7 +740,7 @@ public function testOrphanRemovalOnCreateOneToMany() { $this->assertIsFluent( $this->builder - ->createOneToMany('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') + ->createOneToMany('groups', CmsGroup::class) ->mappedBy('test') ->orphanRemoval() ->build() @@ -751,12 +751,12 @@ public function testOrphanRemovalOnCreateOneToMany() 'groups' => [ 'fieldName' => 'groups', - 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsGroup', + 'targetEntity' => CmsGroup::class, 'mappedBy' => 'test', 'type' => 4, 'inversedBy' => NULL, 'isOwningSide' => false, - 'sourceEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', + 'sourceEntity' => CmsUser::class, 'fetch' => 2, 'cascade' => [], 'isCascadeRemove' => true, @@ -774,7 +774,7 @@ public function testExceptionOnOrphanRemovalOnManyToOne() $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); $this->builder - ->createManyToOne('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') + ->createManyToOne('groups', CmsGroup::class) ->addJoinColumn('group_id', 'id', true, false, 'CASCADE') ->orphanRemoval() ->build(); @@ -783,7 +783,7 @@ public function testExceptionOnOrphanRemovalOnManyToOne() public function testOrphanRemovalOnManyToMany() { $this->builder - ->createManyToMany('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') + ->createManyToMany('groups', CmsGroup::class) ->addJoinColumn('group_id', 'id', true, false, 'CASCADE') ->orphanRemoval() ->build(); @@ -792,7 +792,7 @@ public function testOrphanRemovalOnManyToMany() [ 'groups' => [ 'fieldName' => 'groups', - 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsGroup', + 'targetEntity' => CmsGroup::class, 'cascade' => [], 'fetch' => 2, 'joinTable' => [ @@ -819,7 +819,7 @@ public function testOrphanRemovalOnManyToMany() 'mappedBy' => NULL, 'inversedBy' => NULL, 'isOwningSide' => true, - 'sourceEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', + 'sourceEntity' => CmsUser::class, 'isCascadeRemove' => false, 'isCascadePersist' => false, 'isCascadeRefresh' => false, diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index bdfd6893d48..d1cf1b48f88 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -20,7 +20,15 @@ use Doctrine\Tests\Mocks\DriverMock; use Doctrine\Tests\Mocks\EntityManagerMock; use Doctrine\Tests\Mocks\MetadataDriverMock; +use Doctrine\Tests\Models\CMS\CmsArticle; +use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\Models\DDC4006\DDC4006User; +use Doctrine\Tests\Models\JoinedInheritanceType\AnotherChildClass; +use Doctrine\Tests\Models\JoinedInheritanceType\ChildClass; +use Doctrine\Tests\Models\JoinedInheritanceType\RootClass; +use Doctrine\Tests\Models\Quote; use Doctrine\Tests\OrmTestCase; +use DoctrineGlobal_Article; class ClassMetadataFactoryTest extends OrmTestCase { @@ -63,18 +71,14 @@ public function testGetMetadataFor_ReturnsLoadedCustomIdGenerator() { $cm1 = $this->_createValidClassMetadata(); $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_CUSTOM); - $cm1->customGeneratorDefinition = [ - "class" => "Doctrine\Tests\ORM\Mapping\CustomIdGenerator" - ]; + $cm1->customGeneratorDefinition = ['class' => CustomIdGenerator::class]; $cmf = $this->_createTestFactory(); $cmf->setMetadataForClass($cm1->name, $cm1); $actual = $cmf->getMetadataFor($cm1->name); - $this->assertEquals(ClassMetadata::GENERATOR_TYPE_CUSTOM, - $actual->generatorType); - $this->assertInstanceOf("Doctrine\Tests\ORM\Mapping\CustomIdGenerator", - $actual->idGenerator); + $this->assertEquals(ClassMetadata::GENERATOR_TYPE_CUSTOM, $actual->generatorType); + $this->assertInstanceOf(CustomIdGenerator::class, $actual->idGenerator); } public function testGetMetadataFor_ThrowsExceptionOnUnknownCustomGeneratorClass() @@ -109,10 +113,10 @@ public function testHasGetMetadata_NamespaceSeparatorIsNotNormalized() $entityManager = $this->_createEntityManager($metadataDriver); $mf = $entityManager->getMetadataFactory(); - $m1 = $mf->getMetadataFor("DoctrineGlobal_Article"); - $h1 = $mf->hasMetadataFor("DoctrineGlobal_Article"); - $h2 = $mf->hasMetadataFor("\DoctrineGlobal_Article"); - $m2 = $mf->getMetadataFor("\DoctrineGlobal_Article"); + $m1 = $mf->getMetadataFor(DoctrineGlobal_Article::class); + $h1 = $mf->hasMetadataFor(DoctrineGlobal_Article::class); + $h2 = $mf->hasMetadataFor('\\' . DoctrineGlobal_Article::class); + $m2 = $mf->getMetadataFor('\\' . DoctrineGlobal_Article::class); $this->assertNotSame($m1, $m2); $this->assertFalse($h2); @@ -128,17 +132,17 @@ public function testIsTransient() $driver = $this->createMock(MappingDriver::class); $driver->expects($this->at(0)) ->method('isTransient') - ->with($this->equalTo('Doctrine\Tests\Models\CMS\CmsUser')) + ->with($this->equalTo(CmsUser::class)) ->will($this->returnValue(true)); $driver->expects($this->at(1)) ->method('isTransient') - ->with($this->equalTo('Doctrine\Tests\Models\CMS\CmsArticle')) + ->with($this->equalTo(CmsArticle::class)) ->will($this->returnValue(false)); $em = $this->_createEntityManager($driver); - $this->assertTrue($em->getMetadataFactory()->isTransient('Doctrine\Tests\Models\CMS\CmsUser')); - $this->assertFalse($em->getMetadataFactory()->isTransient('Doctrine\Tests\Models\CMS\CmsArticle')); + $this->assertTrue($em->getMetadataFactory()->isTransient(CmsUser::class)); + $this->assertFalse($em->getMetadataFactory()->isTransient(CmsArticle::class)); } /** @@ -150,11 +154,11 @@ public function testIsTransientEntityNamespace() $driver = $this->createMock(MappingDriver::class); $driver->expects($this->at(0)) ->method('isTransient') - ->with($this->equalTo('Doctrine\Tests\Models\CMS\CmsUser')) + ->with($this->equalTo(CmsUser::class)) ->will($this->returnValue(true)); $driver->expects($this->at(1)) ->method('isTransient') - ->with($this->equalTo('Doctrine\Tests\Models\CMS\CmsArticle')) + ->with($this->equalTo(CmsArticle::class)) ->will($this->returnValue(false)); $em = $this->_createEntityManager($driver); @@ -171,16 +175,16 @@ public function testAddDefaultDiscriminatorMap() $em = $this->_createEntityManager($driver); $cmf->setEntityManager($em); - $rootMetadata = $cmf->getMetadataFor('Doctrine\Tests\Models\JoinedInheritanceType\RootClass'); - $childMetadata = $cmf->getMetadataFor('Doctrine\Tests\Models\JoinedInheritanceType\ChildClass'); - $anotherChildMetadata = $cmf->getMetadataFor('Doctrine\Tests\Models\JoinedInheritanceType\AnotherChildClass'); + $rootMetadata = $cmf->getMetadataFor(RootClass::class); + $childMetadata = $cmf->getMetadataFor(ChildClass::class); + $anotherChildMetadata = $cmf->getMetadataFor(AnotherChildClass::class); $rootDiscriminatorMap = $rootMetadata->discriminatorMap; $childDiscriminatorMap = $childMetadata->discriminatorMap; $anotherChildDiscriminatorMap = $anotherChildMetadata->discriminatorMap; - $rootClass = 'Doctrine\Tests\Models\JoinedInheritanceType\RootClass'; - $childClass = 'Doctrine\Tests\Models\JoinedInheritanceType\ChildClass'; - $anotherChildClass = 'Doctrine\Tests\Models\JoinedInheritanceType\AnotherChildClass'; + $rootClass = RootClass::class; + $childClass = ChildClass::class; + $anotherChildClass = AnotherChildClass::class; $rootClassKey = array_search($rootClass, $rootDiscriminatorMap); $childClassKey = array_search($childClass, $rootDiscriminatorMap); @@ -200,7 +204,7 @@ public function testAddDefaultDiscriminatorMap() $cmf->expects($this->never()) ->method('addDefaultDiscriminatorMap'); - $rootMetadata = $cmf->getMetadataFor('Doctrine\Tests\Models\JoinedInheritanceType\RootClass'); + $rootMetadata = $cmf->getMetadataFor(RootClass::class); } public function testGetAllMetadataWorksWithBadConnection() @@ -257,7 +261,7 @@ protected function _createTestFactory() protected function _createValidClassMetadata() { // Self-made metadata - $cm1 = new ClassMetadata('Doctrine\Tests\ORM\Mapping\TestEntity1'); + $cm1 = new ClassMetadata(TestEntity1::class); $cm1->initializeReflection(new RuntimeReflectionService()); $cm1->setPrimaryTable(['name' => '`group`']); // Add a mapped field @@ -289,10 +293,10 @@ public function testQuoteMetadata() $cmf->setEntityManager($em); - $userMetadata = $cmf->getMetadataFor('Doctrine\Tests\Models\Quote\User'); - $phoneMetadata = $cmf->getMetadataFor('Doctrine\Tests\Models\Quote\Phone'); - $groupMetadata = $cmf->getMetadataFor('Doctrine\Tests\Models\Quote\Group'); - $addressMetadata = $cmf->getMetadataFor('Doctrine\Tests\Models\Quote\Address'); + $userMetadata = $cmf->getMetadataFor(Quote\User::class); + $phoneMetadata = $cmf->getMetadataFor(Quote\Phone::class); + $groupMetadata = $cmf->getMetadataFor(Quote\Group::class); + $addressMetadata = $cmf->getMetadataFor(Quote\Address::class); // Phone Class Metadata @@ -443,7 +447,7 @@ public function testInheritsIdGeneratorMappingFromEmbeddable() $em = $this->_createEntityManager($driver); $cmf->setEntityManager($em); - $userMetadata = $cmf->getMetadataFor('Doctrine\Tests\Models\DDC4006\DDC4006User'); + $userMetadata = $cmf->getMetadataFor(DDC4006User::class); $this->assertTrue($userMetadata->isIdGeneratorIdentity()); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataLoadEventTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataLoadEventTest.php index 424cafb9468..bf268cf829a 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataLoadEventTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataLoadEventTest.php @@ -17,7 +17,7 @@ public function testEvent() $metadataFactory = $em->getMetadataFactory(); $evm = $em->getEventManager(); $evm->addEventListener(Events::loadClassMetadata, $this); - $classMetadata = $metadataFactory->getMetadataFor('Doctrine\Tests\ORM\Mapping\LoadEventTestEntity'); + $classMetadata = $metadataFactory->getMetadataFor(LoadEventTestEntity::class); $this->assertTrue($classMetadata->hasField('about')); $this->assertArrayHasKey('about', $classMetadata->reflFields); $this->assertInstanceOf('ReflectionProperty', $classMetadata->reflFields['about']); diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php index bfaec804104..1dac953c2ba 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php @@ -4,13 +4,21 @@ use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; use Doctrine\Common\Persistence\Mapping\StaticReflectionService; -use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Events; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\DefaultNamingStrategy; use Doctrine\ORM\Mapping\MappingException; use Doctrine\ORM\Mapping\UnderscoreNamingStrategy; +use Doctrine\Tests\Models\CMS; +use Doctrine\Tests\Models\Company\CompanyContract; +use Doctrine\Tests\Models\CustomType\CustomTypeParent; +use Doctrine\Tests\Models\DDC117\DDC117Article; +use Doctrine\Tests\Models\DDC117\DDC117ArticleDetails; +use Doctrine\Tests\Models\DDC964\DDC964Admin; +use Doctrine\Tests\Models\DDC964\DDC964Guest; +use Doctrine\Tests\Models\Routing\RoutingLeg; use Doctrine\Tests\OrmTestCase; -use Doctrine\Tests\Proxies\__CG__\Doctrine\Tests\Models\CMS\CmsUser; +use DoctrineGlobal_Article; require_once __DIR__ . '/../../Models/Global/GlobalNamespaceModel.php'; @@ -18,14 +26,14 @@ class ClassMetadataTest extends OrmTestCase { public function testClassMetadataInstanceSerialization() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); // Test initial state $this->assertTrue(count($cm->getReflectionProperties()) == 0); $this->assertInstanceOf('ReflectionClass', $cm->reflClass); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->name); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->rootEntityName); + $this->assertEquals(CMS\CmsUser::class, $cm->name); + $this->assertEquals(CMS\CmsUser::class, $cm->rootEntityName); $this->assertEquals([], $cm->subClasses); $this->assertEquals([], $cm->parentClasses); $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $cm->inheritanceType); @@ -48,27 +56,26 @@ public function testClassMetadataInstanceSerialization() // Check state $this->assertTrue(count($cm->getReflectionProperties()) > 0); $this->assertEquals('Doctrine\Tests\Models\CMS', $cm->namespace); - $this->assertInstanceOf('ReflectionClass', $cm->reflClass); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->name); + $this->assertInstanceOf(\ReflectionClass::class, $cm->reflClass); + $this->assertEquals(CMS\CmsUser::class, $cm->name); $this->assertEquals('UserParent', $cm->rootEntityName); - $this->assertEquals( - ['Doctrine\Tests\Models\CMS\One', 'Doctrine\Tests\Models\CMS\Two', 'Doctrine\Tests\Models\CMS\Three'], $cm->subClasses); + $this->assertEquals([CMS\One::class, CMS\Two::class, CMS\Three::class], $cm->subClasses); $this->assertEquals(['UserParent'], $cm->parentClasses); - $this->assertEquals('Doctrine\Tests\Models\CMS\UserRepository', $cm->customRepositoryClassName); + $this->assertEquals(CMS\UserRepository::class, $cm->customRepositoryClassName); $this->assertEquals(['name' => 'disc', 'type' => 'integer', 'fieldName' => 'disc'], $cm->discriminatorColumn); $this->assertTrue($cm->associationMappings['phonenumbers']['type'] == ClassMetadata::ONE_TO_ONE); $this->assertEquals(1, count($cm->associationMappings)); $oneOneMapping = $cm->getAssociationMapping('phonenumbers'); $this->assertTrue($oneOneMapping['fetch'] == ClassMetadata::FETCH_LAZY); $this->assertEquals('phonenumbers', $oneOneMapping['fieldName']); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress', $oneOneMapping['targetEntity']); + $this->assertEquals(CMS\CmsAddress::class, $oneOneMapping['targetEntity']); $this->assertTrue($cm->isReadOnly); $this->assertEquals(['dql' => ['name'=>'dql','query'=>'foo','dql'=>'foo']], $cm->namedQueries); } public function testFieldIsNullable() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); // Explicit Nullable @@ -110,7 +117,7 @@ public function testMapAssociationInGlobalNamespace() public function testMapManyToManyJoinTableDefaults() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->mapManyToMany( [ @@ -132,7 +139,7 @@ public function testMapManyToManyJoinTableDefaults() public function testSerializeManyToManyJoinTableCascade() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->mapManyToMany( [ @@ -141,7 +148,7 @@ public function testSerializeManyToManyJoinTableCascade() ] ); - /* @var $assoc \Doctrine\ORM\Mapping\ManyToManyMapping */ + /* @var $assoc \Doctrine\ORM\Mapping\ManyToMany */ $assoc = $cm->associationMappings['groups']; $assoc = unserialize(serialize($assoc)); @@ -186,7 +193,7 @@ public function testSetInvalidVersionMapping_ThrowsException() $field['fieldName'] = 'foo'; $field['type'] = 'string'; - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); @@ -195,7 +202,7 @@ public function testSetInvalidVersionMapping_ThrowsException() public function testGetSingleIdentifierFieldName_MultipleIdentifierEntity_ThrowsException() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->isIdentifierComposite = true; @@ -205,7 +212,7 @@ public function testGetSingleIdentifierFieldName_MultipleIdentifierEntity_Throws public function testDuplicateAssociationMappingException() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $a1 = ['fieldName' => 'foo', 'sourceEntity' => 'stdClass', 'targetEntity' => 'stdClass', 'mappedBy' => 'foo']; @@ -218,7 +225,7 @@ public function testDuplicateAssociationMappingException() public function testDuplicateColumnName_ThrowsMappingException() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->mapField(['fieldName' => 'name', 'columnName' => 'name']); @@ -229,7 +236,7 @@ public function testDuplicateColumnName_ThrowsMappingException() public function testDuplicateColumnName_DiscriminatorColumn_ThrowsMappingException() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->mapField(['fieldName' => 'name', 'columnName' => 'name']); @@ -240,7 +247,7 @@ public function testDuplicateColumnName_DiscriminatorColumn_ThrowsMappingExcepti public function testDuplicateColumnName_DiscriminatorColumn2_ThrowsMappingException() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->setDiscriminatorColumn(['name' => 'name']); @@ -251,7 +258,7 @@ public function testDuplicateColumnName_DiscriminatorColumn2_ThrowsMappingExcept public function testDuplicateFieldAndAssociationMapping1_ThrowsException() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->mapField(['fieldName' => 'name', 'columnName' => 'name']); @@ -262,7 +269,7 @@ public function testDuplicateFieldAndAssociationMapping1_ThrowsException() public function testDuplicateFieldAndAssociationMapping2_ThrowsException() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->mapOneToOne(['fieldName' => 'name', 'targetEntity' => 'CmsUser']); @@ -276,7 +283,7 @@ public function testDuplicateFieldAndAssociationMapping2_ThrowsException() */ public function testGetTemporaryTableNameSchema() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->setTableName('foo.bar'); @@ -286,7 +293,7 @@ public function testGetTemporaryTableNameSchema() public function testDefaultTableName() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); // When table's name is not given @@ -296,18 +303,18 @@ public function testDefaultTableName() $this->assertEquals('CmsUser', $cm->getTableName()); $this->assertEquals('CmsUser', $cm->table['name']); - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); + $cm = new ClassMetadata(CMS\CmsAddress::class); $cm->initializeReflection(new RuntimeReflectionService()); // When joinTable's name is not given $cm->mapManyToMany( [ - 'fieldName' => 'user', - 'targetEntity' => 'CmsUser', - 'inversedBy' => 'users', - 'joinTable' => [ - 'joinColumns' => [['referencedColumnName' => 'id']], - 'inverseJoinColumns' => [['referencedColumnName' => 'id']] - ] + 'fieldName' => 'user', + 'targetEntity' => 'CmsUser', + 'inversedBy' => 'users', + 'joinTable' => [ + 'joinColumns' => [['referencedColumnName' => 'id']], + 'inverseJoinColumns' => [['referencedColumnName' => 'id']] + ] ] ); $this->assertEquals('cmsaddress_cmsuser', $cm->associationMappings['user']['joinTable']['name']); @@ -315,7 +322,7 @@ public function testDefaultTableName() public function testDefaultJoinColumnName() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); + $cm = new ClassMetadata(CMS\CmsAddress::class); $cm->initializeReflection(new RuntimeReflectionService()); // this is really dirty, but it's the simplest way to test whether @@ -329,7 +336,7 @@ public function testDefaultJoinColumnName() ); $this->assertEquals('user_id', $cm->associationMappings['user']['joinColumns'][0]['name']); - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); + $cm = new ClassMetadata(CMS\CmsAddress::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->mapManyToMany( [ @@ -337,10 +344,10 @@ public function testDefaultJoinColumnName() 'targetEntity' => 'CmsUser', 'inversedBy' => 'users', 'joinTable' => [ - 'name' => 'user_CmsUser', - 'joinColumns' => [['referencedColumnName' => 'id']], - 'inverseJoinColumns' => [['referencedColumnName' => 'id']] - ] + 'name' => 'user_CmsUser', + 'joinColumns' => [['referencedColumnName' => 'id']], + 'inverseJoinColumns' => [['referencedColumnName' => 'id']] + ] ] ); $this->assertEquals('cmsaddress_id', $cm->associationMappings['user']['joinTable']['joinColumns'][0]['name']); @@ -353,8 +360,8 @@ public function testDefaultJoinColumnName() public function testUnderscoreNamingStrategyDefaults() { $namingStrategy = new UnderscoreNamingStrategy(CASE_UPPER); - $oneToOneMetadata = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', $namingStrategy); - $manyToManyMetadata = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', $namingStrategy); + $oneToOneMetadata = new ClassMetadata(CMS\CmsAddress::class, $namingStrategy); + $manyToManyMetadata = new ClassMetadata(CMS\CmsAddress::class, $namingStrategy); $oneToOneMetadata->mapOneToOne( [ @@ -392,7 +399,7 @@ public function testUnderscoreNamingStrategyDefaults() $cm = new ClassMetadata('DoctrineGlobal_Article', $namingStrategy); - $cm->mapManyToMany(['fieldName' => 'author', 'targetEntity' => 'Doctrine\Tests\Models\CMS\CmsUser']); + $cm->mapManyToMany(['fieldName' => 'author', 'targetEntity' => CMS\CmsUser::class]); $this->assertEquals('DOCTRINE_GLOBAL_ARTICLE_CMS_USER', $cm->associationMappings['author']['joinTable']['name']); } @@ -401,7 +408,7 @@ public function testUnderscoreNamingStrategyDefaults() */ public function testSetMultipleIdentifierSetsComposite() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->mapField(['fieldName' => 'name']); @@ -416,11 +423,11 @@ public function testSetMultipleIdentifierSetsComposite() */ public function testMappingNotFound() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $this->expectException(MappingException::class); - $this->expectExceptionMessage("No mapping found for field 'foo' on class 'Doctrine\Tests\Models\CMS\CmsUser'."); + $this->expectExceptionMessage("No mapping found for field 'foo' on class '" . CMS\CmsUser::class . "'."); $cm->getFieldMapping('foo'); } @@ -433,7 +440,7 @@ public function testJoinTableMappingDefaults() $cm = new ClassMetadata('DoctrineGlobal_Article'); $cm->initializeReflection(new RuntimeReflectionService()); - $cm->mapManyToMany(['fieldName' => 'author', 'targetEntity' => 'Doctrine\Tests\Models\CMS\CmsUser']); + $cm->mapManyToMany(['fieldName' => 'author', 'targetEntity' => CMS\CmsUser::class]); $this->assertEquals('doctrineglobal_article_cmsuser', $cm->associationMappings['author']['joinTable']['name']); } @@ -443,14 +450,14 @@ public function testJoinTableMappingDefaults() */ public function testMapIdentifierAssociation() { - $cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); + $cm = new ClassMetadata(DDC117ArticleDetails::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->mapOneToOne( [ 'fieldName' => 'article', 'id' => true, - 'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', + 'targetEntity' => DDC117Article::class, 'joinColumns' => [], ] ); @@ -464,7 +471,7 @@ public function testMapIdentifierAssociation() */ public function testOrphanRemovalIdentifierAssociation() { - $cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); + $cm = new ClassMetadata(DDC117ArticleDetails::class); $cm->initializeReflection(new RuntimeReflectionService()); $this->expectException(MappingException::class); @@ -474,7 +481,7 @@ public function testOrphanRemovalIdentifierAssociation() [ 'fieldName' => 'article', 'id' => true, - 'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', + 'targetEntity' => DDC117Article::class, 'orphanRemoval' => true, 'joinColumns' => [], ] @@ -486,7 +493,7 @@ public function testOrphanRemovalIdentifierAssociation() */ public function testInverseIdentifierAssociation() { - $cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); + $cm = new ClassMetadata(DDC117ArticleDetails::class); $cm->initializeReflection(new RuntimeReflectionService()); $this->expectException(MappingException::class); @@ -497,7 +504,7 @@ public function testInverseIdentifierAssociation() 'fieldName' => 'article', 'id' => true, 'mappedBy' => 'details', // INVERSE! - 'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', + 'targetEntity' => DDC117Article::class, 'joinColumns' => [], ] ); @@ -508,7 +515,7 @@ public function testInverseIdentifierAssociation() */ public function testIdentifierAssociationManyToMany() { - $cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); + $cm = new ClassMetadata(DDC117ArticleDetails::class); $cm->initializeReflection(new RuntimeReflectionService()); $this->expectException(MappingException::class); @@ -518,7 +525,7 @@ public function testIdentifierAssociationManyToMany() [ 'fieldName' => 'article', 'id' => true, - 'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', + 'targetEntity' => DDC117Article::class, 'joinColumns' => [], ] ); @@ -530,9 +537,9 @@ public function testIdentifierAssociationManyToMany() public function testEmptyFieldNameThrowsException() { $this->expectException(MappingException::class); - $this->expectExceptionMessage("The field or association mapping misses the 'fieldName' attribute in entity 'Doctrine\Tests\Models\CMS\CmsUser'."); + $this->expectExceptionMessage("The field or association mapping misses the 'fieldName' attribute in entity '" . CMS\CmsUser::class . "'."); - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->mapField(['fieldName' => '']); @@ -540,7 +547,7 @@ public function testEmptyFieldNameThrowsException() public function testRetrievalOfNamedQueries() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); @@ -561,7 +568,7 @@ public function testRetrievalOfNamedQueries() */ public function testRetrievalOfResultSetMappings() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); @@ -572,7 +579,7 @@ public function testRetrievalOfResultSetMappings() 'name' => 'find-all', 'entities' => [ [ - 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', + 'entityClass' => CMS\CmsUser::class, ], ], ] @@ -583,7 +590,7 @@ public function testRetrievalOfResultSetMappings() public function testExistanceOfNamedQuery() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); @@ -603,7 +610,7 @@ public function testExistanceOfNamedQuery() */ public function testRetrieveOfNamedNativeQuery() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->addNamedNativeQuery( @@ -611,7 +618,7 @@ public function testRetrieveOfNamedNativeQuery() 'name' => 'find-all', 'query' => 'SELECT * FROM cms_users', 'resultSetMapping' => 'result-mapping-name', - 'resultClass' => 'Doctrine\Tests\Models\CMS\CmsUser', + 'resultClass' => CMS\CmsUser::class, ] ); @@ -627,12 +634,12 @@ public function testRetrieveOfNamedNativeQuery() $mapping = $cm->getNamedNativeQuery('find-all'); $this->assertEquals('SELECT * FROM cms_users', $mapping['query']); $this->assertEquals('result-mapping-name', $mapping['resultSetMapping']); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $mapping['resultClass']); + $this->assertEquals(CMS\CmsUser::class, $mapping['resultClass']); $mapping = $cm->getNamedNativeQuery('find-by-id'); $this->assertEquals('SELECT * FROM cms_users WHERE id = ?', $mapping['query']); $this->assertEquals('result-mapping-name', $mapping['resultSetMapping']); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $mapping['resultClass']); + $this->assertEquals(CMS\CmsUser::class, $mapping['resultClass']); } /** @@ -640,7 +647,7 @@ public function testRetrieveOfNamedNativeQuery() */ public function testRetrieveOfSqlResultSetMapping() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->addSqlResultSetMapping( @@ -661,7 +668,7 @@ public function testRetrieveOfSqlResultSetMapping() ] ], [ - 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsEmail', + 'entityClass' => CMS\CmsEmail::class, 'fields' => [ [ 'name' => 'id', @@ -684,11 +691,11 @@ public function testRetrieveOfSqlResultSetMapping() $mapping = $cm->getSqlResultSetMapping('find-all'); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $mapping['entities'][0]['entityClass']); + $this->assertEquals(CMS\CmsUser::class, $mapping['entities'][0]['entityClass']); $this->assertEquals(['name'=>'id','column'=>'id'], $mapping['entities'][0]['fields'][0]); $this->assertEquals(['name'=>'name','column'=>'name'], $mapping['entities'][0]['fields'][1]); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsEmail', $mapping['entities'][1]['entityClass']); + $this->assertEquals(CMS\CmsEmail::class, $mapping['entities'][1]['entityClass']); $this->assertEquals(['name'=>'id','column'=>'id'], $mapping['entities'][1]['fields'][0]); $this->assertEquals(['name'=>'email','column'=>'email'], $mapping['entities'][1]['fields'][1]); @@ -700,7 +707,7 @@ public function testRetrieveOfSqlResultSetMapping() */ public function testExistanceOfSqlResultSetMapping() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->addSqlResultSetMapping( @@ -708,7 +715,7 @@ public function testExistanceOfSqlResultSetMapping() 'name' => 'find-all', 'entities' => [ [ - 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', + 'entityClass' => CMS\CmsUser::class, ], ], ] @@ -723,7 +730,7 @@ public function testExistanceOfSqlResultSetMapping() */ public function testExistanceOfNamedNativeQuery() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); @@ -731,7 +738,7 @@ public function testExistanceOfNamedNativeQuery() [ 'name' => 'find-all', 'query' => 'SELECT * FROM cms_users', - 'resultClass' => 'Doctrine\Tests\Models\CMS\CmsUser', + 'resultClass' => CMS\CmsUser::class, 'resultSetMapping' => 'result-mapping-name' ] ); @@ -742,7 +749,7 @@ public function testExistanceOfNamedNativeQuery() public function testRetrieveOfNamedQuery() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); @@ -761,7 +768,7 @@ public function testRetrieveOfNamedQuery() */ public function testRetrievalOfNamedNativeQueries() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $this->assertEquals(0, count($cm->getNamedNativeQueries())); @@ -770,7 +777,7 @@ public function testRetrievalOfNamedNativeQueries() [ 'name' => 'find-all', 'query' => 'SELECT * FROM cms_users', - 'resultClass' => 'Doctrine\Tests\Models\CMS\CmsUser', + 'resultClass' => CMS\CmsUser::class, 'resultSetMapping' => 'result-mapping-name' ] ); @@ -783,7 +790,7 @@ public function testRetrievalOfNamedNativeQueries() */ public function testSerializeEntityListeners() { - $metadata = new ClassMetadata('Doctrine\Tests\Models\Company\CompanyContract'); + $metadata = new ClassMetadata(CompanyContract::class); $metadata->initializeReflection(new RuntimeReflectionService()); $metadata->addEntityListener(Events::prePersist, 'CompanyContractListener', 'prePersistHandler'); @@ -801,7 +808,7 @@ public function testSerializeEntityListeners() */ public function testNamingCollisionNamedQueryShouldThrowException() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->addNamedQuery( @@ -827,14 +834,14 @@ public function testNamingCollisionNamedQueryShouldThrowException() */ public function testNamingCollisionNamedNativeQueryShouldThrowException() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->addNamedNativeQuery( [ 'name' => 'find-all', 'query' => 'SELECT * FROM cms_users', - 'resultClass' => 'Doctrine\Tests\Models\CMS\CmsUser', + 'resultClass' => CMS\CmsUser::class, 'resultSetMapping' => 'result-mapping-name' ] ); @@ -843,7 +850,7 @@ public function testNamingCollisionNamedNativeQueryShouldThrowException() [ 'name' => 'find-all', 'query' => 'SELECT * FROM cms_users', - 'resultClass' => 'Doctrine\Tests\Models\CMS\CmsUser', + 'resultClass' => CMS\CmsUser::class, 'resultSetMapping' => 'result-mapping-name' ] ); @@ -857,7 +864,7 @@ public function testNamingCollisionNamedNativeQueryShouldThrowException() */ public function testNamingCollisionSqlResultSetMappingShouldThrowException() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->addSqlResultSetMapping( @@ -865,7 +872,7 @@ public function testNamingCollisionSqlResultSetMappingShouldThrowException() 'name' => 'find-all', 'entities' => [ [ - 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', + 'entityClass' => CMS\CmsUser::class, ], ], ] @@ -876,7 +883,7 @@ public function testNamingCollisionSqlResultSetMappingShouldThrowException() 'name' => 'find-all', 'entities' => [ [ - 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', + 'entityClass' => CMS\CmsUser::class, ], ], ] @@ -888,11 +895,11 @@ public function testNamingCollisionSqlResultSetMappingShouldThrowException() */ public function testClassCaseSensitivity() { - $user = new CmsUser(); - $cm = new ClassMetadata('DOCTRINE\TESTS\MODELS\CMS\CMSUSER'); + $user = new CMS\CmsUser(); + $cm = new ClassMetadata(strtoupper(CMS\CmsUser::class)); $cm->initializeReflection(new RuntimeReflectionService()); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->name); + $this->assertEquals(CMS\CmsUser::class, $cm->name); } /** @@ -900,12 +907,12 @@ public function testClassCaseSensitivity() */ public function testLifecycleCallbackNotFound() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->addLifecycleCallback('notfound', 'postLoad'); $this->expectException(MappingException::class); - $this->expectExceptionMessage("Entity 'Doctrine\Tests\Models\CMS\CmsUser' has no method 'notfound' to be registered as lifecycle callback."); + $this->expectExceptionMessage("Entity '" . CMS\CmsUser::class . "' has no method 'notfound' to be registered as lifecycle callback."); $cm->validateLifecycleCallbacks(new RuntimeReflectionService()); } @@ -915,12 +922,12 @@ public function testLifecycleCallbackNotFound() */ public function testTargetEntityNotFound() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->mapManyToOne(['fieldName' => 'address', 'targetEntity' => 'UnknownClass']); $this->expectException(MappingException::class); - $this->expectExceptionMessage("The target-entity Doctrine\Tests\Models\CMS\UnknownClass cannot be found in 'Doctrine\Tests\Models\CMS\CmsUser#address'."); + $this->expectExceptionMessage("The target-entity Doctrine\\Tests\\Models\\CMS\\UnknownClass cannot be found in '" . CMS\CmsUser::class . "#address'."); $cm->validateAssociations(); } @@ -933,7 +940,7 @@ public function testTargetEntityNotFound() */ public function testNameIsMandatoryForNamedQueryMappingException() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->addNamedQuery( [ @@ -950,12 +957,12 @@ public function testNameIsMandatoryForNamedQueryMappingException() */ public function testNameIsMandatoryForNameNativeQueryMappingException() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->addNamedQuery( [ 'query' => 'SELECT * FROM cms_users', - 'resultClass' => 'Doctrine\Tests\Models\CMS\CmsUser', + 'resultClass' => CMS\CmsUser::class, 'resultSetMapping' => 'result-mapping-name' ] ); @@ -969,7 +976,7 @@ public function testNameIsMandatoryForNameNativeQueryMappingException() */ public function testNameIsMandatoryForEntityNameSqlResultSetMappingException() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->addSqlResultSetMapping( [ @@ -989,7 +996,7 @@ public function testNameIsMandatoryForEntityNameSqlResultSetMappingException() */ public function testNameIsMandatoryForDiscriminatorColumnsMappingException() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->setDiscriminatorColumn([]); } @@ -1002,9 +1009,9 @@ public function testNameIsMandatoryForDiscriminatorColumnsMappingException() public function testFullyQualifiedClassNameShouldBeGivenToNamingStrategy() { $namingStrategy = new MyNamespacedNamingStrategy(); - $addressMetadata = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', $namingStrategy); - $articleMetadata = new ClassMetadata('DoctrineGlobal_Article', $namingStrategy); - $routingMetadata = new ClassMetadata('Doctrine\Tests\Models\Routing\RoutingLeg',$namingStrategy); + $addressMetadata = new ClassMetadata(CMS\CmsAddress::class, $namingStrategy); + $articleMetadata = new ClassMetadata(DoctrineGlobal_Article::class, $namingStrategy); + $routingMetadata = new ClassMetadata(RoutingLeg::class, $namingStrategy); $addressMetadata->initializeReflection(new RuntimeReflectionService()); $articleMetadata->initializeReflection(new RuntimeReflectionService()); @@ -1020,7 +1027,7 @@ public function testFullyQualifiedClassNameShouldBeGivenToNamingStrategy() $articleMetadata->mapManyToMany( [ 'fieldName' => 'author', - 'targetEntity' => 'Doctrine\Tests\Models\CMS\CmsUser' + 'targetEntity' => CMS\CmsUser::class ] ); @@ -1036,7 +1043,7 @@ public function testFullyQualifiedClassNameShouldBeGivenToNamingStrategy() public function testFullyQualifiedClassNameShouldBeGivenToNamingStrategyPropertyToColumnName() { $namingStrategy = new MyPrefixNamingStrategy(); - $metadata = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', $namingStrategy); + $metadata = new ClassMetadata(CMS\CmsAddress::class, $namingStrategy); $metadata->initializeReflection(new RuntimeReflectionService()); @@ -1055,11 +1062,11 @@ public function testFullyQualifiedClassNameShouldBeGivenToNamingStrategyProperty */ public function testInvalidCascade() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $this->expectException(MappingException::class); - $this->expectExceptionMessage("You have specified invalid cascade options for Doctrine\Tests\Models\CMS\CmsUser::\$address: 'invalid'; available options: 'remove', 'persist', 'refresh', 'merge', and 'detach'"); + $this->expectExceptionMessage("You have specified invalid cascade options for " . CMS\CmsUser::class . "::\$address: 'invalid'; available options: 'remove', 'persist', 'refresh', 'merge', and 'detach'"); $cm->mapManyToOne(['fieldName' => 'address', 'targetEntity' => 'UnknownClass', 'cascade' => ['invalid']]); } @@ -1071,7 +1078,7 @@ public function testInvalidCascade() */ public function testInvalidPropertyAssociationOverrideNameException() { - $cm = new ClassMetadata('Doctrine\Tests\Models\DDC964\DDC964Admin'); + $cm = new ClassMetadata(DDC964Admin::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->mapManyToOne(['fieldName' => 'address', 'targetEntity' => 'DDC964Address']); @@ -1085,7 +1092,7 @@ public function testInvalidPropertyAssociationOverrideNameException() */ public function testInvalidPropertyAttributeOverrideNameException() { - $cm = new ClassMetadata('Doctrine\Tests\Models\DDC964\DDC964Guest'); + $cm = new ClassMetadata(DDC964Guest::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->mapField(['fieldName' => 'name']); @@ -1099,7 +1106,7 @@ public function testInvalidPropertyAttributeOverrideNameException() */ public function testInvalidOverrideAttributeFieldTypeException() { - $cm = new ClassMetadata('Doctrine\Tests\Models\DDC964\DDC964Guest'); + $cm = new ClassMetadata(DDC964Guest::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->mapField(['fieldName' => 'name', 'type'=>'string']); @@ -1114,7 +1121,7 @@ public function testInvalidOverrideAttributeFieldTypeException() */ public function testInvalidEntityListenerClassException() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->addEntityListener(Events::postLoad, '\InvalidClassName', 'postLoadHandler'); @@ -1128,7 +1135,7 @@ public function testInvalidEntityListenerClassException() */ public function testInvalidEntityListenerMethodException() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->addEntityListener(Events::postLoad, '\Doctrine\Tests\Models\Company\CompanyContractListener', 'invalidMethod'); @@ -1136,7 +1143,7 @@ public function testInvalidEntityListenerMethodException() public function testManyToManySelfReferencingNamingStrategyDefaults() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CustomType\CustomTypeParent'); + $cm = new ClassMetadata(CustomTypeParent::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->mapManyToMany( [ @@ -1163,7 +1170,7 @@ public function testManyToManySelfReferencingNamingStrategyDefaults() */ public function testSetSequenceGeneratorThrowsExceptionWhenSequenceNameIsMissing() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); @@ -1175,7 +1182,7 @@ public function testSetSequenceGeneratorThrowsExceptionWhenSequenceNameIsMissing */ public function testQuotedSequenceName() { - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CMS\CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->setSequenceGeneratorDefinition(['sequenceName' => '`foo`']); @@ -1188,7 +1195,7 @@ public function testQuotedSequenceName() */ public function testIsIdentifierMappedSuperClass() { - $class = new ClassMetadata(__NAMESPACE__ . '\\DDC2700MappedSuperClass'); + $class = new ClassMetadata(DDC2700MappedSuperClass::class); $this->assertFalse($class->isIdentifier('foo')); } @@ -1198,9 +1205,9 @@ public function testIsIdentifierMappedSuperClass() */ public function testCanInstantiateInternalPhpClassSubclass() { - $classMetadata = new ClassMetadata(__NAMESPACE__ . '\\MyArrayObjectEntity'); + $classMetadata = new ClassMetadata(MyArrayObjectEntity::class); - $this->assertInstanceOf(__NAMESPACE__ . '\\MyArrayObjectEntity', $classMetadata->newInstance()); + $this->assertInstanceOf(MyArrayObjectEntity::class, $classMetadata->newInstance()); } /** @@ -1209,21 +1216,21 @@ public function testCanInstantiateInternalPhpClassSubclass() public function testCanInstantiateInternalPhpClassSubclassFromUnserializedMetadata() { /* @var $classMetadata ClassMetadata */ - $classMetadata = unserialize(serialize(new ClassMetadata(__NAMESPACE__ . '\\MyArrayObjectEntity'))); + $classMetadata = unserialize(serialize(new ClassMetadata(MyArrayObjectEntity::class))); $classMetadata->wakeupReflection(new RuntimeReflectionService()); - $this->assertInstanceOf(__NAMESPACE__ . '\\MyArrayObjectEntity', $classMetadata->newInstance()); + $this->assertInstanceOf(MyArrayObjectEntity::class, $classMetadata->newInstance()); } public function testWakeupReflectionWithEmbeddableAndStaticReflectionService() { - $classMetadata = new ClassMetadata('Doctrine\Tests\ORM\Mapping\TestEntity1'); + $classMetadata = new ClassMetadata(TestEntity1::class); $classMetadata->mapEmbedded( [ 'fieldName' => 'test', - 'class' => 'Doctrine\Tests\ORM\Mapping\TestEntity1', + 'class' => TestEntity1::class, 'columnPrefix' => false, ] ); @@ -1231,7 +1238,7 @@ public function testWakeupReflectionWithEmbeddableAndStaticReflectionService() $field = [ 'fieldName' => 'test.embeddedProperty', 'type' => 'string', - 'originalClass' => 'Doctrine\Tests\ORM\Mapping\TestEntity1', + 'originalClass' => TestEntity1::class, 'declaredField' => 'test', 'originalField' => 'embeddedProperty' ]; @@ -1244,7 +1251,7 @@ public function testWakeupReflectionWithEmbeddableAndStaticReflectionService() public function testGetColumnNamesWithGivenFieldNames() { - $metadata = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $metadata = new ClassMetadata(CMS\CmsUser::class); $metadata->initializeReflection(new RuntimeReflectionService()); $metadata->mapField(['fieldName' => 'status', 'type' => 'string', 'columnName' => 'foo']); diff --git a/tests/Doctrine/Tests/ORM/Mapping/DefaultQuoteStrategyTest.php b/tests/Doctrine/Tests/ORM/Mapping/DefaultQuoteStrategyTest.php index 9c20cb8b9dd..765518c41bb 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/DefaultQuoteStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/DefaultQuoteStrategyTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Mapping; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\ORM\Mapping\DefaultQuoteStrategy; use Doctrine\Tests\Models\NonPublicSchemaJoins\User as NonPublicSchemaUser; use Doctrine\Tests\OrmTestCase; @@ -20,10 +21,10 @@ class DefaultQuoteStrategyTest extends OrmTestCase public function testGetJoinTableName() { $em = $this->_getTestEntityManager(); - $metadata = $em->getClassMetadata(NonPublicSchemaUser::CLASSNAME); - /* @var $platform \Doctrine\DBAL\Platforms\AbstractPlatform */ + $metadata = $em->getClassMetadata(NonPublicSchemaUser::class); $strategy = new DefaultQuoteStrategy(); - $platform = $this->getMockForAbstractClass('Doctrine\DBAL\Platforms\AbstractPlatform'); + /* @var $platform AbstractPlatform */ + $platform = $this->getMockForAbstractClass(AbstractPlatform::class); $this->assertSame( 'readers.author_reader', diff --git a/tests/Doctrine/Tests/ORM/Mapping/FieldBuilderTest.php b/tests/Doctrine/Tests/ORM/Mapping/FieldBuilderTest.php index 67a0ebce032..0ec0798aae1 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/FieldBuilderTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/FieldBuilderTest.php @@ -4,13 +4,14 @@ use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder; use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\OrmTestCase; class FieldBuilderTest extends OrmTestCase { public function testCustomIdGeneratorCanBeSet() { - $cmBuilder = new ClassMetadataBuilder(new ClassMetadataInfo('Doctrine\Tests\Models\CMS\CmsUser')); + $cmBuilder = new ClassMetadataBuilder(new ClassMetadataInfo(CmsUser::class)); $fieldBuilder = $cmBuilder->createField('aField', 'string'); diff --git a/tests/Doctrine/Tests/ORM/Mapping/PHPMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/PHPMappingDriverTest.php index cfc7f0cc8d7..39b5525b295 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/PHPMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/PHPMappingDriverTest.php @@ -2,8 +2,10 @@ namespace Doctrine\Tests\ORM\Mapping; -use Doctrine\ORM\Mapping\ClassMetadata, - Doctrine\Common\Persistence\Mapping\Driver\PHPDriver; +use Doctrine\Common\Persistence\Mapping\Driver\PHPDriver; +use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\Tests\Models\DDC889\DDC889Class; +use Doctrine\Tests\ORM\Mapping; class PHPMappingDriverTest extends AbstractMappingDriverTest { @@ -30,7 +32,7 @@ protected function _loadDriver() */ public function testinvalidEntityOrMappedSuperClassShouldMentionParentClasses() { - $this->createClassMetadata('Doctrine\Tests\Models\DDC889\DDC889Class'); + $this->createClassMetadata(DDC889Class::class); } /** @@ -39,10 +41,9 @@ public function testinvalidEntityOrMappedSuperClassShouldMentionParentClasses() */ public function testFailingSecondLevelCacheAssociation() { - $className = 'Doctrine\Tests\ORM\Mapping\PHPSLC'; $mappingDriver = $this->_loadDriver(); - $class = new ClassMetadata($className); - $mappingDriver->loadMetadataForClass($className, $class); + $class = new ClassMetadata(Mapping\PHPSLC::class); + $mappingDriver->loadMetadataForClass(Mapping\PHPSLC::class, $class); } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php index 0afb3698dcd..2af97169c80 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php @@ -3,8 +3,13 @@ namespace Doctrine\Tests\ORM\Mapping; use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; -use Doctrine\ORM\Mapping\DefaultQuoteStrategy; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Mapping\DefaultQuoteStrategy; +use Doctrine\ORM\Mapping\QuoteStrategy; +use Doctrine\Tests\Models\CMS\CmsAddress; +use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\Models\DDC117\DDC117Article; +use Doctrine\Tests\Models\DDC117\DDC117ArticleDetails; use Doctrine\Tests\OrmTestCase; /** @@ -48,18 +53,18 @@ public function testConfiguration() $em = $this->_getTestEntityManager(); $config = $em->getConfiguration(); - $this->assertInstanceOf('Doctrine\ORM\Mapping\QuoteStrategy', $config->getQuoteStrategy()); - $this->assertInstanceOf('Doctrine\ORM\Mapping\DefaultQuoteStrategy', $config->getQuoteStrategy()); + $this->assertInstanceOf(QuoteStrategy::class, $config->getQuoteStrategy()); + $this->assertInstanceOf(DefaultQuoteStrategy::class, $config->getQuoteStrategy()); $config->setQuoteStrategy(new MyQuoteStrategy()); - $this->assertInstanceOf('Doctrine\ORM\Mapping\QuoteStrategy', $config->getQuoteStrategy()); - $this->assertInstanceOf('Doctrine\Tests\ORM\Mapping\MyQuoteStrategy', $config->getQuoteStrategy()); + $this->assertInstanceOf(QuoteStrategy::class, $config->getQuoteStrategy()); + $this->assertInstanceOf(MyQuoteStrategy::class, $config->getQuoteStrategy()); } public function testGetColumnName() { - $cm = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = $this->createClassMetadata(CmsUser::class); $cm->mapField(['fieldName' => 'name', 'columnName' => '`name`']); $cm->mapField(['fieldName' => 'id', 'columnName' => 'id']); @@ -69,20 +74,20 @@ public function testGetColumnName() public function testGetTableName() { - $cm = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = $this->createClassMetadata(CmsUser::class); $cm->setPrimaryTable(['name'=>'`cms_user`']); - $this->assertEquals('"cms_user"' ,$this->strategy->getTableName($cm, $this->platform)); + $this->assertEquals('"cms_user"', $this->strategy->getTableName($cm, $this->platform)); - $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm = new ClassMetadata(CmsUser::class); $cm->initializeReflection(new RuntimeReflectionService()); $cm->setPrimaryTable(['name'=>'cms_user']); - $this->assertEquals('cms_user' ,$this->strategy->getTableName($cm, $this->platform)); + $this->assertEquals('cms_user', $this->strategy->getTableName($cm, $this->platform)); } public function testJoinTableName() { - $cm1 = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); - $cm2 = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); + $cm1 = $this->createClassMetadata(CmsAddress::class); + $cm2 = $this->createClassMetadata(CmsAddress::class); $cm1->mapManyToMany( [ @@ -113,8 +118,8 @@ public function testJoinTableName() public function testIdentifierColumnNames() { - $cm1 = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); - $cm2 = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); + $cm1 = $this->createClassMetadata(CmsAddress::class); + $cm2 = $this->createClassMetadata(CmsAddress::class); $cm1->mapField( [ @@ -148,13 +153,13 @@ public function testColumnAlias() public function testQuoteIdentifierJoinColumns() { - $cm = $this->createClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); + $cm = $this->createClassMetadata(DDC117ArticleDetails::class); $cm->mapOneToOne( [ 'id' => true, 'fieldName' => 'article', - 'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', + 'targetEntity' => DDC117Article::class, 'joinColumns' => [ [ 'name' => '`article`' @@ -168,13 +173,13 @@ public function testQuoteIdentifierJoinColumns() public function testJoinColumnName() { - $cm = $this->createClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); + $cm = $this->createClassMetadata(DDC117ArticleDetails::class); $cm->mapOneToOne( [ 'id' => true, 'fieldName' => 'article', - 'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', + 'targetEntity' => DDC117Article::class, 'joinColumns' => [ [ 'name' => '`article`' @@ -189,13 +194,13 @@ public function testJoinColumnName() public function testReferencedJoinColumnName() { - $cm = $this->createClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); + $cm = $this->createClassMetadata(DDC117ArticleDetails::class); $cm->mapOneToOne( [ 'id' => true, 'fieldName' => 'article', - 'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article', + 'targetEntity' => DDC117Article::class, 'joinColumns' => [ [ 'name' => '`article`' diff --git a/tests/Doctrine/Tests/ORM/Mapping/Reflection/ReflectionPropertiesGetterTest.php b/tests/Doctrine/Tests/ORM/Mapping/Reflection/ReflectionPropertiesGetterTest.php index 1b18deb114d..06a895159c5 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/Reflection/ReflectionPropertiesGetterTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/Reflection/ReflectionPropertiesGetterTest.php @@ -20,7 +20,7 @@ class ReflectionPropertiesGetterTest extends PHPUnit_Framework_TestCase public function testRetrievesProperties() { $properties = (new ReflectionPropertiesGetter(new RuntimeReflectionService())) - ->getProperties(ClassWithMixedProperties::CLASSNAME); + ->getProperties(ClassWithMixedProperties::class); $this->assertCount(5, $properties); @@ -32,7 +32,7 @@ public function testRetrievesProperties() public function testRetrievedInstancesAreNotStatic() { $properties = (new ReflectionPropertiesGetter(new RuntimeReflectionService())) - ->getProperties(ClassWithMixedProperties::CLASSNAME); + ->getProperties(ClassWithMixedProperties::class); foreach ($properties as $property) { $this->assertFalse($property->isStatic()); @@ -42,18 +42,18 @@ public function testRetrievedInstancesAreNotStatic() public function testExpectedKeys() { $properties = (new ReflectionPropertiesGetter(new RuntimeReflectionService())) - ->getProperties(ClassWithMixedProperties::CLASSNAME); + ->getProperties(ClassWithMixedProperties::class); $this->assertArrayHasKey( - "\0" . ClassWithMixedProperties::CLASSNAME . "\0" . 'privateProperty', + "\0" . ClassWithMixedProperties::class . "\0" . 'privateProperty', $properties ); $this->assertArrayHasKey( - "\0" . ClassWithMixedProperties::CLASSNAME . "\0" . 'privatePropertyOverride', + "\0" . ClassWithMixedProperties::class . "\0" . 'privatePropertyOverride', $properties ); $this->assertArrayHasKey( - "\0" . ParentClass::CLASSNAME . "\0" . 'privatePropertyOverride', + "\0" . ParentClass::class . "\0" . 'privatePropertyOverride', $properties ); $this->assertArrayHasKey( @@ -70,7 +70,7 @@ public function testPropertiesAreAccessible() { $object = new ClassWithMixedProperties(); $properties = (new ReflectionPropertiesGetter(new RuntimeReflectionService())) - ->getProperties(ClassWithMixedProperties::CLASSNAME); + ->getProperties(ClassWithMixedProperties::class); foreach ($properties as $property) { $this->assertSame($property->getName(), $property->getValue($object)); @@ -82,8 +82,8 @@ public function testPropertyGetterIsIdempotent() $getter = (new ReflectionPropertiesGetter(new RuntimeReflectionService())); $this->assertSame( - $getter->getProperties(ClassWithMixedProperties::CLASSNAME), - $getter->getProperties(ClassWithMixedProperties::CLASSNAME) + $getter->getProperties(ClassWithMixedProperties::class), + $getter->getProperties(ClassWithMixedProperties::class) ); } @@ -95,10 +95,10 @@ public function testPropertyGetterWillSkipPropertiesNotRetrievedByTheRuntimeRefl $reflectionService ->expects($this->exactly(2)) ->method('getClass') - ->with($this->logicalOr(ClassWithMixedProperties::CLASSNAME, ParentClass::CLASSNAME)) + ->with($this->logicalOr(ClassWithMixedProperties::class, ParentClass::class)) ->will($this->returnValueMap([ - [ClassWithMixedProperties::CLASSNAME, new ReflectionClass(ClassWithMixedProperties::CLASSNAME)], - [ParentClass::CLASSNAME, new ReflectionClass(ParentClass::CLASSNAME)], + [ClassWithMixedProperties::class, new ReflectionClass(ClassWithMixedProperties::class)], + [ParentClass::class, new ReflectionClass(ParentClass::class)], ])); $reflectionService @@ -107,7 +107,7 @@ public function testPropertyGetterWillSkipPropertiesNotRetrievedByTheRuntimeRefl $getter = (new ReflectionPropertiesGetter($reflectionService)); - $this->assertEmpty($getter->getProperties(ClassWithMixedProperties::CLASSNAME)); + $this->assertEmpty($getter->getProperties(ClassWithMixedProperties::class)); } public function testPropertyGetterWillSkipClassesNotRetrievedByTheRuntimeReflectionService() @@ -118,12 +118,12 @@ public function testPropertyGetterWillSkipClassesNotRetrievedByTheRuntimeReflect $reflectionService ->expects($this->once()) ->method('getClass') - ->with(ClassWithMixedProperties::CLASSNAME); + ->with(ClassWithMixedProperties::class); $reflectionService->expects($this->never())->method('getAccessibleProperty'); $getter = (new ReflectionPropertiesGetter($reflectionService)); - $this->assertEmpty($getter->getProperties(ClassWithMixedProperties::CLASSNAME)); + $this->assertEmpty($getter->getProperties(ClassWithMixedProperties::class)); } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/ReflectionEmbeddedPropertyTest.php b/tests/Doctrine/Tests/ORM/Mapping/ReflectionEmbeddedPropertyTest.php index d6f6291499b..04ed194a62f 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ReflectionEmbeddedPropertyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ReflectionEmbeddedPropertyTest.php @@ -4,7 +4,11 @@ use Doctrine\Instantiator\Instantiator; use Doctrine\ORM\Mapping\ReflectionEmbeddedProperty; +use Doctrine\Tests\Models\Generic\BooleanModel; use Doctrine\Tests\Models\Mapping\Entity; +use Doctrine\Tests\Models\Reflection\AbstractEmbeddable; +use Doctrine\Tests\Models\Reflection\ArrayObjectExtendingClass; +use Doctrine\Tests\Models\Reflection\ConcreteEmbeddable; use ReflectionProperty; /** @@ -71,72 +75,36 @@ public function getTestedReflectionProperties() { return [ [ - $this->getReflectionProperty( - 'Doctrine\\Tests\\Models\\Generic\\BooleanModel', - 'id' - ), - $this->getReflectionProperty( - 'Doctrine\\Tests\\Models\\Generic\\BooleanModel', - 'id' - ), - 'Doctrine\\Tests\\Models\\Generic\\BooleanModel' + $this->getReflectionProperty(BooleanModel::class, 'id'), + $this->getReflectionProperty(BooleanModel::class, 'id'), + BooleanModel::class ], // reflection on embeddables that have properties defined in abstract ancestors: [ - $this->getReflectionProperty( - 'Doctrine\\Tests\\Models\\Generic\\BooleanModel', - 'id' - ), - $this->getReflectionProperty( - 'Doctrine\\Tests\\Models\\Reflection\\AbstractEmbeddable', - 'propertyInAbstractClass' - ), - 'Doctrine\\Tests\\Models\\Reflection\\ConcreteEmbeddable' + $this->getReflectionProperty(BooleanModel::class, 'id'), + $this->getReflectionProperty(AbstractEmbeddable::class, 'propertyInAbstractClass'), + ConcreteEmbeddable::class ], [ - $this->getReflectionProperty( - 'Doctrine\\Tests\\Models\\Generic\\BooleanModel', - 'id' - ), - $this->getReflectionProperty( - 'Doctrine\\Tests\\Models\\Reflection\\ConcreteEmbeddable', - 'propertyInConcreteClass' - ), - 'Doctrine\\Tests\\Models\\Reflection\\ConcreteEmbeddable' + $this->getReflectionProperty(BooleanModel::class, 'id'), + $this->getReflectionProperty(ConcreteEmbeddable::class, 'propertyInConcreteClass'), + ConcreteEmbeddable::class ], // reflection on classes extending internal PHP classes: [ - $this->getReflectionProperty( - 'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass', - 'publicProperty' - ), - $this->getReflectionProperty( - 'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass', - 'privateProperty' - ), - 'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass' + $this->getReflectionProperty(ArrayObjectExtendingClass::class, 'publicProperty'), + $this->getReflectionProperty(ArrayObjectExtendingClass::class, 'privateProperty'), + ArrayObjectExtendingClass::class ], [ - $this->getReflectionProperty( - 'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass', - 'publicProperty' - ), - $this->getReflectionProperty( - 'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass', - 'protectedProperty' - ), - 'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass' + $this->getReflectionProperty(ArrayObjectExtendingClass::class, 'publicProperty'), + $this->getReflectionProperty(ArrayObjectExtendingClass::class, 'protectedProperty'), + ArrayObjectExtendingClass::class ], [ - $this->getReflectionProperty( - 'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass', - 'publicProperty' - ), - $this->getReflectionProperty( - 'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass', - 'publicProperty' - ), - 'Doctrine\\Tests\\Models\\Reflection\\ArrayObjectExtendingClass' + $this->getReflectionProperty(ArrayObjectExtendingClass::class, 'publicProperty'), + $this->getReflectionProperty(ArrayObjectExtendingClass::class, 'publicProperty'), + ArrayObjectExtendingClass::class ], ]; } diff --git a/tests/Doctrine/Tests/ORM/Mapping/StaticPHPMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/StaticPHPMappingDriverTest.php index 598a42ce88a..e374e135e38 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/StaticPHPMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/StaticPHPMappingDriverTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM\Mapping; use Doctrine\Common\Persistence\Mapping\Driver\StaticPHPDriver; +use Doctrine\Tests\Models\DDC889\DDC889Class; class StaticPHPMappingDriverTest extends AbstractMappingDriverTest { @@ -19,7 +20,7 @@ protected function _loadDriver() */ public function testinvalidEntityOrMappedSuperClassShouldMentionParentClasses() { - $this->createClassMetadata('Doctrine\Tests\Models\DDC889\DDC889Class'); + $this->createClassMetadata(DDC889Class::class); } /** diff --git a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php index 6d5dde33106..cc543b8919f 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php @@ -6,6 +6,13 @@ use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\Driver\XmlDriver; +use Doctrine\Tests\Models\DDC117\DDC117Translation; +use Doctrine\Tests\Models\DDC3293\DDC3293User; +use Doctrine\Tests\Models\DDC3293\DDC3293UserPrefixed; +use Doctrine\Tests\Models\DDC889\DDC889Class; +use Doctrine\Tests\Models\Generic\SerializationModel; +use Doctrine\Tests\Models\ValueObjects\Name; +use Doctrine\Tests\Models\ValueObjects\Person; class XmlMappingDriverTest extends AbstractMappingDriverTest { @@ -16,17 +23,16 @@ protected function _loadDriver() public function testClassTableInheritanceDiscriminatorMap() { - $className = 'Doctrine\Tests\ORM\Mapping\CTI'; $mappingDriver = $this->_loadDriver(); - $class = new ClassMetadata($className); + $class = new ClassMetadata(CTI::class); $class->initializeReflection(new RuntimeReflectionService()); - $mappingDriver->loadMetadataForClass($className, $class); + $mappingDriver->loadMetadataForClass(CTI::class, $class); $expectedMap = [ - 'foo' => 'Doctrine\Tests\ORM\Mapping\CTIFoo', - 'bar' => 'Doctrine\Tests\ORM\Mapping\CTIBar', - 'baz' => 'Doctrine\Tests\ORM\Mapping\CTIBaz', + 'foo' => CTIFoo::class, + 'bar' => CTIBar::class, + 'baz' => CTIBaz::class, ]; $this->assertEquals(3, count($class->discriminatorMap)); @@ -39,11 +45,10 @@ public function testClassTableInheritanceDiscriminatorMap() */ public function testFailingSecondLevelCacheAssociation() { - $className = 'Doctrine\Tests\ORM\Mapping\XMLSLC'; $mappingDriver = $this->_loadDriver(); - $class = new ClassMetadata($className); - $mappingDriver->loadMetadataForClass($className, $class); + $class = new ClassMetadata(XMLSLC::class); + $mappingDriver->loadMetadataForClass(XMLSLC::class, $class); } public function testIdentifierWithAssociationKey() @@ -55,7 +60,7 @@ public function testIdentifierWithAssociationKey() $em->getConfiguration()->setMetadataDriverImpl($driver); $factory->setEntityManager($em); - $class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC117\DDC117Translation'); + $class = $factory->getMetadataFor(DDC117Translation::class); $this->assertEquals(['language', 'article'], $class->identifier); $this->assertArrayHasKey('article', $class->associationMappings); @@ -66,7 +71,7 @@ public function testIdentifierWithAssociationKey() public function testEmbeddableMapping() { - $class = $this->createClassMetadata('Doctrine\Tests\Models\ValueObjects\Name'); + $class = $this->createClassMetadata(Name::class); $this->assertEquals(true, $class->isEmbeddedClass); } @@ -86,8 +91,7 @@ public function testEmbeddedMappingsWithUseColumnPrefix() $this->assertEquals( '__prefix__', - $factory - ->getMetadataFor('Doctrine\Tests\Models\DDC3293\DDC3293UserPrefixed') + $factory->getMetadataFor(DDC3293UserPrefixed::class) ->embeddedClasses['address']['columnPrefix'] ); } @@ -106,20 +110,19 @@ public function testEmbeddedMappingsWithFalseUseColumnPrefix() $factory->setEntityManager($em); $this->assertFalse( - $factory - ->getMetadataFor('Doctrine\Tests\Models\DDC3293\DDC3293User') + $factory->getMetadataFor(DDC3293User::class) ->embeddedClasses['address']['columnPrefix'] ); } public function testEmbeddedMapping() { - $class = $this->createClassMetadata('Doctrine\Tests\Models\ValueObjects\Person'); + $class = $this->createClassMetadata(Person::class); $this->assertEquals( [ 'name' => [ - 'class' => 'Doctrine\Tests\Models\ValueObjects\Name', + 'class' => Name::class, 'columnPrefix' => 'nm_', 'declaredField' => null, 'originalField' => null, @@ -137,7 +140,7 @@ public function testEmbeddedMapping() */ public function testInvalidMappingFileException() { - $this->createClassMetadata('Doctrine\Tests\Models\Generic\SerializationModel'); + $this->createClassMetadata(SerializationModel::class); } /** @@ -178,7 +181,7 @@ static public function dataValidSchema() */ public function testinvalidEntityOrMappedSuperClassShouldMentionParentClasses() { - $this->createClassMetadata('Doctrine\Tests\Models\DDC889\DDC889Class'); + $this->createClassMetadata(DDC889Class::class); } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php index a739c2b61b3..b6feb405290 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php @@ -2,15 +2,19 @@ namespace Doctrine\Tests\ORM\Mapping; -use Doctrine\ORM\Mapping\ClassMetadata, - Doctrine\ORM\Mapping\Driver\YamlDriver; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataFactory; +use Doctrine\ORM\Mapping\Driver\YamlDriver; +use Doctrine\Tests\Models\DirectoryTree\Directory; +use Doctrine\Tests\Models\DirectoryTree\File; +use Doctrine\Tests\Models\Generic\SerializationModel; +use Symfony\Component\Yaml\Yaml; class YamlMappingDriverTest extends AbstractMappingDriverTest { protected function _loadDriver() { - if (!class_exists('Symfony\Component\Yaml\Yaml', true)) { + if (!class_exists(Yaml::class, true)) { $this->markTestSkipped('Please install Symfony YAML Component into the include path of your PHP installation.'); } @@ -32,13 +36,13 @@ public function testJoinTablesWithMappedSuperclassForYamlDriver() $factory = new ClassMetadataFactory(); $factory->setEntityManager($em); - $classPage = new ClassMetadata('Doctrine\Tests\Models\DirectoryTree\File'); - $classPage = $factory->getMetadataFor('Doctrine\Tests\Models\DirectoryTree\File'); - $this->assertEquals('Doctrine\Tests\Models\DirectoryTree\File', $classPage->associationMappings['parentDirectory']['sourceEntity']); + $classPage = new ClassMetadata(File::class); + $classPage = $factory->getMetadataFor(File::class); + $this->assertEquals(File::class, $classPage->associationMappings['parentDirectory']['sourceEntity']); - $classDirectory = new ClassMetadata('Doctrine\Tests\Models\DirectoryTree\Directory'); - $classDirectory = $factory->getMetadataFor('Doctrine\Tests\Models\DirectoryTree\Directory'); - $this->assertEquals('Doctrine\Tests\Models\DirectoryTree\Directory', $classDirectory->associationMappings['parentDirectory']['sourceEntity']); + $classDirectory = new ClassMetadata(Directory::class); + $classDirectory = $factory->getMetadataFor(Directory::class); + $this->assertEquals(Directory::class, $classDirectory->associationMappings['parentDirectory']['sourceEntity']); } /** @@ -49,7 +53,7 @@ public function testJoinTablesWithMappedSuperclassForYamlDriver() */ public function testInvalidMappingFileException() { - $this->createClassMetadata('Doctrine\Tests\Models\Generic\SerializationModel'); + $this->createClassMetadata(SerializationModel::class); } /** @@ -57,7 +61,7 @@ public function testInvalidMappingFileException() */ public function testSpacesShouldBeIgnoredWhenUseExplode() { - $metadata = $this->createClassMetadata(__NAMESPACE__.'\DDC2069Entity'); + $metadata = $this->createClassMetadata(DDC2069Entity::class); $unique = $metadata->table['uniqueConstraints'][0]['columns']; $indexes = $metadata->table['indexes'][0]['columns']; diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsAddress.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsAddress.php index 2dce0c41628..7238eb15a05 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsAddress.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsAddress.php @@ -1,5 +1,8 @@ setPrimaryTable( [ 'name' => 'company_person', @@ -48,7 +51,7 @@ [ 'name' => 'find-by-id', 'query' => 'SELECT * FROM cms_addresses WHERE id = ?', - 'resultClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsAddress', + 'resultClass' => CmsAddress::class, ] ); @@ -81,7 +84,7 @@ 'column' => 'country', ], ], - 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsAddress', + 'entityClass' => CmsAddress::class, ], ], ] @@ -93,7 +96,7 @@ 'columns' => [], 'entities' => [ [ - 'entityClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsAddress', + 'entityClass' => CmsAddress::class, 'fields' => [] ] ] @@ -111,14 +114,14 @@ ] ); -$metadata->addEntityListener(\Doctrine\ORM\Events::postPersist, 'CmsAddressListener', 'postPersist'); -$metadata->addEntityListener(\Doctrine\ORM\Events::prePersist, 'CmsAddressListener', 'prePersist'); +$metadata->addEntityListener(Events::postPersist, 'CmsAddressListener', 'postPersist'); +$metadata->addEntityListener(Events::prePersist, 'CmsAddressListener', 'prePersist'); -$metadata->addEntityListener(\Doctrine\ORM\Events::postUpdate, 'CmsAddressListener', 'postUpdate'); -$metadata->addEntityListener(\Doctrine\ORM\Events::preUpdate, 'CmsAddressListener', 'preUpdate'); +$metadata->addEntityListener(Events::postUpdate, 'CmsAddressListener', 'postUpdate'); +$metadata->addEntityListener(Events::preUpdate, 'CmsAddressListener', 'preUpdate'); -$metadata->addEntityListener(\Doctrine\ORM\Events::postRemove, 'CmsAddressListener', 'postRemove'); -$metadata->addEntityListener(\Doctrine\ORM\Events::preRemove, 'CmsAddressListener', 'preRemove'); +$metadata->addEntityListener(Events::postRemove, 'CmsAddressListener', 'postRemove'); +$metadata->addEntityListener(Events::preRemove, 'CmsAddressListener', 'preRemove'); -$metadata->addEntityListener(\Doctrine\ORM\Events::preFlush, 'CmsAddressListener', 'preFlush'); -$metadata->addEntityListener(\Doctrine\ORM\Events::postLoad, 'CmsAddressListener', 'postLoad'); +$metadata->addEntityListener(Events::preFlush, 'CmsAddressListener', 'preFlush'); +$metadata->addEntityListener(Events::postLoad, 'CmsAddressListener', 'postLoad'); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsUser.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsUser.php index c707f3fdfaf..4b0075ecfe4 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsUser.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsUser.php @@ -1,5 +1,8 @@ setPrimaryTable( [ 'name' => 'cms_users', @@ -10,7 +13,7 @@ [ 'name' => 'fetchIdAndUsernameWithResultClass', 'query' => 'SELECT id, username FROM cms_users WHERE username = ?', - 'resultClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', + 'resultClass' => CmsUser::class, ] ); @@ -18,7 +21,7 @@ [ 'name' => 'fetchAllColumns', 'query' => 'SELECT * FROM cms_users WHERE username = ?', - 'resultClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', + 'resultClass' => CmsUser::class, ] ); @@ -90,7 +93,7 @@ 'column' => 'a_id', ], ], - 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', + 'entityClass' => CmsUser::class, 'discriminatorColumn' => null ], ], @@ -121,7 +124,7 @@ 'column' => 'number', ], ], - 'entityClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', + 'entityClass' => CmsUser::class, 'discriminatorColumn' => null ], ], @@ -148,7 +151,7 @@ 'column' => 'status', ] ], - 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', + 'entityClass' => CmsUser::class, 'discriminatorColumn' => null ] ], @@ -179,7 +182,7 @@ 'column' => 'u_status', ] ], - 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', + 'entityClass' => CmsUser::class, 'discriminatorColumn' => null, ], [ @@ -197,7 +200,7 @@ 'column' => 'a_country', ], ], - 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsAddress', + 'entityClass' => CmsAddress::class, 'discriminatorColumn' => null, ], ], diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Cache.City.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Cache.City.php index 4626cd46b06..6ee9a78fc0b 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Cache.City.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Cache.City.php @@ -1,6 +1,9 @@ setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE); $metadata->setPrimaryTable(['name' => 'cache_city']); @@ -32,7 +35,7 @@ $metadata->mapOneToOne( [ 'fieldName' => 'state', - 'targetEntity' => 'Doctrine\\Tests\\Models\\Cache\\State', + 'targetEntity' => State::class, 'inversedBy' => 'cities', 'joinColumns' => [ @@ -51,7 +54,7 @@ $metadata->mapManyToMany( [ 'fieldName' => 'travels', - 'targetEntity' => 'Doctrine\\Tests\\Models\\Cache\\Travel', + 'targetEntity' => Travel::class, 'mappedBy' => 'visitedCities', ] ); @@ -59,7 +62,7 @@ $metadata->mapOneToMany( [ 'fieldName' => 'attractions', - 'targetEntity' => 'Doctrine\\Tests\\Models\\Cache\\Attraction', + 'targetEntity' => Attraction::class, 'mappedBy' => 'city', 'orderBy' => ['name' => 'ASC',], ] diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyPerson.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyPerson.php index 9402cc1edfd..d92bd218b8f 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyPerson.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyPerson.php @@ -1,5 +1,7 @@ setPrimaryTable( [ 'name' => 'company_person', @@ -10,7 +12,7 @@ [ 'name' => 'fetchAllWithResultClass', 'query' => 'SELECT id, name, discr FROM company_persons ORDER BY name', - 'resultClass' => 'Doctrine\\Tests\\Models\\Company\\CompanyPerson', + 'resultClass' => CompanyPerson::class, ] ); @@ -38,7 +40,7 @@ 'column' => 'name', ], ], - 'entityClass' => 'Doctrine\Tests\Models\Company\CompanyPerson', + 'entityClass' => CompanyPerson::class, 'discriminatorColumn' => 'discriminator', ], ], diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869Payment.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869Payment.php index 3a9b84793f5..1f3f12b2d5f 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869Payment.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869Payment.php @@ -1,6 +1,7 @@ mapField( [ @@ -17,5 +18,5 @@ ] ); $metadata->isMappedSuperclass = true; -$metadata->setCustomRepositoryClass("Doctrine\Tests\Models\DDC869\DDC869PaymentRepository"); +$metadata->setCustomRepositoryClass(DDC869PaymentRepository::class); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC889.DDC889SuperClass.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC889.DDC889SuperClass.php index c3ee069df57..f7f4816a8a3 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC889.DDC889SuperClass.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC889.DDC889SuperClass.php @@ -1,6 +1,7 @@ mapField( [ @@ -9,5 +10,5 @@ ] ); $metadata->isMappedSuperclass = true; -$metadata->setCustomRepositoryClass("Doctrine\Tests\Models\DDC889\DDC889SuperClass"); +$metadata->setCustomRepositoryClass(DDC889SuperClass::class); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Animal.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Animal.php index 3adc2a7a6ca..5000a68a229 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Animal.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Animal.php @@ -1,6 +1,8 @@ setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE); @@ -14,8 +16,8 @@ ); $metadata->setDiscriminatorMap( [ - 'cat' => 'Doctrine\\Tests\\ORM\\Mapping\\Cat', - 'dog' => 'Doctrine\\Tests\\ORM\\Mapping\\Dog', + 'cat' => Cat::class, + 'dog' => Dog::class, ] ); $metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php index cc23c399240..b716893b6fb 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php @@ -1,6 +1,9 @@ setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE); $metadata->setPrimaryTable( @@ -53,7 +56,7 @@ $metadata->mapOneToOne( [ 'fieldName' => 'address', - 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Address', + 'targetEntity' => Address::class, 'cascade' => [ 0 => 'remove', @@ -75,7 +78,7 @@ $metadata->mapOneToMany( [ 'fieldName' => 'phonenumbers', - 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Phonenumber', + 'targetEntity' => Phonenumber::class, 'cascade' => [ 1 => 'persist', @@ -91,7 +94,7 @@ $metadata->mapManyToMany( [ 'fieldName' => 'groups', - 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Group', + 'targetEntity' => Group::class, 'cascade' => [ 0 => 'remove', diff --git a/tests/Doctrine/Tests/ORM/Performance/DDC2602Test.php b/tests/Doctrine/Tests/ORM/Performance/DDC2602Test.php index 4c992a87047..618b5f9c606 100644 --- a/tests/Doctrine/Tests/ORM/Performance/DDC2602Test.php +++ b/tests/Doctrine/Tests/ORM/Performance/DDC2602Test.php @@ -19,10 +19,10 @@ protected function setUp() $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2602User'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2602Biography'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2602BiographyField'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2602BiographyFieldChoice'), + $this->_em->getClassMetadata(DDC2602User::class), + $this->_em->getClassMetadata(DDC2602Biography::class), + $this->_em->getClassMetadata(DDC2602BiographyField::class), + $this->_em->getClassMetadata(DDC2602BiographyFieldChoice::class), ] ); @@ -35,10 +35,10 @@ protected function tearDown() $this->_schemaTool->dropSchema( [ - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2602User'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2602Biography'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2602BiographyField'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2602BiographyFieldChoice'), + $this->_em->getClassMetadata(DDC2602User::class), + $this->_em->getClassMetadata(DDC2602Biography::class), + $this->_em->getClassMetadata(DDC2602BiographyField::class), + $this->_em->getClassMetadata(DDC2602BiographyFieldChoice::class), ] ); } diff --git a/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php index 0846ca4de86..0035222adb8 100644 --- a/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php @@ -5,9 +5,12 @@ use Doctrine\ORM\Internal\Hydration\ArrayHydrator; use Doctrine\ORM\Internal\Hydration\ObjectHydrator; use Doctrine\ORM\Internal\Hydration\ScalarHydrator; -use Doctrine\Tests\Mocks\HydratorMockStatement, - Doctrine\ORM\Query\ResultSetMapping, - Doctrine\ORM\Query; +use Doctrine\ORM\Query; +use Doctrine\ORM\Query\ResultSetMapping; +use Doctrine\Tests\Mocks\HydratorMockStatement; +use Doctrine\Tests\Models\CMS\CmsAddress; +use Doctrine\Tests\Models\CMS\CmsPhonenumber; +use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\OrmPerformanceTestCase; /** @@ -31,7 +34,7 @@ class HydrationPerformanceTest extends OrmPerformanceTestCase public function testSimpleQueryScalarHydrationPerformance10000Rows() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addEntityResult(CmsUser::class, 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); $rsm->addFieldResult('u', 'u__username', 'username'); @@ -89,7 +92,7 @@ public function testSimpleQueryScalarHydrationPerformance10000Rows() public function testSimpleQueryArrayHydrationPerformance10000Rows() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addEntityResult(CmsUser::class, 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); $rsm->addFieldResult('u', 'u__username', 'username'); @@ -147,9 +150,9 @@ public function testSimpleQueryArrayHydrationPerformance10000Rows() public function testMixedQueryFetchJoinArrayHydrationPerformance10000Rows() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addEntityResult(CmsUser::class, 'u'); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsPhonenumber', + CmsPhonenumber::class, 'p', 'u', 'phonenumbers' @@ -219,7 +222,7 @@ public function testMixedQueryFetchJoinArrayHydrationPerformance10000Rows() public function testSimpleQueryPartialObjectHydrationPerformance10000Rows() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addEntityResult(CmsUser::class, 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); $rsm->addFieldResult('u', 'u__username', 'username'); @@ -275,13 +278,13 @@ public function testSimpleQueryPartialObjectHydrationPerformance10000Rows() public function testSimpleQueryFullObjectHydrationPerformance10000Rows() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addEntityResult(CmsUser::class, 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); $rsm->addFieldResult('u', 'u__username', 'username'); $rsm->addFieldResult('u', 'u__name', 'name'); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsAddress', + CmsAddress::class, 'a', 'u', 'address' @@ -331,9 +334,9 @@ public function testSimpleQueryFullObjectHydrationPerformance10000Rows() public function testMixedQueryFetchJoinPartialObjectHydrationPerformance2000Rows() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $rsm->addEntityResult(CmsUser::class, 'u'); $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsPhonenumber', + CmsPhonenumber::class, 'p', 'u', 'phonenumbers' @@ -403,25 +406,15 @@ public function testMixedQueryFetchJoinPartialObjectHydrationPerformance2000Rows public function testMixedQueryFetchJoinFullObjectHydrationPerformance2000Rows() { $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); - $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsPhonenumber', - 'p', - 'u', - 'phonenumbers' - ); + $rsm->addEntityResult(CmsUser::class, 'u'); + $rsm->addJoinedEntityResult(CmsPhonenumber::class, 'p', 'u', 'phonenumbers'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); $rsm->addFieldResult('u', 'u__username', 'username'); $rsm->addFieldResult('u', 'u__name', 'name'); $rsm->addScalarResult('sclr0', 'nameUpper'); $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); - $rsm->addJoinedEntityResult( - 'Doctrine\Tests\Models\CMS\CmsAddress', - 'a', - 'u', - 'address' - ); + $rsm->addJoinedEntityResult(CmsAddress::class, 'a', 'u', 'address'); $rsm->addFieldResult('a', 'a__id', 'id'); // Faked result set diff --git a/tests/Doctrine/Tests/ORM/Performance/InheritancePersisterPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/InheritancePersisterPerformanceTest.php index 2104587aea4..726389a4c1c 100644 --- a/tests/Doctrine/Tests/ORM/Performance/InheritancePersisterPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/InheritancePersisterPerformanceTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM\Performance; use Doctrine\ORM\Query; +use Doctrine\Tests\Models\Company\CompanyContract; use Doctrine\Tests\Models\Company\CompanyEmployee; use Doctrine\Tests\Models\Company\CompanyFixContract; use Doctrine\Tests\Models\Company\CompanyFlexContract; @@ -54,14 +55,14 @@ public function testCompanyContract() $this->_em->clear(); $start = microtime(true); - $contracts = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyContract')->findAll(); + $contracts = $this->_em->getRepository(CompanyContract::class)->findAll(); echo "99 CompanyContract: " . number_format(microtime(true) - $start, 6) . "\n"; $this->assertEquals(99, count($contracts)); $this->_em->clear(); $start = microtime(true); - $contracts = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyContract')->findAll(); + $contracts = $this->_em->getRepository(CompanyContract::class)->findAll(); echo "99 CompanyContract: " . number_format(microtime(true) - $start, 6) . "\n"; $this->assertEquals(99, count($contracts)); } diff --git a/tests/Doctrine/Tests/ORM/Performance/PersisterPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/PersisterPerformanceTest.php index 8d66ba601a9..30494d49bae 100644 --- a/tests/Doctrine/Tests/ORM/Performance/PersisterPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/PersisterPerformanceTest.php @@ -40,20 +40,20 @@ public function testFindCmsArticle() $this->_em->clear(); $start = microtime(true); - $articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsArticle')->findAll(); + $articles = $this->_em->getRepository(CmsArticle::class)->findAll(); echo "100 CmsArticle findAll(): " . number_format(microtime(true) - $start, 6) . "\n"; $this->_em->clear(); $start = microtime(true); - $articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsArticle')->findAll(); + $articles = $this->_em->getRepository(CmsArticle::class)->findAll(); echo "100 CmsArticle findAll(): " . number_format(microtime(true) - $start, 6) . "\n"; $this->_em->clear(); $start = microtime(true); for ($i = 0; $i < 100; $i++) { - $articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsArticle')->find($ids[$i]->id); + $articles = $this->_em->getRepository(CmsArticle::class)->find($ids[$i]->id); } echo "100 CmsArticle find(): " . number_format(microtime(true) - $start, 6) . "\n"; @@ -61,7 +61,7 @@ public function testFindCmsArticle() $start = microtime(true); for ($i = 0; $i < 100; $i++) { - $articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsArticle')->find($ids[$i]->id); + $articles = $this->_em->getRepository(CmsArticle::class)->find($ids[$i]->id); } echo "100 CmsArticle find(): " . number_format(microtime(true) - $start, 6) . "\n"; } @@ -77,13 +77,13 @@ public function testFindCmsGroup() $this->_em->clear(); $start = microtime(true); - $articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findAll(); + $articles = $this->_em->getRepository(CmsGroup::class)->findAll(); echo "100 CmsGroup: " . number_format(microtime(true) - $start, 6) . "\n"; $this->_em->clear(); $start = microtime(true); - $articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsGroup')->findAll(); + $articles = $this->_em->getRepository(CmsGroup::class)->findAll(); echo "100 CmsGroup: " . number_format(microtime(true) - $start, 6) . "\n"; } @@ -101,13 +101,13 @@ public function testFindCmsUser() $this->_em->clear(); $start = microtime(true); - $articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findAll(); + $articles = $this->_em->getRepository(CmsUser::class)->findAll(); echo "100 CmsUser: " . number_format(microtime(true) - $start, 6) . "\n"; $this->_em->clear(); $start = microtime(true); - $articles = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findAll(); + $articles = $this->_em->getRepository(CmsUser::class)->findAll(); echo "100 CmsUser: " . number_format(microtime(true) - $start, 6) . "\n"; } } diff --git a/tests/Doctrine/Tests/ORM/Performance/ProxyPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/ProxyPerformanceTest.php index de77aafd826..d73964dcc4a 100644 --- a/tests/Doctrine/Tests/ORM/Performance/ProxyPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/ProxyPerformanceTest.php @@ -2,11 +2,13 @@ namespace Doctrine\Tests\ORM\Performance; -use Doctrine\Tests\OrmPerformanceTestCase; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\UnitOfWork; -use Doctrine\ORM\Proxy\ProxyFactory; use Doctrine\ORM\Persisters\Entity\BasicEntityPersister; +use Doctrine\ORM\Proxy\ProxyFactory; +use Doctrine\ORM\UnitOfWork; +use Doctrine\Tests\Models\CMS\CmsEmployee; +use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\OrmPerformanceTestCase; /** * Performance test used to measure performance of proxy instantiation @@ -22,8 +24,8 @@ class ProxyPerformanceTest extends OrmPerformanceTestCase public function entitiesProvider() { return [ - ['Doctrine\Tests\Models\CMS\CmsEmployee'], - ['Doctrine\Tests\Models\CMS\CmsUser'], + [CmsEmployee::class], + [CmsUser::class], ]; } diff --git a/tests/Doctrine/Tests/ORM/Performance/SecondLevelCacheTest.php b/tests/Doctrine/Tests/ORM/Performance/SecondLevelCacheTest.php index 27974091809..f954d4f4791 100644 --- a/tests/Doctrine/Tests/ORM/Performance/SecondLevelCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/SecondLevelCacheTest.php @@ -202,7 +202,7 @@ public function findEntityOneToMany(EntityManagerInterface $em, $label) foreach ($states as $state) { - $state = $em->find(State::CLASSNAME, $state->getId()); + $state = $em->find(State::class, $state->getId()); foreach ($state->getCities() as $city) { $city->getName(); @@ -240,7 +240,7 @@ private function findEntity(EntityManagerInterface $em, $label) for ($i = 0; $i <= $times; $i++) { foreach ($countries as $country) { - $em->find(Country::CLASSNAME, $country->getId()); + $em->find(Country::class, $country->getId()); $em->clear(); } } @@ -254,7 +254,7 @@ private function findAllEntity(EntityManagerInterface $em, $label) $times = 100; $size = 50; $startPersist = microtime(true); - $rep = $em->getRepository(Country::CLASSNAME); + $rep = $em->getRepository(Country::class); echo PHP_EOL . $label; diff --git a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php index df1a16867f8..0e1c20f517e 100644 --- a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php @@ -40,7 +40,7 @@ protected function setUp() */ public function setUpPersistentCollection() { - $classMetaData = $this->_emMock->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceCart'); + $classMetaData = $this->_emMock->getClassMetadata(ECommerceCart::class); $this->collection = new PersistentCollection($this->_emMock, $classMetaData, new ArrayCollection); $this->collection->setInitialized(false); $this->collection->setOwner(new ECommerceCart(), $classMetaData->getAssociationMapping('products')); @@ -48,7 +48,7 @@ public function setUpPersistentCollection() public function testCanBePutInLazyLoadingMode() { - $class = $this->_emMock->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceProduct'); + $class = $this->_emMock->getClassMetadata(ECommerceProduct::class); $collection = new PersistentCollection($this->_emMock, $class, new ArrayCollection); $collection->setInitialized(false); $this->assertFalse($collection->isInitialized()); diff --git a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeParametersTest.php b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeParametersTest.php index db6fa5c836c..1694d97ce8f 100644 --- a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeParametersTest.php +++ b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeParametersTest.php @@ -5,6 +5,7 @@ use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\Persisters\Entity\BasicEntityPersister; use Doctrine\Tests\Models\GeoNames\Admin1; +use Doctrine\Tests\Models\GeoNames\Admin1AlternateName; use Doctrine\Tests\Models\GeoNames\Country; use Doctrine\Tests\OrmTestCase; @@ -29,11 +30,11 @@ protected function setUp() $this->_em = $this->_getTestEntityManager(); - $this->_em->getClassMetadata('Doctrine\Tests\Models\GeoNames\Country'); - $this->_em->getClassMetadata('Doctrine\Tests\Models\GeoNames\Admin1'); - $this->_em->getClassMetadata('Doctrine\Tests\Models\GeoNames\Admin1AlternateName'); + $this->_em->getClassMetadata(Country::class); + $this->_em->getClassMetadata(Admin1::class); + $this->_em->getClassMetadata(Admin1AlternateName::class); - $this->_persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata('Doctrine\Tests\Models\GeoNames\Admin1AlternateName')); + $this->_persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata(Admin1AlternateName::class)); } @@ -42,12 +43,7 @@ public function testExpandParametersWillExpandCompositeEntityKeys() $country = new Country("IT", "Italy"); $admin1 = new Admin1(10, "Rome", $country); - - list ($values, $types) = $this->_persister->expandParameters( - [ - 'admin1' => $admin1 - ] - ); + list ($values, $types) = $this->_persister->expandParameters(['admin1' => $admin1]); $this->assertEquals(['integer', 'string'], $types); $this->assertEquals([10, 'IT'], $values); @@ -59,7 +55,6 @@ public function testExpandCriteriaParametersWillExpandCompositeEntityKeys() $admin1 = new Admin1(10, "Rome", $country); $criteria = Criteria::create(); - $criteria->andWhere(Criteria::expr()->eq("admin1", $admin1)); list ($values, $types) = $this->_persister->expandCriteriaParameters($criteria); diff --git a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeSqlTest.php b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeSqlTest.php index 441ff010162..9392b8ee507 100644 --- a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeSqlTest.php +++ b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeSqlTest.php @@ -4,6 +4,7 @@ use Doctrine\ORM\Persisters\Entity\BasicEntityPersister; use Doctrine\Common\Collections\Expr\Comparison; +use Doctrine\Tests\Models\GeoNames\Admin1AlternateName; use Doctrine\Tests\OrmTestCase; class BasicEntityPersisterCompositeTypeSqlTest extends OrmTestCase @@ -26,8 +27,7 @@ protected function setUp() parent::setUp(); $this->_em = $this->_getTestEntityManager(); - - $this->_persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata('Doctrine\Tests\Models\GeoNames\Admin1AlternateName')); + $this->_persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata(Admin1AlternateName::class)); } public function testSelectConditionStatementEq() diff --git a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php index c4d747058b8..ba1d18051e1 100644 --- a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php +++ b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php @@ -3,12 +3,13 @@ namespace Doctrine\Tests\ORM\Persisters; use Doctrine\Common\Collections\Criteria; +use Doctrine\Common\Collections\Expr\Comparison; use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\ORM\Persisters\Entity\BasicEntityPersister; -use Doctrine\Tests\Models\CustomType\CustomTypeParent; use Doctrine\Tests\Models\CustomType\CustomTypeChild; use Doctrine\Tests\Models\CustomType\CustomTypeFriend; -use Doctrine\Common\Collections\Expr\Comparison; +use Doctrine\Tests\Models\CustomType\CustomTypeParent; +use Doctrine\Tests\Models\Generic\NonAlphaColumnsEntity; use Doctrine\Tests\OrmTestCase; class BasicEntityPersisterTypeValueSqlTest extends OrmTestCase @@ -44,7 +45,7 @@ protected function setUp() $this->_em = $this->_getTestEntityManager(); - $this->_persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata("Doctrine\Tests\Models\CustomType\CustomTypeParent")); + $this->_persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata(CustomTypeParent::class)); } public function testGetInsertSQLUsesTypeValuesSQL() @@ -93,7 +94,7 @@ public function testGetSelectConditionSQLUsesTypeValuesSQL() */ public function testStripNonAlphanumericCharactersFromSelectColumnListSQL() { - $persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata('Doctrine\Tests\Models\Generic\NonAlphaColumnsEntity')); + $persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata(NonAlphaColumnsEntity::class)); $method = new \ReflectionMethod($persister, 'getSelectColumnsSQL'); $method->setAccessible(true); @@ -144,7 +145,7 @@ public function testSelectConditionStatementWithMultipleValuesContainingNull() public function testCountCondition() { - $persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata('Doctrine\Tests\Models\Generic\NonAlphaColumnsEntity')); + $persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata(NonAlphaColumnsEntity::class)); // Using a criteria as array $statement = $persister->getCountSQL(['value' => 'bar']); diff --git a/tests/Doctrine/Tests/ORM/Persisters/JoinedSubclassPersisterTest.php b/tests/Doctrine/Tests/ORM/Persisters/JoinedSubclassPersisterTest.php index 14deca10034..4a4cec244a4 100644 --- a/tests/Doctrine/Tests/ORM/Persisters/JoinedSubclassPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Persisters/JoinedSubclassPersisterTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM\Persisters; use Doctrine\ORM\Persisters\Entity\JoinedSubclassPersister; +use Doctrine\Tests\Models\JoinedInheritanceType\RootClass; use Doctrine\Tests\OrmTestCase; /** @@ -30,11 +31,7 @@ protected function setUp() parent::setUp(); $this->em = $this->_getTestEntityManager(); - - $this->persister = new JoinedSubclassPersister( - $this->em, - $this->em->getClassMetadata('Doctrine\Tests\Models\JoinedInheritanceType\RootClass') - ); + $this->persister = new JoinedSubclassPersister($this->em, $this->em->getClassMetadata(RootClass::class)); } /** diff --git a/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php b/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php index e7da7a463f5..739a41f1807 100644 --- a/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php @@ -12,9 +12,10 @@ use Doctrine\Tests\Mocks\DriverMock; use Doctrine\Tests\Mocks\EntityManagerMock; use Doctrine\Tests\Mocks\UnitOfWorkMock; +use Doctrine\Tests\Models\Company\CompanyEmployee; use Doctrine\Tests\Models\Company\CompanyPerson; +use Doctrine\Tests\Models\ECommerce\ECommerceFeature; use Doctrine\Tests\OrmTestCase; -use Doctrine\Tests\Models\Company\CompanyEmployee; /** * Test the proxy generator. Its work is generating on-the-fly subclasses of a given model, which implement the Proxy pattern. @@ -61,9 +62,9 @@ public function testReferenceProxyDelegatesLoadingToThePersister() $proxyClass = 'Proxies\__CG__\Doctrine\Tests\Models\ECommerce\ECommerceFeature'; $persister = $this->getMockBuilder(BasicEntityPersister::class)->setMethods(['load'])->disableOriginalConstructor()->getMock(); - $this->uowMock->setEntityPersister('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $persister); + $this->uowMock->setEntityPersister(ECommerceFeature::class, $persister); - $proxy = $this->proxyFactory->getProxy('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $identifier); + $proxy = $this->proxyFactory->getProxy(ECommerceFeature::class, $identifier); $persister ->expects($this->atLeastOnce()) @@ -79,7 +80,7 @@ public function testReferenceProxyDelegatesLoadingToThePersister() */ public function testSkipAbstractClassesOnGeneration() { - $cm = new ClassMetadata(__NAMESPACE__ . '\\AbstractClass'); + $cm = new ClassMetadata(AbstractClass::class); $cm->initializeReflection(new RuntimeReflectionService()); $this->assertNotNull($cm->reflClass); @@ -94,10 +95,10 @@ public function testSkipAbstractClassesOnGeneration() public function testFailedProxyLoadingDoesNotMarkTheProxyAsInitialized() { $persister = $this->getMockBuilder(BasicEntityPersister::class)->setMethods(['load'])->disableOriginalConstructor()->getMock(); - $this->uowMock->setEntityPersister('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $persister); + $this->uowMock->setEntityPersister(ECommerceFeature::class, $persister); /* @var $proxy \Doctrine\Common\Proxy\Proxy */ - $proxy = $this->proxyFactory->getProxy('Doctrine\Tests\Models\ECommerce\ECommerceFeature', ['id' => 42]); + $proxy = $this->proxyFactory->getProxy(ECommerceFeature::class, ['id' => 42]); $persister ->expects($this->atLeastOnce()) @@ -121,10 +122,10 @@ public function testFailedProxyLoadingDoesNotMarkTheProxyAsInitialized() public function testFailedProxyCloningDoesNotMarkTheProxyAsInitialized() { $persister = $this->getMockBuilder(BasicEntityPersister::class)->setMethods(['load'])->disableOriginalConstructor()->getMock(); - $this->uowMock->setEntityPersister('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $persister); + $this->uowMock->setEntityPersister(ECommerceFeature::class, $persister); /* @var $proxy \Doctrine\Common\Proxy\Proxy */ - $proxy = $this->proxyFactory->getProxy('Doctrine\Tests\Models\ECommerce\ECommerceFeature', ['id' => 42]); + $proxy = $this->proxyFactory->getProxy(ECommerceFeature::class, ['id' => 42]); $persister ->expects($this->atLeastOnce()) diff --git a/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersJoinTest.php b/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersJoinTest.php index bedcd659758..9bc5bf5a0dc 100644 --- a/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersJoinTest.php +++ b/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersJoinTest.php @@ -3,6 +3,8 @@ namespace Doctrine\Tests\ORM\Query; use Doctrine\ORM\Query; +use Doctrine\Tests\Models\CMS\CmsAddress; +use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\OrmTestCase; /** @@ -25,7 +27,7 @@ public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed) { try { $query = $this->em->createQuery($dqlToBeTested); - $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\Tests\ORM\Query\CustomTreeWalkerJoin']) + $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [CustomTreeWalkerJoin::class]) ->useQueryCache(false); $this->assertEquals($sqlToBeConfirmed, $query->getSql()); @@ -60,7 +62,7 @@ public function walkSelectStatement(Query\AST\SelectStatement $selectStatement) foreach ($selectStatement->fromClause->identificationVariableDeclarations as $identificationVariableDeclaration) { $rangeVariableDecl = $identificationVariableDeclaration->rangeVariableDeclaration; - if ($rangeVariableDecl->abstractSchemaName !== 'Doctrine\Tests\Models\CMS\CmsUser') { + if ($rangeVariableDecl->abstractSchemaName !== CmsUser::class) { continue; } @@ -80,8 +82,8 @@ private function modifySelectStatement(Query\AST\SelectStatement $selectStatemen $selectStatement->selectClause->selectExpressions[] = $selectExpression; $entityManager = $this->_getQuery()->getEntityManager(); - $userMetadata = $entityManager->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); - $addressMetadata = $entityManager->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); + $userMetadata = $entityManager->getClassMetadata(CmsUser::class); + $addressMetadata = $entityManager->getClassMetadata(CmsAddress::class); $this->setQueryComponent($rangeVariableDecl->aliasIdentificationVariable . 'a', [ diff --git a/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersTest.php b/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersTest.php index d6ae708180a..4c2898141a7 100644 --- a/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersTest.php +++ b/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersTest.php @@ -4,6 +4,8 @@ use Doctrine\ORM\Query; use Doctrine\ORM\Query\QueryException; +use Doctrine\Tests\Models\CMS\CmsAddress; +use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\OrmTestCase; /** @@ -50,7 +52,7 @@ public function testSupportsQueriesWithoutWhere() $this->assertSqlGeneration( 'select u from Doctrine\Tests\Models\CMS\CmsUser u', "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c0_.email_id AS email_id_4 FROM cms_users c0_ WHERE c0_.id = 1", - ['Doctrine\Tests\ORM\Functional\CustomTreeWalker'] + [CustomTreeWalker::class] ); } @@ -59,7 +61,7 @@ public function testSupportsQueriesWithMultipleConditionalExpressions() $this->assertSqlGeneration( 'select u from Doctrine\Tests\Models\CMS\CmsUser u where u.name = :name or u.name = :otherName', "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c0_.email_id AS email_id_4 FROM cms_users c0_ WHERE (c0_.name = ? OR c0_.name = ?) AND c0_.id = 1", - ['Doctrine\Tests\ORM\Functional\CustomTreeWalker'] + [CustomTreeWalker::class] ); } @@ -68,7 +70,7 @@ public function testSupportsQueriesWithSimpleConditionalExpression() $this->assertSqlGeneration( 'select u from Doctrine\Tests\Models\CMS\CmsUser u where u.name = :name', "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c0_.email_id AS email_id_4 FROM cms_users c0_ WHERE c0_.name = ? AND c0_.id = 1", - ['Doctrine\Tests\ORM\Functional\CustomTreeWalker'] + [CustomTreeWalker::class] ); } @@ -80,7 +82,7 @@ public function testSetUnknownQueryComponentThrowsException() $this->generateSql( 'select u from Doctrine\Tests\Models\CMS\CmsUser u', [], - __NAMESPACE__ . '\\AddUnknownQueryComponentWalker' + AddUnknownQueryComponentWalker::class ); } @@ -89,7 +91,7 @@ public function testSupportsSeveralHintsQueries() $this->assertSqlGeneration( 'select u from Doctrine\Tests\Models\CMS\CmsUser u', "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c1_.id AS id_4, c1_.country AS country_5, c1_.zip AS zip_6, c1_.city AS city_7, c0_.email_id AS email_id_8, c1_.user_id AS user_id_9 FROM cms_users c0_ LEFT JOIN cms_addresses c1_ ON c0_.id = c1_.user_id WHERE c0_.id = 1", - ['Doctrine\Tests\ORM\Functional\CustomTreeWalkerJoin', 'Doctrine\Tests\ORM\Functional\CustomTreeWalker'] + [CustomTreeWalkerJoin::class, CustomTreeWalker::class] ); } } @@ -114,7 +116,7 @@ public function walkSelectStatement(Query\AST\SelectStatement $selectStatement) foreach ($this->_getQueryComponents() as $dqlAlias => $comp) { // Hard-coded check just for demonstration: We want to modify the query if // it involves the CmsUser class. - if ($comp['metadata']->name == 'Doctrine\Tests\Models\CMS\CmsUser') { + if ($comp['metadata']->name == CmsUser::class) { $dqlAliases[] = $dqlAlias; } } @@ -187,7 +189,7 @@ public function walkSelectStatement(Query\AST\SelectStatement $selectStatement) foreach ($selectStatement->fromClause->identificationVariableDeclarations as $identificationVariableDeclaration) { $rangeVariableDecl = $identificationVariableDeclaration->rangeVariableDeclaration; - if ($rangeVariableDecl->abstractSchemaName !== 'Doctrine\Tests\Models\CMS\CmsUser') { + if ($rangeVariableDecl->abstractSchemaName !== CmsUser::class) { continue; } @@ -207,8 +209,8 @@ private function modifySelectStatement(Query\AST\SelectStatement $selectStatemen $selectStatement->selectClause->selectExpressions[] = $selectExpression; $entityManager = $this->_getQuery()->getEntityManager(); - $userMetadata = $entityManager->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); - $addressMetadata = $entityManager->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); + $userMetadata = $entityManager->getClassMetadata(CmsUser::class); + $addressMetadata = $entityManager->getClassMetadata(CmsAddress::class); $this->setQueryComponent($rangeVariableDecl->aliasIdentificationVariable . 'a', [ diff --git a/tests/Doctrine/Tests/ORM/Query/ExprTest.php b/tests/Doctrine/Tests/ORM/Query/ExprTest.php index 791f2f9b934..37a4b70a657 100644 --- a/tests/Doctrine/Tests/ORM/Query/ExprTest.php +++ b/tests/Doctrine/Tests/ORM/Query/ExprTest.php @@ -3,7 +3,7 @@ namespace Doctrine\Tests\ORM\Query; use Doctrine\ORM\Query\Expr; -use Doctrine\ORM\Query; +use Doctrine\Tests\Models\Company\CompanyEmployee; use Doctrine\Tests\OrmTestCase; /** @@ -265,7 +265,7 @@ public function testIsNotNullExpr() } public function testIsInstanceOfExpr() { - $this->assertEquals('u INSTANCE OF Doctrine\Tests\Models\Company\CompanyEmployee', (string) $this->_expr->isInstanceOf('u', 'Doctrine\Tests\Models\Company\CompanyEmployee')); + $this->assertEquals('u INSTANCE OF Doctrine\Tests\Models\Company\CompanyEmployee', (string) $this->_expr->isInstanceOf('u', CompanyEmployee::class)); } public function testIsMemberOfExpr() { diff --git a/tests/Doctrine/Tests/ORM/Query/FilterCollectionTest.php b/tests/Doctrine/Tests/ORM/Query/FilterCollectionTest.php index 7a50516a793..0e47f6e82d6 100644 --- a/tests/Doctrine/Tests/ORM/Query/FilterCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Query/FilterCollectionTest.php @@ -2,8 +2,8 @@ namespace Doctrine\Tests\ORM\Query; -use Doctrine\ORM\Mapping\ClassMetadata, - Doctrine\ORM\Query\Filter\SQLFilter; +use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Query\Filter\SQLFilter; use Doctrine\Tests\OrmTestCase; /** @@ -21,8 +21,7 @@ class FilterCollectionTest extends OrmTestCase protected function setUp() { $this->em = $this->_getTestEntityManager(); - - $this->em->getConfiguration()->addFilter('testFilter', 'Doctrine\Tests\ORM\Query\MyFilter'); + $this->em->getConfiguration()->addFilter('testFilter', MyFilter::class); } public function testEnable() @@ -36,7 +35,7 @@ public function testEnable() $enabledFilters = $filterCollection->getEnabledFilters(); $this->assertCount(1, $enabledFilters); - $this->assertContainsOnly('Doctrine\Tests\ORM\Query\MyFilter', $enabledFilters); + $this->assertContainsOnly(MyFilter::class, $enabledFilters); $filterCollection->disable('testFilter'); $this->assertCount(0, $filterCollection->getEnabledFilters()); @@ -70,17 +69,15 @@ public function testIsEnabled() public function testGetFilterInvalidArgument() { $filterCollection = $this->em->getFilters(); - $filterCollection->getFilter('testFilter'); } public function testGetFilter() { $filterCollection = $this->em->getFilters(); - $filterCollection->enable('testFilter'); - $this->assertInstanceOf('Doctrine\Tests\ORM\Query\MyFilter', $filterCollection->getFilter('testFilter')); + $this->assertInstanceOf(MyFilter::class, $filterCollection->getFilter('testFilter')); } } diff --git a/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php b/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php index 88fdca9bf45..46e72245a22 100644 --- a/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php +++ b/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php @@ -5,6 +5,7 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query, Doctrine\ORM\Query\QueryException; +use Doctrine\Tests\Mocks\MockTreeWalker; use Doctrine\Tests\OrmTestCase; class LanguageRecognitionTest extends OrmTestCase @@ -59,7 +60,7 @@ public function parseDql($dql, $hints = []) $parser = new Query\Parser($query); // We do NOT test SQL output here. That only unnecessarily slows down the tests! - $parser->setCustomOutputTreeWalker('Doctrine\Tests\Mocks\MockTreeWalker'); + $parser->setCustomOutputTreeWalker(MockTreeWalker::class); return $parser->parse(); } @@ -572,7 +573,7 @@ public function testInputParameterInSelect() */ public function testCustomFunctionsReturningStringInStringPrimary() { - $this->_em->getConfiguration()->addCustomStringFunction('CC', 'Doctrine\ORM\Query\AST\Functions\ConcatFunction'); + $this->_em->getConfiguration()->addCustomStringFunction('CC', Query\AST\Functions\ConcatFunction::class); $this->assertValidDQL("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE CC('%', u.name) LIKE '%foo%'", true); } diff --git a/tests/Doctrine/Tests/ORM/Query/ParserResultTest.php b/tests/Doctrine/Tests/ORM/Query/ParserResultTest.php index 0a61d7d31d1..3d74e0f96c5 100644 --- a/tests/Doctrine/Tests/ORM/Query/ParserResultTest.php +++ b/tests/Doctrine/Tests/ORM/Query/ParserResultTest.php @@ -4,6 +4,7 @@ use Doctrine\ORM\Query\Exec\AbstractSqlExecutor; use Doctrine\ORM\Query\ParserResult; +use Doctrine\ORM\Query\ResultSetMapping; class ParserResultTest extends \PHPUnit_Framework_TestCase { @@ -16,10 +17,7 @@ public function setUp() public function testGetRsm() { - $this->assertInstanceOf( - 'Doctrine\ORM\Query\ResultSetMapping', - $this->parserResult->getResultSetMapping() - ); + $this->assertInstanceOf(ResultSetMapping::class, $this->parserResult->getResultSetMapping()); } public function testSetGetSqlExecutor() diff --git a/tests/Doctrine/Tests/ORM/Query/ParserTest.php b/tests/Doctrine/Tests/ORM/Query/ParserTest.php index 6b898f80b43..b290812fc85 100644 --- a/tests/Doctrine/Tests/ORM/Query/ParserTest.php +++ b/tests/Doctrine/Tests/ORM/Query/ParserTest.php @@ -6,6 +6,7 @@ use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\QueryException; +use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\OrmTestCase; class ParserTest extends OrmTestCase @@ -17,9 +18,9 @@ class ParserTest extends OrmTestCase */ public function testAbstractSchemaNameSupportsFQCN() { - $parser = $this->createParser('Doctrine\Tests\Models\CMS\CmsUser'); + $parser = $this->createParser(CmsUser::class); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $parser->AbstractSchemaName()); + $this->assertEquals(CmsUser::class, $parser->AbstractSchemaName()); } /** @@ -28,9 +29,9 @@ public function testAbstractSchemaNameSupportsFQCN() */ public function testAbstractSchemaNameSupportsClassnamesWithLeadingBackslash() { - $parser = $this->createParser('\Doctrine\Tests\Models\CMS\CmsUser'); + $parser = $this->createParser('\\' . CmsUser::class); - $this->assertEquals('\Doctrine\Tests\Models\CMS\CmsUser', $parser->AbstractSchemaName()); + $this->assertEquals('\\' . CmsUser::class, $parser->AbstractSchemaName()); } /** @@ -39,9 +40,9 @@ public function testAbstractSchemaNameSupportsClassnamesWithLeadingBackslash() */ public function testAbstractSchemaNameSupportsIdentifier() { - $parser = $this->createParser('stdClass'); + $parser = $this->createParser(\stdClass::class); - $this->assertEquals('stdClass', $parser->AbstractSchemaName()); + $this->assertEquals(\stdClass::class, $parser->AbstractSchemaName()); } /** @@ -54,7 +55,7 @@ public function testAbstractSchemaNameSupportsNamespaceAlias() $parser->getEntityManager()->getConfiguration()->addEntityNamespace('CMS', 'Doctrine\Tests\Models\CMS'); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $parser->AbstractSchemaName()); + $this->assertEquals(CmsUser::class, $parser->AbstractSchemaName()); } /** @@ -67,7 +68,7 @@ public function testAbstractSchemaNameSupportsNamespaceAliasWithRelativeClassnam $parser->getEntityManager()->getConfiguration()->addEntityNamespace('Model', 'Doctrine\Tests\Models'); - $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $parser->AbstractSchemaName()); + $this->assertEquals(CmsUser::class, $parser->AbstractSchemaName()); } /** diff --git a/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php b/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php index 7653be5ec10..91b99f2e35f 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php @@ -3,13 +3,10 @@ namespace Doctrine\Tests\ORM\Query; use Doctrine\Common\Collections\ArrayCollection; - -use Doctrine\Common\Collections\Expr\Value; use Doctrine\Common\Collections\Expr\Comparison as CriteriaComparison; -use Doctrine\ORM\Query\Expr\Comparison as QueryComparison; +use Doctrine\Common\Collections\Expr\Value; use Doctrine\Common\Collections\ExpressionBuilder as CriteriaBuilder; use Doctrine\ORM\Query\Expr as QueryBuilder; - use Doctrine\ORM\Query\Parameter; use Doctrine\ORM\Query\QueryExpressionVisitor; @@ -35,7 +32,7 @@ protected function setUp() /** * @param CriteriaComparison $criteriaExpr - * @param QueryComparison|string $queryExpr + * @param QueryBuilder\Comparison|string $queryExpr * @param Parameter $parameter * * @dataProvider comparisonData @@ -89,7 +86,7 @@ public function testWalkAndCompositeExpression() ) ); - $this->assertInstanceOf('Doctrine\ORM\Query\Expr\Andx', $expr); + $this->assertInstanceOf(QueryBuilder\Andx::class, $expr); $this->assertCount(2, $expr->getParts()); } @@ -103,7 +100,7 @@ public function testWalkOrCompositeExpression() ) ); - $this->assertInstanceOf('Doctrine\ORM\Query\Expr\Orx', $expr); + $this->assertInstanceOf(QueryBuilder\Orx::class, $expr); $this->assertCount(2, $expr->getParts()); } diff --git a/tests/Doctrine/Tests/ORM/Query/QueryTest.php b/tests/Doctrine/Tests/ORM/Query/QueryTest.php index e646d670a43..9b8f24d40ec 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryTest.php @@ -9,6 +9,7 @@ use Doctrine\ORM\Query\Parameter; use Doctrine\Tests\Mocks\DriverConnectionMock; use Doctrine\Tests\Mocks\StatementArrayMock; +use Doctrine\Tests\Models\CMS\CmsAddress; use Doctrine\Tests\OrmTestCase; class QueryTest extends OrmTestCase @@ -178,8 +179,8 @@ public function testProcessParameterValueClassMetadata() { $query = $this->_em->createQuery("SELECT a FROM Doctrine\Tests\Models\CMS\CmsAddress a WHERE a.city IN (:cities)"); $this->assertEquals( - 'Doctrine\Tests\Models\CMS\CmsAddress', - $query->processParameterValue($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress')) + CmsAddress::class, + $query->processParameterValue($this->_em->getClassMetadata(CmsAddress::class)) ); } diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 9a074d60ead..b6bdce3233b 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -15,8 +15,10 @@ use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\QueryException; use Doctrine\ORM\Query\SqlWalker; +use Doctrine\Tests\DbalTypes\NegativeToPositiveType; use Doctrine\Tests\Models\CMS\CmsGroup; use Doctrine\Tests\Models\CMS\CmsPhonenumber; +use Doctrine\Tests\Models\Company\CompanyEmployee; use Doctrine\Tests\Models\Company\CompanyPerson; use Doctrine\Tests\OrmTestCase; @@ -531,7 +533,7 @@ public function testSupportsInstanceOfExpressionsInWherePartWithUnrelatedClass() { $this->assertInvalidSqlGeneration( "SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF \Doctrine\Tests\Models\CMS\CmsUser", - "Doctrine\\ORM\\Query\\QueryException" + QueryException::class ); } @@ -556,7 +558,7 @@ public function testSupportsInstanceOfExpressionsUsingInputParameterInWherePart( $this->assertSqlGeneration( "SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF ?1", "SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.discr AS discr_2 FROM company_persons c0_ WHERE c0_.discr IN (?)", - [], [1 => $this->_em->getClassMetadata('Doctrine\Tests\Models\Company\CompanyEmployee')] + [], [1 => $this->_em->getClassMetadata(CompanyEmployee::class)] ); } @@ -609,7 +611,7 @@ public function testInvalidInExpressionWithSingleValuedAssociationPathExpression // We do not support SingleValuedAssociationPathExpression on inverse side $this->assertInvalidSqlGeneration( "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.address IN (?1, ?2)", - "Doctrine\ORM\Query\QueryException" + QueryException::class ); } @@ -1132,7 +1134,7 @@ public function testPessimisticReadLockQueryHintOracle() public function testSupportToCustomDQLFunctions() { $config = $this->_em->getConfiguration(); - $config->addCustomNumericFunction('MYABS', 'Doctrine\Tests\ORM\Query\MyAbsFunction'); + $config->addCustomNumericFunction('MYABS', MyAbsFunction::class); $this->assertSqlGeneration( 'SELECT MYABS(p.phonenumber) FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p', @@ -1378,7 +1380,7 @@ public function testIdentityFunctionWithCompositePrimaryKey() $this->assertInvalidSqlGeneration( "SELECT IDENTITY(p.poi, 'invalid') AS invalid FROM Doctrine\Tests\Models\Navigation\NavPhotos p", - "Doctrine\ORM\Query\QueryException" + QueryException::class ); } @@ -1431,7 +1433,7 @@ public function testIdentityFunctionDoesNotAcceptStateField() { $this->assertInvalidSqlGeneration( "SELECT IDENTITY(u.name) as name FROM Doctrine\Tests\Models\CMS\CmsUser u", - "Doctrine\ORM\Query\QueryException" + QueryException::class ); } @@ -1838,9 +1840,9 @@ public function testWhereFunctionIsNullComparisonExpression() public function testCustomTypeValueSql() { if (DBALType::hasType('negative_to_positive')) { - DBALType::overrideType('negative_to_positive', 'Doctrine\Tests\DbalTypes\NegativeToPositiveType'); + DBALType::overrideType('negative_to_positive', NegativeToPositiveType::class); } else { - DBALType::addType('negative_to_positive', 'Doctrine\Tests\DbalTypes\NegativeToPositiveType'); + DBALType::addType('negative_to_positive', NegativeToPositiveType::class); } $this->assertSqlGeneration( @@ -1852,9 +1854,9 @@ public function testCustomTypeValueSql() public function testCustomTypeValueSqlIgnoresIdentifierColumn() { if (DBALType::hasType('negative_to_positive')) { - DBALType::overrideType('negative_to_positive', 'Doctrine\Tests\DbalTypes\NegativeToPositiveType'); + DBALType::overrideType('negative_to_positive', NegativeToPositiveType::class); } else { - DBALType::addType('negative_to_positive', 'Doctrine\Tests\DbalTypes\NegativeToPositiveType'); + DBALType::addType('negative_to_positive', NegativeToPositiveType::class); } $this->assertSqlGeneration( @@ -1866,9 +1868,9 @@ public function testCustomTypeValueSqlIgnoresIdentifierColumn() public function testCustomTypeValueSqlForAllFields() { if (DBALType::hasType('negative_to_positive')) { - DBALType::overrideType('negative_to_positive', 'Doctrine\Tests\DbalTypes\NegativeToPositiveType'); + DBALType::overrideType('negative_to_positive', NegativeToPositiveType::class); } else { - DBALType::addType('negative_to_positive', 'Doctrine\Tests\DbalTypes\NegativeToPositiveType'); + DBALType::addType('negative_to_positive', NegativeToPositiveType::class); } $this->assertSqlGeneration( @@ -1880,9 +1882,9 @@ public function testCustomTypeValueSqlForAllFields() public function testCustomTypeValueSqlForPartialObject() { if (DBALType::hasType('negative_to_positive')) { - DBALType::overrideType('negative_to_positive', 'Doctrine\Tests\DbalTypes\NegativeToPositiveType'); + DBALType::overrideType('negative_to_positive', NegativeToPositiveType::class); } else { - DBALType::addType('negative_to_positive', 'Doctrine\Tests\DbalTypes\NegativeToPositiveType'); + DBALType::addType('negative_to_positive', NegativeToPositiveType::class); } $this->assertSqlGeneration( diff --git a/tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php index 4110b54e62d..7044929e940 100644 --- a/tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM\Query; use Doctrine\DBAL\Types\Type as DBALType; +use Doctrine\Tests\DbalTypes\NegativeToPositiveType; use Doctrine\Tests\OrmTestCase; /** @@ -25,9 +26,9 @@ class UpdateSqlGenerationTest extends OrmTestCase protected function setUp() { if (DBALType::hasType('negative_to_positive')) { - DBALType::overrideType('negative_to_positive', 'Doctrine\Tests\DbalTypes\NegativeToPositiveType'); + DBALType::overrideType('negative_to_positive', NegativeToPositiveType::class); } else { - DBALType::addType('negative_to_positive', 'Doctrine\Tests\DbalTypes\NegativeToPositiveType'); + DBALType::addType('negative_to_positive', NegativeToPositiveType::class); } $this->_em = $this->_getTestEntityManager(); diff --git a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php index 9418028ecbb..7da2c663caa 100644 --- a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php +++ b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php @@ -5,11 +5,14 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\Cache; - -use Doctrine\ORM\QueryBuilder; -use Doctrine\ORM\Query\Expr; +use Doctrine\ORM\Query; use Doctrine\ORM\Query\Parameter; use Doctrine\ORM\Query\ParameterTypeInferer; +use Doctrine\ORM\QueryBuilder; +use Doctrine\Tests\Models\Cache\State; +use Doctrine\Tests\Models\CMS\CmsArticle; +use Doctrine\Tests\Models\CMS\CmsGroup; +use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\OrmTestCase; /** @@ -43,7 +46,7 @@ protected function assertValidQueryBuilder(QueryBuilder $qb, $expectedDql) public function testSelectSetsType() { $qb = $this->_em->createQueryBuilder() - ->delete('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->delete(CmsUser::class, 'u') ->select('u.id', 'u.username'); $this->assertEquals($qb->getType(), QueryBuilder::SELECT); @@ -52,7 +55,7 @@ public function testSelectSetsType() public function testEmptySelectSetsType() { $qb = $this->_em->createQueryBuilder() - ->delete('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->delete(CmsUser::class, 'u') ->select(); $this->assertEquals($qb->getType(), QueryBuilder::SELECT); @@ -61,7 +64,7 @@ public function testEmptySelectSetsType() public function testDeleteSetsType() { $qb = $this->_em->createQueryBuilder() - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->delete(); $this->assertEquals($qb->getType(), QueryBuilder::DELETE); @@ -70,7 +73,7 @@ public function testDeleteSetsType() public function testUpdateSetsType() { $qb = $this->_em->createQueryBuilder() - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->update(); $this->assertEquals($qb->getType(), QueryBuilder::UPDATE); @@ -79,7 +82,7 @@ public function testUpdateSetsType() public function testSimpleSelect() { $qb = $this->_em->createQueryBuilder() - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->select('u.id', 'u.username'); $this->assertValidQueryBuilder($qb, 'SELECT u.id, u.username FROM Doctrine\Tests\Models\CMS\CmsUser u'); @@ -88,7 +91,7 @@ public function testSimpleSelect() public function testSimpleDelete() { $qb = $this->_em->createQueryBuilder() - ->delete('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + ->delete(CmsUser::class, 'u'); $this->assertValidQueryBuilder($qb, 'DELETE Doctrine\Tests\Models\CMS\CmsUser u'); } @@ -96,7 +99,7 @@ public function testSimpleDelete() public function testSimpleSelectWithFromIndexBy() { $qb = $this->_em->createQueryBuilder() - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u', 'u.id') + ->from(CmsUser::class, 'u', 'u.id') ->select('u.id', 'u.username'); $this->assertValidQueryBuilder($qb, 'SELECT u.id, u.username FROM Doctrine\Tests\Models\CMS\CmsUser u INDEX BY u.id'); @@ -105,7 +108,7 @@ public function testSimpleSelectWithFromIndexBy() public function testSimpleSelectWithIndexBy() { $qb = $this->_em->createQueryBuilder() - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->indexBy('u', 'u.id') ->select('u.id', 'u.username'); @@ -115,7 +118,7 @@ public function testSimpleSelectWithIndexBy() public function testSimpleUpdate() { $qb = $this->_em->createQueryBuilder() - ->update('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->update(CmsUser::class, 'u') ->set('u.username', ':username'); $this->assertValidQueryBuilder($qb, 'UPDATE Doctrine\Tests\Models\CMS\CmsUser u SET u.username = :username'); @@ -125,7 +128,7 @@ public function testInnerJoin() { $qb = $this->_em->createQueryBuilder() ->select('u', 'a') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->innerJoin('u.articles', 'a'); $this->assertValidQueryBuilder($qb, 'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles a'); @@ -135,7 +138,7 @@ public function testComplexInnerJoin() { $qb = $this->_em->createQueryBuilder() ->select('u', 'a') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->innerJoin('u.articles', 'a', 'ON', 'u.id = a.author_id'); $this->assertValidQueryBuilder( @@ -148,7 +151,7 @@ public function testComplexInnerJoinWithIndexBy() { $qb = $this->_em->createQueryBuilder() ->select('u', 'a') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->innerJoin('u.articles', 'a', 'ON', 'u.id = a.author_id', 'a.name'); $this->assertValidQueryBuilder( @@ -161,7 +164,7 @@ public function testLeftJoin() { $qb = $this->_em->createQueryBuilder() ->select('u', 'a') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->leftJoin('u.articles', 'a'); $this->assertValidQueryBuilder($qb, 'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a'); @@ -171,7 +174,7 @@ public function testLeftJoinWithIndexBy() { $qb = $this->_em->createQueryBuilder() ->select('u', 'a') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->leftJoin('u.articles', 'a', null, null, 'a.name'); $this->assertValidQueryBuilder($qb, 'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a INDEX BY a.name'); @@ -181,8 +184,8 @@ public function testMultipleFrom() { $qb = $this->_em->createQueryBuilder() ->select('u', 'g') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') - ->from('Doctrine\Tests\Models\CMS\CmsGroup', 'g'); + ->from(CmsUser::class, 'u') + ->from(CmsGroup::class, 'g'); $this->assertValidQueryBuilder($qb, 'SELECT u, g FROM Doctrine\Tests\Models\CMS\CmsUser u, Doctrine\Tests\Models\CMS\CmsGroup g'); } @@ -191,8 +194,8 @@ public function testMultipleFromWithIndexBy() { $qb = $this->_em->createQueryBuilder() ->select('u', 'g') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') - ->from('Doctrine\Tests\Models\CMS\CmsGroup', 'g') + ->from(CmsUser::class, 'u') + ->from(CmsGroup::class, 'g') ->indexBy('g', 'g.id'); $this->assertValidQueryBuilder($qb, 'SELECT u, g FROM Doctrine\Tests\Models\CMS\CmsUser u, Doctrine\Tests\Models\CMS\CmsGroup g INDEX BY g.id'); @@ -202,8 +205,8 @@ public function testMultipleFromWithJoin() { $qb = $this->_em->createQueryBuilder() ->select('u', 'g') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') - ->from('Doctrine\Tests\Models\CMS\CmsGroup', 'g') + ->from(CmsUser::class, 'u') + ->from(CmsGroup::class, 'g') ->innerJoin('u.articles', 'a', 'ON', 'u.id = a.author_id'); $this->assertValidQueryBuilder($qb, 'SELECT u, g FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles a ON u.id = a.author_id, Doctrine\Tests\Models\CMS\CmsGroup g'); @@ -213,8 +216,8 @@ public function testMultipleFromWithMultipleJoin() { $qb = $this->_em->createQueryBuilder() ->select('u', 'g') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') - ->from('Doctrine\Tests\Models\CMS\CmsArticle', 'a') + ->from(CmsUser::class, 'u') + ->from(CmsArticle::class, 'a') ->innerJoin('u.groups', 'g') ->leftJoin('u.address', 'ad') ->innerJoin('a.comments', 'c'); @@ -226,7 +229,7 @@ public function testWhere() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->where('u.id = :uid'); $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid'); @@ -236,7 +239,7 @@ public function testComplexAndWhere() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->where('u.id = :uid OR u.id = :uid2 OR u.id = :uid3') ->andWhere('u.name = :name'); @@ -247,7 +250,7 @@ public function testAndWhere() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->where('u.id = :uid') ->andWhere('u.id = :uid2'); @@ -258,7 +261,7 @@ public function testOrWhere() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->where('u.id = :uid') ->orWhere('u.id = :uid2'); @@ -269,7 +272,7 @@ public function testComplexAndWhereOrWhereNesting() { $qb = $this->_em->createQueryBuilder(); $qb->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->where('u.id = :uid') ->orWhere('u.id = :uid2') ->andWhere('u.id = :uid3') @@ -283,7 +286,7 @@ public function testAndWhereIn() { $qb = $this->_em->createQueryBuilder(); $qb->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->where('u.id = :uid') ->andWhere($qb->expr()->in('u.id', [1, 2, 3])); @@ -294,7 +297,7 @@ public function testOrWhereIn() { $qb = $this->_em->createQueryBuilder(); $qb->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->where('u.id = :uid') ->orWhere($qb->expr()->in('u.id', [1, 2, 3])); @@ -305,7 +308,7 @@ public function testAndWhereNotIn() { $qb = $this->_em->createQueryBuilder(); $qb->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->where('u.id = :uid') ->andWhere($qb->expr()->notIn('u.id', [1, 2, 3])); @@ -316,7 +319,7 @@ public function testOrWhereNotIn() { $qb = $this->_em->createQueryBuilder(); $qb->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->where('u.id = :uid') ->orWhere($qb->expr()->notIn('u.id', [1, 2, 3])); @@ -327,7 +330,7 @@ public function testGroupBy() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->groupBy('u.id') ->addGroupBy('u.username'); @@ -338,7 +341,7 @@ public function testHaving() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->groupBy('u.id') ->having('COUNT(u.id) > 1'); @@ -349,7 +352,7 @@ public function testAndHaving() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->groupBy('u.id') ->having('COUNT(u.id) > 1') ->andHaving('COUNT(u.id) < 1'); @@ -361,7 +364,7 @@ public function testOrHaving() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->groupBy('u.id') ->having('COUNT(u.id) > 1') ->andHaving('COUNT(u.id) < 1') @@ -374,7 +377,7 @@ public function testOrderBy() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->orderBy('u.username', 'ASC'); $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.username ASC'); @@ -384,7 +387,7 @@ public function testOrderByWithExpression() { $qb = $this->_em->createQueryBuilder(); $qb->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->orderBy($qb->expr()->asc('u.username')); $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.username ASC'); @@ -394,7 +397,7 @@ public function testAddOrderBy() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->orderBy('u.username', 'ASC') ->addOrderBy('u.username', 'DESC'); @@ -405,7 +408,7 @@ public function testAddOrderByWithExpression() { $qb = $this->_em->createQueryBuilder(); $qb->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->orderBy('u.username', 'ASC') ->addOrderBy($qb->expr()->desc('u.username')); @@ -416,7 +419,7 @@ public function testAddCriteriaWhere() { $qb = $this->_em->createQueryBuilder(); $qb->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + ->from(CmsUser::class, 'u'); $criteria = new Criteria(); $criteria->where($criteria->expr()->eq('field', 'value')); @@ -430,7 +433,7 @@ public function testAddCriteriaWhere() public function testAddMultipleSameCriteriaWhere() { $qb = $this->_em->createQueryBuilder(); - $qb->select('alias1')->from('Doctrine\Tests\Models\CMS\CmsUser', 'alias1'); + $qb->select('alias1')->from(CmsUser::class, 'alias1'); $criteria = new Criteria(); $criteria->where($criteria->expr()->andX( @@ -451,7 +454,7 @@ public function testAddMultipleSameCriteriaWhere() public function testAddCriteriaWhereWithMultipleParametersWithSameField() { $qb = $this->_em->createQueryBuilder(); - $qb->select('alias1')->from('Doctrine\Tests\Models\CMS\CmsUser', 'alias1'); + $qb->select('alias1')->from(CmsUser::class, 'alias1'); $criteria = new Criteria(); $criteria->where($criteria->expr()->eq('field', 'value1')); @@ -470,7 +473,7 @@ public function testAddCriteriaWhereWithMultipleParametersWithSameField() public function testAddCriteriaWhereWithMultipleParametersWithDifferentFields() { $qb = $this->_em->createQueryBuilder(); - $qb->select('alias1')->from('Doctrine\Tests\Models\CMS\CmsUser', 'alias1'); + $qb->select('alias1')->from(CmsUser::class, 'alias1'); $criteria = new Criteria(); $criteria->where($criteria->expr()->eq('field1', 'value1')); @@ -489,7 +492,7 @@ public function testAddCriteriaWhereWithMultipleParametersWithDifferentFields() public function testAddCriteriaWhereWithMultipleParametersWithSubpathsAndDifferentProperties() { $qb = $this->_em->createQueryBuilder(); - $qb->select('alias1')->from('Doctrine\Tests\Models\CMS\CmsUser', 'alias1'); + $qb->select('alias1')->from(CmsUser::class, 'alias1'); $criteria = new Criteria(); $criteria->where($criteria->expr()->eq('field1', 'value1')); @@ -508,7 +511,7 @@ public function testAddCriteriaWhereWithMultipleParametersWithSubpathsAndDiffere public function testAddCriteriaWhereWithMultipleParametersWithSubpathsAndSameProperty() { $qb = $this->_em->createQueryBuilder(); - $qb->select('alias1')->from('Doctrine\Tests\Models\CMS\CmsUser', 'alias1'); + $qb->select('alias1')->from(CmsUser::class, 'alias1'); $criteria = new Criteria(); $criteria->where($criteria->expr()->eq('field1', 'value1')); @@ -525,7 +528,7 @@ public function testAddCriteriaOrder() { $qb = $this->_em->createQueryBuilder(); $qb->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + ->from(CmsUser::class, 'u'); $criteria = new Criteria(); $criteria->orderBy(['field' => Criteria::DESC]); @@ -543,7 +546,7 @@ public function testAddCriteriaOrderOnJoinAlias() { $qb = $this->_em->createQueryBuilder(); $qb->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->join('u.article','a'); $criteria = new Criteria(); @@ -559,7 +562,7 @@ public function testAddCriteriaLimit() { $qb = $this->_em->createQueryBuilder(); $qb->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + ->from(CmsUser::class, 'u'); $criteria = new Criteria(); $criteria->setFirstResult(2); @@ -575,7 +578,7 @@ public function testAddCriteriaUndefinedLimit() { $qb = $this->_em->createQueryBuilder(); $qb->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->setFirstResult(2) ->setMaxResults(10); @@ -591,17 +594,17 @@ public function testGetQuery() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + ->from(CmsUser::class, 'u'); $q = $qb->getQuery(); - $this->assertEquals('Doctrine\ORM\Query', get_class($q)); + $this->assertEquals(Query::class, get_class($q)); } public function testSetParameter() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->where('u.id = :id') ->setParameter('id', 1); @@ -614,7 +617,7 @@ public function testSetParameters() { $qb = $this->_em->createQueryBuilder(); $qb->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->where($qb->expr()->orX('u.username = :username', 'u.username = :username2')); $parameters = new ArrayCollection(); @@ -631,7 +634,7 @@ public function testGetParameters() { $qb = $this->_em->createQueryBuilder(); $qb->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->where('u.id = :id'); $parameters = new ArrayCollection(); @@ -646,7 +649,7 @@ public function testGetParameter() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->where('u.id = :id'); $parameters = new ArrayCollection(); @@ -661,7 +664,7 @@ public function testMultipleWhere() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->where('u.id = :uid', 'u.id = :uid2'); $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid AND u.id = :uid2'); @@ -671,7 +674,7 @@ public function testMultipleAndWhere() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->andWhere('u.id = :uid', 'u.id = :uid2'); $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid AND u.id = :uid2'); @@ -681,7 +684,7 @@ public function testMultipleOrWhere() { $qb = $this->_em->createQueryBuilder(); $qb->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->orWhere('u.id = :uid', $qb->expr()->eq('u.id', ':uid2')); $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid OR u.id = :uid2'); @@ -695,7 +698,7 @@ public function testComplexWhere() $orExpr->add($qb->expr()->in('u.id', [1])); $qb->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->where($orExpr); $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid3 OR u.id IN(1)'); @@ -705,7 +708,7 @@ public function testWhereInWithStringLiterals() { $qb = $this->_em->createQueryBuilder(); $qb->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->where($qb->expr()->in('u.name', ['one', 'two', 'three'])); $this->assertValidQueryBuilder($qb, "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name IN('one', 'two', 'three')"); @@ -720,7 +723,7 @@ public function testWhereInWithObjectLiterals() $qb = $this->_em->createQueryBuilder(); $expr = $this->_em->getExpressionBuilder(); $qb->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->where($expr->in('u.name', [$expr->literal('one'), $expr->literal('two'), $expr->literal('three')])); $this->assertValidQueryBuilder($qb, "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name IN('one', 'two', 'three')"); @@ -739,7 +742,7 @@ public function testNegation() $qb = $this->_em->createQueryBuilder(); $qb->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->where($orExpr); $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid3 OR NOT(u.id IN(1))'); @@ -750,10 +753,8 @@ public function testSomeAllAny() $qb = $this->_em->createQueryBuilder(); $expr = $this->_em->getExpressionBuilder(); - //$subquery = $qb->subquery('Doctrine\Tests\Models\CMS\CmsArticle', 'a')->select('a.id'); - $qb->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->where($expr->gt('u.id', $expr->all('select a.id from Doctrine\Tests\Models\CMS\CmsArticle a'))); $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id > ALL(select a.id from Doctrine\Tests\Models\CMS\CmsArticle a)'); @@ -765,7 +766,7 @@ public function testMultipleIsolatedQueryConstruction() $qb = $this->_em->createQueryBuilder(); $expr = $this->_em->getExpressionBuilder(); - $qb->select('u')->from('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $qb->select('u')->from(CmsUser::class, 'u'); $qb->where($expr->eq('u.name', ':name')); $qb->setParameter('name', 'romanb'); @@ -802,7 +803,7 @@ public function testAlteringQueryChangesStateToDirty() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + ->from(CmsUser::class, 'u'); $this->assertEquals(QueryBuilder::STATE_DIRTY, $qb->getState()); } @@ -820,7 +821,7 @@ public function testResetDQLPart() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->where('u.username = ?1')->orderBy('u.username'); $this->assertEquals('u.username = ?1', (string)$qb->getDQLPart('where')); @@ -836,7 +837,7 @@ public function testResetDQLParts() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->where('u.username = ?1')->orderBy('u.username'); $qb->resetDQLParts(['where', 'orderBy']); @@ -850,7 +851,7 @@ public function testResetAllDQLParts() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->where('u.username = ?1')->orderBy('u.username'); $qb->resetDQLParts(); @@ -867,7 +868,7 @@ public function testDeepClone() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->andWhere('u.username = ?1') ->andWhere('u.status = ?2'); @@ -886,7 +887,7 @@ public function testDeepClone() public function testAddCriteriaWhereWithJoinAlias() { $qb = $this->_em->createQueryBuilder(); - $qb->select('alias1')->from('Doctrine\Tests\Models\CMS\CmsUser', 'alias1'); + $qb->select('alias1')->from(CmsUser::class, 'alias1'); $qb->join('alias1.articles','alias2'); $criteria = new Criteria(); @@ -906,7 +907,7 @@ public function testAddCriteriaWhereWithJoinAlias() public function testAddCriteriaWhereWithDefaultAndJoinAlias() { $qb = $this->_em->createQueryBuilder(); - $qb->select('alias1')->from('Doctrine\Tests\Models\CMS\CmsUser', 'alias1'); + $qb->select('alias1')->from(CmsUser::class, 'alias1'); $qb->join('alias1.articles','alias2'); $criteria = new Criteria(); @@ -926,7 +927,7 @@ public function testAddCriteriaWhereWithDefaultAndJoinAlias() public function testAddCriteriaWhereOnJoinAliasWithDuplicateFields() { $qb = $this->_em->createQueryBuilder(); - $qb->select('alias1')->from('Doctrine\Tests\Models\CMS\CmsUser', 'alias1'); + $qb->select('alias1')->from(CmsUser::class, 'alias1'); $qb->join('alias1.articles','alias2'); $criteria = new Criteria(); @@ -964,7 +965,7 @@ public function testGetRootAlias() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + ->from(CmsUser::class, 'u'); $this->assertEquals('u', $qb->getRootAlias()); } @@ -973,7 +974,7 @@ public function testGetRootAliases() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + ->from(CmsUser::class, 'u'); $this->assertEquals(['u'], $qb->getRootAliases()); } @@ -982,17 +983,17 @@ public function testGetRootEntities() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + ->from(CmsUser::class, 'u'); - $this->assertEquals(['Doctrine\Tests\Models\CMS\CmsUser'], $qb->getRootEntities()); + $this->assertEquals([CmsUser::class], $qb->getRootEntities()); } public function testGetSeveralRootAliases() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u2'); + ->from(CmsUser::class, 'u') + ->from(CmsUser::class, 'u2'); $this->assertEquals(['u', 'u2'], $qb->getRootAliases()); $this->assertEquals('u', $qb->getRootAlias()); @@ -1002,7 +1003,7 @@ public function testBCAddJoinWithoutRootAlias() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->add('join', ['INNER JOIN u.groups g'], true); $this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.groups g', $qb->getDQL()); @@ -1016,7 +1017,7 @@ public function testEmptyStringLiteral() $expr = $this->_em->getExpressionBuilder(); $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->where($expr->eq('u.username', $expr->literal(""))); $this->assertEquals("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = ''", $qb->getDQL()); @@ -1030,7 +1031,7 @@ public function testEmptyNumericLiteral() $expr = $this->_em->getExpressionBuilder(); $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->where($expr->eq('u.username', $expr->literal(0))); $this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 0', $qb->getDQL()); @@ -1043,7 +1044,7 @@ public function testAddFromString() { $qb = $this->_em->createQueryBuilder() ->add('select', 'u') - ->add('from', 'Doctrine\Tests\Models\CMS\CmsUser u'); + ->add('from', CmsUser::class . ' u'); $this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u', $qb->getDQL()); } @@ -1056,7 +1057,7 @@ public function testAddDistinct() $qb = $this->_em->createQueryBuilder() ->select('u') ->distinct() - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + ->from(CmsUser::class, 'u'); $this->assertEquals('SELECT DISTINCT u FROM Doctrine\Tests\Models\CMS\CmsUser u', $qb->getDQL()); } @@ -1079,7 +1080,7 @@ public function testSecondLevelCacheQueryBuilderOptions() { $defaultQueryBuilder = $this->_em->createQueryBuilder() ->select('s') - ->from('Doctrine\Tests\Models\Cache\State', 's'); + ->from(State::class, 's'); $this->assertFalse($defaultQueryBuilder->isCacheable()); $this->assertEquals(0, $defaultQueryBuilder->getLifetime()); @@ -1099,7 +1100,7 @@ public function testSecondLevelCacheQueryBuilderOptions() ->setCacheable(true) ->setCacheRegion('foo_reg') ->setCacheMode(Cache::MODE_REFRESH) - ->from('Doctrine\Tests\Models\Cache\State', 's'); + ->from(State::class, 's'); $this->assertTrue($builder->isCacheable()); $this->assertEquals(123, $builder->getLifetime()); @@ -1121,7 +1122,7 @@ public function testRebuildsFromParts() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->join('u.article', 'a'); $dqlParts = $qb->getDQLParts(); @@ -1139,7 +1140,7 @@ public function testRebuildsFromParts() public function testGetAllAliasesWithNoJoins() { $qb = $this->_em->createQueryBuilder(); - $qb->select('u')->from('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + $qb->select('u')->from(CmsUser::class, 'u'); $aliases = $qb->getAllAliases(); @@ -1150,7 +1151,7 @@ public function testGetAllAliasesWithJoins() { $qb = $this->_em->createQueryBuilder() ->select('u') - ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->from(CmsUser::class, 'u') ->join('u.groups', 'g'); $aliases = $qb->getAllAliases(); diff --git a/tests/Doctrine/Tests/ORM/Repository/DefaultRepositoryFactoryTest.php b/tests/Doctrine/Tests/ORM/Repository/DefaultRepositoryFactoryTest.php index 182554c9325..963757618af 100644 --- a/tests/Doctrine/Tests/ORM/Repository/DefaultRepositoryFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Repository/DefaultRepositoryFactoryTest.php @@ -6,6 +6,8 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Repository\DefaultRepositoryFactory; +use Doctrine\Tests\Models\DDC753\DDC753DefaultRepository; +use Doctrine\Tests\Models\DDC869\DDC869PaymentRepository; use PHPUnit_Framework_TestCase; /** @@ -39,31 +41,28 @@ protected function setUp() $this->entityManager = $this->createEntityManager(); $this->repositoryFactory = new DefaultRepositoryFactory(); - $this - ->configuration + $this->configuration ->expects($this->any()) ->method('getDefaultRepositoryClassName') - ->will($this->returnValue('Doctrine\\Tests\\Models\\DDC869\\DDC869PaymentRepository')); + ->will($this->returnValue(DDC869PaymentRepository::class)); } public function testCreatesRepositoryFromDefaultRepositoryClass() { - $this - ->entityManager + $this->entityManager ->expects($this->any()) ->method('getClassMetadata') ->will($this->returnCallback([$this, 'buildClassMetadata'])); $this->assertInstanceOf( - 'Doctrine\\Tests\\Models\\DDC869\\DDC869PaymentRepository', + DDC869PaymentRepository::class, $this->repositoryFactory->getRepository($this->entityManager, __CLASS__) ); } public function testCreatedRepositoriesAreCached() { - $this - ->entityManager + $this->entityManager ->expects($this->any()) ->method('getClassMetadata') ->will($this->returnCallback([$this, 'buildClassMetadata'])); @@ -77,17 +76,15 @@ public function testCreatedRepositoriesAreCached() public function testCreatesRepositoryFromCustomClassMetadata() { $customMetadata = $this->buildClassMetadata(__DIR__); + $customMetadata->customRepositoryClassName = DDC753DefaultRepository::class; - $customMetadata->customRepositoryClassName = 'Doctrine\\Tests\\Models\\DDC753\\DDC753DefaultRepository'; - - $this - ->entityManager + $this->entityManager ->expects($this->any()) ->method('getClassMetadata') ->will($this->returnValue($customMetadata)); $this->assertInstanceOf( - 'Doctrine\\Tests\\Models\\DDC753\\DDC753DefaultRepository', + DDC753DefaultRepository::class, $this->repositoryFactory->getRepository($this->entityManager, __CLASS__) ); } @@ -97,12 +94,11 @@ public function testCachesDistinctRepositoriesPerDistinctEntityManager() $em1 = $this->createEntityManager(); $em2 = $this->createEntityManager(); - $em1 - ->expects($this->any()) + $em1->expects($this->any()) ->method('getClassMetadata') ->will($this->returnCallback([$this, 'buildClassMetadata'])); - $em2 - ->expects($this->any()) + + $em2->expects($this->any()) ->method('getClassMetadata') ->will($this->returnCallback([$this, 'buildClassMetadata'])); @@ -141,8 +137,7 @@ private function createEntityManager() { $entityManager = $this->createMock(EntityManagerInterface::class); - $entityManager - ->expects($this->any()) + $entityManager->expects($this->any()) ->method('getConfiguration') ->will($this->returnValue($this->configuration)); diff --git a/tests/Doctrine/Tests/ORM/Tools/AttachEntityListenersListenerTest.php b/tests/Doctrine/Tests/ORM/Tools/AttachEntityListenersListenerTest.php index 8c0a7a75bcd..5008470feb5 100644 --- a/tests/Doctrine/Tests/ORM/Tools/AttachEntityListenersListenerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/AttachEntityListenersListenerTest.php @@ -40,36 +40,36 @@ public function setUp() public function testAttachEntityListeners() { $this->listener->addEntityListener( - AttachEntityListenersListenerTestFooEntity::CLASSNAME, - AttachEntityListenersListenerTestListener::CLASSNAME, + AttachEntityListenersListenerTestFooEntity::class, + AttachEntityListenersListenerTestListener::class, Events::postLoad, 'postLoadHandler' ); - $metadata = $this->factory->getMetadataFor(AttachEntityListenersListenerTestFooEntity::CLASSNAME); + $metadata = $this->factory->getMetadataFor(AttachEntityListenersListenerTestFooEntity::class); $this->assertArrayHasKey('postLoad', $metadata->entityListeners); $this->assertCount(1, $metadata->entityListeners['postLoad']); $this->assertEquals('postLoadHandler', $metadata->entityListeners['postLoad'][0]['method']); - $this->assertEquals(AttachEntityListenersListenerTestListener::CLASSNAME, $metadata->entityListeners['postLoad'][0]['class']); + $this->assertEquals(AttachEntityListenersListenerTestListener::class, $metadata->entityListeners['postLoad'][0]['class']); } public function testAttachToExistingEntityListeners() { $this->listener->addEntityListener( - AttachEntityListenersListenerTestBarEntity::CLASSNAME, - AttachEntityListenersListenerTestListener2::CLASSNAME, + AttachEntityListenersListenerTestBarEntity::class, + AttachEntityListenersListenerTestListener2::class, Events::prePersist ); $this->listener->addEntityListener( - AttachEntityListenersListenerTestBarEntity::CLASSNAME, - AttachEntityListenersListenerTestListener2::CLASSNAME, + AttachEntityListenersListenerTestBarEntity::class, + AttachEntityListenersListenerTestListener2::class, Events::postPersist, 'postPersistHandler' ); - $metadata = $this->factory->getMetadataFor(AttachEntityListenersListenerTestBarEntity::CLASSNAME); + $metadata = $this->factory->getMetadataFor(AttachEntityListenersListenerTestBarEntity::class); $this->assertArrayHasKey('postPersist', $metadata->entityListeners); $this->assertArrayHasKey('prePersist', $metadata->entityListeners); @@ -78,16 +78,16 @@ public function testAttachToExistingEntityListeners() $this->assertCount(2, $metadata->entityListeners['postPersist']); $this->assertEquals('prePersist', $metadata->entityListeners['prePersist'][0]['method']); - $this->assertEquals(AttachEntityListenersListenerTestListener::CLASSNAME, $metadata->entityListeners['prePersist'][0]['class']); + $this->assertEquals(AttachEntityListenersListenerTestListener::class, $metadata->entityListeners['prePersist'][0]['class']); $this->assertEquals('prePersist', $metadata->entityListeners['prePersist'][1]['method']); - $this->assertEquals(AttachEntityListenersListenerTestListener2::CLASSNAME, $metadata->entityListeners['prePersist'][1]['class']); + $this->assertEquals(AttachEntityListenersListenerTestListener2::class, $metadata->entityListeners['prePersist'][1]['class']); $this->assertEquals('postPersist', $metadata->entityListeners['postPersist'][0]['method']); - $this->assertEquals(AttachEntityListenersListenerTestListener::CLASSNAME, $metadata->entityListeners['postPersist'][0]['class']); + $this->assertEquals(AttachEntityListenersListenerTestListener::class, $metadata->entityListeners['postPersist'][0]['class']); $this->assertEquals('postPersistHandler', $metadata->entityListeners['postPersist'][1]['method']); - $this->assertEquals(AttachEntityListenersListenerTestListener2::CLASSNAME, $metadata->entityListeners['postPersist'][1]['class']); + $this->assertEquals(AttachEntityListenersListenerTestListener2::class, $metadata->entityListeners['postPersist'][1]['class']); } /** @@ -97,18 +97,18 @@ public function testAttachToExistingEntityListeners() public function testDuplicateEntityListenerException() { $this->listener->addEntityListener( - AttachEntityListenersListenerTestFooEntity::CLASSNAME, - AttachEntityListenersListenerTestListener::CLASSNAME, + AttachEntityListenersListenerTestFooEntity::class, + AttachEntityListenersListenerTestListener::class, Events::postPersist ); $this->listener->addEntityListener( - AttachEntityListenersListenerTestFooEntity::CLASSNAME, - AttachEntityListenersListenerTestListener::CLASSNAME, + AttachEntityListenersListenerTestFooEntity::class, + AttachEntityListenersListenerTestListener::class, Events::postPersist ); - $this->factory->getMetadataFor(AttachEntityListenersListenerTestFooEntity::CLASSNAME); + $this->factory->getMetadataFor(AttachEntityListenersListenerTestFooEntity::class); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheCollectionRegionCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheCollectionRegionCommandTest.php index c8e2abca785..5ac2f97527d 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheCollectionRegionCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheCollectionRegionCommandTest.php @@ -4,10 +4,11 @@ use Doctrine\ORM\Tools\Console\Command\ClearCache\CollectionRegionCommand; use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; -use Symfony\Component\Console\Tester\CommandTester; -use Symfony\Component\Console\Helper\HelperSet; -use Symfony\Component\Console\Application; +use Doctrine\Tests\Models\Cache\State; use Doctrine\Tests\OrmFunctionalTestCase; +use Symfony\Component\Console\Application; +use Symfony\Component\Console\Helper\HelperSet; +use Symfony\Component\Console\Tester\CommandTester; /** * @group DDC-2183 @@ -62,7 +63,7 @@ public function testClearByOwnerEntityClassName() $tester->execute( [ 'command' => $command->getName(), - 'owner-class' => 'Doctrine\Tests\Models\Cache\State', + 'owner-class' => State::class, 'association' => 'cities', ], ['decorated' => false] ); @@ -77,7 +78,7 @@ public function testClearCacheEntryName() $tester->execute( [ 'command' => $command->getName(), - 'owner-class' => 'Doctrine\Tests\Models\Cache\State', + 'owner-class' => State::class, 'association' => 'cities', 'owner-id' => 1, ], ['decorated' => false] @@ -93,7 +94,7 @@ public function testFlushRegionName() $tester->execute( [ 'command' => $command->getName(), - 'owner-class' => 'Doctrine\Tests\Models\Cache\State', + 'owner-class' => State::class, 'association' => 'cities', '--flush' => true, ], ['decorated' => false] diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheEntityRegionCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheEntityRegionCommandTest.php index b579c14d12d..3546a3116df 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheEntityRegionCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheEntityRegionCommandTest.php @@ -4,10 +4,11 @@ use Doctrine\ORM\Tools\Console\Command\ClearCache\EntityRegionCommand; use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; -use Symfony\Component\Console\Tester\CommandTester; -use Symfony\Component\Console\Helper\HelperSet; -use Symfony\Component\Console\Application; +use Doctrine\Tests\Models\Cache\Country; use Doctrine\Tests\OrmFunctionalTestCase; +use Symfony\Component\Console\Application; +use Symfony\Component\Console\Helper\HelperSet; +use Symfony\Component\Console\Tester\CommandTester; /** * @group DDC-2183 @@ -62,7 +63,7 @@ public function testClearByEntityClassName() $tester->execute( [ 'command' => $command->getName(), - 'entity-class' => 'Doctrine\Tests\Models\Cache\Country', + 'entity-class' => Country::class, ], ['decorated' => false] ); @@ -76,7 +77,7 @@ public function testClearCacheEntryName() $tester->execute( [ 'command' => $command->getName(), - 'entity-class' => 'Doctrine\Tests\Models\Cache\Country', + 'entity-class' => Country::class, 'entity-id' => 1, ], ['decorated' => false] ); @@ -91,7 +92,7 @@ public function testFlushRegionName() $tester->execute( [ 'command' => $command->getName(), - 'entity-class' => 'Doctrine\Tests\Models\Cache\Country', + 'entity-class' => Country::class, '--flush' => true, ], ['decorated' => false] ); diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php index e306c34b6f4..45bdfa3862f 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php @@ -2,8 +2,10 @@ namespace Doctrine\Tests\ORM\Tools\Console\Command; +use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand; use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; +use Doctrine\Tests\Models\DDC3231\DDC3231EntityRepository; use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Helper\HelperSet; use Symfony\Component\Console\Application; @@ -98,13 +100,13 @@ public function testGenerateRepositories() $repo1 = new \ReflectionClass($cname); $repo2 = new \ReflectionClass('DDC3231User1NoNamespaceRepository'); - $this->assertSame('Doctrine\ORM\EntityRepository', $repo1->getParentClass()->getName()); - $this->assertSame('Doctrine\ORM\EntityRepository', $repo2->getParentClass()->getName()); + $this->assertSame(EntityRepository::class, $repo1->getParentClass()->getName()); + $this->assertSame(EntityRepository::class, $repo2->getParentClass()->getName()); } public function testGenerateRepositoriesCustomDefaultRepository() { - $this->generateRepositories('DDC3231User2', 'Doctrine\Tests\Models\DDC3231\DDC3231EntityRepository'); + $this->generateRepositories('DDC3231User2', DDC3231EntityRepository::class); $cname = 'Doctrine\Tests\Models\DDC3231\DDC3231User2Repository'; $fname = str_replace('\\', DIRECTORY_SEPARATOR, $cname) . '.php'; @@ -121,8 +123,8 @@ public function testGenerateRepositoriesCustomDefaultRepository() $repo1 = new \ReflectionClass($cname); $repo2 = new \ReflectionClass('DDC3231User2NoNamespaceRepository'); - $this->assertSame('Doctrine\Tests\Models\DDC3231\DDC3231EntityRepository', $repo1->getParentClass()->getName()); - $this->assertSame('Doctrine\Tests\Models\DDC3231\DDC3231EntityRepository', $repo2->getParentClass()->getName()); + $this->assertSame(DDC3231EntityRepository::class, $repo1->getParentClass()->getName()); + $this->assertSame(DDC3231EntityRepository::class, $repo2->getParentClass()->getName()); } /** diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/InfoCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/InfoCommandTest.php index 01a4d13db13..a27fb90d79a 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/InfoCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/InfoCommandTest.php @@ -3,6 +3,8 @@ namespace Doctrine\Tests\ORM\Tools\Console\Command; use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; +use Doctrine\Tests\Models\Cache\AttractionInfo; +use Doctrine\Tests\Models\Cache\City; use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Helper\HelperSet; use Symfony\Component\Console\Application; @@ -33,11 +35,9 @@ protected function setUp() $this->application = new Application(); $command = new InfoCommand(); - $this->application->setHelperSet(new HelperSet( - [ - 'em' => new EntityManagerHelper($this->_em) - ] - )); + $this->application->setHelperSet( + new HelperSet(['em' => new EntityManagerHelper($this->_em)]) + ); $this->application->add($command); @@ -47,13 +47,9 @@ protected function setUp() public function testListAllClasses() { - $this->tester->execute( - [ - 'command' => $this->command->getName(), - ] - ); + $this->tester->execute(['command' => $this->command->getName()]); - $this->assertContains('Doctrine\Tests\Models\Cache\AttractionInfo', $this->tester->getDisplay()); - $this->assertContains('Doctrine\Tests\Models\Cache\City', $this->tester->getDisplay()); + $this->assertContains(AttractionInfo::class, $this->tester->getDisplay()); + $this->assertContains(City::class, $this->tester->getDisplay()); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/MappingDescribeCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/MappingDescribeCommandTest.php index 9f1cec7f490..437f521e3d7 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/MappingDescribeCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/MappingDescribeCommandTest.php @@ -4,6 +4,7 @@ use Doctrine\ORM\Tools\Console\Command\MappingDescribeCommand; use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; +use Doctrine\Tests\Models\Cache\AttractionInfo; use Doctrine\Tests\OrmFunctionalTestCase; use Symfony\Component\Console\Application; use Symfony\Component\Console\Helper\HelperSet; @@ -60,7 +61,7 @@ public function testShowSpecificFuzzySingle() ); $display = $this->tester->getDisplay(); - $this->assertContains('Doctrine\Tests\Models\Cache\AttractionInfo', $display); + $this->assertContains(AttractionInfo::class, $display); $this->assertContains('Root entity name', $display); } diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php index aa74ce75305..e2e68bd7e28 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php @@ -67,12 +67,12 @@ public function testWillRunQuery() $this->tester->execute( [ 'command' => $this->command->getName(), - 'dql' => 'SELECT e FROM ' . DateTimeModel::CLASSNAME . ' e', + 'dql' => 'SELECT e FROM ' . DateTimeModel::class . ' e', ] ) ); - $this->assertContains(DateTimeModel::CLASSNAME, $this->tester->getDisplay()); + $this->assertContains(DateTimeModel::class, $this->tester->getDisplay()); } public function testWillShowQuery() @@ -85,7 +85,7 @@ public function testWillShowQuery() $this->tester->execute( [ 'command' => $this->command->getName(), - 'dql' => 'SELECT e FROM ' . DateTimeModel::CLASSNAME . ' e', + 'dql' => 'SELECT e FROM ' . DateTimeModel::class . ' e', '--show-sql' => 'true' ] ) diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index e51bb311658..5a9f451fe32 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -67,7 +67,7 @@ public function generateBookEntityFixture(array $embeddedClasses = []) $metadata->mapField(['fieldName' => 'status', 'type' => 'string', 'options' => ['default' => 'published']]); $metadata->mapField(['fieldName' => 'id', 'type' => 'integer', 'id' => true]); $metadata->mapOneToOne( - ['fieldName' => 'author', 'targetEntity' => 'Doctrine\Tests\ORM\Tools\EntityGeneratorAuthor', 'mappedBy' => 'book'] + ['fieldName' => 'author', 'targetEntity' => EntityGeneratorAuthor::class, 'mappedBy' => 'book'] ); $joinColumns = [ ['name' => 'author_id', 'referencedColumnName' => 'id'] @@ -75,7 +75,7 @@ public function generateBookEntityFixture(array $embeddedClasses = []) $metadata->mapManyToMany( [ 'fieldName' => 'comments', - 'targetEntity' => 'Doctrine\Tests\ORM\Tools\EntityGeneratorComment', + 'targetEntity' => EntityGeneratorComment::class, 'fetch' => ClassMetadataInfo::FETCH_EXTRA_LAZY, 'joinTable' => [ 'name' => 'book_comment', @@ -270,7 +270,7 @@ public function testGeneratedEntityClass() $comment = new EntityGeneratorComment(); $this->assertInstanceOf($metadata->name, $book->addComment($comment)); - $this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $book->getComments()); + $this->assertInstanceOf(ArrayCollection::class, $book->getComments()); $this->assertEquals(new ArrayCollection([$comment]), $book->getComments()); $this->assertInternalType('boolean', $book->removeComment($comment)); $this->assertEquals(new ArrayCollection([]), $book->getComments()); diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityRepositoryGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityRepositoryGeneratorTest.php index f40aba8f2aa..feff13dc066 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityRepositoryGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityRepositoryGeneratorTest.php @@ -2,9 +2,13 @@ namespace Doctrine\Tests\ORM\Tools; +use Doctrine\ORM\EntityRepository; +use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Tools\EntityGenerator; use Doctrine\ORM\Tools\EntityRepositoryGenerator; -use Doctrine\ORM\Mapping\ClassMetadataFactory; +use Doctrine\Tests\Models\DDC3231\DDC3231EntityRepository; +use Doctrine\Tests\Models\DDC3231\DDC3231User1; +use Doctrine\Tests\Models\DDC3231\DDC3231User2; use Doctrine\Tests\OrmTestCase; class EntityRepositoryGeneratorTest extends OrmTestCase @@ -74,11 +78,8 @@ public function testGeneratedEntityRepositoryClass() $em = $this->_getTestEntityManager(); $ns = $this->_namespace; - - require_once __DIR__ . '/../../Models/DDC3231/DDC3231User1.php'; - $className = $ns . '\DDC3231User1Tmp'; - $this->writeEntityClass('Doctrine\Tests\Models\DDC3231\DDC3231User1', $className); + $this->writeEntityClass(DDC3231User1::class, $className); $rpath = $this->writeRepositoryClass($className); @@ -90,13 +91,12 @@ public function testGeneratedEntityRepositoryClass() $this->assertTrue($repo->inNamespace()); $this->assertSame($className . 'Repository', $repo->getName()); - $this->assertSame('Doctrine\ORM\EntityRepository', $repo->getParentClass()->getName()); - + $this->assertSame(EntityRepository::class, $repo->getParentClass()->getName()); require_once __DIR__ . '/../../Models/DDC3231/DDC3231User1NoNamespace.php'; $className2 = 'DDC3231User1NoNamespaceTmp'; - $this->writeEntityClass('DDC3231User1NoNamespace', $className2); + $this->writeEntityClass(\DDC3231User1NoNamespace::class, $className2); $rpath2 = $this->writeRepositoryClass($className2); @@ -108,7 +108,7 @@ public function testGeneratedEntityRepositoryClass() $this->assertFalse($repo2->inNamespace()); $this->assertSame($className2 . 'Repository', $repo2->getName()); - $this->assertSame('Doctrine\ORM\EntityRepository', $repo2->getParentClass()->getName()); + $this->assertSame(EntityRepository::class, $repo2->getParentClass()->getName()); } /** @@ -119,13 +119,10 @@ public function testGeneratedEntityRepositoryClassCustomDefaultRepository() $em = $this->_getTestEntityManager(); $ns = $this->_namespace; - - require_once __DIR__ . '/../../Models/DDC3231/DDC3231User2.php'; - $className = $ns . '\DDC3231User2Tmp'; - $this->writeEntityClass('Doctrine\Tests\Models\DDC3231\DDC3231User2', $className); + $this->writeEntityClass(DDC3231User2::class, $className); - $rpath = $this->writeRepositoryClass($className, 'Doctrine\Tests\Models\DDC3231\DDC3231EntityRepository'); + $rpath = $this->writeRepositoryClass($className, DDC3231EntityRepository::class); $this->assertNotNull($rpath); $this->assertFileExists($rpath); @@ -136,7 +133,7 @@ public function testGeneratedEntityRepositoryClassCustomDefaultRepository() $this->assertTrue($repo->inNamespace()); $this->assertSame($className . 'Repository', $repo->getName()); - $this->assertSame('Doctrine\Tests\Models\DDC3231\DDC3231EntityRepository', $repo->getParentClass()->getName()); + $this->assertSame(DDC3231EntityRepository::class, $repo->getParentClass()->getName()); require_once __DIR__ . '/../../Models/DDC3231/DDC3231User2NoNamespace.php'; @@ -144,7 +141,7 @@ public function testGeneratedEntityRepositoryClassCustomDefaultRepository() $className2 = 'DDC3231User2NoNamespaceTmp'; $this->writeEntityClass('DDC3231User2NoNamespace', $className2); - $rpath2 = $this->writeRepositoryClass($className2, 'Doctrine\Tests\Models\DDC3231\DDC3231EntityRepository'); + $rpath2 = $this->writeRepositoryClass($className2, DDC3231EntityRepository::class); $this->assertNotNull($rpath2); $this->assertFileExists($rpath2); @@ -155,13 +152,12 @@ public function testGeneratedEntityRepositoryClassCustomDefaultRepository() $this->assertFalse($repo2->inNamespace()); $this->assertSame($className2 . 'Repository', $repo2->getName()); - $this->assertSame('Doctrine\Tests\Models\DDC3231\DDC3231EntityRepository', $repo2->getParentClass()->getName()); + $this->assertSame(DDC3231EntityRepository::class, $repo2->getParentClass()->getName()); } /** * @param string $className * @param string $newClassName - * @return string */ private function writeEntityClass($className, $newClassName) { diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php index 2cf91c39047..e9523b5b1df 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php @@ -2,17 +2,20 @@ namespace Doctrine\Tests\ORM\Tools\Export; +use Doctrine\Common\EventManager; +use Doctrine\Common\Persistence\Mapping\Driver\PHPDriver; use Doctrine\ORM\Configuration; -use Doctrine\ORM\Tools\Export\ClassMetadataExporter; +use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\ORM\Mapping\Driver\AnnotationDriver; +use Doctrine\ORM\Mapping\Driver\XmlDriver; +use Doctrine\ORM\Mapping\Driver\YamlDriver; +use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory; use Doctrine\ORM\Tools\EntityGenerator; -use Doctrine\Tests\Mocks\MetadataDriverMock; -use Doctrine\Tests\Mocks\EntityManagerMock; +use Doctrine\ORM\Tools\Export\ClassMetadataExporter; use Doctrine\Tests\Mocks\ConnectionMock; use Doctrine\Tests\Mocks\DriverMock; -use Doctrine\Common\EventManager; -use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory; -use Doctrine\ORM\Mapping\ClassMetadataFactory; +use Doctrine\Tests\Mocks\EntityManagerMock; use Doctrine\Tests\OrmTestCase; use Symfony\Component\Yaml\Parser; @@ -48,10 +51,10 @@ protected function _createEntityManager($metadataDriver) protected function _createMetadataDriver($type, $path) { $mappingDriver = [ - 'php' => 'Doctrine\Common\Persistence\Mapping\Driver\PHPDriver', - 'annotation' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver', - 'xml' => 'Doctrine\ORM\Mapping\Driver\XmlDriver', - 'yaml' => 'Doctrine\ORM\Mapping\Driver\YamlDriver', + 'php' => PHPDriver::class, + 'annotation' => AnnotationDriver::class, + 'xml' => XmlDriver::class, + 'yaml' => YamlDriver::class, ]; $this->assertArrayHasKey($type, $mappingDriver, "There is no metadata driver for the type '" . $type . "'."); @@ -85,9 +88,9 @@ public function testExportDirectoryAndFilesAreCreated() $cmf = $this->_createClassMetadataFactory($em, $type); $metadata = $cmf->getAllMetadata(); - $metadata[0]->name = 'Doctrine\Tests\ORM\Tools\Export\ExportedUser'; + $metadata[0]->name = ExportedUser::class; - $this->assertEquals('Doctrine\Tests\ORM\Tools\Export\ExportedUser', $metadata[0]->name); + $this->assertEquals(ExportedUser::class, $metadata[0]->name); $type = $this->_getType(); $cme = new ClassMetadataExporter(); @@ -106,7 +109,7 @@ public function testExportDirectoryAndFilesAreCreated() $exporter->export(); if ($type == 'annotation') { - $this->assertTrue(file_exists(__DIR__ . '/export/' . $type . '/'.str_replace('\\', '/', 'Doctrine\Tests\ORM\Tools\Export\ExportedUser').$this->_extension)); + $this->assertTrue(file_exists(__DIR__ . '/export/' . $type . '/'.str_replace('\\', '/', ExportedUser::class).$this->_extension)); } else { $this->assertTrue(file_exists(__DIR__ . '/export/' . $type . '/Doctrine.Tests.ORM.Tools.Export.ExportedUser'.$this->_extension)); } @@ -128,7 +131,7 @@ public function testExportedMetadataCanBeReadBackIn() $class = current($metadata); - $this->assertEquals('Doctrine\Tests\ORM\Tools\Export\ExportedUser', $class->name); + $this->assertEquals(ExportedUser::class, $class->name); return $class; } @@ -225,7 +228,7 @@ public function testFieldsAreProperlySerialized() public function testOneToOneAssociationsAreExported($class) { $this->assertTrue(isset($class->associationMappings['address'])); - $this->assertEquals('Doctrine\Tests\ORM\Tools\Export\Address', $class->associationMappings['address']['targetEntity']); + $this->assertEquals(Address::class, $class->associationMappings['address']['targetEntity']); $this->assertEquals('address_id', $class->associationMappings['address']['joinColumns'][0]['name']); $this->assertEquals('id', $class->associationMappings['address']['joinColumns'][0]['referencedColumnName']); $this->assertEquals('CASCADE', $class->associationMappings['address']['joinColumns'][0]['onDelete']); @@ -247,7 +250,7 @@ public function testOneToOneAssociationsAreExported($class) public function testManyToOneAssociationsAreExported($class) { $this->assertTrue(isset($class->associationMappings['mainGroup'])); - $this->assertEquals('Doctrine\Tests\ORM\Tools\Export\Group', $class->associationMappings['mainGroup']['targetEntity']); + $this->assertEquals(Group::class, $class->associationMappings['mainGroup']['targetEntity']); } /** @@ -257,8 +260,7 @@ public function testManyToOneAssociationsAreExported($class) public function testOneToManyAssociationsAreExported($class) { $this->assertTrue(isset($class->associationMappings['phonenumbers'])); - //$this->assertInstanceOf('Doctrine\ORM\Mapping\OneToManyMapping', $class->associationMappings['phonenumbers']); - $this->assertEquals('Doctrine\Tests\ORM\Tools\Export\Phonenumber', $class->associationMappings['phonenumbers']['targetEntity']); + $this->assertEquals(Phonenumber::class, $class->associationMappings['phonenumbers']['targetEntity']); $this->assertEquals('user', $class->associationMappings['phonenumbers']['mappedBy']); $this->assertEquals(['number' => 'ASC'], $class->associationMappings['phonenumbers']['orderBy']); @@ -280,8 +282,7 @@ public function testOneToManyAssociationsAreExported($class) public function testManyToManyAssociationsAreExported($class) { $this->assertTrue(isset($class->associationMappings['groups'])); - //$this->assertInstanceOf('Doctrine\ORM\Mapping\ManyToManyMapping', $class->associationMappings['groups']); - $this->assertEquals('Doctrine\Tests\ORM\Tools\Export\Group', $class->associationMappings['groups']['targetEntity']); + $this->assertEquals(Group::class, $class->associationMappings['groups']['targetEntity']); $this->assertEquals('cms_users_groups', $class->associationMappings['groups']['joinTable']['name']); $this->assertEquals('user_id', $class->associationMappings['groups']['joinTable']['joinColumns'][0]['name']); @@ -362,9 +363,9 @@ public function testCascadeAllCollapsed() $yaml = new Parser(); $value = $yaml->parse(file_get_contents(__DIR__ . '/export/'.$type.'/Doctrine.Tests.ORM.Tools.Export.ExportedUser.dcm.yml')); - $this->assertTrue(isset($value['Doctrine\Tests\ORM\Tools\Export\ExportedUser']['oneToMany']['interests']['cascade'])); - $this->assertEquals(1, count($value['Doctrine\Tests\ORM\Tools\Export\ExportedUser']['oneToMany']['interests']['cascade'])); - $this->assertEquals('all', $value['Doctrine\Tests\ORM\Tools\Export\ExportedUser']['oneToMany']['interests']['cascade'][0]); + $this->assertTrue(isset($value[ExportedUser::class]['oneToMany']['interests']['cascade'])); + $this->assertEquals(1, count($value[ExportedUser::class]['oneToMany']['interests']['cascade'])); + $this->assertEquals('all', $value[ExportedUser::class]['oneToMany']['interests']['cascade'][0]); } else { $this->markTestSkipped('Test not available for '.$type.' driver'); } diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/php/Doctrine.Tests.ORM.Tools.Export.User.php b/tests/Doctrine/Tests/ORM/Tools/Export/php/Doctrine.Tests.ORM.Tools.Export.User.php index 8fe7425d92b..5c8a0c013ba 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/php/Doctrine.Tests.ORM.Tools.Export.User.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/php/Doctrine.Tests.ORM.Tools.Export.User.php @@ -1,6 +1,7 @@ setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE); $metadata->setPrimaryTable( @@ -50,13 +51,13 @@ $metadata->mapManyToOne( [ 'fieldName' => 'mainGroup', - 'targetEntity' => 'Doctrine\\Tests\\ORM\Tools\\Export\\Group', + 'targetEntity' => Export\Group::class, ] ); $metadata->mapOneToOne( [ 'fieldName' => 'address', - 'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\Export\\Address', + 'targetEntity' => Export\Address::class, 'inversedBy' => 'user', 'cascade' => [ @@ -79,7 +80,7 @@ $metadata->mapOneToOne( [ 'fieldName' => 'cart', - 'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\Export\\Cart', + 'targetEntity' => Export\Cart::class, 'mappedBy' => 'user', 'cascade' => [ @@ -93,7 +94,7 @@ $metadata->mapOneToMany( [ 'fieldName' => 'phonenumbers', - 'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\Export\\Phonenumber', + 'targetEntity' => Export\Phonenumber::class, 'cascade' => [ 1 => 'persist', @@ -111,7 +112,7 @@ $metadata->mapManyToMany( [ 'fieldName' => 'groups', - 'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\Export\\Group', + 'targetEntity' => Export\Group::class, 'fetch' => ClassMetadataInfo::FETCH_EXTRA_LAZY, 'cascade' => [ diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/CountOutputWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/CountOutputWalkerTest.php index 691b8ef2014..5f999f28a01 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/CountOutputWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/CountOutputWalkerTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM\Tools\Pagination; use Doctrine\ORM\Query; +use Doctrine\ORM\Tools\Pagination\CountOutputWalker; class CountOutputWalkerTest extends PaginationTestCase { @@ -10,7 +11,7 @@ public function testCountQuery() { $query = $this->entityManager->createQuery( 'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p JOIN p.category c JOIN p.author a'); - $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\CountOutputWalker'); + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, CountOutputWalker::class); $query->setFirstResult(null)->setMaxResults(null); $this->assertEquals( @@ -22,7 +23,7 @@ public function testCountQuery_MixedResultsWithName() { $query = $this->entityManager->createQuery( 'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a'); - $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\CountOutputWalker'); + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, CountOutputWalker::class); $query->setFirstResult(null)->setMaxResults(null); $this->assertEquals( @@ -34,7 +35,7 @@ public function testCountQuery_Having() { $query = $this->entityManager->createQuery( 'SELECT g, u, count(u.id) AS userCount FROM Doctrine\Tests\ORM\Tools\Pagination\Group g LEFT JOIN g.users u GROUP BY g.id HAVING userCount > 0'); - $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\CountOutputWalker'); + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, CountOutputWalker::class); $query->setFirstResult(null)->setMaxResults(null); $this->assertEquals( @@ -50,7 +51,7 @@ public function testCountQueryOrderBySqlServer() $query = $this->entityManager->createQuery( 'SELECT p FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p ORDER BY p.id'); - $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\CountOutputWalker'); + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, CountOutputWalker::class); $query->setFirstResult(null)->setMaxResults(null); $this->assertEquals( diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/CountWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/CountWalkerTest.php index cb085124d6c..2aa398d6fbe 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/CountWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/CountWalkerTest.php @@ -14,7 +14,7 @@ public function testCountQuery() { $query = $this->entityManager->createQuery( 'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p JOIN p.category c JOIN p.author a'); - $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\CountWalker']); + $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [CountWalker::class]); $query->setHint(CountWalker::HINT_DISTINCT, true); $query->setFirstResult(null)->setMaxResults(null); @@ -27,7 +27,7 @@ public function testCountQuery_MixedResultsWithName() { $query = $this->entityManager->createQuery( 'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a'); - $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\CountWalker']); + $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [CountWalker::class]); $query->setHint(CountWalker::HINT_DISTINCT, true); $query->setFirstResult(null)->setMaxResults(null); @@ -40,7 +40,7 @@ public function testCountQuery_KeepsGroupBy() { $query = $this->entityManager->createQuery( 'SELECT b FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost b GROUP BY b.id'); - $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\CountWalker']); + $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [CountWalker::class]); $query->setHint(CountWalker::HINT_DISTINCT, true); $query->setFirstResult(null)->setMaxResults(null); @@ -53,7 +53,7 @@ public function testCountQuery_RemovesOrderBy() { $query = $this->entityManager->createQuery( 'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p JOIN p.category c JOIN p.author a ORDER BY a.name'); - $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\CountWalker']); + $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [CountWalker::class]); $query->setHint(CountWalker::HINT_DISTINCT, true); $query->setFirstResult(null)->setMaxResults(null); @@ -66,7 +66,7 @@ public function testCountQuery_RemovesLimits() { $query = $this->entityManager->createQuery( 'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p JOIN p.category c JOIN p.author a'); - $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\CountWalker']); + $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [CountWalker::class]); $query->setHint(CountWalker::HINT_DISTINCT, true); $query->setFirstResult(null)->setMaxResults(null); @@ -80,7 +80,7 @@ public function testCountQuery_HavingException() $query = $this->entityManager->createQuery( "SELECT g, COUNT(u.id) AS userCount FROM Doctrine\Tests\Models\CMS\CmsGroup g LEFT JOIN g.users u GROUP BY g.id HAVING userCount > 0" ); - $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\CountWalker']); + $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [CountWalker::class]); $query->setFirstResult(null)->setMaxResults(null); $this->expectException(\RuntimeException::class); @@ -96,7 +96,7 @@ public function testCountQueryWithArbitraryJoin() { $query = $this->entityManager->createQuery( 'SELECT p FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p LEFT JOIN Doctrine\Tests\ORM\Tools\Pagination\Category c WITH p.category = c'); - $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\CountWalker']); + $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [CountWalker::class]); $query->setHint(CountWalker::HINT_DISTINCT, true); $query->setFirstResult(null)->setMaxResults(null); diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php index 78fd38e9a39..06e21173df2 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Platforms\PostgreSqlPlatform; use Doctrine\ORM\Query; +use Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker; class LimitSubqueryOutputWalkerTest extends PaginationTestCase { @@ -15,7 +16,7 @@ public function testLimitSubquery() 'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category c JOIN p.author a'); $query->expireQueryCache(true); $limitQuery = clone $query; - $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( "SELECT DISTINCT id_0 FROM (SELECT m0_.id AS id_0, m0_.title AS title_1, c1_.id AS id_2, a2_.id AS id_3, a2_.name AS name_4, m0_.author_id AS author_id_5, m0_.category_id AS category_id_6 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON m0_.category_id = c1_.id INNER JOIN Author a2_ ON m0_.author_id = a2_.id) dctrn_result", $limitQuery->getSQL() @@ -30,7 +31,7 @@ public function testLimitSubqueryWithSortPg() $query = $this->entityManager->createQuery( 'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category c JOIN p.author a ORDER BY p.title'); $limitQuery = clone $query; - $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( "SELECT DISTINCT id_0, MIN(sclr_5) AS dctrn_minrownum FROM (SELECT m0_.id AS id_0, m0_.title AS title_1, c1_.id AS id_2, a2_.id AS id_3, a2_.name AS name_4, ROW_NUMBER() OVER(ORDER BY m0_.title ASC) AS sclr_5, m0_.author_id AS author_id_6, m0_.category_id AS category_id_7 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON m0_.category_id = c1_.id INNER JOIN Author a2_ ON m0_.author_id = a2_.id) dctrn_result GROUP BY id_0 ORDER BY dctrn_minrownum ASC", $limitQuery->getSQL() @@ -48,7 +49,7 @@ public function testLimitSubqueryWithScalarSortPg() 'SELECT u, g, COUNT(g.id) AS g_quantity FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g ORDER BY g_quantity' ); $limitQuery = clone $query; - $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( "SELECT DISTINCT id_1, MIN(sclr_3) AS dctrn_minrownum FROM (SELECT COUNT(g0_.id) AS sclr_0, u1_.id AS id_1, g0_.id AS id_2, ROW_NUMBER() OVER(ORDER BY COUNT(g0_.id) ASC) AS sclr_3 FROM User u1_ INNER JOIN user_group u2_ ON u1_.id = u2_.user_id INNER JOIN groups g0_ ON g0_.id = u2_.group_id) dctrn_result GROUP BY id_1 ORDER BY dctrn_minrownum ASC", @@ -67,7 +68,7 @@ public function testLimitSubqueryWithMixedSortPg() 'SELECT u, g, COUNT(g.id) AS g_quantity FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g ORDER BY g_quantity, u.id DESC' ); $limitQuery = clone $query; - $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( "SELECT DISTINCT id_1, MIN(sclr_3) AS dctrn_minrownum FROM (SELECT COUNT(g0_.id) AS sclr_0, u1_.id AS id_1, g0_.id AS id_2, ROW_NUMBER() OVER(ORDER BY COUNT(g0_.id) ASC, u1_.id DESC) AS sclr_3 FROM User u1_ INNER JOIN user_group u2_ ON u1_.id = u2_.user_id INNER JOIN groups g0_ ON g0_.id = u2_.group_id) dctrn_result GROUP BY id_1 ORDER BY dctrn_minrownum ASC", @@ -86,7 +87,7 @@ public function testLimitSubqueryWithHiddenScalarSortPg() 'SELECT u, g, COUNT(g.id) AS hidden g_quantity FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g ORDER BY g_quantity, u.id DESC' ); $limitQuery = clone $query; - $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( "SELECT DISTINCT id_1, MIN(sclr_3) AS dctrn_minrownum FROM (SELECT COUNT(g0_.id) AS sclr_0, u1_.id AS id_1, g0_.id AS id_2, ROW_NUMBER() OVER(ORDER BY COUNT(g0_.id) ASC, u1_.id DESC) AS sclr_3 FROM User u1_ INNER JOIN user_group u2_ ON u1_.id = u2_.user_id INNER JOIN groups g0_ ON g0_.id = u2_.group_id) dctrn_result GROUP BY id_1 ORDER BY dctrn_minrownum ASC", @@ -105,7 +106,7 @@ public function testLimitSubqueryPg() $this->entityManager->getConnection()->setDatabasePlatform($odp); } - + public function testLimitSubqueryWithSortOracle() { $odp = $this->entityManager->getConnection()->getDatabasePlatform(); @@ -115,7 +116,7 @@ public function testLimitSubqueryWithSortOracle() 'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category c JOIN p.author a ORDER BY p.title'); $query->expireQueryCache(true); $limitQuery = clone $query; - $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( "SELECT DISTINCT ID_0, MIN(SCLR_5) AS dctrn_minrownum FROM (SELECT m0_.id AS ID_0, m0_.title AS TITLE_1, c1_.id AS ID_2, a2_.id AS ID_3, a2_.name AS NAME_4, ROW_NUMBER() OVER(ORDER BY m0_.title ASC) AS SCLR_5, m0_.author_id AS AUTHOR_ID_6, m0_.category_id AS CATEGORY_ID_7 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON m0_.category_id = c1_.id INNER JOIN Author a2_ ON m0_.author_id = a2_.id) dctrn_result GROUP BY ID_0 ORDER BY dctrn_minrownum ASC", $limitQuery->getSQL() @@ -134,7 +135,7 @@ public function testLimitSubqueryWithScalarSortOracle() ); $query->expireQueryCache(true); $limitQuery = clone $query; - $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( "SELECT DISTINCT ID_1, MIN(SCLR_3) AS dctrn_minrownum FROM (SELECT COUNT(g0_.id) AS SCLR_0, u1_.id AS ID_1, g0_.id AS ID_2, ROW_NUMBER() OVER(ORDER BY COUNT(g0_.id) ASC) AS SCLR_3 FROM User u1_ INNER JOIN user_group u2_ ON u1_.id = u2_.user_id INNER JOIN groups g0_ ON g0_.id = u2_.group_id) dctrn_result GROUP BY ID_1 ORDER BY dctrn_minrownum ASC", @@ -154,7 +155,7 @@ public function testLimitSubqueryWithMixedSortOracle() ); $query->expireQueryCache(true); $limitQuery = clone $query; - $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( "SELECT DISTINCT ID_1, MIN(SCLR_3) AS dctrn_minrownum FROM (SELECT COUNT(g0_.id) AS SCLR_0, u1_.id AS ID_1, g0_.id AS ID_2, ROW_NUMBER() OVER(ORDER BY COUNT(g0_.id) ASC, u1_.id DESC) AS SCLR_3 FROM User u1_ INNER JOIN user_group u2_ ON u1_.id = u2_.user_id INNER JOIN groups g0_ ON g0_.id = u2_.group_id) dctrn_result GROUP BY ID_1 ORDER BY dctrn_minrownum ASC", @@ -173,7 +174,7 @@ public function testLimitSubqueryOracle() 'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category c JOIN p.author a'); $query->expireQueryCache(true); $limitQuery = clone $query; - $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( "SELECT DISTINCT ID_0 FROM (SELECT m0_.id AS ID_0, m0_.title AS TITLE_1, c1_.id AS ID_2, a2_.id AS ID_3, a2_.name AS NAME_4, m0_.author_id AS AUTHOR_ID_5, m0_.category_id AS CATEGORY_ID_6 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON m0_.category_id = c1_.id INNER JOIN Author a2_ ON m0_.author_id = a2_.id) dctrn_result", $limitQuery->getSQL() @@ -187,7 +188,7 @@ public function testCountQueryMixedResultsWithName() $query = $this->entityManager->createQuery( 'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a'); $limitQuery = clone $query; - $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( "SELECT DISTINCT id_0 FROM (SELECT a0_.id AS id_0, a0_.name AS name_1, sum(a0_.name) AS sclr_2 FROM Author a0_) dctrn_result", $limitQuery->getSQL() @@ -204,7 +205,7 @@ public function testCountQueryWithArithmeticOrderByCondition() ); $this->entityManager->getConnection()->setDatabasePlatform(new MySqlPlatform()); - $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertSame( 'SELECT DISTINCT id_0 FROM (SELECT a0_.id AS id_0, a0_.name AS name_1 FROM Author a0_) dctrn_result ORDER BY (1 - 1000) * 1 DESC', @@ -219,7 +220,7 @@ public function testCountQueryWithComplexScalarOrderByItem() ); $this->entityManager->getConnection()->setDatabasePlatform(new MySqlPlatform()); - $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertSame( 'SELECT DISTINCT id_0 FROM (SELECT a0_.id AS id_0, a0_.image AS image_1, a0_.image_height AS image_height_2, a0_.image_width AS image_width_3, a0_.image_alt_desc AS image_alt_desc_4, a0_.user_id AS user_id_5 FROM Avatar a0_) dctrn_result ORDER BY image_height_2 * image_width_3 DESC', @@ -234,7 +235,7 @@ public function testCountQueryWithComplexScalarOrderByItemJoined() ); $this->entityManager->getConnection()->setDatabasePlatform(new MySqlPlatform()); - $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertSame( 'SELECT DISTINCT id_0 FROM (SELECT u0_.id AS id_0, a1_.image_height AS image_height_1, a1_.image_width AS image_width_2, a1_.user_id AS user_id_3 FROM User u0_ INNER JOIN Avatar a1_ ON u0_.id = a1_.user_id) dctrn_result ORDER BY image_height_1 * image_width_2 DESC', @@ -249,7 +250,7 @@ public function testCountQueryWithComplexScalarOrderByItemJoinedWithPartial() ); $this->entityManager->getConnection()->setDatabasePlatform(new MySqlPlatform()); - $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertSame( 'SELECT DISTINCT id_0 FROM (SELECT u0_.id AS id_0, a1_.id AS id_1, a1_.image_alt_desc AS image_alt_desc_2, a1_.image_height AS image_height_3, a1_.image_width AS image_width_4, a1_.user_id AS user_id_5 FROM User u0_ INNER JOIN Avatar a1_ ON u0_.id = a1_.user_id) dctrn_result ORDER BY image_height_3 * image_width_4 DESC', @@ -264,7 +265,7 @@ public function testCountQueryWithComplexScalarOrderByItemOracle() ); $this->entityManager->getConnection()->setDatabasePlatform(new OraclePlatform()); - $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertSame( 'SELECT DISTINCT ID_0, MIN(SCLR_5) AS dctrn_minrownum FROM (SELECT a0_.id AS ID_0, a0_.image AS IMAGE_1, a0_.image_height AS IMAGE_HEIGHT_2, a0_.image_width AS IMAGE_WIDTH_3, a0_.image_alt_desc AS IMAGE_ALT_DESC_4, ROW_NUMBER() OVER(ORDER BY a0_.image_height * a0_.image_width DESC) AS SCLR_5, a0_.user_id AS USER_ID_6 FROM Avatar a0_) dctrn_result GROUP BY ID_0 ORDER BY dctrn_minrownum ASC', @@ -281,7 +282,7 @@ public function testLimitSubqueryWithHiddenSelectionInOrderBy() 'SELECT a, a.name AS HIDDEN ord FROM Doctrine\Tests\ORM\Tools\Pagination\Author a ORDER BY ord DESC' ); - $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( 'SELECT DISTINCT id_0 FROM (SELECT a0_.id AS id_0, a0_.name AS name_1, a0_.name AS name_2 FROM Author a0_) dctrn_result ORDER BY name_2 DESC', @@ -296,7 +297,7 @@ public function testLimitSubqueryWithColumnWithSortDirectionInName() ); $this->entityManager->getConnection()->setDatabasePlatform(new MySqlPlatform()); - $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertSame( 'SELECT DISTINCT id_0 FROM (SELECT a0_.id AS id_0, a0_.image AS image_1, a0_.image_height AS image_height_2, a0_.image_width AS image_width_3, a0_.image_alt_desc AS image_alt_desc_4, a0_.user_id AS user_id_5 FROM Avatar a0_) dctrn_result ORDER BY image_alt_desc_4 DESC', @@ -310,7 +311,7 @@ public function testLimitSubqueryWithOrderByInnerJoined() 'SELECT b FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost b JOIN b.author a ORDER BY a.name ASC' ); - $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( 'SELECT DISTINCT id_0 FROM (SELECT b0_.id AS id_0, a1_.name AS name_1, b0_.author_id AS author_id_2, b0_.category_id AS category_id_3 FROM BlogPost b0_ INNER JOIN Author a1_ ON b0_.author_id = a1_.id) dctrn_result ORDER BY name_1 ASC', @@ -326,7 +327,7 @@ public function testLimitSubqueryWithOrderByAndSubSelectInWhereClauseMySql() WHERE ((SELECT COUNT(simple.id) FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost simple) = 1) ORDER BY b.id DESC' ); - $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( 'SELECT DISTINCT id_0 FROM (SELECT b0_.id AS id_0, b0_.author_id AS author_id_1, b0_.category_id AS category_id_2 FROM BlogPost b0_ WHERE ((SELECT COUNT(b1_.id) AS dctrn__1 FROM BlogPost b1_) = 1)) dctrn_result ORDER BY id_0 DESC', @@ -342,7 +343,7 @@ public function testLimitSubqueryWithOrderByAndSubSelectInWhereClausePgSql() WHERE ((SELECT COUNT(simple.id) FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost simple) = 1) ORDER BY b.id DESC' ); - $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( 'SELECT DISTINCT id_0, MIN(sclr_1) AS dctrn_minrownum FROM (SELECT b0_.id AS id_0, ROW_NUMBER() OVER(ORDER BY b0_.id DESC) AS sclr_1, b0_.author_id AS author_id_2, b0_.category_id AS category_id_3 FROM BlogPost b0_ WHERE ((SELECT COUNT(b1_.id) AS dctrn__1 FROM BlogPost b1_) = 1)) dctrn_result GROUP BY id_0 ORDER BY dctrn_minrownum ASC', @@ -361,7 +362,7 @@ public function testLimitSubqueryOrderByFieldFromMappedSuperclass() $query = $this->entityManager->createQuery( 'SELECT b FROM Doctrine\Tests\ORM\Tools\Pagination\Banner b ORDER BY b.id DESC' ); - $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( 'SELECT DISTINCT id_0 FROM (SELECT b0_.id AS id_0, b0_.name AS name_1 FROM Banner b0_) dctrn_result ORDER BY id_0 DESC', @@ -386,7 +387,7 @@ public function testLimitSubqueryOrderBySubSelectOrderByExpression() FROM Doctrine\Tests\ORM\Tools\Pagination\Author a ORDER BY first_blog_post DESC' ); - $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( 'SELECT DISTINCT id_0 FROM (SELECT a0_.id AS id_0, a0_.name AS name_1, (SELECT MIN(m1_.title) AS dctrn__1 FROM MyBlogPost m1_ WHERE m1_.author_id = a0_.id) AS sclr_2 FROM Author a0_) dctrn_result ORDER BY sclr_2 DESC', @@ -411,7 +412,7 @@ public function testLimitSubqueryOrderBySubSelectOrderByExpressionPg() FROM Doctrine\Tests\ORM\Tools\Pagination\Author a ORDER BY first_blog_post DESC' ); - $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( 'SELECT DISTINCT id_0, MIN(sclr_3) AS dctrn_minrownum FROM (SELECT a0_.id AS id_0, a0_.name AS name_1, (SELECT MIN(m1_.title) AS dctrn__1 FROM MyBlogPost m1_ WHERE m1_.author_id = a0_.id) AS sclr_2, ROW_NUMBER() OVER(ORDER BY (SELECT MIN(m1_.title) AS dctrn__2 FROM MyBlogPost m1_ WHERE m1_.author_id = a0_.id) DESC) AS sclr_3 FROM Author a0_) dctrn_result GROUP BY id_0 ORDER BY dctrn_minrownum ASC', @@ -436,7 +437,7 @@ public function testLimitSubqueryOrderBySubSelectOrderByExpressionOracle() FROM Doctrine\Tests\ORM\Tools\Pagination\Author a ORDER BY first_blog_post DESC' ); - $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( 'SELECT DISTINCT ID_0, MIN(SCLR_3) AS dctrn_minrownum FROM (SELECT a0_.id AS ID_0, a0_.name AS NAME_1, (SELECT MIN(m1_.title) AS dctrn__1 FROM MyBlogPost m1_ WHERE m1_.author_id = a0_.id) AS SCLR_2, ROW_NUMBER() OVER(ORDER BY (SELECT MIN(m1_.title) AS dctrn__2 FROM MyBlogPost m1_ WHERE m1_.author_id = a0_.id) DESC) AS SCLR_3 FROM Author a0_) dctrn_result GROUP BY ID_0 ORDER BY dctrn_minrownum ASC', diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php index 5ccec2e757c..8ddc158b928 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM\Tools\Pagination; use Doctrine\ORM\Query; +use Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker; /** * @group DDC-1613 @@ -15,7 +16,7 @@ public function testLimitSubquery() $query = $this->entityManager->createQuery($dql); $limitQuery = clone $query; - $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker']); + $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [LimitSubqueryWalker::class]); $this->assertEquals( "SELECT DISTINCT m0_.id AS id_0 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON m0_.category_id = c1_.id INNER JOIN Author a2_ ON m0_.author_id = a2_.id", @@ -29,7 +30,7 @@ public function testLimitSubqueryWithSort() $query = $this->entityManager->createQuery($dql); $limitQuery = clone $query; - $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker']); + $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [LimitSubqueryWalker::class]); $this->assertEquals( "SELECT DISTINCT m0_.id AS id_0, m0_.title AS title_1 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON m0_.category_id = c1_.id INNER JOIN Author a2_ ON m0_.author_id = a2_.id ORDER BY m0_.title ASC", @@ -43,7 +44,7 @@ public function testCountQuery_MixedResultsWithName() $query = $this->entityManager->createQuery($dql); $limitQuery = clone $query; - $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker']); + $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [LimitSubqueryWalker::class]); $this->assertEquals( "SELECT DISTINCT a0_.id AS id_0, sum(a0_.name) AS sclr_1 FROM Author a0_", @@ -60,7 +61,7 @@ public function testLimitSubqueryWithSortOnAssociation() $query = $this->entityManager->createQuery($dql); $limitQuery = clone $query; - $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker']); + $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [LimitSubqueryWalker::class]); $this->assertEquals( "SELECT DISTINCT m0_.id AS id_0, m0_.author_id AS sclr_1 FROM MyBlogPost m0_ ORDER BY m0_.author_id ASC", @@ -77,7 +78,7 @@ public function testLimitSubqueryWithArbitraryJoin() $query = $this->entityManager->createQuery($dql); $limitQuery = clone $query; - $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker']); + $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [LimitSubqueryWalker::class]); $this->assertEquals( "SELECT DISTINCT m0_.id AS id_0 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON (m0_.category_id = c1_.id)", @@ -91,7 +92,7 @@ public function testLimitSubqueryWithSortWithArbitraryJoin() $query = $this->entityManager->createQuery($dql); $limitQuery = clone $query; - $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker']); + $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [LimitSubqueryWalker::class]); $this->assertEquals( "SELECT DISTINCT m0_.id AS id_0, m0_.title AS title_1 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON (m0_.category_id = c1_.id) ORDER BY m0_.title ASC", diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/WhereInWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/WhereInWalkerTest.php index bbe2dcea6a4..0c7cd48c2d3 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/WhereInWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/WhereInWalkerTest.php @@ -16,7 +16,7 @@ public function testWhereInQuery_NoWhere() 'SELECT u, g FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g' ); $whereInQuery = clone $query; - $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\WhereInWalker']); + $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [WhereInWalker::class]); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); $this->assertEquals( @@ -30,7 +30,7 @@ public function testCountQuery_MixedResultsWithName() 'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a' ); $whereInQuery = clone $query; - $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\WhereInWalker']); + $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [WhereInWalker::class]); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); $this->assertEquals( @@ -44,7 +44,7 @@ public function testWhereInQuery_SingleWhere() 'SELECT u, g FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g WHERE 1 = 1' ); $whereInQuery = clone $query; - $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\WhereInWalker']); + $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [WhereInWalker::class]); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); $this->assertEquals( @@ -58,7 +58,7 @@ public function testWhereInQuery_MultipleWhereWithAnd() 'SELECT u, g FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g WHERE 1 = 1 AND 2 = 2' ); $whereInQuery = clone $query; - $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\WhereInWalker']); + $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [WhereInWalker::class]); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); $this->assertEquals( @@ -72,7 +72,7 @@ public function testWhereInQuery_MultipleWhereWithOr() 'SELECT u, g FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g WHERE 1 = 1 OR 2 = 2' ); $whereInQuery = clone $query; - $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\WhereInWalker']); + $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [WhereInWalker::class]); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); $this->assertEquals( @@ -86,7 +86,7 @@ public function testWhereInQuery_MultipleWhereWithMixed_1() 'SELECT u, g FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g WHERE (1 = 1 OR 2 = 2) AND 3 = 3' ); $whereInQuery = clone $query; - $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\WhereInWalker']); + $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [WhereInWalker::class]); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); $this->assertEquals( @@ -100,7 +100,7 @@ public function testWhereInQuery_MultipleWhereWithMixed_2() 'SELECT u, g FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g WHERE 1 = 1 AND 2 = 2 OR 3 = 3' ); $whereInQuery = clone $query; - $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\WhereInWalker']); + $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [WhereInWalker::class]); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); $this->assertEquals( @@ -114,7 +114,7 @@ public function testWhereInQuery_WhereNot() 'SELECT u, g FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g WHERE NOT 1 = 2' ); $whereInQuery = clone $query; - $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\WhereInWalker']); + $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [WhereInWalker::class]); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); $this->assertEquals( @@ -130,7 +130,7 @@ public function testWhereInQueryWithArbitraryJoin_NoWhere() $whereInQuery = $this->entityManager->createQuery( 'SELECT p FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p JOIN Doctrine\Tests\ORM\Tools\Pagination\Category c WITH p.category = c' ); - $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\WhereInWalker']); + $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [WhereInWalker::class]); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); $this->assertEquals( @@ -143,7 +143,7 @@ public function testWhereInQueryWithArbitraryJoin_SingleWhere() $whereInQuery = $this->entityManager->createQuery( 'SELECT p FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p JOIN Doctrine\Tests\ORM\Tools\Pagination\Category c WITH p.category = c WHERE 1 = 1' ); - $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, ['Doctrine\ORM\Tools\Pagination\WhereInWalker']); + $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [WhereInWalker::class]); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); $this->assertEquals( diff --git a/tests/Doctrine/Tests/ORM/Tools/ResolveTargetEntityListenerTest.php b/tests/Doctrine/Tests/ORM/Tools/ResolveTargetEntityListenerTest.php index d089317c917..910df27f87c 100644 --- a/tests/Doctrine/Tests/ORM/Tools/ResolveTargetEntityListenerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/ResolveTargetEntityListenerTest.php @@ -40,27 +40,19 @@ public function setUp() public function testResolveTargetEntityListenerCanResolveTargetEntity() { $evm = $this->em->getEventManager(); - $this->listener->addResolveTargetEntity( - 'Doctrine\Tests\ORM\Tools\ResolveTargetInterface', - 'Doctrine\Tests\ORM\Tools\ResolveTargetEntity', - [] - ); - $this->listener->addResolveTargetEntity( - 'Doctrine\Tests\ORM\Tools\TargetInterface', - 'Doctrine\Tests\ORM\Tools\TargetEntity', - [] - ); + $this->listener->addResolveTargetEntity(ResolveTargetInterface::class, ResolveTargetEntity::class, []); + $this->listener->addResolveTargetEntity(TargetInterface::class, TargetEntity::class, []); $evm->addEventSubscriber($this->listener); - $cm = $this->factory->getMetadataFor('Doctrine\Tests\ORM\Tools\ResolveTargetEntity'); + $cm = $this->factory->getMetadataFor(ResolveTargetEntity::class); $meta = $cm->associationMappings; - $this->assertSame('Doctrine\Tests\ORM\Tools\TargetEntity', $meta['manyToMany']['targetEntity']); - $this->assertSame('Doctrine\Tests\ORM\Tools\ResolveTargetEntity', $meta['manyToOne']['targetEntity']); - $this->assertSame('Doctrine\Tests\ORM\Tools\ResolveTargetEntity', $meta['oneToMany']['targetEntity']); - $this->assertSame('Doctrine\Tests\ORM\Tools\TargetEntity', $meta['oneToOne']['targetEntity']); + $this->assertSame(TargetEntity::class, $meta['manyToMany']['targetEntity']); + $this->assertSame(ResolveTargetEntity::class, $meta['manyToOne']['targetEntity']); + $this->assertSame(ResolveTargetEntity::class, $meta['oneToMany']['targetEntity']); + $this->assertSame(TargetEntity::class, $meta['oneToOne']['targetEntity']); - $this->assertSame($cm, $this->factory->getMetadataFor('Doctrine\Tests\ORM\Tools\ResolveTargetInterface')); + $this->assertSame($cm, $this->factory->getMetadataFor(ResolveTargetInterface::class)); } /** @@ -70,17 +62,13 @@ public function testResolveTargetEntityListenerCanResolveTargetEntity() */ public function testResolveTargetEntityListenerCanRetrieveTargetEntityByInterfaceName() { - $this->listener->addResolveTargetEntity( - 'Doctrine\Tests\ORM\Tools\ResolveTargetInterface', - 'Doctrine\Tests\ORM\Tools\ResolveTargetEntity', - [] - ); + $this->listener->addResolveTargetEntity(ResolveTargetInterface::class, ResolveTargetEntity::class, []); $this->em->getEventManager()->addEventSubscriber($this->listener); - $cm = $this->factory->getMetadataFor('Doctrine\Tests\ORM\Tools\ResolveTargetInterface'); + $cm = $this->factory->getMetadataFor(ResolveTargetInterface::class); - $this->assertSame($this->factory->getMetadataFor('Doctrine\Tests\ORM\Tools\ResolveTargetEntity'), $cm); + $this->assertSame($this->factory->getMetadataFor(ResolveTargetEntity::class), $cm); } /** @@ -89,22 +77,14 @@ public function testResolveTargetEntityListenerCanRetrieveTargetEntityByInterfac public function testAssertTableColumnsAreNotAddedInManyToMany() { $evm = $this->em->getEventManager(); - $this->listener->addResolveTargetEntity( - 'Doctrine\Tests\ORM\Tools\ResolveTargetInterface', - 'Doctrine\Tests\ORM\Tools\ResolveTargetEntity', - [] - ); - $this->listener->addResolveTargetEntity( - 'Doctrine\Tests\ORM\Tools\TargetInterface', - 'Doctrine\Tests\ORM\Tools\TargetEntity', - [] - ); + $this->listener->addResolveTargetEntity(ResolveTargetInterface::class, ResolveTargetEntity::class, []); + $this->listener->addResolveTargetEntity(TargetInterface::class, TargetEntity::class, []); $evm->addEventListener(Events::loadClassMetadata, $this->listener); - $cm = $this->factory->getMetadataFor('Doctrine\Tests\ORM\Tools\ResolveTargetEntity'); + $cm = $this->factory->getMetadataFor(ResolveTargetEntity::class); $meta = $cm->associationMappings['manyToMany']; - $this->assertSame('Doctrine\Tests\ORM\Tools\TargetEntity', $meta['targetEntity']); + $this->assertSame(TargetEntity::class, $meta['targetEntity']); $this->assertEquals(['resolvetargetentity_id', 'targetinterface_id'], $meta['joinTableColumns']); } @@ -117,11 +97,7 @@ public function testAssertTableColumnsAreNotAddedInManyToMany() public function testDoesResolveTargetEntitiesInDQLAlsoWithInterfaces() { $evm = $this->em->getEventManager(); - $this->listener->addResolveTargetEntity( - 'Doctrine\Tests\ORM\Tools\ResolveTargetInterface', - 'Doctrine\Tests\ORM\Tools\ResolveTargetEntity', - [] - ); + $this->listener->addResolveTargetEntity(ResolveTargetInterface::class, ResolveTargetEntity::class, []); $evm->addEventSubscriber($this->listener); diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php index 142ddcb2fa7..7bae933a635 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php @@ -2,10 +2,20 @@ namespace Doctrine\Tests\ORM\Tools; +use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs; +use Doctrine\ORM\Tools\Event\GenerateSchemaTableEventArgs; use Doctrine\ORM\Tools\SchemaTool; use Doctrine\ORM\Tools\ToolEvents; -use Doctrine\ORM\Tools\Event\GenerateSchemaTableEventArgs; -use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs; +use Doctrine\Tests\Models\CMS\CmsAddress; +use Doctrine\Tests\Models\CMS\CmsArticle; +use Doctrine\Tests\Models\CMS\CmsComment; +use Doctrine\Tests\Models\CMS\CmsEmployee; +use Doctrine\Tests\Models\CMS\CmsGroup; +use Doctrine\Tests\Models\CMS\CmsPhonenumber; +use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\Models\Forum\ForumAvatar; +use Doctrine\Tests\Models\Forum\ForumUser; +use Doctrine\Tests\Models\NullDefault\NullDefaultColumn; use Doctrine\Tests\OrmTestCase; class SchemaToolTest extends OrmTestCase @@ -16,13 +26,13 @@ public function testAddUniqueIndexForUniqueFieldAnnotation() $schemaTool = new SchemaTool($em); $classes = [ - $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'), - $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsArticle'), - $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsComment'), - $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsEmployee'), - $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsGroup'), - $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), - $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), + $em->getClassMetadata(CmsAddress::class), + $em->getClassMetadata(CmsArticle::class), + $em->getClassMetadata(CmsComment::class), + $em->getClassMetadata(CmsEmployee::class), + $em->getClassMetadata(CmsGroup::class), + $em->getClassMetadata(CmsPhonenumber::class), + $em->getClassMetadata(CmsUser::class), ]; $schema = $schemaTool->getSchemaFromMetadata($classes); @@ -37,7 +47,7 @@ public function testAnnotationOptionsAttribute() $schemaTool = new SchemaTool($em); $classes = [ - $em->getClassMetadata(__NAMESPACE__ . '\\TestEntityWithAnnotationOptionsAttribute'), + $em->getClassMetadata(TestEntityWithAnnotationOptionsAttribute::class), ]; $schema = $schemaTool->getSchemaFromMetadata($classes); @@ -58,9 +68,9 @@ public function testPassColumnDefinitionToJoinColumn() $em = $this->_getTestEntityManager(); $schemaTool = new SchemaTool($em); - $avatar = $em->getClassMetadata('Doctrine\Tests\Models\Forum\ForumAvatar'); + $avatar = $em->getClassMetadata(ForumAvatar::class); $avatar->fieldMappings['id']['columnDefinition'] = $customColumnDef; - $user = $em->getClassMetadata('Doctrine\Tests\Models\Forum\ForumUser'); + $user = $em->getClassMetadata(ForumUser::class); $classes = [$avatar, $user]; @@ -86,13 +96,13 @@ public function testPostGenerateEvents() $schemaTool = new SchemaTool($em); $classes = [ - $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'), - $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsArticle'), - $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsComment'), - $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsEmployee'), - $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsGroup'), - $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), - $em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), + $em->getClassMetadata(CmsAddress::class), + $em->getClassMetadata(CmsArticle::class), + $em->getClassMetadata(CmsComment::class), + $em->getClassMetadata(CmsEmployee::class), + $em->getClassMetadata(CmsGroup::class), + $em->getClassMetadata(CmsPhonenumber::class), + $em->getClassMetadata(CmsUser::class), ]; $schema = $schemaTool->getSchemaFromMetadata($classes); @@ -106,11 +116,7 @@ public function testNullDefaultNotAddedToCustomSchemaOptions() $em = $this->_getTestEntityManager(); $schemaTool = new SchemaTool($em); - $classes = [ - $em->getClassMetadata('Doctrine\Tests\Models\NullDefault\NullDefaultColumn'), - ]; - - $customSchemaOptions = $schemaTool->getSchemaFromMetadata($classes) + $customSchemaOptions = $schemaTool->getSchemaFromMetadata([$em->getClassMetadata(NullDefaultColumn::class)]) ->getTable('NullDefaultColumn') ->getColumn('nullDefault') ->getCustomSchemaOptions(); @@ -126,7 +132,7 @@ public function testSchemaHasProperIndexesFromUniqueConstraintAnnotation() $em = $this->_getTestEntityManager(); $schemaTool = new SchemaTool($em); $classes = [ - $em->getClassMetadata(__NAMESPACE__ . '\\UniqueConstraintAnnotationModel'), + $em->getClassMetadata(UniqueConstraintAnnotationModel::class), ]; $schema = $schemaTool->getSchemaFromMetadata($classes); @@ -144,8 +150,8 @@ public function testRemoveUniqueIndexOverruledByPrimaryKey() $em = $this->_getTestEntityManager(); $schemaTool = new SchemaTool($em); $classes = [ - $em->getClassMetadata(__NAMESPACE__ . '\\FirstEntity'), - $em->getClassMetadata(__NAMESPACE__ . '\\SecondEntity') + $em->getClassMetadata(FirstEntity::class), + $em->getClassMetadata(SecondEntity::class) ]; $schema = $schemaTool->getSchemaFromMetadata($classes); diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php index 627a7b6a6df..ea282630992 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php @@ -89,8 +89,8 @@ public function testRoutingModelSet() */ public function testInvalidManyToManyJoinColumnSchema() { - $class1 = $this->em->getClassMetadata(__NAMESPACE__ . '\InvalidEntity1'); - $class2 = $this->em->getClassMetadata(__NAMESPACE__ . '\InvalidEntity2'); + $class1 = $this->em->getClassMetadata(InvalidEntity1::class); + $class2 = $this->em->getClassMetadata(InvalidEntity2::class); $ce = $this->validator->validateClass($class1); @@ -108,8 +108,8 @@ public function testInvalidManyToManyJoinColumnSchema() */ public function testInvalidToOneJoinColumnSchema() { - $class1 = $this->em->getClassMetadata(__NAMESPACE__ . '\InvalidEntity1'); - $class2 = $this->em->getClassMetadata(__NAMESPACE__ . '\InvalidEntity2'); + $class1 = $this->em->getClassMetadata(InvalidEntity1::class); + $class2 = $this->em->getClassMetadata(InvalidEntity2::class); $ce = $this->validator->validateClass($class2); @@ -127,8 +127,8 @@ public function testInvalidToOneJoinColumnSchema() */ public function testValidOneToOneAsIdentifierSchema() { - $class1 = $this->em->getClassMetadata(__NAMESPACE__ . '\DDC1587ValidEntity2'); - $class2 = $this->em->getClassMetadata(__NAMESPACE__ . '\DDC1587ValidEntity1'); + $class1 = $this->em->getClassMetadata(DDC1587ValidEntity2::class); + $class2 = $this->em->getClassMetadata(DDC1587ValidEntity1::class); $ce = $this->validator->validateClass($class1); @@ -140,7 +140,7 @@ public function testValidOneToOneAsIdentifierSchema() */ public function testInvalidTripleAssociationAsKeyMapping() { - $classThree = $this->em->getClassMetadata(__NAMESPACE__ . '\DDC1649Three'); + $classThree = $this->em->getClassMetadata(DDC1649Three::class); $ce = $this->validator->validateClass($classThree); $this->assertEquals( @@ -155,7 +155,7 @@ public function testInvalidTripleAssociationAsKeyMapping() */ public function testInvalidBiDirectionalRelationMappingMissingInversedByAttribute() { - $class = $this->em->getClassMetadata(__NAMESPACE__ . '\DDC3274One'); + $class = $this->em->getClassMetadata(DDC3274One::class); $ce = $this->validator->validateClass($class); $this->assertEquals( @@ -173,7 +173,7 @@ public function testInvalidBiDirectionalRelationMappingMissingInversedByAttribut */ public function testInvalidOrderByInvalidField() { - $class = $this->em->getClassMetadata(__NAMESPACE__ . '\DDC3322One'); + $class = $this->em->getClassMetadata(DDC3322One::class); $ce = $this->validator->validateClass($class); $this->assertEquals( @@ -190,7 +190,7 @@ public function testInvalidOrderByInvalidField() */ public function testInvalidOrderByCollectionValuedAssociation() { - $class = $this->em->getClassMetadata(__NAMESPACE__ . '\DDC3322Two'); + $class = $this->em->getClassMetadata(DDC3322Two::class); $ce = $this->validator->validateClass($class); $this->assertEquals( @@ -207,7 +207,7 @@ public function testInvalidOrderByCollectionValuedAssociation() */ public function testInvalidOrderByAssociationInverseSide() { - $class = $this->em->getClassMetadata(__NAMESPACE__ . '\DDC3322Three'); + $class = $this->em->getClassMetadata(DDC3322Three::class); $ce = $this->validator->validateClass($class); $this->assertEquals( diff --git a/tests/Doctrine/Tests/ORM/Tools/SetupTest.php b/tests/Doctrine/Tests/ORM/Tools/SetupTest.php index 0709d525638..d69e5b0300b 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SetupTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SetupTest.php @@ -2,9 +2,13 @@ namespace Doctrine\Tests\ORM\Tools; -use Doctrine\ORM\Tools\Setup; -use Doctrine\Common\Cache\Cache; use Doctrine\Common\Cache\ArrayCache; +use Doctrine\Common\Cache\Cache; +use Doctrine\ORM\Configuration; +use Doctrine\ORM\Mapping\Driver\AnnotationDriver; +use Doctrine\ORM\Mapping\Driver\XmlDriver; +use Doctrine\ORM\Mapping\Driver\YamlDriver; +use Doctrine\ORM\Tools\Setup; use Doctrine\ORM\Version; use Doctrine\Tests\OrmTestCase; @@ -49,26 +53,26 @@ public function testAnnotationConfiguration() { $config = Setup::createAnnotationMetadataConfiguration([], true); - $this->assertInstanceOf('Doctrine\ORM\Configuration', $config); + $this->assertInstanceOf(Configuration::class, $config); $this->assertEquals(sys_get_temp_dir(), $config->getProxyDir()); $this->assertEquals('DoctrineProxies', $config->getProxyNamespace()); - $this->assertInstanceOf('Doctrine\ORM\Mapping\Driver\AnnotationDriver', $config->getMetadataDriverImpl()); + $this->assertInstanceOf(AnnotationDriver::class, $config->getMetadataDriverImpl()); } public function testXMLConfiguration() { $config = Setup::createXMLMetadataConfiguration([], true); - $this->assertInstanceOf('Doctrine\ORM\Configuration', $config); - $this->assertInstanceOf('Doctrine\ORM\Mapping\Driver\XmlDriver', $config->getMetadataDriverImpl()); + $this->assertInstanceOf(Configuration::class, $config); + $this->assertInstanceOf(XmlDriver::class, $config->getMetadataDriverImpl()); } public function testYAMLConfiguration() { $config = Setup::createYAMLMetadataConfiguration([], true); - $this->assertInstanceOf('Doctrine\ORM\Configuration', $config); - $this->assertInstanceOf('Doctrine\ORM\Mapping\Driver\YamlDriver', $config->getMetadataDriverImpl()); + $this->assertInstanceOf(Configuration::class, $config); + $this->assertInstanceOf(YamlDriver::class, $config->getMetadataDriverImpl()); } /** diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 42aadd431e1..72382549ebc 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -4,12 +4,10 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\NotifyPropertyChanged; -use Doctrine\Common\Persistence\Mapping\MappingException; use Doctrine\Common\PropertyChangedListener; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\ORMInvalidArgumentException; use Doctrine\ORM\UnitOfWork; -use Doctrine\ORM\ORMException; use Doctrine\Tests\Mocks\ConnectionMock; use Doctrine\Tests\Mocks\DriverMock; use Doctrine\Tests\Mocks\EntityManagerMock; @@ -77,8 +75,8 @@ public function testRegisterRemovedOnNewEntityIsIgnored() public function testSavingSingleEntityWithIdentityColumnForcesInsert() { // Setup fake persister and id generator for identity generation - $userPersister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata('Doctrine\Tests\Models\Forum\ForumUser')); - $this->_unitOfWork->setEntityPersister('Doctrine\Tests\Models\Forum\ForumUser', $userPersister); + $userPersister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata(ForumUser::class)); + $this->_unitOfWork->setEntityPersister(ForumUser::class, $userPersister); $userPersister->setMockIdGeneratorType(ClassMetadata::GENERATOR_TYPE_IDENTITY); // Test @@ -117,12 +115,12 @@ public function testCascadedIdentityColumnInsert() { // Setup fake persister and id generator for identity generation //ForumUser - $userPersister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata('Doctrine\Tests\Models\Forum\ForumUser')); - $this->_unitOfWork->setEntityPersister('Doctrine\Tests\Models\Forum\ForumUser', $userPersister); + $userPersister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata(ForumUser::class)); + $this->_unitOfWork->setEntityPersister(ForumUser::class, $userPersister); $userPersister->setMockIdGeneratorType(ClassMetadata::GENERATOR_TYPE_IDENTITY); // ForumAvatar - $avatarPersister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata('Doctrine\Tests\Models\Forum\ForumAvatar')); - $this->_unitOfWork->setEntityPersister('Doctrine\Tests\Models\Forum\ForumAvatar', $avatarPersister); + $avatarPersister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata(ForumAvatar::class)); + $this->_unitOfWork->setEntityPersister(ForumAvatar::class, $avatarPersister); $avatarPersister->setMockIdGeneratorType(ClassMetadata::GENERATOR_TYPE_IDENTITY); // Test @@ -148,10 +146,10 @@ public function testCascadedIdentityColumnInsert() public function testChangeTrackingNotify() { - $persister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata('Doctrine\Tests\ORM\NotifyChangedEntity')); - $this->_unitOfWork->setEntityPersister('Doctrine\Tests\ORM\NotifyChangedEntity', $persister); - $itemPersister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata('Doctrine\Tests\ORM\NotifyChangedRelatedItem')); - $this->_unitOfWork->setEntityPersister('Doctrine\Tests\ORM\NotifyChangedRelatedItem', $itemPersister); + $persister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata(NotifyChangedEntity::class)); + $this->_unitOfWork->setEntityPersister(NotifyChangedEntity::class, $persister); + $itemPersister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata(NotifyChangedRelatedItem::class)); + $this->_unitOfWork->setEntityPersister(NotifyChangedRelatedItem::class, $itemPersister); $entity = new NotifyChangedEntity; $entity->setData('thedata'); @@ -192,8 +190,8 @@ public function testChangeTrackingNotify() public function testGetEntityStateOnVersionedEntityWithAssignedIdentifier() { - $persister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata('Doctrine\Tests\ORM\VersionedAssignedIdentifierEntity')); - $this->_unitOfWork->setEntityPersister('Doctrine\Tests\ORM\VersionedAssignedIdentifierEntity', $persister); + $persister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata(VersionedAssignedIdentifierEntity::class)); + $this->_unitOfWork->setEntityPersister(VersionedAssignedIdentifierEntity::class, $persister); $e = new VersionedAssignedIdentifierEntity(); $e->id = 42; @@ -203,8 +201,8 @@ public function testGetEntityStateOnVersionedEntityWithAssignedIdentifier() public function testGetEntityStateWithAssignedIdentity() { - $persister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber')); - $this->_unitOfWork->setEntityPersister('Doctrine\Tests\Models\CMS\CmsPhonenumber', $persister); + $persister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata(CmsPhonenumber::class)); + $this->_unitOfWork->setEntityPersister(CmsPhonenumber::class, $persister); $ph = new CmsPhonenumber(); $ph->phonenumber = '12345'; @@ -230,9 +228,9 @@ public function testGetEntityStateWithAssignedIdentity() public function testNoUndefinedIndexNoticeOnScheduleForUpdateWithoutChanges() { // Setup fake persister and id generator - $userPersister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata('Doctrine\Tests\Models\Forum\ForumUser')); + $userPersister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata(ForumUser::class)); $userPersister->setMockIdGeneratorType(ClassMetadata::GENERATOR_TYPE_IDENTITY); - $this->_unitOfWork->setEntityPersister('Doctrine\Tests\Models\Forum\ForumUser', $userPersister); + $this->_unitOfWork->setEntityPersister(ForumUser::class, $userPersister); // Create a test user $user = new ForumUser(); @@ -266,10 +264,10 @@ public function testLockWithoutEntityThrowsException() public function testRejectsPersistenceOfObjectsWithInvalidAssociationValue($invalidValue) { $this->_unitOfWork->setEntityPersister( - 'Doctrine\Tests\Models\Forum\ForumUser', + ForumUser::class, new EntityPersisterMock( $this->_emMock, - $this->_emMock->getClassMetadata('Doctrine\Tests\Models\Forum\ForumUser') + $this->_emMock->getClassMetadata(ForumUser::class) ) ); @@ -291,10 +289,10 @@ public function testRejectsPersistenceOfObjectsWithInvalidAssociationValue($inva */ public function testRejectsChangeSetComputationForObjectsWithInvalidAssociationValue($invalidValue) { - $metadata = $this->_emMock->getClassMetadata('Doctrine\Tests\Models\Forum\ForumUser'); + $metadata = $this->_emMock->getClassMetadata(ForumUser::class); $this->_unitOfWork->setEntityPersister( - 'Doctrine\Tests\Models\Forum\ForumUser', + ForumUser::class, new EntityPersisterMock($this->_emMock, $metadata) ); diff --git a/tests/Doctrine/Tests/ORM/Utility/IdentifierFlattenerTest.php b/tests/Doctrine/Tests/ORM/Utility/IdentifierFlattenerTest.php index 384d04328c0..86b6503d376 100644 --- a/tests/Doctrine/Tests/ORM/Utility/IdentifierFlattenerTest.php +++ b/tests/Doctrine/Tests/ORM/Utility/IdentifierFlattenerTest.php @@ -37,10 +37,10 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata('Doctrine\Tests\Models\VersionedOneToOne\FirstRelatedEntity'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\VersionedOneToOne\SecondRelatedEntity'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\Cache\Flight'), - $this->_em->getClassMetadata('Doctrine\Tests\Models\Cache\City') + $this->_em->getClassMetadata(FirstRelatedEntity::class), + $this->_em->getClassMetadata(SecondRelatedEntity::class), + $this->_em->getClassMetadata(Flight::class), + $this->_em->getClassMetadata(City::class) ] ); } catch (ORMException $e) { @@ -65,10 +65,10 @@ public function testFlattenIdentifierWithOneToOneId() $this->_em->persist($firstRelatedEntity); $this->_em->flush(); - $firstEntity = $this->_em->getRepository('Doctrine\Tests\Models\VersionedOneToOne\FirstRelatedEntity') + $firstEntity = $this->_em->getRepository(FirstRelatedEntity::class) ->findOneBy(['name' => 'Fred']); - $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\VersionedOneToOne\FirstRelatedEntity'); + $class = $this->_em->getClassMetadata(FirstRelatedEntity::class); $id = $class->getIdentifierValues($firstEntity); @@ -108,7 +108,7 @@ public function testFlattenIdentifierWithMutlipleIds() $this->_em->persist($flight); $this->_em->flush(); - $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\Cache\Flight'); + $class = $this->_em->getClassMetadata(Flight::class); $id = $class->getIdentifierValues($flight); $this->assertCount(2, $id); diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index b6d2f005ced..9a684785378 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -7,13 +7,15 @@ use Doctrine\DBAL\Logging\DebugStack; use Doctrine\DBAL\Types\Type; use Doctrine\ORM\Cache\CacheConfiguration; +use Doctrine\ORM\Cache\DefaultCacheFactory; +use Doctrine\ORM\Cache\Logging\StatisticsCacheLogger; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Tools\DebugUnitOfWorkListener; use Doctrine\ORM\Tools\SchemaTool; +use Doctrine\Tests\DbalTypes\Rot13Type; use Doctrine\Tests\EventListener\CacheMetadataListener; -use Doctrine\ORM\Cache\Logging\StatisticsCacheLogger; -use Doctrine\ORM\Cache\DefaultCacheFactory; +use Doctrine\Tests\Models; /** * Base testcase class for all functional ORM testcases. @@ -86,219 +88,219 @@ abstract class OrmFunctionalTestCase extends OrmTestCase */ protected static $_modelSets = [ 'cms' => [ - 'Doctrine\Tests\Models\CMS\CmsUser', - 'Doctrine\Tests\Models\CMS\CmsPhonenumber', - 'Doctrine\Tests\Models\CMS\CmsAddress', - 'Doctrine\Tests\Models\CMS\CmsEmail', - 'Doctrine\Tests\Models\CMS\CmsGroup', - 'Doctrine\Tests\Models\CMS\CmsTag', - 'Doctrine\Tests\Models\CMS\CmsArticle', - 'Doctrine\Tests\Models\CMS\CmsComment', + Models\CMS\CmsUser::class, + Models\CMS\CmsPhonenumber::class, + Models\CMS\CmsAddress::class, + Models\CMS\CmsEmail::class, + Models\CMS\CmsGroup::class, + Models\CMS\CmsTag::class, + Models\CMS\CmsArticle::class, + Models\CMS\CmsComment::class, ], 'forum' => [], 'company' => [ - 'Doctrine\Tests\Models\Company\CompanyPerson', - 'Doctrine\Tests\Models\Company\CompanyEmployee', - 'Doctrine\Tests\Models\Company\CompanyManager', - 'Doctrine\Tests\Models\Company\CompanyOrganization', - 'Doctrine\Tests\Models\Company\CompanyEvent', - 'Doctrine\Tests\Models\Company\CompanyAuction', - 'Doctrine\Tests\Models\Company\CompanyRaffle', - 'Doctrine\Tests\Models\Company\CompanyCar', - 'Doctrine\Tests\Models\Company\CompanyContract', + Models\Company\CompanyPerson::class, + Models\Company\CompanyEmployee::class, + Models\Company\CompanyManager::class, + Models\Company\CompanyOrganization::class, + Models\Company\CompanyEvent::class, + Models\Company\CompanyAuction::class, + Models\Company\CompanyRaffle::class, + Models\Company\CompanyCar::class, + Models\Company\CompanyContract::class, ], 'ecommerce' => [ - 'Doctrine\Tests\Models\ECommerce\ECommerceCart', - 'Doctrine\Tests\Models\ECommerce\ECommerceCustomer', - 'Doctrine\Tests\Models\ECommerce\ECommerceProduct', - 'Doctrine\Tests\Models\ECommerce\ECommerceShipping', - 'Doctrine\Tests\Models\ECommerce\ECommerceFeature', - 'Doctrine\Tests\Models\ECommerce\ECommerceCategory' + Models\ECommerce\ECommerceCart::class, + Models\ECommerce\ECommerceCustomer::class, + Models\ECommerce\ECommerceProduct::class, + Models\ECommerce\ECommerceShipping::class, + Models\ECommerce\ECommerceFeature::class, + Models\ECommerce\ECommerceCategory::class ], 'generic' => [ - 'Doctrine\Tests\Models\Generic\BooleanModel', - 'Doctrine\Tests\Models\Generic\DateTimeModel', - 'Doctrine\Tests\Models\Generic\DecimalModel', - 'Doctrine\Tests\Models\Generic\SerializationModel', + Models\Generic\BooleanModel::class, + Models\Generic\DateTimeModel::class, + Models\Generic\DecimalModel::class, + Models\Generic\SerializationModel::class, ], 'routing' => [ - 'Doctrine\Tests\Models\Routing\RoutingLeg', - 'Doctrine\Tests\Models\Routing\RoutingLocation', - 'Doctrine\Tests\Models\Routing\RoutingRoute', - 'Doctrine\Tests\Models\Routing\RoutingRouteBooking', + Models\Routing\RoutingLeg::class, + Models\Routing\RoutingLocation::class, + Models\Routing\RoutingRoute::class, + Models\Routing\RoutingRouteBooking::class, ], 'navigation' => [ - 'Doctrine\Tests\Models\Navigation\NavUser', - 'Doctrine\Tests\Models\Navigation\NavCountry', - 'Doctrine\Tests\Models\Navigation\NavPhotos', - 'Doctrine\Tests\Models\Navigation\NavTour', - 'Doctrine\Tests\Models\Navigation\NavPointOfInterest', + Models\Navigation\NavUser::class, + Models\Navigation\NavCountry::class, + Models\Navigation\NavPhotos::class, + Models\Navigation\NavTour::class, + Models\Navigation\NavPointOfInterest::class, ], 'directorytree' => [ - 'Doctrine\Tests\Models\DirectoryTree\AbstractContentItem', - 'Doctrine\Tests\Models\DirectoryTree\File', - 'Doctrine\Tests\Models\DirectoryTree\Directory', + Models\DirectoryTree\AbstractContentItem::class, + Models\DirectoryTree\File::class, + Models\DirectoryTree\Directory::class, ], 'ddc117' => [ - 'Doctrine\Tests\Models\DDC117\DDC117Article', - 'Doctrine\Tests\Models\DDC117\DDC117Reference', - 'Doctrine\Tests\Models\DDC117\DDC117Translation', - 'Doctrine\Tests\Models\DDC117\DDC117ArticleDetails', - 'Doctrine\Tests\Models\DDC117\DDC117ApproveChanges', - 'Doctrine\Tests\Models\DDC117\DDC117Editor', - 'Doctrine\Tests\Models\DDC117\DDC117Link', + Models\DDC117\DDC117Article::class, + Models\DDC117\DDC117Reference::class, + Models\DDC117\DDC117Translation::class, + Models\DDC117\DDC117ArticleDetails::class, + Models\DDC117\DDC117ApproveChanges::class, + Models\DDC117\DDC117Editor::class, + Models\DDC117\DDC117Link::class, ], 'ddc3699' => [ - 'Doctrine\Tests\Models\DDC3699\DDC3699Parent', - 'Doctrine\Tests\Models\DDC3699\DDC3699RelationOne', - 'Doctrine\Tests\Models\DDC3699\DDC3699RelationMany', - 'Doctrine\Tests\Models\DDC3699\DDC3699Child', + Models\DDC3699\DDC3699Parent::class, + Models\DDC3699\DDC3699RelationOne::class, + Models\DDC3699\DDC3699RelationMany::class, + Models\DDC3699\DDC3699Child::class, ], 'stockexchange' => [ - 'Doctrine\Tests\Models\StockExchange\Bond', - 'Doctrine\Tests\Models\StockExchange\Stock', - 'Doctrine\Tests\Models\StockExchange\Market', + Models\StockExchange\Bond::class, + Models\StockExchange\Stock::class, + Models\StockExchange\Market::class, ], 'legacy' => [ - 'Doctrine\Tests\Models\Legacy\LegacyUser', - 'Doctrine\Tests\Models\Legacy\LegacyUserReference', - 'Doctrine\Tests\Models\Legacy\LegacyArticle', - 'Doctrine\Tests\Models\Legacy\LegacyCar', + Models\Legacy\LegacyUser::class, + Models\Legacy\LegacyUserReference::class, + Models\Legacy\LegacyArticle::class, + Models\Legacy\LegacyCar::class, ], 'customtype' => [ - 'Doctrine\Tests\Models\CustomType\CustomTypeChild', - 'Doctrine\Tests\Models\CustomType\CustomTypeParent', - 'Doctrine\Tests\Models\CustomType\CustomTypeUpperCase', + Models\CustomType\CustomTypeChild::class, + Models\CustomType\CustomTypeParent::class, + Models\CustomType\CustomTypeUpperCase::class, ], 'compositekeyinheritance' => [ - 'Doctrine\Tests\Models\CompositeKeyInheritance\JoinedRootClass', - 'Doctrine\Tests\Models\CompositeKeyInheritance\JoinedChildClass', - 'Doctrine\Tests\Models\CompositeKeyInheritance\SingleRootClass', - 'Doctrine\Tests\Models\CompositeKeyInheritance\SingleChildClass', + Models\CompositeKeyInheritance\JoinedRootClass::class, + Models\CompositeKeyInheritance\JoinedChildClass::class, + Models\CompositeKeyInheritance\SingleRootClass::class, + Models\CompositeKeyInheritance\SingleChildClass::class, ], 'taxi' => [ - 'Doctrine\Tests\Models\Taxi\PaidRide', - 'Doctrine\Tests\Models\Taxi\Ride', - 'Doctrine\Tests\Models\Taxi\Car', - 'Doctrine\Tests\Models\Taxi\Driver', + Models\Taxi\PaidRide::class, + Models\Taxi\Ride::class, + Models\Taxi\Car::class, + Models\Taxi\Driver::class, ], 'cache' => [ - 'Doctrine\Tests\Models\Cache\Country', - 'Doctrine\Tests\Models\Cache\State', - 'Doctrine\Tests\Models\Cache\City', - 'Doctrine\Tests\Models\Cache\Traveler', - 'Doctrine\Tests\Models\Cache\TravelerProfileInfo', - 'Doctrine\Tests\Models\Cache\TravelerProfile', - 'Doctrine\Tests\Models\Cache\Travel', - 'Doctrine\Tests\Models\Cache\Attraction', - 'Doctrine\Tests\Models\Cache\Restaurant', - 'Doctrine\Tests\Models\Cache\Beach', - 'Doctrine\Tests\Models\Cache\Bar', - 'Doctrine\Tests\Models\Cache\Flight', - 'Doctrine\Tests\Models\Cache\Token', - 'Doctrine\Tests\Models\Cache\Login', - 'Doctrine\Tests\Models\Cache\Client', - 'Doctrine\Tests\Models\Cache\Person', - 'Doctrine\Tests\Models\Cache\Address', - 'Doctrine\Tests\Models\Cache\Action', - 'Doctrine\Tests\Models\Cache\ComplexAction', - 'Doctrine\Tests\Models\Cache\AttractionInfo', - 'Doctrine\Tests\Models\Cache\AttractionContactInfo', - 'Doctrine\Tests\Models\Cache\AttractionLocationInfo' + Models\Cache\Country::class, + Models\Cache\State::class, + Models\Cache\City::class, + Models\Cache\Traveler::class, + Models\Cache\TravelerProfileInfo::class, + Models\Cache\TravelerProfile::class, + Models\Cache\Travel::class, + Models\Cache\Attraction::class, + Models\Cache\Restaurant::class, + Models\Cache\Beach::class, + Models\Cache\Bar::class, + Models\Cache\Flight::class, + Models\Cache\Token::class, + Models\Cache\Login::class, + Models\Cache\Client::class, + Models\Cache\Person::class, + Models\Cache\Address::class, + Models\Cache\Action::class, + Models\Cache\ComplexAction::class, + Models\Cache\AttractionInfo::class, + Models\Cache\AttractionContactInfo::class, + Models\Cache\AttractionLocationInfo::class ], 'tweet' => [ - 'Doctrine\Tests\Models\Tweet\User', - 'Doctrine\Tests\Models\Tweet\Tweet', - 'Doctrine\Tests\Models\Tweet\UserList', + Models\Tweet\User::class, + Models\Tweet\Tweet::class, + Models\Tweet\UserList::class, ], 'ddc2504' => [ - 'Doctrine\Tests\Models\DDC2504\DDC2504RootClass', - 'Doctrine\Tests\Models\DDC2504\DDC2504ChildClass', - 'Doctrine\Tests\Models\DDC2504\DDC2504OtherClass', + Models\DDC2504\DDC2504RootClass::class, + Models\DDC2504\DDC2504ChildClass::class, + Models\DDC2504\DDC2504OtherClass::class, ], 'ddc3346' => [ - 'Doctrine\Tests\Models\DDC3346\DDC3346Author', - 'Doctrine\Tests\Models\DDC3346\DDC3346Article', + Models\DDC3346\DDC3346Author::class, + Models\DDC3346\DDC3346Article::class, ], 'quote' => [ - 'Doctrine\Tests\Models\Quote\Address', - 'Doctrine\Tests\Models\Quote\Group', - 'Doctrine\Tests\Models\Quote\NumericEntity', - 'Doctrine\Tests\Models\Quote\Phone', - 'Doctrine\Tests\Models\Quote\User' + Models\Quote\Address::class, + Models\Quote\Group::class, + Models\Quote\NumericEntity::class, + Models\Quote\Phone::class, + Models\Quote\User::class ], 'vct_onetoone' => [ - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneEntity' + Models\ValueConversionType\InversedOneToOneEntity::class, + Models\ValueConversionType\OwningOneToOneEntity::class ], 'vct_onetoone_compositeid' => [ - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdEntity' + Models\ValueConversionType\InversedOneToOneCompositeIdEntity::class, + Models\ValueConversionType\OwningOneToOneCompositeIdEntity::class ], 'vct_onetoone_compositeid_foreignkey' => [ - 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity' + Models\ValueConversionType\AuxiliaryEntity::class, + Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity::class, + Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity::class ], 'vct_onetomany' => [ - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneEntity' + Models\ValueConversionType\InversedOneToManyEntity::class, + Models\ValueConversionType\OwningManyToOneEntity::class ], 'vct_onetomany_compositeid' => [ - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdEntity' + Models\ValueConversionType\InversedOneToManyCompositeIdEntity::class, + Models\ValueConversionType\OwningManyToOneCompositeIdEntity::class ], 'vct_onetomany_compositeid_foreignkey' => [ - 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdForeignKeyEntity' + Models\ValueConversionType\AuxiliaryEntity::class, + Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity::class, + Models\ValueConversionType\OwningManyToOneCompositeIdForeignKeyEntity::class ], 'vct_onetomany_extralazy' => [ - 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyExtraLazyEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneExtraLazyEntity' + Models\ValueConversionType\InversedOneToManyExtraLazyEntity::class, + Models\ValueConversionType\OwningManyToOneExtraLazyEntity::class ], 'vct_manytomany' => [ - 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyEntity' + Models\ValueConversionType\InversedManyToManyEntity::class, + Models\ValueConversionType\OwningManyToManyEntity::class ], 'vct_manytomany_compositeid' => [ - 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdEntity' + Models\ValueConversionType\InversedManyToManyCompositeIdEntity::class, + Models\ValueConversionType\OwningManyToManyCompositeIdEntity::class ], 'vct_manytomany_compositeid_foreignkey' => [ - 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', - 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdForeignKeyEntity' + Models\ValueConversionType\AuxiliaryEntity::class, + Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity::class, + Models\ValueConversionType\OwningManyToManyCompositeIdForeignKeyEntity::class ], 'vct_manytomany_extralazy' => [ - 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyExtraLazyEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyExtraLazyEntity' + Models\ValueConversionType\InversedManyToManyExtraLazyEntity::class, + Models\ValueConversionType\OwningManyToManyExtraLazyEntity::class ], 'geonames' => [ - 'Doctrine\Tests\Models\GeoNames\Country', - 'Doctrine\Tests\Models\GeoNames\Admin1', - 'Doctrine\Tests\Models\GeoNames\Admin1AlternateName', - 'Doctrine\Tests\Models\GeoNames\City' + Models\GeoNames\Country::class, + Models\GeoNames\Admin1::class, + Models\GeoNames\Admin1AlternateName::class, + Models\GeoNames\City::class ], 'custom_id_object_type' => [ - 'Doctrine\Tests\Models\CustomType\CustomIdObjectTypeParent', - 'Doctrine\Tests\Models\CustomType\CustomIdObjectTypeChild', + Models\CustomType\CustomIdObjectTypeParent::class, + Models\CustomType\CustomIdObjectTypeChild::class, ], 'pagination' => [ - 'Doctrine\Tests\Models\Pagination\Company', - 'Doctrine\Tests\Models\Pagination\Logo', - 'Doctrine\Tests\Models\Pagination\Department', - 'Doctrine\Tests\Models\Pagination\User', - 'Doctrine\Tests\Models\Pagination\User1', + Models\Pagination\Company::class, + Models\Pagination\Logo::class, + Models\Pagination\Department::class, + Models\Pagination\User::class, + Models\Pagination\User1::class, ], 'versioned_many_to_one' => [ - 'Doctrine\Tests\Models\VersionedManyToOne\Category', - 'Doctrine\Tests\Models\VersionedManyToOne\Article', + Models\VersionedManyToOne\Category::class, + Models\VersionedManyToOne\Article::class, ], 'issue5989' => [ - 'Doctrine\Tests\Models\Issue5989\Issue5989Person', - 'Doctrine\Tests\Models\Issue5989\Issue5989Employee', - 'Doctrine\Tests\Models\Issue5989\Issue5989Manager', + Models\Issue5989\Issue5989Person::class, + Models\Issue5989\Issue5989Employee::class, + Models\Issue5989\Issue5989Manager::class, ], ]; @@ -810,9 +812,9 @@ protected function getCurrentQueryCount() protected function setUpDBALTypes() { if (Type::hasType('rot13')) { - Type::overrideType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); + Type::overrideType('rot13', Rot13Type::class); } else { - Type::addType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); + Type::addType('rot13', Rot13Type::class); } } } diff --git a/tests/Doctrine/Tests/OrmTestCase.php b/tests/Doctrine/Tests/OrmTestCase.php index 9d6e9b5ac6c..46e8ea143ee 100644 --- a/tests/Doctrine/Tests/OrmTestCase.php +++ b/tests/Doctrine/Tests/OrmTestCase.php @@ -10,7 +10,7 @@ use Doctrine\ORM\Cache\DefaultCacheFactory; use Doctrine\ORM\Configuration; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; -use Doctrine\Tests\Mocks\EntityManagerMock; +use Doctrine\Tests\Mocks; /** * Base testcase class for all ORM testcases. @@ -149,8 +149,8 @@ protected function _getTestEntityManager($conn = null, $conf = null, $eventManag if ($conn === null) { $conn = [ - 'driverClass' => 'Doctrine\Tests\Mocks\DriverMock', - 'wrapperClass' => 'Doctrine\Tests\Mocks\ConnectionMock', + 'driverClass' => Mocks\DriverMock::class, + 'wrapperClass' => Mocks\ConnectionMock::class, 'user' => 'john', 'password' => 'wayne' ]; @@ -160,7 +160,7 @@ protected function _getTestEntityManager($conn = null, $conf = null, $eventManag $conn = DriverManager::getConnection($conn, $config, $eventManager); } - return EntityManagerMock::create($conn, $config, $eventManager); + return Mocks\EntityManagerMock::create($conn, $config, $eventManager); } protected function enableSecondLevelCache($log = true) From 62d122bd5416209413769102bdcb082d51cc01e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Thu, 8 Dec 2016 18:15:48 +0100 Subject: [PATCH 173/877] Remove old "CLASSNAME" constants from test models --- .../Tests/DbalTypes/CustomIdObjectType.php | 1 - tests/Doctrine/Tests/Models/Cache/Action.php | 2 -- tests/Doctrine/Tests/Models/Cache/Address.php | 2 -- .../Doctrine/Tests/Models/Cache/Attraction.php | 2 -- .../Models/Cache/AttractionContactInfo.php | 2 -- .../Tests/Models/Cache/AttractionInfo.php | 2 -- .../Models/Cache/AttractionLocationInfo.php | 2 -- tests/Doctrine/Tests/Models/Cache/Bar.php | 3 +-- tests/Doctrine/Tests/Models/Cache/Beach.php | 3 +-- tests/Doctrine/Tests/Models/Cache/City.php | 2 -- tests/Doctrine/Tests/Models/Cache/Client.php | 2 -- .../Tests/Models/Cache/ComplexAction.php | 2 -- tests/Doctrine/Tests/Models/Cache/Country.php | 2 -- tests/Doctrine/Tests/Models/Cache/Flight.php | 2 -- tests/Doctrine/Tests/Models/Cache/Login.php | 2 -- tests/Doctrine/Tests/Models/Cache/Person.php | 2 -- .../Doctrine/Tests/Models/Cache/Restaurant.php | 3 +-- tests/Doctrine/Tests/Models/Cache/State.php | 2 -- tests/Doctrine/Tests/Models/Cache/Token.php | 2 -- tests/Doctrine/Tests/Models/Cache/Travel.php | 2 -- tests/Doctrine/Tests/Models/Cache/Traveler.php | 2 -- .../Tests/Models/Cache/TravelerProfile.php | 2 -- .../Tests/Models/Cache/TravelerProfileInfo.php | 2 -- .../CustomType/CustomIdObjectTypeChild.php | 2 -- .../CustomType/CustomIdObjectTypeParent.php | 2 -- .../Tests/Models/DDC2504/DDC2504ChildClass.php | 1 - .../Tests/Models/DDC2504/DDC2504OtherClass.php | 2 -- .../Models/DDC2825/ExplicitSchemaAndTable.php | 2 -- .../DDC2825/SchemaAndTableInTableName.php | 4 +--- .../Tests/Models/DDC3346/DDC3346Article.php | 2 -- .../Tests/Models/DDC3346/DDC3346Author.php | 2 -- .../Tests/Models/DDC3597/DDC3597Image.php | 2 -- .../Tests/Models/DDC3597/DDC3597Media.php | 4 +--- .../Tests/Models/DDC3597/DDC3597Root.php | 2 -- .../Tests/Models/DDC3699/DDC3699Child.php | 2 -- .../Tests/Models/DDC3699/DDC3699Parent.php | 4 +--- .../Models/DDC3699/DDC3699RelationMany.php | 2 -- .../Models/DDC3699/DDC3699RelationOne.php | 2 -- .../DirectoryTree/AbstractContentItem.php | 2 -- .../Tests/Models/DirectoryTree/File.php | 2 -- .../Tests/Models/Generic/DateTimeModel.php | 2 -- .../EntityWithArrayDefaultArrayValueM2M.php | 2 -- .../Tests/Models/Hydration/SimpleEntity.php | 2 -- .../CompositeToOneKeyState.php | 2 -- .../Models/MixedToOneIdentity/Country.php | 2 -- .../Tests/Models/NonPublicSchemaJoins/User.php | 2 -- .../OneToOneSingleTableInheritance/Cat.php | 2 -- .../LitterBox.php | 4 +--- .../OneToOneSingleTableInheritance/Pet.php | 2 -- .../Reflection/ClassWithMixedProperties.php | 2 -- .../Tests/Models/Reflection/ParentClass.php | 2 -- tests/Doctrine/Tests/Models/Tweet/Tweet.php | 2 -- tests/Doctrine/Tests/Models/Tweet/User.php | 2 -- tests/Doctrine/Tests/Models/Tweet/UserList.php | 2 -- .../Models/VersionedManyToOne/Article.php | 2 -- .../Models/VersionedManyToOne/Category.php | 2 -- .../ORM/Functional/Ticket/DDC2494Test.php | 4 ---- .../ORM/Functional/Ticket/DDC2579Test.php | 10 ---------- .../ORM/Functional/Ticket/DDC2825Test.php | 2 -- .../ORM/Functional/Ticket/DDC2862Test.php | 4 ---- .../ORM/Functional/Ticket/DDC3192Test.php | 4 ---- .../ORM/Functional/Ticket/DDC3300Test.php | 6 ------ .../ORM/Functional/Ticket/DDC3582Test.php | 8 -------- .../ORM/Functional/Ticket/DDC3634Test.php | 5 ----- .../ORM/Functional/Ticket/DDC5684Test.php | 6 ------ .../Tests/ORM/Functional/ValueObjectsTest.php | 18 ------------------ .../AttachEntityListenersListenerTest.php | 8 -------- 67 files changed, 7 insertions(+), 189 deletions(-) diff --git a/tests/Doctrine/Tests/DbalTypes/CustomIdObjectType.php b/tests/Doctrine/Tests/DbalTypes/CustomIdObjectType.php index f59ab151c5f..0ebae5dff0e 100644 --- a/tests/Doctrine/Tests/DbalTypes/CustomIdObjectType.php +++ b/tests/Doctrine/Tests/DbalTypes/CustomIdObjectType.php @@ -8,7 +8,6 @@ class CustomIdObjectType extends Type { const NAME = 'CustomIdObject'; - const CLASSNAME = __CLASS__; /** * {@inheritdoc} diff --git a/tests/Doctrine/Tests/Models/Cache/Action.php b/tests/Doctrine/Tests/Models/Cache/Action.php index d23ab494bfb..72bbba4c173 100644 --- a/tests/Doctrine/Tests/Models/Cache/Action.php +++ b/tests/Doctrine/Tests/Models/Cache/Action.php @@ -10,8 +10,6 @@ */ class Action { - const CLASSNAME = __CLASS__; - /** * @Id * @Column(type="string") diff --git a/tests/Doctrine/Tests/Models/Cache/Address.php b/tests/Doctrine/Tests/Models/Cache/Address.php index fa5363560fa..5ccb349d0a0 100644 --- a/tests/Doctrine/Tests/Models/Cache/Address.php +++ b/tests/Doctrine/Tests/Models/Cache/Address.php @@ -8,8 +8,6 @@ */ class Address { - const CLASSNAME = __CLASS__; - /** * @Id * @GeneratedValue diff --git a/tests/Doctrine/Tests/Models/Cache/Attraction.php b/tests/Doctrine/Tests/Models/Cache/Attraction.php index 31f3d3069ba..f53786dde7a 100644 --- a/tests/Doctrine/Tests/Models/Cache/Attraction.php +++ b/tests/Doctrine/Tests/Models/Cache/Attraction.php @@ -17,8 +17,6 @@ */ abstract class Attraction { - const CLASSNAME = __CLASS__; - /** * @Id * @GeneratedValue diff --git a/tests/Doctrine/Tests/Models/Cache/AttractionContactInfo.php b/tests/Doctrine/Tests/Models/Cache/AttractionContactInfo.php index 4b4b37f3b1c..e25665528ad 100644 --- a/tests/Doctrine/Tests/Models/Cache/AttractionContactInfo.php +++ b/tests/Doctrine/Tests/Models/Cache/AttractionContactInfo.php @@ -8,8 +8,6 @@ */ class AttractionContactInfo extends AttractionInfo { - const CLASSNAME = __CLASS__; - /** * @Column(unique=true) */ diff --git a/tests/Doctrine/Tests/Models/Cache/AttractionInfo.php b/tests/Doctrine/Tests/Models/Cache/AttractionInfo.php index d257a53f3ad..978d8587e25 100644 --- a/tests/Doctrine/Tests/Models/Cache/AttractionInfo.php +++ b/tests/Doctrine/Tests/Models/Cache/AttractionInfo.php @@ -14,8 +14,6 @@ */ abstract class AttractionInfo { - const CLASSNAME = __CLASS__; - /** * @Id * @GeneratedValue diff --git a/tests/Doctrine/Tests/Models/Cache/AttractionLocationInfo.php b/tests/Doctrine/Tests/Models/Cache/AttractionLocationInfo.php index 66f2633f5d9..e7419fb4a67 100644 --- a/tests/Doctrine/Tests/Models/Cache/AttractionLocationInfo.php +++ b/tests/Doctrine/Tests/Models/Cache/AttractionLocationInfo.php @@ -8,8 +8,6 @@ */ class AttractionLocationInfo extends AttractionInfo { - const CLASSNAME = __CLASS__; - /** * @Column(unique=true) */ diff --git a/tests/Doctrine/Tests/Models/Cache/Bar.php b/tests/Doctrine/Tests/Models/Cache/Bar.php index f0d0931270d..cc54d547c90 100644 --- a/tests/Doctrine/Tests/Models/Cache/Bar.php +++ b/tests/Doctrine/Tests/Models/Cache/Bar.php @@ -7,5 +7,4 @@ */ class Bar extends Attraction { - const CLASSNAME = __CLASS__; -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/Cache/Beach.php b/tests/Doctrine/Tests/Models/Cache/Beach.php index 61e623dc573..dcabe5935ab 100644 --- a/tests/Doctrine/Tests/Models/Cache/Beach.php +++ b/tests/Doctrine/Tests/Models/Cache/Beach.php @@ -7,5 +7,4 @@ */ class Beach extends Attraction { - const CLASSNAME = __CLASS__; -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/Cache/City.php b/tests/Doctrine/Tests/Models/Cache/City.php index 40369728da9..b3769fbe779 100644 --- a/tests/Doctrine/Tests/Models/Cache/City.php +++ b/tests/Doctrine/Tests/Models/Cache/City.php @@ -11,8 +11,6 @@ */ class City { - const CLASSNAME = __CLASS__; - /** * @Id * @GeneratedValue diff --git a/tests/Doctrine/Tests/Models/Cache/Client.php b/tests/Doctrine/Tests/Models/Cache/Client.php index 70544256bf1..dfbc60e30cf 100644 --- a/tests/Doctrine/Tests/Models/Cache/Client.php +++ b/tests/Doctrine/Tests/Models/Cache/Client.php @@ -8,8 +8,6 @@ */ class Client { - const CLASSNAME = __CLASS__; - /** * @Id * @GeneratedValue diff --git a/tests/Doctrine/Tests/Models/Cache/ComplexAction.php b/tests/Doctrine/Tests/Models/Cache/ComplexAction.php index 5f5faf6ddd0..9c0a0abd9fb 100644 --- a/tests/Doctrine/Tests/Models/Cache/ComplexAction.php +++ b/tests/Doctrine/Tests/Models/Cache/ComplexAction.php @@ -10,8 +10,6 @@ */ class ComplexAction { - const CLASSNAME = __CLASS__; - /** * @Column */ diff --git a/tests/Doctrine/Tests/Models/Cache/Country.php b/tests/Doctrine/Tests/Models/Cache/Country.php index 11d09403808..f4179f63e75 100644 --- a/tests/Doctrine/Tests/Models/Cache/Country.php +++ b/tests/Doctrine/Tests/Models/Cache/Country.php @@ -9,8 +9,6 @@ */ class Country { - const CLASSNAME = __CLASS__; - /** * @Id * @GeneratedValue diff --git a/tests/Doctrine/Tests/Models/Cache/Flight.php b/tests/Doctrine/Tests/Models/Cache/Flight.php index ce2f3476fc8..f109c34da38 100644 --- a/tests/Doctrine/Tests/Models/Cache/Flight.php +++ b/tests/Doctrine/Tests/Models/Cache/Flight.php @@ -9,8 +9,6 @@ */ class Flight { - const CLASSNAME = __CLASS__; - /** * @Id * @Cache diff --git a/tests/Doctrine/Tests/Models/Cache/Login.php b/tests/Doctrine/Tests/Models/Cache/Login.php index 8de766d38c5..24e5b133dac 100644 --- a/tests/Doctrine/Tests/Models/Cache/Login.php +++ b/tests/Doctrine/Tests/Models/Cache/Login.php @@ -8,8 +8,6 @@ */ class Login { - const CLASSNAME = __CLASS__; - /** * @Id * @GeneratedValue diff --git a/tests/Doctrine/Tests/Models/Cache/Person.php b/tests/Doctrine/Tests/Models/Cache/Person.php index 9cbe00c57d8..01ab416aac4 100644 --- a/tests/Doctrine/Tests/Models/Cache/Person.php +++ b/tests/Doctrine/Tests/Models/Cache/Person.php @@ -9,8 +9,6 @@ */ class Person { - const CLASSNAME = __CLASS__; - /** * @Id * @GeneratedValue diff --git a/tests/Doctrine/Tests/Models/Cache/Restaurant.php b/tests/Doctrine/Tests/Models/Cache/Restaurant.php index 00d3ac06183..c4bf94cbc7d 100644 --- a/tests/Doctrine/Tests/Models/Cache/Restaurant.php +++ b/tests/Doctrine/Tests/Models/Cache/Restaurant.php @@ -7,5 +7,4 @@ */ class Restaurant extends Attraction { - const CLASSNAME = __CLASS__; -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/Cache/State.php b/tests/Doctrine/Tests/Models/Cache/State.php index e59ecb2b181..77dd0122c13 100644 --- a/tests/Doctrine/Tests/Models/Cache/State.php +++ b/tests/Doctrine/Tests/Models/Cache/State.php @@ -11,8 +11,6 @@ */ class State { - const CLASSNAME = __CLASS__; - /** * @Id * @GeneratedValue diff --git a/tests/Doctrine/Tests/Models/Cache/Token.php b/tests/Doctrine/Tests/Models/Cache/Token.php index ba3fdb1821a..bcfbb1b9121 100644 --- a/tests/Doctrine/Tests/Models/Cache/Token.php +++ b/tests/Doctrine/Tests/Models/Cache/Token.php @@ -10,8 +10,6 @@ */ class Token { - const CLASSNAME = __CLASS__; - /** * @Id * @Column(type="string") diff --git a/tests/Doctrine/Tests/Models/Cache/Travel.php b/tests/Doctrine/Tests/Models/Cache/Travel.php index b25744dd63d..1e0240066a5 100644 --- a/tests/Doctrine/Tests/Models/Cache/Travel.php +++ b/tests/Doctrine/Tests/Models/Cache/Travel.php @@ -11,8 +11,6 @@ */ class Travel { - const CLASSNAME = __CLASS__; - /** * @Id * @GeneratedValue diff --git a/tests/Doctrine/Tests/Models/Cache/Traveler.php b/tests/Doctrine/Tests/Models/Cache/Traveler.php index 3f720b46595..c8b68565b99 100644 --- a/tests/Doctrine/Tests/Models/Cache/Traveler.php +++ b/tests/Doctrine/Tests/Models/Cache/Traveler.php @@ -11,8 +11,6 @@ */ class Traveler { - const CLASSNAME = __CLASS__; - /** * @Id * @GeneratedValue diff --git a/tests/Doctrine/Tests/Models/Cache/TravelerProfile.php b/tests/Doctrine/Tests/Models/Cache/TravelerProfile.php index fbffa8b70a9..03b9c7d3d9e 100644 --- a/tests/Doctrine/Tests/Models/Cache/TravelerProfile.php +++ b/tests/Doctrine/Tests/Models/Cache/TravelerProfile.php @@ -9,8 +9,6 @@ */ class TravelerProfile { - const CLASSNAME = __CLASS__; - /** * @Id * @GeneratedValue diff --git a/tests/Doctrine/Tests/Models/Cache/TravelerProfileInfo.php b/tests/Doctrine/Tests/Models/Cache/TravelerProfileInfo.php index e781628498e..154ce9600dd 100644 --- a/tests/Doctrine/Tests/Models/Cache/TravelerProfileInfo.php +++ b/tests/Doctrine/Tests/Models/Cache/TravelerProfileInfo.php @@ -9,8 +9,6 @@ */ class TravelerProfileInfo { - const CLASSNAME = __CLASS__; - /** * @Id * @GeneratedValue diff --git a/tests/Doctrine/Tests/Models/CustomType/CustomIdObjectTypeChild.php b/tests/Doctrine/Tests/Models/CustomType/CustomIdObjectTypeChild.php index 334ad17c7b4..8e5ec73d574 100644 --- a/tests/Doctrine/Tests/Models/CustomType/CustomIdObjectTypeChild.php +++ b/tests/Doctrine/Tests/Models/CustomType/CustomIdObjectTypeChild.php @@ -10,8 +10,6 @@ */ class CustomIdObjectTypeChild { - const CLASSNAME = __CLASS__; - /** * @Id @Column(type="CustomIdObject") * diff --git a/tests/Doctrine/Tests/Models/CustomType/CustomIdObjectTypeParent.php b/tests/Doctrine/Tests/Models/CustomType/CustomIdObjectTypeParent.php index 0460676fce3..21ce535b8a8 100644 --- a/tests/Doctrine/Tests/Models/CustomType/CustomIdObjectTypeParent.php +++ b/tests/Doctrine/Tests/Models/CustomType/CustomIdObjectTypeParent.php @@ -11,8 +11,6 @@ */ class CustomIdObjectTypeParent { - const CLASSNAME = __CLASS__; - /** * @Id @Column(type="CustomIdObject") * diff --git a/tests/Doctrine/Tests/Models/DDC2504/DDC2504ChildClass.php b/tests/Doctrine/Tests/Models/DDC2504/DDC2504ChildClass.php index 08a4605b62f..a43de5bbfe7 100644 --- a/tests/Doctrine/Tests/Models/DDC2504/DDC2504ChildClass.php +++ b/tests/Doctrine/Tests/Models/DDC2504/DDC2504ChildClass.php @@ -7,5 +7,4 @@ */ class DDC2504ChildClass extends DDC2504RootClass { - const CLASSNAME = __CLASS__; } diff --git a/tests/Doctrine/Tests/Models/DDC2504/DDC2504OtherClass.php b/tests/Doctrine/Tests/Models/DDC2504/DDC2504OtherClass.php index a855cdf8aa9..c90ff2a0c4e 100644 --- a/tests/Doctrine/Tests/Models/DDC2504/DDC2504OtherClass.php +++ b/tests/Doctrine/Tests/Models/DDC2504/DDC2504OtherClass.php @@ -9,8 +9,6 @@ */ class DDC2504OtherClass { - const CLASSNAME = __CLASS__; - /** * @Column(type="integer") * @Id @GeneratedValue diff --git a/tests/Doctrine/Tests/Models/DDC2825/ExplicitSchemaAndTable.php b/tests/Doctrine/Tests/Models/DDC2825/ExplicitSchemaAndTable.php index 60b5d562501..3b6957653cd 100644 --- a/tests/Doctrine/Tests/Models/DDC2825/ExplicitSchemaAndTable.php +++ b/tests/Doctrine/Tests/Models/DDC2825/ExplicitSchemaAndTable.php @@ -5,8 +5,6 @@ /** @Entity @Table(name="explicit_table", schema="explicit_schema") */ class ExplicitSchemaAndTable { - const CLASSNAME = __CLASS__; - /** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */ public $id; } diff --git a/tests/Doctrine/Tests/Models/DDC2825/SchemaAndTableInTableName.php b/tests/Doctrine/Tests/Models/DDC2825/SchemaAndTableInTableName.php index bd22c2b232e..151e577ec56 100644 --- a/tests/Doctrine/Tests/Models/DDC2825/SchemaAndTableInTableName.php +++ b/tests/Doctrine/Tests/Models/DDC2825/SchemaAndTableInTableName.php @@ -10,8 +10,6 @@ */ class SchemaAndTableInTableName { - const CLASSNAME = __CLASS__; - /** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */ public $id; -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DDC3346/DDC3346Article.php b/tests/Doctrine/Tests/Models/DDC3346/DDC3346Article.php index dc8a876c512..8b26c639724 100644 --- a/tests/Doctrine/Tests/Models/DDC3346/DDC3346Article.php +++ b/tests/Doctrine/Tests/Models/DDC3346/DDC3346Article.php @@ -8,8 +8,6 @@ */ class DDC3346Article { - const CLASSNAME = __CLASS__; - /** * @Id * @Column(type="integer") diff --git a/tests/Doctrine/Tests/Models/DDC3346/DDC3346Author.php b/tests/Doctrine/Tests/Models/DDC3346/DDC3346Author.php index e284532c0cc..4611bbdd758 100644 --- a/tests/Doctrine/Tests/Models/DDC3346/DDC3346Author.php +++ b/tests/Doctrine/Tests/Models/DDC3346/DDC3346Author.php @@ -8,8 +8,6 @@ */ class DDC3346Author { - const CLASSNAME = __CLASS__; - /** * @Id @Column(type="integer") * @GeneratedValue diff --git a/tests/Doctrine/Tests/Models/DDC3597/DDC3597Image.php b/tests/Doctrine/Tests/Models/DDC3597/DDC3597Image.php index cc0b92cfb17..5d1acfeb6ad 100644 --- a/tests/Doctrine/Tests/Models/DDC3597/DDC3597Image.php +++ b/tests/Doctrine/Tests/Models/DDC3597/DDC3597Image.php @@ -12,8 +12,6 @@ */ class DDC3597Image extends DDC3597Media { - const CLASSNAME = __CLASS__; - /** * @var DDC3597Dimension * @Embedded(class = "Doctrine\Tests\Models\DDC3597\Embeddable\DDC3597Dimension", columnPrefix = false) diff --git a/tests/Doctrine/Tests/Models/DDC3597/DDC3597Media.php b/tests/Doctrine/Tests/Models/DDC3597/DDC3597Media.php index da6f60cd080..c285b3c40e6 100644 --- a/tests/Doctrine/Tests/Models/DDC3597/DDC3597Media.php +++ b/tests/Doctrine/Tests/Models/DDC3597/DDC3597Media.php @@ -4,14 +4,12 @@ /** * Description of Media - * + * * @author Volker von Hoesslin * @Entity */ abstract class DDC3597Media extends DDC3597Root { - const CLASSNAME = __CLASS__; - /** * @var string * diff --git a/tests/Doctrine/Tests/Models/DDC3597/DDC3597Root.php b/tests/Doctrine/Tests/Models/DDC3597/DDC3597Root.php index 2f24c933af7..3bdb67f13d7 100644 --- a/tests/Doctrine/Tests/Models/DDC3597/DDC3597Root.php +++ b/tests/Doctrine/Tests/Models/DDC3597/DDC3597Root.php @@ -15,8 +15,6 @@ */ abstract class DDC3597Root { - const CLASSNAME = __CLASS__; - /** * @var int * diff --git a/tests/Doctrine/Tests/Models/DDC3699/DDC3699Child.php b/tests/Doctrine/Tests/Models/DDC3699/DDC3699Child.php index dc2222ef156..dc2ccfddde1 100644 --- a/tests/Doctrine/Tests/Models/DDC3699/DDC3699Child.php +++ b/tests/Doctrine/Tests/Models/DDC3699/DDC3699Child.php @@ -5,8 +5,6 @@ /** @Entity @Table(name="ddc3699_child") */ class DDC3699Child extends DDC3699Parent { - const CLASSNAME = __CLASS__; - /** @Id @Column(type="integer") */ public $id; diff --git a/tests/Doctrine/Tests/Models/DDC3699/DDC3699Parent.php b/tests/Doctrine/Tests/Models/DDC3699/DDC3699Parent.php index 09cfedaefdf..2e5e7ab363e 100644 --- a/tests/Doctrine/Tests/Models/DDC3699/DDC3699Parent.php +++ b/tests/Doctrine/Tests/Models/DDC3699/DDC3699Parent.php @@ -5,8 +5,6 @@ /** @MappedSuperclass */ abstract class DDC3699Parent { - const CLASSNAME = __CLASS__; - /** @Column(type="string") */ public $parentField; -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DDC3699/DDC3699RelationMany.php b/tests/Doctrine/Tests/Models/DDC3699/DDC3699RelationMany.php index 3e0c06a67b2..1b907bb9863 100644 --- a/tests/Doctrine/Tests/Models/DDC3699/DDC3699RelationMany.php +++ b/tests/Doctrine/Tests/Models/DDC3699/DDC3699RelationMany.php @@ -8,8 +8,6 @@ */ class DDC3699RelationMany { - const CLASSNAME = __CLASS__; - /** @Id @Column(type="integer") */ public $id; diff --git a/tests/Doctrine/Tests/Models/DDC3699/DDC3699RelationOne.php b/tests/Doctrine/Tests/Models/DDC3699/DDC3699RelationOne.php index c63558d351c..22807aafc82 100644 --- a/tests/Doctrine/Tests/Models/DDC3699/DDC3699RelationOne.php +++ b/tests/Doctrine/Tests/Models/DDC3699/DDC3699RelationOne.php @@ -8,8 +8,6 @@ */ class DDC3699RelationOne { - const CLASSNAME = __CLASS__; - /** @Id @Column(type="integer") */ public $id; diff --git a/tests/Doctrine/Tests/Models/DirectoryTree/AbstractContentItem.php b/tests/Doctrine/Tests/Models/DirectoryTree/AbstractContentItem.php index 166f86cb049..41798724b20 100644 --- a/tests/Doctrine/Tests/Models/DirectoryTree/AbstractContentItem.php +++ b/tests/Doctrine/Tests/Models/DirectoryTree/AbstractContentItem.php @@ -7,8 +7,6 @@ */ abstract class AbstractContentItem { - const CLASSNAME = __CLASS__; - /** * @Id @Column(type="integer") @GeneratedValue */ diff --git a/tests/Doctrine/Tests/Models/DirectoryTree/File.php b/tests/Doctrine/Tests/Models/DirectoryTree/File.php index 2e18a06cfce..f6cbace23ca 100644 --- a/tests/Doctrine/Tests/Models/DirectoryTree/File.php +++ b/tests/Doctrine/Tests/Models/DirectoryTree/File.php @@ -8,8 +8,6 @@ */ class File extends AbstractContentItem { - const CLASSNAME = __CLASS__; - /** @Column(type="string") */ protected $extension = "html"; diff --git a/tests/Doctrine/Tests/Models/Generic/DateTimeModel.php b/tests/Doctrine/Tests/Models/Generic/DateTimeModel.php index c7035ff6856..7ef61ea278c 100644 --- a/tests/Doctrine/Tests/Models/Generic/DateTimeModel.php +++ b/tests/Doctrine/Tests/Models/Generic/DateTimeModel.php @@ -8,8 +8,6 @@ */ class DateTimeModel { - const CLASSNAME = __CLASS__; - /** * @Id @Column(type="integer") * @GeneratedValue diff --git a/tests/Doctrine/Tests/Models/Hydration/EntityWithArrayDefaultArrayValueM2M.php b/tests/Doctrine/Tests/Models/Hydration/EntityWithArrayDefaultArrayValueM2M.php index 8ba57db685a..ff927968eeb 100644 --- a/tests/Doctrine/Tests/Models/Hydration/EntityWithArrayDefaultArrayValueM2M.php +++ b/tests/Doctrine/Tests/Models/Hydration/EntityWithArrayDefaultArrayValueM2M.php @@ -5,8 +5,6 @@ /** @Entity */ class EntityWithArrayDefaultArrayValueM2M { - const CLASSNAME = __CLASS__; - /** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */ public $id; diff --git a/tests/Doctrine/Tests/Models/Hydration/SimpleEntity.php b/tests/Doctrine/Tests/Models/Hydration/SimpleEntity.php index dda00eb3b65..7ec75174de1 100644 --- a/tests/Doctrine/Tests/Models/Hydration/SimpleEntity.php +++ b/tests/Doctrine/Tests/Models/Hydration/SimpleEntity.php @@ -5,8 +5,6 @@ /** @Entity */ class SimpleEntity { - const CLASSNAME = __CLASS__; - /** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */ public $id; } diff --git a/tests/Doctrine/Tests/Models/MixedToOneIdentity/CompositeToOneKeyState.php b/tests/Doctrine/Tests/Models/MixedToOneIdentity/CompositeToOneKeyState.php index 1ff5830585f..09bab229ef6 100644 --- a/tests/Doctrine/Tests/Models/MixedToOneIdentity/CompositeToOneKeyState.php +++ b/tests/Doctrine/Tests/Models/MixedToOneIdentity/CompositeToOneKeyState.php @@ -5,8 +5,6 @@ /** @Entity */ class CompositeToOneKeyState { - const CLASSNAME = __CLASS__; - /** * @Id * @Column(type="string") diff --git a/tests/Doctrine/Tests/Models/MixedToOneIdentity/Country.php b/tests/Doctrine/Tests/Models/MixedToOneIdentity/Country.php index bbdc237f792..629cde160ec 100644 --- a/tests/Doctrine/Tests/Models/MixedToOneIdentity/Country.php +++ b/tests/Doctrine/Tests/Models/MixedToOneIdentity/Country.php @@ -5,8 +5,6 @@ /** @Entity */ class Country { - const CLASSNAME = __CLASS__; - /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ public $country; } diff --git a/tests/Doctrine/Tests/Models/NonPublicSchemaJoins/User.php b/tests/Doctrine/Tests/Models/NonPublicSchemaJoins/User.php index 1c40a5e433c..be80cea33c4 100644 --- a/tests/Doctrine/Tests/Models/NonPublicSchemaJoins/User.php +++ b/tests/Doctrine/Tests/Models/NonPublicSchemaJoins/User.php @@ -10,8 +10,6 @@ */ class User { - const CLASSNAME = __CLASS__; - /** * @Column(type="integer") * @Id diff --git a/tests/Doctrine/Tests/Models/OneToOneSingleTableInheritance/Cat.php b/tests/Doctrine/Tests/Models/OneToOneSingleTableInheritance/Cat.php index 1e7eee014e5..993ae394949 100644 --- a/tests/Doctrine/Tests/Models/OneToOneSingleTableInheritance/Cat.php +++ b/tests/Doctrine/Tests/Models/OneToOneSingleTableInheritance/Cat.php @@ -5,8 +5,6 @@ /** @Entity */ class Cat extends Pet { - const CLASSNAME = __CLASS__; - /** * @OneToOne(targetEntity="LitterBox") * diff --git a/tests/Doctrine/Tests/Models/OneToOneSingleTableInheritance/LitterBox.php b/tests/Doctrine/Tests/Models/OneToOneSingleTableInheritance/LitterBox.php index 7195a83ae0a..c347d2bed80 100644 --- a/tests/Doctrine/Tests/Models/OneToOneSingleTableInheritance/LitterBox.php +++ b/tests/Doctrine/Tests/Models/OneToOneSingleTableInheritance/LitterBox.php @@ -8,8 +8,6 @@ */ class LitterBox { - const CLASSNAME = __CLASS__; - /** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */ public $id; -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/OneToOneSingleTableInheritance/Pet.php b/tests/Doctrine/Tests/Models/OneToOneSingleTableInheritance/Pet.php index e779ddb09da..ed541b9836e 100644 --- a/tests/Doctrine/Tests/Models/OneToOneSingleTableInheritance/Pet.php +++ b/tests/Doctrine/Tests/Models/OneToOneSingleTableInheritance/Pet.php @@ -10,8 +10,6 @@ */ abstract class Pet { - const CLASSNAME = __CLASS__; - /** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */ public $id; } diff --git a/tests/Doctrine/Tests/Models/Reflection/ClassWithMixedProperties.php b/tests/Doctrine/Tests/Models/Reflection/ClassWithMixedProperties.php index 72899959a11..80f48086695 100644 --- a/tests/Doctrine/Tests/Models/Reflection/ClassWithMixedProperties.php +++ b/tests/Doctrine/Tests/Models/Reflection/ClassWithMixedProperties.php @@ -4,8 +4,6 @@ class ClassWithMixedProperties extends ParentClass { - const CLASSNAME = __CLASS__; - public static $staticProperty = 'staticProperty'; public $publicProperty = 'publicProperty'; diff --git a/tests/Doctrine/Tests/Models/Reflection/ParentClass.php b/tests/Doctrine/Tests/Models/Reflection/ParentClass.php index bcc64ce9283..f0e58f8d9ae 100644 --- a/tests/Doctrine/Tests/Models/Reflection/ParentClass.php +++ b/tests/Doctrine/Tests/Models/Reflection/ParentClass.php @@ -4,7 +4,5 @@ class ParentClass { - const CLASSNAME = __CLASS__; - private $privatePropertyOverride = 'privatePropertyOverride'; } diff --git a/tests/Doctrine/Tests/Models/Tweet/Tweet.php b/tests/Doctrine/Tests/Models/Tweet/Tweet.php index 8a315df9ef0..5455452c2b6 100644 --- a/tests/Doctrine/Tests/Models/Tweet/Tweet.php +++ b/tests/Doctrine/Tests/Models/Tweet/Tweet.php @@ -8,8 +8,6 @@ */ class Tweet { - const CLASSNAME = __CLASS__; - /** * @Id * @GeneratedValue diff --git a/tests/Doctrine/Tests/Models/Tweet/User.php b/tests/Doctrine/Tests/Models/Tweet/User.php index 68cf137f2b0..4efd6193e4f 100644 --- a/tests/Doctrine/Tests/Models/Tweet/User.php +++ b/tests/Doctrine/Tests/Models/Tweet/User.php @@ -10,8 +10,6 @@ */ class User { - const CLASSNAME = __CLASS__; - /** * @Id * @GeneratedValue diff --git a/tests/Doctrine/Tests/Models/Tweet/UserList.php b/tests/Doctrine/Tests/Models/Tweet/UserList.php index 1eb3e141f03..0f20f94b938 100644 --- a/tests/Doctrine/Tests/Models/Tweet/UserList.php +++ b/tests/Doctrine/Tests/Models/Tweet/UserList.php @@ -8,8 +8,6 @@ */ class UserList { - const CLASSNAME = __CLASS__; - /** * @Id * @GeneratedValue diff --git a/tests/Doctrine/Tests/Models/VersionedManyToOne/Article.php b/tests/Doctrine/Tests/Models/VersionedManyToOne/Article.php index 0e5b1683fb4..16a5d743aab 100644 --- a/tests/Doctrine/Tests/Models/VersionedManyToOne/Article.php +++ b/tests/Doctrine/Tests/Models/VersionedManyToOne/Article.php @@ -8,8 +8,6 @@ */ class Article { - const CLASSNAME = __CLASS__; - /** * @Id * @Column(name="id", type="integer") diff --git a/tests/Doctrine/Tests/Models/VersionedManyToOne/Category.php b/tests/Doctrine/Tests/Models/VersionedManyToOne/Category.php index cb884067215..e29593a812d 100644 --- a/tests/Doctrine/Tests/Models/VersionedManyToOne/Category.php +++ b/tests/Doctrine/Tests/Models/VersionedManyToOne/Category.php @@ -8,8 +8,6 @@ */ class Category { - const CLASSNAME = __CLASS__; - /** * @Id * @Column(name="id", type="integer") diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2494Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2494Test.php index 33109ddd761..4aa30e95046 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2494Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2494Test.php @@ -76,8 +76,6 @@ public function testIssue() */ class DDC2494Currency { - const CLASSNAME = __CLASS__; - /** * @Id * @Column(type="integer", type="ddc2494_tinyint") @@ -124,8 +122,6 @@ public function getCampaigns() */ class DDC2494Campaign { - const CLASSNAME = __CLASS__; - /** * @Id * @GeneratedValue diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2579Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2579Test.php index 53ab6550b2a..e7ba77759f4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2579Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2579Test.php @@ -67,9 +67,6 @@ public function testIssue() */ class DDC2579Entity { - - const CLASSNAME = __CLASS__; - /** * @Id * @Column(type="ddc2579") @@ -102,8 +99,6 @@ public function __construct(DDC2579EntityAssoc $assoc, $value = 0) */ class DDC2579EntityAssoc { - const CLASSNAME = __CLASS__; - /** * @Id * @ManyToOne(targetEntity="DDC2579AssocAssoc") @@ -122,8 +117,6 @@ public function __construct(DDC2579AssocAssoc $assocAssoc) */ class DDC2579AssocAssoc { - const CLASSNAME = __CLASS__; - /** * @Id * @Column(type="ddc2579") @@ -140,7 +133,6 @@ public function __construct(DDC2579Id $id) class DDC2579Type extends StringType { const NAME = 'ddc2579'; - const CLASSNAME = __CLASS__; /** * {@inheritdoc} @@ -166,8 +158,6 @@ public function getName() class DDC2579Id { - const CLASSNAME = __CLASS__; - private $val; public function __construct($val) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php index 179fff8d0e3..7aeba002a0a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php @@ -100,8 +100,6 @@ public function getTestedClasses() */ class DDC2825ClassWithImplicitlyDefinedSchemaAndQuotedTableName { - const CLASSNAME = __CLASS__; - /** * @Id @GeneratedValue * @Column(type="integer") diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2862Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2862Test.php index 9a5bccd585f..c4b2fb227bf 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2862Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2862Test.php @@ -119,8 +119,6 @@ public function testIssueReopened() */ class DDC2862Driver { - const CLASSNAME = __CLASS__; - /** * @Id * @GeneratedValue @@ -196,8 +194,6 @@ public function getUserProfile() */ class DDC2862User { - const CLASSNAME = __CLASS__; - /** * @Id * @GeneratedValue diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3192Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3192Test.php index 0c4def0456e..1262bce4521 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3192Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3192Test.php @@ -72,8 +72,6 @@ public function testIssue() */ class DDC3192Currency { - const CLASSNAME = __CLASS__; - /** * @Id * @Column(type="ddc3192_currency_code") @@ -99,8 +97,6 @@ public function __construct($code) */ class DDC3192Transaction { - const CLASSNAME = __CLASS__; - /** * @Id * @GeneratedValue diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3300Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3300Test.php index 0f31ecedfe0..17de7d217e1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3300Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3300Test.php @@ -58,30 +58,24 @@ public function testResolveTargetEntitiesChangesDiscriminatorMapValues() */ abstract class DDC3300Person { - const CLASSNAME = __CLASS__; - /** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */ public $id; } interface DDC3300BossInterface { - const INTERFACENAME = __CLASS__; } /** @Entity */ class DDC3300Boss extends DDC3300Person implements DDC3300BossInterface { - const CLASSNAME = __CLASS__; } interface DDC3300EmployeeInterface { - const INTERFACENAME = __CLASS__; } /** @Entity */ class DDC3300Employee extends DDC3300Person implements DDC3300EmployeeInterface { - const CLASSNAME = __CLASS__; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3582Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3582Test.php index 2f10adcee32..17b4bed85e4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3582Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3582Test.php @@ -23,8 +23,6 @@ function testNestedEmbeddablesAreHydratedWithProperClass() /** @Entity */ class DDC3582Entity { - const CLASSNAME = __CLASS__; - /** @Column @Id */ private $id; @@ -41,8 +39,6 @@ public function __construct($id) /** @Embeddable */ class DDC3582Embeddable1 { - const CLASSNAME = __CLASS__; - /** @Embedded(class="DDC3582Embeddable2") @var DDC3582Embeddable2 */ public $embeddable2; @@ -52,8 +48,6 @@ public function __construct() { $this->embeddable2 = new DDC3582Embeddable2(); } /** @Embeddable */ class DDC3582Embeddable2 { - const CLASSNAME = __CLASS__; - /** @Embedded(class="DDC3582Embeddable3") @var DDC3582Embeddable3 */ public $embeddable3; @@ -63,8 +57,6 @@ public function __construct() { $this->embeddable3 = new DDC3582Embeddable3(); } /** @Embeddable */ class DDC3582Embeddable3 { - const CLASSNAME = __CLASS__; - /** @Column */ public $embeddedValue = 'foo'; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php index 2f499f2d292..01f42bb930f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php @@ -74,8 +74,6 @@ public function testSavesIntegerAutoGeneratedValueAsStringWithJoinedInheritance( /** @Entity */ class DDC3634Entity { - const CLASSNAME = __CLASS__; - /** @Id @Column(type="bigint") @GeneratedValue(strategy="AUTO") */ public $id; } @@ -90,8 +88,6 @@ class DDC3634Entity */ class DDC3634JTIBaseEntity { - const CLASSNAME = __CLASS__; - /** @Id @Column(type="bigint") @GeneratedValue(strategy="AUTO") */ public $id; } @@ -99,7 +95,6 @@ class DDC3634JTIBaseEntity /** @Entity */ class DDC3634JTIChildEntity extends DDC3634JTIBaseEntity { - const CLASSNAME = __CLASS__; } class DDC3634LastInsertIdMockingConnection extends Connection diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC5684Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC5684Test.php index 2e9fb8a8c70..e525ae1342b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC5684Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC5684Test.php @@ -60,8 +60,6 @@ public function testFetchObjectWithAutoIncrementedCustomType() class DDC5684ObjectIdType extends DBALTypes\IntegerType { - const CLASSNAME = __CLASS__; - public function convertToPHPValue($value, AbstractPlatform $platform) { return new DDC5684ObjectId($value); @@ -85,8 +83,6 @@ public function requiresSQLCommentHint(AbstractPlatform $platform) class DDC5684ObjectId { - const CLASSNAME = __CLASS__; - public $value; public function __construct($value) @@ -106,8 +102,6 @@ public function __toString() */ class DDC5684Object { - const CLASSNAME = __CLASS__; - /** * @Id * @Column(type=Doctrine\Tests\ORM\Functional\Ticket\DDC5684ObjectIdType::class) diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php index 7df4171b42c..ff5de971acd 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php @@ -336,8 +336,6 @@ public function getInfiniteEmbeddableNestingData() */ class DDC93Person { - const CLASSNAME = __CLASS__; - /** @Id @GeneratedValue @Column(type="integer") */ public $id; @@ -407,8 +405,6 @@ class DDC93Car extends DDC93Vehicle */ class DDC93Country { - const CLASSNAME = __CLASS__; - /** * @Column(type="string", nullable=true) */ @@ -425,8 +421,6 @@ public function __construct($name = null) */ class DDC93Address { - const CLASSNAME = __CLASS__; - /** * @Column(type="string") */ @@ -464,8 +458,6 @@ class DDC93Customer /** @Embeddable */ class DDC93ContactInfo { - const CLASSNAME = __CLASS__; - /** * @Column(type="string") */ @@ -479,8 +471,6 @@ class DDC93ContactInfo */ class DDC3028PersonWithPrefix { - const CLASSNAME = __CLASS__; - /** @Embedded(class="DDC3028Id", columnPrefix = "foobar_") */ public $id; @@ -499,8 +489,6 @@ public function __construct(DDC3028Id $id = null, DDC3028NestedEmbeddable $neste */ class DDC3028PersonEmptyPrefix { - const CLASSNAME = __CLASS__; - /** @Embedded(class="DDC3028Id", columnPrefix = "") */ public $id; @@ -519,8 +507,6 @@ public function __construct(DDC3028Id $id = null, DDC3028NestedEmbeddable $neste */ class DDC3028PersonPrefixFalse { - const CLASSNAME = __CLASS__; - /** @Embedded(class="DDC3028Id", columnPrefix = false) */ public $id; @@ -535,8 +521,6 @@ public function __construct(DDC3028Id $id = null) */ class DDC3028Id { - const CLASSNAME = __CLASS__; - /** * @Id @Column(type="string") */ @@ -553,8 +537,6 @@ public function __construct($id = null) */ class DDC3028NestedEmbeddable { - const CLASSNAME = __CLASS__; - /** @Embedded(class="DDC3028Id", columnPrefix = "foo_") */ public $nestedWithPrefix; diff --git a/tests/Doctrine/Tests/ORM/Tools/AttachEntityListenersListenerTest.php b/tests/Doctrine/Tests/ORM/Tools/AttachEntityListenersListenerTest.php index 5008470feb5..db4da0b5d88 100644 --- a/tests/Doctrine/Tests/ORM/Tools/AttachEntityListenersListenerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/AttachEntityListenersListenerTest.php @@ -117,8 +117,6 @@ public function testDuplicateEntityListenerException() */ class AttachEntityListenersListenerTestFooEntity { - const CLASSNAME = __CLASS__; - /** * @Id * @Column(type="integer") @@ -133,8 +131,6 @@ class AttachEntityListenersListenerTestFooEntity */ class AttachEntityListenersListenerTestBarEntity { - const CLASSNAME = __CLASS__; - /** * @Id * @Column(type="integer") @@ -145,8 +141,6 @@ class AttachEntityListenersListenerTestBarEntity class AttachEntityListenersListenerTestListener { - const CLASSNAME = __CLASS__; - public $calls; public function prePersist() @@ -167,8 +161,6 @@ public function postPersist() class AttachEntityListenersListenerTestListener2 { - const CLASSNAME = __CLASS__; - public $calls; public function prePersist() From ba9fecc43fcf1e6776888854691b287d84429516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Thu, 8 Dec 2016 18:16:11 +0100 Subject: [PATCH 174/877] Remove commented code that seems to not be important --- .../ORM/Functional/BasicFunctionalTest.php | 10 --- .../Functional/ClassTableInheritanceTest.php | 1 - .../Tests/ORM/Functional/NotifyPolicyTest.php | 2 - .../PersistentCollectionCriteriaTest.php | 24 ------- .../ORM/Functional/Ticket/DDC144Test.php | 1 - .../ORM/Functional/Ticket/DDC3330Test.php | 7 -- .../ORM/Functional/Ticket/DDC425Test.php | 1 - .../ORM/Functional/Ticket/DDC522Test.php | 2 - .../ORM/Hydration/ObjectHydratorTest.php | 64 ------------------- .../Tests/ORM/Mapping/ClassMetadataTest.php | 1 - 10 files changed, 113 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php index a0ac9a3a7b7..eec4844d149 100644 --- a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php @@ -50,7 +50,6 @@ public function testBasicUnitsOfWorkWithOneToManyAssociation() $this->_em->flush(); $this->assertTrue($this->_em->contains($ph)); $this->assertTrue($this->_em->contains($user)); - //$this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $user->phonenumbers); // Update name $user->name = 'guilherme'; @@ -96,8 +95,6 @@ public function testOneToManyAssociationModification() $this->_em->persist($user); $this->_em->flush(); - //$this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $user->phonenumbers); - // Remove the first element from the collection unset($user->phonenumbers[0]); $ph1->user = null; // owning side! @@ -283,7 +280,6 @@ public function testBasicOneToManyLeftJoin() $this->assertInstanceOf(PersistentCollection::class, $users[0]->phonenumbers); $this->assertTrue($users[0]->phonenumbers->isInitialized()); $this->assertEquals(0, $users[0]->phonenumbers->count()); - //$this->assertNull($users[0]->articles); } public function testBasicRefresh() @@ -512,9 +508,6 @@ public function testSetSetAssociationWithGetReference() // that address to the user without actually loading it, using getReference(). $addressRef = $this->_em->getReference(CmsAddress::class, $address->getId()); - //$addressRef->getId(); - //\Doctrine\Common\Util\Debug::dump($addressRef); - $user->setAddress($addressRef); // Ugh! Initializes address 'cause of $address->setUser($user)! $this->_em->flush(); @@ -761,7 +754,6 @@ public function testNewAssociatedEntityDuringFlushThrowsException() */ public function testNewAssociatedEntityDuringFlushThrowsException2() { - //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); $user = new CmsUser(); $user->username = "beberlei"; $user->name = "Benjamin E."; @@ -796,7 +788,6 @@ public function testNewAssociatedEntityDuringFlushThrowsException2() */ public function testNewAssociatedEntityDuringFlushThrowsException3() { - //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); $art = new CmsArticle(); $art->topic = 'topic'; $art->text = 'the text'; @@ -954,7 +945,6 @@ public function testMergeThrowsExceptionIfEntityWithGeneratedIdentifierDoesNotEx */ public function testOneToOneMergeSetNull() { - //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); $user = new CmsUser(); $user->username = "beberlei"; $user->name = "Benjamin E."; diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php index 3553f9ad225..2698c325242 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php @@ -137,7 +137,6 @@ public function testFindOnBaseClass() { $this->assertEquals(100000, $person->getSalary()); $this->assertEquals('CTO', $person->getTitle()); $this->assertTrue(is_numeric($person->getId())); - //$this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyCar', $person->getCar()); } public function testSelfReferencingOneToOne() { diff --git a/tests/Doctrine/Tests/ORM/Functional/NotifyPolicyTest.php b/tests/Doctrine/Tests/ORM/Functional/NotifyPolicyTest.php index 24dc6fd2468..5444af6710e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/NotifyPolicyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/NotifyPolicyTest.php @@ -31,8 +31,6 @@ protected function setUp() public function testChangeTracking() { - //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - $user = new NotifyUser(); $group = new NotifyGroup(); $user->setName('roman'); diff --git a/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php b/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php index a02f4091a15..4e0f442d84a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php @@ -95,28 +95,4 @@ public function testCanCountWithoutLoadingPersistentCollection() $this->assertCount(1, $tweets); $this->assertFalse($tweets->isInitialized()); } - - /*public function testCanCountWithoutLoadingManyToManyPersistentCollection() - { - $this->loadQuoteFixture(); - - $repository = $this->_em->getRepository('Doctrine\Tests\Models\Quote\User'); - - $user = $repository->findOneBy(array('name' => 'mgal')); - $groups = $user->groups->matching(new Criteria()); - - $this->assertInstanceOf('Doctrine\ORM\LazyManyToManyCriteriaCollection', $groups); - $this->assertFalse($groups->isInitialized()); - $this->assertCount(2, $groups); - $this->assertFalse($groups->isInitialized()); - - // Make sure it works with constraints - $criteria = new Criteria(Criteria::expr()->eq('name', 'quote1')); - $groups = $user->groups->matching($criteria); - - $this->assertInstanceOf('Doctrine\ORM\LazyManyToManyCriteriaCollection', $groups); - $this->assertFalse($groups->isInitialized()); - $this->assertCount(1, $groups); - $this->assertFalse($groups->isInitialized()); - }*/ } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php index 78276f0ddc8..f85df4a7eee 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php @@ -13,7 +13,6 @@ protected function setUp() { $this->_schemaTool->createSchema( [ $this->_em->getClassMetadata(DDC144FlowElement::class), - // $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC144Expression'), $this->_em->getClassMetadata(DDC144Operand::class), ] ); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3330Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3330Test.php index c6a2f4ab1c2..a03c3172cfd 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3330Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3330Test.php @@ -42,13 +42,6 @@ public function testIssueCollectionOrderWithPaginator() $paginator = new Paginator($query, true); - /*foreach ($paginator as $building) { - echo 'BUILDING ID: '.$building->id."\n"; - foreach ($building->halls as $hall) { - echo ' - HALL: '.$hall->id.' - '.$hall->name."\n"; - } - }*/ - $this->assertEquals(3, count(iterator_to_array($paginator)), 'Count is not correct for pagination'); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC425Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC425Test.php index 9c06160c7a4..8d91119a200 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC425Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC425Test.php @@ -11,7 +11,6 @@ protected function setUp() $this->_schemaTool->createSchema( [ $this->_em->getClassMetadata(DDC425Entity::class), - //$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC425Other') ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php index 91860e8b0d1..9818e60aa87 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php @@ -31,8 +31,6 @@ protected function setUp() */ public function testJoinColumnWithSameNameAsAssociationField() { - //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - $cust = new DDC522Customer; $cust->name = "name"; $cart = new DDC522Cart; diff --git a/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php index 83e398836d8..c7d82a0dc7a 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php @@ -1223,70 +1223,6 @@ public function testChainedJoinWithEmptyCollectionsWithAliasedUserEntity() $this->assertEquals(0, $result[1]['user']->articles->count()); } - /** - * SELECT PARTIAL u.{id,status}, a.id, a.topic, c.id as cid, c.topic as ctopic - * FROM CmsUser u - * LEFT JOIN u.articles a - * LEFT JOIN a.comments c - * - * @group bubu - * @dataProvider provideDataForUserEntityResult - */ - /*public function testChainedJoinWithScalars($userEntityKey) - { - $rsm = new ResultSetMapping; - $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); - $rsm->addFieldResult('u', 'u__id', 'id'); - $rsm->addFieldResult('u', 'u__status', 'status'); - $rsm->addScalarResult('a__id', 'id'); - $rsm->addScalarResult('a__topic', 'topic'); - $rsm->addScalarResult('c__id', 'cid'); - $rsm->addScalarResult('c__topic', 'ctopic'); - - // Faked result set - $resultSet = array( - //row1 - array( - 'u__id' => '1', - 'u__status' => 'developer', - 'a__id' => '1', - 'a__topic' => 'The First', - 'c__id' => '1', - 'c__topic' => 'First Comment' - ), - array( - 'u__id' => '1', - 'u__status' => 'developer', - 'a__id' => '1', - 'a__topic' => 'The First', - 'c__id' => '2', - 'c__topic' => 'Second Comment' - ), - array( - 'u__id' => '1', - 'u__status' => 'developer', - 'a__id' => '42', - 'a__topic' => 'The Answer', - 'c__id' => null, - 'c__topic' => null - ), - ); - - $stmt = new HydratorMockStatement($resultSet); - $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); - - \Doctrine\Common\Util\Debug::dump($result, 3); - - $this->assertEquals(1, count($result)); - - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0][$userEntityKey]); // User object - $this->assertEquals(42, $result[0]['id']); - $this->assertEquals('The First', $result[0]['topic']); - $this->assertEquals(1, $result[0]['cid']); - $this->assertEquals('First Comment', $result[0]['ctopic']); - }*/ - /** * SELECT PARTIAL u.{id, name} * FROM Doctrine\Tests\Models\CMS\CmsUser u diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php index 1dac953c2ba..3e9148b4d27 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php @@ -127,7 +127,6 @@ public function testMapManyToManyJoinTableDefaults() ); $assoc = $cm->associationMappings['groups']; - //$this->assertInstanceOf('Doctrine\ORM\Mapping\ManyToManyMapping', $assoc); $this->assertEquals( [ 'name' => 'cmsuser_cmsgroup', From 6aa81d1d366250fc38b15aedd158843ce8dc68fa Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Wed, 14 Dec 2016 00:10:39 +0100 Subject: [PATCH 175/877] Include example of a cascaded "persist" operation Following up on https://github.com/doctrine/doctrine2/issues/2943 I started to clarify how it's supposed to be done. Please check if this would be necessary (at line 511): `$myFirstComment->setUser($user);` ...and add it (in case). --- docs/en/reference/working-with-associations.rst | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/en/reference/working-with-associations.rst b/docs/en/reference/working-with-associations.rst index 85ffaee3a2f..f79371d16ea 100644 --- a/docs/en/reference/working-with-associations.rst +++ b/docs/en/reference/working-with-associations.rst @@ -453,11 +453,11 @@ following code: $user->addComment($myFirstComment); $em->persist($user); - $em->persist($myFirstComment); + $em->persist($myFirstComment); // mandatory if `persist` isn't set $em->flush(); Even if you *persist* a new User that contains our new Comment this -code would fail if you removed the call to +code requires the explicit call to ``EntityManager#persist($myFirstComment)``. Doctrine 2 does not cascade the persist operation to all nested entities that are new as well. @@ -500,6 +500,18 @@ and the "remove" operation. //... } +Now you can persist the `User` entity like that: + +.. code-block:: php + + addComment($myFirstComment); + + $em->persist($user); + $em->flush(); + Even though automatic cascading is convenient it should be used with care. Do not blindly apply cascade=all to all associations as it will unnecessarily degrade the performance of your application. From a06f8d475992f8fe4ac7cd0e6463882ed2f7c25f Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Wed, 14 Dec 2016 21:38:10 +0100 Subject: [PATCH 176/877] Update working-with-associations.rst --- docs/en/reference/working-with-associations.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/working-with-associations.rst b/docs/en/reference/working-with-associations.rst index f79371d16ea..32fcfdabab0 100644 --- a/docs/en/reference/working-with-associations.rst +++ b/docs/en/reference/working-with-associations.rst @@ -453,7 +453,7 @@ following code: $user->addComment($myFirstComment); $em->persist($user); - $em->persist($myFirstComment); // mandatory if `persist` isn't set + $em->persist($myFirstComment); // mandatory if `cascade: persist` isn't set $em->flush(); Even if you *persist* a new User that contains our new Comment this From 29062fb42e7dd31874f74a1ceb1fd686c290b6ad Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Wed, 14 Dec 2016 21:39:47 +0100 Subject: [PATCH 177/877] Update working-with-associations.rst --- docs/en/reference/working-with-associations.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/working-with-associations.rst b/docs/en/reference/working-with-associations.rst index 32fcfdabab0..2ef52f781bb 100644 --- a/docs/en/reference/working-with-associations.rst +++ b/docs/en/reference/working-with-associations.rst @@ -457,7 +457,7 @@ following code: $em->flush(); Even if you *persist* a new User that contains our new Comment this -code requires the explicit call to +code requires an explicit call to ``EntityManager#persist($myFirstComment)``. Doctrine 2 does not cascade the persist operation to all nested entities that are new as well. From 879d4e7df063745f534115aedc8ac35f7139c37e Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Wed, 14 Dec 2016 21:46:18 +0100 Subject: [PATCH 178/877] Update working-with-associations.rst --- docs/en/reference/working-with-associations.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/en/reference/working-with-associations.rst b/docs/en/reference/working-with-associations.rst index 2ef52f781bb..7e088f94468 100644 --- a/docs/en/reference/working-with-associations.rst +++ b/docs/en/reference/working-with-associations.rst @@ -500,7 +500,8 @@ and the "remove" operation. //... } -Now you can persist the `User` entity like that: +Since ``cascade: persist`` is configured for the ``User#commentsAuthored`` +association, you can now create a user and persist his comment as follows: .. code-block:: php From d1c8d378cfa253489e0fd0623dc8a06708e34af9 Mon Sep 17 00:00:00 2001 From: bilouwan Date: Thu, 15 Dec 2016 12:19:56 +0100 Subject: [PATCH 179/877] Create failing test to reveal the issue --- .../Functional/EntityListenersOnMergeTest.php | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/EntityListenersOnMergeTest.php diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityListenersOnMergeTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityListenersOnMergeTest.php new file mode 100644 index 00000000000..a3575a821e8 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/EntityListenersOnMergeTest.php @@ -0,0 +1,50 @@ +_schemaTool->createSchema( + [ + $this->_em->getClassMetadata(DDC3597Root::class), + $this->_em->getClassMetadata(DDC3597Media::class), + $this->_em->getClassMetadata(DDC3597Image::class), + ] + ); + } + + protected function tearDown() + { + parent::tearDown(); + $this->_schemaTool->dropSchema( + [ + $this->_em->getClassMetadata(DDC3597Root::class), + $this->_em->getClassMetadata(DDC3597Media::class), + $this->_em->getClassMetadata(DDC3597Image::class), + ] + ); + } + + public function testMergeNewEntityLifecyleEventsModificationsShouldBeKept() + { + $imageEntity = new DDC3597Image('foobar'); + $imageEntity->setFormat('JPG'); + $imageEntity->setSize(123); + $imageEntity->getDimension()->setWidth(300); + $imageEntity->getDimension()->setHeight(500); + + $imageEntity = $this->_em->merge($imageEntity); + + $this->assertNotNull($imageEntity->getCreatedAt()); + $this->assertNotNull($imageEntity->getUpdatedAt()); + } +} \ No newline at end of file From 493d39f5dffb51d9614bf312fc60ee0ee9cf5c9c Mon Sep 17 00:00:00 2001 From: bilouwan Date: Thu, 15 Dec 2016 12:49:11 +0100 Subject: [PATCH 180/877] doMerge will mergeEntityStateIntoManagedCopy BEFORE persistNew to let lifecyle events changes be persisted --- lib/Doctrine/ORM/UnitOfWork.php | 46 +++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 00a41e6dffc..f175d47e96b 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1816,6 +1816,7 @@ private function doMerge($entity, array &$visited, $prevManagedCopy = null, arra if ( ! $id) { $managedCopy = $this->newInstance($class); + $this->mergeEntityStateIntoManagedCopy($entity, $managedCopy); $this->persistNew($class, $managedCopy); } else { $flatId = ($class->containsForeignIdentifier) @@ -1847,30 +1848,16 @@ private function doMerge($entity, array &$visited, $prevManagedCopy = null, arra $managedCopy = $this->newInstance($class); $class->setIdentifierValues($managedCopy, $id); + $this->mergeEntityStateIntoManagedCopy($entity, $managedCopy); $this->persistNew($class, $managedCopy); - } - } - - if ($class->isVersioned && $this->isLoaded($managedCopy) && $this->isLoaded($entity)) { - $reflField = $class->reflFields[$class->versionField]; - $managedCopyVersion = $reflField->getValue($managedCopy); - $entityVersion = $reflField->getValue($entity); - - // Throw exception if versions don't match. - if ($managedCopyVersion != $entityVersion) { - throw OptimisticLockException::lockFailedVersionMismatch($entity, $entityVersion, $managedCopyVersion); + }else{ + $this->ensureVersionMatch($class, $entity, $managedCopy); + $this->mergeEntityStateIntoManagedCopy($entity, $managedCopy); } } $visited[$oid] = $managedCopy; // mark visited - - if ($this->isLoaded($entity)) { - if ($managedCopy instanceof Proxy && ! $managedCopy->__isInitialized()) { - $managedCopy->__load(); - } - - $this->mergeEntityStateIntoManagedCopy($entity, $managedCopy); - } + // $this->mergeEntityStateIntoManagedCopy($entity, $managedCopy); if ($class->isChangeTrackingDeferredExplicit()) { $this->scheduleForDirtyCheck($entity); @@ -1889,6 +1876,19 @@ private function doMerge($entity, array &$visited, $prevManagedCopy = null, arra return $managedCopy; } + private function ensureVersionMatch(ClassMetadata $class, $entity, $managedCopy) { + if ($class->isVersioned && $this->isLoaded($managedCopy) && $this->isLoaded($entity)) { + $reflField = $class->reflFields[$class->versionField]; + $managedCopyVersion = $reflField->getValue($managedCopy); + $entityVersion = $reflField->getValue($entity); + + // Throw exception if versions don't match. + if ($managedCopyVersion != $entityVersion) { + throw OptimisticLockException::lockFailedVersionMismatch($entity, $entityVersion, $managedCopyVersion); + } + } + } + /** * Tests if an entity is loaded - must either be a loaded proxy or not a proxy * @@ -3338,6 +3338,14 @@ private function isIdentifierEquals($entity1, $entity2) */ private function mergeEntityStateIntoManagedCopy($entity, $managedCopy) { + if (!$this->isLoaded($entity)) { + return; + } + + if (!$this->isLoaded($managedCopy)) { + $managedCopy->__load(); + } + $class = $this->em->getClassMetadata(get_class($entity)); foreach ($this->reflectionPropertiesGetter->getProperties($class->name) as $prop) { From 7f4de25a268e74521c8f674a9065b90111f762e2 Mon Sep 17 00:00:00 2001 From: bilouwan Date: Thu, 15 Dec 2016 13:03:53 +0100 Subject: [PATCH 181/877] Cherry pick unit test from PR #5570 (Fix PrePersist EventListener when using merge instead of persist) --- .../Company/CompanyContractListener.php | 29 ++++++++++-- .../Functional/EntityListenersOnMergeTest.php | 46 +++++++++++++++++++ 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/tests/Doctrine/Tests/Models/Company/CompanyContractListener.php b/tests/Doctrine/Tests/Models/Company/CompanyContractListener.php index 61c1d4719f2..c5862887835 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyContractListener.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyContractListener.php @@ -4,19 +4,23 @@ class CompanyContractListener { + const PRE_PERSIST = 0; + public $postPersistCalls; public $prePersistCalls; - + public $postUpdateCalls; public $preUpdateCalls; - + public $postRemoveCalls; public $preRemoveCalls; public $preFlushCalls; - + public $postLoadCalls; - + + public $snapshots = []; + /** * @PostPersist */ @@ -30,6 +34,7 @@ public function postPersistHandler(CompanyContract $contract) */ public function prePersistHandler(CompanyContract $contract) { + $this->snapshots[self::PRE_PERSIST][] = $this->takeSnapshot($contract); $this->prePersistCalls[] = func_get_args(); } @@ -81,4 +86,20 @@ public function postLoadHandler(CompanyContract $contract) $this->postLoadCalls[] = func_get_args(); } + public function takeSnapshot(CompanyContract $contract) + { + $snapshot = []; + $reflexion = new \ReflectionClass($contract); + foreach ($reflexion->getProperties() as $property) { + $property->setAccessible(true); + $value = $property->getValue($contract); + if (is_object($value) || is_array($value)) { + continue; + } + $snapshot[$property->getName()] = $property->getValue($contract); + } + + return $snapshot; + } + } diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityListenersOnMergeTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityListenersOnMergeTest.php index a3575a821e8..5354c0a30aa 100644 --- a/tests/Doctrine/Tests/ORM/Functional/EntityListenersOnMergeTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/EntityListenersOnMergeTest.php @@ -2,17 +2,28 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\Tests\Models\Company\CompanyContractListener; +use Doctrine\Tests\Models\Company\CompanyFixContract; use Doctrine\Tests\Models\DDC3597\DDC3597Image; use Doctrine\Tests\Models\DDC3597\DDC3597Media; use Doctrine\Tests\Models\DDC3597\DDC3597Root; /** + * @group DDC-1955 */ class EntityListenersOnMergeTest extends \Doctrine\Tests\OrmFunctionalTestCase { + + /** + * @var \Doctrine\Tests\Models\Company\CompanyContractListener + */ + private $listener; + protected function setUp() { + $this->useModelSet('company'); parent::setUp(); + $this->_schemaTool->createSchema( [ $this->_em->getClassMetadata(DDC3597Root::class), @@ -20,6 +31,10 @@ protected function setUp() $this->_em->getClassMetadata(DDC3597Image::class), ] ); + + $this->listener = $this->_em->getConfiguration() + ->getEntityListenerResolver() + ->resolve('Doctrine\Tests\Models\Company\CompanyContractListener'); } protected function tearDown() @@ -47,4 +62,35 @@ public function testMergeNewEntityLifecyleEventsModificationsShouldBeKept() $this->assertNotNull($imageEntity->getCreatedAt()); $this->assertNotNull($imageEntity->getUpdatedAt()); } + + public function testPrePersistListeners() + { + $fix = new CompanyFixContract(); + $fix->setFixPrice(2000); + + $this->listener->prePersistCalls = []; + + $fix = $this->_em->merge($fix); + $this->_em->flush(); + + $this->assertCount(1, $this->listener->prePersistCalls); + + $this->assertSame($fix, $this->listener->prePersistCalls[0][0]); + + $this->assertInstanceOf( + 'Doctrine\Tests\Models\Company\CompanyFixContract', + $this->listener->prePersistCalls[0][0] + ); + + $this->assertInstanceOf( + 'Doctrine\ORM\Event\LifecycleEventArgs', + $this->listener->prePersistCalls[0][1] + ); + + $this->assertArrayHasKey('fixPrice', $this->listener->snapshots[CompanyContractListener::PRE_PERSIST][0]); + $this->assertEquals( + $fix->getFixPrice(), + $this->listener->snapshots[CompanyContractListener::PRE_PERSIST][0]['fixPrice'] + ); + } } \ No newline at end of file From 1be226cf63943a02e9cf4ea1079fe7fbfb05e4ec Mon Sep 17 00:00:00 2001 From: bilouwan Date: Thu, 15 Dec 2016 15:12:29 +0100 Subject: [PATCH 182/877] Rename test --- .../Tests/ORM/Functional/EntityListenersOnMergeTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityListenersOnMergeTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityListenersOnMergeTest.php index 5354c0a30aa..6123fe99770 100644 --- a/tests/Doctrine/Tests/ORM/Functional/EntityListenersOnMergeTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/EntityListenersOnMergeTest.php @@ -63,7 +63,7 @@ public function testMergeNewEntityLifecyleEventsModificationsShouldBeKept() $this->assertNotNull($imageEntity->getUpdatedAt()); } - public function testPrePersistListeners() + public function testPrePersistListenersShouldBeFiredWithCorrectEntityData() { $fix = new CompanyFixContract(); $fix->setFixPrice(2000); From 754f36ef657c064aa8d062077d13656e0976cc12 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 18 Dec 2016 14:27:35 +0100 Subject: [PATCH 183/877] #6174 #5570 CS - alignment --- lib/Doctrine/ORM/UnitOfWork.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index f175d47e96b..56a7ff7b8e0 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1876,7 +1876,8 @@ private function doMerge($entity, array &$visited, $prevManagedCopy = null, arra return $managedCopy; } - private function ensureVersionMatch(ClassMetadata $class, $entity, $managedCopy) { + private function ensureVersionMatch(ClassMetadata $class, $entity, $managedCopy) + { if ($class->isVersioned && $this->isLoaded($managedCopy) && $this->isLoaded($entity)) { $reflField = $class->reflFields[$class->versionField]; $managedCopyVersion = $reflField->getValue($managedCopy); From 81d44d4d6e1de53976fce8508245975b55d5c5c2 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 18 Dec 2016 14:32:31 +0100 Subject: [PATCH 184/877] #6174 #5570 documenting thrown exception types --- lib/Doctrine/ORM/UnitOfWork.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 56a7ff7b8e0..55a53c3cd37 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1784,7 +1784,7 @@ public function merge($entity) * @throws OptimisticLockException If the entity uses optimistic locking through a version * attribute and the version check against the managed copy fails. * @throws ORMInvalidArgumentException If the entity instance is NEW. - * @throws EntityNotFoundException + * @throws EntityNotFoundException if an assigned identifier is used in the entity, but none is provided */ private function doMerge($entity, array &$visited, $prevManagedCopy = null, array $assoc = []) { @@ -1876,6 +1876,15 @@ private function doMerge($entity, array &$visited, $prevManagedCopy = null, arra return $managedCopy; } + /** + * @param ClassMetadata $class + * @param object $entity + * @param object $managedCopy + * + * @return void + * + * @throws OptimisticLockException + */ private function ensureVersionMatch(ClassMetadata $class, $entity, $managedCopy) { if ($class->isVersioned && $this->isLoaded($managedCopy) && $this->isLoaded($entity)) { From 3ce262a61a329187d8d939f9fddbe0e6020b0fb7 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 18 Dec 2016 14:36:39 +0100 Subject: [PATCH 185/877] #6174 #5570 flattened nested conditionals --- lib/Doctrine/ORM/UnitOfWork.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 55a53c3cd37..485f29d0130 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1887,16 +1887,20 @@ private function doMerge($entity, array &$visited, $prevManagedCopy = null, arra */ private function ensureVersionMatch(ClassMetadata $class, $entity, $managedCopy) { - if ($class->isVersioned && $this->isLoaded($managedCopy) && $this->isLoaded($entity)) { - $reflField = $class->reflFields[$class->versionField]; - $managedCopyVersion = $reflField->getValue($managedCopy); - $entityVersion = $reflField->getValue($entity); - - // Throw exception if versions don't match. - if ($managedCopyVersion != $entityVersion) { - throw OptimisticLockException::lockFailedVersionMismatch($entity, $entityVersion, $managedCopyVersion); - } + if (! ($class->isVersioned && $this->isLoaded($managedCopy) && $this->isLoaded($entity))) { + return; } + + $reflField = $class->reflFields[$class->versionField]; + $managedCopyVersion = $reflField->getValue($managedCopy); + $entityVersion = $reflField->getValue($entity); + + // Throw exception if versions don't match. + if ($managedCopyVersion == $entityVersion) { + return; + } + + throw OptimisticLockException::lockFailedVersionMismatch($entity, $entityVersion, $managedCopyVersion); } /** From 85e2dc8f227d9cc9adbc7013ef8bf8006e252a96 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 18 Dec 2016 14:38:10 +0100 Subject: [PATCH 186/877] #6174 #5570 CS - spacing --- lib/Doctrine/ORM/UnitOfWork.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 485f29d0130..a406c906aeb 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -3352,11 +3352,11 @@ private function isIdentifierEquals($entity1, $entity2) */ private function mergeEntityStateIntoManagedCopy($entity, $managedCopy) { - if (!$this->isLoaded($entity)) { + if (! $this->isLoaded($entity)) { return; } - if (!$this->isLoaded($managedCopy)) { + if (! $this->isLoaded($managedCopy)) { $managedCopy->__load(); } From ab0e854830f1dcff64e9b8e0160727040519a57e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 18 Dec 2016 14:39:46 +0100 Subject: [PATCH 187/877] #6174 #5570 CS - spacing --- lib/Doctrine/ORM/UnitOfWork.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index a406c906aeb..101d28fb8e6 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1850,7 +1850,7 @@ private function doMerge($entity, array &$visited, $prevManagedCopy = null, arra $this->mergeEntityStateIntoManagedCopy($entity, $managedCopy); $this->persistNew($class, $managedCopy); - }else{ + } else { $this->ensureVersionMatch($class, $entity, $managedCopy); $this->mergeEntityStateIntoManagedCopy($entity, $managedCopy); } From a22f1650268051d763bc847f6ad0f4b328085839 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 18 Dec 2016 14:45:08 +0100 Subject: [PATCH 188/877] #6174 #5570 removed unused/dead code --- lib/Doctrine/ORM/UnitOfWork.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 101d28fb8e6..c0b0dd8c302 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1857,7 +1857,6 @@ private function doMerge($entity, array &$visited, $prevManagedCopy = null, arra } $visited[$oid] = $managedCopy; // mark visited - // $this->mergeEntityStateIntoManagedCopy($entity, $managedCopy); if ($class->isChangeTrackingDeferredExplicit()) { $this->scheduleForDirtyCheck($entity); From 0c2edcd08aa5890cdfa3f9f28d65c5bbddc17734 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 18 Dec 2016 14:47:16 +0100 Subject: [PATCH 189/877] #6174 #5570 CS - spacing/variable naming --- .../Tests/Models/Company/CompanyContractListener.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/Doctrine/Tests/Models/Company/CompanyContractListener.php b/tests/Doctrine/Tests/Models/Company/CompanyContractListener.php index c5862887835..ad4133d5064 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyContractListener.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyContractListener.php @@ -89,17 +89,19 @@ public function postLoadHandler(CompanyContract $contract) public function takeSnapshot(CompanyContract $contract) { $snapshot = []; - $reflexion = new \ReflectionClass($contract); - foreach ($reflexion->getProperties() as $property) { + + foreach ((new \ReflectionClass($contract))->getProperties() as $property) { $property->setAccessible(true); + $value = $property->getValue($contract); + if (is_object($value) || is_array($value)) { continue; } + $snapshot[$property->getName()] = $property->getValue($contract); } return $snapshot; } - } From 00c67ba2db5d2ef9e02e76b16aae80e81ef1f5cb Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 18 Dec 2016 14:47:55 +0100 Subject: [PATCH 190/877] #6174 #5570 adding group annotation to newly introduced tests --- .../Tests/ORM/Functional/EntityListenersOnMergeTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityListenersOnMergeTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityListenersOnMergeTest.php index 6123fe99770..e6f3d5fe843 100644 --- a/tests/Doctrine/Tests/ORM/Functional/EntityListenersOnMergeTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/EntityListenersOnMergeTest.php @@ -10,6 +10,8 @@ /** * @group DDC-1955 + * @group 5570 + * @group 6174 */ class EntityListenersOnMergeTest extends \Doctrine\Tests\OrmFunctionalTestCase { From 9582ffc982f8cae74462bb089758faef0e9789d6 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 18 Dec 2016 14:53:54 +0100 Subject: [PATCH 191/877] #6174 #5570 CS fixes around the `EntityListenersOnMergeTest` --- .../Functional/EntityListenersOnMergeTest.php | 49 ++++++++----------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityListenersOnMergeTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityListenersOnMergeTest.php index e6f3d5fe843..6c38d932683 100644 --- a/tests/Doctrine/Tests/ORM/Functional/EntityListenersOnMergeTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/EntityListenersOnMergeTest.php @@ -2,22 +2,23 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\ORM\Event\LifecycleEventArgs; use Doctrine\Tests\Models\Company\CompanyContractListener; use Doctrine\Tests\Models\Company\CompanyFixContract; use Doctrine\Tests\Models\DDC3597\DDC3597Image; use Doctrine\Tests\Models\DDC3597\DDC3597Media; use Doctrine\Tests\Models\DDC3597\DDC3597Root; +use Doctrine\Tests\OrmFunctionalTestCase; /** * @group DDC-1955 * @group 5570 * @group 6174 */ -class EntityListenersOnMergeTest extends \Doctrine\Tests\OrmFunctionalTestCase +class EntityListenersOnMergeTest extends OrmFunctionalTestCase { - /** - * @var \Doctrine\Tests\Models\Company\CompanyContractListener + * @var CompanyContractListener */ private $listener; @@ -26,34 +27,32 @@ protected function setUp() $this->useModelSet('company'); parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC3597Root::class), - $this->_em->getClassMetadata(DDC3597Media::class), - $this->_em->getClassMetadata(DDC3597Image::class), - ] - ); + $this->_schemaTool->createSchema([ + $this->_em->getClassMetadata(DDC3597Root::class), + $this->_em->getClassMetadata(DDC3597Media::class), + $this->_em->getClassMetadata(DDC3597Image::class), + ]); $this->listener = $this->_em->getConfiguration() ->getEntityListenerResolver() - ->resolve('Doctrine\Tests\Models\Company\CompanyContractListener'); + ->resolve(CompanyContractListener::class); } protected function tearDown() { parent::tearDown(); - $this->_schemaTool->dropSchema( - [ - $this->_em->getClassMetadata(DDC3597Root::class), - $this->_em->getClassMetadata(DDC3597Media::class), - $this->_em->getClassMetadata(DDC3597Image::class), - ] - ); + + $this->_schemaTool->dropSchema([ + $this->_em->getClassMetadata(DDC3597Root::class), + $this->_em->getClassMetadata(DDC3597Media::class), + $this->_em->getClassMetadata(DDC3597Image::class), + ]); } public function testMergeNewEntityLifecyleEventsModificationsShouldBeKept() { $imageEntity = new DDC3597Image('foobar'); + $imageEntity->setFormat('JPG'); $imageEntity->setSize(123); $imageEntity->getDimension()->setWidth(300); @@ -68,6 +67,7 @@ public function testMergeNewEntityLifecyleEventsModificationsShouldBeKept() public function testPrePersistListenersShouldBeFiredWithCorrectEntityData() { $fix = new CompanyFixContract(); + $fix->setFixPrice(2000); $this->listener->prePersistCalls = []; @@ -79,15 +79,8 @@ public function testPrePersistListenersShouldBeFiredWithCorrectEntityData() $this->assertSame($fix, $this->listener->prePersistCalls[0][0]); - $this->assertInstanceOf( - 'Doctrine\Tests\Models\Company\CompanyFixContract', - $this->listener->prePersistCalls[0][0] - ); - - $this->assertInstanceOf( - 'Doctrine\ORM\Event\LifecycleEventArgs', - $this->listener->prePersistCalls[0][1] - ); + $this->assertInstanceOf(CompanyFixContract::class, $this->listener->prePersistCalls[0][0]); + $this->assertInstanceOf(LifecycleEventArgs::class, $this->listener->prePersistCalls[0][1]); $this->assertArrayHasKey('fixPrice', $this->listener->snapshots[CompanyContractListener::PRE_PERSIST][0]); $this->assertEquals( @@ -95,4 +88,4 @@ public function testPrePersistListenersShouldBeFiredWithCorrectEntityData() $this->listener->snapshots[CompanyContractListener::PRE_PERSIST][0]['fixPrice'] ); } -} \ No newline at end of file +} From 30cd2d172bb4a56251312de2bbf4970b1e241d32 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 18 Dec 2016 15:37:49 +0100 Subject: [PATCH 192/877] #6174 #5570 started moving tests around `prePersist` event subscriber triggering on `UnitOfWork` into the `UnitOfWorkTest` --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 77 +++++++++++++++++++-- 1 file changed, 72 insertions(+), 5 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 72382549ebc..b91e74e9f97 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -3,8 +3,12 @@ namespace Doctrine\Tests\ORM; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\EventManager; +use Doctrine\Common\EventSubscriber; use Doctrine\Common\NotifyPropertyChanged; +use Doctrine\Common\Persistence\Event\LifecycleEventArgs; use Doctrine\Common\PropertyChangedListener; +use Doctrine\ORM\Events; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\ORMInvalidArgumentException; use Doctrine\ORM\UnitOfWork; @@ -48,18 +52,22 @@ class UnitOfWorkTest extends OrmTestCase */ private $_emMock; - protected function setUp() { + /** + * @var EventManager|\PHPUnit_Framework_MockObject_MockObject + */ + private $eventManager; + + protected function setUp() + { parent::setUp(); $this->_connectionMock = new ConnectionMock([], new DriverMock()); - $this->_emMock = EntityManagerMock::create($this->_connectionMock); + $this->eventManager = $this->getMockBuilder(EventManager::class)->getMock(); + $this->_emMock = EntityManagerMock::create($this->_connectionMock, null, $this->eventManager); // SUT $this->_unitOfWork = new UnitOfWorkMock($this->_emMock); $this->_emMock->setUnitOfWork($this->_unitOfWork); } - protected function tearDown() { - } - public function testRegisterRemovedOnNewEntityIsIgnored() { $user = new ForumUser(); @@ -488,6 +496,45 @@ public function testObjectHashesOfMergedEntitiesAreNotUsedInOriginalEntityDataMa self::assertSame([], $this->_unitOfWork->getOriginalEntityData($newUser), 'No original data was stored'); } + + public function testMergeWithNewEntityWillPersistItAndTriggerPrePersistListenersWithMergedEntityData() + { + $entity = new EntityWithListenerPopulatedField(); + + $generatedFieldValue = $entity->generatedField; + + $this + ->eventManager + ->expects(self::any()) + ->method('hasListeners') + ->willReturnCallback(function ($eventName) { + return $eventName === Events::prePersist; + }); + $this + ->eventManager + ->expects(self::once()) + ->method('dispatchEvent') + ->with( + self::anything(), + self::callback(function (LifecycleEventArgs $args) use ($entity, $generatedFieldValue) { + /* @var $object EntityWithListenerPopulatedField */ + $object = $args->getObject(); + + self::assertInstanceOf(EntityWithListenerPopulatedField::class, $object); + self::assertNotSame($entity, $object); + self::assertSame($generatedFieldValue, $object->generatedField); + + return true; + }) + ); + + /* @var $object EntityWithListenerPopulatedField */ + $object = $this->_unitOfWork->merge($entity); + + self::assertNotSame($object, $entity); + self::assertInstanceOf(EntityWithListenerPopulatedField::class, $object); + self::assertSame($object->generatedField, $entity->generatedField); + } } /** @@ -634,3 +681,23 @@ class EntityWithCompositeStringIdentifier */ public $id2; } + +/** @Entity */ +class EntityWithListenerPopulatedField +{ + const MAX_GENERATED_FIELD_VALUE = 10000; + + /** @Id @Column(type="string") */ + public $id; + + /** + * @Column(type="integer") + */ + public $generatedField; + + public function __construct() + { + $this->id = uniqid('id', true); + $this->generatedField = mt_rand(0, self::MAX_GENERATED_FIELD_VALUE); + } +} From f4595d3a2f35d9e189d976a16cac5067227b829f Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 18 Dec 2016 15:43:29 +0100 Subject: [PATCH 193/877] #6174 #5570 `prePersist` listeners should never be called when entities are merged, but are already in the UoW --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index b91e74e9f97..4feaa88a2b4 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -535,6 +535,39 @@ public function testMergeWithNewEntityWillPersistItAndTriggerPrePersistListeners self::assertInstanceOf(EntityWithListenerPopulatedField::class, $object); self::assertSame($object->generatedField, $entity->generatedField); } + + public function testMergeWithExistingEntityWillNotPersistItNorTriggerPrePersistListeners() + { + $persistedEntity = new EntityWithListenerPopulatedField(); + $mergedEntity = new EntityWithListenerPopulatedField(); + + $mergedEntity->id = $persistedEntity->id; + $mergedEntity->generatedField = mt_rand( + $persistedEntity->generatedField + 1, + $persistedEntity->generatedField + 1000 + ); + + $this + ->eventManager + ->expects(self::any()) + ->method('hasListeners') + ->willReturnCallback(function ($eventName) { + return $eventName === Events::prePersist; + }); + $this->eventManager->expects(self::never())->method('dispatchEvent'); + + $this->_unitOfWork->registerManaged( + $persistedEntity, + ['id' => $persistedEntity->id], + ['generatedField' => $persistedEntity->generatedField] + ); + + /* @var $merged EntityWithListenerPopulatedField */ + $merged = $this->_unitOfWork->merge($mergedEntity); + + self::assertSame($merged, $persistedEntity); + self::assertSame($persistedEntity->generatedField, $mergedEntity->generatedField); + } } /** From 262d13a0476cb9354071dda5af193a1d5eecd4ce Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 18 Dec 2016 15:44:48 +0100 Subject: [PATCH 194/877] #6174 #5570 adding group annotations to newly introduced test --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 4feaa88a2b4..57c842fd721 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -497,6 +497,11 @@ public function testObjectHashesOfMergedEntitiesAreNotUsedInOriginalEntityDataMa self::assertSame([], $this->_unitOfWork->getOriginalEntityData($newUser), 'No original data was stored'); } + /** + * @group DDC-1955 + * @group 5570 + * @group 6174 + */ public function testMergeWithNewEntityWillPersistItAndTriggerPrePersistListenersWithMergedEntityData() { $entity = new EntityWithListenerPopulatedField(); @@ -536,6 +541,11 @@ public function testMergeWithNewEntityWillPersistItAndTriggerPrePersistListeners self::assertSame($object->generatedField, $entity->generatedField); } + /** + * @group DDC-1955 + * @group 5570 + * @group 6174 + */ public function testMergeWithExistingEntityWillNotPersistItNorTriggerPrePersistListeners() { $persistedEntity = new EntityWithListenerPopulatedField(); From f39f1a2e11edcf1e90e8c2192f62f7d560be7864 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 18 Dec 2016 15:45:03 +0100 Subject: [PATCH 195/877] #6174 #5570 removed unused test class --- .../Functional/EntityListenersOnMergeTest.php | 91 ------------------- 1 file changed, 91 deletions(-) delete mode 100644 tests/Doctrine/Tests/ORM/Functional/EntityListenersOnMergeTest.php diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityListenersOnMergeTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityListenersOnMergeTest.php deleted file mode 100644 index 6c38d932683..00000000000 --- a/tests/Doctrine/Tests/ORM/Functional/EntityListenersOnMergeTest.php +++ /dev/null @@ -1,91 +0,0 @@ -useModelSet('company'); - parent::setUp(); - - $this->_schemaTool->createSchema([ - $this->_em->getClassMetadata(DDC3597Root::class), - $this->_em->getClassMetadata(DDC3597Media::class), - $this->_em->getClassMetadata(DDC3597Image::class), - ]); - - $this->listener = $this->_em->getConfiguration() - ->getEntityListenerResolver() - ->resolve(CompanyContractListener::class); - } - - protected function tearDown() - { - parent::tearDown(); - - $this->_schemaTool->dropSchema([ - $this->_em->getClassMetadata(DDC3597Root::class), - $this->_em->getClassMetadata(DDC3597Media::class), - $this->_em->getClassMetadata(DDC3597Image::class), - ]); - } - - public function testMergeNewEntityLifecyleEventsModificationsShouldBeKept() - { - $imageEntity = new DDC3597Image('foobar'); - - $imageEntity->setFormat('JPG'); - $imageEntity->setSize(123); - $imageEntity->getDimension()->setWidth(300); - $imageEntity->getDimension()->setHeight(500); - - $imageEntity = $this->_em->merge($imageEntity); - - $this->assertNotNull($imageEntity->getCreatedAt()); - $this->assertNotNull($imageEntity->getUpdatedAt()); - } - - public function testPrePersistListenersShouldBeFiredWithCorrectEntityData() - { - $fix = new CompanyFixContract(); - - $fix->setFixPrice(2000); - - $this->listener->prePersistCalls = []; - - $fix = $this->_em->merge($fix); - $this->_em->flush(); - - $this->assertCount(1, $this->listener->prePersistCalls); - - $this->assertSame($fix, $this->listener->prePersistCalls[0][0]); - - $this->assertInstanceOf(CompanyFixContract::class, $this->listener->prePersistCalls[0][0]); - $this->assertInstanceOf(LifecycleEventArgs::class, $this->listener->prePersistCalls[0][1]); - - $this->assertArrayHasKey('fixPrice', $this->listener->snapshots[CompanyContractListener::PRE_PERSIST][0]); - $this->assertEquals( - $fix->getFixPrice(), - $this->listener->snapshots[CompanyContractListener::PRE_PERSIST][0]['fixPrice'] - ); - } -} From 018a5db08f2eb37dfcc07c770213d72d5bc0de46 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 18 Dec 2016 15:46:34 +0100 Subject: [PATCH 196/877] #6174 #5570 renamed entity for better fitting the use-cases it's in --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 22 ++++++++++----------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 57c842fd721..238f4ce45b0 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -504,7 +504,7 @@ public function testObjectHashesOfMergedEntitiesAreNotUsedInOriginalEntityDataMa */ public function testMergeWithNewEntityWillPersistItAndTriggerPrePersistListenersWithMergedEntityData() { - $entity = new EntityWithListenerPopulatedField(); + $entity = new EntityWithRandomlyGeneratedField(); $generatedFieldValue = $entity->generatedField; @@ -522,10 +522,10 @@ public function testMergeWithNewEntityWillPersistItAndTriggerPrePersistListeners ->with( self::anything(), self::callback(function (LifecycleEventArgs $args) use ($entity, $generatedFieldValue) { - /* @var $object EntityWithListenerPopulatedField */ + /* @var $object EntityWithRandomlyGeneratedField */ $object = $args->getObject(); - self::assertInstanceOf(EntityWithListenerPopulatedField::class, $object); + self::assertInstanceOf(EntityWithRandomlyGeneratedField::class, $object); self::assertNotSame($entity, $object); self::assertSame($generatedFieldValue, $object->generatedField); @@ -533,11 +533,11 @@ public function testMergeWithNewEntityWillPersistItAndTriggerPrePersistListeners }) ); - /* @var $object EntityWithListenerPopulatedField */ + /* @var $object EntityWithRandomlyGeneratedField */ $object = $this->_unitOfWork->merge($entity); self::assertNotSame($object, $entity); - self::assertInstanceOf(EntityWithListenerPopulatedField::class, $object); + self::assertInstanceOf(EntityWithRandomlyGeneratedField::class, $object); self::assertSame($object->generatedField, $entity->generatedField); } @@ -548,8 +548,8 @@ public function testMergeWithNewEntityWillPersistItAndTriggerPrePersistListeners */ public function testMergeWithExistingEntityWillNotPersistItNorTriggerPrePersistListeners() { - $persistedEntity = new EntityWithListenerPopulatedField(); - $mergedEntity = new EntityWithListenerPopulatedField(); + $persistedEntity = new EntityWithRandomlyGeneratedField(); + $mergedEntity = new EntityWithRandomlyGeneratedField(); $mergedEntity->id = $persistedEntity->id; $mergedEntity->generatedField = mt_rand( @@ -572,7 +572,7 @@ public function testMergeWithExistingEntityWillNotPersistItNorTriggerPrePersistL ['generatedField' => $persistedEntity->generatedField] ); - /* @var $merged EntityWithListenerPopulatedField */ + /* @var $merged EntityWithRandomlyGeneratedField */ $merged = $this->_unitOfWork->merge($mergedEntity); self::assertSame($merged, $persistedEntity); @@ -726,10 +726,8 @@ class EntityWithCompositeStringIdentifier } /** @Entity */ -class EntityWithListenerPopulatedField +class EntityWithRandomlyGeneratedField { - const MAX_GENERATED_FIELD_VALUE = 10000; - /** @Id @Column(type="string") */ public $id; @@ -741,6 +739,6 @@ class EntityWithListenerPopulatedField public function __construct() { $this->id = uniqid('id', true); - $this->generatedField = mt_rand(0, self::MAX_GENERATED_FIELD_VALUE); + $this->generatedField = mt_rand(0, 100000); } } From cfd595b699dde4ebe7ca4b15ed1a16b568bf5f75 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 18 Dec 2016 15:46:49 +0100 Subject: [PATCH 197/877] #6174 #5570 removed unused imports --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 238f4ce45b0..90c621d605a 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -4,7 +4,6 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\EventManager; -use Doctrine\Common\EventSubscriber; use Doctrine\Common\NotifyPropertyChanged; use Doctrine\Common\Persistence\Event\LifecycleEventArgs; use Doctrine\Common\PropertyChangedListener; From 21a5d8ca1b59096fce2afe3ccd2a11fa2165fca2 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 18 Dec 2016 15:48:10 +0100 Subject: [PATCH 198/877] #6174 #5570 removed modifications applied to the `CompanyContractListener`, since `UnitOfWorkTest` now completely encapsulates the scenarios being covered --- .../Company/CompanyContractListener.php | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/tests/Doctrine/Tests/Models/Company/CompanyContractListener.php b/tests/Doctrine/Tests/Models/Company/CompanyContractListener.php index ad4133d5064..23714f32983 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyContractListener.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyContractListener.php @@ -4,8 +4,6 @@ class CompanyContractListener { - const PRE_PERSIST = 0; - public $postPersistCalls; public $prePersistCalls; @@ -19,8 +17,6 @@ class CompanyContractListener public $postLoadCalls; - public $snapshots = []; - /** * @PostPersist */ @@ -34,7 +30,6 @@ public function postPersistHandler(CompanyContract $contract) */ public function prePersistHandler(CompanyContract $contract) { - $this->snapshots[self::PRE_PERSIST][] = $this->takeSnapshot($contract); $this->prePersistCalls[] = func_get_args(); } @@ -85,23 +80,4 @@ public function postLoadHandler(CompanyContract $contract) { $this->postLoadCalls[] = func_get_args(); } - - public function takeSnapshot(CompanyContract $contract) - { - $snapshot = []; - - foreach ((new \ReflectionClass($contract))->getProperties() as $property) { - $property->setAccessible(true); - - $value = $property->getValue($contract); - - if (is_object($value) || is_array($value)) { - continue; - } - - $snapshot[$property->getName()] = $property->getValue($contract); - } - - return $snapshot; - } } From 1a8eeacfba8cb2d1a1ce9b24f91398b525089c55 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Sun, 18 Dec 2016 21:42:08 +0100 Subject: [PATCH 199/877] Update working-with-associations.rst --- docs/en/reference/working-with-associations.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/working-with-associations.rst b/docs/en/reference/working-with-associations.rst index 7e088f94468..0768c3edee0 100644 --- a/docs/en/reference/working-with-associations.rst +++ b/docs/en/reference/working-with-associations.rst @@ -453,7 +453,7 @@ following code: $user->addComment($myFirstComment); $em->persist($user); - $em->persist($myFirstComment); // mandatory if `cascade: persist` isn't set + $em->persist($myFirstComment); // required, if `cascade: persist` isn't set $em->flush(); Even if you *persist* a new User that contains our new Comment this From a8a3a8c9e7796e8984ff76e31a7f48adb5357a63 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Sun, 18 Dec 2016 21:58:44 +0100 Subject: [PATCH 200/877] Update working-with-associations.rst --- docs/en/reference/working-with-associations.rst | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/en/reference/working-with-associations.rst b/docs/en/reference/working-with-associations.rst index 0768c3edee0..106da34ec22 100644 --- a/docs/en/reference/working-with-associations.rst +++ b/docs/en/reference/working-with-associations.rst @@ -513,8 +513,14 @@ association, you can now create a user and persist his comment as follows: $em->persist($user); $em->flush(); -Even though automatic cascading is convenient it should be used -with care. Do not blindly apply cascade=all to all associations as +.. note:: + + This code does not associate the newly created comment with the user. + To achieve this, you *always* have to call ``$myFirstComment->setUser($user);`` – + no matter if ``cascade: persist`` is set or not. + +Even though automatic cascading is convenient, it should be used +with care. Do not blindly apply ``cascade=all`` to all associations as it will unnecessarily degrade the performance of your application. For each cascade operation that gets activated Doctrine also applies that operation to the association, be it single or From eecf4382b03d720b56a6a9bc4cce799c190cde40 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Sun, 18 Dec 2016 23:05:10 +0100 Subject: [PATCH 201/877] Update working-with-associations.rst --- docs/en/reference/working-with-associations.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/en/reference/working-with-associations.rst b/docs/en/reference/working-with-associations.rst index 106da34ec22..21f1fa35681 100644 --- a/docs/en/reference/working-with-associations.rst +++ b/docs/en/reference/working-with-associations.rst @@ -442,7 +442,7 @@ The following cascade options exist: The following example is an extension to the User-Comment example of this chapter. Suppose in our application a user is created -whenever he writes his first comment. In this case we would use the +whenever they write their first comment. In this case we would use the following code: .. code-block:: php @@ -462,7 +462,7 @@ code requires an explicit call to cascade the persist operation to all nested entities that are new as well. -More complicated is the deletion of all of a user's comments when he is +More complicated is the deletion of all user's comments when the user is removed from the system: .. code-block:: php @@ -501,7 +501,7 @@ and the "remove" operation. } Since ``cascade: persist`` is configured for the ``User#commentsAuthored`` -association, you can now create a user and persist his comment as follows: +association, you can now create a user and persist their comments as follows: .. code-block:: php From f64d543d0c3b9f9ea486c26c1976820b6f7b2c14 Mon Sep 17 00:00:00 2001 From: Burhan Ali Date: Mon, 19 Dec 2016 03:34:51 +0000 Subject: [PATCH 202/877] Add minor fixes to the 'getting started' page --- docs/en/tutorials/getting-started.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/en/tutorials/getting-started.rst b/docs/en/tutorials/getting-started.rst index 05492b13308..c8247e21c45 100644 --- a/docs/en/tutorials/getting-started.rst +++ b/docs/en/tutorials/getting-started.rst @@ -717,8 +717,8 @@ the bi-directional reference: { // ... (previous code) - private $reportedBugs = null; - private $assignedBugs = null; + protected $reportedBugs = null; + protected $assignedBugs = null; public function addReportedBug($bug) { @@ -969,7 +969,7 @@ The last missing definition is that of the User entity: .. code-block:: yaml - # config/xml/User.dcm.yml + # config/yaml/User.dcm.yml User: type: entity table: users @@ -1008,7 +1008,7 @@ Update your database running: Implementing more Requirements ------------------------------ -For starters we need a create user entities: +For starters we need to create user entities: .. code-block:: php @@ -1084,7 +1084,7 @@ database. See how simple relating Bug, Reporter, Engineer and Products is done by using the discussed methods in the "A first prototype" -section. The UnitOfWork will detect this relations when flush is +section. The UnitOfWork will detect this relationship when flush is called and relate them in the database appropriately. Queries for Application Use-Cases @@ -1150,7 +1150,7 @@ The console output of this script is then: An important reason why DQL is favourable to the Query API of most ORMs is its similarity to SQL. The DQL language allows query - constructs that most ORMs don't, GROUP BY even with HAVING, + constructs that most ORMs don't: GROUP BY even with HAVING, Sub-selects, Fetch-Joins of nested classes, mixed results with entities and scalar data such as COUNT() results and much more. Using DQL you should seldom come to the point where you want to From f3909ae88527aa254970b63f30f68272c1e1cbdb Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Fri, 23 Dec 2016 20:09:25 +0100 Subject: [PATCH 203/877] Update working-with-associations.rst --- .../reference/working-with-associations.rst | 24 ++++--------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/docs/en/reference/working-with-associations.rst b/docs/en/reference/working-with-associations.rst index 21f1fa35681..d1d7b4265d3 100644 --- a/docs/en/reference/working-with-associations.rst +++ b/docs/en/reference/working-with-associations.rst @@ -405,25 +405,11 @@ There are two approaches to handle this problem in your code: Transitive persistence / Cascade Operations ------------------------------------------- -Persisting, removing, detaching, refreshing and merging individual entities can -become pretty cumbersome, especially when a highly interweaved object graph -is involved. Therefore Doctrine 2 provides a -mechanism for transitive persistence through cascading of these -operations. Each association to another entity or a collection of -entities can be configured to automatically cascade certain -operations. By default, no operations are cascaded. - -The following cascade options exist: - - -- persist : Cascades persist operations to the associated - entities. -- remove : Cascades remove operations to the associated entities. -- merge : Cascades merge operations to the associated entities. -- detach : Cascades detach operations to the associated entities. -- refresh : Cascades refresh operations to the associated entities. -- all : Cascades persist, remove, merge, refresh and detach operations to - associated entities. +When working with many associated entities, you sometimes don't want to "expose" all entities to your PHP application. +Therefore Doctrine 2 provides a mechanism for transitive persistence through cascading of certain operations. +Each association to another entity or a collection of +entities can be configured to automatically cascade the following operations to the associated entities: +``persist``, ``remove``, ``merge``, ``detach``, ``refresh`` or ``all``. .. note:: From 3ce833fb62522f1f84d48cf8e6511a8fb3af1b6c Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Mon, 26 Dec 2016 02:06:46 +0100 Subject: [PATCH 204/877] getSingleScalarResult() returns NULL when the query yields no results `NoResultException` is not thrown in this case. --- lib/Doctrine/ORM/AbstractQuery.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 8d901d51477..8a73ee8ba49 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -796,7 +796,7 @@ public function getOneOrNullResult($hydrationMode = null) * @return mixed * * @throws NonUniqueResultException If the query result is not unique. - * @throws NoResultException If the query returned no result. + * @throws NoResultException If the query returned no result and hydration mode is not HYDRATE_SINGLE_SCALAR. */ public function getSingleResult($hydrationMode = null) { @@ -822,10 +822,9 @@ public function getSingleResult($hydrationMode = null) * * Alias for getSingleResult(HYDRATE_SINGLE_SCALAR). * - * @return mixed + * @return mixed The scalar result, or NULL if the query returned no result. * * @throws NonUniqueResultException If the query result is not unique. - * @throws NoResultException If the query returned no result. */ public function getSingleScalarResult() { From a8d7b327efdd6e0d0fad1ada6e8e221df6b3711f Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Mon, 2 Jan 2017 09:27:34 +0100 Subject: [PATCH 205/877] rip 5.6 --- .travis.yml | 5 ----- composer.json | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4c3b1c6239a..714f8e2bb54 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ sudo: false language: php php: - - 5.6 - 7.0 - 7.1 - nightly @@ -29,10 +28,6 @@ after_script: matrix: fast_finish: true include: - - php: 5.6 - env: DB=mariadb - addons: - mariadb: 10.1 - php: 7.0 env: DB=mariadb addons: diff --git a/composer.json b/composer.json index a787c1752da..b1576b11a2b 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ ], "minimum-stability": "dev", "require": { - "php": "^5.6 || ^7.0", + "php": "^7.0", "ext-pdo": "*", "doctrine/collections": "~1.2", "doctrine/dbal": ">=2.5-dev,<2.7-dev", From 563c79bd802890451c1adfb9053b1b204e8518bf Mon Sep 17 00:00:00 2001 From: Mark Railton Date: Mon, 2 Jan 2017 08:36:42 +0000 Subject: [PATCH 206/877] Removes support for PHP 5.x --- .travis.yml | 5 ----- README.md | 2 +- composer.json | 2 +- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4c3b1c6239a..714f8e2bb54 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ sudo: false language: php php: - - 5.6 - 7.0 - 7.1 - nightly @@ -29,10 +28,6 @@ after_script: matrix: fast_finish: true include: - - php: 5.6 - env: DB=mariadb - addons: - mariadb: 10.1 - php: 7.0 env: DB=mariadb addons: diff --git a/README.md b/README.md index dffd57ed1c0..754e8c018b3 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ | [![Build status][Master image]][Master] | [![Build status][2.5 image]][2.5] | | [![Coverage Status][Master coverage image]][Master coverage] | [![Coverage Status][2.5 coverage image]][2.5 coverage] | -Doctrine 2 is an object-relational mapper (ORM) for PHP 5.6+ that provides transparent persistence +Doctrine 2 is an object-relational mapper (ORM) for PHP 7.0+ that provides transparent persistence for PHP objects. It sits on top of a powerful database abstraction layer (DBAL). One of its key features is the option to write database queries in a proprietary object oriented SQL dialect called Doctrine Query Language (DQL), inspired by Hibernate's HQL. This provides developers with a powerful alternative to SQL that maintains flexibility diff --git a/composer.json b/composer.json index a787c1752da..b1576b11a2b 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ ], "minimum-stability": "dev", "require": { - "php": "^5.6 || ^7.0", + "php": "^7.0", "ext-pdo": "*", "doctrine/collections": "~1.2", "doctrine/dbal": ">=2.5-dev,<2.7-dev", From fc8ede844df7341f6ad94fced9dc181f3e445c0d Mon Sep 17 00:00:00 2001 From: gabidavila Date: Mon, 2 Jan 2017 16:11:46 -0200 Subject: [PATCH 207/877] Fixes missing namespaces on class call --- docs/en/reference/tools.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/reference/tools.rst b/docs/en/reference/tools.rst index b8d90302244..27c6bc00690 100644 --- a/docs/en/reference/tools.rst +++ b/docs/en/reference/tools.rst @@ -385,7 +385,7 @@ First you need to retrieve the metadata instances with the ) ); - $cmf = new DisconnectedClassMetadataFactory(); + $cmf = new \Doctrine\ORM\Tools\DisconnectedClassMetadataFactory(); $cmf->setEntityManager($em); $metadata = $cmf->getAllMetadata(); @@ -395,7 +395,7 @@ to yml: .. code-block:: php getExporter('yml', '/path/to/export/yml'); $exporter->setMetadata($metadata); $exporter->export(); From 8b499a479169e519a47f03911dc565faee9cc22e Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Tue, 3 Jan 2017 21:37:07 -0300 Subject: [PATCH 208/877] =?UTF-8?q?#1808=20=E2=80=94=20Fix=20wrong=20DQL?= =?UTF-8?q?=20example?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/reference/dql-doctrine-query-language.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/dql-doctrine-query-language.rst b/docs/en/reference/dql-doctrine-query-language.rst index 6f987441176..8950c8d4c1a 100644 --- a/docs/en/reference/dql-doctrine-query-language.rst +++ b/docs/en/reference/dql-doctrine-query-language.rst @@ -1004,7 +1004,7 @@ structure: .. code-block:: php - $dql = "SELECT u, 'some scalar string', count(u.groups) AS num FROM User u JOIN u.groups g GROUP BY u.id"; + $dql = "SELECT u, 'some scalar string', count(g.id) AS num FROM User u JOIN u.groups g GROUP BY u.id"; array [0] From a1839048dd5cdc4ef99485ea9317628ddeeb3dac Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Thu, 5 Jan 2017 11:48:16 -0300 Subject: [PATCH 209/877] =?UTF-8?q?#2190=20=E2=80=94=20added=20link=20to?= =?UTF-8?q?=20`Transitive=20Persistence`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/reference/working-with-objects.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/working-with-objects.rst b/docs/en/reference/working-with-objects.rst index 2b52fac412c..01a7692e7c1 100644 --- a/docs/en/reference/working-with-objects.rst +++ b/docs/en/reference/working-with-objects.rst @@ -238,7 +238,7 @@ as follows: persist operation. However, the persist operation is cascaded to entities referenced by X, if the relationships from X to these other entities are mapped with cascade=PERSIST or cascade=ALL (see - "Transitive Persistence"). + ":doc:`Transitive Persistence `"). - If X is a removed entity, it becomes managed. - If X is a detached entity, an exception will be thrown on flush. From f570eb5922af2feda9f5fa56a270c1c31d0784c5 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Thu, 5 Jan 2017 12:46:01 -0300 Subject: [PATCH 210/877] =?UTF-8?q?#2190=20=E2=80=94=20Refer=20link=20to?= =?UTF-8?q?=20proper=20section=20and=20links=20more=20occurrence=20from=20?= =?UTF-8?q?Transitive=20Persistence?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/reference/working-with-associations.rst | 2 ++ docs/en/reference/working-with-objects.rst | 13 ++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/docs/en/reference/working-with-associations.rst b/docs/en/reference/working-with-associations.rst index 85ffaee3a2f..fed47a9a422 100644 --- a/docs/en/reference/working-with-associations.rst +++ b/docs/en/reference/working-with-associations.rst @@ -402,6 +402,8 @@ There are two approaches to handle this problem in your code: association management methods. Reads of the Collections directly after changes are consistent then. +.. _transitive-persistence: + Transitive persistence / Cascade Operations ------------------------------------------- diff --git a/docs/en/reference/working-with-objects.rst b/docs/en/reference/working-with-objects.rst index 01a7692e7c1..32f1a3ee980 100644 --- a/docs/en/reference/working-with-objects.rst +++ b/docs/en/reference/working-with-objects.rst @@ -238,7 +238,7 @@ as follows: persist operation. However, the persist operation is cascaded to entities referenced by X, if the relationships from X to these other entities are mapped with cascade=PERSIST or cascade=ALL (see - ":doc:`Transitive Persistence `"). + ":ref:`Transitive Persistence `"). - If X is a removed entity, it becomes managed. - If X is a detached entity, an exception will be thrown on flush. @@ -279,12 +279,12 @@ as follows: - If X is a new entity, it is ignored by the remove operation. However, the remove operation is cascaded to entities referenced by X, if the relationship from X to these other entities is mapped - with cascade=REMOVE or cascade=ALL (see "Transitive Persistence"). + with cascade=REMOVE or cascade=ALL (see ":ref:`Transitive Persistence `"). - If X is a managed entity, the remove operation causes it to become removed. The remove operation is cascaded to entities referenced by X, if the relationships from X to these other entities is mapped with cascade=REMOVE or cascade=ALL (see - "Transitive Persistence"). + ":ref:`Transitive Persistence `"). - If X is a detached entity, an InvalidArgumentException will be thrown. - If X is a removed entity, it is ignored by the remove operation. @@ -350,14 +350,14 @@ as follows: become detached. The detach operation is cascaded to entities referenced by X, if the relationships from X to these other entities is mapped with cascade=DETACH or cascade=ALL (see - "Transitive Persistence"). Entities which previously referenced X + ":ref:`Transitive Persistence `"). Entities which previously referenced X will continue to reference X. - If X is a new or detached entity, it is ignored by the detach operation. - If X is a removed entity, the detach operation is cascaded to entities referenced by X, if the relationships from X to these other entities is mapped with cascade=DETACH or cascade=ALL (see - "Transitive Persistence"). Entities which previously referenced X + ":ref:`Transitive Persistence `"). Entities which previously referenced X will continue to reference X. There are several situations in which an entity is detached @@ -416,8 +416,7 @@ as follows: - If X is a managed entity, it is ignored by the merge operation, however, the merge operation is cascaded to entities referenced by relationships from X if these relationships have been mapped with - the cascade element value MERGE or ALL (see "Transitive - Persistence"). + the cascade element value MERGE or ALL (see ":ref:`Transitive Persistence `"). - For all entities Y referenced by relationships from X having the cascade element value MERGE or ALL, Y is merged recursively as Y'. For all such Y referenced by X, X' is set to reference Y'. (Note From eaeecc38578164aff4c9db7766bd6ec8e7b81b12 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Thu, 5 Jan 2017 18:21:49 -0300 Subject: [PATCH 211/877] Remove unused arguments --- .../Persisters/Entity/AbstractEntityInheritancePersister.php | 3 +-- lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php | 2 -- lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php | 2 -- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/AbstractEntityInheritancePersister.php b/lib/Doctrine/ORM/Persisters/Entity/AbstractEntityInheritancePersister.php index aa2038ffcb8..6052c63e5b2 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/AbstractEntityInheritancePersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/AbstractEntityInheritancePersister.php @@ -82,12 +82,11 @@ protected function getSelectColumnSQL($field, ClassMetadata $class, $alias = 'r' /** * @param string $tableAlias * @param string $joinColumnName - * @param string $className * @param string $type * * @return string */ - protected function getSelectJoinColumnSQL($tableAlias, $joinColumnName, $className, $type) + protected function getSelectJoinColumnSQL($tableAlias, $joinColumnName, $type) { $columnAlias = $this->getSQLColumnAlias($joinColumnName); diff --git a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php index e3e7d2b4322..8fe679ad4b9 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php @@ -472,7 +472,6 @@ protected function getSelectColumnsSQL() $columnList[] = $this->getSelectJoinColumnSQL( $tableAlias, $srcColumn, - $className, PersisterHelper::getTypeOfColumn( $mapping['sourceToTargetKeyColumns'][$srcColumn], $targetClass, @@ -521,7 +520,6 @@ protected function getSelectColumnsSQL() $columnList[] = $this->getSelectJoinColumnSQL( $tableAlias, $srcColumn, - $className, PersisterHelper::getTypeOfColumn( $mapping['sourceToTargetKeyColumns'][$srcColumn], $targetClass, diff --git a/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php b/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php index d3eb5d8acde..ff1d29652c5 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php @@ -87,14 +87,12 @@ protected function getSelectColumnsSQL() continue; } - $className = isset($assoc['inherited']) ? $assoc['inherited'] : $this->class->name; $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); foreach ($assoc['targetToSourceKeyColumns'] as $srcColumn) { $columnList[] = $this->getSelectJoinColumnSQL( $tableAlias, $srcColumn, - $className, PersisterHelper::getTypeOfColumn( $assoc['sourceToTargetKeyColumns'][$srcColumn], $targetClass, From 7c168c20474b48eb724d019cba70dd0ee783c6bd Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Mon, 9 Jan 2017 14:07:17 +0100 Subject: [PATCH 212/877] Update working-with-associations.rst As requested: https://github.com/doctrine/doctrine2/pull/6171#pullrequestreview-15695400 --- docs/en/reference/working-with-associations.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/reference/working-with-associations.rst b/docs/en/reference/working-with-associations.rst index d1d7b4265d3..e3a14891385 100644 --- a/docs/en/reference/working-with-associations.rst +++ b/docs/en/reference/working-with-associations.rst @@ -495,6 +495,7 @@ association, you can now create a user and persist their comments as follows: $user = new User(); $myFirstComment = new Comment(); $user->addComment($myFirstComment); + $myFirstComment->setUser($user); $em->persist($user); $em->flush(); From 617ec9219e0dcc7f9edd8046af67f4f1774ee694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1chym=20Tou=C5=A1ek?= Date: Tue, 10 Jan 2017 09:12:18 +0100 Subject: [PATCH 213/877] Fix annotations --- lib/Doctrine/ORM/AbstractQuery.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 8a73ee8ba49..0430a113fda 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -106,7 +106,7 @@ abstract class AbstractQuery protected $_hydrationMode = self::HYDRATE_OBJECT; /** - * @param \Doctrine\DBAL\Cache\QueryCacheProfile + * @var \Doctrine\DBAL\Cache\QueryCacheProfile */ protected $_queryCacheProfile; @@ -118,7 +118,7 @@ abstract class AbstractQuery protected $_expireResultCache = false; /** - * @param \Doctrine\DBAL\Cache\QueryCacheProfile + * @var \Doctrine\DBAL\Cache\QueryCacheProfile */ protected $_hydrationCacheProfile; From 5a562b35712aaa85a31cf707aadfa673e67c433d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 11 Jan 2017 10:40:23 +0100 Subject: [PATCH 214/877] Appends cache namespace when it exists (for L2C regions) We're overriding the namespace without even checking if it was previously set, what causes problems when people uses that feature :wink: --- .../ORM/Cache/DefaultCacheFactory.php | 35 ++++++++++++++----- .../ORM/Cache/DefaultCacheFactoryTest.php | 24 +++++++++++++ 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php b/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php index 1510096324c..3bfccdf8456 100644 --- a/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php +++ b/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php @@ -200,14 +200,9 @@ public function getRegion(array $cache) return $this->regions[$cache['region']]; } - $cacheAdapter = clone $this->cache; - - if ($cacheAdapter instanceof CacheProvider) { - $cacheAdapter->setNamespace($cache['region']); - } - - $name = $cache['region']; - $lifetime = $this->regionsConfig->getLifetime($cache['region']); + $name = $cache['region']; + $cacheAdapter = $this->createRegionCache($name); + $lifetime = $this->regionsConfig->getLifetime($cache['region']); $region = ($cacheAdapter instanceof MultiGetCache) ? new DefaultMultiGetRegion($name, $cacheAdapter, $lifetime) @@ -229,6 +224,30 @@ public function getRegion(array $cache) return $this->regions[$cache['region']] = $region; } + /** + * @param string $name + * + * @return CacheAdapter + */ + private function createRegionCache($name) + { + $cacheAdapter = clone $this->cache; + + if (!$cacheAdapter instanceof CacheProvider) { + return $cacheAdapter; + } + + $namespace = $cacheAdapter->getNamespace(); + + if ('' !== $namespace) { + $namespace .= ':'; + } + + $cacheAdapter->setNamespace($namespace . $name); + + return $cacheAdapter; + } + /** * {@inheritdoc} */ diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php index 2047e05b379..90922caeddf 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php @@ -296,6 +296,30 @@ public function testBuildsNewNamespacedCacheInstancePerRegionInstance() $this->assertSame('bar', $barRegion->getCache()->getNamespace()); } + public function testAppendsNamespacedCacheInstancePerRegionInstanceWhenItsAlreadySet() + { + $cache = clone $this->getSharedSecondLevelCacheDriverImpl(); + $cache->setNamespace('testing'); + + $factory = new DefaultCacheFactory($this->regionsConfig, $cache); + + $fooRegion = $factory->getRegion( + [ + 'region' => 'foo', + 'usage' => ClassMetadata::CACHE_USAGE_READ_ONLY, + ] + ); + $barRegion = $factory->getRegion( + [ + 'region' => 'bar', + 'usage' => ClassMetadata::CACHE_USAGE_READ_ONLY, + ] + ); + + $this->assertSame('testing:foo', $fooRegion->getCache()->getNamespace()); + $this->assertSame('testing:bar', $barRegion->getCache()->getNamespace()); + } + public function testBuildsDefaultCacheRegionFromGenericCacheRegion() { /* @var $cache \Doctrine\Common\Cache\Cache */ From eaedc37d7b955daa60eee772e5a1815637931c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 11 Jan 2017 11:04:43 +0100 Subject: [PATCH 215/877] Fix alignment issues on DefaultCacheFactoryTest.php --- .../ORM/Cache/DefaultCacheFactoryTest.php | 102 +++++++++--------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php index 90922caeddf..1ca213b20e0 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php @@ -52,13 +52,13 @@ protected function setUp() $this->enableSecondLevelCache(); parent::setUp(); - $this->em = $this->_getTestEntityManager(); - $this->regionsConfig = new RegionsConfiguration; - $arguments = [$this->regionsConfig, $this->getSharedSecondLevelCacheDriverImpl()]; - $this->factory = $this->getMockBuilder(DefaultCacheFactory::class) - ->setMethods(['getRegion']) - ->setConstructorArgs($arguments) - ->getMock(); + $this->em = $this->_getTestEntityManager(); + $this->regionsConfig = new RegionsConfiguration; + $arguments = [$this->regionsConfig, $this->getSharedSecondLevelCacheDriverImpl()]; + $this->factory = $this->getMockBuilder(DefaultCacheFactory::class) + ->setMethods(['getRegion']) + ->setConstructorArgs($arguments) + ->getMock(); } public function testImplementsCacheFactory() @@ -68,10 +68,10 @@ public function testImplementsCacheFactory() public function testBuildCachedEntityPersisterReadOnly() { - $em = $this->em; - $metadata = clone $em->getClassMetadata(State::class); - $persister = new BasicEntityPersister($em, $metadata); - $region = new ConcurrentRegionMock(new DefaultRegion('regionName', $this->getSharedSecondLevelCacheDriverImpl())); + $em = $this->em; + $metadata = clone $em->getClassMetadata(State::class); + $persister = new BasicEntityPersister($em, $metadata); + $region = new ConcurrentRegionMock(new DefaultRegion('regionName', $this->getSharedSecondLevelCacheDriverImpl())); $metadata->cache['usage'] = ClassMetadata::CACHE_USAGE_READ_ONLY; @@ -88,10 +88,10 @@ public function testBuildCachedEntityPersisterReadOnly() public function testBuildCachedEntityPersisterReadWrite() { - $em = $this->em; - $metadata = clone $em->getClassMetadata(State::class); - $persister = new BasicEntityPersister($em, $metadata); - $region = new ConcurrentRegionMock(new DefaultRegion('regionName', $this->getSharedSecondLevelCacheDriverImpl())); + $em = $this->em; + $metadata = clone $em->getClassMetadata(State::class); + $persister = new BasicEntityPersister($em, $metadata); + $region = new ConcurrentRegionMock(new DefaultRegion('regionName', $this->getSharedSecondLevelCacheDriverImpl())); $metadata->cache['usage'] = ClassMetadata::CACHE_USAGE_READ_WRITE; @@ -108,10 +108,10 @@ public function testBuildCachedEntityPersisterReadWrite() public function testBuildCachedEntityPersisterNonStrictReadWrite() { - $em = $this->em; - $metadata = clone $em->getClassMetadata(State::class); - $persister = new BasicEntityPersister($em, $metadata); - $region = new ConcurrentRegionMock(new DefaultRegion('regionName', $this->getSharedSecondLevelCacheDriverImpl())); + $em = $this->em; + $metadata = clone $em->getClassMetadata(State::class); + $persister = new BasicEntityPersister($em, $metadata); + $region = new ConcurrentRegionMock(new DefaultRegion('regionName', $this->getSharedSecondLevelCacheDriverImpl())); $metadata->cache['usage'] = ClassMetadata::CACHE_USAGE_NONSTRICT_READ_WRITE; @@ -128,11 +128,11 @@ public function testBuildCachedEntityPersisterNonStrictReadWrite() public function testBuildCachedCollectionPersisterReadOnly() { - $em = $this->em; - $metadata = $em->getClassMetadata(State::class); - $mapping = $metadata->associationMappings['cities']; - $persister = new OneToManyPersister($em); - $region = new ConcurrentRegionMock(new DefaultRegion('regionName', $this->getSharedSecondLevelCacheDriverImpl())); + $em = $this->em; + $metadata = $em->getClassMetadata(State::class); + $mapping = $metadata->associationMappings['cities']; + $persister = new OneToManyPersister($em); + $region = new ConcurrentRegionMock(new DefaultRegion('regionName', $this->getSharedSecondLevelCacheDriverImpl())); $mapping['cache']['usage'] = ClassMetadata::CACHE_USAGE_READ_ONLY; @@ -150,11 +150,11 @@ public function testBuildCachedCollectionPersisterReadOnly() public function testBuildCachedCollectionPersisterReadWrite() { - $em = $this->em; - $metadata = $em->getClassMetadata(State::class); - $mapping = $metadata->associationMappings['cities']; - $persister = new OneToManyPersister($em); - $region = new ConcurrentRegionMock(new DefaultRegion('regionName', $this->getSharedSecondLevelCacheDriverImpl())); + $em = $this->em; + $metadata = $em->getClassMetadata(State::class); + $mapping = $metadata->associationMappings['cities']; + $persister = new OneToManyPersister($em); + $region = new ConcurrentRegionMock(new DefaultRegion('regionName', $this->getSharedSecondLevelCacheDriverImpl())); $mapping['cache']['usage'] = ClassMetadata::CACHE_USAGE_READ_WRITE; @@ -171,11 +171,11 @@ public function testBuildCachedCollectionPersisterReadWrite() public function testBuildCachedCollectionPersisterNonStrictReadWrite() { - $em = $this->em; - $metadata = $em->getClassMetadata(State::class); - $mapping = $metadata->associationMappings['cities']; - $persister = new OneToManyPersister($em); - $region = new ConcurrentRegionMock(new DefaultRegion('regionName', $this->getSharedSecondLevelCacheDriverImpl())); + $em = $this->em; + $metadata = $em->getClassMetadata(State::class); + $mapping = $metadata->associationMappings['cities']; + $persister = new OneToManyPersister($em); + $region = new ConcurrentRegionMock(new DefaultRegion('regionName', $this->getSharedSecondLevelCacheDriverImpl())); $mapping['cache']['usage'] = ClassMetadata::CACHE_USAGE_NONSTRICT_READ_WRITE; @@ -234,9 +234,9 @@ public function testCreateNewCacheDriver() */ public function testBuildCachedEntityPersisterNonStrictException() { - $em = $this->em; - $metadata = clone $em->getClassMetadata(State::class); - $persister = new BasicEntityPersister($em, $metadata); + $em = $this->em; + $metadata = clone $em->getClassMetadata(State::class); + $persister = new BasicEntityPersister($em, $metadata); $metadata->cache['usage'] = -1; @@ -249,10 +249,10 @@ public function testBuildCachedEntityPersisterNonStrictException() */ public function testBuildCachedCollectionPersisterException() { - $em = $this->em; - $metadata = $em->getClassMetadata(State::class); - $mapping = $metadata->associationMappings['cities']; - $persister = new OneToManyPersister($em); + $em = $this->em; + $metadata = $em->getClassMetadata(State::class); + $mapping = $metadata->associationMappings['cities']; + $persister = new OneToManyPersister($em); $mapping['cache']['usage'] = -1; @@ -269,8 +269,8 @@ public function testInvalidFileLockRegionDirectoryException() $factory->getRegion( [ - 'usage' => ClassMetadata::CACHE_USAGE_READ_WRITE, - 'region' => 'foo' + 'usage' => ClassMetadata::CACHE_USAGE_READ_WRITE, + 'region' => 'foo' ] ); } @@ -281,14 +281,14 @@ public function testBuildsNewNamespacedCacheInstancePerRegionInstance() $fooRegion = $factory->getRegion( [ - 'region' => 'foo', - 'usage' => ClassMetadata::CACHE_USAGE_READ_ONLY, + 'region' => 'foo', + 'usage' => ClassMetadata::CACHE_USAGE_READ_ONLY, ] ); $barRegion = $factory->getRegion( [ - 'region' => 'bar', - 'usage' => ClassMetadata::CACHE_USAGE_READ_ONLY, + 'region' => 'bar', + 'usage' => ClassMetadata::CACHE_USAGE_READ_ONLY, ] ); @@ -331,8 +331,8 @@ public function testBuildsDefaultCacheRegionFromGenericCacheRegion() DefaultRegion::class, $factory->getRegion( [ - 'region' => 'bar', - 'usage' => ClassMetadata::CACHE_USAGE_READ_ONLY, + 'region' => 'bar', + 'usage' => ClassMetadata::CACHE_USAGE_READ_ONLY, ] ) ); @@ -349,8 +349,8 @@ public function testBuildsMultiGetCacheRegionFromGenericCacheRegion() DefaultMultiGetRegion::class, $factory->getRegion( [ - 'region' => 'bar', - 'usage' => ClassMetadata::CACHE_USAGE_READ_ONLY, + 'region' => 'bar', + 'usage' => ClassMetadata::CACHE_USAGE_READ_ONLY, ] ) ); From df5f480b4cd82b89a64ffdeaeea3859c13faf70d Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Wed, 11 Jan 2017 17:35:28 -0300 Subject: [PATCH 216/877] document change as minor BC Break --- UPGRADE.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index b71e10adb65..e29cd0792cd 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,9 @@ # Upgrade to 2.5 +## Minor BC BREAK: remove $className parameter on AbstractEntityInheritancePersister#getSelectJoinColumnSQL + +As `$className` parameter is not used on its method body, it was safely removed. + ## Minor BC BREAK: query cache key time is now a float As of 2.5.5, the `QueryCacheEntry#time` property will contain a float value From 63e4eea9e2d09f65f93e54d0ef6ea612b9d65ba6 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Thu, 12 Jan 2017 12:49:46 +0100 Subject: [PATCH 217/877] Complete re-write of "Transitive persistence / Cascade Operations" (#6219) Follow-up of https://github.com/doctrine/doctrine2/pull/6171 --- .../reference/working-with-associations.rst | 110 +++++++++--------- 1 file changed, 58 insertions(+), 52 deletions(-) diff --git a/docs/en/reference/working-with-associations.rst b/docs/en/reference/working-with-associations.rst index f8011cebb00..9283a1e861d 100644 --- a/docs/en/reference/working-with-associations.rst +++ b/docs/en/reference/working-with-associations.rst @@ -407,31 +407,14 @@ There are two approaches to handle this problem in your code: Transitive persistence / Cascade Operations ------------------------------------------- -When working with many associated entities, you sometimes don't want to "expose" all entities to your PHP application. -Therefore Doctrine 2 provides a mechanism for transitive persistence through cascading of certain operations. +Doctrine 2 provides a mechanism for transitive persistence through cascading of certain operations. Each association to another entity or a collection of entities can be configured to automatically cascade the following operations to the associated entities: ``persist``, ``remove``, ``merge``, ``detach``, ``refresh`` or ``all``. -.. note:: - - Cascade operations are performed in memory. That means collections and related entities - are fetched into memory, even if they are still marked as lazy when - the cascade operation is about to be performed. However this approach allows - entity lifecycle events to be performed for each of these operations. - - However, pulling objects graph into memory on cascade can cause considerable performance - overhead, especially when cascading collections are large. Makes sure - to weigh the benefits and downsides of each cascade operation that you define. - - To rely on the database level cascade operations for the delete operation instead, you can - configure each join column with the **onDelete** option. See the respective - mapping driver chapters for more information. - -The following example is an extension to the User-Comment example -of this chapter. Suppose in our application a user is created -whenever they write their first comment. In this case we would use the -following code: +The main use case for ``cascade: persist`` is to avoid "exposing" associated entities to your PHP application. +Continuing with the User-Comment example of this chapter, this is how the creation of a new user and a new +comment might look like in your controller (without ``cascade: persist``): .. code-block:: php @@ -444,34 +427,36 @@ following code: $em->persist($myFirstComment); // required, if `cascade: persist` isn't set $em->flush(); -Even if you *persist* a new User that contains our new Comment this -code requires an explicit call to -``EntityManager#persist($myFirstComment)``. Doctrine 2 does not -cascade the persist operation to all nested entities that are new -as well. - -More complicated is the deletion of all user's comments when the user is -removed from the system: +Note that the Comment entity is instantiated right here in the controller. +To avoid this, ``cascade: persist`` allows you to "hide" the Comment entity from the controller, +only accessing it through the User entity: .. code-block:: php find('User', $deleteUserId); - - foreach ($user->getAuthoredComments() as $comment) { - $em->remove($comment); - } - $em->remove($user); - $em->flush(); + // User entity + class User + { + private $id; + private $comments; -Without the loop over all the authored comments Doctrine would use -an UPDATE statement only to set the foreign key to NULL and only -the User would be deleted from the database during the -flush()-Operation. + public function __construct() + { + $this->id = User::new(); + $this->comments = new ArrayCollection(); + } -To have Doctrine handle both cases automatically we can change the -``User#commentsAuthored`` property to cascade both the "persist" -and the "remove" operation. + public function comment(string $text, DateTimeInterface $time) : void + { + $newComment = Comment::create($text, $time); + $newComment->setUser($this); + $this->comments->add($newComment); + } + + // ... + } + +If you then set up the cascading to the ``User#commentsAuthored`` property... .. code-block:: php @@ -488,30 +473,51 @@ and the "remove" operation. //... } -Since ``cascade: persist`` is configured for the ``User#commentsAuthored`` -association, you can now create a user and persist their comments as follows: +...you can now create a user and an associated comment like this: .. code-block:: php addComment($myFirstComment); - $myFirstComment->setUser($user); + $user->comment('Lorem ipsum', new DateTime()); $em->persist($user); $em->flush(); .. note:: - This code does not associate the newly created comment with the user. - To achieve this, you *always* have to call ``$myFirstComment->setUser($user);`` – - no matter if ``cascade: persist`` is set or not. + The idea of ``cascade: persist`` is not to save you any lines of code in the controller. + If you instantiate the comment object in the controller (i.e. don't set up the user entity as shown above), + even with ``cascade: persist`` you still have to call ``$myFirstComment->setUser($user);``. + +Thanks to ``cascade: remove``, you can easily delete a user and all linked comments without having to loop through them: + +.. code-block:: php + + find('User', $deleteUserId); + + $em->remove($user); + $em->flush(); + +.. note:: + + Cascade operations are performed in memory. That means collections and related entities + are fetched into memory (even if they are marked as lazy) when + the cascade operation is about to be performed. However this approach allows + entity lifecycle events to be performed for each of these operations. + + However, pulling objects graph into memory on cascade can cause considerable performance + overhead, especially when the cascaded collections are large. Make sure + to weigh the benefits and downsides of each cascade operation that you define. + + To rely on the database level cascade operations for the delete operation instead, you can + configure each join column with :doc:`the **onDelete** option `. Even though automatic cascading is convenient, it should be used with care. Do not blindly apply ``cascade=all`` to all associations as it will unnecessarily degrade the performance of your application. -For each cascade operation that gets activated Doctrine also +For each cascade operation that gets activated, Doctrine also applies that operation to the association, be it single or collection valued. From 38636e7db4d8e17ab74719d5c555fb615eccd36c Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Thu, 12 Jan 2017 13:59:24 +0100 Subject: [PATCH 218/877] Minor formatting improvements Numbered lists aren't displayed nicely, see e.g. http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/working-with-associations.html#persistence-by-reachability-cascade-persist - is this a rendering bug? --- .../reference/working-with-associations.rst | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/docs/en/reference/working-with-associations.rst b/docs/en/reference/working-with-associations.rst index 9283a1e861d..16afcfd77cf 100644 --- a/docs/en/reference/working-with-associations.rst +++ b/docs/en/reference/working-with-associations.rst @@ -424,7 +424,7 @@ comment might look like in your controller (without ``cascade: persist``): $user->addComment($myFirstComment); $em->persist($user); - $em->persist($myFirstComment); // required, if `cascade: persist` isn't set + $em->persist($myFirstComment); // required, if `cascade: persist` is not set $em->flush(); Note that the Comment entity is instantiated right here in the controller. @@ -504,15 +504,15 @@ Thanks to ``cascade: remove``, you can easily delete a user and all linked comme Cascade operations are performed in memory. That means collections and related entities are fetched into memory (even if they are marked as lazy) when - the cascade operation is about to be performed. However this approach allows + the cascade operation is about to be performed. This approach allows entity lifecycle events to be performed for each of these operations. - However, pulling objects graph into memory on cascade can cause considerable performance + However, pulling object graphs into memory on cascade can cause considerable performance overhead, especially when the cascaded collections are large. Make sure to weigh the benefits and downsides of each cascade operation that you define. To rely on the database level cascade operations for the delete operation instead, you can - configure each join column with :doc:`the **onDelete** option `. + configure each join column with :doc:`the onDelete option `. Even though automatic cascading is convenient, it should be used with care. Do not blindly apply ``cascade=all`` to all associations as @@ -525,21 +525,20 @@ Persistence by Reachability: Cascade Persist ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ There are additional semantics that apply to the Cascade Persist -operation. During each flush() operation Doctrine detects if there +operation. During each ``flush()`` operation Doctrine detects if there are new entities in any collection and three possible cases can happen: -1. New entities in a collection marked as cascade persist will be +1. New entities in a collection marked as ``cascade: persist`` will be directly persisted by Doctrine. -2. New entities in a collection not marked as cascade persist will - produce an Exception and rollback the flush() operation. +2. New entities in a collection not marked as ``cascade: persist`` will + produce an Exception and rollback the ``flush()`` operation. 3. Collections without new entities are skipped. This concept is called Persistence by Reachability: New entities that are found on already managed entities are automatically -persisted as long as the association is defined as cascade -persist. +persisted as long as the association is defined as ``cascade: persist``. Orphan Removal -------------- From 4fccf84c828ead3d869e2f4e3e810ff3b5e0d43f Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Thu, 12 Jan 2017 14:23:55 +0100 Subject: [PATCH 219/877] Added link Sorry, I don't know how to link to the exact section 8.8 --- docs/en/reference/working-with-objects.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/en/reference/working-with-objects.rst b/docs/en/reference/working-with-objects.rst index 32f1a3ee980..bef73cebaa3 100644 --- a/docs/en/reference/working-with-objects.rst +++ b/docs/en/reference/working-with-objects.rst @@ -743,8 +743,7 @@ The Repository implement the ``Doctrine\Common\Collections\Selectable`` interface. That means you can build ``Doctrine\Common\Collections\Criteria`` and pass them to the ``matching($criteria)`` method. -See the :ref:`Working with Associations: Filtering collections -`. +See section `Filtering collections` of chapter :doc:`Working with Associations ` By Eager Loading ~~~~~~~~~~~~~~~~ From 5208187f1a2b7cdaf896f6df19fce9e9a9604298 Mon Sep 17 00:00:00 2001 From: Jefersson Nathan Date: Thu, 12 Jan 2017 13:02:10 -0300 Subject: [PATCH 220/877] rewording upgrade sentence --- UPGRADE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index e29cd0792cd..cc304b8983a 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,8 +1,8 @@ # Upgrade to 2.5 -## Minor BC BREAK: remove $className parameter on AbstractEntityInheritancePersister#getSelectJoinColumnSQL +## Minor BC BREAK: removed $className parameter on `AbstractEntityInheritancePersister#getSelectJoinColumnSQL` -As `$className` parameter is not used on its method body, it was safely removed. +As `$className` parameter was not used in the method, it was safely removed. ## Minor BC BREAK: query cache key time is now a float From d137ffe0a4545245f3de986533655040c3fb5f0e Mon Sep 17 00:00:00 2001 From: Waleed Gadelkareem Date: Fri, 13 Jan 2017 18:09:36 +0100 Subject: [PATCH 221/877] Allow gearman environment vars --- .../Tests/ORM/Functional/Locking/LockAgentWorker.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php b/tests/Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php index c3d226aa482..c7b82f7a87d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php @@ -16,7 +16,10 @@ static public function run() $lockAgent = new LockAgentWorker(); $worker = new \GearmanWorker(); - $worker->addServer(); + $worker->addServer( + isset($_SERVER['GEARMAN_HOST']) ? $_SERVER['GEARMAN_HOST'] : null, + isset($_SERVER['GEARMAN_PORT']) ? $_SERVER['GEARMAN_PORT'] : 4730 + ); $worker->addFunction("findWithLock", [$lockAgent, "findWithLock"]); $worker->addFunction("dqlWithLock", [$lockAgent, "dqlWithLock"]); $worker->addFunction('lock', [$lockAgent, 'lock']); From 109ac5f8271c0c175729da96960b88b3581d71a6 Mon Sep 17 00:00:00 2001 From: Waleed Gadelkareem Date: Fri, 13 Jan 2017 18:11:10 +0100 Subject: [PATCH 222/877] Allow gearman env vars --- .../Tests/ORM/Functional/Locking/GearmanLockTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php index 43a3cbf5b19..9c8d4b7eaf2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php @@ -26,7 +26,10 @@ protected function setUp() $this->tasks = []; $this->gearman = new \GearmanClient(); - $this->gearman->addServer(); + $this->gearman->addServer( + isset($_SERVER['GEARMAN_HOST']) ? $_SERVER['GEARMAN_HOST'] : null, + isset($_SERVER['GEARMAN_PORT']) ? $_SERVER['GEARMAN_PORT'] : 4730 + ); $this->gearman->setCompleteCallback([$this, "gearmanTaskCompleted"]); $article = new CmsArticle(); From 41a377948b8e984b8f28951f74adad29b89cc05b Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 15 Jan 2017 23:56:44 +0100 Subject: [PATCH 223/877] Documenting BC Break introduced by the removal of `Doctrine\ORM\Query\SqlWalker#walkCaseExpression()` Ref: https://github.com/doctrine/doctrine2/pull/5600 --- UPGRADE.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/UPGRADE.md b/UPGRADE.md index cc304b8983a..3592fe5b609 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,6 +1,11 @@ # Upgrade to 2.5 -## Minor BC BREAK: removed $className parameter on `AbstractEntityInheritancePersister#getSelectJoinColumnSQL` +## Minor BC BREAK: removed `Doctrine\ORM\Query\SqlWalker#walkCaseExpression()` + +Method `Doctrine\ORM\Query\SqlWalker#walkCaseExpression()` was unused and part +of the internal API of the ORM, so it was removed. [#5600](https://github.com/doctrine/doctrine2/pull/5600). + +## Minor BC BREAK: removed $className parameter on `AbstractEntityInheritancePersister#getSelectJoinColumnSQL()` As `$className` parameter was not used in the method, it was safely removed. From a831bb82ce3c0551de74e29cf46bbe5cfec1c17c Mon Sep 17 00:00:00 2001 From: mike Date: Mon, 16 Jan 2017 17:08:47 +0100 Subject: [PATCH 224/877] Adding hhvm as allowed to fail in the test matrix --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 714f8e2bb54..36b928bcc18 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ php: - 7.0 - 7.1 - nightly + - hhvm env: - DB=mysql From 5968b9e62f6232e072e8279428219badb45b1dc9 Mon Sep 17 00:00:00 2001 From: mike Date: Mon, 16 Jan 2017 17:09:49 +0100 Subject: [PATCH 225/877] Removing php 7.1 from the allowed failure --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 36b928bcc18..2bf9947183f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -71,7 +71,6 @@ matrix: env: DB=sqlite allow_failures: - - php: 7.1 - php: nightly - php: hhvm From bb943afabe37d1d04158533bf8e7ecac55e172ef Mon Sep 17 00:00:00 2001 From: Mikhail Polyanin Date: Fri, 20 May 2016 13:42:13 +0300 Subject: [PATCH 226/877] Optimization. Multiple get in QueryCache --- lib/Doctrine/ORM/Cache/DefaultQueryCache.php | 15 +++++++-- .../Tests/ORM/Cache/DefaultQueryCacheTest.php | 32 +++++++++++++++---- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php index 88e59421390..4c1fa831da1 100644 --- a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php +++ b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php @@ -112,20 +112,29 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = [] $regionName = $region->getName(); $cm = $this->em->getClassMetadata($entityName); + + $entityCacheKeys = []; + foreach ($entry->result as $index => $concreteEntry) { + $entityCacheKeys[$index] = new EntityCacheKey($cm->rootEntityName, $concreteEntry['identifier']); + } + $entries = $region->getMultiple(new CollectionCacheEntry($entityCacheKeys)); + // @TODO - move to cache hydration component foreach ($entry->result as $index => $entry) { - if (($entityEntry = $region->get($entityKey = new EntityCacheKey($cm->rootEntityName, $entry['identifier']))) === null) { + $entityEntry = is_array($entries) && array_key_exists($index, $entries) ? $entries[$index] : null; + + if ($entityEntry === null) { if ($this->cacheLogger !== null) { - $this->cacheLogger->entityCacheMiss($regionName, $entityKey); + $this->cacheLogger->entityCacheMiss($regionName, $entityCacheKeys[$index]); } return null; } if ($this->cacheLogger !== null) { - $this->cacheLogger->entityCacheHit($regionName, $entityKey); + $this->cacheLogger->entityCacheHit($regionName, $entityCacheKeys[$index]); } if ( ! $hasRelation) { diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php index cfd9142094a..e011159bd33 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php @@ -294,8 +294,14 @@ public function testGetBasicQueryResult() ]; $this->region->addReturn('get', $entry); - $this->region->addReturn('get', new EntityCacheEntry(Country::class, $data[0])); - $this->region->addReturn('get', new EntityCacheEntry(Country::class, $data[1])); + + $this->region->addReturn( + 'getMultiple', + [ + new EntityCacheEntry(Country::class, $data[0]), + new EntityCacheEntry(Country::class, $data[1]) + ] + ); $rsm->addRootEntityFromClassMetadata(Country::class, 'c'); @@ -458,8 +464,14 @@ public function testGetShouldIgnoreOldQueryCacheEntryResult() $entry->time = microtime(true) - 100; $this->region->addReturn('get', $entry); - $this->region->addReturn('get', new EntityCacheEntry(Country::class, $entities[0])); - $this->region->addReturn('get', new EntityCacheEntry(Country::class, $entities[1])); + + $this->region->addReturn( + 'getMultiple', + [ + new EntityCacheEntry(Country::class, $entities[0]), + new EntityCacheEntry(Country::class, $entities[1]) + ] + ); $rsm->addRootEntityFromClassMetadata(Country::class, 'c'); @@ -483,8 +495,14 @@ public function testGetShouldIgnoreNonQueryCacheEntryResult() ]; $this->region->addReturn('get', $entry); - $this->region->addReturn('get', new EntityCacheEntry(Country::class, $data[0])); - $this->region->addReturn('get', new EntityCacheEntry(Country::class, $data[1])); + + $this->region->addReturn( + 'getMultiple', + [ + new EntityCacheEntry(Country::class, $data[0]), + new EntityCacheEntry(Country::class, $data[1]) + ] + ); $rsm->addRootEntityFromClassMetadata(Country::class, 'c'); @@ -503,7 +521,7 @@ public function testGetShouldIgnoreMissingEntityQueryCacheEntry() ); $this->region->addReturn('get', $entry); - $this->region->addReturn('get', null); + $this->region->addReturn('getMultiple', [null]); $rsm->addRootEntityFromClassMetadata(Country::class, 'c'); From 4f28aaa206064563916ac56726d28893054527df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Mon, 16 Jan 2017 23:22:52 +0100 Subject: [PATCH 227/877] Refactor to use class_map() instead --- lib/Doctrine/ORM/Cache/DefaultQueryCache.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php index 4c1fa831da1..b7ac6f00cb4 100644 --- a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php +++ b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php @@ -113,11 +113,12 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = [] $cm = $this->em->getClassMetadata($entityName); - $entityCacheKeys = []; - foreach ($entry->result as $index => $concreteEntry) { - $entityCacheKeys[$index] = new EntityCacheKey($cm->rootEntityName, $concreteEntry['identifier']); - } - $entries = $region->getMultiple(new CollectionCacheEntry($entityCacheKeys)); + $generateKeys = function (array $entry) use ($cm): EntityCacheKey { + return new EntityCacheKey($cm->rootEntityName, $entry['identifier']); + }; + + $cacheKeys = new CollectionCacheEntry(array_map($generateKeys, $entry->result)); + $entries = $region->getMultiple($cacheKeys); // @TODO - move to cache hydration component foreach ($entry->result as $index => $entry) { @@ -127,14 +128,14 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = [] if ($entityEntry === null) { if ($this->cacheLogger !== null) { - $this->cacheLogger->entityCacheMiss($regionName, $entityCacheKeys[$index]); + $this->cacheLogger->entityCacheMiss($regionName, $cacheKeys->identifiers[$index]); } return null; } if ($this->cacheLogger !== null) { - $this->cacheLogger->entityCacheHit($regionName, $entityCacheKeys[$index]); + $this->cacheLogger->entityCacheHit($regionName, $cacheKeys->identifiers[$index]); } if ( ! $hasRelation) { From 1f53afa9cd28425132854e5ec35ae1c7024de408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Thu, 19 Jan 2017 17:19:34 +0100 Subject: [PATCH 228/877] Make sure we're using the rootEntityName on all places Otherwise we might end up with duplicated cache entries and weird results (specially regarding associations). --- .../ORM/Cache/DefaultCollectionHydrator.php | 3 +- .../ORM/Cache/DefaultEntityHydrator.php | 3 +- lib/Doctrine/ORM/Cache/DefaultQueryCache.php | 9 +- .../Entity/AbstractEntityPersister.php | 3 +- .../ORM/Functional/Ticket/GH5562Test.php | 128 ++++++++++++++++++ 5 files changed, 138 insertions(+), 8 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH5562Test.php diff --git a/lib/Doctrine/ORM/Cache/DefaultCollectionHydrator.php b/lib/Doctrine/ORM/Cache/DefaultCollectionHydrator.php index 7ff11e4adf1..f12ccf50a78 100644 --- a/lib/Doctrine/ORM/Cache/DefaultCollectionHydrator.php +++ b/lib/Doctrine/ORM/Cache/DefaultCollectionHydrator.php @@ -65,8 +65,9 @@ public function buildCacheEntry(ClassMetadata $metadata, CollectionCacheKey $key $data = []; foreach ($collection as $index => $entity) { - $data[$index] = new EntityCacheKey($metadata->name, $this->uow->getEntityIdentifier($entity)); + $data[$index] = new EntityCacheKey($metadata->rootEntityName, $this->uow->getEntityIdentifier($entity)); } + return new CollectionCacheEntry($data); } diff --git a/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php b/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php index 99a98bddc77..7d72464dc01 100644 --- a/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php +++ b/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php @@ -175,7 +175,8 @@ public function loadCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, Ent continue; } - $assocKey = new EntityCacheKey($assoc['targetEntity'], $assocId); + $assocMetadata = $this->em->getClassMetadata($assoc['targetEntity']); + $assocKey = new EntityCacheKey($assocMetadata->rootEntityName, $assocId); $assocPersister = $this->uow->getEntityPersister($assoc['targetEntity']); $assocRegion = $assocPersister->getCacheRegion(); $assocEntry = $assocRegion->get($assocKey); diff --git a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php index b7ac6f00cb4..076fe3bebed 100644 --- a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php +++ b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php @@ -148,13 +148,13 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = [] $data = $entityEntry->data; foreach ($entry['associations'] as $name => $assoc) { - $assocPersister = $this->uow->getEntityPersister($assoc['targetEntity']); $assocRegion = $assocPersister->getCacheRegion(); + $assocMetadata = $this->em->getClassMetadata($assoc['targetEntity']); if ($assoc['type'] & ClassMetadata::TO_ONE) { - if (($assocEntry = $assocRegion->get($assocKey = new EntityCacheKey($assoc['targetEntity'], $assoc['identifier']))) === null) { + if (($assocEntry = $assocRegion->get($assocKey = new EntityCacheKey($assocMetadata->rootEntityName, $assoc['identifier']))) === null) { if ($this->cacheLogger !== null) { $this->cacheLogger->entityCacheMiss($assocRegion->getName(), $assocKey); @@ -178,12 +178,11 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = [] continue; } - $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); - $collection = new PersistentCollection($this->em, $targetClass, new ArrayCollection()); + $collection = new PersistentCollection($this->em, $assocMetadata, new ArrayCollection()); foreach ($assoc['list'] as $assocIndex => $assocId) { - if (($assocEntry = $assocRegion->get($assocKey = new EntityCacheKey($assoc['targetEntity'], $assocId))) === null) { + if (($assocEntry = $assocRegion->get($assocKey = new EntityCacheKey($assocMetadata->rootEntityName, $assocId))) === null) { if ($this->cacheLogger !== null) { $this->cacheLogger->entityCacheMiss($assocRegion->getName(), $assocKey); diff --git a/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php b/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php index a6e2b348036..1e0f17972cc 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php @@ -272,7 +272,8 @@ private function storeJoinedAssociations($entity) } $assocId = $this->uow->getEntityIdentifier($assocEntity); - $assocKey = new EntityCacheKey($assoc['targetEntity'], $assocId); + $assocMetadata = $this->metadataFactory->getMetadataFor($assoc['targetEntity']); + $assocKey = new EntityCacheKey($assocMetadata->rootEntityName, $assocId); $assocPersister = $this->uow->getEntityPersister($assoc['targetEntity']); $assocPersister->storeEntityCache($assocEntity, $assocKey); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5562Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5562Test.php new file mode 100644 index 00000000000..824c4378add --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5562Test.php @@ -0,0 +1,128 @@ +enableSecondLevelCache(); + + parent::setUp(); + + $this->_schemaTool->createSchema( + [ + $this->_em->getClassMetadata(GH5562User::class), + $this->_em->getClassMetadata(GH5562Manager::class), + $this->_em->getClassMetadata(GH5562Merchant::class), + ] + ); + } + + /** + * @group 5562 + */ + public function testCacheShouldBeUpdatedWhenAssociationChanges() + { + $manager = new GH5562Manager(); + $merchant = new GH5562Merchant(); + + $manager->username = 'username'; + $manager->merchant = $merchant; + $merchant->manager = $manager; + + $merchant->name = 'Merchant'; + + $this->_em->persist($merchant); + $this->_em->persist($manager); + $this->_em->flush(); + $this->_em->clear(); + + $merchant = $this->_em->find(GH5562Merchant::class, $merchant->id); + + $merchant->name = mt_rand(); + $merchant->manager->username = 'usernameUPDATE'; + + $this->_em->flush(); + $this->_em->clear(); + + $merchant = $this->_em->find(GH5562Merchant::class, $merchant->id); + + self::assertEquals('usernameUPDATE', $merchant->manager->username); + } +} + +/** + * @Entity + * @Cache(usage="NONSTRICT_READ_WRITE") + */ +class GH5562Merchant +{ + /** + * @var integer + * + * @Id + * @Column(name="id", type="integer") + * @GeneratedValue(strategy="IDENTITY") + */ + public $id; + + /** + * @var GH5562Manager + * + * @OneToOne(targetEntity=GH5562Manager::class, mappedBy="merchant") + * @Cache(usage="NONSTRICT_READ_WRITE") + */ + public $manager; + + /** + * @var string + * + * @Column(name="name", type="string", length=255, nullable=false) + */ + public $name; +} + +/** + * @Entity + * @InheritanceType("SINGLE_TABLE") + * @DiscriminatorMap({"MANAGER" = GH5562Manager::class}) + */ +abstract class GH5562User +{ + /** + * @var integer + * + * @Id + * @Column(name="id", type="integer") + * @GeneratedValue(strategy="IDENTITY") + */ + public $id; +} + +/** + * @Entity + * @Cache(usage="NONSTRICT_READ_WRITE") + */ +class GH5562Manager extends GH5562User +{ + + /** + * @var string + * + * @Column + */ + public $username; + + /** + * @var GH5562Merchant + * + * @OneToOne(targetEntity=GH5562Merchant::class, inversedBy="manager") + */ + public $merchant; +} From 57f560401bcb7f9e27d02958662a7ab78657d4a0 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 23 Jan 2017 09:35:26 +0100 Subject: [PATCH 229/877] Note on Entity listeners As requested here https://github.com/doctrine/doctrine2/issues/6247#issuecomment-274123780 I thought it should be interesting to note that. The note could be longer, like "You should avoid to have multiple methods for the same event (e.g. multiple @PrePersist) since the execution order is not guaranteed". --- docs/en/reference/events.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/en/reference/events.rst b/docs/en/reference/events.rst index e6c8b0aa413..7922d3dfd1d 100644 --- a/docs/en/reference/events.rst +++ b/docs/en/reference/events.rst @@ -888,6 +888,9 @@ you need to map the listener method using the event type mapping: preRemove: [preRemoveHandler] # .... +.. note:: + + The order of execution of multiple methods for the same event (e.g. multiple @PrePersist) is not guaranteed. Entity listeners resolver From c816d375e8ed18964ca277d5fb178ed0b8ea2a26 Mon Sep 17 00:00:00 2001 From: Matteo Beccati Date: Tue, 24 Jan 2017 12:46:19 +0100 Subject: [PATCH 230/877] Add missing group to DDC2660Test.php With the current PHPUnit version and PHP 7.2/master, the test fails with: 1) Doctrine\Tests\ORM\Functional\Ticket\DDC2660Test::testIssueWithExtraColumn array_flip(): Can only flip STRING and INTEGER values! 2) Doctrine\Tests\ORM\Functional\Ticket\DDC2660Test::testIssueWithoutExtraColumn array_flip(): Can only flip STRING and INTEGER values! Due to the group being NULL vs "" on older PHP versions. I will also file a bug report or fix to PHPUnit and/or PHP itself, but it sounds like the missing group was just a typo. --- tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2660Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2660Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2660Test.php index 18854bcb8e0..46380f754b2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2660Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2660Test.php @@ -5,7 +5,7 @@ use Doctrine\ORM\Query\ResultSetMappingBuilder; /** - * @group + * @group DDC-2660 */ class DDC2660Test extends \Doctrine\Tests\OrmFunctionalTestCase { From 773af5b30678012c6eb39d90a747064e342e492a Mon Sep 17 00:00:00 2001 From: mike Date: Wed, 25 Jan 2017 15:54:03 +0100 Subject: [PATCH 231/877] Document the Custom option of the generated value annotation --- docs/en/reference/basic-mapping.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/en/reference/basic-mapping.rst b/docs/en/reference/basic-mapping.rst index 07bff32f62e..613d98dcc85 100644 --- a/docs/en/reference/basic-mapping.rst +++ b/docs/en/reference/basic-mapping.rst @@ -363,6 +363,8 @@ Here is the list of possible generation strategies: thus generated) by your code. The assignment must take place before a new entity is passed to ``EntityManager#persist``. NONE is the same as leaving off the @GeneratedValue entirely. +- ``CUSTOM``: With this option, you can use the ``@CustomIdGenerator`` annotation. + It will allow you to pass a :ref:`class of your own to generate the identifiers <_annref_customidgenerator>` Sequence Generator ^^^^^^^^^^^^^^^^^^ From 63bd6c359c239455f6ae5ec2c10c9ea4339f72bf Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Wed, 25 Jan 2017 10:52:17 -0500 Subject: [PATCH 232/877] [Docs] Adding a note about the addCriteria method on QueryBuilder --- docs/en/reference/query-builder.rst | 18 ++++++++++++++++++ .../en/reference/working-with-associations.rst | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/docs/en/reference/query-builder.rst b/docs/en/reference/query-builder.rst index 6b868c653f3..17638305a8a 100644 --- a/docs/en/reference/query-builder.rst +++ b/docs/en/reference/query-builder.rst @@ -499,6 +499,24 @@ complete list of supported helper methods available: public function countDistinct($x); // Returns Expr\Func } +Adding a Criteria to a Query +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +You can also add a :ref:`Criteria ` to a QueryBuilder by +using ``addCriteria``: + +.. code-block:: php + + orderBy(['firstName', 'ASC']); + + // $qb instanceof QueryBuilder + $qb->addCriteria($criteria); + // then execute your query like normal Low Level API ^^^^^^^^^^^^^ diff --git a/docs/en/reference/working-with-associations.rst b/docs/en/reference/working-with-associations.rst index 16afcfd77cf..df7dd595552 100644 --- a/docs/en/reference/working-with-associations.rst +++ b/docs/en/reference/working-with-associations.rst @@ -616,11 +616,11 @@ address reference. When flush is called not only are the references removed but both the old standing data and the one address entity are also deleted from the database. +.. _filtering-collections: + Filtering Collections --------------------- -.. filtering-collections: - Collections have a filtering API that allows to slice parts of data from a collection. If the collection has not been loaded from the database yet, the filtering API can work on the SQL level to make optimized access to From f3df000d294634e6042a11bf8518291fa313e18b Mon Sep 17 00:00:00 2001 From: mike Date: Fri, 27 Jan 2017 09:27:25 +0100 Subject: [PATCH 233/877] Fix a link to a ref in another page --- docs/en/reference/basic-mapping.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/basic-mapping.rst b/docs/en/reference/basic-mapping.rst index 613d98dcc85..d33313d8942 100644 --- a/docs/en/reference/basic-mapping.rst +++ b/docs/en/reference/basic-mapping.rst @@ -364,7 +364,7 @@ Here is the list of possible generation strategies: a new entity is passed to ``EntityManager#persist``. NONE is the same as leaving off the @GeneratedValue entirely. - ``CUSTOM``: With this option, you can use the ``@CustomIdGenerator`` annotation. - It will allow you to pass a :ref:`class of your own to generate the identifiers <_annref_customidgenerator>` + It will allow you to pass a :doc:`class of your own to generate the identifiers.<_annref_customidgenerator>` Sequence Generator ^^^^^^^^^^^^^^^^^^ From 64ab53a243257c2599be4f85250f58b408e5fa09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1chym=20Tou=C5=A1ek?= Date: Tue, 31 Jan 2017 11:57:01 +0100 Subject: [PATCH 234/877] Fix annotation --- lib/Doctrine/ORM/Query/Parser.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 65b8374bdb1..c6015120295 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -2874,8 +2874,7 @@ public function ArithmeticPrimary() /** * StringExpression ::= StringPrimary | ResultVariable | "(" Subselect ")" * - * @return \Doctrine\ORM\Query\AST\StringPrimary | - * \Doctrine\ORM\Query\AST\Subselect | + * @return \Doctrine\ORM\Query\AST\Subselect | * string */ public function StringExpression() From 260c8d0113e8849a490eaec4e77fef97904863ee Mon Sep 17 00:00:00 2001 From: Sven Cannivy Date: Fri, 10 Feb 2017 18:48:57 +0100 Subject: [PATCH 235/877] Fix typos and wording in NamingStrategy documentation --- docs/en/reference/namingstrategy.rst | 41 ++++++++++------------------ 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/docs/en/reference/namingstrategy.rst b/docs/en/reference/namingstrategy.rst index 9d82d8d8b7d..9f8e4a599a2 100644 --- a/docs/en/reference/namingstrategy.rst +++ b/docs/en/reference/namingstrategy.rst @@ -3,21 +3,18 @@ Implementing a NamingStrategy .. versionadded:: 2.3 -Using a naming strategy you can provide rules for automatically generating -database identifiers, columns and tables names -when the table/column name is not given. -This feature helps reduce the verbosity of the mapping document, -eliminating repetitive noise (eg: ``TABLE_``). - +Using a naming strategy you can provide rules for generating database identifiers, +column or table names when the column or table name is not given. This feature helps +reduce the verbosity of the mapping document, eliminating repetitive noise (eg: ``TABLE_``). Configuring a naming strategy ----------------------------- The default strategy used by Doctrine is quite minimal. By default the ``Doctrine\ORM\Mapping\DefaultNamingStrategy`` -uses the simple class name and the attributes names to generate tables and columns +uses the simple class name and the attribute names to generate tables and columns. -You can specify a different strategy by calling ``Doctrine\ORM\Configuration#setNamingStrategy()`` : +You can specify a different strategy by calling ``Doctrine\ORM\Configuration#setNamingStrategy()``: .. code-block:: php @@ -28,8 +25,7 @@ You can specify a different strategy by calling ``Doctrine\ORM\Configuration#set Underscore naming strategy --------------------------- -``\Doctrine\ORM\Mapping\UnderscoreNamingStrategy`` is a built-in strategy -that might be a useful if you want to use a underlying convention. +``\Doctrine\ORM\Mapping\UnderscoreNamingStrategy`` is a built-in strategy. .. code-block:: php @@ -37,14 +33,13 @@ that might be a useful if you want to use a underlying convention. $namingStrategy = new \Doctrine\ORM\Mapping\UnderscoreNamingStrategy(CASE_UPPER); $configuration()->setNamingStrategy($namingStrategy); -Then SomeEntityName will generate the table SOME_ENTITY_NAME when CASE_UPPER -or some_entity_name using CASE_LOWER is given. - +For SomeEntityName the strategy will generate the table SOME_ENTITY_NAME with the +``CASE_UPPER`` option, or some_entity_name with the ``CASE_LOWER`` option. Naming strategy interface ------------------------- The interface ``Doctrine\ORM\Mapping\NamingStrategy`` allows you to specify -a "naming standard" for database tables and columns. +a naming strategy for database tables and columns. .. code-block:: php @@ -101,10 +96,11 @@ a "naming standard" for database tables and columns. Implementing a naming strategy ------------------------------- -If you have database naming standards like all tables names should be prefixed -by the application prefix, all column names should be upper case, -you can easily achieve such standards by implementing a naming strategy. -You need to implements NamingStrategy first. Following is an example +If you have database naming standards, like all table names should be prefixed +by the application prefix, all column names should be upper case, you can easily +achieve such standards by implementing a naming strategy. + +You need to create a class which implements ``Doctrine\ORM\Mapping\NamingStrategy``. .. code-block:: php @@ -139,12 +135,3 @@ You need to implements NamingStrategy first. Following is an example ($referencedColumnName ?: $this->referenceColumnName())); } } - -Configuring the namingstrategy is easy if. -Just set your naming strategy calling ``Doctrine\ORM\Configuration#setNamingStrategy()`` :. - -.. code-block:: php - - setNamingStrategy($namingStrategy); From dcc80af7d934b0bf92caecc5849744ce0f2ad38d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 12 Feb 2017 18:38:21 +0100 Subject: [PATCH 236/877] Fix EntityManagerDecorator tests We were expecting a return value for all methods but on https://github.com/doctrine/common/commit/6a56df9a2445db166dbdae8079b9608f72a8496e we changed some methods to be void and of course that affected the ORM. --- .../Decorator/EntityManagerDecoratorTest.php | 73 ++++++++++++------- 1 file changed, 46 insertions(+), 27 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php b/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php index 70841b1e7b9..1e9f55d43ff 100644 --- a/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php +++ b/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php @@ -3,65 +3,84 @@ namespace Doctrine\Tests\ORM\Decorator; use Doctrine\ORM\Decorator\EntityManagerDecorator; -use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query\ResultSetMapping; class EntityManagerDecoratorTest extends \PHPUnit_Framework_TestCase { + const VOID_METHODS = [ + 'persist', + 'remove', + 'clear', + 'detach', + 'refresh', + 'flush', + 'initializeObject', + ]; + + /** + * @var EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ private $wrapped; - private $decorator; public function setUp() { $this->wrapped = $this->createMock(EntityManagerInterface::class); - $this->decorator = $this->getMockBuilder(EntityManagerDecorator::class) - ->setConstructorArgs([$this->wrapped]) - ->setMethods(null) - ->getMock(); } public function getMethodParameters() { - $class = new \ReflectionClass(EntityManager::class); - + $class = new \ReflectionClass(EntityManagerInterface::class); $methods = []; + foreach ($class->getMethods() as $method) { if ($method->isConstructor() || $method->isStatic() || !$method->isPublic()) { continue; } - /** Special case EntityManager::createNativeQuery() */ - if ($method->getName() === 'createNativeQuery') { - $methods[] = [$method->getName(), ['name', new ResultSetMapping()]]; - continue; - } - - if ($method->getNumberOfRequiredParameters() === 0) { - $methods[] = [$method->getName(), []]; - } elseif ($method->getNumberOfRequiredParameters() > 0) { - $methods[] = [$method->getName(), array_fill(0, $method->getNumberOfRequiredParameters(), 'req') ?: []]; - } - if ($method->getNumberOfParameters() != $method->getNumberOfRequiredParameters()) { - $methods[] = [$method->getName(), array_fill(0, $method->getNumberOfParameters(), 'all') ?: []]; - } + $methods[$method->getName()] = $this->getParameters($method); } return $methods; } + private function getParameters(\ReflectionMethod $method) + { + /** Special case EntityManager::createNativeQuery() */ + if ($method->getName() === 'createNativeQuery') { + return [$method->getName(), ['name', new ResultSetMapping()]]; + } + + if ($method->getNumberOfRequiredParameters() === 0) { + return [$method->getName(), []]; + } + + if ($method->getNumberOfRequiredParameters() > 0) { + return [$method->getName(), array_fill(0, $method->getNumberOfRequiredParameters(), 'req') ?: []]; + } + + if ($method->getNumberOfParameters() != $method->getNumberOfRequiredParameters()) { + return [$method->getName(), array_fill(0, $method->getNumberOfParameters(), 'all') ?: []]; + } + + return []; + } + /** * @dataProvider getMethodParameters */ public function testAllMethodCallsAreDelegatedToTheWrappedInstance($method, array $parameters) { - $stub = $this->wrapped - ->expects($this->once()) + $return = !in_array($method, self::VOID_METHODS) ? 'INNER VALUE FROM ' . $method : null; + + $this->wrapped->expects($this->once()) ->method($method) - ->will($this->returnValue('INNER VALUE FROM ' . $method)); + ->with(...$parameters) + ->willReturn($return); - call_user_func_array([$stub, 'with'], $parameters); + $decorator = new class ($this->wrapped) extends EntityManagerDecorator { + }; - $this->assertSame('INNER VALUE FROM ' . $method, call_user_func_array([$this->decorator, $method], $parameters)); + $this->assertSame($return, $decorator->$method(...$parameters)); } } From 504e7010201ede8359967d9c7be3881a5ea89887 Mon Sep 17 00:00:00 2001 From: Claudio Zizza Date: Mon, 6 Mar 2017 00:34:18 +0100 Subject: [PATCH 237/877] Add existing column check-option to documentation --- docs/en/reference/annotations-reference.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/en/reference/annotations-reference.rst b/docs/en/reference/annotations-reference.rst index e55a23eff9f..8a2487a6502 100644 --- a/docs/en/reference/annotations-reference.rst +++ b/docs/en/reference/annotations-reference.rst @@ -134,6 +134,9 @@ Optional attributes: - ``collation``: The collation of the column (only supported by Drizzle, Mysql, PostgreSQL>=9.1, Sqlite and SQLServer). + - ``check``: Adds a check constraint type to the column (might not + be supported by all vendors). + - **columnDefinition**: DDL SQL snippet that starts after the column name and specifies the complete (non-portable!) column definition. This attribute allows to make use of advanced RMDBS features. From bd1efaf52847f5feb979244eb305af6019ab71e4 Mon Sep 17 00:00:00 2001 From: Boris Yonchev Date: Fri, 26 Feb 2016 09:58:56 +0200 Subject: [PATCH 238/877] DDC-2780 - Fixed issue with IS NULL on join aliases --- lib/Doctrine/ORM/Query/Parser.php | 6 ++ .../ORM/Functional/Ticket/DDC2780Test.php | 89 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2780Test.php diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index c6015120295..54d84f3e64c 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -3264,6 +3264,12 @@ public function NullComparisonExpression() $this->semanticalError('Cannot add having condition on undefined result variable.'); } + // Validate SingleValuedPathExpression (ie.: "product") + if (isset($this->queryComponents[$lookaheadValue]['metadata'])) { + $expr = $this->SingleValuedPathExpression(); + break; + } + // Validating ResultVariable if ( ! isset($this->queryComponents[$lookaheadValue]['resultVariable'])) { $this->semanticalError('Cannot add having condition on a non result variable.'); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2780Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2780Test.php new file mode 100644 index 00000000000..5539dfbbe5c --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2780Test.php @@ -0,0 +1,89 @@ +_schemaTool->createSchema( + [ + $this->_em->getClassMetadata(DDC2780User::class), + $this->_em->getClassMetadata(DDC2780Project::class) + ] + ); + } + + /** + * Verifies that IS [NOT] NULL can be used on join aliases + */ + public function testIssue() + { + $user = new DDC2780User; + $project = new DDC2780Project; + + $user->project = $project; + + $this->_em->persist($project); + $this->_em->persist($user); + $this->_em->flush(); + $this->_em->clear(); + + $result = $this->_em->createQueryBuilder() + ->select('user') + ->from(DDC2780User::class, 'user') + ->leftJoin('user.project', 'project') + ->where('project IS NOT NULL') + ->getQuery() + ->getOneOrNullResult(); + + $this->assertInstanceOf(DDC2780User::class, $result); + } +} + +/** + * @Entity + */ +class DDC2780User +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; + + /** + * @ManyToOne(targetEntity="DDC2780Project") + * + * @var DDC2780Project + */ + public $project; +} + +/** @Entity */ +class DDC2780Project +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; + + /** + * @OneToMany(targetEntity="DDC2780User", mappedBy="project") + * + * @var DDC2780User[] + */ + public $users; + + /** Constructor */ + public function __construct() + { + $this->users = new ArrayCollection(); + } +} + From 5507e0be29ec7b6d078e4389ec59158a002f057f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20G=C4=85sowski?= Date: Thu, 23 Mar 2017 19:12:40 +0100 Subject: [PATCH 239/877] Fix wrong variable name Fix $fieldMapping to $embeddedClass in generateEmbeddedPropertyDocBlock --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 8d1f05ac10a..5bc292a37fa 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -1731,7 +1731,7 @@ protected function generateEmbeddedPropertyDocBlock(array $embeddedClass) $embedded = ['class="' . $embeddedClass['class'] . '"']; - if (isset($fieldMapping['columnPrefix'])) { + if (isset($embeddedClass['columnPrefix'])) { $embedded[] = 'columnPrefix=' . var_export($embeddedClass['columnPrefix'], true); } From d6049f8631883d6ceb62b8220cb8b82d9f8cb364 Mon Sep 17 00:00:00 2001 From: Sam-Burns Date: Fri, 31 Mar 2017 00:49:17 +0100 Subject: [PATCH 240/877] Adding breaking build testing with minimum Composer dependencies --- .travis.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.travis.yml b/.travis.yml index 2bf9947183f..5509e3970e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,8 @@ before_script: - if [[ $TRAVIS_PHP_VERSION -lt '7.0' && $TRAVIS_PHP_VERSION != 'hhv*' ]]; then phpenv config-rm xdebug.ini; fi - composer self-update - composer install --prefer-source + - if [ "$DEPENDENCIES" != "low" ]; then composer update; fi; + - if [ "$DEPENDENCIES" == "low" ]; then composer update --prefer-lowest; fi; script: - ENABLE_SECOND_LEVEL_CACHE=0 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml $PHPUNIT_FLAGS @@ -37,6 +39,10 @@ matrix: env: DB=mariadb addons: mariadb: 10.1 + - php: 7.1 + env: + - DB=sqlite + - DEPENDENCIES='low' - php: hhvm sudo: true dist: trusty From f2edf36248e405a06c654775327e4094ecc5b76d Mon Sep 17 00:00:00 2001 From: Sam-Burns Date: Fri, 31 Mar 2017 01:14:38 +0100 Subject: [PATCH 241/877] Bumping doctrine/collections minimum version, to make tests pass --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b1576b11a2b..fc45544c7c8 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "require": { "php": "^7.0", "ext-pdo": "*", - "doctrine/collections": "~1.2", + "doctrine/collections": "~1.3", "doctrine/dbal": ">=2.5-dev,<2.7-dev", "doctrine/instantiator": "~1.0.1", "doctrine/common": "^2.7.1", From 60cc11461d0625c6aa6f248309972ba6c36c7909 Mon Sep 17 00:00:00 2001 From: Sam-Burns Date: Fri, 31 Mar 2017 01:17:48 +0100 Subject: [PATCH 242/877] Bumping doctrine/cache minimum version, to make tests pass --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fc45544c7c8..7eaddba8a2c 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "doctrine/dbal": ">=2.5-dev,<2.7-dev", "doctrine/instantiator": "~1.0.1", "doctrine/common": "^2.7.1", - "doctrine/cache": "~1.4", + "doctrine/cache": "~1.5", "symfony/console": "~2.5|~3.0" }, "require-dev": { From f5b4e8c82338303ec4cb0b0abb1cf8aba463b05d Mon Sep 17 00:00:00 2001 From: Sam-Burns Date: Fri, 31 Mar 2017 11:27:02 +0100 Subject: [PATCH 243/877] Specifying minimum version of doctrine/annotations with which tests pass --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 7eaddba8a2c..fc164dcc76f 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,7 @@ "doctrine/instantiator": "~1.0.1", "doctrine/common": "^2.7.1", "doctrine/cache": "~1.5", + "doctrine/annotations": "~1.2", "symfony/console": "~2.5|~3.0" }, "require-dev": { From 7aab261c24ca86a676cda6c771577641f1962341 Mon Sep 17 00:00:00 2001 From: Sam-Burns Date: Fri, 31 Mar 2017 15:46:04 +0100 Subject: [PATCH 244/877] Switching to a PHPUnit version that doesn't throw a stty-related PHP warning on Travis --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fc164dcc76f..bd8e8506175 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ }, "require-dev": { "symfony/yaml": "~2.3|~3.0", - "phpunit/phpunit": "^5.4" + "phpunit/phpunit": "^5.7" }, "suggest": { "symfony/yaml": "If you want to use YAML Metadata Mapping Driver" From 5bd7bd8d48402aa52baa6bf89ef15f6d664cc098 Mon Sep 17 00:00:00 2001 From: Sam-Burns Date: Fri, 31 Mar 2017 17:20:10 +0100 Subject: [PATCH 245/877] Updating to PHPUnit 6 --- composer.json | 2 +- tests/Doctrine/Tests/DoctrineTestCase.php | 4 +++- tests/Doctrine/Tests/ORM/ConfigurationTest.php | 4 ++-- .../Tests/ORM/Decorator/EntityManagerDecoratorTest.php | 3 ++- tests/Doctrine/Tests/ORM/EntityNotFoundExceptionTest.php | 3 ++- .../ORM/Event/OnClassMetadataNotFoundEventArgsTest.php | 4 ++-- .../Doctrine/Tests/ORM/Functional/Ticket/DDC2359Test.php | 3 ++- .../Tests/ORM/Internal/HydrationCompleteHandlerTest.php | 4 ++-- tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php | 3 ++- .../Reflection/ReflectionPropertiesGetterTest.php | 4 ++-- .../Tests/ORM/Mapping/ReflectionEmbeddedPropertyTest.php | 3 ++- .../Tests/ORM/Mapping/Symfony/AbstractDriverTest.php | 3 ++- .../Tests/ORM/ORMInvalidArgumentExceptionTest.php | 3 ++- tests/Doctrine/Tests/ORM/Query/ParserResultTest.php | 3 ++- .../Tests/ORM/Query/QueryExpressionVisitorTest.php | 3 ++- .../ORM/Repository/DefaultRepositoryFactoryTest.php | 4 ++-- tests/Doctrine/Tests/OrmFunctionalTestCase.php | 9 +++++---- 17 files changed, 37 insertions(+), 25 deletions(-) diff --git a/composer.json b/composer.json index bd8e8506175..5c0bf595844 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ }, "require-dev": { "symfony/yaml": "~2.3|~3.0", - "phpunit/phpunit": "^5.7" + "phpunit/phpunit": "^6.0" }, "suggest": { "symfony/yaml": "If you want to use YAML Metadata Mapping Driver" diff --git a/tests/Doctrine/Tests/DoctrineTestCase.php b/tests/Doctrine/Tests/DoctrineTestCase.php index e5ce27af91d..457f52f366c 100644 --- a/tests/Doctrine/Tests/DoctrineTestCase.php +++ b/tests/Doctrine/Tests/DoctrineTestCase.php @@ -2,9 +2,11 @@ namespace Doctrine\Tests; +use PHPUnit\Framework\TestCase; + /** * Base testcase class for all Doctrine testcases. */ -abstract class DoctrineTestCase extends \PHPUnit_Framework_TestCase +abstract class DoctrineTestCase extends TestCase { } diff --git a/tests/Doctrine/Tests/ORM/ConfigurationTest.php b/tests/Doctrine/Tests/ORM/ConfigurationTest.php index 1b0042064f3..df74c6df246 100644 --- a/tests/Doctrine/Tests/ORM/ConfigurationTest.php +++ b/tests/Doctrine/Tests/ORM/ConfigurationTest.php @@ -17,13 +17,13 @@ use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\Tests\Models\DDC753\DDC753CustomRepository; use ReflectionClass; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; /** * Tests for the Configuration object * @author Marco Pivetta */ -class ConfigurationTest extends PHPUnit_Framework_TestCase +class ConfigurationTest extends TestCase { /** * @var Configuration diff --git a/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php b/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php index 1e9f55d43ff..b8688d871db 100644 --- a/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php +++ b/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php @@ -5,8 +5,9 @@ use Doctrine\ORM\Decorator\EntityManagerDecorator; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query\ResultSetMapping; +use PHPUnit\Framework\TestCase; -class EntityManagerDecoratorTest extends \PHPUnit_Framework_TestCase +class EntityManagerDecoratorTest extends TestCase { const VOID_METHODS = [ 'persist', diff --git a/tests/Doctrine/Tests/ORM/EntityNotFoundExceptionTest.php b/tests/Doctrine/Tests/ORM/EntityNotFoundExceptionTest.php index bc4979000e8..ec1cfbfc99c 100644 --- a/tests/Doctrine/Tests/ORM/EntityNotFoundExceptionTest.php +++ b/tests/Doctrine/Tests/ORM/EntityNotFoundExceptionTest.php @@ -3,13 +3,14 @@ namespace Doctrine\Tests\ORM; use Doctrine\ORM\EntityNotFoundException; +use PHPUnit\Framework\TestCase; /** * Tests for {@see \Doctrine\ORM\EntityNotFoundException} * * @covers \Doctrine\ORM\EntityNotFoundException */ -class EntityNotFoundExceptionTest extends \PHPUnit_Framework_TestCase +class EntityNotFoundExceptionTest extends TestCase { public function testFromClassNameAndIdentifier() { diff --git a/tests/Doctrine/Tests/ORM/Event/OnClassMetadataNotFoundEventArgsTest.php b/tests/Doctrine/Tests/ORM/Event/OnClassMetadataNotFoundEventArgsTest.php index 54f2feb0dd8..e5f62bd26ae 100644 --- a/tests/Doctrine/Tests/ORM/Event/OnClassMetadataNotFoundEventArgsTest.php +++ b/tests/Doctrine/Tests/ORM/Event/OnClassMetadataNotFoundEventArgsTest.php @@ -5,14 +5,14 @@ use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\Common\Persistence\ObjectManager; use Doctrine\ORM\Event\OnClassMetadataNotFoundEventArgs; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; /** * Tests for {@see \Doctrine\ORM\Event\OnClassMetadataNotFoundEventArgs} * * @covers \Doctrine\ORM\Event\OnClassMetadataNotFoundEventArgs */ -class OnClassMetadataNotFoundEventArgsTest extends PHPUnit_Framework_TestCase +class OnClassMetadataNotFoundEventArgsTest extends TestCase { public function testEventArgsMutability() { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2359Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2359Test.php index ba8a621d59b..21a932ed36d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2359Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2359Test.php @@ -8,11 +8,12 @@ use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataFactory; +use PHPUnit\Framework\TestCase; /** * @group DDC-2359 */ -class DDC2359Test extends \PHPUnit_Framework_TestCase +class DDC2359Test extends TestCase { /** diff --git a/tests/Doctrine/Tests/ORM/Internal/HydrationCompleteHandlerTest.php b/tests/Doctrine/Tests/ORM/Internal/HydrationCompleteHandlerTest.php index 851cc2ae370..27b23f5128f 100644 --- a/tests/Doctrine/Tests/ORM/Internal/HydrationCompleteHandlerTest.php +++ b/tests/Doctrine/Tests/ORM/Internal/HydrationCompleteHandlerTest.php @@ -25,7 +25,7 @@ use Doctrine\ORM\Events; use Doctrine\ORM\Internal\HydrationCompleteHandler; use Doctrine\ORM\Mapping\ClassMetadata; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; use stdClass; /** @@ -33,7 +33,7 @@ * * @covers \Doctrine\ORM\Internal\HydrationCompleteHandler */ -class HydrationCompleteHandlerTest extends PHPUnit_Framework_TestCase +class HydrationCompleteHandlerTest extends TestCase { /** * @var \Doctrine\ORM\Event\ListenersInvoker|\PHPUnit_Framework_MockObject_MockObject diff --git a/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php b/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php index 3015341d951..9286da614f8 100644 --- a/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php @@ -6,6 +6,7 @@ use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\LazyCriteriaCollection; use Doctrine\ORM\Persisters\Entity\EntityPersister; +use PHPUnit\Framework\TestCase; use stdClass; /** @@ -13,7 +14,7 @@ * * @covers \Doctrine\ORM\LazyCriteriaCollection */ -class LazyCriteriaCollectionTest extends \PHPUnit_Framework_TestCase +class LazyCriteriaCollectionTest extends TestCase { /** * @var \Doctrine\ORM\Persisters\Entity\EntityPersister|\PHPUnit_Framework_MockObject_MockObject diff --git a/tests/Doctrine/Tests/ORM/Mapping/Reflection/ReflectionPropertiesGetterTest.php b/tests/Doctrine/Tests/ORM/Mapping/Reflection/ReflectionPropertiesGetterTest.php index 06a895159c5..29906d59b9d 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/Reflection/ReflectionPropertiesGetterTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/Reflection/ReflectionPropertiesGetterTest.php @@ -7,7 +7,7 @@ use Doctrine\ORM\Mapping\Reflection\ReflectionPropertiesGetter; use Doctrine\Tests\Models\Reflection\ClassWithMixedProperties; use Doctrine\Tests\Models\Reflection\ParentClass; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; use ReflectionClass; /** @@ -15,7 +15,7 @@ * * @covers \Doctrine\ORM\Mapping\Reflection\ReflectionPropertiesGetter */ -class ReflectionPropertiesGetterTest extends PHPUnit_Framework_TestCase +class ReflectionPropertiesGetterTest extends TestCase { public function testRetrievesProperties() { diff --git a/tests/Doctrine/Tests/ORM/Mapping/ReflectionEmbeddedPropertyTest.php b/tests/Doctrine/Tests/ORM/Mapping/ReflectionEmbeddedPropertyTest.php index 04ed194a62f..82761282ad4 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ReflectionEmbeddedPropertyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ReflectionEmbeddedPropertyTest.php @@ -9,6 +9,7 @@ use Doctrine\Tests\Models\Reflection\AbstractEmbeddable; use Doctrine\Tests\Models\Reflection\ArrayObjectExtendingClass; use Doctrine\Tests\Models\Reflection\ConcreteEmbeddable; +use PHPUnit\Framework\TestCase; use ReflectionProperty; /** @@ -16,7 +17,7 @@ * * @covers \Doctrine\ORM\Mapping\ReflectionEmbeddedProperty */ -class ReflectionEmbeddedPropertyTest extends \PHPUnit_Framework_TestCase +class ReflectionEmbeddedPropertyTest extends TestCase { /** * @param ReflectionProperty $parentProperty property of the embeddable/entity where to write the embeddable to diff --git a/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php index 082ebaf94be..85b3b2138dd 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php @@ -2,11 +2,12 @@ namespace Doctrine\Tests\ORM\Mapping\Symfony; use Doctrine\Common\Persistence\Mapping\MappingException; +use PHPUnit\Framework\TestCase; /** * @group DDC-1418 */ -abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase +abstract class AbstractDriverTest extends TestCase { public function testFindMappingFile() { diff --git a/tests/Doctrine/Tests/ORM/ORMInvalidArgumentExceptionTest.php b/tests/Doctrine/Tests/ORM/ORMInvalidArgumentExceptionTest.php index 81f22e2b7dc..b4d26907854 100644 --- a/tests/Doctrine/Tests/ORM/ORMInvalidArgumentExceptionTest.php +++ b/tests/Doctrine/Tests/ORM/ORMInvalidArgumentExceptionTest.php @@ -21,12 +21,13 @@ use Doctrine\Tests\Models\GeoNames\City; use Doctrine\Tests\Models\GeoNames\Country; use Doctrine\Tests\OrmTestCase; +use PHPUnit\Framework\TestCase; use stdClass; /** * @covers \Doctrine\ORM\ORMInvalidArgumentException */ -class ORMInvalidArgumentExceptionTest extends \PHPUnit_Framework_TestCase +class ORMInvalidArgumentExceptionTest extends TestCase { /** * @dataProvider invalidEntityNames diff --git a/tests/Doctrine/Tests/ORM/Query/ParserResultTest.php b/tests/Doctrine/Tests/ORM/Query/ParserResultTest.php index 3d74e0f96c5..1b74654430e 100644 --- a/tests/Doctrine/Tests/ORM/Query/ParserResultTest.php +++ b/tests/Doctrine/Tests/ORM/Query/ParserResultTest.php @@ -5,8 +5,9 @@ use Doctrine\ORM\Query\Exec\AbstractSqlExecutor; use Doctrine\ORM\Query\ParserResult; use Doctrine\ORM\Query\ResultSetMapping; +use PHPUnit\Framework\TestCase; -class ParserResultTest extends \PHPUnit_Framework_TestCase +class ParserResultTest extends TestCase { public $parserResult; diff --git a/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php b/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php index 91b99f2e35f..4e7434c851f 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php @@ -9,13 +9,14 @@ use Doctrine\ORM\Query\Expr as QueryBuilder; use Doctrine\ORM\Query\Parameter; use Doctrine\ORM\Query\QueryExpressionVisitor; +use PHPUnit\Framework\TestCase; /** * Test for QueryExpressionVisitor * * @author Kirill chEbba Chebunin */ -class QueryExpressionVisitorTest extends \PHPUnit_Framework_TestCase +class QueryExpressionVisitorTest extends TestCase { /** * @var QueryExpressionVisitor diff --git a/tests/Doctrine/Tests/ORM/Repository/DefaultRepositoryFactoryTest.php b/tests/Doctrine/Tests/ORM/Repository/DefaultRepositoryFactoryTest.php index 963757618af..85a63404618 100644 --- a/tests/Doctrine/Tests/ORM/Repository/DefaultRepositoryFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Repository/DefaultRepositoryFactoryTest.php @@ -8,14 +8,14 @@ use Doctrine\ORM\Repository\DefaultRepositoryFactory; use Doctrine\Tests\Models\DDC753\DDC753DefaultRepository; use Doctrine\Tests\Models\DDC869\DDC869PaymentRepository; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; /** * Tests for {@see \Doctrine\ORM\Repository\DefaultRepositoryFactory} * * @covers \Doctrine\ORM\Repository\DefaultRepositoryFactory */ -class DefaultRepositoryFactoryTest extends PHPUnit_Framework_TestCase +class DefaultRepositoryFactoryTest extends TestCase { /** * @var \Doctrine\ORM\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 9a684785378..88fbc43ca15 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -16,6 +16,7 @@ use Doctrine\Tests\DbalTypes\Rot13Type; use Doctrine\Tests\EventListener\CacheMetadataListener; use Doctrine\Tests\Models; +use PHPUnit\Framework\AssertionFailedError; /** * Base testcase class for all functional ORM testcases. @@ -750,15 +751,15 @@ protected function _getEntityManager($config = null, $eventManager = null) { } /** - * @param \Exception $e + * @param \Throwable $e * * @return void * - * @throws \Exception + * @throws \Throwable */ - protected function onNotSuccessfulTest($e) + protected function onNotSuccessfulTest(\Throwable $e) { - if ($e instanceof \PHPUnit_Framework_AssertionFailedError) { + if ($e instanceof AssertionFailedError) { throw $e; } From 3d7a7346f7a30a6d397422033d0f8728eeeb9732 Mon Sep 17 00:00:00 2001 From: Sam-Burns Date: Fri, 31 Mar 2017 21:45:35 +0100 Subject: [PATCH 246/877] Quieting risky test warnings where tests do actually perform assertions --- tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php b/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php index 46e72245a22..064c0a799cb 100644 --- a/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php +++ b/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php @@ -24,6 +24,7 @@ public function assertValidDQL($dql, $debug = false) { try { $parserResult = $this->parseDql($dql); + $this->addToAssertionCount(1); } catch (QueryException $e) { if ($debug) { echo $e->getTraceAsString() . PHP_EOL; @@ -44,6 +45,7 @@ public function assertInvalidDQL($dql, $debug = false) echo $e->getMessage() . PHP_EOL; echo $e->getTraceAsString() . PHP_EOL; } + $this->addToAssertionCount(1); } } From 2c5e76c96187b512b3b51c14b68ec64c8c2dd857 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Fri, 7 Apr 2017 18:00:49 +0900 Subject: [PATCH 247/877] fix class name. --- docs/en/reference/second-level-cache.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/second-level-cache.rst b/docs/en/reference/second-level-cache.rst index 07f39a34f99..b55376561ca 100644 --- a/docs/en/reference/second-level-cache.rst +++ b/docs/en/reference/second-level-cache.rst @@ -220,7 +220,7 @@ To specify a default lifetime for all regions or specify a different lifetime fo getSecondLevelCacheConfiguration(); $regionConfig = $cacheConfig->getRegionsConfiguration(); From f537eb2915edda7820b53ff2f94bf395ed489ff7 Mon Sep 17 00:00:00 2001 From: mike Date: Tue, 4 Apr 2017 22:12:38 +0200 Subject: [PATCH 248/877] Add a table name type that accept quoted table name --- doctrine-mapping.xsd | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/doctrine-mapping.xsd b/doctrine-mapping.xsd index bb8624190e1..c0c2d462335 100644 --- a/doctrine-mapping.xsd +++ b/doctrine-mapping.xsd @@ -191,7 +191,7 @@ - + @@ -200,6 +200,13 @@ + + + + + + + From b43325760ddddf4983768c7eae802a3644837c5f Mon Sep 17 00:00:00 2001 From: mike Date: Tue, 4 Apr 2017 22:13:21 +0200 Subject: [PATCH 249/877] Add a type for the class FQCN --- doctrine-mapping.xsd | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/doctrine-mapping.xsd b/doctrine-mapping.xsd index c0c2d462335..e220ab71441 100644 --- a/doctrine-mapping.xsd +++ b/doctrine-mapping.xsd @@ -419,9 +419,16 @@ - + + + + + + + + From 0865181702428fd0f94bfe48c8606744ec191b93 Mon Sep 17 00:00:00 2001 From: mike Date: Tue, 4 Apr 2017 22:15:02 +0200 Subject: [PATCH 250/877] Do not force an order of definition in the entity elements --- doctrine-mapping.xsd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doctrine-mapping.xsd b/doctrine-mapping.xsd index e220ab71441..303a26027ab 100644 --- a/doctrine-mapping.xsd +++ b/doctrine-mapping.xsd @@ -167,7 +167,7 @@ - + @@ -189,7 +189,7 @@ - + From e798bfe34a4ec2b685567717f18b747508a47b5c Mon Sep 17 00:00:00 2001 From: Sergio Santoro Date: Mon, 29 Jun 2015 22:05:26 +0200 Subject: [PATCH 251/877] [QUERY] "INSTANCE OF" now behaves correctly with subclasses There was a bug in the "INSTANCE OF" operator as described in https://groups.google.com/forum/#!topic/doctrine-user/B8raq8CNMgg "INSTANCE OF" was not taking into account subclasses. It was merely translating the class to its discriminator. This is not correct since the class can have subtypes and those are, indeed, still instance of the superclass. Also, classes may not have a discriminator (e.g. abstract classes). This commit also provides useful tests to avoid regression. --- lib/Doctrine/ORM/Query/SqlWalker.php | 34 ++-- .../ORM/Functional/InstanceOfAbstractTest.php | 113 +++++++++++++ .../Functional/InstanceOfMultiLevelTest.php | 153 ++++++++++++++++++ .../Tests/ORM/Functional/InstanceOfTest.php | 119 ++++++++++++++ .../ORM/Query/SelectSqlGenerationTest.php | 6 +- 5 files changed, 411 insertions(+), 14 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/InstanceOfMultiLevelTest.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/InstanceOfTest.php diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 57287c7cb47..62350c389f4 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -2038,8 +2038,10 @@ public function walkInstanceOfExpression($instanceOfExpr) $sql .= $class->discriminatorColumn['name'] . ($instanceOfExpr->not ? ' NOT IN ' : ' IN '); - $sqlParameterList = []; + $knownSubclasses = array_flip($discrClass->subClasses); + $sqlParameterList = []; + $discriminators = []; foreach ($instanceOfExpr->value as $parameter) { if ($parameter instanceof AST\InputParameter) { $this->rsm->addMetadataParameterMapping($parameter->name, 'discriminatorValue'); @@ -2049,21 +2051,31 @@ public function walkInstanceOfExpression($instanceOfExpr) continue; } - // Get name from ClassMetadata to resolve aliases. - $entityClassName = $this->em->getClassMetadata($parameter)->name; - $discriminatorValue = $class->discriminatorValue; + // Trim first backslash + $parameter = ltrim($parameter, '\\'); - if ($entityClassName !== $class->name) { - $discrMap = array_flip($class->discriminatorMap); + // Check parameter is really in the hierarchy + if ($parameter !== $discrClass->name && ! array_key_exists($parameter, $knownSubclasses)) { + throw QueryException::instanceOfUnrelatedClass($parameter, $discrClass->name); + } - if ( ! isset($discrMap[$entityClassName])) { - throw QueryException::instanceOfUnrelatedClass($entityClassName, $class->rootEntityName); - } + // Include discriminators for parameter class and its subclass + $metadata = $this->em->getClassMetadata($parameter); + $hierarchyClasses = $metadata->subClasses; + $hierarchyClasses[] = $metadata->name; - $discriminatorValue = $discrMap[$entityClassName]; + foreach ($hierarchyClasses as $class) { + $currentMetadata = $this->em->getClassMetadata($class); + $currentDiscriminator = $currentMetadata->discriminatorValue; + + if (is_string($currentDiscriminator) && ! array_key_exists($currentDiscriminator, $discriminators)) { + $discriminators[$currentDiscriminator] = true; + } } + } - $sqlParameterList[] = $this->conn->quote($discriminatorValue); + foreach (array_keys($discriminators) as $dis) { + $sqlParameterList[] = $this->conn->quote($dis); } $sql .= '(' . implode(', ', $sqlParameterList) . ')'; diff --git a/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php b/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php new file mode 100644 index 00000000000..a84643f84d4 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php @@ -0,0 +1,113 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfAbstractTest\Person'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfAbstractTest\Employee'), + )); + } + + public function testInstanceOf() + { + $this->loadData(); + + $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Person p + WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Person'; + $query = $this->_em->createQuery($dql); + $result = $query->getResult(); + + $this->assertCount(1, $result); + + foreach ($result as $r) { + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Person', $r); + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Employee', $r); + $this->assertEquals('bar', $r->getName()); + } + } + + private function loadData() + { + $employee = new InstanceOfAbstractTest\Employee(); + $employee->setName('bar'); + $employee->setDepartement('qux'); + + $this->_em->persist($employee); + + $this->_em->flush($employee); + } + } +} + +namespace Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest { + + /** + * @Entity() + * @Table(name="instance_of_abstract_test_person") + * @InheritanceType(value="JOINED") + * @DiscriminatorColumn(name="kind", type="string") + * @DiscriminatorMap(value={ + * "employee": "Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Employee" + * }) + */ + abstract class Person + { + /** + * @Id() + * @GeneratedValue() + * @Column(type="integer") + */ + private $id; + + /** + * @Column(type="string") + */ + private $name; + + public function getId() + { + return $this->id; + } + + public function getName() + { + return $this->name; + } + + public function setName($name) + { + $this->name = $name; + } + } + + /** + * @Entity() + * @Table(name="instance_of_abstract_test_employee") + */ + class Employee extends Person + { + /** + * @Column(type="string") + */ + private $departement; + + public function getDepartement() + { + return $this->departement; + } + + public function setDepartement($departement) + { + $this->departement = $departement; + } + } + +} diff --git a/tests/Doctrine/Tests/ORM/Functional/InstanceOfMultiLevelTest.php b/tests/Doctrine/Tests/ORM/Functional/InstanceOfMultiLevelTest.php new file mode 100644 index 00000000000..c4b5bbcd2c3 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/InstanceOfMultiLevelTest.php @@ -0,0 +1,153 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfMultiLevelTest\Person'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfMultiLevelTest\Employee'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfMultiLevelTest\Engineer'), + )); + } + + public function testInstanceOf() + { + $this->loadData(); + + $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Person p + WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Person'; + $query = $this->_em->createQuery($dql); + $result = $query->getResult(); + + $this->assertCount(3, $result); + + foreach ($result as $r) { + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Person', $r); + if ($r instanceof InstanceOfMultiLevelTest\Engineer) { + $this->assertEquals('foobar', $r->getName()); + $this->assertEquals('doctrine', $r->getSpecialization()); + } elseif ($r instanceof InstanceOfMultiLevelTest\Employee) { + $this->assertEquals('bar', $r->getName()); + $this->assertEquals('qux', $r->getDepartement()); + } else { + $this->assertEquals('foo', $r->getName()); + } + } + } + + private function loadData() + { + $person = new InstanceOfMultiLevelTest\Person(); + $person->setName('foo'); + + $employee = new InstanceOfMultiLevelTest\Employee(); + $employee->setName('bar'); + $employee->setDepartement('qux'); + + $engineer = new InstanceOfMultiLevelTest\Engineer(); + $engineer->setName('foobar'); + $engineer->setDepartement('dep'); + $engineer->setSpecialization('doctrine'); + + $this->_em->persist($person); + $this->_em->persist($employee); + $this->_em->persist($engineer); + + $this->_em->flush(array($person, $employee, $engineer)); + } + } +} + +namespace Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest { + /** + * @Entity() + * @Table(name="instance_of_multi_level_test_person") + * @InheritanceType(value="JOINED") + * @DiscriminatorColumn(name="kind", type="string") + * @DiscriminatorMap(value={ + * "person": "Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Person", + * "employee": "Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Employee", + * "engineer": "Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Engineer", + * }) + */ + class Person + { + /** + * @Id() + * @GeneratedValue() + * @Column(type="integer") + */ + private $id; + + /** + * @Column(type="string") + */ + private $name; + + public function getId() + { + return $this->id; + } + + public function getName() + { + return $this->name; + } + + public function setName($name) + { + $this->name = $name; + } + } + + /** + * @Entity() + * @Table(name="instance_of_multi_level_employee") + */ + class Employee extends Person + { + /** + * @Column(type="string") + */ + private $departement; + + public function getDepartement() + { + return $this->departement; + } + + public function setDepartement($departement) + { + $this->departement = $departement; + } + } + + /** + * @Entity() + * @Table(name="instance_of_multi_level_engineer") + */ + class Engineer extends Employee + { + /** + * @Column(type="string") + */ + private $specialization; + + public function getSpecialization() + { + return $this->specialization; + } + + public function setSpecialization($specialization) + { + $this->specialization = $specialization; + } + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/InstanceOfTest.php b/tests/Doctrine/Tests/ORM/Functional/InstanceOfTest.php new file mode 100644 index 00000000000..7f593c3f4a6 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/InstanceOfTest.php @@ -0,0 +1,119 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfTest\Person'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfTest\Employee'), + )); + } + + public function testInstanceOf() + { + $this->loadData(); + + $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\InstanceOfTest\Person p + WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\InstanceOfTest\Person'; + $query = $this->_em->createQuery($dql); + $result = $query->getResult(); + + $this->assertCount(2, $result); + + foreach ($result as $r) { + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\InstanceOfTest\Person', $r); + if ($r instanceof InstanceOfTest\Employee) { + $this->assertEquals('bar', $r->getName()); + } else { + $this->assertEquals('foo', $r->getName()); + } + } + } + + private function loadData() + { + $person = new InstanceOfTest\Person(); + $person->setName('foo'); + + $employee = new InstanceOfTest\Employee(); + $employee->setName('bar'); + $employee->setDepartement('qux'); + + $this->_em->persist($person); + $this->_em->persist($employee); + + $this->_em->flush(array($person, $employee)); + } + } +} + +namespace Doctrine\Tests\ORM\Functional\InstanceOfTest { + /** + * @Entity() + * @Table(name="instance_of_test_person") + * @InheritanceType(value="JOINED") + * @DiscriminatorColumn(name="kind", type="string") + * @DiscriminatorMap(value={ + * "person": "Doctrine\Tests\ORM\Functional\InstanceOfTest\Person", + * "employee": "Doctrine\Tests\ORM\Functional\InstanceOfTest\Employee" + * }) + */ + class Person + { + /** + * @Id() + * @GeneratedValue() + * @Column(type="integer") + */ + private $id; + + /** + * @Column(type="string") + */ + private $name; + + public function getId() + { + return $this->id; + } + + public function getName() + { + return $this->name; + } + + public function setName($name) + { + $this->name = $name; + } + } + + /** + * @Entity() + * @Table(name="instance_of_test_employee") + */ + class Employee extends Person + { + /** + * @Column(type="string") + */ + private $departement; + + public function getDepartement() + { + return $this->departement; + } + + public function setDepartement($departement) + { + $this->departement = $departement; + } + } +} diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index b6bdce3233b..f9fb0b82077 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -502,7 +502,7 @@ public function testSupportsInstanceOfExpressionsInWherePart() { $this->assertSqlGeneration( "SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF Doctrine\Tests\Models\Company\CompanyEmployee", - "SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.discr AS discr_2 FROM company_persons c0_ WHERE c0_.discr IN ('employee')" + "SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.discr AS discr_2 FROM company_persons c0_ WHERE c0_.discr IN ('manager', 'employee')" ); } @@ -511,7 +511,7 @@ public function testSupportsInstanceOfExpressionInWherePartWithMultipleValues() // This also uses FQCNs starting with or without a backslash in the INSTANCE OF parameter $this->assertSqlGeneration( "SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF (Doctrine\Tests\Models\Company\CompanyEmployee, \Doctrine\Tests\Models\Company\CompanyManager)", - "SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.discr AS discr_2 FROM company_persons c0_ WHERE c0_.discr IN ('employee', 'manager')" + "SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.discr AS discr_2 FROM company_persons c0_ WHERE c0_.discr IN ('manager', 'employee')" ); } @@ -522,7 +522,7 @@ public function testSupportsInstanceOfExpressionsInWherePartPrefixedSlash() { $this->assertSqlGeneration( "SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF \Doctrine\Tests\Models\Company\CompanyEmployee", - "SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.discr AS discr_2 FROM company_persons c0_ WHERE c0_.discr IN ('employee')" + "SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.discr AS discr_2 FROM company_persons c0_ WHERE c0_.discr IN ('manager', 'employee')" ); } From 7e50a965fa1baf599b0f0b90dc32dcb5ce71cea0 Mon Sep 17 00:00:00 2001 From: Yannick de Lange Date: Wed, 12 Apr 2017 23:09:48 +0200 Subject: [PATCH 252/877] Updated broken links Updated all links pointing to http://www.doctrine-project.org/documentation/* to their http://docs.doctrine-project.org counterparts --- docs/en/cookbook/dql-user-defined-functions.rst | 2 +- docs/en/cookbook/implementing-wakeup-or-clone.rst | 2 +- docs/en/cookbook/integrating-with-codeigniter.rst | 2 +- docs/en/tutorials/getting-started.rst | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/en/cookbook/dql-user-defined-functions.rst b/docs/en/cookbook/dql-user-defined-functions.rst index a3a7606ad80..3278319d249 100644 --- a/docs/en/cookbook/dql-user-defined-functions.rst +++ b/docs/en/cookbook/dql-user-defined-functions.rst @@ -132,7 +132,7 @@ dql statement. The ``ArithmeticPrimary`` method call is the most common denominator of valid EBNF tokens taken from the -`DQL EBNF grammar `_ +`DQL EBNF grammar `_ that matches our requirements for valid input into the DateDiff Dql function. Picking the right tokens for your methods is a tricky business, but the EBNF grammar is pretty helpful finding it, as is diff --git a/docs/en/cookbook/implementing-wakeup-or-clone.rst b/docs/en/cookbook/implementing-wakeup-or-clone.rst index 6a8ef9c91a7..93c2e54f4f7 100644 --- a/docs/en/cookbook/implementing-wakeup-or-clone.rst +++ b/docs/en/cookbook/implementing-wakeup-or-clone.rst @@ -4,7 +4,7 @@ Implementing Wakeup or Clone .. sectionauthor:: Roman Borschel (roman@code-factory.org) As explained in the -`restrictions for entity classes in the manual `_, +`restrictions for entity classes in the manual `_, it is usually not allowed for an entity to implement ``__wakeup`` or ``__clone``, because Doctrine makes special use of them. However, it is quite easy to make use of these methods in a safe diff --git a/docs/en/cookbook/integrating-with-codeigniter.rst b/docs/en/cookbook/integrating-with-codeigniter.rst index 1c06a34e2c4..49c5403aaf0 100644 --- a/docs/en/cookbook/integrating-with-codeigniter.rst +++ b/docs/en/cookbook/integrating-with-codeigniter.rst @@ -111,7 +111,7 @@ APC, get rid of EchoSqlLogger, and turn off autoGenerateProxyClasses. For more details, consult the -`Doctrine 2 Configuration documentation `_. +`Doctrine 2 Configuration documentation `_. Now to use it ------------- diff --git a/docs/en/tutorials/getting-started.rst b/docs/en/tutorials/getting-started.rst index c8247e21c45..5cbcfb17059 100644 --- a/docs/en/tutorials/getting-started.rst +++ b/docs/en/tutorials/getting-started.rst @@ -162,7 +162,7 @@ read up on the configuration details in the The third block shows the configuration options required to connect to a database, in my case a file-based sqlite database. All the configuration options for all the shipped drivers are given in the -`DBAL Configuration section of the manual `_. +`DBAL Configuration section of the manual `_. The last block shows how the ``EntityManager`` is obtained from a factory method. From 6b6c3003193d858546b4c34c1cb21ef758cfd709 Mon Sep 17 00:00:00 2001 From: Richard Henry Date: Sat, 15 Apr 2017 00:11:39 +0100 Subject: [PATCH 253/877] Fix incorrect YAML example for versioning a field. --- docs/en/reference/transactions-and-concurrency.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/reference/transactions-and-concurrency.rst b/docs/en/reference/transactions-and-concurrency.rst index 1b79adc577e..c962232e6c7 100644 --- a/docs/en/reference/transactions-and-concurrency.rst +++ b/docs/en/reference/transactions-and-concurrency.rst @@ -214,8 +214,8 @@ example we'll use an integer. type: entity fields: version: - version: - type: integer + type: integer + version: true Alternatively a datetime type can be used (which maps to a SQL timestamp or datetime): From e44a83fc7bce112c6996f32c2c179132264a9078 Mon Sep 17 00:00:00 2001 From: Richard Henry Date: Sat, 15 Apr 2017 01:18:44 +0100 Subject: [PATCH 254/877] Fix incorrect YAML datetime version field. --- docs/en/reference/transactions-and-concurrency.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/reference/transactions-and-concurrency.rst b/docs/en/reference/transactions-and-concurrency.rst index c962232e6c7..5ce0852b2a7 100644 --- a/docs/en/reference/transactions-and-concurrency.rst +++ b/docs/en/reference/transactions-and-concurrency.rst @@ -247,8 +247,8 @@ timestamp or datetime): type: entity fields: version: - version: - type: datetime + type: datetime + version: true Version numbers (not timestamps) should however be preferred as they can not potentially conflict in a highly concurrent From 4eb4465169fb386c5bcdb0b25b316ad9f477562a Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Tue, 18 Apr 2017 11:57:49 +0200 Subject: [PATCH 255/877] Fix as per review --- .../Tests/ORM/Functional/InstanceOfAbstractTest.php | 7 +++---- tests/Doctrine/Tests/ORM/Functional/InstanceOfTest.php | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php b/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php index a84643f84d4..3a52d93f96c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php @@ -28,9 +28,9 @@ public function testInstanceOf() $this->assertCount(1, $result); foreach ($result as $r) { - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Person', $r); - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Employee', $r); - $this->assertEquals('bar', $r->getName()); + $this->assertInstanceOf(InstanceOfAbstractTest\Person::class, $r); + $this->assertInstanceOf(InstanceOfAbstractTest\Employee::class, $r); + $this->assertSame('bar', $r->getName()); } } @@ -109,5 +109,4 @@ public function setDepartement($departement) $this->departement = $departement; } } - } diff --git a/tests/Doctrine/Tests/ORM/Functional/InstanceOfTest.php b/tests/Doctrine/Tests/ORM/Functional/InstanceOfTest.php index 7f593c3f4a6..fce0075b63f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/InstanceOfTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/InstanceOfTest.php @@ -10,10 +10,10 @@ protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema([ $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfTest\Person'), $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfTest\Employee'), - )); + ]); } public function testInstanceOf() @@ -28,7 +28,7 @@ public function testInstanceOf() $this->assertCount(2, $result); foreach ($result as $r) { - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\InstanceOfTest\Person', $r); + $this->assertInstanceOf(InstanceOfTest\Person::class, $r); if ($r instanceof InstanceOfTest\Employee) { $this->assertEquals('bar', $r->getName()); } else { From 692a1afa86ab83eba4173471202af9364bf90d40 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Sat, 22 Apr 2017 00:05:57 +0900 Subject: [PATCH 256/877] Minor typo naming strategy documentation --- docs/en/reference/namingstrategy.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/reference/namingstrategy.rst b/docs/en/reference/namingstrategy.rst index 9f8e4a599a2..fff5e601a89 100644 --- a/docs/en/reference/namingstrategy.rst +++ b/docs/en/reference/namingstrategy.rst @@ -20,7 +20,7 @@ You can specify a different strategy by calling ``Doctrine\ORM\Configuration#set setNamingStrategy($namingStrategy); + $configuration->setNamingStrategy($namingStrategy); Underscore naming strategy --------------------------- @@ -31,7 +31,7 @@ Underscore naming strategy setNamingStrategy($namingStrategy); + $configuration->setNamingStrategy($namingStrategy); For SomeEntityName the strategy will generate the table SOME_ENTITY_NAME with the ``CASE_UPPER`` option, or some_entity_name with the ``CASE_LOWER`` option. From 38bfcc6a7ad264b880b847b69cafa10e3df5cf5d Mon Sep 17 00:00:00 2001 From: Jarek Jakubowski Date: Tue, 25 Apr 2017 11:01:17 +0200 Subject: [PATCH 257/877] Fix notice in ClassMetadata when there is no ID Column defined When you forget about defining the ID/PK Column, then this ugly Notice appear. Now it will throw nice Exception. --- .../ORM/Mapping/ClassMetadataInfo.php | 8 +++++-- lib/Doctrine/ORM/Mapping/MappingException.php | 10 +++++++++ .../Tests/Models/DDC6412/DDC6412File.php | 21 +++++++++++++++++++ .../Tests/ORM/Mapping/ClassMetadataTest.php | 10 +++++++++ 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 tests/Doctrine/Tests/Models/DDC6412/DDC6412File.php diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 9a581116391..ce3cd8685f8 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -1796,13 +1796,17 @@ public function getIdentifierFieldNames() * * @return string * - * @throws MappingException If the class has a composite primary key. + * @throws MappingException If the class doesn't have an identifier or it has a composite primary key. */ public function getSingleIdentifierFieldName() { if ($this->isIdentifierComposite) { throw MappingException::singleIdNotAllowedOnCompositePrimaryKey($this->name); } + + if ( ! isset($this->identifier[0])) { + throw MappingException::noIdDefined($this->name); + } return $this->identifier[0]; } @@ -1813,7 +1817,7 @@ public function getSingleIdentifierFieldName() * * @return string * - * @throws MappingException If the class has a composite primary key. + * @throws MappingException If the class doesn't have an identifier or it has a composite primary key. */ public function getSingleIdentifierColumnName() { diff --git a/lib/Doctrine/ORM/Mapping/MappingException.php b/lib/Doctrine/ORM/Mapping/MappingException.php index 97686d6544e..7dc4405159a 100644 --- a/lib/Doctrine/ORM/Mapping/MappingException.php +++ b/lib/Doctrine/ORM/Mapping/MappingException.php @@ -424,6 +424,16 @@ public static function singleIdNotAllowedOnCompositePrimaryKey($entity) return new self('Single id is not allowed on composite primary key in entity '.$entity); } + /** + * @param string $entity + * + * @return MappingException + */ + public static function noIdDefined($entity) + { + return new self('No ID defined for entity ' . $entity); + } + /** * @param string $entity * @param string $fieldName diff --git a/tests/Doctrine/Tests/Models/DDC6412/DDC6412File.php b/tests/Doctrine/Tests/Models/DDC6412/DDC6412File.php new file mode 100644 index 00000000000..64551cdf4fb --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC6412/DDC6412File.php @@ -0,0 +1,21 @@ +getSingleIdentifierFieldName(); } + public function testGetSingleIdentifierFieldName_NoIdEntity_ThrowsException() + { + $cm = new ClassMetadata(DDC6412File::class); + $cm->initializeReflection(new RuntimeReflectionService()); + + $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); + $cm->getSingleIdentifierFieldName(); + } + public function testDuplicateAssociationMappingException() { $cm = new ClassMetadata(CMS\CmsUser::class); From a557c97a93adc1c7c0232e78290cce842a92a6bd Mon Sep 17 00:00:00 2001 From: Vytautas Stankus Date: Thu, 13 Apr 2017 16:25:44 +0300 Subject: [PATCH 258/877] Add support for STARTS_WITH and ENDS_WITH comparison operators --- composer.json | 2 +- .../reference/working-with-associations.rst | 2 ++ .../Entity/BasicEntityPersister.php | 22 +++++++------ .../ORM/Persisters/SqlValueVisitor.php | 16 ++++++++-- .../ORM/Query/QueryExpressionVisitor.php | 10 ++++++ .../ORM/Functional/EntityRepositoryTest.php | 32 +++++++++++++++++++ .../ORM/Query/QueryExpressionVisitorTest.php | 3 ++ 7 files changed, 73 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index 5c0bf595844..780105f3bb7 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "require": { "php": "^7.0", "ext-pdo": "*", - "doctrine/collections": "~1.3", + "doctrine/collections": "^1.4", "doctrine/dbal": ">=2.5-dev,<2.7-dev", "doctrine/instantiator": "~1.0.1", "doctrine/common": "^2.7.1", diff --git a/docs/en/reference/working-with-associations.rst b/docs/en/reference/working-with-associations.rst index df7dd595552..e115efbc97e 100644 --- a/docs/en/reference/working-with-associations.rst +++ b/docs/en/reference/working-with-associations.rst @@ -716,6 +716,8 @@ methods: * ``in($field, array $values)`` * ``notIn($field, array $values)`` * ``contains($field, $value)`` +* ``startsWith($field, $value)`` +* ``endsWith($field, $value)`` .. note:: diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index e3d0a165f9c..5cccadbe2bb 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -87,16 +87,18 @@ class BasicEntityPersister implements EntityPersister * @var array */ static private $comparisonMap = [ - Comparison::EQ => '= %s', - Comparison::IS => '= %s', - Comparison::NEQ => '!= %s', - Comparison::GT => '> %s', - Comparison::GTE => '>= %s', - Comparison::LT => '< %s', - Comparison::LTE => '<= %s', - Comparison::IN => 'IN (%s)', - Comparison::NIN => 'NOT IN (%s)', - Comparison::CONTAINS => 'LIKE %s', + Comparison::EQ => '= %s', + Comparison::IS => '= %s', + Comparison::NEQ => '!= %s', + Comparison::GT => '> %s', + Comparison::GTE => '>= %s', + Comparison::LT => '< %s', + Comparison::LTE => '<= %s', + Comparison::IN => 'IN (%s)', + Comparison::NIN => 'NOT IN (%s)', + Comparison::CONTAINS => 'LIKE %s', + Comparison::STARTS_WITH => 'LIKE %s', + Comparison::ENDS_WITH => 'LIKE %s', ]; /** diff --git a/lib/Doctrine/ORM/Persisters/SqlValueVisitor.php b/lib/Doctrine/ORM/Persisters/SqlValueVisitor.php index 2b3bdedc440..c8df1919d9a 100644 --- a/lib/Doctrine/ORM/Persisters/SqlValueVisitor.php +++ b/lib/Doctrine/ORM/Persisters/SqlValueVisitor.php @@ -111,8 +111,18 @@ protected function getValueFromComparison(Comparison $comparison) { $value = $comparison->getValue()->getValue(); - return $comparison->getOperator() == Comparison::CONTAINS - ? "%{$value}%" - : $value; + switch ($comparison->getOperator()) { + case Comparison::CONTAINS: + return "%{$value}%"; + + case Comparison::STARTS_WITH: + return "{$value}%"; + + case Comparison::ENDS_WITH: + return "%{$value}"; + + default: + return $value; + } } } diff --git a/lib/Doctrine/ORM/Query/QueryExpressionVisitor.php b/lib/Doctrine/ORM/Query/QueryExpressionVisitor.php index dbdaeb40cb3..8b00d998eae 100644 --- a/lib/Doctrine/ORM/Query/QueryExpressionVisitor.php +++ b/lib/Doctrine/ORM/Query/QueryExpressionVisitor.php @@ -185,6 +185,16 @@ public function walkComparison(Comparison $comparison) $parameter->setValue('%' . $parameter->getValue() . '%', $parameter->getType()); $this->parameters[] = $parameter; + return $this->expr->like($field, $placeholder); + case Comparison::STARTS_WITH: + $parameter->setValue($parameter->getValue() . '%', $parameter->getType()); + $this->parameters[] = $parameter; + + return $this->expr->like($field, $placeholder); + case Comparison::ENDS_WITH: + $parameter->setValue('%' . $parameter->getValue(), $parameter->getType()); + $this->parameters[] = $parameter; + return $this->expr->like($field, $placeholder); default: $operator = self::convertComparisonOperator($comparison->getOperator()); diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php index d329b8556e3..ebc7acee973 100644 --- a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php @@ -910,6 +910,38 @@ public function testMatchingCriteriaContainsComparison() $this->assertEquals(2, count($users)); } + public function testMatchingCriteriaStartsWithComparison() + { + $this->loadFixture(); + + $repository = $this->_em->getRepository(CmsUser::class); + + $users = $repository->matching(new Criteria(Criteria::expr()->startsWith('name', 'Foo'))); + $this->assertCount(0, $users); + + $users = $repository->matching(new Criteria(Criteria::expr()->startsWith('name', 'R'))); + $this->assertCount(1, $users); + + $users = $repository->matching(new Criteria(Criteria::expr()->startsWith('status', 'de'))); + $this->assertCount(2, $users); + } + + public function testMatchingCriteriaEndsWithComparison() + { + $this->loadFixture(); + + $repository = $this->_em->getRepository(CmsUser::class); + + $users = $repository->matching(new Criteria(Criteria::expr()->endsWith('name', 'foo'))); + $this->assertCount(0, $users); + + $users = $repository->matching(new Criteria(Criteria::expr()->endsWith('name', 'oman'))); + $this->assertCount(1, $users); + + $users = $repository->matching(new Criteria(Criteria::expr()->endsWith('status', 'ev'))); + $this->assertCount(2, $users); + } + /** * @group DDC-2478 */ diff --git a/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php b/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php index 4e7434c851f..0e306ab06ea 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php @@ -68,6 +68,9 @@ public function comparisonData() [$cb->contains('field', 'value'), $qb->like('o.field', ':field'), new Parameter('field', '%value%')], + [$cb->startsWith('field', 'value'), $qb->like('o.field', ':field'), new Parameter('field', 'value%')], + [$cb->endsWith('field', 'value'), $qb->like('o.field', ':field'), new Parameter('field', '%value')], + // Test parameter conversion [$cb->eq('object.field', 'value'), $qb->eq('o.object.field', ':object_field'), new Parameter('object_field', 'value')], From ccaa4b8ce146d3b1e1a7eee5c049257a3b8b5c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Fri, 20 Jan 2017 00:59:53 +0100 Subject: [PATCH 259/877] Use `getMultiple()` to fetch associations as well --- lib/Doctrine/ORM/Cache/DefaultQueryCache.php | 19 ++++---- .../Tests/ORM/Cache/DefaultQueryCacheTest.php | 46 +++++++++++++++++-- 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php index 076fe3bebed..3ac20654780 100644 --- a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php +++ b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php @@ -122,11 +122,9 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = [] // @TODO - move to cache hydration component foreach ($entry->result as $index => $entry) { - $entityEntry = is_array($entries) && array_key_exists($index, $entries) ? $entries[$index] : null; if ($entityEntry === null) { - if ($this->cacheLogger !== null) { $this->cacheLogger->entityCacheMiss($regionName, $cacheKeys->identifiers[$index]); } @@ -139,7 +137,6 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = [] } if ( ! $hasRelation) { - $result[$index] = $this->uow->createEntity($entityEntry->class, $entityEntry->resolveAssociationEntries($this->em), self::$hints); continue; @@ -178,14 +175,20 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = [] continue; } - $collection = new PersistentCollection($this->em, $assocMetadata, new ArrayCollection()); + $generateKeys = function ($id) use ($assocMetadata): EntityCacheKey { + return new EntityCacheKey($assocMetadata->rootEntityName, $id); + }; - foreach ($assoc['list'] as $assocIndex => $assocId) { + $collection = new PersistentCollection($this->em, $assocMetadata, new ArrayCollection()); + $assocKeys = new CollectionCacheEntry(array_map($generateKeys, $assoc['list'])); + $assocEntries = $assocRegion->getMultiple($assocKeys); - if (($assocEntry = $assocRegion->get($assocKey = new EntityCacheKey($assocMetadata->rootEntityName, $assocId))) === null) { + foreach ($assoc['list'] as $assocIndex => $assocId) { + $assocEntry = is_array($assocEntries) && array_key_exists($assocIndex, $assocEntries) ? $assocEntries[$assocIndex] : null; + if ($assocEntry === null) { if ($this->cacheLogger !== null) { - $this->cacheLogger->entityCacheMiss($assocRegion->getName(), $assocKey); + $this->cacheLogger->entityCacheMiss($assocRegion->getName(), $assocKeys->identifiers[$assocIndex]); } $this->uow->hydrationComplete(); @@ -198,7 +201,7 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = [] $collection->hydrateSet($assocIndex, $element); if ($this->cacheLogger !== null) { - $this->cacheLogger->entityCacheHit($assocRegion->getName(), $assocKey); + $this->cacheLogger->entityCacheHit($assocRegion->getName(), $assocKeys->identifiers[$assocIndex]); } } diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php index e011159bd33..58eddd37509 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php @@ -125,8 +125,7 @@ public function testPutToOneAssociationQueryResult() $stateClass = $this->em->getClassMetadata(State::class); $rsm->addRootEntityFromClassMetadata(City::class, 'c'); - $rsm->addJoinedEntityFromClassMetadata(State::class, 's', 'c', 'state', ['id'=>'state_id', 'name'=>'state_name'] - ); + $rsm->addJoinedEntityFromClassMetadata(State::class, 's', 'c', 'state', ['id'=>'state_id', 'name'=>'state_name']); for ($i = 0; $i < 4; $i++) { $state = new State("State $i"); @@ -283,8 +282,47 @@ public function testGetBasicQueryResult() $key = new QueryCacheKey('query.key1', 0); $entry = new QueryCacheEntry( [ - ['identifier' => ['id' => 1]], - ['identifier' => ['id' => 2]] + ['identifier' => ['id' => 1]], + ['identifier' => ['id' => 2]] + ] + ); + + $data = [ + ['id'=>1, 'name' => 'Foo'], + ['id'=>2, 'name' => 'Bar'] + ]; + + $this->region->addReturn('get', $entry); + + $this->region->addReturn( + 'getMultiple', + [ + new EntityCacheEntry(Country::class, $data[0]), + new EntityCacheEntry(Country::class, $data[1]) + ] + ); + + $rsm->addRootEntityFromClassMetadata(Country::class, 'c'); + + $result = $this->queryCache->get($key, $rsm); + + $this->assertCount(2, $result); + $this->assertInstanceOf(Country::class, $result[0]); + $this->assertInstanceOf(Country::class, $result[1]); + $this->assertEquals(1, $result[0]->getId()); + $this->assertEquals(2, $result[1]->getId()); + $this->assertEquals('Foo', $result[0]->getName()); + $this->assertEquals('Bar', $result[1]->getName()); + } + + public function testGetWithAssociation() + { + $rsm = new ResultSetMappingBuilder($this->em); + $key = new QueryCacheKey('query.key1', 0); + $entry = new QueryCacheEntry( + [ + ['identifier' => ['id' => 1]], + ['identifier' => ['id' => 2]] ] ); From 7c6c5d87c82ad3bb1b4987f65f5201a99cede2d2 Mon Sep 17 00:00:00 2001 From: lemartin Date: Tue, 18 Apr 2017 19:25:02 +0200 Subject: [PATCH 260/877] Fix quoting issues related to ticket #6402 Apply quoting strategy to foreign key columns of one-to-one relation so that correct select statements are generated. And use unquoted column names in result mapping instead of quoted ones, as consumers (namely IdentifierFlattener) expect unquoted column names. --- .../Entity/BasicEntityPersister.php | 2 +- lib/Doctrine/ORM/Query/SqlWalker.php | 3 +- .../ORM/Functional/Ticket/GH6402Test.php | 66 +++++++++++++++++++ 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH6402Test.php diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 5cccadbe2bb..f3cdc705569 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -1329,7 +1329,7 @@ protected function getSelectColumnAssociationSQL($field, $assoc, ClassMetadata $ $resultColumnName = $this->getSQLColumnAlias($joinColumn['name']); $type = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em); - $this->currentPersisterContext->rsm->addMetaResult($alias, $resultColumnName, $quotedColumn, $isIdentifier, $type); + $this->currentPersisterContext->rsm->addMetaResult($alias, $resultColumnName, $joinColumn['name'], $isIdentifier, $type); $columnList[] = sprintf('%s.%s AS %s', $sqlTableAlias, $quotedColumn, $resultColumnName); } diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 57287c7cb47..310034e6916 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -764,7 +764,8 @@ public function walkSelectClause($selectClause) $columnAlias = $this->getSQLColumnAlias($columnName); $columnType = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em); - $sqlSelectExpressions[] = $sqlTableAlias . '.' . $columnName . ' AS ' . $columnAlias; + $quotedColumnName = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform); + $sqlSelectExpressions[] = $sqlTableAlias . '.' . $quotedColumnName . ' AS ' . $columnAlias; $this->rsm->addMetaResult($dqlAlias, $columnAlias, $columnName, $isIdentifier, $columnType); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6402Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6402Test.php new file mode 100644 index 00000000000..50450a6b98b --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6402Test.php @@ -0,0 +1,66 @@ +setUpEntitySchema([ + Address::class, + Group::class, + Phone::class, + User::class, + ]); + } catch (\Exception $exception) { + } + } + + public function testFind() + { + $id = $this->createAddress(); + + $address = $this->_em->find(Address::class, $id); + self::assertNotNull($address->user); + } + + public function testQuery() + { + $id = $this->createAddress(); + + $addresses = $this->_em->createQuery("SELECT a FROM " . Address::class . " a WHERE a.id = :id") + ->setParameter("id", $id) + ->getResult(); + + self::assertCount(1, $addresses); + self::assertNotNull($addresses[0]->user); + } + + private function createAddress() + { + $user = new User(); + $user->name = "foo"; + + $address = new Address(); + $address->zip = "bar"; + $user->setAddress($address); + + $this->_em->persist($user); + $this->_em->flush(); + $this->_em->clear(); + + return $address->id; + } +} From 942bb6cb1fdda9fa1192d3475c26b24b5c995b4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 30 Apr 2017 18:49:19 +0200 Subject: [PATCH 261/877] Remove dead code from OrmFunctionalTestCase --- tests/Doctrine/Tests/OrmFunctionalTestCase.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 88fbc43ca15..c1445eaeccf 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -616,14 +616,8 @@ protected function setUp() { $this->setUpDBALTypes(); - $forceCreateTables = false; - if ( ! isset(static::$_sharedConn)) { static::$_sharedConn = TestUtil::getConnection(); - - if (static::$_sharedConn->getDriver() instanceof SqliteDriver) { - $forceCreateTables = true; - } } if (isset($GLOBALS['DOCTRINE_MARK_SQL_LOGS'])) { @@ -642,7 +636,7 @@ protected function setUp() $classes = []; foreach ($this->_usedModelSets as $setName => $bool) { - if ( ! isset(static::$_tablesCreated[$setName])/* || $forceCreateTables*/) { + if ( ! isset(static::$_tablesCreated[$setName])) { foreach (static::$_modelSets[$setName] as $className) { $classes[] = $this->_em->getClassMetadata($className); } From 4ebf27de357cabbb1cba1da4791fc6ac967a5807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 30 Apr 2017 18:51:26 +0200 Subject: [PATCH 262/877] Use "quoted" from existing data if exists In order to keep that information for inheritance mapping. --- lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index ce3cd8685f8..1af027eafb1 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -1803,7 +1803,7 @@ public function getSingleIdentifierFieldName() if ($this->isIdentifierComposite) { throw MappingException::singleIdNotAllowedOnCompositePrimaryKey($this->name); } - + if ( ! isset($this->identifier[0])) { throw MappingException::noIdDefined($this->name); } @@ -2303,6 +2303,10 @@ public function setPrimaryTable(array $table) $this->table['name'] = $table['name']; } + if (isset($table['quoted'])) { + $this->table['quoted'] = $table['quoted']; + } + if (isset($table['schema'])) { $this->table['schema'] = $table['schema']; } From 0aef63b350c0ea1ff59fbb6b9ce9b3eec3aaa5eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 30 Apr 2017 18:50:37 +0200 Subject: [PATCH 263/877] Fix quoting also when using inheritance --- .../AbstractEntityInheritancePersister.php | 6 +- .../Entity/JoinedSubclassPersister.php | 34 +++------- .../Entity/SingleTablePersister.php | 11 ++-- lib/Doctrine/ORM/Query/SqlWalker.php | 5 +- tests/Doctrine/Tests/Models/Quote/Address.php | 5 +- tests/Doctrine/Tests/Models/Quote/City.php | 27 ++++++++ .../Tests/Models/Quote/FullAddress.php | 17 +++++ .../ORM/Functional/Ticket/GH6402Test.php | 64 ++++++++++++++----- .../ORM/Query/SelectSqlGenerationTest.php | 12 ++-- .../Doctrine/Tests/OrmFunctionalTestCase.php | 20 ++++-- 10 files changed, 137 insertions(+), 64 deletions(-) create mode 100644 tests/Doctrine/Tests/Models/Quote/City.php create mode 100644 tests/Doctrine/Tests/Models/Quote/FullAddress.php diff --git a/lib/Doctrine/ORM/Persisters/Entity/AbstractEntityInheritancePersister.php b/lib/Doctrine/ORM/Persisters/Entity/AbstractEntityInheritancePersister.php index 6052c63e5b2..79472b50c0e 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/AbstractEntityInheritancePersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/AbstractEntityInheritancePersister.php @@ -82,16 +82,18 @@ protected function getSelectColumnSQL($field, ClassMetadata $class, $alias = 'r' /** * @param string $tableAlias * @param string $joinColumnName + * @param string $quotedColumnName + * * @param string $type * * @return string */ - protected function getSelectJoinColumnSQL($tableAlias, $joinColumnName, $type) + protected function getSelectJoinColumnSQL($tableAlias, $joinColumnName, $quotedColumnName, $type) { $columnAlias = $this->getSQLColumnAlias($joinColumnName); $this->currentPersisterContext->rsm->addMetaResult('r', $columnAlias, $joinColumnName, false, $type); - return $tableAlias . '.' . $joinColumnName . ' AS ' . $columnAlias; + return $tableAlias . '.' . $quotedColumnName . ' AS ' . $columnAlias; } } diff --git a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php index 8fe679ad4b9..6c09b604a75 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php @@ -462,21 +462,14 @@ protected function getSelectColumnsSQL() ? $this->getSQLTableAlias($mapping['inherited']) : $baseTableAlias; - foreach ($mapping['targetToSourceKeyColumns'] as $srcColumn) { - $className = isset($mapping['inherited']) - ? $mapping['inherited'] - : $this->class->name; - - $targetClass = $this->em->getClassMetadata($mapping['targetEntity']); + $targetClass = $this->em->getClassMetadata($mapping['targetEntity']); + foreach ($mapping['joinColumns'] as $joinColumn) { $columnList[] = $this->getSelectJoinColumnSQL( $tableAlias, - $srcColumn, - PersisterHelper::getTypeOfColumn( - $mapping['sourceToTargetKeyColumns'][$srcColumn], - $targetClass, - $this->em - ) + $joinColumn['name'], + $this->quoteStrategy->getJoinColumnName($joinColumn, $this->class, $this->platform), + PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em) ); } } @@ -510,21 +503,14 @@ protected function getSelectColumnsSQL() continue; } - foreach ($mapping['targetToSourceKeyColumns'] as $srcColumn) { - $className = isset($mapping['inherited']) - ? $mapping['inherited'] - : $subClass->name; - - $targetClass = $this->em->getClassMetadata($mapping['targetEntity']); + $targetClass = $this->em->getClassMetadata($mapping['targetEntity']); + foreach ($mapping['joinColumns'] as $joinColumn) { $columnList[] = $this->getSelectJoinColumnSQL( $tableAlias, - $srcColumn, - PersisterHelper::getTypeOfColumn( - $mapping['sourceToTargetKeyColumns'][$srcColumn], - $targetClass, - $this->em - ) + $joinColumn['name'], + $this->quoteStrategy->getJoinColumnName($joinColumn, $subClass, $this->platform), + PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em) ); } } diff --git a/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php b/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php index ff1d29652c5..4b8352b350c 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php @@ -89,15 +89,12 @@ protected function getSelectColumnsSQL() $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); - foreach ($assoc['targetToSourceKeyColumns'] as $srcColumn) { + foreach ($assoc['joinColumns'] as $joinColumn) { $columnList[] = $this->getSelectJoinColumnSQL( $tableAlias, - $srcColumn, - PersisterHelper::getTypeOfColumn( - $assoc['sourceToTargetKeyColumns'][$srcColumn], - $targetClass, - $this->em - ) + $joinColumn['name'], + $this->quoteStrategy->getJoinColumnName($joinColumn, $subClass, $this->platform), + PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em) ); } } diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 310034e6916..b39280b396e 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -764,7 +764,7 @@ public function walkSelectClause($selectClause) $columnAlias = $this->getSQLColumnAlias($columnName); $columnType = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em); - $quotedColumnName = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform); + $quotedColumnName = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform); $sqlSelectExpressions[] = $sqlTableAlias . '.' . $quotedColumnName . ' AS ' . $columnAlias; $this->rsm->addMetaResult($dqlAlias, $columnAlias, $columnName, $isIdentifier, $columnType); @@ -793,7 +793,8 @@ public function walkSelectClause($selectClause) $columnAlias = $this->getSQLColumnAlias($columnName); $columnType = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em); - $sqlSelectExpressions[] = $sqlTableAlias . '.' . $columnName . ' AS ' . $columnAlias; + $quotedColumnName = $this->quoteStrategy->getJoinColumnName($joinColumn, $subClass, $this->platform); + $sqlSelectExpressions[] = $sqlTableAlias . '.' . $quotedColumnName . ' AS ' . $columnAlias; $this->rsm->addMetaResult($dqlAlias, $columnAlias, $columnName, $subClass->isIdentifier($columnName), $columnType); } diff --git a/tests/Doctrine/Tests/Models/Quote/Address.php b/tests/Doctrine/Tests/Models/Quote/Address.php index 58e303f1333..42beaf2a4fd 100644 --- a/tests/Doctrine/Tests/Models/Quote/Address.php +++ b/tests/Doctrine/Tests/Models/Quote/Address.php @@ -5,6 +5,9 @@ /** * @Entity * @Table(name="`quote-address`") + * @InheritanceType("SINGLE_TABLE") + * @DiscriminatorColumn(name="type", type="string") + * @DiscriminatorMap({"simple" = Address::class, "full" = FullAddress::class}) */ class Address { @@ -51,4 +54,4 @@ public function getUser() return $this->user; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/Quote/City.php b/tests/Doctrine/Tests/Models/Quote/City.php new file mode 100644 index 00000000000..74503ea0858 --- /dev/null +++ b/tests/Doctrine/Tests/Models/Quote/City.php @@ -0,0 +1,27 @@ +name = $name; + } +} diff --git a/tests/Doctrine/Tests/Models/Quote/FullAddress.php b/tests/Doctrine/Tests/Models/Quote/FullAddress.php new file mode 100644 index 00000000000..b73cda5bd4a --- /dev/null +++ b/tests/Doctrine/Tests/Models/Quote/FullAddress.php @@ -0,0 +1,17 @@ +useModelSet('quote'); - try { - $this->setUpEntitySchema([ - Address::class, - Group::class, - Phone::class, - User::class, - ]); - } catch (\Exception $exception) { - } + parent::setUp(); } public function testFind() @@ -40,8 +34,28 @@ public function testQuery() { $id = $this->createAddress(); - $addresses = $this->_em->createQuery("SELECT a FROM " . Address::class . " a WHERE a.id = :id") - ->setParameter("id", $id) + $addresses = $this->_em->createQuery('SELECT a FROM ' . Address::class . ' a WHERE a.id = :id') + ->setParameter('id', $id) + ->getResult(); + + self::assertCount(1, $addresses); + self::assertNotNull($addresses[0]->user); + } + + public function testFindWithSubClass() + { + $id = $this->createFullAddress(); + + $address = $this->_em->find(FullAddress::class, $id); + self::assertNotNull($address->user); + } + + public function testQueryWithSubClass() + { + $id = $this->createFullAddress(); + + $addresses = $this->_em->createQuery('SELECT a FROM ' . FullAddress::class . ' a WHERE a.id = :id') + ->setParameter('id', $id) ->getResult(); self::assertCount(1, $addresses); @@ -49,18 +63,34 @@ public function testQuery() } private function createAddress() + { + $address = new Address(); + $address->zip = 'bar'; + + $this->persistAddress($address); + + return $address->id; + } + + private function createFullAddress() + { + $address = new FullAddress(); + $address->zip = 'bar'; + $address->city = new City('London'); + + $this->persistAddress($address); + + return $address->id; + } + + private function persistAddress(Address $address) { $user = new User(); $user->name = "foo"; - - $address = new Address(); - $address->zip = "bar"; $user->setAddress($address); $this->_em->persist($user); $this->_em->flush(); $this->_em->clear(); - - return $address->id; } } diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index b6bdce3233b..b674c5d38be 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -39,8 +39,7 @@ protected function setUp() * @param array $queryHints * @param array $queryParams */ - public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed, array $queryHints = [], array $queryParams = [] - ) + public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed, array $queryHints = [], array $queryParams = []) { try { $query = $this->_em->createQuery($dqlToBeTested); @@ -78,8 +77,7 @@ public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed, array $qu * @param array $queryHints * @param array $queryParams */ - public function assertInvalidSqlGeneration($dqlToBeTested, $expectedException, array $queryHints = [], array $queryParams = [] - ) + public function assertInvalidSqlGeneration($dqlToBeTested, $expectedException, array $queryHints = [], array $queryParams = []) { $this->expectException($expectedException); @@ -892,7 +890,7 @@ public function testOrderBySupportsSingleValuedPathExpressionOwningSide() } /** - * @expectedException Doctrine\ORM\Query\QueryException + * @expectedException \Doctrine\ORM\Query\QueryException */ public function testOrderBySupportsSingleValuedPathExpressionInverseSide() { @@ -1991,7 +1989,7 @@ public function testQuotedWalkJoinVariableDeclaration() { $this->assertSqlGeneration( 'SELECT u, a FROM Doctrine\Tests\Models\Quote\User u JOIN u.address a', - 'SELECT q0_."user-id" AS userid_0, q0_."user-name" AS username_1, q1_."address-id" AS addressid_2, q1_."address-zip" AS addresszip_3 FROM "quote-user" q0_ INNER JOIN "quote-address" q1_ ON q0_."address-id" = q1_."address-id"' + 'SELECT q0_."user-id" AS userid_0, q0_."user-name" AS username_1, q1_."address-id" AS addressid_2, q1_."address-zip" AS addresszip_3, q1_.type AS type_4 FROM "quote-user" q0_ INNER JOIN "quote-address" q1_ ON q0_."address-id" = q1_."address-id" AND q1_.type IN (\'simple\', \'full\')' ); $this->assertSqlGeneration( @@ -2006,7 +2004,7 @@ public function testQuotedWalkJoinVariableDeclaration() $this->assertSqlGeneration( 'SELECT a, u FROM Doctrine\Tests\Models\Quote\Address a JOIN a.user u', - 'SELECT q0_."address-id" AS addressid_0, q0_."address-zip" AS addresszip_1, q1_."user-id" AS userid_2, q1_."user-name" AS username_3 FROM "quote-address" q0_ INNER JOIN "quote-user" q1_ ON q0_."user-id" = q1_."user-id"' + 'SELECT q0_."address-id" AS addressid_0, q0_."address-zip" AS addresszip_1, q1_."user-id" AS userid_2, q1_."user-name" AS username_3, q0_.type AS type_4 FROM "quote-address" q0_ INNER JOIN "quote-user" q1_ ON q0_."user-id" = q1_."user-id" WHERE q0_.type IN (\'simple\', \'full\')' ); $this->assertSqlGeneration( diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index c1445eaeccf..2ff2c347c4c 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -225,6 +225,8 @@ abstract class OrmFunctionalTestCase extends OrmTestCase ], 'quote' => [ Models\Quote\Address::class, + Models\Quote\City::class, + Models\Quote\FullAddress::class, Models\Quote\Group::class, Models\Quote\NumericEntity::class, Models\Quote\Phone::class, @@ -480,10 +482,20 @@ protected function tearDown() } if (isset($this->_usedModelSets['quote'])) { - $conn->executeUpdate('DELETE FROM ' . $platform->quoteIdentifier("quote-address")); - $conn->executeUpdate('DELETE FROM ' . $platform->quoteIdentifier("quote-group")); - $conn->executeUpdate('DELETE FROM ' . $platform->quoteIdentifier("quote-phone")); - $conn->executeUpdate('DELETE FROM ' . $platform->quoteIdentifier("quote-user")); + $conn->executeUpdate( + sprintf( + 'UPDATE %s SET %s = NULL', + $platform->quoteIdentifier("quote-address"), + $platform->quoteIdentifier('user-id') + ) + ); + + $conn->executeUpdate('DELETE FROM ' . $platform->quoteIdentifier('quote-users-groups')); + $conn->executeUpdate('DELETE FROM ' . $platform->quoteIdentifier('quote-group')); + $conn->executeUpdate('DELETE FROM ' . $platform->quoteIdentifier('quote-phone')); + $conn->executeUpdate('DELETE FROM ' . $platform->quoteIdentifier('quote-user')); + $conn->executeUpdate('DELETE FROM ' . $platform->quoteIdentifier('quote-address')); + $conn->executeUpdate('DELETE FROM ' . $platform->quoteIdentifier('quote-city')); } if (isset($this->_usedModelSets['vct_onetoone'])) { From a360da5a7e5463f6c12b0922f6063e1cf32dde6d Mon Sep 17 00:00:00 2001 From: Marcin Szulc Date: Fri, 3 Feb 2017 23:54:27 +0100 Subject: [PATCH 264/877] Fix lazy loading of 1-to-1 relationship with custom id object Fixing case when lazy loading of entity in one-to-one relationship on the side without foreign key did not return eht entity because of custom type not being detected and properly formatted before applying to database query. Closes https://github.com/doctrine/doctrine2/issues/5887 --- .../Entity/BasicEntityPersister.php | 2 +- .../ORM/Functional/Ticket/GH5887Test.php | 234 ++++++++++++++++++ 2 files changed, 235 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH5887Test.php diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index f3cdc705569..28dc9179afc 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -785,7 +785,7 @@ public function loadOneToOneEntity(array $assoc, $sourceEntity, array $identifie // unset the old value and set the new sql aliased value here. By definition // unset($identifier[$targetKeyColumn] works here with how UnitOfWork::createEntity() calls this method. - $identifier[$this->getSQLTableAlias($targetClass->name) . "." . $targetKeyColumn] = + $identifier[$targetClass->getFieldForColumn($targetKeyColumn)] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity); unset($identifier[$targetKeyColumn]); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5887Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5887Test.php new file mode 100644 index 00000000000..f19dd5924b5 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5887Test.php @@ -0,0 +1,234 @@ +_schemaTool->createSchema( + [ + $this->_em->getClassMetadata(GH5887Cart::class), + $this->_em->getClassMetadata(GH5887Customer::class), + ] + ); + } + + public function testLazyLoadsForeignEntitiesInOneToOneRelationWhileHavingCustomIdObject() + { + $customerId = new GH5887CustomIdObject(1); + $customer = new GH5887Customer(); + $customer->setId($customerId); + + $cartId = 2; + $cart = new GH5887Cart(); + $cart->setId($cartId); + $cart->setCustomer($customer); + + $this->_em->persist($customer); + $this->_em->persist($cart); + $this->_em->flush(); + + // Clearing cached entities + $this->_em->clear(); + + $customerRepository = $this->_em->getRepository(GH5887Customer::class); + /** @var GH5887Customer $customer */ + $customer = $customerRepository->createQueryBuilder('c') + ->where('c.id = :id') + ->setParameter('id', $customerId->getId()) + ->getQuery() + ->getOneOrNullResult(); + + $this->assertInstanceOf(GH5887Cart::class, $customer->getCart()); + } +} + +/** + * @Entity + */ +class GH5887Cart +{ + /** + * @var int + * + * @Id + * @Column(type="integer") + * @GeneratedValue(strategy="NONE") + */ + private $id; + + /** + * One Cart has One Customer. + * + * @var GH5887Customer + * + * @OneToOne(targetEntity="GH5887Customer", inversedBy="cart") + * @JoinColumn(name="customer_id", referencedColumnName="id") + */ + private $customer; + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param int $id + */ + public function setId($id) + { + $this->id = $id; + } + + /** + * @return GH5887Customer + */ + public function getCustomer() + { + return $this->customer; + } + + /** + * @param GH5887Customer $customer + */ + public function setCustomer(GH5887Customer $customer) + { + if ($this->customer !== $customer) { + $this->customer = $customer; + $customer->setCart($this); + } + } +} + +/** + * @Entity + */ +class GH5887Customer +{ + /** + * @var GH5887CustomIdObject + * + * @Id + * @Column(type="GH5887CustomIdObject") + * @GeneratedValue(strategy="NONE") + */ + private $id; + + /** + * One Customer has One Cart. + * + * @var GH5887Cart + * + * @OneToOne(targetEntity="GH5887Cart", mappedBy="customer") + */ + private $cart; + + /** + * @return GH5887CustomIdObject + */ + public function getId() + { + return $this->id; + } + + /** + * @param GH5887CustomIdObject $id + */ + public function setId(GH5887CustomIdObject $id) + { + $this->id = $id; + } + + /** + * @return GH5887Cart + */ + public function getCart(): GH5887Cart + { + return $this->cart; + } + + /** + * @param GH5887Cart $cart + */ + public function setCart(GH5887Cart $cart) + { + if ($this->cart !== $cart) { + $this->cart = $cart; + $cart->setCustomer($this); + } + } +} + +class GH5887CustomIdObject +{ + /** + * @var int + */ + private $id; + + /** + * @param int $id + */ + public function __construct($id) + { + $this->id = $id; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + public function __toString() + { + return 'non existing id'; + } +} + +class GH5887CustomIdObjectType extends StringType +{ + const NAME = 'GH5887CustomIdObject'; + + /** + * {@inheritdoc} + */ + public function convertToDatabaseValue($value, AbstractPlatform $platform) + { + return $value->getId(); + } + + /** + * {@inheritdoc} + */ + public function convertToPHPValue($value, AbstractPlatform $platform) + { + return new GH5887CustomIdObject($value); + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return self::NAME; + } +} From 0a10f347d3951cc46e5f07dc2ef9ba8ae37af205 Mon Sep 17 00:00:00 2001 From: Timothy Clissold Date: Tue, 28 Mar 2017 13:50:52 +1100 Subject: [PATCH 265/877] Fix inheritance join alias --- .../ORM/Internal/Hydration/ObjectHydrator.php | 4 +- .../ORM/Functional/Ticket/GH6362Test.php | 144 ++++++++++++++++++ 2 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH6362Test.php diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index 9d8ee329a44..ef5e7437112 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -358,8 +358,8 @@ protected function hydrateRowData(array $row, array &$result) // Get a reference to the parent object to which the joined element belongs. if ($this->_rsm->isMixed && isset($this->rootAliases[$parentAlias])) { - $first = reset($this->resultPointers); - $parentObject = $first[key($first)]; + $objectClass = $this->resultPointers[$parentAlias]; + $parentObject = $objectClass[key($objectClass)]; } else if (isset($this->resultPointers[$parentAlias])) { $parentObject = $this->resultPointers[$parentAlias]; } else { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6362Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6362Test.php new file mode 100644 index 00000000000..576fbd0eb86 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6362Test.php @@ -0,0 +1,144 @@ +_schemaTool->createSchema( + [ + $this->_em->getClassMetadata(GH6362Start::class), + $this->_em->getClassMetadata(GH6362Base::class), + $this->_em->getClassMetadata(GH6362Child::class), + $this->_em->getClassMetadata(GH6362Join::class), + ] + ); + } + + /** + * @group 6362 + * + * SELECT a as base, b, c, d + * FROM Start a + * LEFT JOIN a.bases b + * LEFT JOIN Child c WITH b.id = c.id + * LEFT JOIN c.joins d + */ + public function testInheritanceJoinAlias() + { + $rsm = new ResultSetMapping; + $rsm->addEntityResult(GH6362Start::class, 'a', 'base'); + $rsm->addJoinedEntityResult(GH6362Base::class, 'b', 'a', 'bases'); + $rsm->addEntityResult(GH6362Child::class, 'c'); + $rsm->addJoinedEntityResult(GH6362Join::class, 'd', 'c', 'joins'); + + $rsm->addFieldResult('a', 'id_0', 'id'); + $rsm->addFieldResult('b', 'id_1', 'id'); + $rsm->addFieldResult('c', 'id_2', 'id'); + $rsm->addFieldResult('d', 'id_3', 'id'); + + $rsm->addMetaResult('a', 'bases_id_4', 'bases_id', false, 'integer'); + $rsm->addMetaResult('b', 'type_5', 'type'); + $rsm->addMetaResult('c', 'type_6', 'type'); + $rsm->addMetaResult('d', 'child_id_7', 'child_id', false, 'integer'); + + $rsm->setDiscriminatorColumn('b', 'type_5'); + $rsm->setDiscriminatorColumn('c', 'type_6'); + + $resultSet = [ + [ + 'id_0' => '1', + 'id_1' => '1', + 'id_2' => '1', + 'id_3' => '1', + 'bases_id_4' => '1', + 'type_5' => 'child', + 'type_6' => 'child', + 'child_id_7' => '1', + ], + ]; + + $stmt = new HydratorMockStatement($resultSet); + $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); + $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); + + $this->assertInstanceOf(GH6362Start::class, $result[0]['base']); + $this->assertInstanceOf(GH6362Child::class, $result[1][0]); + } +} + +/** + * @Entity + */ +class GH6362Start +{ + /** + * @Column(type="integer") + * @Id + * @GeneratedValue + */ + protected $id; + + /** + * @ManyToOne(targetEntity="GH6362Base", inversedBy="starts") + */ + private $bases; +} + +/** + * @InheritanceType("SINGLE_TABLE") + * @DiscriminatorColumn(name="type", type="string") + * @DiscriminatorMap({"child" = "GH6362Child"}) + * @Entity + */ +abstract class GH6362Base +{ + /** + * @Column(type="integer") + * @Id + * @GeneratedValue + */ + protected $id; + + /** + * @OneToMany(targetEntity="GH6362Start", mappedBy="bases") + */ + private $starts; +} + +/** + * @Entity + */ +class GH6362Child extends GH6362Base +{ + /** + * @OneToMany(targetEntity="GH6362Join", mappedBy="child") + */ + private $joins; +} + +/** + * @Entity + */ +class GH6362Join +{ + /** + * @Column(type="integer") + * @Id + * @GeneratedValue + */ + private $id; + + /** + * @ManyToOne(targetEntity="GH6362Child", inversedBy="joins") + */ + private $child; +} From 85a52d781efe8f03599900b206139b858fd23d55 Mon Sep 17 00:00:00 2001 From: bruno da silva Date: Tue, 11 Apr 2017 10:27:14 +0200 Subject: [PATCH 266/877] add a not weel writend/nammed test testing Query::expireResultCache() --- .../ORM/Functional/Ticket/GH2947Test.php | 95 +++++++++++++++++++ .../Doctrine/Tests/OrmFunctionalTestCase.php | 11 +++ 2 files changed, 106 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH2947Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH2947Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH2947Test.php new file mode 100644 index 00000000000..0b21b57f065 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH2947Test.php @@ -0,0 +1,95 @@ +resultCacheImpl = new ArrayCache(); + + parent::setUp(); + + $this->_schemaTool->createSchema([$this->_em->getClassMetadata(GH2947Car::class)]); + } + + public function testIssue() + { + $this->createData(); + $initialQueryCount = $this->getCurrentQueryCount(); + + $query = $this->createQuery(); + self::assertEquals('BMW', (string) $query->getSingleResult()); + self::assertEquals($initialQueryCount + 1, $this->getCurrentQueryCount()); + + $this->updateData(); + self::assertEquals('BMW', (string) $query->getSingleResult()); + self::assertEquals($initialQueryCount + 2, $this->getCurrentQueryCount()); + + $query->expireResultCache(true); + self::assertEquals('Dacia', (string) $query->getSingleResult()); + self::assertEquals($initialQueryCount + 3, $this->getCurrentQueryCount()); + + $query->expireResultCache(false); + self::assertEquals('Dacia', (string) $query->getSingleResult()); + self::assertEquals($initialQueryCount + 3, $this->getCurrentQueryCount()); + } + + private function createQuery() + { + return $this->_em->createQueryBuilder() + ->select('car') + ->from(GH2947Car::class, 'car') + ->getQuery() + ->useResultCache(true, 3600, 'foo-cache-id'); + } + + private function createData() + { + $this->_em->persist(new GH2947Car('BMW')); + $this->_em->flush(); + $this->_em->clear(); + } + + private function updateData() + { + $this->_em->createQueryBuilder() + ->update(GH2947Car::class, 'car') + ->set('car.brand', ':newBrand') + ->where('car.brand = :oldBrand') + ->setParameter('newBrand', 'Dacia') + ->setParameter('oldBrand', 'BMW') + ->getQuery() + ->execute(); + } +} + +/** + * @Entity + * @Table(name="GH2947_car") + */ +class GH2947Car +{ + /** + * @Id + * @Column(type="string", length=25) + * @GeneratedValue(strategy="NONE") + */ + public $brand; + + public function __construct(string $brand) + { + $this->brand = $brand; + } + + public function __toString(): string + { + return $this->brand; + } +} diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 2ff2c347c4c..5716f2a500d 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -68,6 +68,13 @@ abstract class OrmFunctionalTestCase extends OrmTestCase */ protected $_usedModelSets = []; + /** + * To be configured by the test that uses result set cache + * + * @var \Doctrine\Common\Cache\Cache|null + */ + protected $resultCacheImpl; + /** * Whether the database schema has already been created. * @@ -699,6 +706,10 @@ protected function _getEntityManager($config = null, $eventManager = null) { $config->setProxyDir(__DIR__ . '/Proxies'); $config->setProxyNamespace('Doctrine\Tests\Proxies'); + if (null !== $this->resultCacheImpl) { + $config->setResultCacheImpl($this->resultCacheImpl); + } + $enableSecondLevelCache = getenv('ENABLE_SECOND_LEVEL_CACHE'); if ($this->isSecondLevelCacheEnabled || $enableSecondLevelCache) { From e71272e2b4e1f13318adfb1b16cc09c2e25ae70a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 30 Apr 2017 21:12:40 +0200 Subject: [PATCH 267/877] Evict result set cache if Query#expireResultCache() was called --- lib/Doctrine/ORM/Query.php | 19 +++++++++++ tests/Doctrine/Tests/ORM/Query/QueryTest.php | 33 ++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 12fb3f560ec..9a5ded2c7a7 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -20,6 +20,7 @@ namespace Doctrine\ORM; use Doctrine\DBAL\LockMode; +use Doctrine\ORM\Query\Exec\AbstractSqlExecutor; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\ParserResult; use Doctrine\ORM\Query\QueryException; @@ -322,9 +323,27 @@ protected function _doExecute() list($sqlParams, $types) = $this->processParameterMappings($paramMappings); + $this->evictResultSetCache($executor, $sqlParams, $types); + return $executor->execute($this->_em->getConnection(), $sqlParams, $types); } + private function evictResultSetCache(AbstractSqlExecutor $executor, array $sqlParams, array $types) + { + if (null === $this->_queryCacheProfile || ! $this->getExpireResultCache()) { + return; + } + + $cacheDriver = $this->_queryCacheProfile->getResultCacheDriver(); + $statements = (array) $executor->getSqlStatements(); // Type casted since it can either be a string or an array + + foreach ($statements as $statement) { + $cacheKeys = $this->_queryCacheProfile->generateCacheKeys($statement, $sqlParams, $types); + + $cacheDriver->delete(reset($cacheKeys)); + } + } + /** * Evict entity cache region */ diff --git a/tests/Doctrine/Tests/ORM/Query/QueryTest.php b/tests/Doctrine/Tests/ORM/Query/QueryTest.php index 9b8f24d40ec..6b0091e9caa 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryTest.php @@ -243,4 +243,37 @@ public function testSetHydrationCacheProfileNull() $query->setHydrationCacheProfile(null); $this->assertNull($query->getHydrationCacheProfile()); } + + /** + * @group 2947 + */ + public function testResultCacheEviction() + { + $this->_em->getConfiguration()->setResultCacheImpl(new ArrayCache()); + + $query = $this->_em->createQuery("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u") + ->useResultCache(true); + + /** @var DriverConnectionMock $driverConnectionMock */ + $driverConnectionMock = $this->_em->getConnection() + ->getWrappedConnection(); + + $driverConnectionMock->setStatementMock(new StatementArrayMock([['id_0' => 1]])); + + // Performs the query and sets up the initial cache + self::assertCount(1, $query->getResult()); + + $driverConnectionMock->setStatementMock(new StatementArrayMock([['id_0' => 1], ['id_0' => 2]])); + + // Retrieves cached data since expire flag is false and we have a cached result set + self::assertCount(1, $query->getResult()); + + // Performs the query and caches the result set since expire flag is true + self::assertCount(2, $query->expireResultCache(true)->getResult()); + + $driverConnectionMock->setStatementMock(new StatementArrayMock([['id_0' => 1]])); + + // Retrieves cached data since expire flag is false and we have a cached result set + self::assertCount(2, $query->expireResultCache(false)->getResult()); + } } From 3219fe53160a81a8dd31bd799a65a2b6f9d6d620 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 3 May 2017 10:46:24 +0200 Subject: [PATCH 268/877] Fix small CS issues as per review --- .../ORM/Functional/InstanceOfAbstractTest.php | 12 ++++++---- .../Functional/InstanceOfMultiLevelTest.php | 23 +++++++++++-------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php b/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php index 3a52d93f96c..1b826a4619d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\ORM\Functional { + use Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Employee; + use Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Person; use Doctrine\Tests\OrmFunctionalTestCase; class InstanceOfAbstractTest extends OrmFunctionalTestCase @@ -10,10 +12,10 @@ protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( - $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfAbstractTest\Person'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfAbstractTest\Employee'), - )); + $this->_schemaTool->createSchema([ + $this->_em->getClassMetadata(Person::class), + $this->_em->getClassMetadata(Employee::class), + ]); } public function testInstanceOf() @@ -55,7 +57,7 @@ private function loadData() * @InheritanceType(value="JOINED") * @DiscriminatorColumn(name="kind", type="string") * @DiscriminatorMap(value={ - * "employee": "Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Employee" + * "employee": Employee::class * }) */ abstract class Person diff --git a/tests/Doctrine/Tests/ORM/Functional/InstanceOfMultiLevelTest.php b/tests/Doctrine/Tests/ORM/Functional/InstanceOfMultiLevelTest.php index c4b5bbcd2c3..131f053a285 100644 --- a/tests/Doctrine/Tests/ORM/Functional/InstanceOfMultiLevelTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/InstanceOfMultiLevelTest.php @@ -2,6 +2,9 @@ namespace Doctrine\Tests\ORM\Functional { + use Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Employee; + use Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Engineer; + use Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Person; use Doctrine\Tests\OrmFunctionalTestCase; class InstanceOfMultiLevelTest extends OrmFunctionalTestCase @@ -10,11 +13,11 @@ protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( - $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfMultiLevelTest\Person'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfMultiLevelTest\Employee'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfMultiLevelTest\Engineer'), - )); + $this->_schemaTool->createSchema([ + $this->_em->getClassMetadata(Person::class), + $this->_em->getClassMetadata(Employee::class), + $this->_em->getClassMetadata(Engineer::class), + ]); } public function testInstanceOf() @@ -29,11 +32,11 @@ public function testInstanceOf() $this->assertCount(3, $result); foreach ($result as $r) { - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Person', $r); + $this->assertInstanceOf(Person::class, $r); if ($r instanceof InstanceOfMultiLevelTest\Engineer) { $this->assertEquals('foobar', $r->getName()); $this->assertEquals('doctrine', $r->getSpecialization()); - } elseif ($r instanceof InstanceOfMultiLevelTest\Employee) { + } elseif ($r instanceof Employee) { $this->assertEquals('bar', $r->getName()); $this->assertEquals('qux', $r->getDepartement()); } else { @@ -44,14 +47,14 @@ public function testInstanceOf() private function loadData() { - $person = new InstanceOfMultiLevelTest\Person(); + $person = new Person(); $person->setName('foo'); - $employee = new InstanceOfMultiLevelTest\Employee(); + $employee = new Employee(); $employee->setName('bar'); $employee->setDepartement('qux'); - $engineer = new InstanceOfMultiLevelTest\Engineer(); + $engineer = new Engineer(); $engineer->setName('foobar'); $engineer->setDepartement('dep'); $engineer->setSpecialization('doctrine'); From 11c84c7b20ac9c327a3843ac53a56795c79c01f6 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 3 May 2017 11:00:26 +0200 Subject: [PATCH 269/877] Split SqlWalker::walkInstanceOfExpression method --- lib/Doctrine/ORM/Query/SqlWalker.php | 94 +++++++++++++++------------- 1 file changed, 51 insertions(+), 43 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 62350c389f4..e308b7de7a3 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -37,7 +37,6 @@ * @author Alexander * @author Fabio B. Silva * @since 2.0 - * @todo Rename: SQLWalker */ class SqlWalker implements TreeWalker { @@ -2020,6 +2019,7 @@ public function walkInExpression($inExpr) /** * {@inheritdoc} + * @throws \Doctrine\ORM\Query\QueryException */ public function walkInstanceOfExpression($instanceOfExpr) { @@ -2037,48 +2037,7 @@ public function walkInstanceOfExpression($instanceOfExpr) } $sql .= $class->discriminatorColumn['name'] . ($instanceOfExpr->not ? ' NOT IN ' : ' IN '); - - $knownSubclasses = array_flip($discrClass->subClasses); - - $sqlParameterList = []; - $discriminators = []; - foreach ($instanceOfExpr->value as $parameter) { - if ($parameter instanceof AST\InputParameter) { - $this->rsm->addMetadataParameterMapping($parameter->name, 'discriminatorValue'); - - $sqlParameterList[] = $this->walkInputParameter($parameter); - - continue; - } - - // Trim first backslash - $parameter = ltrim($parameter, '\\'); - - // Check parameter is really in the hierarchy - if ($parameter !== $discrClass->name && ! array_key_exists($parameter, $knownSubclasses)) { - throw QueryException::instanceOfUnrelatedClass($parameter, $discrClass->name); - } - - // Include discriminators for parameter class and its subclass - $metadata = $this->em->getClassMetadata($parameter); - $hierarchyClasses = $metadata->subClasses; - $hierarchyClasses[] = $metadata->name; - - foreach ($hierarchyClasses as $class) { - $currentMetadata = $this->em->getClassMetadata($class); - $currentDiscriminator = $currentMetadata->discriminatorValue; - - if (is_string($currentDiscriminator) && ! array_key_exists($currentDiscriminator, $discriminators)) { - $discriminators[$currentDiscriminator] = true; - } - } - } - - foreach (array_keys($discriminators) as $dis) { - $sqlParameterList[] = $this->conn->quote($dis); - } - - $sql .= '(' . implode(', ', $sqlParameterList) . ')'; + $sql .= $this->getChildDiscriminatorsFromClassMetadata($discrClass, $instanceOfExpr); return $sql; } @@ -2312,4 +2271,53 @@ public function walkResultVariable($resultVariable) return $resultAlias; } + + /** + * @param ClassMetadataInfo $discrClass + * @param AST\InstanceOfExpression $instanceOfExpr + * @return string The list in parentheses of valid child discriminators from the given class + * @throws QueryException + */ + private function getChildDiscriminatorsFromClassMetadata(ClassMetadataInfo $discrClass, AST\InstanceOfExpression $instanceOfExpr) + { + $knownSubclasses = array_flip($discrClass->subClasses); + $sqlParameterList = []; + $discriminators = []; + foreach ($instanceOfExpr->value as $parameter) { + if ($parameter instanceof AST\InputParameter) { + $this->rsm->addMetadataParameterMapping($parameter->name, 'discriminatorValue'); + + $sqlParameterList[] = $this->walkInputParameter($parameter); + + continue; + } + + // Trim first backslash + $parameter = ltrim($parameter, '\\'); + + if ($parameter !== $discrClass->name && ! array_key_exists($parameter, $knownSubclasses)) { + throw QueryException::instanceOfUnrelatedClass($parameter, $discrClass->name); + } + + // Include discriminators for parameter class and its subclass + $metadata = $this->em->getClassMetadata($parameter); + $hierarchyClasses = $metadata->subClasses; + $hierarchyClasses[] = $metadata->name; + + foreach ($hierarchyClasses as $class) { + $currentMetadata = $this->em->getClassMetadata($class); + $currentDiscriminator = $currentMetadata->discriminatorValue; + + if (is_string($currentDiscriminator) && ! array_key_exists($currentDiscriminator, $discriminators)) { + $discriminators[$currentDiscriminator] = true; + } + } + } + + foreach (array_keys($discriminators) as $dis) { + $sqlParameterList[] = $this->conn->quote($dis); + } + + return '(' . implode(', ', $sqlParameterList) . ')'; + } } From 21e12ef4a93a32fad5e15f33ec4803890bea59f6 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 3 May 2017 11:06:43 +0200 Subject: [PATCH 270/877] Move tests to ticket namespace (and rename them) --- .../Ticket4646InstanceOfAbstractTest.php} | 10 +++++----- .../Ticket4646InstanceOfMultiLevelTest.php} | 6 +++--- .../Ticket4646InstanceOfTest.php} | 14 ++++++++------ 3 files changed, 16 insertions(+), 14 deletions(-) rename tests/Doctrine/Tests/ORM/Functional/{InstanceOfAbstractTest.php => Ticket/Ticket4646InstanceOfAbstractTest.php} (88%) rename tests/Doctrine/Tests/ORM/Functional/{InstanceOfMultiLevelTest.php => Ticket/Ticket4646InstanceOfMultiLevelTest.php} (95%) rename tests/Doctrine/Tests/ORM/Functional/{InstanceOfTest.php => Ticket/Ticket4646InstanceOfTest.php} (86%) diff --git a/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php similarity index 88% rename from tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php rename to tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php index 1b826a4619d..b17ca2c2d3c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php @@ -1,12 +1,12 @@ assertCount(1, $result); foreach ($result as $r) { - $this->assertInstanceOf(InstanceOfAbstractTest\Person::class, $r); - $this->assertInstanceOf(InstanceOfAbstractTest\Employee::class, $r); + $this->assertInstanceOf(Person::class, $r); + $this->assertInstanceOf(Employee::class, $r); $this->assertSame('bar', $r->getName()); } } private function loadData() { - $employee = new InstanceOfAbstractTest\Employee(); + $employee = new Employee(); $employee->setName('bar'); $employee->setDepartement('qux'); diff --git a/tests/Doctrine/Tests/ORM/Functional/InstanceOfMultiLevelTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php similarity index 95% rename from tests/Doctrine/Tests/ORM/Functional/InstanceOfMultiLevelTest.php rename to tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php index 131f053a285..79f0d5363c0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/InstanceOfMultiLevelTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php @@ -1,13 +1,13 @@ assertInstanceOf(Person::class, $r); - if ($r instanceof InstanceOfMultiLevelTest\Engineer) { + if ($r instanceof Engineer) { $this->assertEquals('foobar', $r->getName()); $this->assertEquals('doctrine', $r->getSpecialization()); } elseif ($r instanceof Employee) { diff --git a/tests/Doctrine/Tests/ORM/Functional/InstanceOfTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php similarity index 86% rename from tests/Doctrine/Tests/ORM/Functional/InstanceOfTest.php rename to tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php index fce0075b63f..326b83393a4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/InstanceOfTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php @@ -1,10 +1,12 @@ assertCount(2, $result); foreach ($result as $r) { - $this->assertInstanceOf(InstanceOfTest\Person::class, $r); - if ($r instanceof InstanceOfTest\Employee) { + $this->assertInstanceOf(Person::class, $r); + if ($r instanceof Employee) { $this->assertEquals('bar', $r->getName()); } else { $this->assertEquals('foo', $r->getName()); @@ -39,10 +41,10 @@ public function testInstanceOf() private function loadData() { - $person = new InstanceOfTest\Person(); + $person = new Person(); $person->setName('foo'); - $employee = new InstanceOfTest\Employee(); + $employee = new Employee(); $employee->setName('bar'); $employee->setDepartement('qux'); From 96bcee4fa94921bde88b0551c6d4e5ffb6e38563 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 3 May 2017 11:42:51 +0200 Subject: [PATCH 271/877] Fix test --- .../Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php index 326b83393a4..35d4afdac66 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php @@ -13,8 +13,8 @@ protected function setUp() parent::setUp(); $this->_schemaTool->createSchema([ - $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfTest\Person'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfTest\Employee'), + $this->_em->getClassMetadata(Person::class), + $this->_em->getClassMetadata(Employee::class), ]); } From 5c1908d82fcbf672cedfa6b87bcadee78018cf24 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Tue, 9 May 2017 19:21:49 +0200 Subject: [PATCH 272/877] Remove dead code Hopefully this does not do anything...? --- lib/Doctrine/ORM/Tools/SchemaTool.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 627f7b5736a..9acd85ffca9 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -401,12 +401,6 @@ private function gatherColumns($class, Table $table) $pkColumns[] = $this->quoteStrategy->getColumnName($mapping['fieldName'], $class, $this->platform); } } - - // For now, this is a hack required for single table inheritence, since this method is called - // twice by single table inheritence relations - if (!$table->hasIndex('primary')) { - //$table->setPrimaryKey($pkColumns); - } } /** From 885c431bd9c3094799beda88eb79c1e08fa996e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 10 May 2017 17:41:10 +0200 Subject: [PATCH 273/877] Pass the connection parameters for cache key generation That argument was added to not have key collisions for different connections. More info: https://github.com/doctrine/dbal/pull/713 --- lib/Doctrine/ORM/Query.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 9a5ded2c7a7..6d874a8ad1a 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -19,6 +19,7 @@ namespace Doctrine\ORM; +use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\LockMode; use Doctrine\ORM\Query\Exec\AbstractSqlExecutor; use Doctrine\ORM\Query\Parser; @@ -323,13 +324,22 @@ protected function _doExecute() list($sqlParams, $types) = $this->processParameterMappings($paramMappings); - $this->evictResultSetCache($executor, $sqlParams, $types); + $this->evictResultSetCache( + $executor, + $sqlParams, + $types, + $this->_em->getConnection()->getParams() + ); return $executor->execute($this->_em->getConnection(), $sqlParams, $types); } - private function evictResultSetCache(AbstractSqlExecutor $executor, array $sqlParams, array $types) - { + private function evictResultSetCache( + AbstractSqlExecutor $executor, + array $sqlParams, + array $types, + array $connectionParams + ) { if (null === $this->_queryCacheProfile || ! $this->getExpireResultCache()) { return; } @@ -338,7 +348,7 @@ private function evictResultSetCache(AbstractSqlExecutor $executor, array $sqlPa $statements = (array) $executor->getSqlStatements(); // Type casted since it can either be a string or an array foreach ($statements as $statement) { - $cacheKeys = $this->_queryCacheProfile->generateCacheKeys($statement, $sqlParams, $types); + $cacheKeys = $this->_queryCacheProfile->generateCacheKeys($statement, $sqlParams, $types, $connectionParams); $cacheDriver->delete(reset($cacheKeys)); } From fac7e8facb38b90ec4f3532e38057a32ce7958fa Mon Sep 17 00:00:00 2001 From: Simone Gentili Date: Sat, 13 May 2017 23:05:37 +0200 Subject: [PATCH 274/877] align equals signs --- lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 1af027eafb1..f265814b161 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -1547,11 +1547,11 @@ protected function _validateAndCompleteAssociationMapping(array $mapping) } $mapping['cascade'] = $cascades; - $mapping['isCascadeRemove'] = in_array('remove', $cascades); + $mapping['isCascadeRemove'] = in_array('remove', $cascades); $mapping['isCascadePersist'] = in_array('persist', $cascades); $mapping['isCascadeRefresh'] = in_array('refresh', $cascades); - $mapping['isCascadeMerge'] = in_array('merge', $cascades); - $mapping['isCascadeDetach'] = in_array('detach', $cascades); + $mapping['isCascadeMerge'] = in_array('merge', $cascades); + $mapping['isCascadeDetach'] = in_array('detach', $cascades); return $mapping; } From 0a801b895e44c5d2402503e085cd29a17c18a90c Mon Sep 17 00:00:00 2001 From: Simone Gentili Date: Mon, 15 May 2017 07:41:07 +0200 Subject: [PATCH 275/877] compute size of loaders beforehand and not on each iteration --- tests/Doctrine/Tests/ORM/Tools/SetupTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Tools/SetupTest.php b/tests/Doctrine/Tests/ORM/Tools/SetupTest.php index d69e5b0300b..c44cb6bcf56 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SetupTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SetupTest.php @@ -35,7 +35,8 @@ public function tearDown() set_include_path($this->originalIncludePath); $loaders = spl_autoload_functions(); - for ($i = 0; $i < count($loaders); $i++) { + $numberOfLoaders = count($loaders); + for ($i = 0; $i < $numberOfLoaders; $i++) { if ($i > $this->originalAutoloaderCount+1) { spl_autoload_unregister($loaders[$i]); } From 73770ac090c235d4a79d498950a1b8212ebf918c Mon Sep 17 00:00:00 2001 From: Ivan Date: Mon, 15 May 2017 14:53:23 -0600 Subject: [PATCH 276/877] Update git submodule "docs/en/_theme" - This fixes the broken image at the footer of Doctrine 2 ORM's docs --- docs/en/_theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/_theme b/docs/en/_theme index dc294be1dbc..6f1bc8bead1 160000 --- a/docs/en/_theme +++ b/docs/en/_theme @@ -1 +1 @@ -Subproject commit dc294be1dbcf9abde82d24aea1902898d6ee6314 +Subproject commit 6f1bc8bead17b8032389659c0b071d00f2c58328 From 7ce2381bdd7916f5af39336791a111aa1fa0beae Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 18 May 2017 12:57:36 +0200 Subject: [PATCH 277/877] Allow Symfony 4.0 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 780105f3bb7..5c89e8f9792 100644 --- a/composer.json +++ b/composer.json @@ -22,10 +22,10 @@ "doctrine/common": "^2.7.1", "doctrine/cache": "~1.5", "doctrine/annotations": "~1.2", - "symfony/console": "~2.5|~3.0" + "symfony/console": "~2.5|~3.0|~4.0" }, "require-dev": { - "symfony/yaml": "~2.3|~3.0", + "symfony/yaml": "~2.3|~3.0|~4.0", "phpunit/phpunit": "^6.0" }, "suggest": { From 7bfd172156e49bb5197a06dc0405bdf903fac863 Mon Sep 17 00:00:00 2001 From: Greg Bell Date: Sun, 21 May 2017 14:10:38 +1000 Subject: [PATCH 278/877] Clarify English and a few concepts - Globally change 'Shipping' to 'Shipment' - shipment is a noun and thus a clearer name for an object. - Move definition of unidirectional from example to the to of the document. - Explain inversedBy and mappedBy the first time they are used. - Clarify some ownership and bidirectionality text. - Minor English and punctuation fixes. --- docs/en/reference/association-mapping.rst | 91 ++++++++++++----------- 1 file changed, 49 insertions(+), 42 deletions(-) diff --git a/docs/en/reference/association-mapping.rst b/docs/en/reference/association-mapping.rst index a1a9f83a81a..b1cfa22c8a2 100644 --- a/docs/en/reference/association-mapping.rst +++ b/docs/en/reference/association-mapping.rst @@ -16,6 +16,9 @@ This chapter is split into three different sections. - :ref:`association_mapping_defaults` are explained that simplify the use-case examples. - :ref:`collections` are introduced that contain entities in associations. +An association is considered to be unidirectional if only one side of the association has +a property referring to the other side. + To gain a full understanding of associations you should also read about :doc:`owning and inverse sides of associations ` @@ -96,9 +99,7 @@ One-To-One, Unidirectional -------------------------- Here is an example of a one-to-one association with a ``Product`` entity that -references one ``Shipping`` entity. The ``Shipping`` does not reference back to -the ``Product`` so that the reference is said to be unidirectional, in one -direction only. +references one ``Shipment`` entity. .. configuration-block:: @@ -111,16 +112,16 @@ direction only. // ... /** - * @OneToOne(targetEntity="Shipping") - * @JoinColumn(name="shipping_id", referencedColumnName="id") + * @OneToOne(targetEntity="Shipment") + * @JoinColumn(name="shipment_id", referencedColumnName="id") */ - private $shipping; + private $shipment; // ... } /** @Entity */ - class Shipping + class Shipment { // ... } @@ -129,8 +130,8 @@ direction only. - - + + @@ -140,10 +141,10 @@ direction only. Product: type: entity oneToOne: - shipping: - targetEntity: Shipping + shipment: + targetEntity: Shipment joinColumn: - name: shipping_id + name: shipment_id referencedColumnName: id Note that the @JoinColumn is not really necessary in this example, @@ -155,15 +156,15 @@ Generated MySQL Schema: CREATE TABLE Product ( id INT AUTO_INCREMENT NOT NULL, - shipping_id INT DEFAULT NULL, - UNIQUE INDEX UNIQ_6FBC94267FE4B2B (shipping_id), + shipment_id INT DEFAULT NULL, + UNIQUE INDEX UNIQ_6FBC94267FE4B2B (shipment_id), PRIMARY KEY(id) ) ENGINE = InnoDB; - CREATE TABLE Shipping ( + CREATE TABLE Shipment ( id INT AUTO_INCREMENT NOT NULL, PRIMARY KEY(id) ) ENGINE = InnoDB; - ALTER TABLE Product ADD FOREIGN KEY (shipping_id) REFERENCES Shipping(id); + ALTER TABLE Product ADD FOREIGN KEY (shipment_id) REFERENCES Shipment(id); One-To-One, Bidirectional ------------------------- @@ -172,6 +173,10 @@ Here is a one-to-one relationship between a ``Customer`` and a ``Cart``. The ``Cart`` has a reference back to the ``Customer`` so it is bidirectional. +Here we see the ``mappedBy`` and ``inversedBy`` annotations for the first time. +They are used to tell Doctrine which property on the other side refers to the +object. + .. configuration-block:: .. code-block:: php @@ -251,8 +256,9 @@ Generated MySQL Schema: ) ENGINE = InnoDB; ALTER TABLE Cart ADD FOREIGN KEY (customer_id) REFERENCES Customer(id); -See how the foreign key is defined on the owning side of the -relation, the table ``Cart``. +We had a choice of sides on which to place the ``mappedBy`` attribute. Because it +is on the ``Cart``, that is the owning side of the relation, and thus holds the +foreign key. One-To-One, Self-referencing ---------------------------- @@ -294,15 +300,16 @@ With the generated MySQL Schema: One-To-Many, Bidirectional -------------------------- -A one-to-many association has to be bidirectional, unless you are using an -additional join-table. This is necessary, because of the foreign key -in a one-to-many association being defined on the "many" side. Doctrine -needs a many-to-one association that defines the mapping of this -foreign key. +A one-to-many association has to be bidirectional, unless you are using a +join table. This is because the many side in a one-to-many association holds +the foreign key, making it the owning side. Doctrine needs the many side +defined in order to understand the association. This bidirectional mapping requires the ``mappedBy`` attribute on the -``OneToMany`` association and the ``inversedBy`` attribute on the ``ManyToOne`` -association. +"one" side and the "inversedBy" attribute on the "many" side. + +This means there is no difference between a bidirectional one-to-many and a +bidirectional many-to-one. .. configuration-block:: @@ -754,14 +761,14 @@ one is bidirectional. The MySQL schema is exactly the same as for the Many-To-Many uni-directional case above. -Owning and Inverse Side on a ManyToMany association +Owning and Inverse Side on a ManyToMany Association ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For Many-To-Many associations you can chose which entity is the owning and which the inverse side. There is a very simple semantic rule to decide which side is more suitable to be the owning side -from a developers perspective. You only have to ask yourself, which -entity is responsible for the connection management and pick that +from a developers perspective. You only have to ask yourself which +entity is responsible for the connection management, and pick that as the owning side. Take an example of two entities ``Article`` and ``Tag``. Whenever @@ -769,7 +776,7 @@ you want to connect an Article to a Tag and vice-versa, it is mostly the Article that is responsible for this relation. Whenever you add a new article, you want to connect it with existing or new tags. Your create Article form will probably support this notion -and allow to specify the tags directly. This is why you should pick +and allow specifying the tags directly. This is why you should pick the Article as owning side, as it makes the code more understandable: @@ -883,14 +890,14 @@ As an example, consider this mapping: .. code-block:: php - + @@ -899,8 +906,8 @@ As an example, consider this mapping: Product: type: entity oneToOne: - shipping: - targetEntity: Shipping + shipment: + targetEntity: Shipment This is essentially the same as the following, more verbose, mapping: @@ -911,17 +918,17 @@ mapping: - - + + @@ -931,10 +938,10 @@ mapping: Product: type: entity oneToOne: - shipping: - targetEntity: Shipping + shipment: + targetEntity: Shipment joinColumn: - name: shipping_id + name: shipment_id referencedColumnName: id The @JoinTable definition used for many-to-many mappings has From 75821e75f502933bb61678b8b6ca10a4cbc8da7f Mon Sep 17 00:00:00 2001 From: Greg Bell Date: Sun, 21 May 2017 14:10:38 +1000 Subject: [PATCH 279/877] Clarify English and a few concepts - Globally change 'Shipping' to 'Shipment' - shipment is a noun and thus a clearer name for an object. - Move definition of unidirectional from example to the top of the document. - Explain inversedBy and mappedBy the first time they are used. - Clarify some ownership and bidirectionality text. - Minor English and punctuation fixes. --- docs/en/reference/association-mapping.rst | 91 ++++++++++++----------- 1 file changed, 49 insertions(+), 42 deletions(-) diff --git a/docs/en/reference/association-mapping.rst b/docs/en/reference/association-mapping.rst index a1a9f83a81a..b1cfa22c8a2 100644 --- a/docs/en/reference/association-mapping.rst +++ b/docs/en/reference/association-mapping.rst @@ -16,6 +16,9 @@ This chapter is split into three different sections. - :ref:`association_mapping_defaults` are explained that simplify the use-case examples. - :ref:`collections` are introduced that contain entities in associations. +An association is considered to be unidirectional if only one side of the association has +a property referring to the other side. + To gain a full understanding of associations you should also read about :doc:`owning and inverse sides of associations ` @@ -96,9 +99,7 @@ One-To-One, Unidirectional -------------------------- Here is an example of a one-to-one association with a ``Product`` entity that -references one ``Shipping`` entity. The ``Shipping`` does not reference back to -the ``Product`` so that the reference is said to be unidirectional, in one -direction only. +references one ``Shipment`` entity. .. configuration-block:: @@ -111,16 +112,16 @@ direction only. // ... /** - * @OneToOne(targetEntity="Shipping") - * @JoinColumn(name="shipping_id", referencedColumnName="id") + * @OneToOne(targetEntity="Shipment") + * @JoinColumn(name="shipment_id", referencedColumnName="id") */ - private $shipping; + private $shipment; // ... } /** @Entity */ - class Shipping + class Shipment { // ... } @@ -129,8 +130,8 @@ direction only. - - + + @@ -140,10 +141,10 @@ direction only. Product: type: entity oneToOne: - shipping: - targetEntity: Shipping + shipment: + targetEntity: Shipment joinColumn: - name: shipping_id + name: shipment_id referencedColumnName: id Note that the @JoinColumn is not really necessary in this example, @@ -155,15 +156,15 @@ Generated MySQL Schema: CREATE TABLE Product ( id INT AUTO_INCREMENT NOT NULL, - shipping_id INT DEFAULT NULL, - UNIQUE INDEX UNIQ_6FBC94267FE4B2B (shipping_id), + shipment_id INT DEFAULT NULL, + UNIQUE INDEX UNIQ_6FBC94267FE4B2B (shipment_id), PRIMARY KEY(id) ) ENGINE = InnoDB; - CREATE TABLE Shipping ( + CREATE TABLE Shipment ( id INT AUTO_INCREMENT NOT NULL, PRIMARY KEY(id) ) ENGINE = InnoDB; - ALTER TABLE Product ADD FOREIGN KEY (shipping_id) REFERENCES Shipping(id); + ALTER TABLE Product ADD FOREIGN KEY (shipment_id) REFERENCES Shipment(id); One-To-One, Bidirectional ------------------------- @@ -172,6 +173,10 @@ Here is a one-to-one relationship between a ``Customer`` and a ``Cart``. The ``Cart`` has a reference back to the ``Customer`` so it is bidirectional. +Here we see the ``mappedBy`` and ``inversedBy`` annotations for the first time. +They are used to tell Doctrine which property on the other side refers to the +object. + .. configuration-block:: .. code-block:: php @@ -251,8 +256,9 @@ Generated MySQL Schema: ) ENGINE = InnoDB; ALTER TABLE Cart ADD FOREIGN KEY (customer_id) REFERENCES Customer(id); -See how the foreign key is defined on the owning side of the -relation, the table ``Cart``. +We had a choice of sides on which to place the ``mappedBy`` attribute. Because it +is on the ``Cart``, that is the owning side of the relation, and thus holds the +foreign key. One-To-One, Self-referencing ---------------------------- @@ -294,15 +300,16 @@ With the generated MySQL Schema: One-To-Many, Bidirectional -------------------------- -A one-to-many association has to be bidirectional, unless you are using an -additional join-table. This is necessary, because of the foreign key -in a one-to-many association being defined on the "many" side. Doctrine -needs a many-to-one association that defines the mapping of this -foreign key. +A one-to-many association has to be bidirectional, unless you are using a +join table. This is because the many side in a one-to-many association holds +the foreign key, making it the owning side. Doctrine needs the many side +defined in order to understand the association. This bidirectional mapping requires the ``mappedBy`` attribute on the -``OneToMany`` association and the ``inversedBy`` attribute on the ``ManyToOne`` -association. +"one" side and the "inversedBy" attribute on the "many" side. + +This means there is no difference between a bidirectional one-to-many and a +bidirectional many-to-one. .. configuration-block:: @@ -754,14 +761,14 @@ one is bidirectional. The MySQL schema is exactly the same as for the Many-To-Many uni-directional case above. -Owning and Inverse Side on a ManyToMany association +Owning and Inverse Side on a ManyToMany Association ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For Many-To-Many associations you can chose which entity is the owning and which the inverse side. There is a very simple semantic rule to decide which side is more suitable to be the owning side -from a developers perspective. You only have to ask yourself, which -entity is responsible for the connection management and pick that +from a developers perspective. You only have to ask yourself which +entity is responsible for the connection management, and pick that as the owning side. Take an example of two entities ``Article`` and ``Tag``. Whenever @@ -769,7 +776,7 @@ you want to connect an Article to a Tag and vice-versa, it is mostly the Article that is responsible for this relation. Whenever you add a new article, you want to connect it with existing or new tags. Your create Article form will probably support this notion -and allow to specify the tags directly. This is why you should pick +and allow specifying the tags directly. This is why you should pick the Article as owning side, as it makes the code more understandable: @@ -883,14 +890,14 @@ As an example, consider this mapping: .. code-block:: php - + @@ -899,8 +906,8 @@ As an example, consider this mapping: Product: type: entity oneToOne: - shipping: - targetEntity: Shipping + shipment: + targetEntity: Shipment This is essentially the same as the following, more verbose, mapping: @@ -911,17 +918,17 @@ mapping: - - + + @@ -931,10 +938,10 @@ mapping: Product: type: entity oneToOne: - shipping: - targetEntity: Shipping + shipment: + targetEntity: Shipment joinColumn: - name: shipping_id + name: shipment_id referencedColumnName: id The @JoinTable definition used for many-to-many mappings has From 46cebfb33ddb93e981837763be9467f6892576dc Mon Sep 17 00:00:00 2001 From: Greg Bell Date: Sun, 21 May 2017 16:39:06 +1000 Subject: [PATCH 280/877] Clarify concepts, fix minor English issues. - Globally change 'Shipping' to 'Shipment' - shipment is a noun and thus a clearer name for an object. - Add definition of unidirectional to the top of the document. - Explain inversedBy and mappedBy the first time they are used. - Clarify some ownership and bidirectionality text. - Minor English and punctuation fixes. --- docs/en/reference/association-mapping.rst | 95 ++++++++++++----------- 1 file changed, 51 insertions(+), 44 deletions(-) diff --git a/docs/en/reference/association-mapping.rst b/docs/en/reference/association-mapping.rst index 1b58baa0db2..ca3b02f9ea5 100644 --- a/docs/en/reference/association-mapping.rst +++ b/docs/en/reference/association-mapping.rst @@ -24,6 +24,9 @@ One tip for working with relations is to read the relation from left to right, w See below for all the possible relations. +An association is considered to be unidirectional if only one side of the association has +a property referring to the other side. + To gain a full understanding of associations you should also read about :doc:`owning and inverse sides of associations ` @@ -105,9 +108,7 @@ One-To-One, Unidirectional -------------------------- Here is an example of a one-to-one association with a ``Product`` entity that -references one ``Shipping`` entity. The ``Shipping`` does not reference back to -the ``Product`` so that the reference is said to be unidirectional, in one -direction only. +references one ``Shipment`` entity. .. configuration-block:: @@ -120,17 +121,17 @@ direction only. // ... /** - * One Product has One Shipping. - * @OneToOne(targetEntity="Shipping") - * @JoinColumn(name="shipping_id", referencedColumnName="id") + * One Product has One Shipment. + * @OneToOne(targetEntity="Shipment") + * @JoinColumn(name="shipment_id", referencedColumnName="id") */ - private $shipping; + private $shipment; // ... } /** @Entity */ - class Shipping + class Shipment { // ... } @@ -139,8 +140,8 @@ direction only. - - + + @@ -150,10 +151,10 @@ direction only. Product: type: entity oneToOne: - shipping: - targetEntity: Shipping + shipment: + targetEntity: Shipment joinColumn: - name: shipping_id + name: shipment_id referencedColumnName: id Note that the @JoinColumn is not really necessary in this example, @@ -165,15 +166,15 @@ Generated MySQL Schema: CREATE TABLE Product ( id INT AUTO_INCREMENT NOT NULL, - shipping_id INT DEFAULT NULL, - UNIQUE INDEX UNIQ_6FBC94267FE4B2B (shipping_id), + shipment_id INT DEFAULT NULL, + UNIQUE INDEX UNIQ_6FBC94267FE4B2B (shipment_id), PRIMARY KEY(id) ) ENGINE = InnoDB; - CREATE TABLE Shipping ( + CREATE TABLE Shipment ( id INT AUTO_INCREMENT NOT NULL, PRIMARY KEY(id) ) ENGINE = InnoDB; - ALTER TABLE Product ADD FOREIGN KEY (shipping_id) REFERENCES Shipping(id); + ALTER TABLE Product ADD FOREIGN KEY (shipment_id) REFERENCES Shipment(id); One-To-One, Bidirectional ------------------------- @@ -182,6 +183,10 @@ Here is a one-to-one relationship between a ``Customer`` and a ``Cart``. The ``Cart`` has a reference back to the ``Customer`` so it is bidirectional. +Here we see the ``mappedBy`` and ``inversedBy`` annotations for the first time. +They are used to tell Doctrine which property on the other side refers to the +object. + .. configuration-block:: .. code-block:: php @@ -263,8 +268,9 @@ Generated MySQL Schema: ) ENGINE = InnoDB; ALTER TABLE Cart ADD FOREIGN KEY (customer_id) REFERENCES Customer(id); -See how the foreign key is defined on the owning side of the -relation, the table ``Cart``. +We had a choice of sides on which to place the ``mappedBy`` attribute. Because it +is on the ``Cart``, that is the owning side of the relation, and thus holds the +foreign key. One-To-One, Self-referencing ---------------------------- @@ -307,15 +313,16 @@ With the generated MySQL Schema: One-To-Many, Bidirectional -------------------------- -A one-to-many association has to be bidirectional, unless you are using an -additional join-table. This is necessary, because of the foreign key -in a one-to-many association being defined on the "many" side. Doctrine -needs a many-to-one association that defines the mapping of this -foreign key. +A one-to-many association has to be bidirectional, unless you are using a +join table. This is because the many side in a one-to-many association holds +the foreign key, making it the owning side. Doctrine needs the many side +defined in order to understand the association. This bidirectional mapping requires the ``mappedBy`` attribute on the -``OneToMany`` association and the ``inversedBy`` attribute on the ``ManyToOne`` -association. +"one" side and the ``inversedBy`` attribute on the "many" side. + +This means there is no difference between a bidirectional one-to-many and a +bidirectional many-to-one. .. configuration-block:: @@ -775,14 +782,14 @@ one is bidirectional. The MySQL schema is exactly the same as for the Many-To-Many uni-directional case above. -Owning and Inverse Side on a ManyToMany association +Owning and Inverse Side on a ManyToMany Association ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For Many-To-Many associations you can chose which entity is the owning and which the inverse side. There is a very simple semantic rule to decide which side is more suitable to be the owning side -from a developers perspective. You only have to ask yourself, which -entity is responsible for the connection management and pick that +from a developers perspective. You only have to ask yourself which +entity is responsible for the connection management, and pick that as the owning side. Take an example of two entities ``Article`` and ``Tag``. Whenever @@ -790,7 +797,7 @@ you want to connect an Article to a Tag and vice-versa, it is mostly the Article that is responsible for this relation. Whenever you add a new article, you want to connect it with existing or new tags. Your create Article form will probably support this notion -and allow to specify the tags directly. This is why you should pick +and allow specifying the tags directly. This is why you should pick the Article as owning side, as it makes the code more understandable: @@ -906,14 +913,14 @@ As an example, consider this mapping: .. code-block:: php - + @@ -922,8 +929,8 @@ As an example, consider this mapping: Product: type: entity oneToOne: - shipping: - targetEntity: Shipping + shipment: + targetEntity: Shipment This is essentially the same as the following, more verbose, mapping: @@ -934,18 +941,18 @@ mapping: - - + + @@ -955,10 +962,10 @@ mapping: Product: type: entity oneToOne: - shipping: - targetEntity: Shipping + shipment: + targetEntity: Shipment joinColumn: - name: shipping_id + name: shipment_id referencedColumnName: id The @JoinTable definition used for many-to-many mappings has From f304685c6887a58a1236d48524724a67301dbef9 Mon Sep 17 00:00:00 2001 From: Maciej Kosiedowski Date: Mon, 22 May 2017 14:40:12 +0200 Subject: [PATCH 281/877] Fix #6460 - \Doctrine\ORM\Mapping\ClassMetadataInfo::hasField should return true for embedded fields --- .../ORM/Mapping/ClassMetadataInfo.php | 2 +- .../ORM/Functional/Ticket/DDC6460Test.php | 100 ++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6460Test.php diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index f265814b161..75b5281754f 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -1852,7 +1852,7 @@ public function getIdentifier() */ public function hasField($fieldName) { - return isset($this->fieldMappings[$fieldName]); + return isset($this->fieldMappings[$fieldName]) || isset($this->embeddedClasses[$fieldName]); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6460Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6460Test.php new file mode 100644 index 00000000000..d50e2dbdadc --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6460Test.php @@ -0,0 +1,100 @@ +_schemaTool->createSchema( + [ + $this->_em->getClassMetadata(DDC6460Entity::class), + $this->_em->getClassMetadata(DDC6460ParentEntity::class), + ] + ); + } catch (\Exception $e) { + } + } + + public function testInlineEmbeddable() + { + $isFieldMapped = $this->_em + ->getClassMetadata(DDC6460Entity::class) + ->hasField('embedded'); + + $this->assertTrue($isFieldMapped); + } + + public function testInlineEmbeddableProxyInitialization() + { + $entity = new DDC6460Entity(); + $entity->id = 1; + $entity->embedded = new DDC6460Embeddable(); + $entity->embedded->field = 'test'; + $this->_em->persist($entity); + $this->_em->flush(); + + $second = new DDC6460ParentEntity(); + $second->id = 1; + $second->lazyLoaded = $entity; + $this->_em->persist($second); + $this->_em->flush(); + + $this->_em->clear(); + + $proxy = $this->_em->getRepository(DDC6460ParentEntity::class)->findOneById(1); + + $this->assertNotNull($proxy->lazyLoaded->embedded); + } +} + +/** + * @Embeddable() + */ +class DDC6460Embeddable +{ + /** @Column(type="string") */ + public $field; +} + +/** + * @Entity() + */ +class DDC6460Entity +{ + /** + * @Id + * @GeneratedValue(strategy = "NONE") + * @Column(type = "integer") + */ + public $id; + + /** @Embedded(class = "DDC6460Embeddable") */ + public $embedded; +} + +/** + * @Entity() + */ +class DDC6460ParentEntity +{ + /** + * @Id + * @GeneratedValue(strategy = "NONE") + * @Column(type = "integer") + */ + public $id; + + /** @ManyToOne(targetEntity = "DDC6460Entity", fetch="EXTRA_LAZY") */ + public $lazyLoaded; +} From 76f0fe45af6568b6d862a7bd06f153f066495f2d Mon Sep 17 00:00:00 2001 From: Maciej Kosiedowski Date: Mon, 22 May 2017 15:52:19 +0200 Subject: [PATCH 282/877] fixes in tests --- .../ORM/Functional/Ticket/DDC6460Test.php | 27 +++++++++++++------ .../Tests/ORM/Mapping/ClassMetadataTest.php | 18 +++++++++++++ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6460Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6460Test.php index d50e2dbdadc..9868c7d1c00 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6460Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6460Test.php @@ -2,12 +2,14 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\DBAL\Schema\SchemaException; use Doctrine\ORM\Mapping\Column; use Doctrine\ORM\Mapping\Embeddable; use Doctrine\ORM\Mapping\Entity; use Doctrine\ORM\Mapping\Id; use Doctrine\ORM\Mapping\GeneratedValue; use Doctrine\ORM\Mapping\ManyToOne; +use Doctrine\ORM\Proxy\Proxy; class DDC6460Test extends \Doctrine\Tests\OrmFunctionalTestCase { @@ -16,16 +18,19 @@ public function setUp() parent::setUp(); try { - $this->_schemaTool->createSchema( + $this->setUpEntitySchema( [ - $this->_em->getClassMetadata(DDC6460Entity::class), - $this->_em->getClassMetadata(DDC6460ParentEntity::class), + DDC6460Entity::class, + DDC6460ParentEntity::class, ] ); - } catch (\Exception $e) { + } catch (SchemaException $e) { } } + /** + * @group DDC-6460 + */ public function testInlineEmbeddable() { $isFieldMapped = $this->_em @@ -35,6 +40,9 @@ public function testInlineEmbeddable() $this->assertTrue($isFieldMapped); } + /** + * @group DDC-6460 + */ public function testInlineEmbeddableProxyInitialization() { $entity = new DDC6460Entity(); @@ -42,7 +50,6 @@ public function testInlineEmbeddableProxyInitialization() $entity->embedded = new DDC6460Embeddable(); $entity->embedded->field = 'test'; $this->_em->persist($entity); - $this->_em->flush(); $second = new DDC6460ParentEntity(); $second->id = 1; @@ -52,9 +59,13 @@ public function testInlineEmbeddableProxyInitialization() $this->_em->clear(); - $proxy = $this->_em->getRepository(DDC6460ParentEntity::class)->findOneById(1); + $secondEntityWithLazyParameter = $this->_em->getRepository(DDC6460ParentEntity::class)->findOneById(1); - $this->assertNotNull($proxy->lazyLoaded->embedded); + $this->assertInstanceOf(Proxy::class, $secondEntityWithLazyParameter->lazyLoaded); + $this->assertInstanceOf(DDC6460Entity::class, $secondEntityWithLazyParameter->lazyLoaded); + $this->assertFalse($secondEntityWithLazyParameter->lazyLoaded->__isInitialized()); + $this->assertEquals($secondEntityWithLazyParameter->lazyLoaded->embedded, $entity->embedded); + $this->assertTrue($secondEntityWithLazyParameter->lazyLoaded->__isInitialized()); } } @@ -95,6 +106,6 @@ class DDC6460ParentEntity */ public $id; - /** @ManyToOne(targetEntity = "DDC6460Entity", fetch="EXTRA_LAZY") */ + /** @ManyToOne(targetEntity = "DDC6460Entity", fetch="EXTRA_LAZY", cascade={"persist"}) */ public $lazyLoaded; } diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php index 734ea8547ed..24d9559f78a 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php @@ -1269,6 +1269,24 @@ public function testGetColumnNamesWithGivenFieldNames() self::assertSame(['foo', 'baz'], $metadata->getColumnNames(['status', 'name'])); } + + /** + * @group DDC-6460 + */ + public function testInlineEmbeddable() + { + $classMetadata = new ClassMetadata(TestEntity1::class); + + $classMetadata->mapEmbedded( + [ + 'fieldName' => 'test', + 'class' => TestEntity1::class, + 'columnPrefix' => false, + ] + ); + + $this->assertTrue($classMetadata->hasField('test')); + } } /** From 4bf2e890fb3318d6abb0f3d8f64235db0dac0cd7 Mon Sep 17 00:00:00 2001 From: Simone Gentili Date: Mon, 15 May 2017 07:15:26 +0200 Subject: [PATCH 283/877] remove loosely comparison --- lib/Doctrine/ORM/Cache/DefaultCacheFactory.php | 5 ++++- .../ORM/Cache/DefaultCacheFactoryTest.php | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php b/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php index 3bfccdf8456..7c1b2efa528 100644 --- a/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php +++ b/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php @@ -210,7 +210,10 @@ public function getRegion(array $cache) if ($cache['usage'] === ClassMetadata::CACHE_USAGE_READ_WRITE) { - if ( ! $this->fileLockRegionDirectory) { + if ( + '' === $this->fileLockRegionDirectory || + null === $this->fileLockRegionDirectory + ) { throw new \LogicException( 'If you want to use a "READ_WRITE" cache an implementation of "Doctrine\ORM\Cache\ConcurrentRegion" is required, ' . 'The default implementation provided by doctrine is "Doctrine\ORM\Cache\Region\FileLockRegion" if you want to use it please provide a valid directory, DefaultCacheFactory#setFileLockRegionDirectory(). ' diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php index 1ca213b20e0..54fd59e370f 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php @@ -275,6 +275,24 @@ public function testInvalidFileLockRegionDirectoryException() ); } + /** + * @expectedException LogicException + * @expectedExceptionMessage If you want to use a "READ_WRITE" cache an implementation of "Doctrine\ORM\Cache\ConcurrentRegion" is required, The default implementation provided by doctrine is "Doctrine\ORM\Cache\Region\FileLockRegion" if you want to use it please provide a valid directory + */ + public function testInvalidFileLockRegionDirectoryExceptionWithEmptyString() + { + $factory = new DefaultCacheFactory($this->regionsConfig, $this->getSharedSecondLevelCacheDriverImpl()); + + $factory->setFileLockRegionDirectory(''); + + $factory->getRegion( + [ + 'usage' => ClassMetadata::CACHE_USAGE_READ_WRITE, + 'region' => 'foo' + ] + ); + } + public function testBuildsNewNamespacedCacheInstancePerRegionInstance() { $factory = new DefaultCacheFactory($this->regionsConfig, $this->getSharedSecondLevelCacheDriverImpl()); From db528a44b14e76751c41232f81601cfe8e263ad9 Mon Sep 17 00:00:00 2001 From: Franck Magnan Date: Tue, 23 May 2017 15:24:24 +0200 Subject: [PATCH 284/877] Update QueryBuilder.php Hello, thank you very much for your work, it's awesome! I found a minor error in PHPDOC for method setParameter. Argument "type" can be a string or null but can be also an int if it comes from \PDO::PARAM_*. So I've changed typehint "string" into "mixed". --- lib/Doctrine/ORM/QueryBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/QueryBuilder.php b/lib/Doctrine/ORM/QueryBuilder.php index 70b55f17d5c..894fbc32f74 100644 --- a/lib/Doctrine/ORM/QueryBuilder.php +++ b/lib/Doctrine/ORM/QueryBuilder.php @@ -526,7 +526,7 @@ public function getRootEntities() * * @param string|integer $key The parameter position or name. * @param mixed $value The parameter value. - * @param string|null $type PDO::PARAM_* or \Doctrine\DBAL\Types\Type::* constant + * @param string|integer|null $type PDO::PARAM_* or \Doctrine\DBAL\Types\Type::* constant * * @return self */ From f18e1789608ee24aa130e32f7db98a6e25f60394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Tue, 30 May 2017 12:51:51 +0200 Subject: [PATCH 285/877] Fix wrong YAML mapping We had duplicated keys and that's no longer valid on symfony/yaml 3.3. --- .../ORM/Mapping/yaml/Doctrine.Tests.Models.CMS.CmsUser.dcm.yml | 3 +-- .../yaml/Doctrine.Tests.Models.Company.CompanyPerson.dcm.yml | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.CMS.CmsUser.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.CMS.CmsUser.dcm.yml index 3a03dd6c32e..329e3d061dc 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.CMS.CmsUser.dcm.yml +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.CMS.CmsUser.dcm.yml @@ -135,7 +135,6 @@ Doctrine\Tests\Models\CMS\CmsUser: name: address_id referencedColumnName: id cascade: [ persist ] - oneToOne: email: targetEntity: CmsEmail orphanRemoval: true @@ -155,4 +154,4 @@ Doctrine\Tests\Models\CMS\CmsUser: inverseJoinColumns: group_id: referencedColumnName: id - cascade: [ persist , detach, merge] \ No newline at end of file + cascade: [ persist , detach, merge] diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.Company.CompanyPerson.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.Company.CompanyPerson.dcm.yml index 26846c5debd..28eec43e391 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.Company.CompanyPerson.dcm.yml +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.Company.CompanyPerson.dcm.yml @@ -52,7 +52,6 @@ Doctrine\Tests\Models\Company\CompanyPerson: name: address_id referencedColumnName: id cascade: [ persist ] - oneToOne: email: targetEntity: CmsEmail orphanRemoval: true @@ -72,4 +71,4 @@ Doctrine\Tests\Models\Company\CompanyPerson: inverseJoinColumns: group_id: referencedColumnName: id - cascade: [ persist , detach, merge] \ No newline at end of file + cascade: [ persist , detach, merge] From f9062d9931938222d6f50832b02b75131dfd03e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Tue, 30 May 2017 12:53:07 +0200 Subject: [PATCH 286/877] Force YAML parser to convert keys to string Since Symfony 3.3 implicit conversion is not enabled by default so we need to pass that flag manually. Related to: https://github.com/symfony/symfony/pull/21774 --- lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index 8793c070b7b..5161ed0f039 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -800,6 +800,10 @@ private function cacheToArray($cacheMapping) */ protected function loadMappingFile($file) { + if (defined(Yaml::class . '::PARSE_KEYS_AS_STRINGS')) { + return Yaml::parse(file_get_contents($file), Yaml::PARSE_KEYS_AS_STRINGS); + } + return Yaml::parse(file_get_contents($file)); } } From 92476b5953185b640ee6d4959f9568912c271305 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sat, 16 Jul 2016 12:12:33 +0200 Subject: [PATCH 287/877] #5934 - add `fetch` option to `AssociationOverride` in order to override fetch strategy for subclasses of entities --- docs/en/reference/inheritance-mapping.rst | 1 + doctrine-mapping.xsd | 1 + .../ORM/Mapping/AssociationOverride.php | 9 ++++ .../ORM/Mapping/ClassMetadataInfo.php | 4 ++ .../ORM/Mapping/Driver/AnnotationDriver.php | 5 ++ lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 5 ++ .../ORM/Mapping/Driver/YamlDriver.php | 5 ++ .../Models/DDC5934/DDC5934BaseContract.php | 53 +++++++++++++++++++ .../Tests/Models/DDC5934/DDC5934Contract.php | 24 +++++++++ .../Tests/Models/DDC5934/DDC5934Member.php | 24 +++++++++ .../ORM/Mapping/AbstractMappingDriverTest.php | 13 +++++ ...sts.Models.DDC5934.DDC5934BaseContract.php | 17 ++++++ ...e.Tests.Models.DDC5934.DDC5934Contract.php | 7 +++ ...Models.DDC5934.DDC5934BaseContract.dcm.xml | 15 ++++++ ...sts.Models.DDC5934.DDC5934Contract.dcm.xml | 13 +++++ ...Models.DDC5934.DDC5934BaseContract.dcm.yml | 12 +++++ ...sts.Models.DDC5934.DDC5934Contract.dcm.yml | 5 ++ 17 files changed, 213 insertions(+) create mode 100644 tests/Doctrine/Tests/Models/DDC5934/DDC5934BaseContract.php create mode 100644 tests/Doctrine/Tests/Models/DDC5934/DDC5934Contract.php create mode 100644 tests/Doctrine/Tests/Models/DDC5934/DDC5934Member.php create mode 100644 tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC5934.DDC5934BaseContract.php create mode 100644 tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC5934.DDC5934Contract.php create mode 100644 tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC5934.DDC5934BaseContract.dcm.xml create mode 100644 tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC5934.DDC5934Contract.dcm.xml create mode 100644 tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC5934.DDC5934BaseContract.dcm.yml create mode 100644 tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC5934.DDC5934Contract.dcm.yml diff --git a/docs/en/reference/inheritance-mapping.rst b/docs/en/reference/inheritance-mapping.rst index 9e895fcbc82..2063624fe91 100644 --- a/docs/en/reference/inheritance-mapping.rst +++ b/docs/en/reference/inheritance-mapping.rst @@ -455,6 +455,7 @@ Things to note: - The association type *CANNOT* be changed. - The override could redefine the joinTables or joinColumns depending on the association type. - The override could redefine inversedBy to reference more than one extended entity. +- The override could redefine fetch to modify the fetch strategy of the extended entity. Attribute Override ~~~~~~~~~~~~~~~~~~~~ diff --git a/doctrine-mapping.xsd b/doctrine-mapping.xsd index bb8624190e1..18fb6838ad1 100644 --- a/doctrine-mapping.xsd +++ b/doctrine-mapping.xsd @@ -567,6 +567,7 @@ + diff --git a/lib/Doctrine/ORM/Mapping/AssociationOverride.php b/lib/Doctrine/ORM/Mapping/AssociationOverride.php index 83cff417914..e208b16228a 100644 --- a/lib/Doctrine/ORM/Mapping/AssociationOverride.php +++ b/lib/Doctrine/ORM/Mapping/AssociationOverride.php @@ -57,4 +57,13 @@ final class AssociationOverride implements Annotation * @var string */ public $inversedBy; + + /** + * The fetching strategy to use for the association. + * + * @var string + * + * @Enum({"LAZY", "EAGER", "EXTRA_LAZY"}) + */ + public $fetch; } diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index f265814b161..e3da55bdf8d 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -2153,6 +2153,10 @@ public function setAssociationOverride($fieldName, array $overrideMapping) $mapping['joinTable'] = $overrideMapping['joinTable']; } + if (isset($overrideMapping['fetch'])) { + $mapping['fetch'] = $overrideMapping['fetch']; + } + $mapping['joinColumnFieldNames'] = null; $mapping['joinTableColumns'] = null; $mapping['sourceToTargetKeyColumns'] = null; diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index b5a5b714cbc..59730f6b21c 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -470,6 +470,11 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $override['inversedBy'] = $associationOverride->inversedBy; } + // Check for `fetch` + if ($associationOverride->fetch) { + $override['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . $associationOverride->fetch); + } + $metadata->setAssociationOverride($fieldName, $override); } } diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index d7099663f4f..0d51c4c9292 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -621,6 +621,11 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $override['inversedBy'] = (string) $overrideElement->{'inversed-by'}['name']; } + // Check for `fetch` + if (isset($overrideElement['fetch'])) { + $override['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . (string) $overrideElement['fetch']); + } + $metadata->setAssociationOverride($fieldName, $override); } } diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index 5161ed0f039..394722847a8 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -622,6 +622,11 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $override['inversedBy'] = (string) $associationOverrideElement['inversedBy']; } + // Check for `fetch` + if (isset($associationOverrideElement['fetch'])) { + $override['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . $associationOverrideElement['fetch']); + } + $metadata->setAssociationOverride($fieldName, $override); } } diff --git a/tests/Doctrine/Tests/Models/DDC5934/DDC5934BaseContract.php b/tests/Doctrine/Tests/Models/DDC5934/DDC5934BaseContract.php new file mode 100644 index 00000000000..84970c270b3 --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC5934/DDC5934BaseContract.php @@ -0,0 +1,53 @@ +members = new ArrayCollection(); + } + + public static function loadMetadata(ClassMetadata $metadata) + { + $metadata->mapField([ + 'id' => true, + 'fieldName' => 'id', + 'type' => 'integer', + 'columnName' => 'id', + ]); + + $metadata->mapManyToMany([ + 'fieldName' => 'members', + 'targetEntity' => 'DDC5934Member', + ]); + + $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO); + } +} diff --git a/tests/Doctrine/Tests/Models/DDC5934/DDC5934Contract.php b/tests/Doctrine/Tests/Models/DDC5934/DDC5934Contract.php new file mode 100644 index 00000000000..e26c4d66501 --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC5934/DDC5934Contract.php @@ -0,0 +1,24 @@ +setAssociationOverride('members', [ + 'fetch' => ClassMetadata::FETCH_EXTRA_LAZY, + ]); + } +} diff --git a/tests/Doctrine/Tests/Models/DDC5934/DDC5934Member.php b/tests/Doctrine/Tests/Models/DDC5934/DDC5934Member.php new file mode 100644 index 00000000000..ff85d6c6613 --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC5934/DDC5934Member.php @@ -0,0 +1,24 @@ +contracts = new ArrayCollection(); + } +} diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 4e19c987c16..f857bed4547 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -28,6 +28,7 @@ use Doctrine\Tests\Models\DDC2825\ExplicitSchemaAndTable; use Doctrine\Tests\Models\DDC2825\SchemaAndTableInTableName; use Doctrine\Tests\Models\DDC3579\DDC3579Admin; +use Doctrine\Tests\Models\DDC5934\DDC5934Contract; use Doctrine\Tests\Models\DDC869\DDC869ChequePayment; use Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment; use Doctrine\Tests\Models\DDC869\DDC869PaymentRepository; @@ -816,6 +817,18 @@ public function testInversedByOverrideMapping() $this->assertEquals('admins', $adminGroups['inversedBy']); } + /** + * @group DDC-5934 + */ + public function testFetchOverrideMapping() + { + // check override metadata + $contractMetadata = $this->createClassMetadataFactory()->getMetadataFor(DDC5934Contract::class); + + $this->assertArrayHasKey('members', $contractMetadata->associationMappings); + $this->assertSame(ClassMetadata::FETCH_EXTRA_LAZY, $contractMetadata->associationMappings['members']['fetch']); + } + /** * @group DDC-964 */ diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC5934.DDC5934BaseContract.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC5934.DDC5934BaseContract.php new file mode 100644 index 00000000000..fca4bb1185e --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC5934.DDC5934BaseContract.php @@ -0,0 +1,17 @@ +mapField([ + 'id' => true, + 'fieldName' => 'id', + 'type' => 'integer', + 'columnName' => 'id', +]); + +$metadata->mapManyToMany([ + 'fieldName' => 'members', + 'targetEntity' => 'DDC5934Member', +]); + +$metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC5934.DDC5934Contract.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC5934.DDC5934Contract.php new file mode 100644 index 00000000000..3ecf178a63c --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC5934.DDC5934Contract.php @@ -0,0 +1,7 @@ +setAssociationOverride('members', [ + 'fetch' => ClassMetadata::FETCH_EXTRA_LAZY, +]); diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC5934.DDC5934BaseContract.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC5934.DDC5934BaseContract.dcm.xml new file mode 100644 index 00000000000..78a5af6b8d6 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC5934.DDC5934BaseContract.dcm.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC5934.DDC5934Contract.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC5934.DDC5934Contract.dcm.xml new file mode 100644 index 00000000000..bba41b94ec7 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC5934.DDC5934Contract.dcm.xml @@ -0,0 +1,13 @@ + + + + + + + + + + diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC5934.DDC5934BaseContract.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC5934.DDC5934BaseContract.dcm.yml new file mode 100644 index 00000000000..2044c9be527 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC5934.DDC5934BaseContract.dcm.yml @@ -0,0 +1,12 @@ +Doctrine\Tests\Models\DDC5934\DDC5934BaseContract: + type: mappedSuperclass + id: + id: + type: integer + column: id + generator: + strategy: AUTO + manyToMany: + members: + targetEntity: DDC5934Member + inversedBy: contract diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC5934.DDC5934Contract.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC5934.DDC5934Contract.dcm.yml new file mode 100644 index 00000000000..45ba145853e --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC5934.DDC5934Contract.dcm.yml @@ -0,0 +1,5 @@ +Doctrine\Tests\Models\DDC5934\DDC5934Contract: + type: entity + associationOverride: + members: + fetch: EXTRA_LAZY From fcfaa13df9aada8321236a1459b58cc0eeabdf7b Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Wed, 31 May 2017 14:52:29 +0200 Subject: [PATCH 288/877] #5934 - #5938 - use `ClassMetadata::class` expression rather than FQCN in config drivers as of @Ocramius's review --- lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php | 2 +- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 2 +- lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index 59730f6b21c..d916bafb381 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -472,7 +472,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Check for `fetch` if ($associationOverride->fetch) { - $override['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . $associationOverride->fetch); + $override['fetch'] = constant(ClassMetadata::class . '::FETCH_' . $associationOverride->fetch); } $metadata->setAssociationOverride($fieldName, $override); diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 0d51c4c9292..2ca9190bc27 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -623,7 +623,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Check for `fetch` if (isset($overrideElement['fetch'])) { - $override['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . (string) $overrideElement['fetch']); + $override['fetch'] = constant(ClassMetadata::class . '::FETCH_' . (string) $overrideElement['fetch']); } $metadata->setAssociationOverride($fieldName, $override); diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index 394722847a8..d65481be46a 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -624,7 +624,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Check for `fetch` if (isset($associationOverrideElement['fetch'])) { - $override['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . $associationOverrideElement['fetch']); + $override['fetch'] = constant(ClassMetadata::class . '::FETCH_' . $associationOverrideElement['fetch']); } $metadata->setAssociationOverride($fieldName, $override); From 49bb34553316f34181a147b36f89192074345e30 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Wed, 31 May 2017 15:01:25 +0200 Subject: [PATCH 289/877] #5934 - #5938 - fix accidentally introduced regression with wrong target of ::class expression --- lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php | 2 +- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 3 ++- lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index d916bafb381..d59fd3bb773 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -472,7 +472,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Check for `fetch` if ($associationOverride->fetch) { - $override['fetch'] = constant(ClassMetadata::class . '::FETCH_' . $associationOverride->fetch); + $override['fetch'] = constant(Mapping\ClassMetadata::class . '::FETCH_' . $associationOverride->fetch); } $metadata->setAssociationOverride($fieldName, $override); diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 2ca9190bc27..603648ed5f2 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -24,6 +24,7 @@ use Doctrine\ORM\Mapping\Builder\EntityListenerBuilder; use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\MappingException; +use Doctrine\ORM\Mapping\ClassMetadata as Metadata; /** * XmlDriver is a metadata driver that enables mapping through XML files. @@ -623,7 +624,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Check for `fetch` if (isset($overrideElement['fetch'])) { - $override['fetch'] = constant(ClassMetadata::class . '::FETCH_' . (string) $overrideElement['fetch']); + $override['fetch'] = constant(Metadata::class . '::FETCH_' . (string) $overrideElement['fetch']); } $metadata->setAssociationOverride($fieldName, $override); diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index d65481be46a..0908a287887 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -22,6 +22,7 @@ use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\Builder\EntityListenerBuilder; use Doctrine\Common\Persistence\Mapping\Driver\FileDriver; +use Doctrine\ORM\Mapping\ClassMetadata as Metadata; use Doctrine\ORM\Mapping\MappingException; use Symfony\Component\Yaml\Yaml; @@ -624,7 +625,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) // Check for `fetch` if (isset($associationOverrideElement['fetch'])) { - $override['fetch'] = constant(ClassMetadata::class . '::FETCH_' . $associationOverrideElement['fetch']); + $override['fetch'] = constant(Metadata::class . '::FETCH_' . $associationOverrideElement['fetch']); } $metadata->setAssociationOverride($fieldName, $override); From 23593601492f6cee39f0fd7c5b68424a91539b4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 31 May 2017 11:25:10 +0200 Subject: [PATCH 290/877] Disable XDebug based on PHPUnit flags instead Then we don't need to keep changing versions information. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5509e3970e1..fab92a62927 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ env: before_script: - if [[ $TRAVIS_PHP_VERSION = '7.0' && $DB = 'sqlite' ]]; then PHPUNIT_FLAGS="--coverage-clover ./build/logs/clover.xml"; else PHPUNIT_FLAGS=""; fi - - if [[ $TRAVIS_PHP_VERSION -lt '7.0' && $TRAVIS_PHP_VERSION != 'hhv*' ]]; then phpenv config-rm xdebug.ini; fi + - if [[ "$PHPUNIT_FLAGS" == "" ]]; then phpenv config-rm xdebug.ini; fi - composer self-update - composer install --prefer-source - if [ "$DEPENDENCIES" != "low" ]; then composer update; fi; From 1559db7ac17f16c3cb07de7ca4866cda096a19b0 Mon Sep 17 00:00:00 2001 From: Mathew Davies Date: Thu, 8 Jun 2017 16:25:03 +0100 Subject: [PATCH 291/877] Update HydratorMockStatement to implement the right interface. --- tests/Doctrine/Tests/Mocks/HydratorMockStatement.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php b/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php index ca0df22fe71..f2a031488f3 100644 --- a/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php +++ b/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php @@ -30,13 +30,12 @@ public function __construct(array $resultSet) /** * Fetches all rows from the result set. * - * @param int|null $fetchStyle - * @param int|null $columnIndex + * @param null $fetchMode + * @param null $fetchArgument * @param array|null $ctorArgs - * * @return array */ - public function fetchAll($fetchStyle = null, $columnIndex = null, array $ctorArgs = null) + public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) { return $this->_resultSet; } @@ -55,7 +54,7 @@ public function fetchColumn($columnNumber = 0) /** * {@inheritdoc} */ - public function fetch($fetchStyle = null) + public function fetch($fetchStyle = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) { $current = current($this->_resultSet); next($this->_resultSet); @@ -108,8 +107,9 @@ public function errorInfo() /** * {@inheritdoc} */ - public function execute($params = []) + public function execute($params = null) { + } /** From a59367423adb725ea85f9f5adb0bba6dfed529f7 Mon Sep 17 00:00:00 2001 From: Mathew Davies Date: Thu, 8 Jun 2017 16:25:57 +0100 Subject: [PATCH 292/877] Update StatementMock to implement the right interface. --- tests/Doctrine/Tests/Mocks/StatementMock.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/Mocks/StatementMock.php b/tests/Doctrine/Tests/Mocks/StatementMock.php index 8107ff1beb1..efba7d841b4 100644 --- a/tests/Doctrine/Tests/Mocks/StatementMock.php +++ b/tests/Doctrine/Tests/Mocks/StatementMock.php @@ -75,14 +75,14 @@ public function setFetchMode($fetchStyle, $arg2 = null, $arg3 = null) /** * {@inheritdoc} */ - public function fetch($fetchStyle = null) + public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) { } /** * {@inheritdoc} */ - public function fetchAll($fetchStyle = null) + public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) { } From 633b821e18d62cc94ebd68c2038acc82ac2a5311 Mon Sep 17 00:00:00 2001 From: Mathew Davies Date: Thu, 8 Jun 2017 16:27:28 +0100 Subject: [PATCH 293/877] Update StatementArrayMock to implement the right interface. --- tests/Doctrine/Tests/Mocks/StatementArrayMock.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/Mocks/StatementArrayMock.php b/tests/Doctrine/Tests/Mocks/StatementArrayMock.php index 9ef37da463f..ed6ea4fdf6c 100644 --- a/tests/Doctrine/Tests/Mocks/StatementArrayMock.php +++ b/tests/Doctrine/Tests/Mocks/StatementArrayMock.php @@ -34,12 +34,12 @@ public function columnCount() } } - public function fetchAll($fetchStyle = null) + public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) { return $this->_result; } - public function fetch($fetchStyle = null) + public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) { $current = current($this->_result); next($this->_result); From 9f13557d144dc089ea9e9b41c8bbcc585c5bea8b Mon Sep 17 00:00:00 2001 From: Mathew Davies Date: Thu, 8 Jun 2017 16:42:11 +0100 Subject: [PATCH 294/877] Be consistent with the rest of the file. --- tests/Doctrine/Tests/Mocks/HydratorMockStatement.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php b/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php index f2a031488f3..3110dbce6f6 100644 --- a/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php +++ b/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php @@ -109,7 +109,6 @@ public function errorInfo() */ public function execute($params = null) { - } /** From b42c36f4720b3ccfac6b40e1d7566a468b0ae6a3 Mon Sep 17 00:00:00 2001 From: Mathew Davies Date: Thu, 8 Jun 2017 16:43:18 +0100 Subject: [PATCH 295/877] Update phpDoc --- tests/Doctrine/Tests/Mocks/HydratorMockStatement.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php b/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php index 3110dbce6f6..4f6df40e59d 100644 --- a/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php +++ b/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php @@ -30,8 +30,8 @@ public function __construct(array $resultSet) /** * Fetches all rows from the result set. * - * @param null $fetchMode - * @param null $fetchArgument + * @param int|null $fetchMode + * @param int|null $fetchArgument * @param array|null $ctorArgs * @return array */ From 43009682a49c9fa7fe1bacabf22a7230aa524e1f Mon Sep 17 00:00:00 2001 From: Artem Stepin Date: Thu, 8 Jun 2017 22:04:07 +0200 Subject: [PATCH 296/877] minor code work: - method calls with incorrect case - removed unused imports - typos and some other minor code smells - documentation update (wrong return types etc. ) --- lib/Doctrine/ORM/AbstractQuery.php | 3 --- lib/Doctrine/ORM/Cache/DefaultCacheFactory.php | 1 - .../ORM/Cache/Region/DefaultMultiGetRegion.php | 1 - lib/Doctrine/ORM/EntityManager.php | 1 - .../ORM/Internal/Hydration/ObjectHydrator.php | 2 +- lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php | 4 ++-- lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php | 4 ++-- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 2 +- lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php | 2 +- lib/Doctrine/ORM/Mapping/NamingStrategy.php | 10 +++++----- .../ORM/Persisters/Entity/BasicEntityPersister.php | 13 +++++++------ .../Persisters/Entity/JoinedSubclassPersister.php | 4 ++-- lib/Doctrine/ORM/Persisters/PersisterException.php | 3 +++ lib/Doctrine/ORM/Persisters/SqlValueVisitor.php | 4 ++-- lib/Doctrine/ORM/Query.php | 5 ++--- .../ORM/Query/AST/Functions/AbsFunction.php | 2 ++ .../ORM/Query/AST/Functions/BitAndFunction.php | 2 ++ .../ORM/Query/AST/Functions/BitOrFunction.php | 2 ++ .../ORM/Query/AST/Functions/ConcatFunction.php | 2 ++ .../Query/AST/Functions/CurrentDateFunction.php | 2 ++ .../Query/AST/Functions/CurrentTimeFunction.php | 2 ++ .../AST/Functions/CurrentTimestampFunction.php | 2 ++ .../ORM/Query/AST/Functions/DateAddFunction.php | 2 ++ .../ORM/Query/AST/Functions/DateDiffFunction.php | 2 ++ .../ORM/Query/AST/Functions/DateSubFunction.php | 1 + .../ORM/Query/AST/Functions/LengthFunction.php | 2 ++ .../ORM/Query/AST/Functions/LocateFunction.php | 2 ++ .../ORM/Query/AST/Functions/LowerFunction.php | 2 ++ .../ORM/Query/AST/Functions/ModFunction.php | 2 ++ .../ORM/Query/AST/Functions/SizeFunction.php | 2 ++ .../ORM/Query/AST/Functions/SqrtFunction.php | 2 ++ .../ORM/Query/AST/Functions/SubstringFunction.php | 2 ++ .../ORM/Query/AST/Functions/UpperFunction.php | 2 ++ lib/Doctrine/ORM/Query/Parser.php | 14 ++++++-------- lib/Doctrine/ORM/Query/SqlWalker.php | 6 +++--- .../Command/ConvertDoctrine1SchemaCommand.php | 1 - .../Console/Command/MappingDescribeCommand.php | 2 +- lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php | 4 ++-- .../ORM/Tools/Pagination/RowNumberOverFunction.php | 2 ++ .../ORM/Tools/ResolveTargetEntityListener.php | 2 +- lib/Doctrine/ORM/Tools/SchemaTool.php | 7 +++---- lib/Doctrine/ORM/Tools/SchemaValidator.php | 2 +- 42 files changed, 82 insertions(+), 52 deletions(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 0430a113fda..ba013bbbb69 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -27,9 +27,6 @@ use Doctrine\ORM\Cache\QueryCacheKey; use Doctrine\DBAL\Cache\QueryCacheProfile; -use Doctrine\ORM\Cache; -use Doctrine\ORM\Query\ResultSetMapping; - /** * Base contract for ORM queries. Base class for Query and NativeQuery. * diff --git a/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php b/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php index 3bfccdf8456..77a773a53c8 100644 --- a/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php +++ b/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php @@ -30,7 +30,6 @@ use Doctrine\ORM\Cache\Persister\Entity\NonStrictReadWriteCachedEntityPersister; use Doctrine\ORM\Cache\Persister\Entity\ReadOnlyCachedEntityPersister; use Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister; -use Doctrine\ORM\Cache\Region; use Doctrine\ORM\Cache\Region\DefaultMultiGetRegion; use Doctrine\ORM\Cache\Region\DefaultRegion; use Doctrine\ORM\Cache\Region\FileLockRegion; diff --git a/lib/Doctrine/ORM/Cache/Region/DefaultMultiGetRegion.php b/lib/Doctrine/ORM/Cache/Region/DefaultMultiGetRegion.php index 1df073c3e52..2cd94292b49 100644 --- a/lib/Doctrine/ORM/Cache/Region/DefaultMultiGetRegion.php +++ b/lib/Doctrine/ORM/Cache/Region/DefaultMultiGetRegion.php @@ -21,7 +21,6 @@ namespace Doctrine\ORM\Cache\Region; use Doctrine\Common\Cache\MultiGetCache; -use Doctrine\ORM\Cache\Region; use Doctrine\ORM\Cache\CollectionCacheEntry; /** diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 53573c25cd4..d4b032bfc1e 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -19,7 +19,6 @@ namespace Doctrine\ORM; -use Doctrine\ORM\Mapping\MappingException; use Exception; use Doctrine\Common\EventManager; use Doctrine\DBAL\Connection; diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index ef5e7437112..42f59973942 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -433,7 +433,7 @@ protected function hydrateRowData(array $row, array &$result) if ( ! $reflFieldValue || isset($this->_hints[Query::HINT_REFRESH]) || ($reflFieldValue instanceof Proxy && !$reflFieldValue->__isInitialized__)) { // we only need to take action if this value is null, - // we refresh the entity or its an unitialized proxy. + // we refresh the entity or its an uninitialized proxy. if (isset($nonemptyComponents[$dqlAlias])) { $element = $this->getEntity($data, $dqlAlias); $reflField->setValue($parentObject, $element); diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 61328cdacab..b5eebcdde2c 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -1376,7 +1376,7 @@ public function getSqlResultSetMappings() * * @param array $mapping The field mapping to validate & complete. * - * @return array The validated and completed field mapping. + * @return void * * @throws MappingException */ @@ -2034,7 +2034,7 @@ public function getTypeOfField($fieldName) * * @return \Doctrine\DBAL\Types\Type|string|null * - * @deprecated 3.0 remove this. this method is bogous and unreliable, since it cannot resolve the type of a column + * @deprecated 3.0 remove this. this method is bogus and unreliable, since it cannot resolve the type of a column * that is derived by a referenced field on a different entity. */ public function getTypeOfColumn($columnName) diff --git a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php index 41c740ec4e5..756399f6d43 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php @@ -393,7 +393,7 @@ private function buildFieldMapping($tableName, Column $column) 'fieldName' => $this->getFieldNameForColumn($tableName, $column->getName(), false), 'columnName' => $column->getName(), 'type' => $column->getType()->getName(), - 'nullable' => ( ! $column->getNotNull()), + 'nullable' => ( ! $column->getNotnull()), ]; // Type specific elements @@ -482,7 +482,7 @@ private function buildToOneAssociationMappings(ClassMetadataInfo $metadata) } /** - * Retreive schema table definition foreign keys. + * Retrieve schema table definition foreign keys. * * @param \Doctrine\DBAL\Schema\Table $table * diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 603648ed5f2..39af412c9f2 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -166,7 +166,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $inheritanceType = (string) $xmlRoot['inheritance-type']; $metadata->setInheritanceType(constant('Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceType)); - if ($metadata->inheritanceType != \Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_NONE) { + if ($metadata->inheritanceType != Metadata::INHERITANCE_TYPE_NONE) { // Evaluate if (isset($xmlRoot->{'discriminator-column'})) { $discrColumn = $xmlRoot->{'discriminator-column'}; diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index 0908a287887..c4fb45ecedd 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -175,7 +175,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) if (isset($element['inheritanceType'])) { $metadata->setInheritanceType(constant('Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_' . strtoupper($element['inheritanceType']))); - if ($metadata->inheritanceType != \Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_NONE) { + if ($metadata->inheritanceType != Metadata::INHERITANCE_TYPE_NONE) { // Evaluate discriminatorColumn if (isset($element['discriminatorColumn'])) { $discrColumn = $element['discriminatorColumn']; diff --git a/lib/Doctrine/ORM/Mapping/NamingStrategy.php b/lib/Doctrine/ORM/Mapping/NamingStrategy.php index 8845cb1ed5f..9960f949f16 100644 --- a/lib/Doctrine/ORM/Mapping/NamingStrategy.php +++ b/lib/Doctrine/ORM/Mapping/NamingStrategy.php @@ -52,8 +52,10 @@ function propertyToColumnName($propertyName, $className = null); /** * Returns a column name for an embedded property. * - * @param string $propertyName - * @param string $embeddedColumnName + * @param string $propertyName + * @param string $embeddedColumnName + * @param string $className + * @param string $embeddedClassName * * @return string */ @@ -70,12 +72,10 @@ function referenceColumnName(); * Returns a join column name for a property. * * @param string $propertyName A property name. - * @param string|null $className The fully-qualified class name. - * This parameter is omitted from the signature due to BC * * @return string A join column name. */ - function joinColumnName($propertyName/*, $className = null*/); + function joinColumnName($propertyName); /** * Returns a join table name. diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 28dc9179afc..6af159fc7b6 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -1064,11 +1064,11 @@ public function getSelectSQL($criteria, $assoc = null, $lockMode = null, $limit switch ($lockMode) { case LockMode::PESSIMISTIC_READ: - $lockSql = ' ' . $this->platform->getReadLockSql(); + $lockSql = ' ' . $this->platform->getReadLockSQL(); break; case LockMode::PESSIMISTIC_WRITE: - $lockSql = ' ' . $this->platform->getWriteLockSql(); + $lockSql = ' ' . $this->platform->getWriteLockSQL(); break; } @@ -1520,12 +1520,12 @@ public function lock(array $criteria, $lockMode) switch ($lockMode) { case LockMode::PESSIMISTIC_READ: - $lockSql = $this->platform->getReadLockSql(); + $lockSql = $this->platform->getReadLockSQL(); break; case LockMode::PESSIMISTIC_WRITE: - $lockSql = $this->platform->getWriteLockSql(); + $lockSql = $this->platform->getWriteLockSQL(); break; } @@ -1870,8 +1870,9 @@ private function expandToManyParameters($criteria) /** * Infers field types to be used by parameter type casting. * - * @param string $field - * @param mixed $value + * @param string $field + * @param mixed $value + * @param ClassMetadata $class * * @return array * diff --git a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php index 6c09b604a75..0be15068977 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php @@ -341,13 +341,13 @@ public function getSelectSQL($criteria, $assoc = null, $lockMode = null, $limit switch ($lockMode) { case LockMode::PESSIMISTIC_READ: - $lockSql = ' ' . $this->platform->getReadLockSql(); + $lockSql = ' ' . $this->platform->getReadLockSQL(); break; case LockMode::PESSIMISTIC_WRITE: - $lockSql = ' ' . $this->platform->getWriteLockSql(); + $lockSql = ' ' . $this->platform->getWriteLockSQL(); break; } diff --git a/lib/Doctrine/ORM/Persisters/PersisterException.php b/lib/Doctrine/ORM/Persisters/PersisterException.php index 71fd0d179bc..09f73b21b5d 100644 --- a/lib/Doctrine/ORM/Persisters/PersisterException.php +++ b/lib/Doctrine/ORM/Persisters/PersisterException.php @@ -24,6 +24,9 @@ class PersisterException extends ORMException { /** + * @param string $class + * @param string $associationName + * * @return PersisterException */ static public function matchingAssocationFieldRequiresObject($class, $associationName) diff --git a/lib/Doctrine/ORM/Persisters/SqlValueVisitor.php b/lib/Doctrine/ORM/Persisters/SqlValueVisitor.php index c8df1919d9a..78fd0333bb0 100644 --- a/lib/Doctrine/ORM/Persisters/SqlValueVisitor.php +++ b/lib/Doctrine/ORM/Persisters/SqlValueVisitor.php @@ -46,7 +46,7 @@ class SqlValueVisitor extends ExpressionVisitor * * @param \Doctrine\Common\Collections\Expr\Comparison $comparison * - * @return mixed + * @return void */ public function walkComparison(Comparison $comparison) { @@ -69,7 +69,7 @@ public function walkComparison(Comparison $comparison) * * @param \Doctrine\Common\Collections\Expr\CompositeExpression $expr * - * @return mixed + * @return void */ public function walkCompositeExpression(CompositeExpression $expr) { diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 6d874a8ad1a..385b8c8ea6b 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -19,7 +19,6 @@ namespace Doctrine\ORM; -use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\LockMode; use Doctrine\ORM\Query\Exec\AbstractSqlExecutor; use Doctrine\ORM\Query\Parser; @@ -204,7 +203,7 @@ final class Query extends AbstractQuery */ public function getSQL() { - return $this->_parse()->getSQLExecutor()->getSQLStatements(); + return $this->_parse()->getSqlExecutor()->getSqlStatements(); } /** @@ -738,7 +737,7 @@ protected function _getQueryCacheId() ->getName(); return md5( - $this->getDql() . serialize($this->_hints) . + $this->getDQL() . serialize($this->_hints) . '&platform=' . $platform . ($this->_em->hasFilters() ? $this->_em->getFilters()->getHash() : '') . '&firstResult=' . $this->_firstResult . '&maxResult=' . $this->_maxResults . diff --git a/lib/Doctrine/ORM/Query/AST/Functions/AbsFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/AbsFunction.php index 8fade4c7a89..4c614355844 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/AbsFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/AbsFunction.php @@ -41,6 +41,7 @@ class AbsFunction extends FunctionNode /** * @override + * @inheritdoc */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { @@ -51,6 +52,7 @@ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) /** * @override + * @inheritdoc */ public function parse(\Doctrine\ORM\Query\Parser $parser) { diff --git a/lib/Doctrine/ORM/Query/AST/Functions/BitAndFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/BitAndFunction.php index 3ea69c0c115..469a4b0a24e 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/BitAndFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/BitAndFunction.php @@ -36,6 +36,7 @@ class BitAndFunction extends FunctionNode /** * @override + * @inheritdoc */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { @@ -49,6 +50,7 @@ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) /** * @override + * @inheritdoc */ public function parse(\Doctrine\ORM\Query\Parser $parser) { diff --git a/lib/Doctrine/ORM/Query/AST/Functions/BitOrFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/BitOrFunction.php index 6b0d1eb4c32..d3a3efc8324 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/BitOrFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/BitOrFunction.php @@ -36,6 +36,7 @@ class BitOrFunction extends FunctionNode /** * @override + * @inheritdoc */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { @@ -49,6 +50,7 @@ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) /** * @override + * @inheritdoc */ public function parse(\Doctrine\ORM\Query\Parser $parser) { diff --git a/lib/Doctrine/ORM/Query/AST/Functions/ConcatFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/ConcatFunction.php index 71da374dfcd..b7c5ae13f82 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/ConcatFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/ConcatFunction.php @@ -42,6 +42,7 @@ class ConcatFunction extends FunctionNode /** * @override + * @inheritdoc */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { @@ -58,6 +59,7 @@ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) /** * @override + * @inheritdoc */ public function parse(\Doctrine\ORM\Query\Parser $parser) { diff --git a/lib/Doctrine/ORM/Query/AST/Functions/CurrentDateFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/CurrentDateFunction.php index 8e8ce1c77b0..565b87581b3 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/CurrentDateFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/CurrentDateFunction.php @@ -36,6 +36,7 @@ class CurrentDateFunction extends FunctionNode { /** * @override + * @inheritdoc */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { @@ -44,6 +45,7 @@ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) /** * @override + * @inheritdoc */ public function parse(\Doctrine\ORM\Query\Parser $parser) { diff --git a/lib/Doctrine/ORM/Query/AST/Functions/CurrentTimeFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/CurrentTimeFunction.php index 4bab247c0ff..ec9ceb757f5 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/CurrentTimeFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/CurrentTimeFunction.php @@ -36,6 +36,7 @@ class CurrentTimeFunction extends FunctionNode { /** * @override + * @inheritdoc */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { @@ -44,6 +45,7 @@ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) /** * @override + * @inheritdoc */ public function parse(\Doctrine\ORM\Query\Parser $parser) { diff --git a/lib/Doctrine/ORM/Query/AST/Functions/CurrentTimestampFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/CurrentTimestampFunction.php index 8a9b4185fb2..4203072128d 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/CurrentTimestampFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/CurrentTimestampFunction.php @@ -36,6 +36,7 @@ class CurrentTimestampFunction extends FunctionNode { /** * @override + * @inheritdoc */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { @@ -44,6 +45,7 @@ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) /** * @override + * @inheritdoc */ public function parse(\Doctrine\ORM\Query\Parser $parser) { diff --git a/lib/Doctrine/ORM/Query/AST/Functions/DateAddFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/DateAddFunction.php index 2a9aead98a4..859426f0801 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/DateAddFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/DateAddFunction.php @@ -41,6 +41,7 @@ class DateAddFunction extends FunctionNode /** * @override + * @inheritdoc */ public function getSql(SqlWalker $sqlWalker) { @@ -77,6 +78,7 @@ public function getSql(SqlWalker $sqlWalker) /** * @override + * @inheritdoc */ public function parse(Parser $parser) { diff --git a/lib/Doctrine/ORM/Query/AST/Functions/DateDiffFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/DateDiffFunction.php index a33c2d06f33..53724825f4e 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/DateDiffFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/DateDiffFunction.php @@ -38,6 +38,7 @@ class DateDiffFunction extends FunctionNode /** * @override + * @inheritdoc */ public function getSql(SqlWalker $sqlWalker) { @@ -49,6 +50,7 @@ public function getSql(SqlWalker $sqlWalker) /** * @override + * @inheritdoc */ public function parse(Parser $parser) { diff --git a/lib/Doctrine/ORM/Query/AST/Functions/DateSubFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/DateSubFunction.php index d0e890fa793..a6415a2863e 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/DateSubFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/DateSubFunction.php @@ -35,6 +35,7 @@ class DateSubFunction extends DateAddFunction { /** * @override + * @inheritdoc */ public function getSql(SqlWalker $sqlWalker) { diff --git a/lib/Doctrine/ORM/Query/AST/Functions/LengthFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/LengthFunction.php index e2729feebf7..3d2b1a6c92a 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/LengthFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/LengthFunction.php @@ -38,6 +38,7 @@ class LengthFunction extends FunctionNode /** * @override + * @inheritdoc */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { @@ -48,6 +49,7 @@ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) /** * @override + * @inheritdoc */ public function parse(\Doctrine\ORM\Query\Parser $parser) { diff --git a/lib/Doctrine/ORM/Query/AST/Functions/LocateFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/LocateFunction.php index cba45bc1cb1..473aa34eec9 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/LocateFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/LocateFunction.php @@ -44,6 +44,7 @@ class LocateFunction extends FunctionNode /** * @override + * @inheritdoc */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { @@ -60,6 +61,7 @@ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) /** * @override + * @inheritdoc */ public function parse(\Doctrine\ORM\Query\Parser $parser) { diff --git a/lib/Doctrine/ORM/Query/AST/Functions/LowerFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/LowerFunction.php index 5f0387e6f45..5f0fb950018 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/LowerFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/LowerFunction.php @@ -38,6 +38,7 @@ class LowerFunction extends FunctionNode /** * @override + * @inheritdoc */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { @@ -48,6 +49,7 @@ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) /** * @override + * @inheritdoc */ public function parse(\Doctrine\ORM\Query\Parser $parser) { diff --git a/lib/Doctrine/ORM/Query/AST/Functions/ModFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/ModFunction.php index f00c6db7f93..61bc9a79ed9 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/ModFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/ModFunction.php @@ -46,6 +46,7 @@ class ModFunction extends FunctionNode /** * @override + * @inheritdoc */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { @@ -57,6 +58,7 @@ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) /** * @override + * @inheritdoc */ public function parse(\Doctrine\ORM\Query\Parser $parser) { diff --git a/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php index 7970508f17f..bf0f7a4ec04 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php @@ -41,6 +41,7 @@ class SizeFunction extends FunctionNode /** * @override + * @inheritdoc * @todo If the collection being counted is already joined, the SQL can be simpler (more efficient). */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) @@ -110,6 +111,7 @@ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) /** * @override + * @inheritdoc */ public function parse(\Doctrine\ORM\Query\Parser $parser) { diff --git a/lib/Doctrine/ORM/Query/AST/Functions/SqrtFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/SqrtFunction.php index c9f1038c494..08155d25b56 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/SqrtFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/SqrtFunction.php @@ -41,6 +41,7 @@ class SqrtFunction extends FunctionNode /** * @override + * @inheritdoc */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { @@ -51,6 +52,7 @@ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) /** * @override + * @inheritdoc */ public function parse(\Doctrine\ORM\Query\Parser $parser) { diff --git a/lib/Doctrine/ORM/Query/AST/Functions/SubstringFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/SubstringFunction.php index ee80c06acfa..a6a80f8112b 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/SubstringFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/SubstringFunction.php @@ -48,6 +48,7 @@ class SubstringFunction extends FunctionNode /** * @override + * @inheritdoc */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { @@ -65,6 +66,7 @@ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) /** * @override + * @inheritdoc */ public function parse(\Doctrine\ORM\Query\Parser $parser) { diff --git a/lib/Doctrine/ORM/Query/AST/Functions/UpperFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/UpperFunction.php index 22592a174e4..28e0f162714 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/UpperFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/UpperFunction.php @@ -38,6 +38,7 @@ class UpperFunction extends FunctionNode /** * @override + * @inheritdoc */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { @@ -48,6 +49,7 @@ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) /** * @override + * @inheritdoc */ public function parse(\Doctrine\ORM\Query\Parser $parser) { diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 54d84f3e64c..34679ff618e 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -197,7 +197,7 @@ public function __construct(Query $query) { $this->query = $query; $this->em = $query->getEntityManager(); - $this->lexer = new Lexer($query->getDql()); + $this->lexer = new Lexer($query->getDQL()); $this->parserResult = new ParserResult(); } @@ -277,7 +277,7 @@ public function getAST() } if ($this->deferredPathExpressions) { - $this->processDeferredPathExpressions($AST); + $this->processDeferredPathExpressions(); } if ($this->deferredResultVariables) { @@ -482,7 +482,7 @@ public function semanticalError($message = '', $token = null) $distance = 12; // Find a position of a final word to display in error string - $dql = $this->query->getDql(); + $dql = $this->query->getDQL(); $length = strlen($dql); $pos = $token['position'] + $distance; $pos = strpos($dql, ' ', ($length > $pos) ? $pos : $length); @@ -749,11 +749,9 @@ private function processDeferredResultVariables() * SingleValuedAssociationPathExpression ::= IdentificationVariable "." SingleValuedAssociationField * CollectionValuedPathExpression ::= IdentificationVariable "." CollectionValuedAssociationField * - * @param mixed $AST - * * @return void */ - private function processDeferredPathExpressions($AST) + private function processDeferredPathExpressions() { foreach ($this->deferredPathExpressions as $deferredItem) { $pathExpression = $deferredItem['expression']; @@ -1504,7 +1502,7 @@ public function OrderByItem() $glimpse = $this->lexer->glimpse(); switch (true) { - case ($this->isFunction($peek)): + case ($this->isFunction()): $expr = $this->FunctionDeclaration(); break; @@ -1795,7 +1793,7 @@ public function JoinAssociationDeclaration() * PartialObjectExpression ::= "PARTIAL" IdentificationVariable "." PartialFieldSet * PartialFieldSet ::= "{" SimpleStateField {"," SimpleStateField}* "}" * - * @return array + * @return \Doctrine\ORM\Query\AST\PartialObjectExpression */ public function PartialObjectExpression() { diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index b39280b396e..ee57cf90b1a 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -1502,8 +1502,8 @@ public function walkParenthesisExpression(AST\ParenthesisExpression $parenthesis } /** - * @param AST\NewObjectExpression $newObjectExpression - * + * @param AST\NewObjectExpression $newObjectExpression + * @param null|string $newObjectResultAlias * @return string The SQL. */ public function walkNewObject($newObjectExpression, $newObjectResultAlias=null) @@ -1761,7 +1761,7 @@ public function walkUpdateItem($updateItem) public function walkWhereClause($whereClause) { $condSql = null !== $whereClause ? $this->walkConditionalExpression($whereClause->conditionalExpression) : ''; - $discrSql = $this->_generateDiscriminatorColumnConditionSql($this->rootAliases); + $discrSql = $this->_generateDiscriminatorColumnConditionSQL($this->rootAliases); if ($this->em->hasFilters()) { $filterClauses = []; diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php index ee370dd0f08..6c81de940de 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php @@ -21,7 +21,6 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console; use Doctrine\ORM\Tools\Export\ClassMetadataExporter; use Doctrine\ORM\Tools\ConvertDoctrine1Schema; use Doctrine\ORM\Tools\EntityGenerator; diff --git a/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php index 0f5371d44d8..6f2761e0dc6 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php @@ -185,7 +185,7 @@ function ($mappedEntity) use ($entityName) { if (count($matches) > 1) { throw new \InvalidArgumentException(sprintf( - 'Entity name "%s" is ambigous, possible matches: "%s"', + 'Entity name "%s" is ambiguous, possible matches: "%s"', $entityName, implode(', ', $matches) )); } diff --git a/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php b/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php index 41927ce7a39..50113826183 100644 --- a/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php +++ b/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php @@ -143,7 +143,7 @@ private function getType($var) if (is_object($var)) { $refl = new \ReflectionObject($var); - return $refl->getShortname(); + return $refl->getShortName(); } return gettype($var); @@ -176,7 +176,7 @@ private function getIdString($entity, UnitOfWork $uow) $idstring .= " [REMOVED]"; } elseif ($state == UnitOfWork::STATE_MANAGED) { $idstring .= " [MANAGED]"; - } elseif ($state == UnitOfwork::STATE_DETACHED) { + } elseif ($state == UnitOfWork::STATE_DETACHED) { $idstring .= " [DETACHED]"; } diff --git a/lib/Doctrine/ORM/Tools/Pagination/RowNumberOverFunction.php b/lib/Doctrine/ORM/Tools/Pagination/RowNumberOverFunction.php index 52511b4b10a..a9d3e5d686e 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/RowNumberOverFunction.php +++ b/lib/Doctrine/ORM/Tools/Pagination/RowNumberOverFunction.php @@ -40,6 +40,7 @@ class RowNumberOverFunction extends FunctionNode /** * @override + * @inheritdoc */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { @@ -50,6 +51,7 @@ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) /** * @override + * @inheritdoc * * @throws ORMException */ diff --git a/lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php b/lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php index 46488bf97d7..36f1f929bde 100644 --- a/lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php +++ b/lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php @@ -80,7 +80,7 @@ public function onClassMetadataNotFound(OnClassMetadataNotFoundEventArgs $args) $args->setFoundMetadata( $args ->getObjectManager() - ->getClassMetadata($this->resolveTargetEntities[$args->getClassname()]['targetEntity']) + ->getClassMetadata($this->resolveTargetEntities[$args->getClassName()]['targetEntity']) ); } } diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 9acd85ffca9..9ee27c84d4c 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -351,8 +351,7 @@ public function getSchemaFromMetadata(array $classes) * @param ClassMetadata $class * @param Table $table * - * @return array The portable column definition of the discriminator column as required by - * the DBAL. + * @return void */ private function addDiscriminatorColumnDefinition($class, Table $table) { @@ -384,7 +383,7 @@ private function addDiscriminatorColumnDefinition($class, Table $table) * @param ClassMetadata $class * @param Table $table * - * @return array The list of portable column definitions as required by the DBAL. + * @return void */ private function gatherColumns($class, Table $table) { @@ -410,7 +409,7 @@ private function gatherColumns($class, Table $table) * @param array $mapping The field mapping. * @param Table $table * - * @return array The portable column definition as required by the DBAL. + * @return void */ private function gatherColumn($class, array $mapping, Table $table) { diff --git a/lib/Doctrine/ORM/Tools/SchemaValidator.php b/lib/Doctrine/ORM/Tools/SchemaValidator.php index 4119b9d6003..ee39aed817e 100644 --- a/lib/Doctrine/ORM/Tools/SchemaValidator.php +++ b/lib/Doctrine/ORM/Tools/SchemaValidator.php @@ -90,7 +90,7 @@ public function validateClass(ClassMetadataInfo $class) foreach ($class->fieldMappings as $fieldName => $mapping) { if (!Type::hasType($mapping['type'])) { - $ce[] = "The field '" . $class->name . "#" . $fieldName."' uses a non-existant type '" . $mapping['type'] . "'."; + $ce[] = "The field '" . $class->name . "#" . $fieldName."' uses a non-existent type '" . $mapping['type'] . "'."; } } From 7a63e81c9458adc486ae22ad57ee857eae89bbba Mon Sep 17 00:00:00 2001 From: Artem Stepin Date: Thu, 8 Jun 2017 23:18:47 +0200 Subject: [PATCH 297/877] Add failing test for gh-#6314 (gh-#6356) --- .../Tests/ORM/Tools/EntityGeneratorTest.php | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index 5a9f451fe32..35e19cf654d 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -119,7 +119,7 @@ private function generateEntityTypeFixture(array $field) /** * @return ClassMetadataInfo */ - private function generateIsbnEmbeddableFixture(array $embeddedClasses = []) + private function generateIsbnEmbeddableFixture(array $embeddedClasses = [], $columnPrefix = null) { $metadata = new ClassMetadataInfo($this->_namespace . '\EntityGeneratorIsbn'); $metadata->namespace = $this->_namespace; @@ -131,7 +131,7 @@ private function generateIsbnEmbeddableFixture(array $embeddedClasses = []) $metadata->mapField(['fieldName' => 'checkDigit', 'type' => 'integer']); foreach ($embeddedClasses as $fieldName => $embeddedClass) { - $this->mapEmbedded($fieldName, $metadata, $embeddedClass); + $this->mapEmbedded($fieldName, $metadata, $embeddedClass, $columnPrefix); } $this->_generator->writeEntityClass($metadata, $this->_tmpDir); @@ -224,6 +224,26 @@ public function newInstance($metadata) return new $metadata->name; } + /** + * @group GH-6314 + */ + public function testEmbeddedEntityWithColumnPrefix() + { + $testMetadata = $this->generateTestEmbeddableFixture(); + $isbnMetadata = $this->generateIsbnEmbeddableFixture(['testEmbedded' => $testMetadata], 'prefix'); + $isbnEntity = $this->newInstance($isbnMetadata); + $refClass = new \ReflectionClass($isbnEntity); + + self::assertTrue($refClass->hasProperty('testEmbedded')); + + + $docComment = $refClass->getProperty('testEmbedded')->getDocComment(); + + $needle = sprintf('@Embedded(class="%s", columnPrefix=\'%s\')', $testMetadata->name,'prefix'); + self::assertContains($needle, $docComment); + + } + public function testGeneratedEntityClass() { $testMetadata = $this->generateTestEmbeddableFixture(); From 799190d5e4cb0533778969c7e22f4c7d5961d096 Mon Sep 17 00:00:00 2001 From: Artem Stepin Date: Fri, 9 Jun 2017 22:25:19 +0200 Subject: [PATCH 298/877] - fixed columnPrefix generator for the embedded annotation --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 6 ++++- .../Tests/ORM/Tools/EntityGeneratorTest.php | 25 ++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 5bc292a37fa..fafa51f3daa 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -1732,7 +1732,11 @@ protected function generateEmbeddedPropertyDocBlock(array $embeddedClass) $embedded = ['class="' . $embeddedClass['class'] . '"']; if (isset($embeddedClass['columnPrefix'])) { - $embedded[] = 'columnPrefix=' . var_export($embeddedClass['columnPrefix'], true); + if (is_string($embeddedClass['columnPrefix'])) { + $embedded[] = 'columnPrefix="' . $embeddedClass['columnPrefix'] . '"'; + } else { + $embedded[] = 'columnPrefix=' . var_export($embeddedClass['columnPrefix'], true); + } } $lines[] = $this->spaces . ' * @' . diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index 35e19cf654d..f2d74d0437f 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -227,21 +227,34 @@ public function newInstance($metadata) /** * @group GH-6314 */ - public function testEmbeddedEntityWithColumnPrefix() + public function testEmbeddedEntityWithNamedColumnPrefix() { + $columnPrefix = 'GH6314Prefix_'; $testMetadata = $this->generateTestEmbeddableFixture(); - $isbnMetadata = $this->generateIsbnEmbeddableFixture(['testEmbedded' => $testMetadata], 'prefix'); + $isbnMetadata = $this->generateIsbnEmbeddableFixture(['testEmbedded' => $testMetadata], $columnPrefix); $isbnEntity = $this->newInstance($isbnMetadata); $refClass = new \ReflectionClass($isbnEntity); - self::assertTrue($refClass->hasProperty('testEmbedded')); - $docComment = $refClass->getProperty('testEmbedded')->getDocComment(); - - $needle = sprintf('@Embedded(class="%s", columnPrefix=\'%s\')', $testMetadata->name,'prefix'); + $needle = sprintf('@Embedded(class="%s", columnPrefix="%s")', $testMetadata->name, $columnPrefix); self::assertContains($needle, $docComment); + } + /** + * @group GH-6314 + */ + public function testEmbeddedEntityWithoutColumnPrefix() + { + $testMetadata = $this->generateTestEmbeddableFixture(); + $isbnMetadata = $this->generateIsbnEmbeddableFixture(['testEmbedded' => $testMetadata], false); + $isbnEntity = $this->newInstance($isbnMetadata); + $refClass = new \ReflectionClass($isbnEntity); + self::assertTrue($refClass->hasProperty('testEmbedded')); + + $docComment = $refClass->getProperty('testEmbedded')->getDocComment(); + $needle = sprintf('@Embedded(class="%s", columnPrefix=false)', $testMetadata->name); + self::assertContains($needle, $docComment); } public function testGeneratedEntityClass() From 043ca69f0b7bba77f541617de9e47b1fdaa58251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 31 May 2017 07:59:04 +0200 Subject: [PATCH 299/877] Fix some code style issues in tests --- .../DbalTypes/NegativeToPositiveType.php | 4 +- .../Tests/DbalTypes/UpperCaseStringType.php | 4 +- .../ORM/Functional/BasicFunctionalTest.php | 1 - .../ORM/Functional/CascadeRemoveOrderTest.php | 8 +- .../Functional/ClassTableInheritanceTest.php | 73 ++++++++--------- .../ORM/Functional/DetachedEntityTest.php | 11 +-- .../Tests/ORM/Functional/Locking/LockTest.php | 35 +++++--- .../ORM/Functional/Locking/OptimisticTest.php | 10 +-- .../Tests/ORM/Functional/NativeQueryTest.php | 20 +++-- .../ORM/Functional/PersistentObjectTest.php | 5 +- .../Tests/ORM/Functional/QueryTest.php | 66 +++++++++------- .../ORM/Functional/SequenceGeneratorTest.php | 8 +- .../ORM/Functional/Ticket/DDC1113Test.php | 11 ++- .../ORM/Functional/Ticket/DDC117Test.php | 12 +-- .../ORM/Functional/Ticket/DDC1181Test.php | 6 +- .../ORM/Functional/Ticket/DDC1209Test.php | 6 +- .../ORM/Functional/Ticket/DDC1306Test.php | 4 +- .../ORM/Functional/Ticket/DDC1400Test.php | 13 ++- .../ORM/Functional/Ticket/DDC144Test.php | 24 +++--- .../ORM/Functional/Ticket/DDC1454Test.php | 12 +-- .../ORM/Functional/Ticket/DDC1925Test.php | 20 ++--- .../ORM/Functional/Ticket/DDC192Test.php | 35 +++++--- .../ORM/Functional/Ticket/DDC2106Test.php | 3 +- .../ORM/Functional/Ticket/DDC2256Test.php | 8 +- .../ORM/Functional/Ticket/DDC2775Test.php | 11 ++- .../ORM/Functional/Ticket/DDC3170Test.php | 3 +- .../ORM/Functional/Ticket/DDC3711Test.php | 1 - .../ORM/Functional/Ticket/DDC3785Test.php | 57 ++++++------- .../ORM/Functional/Ticket/DDC522Test.php | 29 ++++--- .../ORM/Functional/Ticket/DDC588Test.php | 3 +- .../ORM/Functional/Ticket/DDC742Test.php | 15 ++-- .../ORM/Functional/Ticket/DDC832Test.php | 32 ++++---- .../ORM/Functional/Ticket/DDC933Test.php | 9 ++- .../Tests/ORM/Functional/TypeTest.php | 25 +++--- .../Tests/ORM/Functional/TypeValueSqlTest.php | 14 ++-- .../ORM/Hydration/ScalarHydratorTest.php | 7 +- .../Hydration/SingleScalarHydratorTest.php | 79 ++++++++++--------- .../ORM/Mapping/AbstractMappingDriverTest.php | 19 ++--- .../Mapping/StaticPHPMappingDriverTest.php | 1 - 39 files changed, 373 insertions(+), 331 deletions(-) diff --git a/tests/Doctrine/Tests/DbalTypes/NegativeToPositiveType.php b/tests/Doctrine/Tests/DbalTypes/NegativeToPositiveType.php index 8395b6acdd8..f5e50fa07ce 100644 --- a/tests/Doctrine/Tests/DbalTypes/NegativeToPositiveType.php +++ b/tests/Doctrine/Tests/DbalTypes/NegativeToPositiveType.php @@ -7,12 +7,14 @@ class NegativeToPositiveType extends Type { + const NAME = 'negative_to_positive'; + /** * {@inheritdoc} */ public function getName() { - return 'negative_to_positive'; + return self::NAME; } /** diff --git a/tests/Doctrine/Tests/DbalTypes/UpperCaseStringType.php b/tests/Doctrine/Tests/DbalTypes/UpperCaseStringType.php index 3811aa00d56..866a62475bf 100644 --- a/tests/Doctrine/Tests/DbalTypes/UpperCaseStringType.php +++ b/tests/Doctrine/Tests/DbalTypes/UpperCaseStringType.php @@ -7,12 +7,14 @@ class UpperCaseStringType extends StringType { + const NAME = 'upper_case_string'; + /** * {@inheritdoc} */ public function getName() { - return 'upper_case_string'; + return self::NAME; } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php index eec4844d149..016a7949f2f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php @@ -727,7 +727,6 @@ public function testOneToOneNullUpdate() */ public function testNewAssociatedEntityDuringFlushThrowsException() { - //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); $user = new CmsUser(); $user->username = "beberlei"; $user->name = "Benjamin E."; diff --git a/tests/Doctrine/Tests/ORM/Functional/CascadeRemoveOrderTest.php b/tests/Doctrine/Tests/ORM/Functional/CascadeRemoveOrderTest.php index cb19c2bcf66..a6de137d139 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CascadeRemoveOrderTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CascadeRemoveOrderTest.php @@ -16,8 +16,8 @@ protected function setUp() $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(CascadeRemoveOrderEntityO::class), - $this->_em->getClassMetadata(CascadeRemoveOrderEntityG::class), + $this->_em->getClassMetadata(CascadeRemoveOrderEntityO::class), + $this->_em->getClassMetadata(CascadeRemoveOrderEntityG::class), ] ); } @@ -28,8 +28,8 @@ protected function tearDown() $this->_schemaTool->dropSchema( [ - $this->_em->getClassMetadata(CascadeRemoveOrderEntityO::class), - $this->_em->getClassMetadata(CascadeRemoveOrderEntityG::class), + $this->_em->getClassMetadata(CascadeRemoveOrderEntityO::class), + $this->_em->getClassMetadata(CascadeRemoveOrderEntityG::class), ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php index 2698c325242..02ed0a3565c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php @@ -2,16 +2,16 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\PersistentCollection; use Doctrine\ORM\Proxy\Proxy; -use Doctrine\Tests\Models\Company\CompanyPerson, - Doctrine\Tests\Models\Company\CompanyEmployee, - Doctrine\Tests\Models\Company\CompanyManager, - Doctrine\Tests\Models\Company\CompanyOrganization, - Doctrine\Tests\Models\Company\CompanyAuction, - Doctrine\Tests\Models\Company\CompanyRaffle; - -use Doctrine\Common\Collections\Criteria; +use Doctrine\Tests\Models\Company\CompanyAuction; +use Doctrine\Tests\Models\Company\CompanyEmployee; +use Doctrine\Tests\Models\Company\CompanyEvent; +use Doctrine\Tests\Models\Company\CompanyManager; +use Doctrine\Tests\Models\Company\CompanyOrganization; +use Doctrine\Tests\Models\Company\CompanyPerson; +use Doctrine\Tests\Models\Company\CompanyRaffle; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -24,8 +24,8 @@ class ClassTableInheritanceTest extends OrmFunctionalTestCase protected function setUp() { $this->useModelSet('company'); + parent::setUp(); - //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); } public function testCRUD() @@ -47,7 +47,7 @@ public function testCRUD() $this->_em->clear(); - $query = $this->_em->createQuery("select p from Doctrine\Tests\Models\Company\CompanyPerson p order by p.name desc"); + $query = $this->_em->createQuery('select p from ' . CompanyPerson::class . ' p order by p.name desc'); $entities = $query->getResult(); @@ -62,7 +62,7 @@ public function testCRUD() $this->_em->clear(); - $query = $this->_em->createQuery("select p from Doctrine\Tests\Models\Company\CompanyEmployee p"); + $query = $this->_em->createQuery('select p from ' . CompanyEmployee::class . ' p'); $entities = $query->getResult(); @@ -80,7 +80,7 @@ public function testCRUD() $this->_em->clear(); - $query = $this->_em->createQuery("update Doctrine\Tests\Models\Company\CompanyEmployee p set p.name = ?1, p.department = ?2 where p.name='Guilherme Blanco' and p.salary = ?3"); + $query = $this->_em->createQuery("update " . CompanyEmployee::class . " p set p.name = ?1, p.department = ?2 where p.name='Guilherme Blanco' and p.salary = ?3"); $query->setParameter(1, 'NewName', 'string'); $query->setParameter(2, 'NewDepartment'); $query->setParameter(3, 100000); @@ -88,12 +88,13 @@ public function testCRUD() $numUpdated = $query->execute(); $this->assertEquals(1, $numUpdated); - $query = $this->_em->createQuery("delete from Doctrine\Tests\Models\Company\CompanyPerson p"); + $query = $this->_em->createQuery('delete from ' . CompanyPerson::class . ' p'); $numDeleted = $query->execute(); $this->assertEquals(2, $numDeleted); } - public function testMultiLevelUpdateAndFind() { + public function testMultiLevelUpdateAndFind() + { $manager = new CompanyManager; $manager->setName('Roman S. Borschel'); $manager->setSalary(100000); @@ -119,7 +120,8 @@ public function testMultiLevelUpdateAndFind() { $this->assertTrue(is_numeric($manager->getId())); } - public function testFindOnBaseClass() { + public function testFindOnBaseClass() + { $manager = new CompanyManager; $manager->setName('Roman S. Borschel'); $manager->setSalary(100000); @@ -139,7 +141,8 @@ public function testFindOnBaseClass() { $this->assertTrue(is_numeric($person->getId())); } - public function testSelfReferencingOneToOne() { + public function testSelfReferencingOneToOne() + { $manager = new CompanyManager; $manager->setName('John Smith'); $manager->setSalary(100000); @@ -155,16 +158,10 @@ public function testSelfReferencingOneToOne() { $this->_em->persist($manager); $this->_em->persist($wife); - $this->_em->flush(); - - //var_dump($this->_em->getConnection()->fetchAll('select * from company_persons')); - //var_dump($this->_em->getConnection()->fetchAll('select * from company_employees')); - //var_dump($this->_em->getConnection()->fetchAll('select * from company_managers')); - $this->_em->clear(); - $query = $this->_em->createQuery('select p, s from Doctrine\Tests\Models\Company\CompanyPerson p join p.spouse s where p.name=\'Mary Smith\''); + $query = $this->_em->createQuery('select p, s from ' . CompanyPerson::class . ' p join p.spouse s where p.name=\'Mary Smith\''); $result = $query->getResult(); $this->assertEquals(1, count($result)); @@ -196,7 +193,7 @@ public function testSelfReferencingManyToMany() $this->_em->clear(); - $query = $this->_em->createQuery('select p, f from Doctrine\Tests\Models\Company\CompanyPerson p join p.friends f where p.name=?1'); + $query = $this->_em->createQuery('select p, f from ' . CompanyPerson::class . ' p join p.friends f where p.name=?1'); $query->setParameter(1, 'Roman'); $result = $query->getResult(); @@ -247,7 +244,6 @@ public function testLazyLoading1() } } - public function testLazyLoading2() { $org = new CompanyOrganization; @@ -259,16 +255,16 @@ public function testLazyLoading2() $this->_em->flush(); $this->_em->clear(); - $q = $this->_em->createQuery('select a from Doctrine\Tests\Models\Company\CompanyEvent a where a.id = ?1'); + $q = $this->_em->createQuery('select a from ' . CompanyEvent::class . ' a where a.id = ?1'); $q->setParameter(1, $event1->getId()); $result = $q->getResult(); $this->assertEquals(1, count($result)); - $this->assertInstanceOf(CompanyAuction::class, $result[0], sprintf("Is of class %s",get_class($result[0]))); + $this->assertInstanceOf(CompanyAuction::class, $result[0], sprintf("Is of class %s", get_class($result[0]))); $this->_em->clear(); - $q = $this->_em->createQuery('select a from Doctrine\Tests\Models\Company\CompanyOrganization a where a.id = ?1'); + $q = $this->_em->createQuery('select a from ' . CompanyOrganization::class . ' a where a.id = ?1'); $q->setParameter(1, $org->getId()); $result = $q->getResult(); @@ -287,8 +283,8 @@ public function testLazyLoading2() */ public function testBulkUpdateIssueDDC368() { - $dql = 'UPDATE Doctrine\Tests\Models\Company\CompanyEmployee AS p SET p.salary = 1'; - $this->_em->createQuery($dql)->execute(); + $this->_em->createQuery('UPDATE ' . CompanyEmployee::class . ' AS p SET p.salary = 1') + ->execute(); $this->assertTrue(count($this->_em->createQuery( 'SELECT count(p.id) FROM Doctrine\Tests\Models\Company\CompanyEmployee p WHERE p.salary = 1') @@ -300,12 +296,10 @@ public function testBulkUpdateIssueDDC368() */ public function testBulkUpdateNonScalarParameterDDC1341() { - $dql = 'UPDATE Doctrine\Tests\Models\Company\CompanyEmployee AS p SET p.startDate = ?0 WHERE p.department = ?1'; - $query = $this->_em->createQuery($dql) - ->setParameter(0, new \DateTime()) - ->setParameter(1, 'IT'); - - $result = $query->execute(); + $this->_em->createQuery('UPDATE ' . CompanyEmployee::class . ' AS p SET p.startDate = ?0 WHERE p.department = ?1') + ->setParameter(0, new \DateTime()) + ->setParameter(1, 'IT') + ->execute(); } @@ -314,8 +308,6 @@ public function testBulkUpdateNonScalarParameterDDC1341() */ public function testDeleteJoinTableRecords() { - #$this->markTestSkipped('Nightmare! friends adds both ID 6-7 and 7-6 into two rows of the join table. How to detect this?'); - $employee1 = new CompanyEmployee(); $employee1->setName('gblanco'); $employee1->setSalary(0); @@ -361,8 +353,9 @@ public function testQueryForInheritedSingleValuedAssociation() $this->_em->flush(); $this->_em->clear(); - $dql = "SELECT m FROM Doctrine\Tests\Models\Company\CompanyManager m WHERE m.spouse = ?1"; - $dqlManager = $this->_em->createQuery($dql)->setParameter(1, $person->getId())->getSingleResult(); + $dqlManager = $this->_em->createQuery('SELECT m FROM ' . CompanyManager::class . ' m WHERE m.spouse = ?1') + ->setParameter(1, $person->getId()) + ->getSingleResult(); $this->assertEquals($manager->getId(), $dqlManager->getId()); $this->assertEquals($person->getId(), $dqlManager->getSpouse()->getId()); diff --git a/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php b/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php index b0326e5429d..5060f07a151 100644 --- a/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php @@ -23,7 +23,8 @@ protected function setUp() parent::setUp(); } - public function testSimpleDetachMerge() { + public function testSimpleDetachMerge() + { $user = new CmsUser; $user->name = 'Roman'; $user->username = 'romanb'; @@ -33,13 +34,10 @@ public function testSimpleDetachMerge() { $this->_em->clear(); // $user is now detached - $this->assertFalse($this->_em->contains($user)); $user->name = 'Roman B.'; - //$this->assertEquals(UnitOfWork::STATE_DETACHED, $this->_em->getUnitOfWork()->getEntityState($user)); - $user2 = $this->_em->merge($user); $this->assertFalse($user === $user2); @@ -49,7 +47,6 @@ public function testSimpleDetachMerge() { public function testSerializeUnserializeModifyMerge() { - //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); $user = new CmsUser; $user->name = 'Guilherme'; $user->username = 'gblanco'; @@ -173,7 +170,7 @@ public function testUseDetachedEntityAsQueryParameter() $this->_em->flush(); $this->_em->detach($user); - $dql = "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1"; + $dql = 'SELECT u FROM ' . CmsUser::class . ' u WHERE u.id = ?1'; $query = $this->_em->createQuery($dql); $query->setParameter(1, $user); @@ -216,7 +213,7 @@ public function testMergeArticleWrongVersion() $this->_em->detach($article); - $sql = "UPDATE cms_articles SET version = version+1 WHERE id = " . $article->id; + $sql = 'UPDATE cms_articles SET version = version + 1 WHERE id = ' . $article->id; $this->_em->getConnection()->executeUpdate($sql); $this->expectException(OptimisticLockException::class); diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php index e92b9476baa..dc27d45be47 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php @@ -19,6 +19,7 @@ protected function setUp() { $this->useModelSet('cms'); parent::setUp(); + $this->handles = []; } @@ -26,7 +27,8 @@ protected function setUp() * @group DDC-178 * @group locking */ - public function testLockVersionedEntity() { + public function testLockVersionedEntity() + { $article = new CmsArticle(); $article->text = "my article"; $article->topic = "Hello"; @@ -41,7 +43,8 @@ public function testLockVersionedEntity() { * @group DDC-178 * @group locking */ - public function testLockVersionedEntity_MismatchThrowsException() { + public function testLockVersionedEntity_MismatchThrowsException() + { $article = new CmsArticle(); $article->text = "my article"; $article->topic = "Hello"; @@ -58,7 +61,8 @@ public function testLockVersionedEntity_MismatchThrowsException() { * @group DDC-178 * @group locking */ - public function testLockUnversionedEntity_ThrowsException() { + public function testLockUnversionedEntity_ThrowsException() + { $user = new CmsUser(); $user->name = "foo"; $user->status = "active"; @@ -76,11 +80,12 @@ public function testLockUnversionedEntity_ThrowsException() { * @group DDC-178 * @group locking */ - public function testLockUnmanagedEntity_ThrowsException() { + public function testLockUnmanagedEntity_ThrowsException() + { $article = new CmsArticle(); $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('Entity Doctrine\Tests\Models\CMS\CmsArticle'); + $this->expectExceptionMessage('Entity ' . CmsArticle::class); $this->_em->lock($article, LockMode::OPTIMISTIC, $article->version + 1); } @@ -89,7 +94,8 @@ public function testLockUnmanagedEntity_ThrowsException() { * @group DDC-178 * @group locking */ - public function testLockPessimisticRead_NoTransaction_ThrowsException() { + public function testLockPessimisticRead_NoTransaction_ThrowsException() + { $article = new CmsArticle(); $article->text = "my article"; $article->topic = "Hello"; @@ -106,7 +112,8 @@ public function testLockPessimisticRead_NoTransaction_ThrowsException() { * @group DDC-178 * @group locking */ - public function testLockPessimisticWrite_NoTransaction_ThrowsException() { + public function testLockPessimisticWrite_NoTransaction_ThrowsException() + { $article = new CmsArticle(); $article->text = "my article"; $article->topic = "Hello"; @@ -171,6 +178,7 @@ public function testLockPessimisticRead() $this->_em->flush(); $this->_em->beginTransaction(); + try { $this->_em->lock($article, LockMode::PESSIMISTIC_READ); $this->_em->commit(); @@ -179,8 +187,9 @@ public function testLockPessimisticRead() throw $e; } - $query = array_pop( $this->_sqlLoggerStack->queries ); - $query = array_pop( $this->_sqlLoggerStack->queries ); + array_pop($this->_sqlLoggerStack->queries); + $query = array_pop($this->_sqlLoggerStack->queries); + $this->assertContains($readLockSql, $query['sql']); } @@ -189,13 +198,13 @@ public function testLockPessimisticRead() */ public function testLockOptimisticNonVersionedThrowsExceptionInDQL() { - $dql = "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 'gblanco'"; + $dql = "SELECT u FROM " . CmsUser::class . " u WHERE u.username = 'gblanco'"; $this->expectException(OptimisticLockException::class); $this->expectExceptionMessage('The optimistic lock on an entity failed.'); - $sql = $this->_em->createQuery($dql)->setHint( - Query::HINT_LOCK_MODE, LockMode::OPTIMISTIC - )->getSQL(); + $this->_em->createQuery($dql) + ->setHint(Query::HINT_LOCK_MODE, LockMode::OPTIMISTIC) + ->getSQL(); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php index b5aa9c0ecb1..3681ed95ef9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php @@ -16,15 +16,16 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(OptimisticJoinedParent::class), - $this->_em->getClassMetadata(OptimisticJoinedChild::class), - $this->_em->getClassMetadata(OptimisticStandard::class), - $this->_em->getClassMetadata(OptimisticTimestamp::class) + $this->_em->getClassMetadata(OptimisticJoinedParent::class), + $this->_em->getClassMetadata(OptimisticJoinedChild::class), + $this->_em->getClassMetadata(OptimisticStandard::class), + $this->_em->getClassMetadata(OptimisticTimestamp::class) ] ); } catch (\Exception $e) { // Swallow all exceptions. We do not test the schema tool here. } + $this->_conn = $this->_em->getConnection(); } @@ -168,7 +169,6 @@ public function testStandardFailureThrowsException(OptimisticStandard $entity) public function testLockWorksWithProxy() { $test = new OptimisticStandard(); - $test->name = 'test'; $this->_em->persist($test); diff --git a/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php b/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php index 93eab26678d..4e8e6c96ef5 100644 --- a/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php @@ -35,6 +35,7 @@ protected function setUp() $this->useModelSet('cms'); $this->useModelSet('company'); parent::setUp(); + $this->platform = $this->_em->getConnection()->getDatabasePlatform(); } @@ -426,9 +427,9 @@ public function testBasicNativeNamedQueryWithResultClass() $repository = $this->_em->getRepository(CmsUser::class); - $result = $repository->createNativeNamedQuery('fetchIdAndUsernameWithResultClass') - ->setParameter(1, 'FabioBatSilva')->getResult(); + ->setParameter(1, 'FabioBatSilva') + ->getResult(); $this->assertEquals(1, count($result)); $this->assertInstanceOf(CmsUser::class, $result[0]); @@ -439,9 +440,9 @@ public function testBasicNativeNamedQueryWithResultClass() $this->_em->clear(); - $result = $repository->createNativeNamedQuery('fetchAllColumns') - ->setParameter(1, 'FabioBatSilva')->getResult(); + ->setParameter(1, 'FabioBatSilva') + ->getResult(); $this->assertEquals(1, count($result)); $this->assertInstanceOf(CmsUser::class, $result[0]); @@ -468,19 +469,16 @@ public function testJoinedOneToOneNativeNamedQueryWithResultSetMapping() $addr->zip = 10827; $addr->city = 'São Paulo'; - $user->setAddress($addr); $this->_em->persist($user); $this->_em->flush(); - $this->_em->clear(); - $repository = $this->_em->getRepository(CmsUser::class); - - - $result = $repository->createNativeNamedQuery('fetchJoinedAddress') - ->setParameter(1, 'FabioBatSilva')->getResult(); + $result = $this->_em->getRepository(CmsUser::class) + ->createNativeNamedQuery('fetchJoinedAddress') + ->setParameter(1, 'FabioBatSilva') + ->getResult(); $this->assertEquals(1, count($result)); $this->assertInstanceOf(CmsUser::class, $result[0]); diff --git a/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php b/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php index 9f73bf5e8e4..b611c7125fa 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php @@ -16,15 +16,16 @@ class PersistentObjectTest extends OrmFunctionalTestCase protected function setUp() { parent::setUp(); + try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(PersistentEntity::class), + $this->_em->getClassMetadata(PersistentEntity::class), ] ); } catch (\Exception $e) { - } + PersistentObject::setObjectManager($this->_em); } diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php index 805478bdfc7..127f06d18f7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php @@ -26,6 +26,7 @@ class QueryTest extends OrmFunctionalTestCase protected function setUp() { $this->useModelSet('cms'); + parent::setUp(); } @@ -93,7 +94,7 @@ public function testJoinQueries() $this->_em->flush(); $this->_em->clear(); - $query = $this->_em->createQuery("select u, a from Doctrine\Tests\Models\CMS\CmsUser u join u.articles a ORDER BY a.topic"); + $query = $this->_em->createQuery('select u, a from ' . CmsUser::class . ' u join u.articles a ORDER BY a.topic'); $users = $query->getResult(); $this->assertEquals(1, count($users)); $this->assertInstanceOf(CmsUser::class, $users[0]); @@ -112,7 +113,7 @@ public function testUsingZeroBasedQueryParameterShouldWork() $this->_em->flush(); $this->_em->clear(); - $q = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = ?0'); + $q = $this->_em->createQuery('SELECT u FROM ' . CmsUser::class . ' u WHERE u.username = ?0'); $q->setParameter(0, 'jwage'); $user = $q->getSingleResult(); @@ -124,7 +125,7 @@ public function testUsingUnknownQueryParameterShouldThrowException() $this->expectException(QueryException::class); $this->expectExceptionMessage('Invalid parameter: token 2 is not defined in the query.'); - $q = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = ?1'); + $q = $this->_em->createQuery('SELECT u FROM ' . CmsUser::class . ' u WHERE u.name = ?1'); $q->setParameter(2, 'jwage'); $user = $q->getSingleResult(); } @@ -134,7 +135,7 @@ public function testTooManyParametersShouldThrowException() $this->expectException(QueryException::class); $this->expectExceptionMessage('Too many parameters: the query defines 1 parameters and you bound 2'); - $q = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = ?1'); + $q = $this->_em->createQuery('SELECT u FROM ' . CmsUser::class . ' u WHERE u.name = ?1'); $q->setParameter(1, 'jwage'); $q->setParameter(2, 'jwage'); @@ -146,38 +147,35 @@ public function testTooFewParametersShouldThrowException() $this->expectException(QueryException::class); $this->expectExceptionMessage('Too few parameters: the query defines 1 parameters but you only bound 0'); - $q = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = ?1'); - - $user = $q->getSingleResult(); + $this->_em->createQuery('SELECT u FROM ' . CmsUser::class . ' u WHERE u.name = ?1') + ->getSingleResult(); } public function testInvalidInputParameterThrowsException() { $this->expectException(QueryException::class); - $q = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = ?'); - $q->setParameter(1, 'jwage'); - $user = $q->getSingleResult(); + $this->_em->createQuery('SELECT u FROM ' . CmsUser::class . ' u WHERE u.name = ?') + ->setParameter(1, 'jwage') + ->getSingleResult(); } public function testSetParameters() { - $q = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = ?1 AND u.status = ?2'); - $parameters = new ArrayCollection(); $parameters->add(new Parameter(1, 'jwage')); $parameters->add(new Parameter(2, 'active')); - $q->setParameters($parameters); - $users = $q->getResult(); + $this->_em->createQuery('SELECT u FROM ' . CmsUser::class . ' u WHERE u.name = ?1 AND u.status = ?2') + ->setParameters($parameters) + ->getResult(); } public function testSetParametersBackwardsCompatible() { - $q = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = ?1 AND u.status = ?2'); - $q->setParameters([1 => 'jwage', 2 => 'active']); - - $users = $q->getResult(); + $this->_em->createQuery('SELECT u FROM ' . CmsUser::class . ' u WHERE u.name = ?1 AND u.status = ?2') + ->setParameters([1 => 'jwage', 2 => 'active']) + ->getResult(); } /** @@ -200,18 +198,29 @@ public function testIterateResultAsArrayAndParams() $this->_em->clear(); $articleId = $article1->id; - $query = $this->_em->createQuery("select a from Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.topic = ?1"); + $query = $this->_em->createQuery('select a from ' . CmsArticle::class . ' a WHERE a.topic = ?1'); $articles = $query->iterate(new ArrayCollection([new Parameter(1, 'Doctrine 2')]), Query::HYDRATE_ARRAY); $found = []; + foreach ($articles AS $article) { $found[] = $article; } + $this->assertEquals(1, count($found)); $this->assertEquals( [ - [['id' => $articleId, 'topic' => 'Doctrine 2', 'text' => 'This is an introduction to Doctrine 2.', 'version' => 1]] - ], $found); + [ + [ + 'id' => $articleId, + 'topic' => 'Doctrine 2', + 'text' => 'This is an introduction to Doctrine 2.', + 'version' => 1, + ], + ], + ], + $found + ); } public function testIterateResult_IterativelyBuildUpUnitOfWork() @@ -230,11 +239,12 @@ public function testIterateResult_IterativelyBuildUpUnitOfWork() $this->_em->flush(); $this->_em->clear(); - $query = $this->_em->createQuery("select a from Doctrine\Tests\Models\CMS\CmsArticle a"); + $query = $this->_em->createQuery('select a from ' . CmsArticle::class . ' a'); $articles = $query->iterate(); $iteratedCount = 0; $topics = []; + foreach($articles AS $row) { $article = $row[0]; $topics[] = $article->topic; @@ -294,7 +304,7 @@ public function testIterateResultClearEveryCycle() */ public function testIterateResult_FetchJoinedCollection_ThrowsException() { - $query = $this->_em->createQuery("SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.articles a"); + $query = $this->_em->createQuery("SELECT u, a FROM ' . CmsUser::class . ' u JOIN u.articles a"); $articles = $query->iterate(); } @@ -360,7 +370,7 @@ public function testModifiedLimitQuery() $this->_em->flush(); $this->_em->clear(); - $data = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u') + $data = $this->_em->createQuery('SELECT u FROM ' . CmsUser::class . ' u') ->setFirstResult(1) ->setMaxResults(2) ->getResult(); @@ -369,7 +379,7 @@ public function testModifiedLimitQuery() $this->assertEquals('gblanco1', $data[0]->username); $this->assertEquals('gblanco2', $data[1]->username); - $data = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u') + $data = $this->_em->createQuery('SELECT u FROM ' . CmsUser::class . ' u') ->setFirstResult(3) ->setMaxResults(2) ->getResult(); @@ -378,7 +388,7 @@ public function testModifiedLimitQuery() $this->assertEquals('gblanco3', $data[0]->username); $this->assertEquals('gblanco4', $data[1]->username); - $data = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u') + $data = $this->_em->createQuery('SELECT u FROM ' . CmsUser::class . ' u') ->setFirstResult(3) ->setMaxResults(2) ->getScalarResult(); @@ -472,13 +482,13 @@ public function testgetOneOrNullResult() $this->_em->flush(); $this->_em->clear(); - $query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = 'gblanco'"); + $query = $this->_em->createQuery("select u from " . CmsUser::class . " u where u.username = 'gblanco'"); $fetchedUser = $query->getOneOrNullResult(); $this->assertInstanceOf(CmsUser::class, $fetchedUser); $this->assertEquals('gblanco', $fetchedUser->username); - $query = $this->_em->createQuery("select u.username from Doctrine\Tests\Models\CMS\CmsUser u where u.username = 'gblanco'"); + $query = $this->_em->createQuery("select u.username from " . CmsUser::class . " u where u.username = 'gblanco'"); $fetchedUsername = $query->getOneOrNullResult(Query::HYDRATE_SINGLE_SCALAR); $this->assertEquals('gblanco', $fetchedUsername); } diff --git a/tests/Doctrine/Tests/ORM/Functional/SequenceGeneratorTest.php b/tests/Doctrine/Tests/ORM/Functional/SequenceGeneratorTest.php index 13091c5e50b..c00f8bc9fe4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SequenceGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SequenceGeneratorTest.php @@ -14,18 +14,17 @@ public function setUp() { parent::setUp(); - if (!$this->_em->getConnection()->getDatabasePlatform()->supportsSequences()) { + if ( ! $this->_em->getConnection()->getDatabasePlatform()->supportsSequences()) { $this->markTestSkipped('Only working for Databases that support sequences.'); } try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(SequenceEntity::class), + $this->_em->getClassMetadata(SequenceEntity::class), ] ); } catch(\Exception $e) { - } } @@ -35,6 +34,7 @@ public function testHighAllocationSizeSequence() $e = new SequenceEntity(); $this->_em->persist($e); } + $this->_em->flush(); } } @@ -48,7 +48,7 @@ class SequenceEntity * @Id * @column(type="integer") * @GeneratedValue(strategy="SEQUENCE") - * @SequenceGenerator(allocationSize=5,sequenceName="person_id_seq") + * @SequenceGenerator(allocationSize=5, sequenceName="person_id_seq") */ public $id; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1113Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1113Test.php index f3b399f98ca..7402972b01f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1113Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1113Test.php @@ -8,21 +8,20 @@ */ class DDC1113Test extends \Doctrine\Tests\OrmFunctionalTestCase { - public function setUp() { parent::setUp(); + try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(DDC1113Engine::class), - $this->_em->getClassMetadata(DDC1113Vehicle::class), - $this->_em->getClassMetadata(DDC1113Car::class), - $this->_em->getClassMetadata(DDC1113Bus::class), + $this->_em->getClassMetadata(DDC1113Engine::class), + $this->_em->getClassMetadata(DDC1113Vehicle::class), + $this->_em->getClassMetadata(DDC1113Car::class), + $this->_em->getClassMetadata(DDC1113Bus::class), ] ); } catch (\Exception $e) { - } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php index 9c6740c3367..c6d215cf89e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php @@ -21,7 +21,8 @@ class DDC117Test extends \Doctrine\Tests\OrmFunctionalTestCase private $translation; private $articleDetails; - protected function setUp() { + protected function setUp() + { $this->useModelSet('ddc117'); parent::setUp(); @@ -63,7 +64,7 @@ public function testAssociationOnlyCompositeKey() $this->_em->clear(); - $dql = "SELECT r, s FROM Doctrine\Tests\Models\DDC117\DDC117Reference r JOIN r.source s WHERE r.source = ?1"; + $dql = 'SELECT r, s FROM ' . DDC117Reference::class . ' r JOIN r.source s WHERE r.source = ?1'; $dqlRef = $this->_em->createQuery($dql)->setParameter(1, 1)->getSingleResult(); $this->assertInstanceOf(DDC117Reference::class, $mapRef); @@ -73,7 +74,7 @@ public function testAssociationOnlyCompositeKey() $this->_em->clear(); - $dql = "SELECT r, s FROM Doctrine\Tests\Models\DDC117\DDC117Reference r JOIN r.source s WHERE s.title = ?1"; + $dql = 'SELECT r, s FROM ' . DDC117Reference::class . ' r JOIN r.source s WHERE s.title = ?1'; $dqlRef = $this->_em->createQuery($dql)->setParameter(1, 'Foo')->getSingleResult(); $this->assertInstanceOf(DDC117Reference::class, $dqlRef); @@ -81,7 +82,7 @@ public function testAssociationOnlyCompositeKey() $this->assertInstanceOf(DDC117Article::class, $dqlRef->source()); $this->assertSame($dqlRef, $this->_em->find(DDC117Reference::class, $idCriteria)); - $dql = "SELECT r, s FROM Doctrine\Tests\Models\DDC117\DDC117Reference r JOIN r.source s WHERE s.title = ?1"; + $dql = 'SELECT r, s FROM ' . DDC117Reference::class . ' r JOIN r.source s WHERE s.title = ?1'; $dqlRef = $this->_em->createQuery($dql)->setParameter(1, 'Foo')->getSingleResult(); $this->_em->contains($dqlRef); @@ -265,12 +266,11 @@ public function testOneToOneCascadeRemove() */ public function testOneToOneCascadePersist() { - if (!$this->_em->getConnection()->getDatabasePlatform()->prefersSequences()) { + if ( ! $this->_em->getConnection()->getDatabasePlatform()->prefersSequences()) { $this->markTestSkipped('Test only works with databases that prefer sequences as ID strategy.'); } $this->article1 = new DDC117Article("Foo"); - $this->articleDetails = new DDC117ArticleDetails($this->article1, "Very long text"); $this->_em->persist($this->article1); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php index d72a960f78e..1c4343e409c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php @@ -11,9 +11,9 @@ public function setUp() parent::setUp(); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(DDC1181Hotel::class), - $this->_em->getClassMetadata(DDC1181Booking::class), - $this->_em->getClassMetadata(DDC1181Room::class), + $this->_em->getClassMetadata(DDC1181Hotel::class), + $this->_em->getClassMetadata(DDC1181Booking::class), + $this->_em->getClassMetadata(DDC1181Room::class), ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php index 77cde326245..ce53b7505de 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php @@ -12,9 +12,9 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(DDC1209_1::class), - $this->_em->getClassMetadata(DDC1209_2::class), - $this->_em->getClassMetadata(DDC1209_3::class) + $this->_em->getClassMetadata(DDC1209_1::class), + $this->_em->getClassMetadata(DDC1209_2::class), + $this->_em->getClassMetadata(DDC1209_3::class) ] ); } catch(\Exception $e) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1306Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1306Test.php index 4818c82ad4b..956c5f7d57d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1306Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1306Test.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\Tests\Models\CMS\CmsAddress; use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\CMS\CmsPhonenumber; @@ -13,6 +14,7 @@ class DDC1306Test extends \Doctrine\Tests\OrmFunctionalTestCase public function setUp() { $this->useModelSet('cms'); + parent::setUp(); } @@ -25,7 +27,7 @@ public function testIssue() $this->_em->persist($phone); $this->_em->flush(); - $address = new \Doctrine\Tests\Models\CMS\CmsAddress(); + $address = new CmsAddress(); $address->city = "bonn"; $address->country = "Germany"; $address->street = "somestreet!"; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php index 4ac78d9b77e..a569c1a82f6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php @@ -14,9 +14,9 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(DDC1400Article::class), - $this->_em->getClassMetadata(DDC1400User::class), - $this->_em->getClassMetadata(DDC1400UserState::class), + $this->_em->getClassMetadata(DDC1400Article::class), + $this->_em->getClassMetadata(DDC1400User::class), + $this->_em->getClassMetadata(DDC1400UserState::class), ] ); } catch (\Exception $ignored) { @@ -48,15 +48,14 @@ public function testFailingCase() $this->_em->persist($userState1); $this->_em->persist($userState2); - $this->_em->flush(); $this->_em->clear(); $user1 = $this->_em->getReference(DDC1400User::class, $user1->id); - $q = $this->_em->createQuery("SELECT a, s FROM ".__NAMESPACE__."\DDC1400Article a JOIN a.userStates s WITH s.user = :activeUser"); - $q->setParameter('activeUser', $user1); - $articles = $q->getResult(); + $this->_em->createQuery('SELECT a, s FROM ' . DDC1400Article::class . ' a JOIN a.userStates s WITH s.user = :activeUser') + ->setParameter('activeUser', $user1) + ->getResult(); $this->_em->flush(); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php index f85df4a7eee..064b7802114 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php @@ -8,12 +8,11 @@ class DDC144Test extends OrmFunctionalTestCase { protected function setUp() { parent::setUp(); - //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(DDC144FlowElement::class), - $this->_em->getClassMetadata(DDC144Operand::class), + $this->_em->getClassMetadata(DDC144FlowElement::class), + $this->_em->getClassMetadata(DDC144Operand::class), ] ); @@ -24,10 +23,10 @@ protected function setUp() { */ public function testIssue() { - $operand = new DDC144Operand; $operand->property = 'flowValue'; $operand->operandProperty = 'operandValue'; + $this->_em->persist($operand); $this->_em->flush(); @@ -41,23 +40,30 @@ public function testIssue() * @DiscriminatorColumn(type="string", name="discr") * @DiscriminatorMap({"flowelement" = "DDC144FlowElement", "operand" = "DDC144Operand"}) */ -class DDC144FlowElement { +class DDC144FlowElement +{ /** * @Id @Column(type="integer") @GeneratedValue * @var int */ public $id; + /** @Column */ public $property; } -abstract class DDC144Expression extends DDC144FlowElement { - abstract function method(); +abstract class DDC144Expression extends DDC144FlowElement +{ + abstract public function method(); } /** @Entity @Table(name="ddc144_operands") */ -class DDC144Operand extends DDC144Expression { +class DDC144Operand extends DDC144Expression +{ /** @Column */ public $operandProperty; - function method() {} + + public function method() + { + } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1454Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1454Test.php index 54d5dbd20a6..0f550931018 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1454Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1454Test.php @@ -14,12 +14,11 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(DDC1454File::class), - $this->_em->getClassMetadata(DDC1454Picture::class), + $this->_em->getClassMetadata(DDC1454File::class), + $this->_em->getClassMetadata(DDC1454Picture::class), ] ); } catch (\Exception $ignored) { - } } @@ -36,7 +35,6 @@ public function testFailingCase() */ class DDC1454Picture extends DDC1454File { - } /** @@ -53,14 +51,16 @@ class DDC1454File */ public $fileId; - public function __construct() { + public function __construct() + { $this->fileId = rand(); } /** * Get fileId */ - public function getFileId() { + public function getFileId() + { return $this->fileId; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1925Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1925Test.php index c61fae9c6a1..8c56951beba 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1925Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1925Test.php @@ -14,23 +14,25 @@ public function testIssue() { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(DDC1925User::class), - $this->_em->getClassMetadata(DDC1925Product::class), + $this->_em->getClassMetadata(DDC1925User::class), + $this->_em->getClassMetadata(DDC1925Product::class), ] ); $user = new DDC1925User(); $user->setTitle("Test User"); - $this->_em->persist($user); $product = new DDC1925Product(); $product->setTitle("Test product"); + + $this->_em->persist($user); $this->_em->persist($product); $this->_em->flush(); $product->addBuyer($user); - $this->_em->getUnitOfWork()->computeChangeSets(); + $this->_em->getUnitOfWork() + ->computeChangeSets(); $this->_em->persist($product); $this->_em->flush(); @@ -104,15 +106,7 @@ public function getTitle() } /** - * @param string $buyers - */ - public function setBuyers($buyers) - { - $this->buyers = $buyers; - } - - /** - * @return string + * @return ArrayCollection */ public function getBuyers() { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC192Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC192Test.php index f6f0f173d1c..e9006236379 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC192Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC192Test.php @@ -4,27 +4,31 @@ use Doctrine\Tests\OrmFunctionalTestCase; +/** + * @group DDC-192 + */ class DDC192Test extends OrmFunctionalTestCase { public function testSchemaCreation() { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(DDC192User::class), - $this->_em->getClassMetadata(DDC192Phonenumber::class) + $this->_em->getClassMetadata(DDC192User::class), + $this->_em->getClassMetadata(DDC192Phonenumber::class) ] ); } } - /** - * @Entity @Table(name="ddc192_users") + * @Entity + * @Table(name="ddc192_users") */ class DDC192User { /** - * @Id @Column(name="id", type="integer") + * @Id + * @Column(name="id", type="integer") * @GeneratedValue(strategy="AUTO") */ public $id; @@ -37,12 +41,14 @@ class DDC192User /** - * @Entity @Table(name="ddc192_phonenumbers") + * @Entity + * @Table(name="ddc192_phonenumbers") */ class DDC192Phonenumber { /** - * @Id @Column(name="phone", type="string", length=40) + * @Id + * @Column(name="phone", type="string", length=40) */ protected $phone; @@ -54,14 +60,23 @@ class DDC192Phonenumber protected $User; - public function setPhone($value) { $this->phone = $value; } + public function setPhone($value) + { + $this->phone = $value; + } - public function getPhone() { return $this->phone; } + public function getPhone() + { + return $this->phone; + } public function setUser(User $user) { $this->User = $user; } - public function getUser() { return $this->User; } + public function getUser() + { + return $this->User; + } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php index 0fdc7f84d3e..c56f3fb4826 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php @@ -12,9 +12,10 @@ class DDC2106Test extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { parent::setUp(); + $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(DDC2106Entity::class), + $this->_em->getClassMetadata(DDC2106Entity::class), ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2256Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2256Test.php index 681210159ef..9e6f0bccaaf 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2256Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2256Test.php @@ -13,10 +13,11 @@ class DDC2256Test extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { parent::setUp(); + $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(DDC2256User::class), - $this->_em->getClassMetadata(DDC2256Group::class) + $this->_em->getClassMetadata(DDC2256User::class), + $this->_em->getClassMetadata(DDC2256Group::class) ] ); } @@ -55,8 +56,7 @@ public function testIssue() // Test ResultSetMappingBuilder. $rsm = new ResultSetMappingBuilder($this->_em); $rsm->addRootEntityFromClassMetadata('MyNamespace:DDC2256User', 'u'); - $rsm->addJoinedEntityFromClassMetadata('MyNamespace:DDC2256Group', 'g', 'u', 'group', ['id' => 'group_id', 'name' => 'group_name'] - ); + $rsm->addJoinedEntityFromClassMetadata('MyNamespace:DDC2256Group', 'g', 'u', 'group', ['id' => 'group_id', 'name' => 'group_name']); $this->_em->createNativeQuery($sql, $rsm)->getResult(); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2775Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2775Test.php index 025ee763315..3f77033858d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2775Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2775Test.php @@ -17,10 +17,10 @@ protected function setUp() $this->setUpEntitySchema( [ - User::class, - Role::class, - AdminRole::class, - Authorization::class, + User::class, + Role::class, + AdminRole::class, + Authorization::class, ] ); } @@ -30,9 +30,8 @@ protected function setUp() */ public function testIssueCascadeRemove() { - $user = new User(); - $role = new AdminRole(); + $user = new User(); $user->addRole($role); $authorization = new Authorization(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php index ac3f10be61f..88e3727d2c1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php @@ -38,10 +38,9 @@ protected function setUp() */ public function testIssue() { - // $this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - $productJoined = new DDC3170ProductJoined(); $productSingleTable = new DDC3170ProductSingleTable(); + $this->_em->persist($productJoined); $this->_em->persist($productSingleTable); $this->_em->flush(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3711Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3711Test.php index 3fc4c856bd9..bd2b1ba9bc6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3711Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3711Test.php @@ -26,6 +26,5 @@ public function testCompositeKeyForJoinTableInManyToManyCreation() $this->assertEquals(['link_a_id1' => "id1", 'link_a_id2' => "id2"], $entityA->associationMappings['entityB']['relationToSourceKeyColumns']); $this->assertEquals(['link_b_id1' => "id1", 'link_b_id2' => "id2"], $entityA->associationMappings['entityB']['relationToTargetKeyColumns']); - } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3785Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3785Test.php index 05498db774a..4fcc3932c29 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3785Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3785Test.php @@ -17,9 +17,9 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(DDC3785_Asset::class), - $this->_em->getClassMetadata(DDC3785_AssetId::class), - $this->_em->getClassMetadata(DDC3785_Attribute::class) + $this->_em->getClassMetadata(DDC3785_Asset::class), + $this->_em->getClassMetadata(DDC3785_AssetId::class), + $this->_em->getClassMetadata(DDC3785_Attribute::class) ] ); } catch(\Exception $e) { @@ -31,15 +31,18 @@ protected function setUp() */ public function testOwningValueObjectIdIsCorrectlyTransformedWhenRemovingOrphanedChildEntities() { - $id = new DDC3785_AssetId("919609ba-57d9-4a13-be1d-d202521e858a"); - $attributes = [ - $attribute1 = new DDC3785_Attribute("foo1", "bar1"), - $attribute2 = new DDC3785_Attribute("foo2", "bar2") + $id = new DDC3785_AssetId('919609ba-57d9-4a13-be1d-d202521e858a'); + + $attributes = [ + $attribute1 = new DDC3785_Attribute('foo1', 'bar1'), + $attribute2 = new DDC3785_Attribute('foo2', 'bar2') ]; + $this->_em->persist($asset = new DDC3785_Asset($id, $attributes)); $this->_em->flush(); - $asset->getAttributes()->removeElement($attribute1); + $asset->getAttributes() + ->removeElement($attribute1); $this->_em->persist($asset); $this->_em->flush(); @@ -68,12 +71,12 @@ class DDC3785_Asset public function __construct(DDC3785_AssetId $id, $attributes = []) { - $this->id = $id; - $this->attributes = new ArrayCollection(); + $this->id = $id; + $this->attributes = new ArrayCollection(); - foreach ($attributes as $attribute) { - $this->attributes->add($attribute); - } + foreach ($attributes as $attribute) { + $this->attributes->add($attribute); + } } public function getId() @@ -83,7 +86,7 @@ public function getId() public function getAttributes() { - return $this->attributes; + return $this->attributes; } } @@ -93,23 +96,23 @@ public function getAttributes() */ class DDC3785_Attribute { - /** + /** * @Id @Column(type="integer") * @GeneratedValue */ - private $id; + private $id; - /** @Column(type = "string") */ - private $name; + /** @Column(type = "string") */ + private $name; - /** @Column(type = "string") */ - private $value; + /** @Column(type = "string") */ + private $value; - public function __construct($name, $value) - { - $this->name = $name; - $this->value = $value; - } + public function __construct($name, $value) + { + $this->name = $name; + $this->value = $value; + } } /** @Embeddable */ @@ -120,12 +123,12 @@ class DDC3785_AssetId public function __construct($id) { - $this->id = $id; + $this->id = $id; } public function __toString() { - return $this->id; + return $this->id; } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php index 9818e60aa87..3909b9ca03d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php @@ -13,16 +13,16 @@ class DDC522Test extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { parent::setUp(); + try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(DDC522Customer::class), - $this->_em->getClassMetadata(DDC522Cart::class), - $this->_em->getClassMetadata(DDC522ForeignKeyTest::class) + $this->_em->getClassMetadata(DDC522Customer::class), + $this->_em->getClassMetadata(DDC522Cart::class), + $this->_em->getClassMetadata(DDC522ForeignKeyTest::class) ] ); } catch(\Exception $e) { - } } @@ -43,8 +43,8 @@ public function testJoinColumnWithSameNameAsAssociationField() $this->_em->clear(); - $r = $this->_em->createQuery("select ca,c from ".get_class($cart)." ca join ca.customer c") - ->getResult(); + $r = $this->_em->createQuery('select ca,c from ' . DDC522Cart::class . ' ca join ca.customer c') + ->getResult(); $this->assertInstanceOf(DDC522Cart::class, $r[0]); $this->assertInstanceOf(DDC522Customer::class, $r[0]->customer); @@ -71,7 +71,7 @@ public function testJoinColumnWithSameNameAsAssociationField() public function testJoinColumnWithNullSameNameAssociationField() { $fkCust = new DDC522ForeignKeyTest; - $fkCust->name = "name"; + $fkCust->name = 'name'; $fkCust->cart = null; $this->_em->persist($fkCust); @@ -83,21 +83,27 @@ public function testJoinColumnWithNullSameNameAssociationField() } /** @Entity */ -class DDC522Customer { +class DDC522Customer +{ /** @Id @Column(type="integer") @GeneratedValue */ public $id; + /** @Column */ public $name; + /** @OneToOne(targetEntity="DDC522Cart", mappedBy="customer") */ public $cart; } /** @Entity */ -class DDC522Cart { +class DDC522Cart +{ /** @Id @Column(type="integer") @GeneratedValue */ public $id; + /** @Column(type="integer") */ public $total; + /** * @OneToOne(targetEntity="DDC522Customer", inversedBy="cart") * @JoinColumn(name="customer", referencedColumnName="id") @@ -106,11 +112,14 @@ class DDC522Cart { } /** @Entity */ -class DDC522ForeignKeyTest { +class DDC522ForeignKeyTest +{ /** @Id @Column(type="integer") @GeneratedValue */ public $id; + /** @Column(type="integer", name="cart_id", nullable=true) */ public $cartId; + /** * @OneToOne(targetEntity="DDC522Cart") * @JoinColumn(name="cart_id", referencedColumnName="id") diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC588Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC588Test.php index 021e582e667..aa50f2cdbc8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC588Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC588Test.php @@ -7,9 +7,10 @@ class DDC588Test extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { parent::setUp(); + $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(DDC588Site::class), + $this->_em->getClassMetadata(DDC588Site::class), ] ); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC742Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC742Test.php index 4d03bca2a01..bc465db9257 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC742Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC742Test.php @@ -27,8 +27,8 @@ protected function setUp() try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(DDC742User::class), - $this->_em->getClassMetadata(DDC742Comment::class) + $this->_em->getClassMetadata(DDC742User::class), + $this->_em->getClassMetadata(DDC742Comment::class) ] ); } catch(\Exception $e) { @@ -64,9 +64,9 @@ public function testIssue() $this->_em->flush(); $this->_em->clear(); - $user = $this->_em->find(get_class($user), $user->id); - $comment3 = $this->_em->find(get_class($comment3), $comment3->id); - $user->favoriteComments->add($comment3); + $user = $this->_em->find(DDC742User::class, $user->id); + $user->favoriteComments->add($this->_em->find(DDC742Comment::class, $comment3->id)); + $this->_em->flush(); } } @@ -86,11 +86,13 @@ class DDC742User * @var int */ public $id; + /** * @Column(length=100, type="string") * @var string */ public $title; + /** * @ManyToMany(targetEntity="DDC742Comment", cascade={"persist"}, fetch="EAGER") * @JoinTable( @@ -99,7 +101,7 @@ class DDC742User * inverseJoinColumns={@JoinColumn(name="comment_id", referencedColumnName="id")} * ) * - * @var Doctrine\ORM\PersistentCollection + * @var \Doctrine\ORM\PersistentCollection */ public $favoriteComments; } @@ -119,6 +121,7 @@ class DDC742Comment * @var int */ public $id; + /** * @Column(length=100, type="string") * @var string diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php index 9e674e3cab2..ee46b5bc765 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php @@ -7,22 +7,24 @@ class DDC832Test extends \Doctrine\Tests\OrmFunctionalTestCase public function setUp() { parent::setUp(); + $platform = $this->_em->getConnection()->getDatabasePlatform(); - if ($platform->getName() == "oracle") { + + if ($platform->getName() === 'oracle') { $this->markTestSkipped('Doesnt run on Oracle.'); } $this->_em->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger()); + try { $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(DDC832JoinedIndex::class), - $this->_em->getClassMetadata(DDC832JoinedTreeIndex::class), - $this->_em->getClassMetadata(DDC832Like::class), + $this->_em->getClassMetadata(DDC832JoinedIndex::class), + $this->_em->getClassMetadata(DDC832JoinedTreeIndex::class), + $this->_em->getClassMetadata(DDC832Like::class), ] ); } catch(\Exception $e) { - } } @@ -30,6 +32,7 @@ public function tearDown() { /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ $platform = $this->_em->getConnection()->getDatabasePlatform(); + $sm = $this->_em->getConnection()->getSchemaManager(); $sm->dropTable($platform->quoteIdentifier('TREE_INDEX')); $sm->dropTable($platform->quoteIdentifier('INDEX')); @@ -41,11 +44,11 @@ public function tearDown() */ public function testQuotedTableBasicUpdate() { - $like = new DDC832Like("test"); + $like = new DDC832Like('test'); $this->_em->persist($like); $this->_em->flush(); - $like->word = "test2"; + $like->word = 'test2'; $this->_em->flush(); } @@ -54,7 +57,7 @@ public function testQuotedTableBasicUpdate() */ public function testQuotedTableBasicRemove() { - $like = new DDC832Like("test"); + $like = new DDC832Like('test'); $this->_em->persist($like); $this->_em->flush(); @@ -67,11 +70,11 @@ public function testQuotedTableBasicRemove() */ public function testQuotedTableJoinedUpdate() { - $index = new DDC832JoinedIndex("test"); + $index = new DDC832JoinedIndex('test'); $this->_em->persist($index); $this->_em->flush(); - $index->name = "asdf"; + $index->name = 'asdf'; $this->_em->flush(); } @@ -80,7 +83,7 @@ public function testQuotedTableJoinedUpdate() */ public function testQuotedTableJoinedRemove() { - $index = new DDC832JoinedIndex("test"); + $index = new DDC832JoinedIndex('test'); $this->_em->persist($index); $this->_em->flush(); @@ -93,11 +96,11 @@ public function testQuotedTableJoinedRemove() */ public function testQuotedTableJoinedChildUpdate() { - $index = new DDC832JoinedTreeIndex("test", 1, 2); + $index = new DDC832JoinedTreeIndex('test', 1, 2); $this->_em->persist($index); $this->_em->flush(); - $index->name = "asdf"; + $index->name = 'asdf'; $this->_em->flush(); } @@ -106,7 +109,7 @@ public function testQuotedTableJoinedChildUpdate() */ public function testQuotedTableJoinedChildRemove() { - $index = new DDC832JoinedTreeIndex("test", 1, 2); + $index = new DDC832JoinedTreeIndex('test', 1, 2); $this->_em->persist($index); $this->_em->flush(); @@ -178,6 +181,7 @@ class DDC832JoinedTreeIndex extends DDC832JoinedIndex { /** @Column(type="integer") */ public $lft; + /** @Column(type="integer") */ public $rgt; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC933Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC933Test.php index e4c9d132860..039eb7ab804 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC933Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC933Test.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\DBAL\LockMode; +use Doctrine\Tests\Models\Company\CompanyManager; use Doctrine\Tests\OrmFunctionalTestCase; class DDC933Test extends OrmFunctionalTestCase @@ -9,6 +11,7 @@ class DDC933Test extends OrmFunctionalTestCase public function setUp() { $this->useModelSet('company'); + parent::setUp(); } @@ -17,9 +20,7 @@ public function setUp() */ public function testLockCTIClass() { - //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger()); - - $manager = new \Doctrine\Tests\Models\Company\CompanyManager(); + $manager = new CompanyManager(); $manager->setName('beberlei'); $manager->setSalary(1234); $manager->setTitle('Vice President of This Test'); @@ -29,7 +30,7 @@ public function testLockCTIClass() $this->_em->flush(); $this->_em->beginTransaction(); - $this->_em->lock($manager, \Doctrine\DBAL\LockMode::PESSIMISTIC_READ); + $this->_em->lock($manager, LockMode::PESSIMISTIC_READ); $this->_em->rollback(); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php index 05200201457..9276d74ee8f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php @@ -15,6 +15,7 @@ class TypeTest extends OrmFunctionalTestCase protected function setUp() { $this->useModelSet('generic'); + parent::setUp(); } @@ -28,7 +29,7 @@ public function testDecimal() $this->_em->flush(); $this->_em->clear(); - $dql = "SELECT d FROM Doctrine\Tests\Models\Generic\DecimalModel d"; + $dql = 'SELECT d FROM ' . DecimalModel::class . ' d'; $decimal = $this->_em->createQuery($dql)->getSingleResult(); $this->assertEquals(0.15, $decimal->decimal); @@ -48,7 +49,7 @@ public function testBoolean() $this->_em->flush(); $this->_em->clear(); - $dql = "SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = true"; + $dql = 'SELECT b FROM ' . BooleanModel::class . ' b WHERE b.booleanField = true'; $bool = $this->_em->createQuery($dql)->getSingleResult(); $this->assertTrue($bool->booleanField); @@ -58,7 +59,7 @@ public function testBoolean() $this->_em->flush(); $this->_em->clear(); - $dql = "SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = false"; + $dql = 'SELECT b FROM ' . BooleanModel::class . ' b WHERE b.booleanField = false'; $bool = $this->_em->createQuery($dql)->getSingleResult(); $this->assertFalse($bool->booleanField); @@ -74,7 +75,7 @@ public function testArray() $this->_em->flush(); $this->_em->clear(); - $dql = "SELECT s FROM Doctrine\Tests\Models\Generic\SerializationModel s"; + $dql = 'SELECT s FROM ' . SerializationModel::class . ' s'; $serialize = $this->_em->createQuery($dql)->getSingleResult(); $this->assertEquals(["foo" => "bar", "bar" => "baz"], $serialize->array); @@ -89,7 +90,7 @@ public function testObject() $this->_em->flush(); $this->_em->clear(); - $dql = "SELECT s FROM Doctrine\Tests\Models\Generic\SerializationModel s"; + $dql = 'SELECT s FROM ' . SerializationModel::class . ' s'; $serialize = $this->_em->createQuery($dql)->getSingleResult(); $this->assertInstanceOf('stdClass', $serialize->object); @@ -106,7 +107,7 @@ public function testDate() $dateTimeDb = $this->_em->find(DateTimeModel::class, $dateTime->id); - $this->assertInstanceOf('DateTime', $dateTimeDb->date); + $this->assertInstanceOf(\DateTime::class, $dateTimeDb->date); $this->assertEquals('2009-10-01', $dateTimeDb->date->format('Y-m-d')); } @@ -121,12 +122,12 @@ public function testDateTime() $dateTimeDb = $this->_em->find(DateTimeModel::class, $dateTime->id); - $this->assertInstanceOf('DateTime', $dateTimeDb->datetime); + $this->assertInstanceOf(\DateTime::class, $dateTimeDb->datetime); $this->assertEquals('2009-10-02 20:10:52', $dateTimeDb->datetime->format('Y-m-d H:i:s')); - $articles = $this->_em->getRepository( DateTimeModel::class )->findBy( ['datetime' => new \DateTime( "now" )] - ); - $this->assertEquals( 0, count( $articles ) ); + $articles = $this->_em->getRepository(DateTimeModel::class) + ->findBy(['datetime' => new \DateTime()]); + $this->assertEquals(0, count($articles)); } public function testDqlQueryBindDateTimeInstance() @@ -175,7 +176,7 @@ public function testTime() $dateTimeDb = $this->_em->find(DateTimeModel::class, $dateTime->id); - $this->assertInstanceOf('DateTime', $dateTime->time); - $this->assertEquals('19:27:20', $dateTime->time->format('H:i:s')); + $this->assertInstanceOf(\DateTime::class, $dateTimeDb->time); + $this->assertEquals('19:27:20', $dateTimeDb->time->format('H:i:s')); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php b/tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php index 971af91703f..3af954cfd97 100644 --- a/tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php @@ -3,6 +3,8 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\DBAL\Types\Type as DBALType; +use Doctrine\Tests\DbalTypes\NegativeToPositiveType; +use Doctrine\Tests\DbalTypes\UpperCaseStringType; use Doctrine\Tests\Models\CustomType\CustomTypeChild; use Doctrine\Tests\Models\CustomType\CustomTypeParent; use Doctrine\Tests\Models\CustomType\CustomTypeUpperCase; @@ -12,16 +14,16 @@ class TypeValueSqlTest extends OrmFunctionalTestCase { protected function setUp() { - if (DBALType::hasType('upper_case_string')) { - DBALType::overrideType('upper_case_string', '\Doctrine\Tests\DbalTypes\UpperCaseStringType'); + if (DBALType::hasType(UpperCaseStringType::NAME)) { + DBALType::overrideType(UpperCaseStringType::NAME, UpperCaseStringType::class); } else { - DBALType::addType('upper_case_string', '\Doctrine\Tests\DbalTypes\UpperCaseStringType'); + DBALType::addType(UpperCaseStringType::NAME, UpperCaseStringType::class); } - if (DBALType::hasType('negative_to_positive')) { - DBALType::overrideType('negative_to_positive', '\Doctrine\Tests\DbalTypes\NegativeToPositiveType'); + if (DBALType::hasType(NegativeToPositiveType::NAME)) { + DBALType::overrideType(NegativeToPositiveType::NAME, NegativeToPositiveType::class); } else { - DBALType::addType('negative_to_positive', '\Doctrine\Tests\DbalTypes\NegativeToPositiveType'); + DBALType::addType(NegativeToPositiveType::NAME, NegativeToPositiveType::class); } $this->useModelSet('customtype'); diff --git a/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php index 2ad9461ff04..2c51929bc78 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Hydration; +use Doctrine\ORM\Internal\Hydration\ScalarHydrator; use Doctrine\Tests\Mocks\HydratorMockStatement; use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\Tests\Models\CMS\CmsUser; @@ -32,7 +33,7 @@ public function testNewHydrationSimpleEntityQuery() $stmt = new HydratorMockStatement($resultSet); - $hydrator = new \Doctrine\ORM\Internal\Hydration\ScalarHydrator($this->_em); + $hydrator = new ScalarHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); @@ -63,7 +64,7 @@ public function testHydrateScalarResults() ]; $stmt = new HydratorMockStatement($resultSet); - $hydrator = new \Doctrine\ORM\Internal\Hydration\ScalarHydrator($this->_em); + $hydrator = new ScalarHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); } @@ -93,7 +94,7 @@ public function testSkipUnknownColumns() ]; $stmt = new HydratorMockStatement($resultSet); - $hydrator = new \Doctrine\ORM\Internal\Hydration\ScalarHydrator($this->_em); + $hydrator = new ScalarHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); } diff --git a/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php index d0cebbc494f..694259b298f 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\ORM\Hydration; +use Doctrine\ORM\Internal\Hydration\SingleScalarHydrator; +use Doctrine\ORM\NonUniqueResultException; use Doctrine\Tests\Mocks\HydratorMockStatement; use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\Tests\Models\CMS\CmsUser; @@ -9,48 +11,49 @@ class SingleScalarHydratorTest extends HydrationTestCase { /** Result set provider for the HYDRATE_SINGLE_SCALAR tests */ - public static function singleScalarResultSetProvider() { + public static function singleScalarResultSetProvider(): array + { return [ - // valid - [ - 'name' => 'result1', + // valid + 'valid' => [ + 'name' => 'result1', 'resultSet' => [ - [ - 'u__name' => 'romanb' - ] - ] - ], - // valid - [ - 'name' => 'result2', + [ + 'u__name' => 'romanb', + ], + ], + ], + // valid + [ + 'name' => 'result2', 'resultSet' => [ - [ - 'u__id' => '1' - ] - ] - ], - // invalid - [ - 'name' => 'result3', + [ + 'u__id' => '1', + ], + ], + ], + // invalid + [ + 'name' => 'result3', 'resultSet' => [ - [ - 'u__id' => '1', - 'u__name' => 'romanb' - ] - ] - ], - // invalid - [ - 'name' => 'result4', + [ + 'u__id' => '1', + 'u__name' => 'romanb', + ], + ], + ], + // invalid + [ + 'name' => 'result4', 'resultSet' => [ - [ - 'u__id' => '1' - ], - [ - 'u__id' => '2' - ] - ] - ], + [ + 'u__id' => '1', + ], + [ + 'u__id' => '2', + ], + ], + ], ]; } @@ -67,7 +70,7 @@ public function testHydrateSingleScalar($name, $resultSet) $rsm->addFieldResult('u', 'u__name', 'name'); $stmt = new HydratorMockStatement($resultSet); - $hydrator = new \Doctrine\ORM\Internal\Hydration\SingleScalarHydrator($this->_em); + $hydrator = new SingleScalarHydrator($this->_em); if ($name == 'result1') { $result = $hydrator->hydrateAll($stmt, $rsm); diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index f857bed4547..e13d7aa7e5b 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -68,17 +68,10 @@ protected function createClassMetadataFactory(EntityManager $em = null) return $factory; } - public function testLoadMapping() + public function testEntityTableNameAndInheritance() { - return $this->createClassMetadata(User::class); - } + $class = $this->createClassMetadata(User::class); - /** - * @depends testLoadMapping - * @param ClassMetadata $class - */ - public function testEntityTableNameAndInheritance($class) - { $this->assertEquals('cms_users', $class->getTableName()); $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $class->inheritanceType); @@ -274,14 +267,12 @@ public function testIdentifier($class) /** * @group #6129 * - * @depends testLoadMapping - * - * @param ClassMetadata $class - * * @return ClassMetadata */ - public function testBooleanValuesForOptionIsSetCorrectly(ClassMetadata $class) + public function testBooleanValuesForOptionIsSetCorrectly() { + $class = $this->createClassMetadata(User::class); + $this->assertInternalType('bool', $class->fieldMappings['id']['options']['unsigned']); $this->assertFalse($class->fieldMappings['id']['options']['unsigned']); diff --git a/tests/Doctrine/Tests/ORM/Mapping/StaticPHPMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/StaticPHPMappingDriverTest.php index e374e135e38..5f2f0c1d7bd 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/StaticPHPMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/StaticPHPMappingDriverTest.php @@ -12,7 +12,6 @@ protected function _loadDriver() return new StaticPHPDriver(__DIR__ . DIRECTORY_SEPARATOR . 'php'); } - /** * All class with static::loadMetadata are entities for php driver * From 8d144daf01e7daae4ae2a327beb1de25ce2036b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Mon, 12 Jun 2017 23:04:06 +0200 Subject: [PATCH 300/877] Remove duplicated tests (keeping them on unit test suite only) --- .../ORM/Functional/ManyToManyBasicAssociationTest.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php index 9aa044f5d99..0436b2af762 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php @@ -304,15 +304,6 @@ public function addCmsUserGblancoWithGroups($groupCount = 1) return $user; } - /** - * @group DDC-980 - */ - public function testUpdateDeleteSizeSubselectQueries() - { - $this->_em->createQuery("DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE SIZE(u.groups) = 10")->execute(); - $this->_em->createQuery("UPDATE Doctrine\Tests\Models\CMS\CmsUser u SET u.status = 'inactive' WHERE SIZE(u.groups) = 10")->execute(); - } - /** * @group DDC-978 */ From 1bf884970f2e4c75e817dd4db5532e8bb44a5f2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 31 May 2017 08:05:01 +0200 Subject: [PATCH 301/877] Increment assertion count manually Which is needed to test void methods that shouldn't raise any exception on a certain condition. If the interpreter gets to the point where the assertion count is incremented it means that no exceptions have been thrown and our test is successful. Important to note that some tests were slighly refactored to simplify things a bit. --- .../Doctrine/Tests/ORM/ConfigurationTest.php | 2 + .../Functional/ClassTableInheritanceTest.php | 1 + .../Tests/ORM/Functional/Locking/LockTest.php | 2 + .../ORM/Functional/Locking/OptimisticTest.php | 2 + .../ORM/Functional/PersistentObjectTest.php | 2 + .../ORM/Functional/Ticket/DDC3170Test.php | 30 +++----- .../ORM/Functional/Ticket/DDC588Test.php | 2 + .../ORM/Functional/Ticket/DDC742Test.php | 1 + .../Tests/ORM/Tools/SchemaValidatorTest.php | 68 +++++-------------- 9 files changed, 38 insertions(+), 72 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/ConfigurationTest.php b/tests/Doctrine/Tests/ORM/ConfigurationTest.php index df74c6df246..ab657c5fd2a 100644 --- a/tests/Doctrine/Tests/ORM/ConfigurationTest.php +++ b/tests/Doctrine/Tests/ORM/ConfigurationTest.php @@ -179,6 +179,8 @@ public function testEnsureProductionSettings() { $this->setProductionSettings(); $this->configuration->ensureProductionSettings(); + + $this->addToAssertionCount(1); } public function testEnsureProductionSettingsQueryCache() diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php index 02ed0a3565c..c94d3d73d48 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php @@ -301,6 +301,7 @@ public function testBulkUpdateNonScalarParameterDDC1341() ->setParameter(1, 'IT') ->execute(); + $this->addToAssertionCount(1); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php index dc27d45be47..d515e95bff7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php @@ -37,6 +37,8 @@ public function testLockVersionedEntity() $this->_em->flush(); $this->_em->lock($article, LockMode::OPTIMISTIC, $article->version); + + $this->addToAssertionCount(1); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php index 3681ed95ef9..8b8113b6a66 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php @@ -178,6 +178,8 @@ public function testLockWorksWithProxy() $proxy = $this->_em->getReference(OptimisticStandard::class, $test->id); $this->_em->lock($proxy, LockMode::OPTIMISTIC, 1); + + $this->addToAssertionCount(1); } public function testOptimisticTimestampSetsDefaultValue() diff --git a/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php b/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php index b611c7125fa..0fd2b47455c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php @@ -36,6 +36,8 @@ public function testPersist() $this->_em->persist($entity); $this->_em->flush(); + + $this->addToAssertionCount(1); } public function testFind() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php index 88e3727d2c1..0ef1caee8e1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php @@ -46,27 +46,17 @@ public function testIssue() $this->_em->flush(); $this->_em->clear(); - try { - $this->_em->createQueryBuilder() - ->select('p') - ->from(DDC3170ProductJoined::class, 'p') - ->getQuery() - ->getResult(AbstractQuery::HYDRATE_SIMPLEOBJECT); - } catch (HydrationException $e) // Thrown by SimpleObjectHydrator - { - $this->fail('Failed correct mapping of discriminator column when using simple object hydration and class table inheritance'); - } + $this->_em->createQueryBuilder() + ->select('p') + ->from(DDC3170ProductJoined::class, 'p') + ->getQuery() + ->getResult(AbstractQuery::HYDRATE_SIMPLEOBJECT); - try { - $this->_em->createQueryBuilder() - ->select('p') - ->from(DDC3170ProductSingleTable::class, 'p') - ->getQuery() - ->getResult(AbstractQuery::HYDRATE_SIMPLEOBJECT); - } catch (HydrationException $e) // Thrown by SimpleObjectHydrator - { - $this->fail('Failed correct mapping of discriminator column when using simple object hydration and single table inheritance'); - } + $this->_em->createQueryBuilder() + ->select('p') + ->from(DDC3170ProductSingleTable::class, 'p') + ->getQuery() + ->getResult(AbstractQuery::HYDRATE_SIMPLEOBJECT); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC588Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC588Test.php index aa50f2cdbc8..7361bc4f403 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC588Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC588Test.php @@ -23,6 +23,8 @@ public function testIssue() $this->_em->flush(); // Following should not result in exception $this->_em->refresh($site); + + $this->addToAssertionCount(1); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC742Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC742Test.php index bc465db9257..8adcb08795e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC742Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC742Test.php @@ -68,6 +68,7 @@ public function testIssue() $user->favoriteComments->add($this->_em->find(DDC742Comment::class, $comment3->id)); $this->_em->flush(); + $this->addToAssertionCount(1); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php index ea282630992..955a5f43dc4 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php @@ -24,64 +24,28 @@ public function setUp() $this->validator = new SchemaValidator($this->em); } - public function testCmsModelSet() - { - $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths( - [ - __DIR__ . "/../../Models/CMS" - ] - ); - $this->validator->validateMapping(); - } - - public function testCompanyModelSet() - { - $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths( - [ - __DIR__ . "/../../Models/Company" - ] - ); - $this->validator->validateMapping(); - } - - public function testECommerceModelSet() - { - $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths( - [ - __DIR__ . "/../../Models/ECommerce" - ] - ); - $this->validator->validateMapping(); - } - - public function testForumModelSet() + /** + * @dataProvider modelSetProvider + */ + public function testCmsModelSet(string $path) { - $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths( - [ - __DIR__ . "/../../Models/Forum" - ] - ); - $this->validator->validateMapping(); - } + $this->em->getConfiguration() + ->getMetadataDriverImpl() + ->addPaths([$path]); - public function testNavigationModelSet() - { - $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths( - [ - __DIR__ . "/../../Models/Navigation" - ] - ); $this->validator->validateMapping(); } - public function testRoutingModelSet() + public function modelSetProvider(): array { - $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths( - [ - __DIR__ . "/../../Models/Routing" - ] - ); - $this->validator->validateMapping(); + return [ + 'cms' => [__DIR__ . '/../../Models/CMS'], + 'company' => [__DIR__ . '/../../Models/Company'], + 'ecommerce' => [__DIR__ . '/../../Models/ECommerce'], + 'forum' => [__DIR__ . '/../../Models/Forum'], + 'navigation' => [__DIR__ . '/../../Models/Navigation'], + 'routing' => [__DIR__ . '/../../Models/Routing'], + ]; } /** From 99df158fc8369fbca52568901bc19b734c98c4d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Mon, 12 Jun 2017 20:03:11 +0200 Subject: [PATCH 302/877] Allow passing a connection while creating an entity manager Also removing unsed arguments. --- .../Doctrine/Tests/OrmFunctionalTestCase.php | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 5716f2a500d..2a5f4526471 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests; use Doctrine\Common\Cache\ArrayCache; +use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Driver\PDOSqlite\Driver as SqliteDriver; use Doctrine\DBAL\Logging\DebugStack; use Doctrine\DBAL\Types\Type; @@ -674,12 +675,11 @@ protected function setUp() /** * Gets an EntityManager for testing purposes. * - * @param \Doctrine\ORM\Configuration $config The Configuration to pass to the EntityManager. - * @param \Doctrine\Common\EventManager $eventManager The EventManager to pass to the EntityManager. + * @return EntityManager * - * @return \Doctrine\ORM\EntityManager + * @throws \Doctrine\ORM\ORMException */ - protected function _getEntityManager($config = null, $eventManager = null) { + protected function _getEntityManager(Connection $connection = null) { // NOTE: Functional tests use their own shared metadata cache, because // the actual database platform used during execution has effect on some // metadata mapping behaviors (like the choice of the ID generation). @@ -732,13 +732,17 @@ protected function _getEntityManager($config = null, $eventManager = null) { $this->isSecondLevelCacheEnabled = true; } - $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver( - [ - realpath(__DIR__ . '/Models/Cache'), - realpath(__DIR__ . '/Models/GeoNames') - ], true)); + $config->setMetadataDriverImpl( + $config->newDefaultAnnotationDriver( + [ + realpath(__DIR__ . '/Models/Cache'), + realpath(__DIR__ . '/Models/GeoNames') + ], + true + ) + ); - $conn = static::$_sharedConn; + $conn = $connection ?: static::$_sharedConn; $conn->getConfiguration()->setSQLLogger($this->_sqlLoggerStack); // get rid of more global state From 19fc91482ea814f810080c6a00061c7672309b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Mon, 12 Jun 2017 20:10:52 +0200 Subject: [PATCH 303/877] Validate if optimistic locks are released properly By trying to update an entry using a different connection. --- .../ORM/Functional/Ticket/DDC933Test.php | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC933Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC933Test.php index 039eb7ab804..f6216a16237 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC933Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC933Test.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\LockMode; use Doctrine\Tests\Models\Company\CompanyManager; use Doctrine\Tests\OrmFunctionalTestCase; +use Doctrine\Tests\TestUtil; class DDC933Test extends OrmFunctionalTestCase { @@ -20,6 +21,10 @@ public function setUp() */ public function testLockCTIClass() { + if ($this->_em->getConnection()->getDatabasePlatform()->getName() === 'sqlite') { + self::markTestSkipped('It should not run on in-memory databases'); + } + $manager = new CompanyManager(); $manager->setName('beberlei'); $manager->setSalary(1234); @@ -32,5 +37,33 @@ public function testLockCTIClass() $this->_em->beginTransaction(); $this->_em->lock($manager, LockMode::PESSIMISTIC_READ); $this->_em->rollback(); + + // if lock hasn't been released we'd have an exception here + $this->assertManagerCanBeUpdatedOnAnotherConnection($manager->getId(), 'Master of This Test'); + } + + /** + * @param int $id + * @param string $newName + * + * @return void + * + * @throws \Doctrine\Common\Persistence\Mapping\MappingException + * @throws \Doctrine\ORM\ORMException + * @throws \Doctrine\ORM\OptimisticLockException + * @throws \Doctrine\ORM\TransactionRequiredException + */ + private function assertManagerCanBeUpdatedOnAnotherConnection(int $id, string $newName) + { + $em = $this->_getEntityManager(TestUtil::getConnection()); + + /** @var CompanyManager $manager */ + $manager = $em->find(CompanyManager::class, $id); + $manager->setName($newName); + + $em->flush(); + $em->clear(); + + self::assertSame($newName, $em->find(CompanyManager::class, $id)->getName()); } } From 8796e2d938c391c878e5e352bff50c0190daed49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 31 May 2017 08:14:53 +0200 Subject: [PATCH 304/877] Expect an exception instead of failing the test Since that's the assertion we're actually doing. --- .../ORM/Functional/BasicFunctionalTest.php | 34 ++++++++----------- .../ORM/Functional/DetachedEntityTest.php | 11 +++--- .../Hydration/SingleScalarHydratorTest.php | 19 +++++++---- .../Tests/ORM/Id/AssignedGeneratorTest.php | 25 ++++++++------ 4 files changed, 48 insertions(+), 41 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php index 016a7949f2f..7bdb846535c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php @@ -740,11 +740,10 @@ public function testNewAssociatedEntityDuringFlushThrowsException() $address->user = $user; $this->_em->persist($address); - // pretend we forgot to persist $user - try { - $this->_em->flush(); // should raise an exception - $this->fail(); - } catch (\InvalidArgumentException $expected) {} + + // flushing without persisting $user should raise an exception + $this->expectException(\InvalidArgumentException::class); + $this->_em->flush(); } /** @@ -774,11 +773,10 @@ public function testNewAssociatedEntityDuringFlushThrowsException2() $u2->name = "Benjamin E."; $u2->status = 'inactive'; $address->user = $u2; - // pretend we forgot to persist $u2 - try { - $this->_em->flush(); // should raise an exception - $this->fail(); - } catch (\InvalidArgumentException $expected) {} + + // flushing without persisting $u2 should raise an exception + $this->expectException(\InvalidArgumentException::class); + $this->_em->flush(); } /** @@ -797,11 +795,10 @@ public function testNewAssociatedEntityDuringFlushThrowsException3() $art->addComment($com); $this->_em->persist($art); - // pretend we forgot to persist $com - try { - $this->_em->flush(); // should raise an exception - $this->fail(); - } catch (\InvalidArgumentException $expected) {} + + // flushing without persisting $com should raise an exception + $this->expectException(\InvalidArgumentException::class); + $this->_em->flush(); } public function testOneToOneOrphanRemoval() @@ -933,10 +930,9 @@ public function testMergeThrowsExceptionIfEntityWithGeneratedIdentifierDoesNotEx $user->name = "Benjamin E."; $user->status = 'active'; $user->id = 42; - try { - $this->_em->merge($user); - $this->fail(); - } catch (EntityNotFoundException $enfe) {} + + $this->expectException(EntityNotFoundException::class); + $this->_em->merge($user); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php b/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php index 5060f07a151..523c98c0943 100644 --- a/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use Doctrine\ORM\OptimisticLockException; use Doctrine\ORM\Proxy\Proxy; use Doctrine\Tests\Models\CMS\CmsUser; @@ -113,14 +114,16 @@ public function testDetachedEntityThrowsExceptionOnFlush() { $ph = new CmsPhonenumber(); $ph->phonenumber = '12345'; + $this->_em->persist($ph); $this->_em->flush(); $this->_em->clear(); + $this->_em->persist($ph); - try { - $this->_em->flush(); - $this->fail(); - } catch (\Exception $expected) {} + + // since it tries to insert the object twice (with the same PK) + $this->expectException(UniqueConstraintViolationException::class); + $this->_em->flush(); } public function testUninitializedLazyAssociationsAreIgnoredOnMerge() diff --git a/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php index 694259b298f..f9d91be638d 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php @@ -72,17 +72,22 @@ public function testHydrateSingleScalar($name, $resultSet) $stmt = new HydratorMockStatement($resultSet); $hydrator = new SingleScalarHydrator($this->_em); - if ($name == 'result1') { + if ($name === 'result1') { $result = $hydrator->hydrateAll($stmt, $rsm); $this->assertEquals('romanb', $result); - } else if ($name == 'result2') { + return; + } + + if ($name === 'result2') { $result = $hydrator->hydrateAll($stmt, $rsm); $this->assertEquals(1, $result); - } else if ($name == 'result3' || $name == 'result4') { - try { - $result = $hydrator->hydrateAll($stmt, $rsm); - $this->fail(); - } catch (\Doctrine\ORM\NonUniqueResultException $e) {} + + return; + } + + if (in_array($name, ['result3', 'result4'], true)) { + $this->expectException(NonUniqueResultException::class); + $hydrator->hydrateAll($stmt, $rsm); } } } diff --git a/tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php b/tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php index acc951c1666..aa0240ebcd5 100644 --- a/tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php @@ -22,19 +22,22 @@ protected function setUp() $this->_assignedGen = new AssignedGenerator; } - public function testThrowsExceptionIfIdNotAssigned() + /** + * @dataProvider entitiesWithoutId + */ + public function testThrowsExceptionIfIdNotAssigned($entity) { - try { - $entity = new AssignedSingleIdEntity; - $this->_assignedGen->generate($this->_em, $entity); - $this->fail('Assigned generator did not throw exception even though ID was missing.'); - } catch (ORMException $expected) {} + $this->expectException(ORMException::class); - try { - $entity = new AssignedCompositeIdEntity; - $this->_assignedGen->generate($this->_em, $entity); - $this->fail('Assigned generator did not throw exception even though ID was missing.'); - } catch (ORMException $expected) {} + $this->_assignedGen->generate($this->_em, $entity); + } + + public function entitiesWithoutId(): array + { + return [ + 'single' => [new AssignedSingleIdEntity()], + 'composite' => [new AssignedCompositeIdEntity()], + ]; } public function testCorrectIdGeneration() From d8663cd9ee9bb017fa6bf07fb4a65ae821b37190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 31 May 2017 14:05:43 +0200 Subject: [PATCH 305/877] Use a more appropriate assertion on some tests --- .../Functional/ClassTableInheritanceTest.php | 36 ++++++++++--------- .../Tests/ORM/Functional/QueryTest.php | 10 +++--- .../Tests/ORM/Functional/TypeTest.php | 15 ++++---- .../ORM/Hydration/ScalarHydratorTest.php | 4 +-- 4 files changed, 34 insertions(+), 31 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php index c94d3d73d48..4ece24fa773 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php @@ -51,7 +51,7 @@ public function testCRUD() $entities = $query->getResult(); - $this->assertEquals(2, count($entities)); + $this->assertCount(2, $entities); $this->assertInstanceOf(CompanyPerson::class, $entities[0]); $this->assertInstanceOf(CompanyEmployee::class, $entities[1]); $this->assertTrue(is_numeric($entities[0]->getId())); @@ -66,7 +66,7 @@ public function testCRUD() $entities = $query->getResult(); - $this->assertEquals(1, count($entities)); + $this->assertCount(1, $entities); $this->assertInstanceOf(CompanyEmployee::class, $entities[0]); $this->assertTrue(is_numeric($entities[0]->getId())); $this->assertEquals('Guilherme Blanco', $entities[0]->getName()); @@ -164,7 +164,7 @@ public function testSelfReferencingOneToOne() $query = $this->_em->createQuery('select p, s from ' . CompanyPerson::class . ' p join p.spouse s where p.name=\'Mary Smith\''); $result = $query->getResult(); - $this->assertEquals(1, count($result)); + $this->assertCount(1, $result); $this->assertInstanceOf(CompanyPerson::class, $result[0]); $this->assertEquals('Mary Smith', $result[0]->getName()); $this->assertInstanceOf(CompanyEmployee::class, $result[0]->getSpouse()); @@ -182,8 +182,8 @@ public function testSelfReferencingManyToMany() $person1->addFriend($person2); - $this->assertEquals(1, count($person1->getFriends())); - $this->assertEquals(1, count($person2->getFriends())); + $this->assertCount(1, $person1->getFriends()); + $this->assertCount(1, $person2->getFriends()); $this->_em->persist($person1); @@ -197,8 +197,8 @@ public function testSelfReferencingManyToMany() $query->setParameter(1, 'Roman'); $result = $query->getResult(); - $this->assertEquals(1, count($result)); - $this->assertEquals(1, count($result[0]->getFriends())); + $this->assertCount(1, $result); + $this->assertCount(1, $result[0]->getFriends()); $this->assertEquals('Roman', $result[0]->getName()); $friends = $result[0]->getFriends(); @@ -226,7 +226,7 @@ public function testLazyLoading1() $result = $q->getResult(); - $this->assertEquals(1, count($result)); + $this->assertCount(1, $result); $this->assertInstanceOf(CompanyOrganization::class, $result[0]); $this->assertNull($result[0]->getMainEvent()); @@ -235,7 +235,7 @@ public function testLazyLoading1() $this->assertInstanceOf(PersistentCollection::class, $events); $this->assertFalse($events->isInitialized()); - $this->assertEquals(2, count($events)); + $this->assertCount(2, $events); if ($events[0] instanceof CompanyAuction) { $this->assertInstanceOf(CompanyRaffle::class, $events[1]); } else { @@ -259,7 +259,7 @@ public function testLazyLoading2() $q->setParameter(1, $event1->getId()); $result = $q->getResult(); - $this->assertEquals(1, count($result)); + $this->assertCount(1, $result); $this->assertInstanceOf(CompanyAuction::class, $result[0], sprintf("Is of class %s", get_class($result[0]))); $this->_em->clear(); @@ -269,7 +269,7 @@ public function testLazyLoading2() $result = $q->getResult(); - $this->assertEquals(1, count($result)); + $this->assertCount(1, $result); $this->assertInstanceOf(CompanyOrganization::class, $result[0]); $mainEvent = $result[0]->getMainEvent(); @@ -286,9 +286,10 @@ public function testBulkUpdateIssueDDC368() $this->_em->createQuery('UPDATE ' . CompanyEmployee::class . ' AS p SET p.salary = 1') ->execute(); - $this->assertTrue(count($this->_em->createQuery( - 'SELECT count(p.id) FROM Doctrine\Tests\Models\Company\CompanyEmployee p WHERE p.salary = 1') - ->getResult()) > 0); + $result = $this->_em->createQuery('SELECT count(p.id) FROM ' . CompanyEmployee::class . ' p WHERE p.salary = 1') + ->getResult(); + + $this->assertGreaterThan(0, count($result)); } /** @@ -441,7 +442,8 @@ public function testGetSubClassManyToManyCollection() $this->_em->clear(); $manager = $this->_em->find(CompanyManager::class, $manager->getId()); - $this->assertEquals(1, count($manager->getFriends())); + + $this->assertCount(1, $manager->getFriends()); } /** @@ -481,12 +483,12 @@ public function testMatching() $users = $repository->matching(new Criteria( Criteria::expr()->eq('department', 'IT') )); - $this->assertEquals(1, count($users)); + $this->assertCount(1, $users); $repository = $this->_em->getRepository(CompanyManager::class); $users = $repository->matching(new Criteria( Criteria::expr()->eq('department', 'IT') )); - $this->assertEquals(1, count($users)); + $this->assertCount(1, $users); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php index 127f06d18f7..af4656960db 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php @@ -208,7 +208,7 @@ public function testIterateResultAsArrayAndParams() } $this->assertEquals(1, count($found)); - $this->assertEquals( + $this->assertSame( [ [ [ @@ -256,8 +256,8 @@ public function testIterateResult_IterativelyBuildUpUnitOfWork() $iteratedCount++; } - $this->assertEquals(["Doctrine 2", "Symfony 2"], $topics); - $this->assertEquals(2, $iteratedCount); + $this->assertSame(["Doctrine 2", "Symfony 2"], $topics); + $this->assertSame(2, $iteratedCount); $this->_em->flush(); $this->_em->clear(); @@ -293,8 +293,8 @@ public function testIterateResultClearEveryCycle() $iteratedCount++; } - $this->assertEquals(["Doctrine 2", "Symfony 2"], $topics); - $this->assertEquals(2, $iteratedCount); + $this->assertSame(["Doctrine 2", "Symfony 2"], $topics); + $this->assertSame(2, $iteratedCount); $this->_em->flush(); } diff --git a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php index 9276d74ee8f..0f5c7e223eb 100644 --- a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php @@ -32,8 +32,8 @@ public function testDecimal() $dql = 'SELECT d FROM ' . DecimalModel::class . ' d'; $decimal = $this->_em->createQuery($dql)->getSingleResult(); - $this->assertEquals(0.15, $decimal->decimal); - $this->assertEquals(0.1515, $decimal->highScale); + $this->assertSame('0.15', $decimal->decimal); + $this->assertSame('0.1515', $decimal->highScale); } /** @@ -78,7 +78,7 @@ public function testArray() $dql = 'SELECT s FROM ' . SerializationModel::class . ' s'; $serialize = $this->_em->createQuery($dql)->getSingleResult(); - $this->assertEquals(["foo" => "bar", "bar" => "baz"], $serialize->array); + $this->assertSame(["foo" => "bar", "bar" => "baz"], $serialize->array); } public function testObject() @@ -108,7 +108,7 @@ public function testDate() $dateTimeDb = $this->_em->find(DateTimeModel::class, $dateTime->id); $this->assertInstanceOf(\DateTime::class, $dateTimeDb->date); - $this->assertEquals('2009-10-01', $dateTimeDb->date->format('Y-m-d')); + $this->assertSame('2009-10-01', $dateTimeDb->date->format('Y-m-d')); } public function testDateTime() @@ -123,11 +123,12 @@ public function testDateTime() $dateTimeDb = $this->_em->find(DateTimeModel::class, $dateTime->id); $this->assertInstanceOf(\DateTime::class, $dateTimeDb->datetime); - $this->assertEquals('2009-10-02 20:10:52', $dateTimeDb->datetime->format('Y-m-d H:i:s')); + $this->assertSame('2009-10-02 20:10:52', $dateTimeDb->datetime->format('Y-m-d H:i:s')); $articles = $this->_em->getRepository(DateTimeModel::class) ->findBy(['datetime' => new \DateTime()]); - $this->assertEquals(0, count($articles)); + + $this->assertEmpty($articles); } public function testDqlQueryBindDateTimeInstance() @@ -177,6 +178,6 @@ public function testTime() $dateTimeDb = $this->_em->find(DateTimeModel::class, $dateTime->id); $this->assertInstanceOf(\DateTime::class, $dateTimeDb->time); - $this->assertEquals('19:27:20', $dateTimeDb->time->format('H:i:s')); + $this->assertSame('19:27:20', $dateTimeDb->time->format('H:i:s')); } } diff --git a/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php index 2c51929bc78..85a197cbae9 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php @@ -37,8 +37,8 @@ public function testNewHydrationSimpleEntityQuery() $result = $hydrator->hydrateAll($stmt, $rsm); - $this->assertTrue(is_array($result)); - $this->assertEquals(2, count($result)); + $this->assertInternalType('array', $result); + $this->assertCount(2, $result); $this->assertEquals('romanb', $result[0]['u_name']); $this->assertEquals(1, $result[0]['u_id']); $this->assertEquals('jwage', $result[1]['u_name']); From 8dccd27b5232a4830a3e55f616da2f3a43b0c98c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 31 May 2017 16:36:31 +0200 Subject: [PATCH 306/877] Add the correct assertions for tests that don't have any --- .../ORM/Functional/CascadeRemoveOrderTest.php | 6 ++++ .../Tests/ORM/Functional/NativeQueryTest.php | 2 ++ .../Tests/ORM/Functional/QueryTest.php | 18 +++++++++- .../ORM/Functional/SequenceGeneratorTest.php | 7 ++-- .../ORM/Functional/Ticket/DDC1113Test.php | 5 ++- .../ORM/Functional/Ticket/DDC117Test.php | 2 ++ .../ORM/Functional/Ticket/DDC1181Test.php | 2 ++ .../ORM/Functional/Ticket/DDC1209Test.php | 33 +++++++++++++++---- .../ORM/Functional/Ticket/DDC1306Test.php | 3 ++ .../ORM/Functional/Ticket/DDC1400Test.php | 4 +++ .../ORM/Functional/Ticket/DDC144Test.php | 1 + .../ORM/Functional/Ticket/DDC1454Test.php | 6 ++-- .../ORM/Functional/Ticket/DDC1925Test.php | 6 ++++ .../ORM/Functional/Ticket/DDC192Test.php | 22 +++++++++---- .../ORM/Functional/Ticket/DDC2106Test.php | 3 +- .../ORM/Functional/Ticket/DDC2256Test.php | 4 +-- .../ORM/Functional/Ticket/DDC2775Test.php | 2 ++ .../ORM/Functional/Ticket/DDC3170Test.php | 10 ++++-- .../ORM/Functional/Ticket/DDC3785Test.php | 7 +++- .../ORM/Functional/Ticket/DDC522Test.php | 6 +++- .../ORM/Functional/Ticket/DDC832Test.php | 24 ++++++++++++++ .../Tests/ORM/Functional/TypeTest.php | 6 ++++ .../ORM/Hydration/ScalarHydratorTest.php | 4 +-- .../ORM/Mapping/AnnotationDriverTest.php | 3 +- .../ORM/Mapping/PHPMappingDriverTest.php | 2 +- .../Mapping/StaticPHPMappingDriverTest.php | 3 +- tests/Doctrine/Tests/ORM/Query/QueryTest.php | 4 ++- .../Tests/ORM/Tools/SchemaValidatorTest.php | 2 +- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 4 +++ 29 files changed, 167 insertions(+), 34 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/CascadeRemoveOrderTest.php b/tests/Doctrine/Tests/ORM/Functional/CascadeRemoveOrderTest.php index a6de137d139..8908e51e009 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CascadeRemoveOrderTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CascadeRemoveOrderTest.php @@ -47,6 +47,8 @@ public function testSingle() $this->_em->remove($eOloaded); $this->_em->flush(); + + self::assertNull($this->_em->find(CascadeRemoveOrderEntityG::class, $eG->getId())); } public function testMany() @@ -66,6 +68,10 @@ public function testMany() $this->_em->remove($eOloaded); $this->_em->flush(); + + self::assertNull($this->_em->find(CascadeRemoveOrderEntityG::class, $eG1->getId())); + self::assertNull($this->_em->find(CascadeRemoveOrderEntityG::class, $eG2->getId())); + self::assertNull($this->_em->find(CascadeRemoveOrderEntityG::class, $eG3->getId())); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php b/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php index 4e8e6c96ef5..31c19a1cd4c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php @@ -325,6 +325,8 @@ public function testConcreteClassInSingleTableInheritanceSchemaWithRSMBuilderIsF { $rsm = new ResultSetMappingBuilder($this->_em); $rsm->addRootEntityFromClassMetadata(CompanyFixContract::class, 'c'); + + self::assertSame(CompanyFixContract::class, $rsm->getClassName('c')); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php index af4656960db..f25cd33faaa 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php @@ -169,13 +169,29 @@ public function testSetParameters() $this->_em->createQuery('SELECT u FROM ' . CmsUser::class . ' u WHERE u.name = ?1 AND u.status = ?2') ->setParameters($parameters) ->getResult(); + + $extractValue = function (Parameter $parameter) { + return $parameter->getValue(); + }; + + self::assertSame( + $parameters->map($extractValue)->toArray(), + $this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['params'] + ); } public function testSetParametersBackwardsCompatible() { + $parameters = [1 => 'jwage', 2 => 'active']; + $this->_em->createQuery('SELECT u FROM ' . CmsUser::class . ' u WHERE u.name = ?1 AND u.status = ?2') - ->setParameters([1 => 'jwage', 2 => 'active']) + ->setParameters($parameters) ->getResult(); + + self::assertSame( + array_values($parameters), + $this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['params'] + ); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/SequenceGeneratorTest.php b/tests/Doctrine/Tests/ORM/Functional/SequenceGeneratorTest.php index c00f8bc9fe4..290984f3584 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SequenceGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SequenceGeneratorTest.php @@ -30,12 +30,13 @@ public function setUp() public function testHighAllocationSizeSequence() { - for ($i = 0; $i < 11; $i++) { - $e = new SequenceEntity(); - $this->_em->persist($e); + for ($i = 0; $i < 11; ++$i) { + $this->_em->persist(new SequenceEntity()); } $this->_em->flush(); + + self::assertCount(11, $this->_em->getRepository(SequenceEntity::class)->findAll()); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1113Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1113Test.php index 7402972b01f..324e8481219 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1113Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1113Test.php @@ -42,8 +42,11 @@ public function testIssue() $this->_em->remove($bus); $this->_em->remove($car); $this->_em->flush(); - } + self::assertEmpty($this->_em->getRepository(DDC1113Car::class)->findAll()); + self::assertEmpty($this->_em->getRepository(DDC1113Bus::class)->findAll()); + self::assertEmpty($this->_em->getRepository(DDC1113Engine::class)->findAll()); + } } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php index c6d215cf89e..8478a5f66d6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php @@ -275,6 +275,8 @@ public function testOneToOneCascadePersist() $this->_em->persist($this->article1); $this->_em->flush(); + + self::assertSame($this->articleDetails, $this->_em->find(DDC117ArticleDetails::class, $this->article1)); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php index 1c4343e409c..564e046e7d3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php @@ -47,6 +47,8 @@ public function testIssue() $this->_em->remove($hotel); $this->_em->flush(); + + self::assertEmpty($this->_em->getRepository(DDC1181Booking::class)->findAll()); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php index ce53b7505de..6c54da296be 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php @@ -26,8 +26,12 @@ protected function setUp() */ public function testIdentifierCanHaveCustomType() { - $this->_em->persist(new DDC1209_3()); + $entity = new DDC1209_3(); + + $this->_em->persist($entity); $this->_em->flush(); + + self::assertSame($entity, $this->_em->find(DDC1209_3::class, $entity->date)); } /** @@ -36,14 +40,27 @@ public function testIdentifierCanHaveCustomType() public function testCompositeIdentifierCanHaveCustomType() { $future1 = new DDC1209_1(); - $this->_em->persist($future1); + $this->_em->persist($future1); $this->_em->flush(); $future2 = new DDC1209_2($future1); - $this->_em->persist($future2); + $this->_em->persist($future2); $this->_em->flush(); + + self::assertSame( + $future2, + $this->_em->find( + DDC1209_2::class, + [ + 'future1' => $future1, + 'starting_datetime' => $future2->starting_datetime, + 'during_datetime' => $future2->during_datetime, + 'ending_datetime' => $future2->ending_datetime, + ] + ) + ); } } @@ -78,17 +95,19 @@ class DDC1209_2 * @Id * @Column(type="datetime", nullable=false) */ - private $starting_datetime; + public $starting_datetime; + /** * @Id * @Column(type="datetime", nullable=false) */ - private $during_datetime; + public $during_datetime; + /** * @Id * @Column(type="datetime", nullable=false) */ - private $ending_datetime; + public $ending_datetime; public function __construct(DDC1209_1 $future1) { @@ -108,7 +127,7 @@ class DDC1209_3 * @Id * @Column(type="datetime", name="somedate") */ - private $date; + public $date; public function __construct() { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1306Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1306Test.php index 956c5f7d57d..03c761a959c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1306Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1306Test.php @@ -48,5 +48,8 @@ public function testIssue() $this->_em->remove($user->getAddress()); $this->_em->remove($user); $this->_em->flush(); + + self::assertEmpty($this->_em->getRepository(CmsAddress::class)->findAll()); + self::assertEmpty($this->_em->getRepository(CmsUser::class)->findAll()); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php index a569c1a82f6..1248fe8412d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php @@ -57,7 +57,11 @@ public function testFailingCase() ->setParameter('activeUser', $user1) ->getResult(); + $queryCount = $this->getCurrentQueryCount(); + $this->_em->flush(); + + self::assertSame($queryCount, $this->getCurrentQueryCount(), 'No query should be executed during flush in this case'); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php index 064b7802114..3866c588db0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php @@ -30,6 +30,7 @@ public function testIssue() $this->_em->persist($operand); $this->_em->flush(); + self::assertSame($operand, $this->_em->find(DDC144Operand::class, $operand->id)); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1454Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1454Test.php index 0f550931018..86aba511372 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1454Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1454Test.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\ORM\UnitOfWork; + /** * @group DDC-1454 */ @@ -25,9 +27,9 @@ protected function setUp() public function testFailingCase() { $pic = new DDC1454Picture(); - $this->_em->getUnitOfWork()->getEntityState($pic); - } + self::assertSame(UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($pic)); + } } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1925Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1925Test.php index 8c56951beba..ef7d6014bf6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1925Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1925Test.php @@ -36,6 +36,12 @@ public function testIssue() $this->_em->persist($product); $this->_em->flush(); + $this->_em->clear(); + + /** @var DDC1925Product $persistedProduct */ + $persistedProduct = $this->_em->find(DDC1925Product::class, $product->getId()); + + self::assertEquals($user, $persistedProduct->getBuyers()->first()); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC192Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC192Test.php index e9006236379..532e0edfeb4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC192Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC192Test.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -11,12 +12,21 @@ class DDC192Test extends OrmFunctionalTestCase { public function testSchemaCreation() { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(DDC192User::class), - $this->_em->getClassMetadata(DDC192Phonenumber::class) - ] - ); + $classes = [ + $this->_em->getClassMetadata(DDC192User::class), + $this->_em->getClassMetadata(DDC192Phonenumber::class), + ]; + + $this->_schemaTool->createSchema($classes); + + $tables = $this->_em->getConnection() + ->getSchemaManager() + ->listTableNames(); + + /** @var ClassMetadata $class */ + foreach ($classes as $class) { + self::assertContains($class->getTableName(), $tables); + } } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php index c56f3fb4826..4856852ecaa 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php @@ -34,7 +34,8 @@ public function testDetachedEntityAsId() $this->_em->persist($entityWithoutId); $criteria = Criteria::create()->where(Criteria::expr()->eq('parent', $entityWithoutId)); - $entity->children->matching($criteria)->count(); + + self::assertCount(0, $entity->children->matching($criteria)); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2256Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2256Test.php index 9e6f0bccaaf..02281a5e3a0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2256Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2256Test.php @@ -51,14 +51,14 @@ public function testIssue() $rsm->addFieldResult('g', 'group_id', 'id'); $rsm->addFieldResult('g', 'group_name', 'name'); - $this->_em->createNativeQuery($sql, $rsm)->getResult(); + self::assertCount(1, $this->_em->createNativeQuery($sql, $rsm)->getResult()); // Test ResultSetMappingBuilder. $rsm = new ResultSetMappingBuilder($this->_em); $rsm->addRootEntityFromClassMetadata('MyNamespace:DDC2256User', 'u'); $rsm->addJoinedEntityFromClassMetadata('MyNamespace:DDC2256Group', 'g', 'u', 'group', ['id' => 'group_id', 'name' => 'group_name']); - $this->_em->createNativeQuery($sql, $rsm)->getResult(); + self::assertCount(1, $this->_em->createNativeQuery($sql, $rsm)->getResult()); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2775Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2775Test.php index 3f77033858d..b84024f048d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2775Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2775Test.php @@ -49,6 +49,8 @@ public function testIssueCascadeRemove() $this->_em->remove($user); $this->_em->flush(); + self::assertEmpty($this->_em->getRepository(Authorization::class)->findAll()); + // With the bug, the second flush throws an error because the cascade remove didn't work correctly $this->_em->flush(); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php index 0ef1caee8e1..45a49b7a6d0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php @@ -46,17 +46,23 @@ public function testIssue() $this->_em->flush(); $this->_em->clear(); - $this->_em->createQueryBuilder() + $result = $this->_em->createQueryBuilder() ->select('p') ->from(DDC3170ProductJoined::class, 'p') ->getQuery() ->getResult(AbstractQuery::HYDRATE_SIMPLEOBJECT); - $this->_em->createQueryBuilder() + self::assertCount(1, $result); + self::assertContainsOnly(DDC3170ProductJoined::class, $result); + + $result = $this->_em->createQueryBuilder() ->select('p') ->from(DDC3170ProductSingleTable::class, 'p') ->getQuery() ->getResult(AbstractQuery::HYDRATE_SIMPLEOBJECT); + + self::assertCount(1, $result); + self::assertContainsOnly(DDC3170ProductSingleTable::class, $result); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3785Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3785Test.php index 4fcc3932c29..984cda551ba 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3785Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3785Test.php @@ -44,8 +44,13 @@ public function testOwningValueObjectIdIsCorrectlyTransformedWhenRemovingOrphane $asset->getAttributes() ->removeElement($attribute1); + $idToBeRemoved = $attribute1->id; + $this->_em->persist($asset); $this->_em->flush(); + + self::assertNull($this->_em->find(DDC3785_Attribute::class, $idToBeRemoved)); + self::assertNotNull($this->_em->find(DDC3785_Attribute::class, $attribute2->id)); } } @@ -100,7 +105,7 @@ class DDC3785_Attribute * @Id @Column(type="integer") * @GeneratedValue */ - private $id; + public $id; /** @Column(type = "string") */ private $name; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php index 3909b9ca03d..dc6fa208179 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php @@ -78,7 +78,11 @@ public function testJoinColumnWithNullSameNameAssociationField() $this->_em->flush(); $this->_em->clear(); - $newCust = $this->_em->find(get_class($fkCust), $fkCust->id); + $expected = clone $fkCust; + // removing dynamic field (which is not persisted) + unset($expected->name); + + self::assertEquals($expected, $this->_em->find(DDC522ForeignKeyTest::class, $fkCust->id)); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php index ee46b5bc765..fdae13585fc 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php @@ -50,6 +50,9 @@ public function testQuotedTableBasicUpdate() $like->word = 'test2'; $this->_em->flush(); + $this->_em->clear(); + + self::assertEquals($like, $this->_em->find(DDC832Like::class, $like->id)); } /** @@ -61,8 +64,13 @@ public function testQuotedTableBasicRemove() $this->_em->persist($like); $this->_em->flush(); + $idToBeRemoved = $like->id; + $this->_em->remove($like); $this->_em->flush(); + $this->_em->clear(); + + self::assertNull($this->_em->find(DDC832Like::class, $idToBeRemoved)); } /** @@ -76,6 +84,9 @@ public function testQuotedTableJoinedUpdate() $index->name = 'asdf'; $this->_em->flush(); + $this->_em->clear(); + + self::assertEquals($index, $this->_em->find(DDC832JoinedIndex::class, $index->id)); } /** @@ -87,8 +98,13 @@ public function testQuotedTableJoinedRemove() $this->_em->persist($index); $this->_em->flush(); + $idToBeRemoved = $index->id; + $this->_em->remove($index); $this->_em->flush(); + $this->_em->clear(); + + self::assertNull($this->_em->find(DDC832JoinedIndex::class, $idToBeRemoved)); } /** @@ -102,6 +118,9 @@ public function testQuotedTableJoinedChildUpdate() $index->name = 'asdf'; $this->_em->flush(); + $this->_em->clear(); + + self::assertEquals($index, $this->_em->find(DDC832JoinedTreeIndex::class, $index->id)); } /** @@ -113,8 +132,13 @@ public function testQuotedTableJoinedChildRemove() $this->_em->persist($index); $this->_em->flush(); + $idToBeRemoved = $index->id; + $this->_em->remove($index); $this->_em->flush(); + $this->_em->clear(); + + self::assertNull($this->_em->find(DDC832JoinedTreeIndex::class, $idToBeRemoved)); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php index 0f5c7e223eb..9dd99777a04 100644 --- a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php @@ -145,6 +145,9 @@ public function testDqlQueryBindDateTimeInstance() $dateTimeDb = $this->_em->createQuery('SELECT d FROM Doctrine\Tests\Models\Generic\DateTimeModel d WHERE d.datetime = ?1') ->setParameter(1, $date, DBALType::DATETIME) ->getSingleResult(); + + $this->assertInstanceOf(\DateTime::class, $dateTimeDb->datetime); + $this->assertSame('2009-10-02 20:10:52', $dateTimeDb->datetime->format('Y-m-d H:i:s')); } public function testDqlQueryBuilderBindDateTimeInstance() @@ -164,6 +167,9 @@ public function testDqlQueryBuilderBindDateTimeInstance() ->where('d.datetime = ?1') ->setParameter(1, $date, DBALType::DATETIME) ->getQuery()->getSingleResult(); + + $this->assertInstanceOf(\DateTime::class, $dateTimeDb->datetime); + $this->assertSame('2009-10-02 20:10:52', $dateTimeDb->datetime->format('Y-m-d H:i:s')); } public function testTime() diff --git a/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php index 85a197cbae9..919486cc8ec 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php @@ -66,7 +66,7 @@ public function testHydrateScalarResults() $stmt = new HydratorMockStatement($resultSet); $hydrator = new ScalarHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm); + self::assertCount(1, $hydrator->hydrateAll($stmt, $rsm)); } /** @@ -96,6 +96,6 @@ public function testSkipUnknownColumns() $stmt = new HydratorMockStatement($resultSet); $hydrator = new ScalarHydrator($this->_em); - $result = $hydrator->hydrateAll($stmt, $rsm); + self::assertCount(1, $hydrator->hydrateAll($stmt, $rsm)); } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php index 89951f9715d..b30ed703bc4 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php @@ -221,10 +221,11 @@ public function testMappedSuperclassInMiddleOfInheritanceHierarchy() $em = $this->_getTestEntityManager(); $em->getConfiguration()->setMetadataDriverImpl($annotationDriver); + $factory = new ClassMetadataFactory(); $factory->setEntityManager($em); - $cm = $factory->getMetadataFor(ChildEntity::class); + self::assertInstanceOf(ClassMetadata::class, $factory->getMetadataFor(ChildEntity::class)); } public function testInvalidFetchOptionThrowsException() diff --git a/tests/Doctrine/Tests/ORM/Mapping/PHPMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/PHPMappingDriverTest.php index 39b5525b295..04493dbc424 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/PHPMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/PHPMappingDriverTest.php @@ -32,7 +32,7 @@ protected function _loadDriver() */ public function testinvalidEntityOrMappedSuperClassShouldMentionParentClasses() { - $this->createClassMetadata(DDC889Class::class); + self::assertInstanceOf(ClassMetadata::class, $this->createClassMetadata(DDC889Class::class)); } /** diff --git a/tests/Doctrine/Tests/ORM/Mapping/StaticPHPMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/StaticPHPMappingDriverTest.php index 5f2f0c1d7bd..3bc5a5d5d2e 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/StaticPHPMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/StaticPHPMappingDriverTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM\Mapping; use Doctrine\Common\Persistence\Mapping\Driver\StaticPHPDriver; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\Tests\Models\DDC889\DDC889Class; class StaticPHPMappingDriverTest extends AbstractMappingDriverTest @@ -19,7 +20,7 @@ protected function _loadDriver() */ public function testinvalidEntityOrMappedSuperClassShouldMentionParentClasses() { - $this->createClassMetadata(DDC889Class::class); + self::assertInstanceOf(ClassMetadata::class, $this->createClassMetadata(DDC889Class::class)); } /** diff --git a/tests/Doctrine/Tests/ORM/Query/QueryTest.php b/tests/Doctrine/Tests/ORM/Query/QueryTest.php index 6b0091e9caa..c5a5da41121 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryTest.php @@ -6,6 +6,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\EntityManager; +use Doctrine\ORM\Internal\Hydration\IterableResult; use Doctrine\ORM\Query\Parameter; use Doctrine\Tests\Mocks\DriverConnectionMock; use Doctrine\Tests\Mocks\StatementArrayMock; @@ -147,7 +148,8 @@ public function testIterateWithNoDistinctAndWithValidSelectClause() public function testIterateWithDistinct() { $q = $this->_em->createQuery("SELECT DISTINCT u from Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a"); - $q->iterate(); + + self::assertInstanceOf(IterableResult::class, $q->iterate()); } /** diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php index 955a5f43dc4..682ee896d1a 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php @@ -33,7 +33,7 @@ public function testCmsModelSet(string $path) ->getMetadataDriverImpl() ->addPaths([$path]); - $this->validator->validateMapping(); + self::assertEmpty($this->validator->validateMapping()); } public function modelSetProvider(): array diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 90c621d605a..ff025df4f4b 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -248,8 +248,12 @@ public function testNoUndefinedIndexNoticeOnScheduleForUpdateWithoutChanges() // Schedule user for update without changes $this->_unitOfWork->scheduleForUpdate($user); + self::assertNotEmpty($this->_unitOfWork->getScheduledEntityUpdates()); + // This commit should not raise an E_NOTICE $this->_unitOfWork->commit(); + + self::assertEmpty($this->_unitOfWork->getScheduledEntityUpdates()); } /** From ee5f222c5870c166deadb27af914f4dc237b69d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 31 May 2017 08:22:19 +0200 Subject: [PATCH 307/877] Rename data provider so that it doesn't get executed as test --- .../Tests/ORM/Internal/HydrationCompleteHandlerTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Internal/HydrationCompleteHandlerTest.php b/tests/Doctrine/Tests/ORM/Internal/HydrationCompleteHandlerTest.php index 27b23f5128f..e4e9bcdf7df 100644 --- a/tests/Doctrine/Tests/ORM/Internal/HydrationCompleteHandlerTest.php +++ b/tests/Doctrine/Tests/ORM/Internal/HydrationCompleteHandlerTest.php @@ -61,7 +61,7 @@ protected function setUp() } /** - * @dataProvider testGetValidListenerInvocationFlags + * @dataProvider invocationFlagProvider * * @param int $listenersFlag */ @@ -99,7 +99,7 @@ public function testDefersPostLoadOfEntity($listenersFlag) } /** - * @dataProvider testGetValidListenerInvocationFlags + * @dataProvider invocationFlagProvider * * @param int $listenersFlag */ @@ -125,7 +125,7 @@ public function testDefersPostLoadOfEntityOnlyOnce($listenersFlag) } /** - * @dataProvider testGetValidListenerInvocationFlags + * @dataProvider invocationFlagProvider * * @param int $listenersFlag */ @@ -187,7 +187,7 @@ public function testSkipsDeferredPostLoadOfMetadataWithNoInvokedListeners() $this->handler->hydrationComplete(); } - public function testGetValidListenerInvocationFlags() + public function invocationFlagProvider() { return [ [ListenersInvoker::INVOKE_LISTENERS], From a9c711ad7ea25f9eec286d0054d78299b9e82e8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 31 May 2017 08:22:55 +0200 Subject: [PATCH 308/877] Register custom types to not skip model set validation Also removing an empty and unused model set. --- .../ORM/Functional/SchemaValidatorTest.php | 49 +++++++++++++++---- .../Doctrine/Tests/OrmFunctionalTestCase.php | 1 - 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php index d6f98af1fa4..5ab0f07c07e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php @@ -3,7 +3,11 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\ORM\Tools\SchemaValidator; +use Doctrine\Tests\DbalTypes\CustomIdObjectType; +use Doctrine\Tests\DbalTypes\NegativeToPositiveType; +use Doctrine\Tests\DbalTypes\UpperCaseStringType; use Doctrine\Tests\OrmFunctionalTestCase; +use Doctrine\DBAL\Types\Type as DBALType; /** * Test the validity of all modelsets @@ -12,26 +16,53 @@ */ class SchemaValidatorTest extends OrmFunctionalTestCase { - static public function dataValidateModelSets() + protected function setUp() + { + $this->registerType(CustomIdObjectType::class); + $this->registerType(UpperCaseStringType::class); + $this->registerType(NegativeToPositiveType::class); + + parent::setUp(); + } + + /** + * @param string $className + * + * @throws \Doctrine\DBAL\DBALException + * + * @return void + */ + private function registerType(string $className) + { + $type = constant($className . '::NAME'); + + if (DBALType::hasType($type)) { + DBALType::overrideType($type, $className); + return; + } + + DBALType::addType($type, $className); + } + + public static function dataValidateModelSets(): array { $modelSets = []; - foreach (self::$_modelSets as $modelSet => $classes) { - if ($modelSet == "customtype") { - continue; - } - $modelSets[] = [$modelSet]; + + foreach (array_keys(self::$_modelSets) as $modelSet) { + $modelSets[$modelSet] = [$modelSet]; } + return $modelSets; } /** * @dataProvider dataValidateModelSets */ - public function testValidateModelSets($modelSet) + public function testValidateModelSets(string $modelSet) { $validator = new SchemaValidator($this->_em); + $classes = []; - $classes = []; foreach (self::$_modelSets[$modelSet] as $className) { $classes[] = $this->_em->getClassMetadata($className); } @@ -39,7 +70,7 @@ public function testValidateModelSets($modelSet) foreach ($classes as $class) { $ce = $validator->validateClass($class); - $this->assertEquals(0, count($ce), "Invalid Modelset: " . $modelSet . " class " . $class->name . ": ". implode("\n", $ce)); + $this->assertEmpty($ce, "Invalid Modelset: " . $modelSet . " class " . $class->name . ": ". implode("\n", $ce)); } } } diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 2a5f4526471..e9299b1c685 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -106,7 +106,6 @@ abstract class OrmFunctionalTestCase extends OrmTestCase Models\CMS\CmsArticle::class, Models\CMS\CmsComment::class, ], - 'forum' => [], 'company' => [ Models\Company\CompanyPerson::class, Models\Company\CompanyEmployee::class, From 5c02e0c1e84ce3c669cfc46043602536d93c49b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 31 May 2017 10:58:37 +0200 Subject: [PATCH 309/877] Remove APC dependency on tests By using a shared array cache so that we can reproduce different cache instances that shares the stored data. --- .../Tests/ORM/Cache/DefaultRegionTest.php | 68 +++++++++++++++++-- 1 file changed, 61 insertions(+), 7 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultRegionTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultRegionTest.php index 5faed3c9e2c..97365dfcf28 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultRegionTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultRegionTest.php @@ -2,9 +2,9 @@ namespace Doctrine\Tests\ORM\Cache; -use Doctrine\Common\Cache\ApcCache; use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\Cache\Cache; +use Doctrine\Common\Cache\CacheProvider; use Doctrine\ORM\Cache\CollectionCacheEntry; use Doctrine\ORM\Cache\Region\DefaultRegion; use Doctrine\Tests\Mocks\CacheEntryMock; @@ -28,14 +28,11 @@ public function testGetters() public function testSharedRegion() { - if ( ! extension_loaded('apc') || false === @apc_cache_info()) { - $this->markTestSkipped('The ' . __CLASS__ .' requires the use of APC'); - } - + $cache = new SharedArrayCache(); $key = new CacheKeyMock('key'); $entry = new CacheEntryMock(['value' => 'foo']); - $region1 = new DefaultRegion('region1', new ApcCache()); - $region2 = new DefaultRegion('region2', new ApcCache()); + $region1 = new DefaultRegion('region1', $cache->createChild()); + $region2 = new DefaultRegion('region2', $cache->createChild()); $this->assertFalse($region1->contains($key)); $this->assertFalse($region2->contains($key)); @@ -99,3 +96,60 @@ public function testGetMulti() $this->assertEquals($value2, $actual[1]); } } + +/** + * Cache provider that offers child cache items (sharing the same array) + * + * Declared as a different class for readability purposes and kept in this file + * to keep its monstrosity contained. + * + * @internal + */ +final class SharedArrayCache extends ArrayCache +{ + public function createChild(): Cache + { + return new class ($this) extends CacheProvider + { + /** + * @var ArrayCache + */ + private $parent; + + public function __construct(ArrayCache $parent) + { + $this->parent = $parent; + } + + protected function doFetch($id) + { + return $this->parent->doFetch($id); + } + + protected function doContains($id) + { + return $this->parent->doContains($id); + } + + protected function doSave($id, $data, $lifeTime = 0) + { + return $this->parent->doSave($id, $data, $lifeTime); + } + + protected function doDelete($id) + { + return $this->parent->doDelete($id); + } + + protected function doFlush() + { + return $this->parent->doFlush(); + } + + protected function doGetStats() + { + return $this->parent->doGetStats(); + } + }; + } +} From 5a2a77117384be8a9dfe1c6259fa8205496c5227 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Thu, 15 Jun 2017 01:02:45 +0200 Subject: [PATCH 310/877] Clarify the impact of changing the fetch mode Seems to work for one-to-many as well, but with a negative performance impact. --- docs/en/reference/dql-doctrine-query-language.rst | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/en/reference/dql-doctrine-query-language.rst b/docs/en/reference/dql-doctrine-query-language.rst index 8950c8d4c1a..ee2e2fa153b 100644 --- a/docs/en/reference/dql-doctrine-query-language.rst +++ b/docs/en/reference/dql-doctrine-query-language.rst @@ -935,7 +935,8 @@ the Query class. Here they are: - ``Query#getResult()``: Retrieves a collection of objects. The result is either a plain collection of objects (pure) or an array - where the objects are nested in the result rows (mixed). + where the objects are nested in the result rows ( + ). - ``Query#getSingleResult()``: Retrieves a single object. If the result contains more than one object, an ``NonUniqueResultException`` is thrown. If the result contains no objects, an ``NoResultException`` @@ -1380,7 +1381,13 @@ Given that there are 10 users and corresponding addresses in the database the ex SELECT * FROM address WHERE id IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10); .. note:: - Changing the fetch mode during a query is only possible for one-to-one and many-to-one relations. + Changing the fetch mode during a query mostly makes sense for one-to-one and many-to-one relations. In that case, +   all the necessary IDs are available after the root entity (``user`` in the above example) has been loaded. So, one +   query per association can be executed to fetch all the referred-to entities (``address``). + + For one-to-many relations, changing the fetch mode to eager will cause to execute one query **for every root entity +   loaded**. This gives no improvement over the ``lazy`` fetch mode which will also initialize the associations on + a one-by-one basis once they are accessed. EBNF From 8f9f41ea89e72859bc8198777a929c382053b343 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Thu, 15 Jun 2017 01:03:38 +0200 Subject: [PATCH 311/877] Fix typo --- docs/en/reference/dql-doctrine-query-language.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/en/reference/dql-doctrine-query-language.rst b/docs/en/reference/dql-doctrine-query-language.rst index ee2e2fa153b..2c2e23f9eca 100644 --- a/docs/en/reference/dql-doctrine-query-language.rst +++ b/docs/en/reference/dql-doctrine-query-language.rst @@ -935,8 +935,7 @@ the Query class. Here they are: - ``Query#getResult()``: Retrieves a collection of objects. The result is either a plain collection of objects (pure) or an array - where the objects are nested in the result rows ( - ). + where the objects are nested in the result rows (mixed). - ``Query#getSingleResult()``: Retrieves a single object. If the result contains more than one object, an ``NonUniqueResultException`` is thrown. If the result contains no objects, an ``NoResultException`` From 177c48107d0cbb73f1e8aa9e68d5d78dc375de0b Mon Sep 17 00:00:00 2001 From: Baptiste Lafontaine Date: Mon, 19 Jun 2017 13:31:10 +0200 Subject: [PATCH 312/877] Fix links to api doc --- docs/en/reference/second-level-cache.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/en/reference/second-level-cache.rst b/docs/en/reference/second-level-cache.rst index b55376561ca..62cc5d14fdf 100644 --- a/docs/en/reference/second-level-cache.rst +++ b/docs/en/reference/second-level-cache.rst @@ -97,7 +97,7 @@ Defines a contract for accessing a particular region. Defines a contract for accessing a particular cache region. -`See API Doc `_. +`See API Doc `_. Concurrent cache region ~~~~~~~~~~~~~~~~~~~~~~~ @@ -111,7 +111,7 @@ If you want to use an ``READ_WRITE`` cache, you should consider providing your o Defines contract for concurrently managed data region. -`See API Doc `_. +`See API Doc `_. Timestamp region ~~~~~~~~~~~~~~~~ @@ -120,7 +120,7 @@ Timestamp region Tracks the timestamps of the most recent updates to particular entity. -`See API Doc `_. +`See API Doc `_. .. _reference-second-level-cache-mode: @@ -209,7 +209,7 @@ It allows you to provide a specific implementation of the following components : * ``EntityHydrator`` Transform an entity into a cache entry and cache entry into entities * ``CollectionHydrator`` Transform a collection into a cache entry and cache entry into collection -`See API Doc `_. +`See API Doc `_. Region Lifetime ~~~~~~~~~~~~~~~ @@ -270,7 +270,7 @@ By providing a cache logger you should be able to get information about all cach If you want to get more information you should implement ``\Doctrine\ORM\Cache\Logging\CacheLogger``. and collect all information you want. -`See API Doc `_. +`See API Doc `_. Entity cache definition From 99dc8aa2a911e375ca14f986abac3eae5098c253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sat, 20 May 2017 17:59:23 +0200 Subject: [PATCH 313/877] Drop HHVM support --- .scrutinizer.yml | 4 ---- .travis.yml | 34 ---------------------------------- 2 files changed, 38 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 361b21e38c5..bebd35350b7 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -27,8 +27,4 @@ tools: enabled: true filter: paths: ["lib/*", "tests/*"] - php_hhvm: - enabled: true - filter: - paths: ["lib/*", "tests/*"] sensiolabs_security_checker: true diff --git a/.travis.yml b/.travis.yml index fab92a62927..78c05ab05ca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ php: - 7.0 - 7.1 - nightly - - hhvm env: - DB=mysql @@ -43,42 +42,9 @@ matrix: env: - DB=sqlite - DEPENDENCIES='low' - - php: hhvm - sudo: true - dist: trusty - group: edge # until the next Trusty update - addons: - mariadb: 10.1 - env: DB=mariadb - - php: hhvm - sudo: true - dist: trusty - group: edge # until the next update - addons: - apt: - packages: - - mysql-server-5.6 - - mysql-client-core-5.6 - - mysql-client-5.6 - services: - - mysql - env: DB=mysql - - php: hhvm - sudo: true - dist: trusty - group: edge # until the next update - services: - - postgresql - env: DB=pgsql - - php: hhvm - sudo: true - dist: trusty - group: edge # until the next update - env: DB=sqlite allow_failures: - php: nightly - - php: hhvm cache: directories: From e123f16ec99260f6bdc9fa146ca3b255673c5fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Mon, 19 Jun 2017 11:17:25 +0200 Subject: [PATCH 314/877] Require PHP 7.1 --- .scrutinizer.yml | 5 +++++ .travis.yml | 11 +++-------- composer.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index bebd35350b7..0f7195985ec 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,3 +1,8 @@ +build: + environment: + php: + version: 7.1 + before_commands: - "composer install --no-dev --prefer-source" diff --git a/.travis.yml b/.travis.yml index 78c05ab05ca..bd9d8b32c9f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ sudo: false language: php php: - - 7.0 - 7.1 - nightly @@ -12,7 +11,7 @@ env: - DB=sqlite before_script: - - if [[ $TRAVIS_PHP_VERSION = '7.0' && $DB = 'sqlite' ]]; then PHPUNIT_FLAGS="--coverage-clover ./build/logs/clover.xml"; else PHPUNIT_FLAGS=""; fi + - if [[ $TRAVIS_PHP_VERSION = '7.1' && $DB = 'sqlite' && "$DEPENDENCIES" != "low" ]]; then PHPUNIT_FLAGS="--coverage-clover ./build/logs/clover.xml"; else PHPUNIT_FLAGS=""; fi - if [[ "$PHPUNIT_FLAGS" == "" ]]; then phpenv config-rm xdebug.ini; fi - composer self-update - composer install --prefer-source @@ -24,16 +23,12 @@ script: - ENABLE_SECOND_LEVEL_CACHE=1 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml --exclude-group performance,non-cacheable,locking_functional after_script: - - if [[ $TRAVIS_PHP_VERSION = '7.0' && $DB = 'sqlite' ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi - - if [[ $TRAVIS_PHP_VERSION = '7.0' && $DB = 'sqlite' ]]; then php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml; fi + - if [[ "$PHPUNIT_FLAGS" != "" ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi + - if [[ "$PHPUNIT_FLAGS" != "" ]]; then php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml; fi matrix: fast_finish: true include: - - php: 7.0 - env: DB=mariadb - addons: - mariadb: 10.1 - php: 7.1 env: DB=mariadb addons: diff --git a/composer.json b/composer.json index 5c89e8f9792..e76eae85eb8 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ ], "minimum-stability": "dev", "require": { - "php": "^7.0", + "php": "^7.1", "ext-pdo": "*", "doctrine/collections": "^1.4", "doctrine/dbal": ">=2.5-dev,<2.7-dev", From 9fa456b9f0205419ddf86fb92bc475b7f937ca54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Mon, 19 Jun 2017 11:17:44 +0200 Subject: [PATCH 315/877] Bump versions of some dependencies --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index e76eae85eb8..a4b43de3b73 100644 --- a/composer.json +++ b/composer.json @@ -20,12 +20,12 @@ "doctrine/dbal": ">=2.5-dev,<2.7-dev", "doctrine/instantiator": "~1.0.1", "doctrine/common": "^2.7.1", - "doctrine/cache": "~1.5", - "doctrine/annotations": "~1.2", - "symfony/console": "~2.5|~3.0|~4.0" + "doctrine/cache": "~1.6", + "doctrine/annotations": "~1.4", + "symfony/console": "~3.0|~4.0" }, "require-dev": { - "symfony/yaml": "~2.3|~3.0|~4.0", + "symfony/yaml": "~3.0|~4.0", "phpunit/phpunit": "^6.0" }, "suggest": { From 914c400a7d1446f4bcfc23113516a2299660352a Mon Sep 17 00:00:00 2001 From: Mathew Davies Date: Thu, 8 Jun 2017 17:22:07 +0100 Subject: [PATCH 316/877] Check for custom functions first. --- lib/Doctrine/ORM/Query/Parser.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 34679ff618e..c8294be36ae 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -3376,8 +3376,13 @@ public function FunctionDeclaration() $token = $this->lexer->lookahead; $funcName = strtolower($token['value']); - // Check for built-in functions first! + $customFunctionDeclaration = $this->CustomFunctionDeclaration(); + + // Check for custom functions functions first! switch (true) { + case $customFunctionDeclaration !== null: + return $customFunctionDeclaration; + case (isset(self::$_STRING_FUNCTIONS[$funcName])): return $this->FunctionsReturningStrings(); @@ -3388,7 +3393,7 @@ public function FunctionDeclaration() return $this->FunctionsReturningDatetime(); default: - return $this->CustomFunctionDeclaration(); + $this->syntaxError('known function', $token); } } @@ -3416,7 +3421,7 @@ private function CustomFunctionDeclaration() return $this->CustomFunctionsReturningDatetime(); default: - $this->syntaxError('known function', $token); + return null; } } From e4ff7a35a8fd82e6287afda67ac6b1499f705af0 Mon Sep 17 00:00:00 2001 From: Mathew Davies Date: Fri, 9 Jun 2017 10:00:07 +0100 Subject: [PATCH 317/877] Write a test case for a custom function override. --- lib/Doctrine/ORM/Query/Parser.php | 2 +- .../ORM/Functional/CustomFunctionsTest.php | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index c8294be36ae..3a917f0595f 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -3377,7 +3377,7 @@ public function FunctionDeclaration() $funcName = strtolower($token['value']); $customFunctionDeclaration = $this->CustomFunctionDeclaration(); - + // Check for custom functions functions first! switch (true) { case $customFunctionDeclaration !== null: diff --git a/tests/Doctrine/Tests/ORM/Functional/CustomFunctionsTest.php b/tests/Doctrine/Tests/ORM/Functional/CustomFunctionsTest.php index 63c3e4ee94f..d7231219b40 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CustomFunctionsTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CustomFunctionsTest.php @@ -47,6 +47,24 @@ public function testCustomFunctionDefinedWithCallback() $this->assertEquals(1, count($users)); $this->assertSame($user, $users[0]); } + + public function testCustomFunctionOverride() + { + $user = new CmsUser(); + $user->name = 'Bob'; + $user->username = 'Dylan'; + $this->_em->persist($user); + $this->_em->flush(); + + $this->_em->getConfiguration()->addCustomStringFunction('COUNT', 'Doctrine\Tests\ORM\Functional\CustomCount'); + + $query = $this->_em->createQuery('SELECT COUNT(u.id) FROM Doctrine\Tests\Models\CMS\CmsUser u'); + + $users = $query->getResult(); + + $this->assertEquals(1, count($users)); + $this->assertSame($user, $users[0]); + } } class NoOp extends FunctionNode @@ -70,3 +88,23 @@ public function getSql(SqlWalker $sqlWalker) } } +class CustomCount extends FunctionNode +{ + /** + * @var PathExpression + */ + private $field; + + public function parse(Parser $parser) + { + $parser->match(Lexer::T_IDENTIFIER); + $parser->match(Lexer::T_OPEN_PARENTHESIS); + $this->field = $parser->StringExpression(); + $parser->match(Lexer::T_CLOSE_PARENTHESIS); + } + + public function getSql(SqlWalker $sqlWalker) + { + return $this->field->dispatch($sqlWalker); + } +} From 866418e40f38e33f2c5dcf16ab9bccd3cdffa563 Mon Sep 17 00:00:00 2001 From: Mathew Davies Date: Fri, 9 Jun 2017 15:09:41 +0100 Subject: [PATCH 318/877] No longer treat aggregate functions as a special case. --- lib/Doctrine/ORM/Configuration.php | 12 ---- lib/Doctrine/ORM/ORMException.php | 10 ---- .../ORM/Query/AST/Functions/AvgFunction.php | 55 +++++++++++++++++++ .../ORM/Query/AST/Functions/CountFunction.php | 55 +++++++++++++++++++ .../ORM/Query/AST/Functions/MaxFunction.php | 55 +++++++++++++++++++ .../ORM/Query/AST/Functions/MinFunction.php | 55 +++++++++++++++++++ .../ORM/Query/AST/Functions/SumFunction.php | 55 +++++++++++++++++++ lib/Doctrine/ORM/Query/Parser.php | 45 +++------------ lib/Doctrine/ORM/Query/SqlWalker.php | 8 ++- .../Doctrine/Tests/ORM/ConfigurationTest.php | 6 -- .../ORM/Functional/CustomFunctionsTest.php | 18 +++--- 11 files changed, 295 insertions(+), 79 deletions(-) create mode 100644 lib/Doctrine/ORM/Query/AST/Functions/AvgFunction.php create mode 100644 lib/Doctrine/ORM/Query/AST/Functions/CountFunction.php create mode 100644 lib/Doctrine/ORM/Query/AST/Functions/MaxFunction.php create mode 100644 lib/Doctrine/ORM/Query/AST/Functions/MinFunction.php create mode 100644 lib/Doctrine/ORM/Query/AST/Functions/SumFunction.php diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index 104a4f4b231..4af482faf0e 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -425,10 +425,6 @@ public function ensureProductionSettings() */ public function addCustomStringFunction($name, $className) { - if (Query\Parser::isInternalFunction($name)) { - throw ORMException::overwriteInternalDQLFunctionNotAllowed($name); - } - $this->_attributes['customStringFunctions'][strtolower($name)] = $className; } @@ -483,10 +479,6 @@ public function setCustomStringFunctions(array $functions) */ public function addCustomNumericFunction($name, $className) { - if (Query\Parser::isInternalFunction($name)) { - throw ORMException::overwriteInternalDQLFunctionNotAllowed($name); - } - $this->_attributes['customNumericFunctions'][strtolower($name)] = $className; } @@ -541,10 +533,6 @@ public function setCustomNumericFunctions(array $functions) */ public function addCustomDatetimeFunction($name, $className) { - if (Query\Parser::isInternalFunction($name)) { - throw ORMException::overwriteInternalDQLFunctionNotAllowed($name); - } - $this->_attributes['customDatetimeFunctions'][strtolower($name)] = $className; } diff --git a/lib/Doctrine/ORM/ORMException.php b/lib/Doctrine/ORM/ORMException.php index 039ef2eaaf9..3ce9ce9dc91 100644 --- a/lib/Doctrine/ORM/ORMException.php +++ b/lib/Doctrine/ORM/ORMException.php @@ -323,16 +323,6 @@ public static function unrecognizedIdentifierFields($className, $fieldNames) ); } - /** - * @param string $functionName - * - * @return ORMException - */ - public static function overwriteInternalDQLFunctionNotAllowed($functionName) - { - return new self("It is not allowed to overwrite internal function '$functionName' in the DQL parser through user-defined functions."); - } - /** * @return ORMException */ diff --git a/lib/Doctrine/ORM/Query/AST/Functions/AvgFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/AvgFunction.php new file mode 100644 index 00000000000..7d9703d0d18 --- /dev/null +++ b/lib/Doctrine/ORM/Query/AST/Functions/AvgFunction.php @@ -0,0 +1,55 @@ +. + */ + +namespace Doctrine\ORM\Query\AST\Functions; + +use Doctrine\ORM\Query\Parser; +use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\AST\AggregateExpression; + +/** + * "AVG" "(" ["DISTINCT"] StringPrimary ")" + * + * @link www.doctrine-project.org + * @since 2.0 + * @author Mathew Davies + */ +class AvgFunction extends FunctionNode +{ + /** + * @var AggregateExpression + */ + public $aggregateExpression; + + /** + * @inheritDoc + */ + public function getSql(SqlWalker $sqlWalker) + { + return $this->aggregateExpression->dispatch($sqlWalker); + } + + /** + * @inheritDoc + */ + public function parse(Parser $parser) + { + $this->aggregateExpression = $parser->AggregateExpression(); + } +} diff --git a/lib/Doctrine/ORM/Query/AST/Functions/CountFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/CountFunction.php new file mode 100644 index 00000000000..e5b7220edd7 --- /dev/null +++ b/lib/Doctrine/ORM/Query/AST/Functions/CountFunction.php @@ -0,0 +1,55 @@ +. + */ + +namespace Doctrine\ORM\Query\AST\Functions; + +use Doctrine\ORM\Query\Parser; +use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\AST\AggregateExpression; + +/** + * "COUNT" "(" ["DISTINCT"] StringPrimary ")" + * + * @link www.doctrine-project.org + * @since 2.0 + * @author Mathew Davies + */ +class CountFunction extends FunctionNode +{ + /** + * @var AggregateExpression + */ + public $aggregateExpression; + + /** + * @inheritDoc + */ + public function getSql(SqlWalker $sqlWalker) + { + return $this->aggregateExpression->dispatch($sqlWalker); + } + + /** + * @inheritDoc + */ + public function parse(Parser $parser) + { + $this->aggregateExpression = $parser->AggregateExpression(); + } +} diff --git a/lib/Doctrine/ORM/Query/AST/Functions/MaxFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/MaxFunction.php new file mode 100644 index 00000000000..c01cc2d86e4 --- /dev/null +++ b/lib/Doctrine/ORM/Query/AST/Functions/MaxFunction.php @@ -0,0 +1,55 @@ +. + */ + +namespace Doctrine\ORM\Query\AST\Functions; + +use Doctrine\ORM\Query\Parser; +use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\AST\AggregateExpression; + +/** + * "MAX" "(" ["DISTINCT"] StringPrimary ")" + * + * @link www.doctrine-project.org + * @since 2.0 + * @author Mathew Davies + */ +class MaxFunction extends FunctionNode +{ + /** + * @var AggregateExpression + */ + public $aggregateExpression; + + /** + * @inheritDoc + */ + public function getSql(SqlWalker $sqlWalker) + { + return $this->aggregateExpression->dispatch($sqlWalker); + } + + /** + * @inheritDoc + */ + public function parse(Parser $parser) + { + $this->aggregateExpression = $parser->AggregateExpression(); + } +} diff --git a/lib/Doctrine/ORM/Query/AST/Functions/MinFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/MinFunction.php new file mode 100644 index 00000000000..1985be2d803 --- /dev/null +++ b/lib/Doctrine/ORM/Query/AST/Functions/MinFunction.php @@ -0,0 +1,55 @@ +. + */ + +namespace Doctrine\ORM\Query\AST\Functions; + +use Doctrine\ORM\Query\Parser; +use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\AST\AggregateExpression; + +/** + * "MIN" "(" ["DISTINCT"] StringPrimary ")" + * + * @link www.doctrine-project.org + * @since 2.0 + * @author Mathew Davies + */ +class MinFunction extends FunctionNode +{ + /** + * @var AggregateExpression + */ + public $aggregateExpression; + + /** + * @inheritDoc + */ + public function getSql(SqlWalker $sqlWalker) + { + return $this->aggregateExpression->dispatch($sqlWalker); + } + + /** + * @inheritDoc + */ + public function parse(Parser $parser) + { + $this->aggregateExpression = $parser->AggregateExpression(); + } +} diff --git a/lib/Doctrine/ORM/Query/AST/Functions/SumFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/SumFunction.php new file mode 100644 index 00000000000..f8cd48db011 --- /dev/null +++ b/lib/Doctrine/ORM/Query/AST/Functions/SumFunction.php @@ -0,0 +1,55 @@ +. + */ + +namespace Doctrine\ORM\Query\AST\Functions; + +use Doctrine\ORM\Query\Parser; +use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\AST\AggregateExpression; + +/** + * "SUM" "(" ["DISTINCT"] StringPrimary ")" + * + * @link www.doctrine-project.org + * @since 2.0 + * @author Mathew Davies + */ +class SumFunction extends FunctionNode +{ + /** + * @var AggregateExpression + */ + public $aggregateExpression; + + /** + * @inheritDoc + */ + public function getSql(SqlWalker $sqlWalker) + { + return $this->aggregateExpression->dispatch($sqlWalker); + } + + /** + * @inheritDoc + */ + public function parse(Parser $parser) + { + $this->aggregateExpression = $parser->AggregateExpression(); + } +} diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 3a917f0595f..a06cd83a6a0 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -65,6 +65,13 @@ class Parser 'date_diff' => Functions\DateDiffFunction::class, 'bit_and' => Functions\BitAndFunction::class, 'bit_or' => Functions\BitOrFunction::class, + + // Aggregate functions + 'min' => Functions\MinFunction::class, + 'max' => Functions\MaxFunction::class, + 'avg' => Functions\AvgFunction::class, + 'sum' => Functions\SumFunction::class, + 'count' => Functions\CountFunction::class, ]; /** @@ -171,23 +178,6 @@ class Parser */ private $identVariableExpressions = []; - /** - * Checks if a function is internally defined. Used to prevent overwriting - * of built-in functions through user-defined functions. - * - * @param string $functionName - * - * @return bool - */ - static public function isInternalFunction($functionName) - { - $functionName = strtolower($functionName); - - return isset(self::$_STRING_FUNCTIONS[$functionName]) - || isset(self::$_DATETIME_FUNCTIONS[$functionName]) - || isset(self::$_NUMERIC_FUNCTIONS[$functionName]); - } - /** * Creates a new query parser object. * @@ -1978,9 +1968,6 @@ public function ScalarExpression() // SUM(u.id) + COUNT(u.id) return $this->SimpleArithmeticExpression(); - case ($this->isAggregateFunction($this->lexer->lookahead['type'])): - return $this->AggregateExpression(); - default: // IDENTITY(u) return $this->FunctionDeclaration(); @@ -2209,11 +2196,6 @@ public function SelectExpression() $expression = $this->ScalarExpression(); break; - case ($this->isAggregateFunction($lookaheadType)): - // COUNT(u.id) - $expression = $this->AggregateExpression(); - break; - default: // IDENTITY(u) $expression = $this->FunctionDeclaration(); @@ -2858,10 +2840,6 @@ public function ArithmeticPrimary() $peek = $this->lexer->glimpse(); if ($peek['value'] == '(') { - if ($this->isAggregateFunction($this->lexer->lookahead['type'])) { - return $this->AggregateExpression(); - } - return $this->FunctionDeclaration(); } @@ -2932,11 +2910,6 @@ public function StringPrimary() case Lexer::T_COALESCE: case Lexer::T_NULLIF: return $this->CaseExpression(); - - default: - if ($this->isAggregateFunction($lookaheadType)) { - return $this->AggregateExpression(); - } } $this->syntaxError( @@ -3236,10 +3209,6 @@ public function NullComparisonExpression() $expr = $this->CoalesceExpression(); break; - case $this->isAggregateFunction($this->lexer->lookahead['type']): - $expr = $this->AggregateExpression(); - break; - case $this->isFunction(): $expr = $this->FunctionDeclaration(); break; diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index ee57cf90b1a..206a4676e74 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -1579,10 +1579,14 @@ public function walkSimpleSelectExpression($simpleSelectExpression) $sql .= $this->walkPathExpression($expr); break; - case ($expr instanceof AST\AggregateExpression): + case ($expr instanceof AST\Functions\AvgFunction): + case ($expr instanceof AST\Functions\CountFunction): + case ($expr instanceof AST\Functions\MaxFunction): + case ($expr instanceof AST\Functions\MinFunction): + case ($expr instanceof AST\Functions\SumFunction): $alias = $simpleSelectExpression->fieldIdentificationVariable ?: $this->scalarResultCounter++; - $sql .= $this->walkAggregateExpression($expr) . ' AS dctrn__' . $alias; + $sql .= $expr->dispatch($this) . ' AS dctrn__' . $alias; break; case ($expr instanceof AST\Subselect): diff --git a/tests/Doctrine/Tests/ORM/ConfigurationTest.php b/tests/Doctrine/Tests/ORM/ConfigurationTest.php index ab657c5fd2a..92a2eeaea70 100644 --- a/tests/Doctrine/Tests/ORM/ConfigurationTest.php +++ b/tests/Doctrine/Tests/ORM/ConfigurationTest.php @@ -265,8 +265,6 @@ public function testAddGetCustomStringFunction() $this->assertSame(null, $this->configuration->getCustomStringFunction('NonExistingFunction')); $this->configuration->setCustomStringFunctions(['OtherFunctionName' => __CLASS__]); $this->assertSame(__CLASS__, $this->configuration->getCustomStringFunction('OtherFunctionName')); - $this->expectException(ORMException::class); - $this->configuration->addCustomStringFunction('concat', __CLASS__); } public function testAddGetCustomNumericFunction() @@ -276,8 +274,6 @@ public function testAddGetCustomNumericFunction() $this->assertSame(null, $this->configuration->getCustomNumericFunction('NonExistingFunction')); $this->configuration->setCustomNumericFunctions(['OtherFunctionName' => __CLASS__]); $this->assertSame(__CLASS__, $this->configuration->getCustomNumericFunction('OtherFunctionName')); - $this->expectException(ORMException::class); - $this->configuration->addCustomNumericFunction('abs', __CLASS__); } public function testAddGetCustomDatetimeFunction() @@ -287,8 +283,6 @@ public function testAddGetCustomDatetimeFunction() $this->assertSame(null, $this->configuration->getCustomDatetimeFunction('NonExistingFunction')); $this->configuration->setCustomDatetimeFunctions(['OtherFunctionName' => __CLASS__]); $this->assertSame(__CLASS__, $this->configuration->getCustomDatetimeFunction('OtherFunctionName')); - $this->expectException(ORMException::class); - $this->configuration->addCustomDatetimeFunction('date_add', __CLASS__); } public function testAddGetCustomHydrationMode() diff --git a/tests/Doctrine/Tests/ORM/Functional/CustomFunctionsTest.php b/tests/Doctrine/Tests/ORM/Functional/CustomFunctionsTest.php index d7231219b40..aa56e1f934e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CustomFunctionsTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CustomFunctionsTest.php @@ -58,12 +58,11 @@ public function testCustomFunctionOverride() $this->_em->getConfiguration()->addCustomStringFunction('COUNT', 'Doctrine\Tests\ORM\Functional\CustomCount'); - $query = $this->_em->createQuery('SELECT COUNT(u.id) FROM Doctrine\Tests\Models\CMS\CmsUser u'); + $query = $this->_em->createQuery('SELECT COUNT(DISTINCT u.id) FROM Doctrine\Tests\Models\CMS\CmsUser u'); - $users = $query->getResult(); + $usersCount = $query->getSingleScalarResult(); - $this->assertEquals(1, count($users)); - $this->assertSame($user, $users[0]); + $this->assertEquals(1, $usersCount); } } @@ -91,20 +90,17 @@ public function getSql(SqlWalker $sqlWalker) class CustomCount extends FunctionNode { /** - * @var PathExpression + * @var Query\AST\AggregateExpression */ - private $field; + private $aggregateExpression; public function parse(Parser $parser) { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); - $this->field = $parser->StringExpression(); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $this->aggregateExpression = $parser->AggregateExpression(); } public function getSql(SqlWalker $sqlWalker) { - return $this->field->dispatch($sqlWalker); + return $this->aggregateExpression->dispatch($sqlWalker); } } From e4847534a4c2decb47947f7b32dced5f7ac3a5bf Mon Sep 17 00:00:00 2001 From: Mathew Davies Date: Mon, 19 Jun 2017 08:54:29 +0100 Subject: [PATCH 319/877] Remove @throws in Configuration where necessary. --- lib/Doctrine/ORM/Configuration.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index 4af482faf0e..6073fbe008c 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -420,8 +420,6 @@ public function ensureProductionSettings() * @param string|callable $className Class name or a callable that returns the function. * * @return void - * - * @throws ORMException */ public function addCustomStringFunction($name, $className) { @@ -474,8 +472,6 @@ public function setCustomStringFunctions(array $functions) * @param string|callable $className Class name or a callable that returns the function. * * @return void - * - * @throws ORMException */ public function addCustomNumericFunction($name, $className) { @@ -528,8 +524,6 @@ public function setCustomNumericFunctions(array $functions) * @param string|callable $className Class name or a callable that returns the function. * * @return void - * - * @throws ORMException */ public function addCustomDatetimeFunction($name, $className) { From 966f9a84c26db0888bb86530264c18f8b062429e Mon Sep 17 00:00:00 2001 From: Mathew Davies Date: Mon, 19 Jun 2017 09:00:00 +0100 Subject: [PATCH 320/877] phpDoc and type hint changes. --- lib/Doctrine/ORM/Query/AST/Functions/AvgFunction.php | 9 ++++----- lib/Doctrine/ORM/Query/AST/Functions/CountFunction.php | 9 ++++----- lib/Doctrine/ORM/Query/AST/Functions/MaxFunction.php | 9 ++++----- lib/Doctrine/ORM/Query/AST/Functions/MinFunction.php | 9 ++++----- lib/Doctrine/ORM/Query/AST/Functions/SumFunction.php | 9 ++++----- .../Tests/ORM/Functional/CustomFunctionsTest.php | 4 ++-- 6 files changed, 22 insertions(+), 27 deletions(-) diff --git a/lib/Doctrine/ORM/Query/AST/Functions/AvgFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/AvgFunction.php index 7d9703d0d18..d217eb4b7df 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/AvgFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/AvgFunction.php @@ -26,8 +26,7 @@ /** * "AVG" "(" ["DISTINCT"] StringPrimary ")" * - * @link www.doctrine-project.org - * @since 2.0 + * @since 2.6 * @author Mathew Davies */ class AvgFunction extends FunctionNode @@ -35,12 +34,12 @@ class AvgFunction extends FunctionNode /** * @var AggregateExpression */ - public $aggregateExpression; + private $aggregateExpression; /** * @inheritDoc */ - public function getSql(SqlWalker $sqlWalker) + public function getSql(SqlWalker $sqlWalker): string { return $this->aggregateExpression->dispatch($sqlWalker); } @@ -48,7 +47,7 @@ public function getSql(SqlWalker $sqlWalker) /** * @inheritDoc */ - public function parse(Parser $parser) + public function parse(Parser $parser): void { $this->aggregateExpression = $parser->AggregateExpression(); } diff --git a/lib/Doctrine/ORM/Query/AST/Functions/CountFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/CountFunction.php index e5b7220edd7..34a9a723c5e 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/CountFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/CountFunction.php @@ -26,8 +26,7 @@ /** * "COUNT" "(" ["DISTINCT"] StringPrimary ")" * - * @link www.doctrine-project.org - * @since 2.0 + * @since 2.6 * @author Mathew Davies */ class CountFunction extends FunctionNode @@ -35,12 +34,12 @@ class CountFunction extends FunctionNode /** * @var AggregateExpression */ - public $aggregateExpression; + private $aggregateExpression; /** * @inheritDoc */ - public function getSql(SqlWalker $sqlWalker) + public function getSql(SqlWalker $sqlWalker): string { return $this->aggregateExpression->dispatch($sqlWalker); } @@ -48,7 +47,7 @@ public function getSql(SqlWalker $sqlWalker) /** * @inheritDoc */ - public function parse(Parser $parser) + public function parse(Parser $parser): void { $this->aggregateExpression = $parser->AggregateExpression(); } diff --git a/lib/Doctrine/ORM/Query/AST/Functions/MaxFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/MaxFunction.php index c01cc2d86e4..d430cc428cd 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/MaxFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/MaxFunction.php @@ -26,8 +26,7 @@ /** * "MAX" "(" ["DISTINCT"] StringPrimary ")" * - * @link www.doctrine-project.org - * @since 2.0 + * @since 2.6 * @author Mathew Davies */ class MaxFunction extends FunctionNode @@ -35,12 +34,12 @@ class MaxFunction extends FunctionNode /** * @var AggregateExpression */ - public $aggregateExpression; + private $aggregateExpression; /** * @inheritDoc */ - public function getSql(SqlWalker $sqlWalker) + public function getSql(SqlWalker $sqlWalker): string { return $this->aggregateExpression->dispatch($sqlWalker); } @@ -48,7 +47,7 @@ public function getSql(SqlWalker $sqlWalker) /** * @inheritDoc */ - public function parse(Parser $parser) + public function parse(Parser $parser): void { $this->aggregateExpression = $parser->AggregateExpression(); } diff --git a/lib/Doctrine/ORM/Query/AST/Functions/MinFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/MinFunction.php index 1985be2d803..345f99a9440 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/MinFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/MinFunction.php @@ -26,8 +26,7 @@ /** * "MIN" "(" ["DISTINCT"] StringPrimary ")" * - * @link www.doctrine-project.org - * @since 2.0 + * @since 2.6 * @author Mathew Davies */ class MinFunction extends FunctionNode @@ -35,12 +34,12 @@ class MinFunction extends FunctionNode /** * @var AggregateExpression */ - public $aggregateExpression; + private $aggregateExpression; /** * @inheritDoc */ - public function getSql(SqlWalker $sqlWalker) + public function getSql(SqlWalker $sqlWalker): string { return $this->aggregateExpression->dispatch($sqlWalker); } @@ -48,7 +47,7 @@ public function getSql(SqlWalker $sqlWalker) /** * @inheritDoc */ - public function parse(Parser $parser) + public function parse(Parser $parser): void { $this->aggregateExpression = $parser->AggregateExpression(); } diff --git a/lib/Doctrine/ORM/Query/AST/Functions/SumFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/SumFunction.php index f8cd48db011..d77e284c0ec 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/SumFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/SumFunction.php @@ -26,8 +26,7 @@ /** * "SUM" "(" ["DISTINCT"] StringPrimary ")" * - * @link www.doctrine-project.org - * @since 2.0 + * @since 2.6 * @author Mathew Davies */ class SumFunction extends FunctionNode @@ -35,12 +34,12 @@ class SumFunction extends FunctionNode /** * @var AggregateExpression */ - public $aggregateExpression; + private $aggregateExpression; /** * @inheritDoc */ - public function getSql(SqlWalker $sqlWalker) + public function getSql(SqlWalker $sqlWalker): string { return $this->aggregateExpression->dispatch($sqlWalker); } @@ -48,7 +47,7 @@ public function getSql(SqlWalker $sqlWalker) /** * @inheritDoc */ - public function parse(Parser $parser) + public function parse(Parser $parser): void { $this->aggregateExpression = $parser->AggregateExpression(); } diff --git a/tests/Doctrine/Tests/ORM/Functional/CustomFunctionsTest.php b/tests/Doctrine/Tests/ORM/Functional/CustomFunctionsTest.php index aa56e1f934e..79668b8f2cc 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CustomFunctionsTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CustomFunctionsTest.php @@ -94,12 +94,12 @@ class CustomCount extends FunctionNode */ private $aggregateExpression; - public function parse(Parser $parser) + public function parse(Parser $parser): void { $this->aggregateExpression = $parser->AggregateExpression(); } - public function getSql(SqlWalker $sqlWalker) + public function getSql(SqlWalker $sqlWalker): string { return $this->aggregateExpression->dispatch($sqlWalker); } From 3e3751cfd9595fa1fdef491c53e8464992ebcd18 Mon Sep 17 00:00:00 2001 From: Mathew Davies Date: Mon, 19 Jun 2017 09:37:21 +0100 Subject: [PATCH 321/877] Remove aggregate function conditional in SqlWalker. --- lib/Doctrine/ORM/Query/SqlWalker.php | 10 ---------- .../Tests/ORM/Query/SelectSqlGenerationTest.php | 6 +++--- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 206a4676e74..a4b5089e859 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -1579,16 +1579,6 @@ public function walkSimpleSelectExpression($simpleSelectExpression) $sql .= $this->walkPathExpression($expr); break; - case ($expr instanceof AST\Functions\AvgFunction): - case ($expr instanceof AST\Functions\CountFunction): - case ($expr instanceof AST\Functions\MaxFunction): - case ($expr instanceof AST\Functions\MinFunction): - case ($expr instanceof AST\Functions\SumFunction): - $alias = $simpleSelectExpression->fieldIdentificationVariable ?: $this->scalarResultCounter++; - - $sql .= $expr->dispatch($this) . ' AS dctrn__' . $alias; - break; - case ($expr instanceof AST\Subselect): $alias = $simpleSelectExpression->fieldIdentificationVariable ?: $this->scalarResultCounter++; diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index b674c5d38be..c10afbb8961 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -1031,7 +1031,7 @@ public function testSubselectInSelect() { $this->assertSqlGeneration( "SELECT u.name, (SELECT COUNT(p.phonenumber) FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p WHERE p.phonenumber = 1234) pcount FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = 'jon'", - "SELECT c0_.name AS name_0, (SELECT COUNT(c1_.phonenumber) AS dctrn__1 FROM cms_phonenumbers c1_ WHERE c1_.phonenumber = 1234) AS sclr_1 FROM cms_users c0_ WHERE c0_.name = 'jon'" + "SELECT c0_.name AS name_0, (SELECT COUNT(c1_.phonenumber) AS sclr_2 FROM cms_phonenumbers c1_ WHERE c1_.phonenumber = 1234) AS sclr_1 FROM cms_users c0_ WHERE c0_.name = 'jon'" ); } @@ -1198,7 +1198,7 @@ public function testSubSelectDiscriminator() { $this->assertSqlGeneration( "SELECT u.name, (SELECT COUNT(cfc.id) total FROM Doctrine\Tests\Models\Company\CompanyFixContract cfc) as cfc_count FROM Doctrine\Tests\Models\CMS\CmsUser u", - "SELECT c0_.name AS name_0, (SELECT COUNT(c1_.id) AS dctrn__total FROM company_contracts c1_ WHERE c1_.discr IN ('fix')) AS sclr_1 FROM cms_users c0_" + "SELECT c0_.name AS name_0, (SELECT COUNT(c1_.id) AS sclr_2 FROM company_contracts c1_ WHERE c1_.discr IN ('fix')) AS sclr_1 FROM cms_users c0_" ); } @@ -1750,7 +1750,7 @@ public function testSupportsSubSqlFunction() ); $this->assertSqlGeneration( 'SELECT u1 FROM Doctrine\Tests\Models\CMS\CmsUser u1 WHERE COUNT(u1.id) = ( SELECT SUM(u2.id) FROM Doctrine\Tests\Models\CMS\CmsUser u2 )', - 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE COUNT(c0_.id) = (SELECT SUM(c1_.id) AS dctrn__1 FROM cms_users c1_)' + 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE COUNT(c0_.id) = (SELECT SUM(c1_.id) AS sclr_4 FROM cms_users c1_)' ); $this->assertSqlGeneration( 'SELECT u1 FROM Doctrine\Tests\Models\CMS\CmsUser u1 WHERE COUNT(u1.id) <= ( SELECT SUM(u2.id) + COUNT(u2.email) FROM Doctrine\Tests\Models\CMS\CmsUser u2 )', From 49e4b1004c04e0ace55f3dae819b881b43cac6fe Mon Sep 17 00:00:00 2001 From: Mathew Davies Date: Mon, 19 Jun 2017 09:57:53 +0100 Subject: [PATCH 322/877] Update LimitSubqueryOutputWalkerTest --- .../Tools/Pagination/LimitSubqueryOutputWalkerTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php index 06e21173df2..7e65ab7bc91 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php @@ -330,7 +330,7 @@ public function testLimitSubqueryWithOrderByAndSubSelectInWhereClauseMySql() $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( - 'SELECT DISTINCT id_0 FROM (SELECT b0_.id AS id_0, b0_.author_id AS author_id_1, b0_.category_id AS category_id_2 FROM BlogPost b0_ WHERE ((SELECT COUNT(b1_.id) AS dctrn__1 FROM BlogPost b1_) = 1)) dctrn_result ORDER BY id_0 DESC', + 'SELECT DISTINCT id_0 FROM (SELECT b0_.id AS id_0, b0_.author_id AS author_id_1, b0_.category_id AS category_id_2 FROM BlogPost b0_ WHERE ((SELECT COUNT(b1_.id) AS sclr_3 FROM BlogPost b1_) = 1)) dctrn_result ORDER BY id_0 DESC', $query->getSQL() ); } @@ -346,7 +346,7 @@ public function testLimitSubqueryWithOrderByAndSubSelectInWhereClausePgSql() $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( - 'SELECT DISTINCT id_0, MIN(sclr_1) AS dctrn_minrownum FROM (SELECT b0_.id AS id_0, ROW_NUMBER() OVER(ORDER BY b0_.id DESC) AS sclr_1, b0_.author_id AS author_id_2, b0_.category_id AS category_id_3 FROM BlogPost b0_ WHERE ((SELECT COUNT(b1_.id) AS dctrn__1 FROM BlogPost b1_) = 1)) dctrn_result GROUP BY id_0 ORDER BY dctrn_minrownum ASC', + 'SELECT DISTINCT id_0, MIN(sclr_1) AS dctrn_minrownum FROM (SELECT b0_.id AS id_0, ROW_NUMBER() OVER(ORDER BY b0_.id DESC) AS sclr_1, b0_.author_id AS author_id_2, b0_.category_id AS category_id_3 FROM BlogPost b0_ WHERE ((SELECT COUNT(b1_.id) AS sclr_4 FROM BlogPost b1_) = 1)) dctrn_result GROUP BY id_0 ORDER BY dctrn_minrownum ASC', $query->getSQL() ); } @@ -390,7 +390,7 @@ public function testLimitSubqueryOrderBySubSelectOrderByExpression() $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( - 'SELECT DISTINCT id_0 FROM (SELECT a0_.id AS id_0, a0_.name AS name_1, (SELECT MIN(m1_.title) AS dctrn__1 FROM MyBlogPost m1_ WHERE m1_.author_id = a0_.id) AS sclr_2 FROM Author a0_) dctrn_result ORDER BY sclr_2 DESC', + 'SELECT DISTINCT id_0 FROM (SELECT a0_.id AS id_0, a0_.name AS name_1, (SELECT MIN(m1_.title) AS sclr_3 FROM MyBlogPost m1_ WHERE m1_.author_id = a0_.id) AS sclr_2 FROM Author a0_) dctrn_result ORDER BY sclr_2 DESC', $query->getSQL() ); } @@ -415,7 +415,7 @@ public function testLimitSubqueryOrderBySubSelectOrderByExpressionPg() $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( - 'SELECT DISTINCT id_0, MIN(sclr_3) AS dctrn_minrownum FROM (SELECT a0_.id AS id_0, a0_.name AS name_1, (SELECT MIN(m1_.title) AS dctrn__1 FROM MyBlogPost m1_ WHERE m1_.author_id = a0_.id) AS sclr_2, ROW_NUMBER() OVER(ORDER BY (SELECT MIN(m1_.title) AS dctrn__2 FROM MyBlogPost m1_ WHERE m1_.author_id = a0_.id) DESC) AS sclr_3 FROM Author a0_) dctrn_result GROUP BY id_0 ORDER BY dctrn_minrownum ASC', + 'SELECT DISTINCT id_0, MIN(sclr_4) AS dctrn_minrownum FROM (SELECT a0_.id AS id_0, a0_.name AS name_1, (SELECT MIN(m1_.title) AS sclr_3 FROM MyBlogPost m1_ WHERE m1_.author_id = a0_.id) AS sclr_2, ROW_NUMBER() OVER(ORDER BY (SELECT MIN(m1_.title) AS sclr_5 FROM MyBlogPost m1_ WHERE m1_.author_id = a0_.id) DESC) AS sclr_4 FROM Author a0_) dctrn_result GROUP BY id_0 ORDER BY dctrn_minrownum ASC', $query->getSQL() ); } @@ -440,7 +440,7 @@ public function testLimitSubqueryOrderBySubSelectOrderByExpressionOracle() $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( - 'SELECT DISTINCT ID_0, MIN(SCLR_3) AS dctrn_minrownum FROM (SELECT a0_.id AS ID_0, a0_.name AS NAME_1, (SELECT MIN(m1_.title) AS dctrn__1 FROM MyBlogPost m1_ WHERE m1_.author_id = a0_.id) AS SCLR_2, ROW_NUMBER() OVER(ORDER BY (SELECT MIN(m1_.title) AS dctrn__2 FROM MyBlogPost m1_ WHERE m1_.author_id = a0_.id) DESC) AS SCLR_3 FROM Author a0_) dctrn_result GROUP BY ID_0 ORDER BY dctrn_minrownum ASC', + 'SELECT DISTINCT ID_0, MIN(SCLR_4) AS dctrn_minrownum FROM (SELECT a0_.id AS ID_0, a0_.name AS NAME_1, (SELECT MIN(m1_.title) AS SCLR_3 FROM MyBlogPost m1_ WHERE m1_.author_id = a0_.id) AS SCLR_2, ROW_NUMBER() OVER(ORDER BY (SELECT MIN(m1_.title) AS SCLR_5 FROM MyBlogPost m1_ WHERE m1_.author_id = a0_.id) DESC) AS SCLR_4 FROM Author a0_) dctrn_result GROUP BY ID_0 ORDER BY dctrn_minrownum ASC', $query->getSQL() ); } From 05758f45647861f03cae4e0e9cf926354626e809 Mon Sep 17 00:00:00 2001 From: Mathew Davies Date: Mon, 19 Jun 2017 10:07:58 +0100 Subject: [PATCH 323/877] Documented changes in UPGRADE.md --- UPGRADE.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index 3592fe5b609..8aba870c642 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,3 +1,17 @@ +# Upgrade to 2.6 + +## Minor BC BREAK: removed `Doctrine\ORM\Query\Parser#isInternalFunction` + +Method `Doctrine\ORM\Query\Parser#isInternalFunction` was removed because +the distinction between internal function and user defined DQL was removed. +[#6500](https://github.com/doctrine/doctrine2/pull/6500) + +## Minor BC BREAK: removed `Doctrine\ORM\ORMException#overwriteInternalDQLFunctionNotAllowed` + +Method `Doctrine\ORM\Query\Parser#overwriteInternalDQLFunctionNotAllowed` was +removed because of the choice to allow users to overwrite internal functions, ie +`AVG`, `SUM`, `COUNT`, `MIN` and `MAX`. [#6500](https://github.com/doctrine/doctrine2/pull/6500) + # Upgrade to 2.5 ## Minor BC BREAK: removed `Doctrine\ORM\Query\SqlWalker#walkCaseExpression()` From 747c1857d63fc86f76c730a1eb0f4f591835dbad Mon Sep 17 00:00:00 2001 From: Mathew Davies Date: Mon, 19 Jun 2017 11:11:42 +0100 Subject: [PATCH 324/877] Make the new aggregate function definitions final. --- lib/Doctrine/ORM/Query/AST/Functions/AvgFunction.php | 2 +- lib/Doctrine/ORM/Query/AST/Functions/CountFunction.php | 2 +- lib/Doctrine/ORM/Query/AST/Functions/MaxFunction.php | 2 +- lib/Doctrine/ORM/Query/AST/Functions/MinFunction.php | 2 +- lib/Doctrine/ORM/Query/AST/Functions/SumFunction.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/Query/AST/Functions/AvgFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/AvgFunction.php index d217eb4b7df..6cb8d92b6b2 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/AvgFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/AvgFunction.php @@ -29,7 +29,7 @@ * @since 2.6 * @author Mathew Davies */ -class AvgFunction extends FunctionNode +final class AvgFunction extends FunctionNode { /** * @var AggregateExpression diff --git a/lib/Doctrine/ORM/Query/AST/Functions/CountFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/CountFunction.php index 34a9a723c5e..f232cf43f65 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/CountFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/CountFunction.php @@ -29,7 +29,7 @@ * @since 2.6 * @author Mathew Davies */ -class CountFunction extends FunctionNode +final class CountFunction extends FunctionNode { /** * @var AggregateExpression diff --git a/lib/Doctrine/ORM/Query/AST/Functions/MaxFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/MaxFunction.php index d430cc428cd..eba9b86393a 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/MaxFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/MaxFunction.php @@ -29,7 +29,7 @@ * @since 2.6 * @author Mathew Davies */ -class MaxFunction extends FunctionNode +final class MaxFunction extends FunctionNode { /** * @var AggregateExpression diff --git a/lib/Doctrine/ORM/Query/AST/Functions/MinFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/MinFunction.php index 345f99a9440..e1c08691323 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/MinFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/MinFunction.php @@ -29,7 +29,7 @@ * @since 2.6 * @author Mathew Davies */ -class MinFunction extends FunctionNode +final class MinFunction extends FunctionNode { /** * @var AggregateExpression diff --git a/lib/Doctrine/ORM/Query/AST/Functions/SumFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/SumFunction.php index d77e284c0ec..c9fcf7b04e7 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/SumFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/SumFunction.php @@ -29,7 +29,7 @@ * @since 2.6 * @author Mathew Davies */ -class SumFunction extends FunctionNode +final class SumFunction extends FunctionNode { /** * @var AggregateExpression From 1bdc61f932ba354b5eef47c1992175f8e314ff9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Tue, 20 Jun 2017 09:43:43 +0200 Subject: [PATCH 325/877] Remove tools that are not supported anymore --- .scrutinizer.yml | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 0f7195985ec..1ee7ad79f20 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -9,27 +9,3 @@ before_commands: tools: external_code_coverage: timeout: 3600 - php_code_coverage: - enabled: true - php_code_sniffer: - enabled: false - php_cpd: - enabled: true - excluded_dirs: ["bin", "docs", "tests", "tools", "vendor"] - php_cs_fixer: - enabled: false - php_loc: - enabled: true - excluded_dirs: ["bin", "docs", "tests", "tools", "vendor"] - php_mess_detector: - enabled: true - filter: - paths: ["lib/*"] - php_pdepend: - enabled: true - excluded_dirs: ["docs", "examples", "tests", "vendor"] - php_analyzer: - enabled: true - filter: - paths: ["lib/*", "tests/*"] - sensiolabs_security_checker: true From aa9f34b6009b3f2df0cefc6f101a67e11d6e6c2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Tue, 20 Jun 2017 09:46:10 +0200 Subject: [PATCH 326/877] Configure build failure conditions So that contributors receive some automated feedback in case maintainers are not fast enough. --- .scrutinizer.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 1ee7ad79f20..4ba4635114f 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -9,3 +9,16 @@ before_commands: tools: external_code_coverage: timeout: 3600 + +filter: + excluded_paths: + - docs + - tools + +build_failure_conditions: + - 'elements.rating(<= C).new.exists' # No new classes/methods with a rating of C or worse allowed + - 'issues.label("coding-style").new.exists' # No new coding style issues allowed + - 'issues.severity(>= MAJOR).new.exists' # New issues of major or higher severity + - 'project.metric_change("scrutinizer.test_coverage", < 0)' # Code Coverage decreased from previous inspection + - 'patches.label("Doc Comments").new.exists' # No new doc comments patches allowed + - 'patches.label("Unused Use Statements").new.exists' # No new unused imports patches allowed From f5d4db7d9c989a1b8f10d8ff1ea2e9f5d6020367 Mon Sep 17 00:00:00 2001 From: SimonHeimberg Date: Tue, 22 Nov 2016 09:03:01 +0100 Subject: [PATCH 327/877] Report that FROM and JOIN do not support Subqueries --- lib/Doctrine/ORM/Query/Parser.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index a06cd83a6a0..c6314865443 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -1715,6 +1715,9 @@ public function Join() */ public function RangeVariableDeclaration() { + if ($this->lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS) && $this->lexer->glimpse()['type'] === Lexer::T_SELECT) { + $this->semanticalError('Subquery is not supported here', $this->lexer->token); + } $abstractSchemaName = $this->AbstractSchemaName(); $this->validateAbstractSchemaName($abstractSchemaName); From 5b6d766961e60e2d9dcf4a14ca6e2b7d20591bab Mon Sep 17 00:00:00 2001 From: SimonHeimberg Date: Tue, 27 Dec 2016 09:47:03 +0100 Subject: [PATCH 328/877] Tests for not supported Subqueries in FROM and JOIN --- tests/Doctrine/Tests/ORM/Query/QueryTest.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Query/QueryTest.php b/tests/Doctrine/Tests/ORM/Query/QueryTest.php index c5a5da41121..c97929f9d33 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryTest.php @@ -278,4 +278,24 @@ public function testResultCacheEviction() // Retrieves cached data since expire flag is false and we have a cached result set self::assertCount(2, $query->expireResultCache(false)->getResult()); } + + /** + * @expectedException Doctrine\ORM\Query\QueryException + * @exptectedExcepionMessage Subquery + */ + public function testSelectJoinSubquery() + { + $query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u JOIN (SELECT )"); + $query->getResult(); + } + + /** + * @expectedException Doctrine\ORM\Query\QueryException + * @exptectedExcepionMessage Subquery + */ + public function testSelectFromSubquery() + { + $query = $this->_em->createQuery("select u from (select Doctrine\Tests\Models\CMS\CmsUser c) as u"); + $query->getResult(); + } } From 1dbc67cce16216e3ffcbc165ef4c52da0dddd7ec Mon Sep 17 00:00:00 2001 From: SimonHeimberg Date: Wed, 19 Apr 2017 17:06:48 +0200 Subject: [PATCH 329/877] Tests for Subqueries set expectations directly before their occurrence --- tests/Doctrine/Tests/ORM/Query/QueryTest.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Query/QueryTest.php b/tests/Doctrine/Tests/ORM/Query/QueryTest.php index c97929f9d33..dd7ad3fa567 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryTest.php @@ -8,6 +8,7 @@ use Doctrine\ORM\EntityManager; use Doctrine\ORM\Internal\Hydration\IterableResult; use Doctrine\ORM\Query\Parameter; +use Doctrine\ORM\Query\QueryException; use Doctrine\Tests\Mocks\DriverConnectionMock; use Doctrine\Tests\Mocks\StatementArrayMock; use Doctrine\Tests\Models\CMS\CmsAddress; @@ -279,23 +280,19 @@ public function testResultCacheEviction() self::assertCount(2, $query->expireResultCache(false)->getResult()); } - /** - * @expectedException Doctrine\ORM\Query\QueryException - * @exptectedExcepionMessage Subquery - */ public function testSelectJoinSubquery() { $query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u JOIN (SELECT )"); + $this->expectException(QueryException::class); + $this->expectExceptionMessage('Subquery'); $query->getResult(); } - /** - * @expectedException Doctrine\ORM\Query\QueryException - * @exptectedExcepionMessage Subquery - */ public function testSelectFromSubquery() { $query = $this->_em->createQuery("select u from (select Doctrine\Tests\Models\CMS\CmsUser c) as u"); + $this->expectException(QueryException::class); + $this->expectExceptionMessage('Subquery'); $query->getResult(); } } From a7dcdd8d48c502f1374bc8b097b714f5f94970e3 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 21 Jun 2017 05:35:58 +0200 Subject: [PATCH 330/877] Documenting thrown exception type, spacing #6162 --- lib/Doctrine/ORM/Query/Parser.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index c6314865443..c21b2de9623 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -1712,12 +1712,15 @@ public function Join() * RangeVariableDeclaration ::= AbstractSchemaName ["AS"] AliasIdentificationVariable * * @return \Doctrine\ORM\Query\AST\RangeVariableDeclaration + * + * @throws QueryException */ public function RangeVariableDeclaration() { if ($this->lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS) && $this->lexer->glimpse()['type'] === Lexer::T_SELECT) { $this->semanticalError('Subquery is not supported here', $this->lexer->token); } + $abstractSchemaName = $this->AbstractSchemaName(); $this->validateAbstractSchemaName($abstractSchemaName); From 3260d220e852970fdee68d840a235af4337e51a1 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 21 Jun 2017 05:38:42 +0200 Subject: [PATCH 331/877] #6162 adding `@group` annotation, spacing --- tests/Doctrine/Tests/ORM/Query/QueryTest.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Query/QueryTest.php b/tests/Doctrine/Tests/ORM/Query/QueryTest.php index dd7ad3fa567..5a2a295fe79 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryTest.php @@ -280,19 +280,27 @@ public function testResultCacheEviction() self::assertCount(2, $query->expireResultCache(false)->getResult()); } + /** + * @group #6162 + */ public function testSelectJoinSubquery() { $query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u JOIN (SELECT )"); + $this->expectException(QueryException::class); $this->expectExceptionMessage('Subquery'); - $query->getResult(); + $query->getSQL(); } + /** + * @group #6162 + */ public function testSelectFromSubquery() { $query = $this->_em->createQuery("select u from (select Doctrine\Tests\Models\CMS\CmsUser c) as u"); + $this->expectException(QueryException::class); $this->expectExceptionMessage('Subquery'); - $query->getResult(); + $query->getSQL(); } } From 60b6073643e8fdf33efeb98148632dbb75e4059d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kurzeja?= Date: Fri, 9 Dec 2016 21:48:43 +0100 Subject: [PATCH 332/877] Fixes #6167 - nextval issue on master-slave PostgreSQL setup --- lib/Doctrine/ORM/Id/SequenceGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Id/SequenceGenerator.php b/lib/Doctrine/ORM/Id/SequenceGenerator.php index a27edae9018..18d23849922 100644 --- a/lib/Doctrine/ORM/Id/SequenceGenerator.php +++ b/lib/Doctrine/ORM/Id/SequenceGenerator.php @@ -76,7 +76,7 @@ public function generate(EntityManager $em, $entity) $conn = $em->getConnection(); $sql = $conn->getDatabasePlatform()->getSequenceNextValSQL($this->_sequenceName); - $this->_nextValue = (int) $conn->fetchColumn($sql); + $this->_nextValue = (int) $conn->query($sql)->fetchColumn(0); $this->_maxValue = $this->_nextValue + $this->_allocationSize; } From edffb4d44914761f2b9e0d17af942ad0b5d2b1d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kurzeja?= Date: Mon, 12 Dec 2016 07:45:25 +0100 Subject: [PATCH 333/877] #6167 - fixed tests and added info why query is used in SequenceGenerator --- lib/Doctrine/ORM/Id/SequenceGenerator.php | 3 ++- tests/Doctrine/Tests/Mocks/ConnectionMock.php | 22 +++++++++++++++++++ .../Tests/ORM/Id/SequenceGeneratorTest.php | 6 ++--- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Id/SequenceGenerator.php b/lib/Doctrine/ORM/Id/SequenceGenerator.php index 18d23849922..7db8e908354 100644 --- a/lib/Doctrine/ORM/Id/SequenceGenerator.php +++ b/lib/Doctrine/ORM/Id/SequenceGenerator.php @@ -76,7 +76,8 @@ public function generate(EntityManager $em, $entity) $conn = $em->getConnection(); $sql = $conn->getDatabasePlatform()->getSequenceNextValSQL($this->_sequenceName); - $this->_nextValue = (int) $conn->query($sql)->fetchColumn(0); + // Use query to force master in MasterSlaveConnection + $this->_nextValue = (int) $conn->query($sql)->fetchColumn(); $this->_maxValue = $this->_nextValue + $this->_allocationSize; } diff --git a/tests/Doctrine/Tests/Mocks/ConnectionMock.php b/tests/Doctrine/Tests/Mocks/ConnectionMock.php index 5a28ffa5a52..11d08d4808e 100644 --- a/tests/Doctrine/Tests/Mocks/ConnectionMock.php +++ b/tests/Doctrine/Tests/Mocks/ConnectionMock.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\Mocks; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver\Statement; /** * Mock class for Connection. @@ -13,6 +14,11 @@ class ConnectionMock extends Connection */ private $_fetchOneResult; + /** + * @var Statement + */ + private $_queryResult; + /** * @var DatabasePlatformMock */ @@ -89,6 +95,14 @@ public function fetchColumn($statement, array $params = [], $colnum = 0, array $ return $this->_fetchOneResult; } + /** + * {@inheritdoc} + */ + public function query() + { + return $this->_queryResult; + } + /** * {@inheritdoc} */ @@ -132,6 +146,14 @@ public function setLastInsertId($id) $this->_lastInsertId = $id; } + /** + * @param Statement $result + */ + public function setQueryResult($result) + { + $this->_queryResult = $result; + } + /** * @return array */ diff --git a/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php b/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php index 5d7f7a59b7f..c87547934ac 100644 --- a/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM\Id; use Doctrine\ORM\Id\SequenceGenerator; +use Doctrine\Tests\Mocks\StatementArrayMock; use Doctrine\Tests\OrmTestCase; /** @@ -25,15 +26,14 @@ public function testGeneration() { for ($i=0; $i < 42; ++$i) { if ($i % 10 == 0) { - $this->_em->getConnection()->setFetchOneResult((int)($i / 10) * 10); + $nextId = array(array((int)($i / 10) * 10)); + $this->_em->getConnection()->setQueryResult(new StatementArrayMock($nextId)); } $id = $this->_seqGen->generate($this->_em, null); $this->assertEquals($i, $id); $this->assertEquals((int)($i / 10) * 10 + 10, $this->_seqGen->getCurrentMaxValue()); $this->assertEquals($i + 1, $this->_seqGen->getNextValue()); } - - } } From 71b040c8497bcf5f60c2ad120d5a8283e4e41bdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kurzeja?= Date: Mon, 12 Dec 2016 12:29:29 +0100 Subject: [PATCH 334/877] #6167 - tests - throw exception if wrong method used to get sequence nextval --- tests/Doctrine/Tests/Mocks/ConnectionMock.php | 19 +++++++++++++++++++ .../Tests/ORM/Id/SequenceGeneratorTest.php | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/tests/Doctrine/Tests/Mocks/ConnectionMock.php b/tests/Doctrine/Tests/Mocks/ConnectionMock.php index 11d08d4808e..ba0be9ee42c 100644 --- a/tests/Doctrine/Tests/Mocks/ConnectionMock.php +++ b/tests/Doctrine/Tests/Mocks/ConnectionMock.php @@ -14,6 +14,11 @@ class ConnectionMock extends Connection */ private $_fetchOneResult; + /** + * @var \Exception + */ + private $_fetchOneException; + /** * @var Statement */ @@ -92,6 +97,10 @@ public function lastInsertId($seqName = null) */ public function fetchColumn($statement, array $params = [], $colnum = 0, array $types = []) { + if ($this->_fetchOneException != null) { + throw $this->_fetchOneException; + } + return $this->_fetchOneResult; } @@ -126,6 +135,16 @@ public function setFetchOneResult($fetchOneResult) $this->_fetchOneResult = $fetchOneResult; } + /** + * @param \Exception $exception + * + * @return void + */ + public function setFetchOneException(\Exception $exception = null) + { + $this->_fetchOneException = $exception; + } + /** * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform * diff --git a/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php b/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php index c87547934ac..b972d0640ac 100644 --- a/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php @@ -24,6 +24,10 @@ protected function setUp() public function testGeneration() { + $this->_em->getConnection()->setFetchOneException( + new \Exception('Fetch* method used. Query method should be used instead, as NEXTVAL should be run on a master server in master-slave setup.') + ); + for ($i=0; $i < 42; ++$i) { if ($i % 10 == 0) { $nextId = array(array((int)($i / 10) * 10)); From 571115cf18be0f63edb4868fe03f13f4cb8297e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kurzeja?= Date: Mon, 12 Dec 2016 20:03:25 +0100 Subject: [PATCH 335/877] #6167 Code review updates, better readability --- tests/Doctrine/Tests/Mocks/ConnectionMock.php | 6 +++--- tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Doctrine/Tests/Mocks/ConnectionMock.php b/tests/Doctrine/Tests/Mocks/ConnectionMock.php index ba0be9ee42c..0b5685d2a6d 100644 --- a/tests/Doctrine/Tests/Mocks/ConnectionMock.php +++ b/tests/Doctrine/Tests/Mocks/ConnectionMock.php @@ -97,7 +97,7 @@ public function lastInsertId($seqName = null) */ public function fetchColumn($statement, array $params = [], $colnum = 0, array $types = []) { - if ($this->_fetchOneException != null) { + if (null !== $this->_fetchOneException) { throw $this->_fetchOneException; } @@ -136,7 +136,7 @@ public function setFetchOneResult($fetchOneResult) } /** - * @param \Exception $exception + * @param \Exception|null $exception * * @return void */ @@ -168,7 +168,7 @@ public function setLastInsertId($id) /** * @param Statement $result */ - public function setQueryResult($result) + public function setQueryResult(Statement $result) { $this->_queryResult = $result; } diff --git a/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php b/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php index b972d0640ac..f7ec2ffc708 100644 --- a/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php @@ -25,12 +25,12 @@ protected function setUp() public function testGeneration() { $this->_em->getConnection()->setFetchOneException( - new \Exception('Fetch* method used. Query method should be used instead, as NEXTVAL should be run on a master server in master-slave setup.') + new \RuntimeException('Fetch* method used. Query method should be used instead, as NEXTVAL should be run on a master server in master-slave setup.') ); for ($i=0; $i < 42; ++$i) { if ($i % 10 == 0) { - $nextId = array(array((int)($i / 10) * 10)); + $nextId = [[(int)($i / 10) * 10]]; $this->_em->getConnection()->setQueryResult(new StatementArrayMock($nextId)); } $id = $this->_seqGen->generate($this->_em, null); From d2be4a2b484073bceaf1cc540c80a2ca45a3c90a Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 21 Jun 2017 05:44:58 +0200 Subject: [PATCH 336/877] #6167 #6168 - clarifying on the reasoning why `query` is used instead of `fetchColumn` --- lib/Doctrine/ORM/Id/SequenceGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Id/SequenceGenerator.php b/lib/Doctrine/ORM/Id/SequenceGenerator.php index 7db8e908354..9d8e9eb75aa 100644 --- a/lib/Doctrine/ORM/Id/SequenceGenerator.php +++ b/lib/Doctrine/ORM/Id/SequenceGenerator.php @@ -76,7 +76,7 @@ public function generate(EntityManager $em, $entity) $conn = $em->getConnection(); $sql = $conn->getDatabasePlatform()->getSequenceNextValSQL($this->_sequenceName); - // Use query to force master in MasterSlaveConnection + // Using `query` to force usage of the master server in MasterSlaveConnection $this->_nextValue = (int) $conn->query($sql)->fetchColumn(); $this->_maxValue = $this->_nextValue + $this->_allocationSize; } From 462481ebbe1d57eff6bb39314704e788816f87f8 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 21 Jun 2017 05:47:19 +0200 Subject: [PATCH 337/877] #6167 #6168 - better connection mock documentation/docblocks/return-types --- tests/Doctrine/Tests/Mocks/ConnectionMock.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/Doctrine/Tests/Mocks/ConnectionMock.php b/tests/Doctrine/Tests/Mocks/ConnectionMock.php index 0b5685d2a6d..af8fc252e99 100644 --- a/tests/Doctrine/Tests/Mocks/ConnectionMock.php +++ b/tests/Doctrine/Tests/Mocks/ConnectionMock.php @@ -1,6 +1,7 @@ _queryResult; } From a97c2659fc2e731bdc88070dce09dbc2cc03512b Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 21 Jun 2017 06:04:06 +0200 Subject: [PATCH 338/877] #6167 #6168 rewrote `SequenceGeneratorTest` for better readability and error messages --- .../Tests/ORM/Id/SequenceGeneratorTest.php | 58 ++++++++++++------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php b/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php index f7ec2ffc708..5e4247715b0 100644 --- a/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php @@ -2,41 +2,57 @@ namespace Doctrine\Tests\ORM\Id; +use Doctrine\ORM\EntityManager; use Doctrine\ORM\Id\SequenceGenerator; +use Doctrine\Tests\Mocks\ConnectionMock; use Doctrine\Tests\Mocks\StatementArrayMock; use Doctrine\Tests\OrmTestCase; -/** - * Description of SequenceGeneratorTest - * - * @author robo - */ class SequenceGeneratorTest extends OrmTestCase { - private $_em; - private $_seqGen; + /** + * @var EntityManager + */ + private $entityManager; - protected function setUp() + /** + * @var SequenceGenerator + */ + private $sequenceGenerator; + + /** + * @var ConnectionMock + */ + private $connection; + + protected function setUp() : void { - $this->_em = $this->_getTestEntityManager(); - $this->_seqGen = new SequenceGenerator('seq', 10); + parent::setUp(); + + $this->entityManager = $this->_getTestEntityManager(); + $this->sequenceGenerator = new SequenceGenerator('seq', 10); + $this->connection = $this->entityManager->getConnection(); + + self::assertInstanceOf(ConnectionMock::class, $this->connection); } - public function testGeneration() + public function testGeneration() : void { - $this->_em->getConnection()->setFetchOneException( - new \RuntimeException('Fetch* method used. Query method should be used instead, as NEXTVAL should be run on a master server in master-slave setup.') - ); + $this->connection->setFetchOneException(new \BadMethodCallException( + 'Fetch* method used. Query method should be used instead, ' + . 'as NEXTVAL should be run on a master server in master-slave setup.' + )); - for ($i=0; $i < 42; ++$i) { + for ($i = 0; $i < 42; ++$i) { if ($i % 10 == 0) { - $nextId = [[(int)($i / 10) * 10]]; - $this->_em->getConnection()->setQueryResult(new StatementArrayMock($nextId)); + $this->connection->setQueryResult(new StatementArrayMock([[(int)($i / 10) * 10]])); } - $id = $this->_seqGen->generate($this->_em, null); - $this->assertEquals($i, $id); - $this->assertEquals((int)($i / 10) * 10 + 10, $this->_seqGen->getCurrentMaxValue()); - $this->assertEquals($i + 1, $this->_seqGen->getNextValue()); + + $id = $this->sequenceGenerator->generate($this->entityManager, null); + + self::assertSame($i, $id); + self::assertSame((int)($i / 10) * 10 + 10, $this->sequenceGenerator->getCurrentMaxValue()); + self::assertSame($i + 1, $this->sequenceGenerator->getNextValue()); } } } From 652358a4de7766d4588b1a9b8992437cc085e98c Mon Sep 17 00:00:00 2001 From: Guilliam Xavier Date: Sat, 25 Jun 2016 18:14:26 +0200 Subject: [PATCH 339/877] Add failing test for #5715 (unit test for MetadataFilter) --- .../ORM/Tools/Console/MetadataFilterTest.php | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php new file mode 100644 index 00000000000..7922f90064c --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php @@ -0,0 +1,78 @@ +createAnnotationDriver(); + $em = $this->_getTestEntityManager(); + $em->getConfiguration()->setMetadataDriverImpl($driver); + + $this->cmf = new DisconnectedClassMetadataFactory(); + $this->cmf->setEntityManager($em); + } + + public function testFilterWithArray() + { + $originalMetadatas = array( + $metadataAaa = $this->cmf->getMetadataFor(MetadataFilterTestEntityAaa::CLASSNAME), + $metadataBbb = $this->cmf->getMetadataFor(MetadataFilterTestEntityBbb::CLASSNAME), + $metadataCcc = $this->cmf->getMetadataFor(MetadataFilterTestEntityCcc::CLASSNAME), + ); + + $metadatas = $originalMetadatas; + $metadatas = MetadataFilter::filter($metadatas, array( + 'MetadataFilterTestEntityAaa', + 'MetadataFilterTestEntityCcc', + )); + + $this->assertContains($metadataAaa, $metadatas); + $this->assertNotContains($metadataBbb, $metadatas); + $this->assertContains($metadataCcc, $metadatas); + $this->assertCount(2, $metadatas); + } +} + +/** @Entity */ +class MetadataFilterTestEntityAaa +{ + const CLASSNAME = __CLASS__; + + /** @Id @Column(type="integer") */ + protected $id; +} + +/** @Entity */ +class MetadataFilterTestEntityBbb +{ + const CLASSNAME = __CLASS__; + + /** @Id @Column(type="integer") */ + protected $id; +} + +/** @Entity */ +class MetadataFilterTestEntityCcc +{ + const CLASSNAME = __CLASS__; + + /** @Id @Column(type="integer") */ + protected $id; +} From 87e9879edddefaa7b56f131aff9c9e2540633a16 Mon Sep 17 00:00:00 2001 From: Guilliam Xavier Date: Sat, 25 Jun 2016 18:16:00 +0200 Subject: [PATCH 340/877] Fix MetadataFilter not testing filters after first --- lib/Doctrine/ORM/Tools/Console/MetadataFilter.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Console/MetadataFilter.php b/lib/Doctrine/ORM/Tools/Console/MetadataFilter.php index f480c306302..88357e35c94 100644 --- a/lib/Doctrine/ORM/Tools/Console/MetadataFilter.php +++ b/lib/Doctrine/ORM/Tools/Console/MetadataFilter.php @@ -84,10 +84,6 @@ public function accept() ); } - if ($pregResult === 0) { - return false; - } - if ($pregResult) { return true; } From 1afa8a915db68abd1295d20f517c7d076ce4729c Mon Sep 17 00:00:00 2001 From: Guilliam Xavier Date: Sat, 25 Jun 2016 18:16:44 +0200 Subject: [PATCH 341/877] Add more basic tests for MetadataFilter --- .../ORM/Tools/Console/MetadataFilterTest.php | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php index 7922f90064c..fac23bc0151 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php @@ -29,6 +29,54 @@ protected function setUp() $this->cmf->setEntityManager($em); } + public function testFilterWithEmptyArray() + { + $originalMetadatas = array( + $metadataAaa = $this->cmf->getMetadataFor(MetadataFilterTestEntityAaa::CLASSNAME), + $metadataBbb = $this->cmf->getMetadataFor(MetadataFilterTestEntityBbb::CLASSNAME), + ); + + $metadatas = $originalMetadatas; + $metadatas = MetadataFilter::filter($metadatas, array()); + + $this->assertContains($metadataAaa, $metadatas); + $this->assertContains($metadataBbb, $metadatas); + $this->assertCount(count($originalMetadatas), $metadatas); + } + + public function testFilterWithString() + { + $originalMetadatas = array( + $metadataAaa = $this->cmf->getMetadataFor(MetadataFilterTestEntityAaa::CLASSNAME), + $metadataBbb = $this->cmf->getMetadataFor(MetadataFilterTestEntityBbb::CLASSNAME), + $metadataCcc = $this->cmf->getMetadataFor(MetadataFilterTestEntityCcc::CLASSNAME), + ); + + $metadatas = $originalMetadatas; + $metadatas = MetadataFilter::filter($metadatas, 'MetadataFilterTestEntityAaa'); + + $this->assertContains($metadataAaa, $metadatas); + $this->assertNotContains($metadataBbb, $metadatas); + $this->assertNotContains($metadataCcc, $metadatas); + $this->assertCount(1, $metadatas); + + $metadatas = $originalMetadatas; + $metadatas = MetadataFilter::filter($metadatas, 'MetadataFilterTestEntityBbb'); + + $this->assertNotContains($metadataAaa, $metadatas); + $this->assertContains($metadataBbb, $metadatas); + $this->assertNotContains($metadataCcc, $metadatas); + $this->assertCount(1, $metadatas); + + $metadatas = $originalMetadatas; + $metadatas = MetadataFilter::filter($metadatas, 'MetadataFilterTestEntityCcc'); + + $this->assertNotContains($metadataAaa, $metadatas); + $this->assertNotContains($metadataBbb, $metadatas); + $this->assertContains($metadataCcc, $metadatas); + $this->assertCount(1, $metadatas); + } + public function testFilterWithArray() { $originalMetadatas = array( From a9cc522e8ae9b06c09f3a00760b3d95110e74169 Mon Sep 17 00:00:00 2001 From: Guilliam Xavier Date: Sat, 25 Jun 2016 18:21:42 +0200 Subject: [PATCH 342/877] Add regex tests for MetadataFilter (PR #507) --- .../ORM/Tools/Console/MetadataFilterTest.php | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php index fac23bc0151..aed184e4c20 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php @@ -77,6 +77,23 @@ public function testFilterWithString() $this->assertCount(1, $metadatas); } + public function testFilterWithString2() + { + $originalMetadatas = array( + $metadataFoo = $this->cmf->getMetadataFor(MetadataFilterTestEntityFoo::CLASSNAME), + $metadataFooBar = $this->cmf->getMetadataFor(MetadataFilterTestEntityFooBar::CLASSNAME), + $metadataBar = $this->cmf->getMetadataFor(MetadataFilterTestEntityBar::CLASSNAME), + ); + + $metadatas = $originalMetadatas; + $metadatas = MetadataFilter::filter($metadatas, 'MetadataFilterTestEntityFoo'); + + $this->assertContains($metadataFoo, $metadatas); + $this->assertContains($metadataFooBar, $metadatas); + $this->assertNotContains($metadataBar, $metadatas); + $this->assertCount(2, $metadatas); + } + public function testFilterWithArray() { $originalMetadatas = array( @@ -96,6 +113,31 @@ public function testFilterWithArray() $this->assertContains($metadataCcc, $metadatas); $this->assertCount(2, $metadatas); } + + public function testFilterWithRegex() + { + $originalMetadatas = array( + $metadataFoo = $this->cmf->getMetadataFor(MetadataFilterTestEntityFoo::CLASSNAME), + $metadataFooBar = $this->cmf->getMetadataFor(MetadataFilterTestEntityFooBar::CLASSNAME), + $metadataBar = $this->cmf->getMetadataFor(MetadataFilterTestEntityBar::CLASSNAME), + ); + + $metadatas = $originalMetadatas; + $metadatas = MetadataFilter::filter($metadatas, 'Foo$'); + + $this->assertContains($metadataFoo, $metadatas); + $this->assertNotContains($metadataFooBar, $metadatas); + $this->assertNotContains($metadataBar, $metadatas); + $this->assertCount(1, $metadatas); + + $metadatas = $originalMetadatas; + $metadatas = MetadataFilter::filter($metadatas, 'Bar$'); + + $this->assertNotContains($metadataFoo, $metadatas); + $this->assertContains($metadataFooBar, $metadatas); + $this->assertContains($metadataBar, $metadatas); + $this->assertCount(2, $metadatas); + } } /** @Entity */ @@ -124,3 +166,30 @@ class MetadataFilterTestEntityCcc /** @Id @Column(type="integer") */ protected $id; } + +/** @Entity */ +class MetadataFilterTestEntityFoo +{ + const CLASSNAME = __CLASS__; + + /** @Id @Column(type="integer") */ + protected $id; +} + +/** @Entity */ +class MetadataFilterTestEntityBar +{ + const CLASSNAME = __CLASS__; + + /** @Id @Column(type="integer") */ + protected $id; +} + +/** @Entity */ +class MetadataFilterTestEntityFooBar +{ + const CLASSNAME = __CLASS__; + + /** @Id @Column(type="integer") */ + protected $id; +} From f0e403211b62fb53a1671d8a6a42eadc469454dc Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 21 Jun 2017 06:17:18 +0200 Subject: [PATCH 343/877] #5715 adding return hints \(void\) to test methods --- .../Tests/ORM/Tools/Console/MetadataFilterTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php index aed184e4c20..1972b3fd1bc 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php @@ -17,7 +17,7 @@ class MetadataFilterTest extends \Doctrine\Tests\OrmTestCase */ private $cmf; - protected function setUp() + protected function setUp() : void { parent::setUp(); @@ -29,7 +29,7 @@ protected function setUp() $this->cmf->setEntityManager($em); } - public function testFilterWithEmptyArray() + public function testFilterWithEmptyArray() : void { $originalMetadatas = array( $metadataAaa = $this->cmf->getMetadataFor(MetadataFilterTestEntityAaa::CLASSNAME), @@ -44,7 +44,7 @@ public function testFilterWithEmptyArray() $this->assertCount(count($originalMetadatas), $metadatas); } - public function testFilterWithString() + public function testFilterWithString() : void { $originalMetadatas = array( $metadataAaa = $this->cmf->getMetadataFor(MetadataFilterTestEntityAaa::CLASSNAME), @@ -77,7 +77,7 @@ public function testFilterWithString() $this->assertCount(1, $metadatas); } - public function testFilterWithString2() + public function testFilterWithString2() : void { $originalMetadatas = array( $metadataFoo = $this->cmf->getMetadataFor(MetadataFilterTestEntityFoo::CLASSNAME), @@ -94,7 +94,7 @@ public function testFilterWithString2() $this->assertCount(2, $metadatas); } - public function testFilterWithArray() + public function testFilterWithArray() : void { $originalMetadatas = array( $metadataAaa = $this->cmf->getMetadataFor(MetadataFilterTestEntityAaa::CLASSNAME), @@ -114,7 +114,7 @@ public function testFilterWithArray() $this->assertCount(2, $metadatas); } - public function testFilterWithRegex() + public function testFilterWithRegex() : void { $originalMetadatas = array( $metadataFoo = $this->cmf->getMetadataFor(MetadataFilterTestEntityFoo::CLASSNAME), From 2ce40a6aebb5e274ebca50bb619619cf1c9a7a86 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 21 Jun 2017 06:18:24 +0200 Subject: [PATCH 344/877] #5715 s/CLASSNAME/class --- .../ORM/Tools/Console/MetadataFilterTest.php | 40 +++++++------------ 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php index 1972b3fd1bc..2cc4e5f3293 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php @@ -32,8 +32,8 @@ protected function setUp() : void public function testFilterWithEmptyArray() : void { $originalMetadatas = array( - $metadataAaa = $this->cmf->getMetadataFor(MetadataFilterTestEntityAaa::CLASSNAME), - $metadataBbb = $this->cmf->getMetadataFor(MetadataFilterTestEntityBbb::CLASSNAME), + $metadataAaa = $this->cmf->getMetadataFor(MetadataFilterTestEntityAaa::class), + $metadataBbb = $this->cmf->getMetadataFor(MetadataFilterTestEntityBbb::class), ); $metadatas = $originalMetadatas; @@ -47,9 +47,9 @@ public function testFilterWithEmptyArray() : void public function testFilterWithString() : void { $originalMetadatas = array( - $metadataAaa = $this->cmf->getMetadataFor(MetadataFilterTestEntityAaa::CLASSNAME), - $metadataBbb = $this->cmf->getMetadataFor(MetadataFilterTestEntityBbb::CLASSNAME), - $metadataCcc = $this->cmf->getMetadataFor(MetadataFilterTestEntityCcc::CLASSNAME), + $metadataAaa = $this->cmf->getMetadataFor(MetadataFilterTestEntityAaa::class), + $metadataBbb = $this->cmf->getMetadataFor(MetadataFilterTestEntityBbb::class), + $metadataCcc = $this->cmf->getMetadataFor(MetadataFilterTestEntityCcc::class), ); $metadatas = $originalMetadatas; @@ -80,9 +80,9 @@ public function testFilterWithString() : void public function testFilterWithString2() : void { $originalMetadatas = array( - $metadataFoo = $this->cmf->getMetadataFor(MetadataFilterTestEntityFoo::CLASSNAME), - $metadataFooBar = $this->cmf->getMetadataFor(MetadataFilterTestEntityFooBar::CLASSNAME), - $metadataBar = $this->cmf->getMetadataFor(MetadataFilterTestEntityBar::CLASSNAME), + $metadataFoo = $this->cmf->getMetadataFor(MetadataFilterTestEntityFoo::class), + $metadataFooBar = $this->cmf->getMetadataFor(MetadataFilterTestEntityFooBar::class), + $metadataBar = $this->cmf->getMetadataFor(MetadataFilterTestEntityBar::class), ); $metadatas = $originalMetadatas; @@ -97,9 +97,9 @@ public function testFilterWithString2() : void public function testFilterWithArray() : void { $originalMetadatas = array( - $metadataAaa = $this->cmf->getMetadataFor(MetadataFilterTestEntityAaa::CLASSNAME), - $metadataBbb = $this->cmf->getMetadataFor(MetadataFilterTestEntityBbb::CLASSNAME), - $metadataCcc = $this->cmf->getMetadataFor(MetadataFilterTestEntityCcc::CLASSNAME), + $metadataAaa = $this->cmf->getMetadataFor(MetadataFilterTestEntityAaa::class), + $metadataBbb = $this->cmf->getMetadataFor(MetadataFilterTestEntityBbb::class), + $metadataCcc = $this->cmf->getMetadataFor(MetadataFilterTestEntityCcc::class), ); $metadatas = $originalMetadatas; @@ -117,9 +117,9 @@ public function testFilterWithArray() : void public function testFilterWithRegex() : void { $originalMetadatas = array( - $metadataFoo = $this->cmf->getMetadataFor(MetadataFilterTestEntityFoo::CLASSNAME), - $metadataFooBar = $this->cmf->getMetadataFor(MetadataFilterTestEntityFooBar::CLASSNAME), - $metadataBar = $this->cmf->getMetadataFor(MetadataFilterTestEntityBar::CLASSNAME), + $metadataFoo = $this->cmf->getMetadataFor(MetadataFilterTestEntityFoo::class), + $metadataFooBar = $this->cmf->getMetadataFor(MetadataFilterTestEntityFooBar::class), + $metadataBar = $this->cmf->getMetadataFor(MetadataFilterTestEntityBar::class), ); $metadatas = $originalMetadatas; @@ -143,8 +143,6 @@ public function testFilterWithRegex() : void /** @Entity */ class MetadataFilterTestEntityAaa { - const CLASSNAME = __CLASS__; - /** @Id @Column(type="integer") */ protected $id; } @@ -152,8 +150,6 @@ class MetadataFilterTestEntityAaa /** @Entity */ class MetadataFilterTestEntityBbb { - const CLASSNAME = __CLASS__; - /** @Id @Column(type="integer") */ protected $id; } @@ -161,8 +157,6 @@ class MetadataFilterTestEntityBbb /** @Entity */ class MetadataFilterTestEntityCcc { - const CLASSNAME = __CLASS__; - /** @Id @Column(type="integer") */ protected $id; } @@ -170,8 +164,6 @@ class MetadataFilterTestEntityCcc /** @Entity */ class MetadataFilterTestEntityFoo { - const CLASSNAME = __CLASS__; - /** @Id @Column(type="integer") */ protected $id; } @@ -179,8 +171,6 @@ class MetadataFilterTestEntityFoo /** @Entity */ class MetadataFilterTestEntityBar { - const CLASSNAME = __CLASS__; - /** @Id @Column(type="integer") */ protected $id; } @@ -188,8 +178,6 @@ class MetadataFilterTestEntityBar /** @Entity */ class MetadataFilterTestEntityFooBar { - const CLASSNAME = __CLASS__; - /** @Id @Column(type="integer") */ protected $id; } From 29fe76cced3adf0f8790e976f17846a80053ab09 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 21 Jun 2017 06:20:30 +0200 Subject: [PATCH 345/877] #5715 short array notation --- .../ORM/Tools/Console/MetadataFilterTest.php | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php index 2cc4e5f3293..4873e6ae97f 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php @@ -23,6 +23,7 @@ protected function setUp() : void $driver = $this->createAnnotationDriver(); $em = $this->_getTestEntityManager(); + $em->getConfiguration()->setMetadataDriverImpl($driver); $this->cmf = new DisconnectedClassMetadataFactory(); @@ -31,13 +32,13 @@ protected function setUp() : void public function testFilterWithEmptyArray() : void { - $originalMetadatas = array( + $originalMetadatas = [ $metadataAaa = $this->cmf->getMetadataFor(MetadataFilterTestEntityAaa::class), $metadataBbb = $this->cmf->getMetadataFor(MetadataFilterTestEntityBbb::class), - ); + ]; $metadatas = $originalMetadatas; - $metadatas = MetadataFilter::filter($metadatas, array()); + $metadatas = MetadataFilter::filter($metadatas, []); $this->assertContains($metadataAaa, $metadatas); $this->assertContains($metadataBbb, $metadatas); @@ -46,11 +47,11 @@ public function testFilterWithEmptyArray() : void public function testFilterWithString() : void { - $originalMetadatas = array( + $originalMetadatas = [ $metadataAaa = $this->cmf->getMetadataFor(MetadataFilterTestEntityAaa::class), $metadataBbb = $this->cmf->getMetadataFor(MetadataFilterTestEntityBbb::class), $metadataCcc = $this->cmf->getMetadataFor(MetadataFilterTestEntityCcc::class), - ); + ]; $metadatas = $originalMetadatas; $metadatas = MetadataFilter::filter($metadatas, 'MetadataFilterTestEntityAaa'); @@ -79,11 +80,11 @@ public function testFilterWithString() : void public function testFilterWithString2() : void { - $originalMetadatas = array( + $originalMetadatas = [ $metadataFoo = $this->cmf->getMetadataFor(MetadataFilterTestEntityFoo::class), $metadataFooBar = $this->cmf->getMetadataFor(MetadataFilterTestEntityFooBar::class), $metadataBar = $this->cmf->getMetadataFor(MetadataFilterTestEntityBar::class), - ); + ]; $metadatas = $originalMetadatas; $metadatas = MetadataFilter::filter($metadatas, 'MetadataFilterTestEntityFoo'); @@ -96,17 +97,17 @@ public function testFilterWithString2() : void public function testFilterWithArray() : void { - $originalMetadatas = array( + $originalMetadatas = [ $metadataAaa = $this->cmf->getMetadataFor(MetadataFilterTestEntityAaa::class), $metadataBbb = $this->cmf->getMetadataFor(MetadataFilterTestEntityBbb::class), $metadataCcc = $this->cmf->getMetadataFor(MetadataFilterTestEntityCcc::class), - ); + ]; $metadatas = $originalMetadatas; - $metadatas = MetadataFilter::filter($metadatas, array( + $metadatas = MetadataFilter::filter($metadatas, [ 'MetadataFilterTestEntityAaa', 'MetadataFilterTestEntityCcc', - )); + ]); $this->assertContains($metadataAaa, $metadatas); $this->assertNotContains($metadataBbb, $metadatas); @@ -116,11 +117,11 @@ public function testFilterWithArray() : void public function testFilterWithRegex() : void { - $originalMetadatas = array( + $originalMetadatas = [ $metadataFoo = $this->cmf->getMetadataFor(MetadataFilterTestEntityFoo::class), $metadataFooBar = $this->cmf->getMetadataFor(MetadataFilterTestEntityFooBar::class), $metadataBar = $this->cmf->getMetadataFor(MetadataFilterTestEntityBar::class), - ); + ]; $metadatas = $originalMetadatas; $metadatas = MetadataFilter::filter($metadatas, 'Foo$'); From 01d226aff0b9688141e5c5a5bb79f916e0667f91 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 21 Jun 2017 06:21:22 +0200 Subject: [PATCH 346/877] #5715 removed superfluous mapping information --- .../Tests/ORM/Tools/Console/MetadataFilterTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php index 4873e6ae97f..24f3b54a3a8 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/MetadataFilterTest.php @@ -144,41 +144,41 @@ public function testFilterWithRegex() : void /** @Entity */ class MetadataFilterTestEntityAaa { - /** @Id @Column(type="integer") */ + /** @Id @Column */ protected $id; } /** @Entity */ class MetadataFilterTestEntityBbb { - /** @Id @Column(type="integer") */ + /** @Id @Column */ protected $id; } /** @Entity */ class MetadataFilterTestEntityCcc { - /** @Id @Column(type="integer") */ + /** @Id @Column */ protected $id; } /** @Entity */ class MetadataFilterTestEntityFoo { - /** @Id @Column(type="integer") */ + /** @Id @Column */ protected $id; } /** @Entity */ class MetadataFilterTestEntityBar { - /** @Id @Column(type="integer") */ + /** @Id @Column */ protected $id; } /** @Entity */ class MetadataFilterTestEntityFooBar { - /** @Id @Column(type="integer") */ + /** @Id @Column */ protected $id; } From d13327eca23a8cbf39384470cdd48aeddc2ddd3c Mon Sep 17 00:00:00 2001 From: Sergey Fedotov Date: Thu, 21 Apr 2016 18:28:04 +0300 Subject: [PATCH 347/877] Fix undefined index for discriminator column in SchemaTool --- lib/Doctrine/ORM/Tools/SchemaTool.php | 2 +- .../Tests/ORM/Tools/SchemaToolTest.php | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 9ee27c84d4c..007ac85a8b7 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -358,7 +358,7 @@ private function addDiscriminatorColumnDefinition($class, Table $table) $discrColumn = $class->discriminatorColumn; if ( ! isset($discrColumn['type']) || - (strtolower($discrColumn['type']) == 'string' && $discrColumn['length'] === null) + (strtolower($discrColumn['type']) == 'string' && ! isset($discrColumn['length'])) ) { $discrColumn['type'] = 'string'; $discrColumn['length'] = 255; diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php index 7bae933a635..50ae0347fe8 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Tools; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs; use Doctrine\ORM\Tools\Event\GenerateSchemaTableEventArgs; use Doctrine\ORM\Tools\SchemaTool; @@ -163,6 +164,26 @@ public function testRemoveUniqueIndexOverruledByPrimaryKey() $this->assertCount(1, $indexes, "there should be only one index"); $this->assertTrue(current($indexes)->isPrimary(), "index should be primary"); } + + public function testSetDiscriminatorColumnWithoutLength() + { + $em = $this->_getTestEntityManager(); + $schemaTool = new SchemaTool($em); + $metadata = $em->getClassMetadata(__NAMESPACE__ . '\\FirstEntity'); + + $metadata->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_SINGLE_TABLE); + $metadata->setDiscriminatorColumn(['name' => 'discriminator', 'type' => 'string']); + + $schema = $schemaTool->getSchemaFromMetadata([$metadata]); + + $this->assertTrue($schema->hasTable('first_entity')); + $table = $schema->getTable('first_entity'); + + $this->assertTrue($table->hasColumn('discriminator')); + $column = $table->getColumn('discriminator'); + + $this->assertEquals(255, $column->getLength()); + } } /** From 6e9c1d8a4bc6958d9dd1b11204260d5efc41304a Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 21 Jun 2017 06:34:45 +0200 Subject: [PATCH 348/877] #5798 adding `void` test method return declaration, using `::class` reference over string reference --- tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php index 50ae0347fe8..1164ae219a2 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php @@ -165,11 +165,11 @@ public function testRemoveUniqueIndexOverruledByPrimaryKey() $this->assertTrue(current($indexes)->isPrimary(), "index should be primary"); } - public function testSetDiscriminatorColumnWithoutLength() + public function testSetDiscriminatorColumnWithoutLength() : void { $em = $this->_getTestEntityManager(); $schemaTool = new SchemaTool($em); - $metadata = $em->getClassMetadata(__NAMESPACE__ . '\\FirstEntity'); + $metadata = $em->getClassMetadata(FirstEntity::class); $metadata->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_SINGLE_TABLE); $metadata->setDiscriminatorColumn(['name' => 'discriminator', 'type' => 'string']); From 633a4420465cd1da4d75b21448562cece32ac50e Mon Sep 17 00:00:00 2001 From: Tomasz Darmetko Date: Mon, 6 Mar 2017 19:39:27 +0100 Subject: [PATCH 349/877] Add path expresion to QueryException::associationPathInverseSideNotSupported() --- lib/Doctrine/ORM/Query/QueryException.php | 8 +++++--- lib/Doctrine/ORM/Query/SqlWalker.php | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Query/QueryException.php b/lib/Doctrine/ORM/Query/QueryException.php index 8245722a91b..bde84579eca 100644 --- a/lib/Doctrine/ORM/Query/QueryException.php +++ b/lib/Doctrine/ORM/Query/QueryException.php @@ -204,13 +204,15 @@ public static function overwritingJoinConditionsNotYetSupported($assoc) } /** + * @param object $pathExpr + * * @return QueryException */ - public static function associationPathInverseSideNotSupported() + public static function associationPathInverseSideNotSupported($pathExpr) { return new self( - "A single-valued association path expression to an inverse side is not supported". - " in DQL queries. Use an explicit join instead." + "A single-valued association path expression to an inverse side is not supported in DQL queries. " . + "Instead of '" . $pathExpr->identificationVariable . "." . $pathExpr->field . "' use an explicit join." ); } diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index a4b5089e859..269859528c7 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -671,7 +671,7 @@ public function walkPathExpression($pathExpr) $assoc = $class->associationMappings[$fieldName]; if ( ! $assoc['isOwningSide']) { - throw QueryException::associationPathInverseSideNotSupported(); + throw QueryException::associationPathInverseSideNotSupported($pathExpr); } // COMPOSITE KEYS NOT (YET?) SUPPORTED From b21cb3e2a0ef3e2da8fee00ea3bb157ef6a6ce7b Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 21 Jun 2017 08:16:24 +0200 Subject: [PATCH 350/877] #6325 adding IDE hints, type hints, replacing double quotes with single quotes --- lib/Doctrine/ORM/Query/QueryException.php | 10 ++++++---- lib/Doctrine/ORM/Query/SqlWalker.php | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Query/QueryException.php b/lib/Doctrine/ORM/Query/QueryException.php index bde84579eca..b78e27bcfee 100644 --- a/lib/Doctrine/ORM/Query/QueryException.php +++ b/lib/Doctrine/ORM/Query/QueryException.php @@ -19,6 +19,8 @@ namespace Doctrine\ORM\Query; +use Doctrine\ORM\Query\AST\PathExpression; + /** * Description of QueryException. * @@ -204,15 +206,15 @@ public static function overwritingJoinConditionsNotYetSupported($assoc) } /** - * @param object $pathExpr + * @param PathExpression $pathExpr * * @return QueryException */ - public static function associationPathInverseSideNotSupported($pathExpr) + public static function associationPathInverseSideNotSupported(PathExpression $pathExpr) { return new self( - "A single-valued association path expression to an inverse side is not supported in DQL queries. " . - "Instead of '" . $pathExpr->identificationVariable . "." . $pathExpr->field . "' use an explicit join." + 'A single-valued association path expression to an inverse side is not supported in DQL queries. ' . + 'Instead of "' . $pathExpr->identificationVariable . '.' . $pathExpr->field . '" use an explicit join.' ); } diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 269859528c7..98f58ad8c69 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -644,6 +644,7 @@ public function walkPathExpression($pathExpr) { $sql = ''; + /* @var $pathExpr Query\AST\PathExpression */ switch ($pathExpr->type) { case AST\PathExpression::TYPE_STATE_FIELD: $fieldName = $pathExpr->field; From 9cfdf1ef811be8bb55e33617c935c16ebe3e2c35 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 21 Jun 2017 08:20:20 +0200 Subject: [PATCH 351/877] #6325 documenting minor BC break introduced by adding a required parameter to the exception named constructor --- UPGRADE.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index 8aba870c642..a502c872e6b 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -2,6 +2,11 @@ ## Minor BC BREAK: removed `Doctrine\ORM\Query\Parser#isInternalFunction` +Method `Doctrine\ORM\Query\QueryException::associationPathInverseSideNotSupported` +now has a required parameter `$pathExpr`. + +## Minor BC BREAK: removed `Doctrine\ORM\Query\Parser#isInternalFunction` + Method `Doctrine\ORM\Query\Parser#isInternalFunction` was removed because the distinction between internal function and user defined DQL was removed. [#6500](https://github.com/doctrine/doctrine2/pull/6500) From b446afd93716ea0e5a388d1b929d14ef41c51035 Mon Sep 17 00:00:00 2001 From: NateC Date: Wed, 24 Feb 2016 17:13:25 -0600 Subject: [PATCH 352/877] Updating the Getting Started guide's documentation --- docs/en/tutorials/getting-started.rst | 262 ++++++++++++-------------- 1 file changed, 125 insertions(+), 137 deletions(-) diff --git a/docs/en/tutorials/getting-started.rst b/docs/en/tutorials/getting-started.rst index 5cbcfb17059..605b1a01785 100644 --- a/docs/en/tutorials/getting-started.rst +++ b/docs/en/tutorials/getting-started.rst @@ -14,7 +14,7 @@ Guide Assumptions ----------------- This guide is designed for beginners that haven't worked with Doctrine ORM -before. There are some prerequesites for the tutorial that have to be +before. There are some prerequisites for the tutorial that have to be installed: - PHP (latest stable version) @@ -118,8 +118,8 @@ Add the following directories: Obtaining the EntityManager --------------------------- -Doctrine's public interface is the EntityManager, it provides the -access point to the complete lifecycle management of your entities +Doctrine's public interface is through the ``EntityManager``. This class +provides access points to the complete lifecycle management for your entities, and transforms entities from and back to persistence. You have to configure and create it to use your entities with Doctrine 2. I will show the configuration steps and then discuss them step by @@ -150,8 +150,8 @@ step: // obtaining the entity manager $entityManager = EntityManager::create($conn, $config); -The first require statement sets up the autoloading capabilities of Doctrine -using the Composer autoload. +The require_once statement sets up the class autoloading for Doctrine and +its dependencies using Composer's autoloader. The second block consists of the instantiation of the ORM ``Configuration`` object using the Setup helper. It assumes a bunch @@ -159,8 +159,8 @@ of defaults that you don't have to bother about for now. You can read up on the configuration details in the :doc:`reference chapter on configuration <../reference/configuration>`. -The third block shows the configuration options required to connect -to a database, in my case a file-based sqlite database. All the +The third block shows the configuration options required to connect to +a database. In this case, we'll use a file-based SQLite database. All the configuration options for all the shipped drivers are given in the `DBAL Configuration section of the manual `_. @@ -170,15 +170,10 @@ factory method. Generating the Database Schema ------------------------------ -Now that we have defined the Metadata mappings and bootstrapped the -EntityManager we want to generate the relational database schema -from it. Doctrine has a Command-Line Interface that allows you to -access the SchemaTool, a component that generates the required -tables to work with the metadata. - -For the command-line tool to work a cli-config.php file has to be -present in the project root directory, where you will execute the -doctrine command. Its a fairly simple file: +Doctrine has a command-line interface that allows you to access the SchemaTool, +a component that can generate a relational database schema based entirely on the +defined entity classes and their metadata. For this tool to work, a +cli-config.php file must exist in the project root directory: .. code-block:: php @@ -188,40 +183,38 @@ doctrine command. Its a fairly simple file: return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($entityManager); -You can then change into your project directory and call the -Doctrine command-line tool: +Change into your project directory and call the Doctrine command-line tool: :: $ cd project/ $ vendor/bin/doctrine orm:schema-tool:create -At this point no entity metadata exists in `src` so you will see a message like -"No Metadata Classes to process." Don't worry, we'll create a Product entity and -corresponding metadata in the next section. - -You should be aware that during the development process you'll periodically need -to update your database schema to be in sync with your Entities metadata. +Since we haven't added any entity metadata in `src` yet, you'll see a message +stating "No Metadata Classes to process." In the next section, we'll create a +Product entity along with the corresponding metadata, and run this command again. -You can easily recreate the database: +Note that as you modify your entities' metadata during the development process, +you'll need to update your database schema to stay in sync with the metadata. +You can rasily recreate the database using the following commands: :: $ vendor/bin/doctrine orm:schema-tool:drop --force $ vendor/bin/doctrine orm:schema-tool:create -Or use the update functionality: +Or you can use the update functionality: :: $ vendor/bin/doctrine orm:schema-tool:update --force The updating of databases uses a Diff Algorithm for a given -Database Schema, a cornerstone of the ``Doctrine\DBAL`` package, +Database Schema. This is a cornerstone of the ``Doctrine\DBAL`` package, which can even be used without the Doctrine ORM package. -Starting with the Product -------------------------- +Starting with the Product Entity +-------------------------------- We start with the simplest entity, the Product. Create a ``src/Product.php`` file to contain the ``Product`` entity definition: @@ -257,9 +250,9 @@ entity definition: } } -Note that all fields are set to protected (not public) with a -mutator (getter and setter) defined for every field except $id. -The use of mutators allows Doctrine to hook into calls which +When creating entity classes, all of the fields should be protected or private +(not public), with getter and setter methods for each one (except $id). +The use of mutators allows Doctrine to hook into calls which manipulate the entities in ways that it could not if you just directly set the values with ``entity#field = foo;`` @@ -274,9 +267,10 @@ language. The metadata language describes how entities, their properties and references should be persisted and what constraints should be applied to them. -Metadata for entities are configured using a XML, YAML or Docblock Annotations. -This Getting Started Guide will show the mappings for all Mapping Drivers. -References in the text will be made to the XML mapping. +Metadata for an Entity can be configured using DocBlock annotations directly +in the Entity class itself, or in an external XML or YAML file. This Getting +Started guide will demonstrate metadata mappings using all three methods, +but you only need to choose one. .. configuration-block:: @@ -332,27 +326,28 @@ References in the text will be made to the XML mapping. The top-level ``entity`` definition tag specifies information about the class and table-name. The primitive type ``Product#name`` is defined as a ``field`` attribute. The ``id`` property is defined with -the ``id`` tag, this has a ``generator`` tag nested inside which -defines that the primary key generation mechanism automatically -uses the database platforms native id generation strategy (for -example AUTO INCREMENT in the case of MySql or Sequences in the +the ``id`` tag. It has a ``generator`` tag nested inside, which +specifies that the primary key generation mechanism should automatically +use the database platform's native id generation strategy (for +example, AUTO INCREMENT in the case of MySql, or Sequences in the case of PostgreSql and Oracle). -Now that we have defined our first entity, let's update the database: +Now that we have defined our first entity and its metadata, +let's update the database schema: :: $ vendor/bin/doctrine orm:schema-tool:update --force --dump-sql -Specifying both flags ``--force`` and ``--dump-sql`` prints and executes the DDL -statements. +Specifying both flags ``--force`` and ``--dump-sql`` will cause the DDL +statements to be executed and then printed to the screen. -Now create a new script that will insert products into the database: +Now, we'll create a new script to insert products into the database: .. code-block:: php require_once "bootstrap.php"; $newProductName = $argv[1]; @@ -372,22 +367,19 @@ Call this script from the command-line to see how new products are created: $ php create_product.php ORM $ php create_product.php DBAL -What is happening here? Using the ``Product`` is pretty standard OOP. +What is happening here? Using the ``Product`` class is pretty standard OOP. The interesting bits are the use of the ``EntityManager`` service. To -notify the EntityManager that a new entity should be inserted into the database -you have to call ``persist()``. To initiate a transaction to actually perform -the insertion, You have to explicitly call ``flush()`` on the ``EntityManager``. - -This distinction between persist and flush is allows to aggregate all writes -(INSERT, UPDATE, DELETE) into one single transaction, which is executed when -flush is called. Using this approach the write-performance is significantly -better than in a scenario where updates are done for each entity in isolation. +notify the EntityManager that a new entity should be inserted into the database, +you have to call ``persist()``. To initiate a transaction to actually *perform* +the insertion, you have to explicitly call ``flush()`` on the ``EntityManager``. -Doctrine follows the UnitOfWork pattern which additionally detects all entities -that were fetched and have changed during the request. You don't have to keep track of -entities yourself, when Doctrine already knows about them. +This distinction between persist and flush is what allows the aggregation of +all database writes (INSERT, UPDATE, DELETE) into one single transaction, which +is executed when ``flush()`` is called. Using this approach, the write-performance +is significantly better than in a scenario in which writes are performed on +each entity in isolation. -As a next step we want to fetch a list of all the Products. Let's create a +Next, we'll fetch a list of all the Products in the database. Let's create a new script for this: .. code-block:: php @@ -404,10 +396,10 @@ new script for this: } The ``EntityManager#getRepository()`` method can create a finder object (called -a repository) for every entity. It is provided by Doctrine and contains some -finder methods such as ``findAll()``. +a repository) for every type of entity. It is provided by Doctrine and contains +some finder methods like ``findAll()``. -Let's continue with displaying the name of a product based on its ID: +Let's continue by creating a script to display the name of a product based on its ID: .. code-block:: php @@ -425,9 +417,13 @@ Let's continue with displaying the name of a product based on its ID: echo sprintf("-%s\n", $product->getName()); -Updating a product name demonstrates the functionality UnitOfWork of pattern -discussed before. We only need to find a product entity and all changes to its -properties are written to the database: +Next we'll update a product's name, given its id. This simple example will +help demonstrate Doctrine's implementation of the UnitOfWork pattern. Doctrine +keeps track of all the entities that were retrieved from the Entity Manager, +and can detect when any of those entities' properties have been modified. +As a result, rather than needing to call ``persist($entity)`` for each individual +entity whose properties were changed, a single call to ``flush()`` at the end of a +request is sufficient to update the database for all of the modified entities. .. code-block:: php @@ -455,9 +451,8 @@ product name changed by calling the ``show_product.php`` script. Adding Bug and User Entities ---------------------------- -We continue with the bug tracker domain, by creating the missing classes -``Bug`` and ``User`` and putting them into ``src/Bug.php`` and -``src/User.php`` respectively. +We continue with the bug tracker example by creating the ``Bug`` and ``User`` +classes. We'll store them in ``src/Bug.php`` and ``src/User.php``, respectively. .. code-block:: php @@ -561,14 +556,15 @@ We continue with the bug tracker domain, by creating the missing classes } } -All of the properties discussed so far are simple string and integer values, -for example the id fields of the entities, their names, description, status and -change dates. Next we will model the dynamic relationships between the entities -by defining the references between entities. +All of the properties we've seen so far are of simple types (integer, string, +and datetime). But now, we'll add properties that will store objects of +specific *entity types* in order to model the relationships between different +entities. -References between objects are foreign keys in the database. You never have to -(and never should) work with the foreign keys directly, only with the objects -that represent the foreign key through their own identity. +At the database level, relationships between entities are represented by foreign +keys. But with Doctrine, you'll never have to (and never should) work with +the foreign keys directly. You should only work with objects that represent +foreign keys through their own identities. For every foreign key you either have a Doctrine ManyToOne or OneToOne association. On the inverse sides of these foreign keys you can have @@ -602,6 +598,7 @@ domain model to match the requirements: assignedToBug($this); $this->engineer = $engineer; } - public function setReporter($reporter) + public function setReporter(User $reporter) { $reporter->addReportedBug($this); $this->reporter = $reporter; @@ -717,15 +713,15 @@ the bi-directional reference: { // ... (previous code) - protected $reportedBugs = null; - protected $assignedBugs = null; + protected $reportedBugs; + protected $assignedBugs; - public function addReportedBug($bug) + public function addReportedBug(Bug $bug) { $this->reportedBugs[] = $bug; } - public function assignedToBug($bug) + public function assignedToBug(Bug $bug) { $this->assignedBugs[] = $bug; } @@ -741,7 +737,7 @@ You can see from ``User#addReportedBug()`` and ``User#assignedToBug()`` that using this method in userland alone would not add the Bug to the collection of the owning side in ``Bug#reporter`` or ``Bug#engineer``. Using these methods and -calling Doctrine for persistence would not update the collections +calling Doctrine for persistence would not update the Collections' representation in the database. Only using ``Bug#setEngineer()`` or ``Bug#setReporter()`` @@ -749,7 +745,7 @@ correctly saves the relation information. The ``Bug#reporter`` and ``Bug#engineer`` properties are Many-To-One relations, which point to a User. In a normalized -relational model the foreign key is saved on the Bug's table, hence +relational model, the foreign key is saved on the Bug's table, hence in our object-relation model the Bug is at the owning side of the relation. You should always make sure that the use-cases of your domain model should drive which side is an inverse or owning one in @@ -758,7 +754,7 @@ or an engineer is assigned to the bug, we don't want to update the User to persist the reference, but the Bug. This is the case with the Bug being at the owning side of the relation. -Bugs reference Products by an uni-directional ManyToMany relation in +Bugs reference Products by a uni-directional ManyToMany relation in the database that points from Bugs to Products. .. code-block:: php @@ -771,7 +767,7 @@ the database that points from Bugs to Products. protected $products = null; - public function assignToProduct($product) + public function assignToProduct(Product $product) { $this->products[] = $product; } @@ -783,7 +779,7 @@ the database that points from Bugs to Products. } We are now finished with the domain model given the requirements. -Lets add metadata mappings for the ``User`` and ``Bug`` as we did for +Lets add metadata mappings for the ``Bug`` entity, as we did for the ``Product`` before: .. configuration-block:: @@ -890,13 +886,13 @@ For the "created" field we have used the ``datetime`` type, which translates the YYYY-mm-dd HH:mm:ss database format into a PHP DateTime instance and back. -After the field definitions the two qualified references to the +After the field definitions, the two qualified references to the user entity are defined. They are created by the ``many-to-one`` tag. The class name of the related entity has to be specified with the ``target-entity`` attribute, which is enough information for the database mapper to access the foreign-table. Since ``reporter`` and ``engineer`` are on the owning side of a -bi-directional relation we also have to specify the ``inversed-by`` +bi-directional relation, we also have to specify the ``inversed-by`` attribute. They have to point to the field names on the inverse side of the relationship. We will see in the next example that the ``inversed-by`` attribute has a counterpart ``mapped-by`` which makes that @@ -907,7 +903,7 @@ holds all products where the specific bug occurs. Again you have to define the ``target-entity`` and ``field`` attributes on the ``many-to-many`` tag. -The last missing definition is that of the User entity: +Finally, we'll add metadata mappings for the ``User`` entity. .. configuration-block:: @@ -934,13 +930,13 @@ The last missing definition is that of the User entity: /** * @OneToMany(targetEntity="Bug", mappedBy="reporter") - * @var Bug[] + * @var Bug[] An ArrayCollection of Bug objects. **/ protected $reportedBugs = null; /** * @OneToMany(targetEntity="Bug", mappedBy="engineer") - * @var Bug[] + * @var Bug[] An ArrayCollection of Bug objects. **/ protected $assignedBugs = null; @@ -996,10 +992,7 @@ means the join details have already been defined on the owning side. Therefore we only have to specify the property on the Bug class that holds the owning sides. -This example has a fair overview of the most basic features of the -metadata definition language. - -Update your database running: +Update your database schema by running: :: $ vendor/bin/doctrine orm:schema-tool:update --force @@ -1008,7 +1001,8 @@ Update your database running: Implementing more Requirements ------------------------------ -For starters we need to create user entities: +So far, we've seen the most basic features of the metadata definition language. +To explore additional functionality, let's first create new ``User`` entities: .. code-block:: php @@ -1032,23 +1026,22 @@ Now call: $ php create_user.php beberlei -We now have the data to create a bug and the code for this scenario may look -like this: +We now have the necessary data to create a new Bug entity: .. code-block:: php require_once "bootstrap.php"; - $theReporterId = $argv[1]; - $theDefaultEngineerId = $argv[2]; + $reporterId = $argv[1]; + $engineerId = $argv[2]; $productIds = explode(",", $argv[3]); - $reporter = $entityManager->find("User", $theReporterId); - $engineer = $entityManager->find("User", $theDefaultEngineerId); + $reporter = $entityManager->find("User", $reporterId); + $engineer = $entityManager->find("User", $engineerId); if (!$reporter || !$engineer) { - echo "No reporter and/or engineer found for the input.\n"; + echo "No reporter and/or engineer found for the given id(s).\n"; exit(1); } @@ -1070,22 +1063,17 @@ like this: echo "Your new Bug Id: ".$bug->getId()."\n"; -Since we only have one user and product, probably with the ID of 1, we can call this script with: +Since we only have one user and product, probably with the ID of 1, we can +call this script as follows: :: php create_bug.php 1 1 1 -This is the first contact with the read API of the EntityManager, -showing that a call to ``EntityManager#find($name, $id)`` returns a -single instance of an entity queried by primary key. Besides this -we see the persist + flush pattern again to save the Bug into the -database. - -See how simple relating Bug, Reporter, Engineer and Products is -done by using the discussed methods in the "A first prototype" -section. The UnitOfWork will detect this relationship when flush is -called and relate them in the database appropriately. +See how simple it is to relate a Bug, Reporter, Engineer and Products? +Also recall that thanks to the UnitOfWork pattern, Doctrine will detect +these relations and update all of the modified entities in the database +automatically when ``flush()`` is called. Queries for Application Use-Cases --------------------------------- @@ -1094,7 +1082,7 @@ List of Bugs ~~~~~~~~~~~~ Using the previous examples we can fill up the database quite a -bit, however we now need to discuss how to query the underlying +bit. However, we now need to discuss how to query the underlying mapper for the required view representations. When opening the application, bugs can be paginated through a list-view, which is the first read-only use-case: @@ -1225,7 +1213,7 @@ write scenarios: .. code-block:: php require_once "bootstrap.php"; $theBugId = $argv[1]; @@ -1300,7 +1288,7 @@ and usage of bound parameters: .. code-block:: php require_once "bootstrap.php"; $theUserId = $argv[1]; @@ -1366,7 +1354,7 @@ should be able to close a bug. This looks like: .. code-block:: php require_once "bootstrap.php"; $theBugId = $argv[1]; From 30256e7a085c4681cbc8a6b49e9caa791ca9f4a9 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 21 Jun 2017 09:34:16 +0200 Subject: [PATCH 353/877] Refactor a bit the SqlWalker modifications --- lib/Doctrine/ORM/Query/SqlWalker.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index e308b7de7a3..0557faf318c 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -2280,7 +2280,6 @@ public function walkResultVariable($resultVariable) */ private function getChildDiscriminatorsFromClassMetadata(ClassMetadataInfo $discrClass, AST\InstanceOfExpression $instanceOfExpr) { - $knownSubclasses = array_flip($discrClass->subClasses); $sqlParameterList = []; $discriminators = []; foreach ($instanceOfExpr->value as $parameter) { @@ -2292,15 +2291,13 @@ private function getChildDiscriminatorsFromClassMetadata(ClassMetadataInfo $disc continue; } - // Trim first backslash - $parameter = ltrim($parameter, '\\'); + $metadata = $this->em->getClassMetadata($parameter); - if ($parameter !== $discrClass->name && ! array_key_exists($parameter, $knownSubclasses)) { + if ($metadata->getReflectionClass()->isSubclassOf($discrClass->name)) { throw QueryException::instanceOfUnrelatedClass($parameter, $discrClass->name); } // Include discriminators for parameter class and its subclass - $metadata = $this->em->getClassMetadata($parameter); $hierarchyClasses = $metadata->subClasses; $hierarchyClasses[] = $metadata->name; @@ -2308,15 +2305,13 @@ private function getChildDiscriminatorsFromClassMetadata(ClassMetadataInfo $disc $currentMetadata = $this->em->getClassMetadata($class); $currentDiscriminator = $currentMetadata->discriminatorValue; - if (is_string($currentDiscriminator) && ! array_key_exists($currentDiscriminator, $discriminators)) { - $discriminators[$currentDiscriminator] = true; + if (null !== $currentDiscriminator && ! array_key_exists($currentDiscriminator, $discriminators)) { + $discriminators[$currentDiscriminator] = null; } } } - foreach (array_keys($discriminators) as $dis) { - $sqlParameterList[] = $this->conn->quote($dis); - } + $sqlParameterList = array_map([$this->conn, 'quote'], array_keys($discriminators)); return '(' . implode(', ', $sqlParameterList) . ')'; } From 11c54b7715ced7cffbf44f50e4833ea3b6a8ff19 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 21 Jun 2017 10:11:31 +0200 Subject: [PATCH 354/877] Apply additional fixes to the SqlWalker to fix tests --- lib/Doctrine/ORM/Query/SqlWalker.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 0557faf318c..d94f8d9c683 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -2293,7 +2293,7 @@ private function getChildDiscriminatorsFromClassMetadata(ClassMetadataInfo $disc $metadata = $this->em->getClassMetadata($parameter); - if ($metadata->getReflectionClass()->isSubclassOf($discrClass->name)) { + if (! $metadata->getReflectionClass()->isSubclassOf($discrClass->name)) { throw QueryException::instanceOfUnrelatedClass($parameter, $discrClass->name); } @@ -2305,13 +2305,15 @@ private function getChildDiscriminatorsFromClassMetadata(ClassMetadataInfo $disc $currentMetadata = $this->em->getClassMetadata($class); $currentDiscriminator = $currentMetadata->discriminatorValue; - if (null !== $currentDiscriminator && ! array_key_exists($currentDiscriminator, $discriminators)) { + if (null !== $currentDiscriminator) { $discriminators[$currentDiscriminator] = null; } } } - $sqlParameterList = array_map([$this->conn, 'quote'], array_keys($discriminators)); + foreach (array_keys($discriminators) as $dis) { + $sqlParameterList[] = $this->conn->quote($dis); + } return '(' . implode(', ', $sqlParameterList) . ')'; } From 8b9c29738d22729019c95fa75cf2c272cab7f75c Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 21 Jun 2017 10:26:31 +0200 Subject: [PATCH 355/877] Put all tests classes in a single namespace --- lib/Doctrine/ORM/Query/SqlWalker.php | 2 +- .../Ticket4646InstanceOfAbstractTest.php | 162 ++++++------ .../Ticket4646InstanceOfMultiLevelTest.php | 236 +++++++++--------- .../Ticket/Ticket4646InstanceOfTest.php | 175 +++++++------ 4 files changed, 279 insertions(+), 296 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index d94f8d9c683..0bf999ed531 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -2293,7 +2293,7 @@ private function getChildDiscriminatorsFromClassMetadata(ClassMetadataInfo $disc $metadata = $this->em->getClassMetadata($parameter); - if (! $metadata->getReflectionClass()->isSubclassOf($discrClass->name)) { + if ($metadata->getName() !== $discrClass->name && ! $metadata->getReflectionClass()->isSubclassOf($discrClass->name)) { throw QueryException::instanceOfUnrelatedClass($parameter, $discrClass->name); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php index b17ca2c2d3c..090a172a93f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php @@ -1,114 +1,108 @@ _schemaTool->createSchema([ - $this->_em->getClassMetadata(Person::class), - $this->_em->getClassMetadata(Employee::class), - ]); - } + parent::setUp(); + + $this->_schemaTool->createSchema([ + $this->_em->getClassMetadata(PersonTicket4646Abstract::class), + $this->_em->getClassMetadata(EmployeeTicket4646Abstract::class), + ]); + } - public function testInstanceOf() - { - $this->loadData(); + public function testInstanceOf() + { + $this->loadData(); - $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Person p - WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Person'; - $query = $this->_em->createQuery($dql); - $result = $query->getResult(); + $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646Abstract p + WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646Abstract'; + $query = $this->_em->createQuery($dql); + $result = $query->getResult(); - $this->assertCount(1, $result); + $this->assertCount(1, $result); - foreach ($result as $r) { - $this->assertInstanceOf(Person::class, $r); - $this->assertInstanceOf(Employee::class, $r); - $this->assertSame('bar', $r->getName()); - } + foreach ($result as $r) { + $this->assertInstanceOf(PersonTicket4646Abstract::class, $r); + $this->assertInstanceOf(EmployeeTicket4646Abstract::class, $r); + $this->assertSame('bar', $r->getName()); } + } - private function loadData() - { - $employee = new Employee(); - $employee->setName('bar'); - $employee->setDepartement('qux'); + private function loadData() + { + $employee = new EmployeeTicket4646Abstract(); + $employee->setName('bar'); + $employee->setDepartement('qux'); - $this->_em->persist($employee); + $this->_em->persist($employee); - $this->_em->flush($employee); - } + $this->_em->flush($employee); } } -namespace Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest { +/** + * @Entity() + * @Table(name="instance_of_abstract_test_person") + * @InheritanceType(value="JOINED") + * @DiscriminatorColumn(name="kind", type="string") + * @DiscriminatorMap(value={ + * "employee": EmployeeTicket4646Abstract::class + * }) + */ +abstract class PersonTicket4646Abstract +{ + /** + * @Id() + * @GeneratedValue() + * @Column(type="integer") + */ + private $id; /** - * @Entity() - * @Table(name="instance_of_abstract_test_person") - * @InheritanceType(value="JOINED") - * @DiscriminatorColumn(name="kind", type="string") - * @DiscriminatorMap(value={ - * "employee": Employee::class - * }) + * @Column(type="string") */ - abstract class Person + private $name; + + public function getId() { - /** - * @Id() - * @GeneratedValue() - * @Column(type="integer") - */ - private $id; - - /** - * @Column(type="string") - */ - private $name; - - public function getId() - { - return $this->id; - } + return $this->id; + } - public function getName() - { - return $this->name; - } + public function getName() + { + return $this->name; + } - public function setName($name) - { - $this->name = $name; - } + public function setName($name) + { + $this->name = $name; } +} +/** + * @Entity() + * @Table(name="instance_of_abstract_test_employee") + */ +class EmployeeTicket4646Abstract extends PersonTicket4646Abstract +{ /** - * @Entity() - * @Table(name="instance_of_abstract_test_employee") + * @Column(type="string") */ - class Employee extends Person + private $departement; + + public function getDepartement() { - /** - * @Column(type="string") - */ - private $departement; - - public function getDepartement() - { - return $this->departement; - } + return $this->departement; + } - public function setDepartement($departement) - { - $this->departement = $departement; - } + public function setDepartement($departement) + { + $this->departement = $departement; } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php index 79f0d5363c0..649de27bb5b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php @@ -1,156 +1,150 @@ _schemaTool->createSchema([ - $this->_em->getClassMetadata(Person::class), - $this->_em->getClassMetadata(Employee::class), - $this->_em->getClassMetadata(Engineer::class), - ]); - } + parent::setUp(); + + $this->_schemaTool->createSchema([ + $this->_em->getClassMetadata(PersonTicket4646MultiLevel::class), + $this->_em->getClassMetadata(EmployeeTicket4646MultiLevel::class), + $this->_em->getClassMetadata(EngineerTicket4646MultiLevel::class), + ]); + } - public function testInstanceOf() - { - $this->loadData(); - - $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Person p - WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Person'; - $query = $this->_em->createQuery($dql); - $result = $query->getResult(); - - $this->assertCount(3, $result); - - foreach ($result as $r) { - $this->assertInstanceOf(Person::class, $r); - if ($r instanceof Engineer) { - $this->assertEquals('foobar', $r->getName()); - $this->assertEquals('doctrine', $r->getSpecialization()); - } elseif ($r instanceof Employee) { - $this->assertEquals('bar', $r->getName()); - $this->assertEquals('qux', $r->getDepartement()); - } else { - $this->assertEquals('foo', $r->getName()); - } + public function testInstanceOf() + { + $this->loadData(); + + $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646MultiLevel p + WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646MultiLevel'; + $query = $this->_em->createQuery($dql); + $result = $query->getResult(); + + $this->assertCount(3, $result); + + foreach ($result as $r) { + $this->assertInstanceOf(PersonTicket4646MultiLevel::class, $r); + if ($r instanceof EngineerTicket4646MultiLevel) { + $this->assertEquals('foobar', $r->getName()); + $this->assertEquals('doctrine', $r->getSpecialization()); + } elseif ($r instanceof EmployeeTicket4646MultiLevel) { + $this->assertEquals('bar', $r->getName()); + $this->assertEquals('qux', $r->getDepartement()); + } else { + $this->assertEquals('foo', $r->getName()); } } + } - private function loadData() - { - $person = new Person(); - $person->setName('foo'); + private function loadData() + { + $person = new PersonTicket4646MultiLevel(); + $person->setName('foo'); - $employee = new Employee(); - $employee->setName('bar'); - $employee->setDepartement('qux'); + $employee = new EmployeeTicket4646MultiLevel(); + $employee->setName('bar'); + $employee->setDepartement('qux'); - $engineer = new Engineer(); - $engineer->setName('foobar'); - $engineer->setDepartement('dep'); - $engineer->setSpecialization('doctrine'); + $engineer = new EngineerTicket4646MultiLevel(); + $engineer->setName('foobar'); + $engineer->setDepartement('dep'); + $engineer->setSpecialization('doctrine'); - $this->_em->persist($person); - $this->_em->persist($employee); - $this->_em->persist($engineer); + $this->_em->persist($person); + $this->_em->persist($employee); + $this->_em->persist($engineer); - $this->_em->flush(array($person, $employee, $engineer)); - } + $this->_em->flush(array($person, $employee, $engineer)); } } -namespace Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest { +/** + * @Entity() + * @Table(name="instance_of_multi_level_test_person") + * @InheritanceType(value="JOINED") + * @DiscriminatorColumn(name="kind", type="string") + * @DiscriminatorMap(value={ + * "person": "Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646MultiLevel", + * "employee": "Doctrine\Tests\ORM\Functional\Ticket\EmployeeTicket4646MultiLevel", + * "engineer": "Doctrine\Tests\ORM\Functional\Ticket\EngineerTicket4646MultiLevel", + * }) + */ +class PersonTicket4646MultiLevel +{ /** - * @Entity() - * @Table(name="instance_of_multi_level_test_person") - * @InheritanceType(value="JOINED") - * @DiscriminatorColumn(name="kind", type="string") - * @DiscriminatorMap(value={ - * "person": "Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Person", - * "employee": "Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Employee", - * "engineer": "Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Engineer", - * }) + * @Id() + * @GeneratedValue() + * @Column(type="integer") */ - class Person + private $id; + + /** + * @Column(type="string") + */ + private $name; + + public function getId() { - /** - * @Id() - * @GeneratedValue() - * @Column(type="integer") - */ - private $id; - - /** - * @Column(type="string") - */ - private $name; - - public function getId() - { - return $this->id; - } + return $this->id; + } - public function getName() - { - return $this->name; - } + public function getName() + { + return $this->name; + } - public function setName($name) - { - $this->name = $name; - } + public function setName($name) + { + $this->name = $name; } +} +/** + * @Entity() + * @Table(name="instance_of_multi_level_employee") + */ +class EmployeeTicket4646MultiLevel extends PersonTicket4646MultiLevel +{ /** - * @Entity() - * @Table(name="instance_of_multi_level_employee") + * @Column(type="string") */ - class Employee extends Person + private $departement; + + public function getDepartement() { - /** - * @Column(type="string") - */ - private $departement; - - public function getDepartement() - { - return $this->departement; - } + return $this->departement; + } - public function setDepartement($departement) - { - $this->departement = $departement; - } + public function setDepartement($departement) + { + $this->departement = $departement; } +} +/** + * @Entity() + * @Table(name="instance_of_multi_level_engineer") + */ +class EngineerTicket4646MultiLevel extends EmployeeTicket4646MultiLevel +{ /** - * @Entity() - * @Table(name="instance_of_multi_level_engineer") + * @Column(type="string") */ - class Engineer extends Employee + private $specialization; + + public function getSpecialization() { - /** - * @Column(type="string") - */ - private $specialization; - - public function getSpecialization() - { - return $this->specialization; - } + return $this->specialization; + } - public function setSpecialization($specialization) - { - $this->specialization = $specialization; - } + public function setSpecialization($specialization) + { + $this->specialization = $specialization; } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php index 35d4afdac66..a83e6e7338b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php @@ -1,121 +1,116 @@ _schemaTool->createSchema([ - $this->_em->getClassMetadata(Person::class), - $this->_em->getClassMetadata(Employee::class), - ]); - } + parent::setUp(); + + $this->_schemaTool->createSchema([ + $this->_em->getClassMetadata(PersonTicket4646::class), + $this->_em->getClassMetadata(EmployeeTicket4646::class), + ]); + } - public function testInstanceOf() - { - $this->loadData(); + public function testInstanceOf() + { + $this->loadData(); - $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\InstanceOfTest\Person p - WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\InstanceOfTest\Person'; - $query = $this->_em->createQuery($dql); - $result = $query->getResult(); + $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646 p + WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646'; + $query = $this->_em->createQuery($dql); + $result = $query->getResult(); - $this->assertCount(2, $result); + $this->assertCount(2, $result); - foreach ($result as $r) { - $this->assertInstanceOf(Person::class, $r); - if ($r instanceof Employee) { - $this->assertEquals('bar', $r->getName()); - } else { - $this->assertEquals('foo', $r->getName()); - } + foreach ($result as $r) { + $this->assertInstanceOf(PersonTicket4646::class, $r); + if ($r instanceof EmployeeTicket4646) { + $this->assertEquals('bar', $r->getName()); + } else { + $this->assertEquals('foo', $r->getName()); } } + } - private function loadData() - { - $person = new Person(); - $person->setName('foo'); + private function loadData() + { + $person = new PersonTicket4646(); + $person->setName('foo'); - $employee = new Employee(); - $employee->setName('bar'); - $employee->setDepartement('qux'); + $employee = new EmployeeTicket4646(); + $employee->setName('bar'); + $employee->setDepartement('qux'); - $this->_em->persist($person); - $this->_em->persist($employee); + $this->_em->persist($person); + $this->_em->persist($employee); - $this->_em->flush(array($person, $employee)); - } + $this->_em->flush(array($person, $employee)); } } -namespace Doctrine\Tests\ORM\Functional\InstanceOfTest { +/** + * @Entity() + * @Table(name="instance_of_test_person") + * @InheritanceType(value="JOINED") + * @DiscriminatorColumn(name="kind", type="string") + * @DiscriminatorMap(value={ + * "person": "Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646", + * "employee": "Doctrine\Tests\ORM\Functional\Ticket\EmployeeTicket4646" + * }) + */ +class PersonTicket4646 +{ + /** + * @Id() + * @GeneratedValue() + * @Column(type="integer") + */ + private $id; + /** - * @Entity() - * @Table(name="instance_of_test_person") - * @InheritanceType(value="JOINED") - * @DiscriminatorColumn(name="kind", type="string") - * @DiscriminatorMap(value={ - * "person": "Doctrine\Tests\ORM\Functional\InstanceOfTest\Person", - * "employee": "Doctrine\Tests\ORM\Functional\InstanceOfTest\Employee" - * }) + * @Column(type="string") */ - class Person + private $name; + + public function getId() { - /** - * @Id() - * @GeneratedValue() - * @Column(type="integer") - */ - private $id; - - /** - * @Column(type="string") - */ - private $name; - - public function getId() - { - return $this->id; - } + return $this->id; + } - public function getName() - { - return $this->name; - } + public function getName() + { + return $this->name; + } - public function setName($name) - { - $this->name = $name; - } + public function setName($name) + { + $this->name = $name; } +} +/** + * @Entity() + * @Table(name="instance_of_test_employee") + */ +class EmployeeTicket4646 extends PersonTicket4646 +{ /** - * @Entity() - * @Table(name="instance_of_test_employee") + * @Column(type="string") */ - class Employee extends Person + private $departement; + + public function getDepartement() { - /** - * @Column(type="string") - */ - private $departement; - - public function getDepartement() - { - return $this->departement; - } + return $this->departement; + } - public function setDepartement($departement) - { - $this->departement = $departement; - } + public function setDepartement($departement) + { + $this->departement = $departement; } } From ba69cc8f7a0786539b1ead150fa6179ff37aea57 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 21 Jun 2017 13:25:31 +0200 Subject: [PATCH 356/877] Simplify stubs used in tests --- .../Ticket4646InstanceOfAbstractTest.php | 50 +---------- .../Ticket4646InstanceOfMultiLevelTest.php | 83 ++----------------- .../Ticket/Ticket4646InstanceOfTest.php | 58 +------------ 3 files changed, 12 insertions(+), 179 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php index 090a172a93f..f0ea53fe87f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php @@ -18,7 +18,8 @@ protected function setUp() public function testInstanceOf() { - $this->loadData(); + $this->_em->persist(new EmployeeTicket4646Abstract()); + $this->_em->flush(); $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646Abstract p WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646Abstract'; @@ -26,23 +27,7 @@ public function testInstanceOf() $result = $query->getResult(); $this->assertCount(1, $result); - - foreach ($result as $r) { - $this->assertInstanceOf(PersonTicket4646Abstract::class, $r); - $this->assertInstanceOf(EmployeeTicket4646Abstract::class, $r); - $this->assertSame('bar', $r->getName()); - } - } - - private function loadData() - { - $employee = new EmployeeTicket4646Abstract(); - $employee->setName('bar'); - $employee->setDepartement('qux'); - - $this->_em->persist($employee); - - $this->_em->flush($employee); + $this->assertContainsOnlyInstancesOf(PersonTicket4646Abstract::class, $result); } } @@ -64,25 +49,10 @@ abstract class PersonTicket4646Abstract */ private $id; - /** - * @Column(type="string") - */ - private $name; - public function getId() { return $this->id; } - - public function getName() - { - return $this->name; - } - - public function setName($name) - { - $this->name = $name; - } } /** @@ -91,18 +61,4 @@ public function setName($name) */ class EmployeeTicket4646Abstract extends PersonTicket4646Abstract { - /** - * @Column(type="string") - */ - private $departement; - - public function getDepartement() - { - return $this->departement; - } - - public function setDepartement($departement) - { - $this->departement = $departement; - } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php index 649de27bb5b..6e4160b24f2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php @@ -19,7 +19,10 @@ protected function setUp() public function testInstanceOf() { - $this->loadData(); + $this->_em->persist(new PersonTicket4646MultiLevel()); + $this->_em->persist(new EmployeeTicket4646MultiLevel()); + $this->_em->persist(new EngineerTicket4646MultiLevel()); + $this->_em->flush(); $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646MultiLevel p WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646MultiLevel'; @@ -27,40 +30,7 @@ public function testInstanceOf() $result = $query->getResult(); $this->assertCount(3, $result); - - foreach ($result as $r) { - $this->assertInstanceOf(PersonTicket4646MultiLevel::class, $r); - if ($r instanceof EngineerTicket4646MultiLevel) { - $this->assertEquals('foobar', $r->getName()); - $this->assertEquals('doctrine', $r->getSpecialization()); - } elseif ($r instanceof EmployeeTicket4646MultiLevel) { - $this->assertEquals('bar', $r->getName()); - $this->assertEquals('qux', $r->getDepartement()); - } else { - $this->assertEquals('foo', $r->getName()); - } - } - } - - private function loadData() - { - $person = new PersonTicket4646MultiLevel(); - $person->setName('foo'); - - $employee = new EmployeeTicket4646MultiLevel(); - $employee->setName('bar'); - $employee->setDepartement('qux'); - - $engineer = new EngineerTicket4646MultiLevel(); - $engineer->setName('foobar'); - $engineer->setDepartement('dep'); - $engineer->setSpecialization('doctrine'); - - $this->_em->persist($person); - $this->_em->persist($employee); - $this->_em->persist($engineer); - - $this->_em->flush(array($person, $employee, $engineer)); + $this->assertContainsOnlyInstancesOf(PersonTicket4646MultiLevel::class, $result); } } @@ -84,25 +54,10 @@ class PersonTicket4646MultiLevel */ private $id; - /** - * @Column(type="string") - */ - private $name; - public function getId() { return $this->id; } - - public function getName() - { - return $this->name; - } - - public function setName($name) - { - $this->name = $name; - } } /** @@ -111,20 +66,6 @@ public function setName($name) */ class EmployeeTicket4646MultiLevel extends PersonTicket4646MultiLevel { - /** - * @Column(type="string") - */ - private $departement; - - public function getDepartement() - { - return $this->departement; - } - - public function setDepartement($departement) - { - $this->departement = $departement; - } } /** @@ -133,18 +74,4 @@ public function setDepartement($departement) */ class EngineerTicket4646MultiLevel extends EmployeeTicket4646MultiLevel { - /** - * @Column(type="string") - */ - private $specialization; - - public function getSpecialization() - { - return $this->specialization; - } - - public function setSpecialization($specialization) - { - $this->specialization = $specialization; - } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php index a83e6e7338b..363611d4db8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php @@ -18,7 +18,9 @@ protected function setUp() public function testInstanceOf() { - $this->loadData(); + $this->_em->persist(new PersonTicket4646()); + $this->_em->persist(new EmployeeTicket4646()); + $this->_em->flush(); $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646 p WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646'; @@ -26,30 +28,7 @@ public function testInstanceOf() $result = $query->getResult(); $this->assertCount(2, $result); - - foreach ($result as $r) { - $this->assertInstanceOf(PersonTicket4646::class, $r); - if ($r instanceof EmployeeTicket4646) { - $this->assertEquals('bar', $r->getName()); - } else { - $this->assertEquals('foo', $r->getName()); - } - } - } - - private function loadData() - { - $person = new PersonTicket4646(); - $person->setName('foo'); - - $employee = new EmployeeTicket4646(); - $employee->setName('bar'); - $employee->setDepartement('qux'); - - $this->_em->persist($person); - $this->_em->persist($employee); - - $this->_em->flush(array($person, $employee)); + $this->assertContainsOnlyInstancesOf(PersonTicket4646::class, $result); } } @@ -72,25 +51,10 @@ class PersonTicket4646 */ private $id; - /** - * @Column(type="string") - */ - private $name; - public function getId() { return $this->id; } - - public function getName() - { - return $this->name; - } - - public function setName($name) - { - $this->name = $name; - } } /** @@ -99,18 +63,4 @@ public function setName($name) */ class EmployeeTicket4646 extends PersonTicket4646 { - /** - * @Column(type="string") - */ - private $departement; - - public function getDepartement() - { - return $this->departement; - } - - public function setDepartement($departement) - { - $this->departement = $departement; - } } From fc609271e0fd1da203555ab80e3d91c298dfb448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1chym=20Tou=C5=A1ek?= Date: Thu, 19 Jan 2017 12:54:10 +0100 Subject: [PATCH 357/877] Fix CountOutputWalker for queries with GROUP BY --- .../ORM/Tools/Pagination/CountOutputWalker.php | 8 ++++++++ .../Tools/Pagination/CountOutputWalkerTest.php | 18 +++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Pagination/CountOutputWalker.php b/lib/Doctrine/ORM/Tools/Pagination/CountOutputWalker.php index 8d3163043ab..f3db053ca29 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/CountOutputWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/CountOutputWalker.php @@ -91,6 +91,14 @@ public function walkSelectStatement(SelectStatement $AST) $sql = parent::walkSelectStatement($AST); + if ($AST->groupByClause) { + return sprintf( + 'SELECT %s AS dctrn_count FROM (%s) dctrn_table', + $this->platform->getCountExpression('*'), + $sql + ); + } + // Find out the SQL alias of the identifier column of the root entity // It may be possible to make this work with multiple root entities but that // would probably require issuing multiple queries or doing a UNION SELECT diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/CountOutputWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/CountOutputWalkerTest.php index 5f999f28a01..df7f73f7881 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/CountOutputWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/CountOutputWalkerTest.php @@ -31,15 +31,27 @@ public function testCountQuery_MixedResultsWithName() ); } - public function testCountQuery_Having() + public function testCountQuery_GroupBy(): void + { + $query = $this->entityManager->createQuery( + 'SELECT p.name FROM Doctrine\Tests\ORM\Tools\Pagination\Person p GROUP BY p.name'); + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, CountOutputWalker::class); + $query->setFirstResult(null)->setMaxResults(null); + + $this->assertSame( + "SELECT COUNT(*) AS dctrn_count FROM (SELECT p0_.name AS name_0 FROM Person p0_ GROUP BY p0_.name) dctrn_table", $query->getSQL() + ); + } + + public function testCountQuery_Having(): void { $query = $this->entityManager->createQuery( 'SELECT g, u, count(u.id) AS userCount FROM Doctrine\Tests\ORM\Tools\Pagination\Group g LEFT JOIN g.users u GROUP BY g.id HAVING userCount > 0'); $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, CountOutputWalker::class); $query->setFirstResult(null)->setMaxResults(null); - $this->assertEquals( - "SELECT COUNT(*) AS dctrn_count FROM (SELECT DISTINCT id_1 FROM (SELECT count(u0_.id) AS sclr_0, g1_.id AS id_1, u0_.id AS id_2 FROM groups g1_ LEFT JOIN user_group u2_ ON g1_.id = u2_.group_id LEFT JOIN User u0_ ON u0_.id = u2_.user_id GROUP BY g1_.id HAVING sclr_0 > 0) dctrn_result) dctrn_table", $query->getSQL() + $this->assertSame( + "SELECT COUNT(*) AS dctrn_count FROM (SELECT count(u0_.id) AS sclr_0, g1_.id AS id_1, u0_.id AS id_2 FROM groups g1_ LEFT JOIN user_group u2_ ON g1_.id = u2_.group_id LEFT JOIN User u0_ ON u0_.id = u2_.user_id GROUP BY g1_.id HAVING sclr_0 > 0) dctrn_table", $query->getSQL() ); } From e8332a45dec7cd742bdafaef7fc1062ed58c8e50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Thu, 22 Jun 2017 07:55:44 +0200 Subject: [PATCH 358/877] Use the Travis' Trusty build environment To see if that solves the XML validation issues (since the issues are possibly happening due to old libxml versions). --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index bd9d8b32c9f..8f9d116927f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +dist: trusty sudo: false language: php From d4cdc6e1febf1cfb80e054b8324ef2c2e4e762b4 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Thu, 22 Jun 2017 09:50:53 +0200 Subject: [PATCH 359/877] Adding a failing test case for parameter binding using metadata with INSTANCE OF --- .../Ticket4646InstanceOfParametricTest.php | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfParametricTest.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfParametricTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfParametricTest.php new file mode 100644 index 00000000000..302934e8c10 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfParametricTest.php @@ -0,0 +1,67 @@ +_schemaTool->createSchema([ + $this->_em->getClassMetadata(PersonTicket4646Parametric::class), + $this->_em->getClassMetadata(EmployeeTicket4646Parametric::class), + ]); + } + + public function testInstanceOf() + { + $this->_em->persist(new PersonTicket4646Parametric()); + $this->_em->persist(new EmployeeTicket4646Parametric()); + $this->_em->flush(); + $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646Parametric p + WHERE p INSTANCE OF :parameter'; + $query = $this->_em->createQuery($dql); + $query->setParameter( + 'parameter', + $this->_em->getClassMetadata(PersonTicket4646Parametric::class) + ); + $result = $query->getResult(); + $this->assertCount(2, $result); + $this->assertContainsOnlyInstancesOf(PersonTicket4646Parametric::class, $result); + } +} + +/** + * @Entity() + * @Table(name="instance_of_parametric_person") + * @InheritanceType(value="JOINED") + * @DiscriminatorColumn(name="kind", type="string") + * @DiscriminatorMap(value={ + * "person": "Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646Parametric", + * "employee": "Doctrine\Tests\ORM\Functional\Ticket\EmployeeTicket4646Parametric" + * }) + */ +class PersonTicket4646Parametric +{ + /** + * @Id() + * @GeneratedValue() + * @Column(type="integer") + */ + private $id; + + public function getId() + { + return $this->id; + } +} + +/** + * @Entity() + * @Table(name="instance_of_parametric_employee") + */ +class EmployeeTicket4646Parametric extends PersonTicket4646Parametric +{ +} From 21ad7a1913ae2cedc98f38c2307cc96a05544b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Thu, 22 Jun 2017 08:30:27 +0200 Subject: [PATCH 360/877] Create schema based on config file (on MySQL & MariaDB) --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 8f9d116927f..667d3f2d0b9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ before_script: - composer install --prefer-source - if [ "$DEPENDENCIES" != "low" ]; then composer update; fi; - if [ "$DEPENDENCIES" == "low" ]; then composer update --prefer-lowest; fi; + - if [[ $DB == "mysql" || $DB == "mariadb" ]]; then mysql -e "CREATE SCHEMA doctrine_tests; GRANT ALL PRIVILEGES ON doctrine_tests.* to travis@'%'"; fi; script: - ENABLE_SECOND_LEVEL_CACHE=0 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml $PHPUNIT_FLAGS From 9eb2d6139efe8b8d1ae77d5b47c1e38ae109bc95 Mon Sep 17 00:00:00 2001 From: Emiel Nijpels Date: Thu, 24 Sep 2015 10:26:10 +0200 Subject: [PATCH 361/877] DDC-3146 remove event listener from event listener in abstract hydrator in cleanup function --- .../Internal/Hydration/AbstractHydrator.php | 3 + .../ORM/Functional/Ticket/DDC3146Test.php | 65 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3146Test.php diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index ee9385c8155..d462421ac73 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -211,6 +211,9 @@ protected function cleanup() $this->_rsm = null; $this->_cache = []; $this->_metadataCache = []; + + $evm = $this->_em->getEventManager(); + $evm->removeEventListener(array(Events::onClear), $this); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3146Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3146Test.php new file mode 100644 index 00000000000..7e09642c2f5 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3146Test.php @@ -0,0 +1,65 @@ + + */ +class DDC3146Test extends \Doctrine\Tests\OrmFunctionalTestCase +{ + /** + * Verify that the number of added events to the event listener from the abstract hydrator class is equal to the number of removed events + */ + public function testEventListeners() + { + // Create mock connection to be returned from the entity manager interface + $mockConnection = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock(); + $mockEntityManagerInterface = $this->getMockBuilder('Doctrine\ORM\EntityManagerInterface')->disableOriginalConstructor()->getMock(); + $mockEntityManagerInterface->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection)); + + // Create mock event manager to be returned from the entity manager interface + $mockEventManager = $this->getMockBuilder('Doctrine\Common\EventManager')->disableOriginalConstructor()->getMock(); + $mockEntityManagerInterface->expects($this->any())->method('getEventManager')->will($this->returnValue($mockEventManager)); + + // Create mock statement and result mapping + $mockStatement = $this->getMockBuilder('Doctrine\DBAL\Driver\Statement')->disableOriginalConstructor()->getMock(); + $mockStatement->expects($this->once())->method('fetch')->will($this->returnValue(false)); + $mockResultMapping = $this->getMockBuilder('Doctrine\ORM\Query\ResultSetMapping')->disableOriginalConstructor()->getMock(); + + // Create mock abstract hydrator + $mockAbstractHydrator = $this->getMockBuilder('Doctrine\ORM\Internal\Hydration\AbstractHydrator') + ->setConstructorArgs(array($mockEntityManagerInterface)) + ->setMethods(array('hydrateAllData')) + ->getMock(); + + // Increase counter every time the event listener is added and decrease the counter every time the event listener is removed + $eventCounter = 0; + $mockEventManager->expects($this->any()) + ->method('addEventListener') + ->will( + $this->returnCallback( + function () use (&$eventCounter) { + $eventCounter++; + } + ) + ); + + $mockEventManager->expects($this->any()) + ->method('removeEventListener') + ->will( + $this->returnCallback( + function () use (&$eventCounter) { + $eventCounter--; + } + ) + ); + + // Create iterable result + $iterableResult = $mockAbstractHydrator->iterate($mockStatement, $mockResultMapping, array()); + $iterableResult->next(); + + // Number of added events listeners should be equal or less than the number of removed events + $this->assertLessThanOrEqual(0, $eventCounter, 'More events added to the event listener than removed; this can create a memory leak when references are not cleaned up'); + } +} From aba486ea2d5a189ac1673aed4b2174a7938bc554 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 24 Jun 2017 03:27:12 +0200 Subject: [PATCH 362/877] #1515 removing redundant assignment, short array notation --- lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index d462421ac73..6a7061285be 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -212,8 +212,10 @@ protected function cleanup() $this->_cache = []; $this->_metadataCache = []; - $evm = $this->_em->getEventManager(); - $evm->removeEventListener(array(Events::onClear), $this); + $this + ->_em + ->getEventManager() + ->removeEventListener([Events::onClear], $this); } /** From 067e01e0d7fd550d726fc5e448188e2c02962406 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 24 Jun 2017 03:32:58 +0200 Subject: [PATCH 363/877] #1515 cleaning up test case, since the PHPUnit 5.4+ API is much nicer --- .../ORM/Functional/Ticket/DDC3146Test.php | 61 +++++++++---------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3146Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3146Test.php index 7e09642c2f5..cdf7b123440 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3146Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3146Test.php @@ -2,64 +2,59 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\DBAL\Connection; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\Common\EventManager; +use Doctrine\DBAL\Driver\Statement; +use Doctrine\ORM\Query\ResultSetMapping; +use Doctrine\ORM\Internal\Hydration\AbstractHydrator; +use Doctrine\Tests\OrmFunctionalTestCase; + /** * @group DDC-3146 * @author Emiel Nijpels */ -class DDC3146Test extends \Doctrine\Tests\OrmFunctionalTestCase +class DDC3146Test extends OrmFunctionalTestCase { /** * Verify that the number of added events to the event listener from the abstract hydrator class is equal to the number of removed events */ public function testEventListeners() { - // Create mock connection to be returned from the entity manager interface - $mockConnection = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock(); - $mockEntityManagerInterface = $this->getMockBuilder('Doctrine\ORM\EntityManagerInterface')->disableOriginalConstructor()->getMock(); - $mockEntityManagerInterface->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection)); - - // Create mock event manager to be returned from the entity manager interface - $mockEventManager = $this->getMockBuilder('Doctrine\Common\EventManager')->disableOriginalConstructor()->getMock(); - $mockEntityManagerInterface->expects($this->any())->method('getEventManager')->will($this->returnValue($mockEventManager)); + $mockConnection = $this->createMock(Connection::class); + $mockEntityManagerInterface = $this->createMock(EntityManagerInterface::class); + $mockEventManager = $this->createMock(EventManager::class); + $mockStatement = $this->createMock(Statement::class); + $mockResultMapping = $this->getMockBuilder(ResultSetMapping::class); - // Create mock statement and result mapping - $mockStatement = $this->getMockBuilder('Doctrine\DBAL\Driver\Statement')->disableOriginalConstructor()->getMock(); - $mockStatement->expects($this->once())->method('fetch')->will($this->returnValue(false)); - $mockResultMapping = $this->getMockBuilder('Doctrine\ORM\Query\ResultSetMapping')->disableOriginalConstructor()->getMock(); + $mockEntityManagerInterface->expects(self::any())->method('getEventManager')->willReturn($mockEventManager); + $mockEntityManagerInterface->expects(self::any())->method('getConnection')->willReturn($mockConnection); + $mockStatement->expects(self::once())->method('fetch')->willReturn(false); - // Create mock abstract hydrator - $mockAbstractHydrator = $this->getMockBuilder('Doctrine\ORM\Internal\Hydration\AbstractHydrator') + $mockAbstractHydrator = $this->getMockBuilder(AbstractHydrator::class) ->setConstructorArgs(array($mockEntityManagerInterface)) - ->setMethods(array('hydrateAllData')) + ->setMethods(['hydrateAllData']) ->getMock(); // Increase counter every time the event listener is added and decrease the counter every time the event listener is removed $eventCounter = 0; - $mockEventManager->expects($this->any()) + $mockEventManager->expects(self::atLeastOnce()) ->method('addEventListener') - ->will( - $this->returnCallback( - function () use (&$eventCounter) { - $eventCounter++; - } - ) - ); + ->willReturnCallback(function () use (&$eventCounter) { + $eventCounter++; + }); - $mockEventManager->expects($this->any()) + $mockEventManager->expects(self::atLeastOnce()) ->method('removeEventListener') - ->will( - $this->returnCallback( - function () use (&$eventCounter) { - $eventCounter--; - } - ) - ); + ->willReturnCallback(function () use (&$eventCounter) { + $eventCounter--; + }); // Create iterable result $iterableResult = $mockAbstractHydrator->iterate($mockStatement, $mockResultMapping, array()); $iterableResult->next(); // Number of added events listeners should be equal or less than the number of removed events - $this->assertLessThanOrEqual(0, $eventCounter, 'More events added to the event listener than removed; this can create a memory leak when references are not cleaned up'); + self::assertSame(0, $eventCounter, 'More events added to the event listener than removed; this can create a memory leak when references are not cleaned up'); } } From 0b5d877d5f61aee70c2cc80cdd500a0881f7ea5a Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 24 Jun 2017 03:40:12 +0200 Subject: [PATCH 364/877] Migrating #1515 tests to `AbstractHydratorTest` --- .../ORM/Hydration/AbstractHydratorTest.php | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Hydration/AbstractHydratorTest.php diff --git a/tests/Doctrine/Tests/ORM/Hydration/AbstractHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/AbstractHydratorTest.php new file mode 100644 index 00000000000..1cd49d5ca7e --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Hydration/AbstractHydratorTest.php @@ -0,0 +1,57 @@ +createMock(Connection::class); + $mockEntityManagerInterface = $this->createMock(EntityManagerInterface::class); + $mockEventManager = $this->createMock(EventManager::class); + $mockStatement = $this->createMock(Statement::class); + $mockResultMapping = $this->getMockBuilder(ResultSetMapping::class); + + $mockEntityManagerInterface->expects(self::any())->method('getEventManager')->willReturn($mockEventManager); + $mockEntityManagerInterface->expects(self::any())->method('getConnection')->willReturn($mockConnection); + $mockStatement->expects(self::once())->method('fetch')->willReturn(false); + + /* @var $mockAbstractHydrator AbstractHydrator */ + $mockAbstractHydrator = $this + ->getMockBuilder(AbstractHydrator::class) + ->setConstructorArgs([$mockEntityManagerInterface]) + ->setMethods(['hydrateAllData']) + ->getMock(); + + $mockEventManager + ->expects(self::at(0)) + ->method('addEventListener') + ->with([Events::onClear], $mockAbstractHydrator); + + $mockEventManager + ->expects(self::at(1)) + ->method('removeEventListener') + ->with([Events::onClear], $mockAbstractHydrator); + + iterator_to_array($mockAbstractHydrator->iterate($mockStatement, $mockResultMapping)); + } +} From 995054d884e68cbc15d9f85e126dc1b6682aa2bf Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 24 Jun 2017 03:40:46 +0200 Subject: [PATCH 365/877] #1515 dropping DDC-3146 test, which was moved to the hydration tests --- .../ORM/Functional/Ticket/DDC3146Test.php | 60 ------------------- 1 file changed, 60 deletions(-) delete mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3146Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3146Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3146Test.php deleted file mode 100644 index cdf7b123440..00000000000 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3146Test.php +++ /dev/null @@ -1,60 +0,0 @@ - - */ -class DDC3146Test extends OrmFunctionalTestCase -{ - /** - * Verify that the number of added events to the event listener from the abstract hydrator class is equal to the number of removed events - */ - public function testEventListeners() - { - $mockConnection = $this->createMock(Connection::class); - $mockEntityManagerInterface = $this->createMock(EntityManagerInterface::class); - $mockEventManager = $this->createMock(EventManager::class); - $mockStatement = $this->createMock(Statement::class); - $mockResultMapping = $this->getMockBuilder(ResultSetMapping::class); - - $mockEntityManagerInterface->expects(self::any())->method('getEventManager')->willReturn($mockEventManager); - $mockEntityManagerInterface->expects(self::any())->method('getConnection')->willReturn($mockConnection); - $mockStatement->expects(self::once())->method('fetch')->willReturn(false); - - $mockAbstractHydrator = $this->getMockBuilder(AbstractHydrator::class) - ->setConstructorArgs(array($mockEntityManagerInterface)) - ->setMethods(['hydrateAllData']) - ->getMock(); - - // Increase counter every time the event listener is added and decrease the counter every time the event listener is removed - $eventCounter = 0; - $mockEventManager->expects(self::atLeastOnce()) - ->method('addEventListener') - ->willReturnCallback(function () use (&$eventCounter) { - $eventCounter++; - }); - - $mockEventManager->expects(self::atLeastOnce()) - ->method('removeEventListener') - ->willReturnCallback(function () use (&$eventCounter) { - $eventCounter--; - }); - - // Create iterable result - $iterableResult = $mockAbstractHydrator->iterate($mockStatement, $mockResultMapping, array()); - $iterableResult->next(); - - // Number of added events listeners should be equal or less than the number of removed events - self::assertSame(0, $eventCounter, 'More events added to the event listener than removed; this can create a memory leak when references are not cleaned up'); - } -} From 7d981350846118513fc0df3db350cc4f9968fdf6 Mon Sep 17 00:00:00 2001 From: Sergio Santoro Date: Mon, 29 Jun 2015 22:05:26 +0200 Subject: [PATCH 366/877] [QUERY] "INSTANCE OF" now behaves correctly with subclasses There was a bug in the "INSTANCE OF" operator as described in https://groups.google.com/forum/#!topic/doctrine-user/B8raq8CNMgg "INSTANCE OF" was not taking into account subclasses. It was merely translating the class to its discriminator. This is not correct since the class can have subtypes and those are, indeed, still instance of the superclass. Also, classes may not have a discriminator (e.g. abstract classes). This commit also provides useful tests to avoid regression. --- lib/Doctrine/ORM/Query/SqlWalker.php | 34 ++-- .../ORM/Functional/InstanceOfAbstractTest.php | 113 +++++++++++++ .../Functional/InstanceOfMultiLevelTest.php | 153 ++++++++++++++++++ .../Tests/ORM/Functional/InstanceOfTest.php | 119 ++++++++++++++ .../ORM/Query/SelectSqlGenerationTest.php | 6 +- 5 files changed, 411 insertions(+), 14 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/InstanceOfMultiLevelTest.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/InstanceOfTest.php diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 98f58ad8c69..645a6c21f76 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -2035,8 +2035,10 @@ public function walkInstanceOfExpression($instanceOfExpr) $sql .= $class->discriminatorColumn['name'] . ($instanceOfExpr->not ? ' NOT IN ' : ' IN '); - $sqlParameterList = []; + $knownSubclasses = array_flip($discrClass->subClasses); + $sqlParameterList = []; + $discriminators = []; foreach ($instanceOfExpr->value as $parameter) { if ($parameter instanceof AST\InputParameter) { $this->rsm->addMetadataParameterMapping($parameter->name, 'discriminatorValue'); @@ -2046,21 +2048,31 @@ public function walkInstanceOfExpression($instanceOfExpr) continue; } - // Get name from ClassMetadata to resolve aliases. - $entityClassName = $this->em->getClassMetadata($parameter)->name; - $discriminatorValue = $class->discriminatorValue; + // Trim first backslash + $parameter = ltrim($parameter, '\\'); - if ($entityClassName !== $class->name) { - $discrMap = array_flip($class->discriminatorMap); + // Check parameter is really in the hierarchy + if ($parameter !== $discrClass->name && ! array_key_exists($parameter, $knownSubclasses)) { + throw QueryException::instanceOfUnrelatedClass($parameter, $discrClass->name); + } - if ( ! isset($discrMap[$entityClassName])) { - throw QueryException::instanceOfUnrelatedClass($entityClassName, $class->rootEntityName); - } + // Include discriminators for parameter class and its subclass + $metadata = $this->em->getClassMetadata($parameter); + $hierarchyClasses = $metadata->subClasses; + $hierarchyClasses[] = $metadata->name; - $discriminatorValue = $discrMap[$entityClassName]; + foreach ($hierarchyClasses as $class) { + $currentMetadata = $this->em->getClassMetadata($class); + $currentDiscriminator = $currentMetadata->discriminatorValue; + + if (is_string($currentDiscriminator) && ! array_key_exists($currentDiscriminator, $discriminators)) { + $discriminators[$currentDiscriminator] = true; + } } + } - $sqlParameterList[] = $this->conn->quote($discriminatorValue); + foreach (array_keys($discriminators) as $dis) { + $sqlParameterList[] = $this->conn->quote($dis); } $sql .= '(' . implode(', ', $sqlParameterList) . ')'; diff --git a/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php b/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php new file mode 100644 index 00000000000..a84643f84d4 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php @@ -0,0 +1,113 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfAbstractTest\Person'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfAbstractTest\Employee'), + )); + } + + public function testInstanceOf() + { + $this->loadData(); + + $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Person p + WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Person'; + $query = $this->_em->createQuery($dql); + $result = $query->getResult(); + + $this->assertCount(1, $result); + + foreach ($result as $r) { + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Person', $r); + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Employee', $r); + $this->assertEquals('bar', $r->getName()); + } + } + + private function loadData() + { + $employee = new InstanceOfAbstractTest\Employee(); + $employee->setName('bar'); + $employee->setDepartement('qux'); + + $this->_em->persist($employee); + + $this->_em->flush($employee); + } + } +} + +namespace Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest { + + /** + * @Entity() + * @Table(name="instance_of_abstract_test_person") + * @InheritanceType(value="JOINED") + * @DiscriminatorColumn(name="kind", type="string") + * @DiscriminatorMap(value={ + * "employee": "Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Employee" + * }) + */ + abstract class Person + { + /** + * @Id() + * @GeneratedValue() + * @Column(type="integer") + */ + private $id; + + /** + * @Column(type="string") + */ + private $name; + + public function getId() + { + return $this->id; + } + + public function getName() + { + return $this->name; + } + + public function setName($name) + { + $this->name = $name; + } + } + + /** + * @Entity() + * @Table(name="instance_of_abstract_test_employee") + */ + class Employee extends Person + { + /** + * @Column(type="string") + */ + private $departement; + + public function getDepartement() + { + return $this->departement; + } + + public function setDepartement($departement) + { + $this->departement = $departement; + } + } + +} diff --git a/tests/Doctrine/Tests/ORM/Functional/InstanceOfMultiLevelTest.php b/tests/Doctrine/Tests/ORM/Functional/InstanceOfMultiLevelTest.php new file mode 100644 index 00000000000..c4b5bbcd2c3 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/InstanceOfMultiLevelTest.php @@ -0,0 +1,153 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfMultiLevelTest\Person'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfMultiLevelTest\Employee'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfMultiLevelTest\Engineer'), + )); + } + + public function testInstanceOf() + { + $this->loadData(); + + $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Person p + WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Person'; + $query = $this->_em->createQuery($dql); + $result = $query->getResult(); + + $this->assertCount(3, $result); + + foreach ($result as $r) { + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Person', $r); + if ($r instanceof InstanceOfMultiLevelTest\Engineer) { + $this->assertEquals('foobar', $r->getName()); + $this->assertEquals('doctrine', $r->getSpecialization()); + } elseif ($r instanceof InstanceOfMultiLevelTest\Employee) { + $this->assertEquals('bar', $r->getName()); + $this->assertEquals('qux', $r->getDepartement()); + } else { + $this->assertEquals('foo', $r->getName()); + } + } + } + + private function loadData() + { + $person = new InstanceOfMultiLevelTest\Person(); + $person->setName('foo'); + + $employee = new InstanceOfMultiLevelTest\Employee(); + $employee->setName('bar'); + $employee->setDepartement('qux'); + + $engineer = new InstanceOfMultiLevelTest\Engineer(); + $engineer->setName('foobar'); + $engineer->setDepartement('dep'); + $engineer->setSpecialization('doctrine'); + + $this->_em->persist($person); + $this->_em->persist($employee); + $this->_em->persist($engineer); + + $this->_em->flush(array($person, $employee, $engineer)); + } + } +} + +namespace Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest { + /** + * @Entity() + * @Table(name="instance_of_multi_level_test_person") + * @InheritanceType(value="JOINED") + * @DiscriminatorColumn(name="kind", type="string") + * @DiscriminatorMap(value={ + * "person": "Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Person", + * "employee": "Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Employee", + * "engineer": "Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Engineer", + * }) + */ + class Person + { + /** + * @Id() + * @GeneratedValue() + * @Column(type="integer") + */ + private $id; + + /** + * @Column(type="string") + */ + private $name; + + public function getId() + { + return $this->id; + } + + public function getName() + { + return $this->name; + } + + public function setName($name) + { + $this->name = $name; + } + } + + /** + * @Entity() + * @Table(name="instance_of_multi_level_employee") + */ + class Employee extends Person + { + /** + * @Column(type="string") + */ + private $departement; + + public function getDepartement() + { + return $this->departement; + } + + public function setDepartement($departement) + { + $this->departement = $departement; + } + } + + /** + * @Entity() + * @Table(name="instance_of_multi_level_engineer") + */ + class Engineer extends Employee + { + /** + * @Column(type="string") + */ + private $specialization; + + public function getSpecialization() + { + return $this->specialization; + } + + public function setSpecialization($specialization) + { + $this->specialization = $specialization; + } + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/InstanceOfTest.php b/tests/Doctrine/Tests/ORM/Functional/InstanceOfTest.php new file mode 100644 index 00000000000..7f593c3f4a6 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/InstanceOfTest.php @@ -0,0 +1,119 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfTest\Person'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfTest\Employee'), + )); + } + + public function testInstanceOf() + { + $this->loadData(); + + $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\InstanceOfTest\Person p + WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\InstanceOfTest\Person'; + $query = $this->_em->createQuery($dql); + $result = $query->getResult(); + + $this->assertCount(2, $result); + + foreach ($result as $r) { + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\InstanceOfTest\Person', $r); + if ($r instanceof InstanceOfTest\Employee) { + $this->assertEquals('bar', $r->getName()); + } else { + $this->assertEquals('foo', $r->getName()); + } + } + } + + private function loadData() + { + $person = new InstanceOfTest\Person(); + $person->setName('foo'); + + $employee = new InstanceOfTest\Employee(); + $employee->setName('bar'); + $employee->setDepartement('qux'); + + $this->_em->persist($person); + $this->_em->persist($employee); + + $this->_em->flush(array($person, $employee)); + } + } +} + +namespace Doctrine\Tests\ORM\Functional\InstanceOfTest { + /** + * @Entity() + * @Table(name="instance_of_test_person") + * @InheritanceType(value="JOINED") + * @DiscriminatorColumn(name="kind", type="string") + * @DiscriminatorMap(value={ + * "person": "Doctrine\Tests\ORM\Functional\InstanceOfTest\Person", + * "employee": "Doctrine\Tests\ORM\Functional\InstanceOfTest\Employee" + * }) + */ + class Person + { + /** + * @Id() + * @GeneratedValue() + * @Column(type="integer") + */ + private $id; + + /** + * @Column(type="string") + */ + private $name; + + public function getId() + { + return $this->id; + } + + public function getName() + { + return $this->name; + } + + public function setName($name) + { + $this->name = $name; + } + } + + /** + * @Entity() + * @Table(name="instance_of_test_employee") + */ + class Employee extends Person + { + /** + * @Column(type="string") + */ + private $departement; + + public function getDepartement() + { + return $this->departement; + } + + public function setDepartement($departement) + { + $this->departement = $departement; + } + } +} diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index c10afbb8961..82facdb49b5 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -500,7 +500,7 @@ public function testSupportsInstanceOfExpressionsInWherePart() { $this->assertSqlGeneration( "SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF Doctrine\Tests\Models\Company\CompanyEmployee", - "SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.discr AS discr_2 FROM company_persons c0_ WHERE c0_.discr IN ('employee')" + "SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.discr AS discr_2 FROM company_persons c0_ WHERE c0_.discr IN ('manager', 'employee')" ); } @@ -509,7 +509,7 @@ public function testSupportsInstanceOfExpressionInWherePartWithMultipleValues() // This also uses FQCNs starting with or without a backslash in the INSTANCE OF parameter $this->assertSqlGeneration( "SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF (Doctrine\Tests\Models\Company\CompanyEmployee, \Doctrine\Tests\Models\Company\CompanyManager)", - "SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.discr AS discr_2 FROM company_persons c0_ WHERE c0_.discr IN ('employee', 'manager')" + "SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.discr AS discr_2 FROM company_persons c0_ WHERE c0_.discr IN ('manager', 'employee')" ); } @@ -520,7 +520,7 @@ public function testSupportsInstanceOfExpressionsInWherePartPrefixedSlash() { $this->assertSqlGeneration( "SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF \Doctrine\Tests\Models\Company\CompanyEmployee", - "SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.discr AS discr_2 FROM company_persons c0_ WHERE c0_.discr IN ('employee')" + "SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.discr AS discr_2 FROM company_persons c0_ WHERE c0_.discr IN ('manager', 'employee')" ); } From 04acde667a517db81ed5798d58ccdf39bbb82d06 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Tue, 18 Apr 2017 11:57:49 +0200 Subject: [PATCH 367/877] Fix as per review --- .../Tests/ORM/Functional/InstanceOfAbstractTest.php | 7 +++---- tests/Doctrine/Tests/ORM/Functional/InstanceOfTest.php | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php b/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php index a84643f84d4..3a52d93f96c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php @@ -28,9 +28,9 @@ public function testInstanceOf() $this->assertCount(1, $result); foreach ($result as $r) { - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Person', $r); - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Employee', $r); - $this->assertEquals('bar', $r->getName()); + $this->assertInstanceOf(InstanceOfAbstractTest\Person::class, $r); + $this->assertInstanceOf(InstanceOfAbstractTest\Employee::class, $r); + $this->assertSame('bar', $r->getName()); } } @@ -109,5 +109,4 @@ public function setDepartement($departement) $this->departement = $departement; } } - } diff --git a/tests/Doctrine/Tests/ORM/Functional/InstanceOfTest.php b/tests/Doctrine/Tests/ORM/Functional/InstanceOfTest.php index 7f593c3f4a6..fce0075b63f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/InstanceOfTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/InstanceOfTest.php @@ -10,10 +10,10 @@ protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( + $this->_schemaTool->createSchema([ $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfTest\Person'), $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfTest\Employee'), - )); + ]); } public function testInstanceOf() @@ -28,7 +28,7 @@ public function testInstanceOf() $this->assertCount(2, $result); foreach ($result as $r) { - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\InstanceOfTest\Person', $r); + $this->assertInstanceOf(InstanceOfTest\Person::class, $r); if ($r instanceof InstanceOfTest\Employee) { $this->assertEquals('bar', $r->getName()); } else { From aa233f8e57f8ae313eb7119174ce26377ec63cd5 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 3 May 2017 10:46:24 +0200 Subject: [PATCH 368/877] Fix small CS issues as per review --- .../ORM/Functional/InstanceOfAbstractTest.php | 12 ++++++---- .../Functional/InstanceOfMultiLevelTest.php | 23 +++++++++++-------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php b/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php index 3a52d93f96c..1b826a4619d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\ORM\Functional { + use Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Employee; + use Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Person; use Doctrine\Tests\OrmFunctionalTestCase; class InstanceOfAbstractTest extends OrmFunctionalTestCase @@ -10,10 +12,10 @@ protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( - $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfAbstractTest\Person'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfAbstractTest\Employee'), - )); + $this->_schemaTool->createSchema([ + $this->_em->getClassMetadata(Person::class), + $this->_em->getClassMetadata(Employee::class), + ]); } public function testInstanceOf() @@ -55,7 +57,7 @@ private function loadData() * @InheritanceType(value="JOINED") * @DiscriminatorColumn(name="kind", type="string") * @DiscriminatorMap(value={ - * "employee": "Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Employee" + * "employee": Employee::class * }) */ abstract class Person diff --git a/tests/Doctrine/Tests/ORM/Functional/InstanceOfMultiLevelTest.php b/tests/Doctrine/Tests/ORM/Functional/InstanceOfMultiLevelTest.php index c4b5bbcd2c3..131f053a285 100644 --- a/tests/Doctrine/Tests/ORM/Functional/InstanceOfMultiLevelTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/InstanceOfMultiLevelTest.php @@ -2,6 +2,9 @@ namespace Doctrine\Tests\ORM\Functional { + use Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Employee; + use Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Engineer; + use Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Person; use Doctrine\Tests\OrmFunctionalTestCase; class InstanceOfMultiLevelTest extends OrmFunctionalTestCase @@ -10,11 +13,11 @@ protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema(array( - $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfMultiLevelTest\Person'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfMultiLevelTest\Employee'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfMultiLevelTest\Engineer'), - )); + $this->_schemaTool->createSchema([ + $this->_em->getClassMetadata(Person::class), + $this->_em->getClassMetadata(Employee::class), + $this->_em->getClassMetadata(Engineer::class), + ]); } public function testInstanceOf() @@ -29,11 +32,11 @@ public function testInstanceOf() $this->assertCount(3, $result); foreach ($result as $r) { - $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Person', $r); + $this->assertInstanceOf(Person::class, $r); if ($r instanceof InstanceOfMultiLevelTest\Engineer) { $this->assertEquals('foobar', $r->getName()); $this->assertEquals('doctrine', $r->getSpecialization()); - } elseif ($r instanceof InstanceOfMultiLevelTest\Employee) { + } elseif ($r instanceof Employee) { $this->assertEquals('bar', $r->getName()); $this->assertEquals('qux', $r->getDepartement()); } else { @@ -44,14 +47,14 @@ public function testInstanceOf() private function loadData() { - $person = new InstanceOfMultiLevelTest\Person(); + $person = new Person(); $person->setName('foo'); - $employee = new InstanceOfMultiLevelTest\Employee(); + $employee = new Employee(); $employee->setName('bar'); $employee->setDepartement('qux'); - $engineer = new InstanceOfMultiLevelTest\Engineer(); + $engineer = new Engineer(); $engineer->setName('foobar'); $engineer->setDepartement('dep'); $engineer->setSpecialization('doctrine'); From 0e88f1b654f963c1e7623ab77d11d9d3c21226e8 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 3 May 2017 11:00:26 +0200 Subject: [PATCH 369/877] Split SqlWalker::walkInstanceOfExpression method --- lib/Doctrine/ORM/Query/SqlWalker.php | 94 +++++++++++++++------------- 1 file changed, 51 insertions(+), 43 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 645a6c21f76..baf05ffcabf 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -37,7 +37,6 @@ * @author Alexander * @author Fabio B. Silva * @since 2.0 - * @todo Rename: SQLWalker */ class SqlWalker implements TreeWalker { @@ -2017,6 +2016,7 @@ public function walkInExpression($inExpr) /** * {@inheritdoc} + * @throws \Doctrine\ORM\Query\QueryException */ public function walkInstanceOfExpression($instanceOfExpr) { @@ -2034,48 +2034,7 @@ public function walkInstanceOfExpression($instanceOfExpr) } $sql .= $class->discriminatorColumn['name'] . ($instanceOfExpr->not ? ' NOT IN ' : ' IN '); - - $knownSubclasses = array_flip($discrClass->subClasses); - - $sqlParameterList = []; - $discriminators = []; - foreach ($instanceOfExpr->value as $parameter) { - if ($parameter instanceof AST\InputParameter) { - $this->rsm->addMetadataParameterMapping($parameter->name, 'discriminatorValue'); - - $sqlParameterList[] = $this->walkInputParameter($parameter); - - continue; - } - - // Trim first backslash - $parameter = ltrim($parameter, '\\'); - - // Check parameter is really in the hierarchy - if ($parameter !== $discrClass->name && ! array_key_exists($parameter, $knownSubclasses)) { - throw QueryException::instanceOfUnrelatedClass($parameter, $discrClass->name); - } - - // Include discriminators for parameter class and its subclass - $metadata = $this->em->getClassMetadata($parameter); - $hierarchyClasses = $metadata->subClasses; - $hierarchyClasses[] = $metadata->name; - - foreach ($hierarchyClasses as $class) { - $currentMetadata = $this->em->getClassMetadata($class); - $currentDiscriminator = $currentMetadata->discriminatorValue; - - if (is_string($currentDiscriminator) && ! array_key_exists($currentDiscriminator, $discriminators)) { - $discriminators[$currentDiscriminator] = true; - } - } - } - - foreach (array_keys($discriminators) as $dis) { - $sqlParameterList[] = $this->conn->quote($dis); - } - - $sql .= '(' . implode(', ', $sqlParameterList) . ')'; + $sql .= $this->getChildDiscriminatorsFromClassMetadata($discrClass, $instanceOfExpr); return $sql; } @@ -2309,4 +2268,53 @@ public function walkResultVariable($resultVariable) return $resultAlias; } + + /** + * @param ClassMetadataInfo $discrClass + * @param AST\InstanceOfExpression $instanceOfExpr + * @return string The list in parentheses of valid child discriminators from the given class + * @throws QueryException + */ + private function getChildDiscriminatorsFromClassMetadata(ClassMetadataInfo $discrClass, AST\InstanceOfExpression $instanceOfExpr) + { + $knownSubclasses = array_flip($discrClass->subClasses); + $sqlParameterList = []; + $discriminators = []; + foreach ($instanceOfExpr->value as $parameter) { + if ($parameter instanceof AST\InputParameter) { + $this->rsm->addMetadataParameterMapping($parameter->name, 'discriminatorValue'); + + $sqlParameterList[] = $this->walkInputParameter($parameter); + + continue; + } + + // Trim first backslash + $parameter = ltrim($parameter, '\\'); + + if ($parameter !== $discrClass->name && ! array_key_exists($parameter, $knownSubclasses)) { + throw QueryException::instanceOfUnrelatedClass($parameter, $discrClass->name); + } + + // Include discriminators for parameter class and its subclass + $metadata = $this->em->getClassMetadata($parameter); + $hierarchyClasses = $metadata->subClasses; + $hierarchyClasses[] = $metadata->name; + + foreach ($hierarchyClasses as $class) { + $currentMetadata = $this->em->getClassMetadata($class); + $currentDiscriminator = $currentMetadata->discriminatorValue; + + if (is_string($currentDiscriminator) && ! array_key_exists($currentDiscriminator, $discriminators)) { + $discriminators[$currentDiscriminator] = true; + } + } + } + + foreach (array_keys($discriminators) as $dis) { + $sqlParameterList[] = $this->conn->quote($dis); + } + + return '(' . implode(', ', $sqlParameterList) . ')'; + } } From bd47ec95a10d0d5f358a3de299ba8fd0e9f114a5 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 3 May 2017 11:06:43 +0200 Subject: [PATCH 370/877] Move tests to ticket namespace (and rename them) --- .../Ticket4646InstanceOfAbstractTest.php} | 10 +++++----- .../Ticket4646InstanceOfMultiLevelTest.php} | 6 +++--- .../Ticket4646InstanceOfTest.php} | 14 ++++++++------ 3 files changed, 16 insertions(+), 14 deletions(-) rename tests/Doctrine/Tests/ORM/Functional/{InstanceOfAbstractTest.php => Ticket/Ticket4646InstanceOfAbstractTest.php} (88%) rename tests/Doctrine/Tests/ORM/Functional/{InstanceOfMultiLevelTest.php => Ticket/Ticket4646InstanceOfMultiLevelTest.php} (95%) rename tests/Doctrine/Tests/ORM/Functional/{InstanceOfTest.php => Ticket/Ticket4646InstanceOfTest.php} (86%) diff --git a/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php similarity index 88% rename from tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php rename to tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php index 1b826a4619d..b17ca2c2d3c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/InstanceOfAbstractTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php @@ -1,12 +1,12 @@ assertCount(1, $result); foreach ($result as $r) { - $this->assertInstanceOf(InstanceOfAbstractTest\Person::class, $r); - $this->assertInstanceOf(InstanceOfAbstractTest\Employee::class, $r); + $this->assertInstanceOf(Person::class, $r); + $this->assertInstanceOf(Employee::class, $r); $this->assertSame('bar', $r->getName()); } } private function loadData() { - $employee = new InstanceOfAbstractTest\Employee(); + $employee = new Employee(); $employee->setName('bar'); $employee->setDepartement('qux'); diff --git a/tests/Doctrine/Tests/ORM/Functional/InstanceOfMultiLevelTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php similarity index 95% rename from tests/Doctrine/Tests/ORM/Functional/InstanceOfMultiLevelTest.php rename to tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php index 131f053a285..79f0d5363c0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/InstanceOfMultiLevelTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php @@ -1,13 +1,13 @@ assertInstanceOf(Person::class, $r); - if ($r instanceof InstanceOfMultiLevelTest\Engineer) { + if ($r instanceof Engineer) { $this->assertEquals('foobar', $r->getName()); $this->assertEquals('doctrine', $r->getSpecialization()); } elseif ($r instanceof Employee) { diff --git a/tests/Doctrine/Tests/ORM/Functional/InstanceOfTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php similarity index 86% rename from tests/Doctrine/Tests/ORM/Functional/InstanceOfTest.php rename to tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php index fce0075b63f..326b83393a4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/InstanceOfTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php @@ -1,10 +1,12 @@ assertCount(2, $result); foreach ($result as $r) { - $this->assertInstanceOf(InstanceOfTest\Person::class, $r); - if ($r instanceof InstanceOfTest\Employee) { + $this->assertInstanceOf(Person::class, $r); + if ($r instanceof Employee) { $this->assertEquals('bar', $r->getName()); } else { $this->assertEquals('foo', $r->getName()); @@ -39,10 +41,10 @@ public function testInstanceOf() private function loadData() { - $person = new InstanceOfTest\Person(); + $person = new Person(); $person->setName('foo'); - $employee = new InstanceOfTest\Employee(); + $employee = new Employee(); $employee->setName('bar'); $employee->setDepartement('qux'); From 31d2d841601c64d686385ac58cc63778d24c8751 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 3 May 2017 11:42:51 +0200 Subject: [PATCH 371/877] Fix test --- .../Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php index 326b83393a4..35d4afdac66 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php @@ -13,8 +13,8 @@ protected function setUp() parent::setUp(); $this->_schemaTool->createSchema([ - $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfTest\Person'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfTest\Employee'), + $this->_em->getClassMetadata(Person::class), + $this->_em->getClassMetadata(Employee::class), ]); } From 5181eae8d683ffc0367229df40d52da9895568a6 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 21 Jun 2017 09:34:16 +0200 Subject: [PATCH 372/877] Refactor a bit the SqlWalker modifications --- lib/Doctrine/ORM/Query/SqlWalker.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index baf05ffcabf..33ee45d19fd 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -2277,7 +2277,6 @@ public function walkResultVariable($resultVariable) */ private function getChildDiscriminatorsFromClassMetadata(ClassMetadataInfo $discrClass, AST\InstanceOfExpression $instanceOfExpr) { - $knownSubclasses = array_flip($discrClass->subClasses); $sqlParameterList = []; $discriminators = []; foreach ($instanceOfExpr->value as $parameter) { @@ -2289,15 +2288,13 @@ private function getChildDiscriminatorsFromClassMetadata(ClassMetadataInfo $disc continue; } - // Trim first backslash - $parameter = ltrim($parameter, '\\'); + $metadata = $this->em->getClassMetadata($parameter); - if ($parameter !== $discrClass->name && ! array_key_exists($parameter, $knownSubclasses)) { + if ($metadata->getReflectionClass()->isSubclassOf($discrClass->name)) { throw QueryException::instanceOfUnrelatedClass($parameter, $discrClass->name); } // Include discriminators for parameter class and its subclass - $metadata = $this->em->getClassMetadata($parameter); $hierarchyClasses = $metadata->subClasses; $hierarchyClasses[] = $metadata->name; @@ -2305,15 +2302,13 @@ private function getChildDiscriminatorsFromClassMetadata(ClassMetadataInfo $disc $currentMetadata = $this->em->getClassMetadata($class); $currentDiscriminator = $currentMetadata->discriminatorValue; - if (is_string($currentDiscriminator) && ! array_key_exists($currentDiscriminator, $discriminators)) { - $discriminators[$currentDiscriminator] = true; + if (null !== $currentDiscriminator && ! array_key_exists($currentDiscriminator, $discriminators)) { + $discriminators[$currentDiscriminator] = null; } } } - foreach (array_keys($discriminators) as $dis) { - $sqlParameterList[] = $this->conn->quote($dis); - } + $sqlParameterList = array_map([$this->conn, 'quote'], array_keys($discriminators)); return '(' . implode(', ', $sqlParameterList) . ')'; } From 167dfde00f047a99495e1098db114f96d4f892f3 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 21 Jun 2017 10:11:31 +0200 Subject: [PATCH 373/877] Apply additional fixes to the SqlWalker to fix tests --- lib/Doctrine/ORM/Query/SqlWalker.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 33ee45d19fd..78179d367ef 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -2290,7 +2290,7 @@ private function getChildDiscriminatorsFromClassMetadata(ClassMetadataInfo $disc $metadata = $this->em->getClassMetadata($parameter); - if ($metadata->getReflectionClass()->isSubclassOf($discrClass->name)) { + if (! $metadata->getReflectionClass()->isSubclassOf($discrClass->name)) { throw QueryException::instanceOfUnrelatedClass($parameter, $discrClass->name); } @@ -2302,13 +2302,15 @@ private function getChildDiscriminatorsFromClassMetadata(ClassMetadataInfo $disc $currentMetadata = $this->em->getClassMetadata($class); $currentDiscriminator = $currentMetadata->discriminatorValue; - if (null !== $currentDiscriminator && ! array_key_exists($currentDiscriminator, $discriminators)) { + if (null !== $currentDiscriminator) { $discriminators[$currentDiscriminator] = null; } } } - $sqlParameterList = array_map([$this->conn, 'quote'], array_keys($discriminators)); + foreach (array_keys($discriminators) as $dis) { + $sqlParameterList[] = $this->conn->quote($dis); + } return '(' . implode(', ', $sqlParameterList) . ')'; } From d2f75142486ef8e7fe60e87692ab82f765086b03 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 21 Jun 2017 10:26:31 +0200 Subject: [PATCH 374/877] Put all tests classes in a single namespace --- lib/Doctrine/ORM/Query/SqlWalker.php | 2 +- .../Ticket4646InstanceOfAbstractTest.php | 162 ++++++------ .../Ticket4646InstanceOfMultiLevelTest.php | 236 +++++++++--------- .../Ticket/Ticket4646InstanceOfTest.php | 175 +++++++------ 4 files changed, 279 insertions(+), 296 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 78179d367ef..8c8ef30d13b 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -2290,7 +2290,7 @@ private function getChildDiscriminatorsFromClassMetadata(ClassMetadataInfo $disc $metadata = $this->em->getClassMetadata($parameter); - if (! $metadata->getReflectionClass()->isSubclassOf($discrClass->name)) { + if ($metadata->getName() !== $discrClass->name && ! $metadata->getReflectionClass()->isSubclassOf($discrClass->name)) { throw QueryException::instanceOfUnrelatedClass($parameter, $discrClass->name); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php index b17ca2c2d3c..090a172a93f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php @@ -1,114 +1,108 @@ _schemaTool->createSchema([ - $this->_em->getClassMetadata(Person::class), - $this->_em->getClassMetadata(Employee::class), - ]); - } + parent::setUp(); + + $this->_schemaTool->createSchema([ + $this->_em->getClassMetadata(PersonTicket4646Abstract::class), + $this->_em->getClassMetadata(EmployeeTicket4646Abstract::class), + ]); + } - public function testInstanceOf() - { - $this->loadData(); + public function testInstanceOf() + { + $this->loadData(); - $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Person p - WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Person'; - $query = $this->_em->createQuery($dql); - $result = $query->getResult(); + $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646Abstract p + WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646Abstract'; + $query = $this->_em->createQuery($dql); + $result = $query->getResult(); - $this->assertCount(1, $result); + $this->assertCount(1, $result); - foreach ($result as $r) { - $this->assertInstanceOf(Person::class, $r); - $this->assertInstanceOf(Employee::class, $r); - $this->assertSame('bar', $r->getName()); - } + foreach ($result as $r) { + $this->assertInstanceOf(PersonTicket4646Abstract::class, $r); + $this->assertInstanceOf(EmployeeTicket4646Abstract::class, $r); + $this->assertSame('bar', $r->getName()); } + } - private function loadData() - { - $employee = new Employee(); - $employee->setName('bar'); - $employee->setDepartement('qux'); + private function loadData() + { + $employee = new EmployeeTicket4646Abstract(); + $employee->setName('bar'); + $employee->setDepartement('qux'); - $this->_em->persist($employee); + $this->_em->persist($employee); - $this->_em->flush($employee); - } + $this->_em->flush($employee); } } -namespace Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest { +/** + * @Entity() + * @Table(name="instance_of_abstract_test_person") + * @InheritanceType(value="JOINED") + * @DiscriminatorColumn(name="kind", type="string") + * @DiscriminatorMap(value={ + * "employee": EmployeeTicket4646Abstract::class + * }) + */ +abstract class PersonTicket4646Abstract +{ + /** + * @Id() + * @GeneratedValue() + * @Column(type="integer") + */ + private $id; /** - * @Entity() - * @Table(name="instance_of_abstract_test_person") - * @InheritanceType(value="JOINED") - * @DiscriminatorColumn(name="kind", type="string") - * @DiscriminatorMap(value={ - * "employee": Employee::class - * }) + * @Column(type="string") */ - abstract class Person + private $name; + + public function getId() { - /** - * @Id() - * @GeneratedValue() - * @Column(type="integer") - */ - private $id; - - /** - * @Column(type="string") - */ - private $name; - - public function getId() - { - return $this->id; - } + return $this->id; + } - public function getName() - { - return $this->name; - } + public function getName() + { + return $this->name; + } - public function setName($name) - { - $this->name = $name; - } + public function setName($name) + { + $this->name = $name; } +} +/** + * @Entity() + * @Table(name="instance_of_abstract_test_employee") + */ +class EmployeeTicket4646Abstract extends PersonTicket4646Abstract +{ /** - * @Entity() - * @Table(name="instance_of_abstract_test_employee") + * @Column(type="string") */ - class Employee extends Person + private $departement; + + public function getDepartement() { - /** - * @Column(type="string") - */ - private $departement; - - public function getDepartement() - { - return $this->departement; - } + return $this->departement; + } - public function setDepartement($departement) - { - $this->departement = $departement; - } + public function setDepartement($departement) + { + $this->departement = $departement; } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php index 79f0d5363c0..649de27bb5b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php @@ -1,156 +1,150 @@ _schemaTool->createSchema([ - $this->_em->getClassMetadata(Person::class), - $this->_em->getClassMetadata(Employee::class), - $this->_em->getClassMetadata(Engineer::class), - ]); - } + parent::setUp(); + + $this->_schemaTool->createSchema([ + $this->_em->getClassMetadata(PersonTicket4646MultiLevel::class), + $this->_em->getClassMetadata(EmployeeTicket4646MultiLevel::class), + $this->_em->getClassMetadata(EngineerTicket4646MultiLevel::class), + ]); + } - public function testInstanceOf() - { - $this->loadData(); - - $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Person p - WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Person'; - $query = $this->_em->createQuery($dql); - $result = $query->getResult(); - - $this->assertCount(3, $result); - - foreach ($result as $r) { - $this->assertInstanceOf(Person::class, $r); - if ($r instanceof Engineer) { - $this->assertEquals('foobar', $r->getName()); - $this->assertEquals('doctrine', $r->getSpecialization()); - } elseif ($r instanceof Employee) { - $this->assertEquals('bar', $r->getName()); - $this->assertEquals('qux', $r->getDepartement()); - } else { - $this->assertEquals('foo', $r->getName()); - } + public function testInstanceOf() + { + $this->loadData(); + + $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646MultiLevel p + WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646MultiLevel'; + $query = $this->_em->createQuery($dql); + $result = $query->getResult(); + + $this->assertCount(3, $result); + + foreach ($result as $r) { + $this->assertInstanceOf(PersonTicket4646MultiLevel::class, $r); + if ($r instanceof EngineerTicket4646MultiLevel) { + $this->assertEquals('foobar', $r->getName()); + $this->assertEquals('doctrine', $r->getSpecialization()); + } elseif ($r instanceof EmployeeTicket4646MultiLevel) { + $this->assertEquals('bar', $r->getName()); + $this->assertEquals('qux', $r->getDepartement()); + } else { + $this->assertEquals('foo', $r->getName()); } } + } - private function loadData() - { - $person = new Person(); - $person->setName('foo'); + private function loadData() + { + $person = new PersonTicket4646MultiLevel(); + $person->setName('foo'); - $employee = new Employee(); - $employee->setName('bar'); - $employee->setDepartement('qux'); + $employee = new EmployeeTicket4646MultiLevel(); + $employee->setName('bar'); + $employee->setDepartement('qux'); - $engineer = new Engineer(); - $engineer->setName('foobar'); - $engineer->setDepartement('dep'); - $engineer->setSpecialization('doctrine'); + $engineer = new EngineerTicket4646MultiLevel(); + $engineer->setName('foobar'); + $engineer->setDepartement('dep'); + $engineer->setSpecialization('doctrine'); - $this->_em->persist($person); - $this->_em->persist($employee); - $this->_em->persist($engineer); + $this->_em->persist($person); + $this->_em->persist($employee); + $this->_em->persist($engineer); - $this->_em->flush(array($person, $employee, $engineer)); - } + $this->_em->flush(array($person, $employee, $engineer)); } } -namespace Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest { +/** + * @Entity() + * @Table(name="instance_of_multi_level_test_person") + * @InheritanceType(value="JOINED") + * @DiscriminatorColumn(name="kind", type="string") + * @DiscriminatorMap(value={ + * "person": "Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646MultiLevel", + * "employee": "Doctrine\Tests\ORM\Functional\Ticket\EmployeeTicket4646MultiLevel", + * "engineer": "Doctrine\Tests\ORM\Functional\Ticket\EngineerTicket4646MultiLevel", + * }) + */ +class PersonTicket4646MultiLevel +{ /** - * @Entity() - * @Table(name="instance_of_multi_level_test_person") - * @InheritanceType(value="JOINED") - * @DiscriminatorColumn(name="kind", type="string") - * @DiscriminatorMap(value={ - * "person": "Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Person", - * "employee": "Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Employee", - * "engineer": "Doctrine\Tests\ORM\Functional\InstanceOfMultiLevelTest\Engineer", - * }) + * @Id() + * @GeneratedValue() + * @Column(type="integer") */ - class Person + private $id; + + /** + * @Column(type="string") + */ + private $name; + + public function getId() { - /** - * @Id() - * @GeneratedValue() - * @Column(type="integer") - */ - private $id; - - /** - * @Column(type="string") - */ - private $name; - - public function getId() - { - return $this->id; - } + return $this->id; + } - public function getName() - { - return $this->name; - } + public function getName() + { + return $this->name; + } - public function setName($name) - { - $this->name = $name; - } + public function setName($name) + { + $this->name = $name; } +} +/** + * @Entity() + * @Table(name="instance_of_multi_level_employee") + */ +class EmployeeTicket4646MultiLevel extends PersonTicket4646MultiLevel +{ /** - * @Entity() - * @Table(name="instance_of_multi_level_employee") + * @Column(type="string") */ - class Employee extends Person + private $departement; + + public function getDepartement() { - /** - * @Column(type="string") - */ - private $departement; - - public function getDepartement() - { - return $this->departement; - } + return $this->departement; + } - public function setDepartement($departement) - { - $this->departement = $departement; - } + public function setDepartement($departement) + { + $this->departement = $departement; } +} +/** + * @Entity() + * @Table(name="instance_of_multi_level_engineer") + */ +class EngineerTicket4646MultiLevel extends EmployeeTicket4646MultiLevel +{ /** - * @Entity() - * @Table(name="instance_of_multi_level_engineer") + * @Column(type="string") */ - class Engineer extends Employee + private $specialization; + + public function getSpecialization() { - /** - * @Column(type="string") - */ - private $specialization; - - public function getSpecialization() - { - return $this->specialization; - } + return $this->specialization; + } - public function setSpecialization($specialization) - { - $this->specialization = $specialization; - } + public function setSpecialization($specialization) + { + $this->specialization = $specialization; } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php index 35d4afdac66..a83e6e7338b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php @@ -1,121 +1,116 @@ _schemaTool->createSchema([ - $this->_em->getClassMetadata(Person::class), - $this->_em->getClassMetadata(Employee::class), - ]); - } + parent::setUp(); + + $this->_schemaTool->createSchema([ + $this->_em->getClassMetadata(PersonTicket4646::class), + $this->_em->getClassMetadata(EmployeeTicket4646::class), + ]); + } - public function testInstanceOf() - { - $this->loadData(); + public function testInstanceOf() + { + $this->loadData(); - $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\InstanceOfTest\Person p - WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\InstanceOfTest\Person'; - $query = $this->_em->createQuery($dql); - $result = $query->getResult(); + $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646 p + WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646'; + $query = $this->_em->createQuery($dql); + $result = $query->getResult(); - $this->assertCount(2, $result); + $this->assertCount(2, $result); - foreach ($result as $r) { - $this->assertInstanceOf(Person::class, $r); - if ($r instanceof Employee) { - $this->assertEquals('bar', $r->getName()); - } else { - $this->assertEquals('foo', $r->getName()); - } + foreach ($result as $r) { + $this->assertInstanceOf(PersonTicket4646::class, $r); + if ($r instanceof EmployeeTicket4646) { + $this->assertEquals('bar', $r->getName()); + } else { + $this->assertEquals('foo', $r->getName()); } } + } - private function loadData() - { - $person = new Person(); - $person->setName('foo'); + private function loadData() + { + $person = new PersonTicket4646(); + $person->setName('foo'); - $employee = new Employee(); - $employee->setName('bar'); - $employee->setDepartement('qux'); + $employee = new EmployeeTicket4646(); + $employee->setName('bar'); + $employee->setDepartement('qux'); - $this->_em->persist($person); - $this->_em->persist($employee); + $this->_em->persist($person); + $this->_em->persist($employee); - $this->_em->flush(array($person, $employee)); - } + $this->_em->flush(array($person, $employee)); } } -namespace Doctrine\Tests\ORM\Functional\InstanceOfTest { +/** + * @Entity() + * @Table(name="instance_of_test_person") + * @InheritanceType(value="JOINED") + * @DiscriminatorColumn(name="kind", type="string") + * @DiscriminatorMap(value={ + * "person": "Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646", + * "employee": "Doctrine\Tests\ORM\Functional\Ticket\EmployeeTicket4646" + * }) + */ +class PersonTicket4646 +{ + /** + * @Id() + * @GeneratedValue() + * @Column(type="integer") + */ + private $id; + /** - * @Entity() - * @Table(name="instance_of_test_person") - * @InheritanceType(value="JOINED") - * @DiscriminatorColumn(name="kind", type="string") - * @DiscriminatorMap(value={ - * "person": "Doctrine\Tests\ORM\Functional\InstanceOfTest\Person", - * "employee": "Doctrine\Tests\ORM\Functional\InstanceOfTest\Employee" - * }) + * @Column(type="string") */ - class Person + private $name; + + public function getId() { - /** - * @Id() - * @GeneratedValue() - * @Column(type="integer") - */ - private $id; - - /** - * @Column(type="string") - */ - private $name; - - public function getId() - { - return $this->id; - } + return $this->id; + } - public function getName() - { - return $this->name; - } + public function getName() + { + return $this->name; + } - public function setName($name) - { - $this->name = $name; - } + public function setName($name) + { + $this->name = $name; } +} +/** + * @Entity() + * @Table(name="instance_of_test_employee") + */ +class EmployeeTicket4646 extends PersonTicket4646 +{ /** - * @Entity() - * @Table(name="instance_of_test_employee") + * @Column(type="string") */ - class Employee extends Person + private $departement; + + public function getDepartement() { - /** - * @Column(type="string") - */ - private $departement; - - public function getDepartement() - { - return $this->departement; - } + return $this->departement; + } - public function setDepartement($departement) - { - $this->departement = $departement; - } + public function setDepartement($departement) + { + $this->departement = $departement; } } From 2fd875281809ce1de4fa33070c7dc11895312f0e Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 21 Jun 2017 13:25:31 +0200 Subject: [PATCH 375/877] Simplify stubs used in tests --- .../Ticket4646InstanceOfAbstractTest.php | 50 +---------- .../Ticket4646InstanceOfMultiLevelTest.php | 83 ++----------------- .../Ticket/Ticket4646InstanceOfTest.php | 58 +------------ 3 files changed, 12 insertions(+), 179 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php index 090a172a93f..f0ea53fe87f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php @@ -18,7 +18,8 @@ protected function setUp() public function testInstanceOf() { - $this->loadData(); + $this->_em->persist(new EmployeeTicket4646Abstract()); + $this->_em->flush(); $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646Abstract p WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646Abstract'; @@ -26,23 +27,7 @@ public function testInstanceOf() $result = $query->getResult(); $this->assertCount(1, $result); - - foreach ($result as $r) { - $this->assertInstanceOf(PersonTicket4646Abstract::class, $r); - $this->assertInstanceOf(EmployeeTicket4646Abstract::class, $r); - $this->assertSame('bar', $r->getName()); - } - } - - private function loadData() - { - $employee = new EmployeeTicket4646Abstract(); - $employee->setName('bar'); - $employee->setDepartement('qux'); - - $this->_em->persist($employee); - - $this->_em->flush($employee); + $this->assertContainsOnlyInstancesOf(PersonTicket4646Abstract::class, $result); } } @@ -64,25 +49,10 @@ abstract class PersonTicket4646Abstract */ private $id; - /** - * @Column(type="string") - */ - private $name; - public function getId() { return $this->id; } - - public function getName() - { - return $this->name; - } - - public function setName($name) - { - $this->name = $name; - } } /** @@ -91,18 +61,4 @@ public function setName($name) */ class EmployeeTicket4646Abstract extends PersonTicket4646Abstract { - /** - * @Column(type="string") - */ - private $departement; - - public function getDepartement() - { - return $this->departement; - } - - public function setDepartement($departement) - { - $this->departement = $departement; - } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php index 649de27bb5b..6e4160b24f2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php @@ -19,7 +19,10 @@ protected function setUp() public function testInstanceOf() { - $this->loadData(); + $this->_em->persist(new PersonTicket4646MultiLevel()); + $this->_em->persist(new EmployeeTicket4646MultiLevel()); + $this->_em->persist(new EngineerTicket4646MultiLevel()); + $this->_em->flush(); $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646MultiLevel p WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646MultiLevel'; @@ -27,40 +30,7 @@ public function testInstanceOf() $result = $query->getResult(); $this->assertCount(3, $result); - - foreach ($result as $r) { - $this->assertInstanceOf(PersonTicket4646MultiLevel::class, $r); - if ($r instanceof EngineerTicket4646MultiLevel) { - $this->assertEquals('foobar', $r->getName()); - $this->assertEquals('doctrine', $r->getSpecialization()); - } elseif ($r instanceof EmployeeTicket4646MultiLevel) { - $this->assertEquals('bar', $r->getName()); - $this->assertEquals('qux', $r->getDepartement()); - } else { - $this->assertEquals('foo', $r->getName()); - } - } - } - - private function loadData() - { - $person = new PersonTicket4646MultiLevel(); - $person->setName('foo'); - - $employee = new EmployeeTicket4646MultiLevel(); - $employee->setName('bar'); - $employee->setDepartement('qux'); - - $engineer = new EngineerTicket4646MultiLevel(); - $engineer->setName('foobar'); - $engineer->setDepartement('dep'); - $engineer->setSpecialization('doctrine'); - - $this->_em->persist($person); - $this->_em->persist($employee); - $this->_em->persist($engineer); - - $this->_em->flush(array($person, $employee, $engineer)); + $this->assertContainsOnlyInstancesOf(PersonTicket4646MultiLevel::class, $result); } } @@ -84,25 +54,10 @@ class PersonTicket4646MultiLevel */ private $id; - /** - * @Column(type="string") - */ - private $name; - public function getId() { return $this->id; } - - public function getName() - { - return $this->name; - } - - public function setName($name) - { - $this->name = $name; - } } /** @@ -111,20 +66,6 @@ public function setName($name) */ class EmployeeTicket4646MultiLevel extends PersonTicket4646MultiLevel { - /** - * @Column(type="string") - */ - private $departement; - - public function getDepartement() - { - return $this->departement; - } - - public function setDepartement($departement) - { - $this->departement = $departement; - } } /** @@ -133,18 +74,4 @@ public function setDepartement($departement) */ class EngineerTicket4646MultiLevel extends EmployeeTicket4646MultiLevel { - /** - * @Column(type="string") - */ - private $specialization; - - public function getSpecialization() - { - return $this->specialization; - } - - public function setSpecialization($specialization) - { - $this->specialization = $specialization; - } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php index a83e6e7338b..363611d4db8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php @@ -18,7 +18,9 @@ protected function setUp() public function testInstanceOf() { - $this->loadData(); + $this->_em->persist(new PersonTicket4646()); + $this->_em->persist(new EmployeeTicket4646()); + $this->_em->flush(); $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646 p WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646'; @@ -26,30 +28,7 @@ public function testInstanceOf() $result = $query->getResult(); $this->assertCount(2, $result); - - foreach ($result as $r) { - $this->assertInstanceOf(PersonTicket4646::class, $r); - if ($r instanceof EmployeeTicket4646) { - $this->assertEquals('bar', $r->getName()); - } else { - $this->assertEquals('foo', $r->getName()); - } - } - } - - private function loadData() - { - $person = new PersonTicket4646(); - $person->setName('foo'); - - $employee = new EmployeeTicket4646(); - $employee->setName('bar'); - $employee->setDepartement('qux'); - - $this->_em->persist($person); - $this->_em->persist($employee); - - $this->_em->flush(array($person, $employee)); + $this->assertContainsOnlyInstancesOf(PersonTicket4646::class, $result); } } @@ -72,25 +51,10 @@ class PersonTicket4646 */ private $id; - /** - * @Column(type="string") - */ - private $name; - public function getId() { return $this->id; } - - public function getName() - { - return $this->name; - } - - public function setName($name) - { - $this->name = $name; - } } /** @@ -99,18 +63,4 @@ public function setName($name) */ class EmployeeTicket4646 extends PersonTicket4646 { - /** - * @Column(type="string") - */ - private $departement; - - public function getDepartement() - { - return $this->departement; - } - - public function setDepartement($departement) - { - $this->departement = $departement; - } } From b1f7c59ed560af7770d2ff649d7461605253d1cd Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Thu, 22 Jun 2017 09:50:53 +0200 Subject: [PATCH 376/877] Adding a failing test case for parameter binding using metadata with INSTANCE OF --- .../Ticket4646InstanceOfParametricTest.php | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfParametricTest.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfParametricTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfParametricTest.php new file mode 100644 index 00000000000..302934e8c10 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfParametricTest.php @@ -0,0 +1,67 @@ +_schemaTool->createSchema([ + $this->_em->getClassMetadata(PersonTicket4646Parametric::class), + $this->_em->getClassMetadata(EmployeeTicket4646Parametric::class), + ]); + } + + public function testInstanceOf() + { + $this->_em->persist(new PersonTicket4646Parametric()); + $this->_em->persist(new EmployeeTicket4646Parametric()); + $this->_em->flush(); + $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646Parametric p + WHERE p INSTANCE OF :parameter'; + $query = $this->_em->createQuery($dql); + $query->setParameter( + 'parameter', + $this->_em->getClassMetadata(PersonTicket4646Parametric::class) + ); + $result = $query->getResult(); + $this->assertCount(2, $result); + $this->assertContainsOnlyInstancesOf(PersonTicket4646Parametric::class, $result); + } +} + +/** + * @Entity() + * @Table(name="instance_of_parametric_person") + * @InheritanceType(value="JOINED") + * @DiscriminatorColumn(name="kind", type="string") + * @DiscriminatorMap(value={ + * "person": "Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646Parametric", + * "employee": "Doctrine\Tests\ORM\Functional\Ticket\EmployeeTicket4646Parametric" + * }) + */ +class PersonTicket4646Parametric +{ + /** + * @Id() + * @GeneratedValue() + * @Column(type="integer") + */ + private $id; + + public function getId() + { + return $this->id; + } +} + +/** + * @Entity() + * @Table(name="instance_of_parametric_employee") + */ +class EmployeeTicket4646Parametric extends PersonTicket4646Parametric +{ +} From e91dcf8fb44c2e15afdcdbf403ef62af88547b45 Mon Sep 17 00:00:00 2001 From: Sergio Santoro Date: Sat, 24 Jun 2017 13:35:44 +0200 Subject: [PATCH 377/877] Fix discriminator resolution when using parameters --- lib/Doctrine/ORM/Query.php | 23 ++++++++++ lib/Doctrine/ORM/Query/ResultSetMapping.php | 7 +++ lib/Doctrine/ORM/Query/SqlWalker.php | 46 +++++++++++-------- .../ORM/Functional/Ticket/DDC1995Test.php | 5 +- 4 files changed, 58 insertions(+), 23 deletions(-) diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 385b8c8ea6b..a86cf620124 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -371,6 +371,25 @@ private function evictEntityCacheRegion() $this->_em->getCache()->evictEntityRegion($className); } + private function getAllDiscriminators(ClassMetadata $classMetadata) + { + // FIXME: this code is copied from SqlWalker->getAllDiscriminators() + $hierarchyClasses = $classMetadata->subClasses; + $hierarchyClasses[] = $classMetadata->name; + + $discriminators = []; + foreach ($hierarchyClasses as $class) { + $currentMetadata = $this->getEntityManager()->getClassMetadata($class); + $currentDiscriminator = $currentMetadata->discriminatorValue; + + if (null !== $currentDiscriminator) { + $discriminators[$currentDiscriminator] = null; + } + } + + return $discriminators; + } + /** * Processes query parameter mappings. * @@ -398,6 +417,10 @@ private function processParameterMappings($paramMappings) $value = $value->getMetadataValue($rsm->metadataParameterMapping[$key]); } + if (isset($rsm->discriminatorParameters[$key]) && $value instanceof ClassMetadata) { + $value = array_keys($this->getAllDiscriminators($value)); + } + $value = $this->processParameterValue($value); $type = ($parameter->getValue() === $value) ? $parameter->getType() diff --git a/lib/Doctrine/ORM/Query/ResultSetMapping.php b/lib/Doctrine/ORM/Query/ResultSetMapping.php index 5c4550980e1..058ae8d4c54 100644 --- a/lib/Doctrine/ORM/Query/ResultSetMapping.php +++ b/lib/Doctrine/ORM/Query/ResultSetMapping.php @@ -168,6 +168,13 @@ class ResultSetMapping */ public $metadataParameterMapping = []; + /** + * Contains query parameter names to be resolved as discriminator values + * + * @var array + */ + public $discriminatorParameters = []; + /** * Adds an entity result to this ResultSetMapping. * diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 8c8ef30d13b..3407b0a8b5a 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -2270,42 +2270,29 @@ public function walkResultVariable($resultVariable) } /** - * @param ClassMetadataInfo $discrClass + * @param ClassMetadataInfo $rootClass * @param AST\InstanceOfExpression $instanceOfExpr * @return string The list in parentheses of valid child discriminators from the given class * @throws QueryException */ - private function getChildDiscriminatorsFromClassMetadata(ClassMetadataInfo $discrClass, AST\InstanceOfExpression $instanceOfExpr) + private function getChildDiscriminatorsFromClassMetadata(ClassMetadataInfo $rootClass, AST\InstanceOfExpression $instanceOfExpr) { $sqlParameterList = []; $discriminators = []; foreach ($instanceOfExpr->value as $parameter) { if ($parameter instanceof AST\InputParameter) { - $this->rsm->addMetadataParameterMapping($parameter->name, 'discriminatorValue'); - - $sqlParameterList[] = $this->walkInputParameter($parameter); - + $this->rsm->discriminatorParameters[$parameter->name] = $parameter->name; + $sqlParameterList[] = $this->walkInParameter($parameter); continue; } $metadata = $this->em->getClassMetadata($parameter); - if ($metadata->getName() !== $discrClass->name && ! $metadata->getReflectionClass()->isSubclassOf($discrClass->name)) { - throw QueryException::instanceOfUnrelatedClass($parameter, $discrClass->name); + if ($metadata->getName() !== $rootClass->name && ! $metadata->getReflectionClass()->isSubclassOf($rootClass->name)) { + throw QueryException::instanceOfUnrelatedClass($parameter, $rootClass->name); } - // Include discriminators for parameter class and its subclass - $hierarchyClasses = $metadata->subClasses; - $hierarchyClasses[] = $metadata->name; - - foreach ($hierarchyClasses as $class) { - $currentMetadata = $this->em->getClassMetadata($class); - $currentDiscriminator = $currentMetadata->discriminatorValue; - - if (null !== $currentDiscriminator) { - $discriminators[$currentDiscriminator] = null; - } - } + $discriminators = $discriminators + $this->getAllDiscriminators($metadata); } foreach (array_keys($discriminators) as $dis) { @@ -2314,4 +2301,23 @@ private function getChildDiscriminatorsFromClassMetadata(ClassMetadataInfo $disc return '(' . implode(', ', $sqlParameterList) . ')'; } + + private function getAllDiscriminators(ClassMetadata $classMetadata) + { + // FIXME: this code is identical to Query->getAllDiscriminators() + $hierarchyClasses = $classMetadata->subClasses; + $hierarchyClasses[] = $classMetadata->name; + + $discriminators = []; + foreach ($hierarchyClasses as $class) { + $currentMetadata = $this->em->getClassMetadata($class); + $currentDiscriminator = $currentMetadata->discriminatorValue; + + if (null !== $currentDiscriminator) { + $discriminators[$currentDiscriminator] = null; + } + } + + return $discriminators; + } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1995Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1995Test.php index fb32b99fe51..8bb975a05b3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1995Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1995Test.php @@ -72,10 +72,9 @@ public function testQueryCache() ->getResult(); $this->assertCount(1, $result1); - $this->assertCount(1, $result2); + $this->assertCount(2, $result2); $this->assertInstanceOf(CompanyEmployee::class, $result1[0]); - $this->assertInstanceOf(CompanyPerson::class, $result2[0]); - $this->assertNotInstanceOf(CompanyEmployee::class, $result2[0]); + $this->assertContainsOnlyInstancesOf(CompanyPerson::class, $result2); } } From 1231861b096ab640234e3e8b7c05cfe6770e96b9 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Sun, 14 May 2017 23:31:15 +0200 Subject: [PATCH 378/877] Initial PHPStan integration (level 0) --- .travis.yml | 7 +++++++ lib/Doctrine/ORM/PersistentCollection.php | 5 +++-- lib/Doctrine/ORM/Query/ResultSetMapping.php | 2 +- phpstan.neon | 4 ++++ 4 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 phpstan.neon diff --git a/.travis.yml b/.travis.yml index 667d3f2d0b9..b6b914adf1f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,13 +14,16 @@ env: before_script: - if [[ $TRAVIS_PHP_VERSION = '7.1' && $DB = 'sqlite' && "$DEPENDENCIES" != "low" ]]; then PHPUNIT_FLAGS="--coverage-clover ./build/logs/clover.xml"; else PHPUNIT_FLAGS=""; fi - if [[ "$PHPUNIT_FLAGS" == "" ]]; then phpenv config-rm xdebug.ini; fi + - if [[ $PHPSTAN = 1 ]]; then echo "extension=redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi - composer self-update - composer install --prefer-source - if [ "$DEPENDENCIES" != "low" ]; then composer update; fi; - if [ "$DEPENDENCIES" == "low" ]; then composer update --prefer-lowest; fi; + - if [[ $PHPSTAN = 1 ]]; then composer require --dev --prefer-stable phpstan/phpstan:^0.7 symfony/console:^3.0; fi - if [[ $DB == "mysql" || $DB == "mariadb" ]]; then mysql -e "CREATE SCHEMA doctrine_tests; GRANT ALL PRIVILEGES ON doctrine_tests.* to travis@'%'"; fi; script: + - if [[ $PHPSTAN = 1 ]]; then vendor/bin/phpstan analyse -l 0 -c phpstan.neon lib; fi - ENABLE_SECOND_LEVEL_CACHE=0 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml $PHPUNIT_FLAGS - ENABLE_SECOND_LEVEL_CACHE=1 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml --exclude-group performance,non-cacheable,locking_functional @@ -39,6 +42,10 @@ matrix: env: - DB=sqlite - DEPENDENCIES='low' + - php: 7.1 + env: + - DB=pgsql + - PHPSTAN=1 allow_failures: - php: nightly diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index 11205df04f7..a5024b8d93f 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -514,10 +514,11 @@ public function offsetGet($offset) public function offsetSet($offset, $value) { if ( ! isset($offset)) { - return $this->add($value); + $this->add($value); + return; } - return $this->set($offset, $value); + $this->set($offset, $value); } /** diff --git a/lib/Doctrine/ORM/Query/ResultSetMapping.php b/lib/Doctrine/ORM/Query/ResultSetMapping.php index 5c4550980e1..efffa674c2d 100644 --- a/lib/Doctrine/ORM/Query/ResultSetMapping.php +++ b/lib/Doctrine/ORM/Query/ResultSetMapping.php @@ -451,7 +451,7 @@ public function getDeclaringClass($columnName) /** * @param string $alias * - * @return AssociationMapping + * @return string */ public function getRelation($alias) { diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 00000000000..cc74bf06e5a --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,4 @@ +parameters: + ignoreErrors: + # Memcache does not exist on PHP 7 + - '#Instantiated class Memcache not found#' From 74c48c201dc5284688210872fdb546897de8eba9 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Thu, 29 Jun 2017 23:10:36 +0200 Subject: [PATCH 379/877] Push PHPStan to level 1 --- .travis.yml | 2 +- .../Entity/AbstractEntityPersister.php | 56 +++++++++---------- .../Collection/ManyToManyPersister.php | 1 + .../ORM/Tools/Export/Driver/PhpExporter.php | 3 + .../ORM/Tools/Export/Driver/XmlExporter.php | 1 + phpstan.neon | 3 + 6 files changed, 37 insertions(+), 29 deletions(-) diff --git a/.travis.yml b/.travis.yml index b6b914adf1f..d6d04f4d0df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,7 @@ before_script: - if [[ $DB == "mysql" || $DB == "mariadb" ]]; then mysql -e "CREATE SCHEMA doctrine_tests; GRANT ALL PRIVILEGES ON doctrine_tests.* to travis@'%'"; fi; script: - - if [[ $PHPSTAN = 1 ]]; then vendor/bin/phpstan analyse -l 0 -c phpstan.neon lib; fi + - if [[ $PHPSTAN = 1 ]]; then vendor/bin/phpstan analyse -l 1 -c phpstan.neon lib; fi - ENABLE_SECOND_LEVEL_CACHE=0 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml $PHPUNIT_FLAGS - ENABLE_SECOND_LEVEL_CACHE=1 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml --exclude-group performance,non-cacheable,locking_functional diff --git a/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php b/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php index 1e0f17972cc..53ea6a6fded 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php @@ -548,28 +548,28 @@ public function loadManyToManyCollection(array $assoc, $sourceEntity, Persistent $hasCache = ($persister instanceof CachedPersister); $key = null; - if ($hasCache) { - $ownerId = $this->uow->getEntityIdentifier($coll->getOwner()); - $key = $this->buildCollectionCacheKey($assoc, $ownerId); - $list = $persister->loadCollectionCache($coll, $key); + if ( ! $hasCache) { + return $this->persister->loadManyToManyCollection($assoc, $sourceEntity, $coll); + } - if ($list !== null) { - if ($this->cacheLogger) { - $this->cacheLogger->collectionCacheHit($persister->getCacheRegion()->getName(), $key); - } + $ownerId = $this->uow->getEntityIdentifier($coll->getOwner()); + $key = $this->buildCollectionCacheKey($assoc, $ownerId); + $list = $persister->loadCollectionCache($coll, $key); - return $list; + if ($list !== null) { + if ($this->cacheLogger) { + $this->cacheLogger->collectionCacheHit($persister->getCacheRegion()->getName(), $key); } + + return $list; } $list = $this->persister->loadManyToManyCollection($assoc, $sourceEntity, $coll); - if ($hasCache) { - $persister->storeCollectionCache($key, $list); + $persister->storeCollectionCache($key, $list); - if ($this->cacheLogger) { - $this->cacheLogger->collectionCacheMiss($persister->getCacheRegion()->getName(), $key); - } + if ($this->cacheLogger) { + $this->cacheLogger->collectionCacheMiss($persister->getCacheRegion()->getName(), $key); } return $list; @@ -583,28 +583,28 @@ public function loadOneToManyCollection(array $assoc, $sourceEntity, PersistentC $persister = $this->uow->getCollectionPersister($assoc); $hasCache = ($persister instanceof CachedPersister); - if ($hasCache) { - $ownerId = $this->uow->getEntityIdentifier($coll->getOwner()); - $key = $this->buildCollectionCacheKey($assoc, $ownerId); - $list = $persister->loadCollectionCache($coll, $key); + if ( ! $hasCache) { + return $this->persister->loadOneToManyCollection($assoc, $sourceEntity, $coll); + } - if ($list !== null) { - if ($this->cacheLogger) { - $this->cacheLogger->collectionCacheHit($persister->getCacheRegion()->getName(), $key); - } + $ownerId = $this->uow->getEntityIdentifier($coll->getOwner()); + $key = $this->buildCollectionCacheKey($assoc, $ownerId); + $list = $persister->loadCollectionCache($coll, $key); - return $list; + if ($list !== null) { + if ($this->cacheLogger) { + $this->cacheLogger->collectionCacheHit($persister->getCacheRegion()->getName(), $key); } + + return $list; } $list = $this->persister->loadOneToManyCollection($assoc, $sourceEntity, $coll); - if ($hasCache) { - $persister->storeCollectionCache($key, $list); + $persister->storeCollectionCache($key, $list); - if ($this->cacheLogger) { - $this->cacheLogger->collectionCacheMiss($persister->getCacheRegion()->getName(), $key); - } + if ($this->cacheLogger) { + $this->cacheLogger->collectionCacheMiss($persister->getCacheRegion()->getName(), $key); } return $list; diff --git a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php index ca8575d2a40..176ef37ee07 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php @@ -542,6 +542,7 @@ private function collectJoinTableColumnParameters(PersistentCollection $collecti $identifier1 = $this->uow->getEntityIdentifier($collection->getOwner()); $identifier2 = $this->uow->getEntityIdentifier($element); + $class1 = $class2 = null; if ($isComposite) { $class1 = $this->em->getClassMetadata(get_class($collection->getOwner())); $class2 = $collection->getTypeClass(); diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php index 00a4be59660..69db59f784a 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php @@ -102,6 +102,7 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) $cascade = ['all']; } + $method = null; $associationMappingArray = [ 'fieldName' => $associationMapping['fieldName'], 'targetEntity' => $associationMapping['targetEntity'], @@ -129,6 +130,7 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) 'orphanRemoval', 'orderBy', ]; + $oneToManyMappingArray = []; foreach ($potentialAssociationMappingIndexes as $index) { if (isset($associationMapping[$index])) { $oneToManyMappingArray[$index] = $associationMapping[$index]; @@ -142,6 +144,7 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) 'joinTable', 'orderBy', ]; + $manyToManyMappingArray = []; foreach ($potentialAssociationMappingIndexes as $index) { if (isset($associationMapping[$index])) { $manyToManyMappingArray[$index] = $associationMapping[$index]; diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php index fbcbf42d1c0..c4eb8f63792 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php @@ -240,6 +240,7 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) }); foreach ($metadata->associationMappings as $associationMapping) { + $associationMappingXml = null; if ($associationMapping['type'] == ClassMetadataInfo::ONE_TO_ONE) { $associationMappingXml = $root->addChild('one-to-one'); } elseif ($associationMapping['type'] == ClassMetadataInfo::MANY_TO_ONE) { diff --git a/phpstan.neon b/phpstan.neon index cc74bf06e5a..794fad8d8ad 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,4 +1,7 @@ parameters: + earlyTerminatingMethodCalls: + Doctrine\ORM\Query\Parser: + - syntaxError ignoreErrors: # Memcache does not exist on PHP 7 - '#Instantiated class Memcache not found#' From c678577f8f427f30f830a45202492036c9c587ed Mon Sep 17 00:00:00 2001 From: Lander Vanderstraeten Date: Tue, 11 Jul 2017 13:18:52 +0200 Subject: [PATCH 380/877] Fix newline --- docs/en/reference/basic-mapping.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/en/reference/basic-mapping.rst b/docs/en/reference/basic-mapping.rst index d33313d8942..d9a2769c005 100644 --- a/docs/en/reference/basic-mapping.rst +++ b/docs/en/reference/basic-mapping.rst @@ -295,7 +295,8 @@ annotation. class Message { /** - * @Id @Column(type="integer") + * @Id + * @Column(type="integer") * @GeneratedValue */ private $id; From 260cc6e3e0972b55a1419dfcfb55c4dcc26cbb9e Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 13 Jul 2017 08:16:00 +0200 Subject: [PATCH 381/877] Fix return of removeElement on collections Fixes #5745 --- lib/Doctrine/ORM/PersistentCollection.php | 6 +----- .../Tests/ORM/Functional/ExtraLazyCollectionTest.php | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index a5024b8d93f..2210c3c310c 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -373,11 +373,7 @@ public function removeElement($element) $persister = $this->em->getUnitOfWork()->getCollectionPersister($this->association); - if ($persister->removeElement($this, $element)) { - return $element; - } - - return null; + return $persister->removeElement($this, $element); } $removed = parent::removeElement($element); diff --git a/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php index dc090a05552..7f18aaca011 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php @@ -640,7 +640,7 @@ public function testRemoveElementManyToMany() $group = $this->_em->find(CmsGroup::class, $this->groupId); $queryCount = $this->getCurrentQueryCount(); - $user->groups->removeElement($group); + $this->assertTrue($user->groups->removeElement($group)); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Removing a persisted entity should cause one query to be executed."); $this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized."); From 45e1817f6f4a5a2decee630c099f02f25c00488a Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 13 Jul 2017 16:39:06 +0200 Subject: [PATCH 382/877] Add test for removing element not in collection --- tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php index 7f18aaca011..e7f4fd29803 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php @@ -645,6 +645,8 @@ public function testRemoveElementManyToMany() $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Removing a persisted entity should cause one query to be executed."); $this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized."); + $this->assertFalse($user->groups->removeElement($group), "Removing an already removed element returns false"); + // Test Many to Many removal with Entity state as new $group = new CmsGroup(); $group->name = "A New group!"; From 34c25a3ee3d74bce3be04659aa3983c182706365 Mon Sep 17 00:00:00 2001 From: Greg Bell Date: Wed, 19 Jul 2017 11:14:46 +1000 Subject: [PATCH 383/877] Make minor English fixes. - Remove the apparently dangling text at the bottom of reference/query-builder.rst --- .../reference/dql-doctrine-query-language.rst | 4 +- docs/en/reference/query-builder.rst | 39 +++++++++---------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/docs/en/reference/dql-doctrine-query-language.rst b/docs/en/reference/dql-doctrine-query-language.rst index 2c2e23f9eca..b0d19e8e089 100644 --- a/docs/en/reference/dql-doctrine-query-language.rst +++ b/docs/en/reference/dql-doctrine-query-language.rst @@ -34,9 +34,9 @@ object model. DQL SELECT statements are a very powerful way of retrieving parts of your domain model that are not accessible via associations. -Additionally they allow to retrieve entities and their associations +Additionally they allow you to retrieve entities and their associations in one single SQL select statement which can make a huge difference -in performance in contrast to using several queries. +in performance compared to using several queries. DQL UPDATE and DELETE statements offer a way to execute bulk changes on the entities of your domain model. This is often diff --git a/docs/en/reference/query-builder.rst b/docs/en/reference/query-builder.rst index f57b8ad2f86..1c65d8dc4a2 100644 --- a/docs/en/reference/query-builder.rst +++ b/docs/en/reference/query-builder.rst @@ -7,14 +7,14 @@ conditionally constructing a DQL query in several steps. It provides a set of classes and methods that is able to programmatically build queries, and also provides a fluent API. This means that you can change between one methodology to the other -as you want, and also pick one if you prefer. +as you want, or just pick a preferred one. Constructing a new QueryBuilder object ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The same way you build a normal Query, you build a ``QueryBuilder`` -object, just providing the correct method name. Here is an example -how to build a ``QueryBuilder`` object: +object. Here is an example of how to build a ``QueryBuilder`` +object: .. code-block:: php @@ -24,9 +24,9 @@ how to build a ``QueryBuilder`` object: // example1: creating a QueryBuilder instance $qb = $em->createQueryBuilder(); -Once you have created an instance of QueryBuilder, it provides a -set of useful informative functions that you can use. One good -example is to inspect what type of object the ``QueryBuilder`` is. +An instance of QueryBuilder has several informative methods. One +good example is to inspect what type of object the +``QueryBuilder`` is. .. code-block:: php @@ -80,11 +80,11 @@ Working with QueryBuilder High level API methods ^^^^^^^^^^^^^^^^^^^^^^ -To simplify even more the way you build a query in Doctrine, we can take -advantage of what we call Helper methods. For all base code, there -is a set of useful methods to simplify a programmer's life. To -illustrate how to work with them, here is the same example 6 -re-written using ``QueryBuilder`` helper methods: +To simplify even more the way you build a query in Doctrine, you can take +advantage of Helper methods. For all base code, there is a set of +useful methods to simplify a programmer's life. To illustrate how +to work with them, here is the same example 6 re-written using +``QueryBuilder`` helper methods: .. code-block:: php @@ -97,8 +97,8 @@ re-written using ``QueryBuilder`` helper methods: ->orderBy('u.name', 'ASC'); ``QueryBuilder`` helper methods are considered the standard way to -build DQL queries. Although it is supported, it should be avoided -to use string based queries and greatly encouraged to use +build DQL queries. Although it is supported, using string-based +queries should be avoided. You are greatly encouraged to use ``$qb->expr()->*`` methods. Here is a converted example 8 to suggested standard way to build queries: @@ -317,7 +317,7 @@ the Query object which can be retrieved from ``EntityManager#createQuery()``. Executing a Query ^^^^^^^^^^^^^^^^^ -The QueryBuilder is a builder object only, it has no means of actually +The QueryBuilder is a builder object only - it has no means of actually executing the Query. Additionally a set of parameters such as query hints cannot be set on the QueryBuilder itself. This is why you always have to convert a querybuilder instance into a Query object: @@ -521,10 +521,10 @@ using ``addCriteria``: Low Level API ^^^^^^^^^^^^^ -Now we have describe the low level (thought of as the -hardcore method) of creating queries. It may be useful to work at -this level for optimization purposes, but most of the time it is -preferred to work at a higher level of abstraction. +Now we will describe the low level method of creating queries. +It may be useful to work at this level for optimization purposes, +but most of the time it is preferred to work at a higher level of +abstraction. All helper methods in ``QueryBuilder`` actually rely on a single one: ``add()``. This method is responsible of building every piece @@ -577,6 +577,3 @@ same query of example 6 written using ->add('where', new Expr\Comparison('u.id', '=', '?1')) ->add('orderBy', new Expr\OrderBy('u.name', 'ASC')); -Of course this is the hardest way to build a DQL query in Doctrine. -To simplify some of these efforts, we introduce what we call as -``Expr`` helper class. From c47cf1de34736738040978c7fab38624d9894398 Mon Sep 17 00:00:00 2001 From: stoccc Date: Fri, 21 Jul 2017 10:33:28 +0200 Subject: [PATCH 384/877] Added a test case for postLoad on fetch-joined entities see https://github.com/doctrine/doctrine2/issues/6568 --- .../ORM/Functional/LifecycleCallbackTest.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php b/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php index ca7f8c7d718..83836c66240 100644 --- a/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php @@ -268,6 +268,47 @@ public function testCascadedEntitiesNotLoadedInPostLoadDuringIterationWithSimple break; } } + + /** + * https://github.com/doctrine/doctrine2/issues/6568 + */ + public function testPostLoadIsInvokedOnFetchJoinedEntities() + { + $entA = new LifecycleCallbackCascader(); + $this->_em->persist($entA); + + $entB_1 = new LifecycleCallbackTestEntity(); + $entB_2 = new LifecycleCallbackTestEntity(); + + $entA->entities[] = $entB_1; + $entA->entities[] = $entB_2; + $entB_1->cascader = $entA; + $entB_2->cascader = $entA; + + $this->_em->flush(); + $this->_em->clear(); + + $dql = <<<'DQL' +SELECT + entA, entB +FROM + Doctrine\Tests\ORM\Functional\LifecycleCallbackCascader AS entA +LEFT JOIN + entA.entities AS entB +WHERE + entA.id = %s +DQL; + + $fetchedA = $this + ->_em + ->createQuery(sprintf($dql, $entA->getId())) + ->getOneOrNullResult(); + + $this->assertTrue($fetchedA->postLoadCallbackInvoked); + foreach ($fetchedA->entities as $fetchJoinedEntB) { + $this->assertTrue($fetchJoinedEntB->postLoadCallbackInvoked); + } + } public function testLifecycleCallbacksGetInherited() { From 17892bb32782f8901da3b636ca92681ef37b71b6 Mon Sep 17 00:00:00 2001 From: stoccc Date: Fri, 21 Jul 2017 10:47:32 +0200 Subject: [PATCH 385/877] added named parameter and LifecycleCallbackCascader::getId() --- .../Tests/ORM/Functional/LifecycleCallbackTest.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php b/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php index 83836c66240..914acbecf86 100644 --- a/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php @@ -296,12 +296,12 @@ public function testPostLoadIsInvokedOnFetchJoinedEntities() LEFT JOIN entA.entities AS entB WHERE - entA.id = %s + entA.id = :entA_id DQL; $fetchedA = $this ->_em - ->createQuery(sprintf($dql, $entA->getId())) + ->createQuery($dql)->setParameter('entA_id', $entA->getId()) ->getOneOrNullResult(); $this->assertTrue($fetchedA->postLoadCallbackInvoked); @@ -496,6 +496,10 @@ public function doStuffOnPostLoad() { $this->postLoadCallbackInvoked = true; $this->postLoadEntitiesCount = count($this->entities); } + + public function getId() { + return $this->id; + } } /** @MappedSuperclass @HasLifecycleCallbacks */ From 247fb6ef0dfd16828ff8302dda3a2b7e781c8248 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Fri, 21 Jul 2017 11:03:05 +0200 Subject: [PATCH 386/877] Prevent Travis-CI failure if xdebug is not available --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d6d04f4d0df..e8805355949 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ env: before_script: - if [[ $TRAVIS_PHP_VERSION = '7.1' && $DB = 'sqlite' && "$DEPENDENCIES" != "low" ]]; then PHPUNIT_FLAGS="--coverage-clover ./build/logs/clover.xml"; else PHPUNIT_FLAGS=""; fi - - if [[ "$PHPUNIT_FLAGS" == "" ]]; then phpenv config-rm xdebug.ini; fi + - if [[ "$PHPUNIT_FLAGS" == "" ]]; then phpenv config-rm xdebug.ini || echo "xdebug not available"; fi - if [[ $PHPSTAN = 1 ]]; then echo "extension=redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi - composer self-update - composer install --prefer-source From 80573038ed44da6eeb13e85d4f380d8b08b97292 Mon Sep 17 00:00:00 2001 From: Greg Bell Date: Sat, 22 Jul 2017 17:28:48 +1000 Subject: [PATCH 387/877] Add additional detail and clarifications on SELECT - Also the effect of WHERE on result array. --- .../reference/dql-doctrine-query-language.rst | 59 +++++++++++++++---- 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/docs/en/reference/dql-doctrine-query-language.rst b/docs/en/reference/dql-doctrine-query-language.rst index b0d19e8e089..44ef29483bf 100644 --- a/docs/en/reference/dql-doctrine-query-language.rst +++ b/docs/en/reference/dql-doctrine-query-language.rst @@ -49,9 +49,12 @@ SELECT queries DQL SELECT clause ~~~~~~~~~~~~~~~~~ -The select clause of a DQL query specifies what appears in the -query result. The composition of all the expressions in the select -clause also influences the nature of the query result. +The SELECT clause of a DQL query specifies what gets hydrated in +the query result. You are always returned usable objects, but any +associated objects not included in the SELECT clause will be +proxies (ie. unhydrated). They get hydrated by Doctrine when +they're read by your code, but that means at least one additional +database access. Here is an example that selects all users with an age > 20: @@ -83,14 +86,48 @@ Lets examine the query: The result of this query would be a list of User objects where all users are older than 20. -The SELECT clause allows to specify both class identification -variables that signal the hydration of a complete entity class or -just fields of the entity using the syntax ``u.name``. Combinations -of both are also allowed and it is possible to wrap both fields and -identification values into aggregation and DQL functions. Numerical -fields can be part of computations using mathematical operations. -See the sub-section on `Functions, Operators, Aggregates`_ for -more information. +The composition of the expressions in the SELECT clause also +influences the nature of the query result. There are three +cases: + +- All objects. For example: + ``SELECT u, p, n FROM Users u...`` + In this case, the result array will be made up of objects of + the type in the FROM clause. In the example above, the query + will return an array of User objects, with associated classes + identify else where in the query as 'p' and 'n' hydrated. + +- All scalars. For example: + ``SELECT u.name, u.address FROM Users u...`` + In this case, the result will be an array of arrays. In the + example above, each element of the result array would be an + array of the scalar name and address values. + + You can select scalars from any entity in the query. + +- Mixed. For example: + ``SELECT u, p.quantity FROM Users u...`` + Here, the result will again be an array of arrays, with each + element being an array made up of a User object and the scalar + value p.quantity. + +Multiple FROM clauses are allowed, which would cause the result +array elements to cycle through the classes included in the +multiple FROM clauses. + +.. note:: + + You cannot select other entities unless you also select the + root of the selection (the first entity in FROM). + + Doctrine tells you you have violated this constraint with the + exception "Cannot select entity through identification + variables without choosing at least one root entity alias." + +It is possible to wrap both fields and identification values into +aggregation and DQL functions. Numerical fields can be part of +computations using mathematical operations. See the sub-section +on `Functions, Operators, Aggregates`_ for more information. Joins ~~~~~ From 624af3df220a409731b31495a9e2c6bdd7cf3ca3 Mon Sep 17 00:00:00 2001 From: Greg Bell Date: Sat, 22 Jul 2017 17:40:56 +1000 Subject: [PATCH 388/877] Add note clarifying WHERE, WITH and HAVING - A per Ocramius' explanation in #6563 --- docs/en/reference/dql-doctrine-query-language.rst | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/en/reference/dql-doctrine-query-language.rst b/docs/en/reference/dql-doctrine-query-language.rst index 44ef29483bf..035ef611cf2 100644 --- a/docs/en/reference/dql-doctrine-query-language.rst +++ b/docs/en/reference/dql-doctrine-query-language.rst @@ -356,7 +356,8 @@ article-ids: $query = $em->createQuery('SELECT u.id, a.id as article_id FROM CmsUser u LEFT JOIN u.articles a'); $results = $query->getResult(); // array of user ids and every article_id for each user -Restricting a JOIN clause by additional conditions: +Restricting a JOIN clause by additional conditions specified by +WITH: .. code-block:: php @@ -489,6 +490,17 @@ Joins between entities without associations were not possible until version createQuery('SELECT u FROM User u JOIN Blacklist b WITH u.email = b.email'); +.. note:: + The differences between WHERE, WITH and HAVING clauses may be + confusing. + + - WHERE is applied to the results of an entire query + - WITH is applied to a join as an additional condition. For + arbitrary joins (SELECT f, b FROM Foo f, Bar b WITH f.id = b.id) + the WITH is required, even if it is 1 = 1 + - HAVING is applied to the results of a query after + aggregation (GROUP BY) + Partial Object Syntax ^^^^^^^^^^^^^^^^^^^^^ From 854ff17ab90ce42d6851866fc23c752d8defaa5b Mon Sep 17 00:00:00 2001 From: Martin Kirilov Date: Fri, 12 Aug 2016 17:24:00 +0300 Subject: [PATCH 389/877] Should fix MySQL 5.7 issues caused by ONLY_FULL_GROUP_BY Should fix MySQL 5.7 issues caused by ONLY_FULL_GROUP_BY --- .../Pagination/LimitSubqueryOutputWalker.php | 41 +++++++++++++++---- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php index 5d59722ed53..93618e7709a 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php @@ -354,33 +354,56 @@ private function addMissingItemsFromOrderByToSelect(SelectStatement $AST) /** * Generates new SQL for statements with an order by clause * - * @param array $sqlIdentifier - * @param string $innerSql - * @param string $sql - * @param OrderByClause $orderByClause + * @param array $sqlIdentifier + * @param string $innerSql + * @param string $sql + * @param OrderByClause $orderByClause * * @return string */ - private function preserveSqlOrdering(array $sqlIdentifier, $innerSql, $sql, $orderByClause) - { + private function preserveSqlOrdering(array $sqlIdentifier, $innerSql, $sql, $orderByClause) { // If the sql statement has an order by clause, we need to wrap it in a new select distinct // statement - if (! $orderByClause instanceof OrderByClause) { + if (!$orderByClause instanceof OrderByClause) { return $sql; } // Rebuild the order by clause to work in the scope of the new select statement /* @var array $orderBy an array of rebuilt order by items */ $orderBy = $this->rebuildOrderByClauseForOuterScope($orderByClause); + $orderByFields = str_replace([' DESC', ' ASC'], ['', ''], $orderBy); + + $innerSqlIdentifier = []; + + foreach ($orderByFields as $k => $v) { + // remove fields that are selected by identifiers, + // if those are ordered by in the query + if (in_array($v, $sqlIdentifier)) { + unset($orderByFields[$k]); + } + } + + foreach ($sqlIdentifier as $k => $v) { + $innerSqlIdentifier[$k] = 'dctrn_result_inner.' . $v; + $sqlIdentifier[$k] = 'dctrn_result.' . $v; + } + + // add the + foreach ($orderByFields as $k => $v) { + $innerSqlIdentifier[$k] = 'dctrn_result_inner.' . $v; + } // Build the select distinct statement $sql = sprintf( - 'SELECT DISTINCT %s FROM (%s) dctrn_result ORDER BY %s', - implode(', ', $sqlIdentifier), + 'SELECT DISTINCT %s FROM (%s) dctrn_result_inner ORDER BY %s', + implode(', ', $innerSqlIdentifier), $innerSql, implode(', ', $orderBy) ); + // now only select distinct identifier + $sql = sprintf('SELECT DISTINCT %s FROM (%s) dctrn_result', implode(', ', $sqlIdentifier), $sql); + return $sql; } From 60601a932301672141fc1a21cf032a5bf5d4f3d6 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Tue, 22 Nov 2016 17:01:27 +0900 Subject: [PATCH 390/877] fix query and tests --- .../Pagination/LimitSubqueryOutputWalker.php | 39 ++++++++----------- .../LimitSubqueryOutputWalkerTest.php | 20 +++++----- 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php index 93618e7709a..2b984b8462c 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php @@ -354,46 +354,39 @@ private function addMissingItemsFromOrderByToSelect(SelectStatement $AST) /** * Generates new SQL for statements with an order by clause * - * @param array $sqlIdentifier - * @param string $innerSql - * @param string $sql - * @param OrderByClause $orderByClause + * @param array $sqlIdentifier + * @param string $innerSql + * @param string $sql + * @param OrderByClause $orderByClause * * @return string */ - private function preserveSqlOrdering(array $sqlIdentifier, $innerSql, $sql, $orderByClause) { + private function preserveSqlOrdering(array $sqlIdentifier, $innerSql, $sql, $orderByClause) + { // If the sql statement has an order by clause, we need to wrap it in a new select distinct // statement - if (!$orderByClause instanceof OrderByClause) { + if (! $orderByClause instanceof OrderByClause) { return $sql; } // Rebuild the order by clause to work in the scope of the new select statement /* @var array $orderBy an array of rebuilt order by items */ $orderBy = $this->rebuildOrderByClauseForOuterScope($orderByClause); - $orderByFields = str_replace([' DESC', ' ASC'], ['', ''], $orderBy); - $innerSqlIdentifier = []; + $innerSqlIdentifier = $sqlIdentifier; - foreach ($orderByFields as $k => $v) { - // remove fields that are selected by identifiers, + foreach ($orderBy as $field) { + $field = preg_replace('/((\S+)\s+(ASC|DESC)\s*,?)*/', '${2}', $field); + + // skip fields that are selected by identifiers, // if those are ordered by in the query - if (in_array($v, $sqlIdentifier)) { - unset($orderByFields[$k]); + if (in_array($field, $sqlIdentifier, true)) { + continue; } + $innerSqlIdentifier[] = $field; } - foreach ($sqlIdentifier as $k => $v) { - $innerSqlIdentifier[$k] = 'dctrn_result_inner.' . $v; - $sqlIdentifier[$k] = 'dctrn_result.' . $v; - } - - // add the - foreach ($orderByFields as $k => $v) { - $innerSqlIdentifier[$k] = 'dctrn_result_inner.' . $v; - } - - // Build the select distinct statement + // Build the innner select statement $sql = sprintf( 'SELECT DISTINCT %s FROM (%s) dctrn_result_inner ORDER BY %s', implode(', ', $innerSqlIdentifier), diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php index 7e65ab7bc91..463c413d2e1 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php @@ -208,7 +208,7 @@ public function testCountQueryWithArithmeticOrderByCondition() $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertSame( - 'SELECT DISTINCT id_0 FROM (SELECT a0_.id AS id_0, a0_.name AS name_1 FROM Author a0_) dctrn_result ORDER BY (1 - 1000) * 1 DESC', + 'SELECT DISTINCT id_0 FROM (SELECT DISTINCT id_0, (1 - 1000) * 1 FROM (SELECT a0_.id AS id_0, a0_.name AS name_1 FROM Author a0_) dctrn_result_inner ORDER BY (1 - 1000) * 1 DESC) dctrn_result', $query->getSQL() ); } @@ -223,7 +223,7 @@ public function testCountQueryWithComplexScalarOrderByItem() $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertSame( - 'SELECT DISTINCT id_0 FROM (SELECT a0_.id AS id_0, a0_.image AS image_1, a0_.image_height AS image_height_2, a0_.image_width AS image_width_3, a0_.image_alt_desc AS image_alt_desc_4, a0_.user_id AS user_id_5 FROM Avatar a0_) dctrn_result ORDER BY image_height_2 * image_width_3 DESC', + 'SELECT DISTINCT id_0 FROM (SELECT DISTINCT id_0, image_height_2 * image_width_3 FROM (SELECT a0_.id AS id_0, a0_.image AS image_1, a0_.image_height AS image_height_2, a0_.image_width AS image_width_3, a0_.image_alt_desc AS image_alt_desc_4, a0_.user_id AS user_id_5 FROM Avatar a0_) dctrn_result_inner ORDER BY image_height_2 * image_width_3 DESC) dctrn_result', $query->getSQL() ); } @@ -238,7 +238,7 @@ public function testCountQueryWithComplexScalarOrderByItemJoined() $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertSame( - 'SELECT DISTINCT id_0 FROM (SELECT u0_.id AS id_0, a1_.image_height AS image_height_1, a1_.image_width AS image_width_2, a1_.user_id AS user_id_3 FROM User u0_ INNER JOIN Avatar a1_ ON u0_.id = a1_.user_id) dctrn_result ORDER BY image_height_1 * image_width_2 DESC', + 'SELECT DISTINCT id_0 FROM (SELECT DISTINCT id_0, image_height_1 * image_width_2 FROM (SELECT u0_.id AS id_0, a1_.image_height AS image_height_1, a1_.image_width AS image_width_2, a1_.user_id AS user_id_3 FROM User u0_ INNER JOIN Avatar a1_ ON u0_.id = a1_.user_id) dctrn_result_inner ORDER BY image_height_1 * image_width_2 DESC) dctrn_result', $query->getSQL() ); } @@ -253,7 +253,7 @@ public function testCountQueryWithComplexScalarOrderByItemJoinedWithPartial() $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertSame( - 'SELECT DISTINCT id_0 FROM (SELECT u0_.id AS id_0, a1_.id AS id_1, a1_.image_alt_desc AS image_alt_desc_2, a1_.image_height AS image_height_3, a1_.image_width AS image_width_4, a1_.user_id AS user_id_5 FROM User u0_ INNER JOIN Avatar a1_ ON u0_.id = a1_.user_id) dctrn_result ORDER BY image_height_3 * image_width_4 DESC', + 'SELECT DISTINCT id_0 FROM (SELECT DISTINCT id_0, image_height_3 * image_width_4 FROM (SELECT u0_.id AS id_0, a1_.id AS id_1, a1_.image_alt_desc AS image_alt_desc_2, a1_.image_height AS image_height_3, a1_.image_width AS image_width_4, a1_.user_id AS user_id_5 FROM User u0_ INNER JOIN Avatar a1_ ON u0_.id = a1_.user_id) dctrn_result_inner ORDER BY image_height_3 * image_width_4 DESC) dctrn_result', $query->getSQL() ); } @@ -285,7 +285,7 @@ public function testLimitSubqueryWithHiddenSelectionInOrderBy() $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( - 'SELECT DISTINCT id_0 FROM (SELECT a0_.id AS id_0, a0_.name AS name_1, a0_.name AS name_2 FROM Author a0_) dctrn_result ORDER BY name_2 DESC', + 'SELECT DISTINCT id_0 FROM (SELECT DISTINCT id_0, name_2 FROM (SELECT a0_.id AS id_0, a0_.name AS name_1, a0_.name AS name_2 FROM Author a0_) dctrn_result_inner ORDER BY name_2 DESC) dctrn_result', $query->getSQL() ); } @@ -300,7 +300,7 @@ public function testLimitSubqueryWithColumnWithSortDirectionInName() $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertSame( - 'SELECT DISTINCT id_0 FROM (SELECT a0_.id AS id_0, a0_.image AS image_1, a0_.image_height AS image_height_2, a0_.image_width AS image_width_3, a0_.image_alt_desc AS image_alt_desc_4, a0_.user_id AS user_id_5 FROM Avatar a0_) dctrn_result ORDER BY image_alt_desc_4 DESC', + 'SELECT DISTINCT id_0 FROM (SELECT DISTINCT id_0, image_alt_desc_4 FROM (SELECT a0_.id AS id_0, a0_.image AS image_1, a0_.image_height AS image_height_2, a0_.image_width AS image_width_3, a0_.image_alt_desc AS image_alt_desc_4, a0_.user_id AS user_id_5 FROM Avatar a0_) dctrn_result_inner ORDER BY image_alt_desc_4 DESC) dctrn_result', $query->getSQL() ); } @@ -314,7 +314,7 @@ public function testLimitSubqueryWithOrderByInnerJoined() $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( - 'SELECT DISTINCT id_0 FROM (SELECT b0_.id AS id_0, a1_.name AS name_1, b0_.author_id AS author_id_2, b0_.category_id AS category_id_3 FROM BlogPost b0_ INNER JOIN Author a1_ ON b0_.author_id = a1_.id) dctrn_result ORDER BY name_1 ASC', + 'SELECT DISTINCT id_0 FROM (SELECT DISTINCT id_0, name_1 FROM (SELECT b0_.id AS id_0, a1_.name AS name_1, b0_.author_id AS author_id_2, b0_.category_id AS category_id_3 FROM BlogPost b0_ INNER JOIN Author a1_ ON b0_.author_id = a1_.id) dctrn_result_inner ORDER BY name_1 ASC) dctrn_result', $query->getSQL() ); } @@ -330,7 +330,7 @@ public function testLimitSubqueryWithOrderByAndSubSelectInWhereClauseMySql() $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( - 'SELECT DISTINCT id_0 FROM (SELECT b0_.id AS id_0, b0_.author_id AS author_id_1, b0_.category_id AS category_id_2 FROM BlogPost b0_ WHERE ((SELECT COUNT(b1_.id) AS sclr_3 FROM BlogPost b1_) = 1)) dctrn_result ORDER BY id_0 DESC', + 'SELECT DISTINCT id_0 FROM (SELECT DISTINCT id_0 FROM (SELECT b0_.id AS id_0, b0_.author_id AS author_id_1, b0_.category_id AS category_id_2 FROM BlogPost b0_ WHERE ((SELECT COUNT(b1_.id) AS sclr_3 FROM BlogPost b1_) = 1)) dctrn_result_inner ORDER BY id_0 DESC) dctrn_result', $query->getSQL() ); } @@ -365,7 +365,7 @@ public function testLimitSubqueryOrderByFieldFromMappedSuperclass() $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( - 'SELECT DISTINCT id_0 FROM (SELECT b0_.id AS id_0, b0_.name AS name_1 FROM Banner b0_) dctrn_result ORDER BY id_0 DESC', + 'SELECT DISTINCT id_0 FROM (SELECT DISTINCT id_0 FROM (SELECT b0_.id AS id_0, b0_.name AS name_1 FROM Banner b0_) dctrn_result_inner ORDER BY id_0 DESC) dctrn_result', $query->getSQL() ); } @@ -390,7 +390,7 @@ public function testLimitSubqueryOrderBySubSelectOrderByExpression() $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); $this->assertEquals( - 'SELECT DISTINCT id_0 FROM (SELECT a0_.id AS id_0, a0_.name AS name_1, (SELECT MIN(m1_.title) AS sclr_3 FROM MyBlogPost m1_ WHERE m1_.author_id = a0_.id) AS sclr_2 FROM Author a0_) dctrn_result ORDER BY sclr_2 DESC', + 'SELECT DISTINCT id_0 FROM (SELECT DISTINCT id_0, sclr_2 FROM (SELECT a0_.id AS id_0, a0_.name AS name_1, (SELECT MIN(m1_.title) AS sclr_3 FROM MyBlogPost m1_ WHERE m1_.author_id = a0_.id) AS sclr_2 FROM Author a0_) dctrn_result_inner ORDER BY sclr_2 DESC) dctrn_result', $query->getSQL() ); } From 4a736f48f82c1e555bbe0e477fcacf80fcd0444f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sat, 1 Jul 2017 14:22:40 +0200 Subject: [PATCH 391/877] Add MySQL 5.7 to Travis configuration Following the same setup of doctrine/dbal#2764. --- .travis.yml | 8 ++++++++ tests/travis/install-mysql-5.7.sh | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/travis/install-mysql-5.7.sh diff --git a/.travis.yml b/.travis.yml index e8805355949..57b2cb1f680 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,7 @@ before_script: - if [ "$DEPENDENCIES" != "low" ]; then composer update; fi; - if [ "$DEPENDENCIES" == "low" ]; then composer update --prefer-lowest; fi; - if [[ $PHPSTAN = 1 ]]; then composer require --dev --prefer-stable phpstan/phpstan:^0.7 symfony/console:^3.0; fi + - if [ "$MYSQL_VERSION" == "5.7" ]; then bash ./tests/travis/install-mysql-5.7.sh; fi; - if [[ $DB == "mysql" || $DB == "mariadb" ]]; then mysql -e "CREATE SCHEMA doctrine_tests; GRANT ALL PRIVILEGES ON doctrine_tests.* to travis@'%'"; fi; script: @@ -47,6 +48,13 @@ matrix: - DB=pgsql - PHPSTAN=1 + - php: 7.1 + env: DB=mysql MYSQL_VERSION=5.7 + sudo: required + - php: nightly + env: DB=mysql MYSQL_VERSION=5.7 + sudo: required + allow_failures: - php: nightly diff --git a/tests/travis/install-mysql-5.7.sh b/tests/travis/install-mysql-5.7.sh new file mode 100644 index 00000000000..66b0d1ecf1f --- /dev/null +++ b/tests/travis/install-mysql-5.7.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +set -ex + +echo "Installing MySQL 5.7..." + +sudo service mysql stop +sudo apt-get remove "^mysql.*" +sudo apt-get autoremove +sudo apt-get autoclean +echo mysql-apt-config mysql-apt-config/select-server select mysql-5.7 | sudo debconf-set-selections +wget http://dev.mysql.com/get/mysql-apt-config_0.8.6-1_all.deb +sudo DEBIAN_FRONTEND=noninteractive dpkg -i mysql-apt-config_0.8.6-1_all.deb +sudo rm -rf /var/lib/apt/lists/* +sudo apt-get clean +sudo apt-get update -q +sudo apt-get install -q -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" mysql-server libmysqlclient-dev +sudo mysql_upgrade + +echo "Restart mysql..." +sudo mysql -e "use mysql; update user set authentication_string=PASSWORD('') where User='root'; update user set plugin='mysql_native_password';FLUSH PRIVILEGES;" + From 3d5acd607ba51fec5a1f79208b1fe507cc6be0cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sat, 22 Jul 2017 19:30:47 +0200 Subject: [PATCH 392/877] Bump up doctrine/instantiator version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a4b43de3b73..d320b0b4dd5 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "ext-pdo": "*", "doctrine/collections": "^1.4", "doctrine/dbal": ">=2.5-dev,<2.7-dev", - "doctrine/instantiator": "~1.0.1", + "doctrine/instantiator": "~1.1", "doctrine/common": "^2.7.1", "doctrine/cache": "~1.6", "doctrine/annotations": "~1.4", From 5389ad72615a613dc01ce65b257147d5b698fd41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sat, 22 Jul 2017 20:34:18 +0200 Subject: [PATCH 393/877] Make LimitSubqueryOutputWalker a bit more readable Also simplifying the REGEX to remove the ORDER BY type (ASC/DESC) with a substr() since OrderByItem#type is always defined. --- .../Pagination/LimitSubqueryOutputWalker.php | 142 +++++++++--------- .../LimitSubqueryOutputWalkerTest.php | 88 +++++------ 2 files changed, 117 insertions(+), 113 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php index 2b984b8462c..034b33b2c16 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php @@ -43,6 +43,8 @@ */ class LimitSubqueryOutputWalker extends SqlWalker { + private const ORDER_BY_PATH_EXPRESSION = '/(?rebuildOrderByClauseForOuterScope($orderByClause); + // now only select distinct identifier + return \sprintf( + 'SELECT DISTINCT %s FROM (%s) dctrn_result', + \implode(', ', $sqlIdentifier), + $this->recreateInnerSql($orderByClause, $sqlIdentifier, $innerSql) + ); + } - $innerSqlIdentifier = $sqlIdentifier; + /** + * Generates a new SQL statement for the inner query to keep the correct sorting + * + * @param OrderByClause $orderByClause + * @param array $identifiers + * @param string $innerSql + * + * @return string + */ + private function recreateInnerSql( + OrderByClause $orderByClause, + array $identifiers, + string $innerSql + ) : string { + [$searchPatterns, $replacements] = $this->generateSqlAliasReplacements(); - foreach ($orderBy as $field) { - $field = preg_replace('/((\S+)\s+(ASC|DESC)\s*,?)*/', '${2}', $field); + $orderByItems = []; - // skip fields that are selected by identifiers, - // if those are ordered by in the query - if (in_array($field, $sqlIdentifier, true)) { - continue; + foreach ($orderByClause->orderByItems as $orderByItem) { + // Walk order by item to get string representation of it and + // replace path expressions in the order by clause with their column alias + $orderByItemString = \preg_replace( + $searchPatterns, + $replacements, + $this->walkOrderByItem($orderByItem) + ); + + $orderByItems[] = $orderByItemString; + $identifier = \substr($orderByItemString, 0, \strrpos($orderByItemString, ' ')); + + if (! \in_array($identifier, $identifiers, true)) { + $identifiers[] = $identifier; } - $innerSqlIdentifier[] = $field; } - // Build the innner select statement - $sql = sprintf( + return $sql = \sprintf( 'SELECT DISTINCT %s FROM (%s) dctrn_result_inner ORDER BY %s', - implode(', ', $innerSqlIdentifier), + \implode(', ', $identifiers), $innerSql, - implode(', ', $orderBy) + \implode(', ', $orderByItems) ); - - // now only select distinct identifier - $sql = sprintf('SELECT DISTINCT %s FROM (%s) dctrn_result', implode(', ', $sqlIdentifier), $sql); - - return $sql; } /** - * Generates a new order by clause that works in the scope of a select query wrapping the original - * - * @param OrderByClause $orderByClause - * @return array + * @return string[][] */ - private function rebuildOrderByClauseForOuterScope(OrderByClause $orderByClause) + private function generateSqlAliasReplacements() : array { - $dqlAliasToSqlTableAliasMap - = $searchPatterns - = $replacements - = $dqlAliasToClassMap - = $selectListAdditions - = $orderByItems - = []; + $aliasMap = $searchPatterns = $replacements = $metadataList = []; // Generate DQL alias -> SQL table alias mapping - foreach(array_keys($this->rsm->aliasMap) as $dqlAlias) { - $dqlAliasToClassMap[$dqlAlias] = $class = $this->queryComponents[$dqlAlias]['metadata']; - $dqlAliasToSqlTableAliasMap[$dqlAlias] = $this->getSQLTableAlias($class->getTableName(), $dqlAlias); + foreach (\array_keys($this->rsm->aliasMap) as $dqlAlias) { + $metadataList[$dqlAlias] = $class = $this->queryComponents[$dqlAlias]['metadata']; + $aliasMap[$dqlAlias] = $this->getSQLTableAlias($class->getTableName(), $dqlAlias); } - // Pattern to find table path expressions in the order by clause - $fieldSearchPattern = '/(?rsm->fieldMappings as $fieldAlias => $fieldName) { + foreach ($this->rsm->fieldMappings as $fieldAlias => $fieldName) { $dqlAliasForFieldAlias = $this->rsm->columnOwnerMap[$fieldAlias]; - $class = $dqlAliasToClassMap[$dqlAliasForFieldAlias]; + $class = $metadataList[$dqlAliasForFieldAlias]; - // If the field is from a joined child table, we won't be ordering - // on it. - if (!isset($class->fieldMappings[$fieldName])) { + // If the field is from a joined child table, we won't be ordering on it. + if (! isset($class->fieldMappings[$fieldName])) { continue; } @@ -441,37 +453,29 @@ private function rebuildOrderByClauseForOuterScope(OrderByClause $orderByClause) // Get the proper column name as will appear in the select list $columnName = $this->quoteStrategy->getColumnName( $fieldName, - $dqlAliasToClassMap[$dqlAliasForFieldAlias], + $metadataList[$dqlAliasForFieldAlias], $this->em->getConnection()->getDatabasePlatform() ); // Get the SQL table alias for the entity and field - $sqlTableAliasForFieldAlias = $dqlAliasToSqlTableAliasMap[$dqlAliasForFieldAlias]; + $sqlTableAliasForFieldAlias = $aliasMap[$dqlAliasForFieldAlias]; + if (isset($fieldMapping['declared']) && $fieldMapping['declared'] !== $class->name) { // Field was declared in a parent class, so we need to get the proper SQL table alias // for the joined parent table. $otherClassMetadata = $this->em->getClassMetadata($fieldMapping['declared']); - if (!$otherClassMetadata->isMappedSuperclass) { + + if (! $otherClassMetadata->isMappedSuperclass) { $sqlTableAliasForFieldAlias = $this->getSQLTableAlias($otherClassMetadata->getTableName(), $dqlAliasForFieldAlias); } } - // Compose search/replace patterns - $searchPatterns[] = sprintf($fieldSearchPattern, $sqlTableAliasForFieldAlias, $columnName); - $replacements[] = $fieldAlias; - } - - foreach($orderByClause->orderByItems as $orderByItem) { - // Walk order by item to get string representation of it - $orderByItemString = $this->walkOrderByItem($orderByItem); - - // Replace path expressions in the order by clause with their column alias - $orderByItemString = preg_replace($searchPatterns, $replacements, $orderByItemString); - - $orderByItems[] = $orderByItemString; + // Compose search and replace patterns + $searchPatterns[] = \sprintf(self::ORDER_BY_PATH_EXPRESSION, $sqlTableAliasForFieldAlias, $columnName); + $replacements[] = $fieldAlias; } - return $orderByItems; + return [$searchPatterns, $replacements]; } /** diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php index 463c413d2e1..39ee1360dc9 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php @@ -8,9 +8,9 @@ use Doctrine\ORM\Query; use Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker; -class LimitSubqueryOutputWalkerTest extends PaginationTestCase +final class LimitSubqueryOutputWalkerTest extends PaginationTestCase { - public function testLimitSubquery() + public function testLimitSubquery() : void { $query = $this->entityManager->createQuery( 'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category c JOIN p.author a'); @@ -18,12 +18,12 @@ public function testLimitSubquery() $limitQuery = clone $query; $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); - $this->assertEquals( + self::assertSame( "SELECT DISTINCT id_0 FROM (SELECT m0_.id AS id_0, m0_.title AS title_1, c1_.id AS id_2, a2_.id AS id_3, a2_.name AS name_4, m0_.author_id AS author_id_5, m0_.category_id AS category_id_6 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON m0_.category_id = c1_.id INNER JOIN Author a2_ ON m0_.author_id = a2_.id) dctrn_result", $limitQuery->getSQL() ); } - public function testLimitSubqueryWithSortPg() + public function testLimitSubqueryWithSortPg() : void { $odp = $this->entityManager->getConnection()->getDatabasePlatform(); $this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform); @@ -33,14 +33,14 @@ public function testLimitSubqueryWithSortPg() $limitQuery = clone $query; $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); - $this->assertEquals( + self::assertSame( "SELECT DISTINCT id_0, MIN(sclr_5) AS dctrn_minrownum FROM (SELECT m0_.id AS id_0, m0_.title AS title_1, c1_.id AS id_2, a2_.id AS id_3, a2_.name AS name_4, ROW_NUMBER() OVER(ORDER BY m0_.title ASC) AS sclr_5, m0_.author_id AS author_id_6, m0_.category_id AS category_id_7 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON m0_.category_id = c1_.id INNER JOIN Author a2_ ON m0_.author_id = a2_.id) dctrn_result GROUP BY id_0 ORDER BY dctrn_minrownum ASC", $limitQuery->getSQL() ); $this->entityManager->getConnection()->setDatabasePlatform($odp); } - public function testLimitSubqueryWithScalarSortPg() + public function testLimitSubqueryWithScalarSortPg() : void { $odp = $this->entityManager->getConnection()->getDatabasePlatform(); $this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform); @@ -51,7 +51,7 @@ public function testLimitSubqueryWithScalarSortPg() $limitQuery = clone $query; $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); - $this->assertEquals( + self::assertSame( "SELECT DISTINCT id_1, MIN(sclr_3) AS dctrn_minrownum FROM (SELECT COUNT(g0_.id) AS sclr_0, u1_.id AS id_1, g0_.id AS id_2, ROW_NUMBER() OVER(ORDER BY COUNT(g0_.id) ASC) AS sclr_3 FROM User u1_ INNER JOIN user_group u2_ ON u1_.id = u2_.user_id INNER JOIN groups g0_ ON g0_.id = u2_.group_id) dctrn_result GROUP BY id_1 ORDER BY dctrn_minrownum ASC", $limitQuery->getSQL() ); @@ -59,7 +59,7 @@ public function testLimitSubqueryWithScalarSortPg() $this->entityManager->getConnection()->setDatabasePlatform($odp); } - public function testLimitSubqueryWithMixedSortPg() + public function testLimitSubqueryWithMixedSortPg() : void { $odp = $this->entityManager->getConnection()->getDatabasePlatform(); $this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform); @@ -70,7 +70,7 @@ public function testLimitSubqueryWithMixedSortPg() $limitQuery = clone $query; $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); - $this->assertEquals( + self::assertSame( "SELECT DISTINCT id_1, MIN(sclr_3) AS dctrn_minrownum FROM (SELECT COUNT(g0_.id) AS sclr_0, u1_.id AS id_1, g0_.id AS id_2, ROW_NUMBER() OVER(ORDER BY COUNT(g0_.id) ASC, u1_.id DESC) AS sclr_3 FROM User u1_ INNER JOIN user_group u2_ ON u1_.id = u2_.user_id INNER JOIN groups g0_ ON g0_.id = u2_.group_id) dctrn_result GROUP BY id_1 ORDER BY dctrn_minrownum ASC", $limitQuery->getSQL() ); @@ -78,7 +78,7 @@ public function testLimitSubqueryWithMixedSortPg() $this->entityManager->getConnection()->setDatabasePlatform($odp); } - public function testLimitSubqueryWithHiddenScalarSortPg() + public function testLimitSubqueryWithHiddenScalarSortPg() : void { $odp = $this->entityManager->getConnection()->getDatabasePlatform(); $this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform); @@ -89,7 +89,7 @@ public function testLimitSubqueryWithHiddenScalarSortPg() $limitQuery = clone $query; $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); - $this->assertEquals( + self::assertSame( "SELECT DISTINCT id_1, MIN(sclr_3) AS dctrn_minrownum FROM (SELECT COUNT(g0_.id) AS sclr_0, u1_.id AS id_1, g0_.id AS id_2, ROW_NUMBER() OVER(ORDER BY COUNT(g0_.id) ASC, u1_.id DESC) AS sclr_3 FROM User u1_ INNER JOIN user_group u2_ ON u1_.id = u2_.user_id INNER JOIN groups g0_ ON g0_.id = u2_.group_id) dctrn_result GROUP BY id_1 ORDER BY dctrn_minrownum ASC", $limitQuery->getSQL() ); @@ -97,7 +97,7 @@ public function testLimitSubqueryWithHiddenScalarSortPg() $this->entityManager->getConnection()->setDatabasePlatform($odp); } - public function testLimitSubqueryPg() + public function testLimitSubqueryPg() : void { $odp = $this->entityManager->getConnection()->getDatabasePlatform(); $this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform); @@ -107,7 +107,7 @@ public function testLimitSubqueryPg() $this->entityManager->getConnection()->setDatabasePlatform($odp); } - public function testLimitSubqueryWithSortOracle() + public function testLimitSubqueryWithSortOracle() : void { $odp = $this->entityManager->getConnection()->getDatabasePlatform(); $this->entityManager->getConnection()->setDatabasePlatform(new OraclePlatform); @@ -118,14 +118,14 @@ public function testLimitSubqueryWithSortOracle() $limitQuery = clone $query; $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); - $this->assertEquals( + self::assertSame( "SELECT DISTINCT ID_0, MIN(SCLR_5) AS dctrn_minrownum FROM (SELECT m0_.id AS ID_0, m0_.title AS TITLE_1, c1_.id AS ID_2, a2_.id AS ID_3, a2_.name AS NAME_4, ROW_NUMBER() OVER(ORDER BY m0_.title ASC) AS SCLR_5, m0_.author_id AS AUTHOR_ID_6, m0_.category_id AS CATEGORY_ID_7 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON m0_.category_id = c1_.id INNER JOIN Author a2_ ON m0_.author_id = a2_.id) dctrn_result GROUP BY ID_0 ORDER BY dctrn_minrownum ASC", $limitQuery->getSQL() ); $this->entityManager->getConnection()->setDatabasePlatform($odp); } - public function testLimitSubqueryWithScalarSortOracle() + public function testLimitSubqueryWithScalarSortOracle() : void { $odp = $this->entityManager->getConnection()->getDatabasePlatform(); $this->entityManager->getConnection()->setDatabasePlatform(new OraclePlatform); @@ -137,7 +137,7 @@ public function testLimitSubqueryWithScalarSortOracle() $limitQuery = clone $query; $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); - $this->assertEquals( + self::assertSame( "SELECT DISTINCT ID_1, MIN(SCLR_3) AS dctrn_minrownum FROM (SELECT COUNT(g0_.id) AS SCLR_0, u1_.id AS ID_1, g0_.id AS ID_2, ROW_NUMBER() OVER(ORDER BY COUNT(g0_.id) ASC) AS SCLR_3 FROM User u1_ INNER JOIN user_group u2_ ON u1_.id = u2_.user_id INNER JOIN groups g0_ ON g0_.id = u2_.group_id) dctrn_result GROUP BY ID_1 ORDER BY dctrn_minrownum ASC", $limitQuery->getSQL() ); @@ -145,7 +145,7 @@ public function testLimitSubqueryWithScalarSortOracle() $this->entityManager->getConnection()->setDatabasePlatform($odp); } - public function testLimitSubqueryWithMixedSortOracle() + public function testLimitSubqueryWithMixedSortOracle() : void { $odp = $this->entityManager->getConnection()->getDatabasePlatform(); $this->entityManager->getConnection()->setDatabasePlatform(new OraclePlatform); @@ -157,7 +157,7 @@ public function testLimitSubqueryWithMixedSortOracle() $limitQuery = clone $query; $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); - $this->assertEquals( + self::assertSame( "SELECT DISTINCT ID_1, MIN(SCLR_3) AS dctrn_minrownum FROM (SELECT COUNT(g0_.id) AS SCLR_0, u1_.id AS ID_1, g0_.id AS ID_2, ROW_NUMBER() OVER(ORDER BY COUNT(g0_.id) ASC, u1_.id DESC) AS SCLR_3 FROM User u1_ INNER JOIN user_group u2_ ON u1_.id = u2_.user_id INNER JOIN groups g0_ ON g0_.id = u2_.group_id) dctrn_result GROUP BY ID_1 ORDER BY dctrn_minrownum ASC", $limitQuery->getSQL() ); @@ -165,7 +165,7 @@ public function testLimitSubqueryWithMixedSortOracle() $this->entityManager->getConnection()->setDatabasePlatform($odp); } - public function testLimitSubqueryOracle() + public function testLimitSubqueryOracle() : void { $odp = $this->entityManager->getConnection()->getDatabasePlatform(); $this->entityManager->getConnection()->setDatabasePlatform(new OraclePlatform); @@ -176,21 +176,21 @@ public function testLimitSubqueryOracle() $limitQuery = clone $query; $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); - $this->assertEquals( + self::assertSame( "SELECT DISTINCT ID_0 FROM (SELECT m0_.id AS ID_0, m0_.title AS TITLE_1, c1_.id AS ID_2, a2_.id AS ID_3, a2_.name AS NAME_4, m0_.author_id AS AUTHOR_ID_5, m0_.category_id AS CATEGORY_ID_6 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON m0_.category_id = c1_.id INNER JOIN Author a2_ ON m0_.author_id = a2_.id) dctrn_result", $limitQuery->getSQL() ); $this->entityManager->getConnection()->setDatabasePlatform($odp); } - public function testCountQueryMixedResultsWithName() + public function testCountQueryMixedResultsWithName() : void { $query = $this->entityManager->createQuery( 'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a'); $limitQuery = clone $query; $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); - $this->assertEquals( + self::assertSame( "SELECT DISTINCT id_0 FROM (SELECT a0_.id AS id_0, a0_.name AS name_1, sum(a0_.name) AS sclr_2 FROM Author a0_) dctrn_result", $limitQuery->getSQL() ); } @@ -198,7 +198,7 @@ public function testCountQueryMixedResultsWithName() /** * @group DDC-3336 */ - public function testCountQueryWithArithmeticOrderByCondition() + public function testCountQueryWithArithmeticOrderByCondition() : void { $query = $this->entityManager->createQuery( 'SELECT a FROM Doctrine\Tests\ORM\Tools\Pagination\Author a ORDER BY (1 - 1000) * 1 DESC' @@ -213,7 +213,7 @@ public function testCountQueryWithArithmeticOrderByCondition() ); } - public function testCountQueryWithComplexScalarOrderByItem() + public function testCountQueryWithComplexScalarOrderByItem() : void { $query = $this->entityManager->createQuery( 'SELECT a FROM Doctrine\Tests\ORM\Tools\Pagination\Avatar a ORDER BY a.image_height * a.image_width DESC' @@ -228,7 +228,7 @@ public function testCountQueryWithComplexScalarOrderByItem() ); } - public function testCountQueryWithComplexScalarOrderByItemJoined() + public function testCountQueryWithComplexScalarOrderByItemJoined() : void { $query = $this->entityManager->createQuery( 'SELECT u FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.avatar a ORDER BY a.image_height * a.image_width DESC' @@ -243,7 +243,7 @@ public function testCountQueryWithComplexScalarOrderByItemJoined() ); } - public function testCountQueryWithComplexScalarOrderByItemJoinedWithPartial() + public function testCountQueryWithComplexScalarOrderByItemJoinedWithPartial() : void { $query = $this->entityManager->createQuery( 'SELECT u, partial a.{id, image_alt_desc} FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.avatar a ORDER BY a.image_height * a.image_width DESC' @@ -258,7 +258,7 @@ public function testCountQueryWithComplexScalarOrderByItemJoinedWithPartial() ); } - public function testCountQueryWithComplexScalarOrderByItemOracle() + public function testCountQueryWithComplexScalarOrderByItemOracle() : void { $query = $this->entityManager->createQuery( 'SELECT a FROM Doctrine\Tests\ORM\Tools\Pagination\Avatar a ORDER BY a.image_height * a.image_width DESC' @@ -276,7 +276,7 @@ public function testCountQueryWithComplexScalarOrderByItemOracle() /** * @group DDC-3434 */ - public function testLimitSubqueryWithHiddenSelectionInOrderBy() + public function testLimitSubqueryWithHiddenSelectionInOrderBy() : void { $query = $this->entityManager->createQuery( 'SELECT a, a.name AS HIDDEN ord FROM Doctrine\Tests\ORM\Tools\Pagination\Author a ORDER BY ord DESC' @@ -284,13 +284,13 @@ public function testLimitSubqueryWithHiddenSelectionInOrderBy() $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); - $this->assertEquals( + self::assertSame( 'SELECT DISTINCT id_0 FROM (SELECT DISTINCT id_0, name_2 FROM (SELECT a0_.id AS id_0, a0_.name AS name_1, a0_.name AS name_2 FROM Author a0_) dctrn_result_inner ORDER BY name_2 DESC) dctrn_result', $query->getSQL() ); } - public function testLimitSubqueryWithColumnWithSortDirectionInName() + public function testLimitSubqueryWithColumnWithSortDirectionInName() : void { $query = $this->entityManager->createQuery( 'SELECT a FROM Doctrine\Tests\ORM\Tools\Pagination\Avatar a ORDER BY a.image_alt_desc DESC' @@ -305,7 +305,7 @@ public function testLimitSubqueryWithColumnWithSortDirectionInName() ); } - public function testLimitSubqueryWithOrderByInnerJoined() + public function testLimitSubqueryWithOrderByInnerJoined() : void { $query = $this->entityManager->createQuery( 'SELECT b FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost b JOIN b.author a ORDER BY a.name ASC' @@ -313,13 +313,13 @@ public function testLimitSubqueryWithOrderByInnerJoined() $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); - $this->assertEquals( + self::assertSame( 'SELECT DISTINCT id_0 FROM (SELECT DISTINCT id_0, name_1 FROM (SELECT b0_.id AS id_0, a1_.name AS name_1, b0_.author_id AS author_id_2, b0_.category_id AS category_id_3 FROM BlogPost b0_ INNER JOIN Author a1_ ON b0_.author_id = a1_.id) dctrn_result_inner ORDER BY name_1 ASC) dctrn_result', $query->getSQL() ); } - public function testLimitSubqueryWithOrderByAndSubSelectInWhereClauseMySql() + public function testLimitSubqueryWithOrderByAndSubSelectInWhereClauseMySql() : void { $this->entityManager->getConnection()->setDatabasePlatform(new MySqlPlatform()); $query = $this->entityManager->createQuery( @@ -329,13 +329,13 @@ public function testLimitSubqueryWithOrderByAndSubSelectInWhereClauseMySql() ); $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); - $this->assertEquals( + self::assertSame( 'SELECT DISTINCT id_0 FROM (SELECT DISTINCT id_0 FROM (SELECT b0_.id AS id_0, b0_.author_id AS author_id_1, b0_.category_id AS category_id_2 FROM BlogPost b0_ WHERE ((SELECT COUNT(b1_.id) AS sclr_3 FROM BlogPost b1_) = 1)) dctrn_result_inner ORDER BY id_0 DESC) dctrn_result', $query->getSQL() ); } - public function testLimitSubqueryWithOrderByAndSubSelectInWhereClausePgSql() + public function testLimitSubqueryWithOrderByAndSubSelectInWhereClausePgSql() : void { $this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform()); $query = $this->entityManager->createQuery( @@ -345,7 +345,7 @@ public function testLimitSubqueryWithOrderByAndSubSelectInWhereClausePgSql() ); $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); - $this->assertEquals( + self::assertSame( 'SELECT DISTINCT id_0, MIN(sclr_1) AS dctrn_minrownum FROM (SELECT b0_.id AS id_0, ROW_NUMBER() OVER(ORDER BY b0_.id DESC) AS sclr_1, b0_.author_id AS author_id_2, b0_.category_id AS category_id_3 FROM BlogPost b0_ WHERE ((SELECT COUNT(b1_.id) AS sclr_4 FROM BlogPost b1_) = 1)) dctrn_result GROUP BY id_0 ORDER BY dctrn_minrownum ASC', $query->getSQL() ); @@ -354,7 +354,7 @@ public function testLimitSubqueryWithOrderByAndSubSelectInWhereClausePgSql() /** * This tests ordering by property that has the 'declared' field. */ - public function testLimitSubqueryOrderByFieldFromMappedSuperclass() + public function testLimitSubqueryOrderByFieldFromMappedSuperclass() : void { $this->entityManager->getConnection()->setDatabasePlatform(new MySqlPlatform()); @@ -364,7 +364,7 @@ public function testLimitSubqueryOrderByFieldFromMappedSuperclass() ); $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); - $this->assertEquals( + self::assertSame( 'SELECT DISTINCT id_0 FROM (SELECT DISTINCT id_0 FROM (SELECT b0_.id AS id_0, b0_.name AS name_1 FROM Banner b0_) dctrn_result_inner ORDER BY id_0 DESC) dctrn_result', $query->getSQL() ); @@ -373,7 +373,7 @@ public function testLimitSubqueryOrderByFieldFromMappedSuperclass() /** * Tests order by on a subselect expression (mysql). */ - public function testLimitSubqueryOrderBySubSelectOrderByExpression() + public function testLimitSubqueryOrderBySubSelectOrderByExpression() : void { $this->entityManager->getConnection()->setDatabasePlatform(new MySqlPlatform()); @@ -389,7 +389,7 @@ public function testLimitSubqueryOrderBySubSelectOrderByExpression() ); $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); - $this->assertEquals( + self::assertSame( 'SELECT DISTINCT id_0 FROM (SELECT DISTINCT id_0, sclr_2 FROM (SELECT a0_.id AS id_0, a0_.name AS name_1, (SELECT MIN(m1_.title) AS sclr_3 FROM MyBlogPost m1_ WHERE m1_.author_id = a0_.id) AS sclr_2 FROM Author a0_) dctrn_result_inner ORDER BY sclr_2 DESC) dctrn_result', $query->getSQL() ); @@ -398,7 +398,7 @@ public function testLimitSubqueryOrderBySubSelectOrderByExpression() /** * Tests order by on a subselect expression invoking RowNumberOverFunction (postgres). */ - public function testLimitSubqueryOrderBySubSelectOrderByExpressionPg() + public function testLimitSubqueryOrderBySubSelectOrderByExpressionPg() : void { $this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform()); @@ -414,7 +414,7 @@ public function testLimitSubqueryOrderBySubSelectOrderByExpressionPg() ); $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); - $this->assertEquals( + self::assertSame( 'SELECT DISTINCT id_0, MIN(sclr_4) AS dctrn_minrownum FROM (SELECT a0_.id AS id_0, a0_.name AS name_1, (SELECT MIN(m1_.title) AS sclr_3 FROM MyBlogPost m1_ WHERE m1_.author_id = a0_.id) AS sclr_2, ROW_NUMBER() OVER(ORDER BY (SELECT MIN(m1_.title) AS sclr_5 FROM MyBlogPost m1_ WHERE m1_.author_id = a0_.id) DESC) AS sclr_4 FROM Author a0_) dctrn_result GROUP BY id_0 ORDER BY dctrn_minrownum ASC', $query->getSQL() ); @@ -423,7 +423,7 @@ public function testLimitSubqueryOrderBySubSelectOrderByExpressionPg() /** * Tests order by on a subselect expression invoking RowNumberOverFunction (oracle). */ - public function testLimitSubqueryOrderBySubSelectOrderByExpressionOracle() + public function testLimitSubqueryOrderBySubSelectOrderByExpressionOracle() : void { $this->entityManager->getConnection()->setDatabasePlatform(new OraclePlatform()); @@ -439,7 +439,7 @@ public function testLimitSubqueryOrderBySubSelectOrderByExpressionOracle() ); $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); - $this->assertEquals( + self::assertSame( 'SELECT DISTINCT ID_0, MIN(SCLR_4) AS dctrn_minrownum FROM (SELECT a0_.id AS ID_0, a0_.name AS NAME_1, (SELECT MIN(m1_.title) AS SCLR_3 FROM MyBlogPost m1_ WHERE m1_.author_id = a0_.id) AS SCLR_2, ROW_NUMBER() OVER(ORDER BY (SELECT MIN(m1_.title) AS SCLR_5 FROM MyBlogPost m1_ WHERE m1_.author_id = a0_.id) DESC) AS SCLR_4 FROM Author a0_) dctrn_result GROUP BY ID_0 ORDER BY dctrn_minrownum ASC', $query->getSQL() ); From 2b824ea9dfa9e2aef6b2b8e202efd486430e81d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 16 Jul 2017 23:48:35 +0200 Subject: [PATCH 394/877] Update ConsoleRunner command list Adding L2C commands and DBAL reserved words command. --- lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php b/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php index 706d99d33e6..a6f198507cd 100644 --- a/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php +++ b/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php @@ -92,13 +92,17 @@ static public function addCommands(Application $cli) $cli->addCommands( [ // DBAL Commands - new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(), new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(), + new \Doctrine\DBAL\Tools\Console\Command\ReservedWordsCommand(), + new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(), // ORM Commands + new \Doctrine\ORM\Tools\Console\Command\ClearCache\CollectionRegionCommand(), + new \Doctrine\ORM\Tools\Console\Command\ClearCache\EntityRegionCommand(), new \Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand(), - new \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand(), new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand(), + new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryRegionCommand(), + new \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand(), new \Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand(), new \Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand(), new \Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand(), From d4b94e097a54dc0f53f2186c9da5445f507a8fbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sat, 22 Jul 2017 21:47:50 +0200 Subject: [PATCH 395/877] Ensure that ConsoleRunner has the right command list --- .../ORM/Tools/Console/ConsoleRunnerTest.php | 46 +++++++++++++++++-- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/ConsoleRunnerTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/ConsoleRunnerTest.php index 9d19665344d..a53ba514dd9 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/ConsoleRunnerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/ConsoleRunnerTest.php @@ -5,6 +5,7 @@ use Doctrine\ORM\Tools\Console\ConsoleRunner; use Doctrine\ORM\Version; use Doctrine\Tests\DoctrineTestCase; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\HelperSet; /** @@ -12,15 +13,50 @@ * * @covers \Doctrine\ORM\Tools\Console\ConsoleRunner */ -class ConsoleRunnerTest extends DoctrineTestCase +final class ConsoleRunnerTest extends DoctrineTestCase { - public function testCreateApplication() + public function testCreateApplicationShouldReturnAnApplicationWithTheCorrectCommands() : void { $helperSet = new HelperSet(); $app = ConsoleRunner::createApplication($helperSet); - $this->assertInstanceOf('Symfony\Component\Console\Application', $app); - $this->assertSame($helperSet, $app->getHelperSet()); - $this->assertEquals(Version::VERSION, $app->getVersion()); + self::assertSame($helperSet, $app->getHelperSet()); + self::assertEquals(Version::VERSION, $app->getVersion()); + + self::assertTrue($app->has('dbal:import')); + self::assertTrue($app->has('dbal:reserved-words')); + self::assertTrue($app->has('dbal:run-sql')); + self::assertTrue($app->has('orm:clear-cache:region:collection')); + self::assertTrue($app->has('orm:clear-cache:region:entity')); + self::assertTrue($app->has('orm:clear-cache:region:query')); + self::assertTrue($app->has('orm:clear-cache:metadata')); + self::assertTrue($app->has('orm:clear-cache:query')); + self::assertTrue($app->has('orm:clear-cache:result')); + self::assertTrue($app->has('orm:convert-d1-schema')); + self::assertTrue($app->has('orm:convert-mapping')); + self::assertTrue($app->has('orm:convert:d1-schema')); + self::assertTrue($app->has('orm:convert:mapping')); + self::assertTrue($app->has('orm:ensure-production-settings')); + self::assertTrue($app->has('orm:generate-entities')); + self::assertTrue($app->has('orm:generate-proxies')); + self::assertTrue($app->has('orm:generate-repositories')); + self::assertTrue($app->has('orm:generate:entities')); + self::assertTrue($app->has('orm:generate:proxies')); + self::assertTrue($app->has('orm:generate:repositories')); + self::assertTrue($app->has('orm:info')); + self::assertTrue($app->has('orm:mapping:describe')); + self::assertTrue($app->has('orm:run-dql')); + self::assertTrue($app->has('orm:schema-tool:create')); + self::assertTrue($app->has('orm:schema-tool:drop')); + self::assertTrue($app->has('orm:schema-tool:update')); + self::assertTrue($app->has('orm:validate-schema')); + } + + public function testCreateApplicationShouldAppendGivenCommands() : void + { + $command = 'my:lovely-command'; + $app = ConsoleRunner::createApplication(new HelperSet(), [new Command($command)]); + + self::assertTrue($app->has($command)); } } From 5109322f7d7bb1e804943954b821c6fa561dcaa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sat, 22 Jul 2017 21:52:58 +0200 Subject: [PATCH 396/877] Make explicit the design decisions of ConsoleRunner --- UPGRADE.md | 4 + .../ORM/Tools/Console/ConsoleRunner.php | 73 +++++++++---------- 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index a502c872e6b..3132aef9805 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,9 @@ # Upgrade to 2.6 +## Minor BC BREAK: `Doctrine\ORM\Tools\Console\ConsoleRunner` is now final + +Since it's just an utilitarian class and should not be inherited. + ## Minor BC BREAK: removed `Doctrine\ORM\Query\Parser#isInternalFunction` Method `Doctrine\ORM\Query\QueryException::associationPathInverseSideNotSupported` diff --git a/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php b/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php index a6f198507cd..c6a265cc079 100644 --- a/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php +++ b/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php @@ -19,44 +19,44 @@ namespace Doctrine\ORM\Tools\Console; -use Symfony\Component\Console\Application; -use Symfony\Component\Console\Helper\HelperSet; -use Doctrine\ORM\Version; +use Doctrine\DBAL\Tools\Console as DBALConsole; use Doctrine\ORM\EntityManagerInterface; - -use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper; use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; +use Doctrine\ORM\Version; +use Symfony\Component\Console\Application; +use Symfony\Component\Console\Helper\HelperSet; /** * Handles running the Console Tools inside Symfony Console context. */ -class ConsoleRunner +final class ConsoleRunner { /** * Create a Symfony Console HelperSet * * @param EntityManagerInterface $entityManager + * * @return HelperSet */ - public static function createHelperSet(EntityManagerInterface $entityManager) + public static function createHelperSet(EntityManagerInterface $entityManager) : HelperSet { return new HelperSet( [ - 'db' => new ConnectionHelper($entityManager->getConnection()), - 'em' => new EntityManagerHelper($entityManager) + 'db' => new DBALConsole\Helper\ConnectionHelper($entityManager->getConnection()), + 'em' => new EntityManagerHelper($entityManager), ] ); } /** - * Runs console with the given helperset. + * Runs console with the given helper set. * * @param \Symfony\Component\Console\Helper\HelperSet $helperSet * @param \Symfony\Component\Console\Command\Command[] $commands * * @return void */ - static public function run(HelperSet $helperSet, $commands = []) + public static function run(HelperSet $helperSet, array $commands = []) : void { $cli = self::createApplication($helperSet, $commands); $cli->run(); @@ -71,7 +71,7 @@ static public function run(HelperSet $helperSet, $commands = []) * * @return \Symfony\Component\Console\Application */ - static public function createApplication(HelperSet $helperSet, $commands = []) + public static function createApplication(HelperSet $helperSet, array $commands = []) : Application { $cli = new Application('Doctrine Command Line Interface', Version::VERSION); $cli->setCatchExceptions(true); @@ -87,40 +87,40 @@ static public function createApplication(HelperSet $helperSet, $commands = []) * * @return void */ - static public function addCommands(Application $cli) + public static function addCommands(Application $cli) : void { $cli->addCommands( [ // DBAL Commands - new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(), - new \Doctrine\DBAL\Tools\Console\Command\ReservedWordsCommand(), - new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(), + new DBALConsole\Command\ImportCommand(), + new DBALConsole\Command\ReservedWordsCommand(), + new DBALConsole\Command\RunSqlCommand(), // ORM Commands - new \Doctrine\ORM\Tools\Console\Command\ClearCache\CollectionRegionCommand(), - new \Doctrine\ORM\Tools\Console\Command\ClearCache\EntityRegionCommand(), - new \Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand(), - new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand(), - new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryRegionCommand(), - new \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand(), - new \Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand(), - new \Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand(), - new \Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand(), - new \Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand(), - new \Doctrine\ORM\Tools\Console\Command\ConvertDoctrine1SchemaCommand(), - new \Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand(), - new \Doctrine\ORM\Tools\Console\Command\GenerateEntitiesCommand(), - new \Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand(), - new \Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand(), - new \Doctrine\ORM\Tools\Console\Command\RunDqlCommand(), - new \Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand(), - new \Doctrine\ORM\Tools\Console\Command\InfoCommand(), - new \Doctrine\ORM\Tools\Console\Command\MappingDescribeCommand(), + new Command\ClearCache\CollectionRegionCommand(), + new Command\ClearCache\EntityRegionCommand(), + new Command\ClearCache\MetadataCommand(), + new Command\ClearCache\QueryCommand(), + new Command\ClearCache\QueryRegionCommand(), + new Command\ClearCache\ResultCommand(), + new Command\SchemaTool\CreateCommand(), + new Command\SchemaTool\UpdateCommand(), + new Command\SchemaTool\DropCommand(), + new Command\EnsureProductionSettingsCommand(), + new Command\ConvertDoctrine1SchemaCommand(), + new Command\GenerateRepositoriesCommand(), + new Command\GenerateEntitiesCommand(), + new Command\GenerateProxiesCommand(), + new Command\ConvertMappingCommand(), + new Command\RunDqlCommand(), + new Command\ValidateSchemaCommand(), + new Command\InfoCommand(), + new Command\MappingDescribeCommand(), ] ); } - static public function printCliConfigTemplate() + public static function printCliConfigTemplate() : void { echo <<<'HELP' You are missing a "cli-config.php" or "config/cli-config.php" file in your @@ -139,6 +139,5 @@ static public function printCliConfigTemplate() return ConsoleRunner::createHelperSet($entityManager); HELP; - } } From af3591fbca0610c3c8b9859efe5fae79214b7fe1 Mon Sep 17 00:00:00 2001 From: Alessandro Frangioni <> Date: Mon, 5 Jun 2017 11:47:15 +0200 Subject: [PATCH 397/877] Fixes #5804 --- lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 6af159fc7b6..3c502e3d746 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -344,9 +344,13 @@ protected function fetchVersionValue($versionedClass, array $id) . ' FROM ' . $tableName . ' WHERE ' . implode(' = ? AND ', $identifier) . ' = ?'; + $types = []; + foreach ($identifier as $fieldName) { + $types[] = $versionedClass->fieldMappings[$fieldName]['type']; + } $flatId = $this->identifierFlattener->flattenIdentifier($versionedClass, $id); - $value = $this->conn->fetchColumn($sql, array_values($flatId)); + $value = $this->conn->fetchColumn($sql, array_values($flatId), 0, $types); return Type::getType($fieldMapping['type'])->convertToPHPValue($value, $this->platform); } From 4ef0a238bfb0b5da59104bfe11189f4c5b103020 Mon Sep 17 00:00:00 2001 From: Alessandro Frangioni <> Date: Tue, 6 Jun 2017 17:28:34 +0200 Subject: [PATCH 398/877] Inferring id's field types --- .../ORM/Persisters/Entity/BasicEntityPersister.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 3c502e3d746..f94d79e9609 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -345,9 +345,12 @@ protected function fetchVersionValue($versionedClass, array $id) . ' WHERE ' . implode(' = ? AND ', $identifier) . ' = ?'; $types = []; - foreach ($identifier as $fieldName) { - $types[] = $versionedClass->fieldMappings[$fieldName]['type']; + foreach ($id as $field => $value) { + foreach ($this->getTypes($field, $value, $versionedClass) as $type) { + $types[] = $type; + } } + $flatId = $this->identifierFlattener->flattenIdentifier($versionedClass, $id); $value = $this->conn->fetchColumn($sql, array_values($flatId), 0, $types); From f6907b95032e0af3875d802405e432d47df7578c Mon Sep 17 00:00:00 2001 From: Alessandro Frangioni <> Date: Mon, 12 Jun 2017 15:40:14 +0200 Subject: [PATCH 399/877] Applied patches as for #6496 --- .../ORM/Functional/Ticket/GH5804Test.php | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php new file mode 100644 index 00000000000..6d877711d5a --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php @@ -0,0 +1,108 @@ +_schemaTool->createSchema( + [$this->_em->getClassMetadata(GH5804Article::class)] + ); + } + + public function testTextColumnSaveAndRetrieve2() + { + $firstArticle = new GH5804Article; + $firstArticle->text = 'Max'; + $this->_em->persist($firstArticle); + $this->_em->flush(); + + self::assertSame(1, $firstArticle->version); + + $firstArticle->text = 'Moritz'; + $this->_em->persist($firstArticle); + $this->_em->flush(); + + self::assertSame(2, $firstArticle->version); + } +} + +final class GH5804Generator extends AbstractIdGenerator +{ + /** + * {@inheritdoc} + */ + public function generate(EntityManager $em, $entity) + { + return 'test5804'; + } +} + +final class GH5804Type extends Type +{ + const NAME = 'GH5804Type'; + + public function getName() + { + return self::NAME; + } + + /** + * {@inheritdoc} + */ + public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) + { + return $platform->getGuidTypeDeclarationSQL($fieldDeclaration); + } + + /** + * {@inheritdoc} + */ + public function convertToDatabaseValue($value, AbstractPlatform $platform) + { + if (empty($value)) { + return null; + } + + return 'testGh5804DbValue'; + } +} + +/** + * @Entity + * @Table(name="gh5804_articles") + */ +class GH5804Article +{ + /** + * @Id + * @Column(type="GH5804Type") + * @GeneratedValue(strategy="CUSTOM") + * @CustomIdGenerator(class=\Doctrine\Tests\ORM\Functional\Ticket\GH5804Generator::class) + */ + public $id; + /** + * @Version + * @Column(type="integer") + */ + public $version; + + /** + * @Column(type="text") + */ + public $text; +} From 82c87081b4804c013c6f34b780f1bf015d18e799 Mon Sep 17 00:00:00 2001 From: Alessandro Frangioni <> Date: Mon, 12 Jun 2017 15:41:20 +0200 Subject: [PATCH 400/877] Changed SQL declaration for custom type --- tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php index 6d877711d5a..272d2fdbe11 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php @@ -66,7 +66,7 @@ public function getName() */ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { - return $platform->getGuidTypeDeclarationSQL($fieldDeclaration); + return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration); } /** From 60a2628f9d1a62fbe4bc467dbf60301344c52953 Mon Sep 17 00:00:00 2001 From: Alessandro Frangioni <> Date: Tue, 20 Jun 2017 09:25:14 +0200 Subject: [PATCH 401/877] Iteration simplified --- lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index f94d79e9609..9cec30ffd9a 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -346,9 +346,7 @@ protected function fetchVersionValue($versionedClass, array $id) $types = []; foreach ($id as $field => $value) { - foreach ($this->getTypes($field, $value, $versionedClass) as $type) { - $types[] = $type; - } + $types = array_merge($types, $this->getTypes($field, $value, $versionedClass)); } $flatId = $this->identifierFlattener->flattenIdentifier($versionedClass, $id); From eba8fec1fb6460937504fe4dcd6036b5ce1a4a48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sat, 22 Jul 2017 22:39:47 +0200 Subject: [PATCH 402/877] Move identifier types extraction to a method --- .../Entity/BasicEntityPersister.php | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 9cec30ffd9a..972199c5ea2 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -344,18 +344,30 @@ protected function fetchVersionValue($versionedClass, array $id) . ' FROM ' . $tableName . ' WHERE ' . implode(' = ? AND ', $identifier) . ' = ?'; - $types = []; - foreach ($id as $field => $value) { - $types = array_merge($types, $this->getTypes($field, $value, $versionedClass)); - } $flatId = $this->identifierFlattener->flattenIdentifier($versionedClass, $id); - $value = $this->conn->fetchColumn($sql, array_values($flatId), 0, $types); + $value = $this->conn->fetchColumn( + $sql, + array_values($flatId), + 0, + $this->extractIdentifierTypes($id, $versionedClass) + ); return Type::getType($fieldMapping['type'])->convertToPHPValue($value, $this->platform); } + private function extractIdentifierTypes(array $id, ClassMetadata $versionedClass) : array + { + $types = []; + + foreach ($id as $field => $value) { + $types = array_merge($types, $this->getTypes($field, $value, $versionedClass)); + } + + return $types; + } + /** * {@inheritdoc} */ From 6bf9f6f72f84de58a180aa9124f7ec8b0089fe56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sat, 22 Jul 2017 22:41:07 +0200 Subject: [PATCH 403/877] Remove unnecessary annotation from test --- tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php index 272d2fdbe11..77d4fbc878e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php @@ -84,7 +84,6 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) /** * @Entity - * @Table(name="gh5804_articles") */ class GH5804Article { @@ -95,6 +94,7 @@ class GH5804Article * @CustomIdGenerator(class=\Doctrine\Tests\ORM\Functional\Ticket\GH5804Generator::class) */ public $id; + /** * @Version * @Column(type="integer") From c8a41598c9fd065727a35ef636c3c3b4c627dbad Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 20:17:30 +0200 Subject: [PATCH 404/877] Not a performance test --- .../Doctrine/Tests/ORM/Performance/DDC2602Test.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Performance/DDC2602Test.php b/tests/Doctrine/Tests/ORM/Performance/DDC2602Test.php index 618b5f9c606..de8bedfc7d1 100644 --- a/tests/Doctrine/Tests/ORM/Performance/DDC2602Test.php +++ b/tests/Doctrine/Tests/ORM/Performance/DDC2602Test.php @@ -8,7 +8,6 @@ use Doctrine\Tests\OrmPerformanceTestCase; /** - * @group performance * @group DDC-2602 */ class DDC2602Test extends OrmPerformanceTestCase @@ -51,14 +50,10 @@ public function testIssue() // Set maximum seconds this can run $this->setMaxRunningTime(1); - $s = microtime(true); - - $query = $this->_em->createQuery('SELECT u, b FROM Doctrine\Tests\ORM\Performance\DDC2602User u JOIN u.biography b'); - $query->getResult(); - - $e = microtime(true); - - echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL; + $this + ->_em + ->createQuery('SELECT u, b FROM Doctrine\Tests\ORM\Performance\DDC2602User u JOIN u.biography b') + ->getResult(); } private function loadFixture() From 25669c51b604fb8bf7ee3d8cde48496699f3873b Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 20:17:41 +0200 Subject: [PATCH 405/877] PHPBench base config --- .gitignore | 1 + phpbench.json | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 phpbench.json diff --git a/.gitignore b/.gitignore index 490413d15f7..d2f5f690158 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ lib/Doctrine/DBAL .idea vendor/ composer.lock +/tests/Doctrine/Performance/history.db diff --git a/phpbench.json b/phpbench.json new file mode 100644 index 00000000000..74fdef412a7 --- /dev/null +++ b/phpbench.json @@ -0,0 +1,15 @@ +{ + "bootstrap": "vendor/autoload.php", + "path": "tests/Doctrine/Performance", + + "extensions": [ + "PhpBench\\Extensions\\Dbal\\DbalExtension", + "PhpBench\\Extensions\\XDebug\\XDebugExtension" + ], + + "storage": "dbal", + "storage.dbal.connection": { + "driver": "pdo_sqlite", + "path": "tests/Doctrine/Performance/history.db" + } +} From 37cb2c0722161d27eff2def8da3efd81c4250307 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 20:17:56 +0200 Subject: [PATCH 406/877] Benchmark autoloading definitions --- composer.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d320b0b4dd5..d632c89919d 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,10 @@ "psr-4": { "Doctrine\\ORM\\": "lib/Doctrine/ORM" } }, "autoload-dev": { - "psr-4": { "Doctrine\\Tests\\": "tests/Doctrine/Tests" } + "psr-4": { + "Doctrine\\Tests\\": "tests/Doctrine/Tests", + "Doctrine\\Performance\\": "tests/Doctrine/Performance" + } }, "bin": ["bin/doctrine"], "extra": { From 94adf9755023d611eed424995660683738272ced Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 20:49:39 +0200 Subject: [PATCH 407/877] Factory used to create a new entity manager --- .../Performance/EntityManagerFactory.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/Doctrine/Performance/EntityManagerFactory.php diff --git a/tests/Doctrine/Performance/EntityManagerFactory.php b/tests/Doctrine/Performance/EntityManagerFactory.php new file mode 100644 index 00000000000..fab5eba767c --- /dev/null +++ b/tests/Doctrine/Performance/EntityManagerFactory.php @@ -0,0 +1,39 @@ +setProxyDir(__DIR__ . '/../Tests/Proxies'); + $config->setProxyNamespace('Doctrine\Tests\Proxies'); + $config->setAutoGenerateProxyClasses(ProxyFactory::AUTOGENERATE_EVAL); + $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([ + realpath(__DIR__ . '/Models/Cache'), + realpath(__DIR__ . '/Models/GeoNames') + ], true)); + + $entityManager = EntityManager::create( + [ + 'driverClass' => Driver::class, + 'memory' => true, + ], + $config + ); + + (new SchemaTool($entityManager)) + ->createSchema(array_map([$entityManager, 'getClassMetadata'], $schemaClassNames)); + + return $entityManager; + } +} From f95c81b21018394004a2368c13a0b94715012093 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 20:49:56 +0200 Subject: [PATCH 408/877] Simple array hydration benchmark --- ...leQueryScalarHydrationPerformanceBench.php | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tests/Doctrine/Performance/Hydration/SimpleQueryScalarHydrationPerformanceBench.php diff --git a/tests/Doctrine/Performance/Hydration/SimpleQueryScalarHydrationPerformanceBench.php b/tests/Doctrine/Performance/Hydration/SimpleQueryScalarHydrationPerformanceBench.php new file mode 100644 index 00000000000..298aaf86b1d --- /dev/null +++ b/tests/Doctrine/Performance/Hydration/SimpleQueryScalarHydrationPerformanceBench.php @@ -0,0 +1,83 @@ + '1', + 'u__status' => 'developer', + 'u__username' => 'romanb', + 'u__name' => 'Roman', + ], + [ + 'u__id' => '1', + 'u__status' => 'developer', + 'u__username' => 'romanb', + 'u__name' => 'Roman', + ], + [ + 'u__id' => '2', + 'u__status' => 'developer', + 'u__username' => 'romanb', + 'u__name' => 'Roman', + ] + ]; + + for ($i = 4; $i < 10000; ++$i) { + $resultSet[] = [ + 'u__id' => $i, + 'u__status' => 'developer', + 'u__username' => 'jwage', + 'u__name' => 'Jonathan', + ]; + } + + $this->stmt = new HydratorMockStatement($resultSet); + $this->hydrator = new ScalarHydrator($entityManager); + $this->rsm = new ResultSetMapping; + + $this->rsm->addEntityResult(CmsUser::class, 'u'); + $this->rsm->addFieldResult('u', 'u__id', 'id'); + $this->rsm->addFieldResult('u', 'u__status', 'status'); + $this->rsm->addFieldResult('u', 'u__username', 'username'); + $this->rsm->addFieldResult('u', 'u__name', 'name'); + } + + public function benchSimpleQueryScalarHydrationPerformance() + { + $this->hydrator->hydrateAll($this->stmt, $this->rsm); + } +} + From 88ea1d33fa92e26bcc44ed1a42b172af1b780c10 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 20:50:11 +0200 Subject: [PATCH 409/877] Full hydration + query benchmark --- .../Hydration/SimpleHydrationBench.php | 58 +++++++++++++++++++ .../ORM/Functional/Ticket/DDC1050Test.php | 39 ------------- 2 files changed, 58 insertions(+), 39 deletions(-) create mode 100644 tests/Doctrine/Performance/Hydration/SimpleHydrationBench.php delete mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1050Test.php diff --git a/tests/Doctrine/Performance/Hydration/SimpleHydrationBench.php b/tests/Doctrine/Performance/Hydration/SimpleHydrationBench.php new file mode 100644 index 00000000000..c1bc1d61dbf --- /dev/null +++ b/tests/Doctrine/Performance/Hydration/SimpleHydrationBench.php @@ -0,0 +1,58 @@ +entityManager = EntityManagerFactory::getEntityManager([ + \Doctrine\Tests\Models\CMS\CmsUser::class, + \Doctrine\Tests\Models\CMS\CmsPhonenumber::class, + \Doctrine\Tests\Models\CMS\CmsAddress::class, + \Doctrine\Tests\Models\CMS\CmsEmail::class, + \Doctrine\Tests\Models\CMS\CmsGroup::class, + \Doctrine\Tests\Models\CMS\CmsTag::class, + \Doctrine\Tests\Models\CMS\CmsArticle::class, + \Doctrine\Tests\Models\CMS\CmsComment::class, + ]); + + for ($i = 2; $i < 10000; ++$i) { + $user = new CmsUser(); + + $user->status = 'developer'; + $user->username = 'jwage' . $i; + $user->name = 'Jonathan'; + + $this->entityManager->persist($user); + } + + $this->entityManager->flush(); + $this->entityManager->clear(); + + $this->repository = $this->entityManager->getRepository(CmsUser::class); + } + + public function benchSimpleFindOperationHydration() + { + $this->repository->findAll(); + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1050Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1050Test.php deleted file mode 100644 index 12c3898d858..00000000000 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1050Test.php +++ /dev/null @@ -1,39 +0,0 @@ -markTestSkipped('performance skipped'); - - $this->useModelSet('cms'); - - parent::setUp(); - } - - public function testPerformance() - { - for ($i = 2; $i < 10000; ++$i) { - $user = new CmsUser(); - $user->status = 'developer'; - $user->username = 'jwage'.$i; - $user->name = 'Jonathan'; - $this->_em->persist($user); - } - $this->_em->flush(); - $this->_em->clear(); - - $s = microtime(true); - $users = $this->_em->getRepository(CmsUser::class)->findAll(); - $e = microtime(true); - echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL; - } -} From d8ddc47f83840bf16870d5873bf91e675aeaad4b Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 20:52:18 +0200 Subject: [PATCH 410/877] Array hydration benchmark --- ...pleQueryArrayHydrationPerformanceBench.php | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tests/Doctrine/Performance/Hydration/SimpleQueryArrayHydrationPerformanceBench.php diff --git a/tests/Doctrine/Performance/Hydration/SimpleQueryArrayHydrationPerformanceBench.php b/tests/Doctrine/Performance/Hydration/SimpleQueryArrayHydrationPerformanceBench.php new file mode 100644 index 00000000000..9ff8a1f9b34 --- /dev/null +++ b/tests/Doctrine/Performance/Hydration/SimpleQueryArrayHydrationPerformanceBench.php @@ -0,0 +1,83 @@ + '1', + 'u__status' => 'developer', + 'u__username' => 'romanb', + 'u__name' => 'Roman', + ], + [ + 'u__id' => '1', + 'u__status' => 'developer', + 'u__username' => 'romanb', + 'u__name' => 'Roman', + ], + [ + 'u__id' => '2', + 'u__status' => 'developer', + 'u__username' => 'romanb', + 'u__name' => 'Roman', + ] + ]; + + for ($i = 4; $i < 10000; ++$i) { + $resultSet[] = [ + 'u__id' => $i, + 'u__status' => 'developer', + 'u__username' => 'jwage', + 'u__name' => 'Jonathan', + ]; + } + + $this->stmt = new HydratorMockStatement($resultSet); + $this->hydrator = new ArrayHydrator($entityManager); + $this->rsm = new ResultSetMapping; + + $this->rsm->addEntityResult(CmsUser::class, 'u'); + $this->rsm->addFieldResult('u', 'u__id', 'id'); + $this->rsm->addFieldResult('u', 'u__status', 'status'); + $this->rsm->addFieldResult('u', 'u__username', 'username'); + $this->rsm->addFieldResult('u', 'u__name', 'name'); + } + + public function benchSimpleQueryScalarHydrationPerformance() + { + $this->hydrator->hydrateAll($this->stmt, $this->rsm); + } +} + From 8774b02c8884f4af30403fd1b5d4f62d7a9d6324 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 20:57:40 +0200 Subject: [PATCH 411/877] Testing mixed array hydration (with scalars and fetch-joined results) --- ...etchJoinArrayHydrationPerformanceBench.php | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 tests/Doctrine/Performance/Hydration/MixedQueryFetchJoinArrayHydrationPerformanceBench.php diff --git a/tests/Doctrine/Performance/Hydration/MixedQueryFetchJoinArrayHydrationPerformanceBench.php b/tests/Doctrine/Performance/Hydration/MixedQueryFetchJoinArrayHydrationPerformanceBench.php new file mode 100644 index 00000000000..31757f940f2 --- /dev/null +++ b/tests/Doctrine/Performance/Hydration/MixedQueryFetchJoinArrayHydrationPerformanceBench.php @@ -0,0 +1,94 @@ + '1', + 'u__status' => 'developer', + 'u__username' => 'romanb', + 'u__name' => 'Roman', + 'sclr0' => 'ROMANB', + 'p__phonenumber' => '42', + ], + [ + 'u__id' => '1', + 'u__status' => 'developer', + 'u__username' => 'romanb', + 'u__name' => 'Roman', + 'sclr0' => 'ROMANB', + 'p__phonenumber' => '43', + ], + [ + 'u__id' => '2', + 'u__status' => 'developer', + 'u__username' => 'romanb', + 'u__name' => 'Roman', + 'sclr0' => 'JWAGE', + 'p__phonenumber' => '91' + ] + ]; + + for ($i = 4; $i < 10000; ++$i) { + $resultSet[] = [ + 'u__id' => $i, + 'u__status' => 'developer', + 'u__username' => 'jwage', + 'u__name' => 'Jonathan', + 'sclr0' => 'JWAGE' . $i, + 'p__phonenumber' => '91' + ]; + } + + $this->stmt = new HydratorMockStatement($resultSet); + $this->hydrator = new ArrayHydrator($entityManager); + $this->rsm = new ResultSetMapping; + + $this->rsm->addEntityResult(CmsUser::class, 'u'); + $this->rsm->addJoinedEntityResult(CmsPhonenumber::class, 'p', 'u', 'phonenumbers'); + $this->rsm->addFieldResult('u', 'u__id', 'id'); + $this->rsm->addFieldResult('u', 'u__status', 'status'); + $this->rsm->addFieldResult('u', 'u__username', 'username'); + $this->rsm->addFieldResult('u', 'u__name', 'name'); + $this->rsm->addScalarResult('sclr0', 'nameUpper'); + $this->rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); + } + + public function benchSimpleQueryScalarHydrationPerformance() + { + $this->hydrator->hydrateAll($this->stmt, $this->rsm); + } +} + From 0fdcc7188705333c282da948910c09bdd9c0d21c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 20:57:50 +0200 Subject: [PATCH 412/877] CS (alignment) --- ...pleQueryArrayHydrationPerformanceBench.php | 24 +++++++++---------- ...leQueryScalarHydrationPerformanceBench.php | 24 +++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/Doctrine/Performance/Hydration/SimpleQueryArrayHydrationPerformanceBench.php b/tests/Doctrine/Performance/Hydration/SimpleQueryArrayHydrationPerformanceBench.php index 9ff8a1f9b34..4e19ad8b364 100644 --- a/tests/Doctrine/Performance/Hydration/SimpleQueryArrayHydrationPerformanceBench.php +++ b/tests/Doctrine/Performance/Hydration/SimpleQueryArrayHydrationPerformanceBench.php @@ -36,31 +36,31 @@ public function init() $resultSet = [ [ - 'u__id' => '1', - 'u__status' => 'developer', + 'u__id' => '1', + 'u__status' => 'developer', 'u__username' => 'romanb', - 'u__name' => 'Roman', + 'u__name' => 'Roman', ], [ - 'u__id' => '1', - 'u__status' => 'developer', + 'u__id' => '1', + 'u__status' => 'developer', 'u__username' => 'romanb', - 'u__name' => 'Roman', + 'u__name' => 'Roman', ], [ - 'u__id' => '2', - 'u__status' => 'developer', + 'u__id' => '2', + 'u__status' => 'developer', 'u__username' => 'romanb', - 'u__name' => 'Roman', + 'u__name' => 'Roman', ] ]; for ($i = 4; $i < 10000; ++$i) { $resultSet[] = [ - 'u__id' => $i, - 'u__status' => 'developer', + 'u__id' => $i, + 'u__status' => 'developer', 'u__username' => 'jwage', - 'u__name' => 'Jonathan', + 'u__name' => 'Jonathan', ]; } diff --git a/tests/Doctrine/Performance/Hydration/SimpleQueryScalarHydrationPerformanceBench.php b/tests/Doctrine/Performance/Hydration/SimpleQueryScalarHydrationPerformanceBench.php index 298aaf86b1d..47242bd8e77 100644 --- a/tests/Doctrine/Performance/Hydration/SimpleQueryScalarHydrationPerformanceBench.php +++ b/tests/Doctrine/Performance/Hydration/SimpleQueryScalarHydrationPerformanceBench.php @@ -36,31 +36,31 @@ public function init() $resultSet = [ [ - 'u__id' => '1', - 'u__status' => 'developer', + 'u__id' => '1', + 'u__status' => 'developer', 'u__username' => 'romanb', - 'u__name' => 'Roman', + 'u__name' => 'Roman', ], [ - 'u__id' => '1', - 'u__status' => 'developer', + 'u__id' => '1', + 'u__status' => 'developer', 'u__username' => 'romanb', - 'u__name' => 'Roman', + 'u__name' => 'Roman', ], [ - 'u__id' => '2', - 'u__status' => 'developer', + 'u__id' => '2', + 'u__status' => 'developer', 'u__username' => 'romanb', - 'u__name' => 'Roman', + 'u__name' => 'Roman', ] ]; for ($i = 4; $i < 10000; ++$i) { $resultSet[] = [ - 'u__id' => $i, - 'u__status' => 'developer', + 'u__id' => $i, + 'u__status' => 'developer', 'u__username' => 'jwage', - 'u__name' => 'Jonathan', + 'u__name' => 'Jonathan', ]; } From f23359c1f38efaf2be8a8267f36eb60898b34bb1 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 21:04:35 +0200 Subject: [PATCH 413/877] Renaming bench methods, for clarity --- .../MixedQueryFetchJoinArrayHydrationPerformanceBench.php | 2 +- tests/Doctrine/Performance/Hydration/SimpleHydrationBench.php | 2 +- .../Hydration/SimpleQueryArrayHydrationPerformanceBench.php | 2 +- .../Hydration/SimpleQueryScalarHydrationPerformanceBench.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Doctrine/Performance/Hydration/MixedQueryFetchJoinArrayHydrationPerformanceBench.php b/tests/Doctrine/Performance/Hydration/MixedQueryFetchJoinArrayHydrationPerformanceBench.php index 31757f940f2..478f0b44d3e 100644 --- a/tests/Doctrine/Performance/Hydration/MixedQueryFetchJoinArrayHydrationPerformanceBench.php +++ b/tests/Doctrine/Performance/Hydration/MixedQueryFetchJoinArrayHydrationPerformanceBench.php @@ -86,7 +86,7 @@ public function init() $this->rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); } - public function benchSimpleQueryScalarHydrationPerformance() + public function benchHydration() { $this->hydrator->hydrateAll($this->stmt, $this->rsm); } diff --git a/tests/Doctrine/Performance/Hydration/SimpleHydrationBench.php b/tests/Doctrine/Performance/Hydration/SimpleHydrationBench.php index c1bc1d61dbf..b3ecbab2eea 100644 --- a/tests/Doctrine/Performance/Hydration/SimpleHydrationBench.php +++ b/tests/Doctrine/Performance/Hydration/SimpleHydrationBench.php @@ -51,7 +51,7 @@ public function init() $this->repository = $this->entityManager->getRepository(CmsUser::class); } - public function benchSimpleFindOperationHydration() + public function benchHydration() { $this->repository->findAll(); } diff --git a/tests/Doctrine/Performance/Hydration/SimpleQueryArrayHydrationPerformanceBench.php b/tests/Doctrine/Performance/Hydration/SimpleQueryArrayHydrationPerformanceBench.php index 4e19ad8b364..10081245dcb 100644 --- a/tests/Doctrine/Performance/Hydration/SimpleQueryArrayHydrationPerformanceBench.php +++ b/tests/Doctrine/Performance/Hydration/SimpleQueryArrayHydrationPerformanceBench.php @@ -75,7 +75,7 @@ public function init() $this->rsm->addFieldResult('u', 'u__name', 'name'); } - public function benchSimpleQueryScalarHydrationPerformance() + public function benchHydration() { $this->hydrator->hydrateAll($this->stmt, $this->rsm); } diff --git a/tests/Doctrine/Performance/Hydration/SimpleQueryScalarHydrationPerformanceBench.php b/tests/Doctrine/Performance/Hydration/SimpleQueryScalarHydrationPerformanceBench.php index 47242bd8e77..030b3667b69 100644 --- a/tests/Doctrine/Performance/Hydration/SimpleQueryScalarHydrationPerformanceBench.php +++ b/tests/Doctrine/Performance/Hydration/SimpleQueryScalarHydrationPerformanceBench.php @@ -75,7 +75,7 @@ public function init() $this->rsm->addFieldResult('u', 'u__name', 'name'); } - public function benchSimpleQueryScalarHydrationPerformance() + public function benchHydration() { $this->hydrator->hydrateAll($this->stmt, $this->rsm); } From 97735cdb68db18a76779886d0d061ec0a1e03763 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 21:12:43 +0200 Subject: [PATCH 414/877] Partial hydration bench --- ...PartialObjectHydrationPerformanceBench.php | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tests/Doctrine/Performance/Hydration/SimpleQueryPartialObjectHydrationPerformanceBench.php diff --git a/tests/Doctrine/Performance/Hydration/SimpleQueryPartialObjectHydrationPerformanceBench.php b/tests/Doctrine/Performance/Hydration/SimpleQueryPartialObjectHydrationPerformanceBench.php new file mode 100644 index 00000000000..cbbc24e1b12 --- /dev/null +++ b/tests/Doctrine/Performance/Hydration/SimpleQueryPartialObjectHydrationPerformanceBench.php @@ -0,0 +1,83 @@ + '1', + 'u__status' => 'developer', + 'u__username' => 'romanb', + 'u__name' => 'Roman', + ], + [ + 'u__id' => '1', + 'u__status' => 'developer', + 'u__username' => 'romanb', + 'u__name' => 'Roman', + ], + [ + 'u__id' => '2', + 'u__status' => 'developer', + 'u__username' => 'romanb', + 'u__name' => 'Roman', + ] + ]; + + for ($i = 4; $i < 10000; ++$i) { + $resultSet[] = [ + 'u__id' => $i, + 'u__status' => 'developer', + 'u__username' => 'jwage', + 'u__name' => 'Jonathan', + ]; + } + + $this->stmt = new HydratorMockStatement($resultSet); + $this->hydrator = new ObjectHydrator($entityManager); + $this->rsm = new ResultSetMapping; + + $this->rsm->addEntityResult(CmsUser::class, 'u'); + $this->rsm->addFieldResult('u', 'u__id', 'id'); + $this->rsm->addFieldResult('u', 'u__status', 'status'); + $this->rsm->addFieldResult('u', 'u__username', 'username'); + $this->rsm->addFieldResult('u', 'u__name', 'name'); + } + + public function benchHydration() + { + $this->hydrator->hydrateAll($this->stmt, $this->rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); + } +} + From 1e16cb83f847a228b6209f326f7cc610831a427c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 21:21:26 +0200 Subject: [PATCH 415/877] Full object hydration benchmark --- ...eryFullObjectHydrationPerformanceBench.php | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/Doctrine/Performance/Hydration/SimpleQueryFullObjectHydrationPerformanceBench.php diff --git a/tests/Doctrine/Performance/Hydration/SimpleQueryFullObjectHydrationPerformanceBench.php b/tests/Doctrine/Performance/Hydration/SimpleQueryFullObjectHydrationPerformanceBench.php new file mode 100644 index 00000000000..fc61b92402d --- /dev/null +++ b/tests/Doctrine/Performance/Hydration/SimpleQueryFullObjectHydrationPerformanceBench.php @@ -0,0 +1,76 @@ + '1', + 'u__status' => 'developer', + 'u__username' => 'romanb', + 'u__name' => 'Roman', + 'a__id' => '1' + ] + ]; + + for ($i = 2; $i < 10000; ++$i) { + $resultSet[] = [ + 'u__id' => $i, + 'u__status' => 'developer', + 'u__username' => 'jwage', + 'u__name' => 'Jonathan', + 'a__id' => $i + ]; + } + + $this->stmt = new HydratorMockStatement($resultSet); + $this->hydrator = new ObjectHydrator($entityManager); + $this->rsm = new ResultSetMapping; + + $this->rsm->addEntityResult(CmsUser::class, 'u'); + $this->rsm->addFieldResult('u', 'u__id', 'id'); + $this->rsm->addFieldResult('u', 'u__status', 'status'); + $this->rsm->addFieldResult('u', 'u__username', 'username'); + $this->rsm->addFieldResult('u', 'u__name', 'name'); + $this->rsm->addJoinedEntityResult(CmsAddress::class, 'a', 'u', 'address'); + $this->rsm->addFieldResult('a', 'a__id', 'id'); + } + + public function benchHydration() + { + $this->hydrator->hydrateAll($this->stmt, $this->rsm); + } +} + From 131aac531ad8e4dc8eaf91b853057544bb7dfed7 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 21:25:06 +0200 Subject: [PATCH 416/877] Removing unused `$entityManager` variable --- .../MixedQueryFetchJoinArrayHydrationPerformanceBench.php | 4 +--- .../Hydration/SimpleQueryArrayHydrationPerformanceBench.php | 4 +--- .../SimpleQueryFullObjectHydrationPerformanceBench.php | 4 +--- .../SimpleQueryPartialObjectHydrationPerformanceBench.php | 4 +--- .../Hydration/SimpleQueryScalarHydrationPerformanceBench.php | 4 +--- 5 files changed, 5 insertions(+), 15 deletions(-) diff --git a/tests/Doctrine/Performance/Hydration/MixedQueryFetchJoinArrayHydrationPerformanceBench.php b/tests/Doctrine/Performance/Hydration/MixedQueryFetchJoinArrayHydrationPerformanceBench.php index 478f0b44d3e..bbda1f23dd8 100644 --- a/tests/Doctrine/Performance/Hydration/MixedQueryFetchJoinArrayHydrationPerformanceBench.php +++ b/tests/Doctrine/Performance/Hydration/MixedQueryFetchJoinArrayHydrationPerformanceBench.php @@ -32,8 +32,6 @@ final class MixedQueryFetchJoinArrayHydrationPerformanceBench public function init() { - $entityManager = EntityManagerFactory::getEntityManager([]); - $resultSet = [ [ 'u__id' => '1', @@ -73,7 +71,7 @@ public function init() } $this->stmt = new HydratorMockStatement($resultSet); - $this->hydrator = new ArrayHydrator($entityManager); + $this->hydrator = new ArrayHydrator(EntityManagerFactory::getEntityManager([])); $this->rsm = new ResultSetMapping; $this->rsm->addEntityResult(CmsUser::class, 'u'); diff --git a/tests/Doctrine/Performance/Hydration/SimpleQueryArrayHydrationPerformanceBench.php b/tests/Doctrine/Performance/Hydration/SimpleQueryArrayHydrationPerformanceBench.php index 10081245dcb..aa404554dc8 100644 --- a/tests/Doctrine/Performance/Hydration/SimpleQueryArrayHydrationPerformanceBench.php +++ b/tests/Doctrine/Performance/Hydration/SimpleQueryArrayHydrationPerformanceBench.php @@ -32,8 +32,6 @@ final class SimpleQueryArrayHydrationPerformanceBench public function init() { - $entityManager = EntityManagerFactory::getEntityManager([]); - $resultSet = [ [ 'u__id' => '1', @@ -65,7 +63,7 @@ public function init() } $this->stmt = new HydratorMockStatement($resultSet); - $this->hydrator = new ArrayHydrator($entityManager); + $this->hydrator = new ArrayHydrator(EntityManagerFactory::getEntityManager([])); $this->rsm = new ResultSetMapping; $this->rsm->addEntityResult(CmsUser::class, 'u'); diff --git a/tests/Doctrine/Performance/Hydration/SimpleQueryFullObjectHydrationPerformanceBench.php b/tests/Doctrine/Performance/Hydration/SimpleQueryFullObjectHydrationPerformanceBench.php index fc61b92402d..173001ff80c 100644 --- a/tests/Doctrine/Performance/Hydration/SimpleQueryFullObjectHydrationPerformanceBench.php +++ b/tests/Doctrine/Performance/Hydration/SimpleQueryFullObjectHydrationPerformanceBench.php @@ -33,8 +33,6 @@ final class SimpleQueryFullObjectHydrationPerformanceBench public function init() { - $entityManager = EntityManagerFactory::getEntityManager([]); - $resultSet = [ [ 'u__id' => '1', @@ -56,7 +54,7 @@ public function init() } $this->stmt = new HydratorMockStatement($resultSet); - $this->hydrator = new ObjectHydrator($entityManager); + $this->hydrator = new ObjectHydrator(EntityManagerFactory::getEntityManager([])); $this->rsm = new ResultSetMapping; $this->rsm->addEntityResult(CmsUser::class, 'u'); diff --git a/tests/Doctrine/Performance/Hydration/SimpleQueryPartialObjectHydrationPerformanceBench.php b/tests/Doctrine/Performance/Hydration/SimpleQueryPartialObjectHydrationPerformanceBench.php index cbbc24e1b12..55d78973fe2 100644 --- a/tests/Doctrine/Performance/Hydration/SimpleQueryPartialObjectHydrationPerformanceBench.php +++ b/tests/Doctrine/Performance/Hydration/SimpleQueryPartialObjectHydrationPerformanceBench.php @@ -32,8 +32,6 @@ final class SimpleQueryPartialObjectHydrationPerformanceBench public function init() { - $entityManager = EntityManagerFactory::getEntityManager([]); - $resultSet = [ [ 'u__id' => '1', @@ -65,7 +63,7 @@ public function init() } $this->stmt = new HydratorMockStatement($resultSet); - $this->hydrator = new ObjectHydrator($entityManager); + $this->hydrator = new ObjectHydrator(EntityManagerFactory::getEntityManager([])); $this->rsm = new ResultSetMapping; $this->rsm->addEntityResult(CmsUser::class, 'u'); diff --git a/tests/Doctrine/Performance/Hydration/SimpleQueryScalarHydrationPerformanceBench.php b/tests/Doctrine/Performance/Hydration/SimpleQueryScalarHydrationPerformanceBench.php index 030b3667b69..4af2c0791bf 100644 --- a/tests/Doctrine/Performance/Hydration/SimpleQueryScalarHydrationPerformanceBench.php +++ b/tests/Doctrine/Performance/Hydration/SimpleQueryScalarHydrationPerformanceBench.php @@ -32,8 +32,6 @@ final class SimpleQueryScalarHydrationPerformanceBench public function init() { - $entityManager = EntityManagerFactory::getEntityManager([]); - $resultSet = [ [ 'u__id' => '1', @@ -65,7 +63,7 @@ public function init() } $this->stmt = new HydratorMockStatement($resultSet); - $this->hydrator = new ScalarHydrator($entityManager); + $this->hydrator = new ScalarHydrator(EntityManagerFactory::getEntityManager([])); $this->rsm = new ResultSetMapping; $this->rsm->addEntityResult(CmsUser::class, 'u'); From 608b3ed6a4bf324464a4892c4c84075d734bb6d9 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 21:26:55 +0200 Subject: [PATCH 417/877] Benchmarking mixed fetch-join with partial hydration --- ...PartialObjectHydrationPerformanceBench.php | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 tests/Doctrine/Performance/Hydration/MixedQueryFetchJoinPartialObjectHydrationPerformanceBench.php diff --git a/tests/Doctrine/Performance/Hydration/MixedQueryFetchJoinPartialObjectHydrationPerformanceBench.php b/tests/Doctrine/Performance/Hydration/MixedQueryFetchJoinPartialObjectHydrationPerformanceBench.php new file mode 100644 index 00000000000..f2e33f76dbd --- /dev/null +++ b/tests/Doctrine/Performance/Hydration/MixedQueryFetchJoinPartialObjectHydrationPerformanceBench.php @@ -0,0 +1,93 @@ + '1', + 'u__status' => 'developer', + 'u__username' => 'romanb', + 'u__name' => 'Roman', + 'sclr0' => 'ROMANB', + 'p__phonenumber' => '42', + ], + [ + 'u__id' => '1', + 'u__status' => 'developer', + 'u__username' => 'romanb', + 'u__name' => 'Roman', + 'sclr0' => 'ROMANB', + 'p__phonenumber' => '43', + ], + [ + 'u__id' => '2', + 'u__status' => 'developer', + 'u__username' => 'romanb', + 'u__name' => 'Roman', + 'sclr0' => 'JWAGE', + 'p__phonenumber' => '91' + ] + ]; + + for ($i = 4; $i < 2000; ++$i) { + $resultSet[] = [ + 'u__id' => $i, + 'u__status' => 'developer', + 'u__username' => 'jwage', + 'u__name' => 'Jonathan', + 'sclr0' => 'JWAGE' . $i, + 'p__phonenumber' => '91' + ]; + } + + $this->stmt = new HydratorMockStatement($resultSet); + $this->hydrator = new ObjectHydrator(EntityManagerFactory::getEntityManager([])); + $this->rsm = new ResultSetMapping; + + $this->rsm->addEntityResult(CmsUser::class, 'u'); + $this->rsm->addJoinedEntityResult(CmsPhonenumber::class, 'p', 'u', 'phonenumbers'); + $this->rsm->addFieldResult('u', 'u__id', 'id'); + $this->rsm->addFieldResult('u', 'u__status', 'status'); + $this->rsm->addFieldResult('u', 'u__username', 'username'); + $this->rsm->addFieldResult('u', 'u__name', 'name'); + $this->rsm->addScalarResult('sclr0', 'nameUpper'); + $this->rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); + } + + public function benchHydration() + { + $this->hydrator->hydrateAll($this->stmt, $this->rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); + } +} + From 93dc02819484cfef1402cd6853191965fb6b5e5a Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 21:29:26 +0200 Subject: [PATCH 418/877] Benchmarking full object hydration with fetch joins and mixed values --- ...oinFullObjectHydrationPerformanceBench.php | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 tests/Doctrine/Performance/Hydration/MixedQueryFetchJoinFullObjectHydrationPerformanceBench.php diff --git a/tests/Doctrine/Performance/Hydration/MixedQueryFetchJoinFullObjectHydrationPerformanceBench.php b/tests/Doctrine/Performance/Hydration/MixedQueryFetchJoinFullObjectHydrationPerformanceBench.php new file mode 100644 index 00000000000..c70ca77cb10 --- /dev/null +++ b/tests/Doctrine/Performance/Hydration/MixedQueryFetchJoinFullObjectHydrationPerformanceBench.php @@ -0,0 +1,81 @@ + '1', + 'u__status' => 'developer', + 'u__username' => 'romanb', + 'u__name' => 'Roman', + 'sclr0' => 'ROMANB', + 'p__phonenumber' => '42', + 'a__id' => '1' + ] + ]; + + for ($i = 2; $i < 2000; ++$i) { + $resultSet[] = [ + 'u__id' => $i, + 'u__status' => 'developer', + 'u__username' => 'jwage', + 'u__name' => 'Jonathan', + 'sclr0' => 'JWAGE' . $i, + 'p__phonenumber' => '91', + 'a__id' => $i + ]; + } + + $this->stmt = new HydratorMockStatement($resultSet); + $this->hydrator = new ObjectHydrator(EntityManagerFactory::getEntityManager([])); + $this->rsm = new ResultSetMapping; + + $this->rsm->addEntityResult(CmsUser::class, 'u'); + $this->rsm->addJoinedEntityResult(CmsPhonenumber::class, 'p', 'u', 'phonenumbers'); + $this->rsm->addFieldResult('u', 'u__id', 'id'); + $this->rsm->addFieldResult('u', 'u__status', 'status'); + $this->rsm->addFieldResult('u', 'u__username', 'username'); + $this->rsm->addFieldResult('u', 'u__name', 'name'); + $this->rsm->addScalarResult('sclr0', 'nameUpper'); + $this->rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); + $this->rsm->addJoinedEntityResult(CmsAddress::class, 'a', 'u', 'address'); + $this->rsm->addFieldResult('a', 'a__id', 'id'); + } + + public function benchHydration() + { + $this->hydrator->hydrateAll($this->stmt, $this->rsm); + } +} + From fd27b22ad1755b9d76021cf1dc00b62c9c6d12a6 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 21:29:50 +0200 Subject: [PATCH 419/877] Removing old `HydrationPerformanceTest` --- .../Performance/HydrationPerformanceTest.php | 456 ------------------ 1 file changed, 456 deletions(-) delete mode 100644 tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php diff --git a/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php deleted file mode 100644 index 0035222adb8..00000000000 --- a/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php +++ /dev/null @@ -1,456 +0,0 @@ - 0.7 seconds] - * - * MAXIMUM TIME: 1 second - */ - public function testSimpleQueryScalarHydrationPerformance10000Rows() - { - $rsm = new ResultSetMapping; - $rsm->addEntityResult(CmsUser::class, 'u'); - $rsm->addFieldResult('u', 'u__id', 'id'); - $rsm->addFieldResult('u', 'u__status', 'status'); - $rsm->addFieldResult('u', 'u__username', 'username'); - $rsm->addFieldResult('u', 'u__name', 'name'); - - // Faked result set - $resultSet = [ - //row1 - [ - 'u__id' => '1', - 'u__status' => 'developer', - 'u__username' => 'romanb', - 'u__name' => 'Roman', - ], - [ - 'u__id' => '1', - 'u__status' => 'developer', - 'u__username' => 'romanb', - 'u__name' => 'Roman', - ], - [ - 'u__id' => '2', - 'u__status' => 'developer', - 'u__username' => 'romanb', - 'u__name' => 'Roman', - ] - ]; - - for ($i = 4; $i < 10000; ++$i) { - $resultSet[] = [ - 'u__id' => $i, - 'u__status' => 'developer', - 'u__username' => 'jwage', - 'u__name' => 'Jonathan', - ]; - } - - $stmt = new HydratorMockStatement($resultSet); - $hydrator = new ScalarHydrator($this->_em); - - $this->setMaxRunningTime(1); - $s = microtime(true); - $result = $hydrator->hydrateAll($stmt, $rsm); - $e = microtime(true); - echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL; - } - - /** - * Times for comparison: - * - * [romanb: 10000 rows => 1 second] - * - * MAXIMUM TIME: 2 seconds - */ - public function testSimpleQueryArrayHydrationPerformance10000Rows() - { - $rsm = new ResultSetMapping; - $rsm->addEntityResult(CmsUser::class, 'u'); - $rsm->addFieldResult('u', 'u__id', 'id'); - $rsm->addFieldResult('u', 'u__status', 'status'); - $rsm->addFieldResult('u', 'u__username', 'username'); - $rsm->addFieldResult('u', 'u__name', 'name'); - - // Faked result set - $resultSet = [ - //row1 - [ - 'u__id' => '1', - 'u__status' => 'developer', - 'u__username' => 'romanb', - 'u__name' => 'Roman', - ], - [ - 'u__id' => '1', - 'u__status' => 'developer', - 'u__username' => 'romanb', - 'u__name' => 'Roman', - ], - [ - 'u__id' => '2', - 'u__status' => 'developer', - 'u__username' => 'romanb', - 'u__name' => 'Roman', - ] - ]; - - for ($i = 4; $i < 10000; ++$i) { - $resultSet[] = [ - 'u__id' => $i, - 'u__status' => 'developer', - 'u__username' => 'jwage', - 'u__name' => 'Jonathan', - ]; - } - - $stmt = new HydratorMockStatement($resultSet); - $hydrator = new ArrayHydrator($this->_em); - - $this->setMaxRunningTime(2); - $s = microtime(true); - $result = $hydrator->hydrateAll($stmt, $rsm); - $e = microtime(true); - echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL; - } - - /** - * Times for comparison: - * - * [romanb: 10000 rows => 1.4 seconds] - * - * MAXIMUM TIME: 3 seconds - */ - public function testMixedQueryFetchJoinArrayHydrationPerformance10000Rows() - { - $rsm = new ResultSetMapping; - $rsm->addEntityResult(CmsUser::class, 'u'); - $rsm->addJoinedEntityResult( - CmsPhonenumber::class, - 'p', - 'u', - 'phonenumbers' - ); - $rsm->addFieldResult('u', 'u__id', 'id'); - $rsm->addFieldResult('u', 'u__status', 'status'); - $rsm->addFieldResult('u', 'u__username', 'username'); - $rsm->addFieldResult('u', 'u__name', 'name'); - $rsm->addScalarResult('sclr0', 'nameUpper'); - $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); - - // Faked result set - $resultSet = [ - //row1 - [ - 'u__id' => '1', - 'u__status' => 'developer', - 'u__username' => 'romanb', - 'u__name' => 'Roman', - 'sclr0' => 'ROMANB', - 'p__phonenumber' => '42', - ], - [ - 'u__id' => '1', - 'u__status' => 'developer', - 'u__username' => 'romanb', - 'u__name' => 'Roman', - 'sclr0' => 'ROMANB', - 'p__phonenumber' => '43', - ], - [ - 'u__id' => '2', - 'u__status' => 'developer', - 'u__username' => 'romanb', - 'u__name' => 'Roman', - 'sclr0' => 'JWAGE', - 'p__phonenumber' => '91' - ] - ]; - - for ($i = 4; $i < 10000; ++$i) { - $resultSet[] = [ - 'u__id' => $i, - 'u__status' => 'developer', - 'u__username' => 'jwage', - 'u__name' => 'Jonathan', - 'sclr0' => 'JWAGE' . $i, - 'p__phonenumber' => '91' - ]; - } - - $stmt = new HydratorMockStatement($resultSet); - $hydrator = new ArrayHydrator($this->_em); - - $this->setMaxRunningTime(3); - $s = microtime(true); - $result = $hydrator->hydrateAll($stmt, $rsm); - $e = microtime(true); - echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL; - } - - /** - * [romanb: 10000 rows => 1.5 seconds] - * - * MAXIMUM TIME: 3 seconds - */ - public function testSimpleQueryPartialObjectHydrationPerformance10000Rows() - { - $rsm = new ResultSetMapping; - $rsm->addEntityResult(CmsUser::class, 'u'); - $rsm->addFieldResult('u', 'u__id', 'id'); - $rsm->addFieldResult('u', 'u__status', 'status'); - $rsm->addFieldResult('u', 'u__username', 'username'); - $rsm->addFieldResult('u', 'u__name', 'name'); - - // Faked result set - $resultSet = [ - //row1 - [ - 'u__id' => '1', - 'u__status' => 'developer', - 'u__username' => 'romanb', - 'u__name' => 'Roman', - ], - [ - 'u__id' => '1', - 'u__status' => 'developer', - 'u__username' => 'romanb', - 'u__name' => 'Roman', - ], - [ - 'u__id' => '2', - 'u__status' => 'developer', - 'u__username' => 'romanb', - 'u__name' => 'Roman', - ] - ]; - - for ($i = 4; $i < 10000; ++$i) { - $resultSet[] = [ - 'u__id' => $i, - 'u__status' => 'developer', - 'u__username' => 'jwage', - 'u__name' => 'Jonathan', - ]; - } - - $stmt = new HydratorMockStatement($resultSet); - $hydrator = new ObjectHydrator($this->_em); - - $this->setMaxRunningTime(3); - $s = microtime(true); - $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); - $e = microtime(true); - echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL; - } - - /** - * [romanb: 10000 rows => 3 seconds] - * - * MAXIMUM TIME: 4.5 seconds - */ - public function testSimpleQueryFullObjectHydrationPerformance10000Rows() - { - $rsm = new ResultSetMapping; - $rsm->addEntityResult(CmsUser::class, 'u'); - $rsm->addFieldResult('u', 'u__id', 'id'); - $rsm->addFieldResult('u', 'u__status', 'status'); - $rsm->addFieldResult('u', 'u__username', 'username'); - $rsm->addFieldResult('u', 'u__name', 'name'); - $rsm->addJoinedEntityResult( - CmsAddress::class, - 'a', - 'u', - 'address' - ); - $rsm->addFieldResult('a', 'a__id', 'id'); - //$rsm->addFieldResult('a', 'a__country', 'country'); - //$rsm->addFieldResult('a', 'a__zip', 'zip'); - //$rsm->addFieldResult('a', 'a__city', 'city'); - - // Faked result set - $resultSet = [ - //row1 - [ - 'u__id' => '1', - 'u__status' => 'developer', - 'u__username' => 'romanb', - 'u__name' => 'Roman', - 'a__id' => '1' - ] - ]; - - for ($i = 2; $i < 10000; ++$i) { - $resultSet[] = [ - 'u__id' => $i, - 'u__status' => 'developer', - 'u__username' => 'jwage', - 'u__name' => 'Jonathan', - 'a__id' => $i - ]; - } - - $stmt = new HydratorMockStatement($resultSet); - $hydrator = new ObjectHydrator($this->_em); - - $this->setMaxRunningTime(5); - $s = microtime(true); - $result = $hydrator->hydrateAll($stmt, $rsm); - $e = microtime(true); - echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL; - } - - /** - * [romanb: 2000 rows => 0.4 seconds] - * - * MAXIMUM TIME: 1 second - */ - public function testMixedQueryFetchJoinPartialObjectHydrationPerformance2000Rows() - { - $rsm = new ResultSetMapping; - $rsm->addEntityResult(CmsUser::class, 'u'); - $rsm->addJoinedEntityResult( - CmsPhonenumber::class, - 'p', - 'u', - 'phonenumbers' - ); - $rsm->addFieldResult('u', 'u__id', 'id'); - $rsm->addFieldResult('u', 'u__status', 'status'); - $rsm->addFieldResult('u', 'u__username', 'username'); - $rsm->addFieldResult('u', 'u__name', 'name'); - $rsm->addScalarResult('sclr0', 'nameUpper'); - $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); - - // Faked result set - $resultSet = [ - //row1 - [ - 'u__id' => '1', - 'u__status' => 'developer', - 'u__username' => 'romanb', - 'u__name' => 'Roman', - 'sclr0' => 'ROMANB', - 'p__phonenumber' => '42', - ], - [ - 'u__id' => '1', - 'u__status' => 'developer', - 'u__username' => 'romanb', - 'u__name' => 'Roman', - 'sclr0' => 'ROMANB', - 'p__phonenumber' => '43', - ], - [ - 'u__id' => '2', - 'u__status' => 'developer', - 'u__username' => 'romanb', - 'u__name' => 'Roman', - 'sclr0' => 'JWAGE', - 'p__phonenumber' => '91' - ] - ]; - - for ($i = 4; $i < 2000; ++$i) { - $resultSet[] = [ - 'u__id' => $i, - 'u__status' => 'developer', - 'u__username' => 'jwage', - 'u__name' => 'Jonathan', - 'sclr0' => 'JWAGE' . $i, - 'p__phonenumber' => '91' - ]; - } - - $stmt = new HydratorMockStatement($resultSet); - $hydrator = new ObjectHydrator($this->_em); - - $this->setMaxRunningTime(1); - $s = microtime(true); - $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); - $e = microtime(true); - echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL; - } - - /** - * [romanb: 2000 rows => 0.6 seconds] - * - * MAXIMUM TIME: 1 second - */ - public function testMixedQueryFetchJoinFullObjectHydrationPerformance2000Rows() - { - $rsm = new ResultSetMapping; - $rsm->addEntityResult(CmsUser::class, 'u'); - $rsm->addJoinedEntityResult(CmsPhonenumber::class, 'p', 'u', 'phonenumbers'); - $rsm->addFieldResult('u', 'u__id', 'id'); - $rsm->addFieldResult('u', 'u__status', 'status'); - $rsm->addFieldResult('u', 'u__username', 'username'); - $rsm->addFieldResult('u', 'u__name', 'name'); - $rsm->addScalarResult('sclr0', 'nameUpper'); - $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); - $rsm->addJoinedEntityResult(CmsAddress::class, 'a', 'u', 'address'); - $rsm->addFieldResult('a', 'a__id', 'id'); - - // Faked result set - $resultSet = [ - //row1 - [ - 'u__id' => '1', - 'u__status' => 'developer', - 'u__username' => 'romanb', - 'u__name' => 'Roman', - 'sclr0' => 'ROMANB', - 'p__phonenumber' => '42', - 'a__id' => '1' - ] - ]; - - for ($i = 2; $i < 2000; ++$i) { - $resultSet[] = [ - 'u__id' => $i, - 'u__status' => 'developer', - 'u__username' => 'jwage', - 'u__name' => 'Jonathan', - 'sclr0' => 'JWAGE' . $i, - 'p__phonenumber' => '91', - 'a__id' => $i - ]; - } - - $stmt = new HydratorMockStatement($resultSet); - $hydrator = new ObjectHydrator($this->_em); - - $this->setMaxRunningTime(1); - $s = microtime(true); - $result = $hydrator->hydrateAll($stmt, $rsm); - $e = microtime(true); - echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL; - } -} - From ef0edc892935e8dd2eced5443a3aca9bc7b2b5e8 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 21:45:23 +0200 Subject: [PATCH 420/877] Benchmarking simple insert operations (batched) --- .../Hydration/SimpleInsertPerformanceTest.php | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/Doctrine/Performance/Hydration/SimpleInsertPerformanceTest.php diff --git a/tests/Doctrine/Performance/Hydration/SimpleInsertPerformanceTest.php b/tests/Doctrine/Performance/Hydration/SimpleInsertPerformanceTest.php new file mode 100644 index 00000000000..48ec971ca41 --- /dev/null +++ b/tests/Doctrine/Performance/Hydration/SimpleInsertPerformanceTest.php @@ -0,0 +1,54 @@ +entityManager = EntityManagerFactory::getEntityManager([ + CMS\CmsUser::class, + CMS\CmsPhonenumber::class, + CMS\CmsAddress::class, + CMS\CmsEmail::class, + CMS\CmsGroup::class, + CMS\CmsTag::class, + CMS\CmsArticle::class, + CMS\CmsComment::class, + ]); + } + + public function benchHydration() + { + $batchSize = 20; + + for ($i = 1; $i <= 10000; ++$i) { + $user = new CMS\CmsUser; + $user->status = 'user'; + $user->username = 'user' . $i; + $user->name = 'Mr.Smith-' . $i; + + $this->entityManager->persist($user); + + if (! ($i % $batchSize)) { + $this->entityManager->flush(); + $this->entityManager->clear(); + } + } + } +} From cbb0c1bd0408e51dcb3740111086dd9d84ec00fc Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 21:46:02 +0200 Subject: [PATCH 421/877] Corrected class name - needs to end with `Bench` --- ...sertPerformanceTest.php => SimpleInsertPerformanceBench.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/Doctrine/Performance/Hydration/{SimpleInsertPerformanceTest.php => SimpleInsertPerformanceBench.php} (96%) diff --git a/tests/Doctrine/Performance/Hydration/SimpleInsertPerformanceTest.php b/tests/Doctrine/Performance/Hydration/SimpleInsertPerformanceBench.php similarity index 96% rename from tests/Doctrine/Performance/Hydration/SimpleInsertPerformanceTest.php rename to tests/Doctrine/Performance/Hydration/SimpleInsertPerformanceBench.php index 48ec971ca41..5ab8906edc9 100644 --- a/tests/Doctrine/Performance/Hydration/SimpleInsertPerformanceTest.php +++ b/tests/Doctrine/Performance/Hydration/SimpleInsertPerformanceBench.php @@ -12,7 +12,7 @@ /** * @BeforeMethods({"init"}) */ -final class SimpleInsertPerformanceTest +final class SimpleInsertPerformanceBench { /** * @var EntityManagerInterface From d51235f200dae6ac68bbeea8df2372310519fddf Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 21:46:24 +0200 Subject: [PATCH 422/877] Removing useless imports --- .../Hydration/SimpleHydrationBench.php | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/Doctrine/Performance/Hydration/SimpleHydrationBench.php b/tests/Doctrine/Performance/Hydration/SimpleHydrationBench.php index b3ecbab2eea..a3fd637d67e 100644 --- a/tests/Doctrine/Performance/Hydration/SimpleHydrationBench.php +++ b/tests/Doctrine/Performance/Hydration/SimpleHydrationBench.php @@ -5,7 +5,7 @@ use Doctrine\Common\Persistence\ObjectRepository; use Doctrine\ORM\EntityManagerInterface; use Doctrine\Performance\EntityManagerFactory; -use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\Models\CMS; /** * @BeforeMethods({"init"}) @@ -25,18 +25,18 @@ final class SimpleHydrationBench public function init() { $this->entityManager = EntityManagerFactory::getEntityManager([ - \Doctrine\Tests\Models\CMS\CmsUser::class, - \Doctrine\Tests\Models\CMS\CmsPhonenumber::class, - \Doctrine\Tests\Models\CMS\CmsAddress::class, - \Doctrine\Tests\Models\CMS\CmsEmail::class, - \Doctrine\Tests\Models\CMS\CmsGroup::class, - \Doctrine\Tests\Models\CMS\CmsTag::class, - \Doctrine\Tests\Models\CMS\CmsArticle::class, - \Doctrine\Tests\Models\CMS\CmsComment::class, + CMS\CmsUser::class, + CMS\CmsPhonenumber::class, + CMS\CmsAddress::class, + CMS\CmsEmail::class, + CMS\CmsGroup::class, + CMS\CmsTag::class, + CMS\CmsArticle::class, + CMS\CmsComment::class, ]); for ($i = 2; $i < 10000; ++$i) { - $user = new CmsUser(); + $user = new CMS\CmsUser(); $user->status = 'developer'; $user->username = 'jwage' . $i; @@ -48,7 +48,7 @@ public function init() $this->entityManager->flush(); $this->entityManager->clear(); - $this->repository = $this->entityManager->getRepository(CmsUser::class); + $this->repository = $this->entityManager->getRepository(CMS\CmsUser::class); } public function benchHydration() From 5401cb5329e78545d2e2192865e971c3b297042b Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 21:46:50 +0200 Subject: [PATCH 423/877] Removed old `InsertPerformanceTest` (moved to benchmark) --- .../ORM/Performance/InsertPerformanceTest.php | 56 ------------------- 1 file changed, 56 deletions(-) delete mode 100644 tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php diff --git a/tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php deleted file mode 100644 index db5455b062d..00000000000 --- a/tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php +++ /dev/null @@ -1,56 +0,0 @@ -useModelSet('cms'); - parent::setUp(); - } - - /** - * [romanb: 10000 objects in ~8 seconds] - */ - public function testInsertPerformance() - { - $s = microtime(true); - - $conn = $this->_em->getConnection(); - - $this->setMaxRunningTime(10); - - //echo "Memory usage before: " . (memory_get_usage() / 1024) . " KB" . PHP_EOL; - - $batchSize = 20; - for ($i=1; $i<=10000; ++$i) { - $user = new CmsUser; - $user->status = 'user'; - $user->username = 'user' . $i; - $user->name = 'Mr.Smith-' . $i; - $this->_em->persist($user); - if (($i % $batchSize) == 0) { - $this->_em->flush(); - $this->_em->clear(); - } - } - - //gc_collect_cycles(); - //echo "Memory usage after: " . (memory_get_usage() / 1024) . " KB" . PHP_EOL; - - $e = microtime(true); - - echo ' Inserted 10000 objects in ' . ($e - $s) . ' seconds' . PHP_EOL; - } -} - From 29f55eaef975e98ddd6785e1fcf5ceb8c22cd8b9 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 21:50:59 +0200 Subject: [PATCH 424/877] Removing instantiation overhead from benchmark --- .../SimpleInsertPerformanceBench.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/Doctrine/Performance/Hydration/SimpleInsertPerformanceBench.php b/tests/Doctrine/Performance/Hydration/SimpleInsertPerformanceBench.php index 5ab8906edc9..68a933dd31e 100644 --- a/tests/Doctrine/Performance/Hydration/SimpleInsertPerformanceBench.php +++ b/tests/Doctrine/Performance/Hydration/SimpleInsertPerformanceBench.php @@ -19,6 +19,11 @@ final class SimpleInsertPerformanceBench */ private $entityManager; + /** + * @var CMS\CmsUser[] + */ + private $users; + public function init() { $this->entityManager = EntityManagerFactory::getEntityManager([ @@ -31,11 +36,6 @@ public function init() CMS\CmsArticle::class, CMS\CmsComment::class, ]); - } - - public function benchHydration() - { - $batchSize = 20; for ($i = 1; $i <= 10000; ++$i) { $user = new CMS\CmsUser; @@ -43,9 +43,16 @@ public function benchHydration() $user->username = 'user' . $i; $user->name = 'Mr.Smith-' . $i; + $this->users[$i] = $user; + } + } + + public function benchHydration() + { + foreach ($this->users as $key => $user) { $this->entityManager->persist($user); - if (! ($i % $batchSize)) { + if (! ($key % 20)) { $this->entityManager->flush(); $this->entityManager->clear(); } From 2692435705413c7bed7040c2495532b036a6bda5 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 21:58:24 +0200 Subject: [PATCH 425/877] Benchmarking insert operations for a JTI --- .../InheritanceInsertPerformanceBench.php | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 tests/Doctrine/Performance/Hydration/InheritanceInsertPerformanceBench.php diff --git a/tests/Doctrine/Performance/Hydration/InheritanceInsertPerformanceBench.php b/tests/Doctrine/Performance/Hydration/InheritanceInsertPerformanceBench.php new file mode 100644 index 00000000000..220ec5c01d3 --- /dev/null +++ b/tests/Doctrine/Performance/Hydration/InheritanceInsertPerformanceBench.php @@ -0,0 +1,100 @@ +entityManager = EntityManagerFactory::getEntityManager([ + Company\CompanyPerson::class, + Company\CompanyEmployee::class, + Company\CompanyManager::class, + Company\CompanyOrganization::class, + Company\CompanyEvent::class, + Company\CompanyAuction::class, + Company\CompanyRaffle::class, + Company\CompanyCar::class, + Company\CompanyContract::class, + ]); + + $person = new Company\CompanyEmployee(); + $person->setName('Poor Sales Guy'); + $person->setDepartment('Sales'); + $person->setSalary(100); + $this->entityManager->persist($person); + + for ($i = 0; $i < 33; $i++) { + $this->fixContracts[$i] = new Company\CompanyFixContract(); + $this->fixContracts[$i]->setFixPrice(1000); + $this->fixContracts[$i]->setSalesPerson($person); + $this->fixContracts[$i]->markCompleted(); + + $this->flexContracts[$i] = new Company\CompanyFlexContract(); + $this->flexContracts[$i]->setSalesPerson($person); + $this->flexContracts[$i]->setHoursWorked(100); + $this->flexContracts[$i]->setPricePerHour(100); + $this->flexContracts[$i]->markCompleted(); + + $this->ultraContracts[$i] = new Company\CompanyFlexUltraContract(); + $this->ultraContracts[$i]->setSalesPerson($person); + $this->ultraContracts[$i]->setHoursWorked(150); + $this->ultraContracts[$i]->setPricePerHour(150); + $this->ultraContracts[$i]->setMaxPrice(7000); + } + } + + public function benchInsertFixContracts() + { + array_map([$this->entityManager, 'persist'], $this->fixContracts); + $this->entityManager->flush(); + } + + public function benchInsertFlexContracts() + { + array_map([$this->entityManager, 'persist'], $this->flexContracts); + $this->entityManager->flush(); + } + + public function benchInsertUltraContracts() + { + array_map([$this->entityManager, 'persist'], $this->ultraContracts); + $this->entityManager->flush(); + } + + public function benchInsertAllContracts() + { + array_map([$this->entityManager, 'persist'], $this->fixContracts); + array_map([$this->entityManager, 'persist'], $this->flexContracts); + array_map([$this->entityManager, 'persist'], $this->ultraContracts); + $this->entityManager->flush(); + } +} From c5a636ebfbe4f6abd9ad9ddd2e28c5ab93c3b13c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 22:07:25 +0200 Subject: [PATCH 426/877] Corrected benchmark name: benchmark affects a STI --- ...nch.php => SingleTableInheritanceInsertPerformanceBench.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/Doctrine/Performance/Hydration/{InheritanceInsertPerformanceBench.php => SingleTableInheritanceInsertPerformanceBench.php} (98%) diff --git a/tests/Doctrine/Performance/Hydration/InheritanceInsertPerformanceBench.php b/tests/Doctrine/Performance/Hydration/SingleTableInheritanceInsertPerformanceBench.php similarity index 98% rename from tests/Doctrine/Performance/Hydration/InheritanceInsertPerformanceBench.php rename to tests/Doctrine/Performance/Hydration/SingleTableInheritanceInsertPerformanceBench.php index 220ec5c01d3..8014b0ed1f3 100644 --- a/tests/Doctrine/Performance/Hydration/InheritanceInsertPerformanceBench.php +++ b/tests/Doctrine/Performance/Hydration/SingleTableInheritanceInsertPerformanceBench.php @@ -10,7 +10,7 @@ /** * @BeforeMethods({"init"}) */ -final class InheritanceInsertPerformanceBench +final class SingleTableInheritanceInsertPerformanceBench { /** * @var EntityManagerInterface From 52402917a0d519daa44dc104cd7ae1521eff181c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 22:07:35 +0200 Subject: [PATCH 427/877] Benchmarking hydration of a STI --- ...leInheritanceHydrationPerformanceBench.php | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 tests/Doctrine/Performance/Hydration/SingleTableInheritanceHydrationPerformanceBench.php diff --git a/tests/Doctrine/Performance/Hydration/SingleTableInheritanceHydrationPerformanceBench.php b/tests/Doctrine/Performance/Hydration/SingleTableInheritanceHydrationPerformanceBench.php new file mode 100644 index 00000000000..ec6c17c3eef --- /dev/null +++ b/tests/Doctrine/Performance/Hydration/SingleTableInheritanceHydrationPerformanceBench.php @@ -0,0 +1,107 @@ +contractsRepository = $entityManager->getRepository(Company\CompanyContract::class); + $this->fixContractsRepository = $entityManager->getRepository(Company\CompanyFixContract::class); + $this->flexContractRepository = $entityManager->getRepository(Company\CompanyFlexContract::class); + $this->ultraContractRepository = $entityManager->getRepository(Company\CompanyFlexUltraContract::class); + + $person = new Company\CompanyEmployee(); + $person->setName('Poor Sales Guy'); + $person->setDepartment('Sales'); + $person->setSalary(100); + $entityManager->persist($person); + + for ($i = 0; $i < 33; $i++) { + $fixContract = new Company\CompanyFixContract(); + $flexContract = new Company\CompanyFlexContract(); + $ultraContract = new Company\CompanyFlexUltraContract(); + + $fixContract->setFixPrice(1000); + $fixContract->setSalesPerson($person); + $fixContract->markCompleted(); + + $flexContract->setSalesPerson($person); + $flexContract->setHoursWorked(100); + $flexContract->setPricePerHour(100); + $flexContract->markCompleted(); + + $ultraContract->setSalesPerson($person); + $ultraContract->setHoursWorked(150); + $ultraContract->setPricePerHour(150); + $ultraContract->setMaxPrice(7000); + + $entityManager->persist($fixContract); + $entityManager->persist($flexContract); + $entityManager->persist($ultraContract); + } + + $entityManager->flush(); + $entityManager->clear(); + } + + public function benchHydrateFixContracts() + { + $this->fixContractsRepository->findAll(); + } + + public function benchHydrateFlexContracts() + { + $this->flexContractRepository->findAll(); + } + + public function benchHydrateUltraContracts() + { + $this->ultraContractRepository->findAll(); + } + + public function benchHydrateAllContracts() + { + $this->contractsRepository->findAll(); + } +} From 8ec186f0957e9edc107d80b666b15b471dbd6d3a Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 22:10:20 +0200 Subject: [PATCH 428/877] Removing old inheritance persister test --- .../InheritancePersisterPerformanceTest.php | 69 ------------------- 1 file changed, 69 deletions(-) delete mode 100644 tests/Doctrine/Tests/ORM/Performance/InheritancePersisterPerformanceTest.php diff --git a/tests/Doctrine/Tests/ORM/Performance/InheritancePersisterPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/InheritancePersisterPerformanceTest.php deleted file mode 100644 index 726389a4c1c..00000000000 --- a/tests/Doctrine/Tests/ORM/Performance/InheritancePersisterPerformanceTest.php +++ /dev/null @@ -1,69 +0,0 @@ -useModelSet('company'); - parent::setUp(); - } - - public function testCompanyContract() - { - $person = new CompanyEmployee(); - $person->setName('Poor Sales Guy'); - $person->setDepartment('Sales'); - $person->setSalary(100); - $this->_em->persist($person); - - for ($i = 0; $i < 33; $i++) { - $fix = new CompanyFixContract(); - $fix->setFixPrice(1000); - $fix->setSalesPerson($person); - $fix->markCompleted(); - $this->_em->persist($fix); - - $flex = new CompanyFlexContract(); - $flex->setSalesPerson($person); - $flex->setHoursWorked(100); - $flex->setPricePerHour(100); - $flex->markCompleted(); - $this->_em->persist($flex); - - $ultra = new CompanyFlexUltraContract(); - $ultra->setSalesPerson($person); - $ultra->setHoursWorked(150); - $ultra->setPricePerHour(150); - $ultra->setMaxPrice(7000); - $this->_em->persist($ultra); - } - - $this->_em->flush(); - $this->_em->clear(); - - $start = microtime(true); - $contracts = $this->_em->getRepository(CompanyContract::class)->findAll(); - echo "99 CompanyContract: " . number_format(microtime(true) - $start, 6) . "\n"; - $this->assertEquals(99, count($contracts)); - - $this->_em->clear(); - - $start = microtime(true); - $contracts = $this->_em->getRepository(CompanyContract::class)->findAll(); - echo "99 CompanyContract: " . number_format(microtime(true) - $start, 6) . "\n"; - $this->assertEquals(99, count($contracts)); - } -} From 7515dd20f262e7c5a675c67b3a94f05e44691526 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 22:10:47 +0200 Subject: [PATCH 429/877] Removing old `PersisterPerformanceTest` --- .../Performance/PersisterPerformanceTest.php | 113 ------------------ 1 file changed, 113 deletions(-) delete mode 100644 tests/Doctrine/Tests/ORM/Performance/PersisterPerformanceTest.php diff --git a/tests/Doctrine/Tests/ORM/Performance/PersisterPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/PersisterPerformanceTest.php deleted file mode 100644 index 30494d49bae..00000000000 --- a/tests/Doctrine/Tests/ORM/Performance/PersisterPerformanceTest.php +++ /dev/null @@ -1,113 +0,0 @@ -useModelSet('cms'); - parent::setUp(); - } - - public function testFindCmsArticle() - { - $author = new CmsUser(); - $author->name = "beberlei"; - $author->status = "active"; - $author->username = "beberlei"; - $this->_em->persist($author); - - $ids = []; - for ($i = 0; $i < 100; $i++) { - $article = new CmsArticle(); - $article->text = "foo"; - $article->topic = "bar"; - $article->user = $author; - $this->_em->persist($article); - $ids[] = $article; - } - $this->_em->flush(); - $this->_em->clear(); - - $start = microtime(true); - $articles = $this->_em->getRepository(CmsArticle::class)->findAll(); - echo "100 CmsArticle findAll(): " . number_format(microtime(true) - $start, 6) . "\n"; - - $this->_em->clear(); - - $start = microtime(true); - $articles = $this->_em->getRepository(CmsArticle::class)->findAll(); - echo "100 CmsArticle findAll(): " . number_format(microtime(true) - $start, 6) . "\n"; - - $this->_em->clear(); - - $start = microtime(true); - for ($i = 0; $i < 100; $i++) { - $articles = $this->_em->getRepository(CmsArticle::class)->find($ids[$i]->id); - } - echo "100 CmsArticle find(): " . number_format(microtime(true) - $start, 6) . "\n"; - - $this->_em->clear(); - - $start = microtime(true); - for ($i = 0; $i < 100; $i++) { - $articles = $this->_em->getRepository(CmsArticle::class)->find($ids[$i]->id); - } - echo "100 CmsArticle find(): " . number_format(microtime(true) - $start, 6) . "\n"; - } - - public function testFindCmsGroup() - { - for ($i = 0; $i < 100; $i++) { - $group = new CmsGroup(); - $group->name = "foo" . $i; - $this->_em->persist($group); - } - $this->_em->flush(); - $this->_em->clear(); - - $start = microtime(true); - $articles = $this->_em->getRepository(CmsGroup::class)->findAll(); - echo "100 CmsGroup: " . number_format(microtime(true) - $start, 6) . "\n"; - - $this->_em->clear(); - - $start = microtime(true); - $articles = $this->_em->getRepository(CmsGroup::class)->findAll(); - echo "100 CmsGroup: " . number_format(microtime(true) - $start, 6) . "\n"; - } - - public function testFindCmsUser() - { - for ($i = 0; $i < 100; $i++) { - $user = new CmsUser(); - $user->name = "beberlei"; - $user->status = "active"; - $user->username = "beberlei".$i; - $this->_em->persist($user); - } - - $this->_em->flush(); - $this->_em->clear(); - - $start = microtime(true); - $articles = $this->_em->getRepository(CmsUser::class)->findAll(); - echo "100 CmsUser: " . number_format(microtime(true) - $start, 6) . "\n"; - - $this->_em->clear(); - - $start = microtime(true); - $articles = $this->_em->getRepository(CmsUser::class)->findAll(); - echo "100 CmsUser: " . number_format(microtime(true) - $start, 6) . "\n"; - } -} From b1bbad3b15b10a39320d849b13674a570aa4db77 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 22:28:23 +0200 Subject: [PATCH 430/877] Unit of work changeset computation test --- .../UnitOfWorkComputeChangesBench.php | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 tests/Doctrine/Performance/ChangeSet/UnitOfWorkComputeChangesBench.php diff --git a/tests/Doctrine/Performance/ChangeSet/UnitOfWorkComputeChangesBench.php b/tests/Doctrine/Performance/ChangeSet/UnitOfWorkComputeChangesBench.php new file mode 100644 index 00000000000..25cc2fffdbb --- /dev/null +++ b/tests/Doctrine/Performance/ChangeSet/UnitOfWorkComputeChangesBench.php @@ -0,0 +1,73 @@ +unitOfWork = EntityManagerFactory::getEntityManager([])->getUnitOfWork(); + + for ($i = 1; $i <= 100; ++$i) { + $user = new CmsUser; + $user->id = $i; + $user->status = 'user'; + $user->username = 'user' . $i; + $user->name = 'Mr.Smith-' . $i; + $this->users[] = $user; + + $this->unitOfWork->registerManaged( + $user, + [ + 'id' => $i, + ], + [ + 'id' => $user->id, + 'status' => $user->status, + 'username' => $user->username, + 'name' => $user->name, + 'address' => $user->address, + 'email' => $user->email, + ] + ); + } + + $this->unitOfWork->computeChangeSets(); + + if ($this->unitOfWork->getScheduledEntityUpdates()) { + throw new \LogicException('Unit of work should be clean at this stage'); + } + + foreach ($this->users AS $user) { + $user->status = 'other'; + $user->username .= '++'; + $user->name = str_replace('Mr.', 'Mrs.', $user->name); + } + } + + public function benchChangeSetComputation() + { + $this->unitOfWork->computeChangeSets(); + } +} + From 77ce354f183674091dab9dca4363ba0b78bcfa0c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 22:28:54 +0200 Subject: [PATCH 431/877] Removing old `UnitOfWorkPerformanceTest` --- .../Performance/UnitOfWorkPerformanceTest.php | 50 ------------------- 1 file changed, 50 deletions(-) delete mode 100644 tests/Doctrine/Tests/ORM/Performance/UnitOfWorkPerformanceTest.php diff --git a/tests/Doctrine/Tests/ORM/Performance/UnitOfWorkPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/UnitOfWorkPerformanceTest.php deleted file mode 100644 index 3d63eb4d844..00000000000 --- a/tests/Doctrine/Tests/ORM/Performance/UnitOfWorkPerformanceTest.php +++ /dev/null @@ -1,50 +0,0 @@ -useModelSet('cms'); - parent::setUp(); - } - - public function testComputeChanges() - { - $n = 100; - - $users = []; - for ($i=1; $i<=$n; ++$i) { - $user = new CmsUser; - $user->status = 'user'; - $user->username = 'user' . $i; - $user->name = 'Mr.Smith-' . $i; - $this->_em->persist($user); - $users[] = $user; - } - $this->_em->flush(); - - - foreach ($users AS $user) { - $user->status = 'other'; - $user->username = $user->username . '++'; - $user->name = str_replace('Mr.', 'Mrs.', $user->name); - } - - $s = microtime(true); - $this->_em->flush(); - $e = microtime(true); - - echo ' Compute ChangeSet '.$n.' objects in ' . ($e - $s) . ' seconds' . PHP_EOL; - } -} From d658364b59309af8612ae03a170a58d8764aae53 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 22:38:02 +0200 Subject: [PATCH 432/877] Benchmarking instantiation of proxies --- .../ProxyInstantiationTimeBench.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/Doctrine/Performance/LazyLoading/ProxyInstantiationTimeBench.php diff --git a/tests/Doctrine/Performance/LazyLoading/ProxyInstantiationTimeBench.php b/tests/Doctrine/Performance/LazyLoading/ProxyInstantiationTimeBench.php new file mode 100644 index 00000000000..da5a2c94ff9 --- /dev/null +++ b/tests/Doctrine/Performance/LazyLoading/ProxyInstantiationTimeBench.php @@ -0,0 +1,40 @@ +proxyFactory = EntityManagerFactory::getEntityManager([])->getProxyFactory(); + } + + public function benchCmsUserInstantiation() + { + for ($i = 0; $i < 100000; ++$i) { + $this->proxyFactory->getProxy(CmsUser::class, ['id' => $i]); + } + } + + public function benchCmsEmployeeInstantiation() + { + for ($i = 0; $i < 100000; ++$i) { + $this->proxyFactory->getProxy(CmsEmployee::class, ['id' => $i]); + } + } +} + From d8140d700ac40d4d8d165a89ca8182ec5ab98c6c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 23:02:26 +0200 Subject: [PATCH 433/877] Benchmarking proxy initialization logic --- .../ProxyInitializationTimeBench.php | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 tests/Doctrine/Performance/LazyLoading/ProxyInitializationTimeBench.php diff --git a/tests/Doctrine/Performance/LazyLoading/ProxyInitializationTimeBench.php b/tests/Doctrine/Performance/LazyLoading/ProxyInitializationTimeBench.php new file mode 100644 index 00000000000..aeb5a1d2dee --- /dev/null +++ b/tests/Doctrine/Performance/LazyLoading/ProxyInitializationTimeBench.php @@ -0,0 +1,81 @@ +getProxyFactory(); + + for ($i = 0; $i < 10000; ++$i) { + $this->cmsUsers[$i] = $proxyFactory->getProxy(CmsUser::class, ['id' => $i]); + $this->cmsEmployees[$i] = $proxyFactory->getProxy(CmsEmployee::class, ['id' => $i]); + $this->initializedUsers[$i] = $proxyFactory->getProxy(CmsUser::class, ['id' => $i]); + $this->initializedEmployees[$i] = $proxyFactory->getProxy(CmsEmployee::class, ['id' => $i]); + + $this->initializedUsers[$i]->__load(); + $this->initializedEmployees[$i]->__load(); + } + } + + public function benchCmsUserInitialization() + { + foreach ($this->cmsUsers as $proxy) { + $proxy->__load(); + } + } + + public function benchCmsEmployeeInitialization() + { + foreach ($this->cmsEmployees as $proxy) { + $proxy->__load(); + } + } + + public function benchInitializationOfAlreadyInitializedCmsUsers() + { + foreach ($this->initializedUsers as $proxy) { + $proxy->__load(); + } + } + + public function benchInitializationOfAlreadyInitializedCmsEmployees() + { + foreach ($this->initializedEmployees as $proxy) { + $proxy->__load(); + } + } +} + From f1bc1bbf12becd1cc46cc4e2f0636c6e28344969 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 23:02:44 +0200 Subject: [PATCH 434/877] Mocks required by the proxy performance benchmarks --- .../Performance/Mock/NonLoadingPersister.php | 31 ++ .../Mock/NonProxyLoadingEntityManager.php | 352 ++++++++++++++++++ .../Mock/NonProxyLoadingUnitOfWork.php | 31 ++ 3 files changed, 414 insertions(+) create mode 100644 tests/Doctrine/Performance/Mock/NonLoadingPersister.php create mode 100644 tests/Doctrine/Performance/Mock/NonProxyLoadingEntityManager.php create mode 100644 tests/Doctrine/Performance/Mock/NonProxyLoadingUnitOfWork.php diff --git a/tests/Doctrine/Performance/Mock/NonLoadingPersister.php b/tests/Doctrine/Performance/Mock/NonLoadingPersister.php new file mode 100644 index 00000000000..35881c5a94b --- /dev/null +++ b/tests/Doctrine/Performance/Mock/NonLoadingPersister.php @@ -0,0 +1,31 @@ +realEntityManager = $realEntityManager; + } + + /** + * {@inheritDoc} + */ + public function getProxyFactory() + { + $config = $this->realEntityManager->getConfiguration(); + + return new ProxyFactory( + $this, + $config->getProxyDir(), + $config->getProxyNamespace(), + $config->getAutoGenerateProxyClasses() + ); + } + + /** + * {@inheritDoc} + */ + public function getMetadataFactory() + { + return $this->realEntityManager->getMetadataFactory(); + } + + /** + * {@inheritDoc} + */ + public function getClassMetadata($className) + { + return $this->realEntityManager->getClassMetadata($className); + } + + /** + * {@inheritDoc} + */ + public function getUnitOfWork() + { + return new NonProxyLoadingUnitOfWork(); + } + + /** + * {@inheritDoc} + */ + public function getCache() + { + return $this->realEntityManager->getCache(); + } + + /** + * {@inheritDoc} + */ + public function getConnection() + { + return $this->realEntityManager->getConnection(); + } + + /** + * {@inheritDoc} + */ + public function getExpressionBuilder() + { + return $this->realEntityManager->getExpressionBuilder(); + } + + /** + * {@inheritDoc} + */ + public function beginTransaction() + { + $this->realEntityManager->beginTransaction(); + } + + /** + * {@inheritDoc} + */ + public function transactional($func) + { + return $this->realEntityManager->transactional($func); + } + + /** + * {@inheritDoc} + */ + public function commit() + { + $this->realEntityManager->commit(); + } + + /** + * {@inheritDoc} + */ + public function rollback() + { + $this->realEntityManager->rollback(); + } + + /** + * {@inheritDoc} + */ + public function createQuery($dql = '') + { + return $this->realEntityManager->createQuery($dql); + } + + /** + * {@inheritDoc} + */ + public function createNamedQuery($name) + { + return $this->realEntityManager->createNamedQuery($name); + } + + /** + * {@inheritDoc} + */ + public function createNativeQuery($sql, ResultSetMapping $rsm) + { + return $this->realEntityManager->createNativeQuery($sql, $rsm); + } + + /** + * {@inheritDoc} + */ + public function createNamedNativeQuery($name) + { + return $this->realEntityManager->createNamedNativeQuery($name); + } + + /** + * {@inheritDoc} + */ + public function createQueryBuilder() + { + return $this->realEntityManager->createQueryBuilder(); + } + + /** + * {@inheritDoc} + */ + public function getReference($entityName, $id) + { + return $this->realEntityManager->getReference($entityName, $id); + } + + /** + * {@inheritDoc} + */ + public function getPartialReference($entityName, $identifier) + { + return $this->realEntityManager->getPartialReference($entityName, $identifier); + } + + /** + * {@inheritDoc} + */ + public function close() + { + $this->realEntityManager->close(); + } + + /** + * {@inheritDoc} + */ + public function copy($entity, $deep = false) + { + return $this->realEntityManager->copy($entity, $deep); + } + + /** + * {@inheritDoc} + */ + public function lock($entity, $lockMode, $lockVersion = null) + { + $this->realEntityManager->lock($entity, $lockMode, $lockVersion); + } + + /** + * {@inheritDoc} + */ + public function getEventManager() + { + return $this->realEntityManager->getEventManager(); + } + + /** + * {@inheritDoc} + */ + public function getConfiguration() + { + return $this->realEntityManager->getConfiguration(); + } + + /** + * {@inheritDoc} + */ + public function isOpen() + { + return $this->realEntityManager->isOpen(); + } + + /** + * {@inheritDoc} + */ + public function getHydrator($hydrationMode) + { + return $this->realEntityManager->getHydrator($hydrationMode); + } + + /** + * {@inheritDoc} + */ + public function newHydrator($hydrationMode) + { + return $this->realEntityManager->newHydrator($hydrationMode); + } + + /** + * {@inheritDoc} + */ + public function getFilters() + { + return $this->realEntityManager->getFilters(); + } + + /** + * {@inheritDoc} + */ + public function isFiltersStateClean() + { + return $this->realEntityManager->isFiltersStateClean(); + } + + /** + * {@inheritDoc} + */ + public function hasFilters() + { + return $this->realEntityManager->hasFilters(); + } + + /** + * {@inheritDoc} + */ + public function find($className, $id) + { + return $this->realEntityManager->find($className, $id); + } + + /** + * {@inheritDoc} + */ + public function persist($object) + { + $this->realEntityManager->persist($object); + } + + /** + * {@inheritDoc} + */ + public function remove($object) + { + $this->realEntityManager->remove($object); + } + + /** + * {@inheritDoc} + */ + public function merge($object) + { + return $this->realEntityManager->merge($object); + } + + /** + * {@inheritDoc} + */ + public function clear($objectName = null) + { + $this->realEntityManager->clear($objectName); + } + + /** + * {@inheritDoc} + */ + public function detach($object) + { + $this->realEntityManager->detach($object); + } + + /** + * {@inheritDoc} + */ + public function refresh($object) + { + $this->realEntityManager->refresh($object); + } + + /** + * {@inheritDoc} + */ + public function flush() + { + $this->realEntityManager->flush(); + } + + /** + * {@inheritDoc} + */ + public function getRepository($className) + { + return $this->realEntityManager->getRepository($className); + } + + /** + * {@inheritDoc} + */ + public function initializeObject($obj) + { + $this->realEntityManager->initializeObject($obj); + } + + /** + * {@inheritDoc} + */ + public function contains($object) + { + return $this->realEntityManager->contains($object); + } +} \ No newline at end of file diff --git a/tests/Doctrine/Performance/Mock/NonProxyLoadingUnitOfWork.php b/tests/Doctrine/Performance/Mock/NonProxyLoadingUnitOfWork.php new file mode 100644 index 00000000000..dd9139ae778 --- /dev/null +++ b/tests/Doctrine/Performance/Mock/NonProxyLoadingUnitOfWork.php @@ -0,0 +1,31 @@ +entityPersister = new NonLoadingPersister(); + } + + /** + * {@inheritDoc} + */ + public function getEntityPersister($entityName) + { + return $this->entityPersister; + } +} From cfa9d787fedd0e76fb17c568dff8d251ac578ba6 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 23:02:58 +0200 Subject: [PATCH 435/877] Removing old `ProxyPerformanceTest` --- .../ORM/Performance/ProxyPerformanceTest.php | 155 ------------------ 1 file changed, 155 deletions(-) delete mode 100644 tests/Doctrine/Tests/ORM/Performance/ProxyPerformanceTest.php diff --git a/tests/Doctrine/Tests/ORM/Performance/ProxyPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/ProxyPerformanceTest.php deleted file mode 100644 index d73964dcc4a..00000000000 --- a/tests/Doctrine/Tests/ORM/Performance/ProxyPerformanceTest.php +++ /dev/null @@ -1,155 +0,0 @@ - - * @group performance - */ -class ProxyPerformanceTest extends OrmPerformanceTestCase -{ - /** - * @return array - */ - public function entitiesProvider() - { - return [ - [CmsEmployee::class], - [CmsUser::class], - ]; - } - - /** - * @dataProvider entitiesProvider - */ - public function testProxyInstantiationPerformance($entityName) - { - $proxyFactory = $this->_getEntityManager()->getProxyFactory(); - $this->setMaxRunningTime(5); - $start = microtime(true); - - for ($i = 0; $i < 100000; $i += 1) { - $user = $proxyFactory->getProxy($entityName, ['id' => $i]); - } - - echo __FUNCTION__ . " - " . (microtime(true) - $start) . " seconds with " . $entityName . PHP_EOL; - } - - /** - * @dataProvider entitiesProvider - */ - public function testProxyForcedInitializationPerformance($entityName) - { - $em = new MockEntityManager($this->_getEntityManager()); - $proxyFactory = $em->getProxyFactory(); - /* @var $user \Doctrine\Common\Proxy\Proxy */ - $user = $proxyFactory->getProxy($entityName, ['id' => 1]); - $initializer = $user->__getInitializer(); - - $this->setMaxRunningTime(5); - $start = microtime(true); - - for ($i = 0; $i < 100000; $i += 1) { - $user->__setInitialized(false); - $user->__setInitializer($initializer); - $user->__load(); - $user->__load(); - } - - echo __FUNCTION__ . " - " . (microtime(true) - $start) . " seconds with " . $entityName . PHP_EOL; - } -} - -/** - * Mock entity manager to fake `getPersister()` - */ -class MockEntityManager extends EntityManager -{ - /** @var EntityManager */ - private $em; - - /** @param EntityManager $em */ - public function __construct(EntityManager $em) - { - $this->em = $em; - } - - /** {@inheritDoc} */ - public function getProxyFactory() - { - $config = $this->em->getConfiguration(); - - return new ProxyFactory( - $this, - $config->getProxyDir(), - $config->getProxyNamespace(), - $config->getAutoGenerateProxyClasses() - ); - } - - /** {@inheritDoc} */ - public function getMetadataFactory() - { - return $this->em->getMetadataFactory(); - } - - /** {@inheritDoc} */ - public function getClassMetadata($className) - { - return $this->em->getClassMetadata($className); - } - - /** {@inheritDoc} */ - public function getUnitOfWork() - { - return new MockUnitOfWork(); - } -} - -/** - * Mock UnitOfWork manager to fake `getPersister()` - */ -class MockUnitOfWork extends UnitOfWork -{ - /** @var PersisterMock */ - private $entityPersister; - - /** */ - public function __construct() - { - $this->entityPersister = new PersisterMock(); - } - - /** {@inheritDoc} */ - public function getEntityPersister($entityName) - { - return $this->entityPersister; - } -} - -/** - * Mock persister (we don't want PHPUnit comparator API to play a role in here) - */ -class PersisterMock extends BasicEntityPersister -{ - /** */ - public function __construct() - { - } - - /** {@inheritDoc} */ - public function load(array $criteria, $entity = null, $assoc = null, array $hints = [], $lockMode = 0, $limit = null, array $orderBy = null) - { - return $entity; - } -} From e07c90df4488b7b44494695e46c3505f5cf21266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 23 Jul 2017 10:11:43 +0200 Subject: [PATCH 436/877] Add PHPBench to Travis-CI matrix Also separating the execution of the tests from other tools. --- .travis.yml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 57b2cb1f680..20c2aa3af32 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,11 +22,13 @@ before_script: - if [[ $PHPSTAN = 1 ]]; then composer require --dev --prefer-stable phpstan/phpstan:^0.7 symfony/console:^3.0; fi - if [ "$MYSQL_VERSION" == "5.7" ]; then bash ./tests/travis/install-mysql-5.7.sh; fi; - if [[ $DB == "mysql" || $DB == "mariadb" ]]; then mysql -e "CREATE SCHEMA doctrine_tests; GRANT ALL PRIVILEGES ON doctrine_tests.* to travis@'%'"; fi; + - if [[ $PHPBENCH = 1 ]]; then wget https://phpbench.github.io/phpbench/phpbench.phar https://phpbench.github.io/phpbench/phpbench.phar.pubkey; fi script: - if [[ $PHPSTAN = 1 ]]; then vendor/bin/phpstan analyse -l 1 -c phpstan.neon lib; fi - - ENABLE_SECOND_LEVEL_CACHE=0 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml $PHPUNIT_FLAGS - - ENABLE_SECOND_LEVEL_CACHE=1 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml --exclude-group performance,non-cacheable,locking_functional + - if [[ $PHPBENCH = 1 ]]; then php phpbench.phar run -l dots --report=default; fi + - if [[ $DB != "none" ]]; then ENABLE_SECOND_LEVEL_CACHE=0 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml $PHPUNIT_FLAGS; fi + - if [[ $DB != "none" ]]; then ENABLE_SECOND_LEVEL_CACHE=1 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml --exclude-group performance,non-cacheable,locking_functional; fi after_script: - if [[ "$PHPUNIT_FLAGS" != "" ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi @@ -39,14 +41,15 @@ matrix: env: DB=mariadb addons: mariadb: 10.1 + - php: 7.1 env: - DB=sqlite - DEPENDENCIES='low' + - php: 7.1 env: - DB=pgsql - - PHPSTAN=1 - php: 7.1 env: DB=mysql MYSQL_VERSION=5.7 @@ -55,6 +58,15 @@ matrix: env: DB=mysql MYSQL_VERSION=5.7 sudo: required + - php: 7.1 + env: + - DB=none + - PHPSTAN=1 + - php: 7.1 + env: + - DB=none + - PHPBENCH=1 + allow_failures: - php: nightly From 03d33ec90091a13ee2b27da4fec14ec0530e028b Mon Sep 17 00:00:00 2001 From: Maxime Veber Date: Mon, 24 Jul 2017 14:23:16 +0200 Subject: [PATCH 437/877] Add string type as possible parameter for between People may want to enter a date, or simply the parameter name. Linter may report an error while it's a good usage. --- lib/Doctrine/ORM/Query/Expr.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Expr.php b/lib/Doctrine/ORM/Query/Expr.php index eada610580d..120d457c7b6 100644 --- a/lib/Doctrine/ORM/Query/Expr.php +++ b/lib/Doctrine/ORM/Query/Expr.php @@ -625,9 +625,9 @@ private function _quoteLiteral($literal) /** * Creates an instance of BETWEEN() function, with the given argument. * - * @param mixed $val Valued to be inspected by range values. - * @param integer $x Starting range value to be used in BETWEEN() function. - * @param integer $y End point value to be used in BETWEEN() function. + * @param mixed $val Valued to be inspected by range values. + * @param integer|string $x Starting range value to be used in BETWEEN() function. + * @param integer|string $y End point value to be used in BETWEEN() function. * * @return Expr\Func A BETWEEN expression. */ From dbb0cdea51b110ba7cc616f7059b08d233584b0a Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Tue, 25 Jul 2017 02:45:50 +0200 Subject: [PATCH 438/877] Travis enhancements: Use Build Stages, added PHP 7.2 --- .travis.yml | 93 +++++++++++++++++-------------- tests/travis/install-mysql-5.7.sh | 0 2 files changed, 52 insertions(+), 41 deletions(-) mode change 100644 => 100755 tests/travis/install-mysql-5.7.sh diff --git a/.travis.yml b/.travis.yml index 20c2aa3af32..e55ea503c5e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,68 +4,79 @@ language: php php: - 7.1 + - 7.2 - nightly env: + - DB=sqlite - DB=mysql - DB=pgsql - - DB=sqlite -before_script: - - if [[ $TRAVIS_PHP_VERSION = '7.1' && $DB = 'sqlite' && "$DEPENDENCIES" != "low" ]]; then PHPUNIT_FLAGS="--coverage-clover ./build/logs/clover.xml"; else PHPUNIT_FLAGS=""; fi - - if [[ "$PHPUNIT_FLAGS" == "" ]]; then phpenv config-rm xdebug.ini || echo "xdebug not available"; fi - - if [[ $PHPSTAN = 1 ]]; then echo "extension=redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi +before_install: + - mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{,.disabled} || echo "xdebug not available" - composer self-update - - composer install --prefer-source - - if [ "$DEPENDENCIES" != "low" ]; then composer update; fi; - - if [ "$DEPENDENCIES" == "low" ]; then composer update --prefer-lowest; fi; - - if [[ $PHPSTAN = 1 ]]; then composer require --dev --prefer-stable phpstan/phpstan:^0.7 symfony/console:^3.0; fi - - if [ "$MYSQL_VERSION" == "5.7" ]; then bash ./tests/travis/install-mysql-5.7.sh; fi; - - if [[ $DB == "mysql" || $DB == "mariadb" ]]; then mysql -e "CREATE SCHEMA doctrine_tests; GRANT ALL PRIVILEGES ON doctrine_tests.* to travis@'%'"; fi; - - if [[ $PHPBENCH = 1 ]]; then wget https://phpbench.github.io/phpbench/phpbench.phar https://phpbench.github.io/phpbench/phpbench.phar.pubkey; fi -script: - - if [[ $PHPSTAN = 1 ]]; then vendor/bin/phpstan analyse -l 1 -c phpstan.neon lib; fi - - if [[ $PHPBENCH = 1 ]]; then php phpbench.phar run -l dots --report=default; fi - - if [[ $DB != "none" ]]; then ENABLE_SECOND_LEVEL_CACHE=0 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml $PHPUNIT_FLAGS; fi - - if [[ $DB != "none" ]]; then ENABLE_SECOND_LEVEL_CACHE=1 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml --exclude-group performance,non-cacheable,locking_functional; fi +install: travis_retry composer update --prefer-dist -after_script: - - if [[ "$PHPUNIT_FLAGS" != "" ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi - - if [[ "$PHPUNIT_FLAGS" != "" ]]; then php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml; fi +script: + - if [[ "$DB" == "mysql" || "$DB" == "mariadb" ]]; then mysql -e "CREATE SCHEMA doctrine_tests; GRANT ALL PRIVILEGES ON doctrine_tests.* to travis@'%'"; fi + - ENABLE_SECOND_LEVEL_CACHE=0 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml + - ENABLE_SECOND_LEVEL_CACHE=1 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml --exclude-group performance,non-cacheable,locking_functional -matrix: - fast_finish: true +jobs: include: - - php: 7.1 + - stage: Test env: DB=mariadb addons: mariadb: 10.1 - - php: 7.1 - env: - - DB=sqlite - - DEPENDENCIES='low' - - - php: 7.1 - env: - - DB=pgsql + - stage: Test + env: DB=mysql MYSQL_VERSION=5.7 + php: 7.1 + before_script: + - ./tests/travis/install-mysql-$MYSQL_VERSION.sh + sudo: required - - php: 7.1 + - stage: Test env: DB=mysql MYSQL_VERSION=5.7 + php: 7.2 + before_script: + - ./tests/travis/install-mysql-$MYSQL_VERSION.sh sudo: required - - php: nightly + + - stage: Test env: DB=mysql MYSQL_VERSION=5.7 + php: nightly + before_script: + - ./tests/travis/install-mysql-$MYSQL_VERSION.sh sudo: required - - php: 7.1 - env: - - DB=none - - PHPSTAN=1 - - php: 7.1 - env: - - DB=none - - PHPBENCH=1 + - stage: Test + env: DB=sqlite DEPENDENCIES=low + install: travis_retry composer update --prefer-dist --prefer-lowest + + - stage: Lint + env: DB=none + before_script: + - echo "extension=redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini + - travis_retry composer require --dev --prefer-dist --prefer-stable phpstan/phpstan:^0.7 symfony/console:^3.0 + script: vendor/bin/phpstan analyse -l 1 -c phpstan.neon lib + + - stage: Coverage + env: DB=sqlite + before_script: + - mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{.disabled,} + - if [[ ! $(php -m | grep -si xdebug) ]]; then echo "xdebug required for coverage"; exit 1; fi + script: + - ENABLE_SECOND_LEVEL_CACHE=0 ./vendor/bin/phpunit -v -c tests/travis/$DB.travis.xml --coverage-clover ./build/logs/clover.xml + after_script: + - wget https://scrutinizer-ci.com/ocular.phar + - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml + + - stage: Benchmark + env: DB=none + before_script: wget https://phpbench.github.io/phpbench/phpbench.phar https://phpbench.github.io/phpbench/phpbench.phar.pubkey + script: php phpbench.phar run -l dots --report=default allow_failures: - php: nightly diff --git a/tests/travis/install-mysql-5.7.sh b/tests/travis/install-mysql-5.7.sh old mode 100644 new mode 100755 From 5d8dc1757fc70696e1ce8d3aa72b8223f51c2d8f Mon Sep 17 00:00:00 2001 From: reypm Date: Sun, 30 Jul 2017 12:51:39 -0400 Subject: [PATCH 439/877] Updating docs to support for APCu as a cache driver --- docs/en/reference/advanced-configuration.rst | 2 ++ docs/en/reference/caching.rst | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/docs/en/reference/advanced-configuration.rst b/docs/en/reference/advanced-configuration.rst index abb72636cfb..00f8f89696b 100644 --- a/docs/en/reference/advanced-configuration.rst +++ b/docs/en/reference/advanced-configuration.rst @@ -152,6 +152,7 @@ The recommended implementations for production are: - ``Doctrine\Common\Cache\ApcCache`` +- ``Doctrine\Common\Cache\ApcuCache`` - ``Doctrine\Common\Cache\MemcacheCache`` - ``Doctrine\Common\Cache\XcacheCache`` - ``Doctrine\Common\Cache\RedisCache`` @@ -183,6 +184,7 @@ The recommended implementations for production are: - ``Doctrine\Common\Cache\ApcCache`` +- ``Doctrine\Common\Cache\ApcuCache`` - ``Doctrine\Common\Cache\MemcacheCache`` - ``Doctrine\Common\Cache\XcacheCache`` - ``Doctrine\Common\Cache\RedisCache`` diff --git a/docs/en/reference/caching.rst b/docs/en/reference/caching.rst index 512254ef6bf..0839ff614bd 100644 --- a/docs/en/reference/caching.rst +++ b/docs/en/reference/caching.rst @@ -63,6 +63,24 @@ by itself. $cacheDriver = new \Doctrine\Common\Cache\ApcCache(); $cacheDriver->save('cache_id', 'my_data'); +APCu +~~~ + +In order to use the APCu cache driver you must have it compiled and +enabled in your php.ini. You can read about APCu +`in the PHP Documentation `_. It will give +you a little background information about what it is and how you +can use it as well as how to install it. + +Below is a simple example of how you could use the APCu cache driver +by itself. + +.. code-block:: php + + save('cache_id', 'my_data'); + Memcache ~~~~~~~~ From 0c30bab776793b750be82cbd0e688af5bcaed7f8 Mon Sep 17 00:00:00 2001 From: reypm Date: Sun, 30 Jul 2017 14:40:19 -0400 Subject: [PATCH 440/877] Adding extra tilde and updating APC references to APCu (APC is deprecated as per http://php.net/manual/en/intro.apc.php) --- docs/en/reference/caching.rst | 12 ++++++------ docs/en/reference/metadata-drivers.rst | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/en/reference/caching.rst b/docs/en/reference/caching.rst index 0839ff614bd..f2937c78004 100644 --- a/docs/en/reference/caching.rst +++ b/docs/en/reference/caching.rst @@ -60,11 +60,11 @@ by itself. .. code-block:: php save('cache_id', 'my_data'); APCu -~~~ +~~~~ In order to use the APCu cache driver you must have it compiled and enabled in your php.ini. You can read about APCu @@ -305,7 +305,7 @@ use on your ORM configuration. setQueryCacheImpl(new \Doctrine\Common\Cache\ApcCache()); + $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ApcuCache()); Result Cache ~~~~~~~~~~~~ @@ -318,7 +318,7 @@ cache implementation. .. code-block:: php setResultCacheImpl(new \Doctrine\Common\Cache\ApcCache()); + $config->setResultCacheImpl(new \Doctrine\Common\Cache\ApcuCache()); Now when you're executing DQL queries you can configure them to use the result cache. @@ -335,7 +335,7 @@ result cache driver. .. code-block:: php setResultCacheDriver(new \Doctrine\Common\Cache\ApcCache()); + $query->setResultCacheDriver(new \Doctrine\Common\Cache\ApcuCache()); .. note:: @@ -387,7 +387,7 @@ first. .. code-block:: php setMetadataCacheImpl(new \Doctrine\Common\Cache\ApcCache()); + $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ApcuCache()); Now the metadata information will only be parsed once and stored in the cache driver. diff --git a/docs/en/reference/metadata-drivers.rst b/docs/en/reference/metadata-drivers.rst index 6b9cb31e42c..5162dee2d3f 100644 --- a/docs/en/reference/metadata-drivers.rst +++ b/docs/en/reference/metadata-drivers.rst @@ -35,7 +35,7 @@ an entity. .. code-block:: php getConfiguration()->setMetadataCacheImpl(new ApcCache()); + $em->getConfiguration()->setMetadataCacheImpl(new ApcuCache()); If you want to use one of the included core metadata drivers you From 40ee7af9c8e44541c0a1dc1df9065cfbcdf81e44 Mon Sep 17 00:00:00 2001 From: reypm Date: Sun, 30 Jul 2017 15:31:42 -0400 Subject: [PATCH 441/877] Fixing issue in APC driver --- docs/en/reference/caching.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/caching.rst b/docs/en/reference/caching.rst index f2937c78004..4423fb130f7 100644 --- a/docs/en/reference/caching.rst +++ b/docs/en/reference/caching.rst @@ -60,7 +60,7 @@ by itself. .. code-block:: php save('cache_id', 'my_data'); APCu From a54a2588660d2914492771179fa7c393e82b9409 Mon Sep 17 00:00:00 2001 From: mike Date: Wed, 2 Aug 2017 22:58:05 +0200 Subject: [PATCH 442/877] More refinement of the xml dtd --- doctrine-mapping.xsd | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doctrine-mapping.xsd b/doctrine-mapping.xsd index 9524c79d1a3..3d6e3457f94 100644 --- a/doctrine-mapping.xsd +++ b/doctrine-mapping.xsd @@ -101,7 +101,7 @@ - + @@ -117,7 +117,7 @@ - + @@ -139,7 +139,7 @@ - + @@ -193,7 +193,7 @@ - + @@ -309,7 +309,7 @@ - + @@ -368,7 +368,7 @@ - + From 30088fe529d01156287d54c294d0fd82e811dcd2 Mon Sep 17 00:00:00 2001 From: Martin Georgiev Date: Thu, 3 Aug 2017 11:52:06 +0100 Subject: [PATCH 443/877] Fix double spacing in exception's message --- lib/Doctrine/ORM/ORMInvalidArgumentException.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/ORMInvalidArgumentException.php b/lib/Doctrine/ORM/ORMInvalidArgumentException.php index accf1cc1517..6aa270c782f 100644 --- a/lib/Doctrine/ORM/ORMInvalidArgumentException.php +++ b/lib/Doctrine/ORM/ORMInvalidArgumentException.php @@ -93,7 +93,7 @@ static public function newEntityFoundThroughRelationship(array $assoc, $entry) . $assoc['sourceEntity'] . "#" . $assoc['fieldName'] . "' that was not" . " configured to cascade persist operations for entity: " . self::objToStr($entry) . "." . " To solve this issue: Either explicitly call EntityManager#persist()" - . " on this unknown entity or configure cascade persist " + . " on this unknown entity or configure cascade persist" . " this association in the mapping for example @ManyToOne(..,cascade={\"persist\"})." . (method_exists($entry, '__toString') ? "": " If you cannot find out which entity causes the problem" . " implement '" . $assoc['targetEntity'] . "#__toString()' to get a clue.")); From 8952176c73c74500a90cce7400bec60869c8913f Mon Sep 17 00:00:00 2001 From: Alfredo Costa Date: Tue, 1 Dec 2015 11:43:55 -0200 Subject: [PATCH 444/877] Add message to NonUniqueResultException --- lib/Doctrine/ORM/NonUniqueResultException.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/Doctrine/ORM/NonUniqueResultException.php b/lib/Doctrine/ORM/NonUniqueResultException.php index 55b71300058..78a58dd4990 100644 --- a/lib/Doctrine/ORM/NonUniqueResultException.php +++ b/lib/Doctrine/ORM/NonUniqueResultException.php @@ -27,4 +27,10 @@ */ class NonUniqueResultException extends UnexpectedResultException { + const DEFAULT_MESSAGE = 'More than one result was found for query although one row or none was expected.'; + + public function __construct(string $message = null) + { + parent::__construct($message ?? self::DEFAULT_MESSAGE); + } } From c2167664fc782fcbb1a47c7f38ba01c5daba3afc Mon Sep 17 00:00:00 2001 From: Jean Carlo Machado Date: Sun, 21 Feb 2016 13:01:19 -0300 Subject: [PATCH 445/877] add test of NonUniqueResultException message presence --- .../ORM/Functional/Ticket/DDC4024Test.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC4024Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC4024Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC4024Test.php new file mode 100644 index 00000000000..fa1208292bc --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC4024Test.php @@ -0,0 +1,25 @@ +getMessage()); + } + + public function testADefaultMessageShouldBeUsedWhenNothingWasProvided() : void + { + $exception = new NonUniqueResultException(); + + self::assertSame(NonUniqueResultException::DEFAULT_MESSAGE, $exception->getMessage()); + } +} From 27300bf4afadf7323d2b7e2887a2e36f1127afd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 6 Aug 2017 12:51:16 +0200 Subject: [PATCH 446/877] Make PHPUnit strict about risky tests --- phpunit.xml.dist | 16 ++++++---------- tests/travis/mariadb.travis.xml | 8 +++++++- tests/travis/mysql.travis.xml | 8 +++++++- tests/travis/pgsql.travis.xml | 8 +++++++- tests/travis/sqlite.travis.xml | 9 +++++++-- 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e6fc543159c..c6bd8988243 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -11,15 +11,11 @@ tests/ folder: phpunit -c ... Example: phpunit -c mysqlconf.xml AllTests --> - @@ -46,7 +42,7 @@ --> - + @@ -56,4 +52,4 @@ - \ No newline at end of file + diff --git a/tests/travis/mariadb.travis.xml b/tests/travis/mariadb.travis.xml index bac3fa48060..16024c4c6c8 100644 --- a/tests/travis/mariadb.travis.xml +++ b/tests/travis/mariadb.travis.xml @@ -1,5 +1,11 @@ - + diff --git a/tests/travis/mysql.travis.xml b/tests/travis/mysql.travis.xml index bac3fa48060..16024c4c6c8 100644 --- a/tests/travis/mysql.travis.xml +++ b/tests/travis/mysql.travis.xml @@ -1,5 +1,11 @@ - + diff --git a/tests/travis/pgsql.travis.xml b/tests/travis/pgsql.travis.xml index d1a0a49f274..6ad430af329 100644 --- a/tests/travis/pgsql.travis.xml +++ b/tests/travis/pgsql.travis.xml @@ -1,5 +1,11 @@ - + diff --git a/tests/travis/sqlite.travis.xml b/tests/travis/sqlite.travis.xml index f9b3ef1f322..7894dfd2e0b 100644 --- a/tests/travis/sqlite.travis.xml +++ b/tests/travis/sqlite.travis.xml @@ -1,6 +1,11 @@ - - + ./../Doctrine/Tests/ORM From b960170fe1f4caef762cf2837be3340ae472c120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 6 Aug 2017 12:51:37 +0200 Subject: [PATCH 447/877] Move test to the right place and add assertions That test was removed from "performance" group but we forgot to move it to the correct namespace. It was also not doing any assertion, which is quite bad. More info: - https://github.com/doctrine/doctrine2/issues/3333 --- .../Ticket}/DDC2602Test.php | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) rename tests/Doctrine/Tests/ORM/{Performance => Functional/Ticket}/DDC2602Test.php (83%) diff --git a/tests/Doctrine/Tests/ORM/Performance/DDC2602Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2602Test.php similarity index 83% rename from tests/Doctrine/Tests/ORM/Performance/DDC2602Test.php rename to tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2602Test.php index de8bedfc7d1..23b9f662f56 100644 --- a/tests/Doctrine/Tests/ORM/Performance/DDC2602Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2602Test.php @@ -1,62 +1,61 @@ _schemaTool->createSchema( [ - $this->_em->getClassMetadata(DDC2602User::class), - $this->_em->getClassMetadata(DDC2602Biography::class), - $this->_em->getClassMetadata(DDC2602BiographyField::class), - $this->_em->getClassMetadata(DDC2602BiographyFieldChoice::class), + $this->_em->getClassMetadata(DDC2602User::class), + $this->_em->getClassMetadata(DDC2602Biography::class), + $this->_em->getClassMetadata(DDC2602BiographyField::class), + $this->_em->getClassMetadata(DDC2602BiographyFieldChoice::class), ] ); $this->loadFixture(); } - protected function tearDown() + protected function tearDown() : void { parent::tearDown(); $this->_schemaTool->dropSchema( [ - $this->_em->getClassMetadata(DDC2602User::class), - $this->_em->getClassMetadata(DDC2602Biography::class), - $this->_em->getClassMetadata(DDC2602BiographyField::class), - $this->_em->getClassMetadata(DDC2602BiographyFieldChoice::class), + $this->_em->getClassMetadata(DDC2602User::class), + $this->_em->getClassMetadata(DDC2602Biography::class), + $this->_em->getClassMetadata(DDC2602BiographyField::class), + $this->_em->getClassMetadata(DDC2602BiographyFieldChoice::class), ] ); } - public function testIssue() + public function testPostLoadListenerShouldBeAbleToRunQueries() : void { $eventManager = $this->_em->getEventManager(); $eventManager->addEventListener([Events::postLoad], new DDC2602PostLoadListener()); - // Set maximum seconds this can run - $this->setMaxRunningTime(1); + $result = $this->_em->createQuery('SELECT u, b FROM Doctrine\Tests\ORM\Functional\Ticket\DDC2602User u JOIN u.biography b') + ->getResult(); - $this - ->_em - ->createQuery('SELECT u, b FROM Doctrine\Tests\ORM\Performance\DDC2602User u JOIN u.biography b') - ->getResult(); + self::assertCount(2, $result); + self::assertCount(2, $result[0]->biography->fieldList); + self::assertCount(1, $result[1]->biography->fieldList); } - private function loadFixture() + private function loadFixture() : void { $user1 = new DDC2602User(); $user2 = new DDC2602User(); @@ -127,7 +126,7 @@ private function loadFixture() class DDC2602PostLoadListener { - public function postLoad(LifecycleEventArgs $event) + public function postLoad(LifecycleEventArgs $event) : void { $entity = $event->getEntity(); @@ -138,7 +137,7 @@ public function postLoad(LifecycleEventArgs $event) $entityManager = $event->getEntityManager(); $query = $entityManager->createQuery(' SELECT f, fc - FROM Doctrine\Tests\ORM\Performance\DDC2602BiographyField f INDEX BY f.id + FROM Doctrine\Tests\ORM\Functional\Ticket\DDC2602BiographyField f INDEX BY f.id JOIN f.choiceList fc INDEX BY fc.id '); From 874d60d8c7bd236b736ce5a15999ce2b81833a35 Mon Sep 17 00:00:00 2001 From: Uladzimir Struts Date: Fri, 11 Aug 2017 13:46:21 +0300 Subject: [PATCH 448/877] It added the unit test #6613 --- tests/Doctrine/Tests/Models/DDC6613/Phone.php | 27 ++++++++ tests/Doctrine/Tests/Models/DDC6613/User.php | 43 ++++++++++++ .../ORM/Functional/Ticket/DDC6613Test.php | 67 +++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 tests/Doctrine/Tests/Models/DDC6613/Phone.php create mode 100644 tests/Doctrine/Tests/Models/DDC6613/User.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php diff --git a/tests/Doctrine/Tests/Models/DDC6613/Phone.php b/tests/Doctrine/Tests/Models/DDC6613/Phone.php new file mode 100644 index 00000000000..32f878eeecb --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC6613/Phone.php @@ -0,0 +1,27 @@ + + * Date: 11.08.2017 + * Time: 13:12 + */ + +namespace Doctrine\Tests\Models\DDC6613; + + +/** + * @Entity(readOnly=true) + * @Table(name="ddc6613_phone") + */ + +class Phone +{ + + /** + * @Id + * @GeneratedValue + * @Column(type="integer") + */ + public $id; + +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/DDC6613/User.php b/tests/Doctrine/Tests/Models/DDC6613/User.php new file mode 100644 index 00000000000..ee4e7260b0b --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC6613/User.php @@ -0,0 +1,43 @@ + + * Date: 11.08.2017 + * Time: 13:12 + */ + +namespace Doctrine\Tests\Models\DDC6613; + + +use Doctrine\Common\Collections\ArrayCollection; + +/** + * @Entity() + * @Table(name="ddc6613_user") + */ +class User +{ + + /** + * @Id + * @GeneratedValue + * @Column(type="integer") + */ + public $id; + + + /** + * @ManyToMany(targetEntity="Phone", fetch="LAZY", cascade={"remove", "detach"}) + */ + public $phones; + + /** + * User constructor. + */ + public function __construct() + { + $this->phones = new ArrayCollection(); + } + + +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php new file mode 100644 index 00000000000..11b8f511102 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php @@ -0,0 +1,67 @@ + + * Date: 11.08.2017 + * Time: 12:28 + */ + +namespace Doctrine\Tests\ORM\Functional\Ticket; + + +use Doctrine\DBAL\Schema\SchemaException; +use Doctrine\ORM\Mapping\Column; +use Doctrine\ORM\Mapping\Embeddable; +use Doctrine\ORM\Mapping\Entity; +use Doctrine\ORM\Mapping\Id; +use Doctrine\ORM\Mapping\GeneratedValue; +use Doctrine\ORM\Mapping\ManyToOne; +use Doctrine\ORM\Proxy\Proxy; +use Doctrine\Tests\Models\DDC6613\Phone; +use Doctrine\Tests\Models\DDC6613\User; + + +class DDC6613Test extends \Doctrine\Tests\OrmFunctionalTestCase +{ + + public function setUp() + { + parent::setUp(); + + try { + $this->setUpEntitySchema( + [ + Phone::class, + User::class + ] + ); + } catch (SchemaException $e) { + } + } + + public function testFail() + { + $user = new User(); + $user->id = 1; + $this->_em->persist($user); + $this->_em->flush(); + + $this->_em->clear(); + + /** @var User $user */ + $user = $this->_em->find(User::class, 1); + $phone1 = new Phone(); + $phone1->id = 1; + $user->phones->add($phone1); + $this->_em->persist($phone1); + $this->_em->flush(); + + $phone2 = new Phone(); + $phone2->id = 2; + $user->phones->add($phone2); + $this->_em->persist($phone2); + $user->phones->toArray(); + $this->_em->flush(); + } + +} \ No newline at end of file From 594e60d3f7610016d3fa0b9de5d71de3308293f2 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 14:19:01 +0200 Subject: [PATCH 449/877] #6613 #6614 simplifying entity definition - using auto-assigned string identifiers to reduce moving parts --- tests/Doctrine/Tests/Models/DDC6613/Phone.php | 7 +++++-- tests/Doctrine/Tests/Models/DDC6613/User.php | 7 ++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/Doctrine/Tests/Models/DDC6613/Phone.php b/tests/Doctrine/Tests/Models/DDC6613/Phone.php index 32f878eeecb..9ce0909608f 100644 --- a/tests/Doctrine/Tests/Models/DDC6613/Phone.php +++ b/tests/Doctrine/Tests/Models/DDC6613/Phone.php @@ -10,7 +10,6 @@ /** - * @Entity(readOnly=true) * @Table(name="ddc6613_phone") */ @@ -19,9 +18,13 @@ class Phone /** * @Id - * @GeneratedValue + * @GeneratedValue(strategy="NONE") * @Column(type="integer") */ public $id; + public function __construct() + { + $this->id = uniqid('phone', true); + } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/DDC6613/User.php b/tests/Doctrine/Tests/Models/DDC6613/User.php index ee4e7260b0b..6b233c0a233 100644 --- a/tests/Doctrine/Tests/Models/DDC6613/User.php +++ b/tests/Doctrine/Tests/Models/DDC6613/User.php @@ -20,10 +20,10 @@ class User /** * @Id - * @GeneratedValue - * @Column(type="integer") + * @GeneratedValue(strategy="NONE") + * @Column(type="string") */ - public $id; + private $id; /** @@ -36,6 +36,7 @@ class User */ public function __construct() { + $this->id = uniqid('user', true); $this->phones = new ArrayCollection(); } From 0a1a84163e91836afa51d8e9068bbf0fa2e29f6c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 14:20:07 +0200 Subject: [PATCH 450/877] #6613 #6614 better test specification - removing useless assertions --- tests/Doctrine/Tests/Models/DDC6613/User.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/Doctrine/Tests/Models/DDC6613/User.php b/tests/Doctrine/Tests/Models/DDC6613/User.php index 6b233c0a233..9475bef4b2c 100644 --- a/tests/Doctrine/Tests/Models/DDC6613/User.php +++ b/tests/Doctrine/Tests/Models/DDC6613/User.php @@ -31,9 +31,6 @@ class User */ public $phones; - /** - * User constructor. - */ public function __construct() { $this->id = uniqid('user', true); From 112a402016c0e056aeb99e217a52d63813e2b9c8 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 14:21:56 +0200 Subject: [PATCH 451/877] #6613 #6614 smashing entity definitions into the test --- .../ORM/Functional/Ticket/DDC6613Test.php | 78 ++++++++++++++++--- 1 file changed, 69 insertions(+), 9 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php index 11b8f511102..30e4f5276da 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php @@ -16,6 +16,7 @@ use Doctrine\ORM\Mapping\Id; use Doctrine\ORM\Mapping\GeneratedValue; use Doctrine\ORM\Mapping\ManyToOne; +use Doctrine\ORM\PersistentCollection; use Doctrine\ORM\Proxy\Proxy; use Doctrine\Tests\Models\DDC6613\Phone; use Doctrine\Tests\Models\DDC6613\User; @@ -31,8 +32,8 @@ public function setUp() try { $this->setUpEntitySchema( [ - Phone::class, - User::class + DDC6613Phone::class, + DDC6613User::class ] ); } catch (SchemaException $e) { @@ -41,8 +42,7 @@ public function setUp() public function testFail() { - $user = new User(); - $user->id = 1; + $user = new DDC6613User(); $this->_em->persist($user); $this->_em->flush(); @@ -50,18 +50,78 @@ public function testFail() /** @var User $user */ $user = $this->_em->find(User::class, 1); - $phone1 = new Phone(); - $phone1->id = 1; + $phone1 = new DDC6613Phone(); + $phones = $user->phones; $user->phones->add($phone1); $this->_em->persist($phone1); $this->_em->flush(); - $phone2 = new Phone(); - $phone2->id = 2; + $phone2 = new DDC6613Phone(); $user->phones->add($phone2); $this->_em->persist($phone2); - $user->phones->toArray(); + + /* @var $phones PersistentCollection */ +// $phones = $user->phones; + + self::assertInstanceOf(PersistentCollection::class, $phones); + self::assertFalse($phones->isInitialized()); + + $phones->initialize(); + + self::assertTrue($phones->isInitialized()); + self::assertCount(2, $phones); + $this->_em->flush(); + + self::assertFalse($phones->isDirty()); + self::assertTrue($phones->isInitialized()); + self::assertCount(2, $user->phones); + } + +} + +/** + * @Entity + * @Table(name="ddc6613_user") + */ +class DDC6613User +{ + /** + * @Id + * @GeneratedValue(strategy="NONE") + * @Column(type="string") + */ + private $id; + + /** + * @ManyToMany(targetEntity="Phone", fetch="LAZY", cascade={"remove", "detach"}) + */ + public $phones; + + public function __construct() + { + $this->id = uniqid('user', true); + $this->phones = new ArrayCollection(); } + +} + +/** + * @Table(name="ddc6613_phone") + */ +class DDC6613Phone +{ + + /** + * @Id + * @GeneratedValue(strategy="NONE") + * @Column(type="integer") + */ + public $id; + + public function __construct() + { + $this->id = uniqid('phone', true); + } } \ No newline at end of file From 625f79229031e02c787d2d2e88cae58f53e7e5f7 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 14:22:31 +0200 Subject: [PATCH 452/877] #6613 #6614 removing dedicated DDC6613 model directory --- tests/Doctrine/Tests/Models/DDC6613/Phone.php | 30 -------------- tests/Doctrine/Tests/Models/DDC6613/User.php | 41 ------------------- 2 files changed, 71 deletions(-) delete mode 100644 tests/Doctrine/Tests/Models/DDC6613/Phone.php delete mode 100644 tests/Doctrine/Tests/Models/DDC6613/User.php diff --git a/tests/Doctrine/Tests/Models/DDC6613/Phone.php b/tests/Doctrine/Tests/Models/DDC6613/Phone.php deleted file mode 100644 index 9ce0909608f..00000000000 --- a/tests/Doctrine/Tests/Models/DDC6613/Phone.php +++ /dev/null @@ -1,30 +0,0 @@ - - * Date: 11.08.2017 - * Time: 13:12 - */ - -namespace Doctrine\Tests\Models\DDC6613; - - -/** - * @Table(name="ddc6613_phone") - */ - -class Phone -{ - - /** - * @Id - * @GeneratedValue(strategy="NONE") - * @Column(type="integer") - */ - public $id; - - public function __construct() - { - $this->id = uniqid('phone', true); - } -} \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/DDC6613/User.php b/tests/Doctrine/Tests/Models/DDC6613/User.php deleted file mode 100644 index 9475bef4b2c..00000000000 --- a/tests/Doctrine/Tests/Models/DDC6613/User.php +++ /dev/null @@ -1,41 +0,0 @@ - - * Date: 11.08.2017 - * Time: 13:12 - */ - -namespace Doctrine\Tests\Models\DDC6613; - - -use Doctrine\Common\Collections\ArrayCollection; - -/** - * @Entity() - * @Table(name="ddc6613_user") - */ -class User -{ - - /** - * @Id - * @GeneratedValue(strategy="NONE") - * @Column(type="string") - */ - private $id; - - - /** - * @ManyToMany(targetEntity="Phone", fetch="LAZY", cascade={"remove", "detach"}) - */ - public $phones; - - public function __construct() - { - $this->id = uniqid('user', true); - $this->phones = new ArrayCollection(); - } - - -} \ No newline at end of file From c195064ba49d58cb46ecd5387875350a59e9ca7e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 14:23:21 +0200 Subject: [PATCH 453/877] #6613 #6614 CS - applying `@group` annotation to the test --- .../ORM/Functional/Ticket/DDC6613Test.php | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php index 30e4f5276da..16d21bbd1c3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php @@ -8,23 +8,21 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; - +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\DBAL\Schema\SchemaException; use Doctrine\ORM\Mapping\Column; -use Doctrine\ORM\Mapping\Embeddable; use Doctrine\ORM\Mapping\Entity; -use Doctrine\ORM\Mapping\Id; use Doctrine\ORM\Mapping\GeneratedValue; -use Doctrine\ORM\Mapping\ManyToOne; +use Doctrine\ORM\Mapping\Id; use Doctrine\ORM\PersistentCollection; -use Doctrine\ORM\Proxy\Proxy; -use Doctrine\Tests\Models\DDC6613\Phone; -use Doctrine\Tests\Models\DDC6613\User; +use Doctrine\Tests\OrmFunctionalTestCase; - -class DDC6613Test extends \Doctrine\Tests\OrmFunctionalTestCase +/** + * @group #6613 + * @group #6614 + */ +class DDC6613Test extends OrmFunctionalTestCase { - public function setUp() { parent::setUp(); @@ -33,7 +31,7 @@ public function setUp() $this->setUpEntitySchema( [ DDC6613Phone::class, - DDC6613User::class + DDC6613User::class, ] ); } catch (SchemaException $e) { @@ -49,7 +47,7 @@ public function testFail() $this->_em->clear(); /** @var User $user */ - $user = $this->_em->find(User::class, 1); + $user = $this->_em->find(User::class, 1); $phone1 = new DDC6613Phone(); $phones = $user->phones; $user->phones->add($phone1); @@ -77,7 +75,6 @@ public function testFail() self::assertTrue($phones->isInitialized()); self::assertCount(2, $user->phones); } - } /** @@ -103,8 +100,6 @@ public function __construct() $this->id = uniqid('user', true); $this->phones = new ArrayCollection(); } - - } /** @@ -112,7 +107,6 @@ public function __construct() */ class DDC6613Phone { - /** * @Id * @GeneratedValue(strategy="NONE") From eca1d6b3ead294a40727f8b26ea9572c02214d7c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 14:27:34 +0200 Subject: [PATCH 454/877] #6613 #6614 rewrote test logic to be less magic-constant-dependent --- .../ORM/Functional/Ticket/DDC6613Test.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php index 16d21bbd1c3..5c3e0c0396b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php @@ -10,10 +10,6 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\DBAL\Schema\SchemaException; -use Doctrine\ORM\Mapping\Column; -use Doctrine\ORM\Mapping\Entity; -use Doctrine\ORM\Mapping\GeneratedValue; -use Doctrine\ORM\Mapping\Id; use Doctrine\ORM\PersistentCollection; use Doctrine\Tests\OrmFunctionalTestCase; @@ -40,14 +36,17 @@ public function setUp() public function testFail() { - $user = new DDC6613User(); - $this->_em->persist($user); + $newUser = new DDC6613User(); + $this->_em->persist($newUser); $this->_em->flush(); $this->_em->clear(); - /** @var User $user */ - $user = $this->_em->find(User::class, 1); + /** @var DDC6613User $user */ + $user = $this->_em->find(DDC6613User::class, $newUser->id); + + self::assertInstanceOf(DDC6613User::class, $user); + $phone1 = new DDC6613Phone(); $phones = $user->phones; $user->phones->add($phone1); @@ -88,10 +87,10 @@ class DDC6613User * @GeneratedValue(strategy="NONE") * @Column(type="string") */ - private $id; + public $id; /** - * @ManyToMany(targetEntity="Phone", fetch="LAZY", cascade={"remove", "detach"}) + * @ManyToMany(targetEntity=DDC6613Phone::class, fetch="LAZY", cascade={"remove", "detach"}) */ public $phones; @@ -103,6 +102,7 @@ public function __construct() } /** + * @Entity * @Table(name="ddc6613_phone") */ class DDC6613Phone From a4e547b6915bcfed7fbce54ac7c5398a025f48bf Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 14:34:35 +0200 Subject: [PATCH 455/877] #6613 #6614 remove superfluous mappings --- .../ORM/Functional/Ticket/DDC6613Test.php | 28 ++++--------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php index 5c3e0c0396b..26fe56b0192 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php @@ -76,22 +76,13 @@ public function testFail() } } -/** - * @Entity - * @Table(name="ddc6613_user") - */ +/** @Entity */ class DDC6613User { - /** - * @Id - * @GeneratedValue(strategy="NONE") - * @Column(type="string") - */ + /** @Id @Column(type="string") */ public $id; - /** - * @ManyToMany(targetEntity=DDC6613Phone::class, fetch="LAZY", cascade={"remove", "detach"}) - */ + /** @ManyToMany(targetEntity=DDC6613Phone::class) */ public $phones; public function __construct() @@ -101,18 +92,11 @@ public function __construct() } } -/** - * @Entity - * @Table(name="ddc6613_phone") - */ +/** @Entity */ class DDC6613Phone { - /** - * @Id - * @GeneratedValue(strategy="NONE") - * @Column(type="integer") - */ - public $id; + /** @Id @Column(type="integer") */ + private $id; public function __construct() { From 80f12ed49040eb7991f1956fe3a74682b085b318 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 14:41:32 +0200 Subject: [PATCH 456/877] #6613 #6614 correcting column mapping (was `integer`, should be `string`), segregating phone creation away --- .../ORM/Functional/Ticket/DDC6613Test.php | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php index 26fe56b0192..84f60243d38 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php @@ -9,7 +9,6 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; use Doctrine\Common\Collections\ArrayCollection; -use Doctrine\DBAL\Schema\SchemaException; use Doctrine\ORM\PersistentCollection; use Doctrine\Tests\OrmFunctionalTestCase; @@ -23,46 +22,43 @@ public function setUp() { parent::setUp(); - try { - $this->setUpEntitySchema( - [ - DDC6613Phone::class, - DDC6613User::class, - ] - ); - } catch (SchemaException $e) { - } + $this->setUpEntitySchema([ + DDC6613Phone::class, + DDC6613User::class, + ]); } public function testFail() { $newUser = new DDC6613User(); + $this->_em->persist($newUser); $this->_em->flush(); - $this->_em->clear(); - /** @var DDC6613User $user */ - $user = $this->_em->find(DDC6613User::class, $newUser->id); - - self::assertInstanceOf(DDC6613User::class, $user); - $phone1 = new DDC6613Phone(); - $phones = $user->phones; - $user->phones->add($phone1); + $phone2 = new DDC6613Phone(); + $this->_em->persist($phone1); + $this->_em->persist($phone2); $this->_em->flush(); - $phone2 = new DDC6613Phone(); - $user->phones->add($phone2); - $this->_em->persist($phone2); + /* @var DDC6613User $user */ + $user = $this->_em->find(DDC6613User::class, $newUser->id); + + self::assertInstanceOf(DDC6613User::class, $user); /* @var $phones PersistentCollection */ -// $phones = $user->phones; + $phones = $user->phones; self::assertInstanceOf(PersistentCollection::class, $phones); self::assertFalse($phones->isInitialized()); + $phones->add($phone1); + $this->_em->flush(); + + $phones->add($phone2); + $phones->initialize(); self::assertTrue($phones->isInitialized()); @@ -95,7 +91,7 @@ public function __construct() /** @Entity */ class DDC6613Phone { - /** @Id @Column(type="integer") */ + /** @Id @Column(type="string") */ private $id; public function __construct() From 8c4b5a4b7122b76b1ffaaec68948af307749807d Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 14:44:04 +0200 Subject: [PATCH 457/877] #6613 #6614 removing phone/user specifics, using ORM naming for associations --- .../ORM/Functional/Ticket/DDC6613Test.php | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php index 84f60243d38..2456f1ed97d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php @@ -23,41 +23,41 @@ public function setUp() parent::setUp(); $this->setUpEntitySchema([ - DDC6613Phone::class, - DDC6613User::class, + DDC6613InverseSide::class, + DDC6613OwningSide::class, ]); } public function testFail() { - $newUser = new DDC6613User(); + $owningSide = new DDC6613OwningSide(); - $this->_em->persist($newUser); + $this->_em->persist($owningSide); $this->_em->flush(); $this->_em->clear(); - $phone1 = new DDC6613Phone(); - $phone2 = new DDC6613Phone(); + $item1 = new DDC6613InverseSide(); + $item2 = new DDC6613InverseSide(); - $this->_em->persist($phone1); - $this->_em->persist($phone2); + $this->_em->persist($item1); + $this->_em->persist($item2); $this->_em->flush(); - /* @var DDC6613User $user */ - $user = $this->_em->find(DDC6613User::class, $newUser->id); + /* @var DDC6613OwningSide $foundOwningSide */ + $foundOwningSide = $this->_em->find(DDC6613OwningSide::class, $owningSide->id); - self::assertInstanceOf(DDC6613User::class, $user); + self::assertInstanceOf(DDC6613OwningSide::class, $foundOwningSide); /* @var $phones PersistentCollection */ - $phones = $user->phones; + $phones = $foundOwningSide->phones; self::assertInstanceOf(PersistentCollection::class, $phones); self::assertFalse($phones->isInitialized()); - $phones->add($phone1); + $phones->add($item1); $this->_em->flush(); - $phones->add($phone2); + $phones->add($item2); $phones->initialize(); @@ -68,17 +68,17 @@ public function testFail() self::assertFalse($phones->isDirty()); self::assertTrue($phones->isInitialized()); - self::assertCount(2, $user->phones); + self::assertCount(2, $foundOwningSide->phones); } } /** @Entity */ -class DDC6613User +class DDC6613OwningSide { /** @Id @Column(type="string") */ public $id; - /** @ManyToMany(targetEntity=DDC6613Phone::class) */ + /** @ManyToMany(targetEntity=DDC6613InverseSide::class) */ public $phones; public function __construct() @@ -89,7 +89,7 @@ public function __construct() } /** @Entity */ -class DDC6613Phone +class DDC6613InverseSide { /** @Id @Column(type="string") */ private $id; From d2c9b22397f3edee08c9f92a5f6df26536f384dc Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 14:44:28 +0200 Subject: [PATCH 458/877] #6613 #6614 removing IDE-generated header --- tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php index 2456f1ed97d..35195f29079 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php @@ -1,10 +1,4 @@ - * Date: 11.08.2017 - * Time: 12:28 - */ namespace Doctrine\Tests\ORM\Functional\Ticket; From 5e2257db04971e753dd008f5f1790c70b06458a2 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 14:46:11 +0200 Subject: [PATCH 459/877] #6613 #6614 adding assertions about collection initialization and dirty status --- .../Tests/ORM/Functional/Ticket/DDC6613Test.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php index 35195f29079..519e88e88a7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php @@ -47,15 +47,27 @@ public function testFail() self::assertInstanceOf(PersistentCollection::class, $phones); self::assertFalse($phones->isInitialized()); + self::assertFalse($phones->isDirty()); $phones->add($item1); + + self::assertFalse($phones->isInitialized()); + self::assertTrue($phones->isDirty()); + $this->_em->flush(); + self::assertFalse($phones->isInitialized()); + self::assertFalse($phones->isDirty()); + $phones->add($item2); + self::assertFalse($phones->isInitialized()); + self::assertTrue($phones->isDirty()); + $phones->initialize(); self::assertTrue($phones->isInitialized()); + self::assertFalse($phones->isDirty(), 'Possibly wrong assertion'); self::assertCount(2, $phones); $this->_em->flush(); From 1fc7f81741be84bbce6f92c61d6f6c2b4a3e573f Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 14:47:27 +0200 Subject: [PATCH 460/877] #6613 #6614 after initialization, the collection should be dirty anyway --- tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php index 519e88e88a7..d95c8d8ff46 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php @@ -67,7 +67,7 @@ public function testFail() $phones->initialize(); self::assertTrue($phones->isInitialized()); - self::assertFalse($phones->isDirty(), 'Possibly wrong assertion'); + self::assertTrue($phones->isDirty()); self::assertCount(2, $phones); $this->_em->flush(); From d44e6e1a9ec833c4380bf46d26907c3e3e11a22a Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 15:13:39 +0200 Subject: [PATCH 461/877] #6613 #6614 ensuring that only newly added items that weren't loaded are restored in the dirty state of the collection --- lib/Doctrine/ORM/PersistentCollection.php | 34 +++++++++++++++++------ 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index 2210c3c310c..3dc254a53a5 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -692,23 +692,41 @@ public function unwrap() protected function doInitialize() { // Has NEW objects added through add(). Remember them. - $newObjects = []; + $newlyAddedDirtyObjects = []; if ($this->isDirty) { - $newObjects = $this->collection->toArray(); + $newlyAddedDirtyObjects = $this->collection->toArray(); } $this->collection->clear(); $this->em->getUnitOfWork()->loadCollection($this); $this->takeSnapshot(); + if ($newlyAddedDirtyObjects) { + $this->restoreNewObjectsInDirtyCollection($newlyAddedDirtyObjects); + } + } + + /** + * @param object[] $newObjects + * + * @return void + * + * Note: the only reason why this entire looping/complexity is performed via `spl_object_hash` + * is because we want to prevent using `array_udiff()`, which is likely to cause very + * high overhead (complexity of O(n^2)). `array_diff_key()` performs the operation in + * core, which is faster than using a callback for comparisons + */ + private function restoreNewObjectsInDirtyCollection(array $newObjects) + { + $loadedObjects = $this->collection->toArray(); + $newObjectsByOid = array_combine(array_map('spl_object_hash', $newObjects), $newObjects); + $loadedObjectsByOid = array_combine(array_map('spl_object_hash', $loadedObjects), $loadedObjects); + $newObjectsThatWereNotLoaded = array_diff_key($newObjectsByOid, $loadedObjectsByOid); + // Reattach NEW objects added through add(), if any. - if ($newObjects) { - foreach ($newObjects as $obj) { - $this->collection->add($obj); - } + array_walk($newObjectsThatWereNotLoaded, [$this->collection, 'add']); - $this->isDirty = true; - } + $this->isDirty = true; } } From 031e79e726bf08f1fd3acb9047c63419e0377d62 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 15:14:42 +0200 Subject: [PATCH 462/877] #6613 #6614 correcting broken test that isn't using objects against a `PersistentCollection` --- tests/Doctrine/Tests/ORM/PersistentCollectionTest.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php index 0e1c20f517e..a678b7f5057 100644 --- a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php @@ -115,10 +115,12 @@ public function testRemovingElementsAlsoRemovesKeys() { $this->setUpPersistentCollection(); - $this->collection->add('dummy'); + $dummy = new \stdClass(); + + $this->collection->add($dummy); $this->assertEquals([0], array_keys($this->collection->toArray())); - $this->collection->removeElement('dummy'); + $this->collection->removeElement($dummy); $this->assertEquals([], array_keys($this->collection->toArray())); } @@ -129,7 +131,7 @@ public function testClearWillAlsoClearKeys() { $this->setUpPersistentCollection(); - $this->collection->add('dummy'); + $this->collection->add(new \stdClass()); $this->collection->clear(); $this->assertEquals([], array_keys($this->collection->toArray())); } From 345cf1acf84a5c178352e5c6662eb3f6c8a58a56 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 15:15:57 +0200 Subject: [PATCH 463/877] #6613 #6614 correcting broken test that isn't using objects against a `PersistentCollection` --- tests/Doctrine/Tests/ORM/PersistentCollectionTest.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php index a678b7f5057..1c48cf207c3 100644 --- a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php @@ -143,10 +143,12 @@ public function testClearWillAlsoResetKeyPositions() { $this->setUpPersistentCollection(); - $this->collection->add('dummy'); - $this->collection->removeElement('dummy'); + $dummy = new \stdClass(); + + $this->collection->add($dummy); + $this->collection->removeElement($dummy); $this->collection->clear(); - $this->collection->add('dummy'); + $this->collection->add($dummy); $this->assertEquals([0], array_keys($this->collection->toArray())); } } From 04a5b122b0eeeba7a71b2cf240f8e04f06755c90 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 18:58:05 +0200 Subject: [PATCH 464/877] #6613 #6614 #6616 moved integration test basics to a unit test that verifies basic dirty collection initialization semantics --- .../Tests/ORM/PersistentCollectionTest.php | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php index 1c48cf207c3..82b8096a64c 100644 --- a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php @@ -3,7 +3,9 @@ namespace Doctrine\Tests\ORM; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\PersistentCollection; +use Doctrine\ORM\UnitOfWork; use Doctrine\Tests\Mocks\ConnectionMock; use Doctrine\Tests\Mocks\DriverMock; use Doctrine\Tests\Mocks\EntityManagerMock; @@ -24,7 +26,7 @@ class PersistentCollectionTest extends OrmTestCase protected $collection; /** - * @var \Doctrine\ORM\EntityManagerInterface + * @var EntityManagerMock */ private $_emMock; @@ -151,4 +153,41 @@ public function testClearWillAlsoResetKeyPositions() $this->collection->add($dummy); $this->assertEquals([0], array_keys($this->collection->toArray())); } + + /** + * @group 6613 + * @group 6614 + * @group 6616 + */ + public function testWillKeepNewItemsAfterInitialization() + { + /* @var $unitOfWork UnitOfWork|\PHPUnit_Framework_MockObject_MockObject */ + $unitOfWork = $this->createMock(UnitOfWork::class); + + $this->_emMock->setUnitOfWork($unitOfWork); + + $this->setUpPersistentCollection(); + + $newElement = new \stdClass(); + $persistedElement = new \stdClass(); + + $this->collection->add($newElement); + + self::assertFalse($this->collection->isInitialized()); + self::assertTrue($this->collection->isDirty()); + + $unitOfWork + ->expects(self::once()) + ->method('loadCollection') + ->with($this->collection) + ->willReturnCallback(function (PersistentCollection $persistentCollection) use ($persistedElement) { + $persistentCollection->unwrap()->add($persistedElement); + }); + + $this->collection->initialize(); + + self::assertSame([$persistedElement, $newElement], $this->collection->toArray()); + self::assertTrue($this->collection->isInitialized()); + self::assertTrue($this->collection->isDirty()); + } } From 93c4064679d4315b8445198919e5eac4b938d7ca Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 19:02:39 +0200 Subject: [PATCH 465/877] #6613 #6614 #6616 initializing a dirty collection that has new items that are also coming from initialization data de-duplicates new and persisted items --- .../Tests/ORM/PersistentCollectionTest.php | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php index 82b8096a64c..4c7f14f79a5 100644 --- a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php @@ -159,7 +159,7 @@ public function testClearWillAlsoResetKeyPositions() * @group 6614 * @group 6616 */ - public function testWillKeepNewItemsAfterInitialization() + public function testWillKeepNewItemsInDirtyCollectionAfterInitialization() { /* @var $unitOfWork UnitOfWork|\PHPUnit_Framework_MockObject_MockObject */ $unitOfWork = $this->createMock(UnitOfWork::class); @@ -190,4 +190,50 @@ public function testWillKeepNewItemsAfterInitialization() self::assertTrue($this->collection->isInitialized()); self::assertTrue($this->collection->isDirty()); } + + /** + * @group 6613 + * @group 6614 + * @group 6616 + */ + public function testWillDeDuplicateNewItemsThatWerePreviouslyPersistedInDirtyCollectionAfterInitialization() + { + /* @var $unitOfWork UnitOfWork|\PHPUnit_Framework_MockObject_MockObject */ + $unitOfWork = $this->createMock(UnitOfWork::class); + + $this->_emMock->setUnitOfWork($unitOfWork); + + $this->setUpPersistentCollection(); + + $newElement = new \stdClass(); + $newElementThatIsAlsoPersisted = new \stdClass(); + $persistedElement = new \stdClass(); + + $this->collection->add($newElementThatIsAlsoPersisted); + $this->collection->add($newElement); + + self::assertFalse($this->collection->isInitialized()); + self::assertTrue($this->collection->isDirty()); + + $unitOfWork + ->expects(self::once()) + ->method('loadCollection') + ->with($this->collection) + ->willReturnCallback(function (PersistentCollection $persistentCollection) use ( + $persistedElement, + $newElementThatIsAlsoPersisted + ) { + $persistentCollection->unwrap()->add($newElementThatIsAlsoPersisted); + $persistentCollection->unwrap()->add($persistedElement); + }); + + $this->collection->initialize(); + + self::assertSame( + [$newElementThatIsAlsoPersisted, $persistedElement, $newElement], + $this->collection->toArray() + ); + self::assertTrue($this->collection->isInitialized()); + self::assertTrue($this->collection->isDirty()); + } } From b064fe3d8600d85f9f098e4fed8f1e3bd0fc1cf9 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 19:08:24 +0200 Subject: [PATCH 466/877] #6613 #6614 #6616 removing repeated `PersistentCollectionTest` chunks of code --- .../Tests/ORM/PersistentCollectionTest.php | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php index 4c7f14f79a5..e4566620bb7 100644 --- a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php @@ -35,6 +35,8 @@ protected function setUp() parent::setUp(); $this->_emMock = EntityManagerMock::create(new ConnectionMock([], new DriverMock())); + + $this->setUpPersistentCollection(); } /** @@ -61,7 +63,6 @@ public function testCanBePutInLazyLoadingMode() */ public function testCurrentInitializesCollection() { - $this->setUpPersistentCollection(); $this->collection->current(); $this->assertTrue($this->collection->isInitialized()); } @@ -71,7 +72,6 @@ public function testCurrentInitializesCollection() */ public function testKeyInitializesCollection() { - $this->setUpPersistentCollection(); $this->collection->key(); $this->assertTrue($this->collection->isInitialized()); } @@ -81,7 +81,6 @@ public function testKeyInitializesCollection() */ public function testNextInitializesCollection() { - $this->setUpPersistentCollection(); $this->collection->next(); $this->assertTrue($this->collection->isInitialized()); } @@ -91,8 +90,6 @@ public function testNextInitializesCollection() */ public function testNonObjects() { - $this->setUpPersistentCollection(); - $this->assertEmpty($this->collection); $this->collection->add("dummy"); @@ -115,8 +112,6 @@ public function testNonObjects() */ public function testRemovingElementsAlsoRemovesKeys() { - $this->setUpPersistentCollection(); - $dummy = new \stdClass(); $this->collection->add($dummy); @@ -131,8 +126,6 @@ public function testRemovingElementsAlsoRemovesKeys() */ public function testClearWillAlsoClearKeys() { - $this->setUpPersistentCollection(); - $this->collection->add(new \stdClass()); $this->collection->clear(); $this->assertEquals([], array_keys($this->collection->toArray())); @@ -143,8 +136,6 @@ public function testClearWillAlsoClearKeys() */ public function testClearWillAlsoResetKeyPositions() { - $this->setUpPersistentCollection(); - $dummy = new \stdClass(); $this->collection->add($dummy); @@ -166,8 +157,6 @@ public function testWillKeepNewItemsInDirtyCollectionAfterInitialization() $this->_emMock->setUnitOfWork($unitOfWork); - $this->setUpPersistentCollection(); - $newElement = new \stdClass(); $persistedElement = new \stdClass(); @@ -203,8 +192,6 @@ public function testWillDeDuplicateNewItemsThatWerePreviouslyPersistedInDirtyCol $this->_emMock->setUnitOfWork($unitOfWork); - $this->setUpPersistentCollection(); - $newElement = new \stdClass(); $newElementThatIsAlsoPersisted = new \stdClass(); $persistedElement = new \stdClass(); From 1174ec6e8ae746bbbae865dcdab6dbfe2c6899b5 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Fri, 11 Aug 2017 20:37:23 +0200 Subject: [PATCH 467/877] Add failing test for dirty flag --- .../Tests/ORM/PersistentCollectionTest.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php index e4566620bb7..c7b68fe5283 100644 --- a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php @@ -223,4 +223,46 @@ public function testWillDeDuplicateNewItemsThatWerePreviouslyPersistedInDirtyCol self::assertTrue($this->collection->isInitialized()); self::assertTrue($this->collection->isDirty()); } + + /** + * @group 6613 + * @group 6614 + * @group 6616 + */ + public function testWillNotMarkCollectionAsDirtyAfterInitializationIfNoElementsWereAdded() + { + /* @var $unitOfWork UnitOfWork|\PHPUnit_Framework_MockObject_MockObject */ + $unitOfWork = $this->createMock(UnitOfWork::class); + + $this->_emMock->setUnitOfWork($unitOfWork); + + $newElementThatIsAlsoPersisted = new \stdClass(); + $persistedElement = new \stdClass(); + + $this->collection->add($newElementThatIsAlsoPersisted); + + self::assertFalse($this->collection->isInitialized()); + self::assertTrue($this->collection->isDirty()); + + $unitOfWork + ->expects(self::once()) + ->method('loadCollection') + ->with($this->collection) + ->willReturnCallback(function (PersistentCollection $persistentCollection) use ( + $persistedElement, + $newElementThatIsAlsoPersisted + ) { + $persistentCollection->unwrap()->add($newElementThatIsAlsoPersisted); + $persistentCollection->unwrap()->add($persistedElement); + }); + + $this->collection->initialize(); + + self::assertSame( + [$newElementThatIsAlsoPersisted, $persistedElement], + $this->collection->toArray() + ); + self::assertTrue($this->collection->isInitialized()); + self::assertFalse($this->collection->isDirty()); + } } From a2ca6bbfafd0200d2cf658f5b4fd9e80d65c3d9d Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 21:09:34 +0200 Subject: [PATCH 468/877] #6613 #6614 #6616 ensuring that the collection is marked as non-dirty if all new items are contained in the initialized ones --- lib/Doctrine/ORM/PersistentCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index 3dc254a53a5..1ce3e495bde 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -727,6 +727,6 @@ private function restoreNewObjectsInDirtyCollection(array $newObjects) // Reattach NEW objects added through add(), if any. array_walk($newObjectsThatWereNotLoaded, [$this->collection, 'add']); - $this->isDirty = true; + $this->isDirty = (bool) $newObjectsThatWereNotLoaded; } } From 35799975310d2f9c9a2c11c0400c30b801e0328d Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 21:11:31 +0200 Subject: [PATCH 469/877] #6613 #6614 #6616 removing DDC6613 test, which was fully ported to unit tests --- .../ORM/Functional/Ticket/DDC6613Test.php | 107 ------------------ 1 file changed, 107 deletions(-) delete mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php deleted file mode 100644 index d95c8d8ff46..00000000000 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6613Test.php +++ /dev/null @@ -1,107 +0,0 @@ -setUpEntitySchema([ - DDC6613InverseSide::class, - DDC6613OwningSide::class, - ]); - } - - public function testFail() - { - $owningSide = new DDC6613OwningSide(); - - $this->_em->persist($owningSide); - $this->_em->flush(); - $this->_em->clear(); - - $item1 = new DDC6613InverseSide(); - $item2 = new DDC6613InverseSide(); - - $this->_em->persist($item1); - $this->_em->persist($item2); - $this->_em->flush(); - - /* @var DDC6613OwningSide $foundOwningSide */ - $foundOwningSide = $this->_em->find(DDC6613OwningSide::class, $owningSide->id); - - self::assertInstanceOf(DDC6613OwningSide::class, $foundOwningSide); - - /* @var $phones PersistentCollection */ - $phones = $foundOwningSide->phones; - - self::assertInstanceOf(PersistentCollection::class, $phones); - self::assertFalse($phones->isInitialized()); - self::assertFalse($phones->isDirty()); - - $phones->add($item1); - - self::assertFalse($phones->isInitialized()); - self::assertTrue($phones->isDirty()); - - $this->_em->flush(); - - self::assertFalse($phones->isInitialized()); - self::assertFalse($phones->isDirty()); - - $phones->add($item2); - - self::assertFalse($phones->isInitialized()); - self::assertTrue($phones->isDirty()); - - $phones->initialize(); - - self::assertTrue($phones->isInitialized()); - self::assertTrue($phones->isDirty()); - self::assertCount(2, $phones); - - $this->_em->flush(); - - self::assertFalse($phones->isDirty()); - self::assertTrue($phones->isInitialized()); - self::assertCount(2, $foundOwningSide->phones); - } -} - -/** @Entity */ -class DDC6613OwningSide -{ - /** @Id @Column(type="string") */ - public $id; - - /** @ManyToMany(targetEntity=DDC6613InverseSide::class) */ - public $phones; - - public function __construct() - { - $this->id = uniqid('user', true); - $this->phones = new ArrayCollection(); - } -} - -/** @Entity */ -class DDC6613InverseSide -{ - /** @Id @Column(type="string") */ - private $id; - - public function __construct() - { - $this->id = uniqid('phone', true); - } -} \ No newline at end of file From 004ac518695da8a0194d1dbd2ba00574a6027a12 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 21:14:05 +0200 Subject: [PATCH 470/877] #6613 #6614 #6616 minor performance optimisations around the new `restoreNewObjectsInDirtyCollection` implementation --- lib/Doctrine/ORM/PersistentCollection.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index 1ce3e495bde..9abea4f22ca 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -720,13 +720,15 @@ protected function doInitialize() private function restoreNewObjectsInDirtyCollection(array $newObjects) { $loadedObjects = $this->collection->toArray(); - $newObjectsByOid = array_combine(array_map('spl_object_hash', $newObjects), $newObjects); - $loadedObjectsByOid = array_combine(array_map('spl_object_hash', $loadedObjects), $loadedObjects); - $newObjectsThatWereNotLoaded = array_diff_key($newObjectsByOid, $loadedObjectsByOid); + $newObjectsByOid = \array_combine(\array_map('spl_object_hash', $newObjects), $newObjects); + $loadedObjectsByOid = \array_combine(\array_map('spl_object_hash', $loadedObjects), $loadedObjects); + $newObjectsThatWereNotLoaded = \array_diff_key($newObjectsByOid, $loadedObjectsByOid); - // Reattach NEW objects added through add(), if any. - array_walk($newObjectsThatWereNotLoaded, [$this->collection, 'add']); + if ($newObjectsThatWereNotLoaded) { + // Reattach NEW objects added through add(), if any. + \array_walk($newObjectsThatWereNotLoaded, [$this->collection, 'add']); - $this->isDirty = (bool) $newObjectsThatWereNotLoaded; + $this->isDirty = true; + } } } From c2dd274c42b35a239670d507779e9bfe02fe66e2 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 21:27:09 +0200 Subject: [PATCH 471/877] #6613 #6614 #6616 adding `void` return type --- lib/Doctrine/ORM/PersistentCollection.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index 9abea4f22ca..4ea56f55b57 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -710,14 +710,12 @@ protected function doInitialize() /** * @param object[] $newObjects * - * @return void - * * Note: the only reason why this entire looping/complexity is performed via `spl_object_hash` * is because we want to prevent using `array_udiff()`, which is likely to cause very * high overhead (complexity of O(n^2)). `array_diff_key()` performs the operation in * core, which is faster than using a callback for comparisons */ - private function restoreNewObjectsInDirtyCollection(array $newObjects) + private function restoreNewObjectsInDirtyCollection(array $newObjects) : void { $loadedObjects = $this->collection->toArray(); $newObjectsByOid = \array_combine(\array_map('spl_object_hash', $newObjects), $newObjects); From 352b3ba6f6dad03863a8ef2696a1097146551699 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 21:28:18 +0200 Subject: [PATCH 472/877] #6613 #6614 #6616 adding `void` return type to newly introduced test methods --- .../Doctrine/Tests/ORM/PersistentCollectionTest.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php index c7b68fe5283..38be94522a7 100644 --- a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php @@ -3,7 +3,6 @@ namespace Doctrine\Tests\ORM; use Doctrine\Common\Collections\ArrayCollection; -use Doctrine\Common\Collections\Collection; use Doctrine\ORM\PersistentCollection; use Doctrine\ORM\UnitOfWork; use Doctrine\Tests\Mocks\ConnectionMock; @@ -150,7 +149,7 @@ public function testClearWillAlsoResetKeyPositions() * @group 6614 * @group 6616 */ - public function testWillKeepNewItemsInDirtyCollectionAfterInitialization() + public function testWillKeepNewItemsInDirtyCollectionAfterInitialization() : void { /* @var $unitOfWork UnitOfWork|\PHPUnit_Framework_MockObject_MockObject */ $unitOfWork = $this->createMock(UnitOfWork::class); @@ -169,7 +168,7 @@ public function testWillKeepNewItemsInDirtyCollectionAfterInitialization() ->expects(self::once()) ->method('loadCollection') ->with($this->collection) - ->willReturnCallback(function (PersistentCollection $persistentCollection) use ($persistedElement) { + ->willReturnCallback(function (PersistentCollection $persistentCollection) use ($persistedElement) : void { $persistentCollection->unwrap()->add($persistedElement); }); @@ -185,7 +184,7 @@ public function testWillKeepNewItemsInDirtyCollectionAfterInitialization() * @group 6614 * @group 6616 */ - public function testWillDeDuplicateNewItemsThatWerePreviouslyPersistedInDirtyCollectionAfterInitialization() + public function testWillDeDuplicateNewItemsThatWerePreviouslyPersistedInDirtyCollectionAfterInitialization() : void { /* @var $unitOfWork UnitOfWork|\PHPUnit_Framework_MockObject_MockObject */ $unitOfWork = $this->createMock(UnitOfWork::class); @@ -209,7 +208,7 @@ public function testWillDeDuplicateNewItemsThatWerePreviouslyPersistedInDirtyCol ->willReturnCallback(function (PersistentCollection $persistentCollection) use ( $persistedElement, $newElementThatIsAlsoPersisted - ) { + ) : void { $persistentCollection->unwrap()->add($newElementThatIsAlsoPersisted); $persistentCollection->unwrap()->add($persistedElement); }); @@ -229,7 +228,7 @@ public function testWillDeDuplicateNewItemsThatWerePreviouslyPersistedInDirtyCol * @group 6614 * @group 6616 */ - public function testWillNotMarkCollectionAsDirtyAfterInitializationIfNoElementsWereAdded() + public function testWillNotMarkCollectionAsDirtyAfterInitializationIfNoElementsWereAdded() : void { /* @var $unitOfWork UnitOfWork|\PHPUnit_Framework_MockObject_MockObject */ $unitOfWork = $this->createMock(UnitOfWork::class); @@ -251,7 +250,7 @@ public function testWillNotMarkCollectionAsDirtyAfterInitializationIfNoElementsW ->willReturnCallback(function (PersistentCollection $persistentCollection) use ( $persistedElement, $newElementThatIsAlsoPersisted - ) { + ) : void { $persistentCollection->unwrap()->add($newElementThatIsAlsoPersisted); $persistentCollection->unwrap()->add($persistedElement); }); From 55882ca7a646d4c1c908a9b7bc3fd7b8345f658a Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Sat, 27 May 2017 15:56:57 +0200 Subject: [PATCH 473/877] #6464 add test --- .../ORM/Functional/Ticket/GH6464Test.php | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php new file mode 100644 index 00000000000..a69166d5d01 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php @@ -0,0 +1,89 @@ +_schemaTool->createSchema( + [ + $this->_em->getClassMetadata(GH6464Post::class), + $this->_em->getClassMetadata(GH6464User::class), + $this->_em->getClassMetadata(GH6464Author::class), + ] + ); + } + + /** + * Verifies that SqlWalker generates valid SQL for an INNER JOIN to CTI table + * + * SqlWalker needs to generate nested INNER JOIN statements, otherwise there would be INNER JOIN + * statements without an ON clause, which are valid on e.g. MySQL but rejected by PostgreSQL. + */ + public function testIssue() + { + + $qb = $this->_em->createQueryBuilder(); + + $query = $qb + ->select('p', 'a') + ->from(GH6464Post::class, 'p') + ->innerJoin(GH6464Author::class, 'a', 'WITH', 'p.authorId = a.id') + ->getQuery(); + + $this->assertNotRegExp( + '/INNER JOIN \w+ \w+ INNER JOIN/', + $query->getSQL(), + 'As of GH-6464, every INNER JOIN should have an ON clause, which is missing here' + ); + + // Query shouldn't yield a result, yet it shouldn't crash (anymore) + $this->assertEquals([], $query->getResult()); + } +} + +/** @Entity */ +class GH6464Post +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; + + /** @Column(type="integer") */ + public $authorId; + + /** @Column(length=100) */ + public $title; + + /** @Column(type="text") */ + public $text; +} + +/** + * @Entity + * @InheritanceType("JOINED") + * @DiscriminatorColumn(name="discr", type="string") + * @DiscriminatorMap({"author" = "GH6464Author"}) + */ +abstract class GH6464User +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; +} + +/** @Entity */ +class GH6464Author extends GH6464User +{ + /** @Column(length=50) */ + public $displayName; +} From 99fdbf550df0e070eb63df834676b9e12fedeae7 Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Sat, 27 May 2017 19:03:16 +0200 Subject: [PATCH 474/877] generate nested join sql for CTIs, closes #6464 --- lib/Doctrine/ORM/Query/SqlWalker.php | 13 +++++++++---- .../Tests/ORM/Query/SelectSqlGenerationTest.php | 6 +++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 98f58ad8c69..0fc3090f8ae 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -872,10 +872,11 @@ public function walkIndexBy($indexBy) * Walks down a RangeVariableDeclaration AST node, thereby generating the appropriate SQL. * * @param AST\RangeVariableDeclaration $rangeVariableDeclaration + * @param bool $buildNestedJoins * * @return string */ - public function walkRangeVariableDeclaration($rangeVariableDeclaration) + public function walkRangeVariableDeclaration($rangeVariableDeclaration, $buildNestedJoins = false) { $class = $this->em->getClassMetadata($rangeVariableDeclaration->abstractSchemaName); $dqlAlias = $rangeVariableDeclaration->aliasIdentificationVariable; @@ -891,7 +892,11 @@ public function walkRangeVariableDeclaration($rangeVariableDeclaration) ); if ($class->isInheritanceTypeJoined()) { - $sql .= $this->_generateClassTableInheritanceJoins($class, $dqlAlias); + if ($buildNestedJoins) { + $sql = '(' . $sql . $this->_generateClassTableInheritanceJoins($class, $dqlAlias) . ')'; + } else { + $sql .= $this->_generateClassTableInheritanceJoins($class, $dqlAlias); + } } return $sql; @@ -1137,11 +1142,11 @@ public function walkJoin($join) $conditions[] = '(' . $this->walkConditionalExpression($join->conditionalExpression) . ')'; } - $condExprConjunction = ($class->isInheritanceTypeJoined() && $joinType != AST\Join::JOIN_TYPE_LEFT && $joinType != AST\Join::JOIN_TYPE_LEFTOUTER) + $condExprConjunction = ($class->isInheritanceTypeJoined() && $joinType != AST\Join::JOIN_TYPE_LEFT && $joinType != AST\Join::JOIN_TYPE_LEFTOUTER && empty($conditions)) ? ' AND ' : ' ON '; - $sql .= $this->walkRangeVariableDeclaration($joinDeclaration); + $sql .= $this->walkRangeVariableDeclaration($joinDeclaration, !empty($conditions)); // Apply remaining inheritance restrictions $discrSql = $this->_generateDiscriminatorColumnConditionSQL([$dqlAlias]); diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index c10afbb8961..9e04c3183ac 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -198,12 +198,12 @@ public function testSupportsJoinOnMultipleComponentsWithJoinedInheritanceType() { $this->assertSqlGeneration( 'SELECT e FROM Doctrine\Tests\Models\Company\CompanyEmployee e JOIN Doctrine\Tests\Models\Company\CompanyManager m WITH e.id = m.id', - 'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, c0_.discr AS discr_5 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id INNER JOIN company_managers c2_ INNER JOIN company_employees c4_ ON c2_.id = c4_.id INNER JOIN company_persons c3_ ON c2_.id = c3_.id AND (c0_.id = c3_.id)' + 'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, c0_.discr AS discr_5 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id INNER JOIN (company_managers c2_ INNER JOIN company_employees c4_ ON c2_.id = c4_.id INNER JOIN company_persons c3_ ON c2_.id = c3_.id) ON (c0_.id = c3_.id)' ); $this->assertSqlGeneration( 'SELECT e FROM Doctrine\Tests\Models\Company\CompanyEmployee e LEFT JOIN Doctrine\Tests\Models\Company\CompanyManager m WITH e.id = m.id', - 'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, c0_.discr AS discr_5 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id LEFT JOIN company_managers c2_ INNER JOIN company_employees c4_ ON c2_.id = c4_.id INNER JOIN company_persons c3_ ON c2_.id = c3_.id ON (c0_.id = c3_.id)' + 'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, c0_.discr AS discr_5 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id LEFT JOIN (company_managers c2_ INNER JOIN company_employees c4_ ON c2_.id = c4_.id INNER JOIN company_persons c3_ ON c2_.id = c3_.id) ON (c0_.id = c3_.id)' ); } @@ -2211,7 +2211,7 @@ public function testSingleTableInheritanceLeftJoinNonAssociationWithConditionAnd // the where clause when not joining onto that table $this->assertSqlGeneration( 'SELECT c FROM Doctrine\Tests\Models\Company\CompanyContract c LEFT JOIN Doctrine\Tests\Models\Company\CompanyEmployee e WITH e.id = c.salesPerson WHERE c.completed = true', - "SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.fixPrice AS fixPrice_2, c0_.hoursWorked AS hoursWorked_3, c0_.pricePerHour AS pricePerHour_4, c0_.maxPrice AS maxPrice_5, c0_.discr AS discr_6 FROM company_contracts c0_ LEFT JOIN company_employees c1_ INNER JOIN company_persons c2_ ON c1_.id = c2_.id ON (c2_.id = c0_.salesPerson_id) WHERE (c0_.completed = 1) AND c0_.discr IN ('fix', 'flexible', 'flexultra')" + "SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.fixPrice AS fixPrice_2, c0_.hoursWorked AS hoursWorked_3, c0_.pricePerHour AS pricePerHour_4, c0_.maxPrice AS maxPrice_5, c0_.discr AS discr_6 FROM company_contracts c0_ LEFT JOIN (company_employees c1_ INNER JOIN company_persons c2_ ON c1_.id = c2_.id) ON (c2_.id = c0_.salesPerson_id) WHERE (c0_.completed = 1) AND c0_.discr IN ('fix', 'flexible', 'flexultra')" ); } From 025ed1147bc981ae24a93c351408bc9aa71c4698 Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Sat, 29 Jul 2017 12:41:57 +0200 Subject: [PATCH 475/877] #6464 code review updates --- lib/Doctrine/ORM/Query/SqlWalker.php | 23 +++++++++++++++---- .../ORM/Functional/Ticket/GH6464Test.php | 13 +---------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 0fc3090f8ae..713f5534eb5 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -872,11 +872,23 @@ public function walkIndexBy($indexBy) * Walks down a RangeVariableDeclaration AST node, thereby generating the appropriate SQL. * * @param AST\RangeVariableDeclaration $rangeVariableDeclaration + * + * @return string + */ + public function walkRangeVariableDeclaration($rangeVariableDeclaration) + { + return $this->generateRangeVariableDeclarationSQL($rangeVariableDeclaration, false); + } + + /** + * Generate appropriate SQL for RangeVariableDeclaration AST node + * + * @param AST\RangeVariableDeclaration $rangeVariableDeclaration * @param bool $buildNestedJoins * * @return string */ - public function walkRangeVariableDeclaration($rangeVariableDeclaration, $buildNestedJoins = false) + private function generateRangeVariableDeclarationSQL($rangeVariableDeclaration, $buildNestedJoins) { $class = $this->em->getClassMetadata($rangeVariableDeclaration->abstractSchemaName); $dqlAlias = $rangeVariableDeclaration->aliasIdentificationVariable; @@ -1132,7 +1144,7 @@ public function walkJoin($join) : ' INNER JOIN '; switch (true) { - case ($joinDeclaration instanceof \Doctrine\ORM\Query\AST\RangeVariableDeclaration): + case ($joinDeclaration instanceof AST\RangeVariableDeclaration): $class = $this->em->getClassMetadata($joinDeclaration->abstractSchemaName); $dqlAlias = $joinDeclaration->aliasIdentificationVariable; $tableAlias = $this->getSQLTableAlias($class->table['name'], $dqlAlias); @@ -1142,11 +1154,12 @@ public function walkJoin($join) $conditions[] = '(' . $this->walkConditionalExpression($join->conditionalExpression) . ')'; } - $condExprConjunction = ($class->isInheritanceTypeJoined() && $joinType != AST\Join::JOIN_TYPE_LEFT && $joinType != AST\Join::JOIN_TYPE_LEFTOUTER && empty($conditions)) + $isUnconditionalJoin = empty($conditions); + $condExprConjunction = ($class->isInheritanceTypeJoined() && $joinType != AST\Join::JOIN_TYPE_LEFT && $joinType != AST\Join::JOIN_TYPE_LEFTOUTER && $isUnconditionalJoin) ? ' AND ' : ' ON '; - $sql .= $this->walkRangeVariableDeclaration($joinDeclaration, !empty($conditions)); + $sql .= $this->generateRangeVariableDeclarationSQL($joinDeclaration, !$isUnconditionalJoin); // Apply remaining inheritance restrictions $discrSql = $this->_generateDiscriminatorColumnConditionSQL([$dqlAlias]); @@ -1168,7 +1181,7 @@ public function walkJoin($join) break; - case ($joinDeclaration instanceof \Doctrine\ORM\Query\AST\JoinAssociationDeclaration): + case ($joinDeclaration instanceof AST\JoinAssociationDeclaration): $sql .= $this->walkJoinAssociationDeclaration($joinDeclaration, $joinType, $join->conditionalExpression); break; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php index a69166d5d01..75762e7d772 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php @@ -33,10 +33,7 @@ protected function setUp() */ public function testIssue() { - - $qb = $this->_em->createQueryBuilder(); - - $query = $qb + $query = $this->_em->createQueryBuilder() ->select('p', 'a') ->from(GH6464Post::class, 'p') ->innerJoin(GH6464Author::class, 'a', 'WITH', 'p.authorId = a.id') @@ -61,12 +58,6 @@ class GH6464Post /** @Column(type="integer") */ public $authorId; - - /** @Column(length=100) */ - public $title; - - /** @Column(type="text") */ - public $text; } /** @@ -84,6 +75,4 @@ abstract class GH6464User /** @Entity */ class GH6464Author extends GH6464User { - /** @Column(length=50) */ - public $displayName; } From 91a50916121beff07e413d4905cf5f63dec7dac6 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 21:39:13 +0200 Subject: [PATCH 476/877] #6464 #6475 cleaning up test - removed invalid fetch join, CS --- .../Tests/ORM/Functional/Ticket/GH6464Test.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php index 75762e7d772..adc6f7b161c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php @@ -16,13 +16,11 @@ protected function setUp() { parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(GH6464Post::class), - $this->_em->getClassMetadata(GH6464User::class), - $this->_em->getClassMetadata(GH6464Author::class), - ] - ); + $this->_schemaTool->createSchema([ + $this->_em->getClassMetadata(GH6464Post::class), + $this->_em->getClassMetadata(GH6464User::class), + $this->_em->getClassMetadata(GH6464Author::class), + ]); } /** @@ -34,7 +32,7 @@ protected function setUp() public function testIssue() { $query = $this->_em->createQueryBuilder() - ->select('p', 'a') + ->select('p') ->from(GH6464Post::class, 'p') ->innerJoin(GH6464Author::class, 'a', 'WITH', 'p.authorId = a.id') ->getQuery(); From 9ad91ddc1c57542833532a89bcc22faacb4dcd32 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 21:45:23 +0200 Subject: [PATCH 477/877] #6464 #6475 using PHP 7.1 `void` and `string` return hints where available --- lib/Doctrine/ORM/Query/SqlWalker.php | 2 +- tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 713f5534eb5..6e2e41ddcd8 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -888,7 +888,7 @@ public function walkRangeVariableDeclaration($rangeVariableDeclaration) * * @return string */ - private function generateRangeVariableDeclarationSQL($rangeVariableDeclaration, $buildNestedJoins) + private function generateRangeVariableDeclarationSQL($rangeVariableDeclaration, bool $buildNestedJoins) : string { $class = $this->em->getClassMetadata($rangeVariableDeclaration->abstractSchemaName); $dqlAlias = $rangeVariableDeclaration->aliasIdentificationVariable; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php index adc6f7b161c..1d75cdf3dc2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php @@ -12,7 +12,7 @@ class GH6464Test extends OrmFunctionalTestCase /** * {@inheritDoc} */ - protected function setUp() + protected function setUp() : void { parent::setUp(); @@ -29,7 +29,7 @@ protected function setUp() * SqlWalker needs to generate nested INNER JOIN statements, otherwise there would be INNER JOIN * statements without an ON clause, which are valid on e.g. MySQL but rejected by PostgreSQL. */ - public function testIssue() + public function testIssue() : void { $query = $this->_em->createQueryBuilder() ->select('p') From 16a14f223839f173b5058d4ac35915e30c6c659d Mon Sep 17 00:00:00 2001 From: Gabe van der Weijde Date: Wed, 28 Jun 2017 20:40:25 +0200 Subject: [PATCH 478/877] -- Created test for validation issue #6499. --- .../ORM/Functional/Ticket/DDC6499Test.php | 172 ++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php new file mode 100644 index 00000000000..98b0e42a722 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php @@ -0,0 +1,172 @@ +_schemaTool->createSchema( + [ + $this->_em->getClassMetadata(DDC6499A::class), + $this->_em->getClassMetadata(DDC6499B::class), + ] + ); + } + + /** + * Test for the bug described in issue #6499. + */ + public function testIssue() + { + $a = new DDC6499A(); + $this->_em->persist($a); + + $b = new DDC6499B(); + $a->setB($b); + $this->_em->persist($b); + + $this->_em->flush(); + + // Issue #6499 will result in a Integrity constraint violation before reaching this point + $this->assertEquals(true, true); + } +} + +/** @Entity */ +class DDC6499A +{ + /** + * @Id() + * @GeneratedValue(strategy="AUTO") + * @Column(name="id", type="integer") + */ + private $id; + + /** + * @OneToMany(targetEntity="DDC6499B", mappedBy="a", cascade={"persist", "remove"}, orphanRemoval=true) + */ + private $bs; + + /** + * @OneToOne(targetEntity="DDC6499B", cascade={"persist"}) + * @JoinColumn(nullable=false) + */ + private $b; + + /** + * DDC6499A constructor. + */ + public function __construct() + { + $this->bs = new ArrayCollection(); + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @return DDC6499B[]|ArrayCollection + */ + public function getBs() + { + return $this->bs; + } + + /** + * @param DDC6499B $b + */ + public function addB(DDC6499B $b) + { + if ($this->bs->contains($b)) return; + + $this->bs->add($b); + + // Update owning side + $b->setA($this); + } + + /** + * @param DDC6499B $b + */ + public function removeB(DDC6499B $b) + { + if (!$this->bs->contains($b)) return; + + $this->bs->removeElement($b); + + // Not updating owning side due to orphan removal + } + + /** + * @return DDC6499B + */ + public function getB() + { + return $this->b; + } + + /** + * @param DDC6499B $b + */ + public function setB(DDC6499B $b) + { + $this->b = $b; + } +} + +/** @Entity */ +class DDC6499B +{ + /** + * @Id() + * @GeneratedValue(strategy="AUTO") + * @Column(name="id", type="integer") + */ + private $id; + + /** + * @ManyToOne(targetEntity="DDC6499A", inversedBy="bs", cascade={"persist"}) + */ + private $a; + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @return DDC6499A + */ + public function getA() + { + return $this->a; + } + + /** + * @param DDC6499A $a + */ + public function setA(DDC6499A $a) + { + $this->a = $a; + } +} \ No newline at end of file From db2530d6fdbda608d2eaada74c16d253c89eb59c Mon Sep 17 00:00:00 2001 From: Gabe van der Weijde Date: Wed, 28 Jun 2017 20:55:58 +0200 Subject: [PATCH 479/877] -- Proposed fix due to logic error. --- lib/Doctrine/ORM/UnitOfWork.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index c0b0dd8c302..0afabf805f8 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1154,7 +1154,7 @@ private function getCommitOrder(array $entityChangeSet = null) $joinColumns = reset($assoc['joinColumns']); - $calc->addDependency($targetClass->name, $class->name, (int)empty($joinColumns['nullable'])); + $calc->addDependency($targetClass->name, $class->name, (int) ! ( ! isset($joinColumns['nullable']) || $joinColumns['nullable'] === true)); // If the target class has mapped subclasses, these share the same dependency. if ( ! $targetClass->subClasses) { From da3cd04993b107e6dff8e2e382d5769add8ed0b4 Mon Sep 17 00:00:00 2001 From: Gabe van der Weijde Date: Thu, 29 Jun 2017 17:16:35 +0200 Subject: [PATCH 480/877] -- Transformed into a minimal example. -- Processed Ocramius' feedback. --- .../ORM/Functional/Ticket/DDC6499Test.php | 150 +++++------------- 1 file changed, 43 insertions(+), 107 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php index 98b0e42a722..3cee68cf88d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php @@ -13,7 +13,7 @@ class DDC6499Test extends OrmFunctionalTestCase /** * {@inheritDoc} */ - protected function setUp() + protected function setUp() : void { parent::setUp(); @@ -25,148 +25,84 @@ protected function setUp() ); } + /** + * {@inheritDoc} + */ + protected function tearDown() : void + { + parent::tearDown(); + + $this->_schemaTool->dropSchema( + [ + $this->_em->getClassMetadata(DDC6499A::class), + $this->_em->getClassMetadata(DDC6499B::class), + ] + ); + } + /** * Test for the bug described in issue #6499. */ - public function testIssue() + public function testIssue() : void { $a = new DDC6499A(); $this->_em->persist($a); $b = new DDC6499B(); - $a->setB($b); + $a->b = $b; $this->_em->persist($b); $this->_em->flush(); + $this->_em->clear(); - // Issue #6499 will result in a Integrity constraint violation before reaching this point - $this->assertEquals(true, true); + self::assertEquals($this->_em->find(DDC6499A::class, $a->id)->b->id, $b->id, "Issue #6499 will result in a Integrity constraint violation before reaching this point."); } -} -/** @Entity */ -class DDC6499A -{ /** - * @Id() - * @GeneratedValue(strategy="AUTO") - * @Column(name="id", type="integer") + * Test for the bug described in issue #6499 (reversed order). */ - private $id; - - /** - * @OneToMany(targetEntity="DDC6499B", mappedBy="a", cascade={"persist", "remove"}, orphanRemoval=true) - */ - private $bs; - - /** - * @OneToOne(targetEntity="DDC6499B", cascade={"persist"}) - * @JoinColumn(nullable=false) - */ - private $b; - - /** - * DDC6499A constructor. - */ - public function __construct() - { - $this->bs = new ArrayCollection(); - } - - /** - * @return int - */ - public function getId() + public function testIssueReversed() : void { - return $this->id; - } - - /** - * @return DDC6499B[]|ArrayCollection - */ - public function getBs() - { - return $this->bs; - } - - /** - * @param DDC6499B $b - */ - public function addB(DDC6499B $b) - { - if ($this->bs->contains($b)) return; - - $this->bs->add($b); + $a = new DDC6499A(); - // Update owning side - $b->setA($this); - } + $b = new DDC6499B(); + $a->b = $b; - /** - * @param DDC6499B $b - */ - public function removeB(DDC6499B $b) - { - if (!$this->bs->contains($b)) return; + $this->_em->persist($b); + $this->_em->persist($a); - $this->bs->removeElement($b); + $this->_em->flush(); + $this->_em->clear(); - // Not updating owning side due to orphan removal + self::assertEquals($this->_em->find(DDC6499A::class, $a->id)->b->id, $b->id, "Issue #6499 will result in a Integrity constraint violation before reaching this point."); } +} +/** @Entity */ +class DDC6499A +{ /** - * @return DDC6499B + * @Id @Column(type="integer") @GeneratedValue */ - public function getB() - { - return $this->b; - } + public $id; /** - * @param DDC6499B $b + * @OneToOne(targetEntity="DDC6499B") + * @JoinColumn(nullable=false) */ - public function setB(DDC6499B $b) - { - $this->b = $b; - } + public $b; } /** @Entity */ class DDC6499B { /** - * @Id() - * @GeneratedValue(strategy="AUTO") - * @Column(name="id", type="integer") - */ - private $id; - - /** - * @ManyToOne(targetEntity="DDC6499A", inversedBy="bs", cascade={"persist"}) - */ - private $a; - - /** - * @return int + * @Id @Column(type="integer") @GeneratedValue */ - public function getId() - { - return $this->id; - } + public $id; /** - * @return DDC6499A + * @ManyToOne(targetEntity="DDC6499A", inversedBy="bs") */ - public function getA() - { - return $this->a; - } - - /** - * @param DDC6499A $a - */ - public function setA(DDC6499A $a) - { - $this->a = $a; - } + public $a; } \ No newline at end of file From b352cd3e222db4680a365a1408fafea27daabb90 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 21:54:30 +0200 Subject: [PATCH 481/877] #6499 #6533 minor CS fixes in the test --- tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php index 3cee68cf88d..4b27478c685 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php @@ -17,12 +17,10 @@ protected function setUp() : void { parent::setUp(); - $this->_schemaTool->createSchema( - [ + $this->_schemaTool->createSchema([ $this->_em->getClassMetadata(DDC6499A::class), $this->_em->getClassMetadata(DDC6499B::class), - ] - ); + ]); } /** From ebd521c56eef4a9ad9cec239997554182db1e9a4 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 21:55:02 +0200 Subject: [PATCH 482/877] #6499 #6533 minor CS fixes in the test --- .../Tests/ORM/Functional/Ticket/DDC6499Test.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php index 4b27478c685..066c0b1b4a7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php @@ -30,12 +30,10 @@ protected function tearDown() : void { parent::tearDown(); - $this->_schemaTool->dropSchema( - [ - $this->_em->getClassMetadata(DDC6499A::class), - $this->_em->getClassMetadata(DDC6499B::class), - ] - ); + $this->_schemaTool->dropSchema([ + $this->_em->getClassMetadata(DDC6499A::class), + $this->_em->getClassMetadata(DDC6499B::class), + ]); } /** From 25829ea450f60fb9f1507444f339edc8b0915669 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 22:05:00 +0200 Subject: [PATCH 483/877] #6499 #6533 simplifying test scenario to the bone, adding description of what happened at persistence-level --- .../ORM/Functional/Ticket/DDC6499Test.php | 58 ++++++++----------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php index 066c0b1b4a7..6e8b2533604 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php @@ -6,7 +6,12 @@ use Doctrine\Tests\OrmFunctionalTestCase; /** - * @group DDC-6499 + * @group #6499 + * + * + * Specifically, DDC6499B has a dependency on DDC6499A, and DDC6499A + * has a dependency on DDC6499B. Since DDC6499A#b is not nullable, + * the DDC6499B should be inserted first. */ class DDC6499Test extends OrmFunctionalTestCase { @@ -36,69 +41,56 @@ protected function tearDown() : void ]); } - /** - * Test for the bug described in issue #6499. - */ public function testIssue() : void { - $a = new DDC6499A(); - $this->_em->persist($a); - $b = new DDC6499B(); - $a->b = $b; + $a = new DDC6499A($b); + + $this->_em->persist($a); $this->_em->persist($b); $this->_em->flush(); - $this->_em->clear(); - self::assertEquals($this->_em->find(DDC6499A::class, $a->id)->b->id, $b->id, "Issue #6499 will result in a Integrity constraint violation before reaching this point."); + self::assertInternalType('integer', $a->id); + self::assertInternalType('integer', $b->id); } - /** - * Test for the bug described in issue #6499 (reversed order). - */ public function testIssueReversed() : void { - $a = new DDC6499A(); - $b = new DDC6499B(); - $a->b = $b; + $a = new DDC6499A($b); $this->_em->persist($b); $this->_em->persist($a); $this->_em->flush(); - $this->_em->clear(); - self::assertEquals($this->_em->find(DDC6499A::class, $a->id)->b->id, $b->id, "Issue #6499 will result in a Integrity constraint violation before reaching this point."); + self::assertInternalType('integer', $a->id); + self::assertInternalType('integer', $b->id); } } /** @Entity */ class DDC6499A { - /** - * @Id @Column(type="integer") @GeneratedValue - */ + /** @Id @Column(type="integer") @GeneratedValue */ public $id; - /** - * @OneToOne(targetEntity="DDC6499B") - * @JoinColumn(nullable=false) - */ + /** @JoinColumn(nullable=false) @OneToOne(targetEntity=DDC6499B::class) */ public $b; + + public function __construct(DDC6499B $b) + { + $this->b = $b; + } } /** @Entity */ class DDC6499B { - /** - * @Id @Column(type="integer") @GeneratedValue - */ + /** @Id @Column(type="integer") @GeneratedValue */ public $id; - /** - * @ManyToOne(targetEntity="DDC6499A", inversedBy="bs") - */ - public $a; -} \ No newline at end of file + /** @ManyToOne(targetEntity="DDC6499A") */ + private $a; +} From 166c5816b6296fc14860149fe1a6d2cf3f40e092 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 22:10:02 +0200 Subject: [PATCH 484/877] #6499 #6533 calibrating test so that the association is populated after persistence in some edge cases --- .../Tests/ORM/Functional/Ticket/DDC6499Test.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php index 6e8b2533604..0d86fffb037 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php @@ -44,9 +44,12 @@ protected function tearDown() : void public function testIssue() : void { $b = new DDC6499B(); - $a = new DDC6499A($b); + $a = new DDC6499A(); $this->_em->persist($a); + + $a->b = $b; + $this->_em->persist($b); $this->_em->flush(); @@ -58,7 +61,9 @@ public function testIssue() : void public function testIssueReversed() : void { $b = new DDC6499B(); - $a = new DDC6499A($b); + $a = new DDC6499A(); + + $a->b = $b; $this->_em->persist($b); $this->_em->persist($a); @@ -78,11 +83,6 @@ class DDC6499A /** @JoinColumn(nullable=false) @OneToOne(targetEntity=DDC6499B::class) */ public $b; - - public function __construct(DDC6499B $b) - { - $this->b = $b; - } } /** @Entity */ From 1ede3c514f78837ffa5f4bb0621a188791d80cd0 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 22:13:20 +0200 Subject: [PATCH 485/877] #6499 #6533 simplifying nullable column check - null coalesce operator makes it *SOMEWHAT* more readable (no miracles) --- lib/Doctrine/ORM/UnitOfWork.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 0afabf805f8..56615807f4e 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1154,7 +1154,11 @@ private function getCommitOrder(array $entityChangeSet = null) $joinColumns = reset($assoc['joinColumns']); - $calc->addDependency($targetClass->name, $class->name, (int) ! ( ! isset($joinColumns['nullable']) || $joinColumns['nullable'] === true)); + $calc->addDependency( + $targetClass->name, + $class->name, + (int) (($joinColumns['nullable'] ?? true) === false) + ); // If the target class has mapped subclasses, these share the same dependency. if ( ! $targetClass->subClasses) { From a0c0d3bf2a7f49020ad7e54d7d3319a251574230 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 22:29:45 +0200 Subject: [PATCH 486/877] Revert "Merge branch 'fix/#6499-#6533-fix-commit-order-calculation-consider-all-join-column-fields'" This reverts commit 2a58645cb5870f0ab61e918c7165c248d225dbac, reversing changes made to 6d428c90e24c914c1e5d817d74646f3b94757c43. --- lib/Doctrine/ORM/UnitOfWork.php | 6 +- .../ORM/Functional/Ticket/DDC6499Test.php | 96 ------------------- 2 files changed, 1 insertion(+), 101 deletions(-) delete mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 56615807f4e..c0b0dd8c302 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1154,11 +1154,7 @@ private function getCommitOrder(array $entityChangeSet = null) $joinColumns = reset($assoc['joinColumns']); - $calc->addDependency( - $targetClass->name, - $class->name, - (int) (($joinColumns['nullable'] ?? true) === false) - ); + $calc->addDependency($targetClass->name, $class->name, (int)empty($joinColumns['nullable'])); // If the target class has mapped subclasses, these share the same dependency. if ( ! $targetClass->subClasses) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php deleted file mode 100644 index 0d86fffb037..00000000000 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6499Test.php +++ /dev/null @@ -1,96 +0,0 @@ -_schemaTool->createSchema([ - $this->_em->getClassMetadata(DDC6499A::class), - $this->_em->getClassMetadata(DDC6499B::class), - ]); - } - - /** - * {@inheritDoc} - */ - protected function tearDown() : void - { - parent::tearDown(); - - $this->_schemaTool->dropSchema([ - $this->_em->getClassMetadata(DDC6499A::class), - $this->_em->getClassMetadata(DDC6499B::class), - ]); - } - - public function testIssue() : void - { - $b = new DDC6499B(); - $a = new DDC6499A(); - - $this->_em->persist($a); - - $a->b = $b; - - $this->_em->persist($b); - - $this->_em->flush(); - - self::assertInternalType('integer', $a->id); - self::assertInternalType('integer', $b->id); - } - - public function testIssueReversed() : void - { - $b = new DDC6499B(); - $a = new DDC6499A(); - - $a->b = $b; - - $this->_em->persist($b); - $this->_em->persist($a); - - $this->_em->flush(); - - self::assertInternalType('integer', $a->id); - self::assertInternalType('integer', $b->id); - } -} - -/** @Entity */ -class DDC6499A -{ - /** @Id @Column(type="integer") @GeneratedValue */ - public $id; - - /** @JoinColumn(nullable=false) @OneToOne(targetEntity=DDC6499B::class) */ - public $b; -} - -/** @Entity */ -class DDC6499B -{ - /** @Id @Column(type="integer") @GeneratedValue */ - public $id; - - /** @ManyToOne(targetEntity="DDC6499A") */ - private $a; -} From f0ed4e87b56d5b0b1090531fa468497b10856a6c Mon Sep 17 00:00:00 2001 From: Nikolas Tsiongas Date: Sun, 13 Aug 2017 22:42:09 +0200 Subject: [PATCH 487/877] fix AbstractHydrator addEventListener on hydrateAll() # Conflicts: # tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3146Test.php --- .../ORM/Internal/Hydration/AbstractHydrator.php | 3 +++ .../Tests/ORM/Hydration/AbstractHydratorTest.php | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index 6a7061285be..38bbacb4a6a 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -143,6 +143,9 @@ public function hydrateAll($stmt, $resultSetMapping, array $hints = []) $this->_rsm = $resultSetMapping; $this->_hints = $hints; + $evm = $this->_em->getEventManager(); + $evm->addEventListener(array(Events::onClear), $this); + $this->prepare(); $result = $this->hydrateAllData(); diff --git a/tests/Doctrine/Tests/ORM/Hydration/AbstractHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/AbstractHydratorTest.php index 1cd49d5ca7e..1d02b6c2bf8 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/AbstractHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/AbstractHydratorTest.php @@ -52,6 +52,17 @@ public function testOnClearEventListenerIsDetachedOnCleanup() ->method('removeEventListener') ->with([Events::onClear], $mockAbstractHydrator); + $mockEventManager + ->expects(self::at(2)) + ->method('addEventListener') + ->with([Events::onClear], $mockAbstractHydrator); + + $mockEventManager + ->expects(self::at(3)) + ->method('removeEventListener') + ->with([Events::onClear], $mockAbstractHydrator); + iterator_to_array($mockAbstractHydrator->iterate($mockStatement, $mockResultMapping)); + $mockAbstractHydrator->hydrateAll($mockStatement, $mockResultMapping); } } From b7ae5b4afba0e39599c39baba0c8e1051bb8ff91 Mon Sep 17 00:00:00 2001 From: Thomas Ploch Date: Tue, 1 Aug 2017 12:15:30 +0200 Subject: [PATCH 488/877] Entity listeners are now processed by exporters The current implementation of the exporters are not taking the entity listeners into account. I have added test cases for most of the edge cases I could think of and implemented the Exporter handling. This PR originates from https://github.com/doctrine/doctrine2/pull/5864, I was overwhelmed by the amount of conflicts I had to resolve so I started anew on a clean master HEAD. Squashed commits: - Code review aftermath - Add even more return type declarations - Added `return null` to methods declared with nullable return types - Removed unneeded docblocks when types are self-explanatory --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 379 ++++++------------ .../Export/Driver/AnnotationExporter.php | 6 +- .../ORM/Tools/Export/Driver/PhpExporter.php | 28 +- .../ORM/Tools/Export/Driver/XmlExporter.php | 66 ++- .../ORM/Tools/Export/Driver/YamlExporter.php | 33 +- .../AbstractClassMetadataExporterTest.php | 49 ++- .../Doctrine.Tests.ORM.Tools.Export.User.php | 11 +- .../Doctrine.Tests.ORM.Tools.Export.User.php | 14 +- ...ctrine.Tests.ORM.Tools.Export.User.dcm.xml | 12 + ...ctrine.Tests.ORM.Tools.Export.User.dcm.yml | 8 + 10 files changed, 324 insertions(+), 282 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index fafa51f3daa..9a282fa6bbd 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -346,7 +346,7 @@ public function __construct() * * @return void */ - public function generate(array $metadatas, $outputDirectory) + public function generate(array $metadatas, $outputDirectory): void { foreach ($metadatas as $metadata) { $this->writeEntityClass($metadata, $outputDirectory); @@ -363,7 +363,7 @@ public function generate(array $metadatas, $outputDirectory) * * @throws \RuntimeException */ - public function writeEntityClass(ClassMetadataInfo $metadata, $outputDirectory) + public function writeEntityClass(ClassMetadataInfo $metadata, $outputDirectory): void { $path = $outputDirectory . '/' . str_replace('\\', DIRECTORY_SEPARATOR, $metadata->name) . $this->extension; $dir = dirname($path); @@ -404,7 +404,7 @@ public function writeEntityClass(ClassMetadataInfo $metadata, $outputDirectory) * * @return string */ - public function generateEntityClass(ClassMetadataInfo $metadata) + public function generateEntityClass(ClassMetadataInfo $metadata): string { $placeHolders = [ '', @@ -435,7 +435,7 @@ public function generateEntityClass(ClassMetadataInfo $metadata) * * @return string */ - public function generateUpdatedEntityClass(ClassMetadataInfo $metadata, $path) + public function generateUpdatedEntityClass(ClassMetadataInfo $metadata, $path): string { $currentCode = file_get_contents($path); @@ -453,7 +453,7 @@ public function generateUpdatedEntityClass(ClassMetadataInfo $metadata, $path) * * @return void */ - public function setNumSpaces($numSpaces) + public function setNumSpaces($numSpaces): void { $this->spaces = str_repeat(' ', $numSpaces); $this->numSpaces = $numSpaces; @@ -466,7 +466,7 @@ public function setNumSpaces($numSpaces) * * @return void */ - public function setExtension($extension) + public function setExtension($extension): void { $this->extension = $extension; } @@ -478,7 +478,7 @@ public function setExtension($extension) * * @return void */ - public function setClassToExtend($classToExtend) + public function setClassToExtend($classToExtend): void { $this->classToExtend = $classToExtend; } @@ -490,7 +490,7 @@ public function setClassToExtend($classToExtend) * * @return void */ - public function setGenerateAnnotations($bool) + public function setGenerateAnnotations($bool): void { $this->generateAnnotations = $bool; } @@ -504,7 +504,7 @@ public function setGenerateAnnotations($bool) * * @throws \InvalidArgumentException */ - public function setFieldVisibility($visibility) + public function setFieldVisibility($visibility): void { if ($visibility !== static::FIELD_VISIBLE_PRIVATE && $visibility !== static::FIELD_VISIBLE_PROTECTED) { throw new \InvalidArgumentException('Invalid provided visibility (only private and protected are allowed): ' . $visibility); @@ -518,7 +518,7 @@ public function setFieldVisibility($visibility) * * @param boolean $embeddablesImmutable */ - public function setEmbeddablesImmutable($embeddablesImmutable) + public function setEmbeddablesImmutable($embeddablesImmutable): void { $this->embeddablesImmutable = (boolean) $embeddablesImmutable; } @@ -530,7 +530,7 @@ public function setEmbeddablesImmutable($embeddablesImmutable) * * @return void */ - public function setAnnotationPrefix($prefix) + public function setAnnotationPrefix($prefix): void { $this->annotationsPrefix = $prefix; } @@ -542,7 +542,7 @@ public function setAnnotationPrefix($prefix) * * @return void */ - public function setUpdateEntityIfExists($bool) + public function setUpdateEntityIfExists($bool): void { $this->updateEntityIfExists = $bool; } @@ -554,7 +554,7 @@ public function setUpdateEntityIfExists($bool) * * @return void */ - public function setRegenerateEntityIfExists($bool) + public function setRegenerateEntityIfExists($bool): void { $this->regenerateEntityIfExists = $bool; } @@ -566,7 +566,7 @@ public function setRegenerateEntityIfExists($bool) * * @return void */ - public function setGenerateStubMethods($bool) + public function setGenerateStubMethods($bool): void { $this->generateEntityStubMethods = $bool; } @@ -578,7 +578,7 @@ public function setGenerateStubMethods($bool) * * @return void */ - public function setBackupExisting($bool) + public function setBackupExisting($bool): void { $this->backupExisting = $bool; } @@ -588,7 +588,7 @@ public function setBackupExisting($bool) * * @return string */ - protected function getType($type) + protected function getType($type): string { if (isset($this->typeAlias[$type])) { return $this->typeAlias[$type]; @@ -602,20 +602,22 @@ protected function getType($type) * * @return string */ - protected function generateEntityNamespace(ClassMetadataInfo $metadata) + protected function generateEntityNamespace(ClassMetadataInfo $metadata): ?string { - if ($this->hasNamespace($metadata)) { - return 'namespace ' . $this->getNamespace($metadata) .';'; + if (!$this->hasNamespace($metadata)) { + return null; } + + return 'namespace ' . $this->getNamespace($metadata) .';'; } - protected function generateEntityUse() + protected function generateEntityUse(): ?string { - if ($this->generateAnnotations) { - return "\n".'use Doctrine\ORM\Mapping as ORM;'."\n"; - } else { - return ""; + if (!$this->generateAnnotations) { + return null; } + + return "\n".'use Doctrine\ORM\Mapping as ORM;'."\n"; } /** @@ -623,7 +625,7 @@ protected function generateEntityUse() * * @return string */ - protected function generateEntityClassName(ClassMetadataInfo $metadata) + protected function generateEntityClassName(ClassMetadataInfo $metadata): string { return 'class ' . $this->getClassName($metadata) . ($this->extendsClass() ? ' extends ' . $this->getClassToExtendName() : null); @@ -634,7 +636,7 @@ protected function generateEntityClassName(ClassMetadataInfo $metadata) * * @return string */ - protected function generateEntityBody(ClassMetadataInfo $metadata) + protected function generateEntityBody(ClassMetadataInfo $metadata): string { $fieldMappingProperties = $this->generateEntityFieldMappingProperties($metadata); $embeddedProperties = $this->generateEntityEmbeddedProperties($metadata); @@ -674,7 +676,7 @@ protected function generateEntityBody(ClassMetadataInfo $metadata) * * @return string */ - protected function generateEntityConstructor(ClassMetadataInfo $metadata) + protected function generateEntityConstructor(ClassMetadataInfo $metadata): string { if ($this->hasMethod('__construct', $metadata)) { return ''; @@ -704,7 +706,7 @@ protected function generateEntityConstructor(ClassMetadataInfo $metadata) * * @return string */ - private function generateEmbeddableConstructor(ClassMetadataInfo $metadata) + private function generateEmbeddableConstructor(ClassMetadataInfo $metadata): string { $paramTypes = []; $paramVariables = []; @@ -738,9 +740,7 @@ private function generateEmbeddableConstructor(ClassMetadataInfo $metadata) } foreach ($fieldMappings as $fieldMapping) { - if (isset($fieldMapping['declaredField']) && - isset($metadata->embeddedClasses[$fieldMapping['declaredField']]) - ) { + if (isset($fieldMapping['declaredField'], $metadata->embeddedClasses[$fieldMapping['declaredField']])) { continue; } @@ -800,7 +800,7 @@ function ($type, $variable) use ($maxParamTypeLength) { * * @return void */ - protected function parseTokensInEntityFile($src) + protected function parseTokensInEntityFile($src): void { $tokens = token_get_all($src); $tokensCount = count($tokens); @@ -848,13 +848,7 @@ protected function parseTokensInEntityFile($src) } } - /** - * @param string $property - * @param ClassMetadataInfo $metadata - * - * @return bool - */ - protected function hasProperty($property, ClassMetadataInfo $metadata) + protected function hasProperty(string $property, ClassMetadataInfo $metadata): bool { if ($this->extendsClass() || (!$this->isNew && class_exists($metadata->name))) { // don't generate property if its already on the base class. @@ -877,13 +871,7 @@ protected function hasProperty($property, ClassMetadataInfo $metadata) ); } - /** - * @param string $method - * @param ClassMetadataInfo $metadata - * - * @return bool - */ - protected function hasMethod($method, ClassMetadataInfo $metadata) + protected function hasMethod(string $method, ClassMetadataInfo $metadata): bool { if ($this->extendsClass() || (!$this->isNew && class_exists($metadata->name))) { // don't generate method if its already on the base class. @@ -907,20 +895,13 @@ protected function hasMethod($method, ClassMetadataInfo $metadata) ); } - /** - * @param ClassMetadataInfo $metadata - * - * @return array - */ - protected function getTraits(ClassMetadataInfo $metadata) + protected function getTraits(ClassMetadataInfo $metadata): array { if (! ($metadata->reflClass !== null || class_exists($metadata->name))) { return []; } - $reflClass = $metadata->reflClass === null - ? new \ReflectionClass($metadata->name) - : $metadata->reflClass; + $reflClass = $metadata->reflClass ?? new \ReflectionClass($metadata->name); $traits = []; @@ -933,69 +914,40 @@ protected function getTraits(ClassMetadataInfo $metadata) return $traits; } - /** - * @param ClassMetadataInfo $metadata - * - * @return bool - */ - protected function hasNamespace(ClassMetadataInfo $metadata) + protected function hasNamespace(ClassMetadataInfo $metadata): bool { return (bool) strpos($metadata->name, '\\'); } - /** - * @return bool - */ - protected function extendsClass() + protected function extendsClass(): bool { return (bool) $this->classToExtend; } - /** - * @return string - */ - protected function getClassToExtend() + protected function getClassToExtend(): ?string { return $this->classToExtend; } - /** - * @return string - */ - protected function getClassToExtendName() + protected function getClassToExtendName(): string { $refl = new \ReflectionClass($this->getClassToExtend()); return '\\' . $refl->getName(); } - /** - * @param ClassMetadataInfo $metadata - * - * @return string - */ - protected function getClassName(ClassMetadataInfo $metadata) + protected function getClassName(ClassMetadataInfo $metadata): string { return ($pos = strrpos($metadata->name, '\\')) ? substr($metadata->name, $pos + 1, strlen($metadata->name)) : $metadata->name; } - /** - * @param ClassMetadataInfo $metadata - * - * @return string - */ - protected function getNamespace(ClassMetadataInfo $metadata) + protected function getNamespace(ClassMetadataInfo $metadata): string { return substr($metadata->name, 0, strrpos($metadata->name, '\\')); } - /** - * @param ClassMetadataInfo $metadata - * - * @return string - */ - protected function generateEntityDocBlock(ClassMetadataInfo $metadata) + protected function generateEntityDocBlock(ClassMetadataInfo $metadata): string { $lines = []; $lines[] = '/**'; @@ -1010,6 +962,7 @@ protected function generateEntityDocBlock(ClassMetadataInfo $metadata) 'generateDiscriminatorColumnAnnotation', 'generateDiscriminatorMapAnnotation', 'generateEntityAnnotation', + 'generateEntityListenerAnnotation', ]; foreach ($methods as $method) { @@ -1028,12 +981,7 @@ protected function generateEntityDocBlock(ClassMetadataInfo $metadata) return implode("\n", $lines); } - /** - * @param ClassMetadataInfo $metadata - * - * @return string - */ - protected function generateEntityAnnotation(ClassMetadataInfo $metadata) + protected function generateEntityAnnotation(ClassMetadataInfo $metadata): string { $prefix = '@' . $this->annotationsPrefix; @@ -1048,12 +996,7 @@ protected function generateEntityAnnotation(ClassMetadataInfo $metadata) return $prefix . ($metadata->isMappedSuperclass ? 'MappedSuperclass' : 'Entity') . $customRepository; } - /** - * @param ClassMetadataInfo $metadata - * - * @return string - */ - protected function generateTableAnnotation(ClassMetadataInfo $metadata) + protected function generateTableAnnotation(ClassMetadataInfo $metadata): string { if ($metadata->isEmbeddedClass) { return ''; @@ -1086,13 +1029,7 @@ protected function generateTableAnnotation(ClassMetadataInfo $metadata) return '@' . $this->annotationsPrefix . 'Table(' . implode(', ', $table) . ')'; } - /** - * @param string $constraintName - * @param array $constraints - * - * @return string - */ - protected function generateTableConstraints($constraintName, array $constraints) + protected function generateTableConstraints(string $constraintName, array $constraints): string { $annotations = []; foreach ($constraints as $name => $constraint) { @@ -1106,75 +1043,57 @@ protected function generateTableConstraints($constraintName, array $constraints) return implode(', ', $annotations); } - /** - * @param ClassMetadataInfo $metadata - * - * @return string - */ - protected function generateInheritanceAnnotation(ClassMetadataInfo $metadata) + protected function generateInheritanceAnnotation(ClassMetadataInfo $metadata): ?string { - if ($metadata->inheritanceType != ClassMetadataInfo::INHERITANCE_TYPE_NONE) { - return '@' . $this->annotationsPrefix . 'InheritanceType("'.$this->getInheritanceTypeString($metadata->inheritanceType).'")'; + if ($metadata->inheritanceType === ClassMetadataInfo::INHERITANCE_TYPE_NONE) { + return null; } + + return '@' . $this->annotationsPrefix . 'InheritanceType("'.$this->getInheritanceTypeString($metadata->inheritanceType).'")'; } - /** - * @param ClassMetadataInfo $metadata - * - * @return string - */ - protected function generateDiscriminatorColumnAnnotation(ClassMetadataInfo $metadata) + protected function generateDiscriminatorColumnAnnotation(ClassMetadataInfo $metadata): ?string { - if ($metadata->inheritanceType != ClassMetadataInfo::INHERITANCE_TYPE_NONE) { - $discrColumn = $metadata->discriminatorColumn; - $columnDefinition = 'name="' . $discrColumn['name'] - . '", type="' . $discrColumn['type'] - . '", length=' . $discrColumn['length']; - - return '@' . $this->annotationsPrefix . 'DiscriminatorColumn(' . $columnDefinition . ')'; + if ($metadata->inheritanceType === ClassMetadataInfo::INHERITANCE_TYPE_NONE) { + return null; } + + $discrColumn = $metadata->discriminatorColumn; + $columnDefinition = 'name="' . $discrColumn['name'] + . '", type="' . $discrColumn['type'] + . '", length=' . $discrColumn['length']; + + return '@' . $this->annotationsPrefix . 'DiscriminatorColumn(' . $columnDefinition . ')'; } - /** - * @param ClassMetadataInfo $metadata - * - * @return string - */ - protected function generateDiscriminatorMapAnnotation(ClassMetadataInfo $metadata) + protected function generateDiscriminatorMapAnnotation(ClassMetadataInfo $metadata): ?string { - if ($metadata->inheritanceType != ClassMetadataInfo::INHERITANCE_TYPE_NONE) { - $inheritanceClassMap = []; + if ($metadata->inheritanceType === ClassMetadataInfo::INHERITANCE_TYPE_NONE) { + return null; + } - foreach ($metadata->discriminatorMap as $type => $class) { - $inheritanceClassMap[] .= '"' . $type . '" = "' . $class . '"'; - } + $inheritanceClassMap = []; - return '@' . $this->annotationsPrefix . 'DiscriminatorMap({' . implode(', ', $inheritanceClassMap) . '})'; + foreach ($metadata->discriminatorMap as $type => $class) { + $inheritanceClassMap[] .= '"' . $type . '" = "' . $class . '"'; } + + return '@' . $this->annotationsPrefix . 'DiscriminatorMap({' . implode(', ', $inheritanceClassMap) . '})'; } - /** - * @param ClassMetadataInfo $metadata - * - * @return string - */ - protected function generateEntityStubMethods(ClassMetadataInfo $metadata) + protected function generateEntityStubMethods(ClassMetadataInfo $metadata): string { $methods = []; foreach ($metadata->fieldMappings as $fieldMapping) { - if (isset($fieldMapping['declaredField']) && - isset($metadata->embeddedClasses[$fieldMapping['declaredField']]) - ) { + if (isset($fieldMapping['declaredField'], $metadata->embeddedClasses[$fieldMapping['declaredField']])) { continue; } $nullableField = $this->nullableFieldExpression($fieldMapping); - if (( ! isset($fieldMapping['id']) || - ! $fieldMapping['id'] || - $metadata->generatorType == ClassMetadataInfo::GENERATOR_TYPE_NONE - ) && (! $metadata->isEmbeddedClass || ! $this->embeddablesImmutable) + if ((!$metadata->isEmbeddedClass || !$this->embeddablesImmutable) + && (!isset($fieldMapping['id']) || ! $fieldMapping['id'] || $metadata->generatorType === ClassMetadataInfo::GENERATOR_TYPE_NONE) && $code = $this->generateEntityStubMethod($metadata, 'set', $fieldMapping['fieldName'], $fieldMapping['type'], $nullableField) ) { $methods[] = $code; @@ -1226,12 +1145,7 @@ protected function generateEntityStubMethods(ClassMetadataInfo $metadata) return implode("\n\n", $methods); } - /** - * @param array $associationMapping - * - * @return bool - */ - protected function isAssociationIsNullable(array $associationMapping) + protected function isAssociationIsNullable(array $associationMapping): bool { if (isset($associationMapping['id']) && $associationMapping['id']) { return false; @@ -1253,15 +1167,10 @@ protected function isAssociationIsNullable(array $associationMapping) return true; } - /** - * @param ClassMetadataInfo $metadata - * - * @return string - */ - protected function generateEntityLifecycleCallbackMethods(ClassMetadataInfo $metadata) + protected function generateEntityLifecycleCallbackMethods(ClassMetadataInfo $metadata): ?string { if (empty($metadata->lifecycleCallbacks)) { - return ''; + return null; } $methods = []; @@ -1275,12 +1184,7 @@ protected function generateEntityLifecycleCallbackMethods(ClassMetadataInfo $met return implode("\n\n", array_filter($methods)); } - /** - * @param ClassMetadataInfo $metadata - * - * @return string - */ - protected function generateEntityAssociationMappingProperties(ClassMetadataInfo $metadata) + protected function generateEntityAssociationMappingProperties(ClassMetadataInfo $metadata): string { $lines = []; @@ -1297,22 +1201,14 @@ protected function generateEntityAssociationMappingProperties(ClassMetadataInfo return implode("\n", $lines); } - /** - * @param ClassMetadataInfo $metadata - * - * @return string - */ - protected function generateEntityFieldMappingProperties(ClassMetadataInfo $metadata) + protected function generateEntityFieldMappingProperties(ClassMetadataInfo $metadata): string { $lines = []; foreach ($metadata->fieldMappings as $fieldMapping) { - if ($this->hasProperty($fieldMapping['fieldName'], $metadata) || - $metadata->isInheritedField($fieldMapping['fieldName']) || - ( - isset($fieldMapping['declaredField']) && - isset($metadata->embeddedClasses[$fieldMapping['declaredField']]) - ) + if (isset($fieldMapping['declaredField'], $metadata->embeddedClasses[$fieldMapping['declaredField']]) || + $this->hasProperty($fieldMapping['fieldName'], $metadata) || + $metadata->isInheritedField($fieldMapping['fieldName']) ) { continue; } @@ -1325,12 +1221,7 @@ protected function generateEntityFieldMappingProperties(ClassMetadataInfo $metad return implode("\n", $lines); } - /** - * @param ClassMetadataInfo $metadata - * - * @return string - */ - protected function generateEntityEmbeddedProperties(ClassMetadataInfo $metadata) + protected function generateEntityEmbeddedProperties(ClassMetadataInfo $metadata): string { $lines = []; @@ -1346,16 +1237,12 @@ protected function generateEntityEmbeddedProperties(ClassMetadataInfo $metadata) return implode("\n", $lines); } - /** - * @param ClassMetadataInfo $metadata - * @param string $type - * @param string $fieldName - * @param string|null $typeHint - * @param string|null $defaultValue - * - * @return string - */ - protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null) + protected function generateEntityStubMethod( + ClassMetadataInfo $metadata, + string $type, + string $fieldName, + ?string $typeHint = null, + ?string $defaultValue = null): string { $methodName = $type . Inflector::classify($fieldName); $variableName = Inflector::camelize($fieldName); @@ -1401,18 +1288,12 @@ protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, return $this->prefixCodeWithSpaces($method); } - /** - * @param string $name - * @param string $methodName - * @param ClassMetadataInfo $metadata - * - * @return string - */ - protected function generateLifecycleCallbackMethod($name, $methodName, ClassMetadataInfo $metadata) + protected function generateLifecycleCallbackMethod(string $name, string $methodName, ClassMetadataInfo $metadata): ?string { if ($this->hasMethod($methodName, $metadata)) { - return ''; + return null; } + $this->staticReflection[$metadata->name]['methods'][] = $methodName; $replacements = [ @@ -1429,12 +1310,7 @@ protected function generateLifecycleCallbackMethod($name, $methodName, ClassMeta return $this->prefixCodeWithSpaces($method); } - /** - * @param array $joinColumn - * - * @return string - */ - protected function generateJoinColumnAnnotation(array $joinColumn) + protected function generateJoinColumnAnnotation(array $joinColumn): string { $joinColumnAnnot = []; @@ -1465,13 +1341,7 @@ protected function generateJoinColumnAnnotation(array $joinColumn) return '@' . $this->annotationsPrefix . 'JoinColumn(' . implode(', ', $joinColumnAnnot) . ')'; } - /** - * @param array $associationMapping - * @param ClassMetadataInfo $metadata - * - * @return string - */ - protected function generateAssociationMappingPropertyDocBlock(array $associationMapping, ClassMetadataInfo $metadata) + protected function generateAssociationMappingPropertyDocBlock(array $associationMapping, ClassMetadataInfo $metadata): string { $lines = []; $lines[] = $this->spaces . '/**'; @@ -1617,13 +1487,7 @@ protected function generateAssociationMappingPropertyDocBlock(array $association return implode("\n", $lines); } - /** - * @param array $fieldMapping - * @param ClassMetadataInfo $metadata - * - * @return string - */ - protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, ClassMetadataInfo $metadata) + protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, ClassMetadataInfo $metadata): string { $lines = []; $lines[] = $this->spaces . '/**'; @@ -1715,12 +1579,7 @@ protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, Cla return implode("\n", $lines); } - /** - * @param array $embeddedClass - * - * @return string - */ - protected function generateEmbeddedPropertyDocBlock(array $embeddedClass) + protected function generateEmbeddedPropertyDocBlock(array $embeddedClass): string { $lines = []; $lines[] = $this->spaces . '/**'; @@ -1748,13 +1607,28 @@ protected function generateEmbeddedPropertyDocBlock(array $embeddedClass) return implode("\n", $lines); } - /** - * @param string $code - * @param int $num - * - * @return string - */ - protected function prefixCodeWithSpaces($code, $num = 1) + protected function generateEntityListenerAnnotation(ClassMetadataInfo $metadata): ?string + { + if (0 === \count($metadata->entityListeners)) { + return null; + } + + $processedClasses = []; + foreach ($metadata->entityListeners as $event => $eventListeners) { + foreach ($eventListeners as $eventListener) { + $processedClasses[] = '"' . $eventListener['class'] . '"'; + } + } + + return \sprintf( + '%s%s({%s})', + '@' . $this->annotationsPrefix, + 'EntityListeners', + \implode(',', \array_unique($processedClasses)) + ); + } + + protected function prefixCodeWithSpaces($code, $num = 1): string { $lines = explode("\n", $code); @@ -1774,7 +1648,7 @@ protected function prefixCodeWithSpaces($code, $num = 1) * * @throws \InvalidArgumentException When the inheritance type does not exist. */ - protected function getInheritanceTypeString($type) + protected function getInheritanceTypeString($type): string { if ( ! isset(static::$inheritanceTypeMap[$type])) { throw new \InvalidArgumentException(sprintf('Invalid provided InheritanceType: %s', $type)); @@ -1790,7 +1664,7 @@ protected function getInheritanceTypeString($type) * * @throws \InvalidArgumentException When the change-tracking type does not exist. */ - protected function getChangeTrackingPolicyString($type) + protected function getChangeTrackingPolicyString($type): string { if ( ! isset(static::$changeTrackingPolicyMap[$type])) { throw new \InvalidArgumentException(sprintf('Invalid provided ChangeTrackingPolicy: %s', $type)); @@ -1806,7 +1680,7 @@ protected function getChangeTrackingPolicyString($type) * * @throws \InvalidArgumentException When the generator type does not exist. */ - protected function getIdGeneratorTypeString($type) + protected function getIdGeneratorTypeString($type): string { if ( ! isset(static::$generatorStrategyMap[$type])) { throw new \InvalidArgumentException(sprintf('Invalid provided IdGeneratorType: %s', $type)); @@ -1815,12 +1689,7 @@ protected function getIdGeneratorTypeString($type) return static::$generatorStrategyMap[$type]; } - /** - * @param array $fieldMapping - * - * @return string|null - */ - private function nullableFieldExpression(array $fieldMapping) + private function nullableFieldExpression(array $fieldMapping): ?string { if (isset($fieldMapping['nullable']) && true === $fieldMapping['nullable']) { return 'null'; @@ -1836,7 +1705,7 @@ private function nullableFieldExpression(array $fieldMapping) * * @return string */ - private function exportTableOptions(array $options) + private function exportTableOptions(array $options): string { $optionsStr = []; diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php index 044a1da53a8..43d1201615f 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php @@ -44,7 +44,7 @@ class AnnotationExporter extends AbstractExporter /** * {@inheritdoc} */ - public function exportClassMetadata(ClassMetadataInfo $metadata) + public function exportClassMetadata(ClassMetadataInfo $metadata): string { if ( ! $this->_entityGenerator) { throw new \RuntimeException('For the AnnotationExporter you must set an EntityGenerator instance with the setEntityGenerator() method.'); @@ -63,7 +63,7 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) * * @return string */ - protected function _generateOutputPath(ClassMetadataInfo $metadata) + protected function _generateOutputPath(ClassMetadataInfo $metadata): string { return $this->_outputDir . '/' . str_replace('\\', '/', $metadata->name) . $this->_extension; } @@ -73,7 +73,7 @@ protected function _generateOutputPath(ClassMetadataInfo $metadata) * * @return void */ - public function setEntityGenerator(EntityGenerator $entityGenerator) + public function setEntityGenerator(EntityGenerator $entityGenerator): void { $this->_entityGenerator = $entityGenerator; } diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php index 69db59f784a..5054743aa35 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php @@ -38,7 +38,7 @@ class PhpExporter extends AbstractExporter /** * {@inheritdoc} */ - public function exportClassMetadata(ClassMetadataInfo $metadata) + public function exportClassMetadata(ClassMetadataInfo $metadata): string { $lines = []; $lines[] = 'processEntityListeners($metadata)); + foreach ($metadata->fieldMappings as $fieldMapping) { $lines[] = '$metadata->mapField(' . $this->_varExport($fieldMapping) . ');'; } @@ -164,7 +166,7 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) * * @return string */ - protected function _varExport($var) + protected function _varExport($var): string { $export = var_export($var, true); $export = str_replace("\n", PHP_EOL . str_repeat(' ', 8), $export); @@ -177,4 +179,26 @@ protected function _varExport($var) return $export; } + + private function processEntityListeners(ClassMetadataInfo $metadata): array + { + $lines = []; + + if (0 === \count($metadata->entityListeners)) { + return $lines; + } + + foreach ($metadata->entityListeners as $event => $entityListenerConfig) { + foreach ($entityListenerConfig as $entityListener) { + $lines[] = sprintf( + '$metadata->addEntityListener(%s, %s, %s);', + var_export($event, true), + var_export($entityListener['class'], true), + var_export($entityListener['method'], true) + ); + } + } + + return $lines; + } } diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php index c4eb8f63792..fb45516eb13 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php @@ -20,6 +20,7 @@ namespace Doctrine\ORM\Tools\Export\Driver; use Doctrine\ORM\Mapping\ClassMetadataInfo; +use SimpleXMLElement; /** * ClassMetadata exporter for Doctrine XML mapping files. @@ -38,9 +39,9 @@ class XmlExporter extends AbstractExporter /** * {@inheritdoc} */ - public function exportClassMetadata(ClassMetadataInfo $metadata) + public function exportClassMetadata(ClassMetadataInfo $metadata): string { - $xml = new \SimpleXmlElement(""); @@ -390,16 +391,18 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) } } + $this->processEntityListeners($metadata, $root); + return $this->_asXml($xml); } /** * Exports (nested) option elements. * - * @param \SimpleXMLElement $parentXml - * @param array $options + * @param SimpleXMLElement $parentXml + * @param array $options */ - private function exportTableOptions(\SimpleXMLElement $parentXml, array $options) + private function exportTableOptions(SimpleXMLElement $parentXml, array $options): void { foreach ($options as $name => $option) { $isArray = is_array($option); @@ -418,12 +421,12 @@ private function exportTableOptions(\SimpleXMLElement $parentXml, array $options /** * Export sequence information (if available/configured) into the current identifier XML node * - * @param \SimpleXMLElement $identifierXmlNode + * @param SimpleXMLElement $identifierXmlNode * @param ClassMetadataInfo $metadata * * @return void */ - private function exportSequenceInformation(\SimpleXMLElement $identifierXmlNode, ClassMetadataInfo $metadata) + private function exportSequenceInformation(SimpleXMLElement $identifierXmlNode, ClassMetadataInfo $metadata): void { $sequenceDefinition = $metadata->sequenceGeneratorDefinition; @@ -438,12 +441,7 @@ private function exportSequenceInformation(\SimpleXMLElement $identifierXmlNode, $sequenceGeneratorXml->addAttribute('initial-value', $sequenceDefinition['initialValue']); } - /** - * @param \SimpleXMLElement $simpleXml - * - * @return string $xml - */ - private function _asXml($simpleXml) + private function _asXml(SimpleXMLElement $simpleXml): string { $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->loadXML($simpleXml->asXML()); @@ -451,4 +449,46 @@ private function _asXml($simpleXml) return $dom->saveXML(); } + + private function processEntityListeners(ClassMetadataInfo $metadata, SimpleXMLElement $root): void + { + if (0 === \count($metadata->entityListeners)) { + return; + } + + $entityListenersXml = $root->addChild('entity-listeners'); + $entityListenersXmlMap = []; + + $this->generateEntityListenerXml($metadata, $entityListenersXmlMap, $entityListenersXml); + } + + private function generateEntityListenerXml(ClassMetadataInfo $metadata, array $entityListenersXmlMap, SimpleXMLElement $entityListenersXml): void + { + foreach ($metadata->entityListeners as $event => $entityListenerConfig) { + foreach ($entityListenerConfig as $entityListener) { + $entityListenerXml = $this->addClassToMapIfExists( + $entityListenersXmlMap, + $entityListener, + $entityListenersXml + ); + + $entityListenerCallbackXml = $entityListenerXml->addChild('lifecycle-callback'); + $entityListenerCallbackXml->addAttribute('type', $event); + $entityListenerCallbackXml->addAttribute('method', $entityListener['method']); + } + } + } + + private function addClassToMapIfExists(array $entityListenersXmlMap, array $entityListener, SimpleXMLElement $entityListenersXml): SimpleXMLElement + { + if (isset($entityListenersXmlMap[$entityListener['class']])) { + return $entityListenersXmlMap[$entityListener['class']]; + } + + $entityListenerXml = $entityListenersXml->addChild('entity-listener'); + $entityListenerXml->addAttribute('class', $entityListener['class']); + $entityListenersXmlMap[$entityListener['class']] = $entityListenerXml; + + return $entityListenerXml; + } } diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php index b9a38f9046f..053ad58972c 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php @@ -39,7 +39,7 @@ class YamlExporter extends AbstractExporter /** * {@inheritdoc} */ - public function exportClassMetadata(ClassMetadataInfo $metadata) + public function exportClassMetadata(ClassMetadataInfo $metadata): string { $array = []; @@ -214,6 +214,8 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) $array['lifecycleCallbacks'] = $metadata->lifecycleCallbacks; } + $array = $this->processEntityListeners($metadata, $array); + return $this->yamlDump([$metadata->name => $array], 10); } @@ -228,8 +230,35 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) * * @return string A YAML string representing the original PHP array */ - protected function yamlDump($array, $inline = 2) + protected function yamlDump($array, $inline = 2): string { return Yaml::dump($array, $inline); } + + private function processEntityListeners(ClassMetadataInfo $metadata, array $array): array + { + if (0 === \count($metadata->entityListeners)) { + return $array; + } + + $array['entityListeners'] = []; + + foreach ($metadata->entityListeners as $event => $entityListenerConfig) { + $array = $this->processEntityListenerConfig($array, $entityListenerConfig, $event); + } + + return $array; + } + + private function processEntityListenerConfig(array $array, array $entityListenerConfig, string $event): array + { + foreach ($entityListenerConfig as $entityListener) { + if (!isset($array['entityListeners'][$entityListener['class']])) { + $array['entityListeners'][$entityListener['class']] = []; + } + $array['entityListeners'][$entityListener['class']][$event] = [$entityListener['method']]; + } + + return $array; + } } diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php index e9523b5b1df..a74af72a17f 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php @@ -5,6 +5,8 @@ use Doctrine\Common\EventManager; use Doctrine\Common\Persistence\Mapping\Driver\PHPDriver; use Doctrine\ORM\Configuration; +use Doctrine\ORM\Events; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; @@ -344,7 +346,7 @@ public function testInversedByIsExported($class) { $this->assertEquals('user', $class->associationMappings['address']['inversedBy']); } - /** + /** * @depends testExportDirectoryAndFilesAreCreated */ public function testCascadeAllCollapsed() @@ -371,6 +373,26 @@ public function testCascadeAllCollapsed() } } + /** + * @depends testExportedMetadataCanBeReadBackIn + * + * @param ClassMetadata $class + */ + public function testEntityListenersAreExported($class) + { + $this->assertNotEmpty($class->entityListeners); + $this->assertCount(2, $class->entityListeners[Events::prePersist]); + $this->assertCount(2, $class->entityListeners[Events::postPersist]); + $this->assertEquals(UserListener::class, $class->entityListeners[Events::prePersist][0]['class']); + $this->assertEquals('customPrePersist', $class->entityListeners[Events::prePersist][0]['method']); + $this->assertEquals(GroupListener::class, $class->entityListeners[Events::prePersist][1]['class']); + $this->assertEquals('prePersist', $class->entityListeners[Events::prePersist][1]['method']); + $this->assertEquals(UserListener::class, $class->entityListeners[Events::postPersist][0]['class']); + $this->assertEquals('customPostPersist', $class->entityListeners[Events::postPersist][0]['method']); + $this->assertEquals(AddressListener::class, $class->entityListeners[Events::postPersist][1]['class']); + $this->assertEquals('customPostPersist', $class->entityListeners[Events::postPersist][1]['method']); + } + public function __destruct() { # $this->_deleteDirectory(__DIR__ . '/export/'.$this->_getType()); @@ -406,3 +428,28 @@ class Group { } +class UserListener +{ + /** + * @\Doctrine\ORM\Mapping\PrePersist + */ + public function customPrePersist(): void {} + /** + * @\Doctrine\ORM\Mapping\PostPersist + */ + public function customPostPersist(): void {} +} +class GroupListener +{ + /** + * @\Doctrine\ORM\Mapping\PrePersist + */ + public function prePersist(): void {} +} +class AddressListener +{ + /** + * @\Doctrine\ORM\Mapping\PostPersist + */ + public function customPostPersist(): void {} +} diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/annotation/Doctrine.Tests.ORM.Tools.Export.User.php b/tests/Doctrine/Tests/ORM/Tools/Export/annotation/Doctrine.Tests.ORM.Tools.Export.User.php index 34470805953..c6a066258f4 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/annotation/Doctrine.Tests.ORM.Tools.Export.User.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/annotation/Doctrine.Tests.ORM.Tools.Export.User.php @@ -5,6 +5,11 @@ /** * @Entity * @HasLifecycleCallbacks + * @EntityListeners({ + * Doctrine\Tests\ORM\Tools\Export\UserListener::class, + * Doctrine\Tests\ORM\Tools\Export\GroupListener::class, + * Doctrine\Tests\ORM\Tools\Export\AddressListener::class + * }) * @Table(name="cms_users",options={"engine"="MyISAM","foo"={"bar"="baz"}}) */ class User @@ -57,21 +62,21 @@ class User /** * @PrePersist */ - public function doStuffOnPrePersist() + public function doStuffOnPrePersist(): void { } /** * @PrePersist */ - public function doOtherStuffOnPrePersistToo() + public function doOtherStuffOnPrePersistToo(): void { } /** * @PostPersist */ - public function doStuffOnPostPersist() + public function doStuffOnPostPersist(): void { } } diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/php/Doctrine.Tests.ORM.Tools.Export.User.php b/tests/Doctrine/Tests/ORM/Tools/Export/php/Doctrine.Tests.ORM.Tools.Export.User.php index 5c8a0c013ba..5e54c0b2e7e 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/php/Doctrine.Tests.ORM.Tools.Export.User.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/php/Doctrine.Tests.ORM.Tools.Export.User.php @@ -1,7 +1,11 @@ setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE); $metadata->setPrimaryTable( @@ -11,9 +15,9 @@ ] ); $metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT); -$metadata->addLifecycleCallback('doStuffOnPrePersist', 'prePersist'); -$metadata->addLifecycleCallback('doOtherStuffOnPrePersistToo', 'prePersist'); -$metadata->addLifecycleCallback('doStuffOnPostPersist', 'postPersist'); +$metadata->addLifecycleCallback('doStuffOnPrePersist', Events::prePersist); +$metadata->addLifecycleCallback('doOtherStuffOnPrePersistToo', Events::prePersist); +$metadata->addLifecycleCallback('doStuffOnPostPersist', Events::postPersist); $metadata->mapField( [ 'id' => true, @@ -149,3 +153,7 @@ 'orderBy' => NULL, ] ); +$metadata->addEntityListener(Events::prePersist, UserListener::class, 'customPrePersist'); +$metadata->addEntityListener(Events::postPersist, UserListener::class, 'customPostPersist'); +$metadata->addEntityListener(Events::prePersist, GroupListener::class, 'prePersist'); +$metadata->addEntityListener(Events::postPersist, AddressListener::class, 'customPostPersist'); diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml b/tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml index 8d0c5d217e3..78bac4f5f3f 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml @@ -77,6 +77,18 @@ + + + + + + + + + + + + diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/yaml/Doctrine.Tests.ORM.Tools.Export.User.dcm.yml b/tests/Doctrine/Tests/ORM/Tools/Export/yaml/Doctrine.Tests.ORM.Tools.Export.User.dcm.yml index d52e94601da..df2dae1c558 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/yaml/Doctrine.Tests.ORM.Tools.Export.User.dcm.yml +++ b/tests/Doctrine/Tests/ORM/Tools/Export/yaml/Doctrine.Tests.ORM.Tools.Export.User.dcm.yml @@ -75,3 +75,11 @@ Doctrine\Tests\ORM\Tools\Export\User: lifecycleCallbacks: prePersist: [ doStuffOnPrePersist, doOtherStuffOnPrePersistToo ] postPersist: [ doStuffOnPostPersist ] + entityListeners: + Doctrine\Tests\ORM\Tools\Export\UserListener: + prePersist: [customPrePersist] + postPersist: [customPostPersist] + Doctrine\Tests\ORM\Tools\Export\GroupListener: + prePersist: [prePersist] + Doctrine\Tests\ORM\Tools\Export\AddressListener: + postPersist: [customPostPersist] From ec3eed68ca0551edc33fb1dc94a604d84857a122 Mon Sep 17 00:00:00 2001 From: Thomas Ploch Date: Tue, 15 Aug 2017 10:17:20 +0200 Subject: [PATCH 489/877] Minor coding style fixes and more docblock removal --- .../ORM/Tools/Export/Driver/AnnotationExporter.php | 12 +----------- .../ORM/Tools/Export/Driver/PhpExporter.php | 13 ++++--------- .../ORM/Tools/Export/Driver/XmlExporter.php | 14 +++++++------- 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php index 43d1201615f..d14ca926398 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php @@ -46,7 +46,7 @@ class AnnotationExporter extends AbstractExporter */ public function exportClassMetadata(ClassMetadataInfo $metadata): string { - if ( ! $this->_entityGenerator) { + if (!$this->_entityGenerator) { throw new \RuntimeException('For the AnnotationExporter you must set an EntityGenerator instance with the setEntityGenerator() method.'); } @@ -58,21 +58,11 @@ public function exportClassMetadata(ClassMetadataInfo $metadata): string return $this->_entityGenerator->generateEntityClass($metadata); } - /** - * @param \Doctrine\ORM\Mapping\ClassMetadataInfo $metadata - * - * @return string - */ protected function _generateOutputPath(ClassMetadataInfo $metadata): string { return $this->_outputDir . '/' . str_replace('\\', '/', $metadata->name) . $this->_extension; } - /** - * @param \Doctrine\ORM\Tools\EntityGenerator $entityGenerator - * - * @return void - */ public function setEntityGenerator(EntityGenerator $entityGenerator): void { $this->_entityGenerator = $entityGenerator; diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php index 5054743aa35..cecefeab8b3 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php @@ -161,11 +161,6 @@ public function exportClassMetadata(ClassMetadataInfo $metadata): string return implode("\n", $lines); } - /** - * @param mixed $var - * - * @return string - */ protected function _varExport($var): string { $export = var_export($var, true); @@ -190,11 +185,11 @@ private function processEntityListeners(ClassMetadataInfo $metadata): array foreach ($metadata->entityListeners as $event => $entityListenerConfig) { foreach ($entityListenerConfig as $entityListener) { - $lines[] = sprintf( + $lines[] = \sprintf( '$metadata->addEntityListener(%s, %s, %s);', - var_export($event, true), - var_export($entityListener['class'], true), - var_export($entityListener['method'], true) + \var_export($event, true), + \var_export($entityListener['class'], true), + \var_export($entityListener['method'], true) ); } } diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php index fb45516eb13..0776a069434 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php @@ -41,10 +41,10 @@ class XmlExporter extends AbstractExporter */ public function exportClassMetadata(ClassMetadataInfo $metadata): string { - $xml = new SimpleXmlElement(""); + $xml = new SimpleXmlElement(''); if ($metadata->isMappedSuperclass) { $root = $xml->addChild('mapped-superclass'); @@ -98,7 +98,7 @@ public function exportClassMetadata(ClassMetadataInfo $metadata): string $trackingPolicy = $this->_getChangeTrackingPolicyString($metadata->changeTrackingPolicy); - if ( $trackingPolicy != 'DEFERRED_IMPLICIT') { + if ($trackingPolicy != 'DEFERRED_IMPLICIT') { $root->addChild('change-tracking-policy', $trackingPolicy); } @@ -144,7 +144,7 @@ public function exportClassMetadata(ClassMetadataInfo $metadata): string } } - if ( ! $metadata->isIdentifierComposite && $idGeneratorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) { + if (!$metadata->isIdentifierComposite && $idGeneratorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) { $id[$metadata->getSingleIdentifierFieldName()]['generator']['strategy'] = $idGeneratorType; } @@ -430,7 +430,7 @@ private function exportSequenceInformation(SimpleXMLElement $identifierXmlNode, { $sequenceDefinition = $metadata->sequenceGeneratorDefinition; - if (! ($metadata->generatorType === ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE && $sequenceDefinition)) { + if (!($metadata->generatorType === ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE && $sequenceDefinition)) { return; } From 741819f060e750a8bb94a774827dc2c5502cc4a7 Mon Sep 17 00:00:00 2001 From: Thomas Ploch Date: Tue, 15 Aug 2017 10:28:43 +0200 Subject: [PATCH 490/877] Revert "Minor coding style fixes and more docblock removal" This reverts commit ec3eed68ca0551edc33fb1dc94a604d84857a122. --- .../ORM/Tools/Export/Driver/AnnotationExporter.php | 12 +++++++++++- .../ORM/Tools/Export/Driver/PhpExporter.php | 13 +++++++++---- .../ORM/Tools/Export/Driver/XmlExporter.php | 14 +++++++------- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php index d14ca926398..43d1201615f 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php @@ -46,7 +46,7 @@ class AnnotationExporter extends AbstractExporter */ public function exportClassMetadata(ClassMetadataInfo $metadata): string { - if (!$this->_entityGenerator) { + if ( ! $this->_entityGenerator) { throw new \RuntimeException('For the AnnotationExporter you must set an EntityGenerator instance with the setEntityGenerator() method.'); } @@ -58,11 +58,21 @@ public function exportClassMetadata(ClassMetadataInfo $metadata): string return $this->_entityGenerator->generateEntityClass($metadata); } + /** + * @param \Doctrine\ORM\Mapping\ClassMetadataInfo $metadata + * + * @return string + */ protected function _generateOutputPath(ClassMetadataInfo $metadata): string { return $this->_outputDir . '/' . str_replace('\\', '/', $metadata->name) . $this->_extension; } + /** + * @param \Doctrine\ORM\Tools\EntityGenerator $entityGenerator + * + * @return void + */ public function setEntityGenerator(EntityGenerator $entityGenerator): void { $this->_entityGenerator = $entityGenerator; diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php index cecefeab8b3..5054743aa35 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php @@ -161,6 +161,11 @@ public function exportClassMetadata(ClassMetadataInfo $metadata): string return implode("\n", $lines); } + /** + * @param mixed $var + * + * @return string + */ protected function _varExport($var): string { $export = var_export($var, true); @@ -185,11 +190,11 @@ private function processEntityListeners(ClassMetadataInfo $metadata): array foreach ($metadata->entityListeners as $event => $entityListenerConfig) { foreach ($entityListenerConfig as $entityListener) { - $lines[] = \sprintf( + $lines[] = sprintf( '$metadata->addEntityListener(%s, %s, %s);', - \var_export($event, true), - \var_export($entityListener['class'], true), - \var_export($entityListener['method'], true) + var_export($event, true), + var_export($entityListener['class'], true), + var_export($entityListener['method'], true) ); } } diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php index 0776a069434..fb45516eb13 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php @@ -41,10 +41,10 @@ class XmlExporter extends AbstractExporter */ public function exportClassMetadata(ClassMetadataInfo $metadata): string { - $xml = new SimpleXmlElement(''); + $xml = new SimpleXmlElement(""); if ($metadata->isMappedSuperclass) { $root = $xml->addChild('mapped-superclass'); @@ -98,7 +98,7 @@ public function exportClassMetadata(ClassMetadataInfo $metadata): string $trackingPolicy = $this->_getChangeTrackingPolicyString($metadata->changeTrackingPolicy); - if ($trackingPolicy != 'DEFERRED_IMPLICIT') { + if ( $trackingPolicy != 'DEFERRED_IMPLICIT') { $root->addChild('change-tracking-policy', $trackingPolicy); } @@ -144,7 +144,7 @@ public function exportClassMetadata(ClassMetadataInfo $metadata): string } } - if (!$metadata->isIdentifierComposite && $idGeneratorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) { + if ( ! $metadata->isIdentifierComposite && $idGeneratorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) { $id[$metadata->getSingleIdentifierFieldName()]['generator']['strategy'] = $idGeneratorType; } @@ -430,7 +430,7 @@ private function exportSequenceInformation(SimpleXMLElement $identifierXmlNode, { $sequenceDefinition = $metadata->sequenceGeneratorDefinition; - if (!($metadata->generatorType === ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE && $sequenceDefinition)) { + if (! ($metadata->generatorType === ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE && $sequenceDefinition)) { return; } From fe88422e68d49636d3bf9f5cdca7da72a75ca40a Mon Sep 17 00:00:00 2001 From: Thomas Ploch Date: Wed, 16 Aug 2017 12:24:00 +0200 Subject: [PATCH 491/877] [CS] Remove obsolete doc blocks --- .../ORM/Tools/Export/Driver/AnnotationExporter.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php index 43d1201615f..5f2a42e6c0a 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php @@ -58,21 +58,11 @@ public function exportClassMetadata(ClassMetadataInfo $metadata): string return $this->_entityGenerator->generateEntityClass($metadata); } - /** - * @param \Doctrine\ORM\Mapping\ClassMetadataInfo $metadata - * - * @return string - */ protected function _generateOutputPath(ClassMetadataInfo $metadata): string { return $this->_outputDir . '/' . str_replace('\\', '/', $metadata->name) . $this->_extension; } - /** - * @param \Doctrine\ORM\Tools\EntityGenerator $entityGenerator - * - * @return void - */ public function setEntityGenerator(EntityGenerator $entityGenerator): void { $this->_entityGenerator = $entityGenerator; From 599865528ecb32688d4109c498c78353a25654be Mon Sep 17 00:00:00 2001 From: Thomas Ploch Date: Wed, 16 Aug 2017 12:24:37 +0200 Subject: [PATCH 492/877] [CS] Remove obsolete doc blocks #2 --- lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php index 5054743aa35..4f29ab3c7a0 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php @@ -161,11 +161,6 @@ public function exportClassMetadata(ClassMetadataInfo $metadata): string return implode("\n", $lines); } - /** - * @param mixed $var - * - * @return string - */ protected function _varExport($var): string { $export = var_export($var, true); From b1e091b0e1c3141490d5f2f41746b132c497b91e Mon Sep 17 00:00:00 2001 From: Thomas Ploch Date: Wed, 16 Aug 2017 12:25:31 +0200 Subject: [PATCH 493/877] [FX] Looking up PHP internal functions from the root namespace is faster --- lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php index 4f29ab3c7a0..cecefeab8b3 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php @@ -185,11 +185,11 @@ private function processEntityListeners(ClassMetadataInfo $metadata): array foreach ($metadata->entityListeners as $event => $entityListenerConfig) { foreach ($entityListenerConfig as $entityListener) { - $lines[] = sprintf( + $lines[] = \sprintf( '$metadata->addEntityListener(%s, %s, %s);', - var_export($event, true), - var_export($entityListener['class'], true), - var_export($entityListener['method'], true) + \var_export($event, true), + \var_export($entityListener['class'], true), + \var_export($entityListener['method'], true) ); } } From e4006e533c0e8472b2d99549ca2e893af13bd1bc Mon Sep 17 00:00:00 2001 From: Thomas Ploch Date: Wed, 16 Aug 2017 12:26:33 +0200 Subject: [PATCH 494/877] [FX] Use single quotes for XML root in XmlExporter --- lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php index fb45516eb13..853f84efe93 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php @@ -41,10 +41,10 @@ class XmlExporter extends AbstractExporter */ public function exportClassMetadata(ClassMetadataInfo $metadata): string { - $xml = new SimpleXmlElement(""); + $xml = new SimpleXmlElement(''); if ($metadata->isMappedSuperclass) { $root = $xml->addChild('mapped-superclass'); From 7024926f10bb7ed475e1c863c8154e5fb6183ec3 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 16 Aug 2017 15:07:48 +0200 Subject: [PATCH 495/877] #6623 splitting test scenario into two bits --- .../ORM/Hydration/AbstractHydratorTest.php | 102 +++++++++++++----- 1 file changed, 73 insertions(+), 29 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Hydration/AbstractHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/AbstractHydratorTest.php index 1d02b6c2bf8..40a3d03233e 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/AbstractHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/AbstractHydratorTest.php @@ -2,13 +2,13 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\DBAL\Connection; -use Doctrine\ORM\EntityManagerInterface; use Doctrine\Common\EventManager; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver\Statement; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Events; -use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\ORM\Internal\Hydration\AbstractHydrator; +use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -17,52 +17,96 @@ class AbstractHydratorTest extends OrmFunctionalTestCase { /** - * @group DDC-3146 - * @group #1515 - * - * Verify that the number of added events to the event listener from the abstract hydrator class is equal to the - * number of removed events + * @var EventManager|\PHPUnit_Framework_MockObject_MockObject + */ + private $mockEventManager; + + /** + * @var Statement|\PHPUnit_Framework_MockObject_MockObject + */ + private $mockStatement; + + /** + * @var ResultSetMapping|\PHPUnit_Framework_MockObject_MockObject + */ + private $mockResultMapping; + + /** + * @var AbstractHydrator */ - public function testOnClearEventListenerIsDetachedOnCleanup() + private $hydrator; + + protected function setUp() : void { + parent::setUp(); + $mockConnection = $this->createMock(Connection::class); $mockEntityManagerInterface = $this->createMock(EntityManagerInterface::class); - $mockEventManager = $this->createMock(EventManager::class); - $mockStatement = $this->createMock(Statement::class); - $mockResultMapping = $this->getMockBuilder(ResultSetMapping::class); + $this->mockEventManager = $this->createMock(EventManager::class); + $this->mockStatement = $this->createMock(Statement::class); + $this->mockResultMapping = $this->getMockBuilder(ResultSetMapping::class); - $mockEntityManagerInterface->expects(self::any())->method('getEventManager')->willReturn($mockEventManager); - $mockEntityManagerInterface->expects(self::any())->method('getConnection')->willReturn($mockConnection); - $mockStatement->expects(self::once())->method('fetch')->willReturn(false); + $mockEntityManagerInterface + ->expects(self::any()) + ->method('getEventManager') + ->willReturn($this->mockEventManager); + $mockEntityManagerInterface + ->expects(self::any()) + ->method('getConnection') + ->willReturn($mockConnection); + $this->mockStatement + ->expects(self::any()) + ->method('fetch') + ->willReturn(false); - /* @var $mockAbstractHydrator AbstractHydrator */ - $mockAbstractHydrator = $this + $this->hydrator = $this ->getMockBuilder(AbstractHydrator::class) ->setConstructorArgs([$mockEntityManagerInterface]) ->setMethods(['hydrateAllData']) ->getMock(); + } - $mockEventManager + /** + * @group DDC-3146 + * @group #1515 + * + * Verify that the number of added events to the event listener from the abstract hydrator class is equal to the + * number of removed events + */ + public function testOnClearEventListenerIsDetachedOnCleanup() : void + { + $this + ->mockEventManager ->expects(self::at(0)) ->method('addEventListener') - ->with([Events::onClear], $mockAbstractHydrator); + ->with([Events::onClear], $this->hydrator); - $mockEventManager + $this + ->mockEventManager ->expects(self::at(1)) ->method('removeEventListener') - ->with([Events::onClear], $mockAbstractHydrator); + ->with([Events::onClear], $this->hydrator); - $mockEventManager - ->expects(self::at(2)) + iterator_to_array($this->hydrator->iterate($this->mockStatement, $this->mockResultMapping)); + } + + /** + * @group #6623 + */ + public function testHydrateAllRegistersAndClearsAllAttachedListeners() : void + { + $this + ->mockEventManager + ->expects(self::at(0)) ->method('addEventListener') - ->with([Events::onClear], $mockAbstractHydrator); + ->with([Events::onClear], $this->hydrator); - $mockEventManager - ->expects(self::at(3)) + $this + ->mockEventManager + ->expects(self::at(1)) ->method('removeEventListener') - ->with([Events::onClear], $mockAbstractHydrator); + ->with([Events::onClear], $this->hydrator); - iterator_to_array($mockAbstractHydrator->iterate($mockStatement, $mockResultMapping)); - $mockAbstractHydrator->hydrateAll($mockStatement, $mockResultMapping); + $this->hydrator->hydrateAll($this->mockStatement, $this->mockResultMapping); } } From ff3c89d8b1c0e7c18d007b25085d438cdd3ddbf9 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 16 Aug 2017 15:10:27 +0200 Subject: [PATCH 496/877] #6623 minor code cleanups (removing useless assignments, array callback syntax) --- lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index 38bbacb4a6a..04e98c72ea8 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -143,8 +143,7 @@ public function hydrateAll($stmt, $resultSetMapping, array $hints = []) $this->_rsm = $resultSetMapping; $this->_hints = $hints; - $evm = $this->_em->getEventManager(); - $evm->addEventListener(array(Events::onClear), $this); + $this->_em->getEventManager()->addEventListener([Events::onClear], $this); $this->prepare(); From 9e837dc53c45d005bfaca342ba0e5d73c7391198 Mon Sep 17 00:00:00 2001 From: "Issei.M" Date: Wed, 16 Aug 2017 12:11:03 +0900 Subject: [PATCH 497/877] Skip embeddable classes proxy generation --- lib/Doctrine/ORM/Proxy/ProxyFactory.php | 2 +- .../Tests/ORM/Proxy/ProxyFactoryTest.php | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Proxy/ProxyFactory.php b/lib/Doctrine/ORM/Proxy/ProxyFactory.php index 6bc7dc5272a..1ec22bfd039 100644 --- a/lib/Doctrine/ORM/Proxy/ProxyFactory.php +++ b/lib/Doctrine/ORM/Proxy/ProxyFactory.php @@ -91,7 +91,7 @@ public function __construct(EntityManagerInterface $em, $proxyDir, $proxyNs, $au protected function skipClass(ClassMetadata $metadata) { /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadataInfo */ - return $metadata->isMappedSuperclass || $metadata->getReflectionClass()->isAbstract(); + return $metadata->isMappedSuperclass || $metadata->isEmbeddedClass || $metadata->getReflectionClass()->isAbstract(); } /** diff --git a/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php b/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php index 739a41f1807..a85ee960ddc 100644 --- a/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php @@ -75,6 +75,26 @@ public function testReferenceProxyDelegatesLoadingToThePersister() $proxy->getDescription(); } + public function testSkipMappedSuperClassesOnGeneration() + { + $cm = new ClassMetadata(\stdClass::class); + $cm->isMappedSuperclass = true; + + $num = $this->proxyFactory->generateProxyClasses([$cm]); + + $this->assertEquals(0, $num, "No proxies generated."); + } + + public function testSkipEmbeddableClassesOnGeneration() + { + $cm = new ClassMetadata(\stdClass::class); + $cm->isEmbeddedClass = true; + + $num = $this->proxyFactory->generateProxyClasses([$cm]); + + $this->assertEquals(0, $num, "No proxies generated."); + } + /** * @group DDC-1771 */ From de6d932e8c09e30dc3a470d4d48099fca57eb8a8 Mon Sep 17 00:00:00 2001 From: "Issei.M" Date: Wed, 16 Aug 2017 20:29:27 +0900 Subject: [PATCH 498/877] Fix CS / Add annotation --- tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php b/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php index a85ee960ddc..a26465f37c0 100644 --- a/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php @@ -75,24 +75,27 @@ public function testReferenceProxyDelegatesLoadingToThePersister() $proxy->getDescription(); } - public function testSkipMappedSuperClassesOnGeneration() + public function testSkipMappedSuperClassesOnGeneration(): void { $cm = new ClassMetadata(\stdClass::class); $cm->isMappedSuperclass = true; $num = $this->proxyFactory->generateProxyClasses([$cm]); - $this->assertEquals(0, $num, "No proxies generated."); + self::assertSame(0, $num, "No proxies generated."); } - public function testSkipEmbeddableClassesOnGeneration() + /** + * @group 6625 + */ + public function testSkipEmbeddableClassesOnGeneration(): void { $cm = new ClassMetadata(\stdClass::class); $cm->isEmbeddedClass = true; $num = $this->proxyFactory->generateProxyClasses([$cm]); - $this->assertEquals(0, $num, "No proxies generated."); + self::assertSame(0, $num, "No proxies generated."); } /** From 0bc91f87339601bf2d8af607b8e67735eefa66b4 Mon Sep 17 00:00:00 2001 From: "Issei.M" Date: Wed, 16 Aug 2017 20:47:54 +0900 Subject: [PATCH 499/877] Replace double quote with single quote --- tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php b/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php index a26465f37c0..9a575b80aa5 100644 --- a/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php @@ -75,6 +75,7 @@ public function testReferenceProxyDelegatesLoadingToThePersister() $proxy->getDescription(); } + public function testSkipMappedSuperClassesOnGeneration(): void { $cm = new ClassMetadata(\stdClass::class); @@ -82,7 +83,7 @@ public function testSkipMappedSuperClassesOnGeneration(): void $num = $this->proxyFactory->generateProxyClasses([$cm]); - self::assertSame(0, $num, "No proxies generated."); + self::assertSame(0, $num, 'No proxies generated.'); } /** @@ -95,7 +96,7 @@ public function testSkipEmbeddableClassesOnGeneration(): void $num = $this->proxyFactory->generateProxyClasses([$cm]); - self::assertSame(0, $num, "No proxies generated."); + self::assertSame(0, $num, 'No proxies generated.'); } /** From 71218b66b9791079ff3327384e99fb1b8a981777 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 16 Aug 2017 15:16:00 +0200 Subject: [PATCH 500/877] #6626 #6625 minor CS fixes (removed useless assignments) --- lib/Doctrine/ORM/Proxy/ProxyFactory.php | 4 +++- .../Tests/ORM/Proxy/ProxyFactoryTest.php | 17 ++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/Doctrine/ORM/Proxy/ProxyFactory.php b/lib/Doctrine/ORM/Proxy/ProxyFactory.php index 1ec22bfd039..16cfde9317a 100644 --- a/lib/Doctrine/ORM/Proxy/ProxyFactory.php +++ b/lib/Doctrine/ORM/Proxy/ProxyFactory.php @@ -91,7 +91,9 @@ public function __construct(EntityManagerInterface $em, $proxyDir, $proxyNs, $au protected function skipClass(ClassMetadata $metadata) { /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadataInfo */ - return $metadata->isMappedSuperclass || $metadata->isEmbeddedClass || $metadata->getReflectionClass()->isAbstract(); + return $metadata->isMappedSuperclass + || $metadata->isEmbeddedClass + || $metadata->getReflectionClass()->isAbstract(); } /** diff --git a/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php b/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php index 9a575b80aa5..d66326faf2f 100644 --- a/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php @@ -75,15 +75,16 @@ public function testReferenceProxyDelegatesLoadingToThePersister() $proxy->getDescription(); } - public function testSkipMappedSuperClassesOnGeneration(): void { $cm = new ClassMetadata(\stdClass::class); $cm->isMappedSuperclass = true; - $num = $this->proxyFactory->generateProxyClasses([$cm]); - - self::assertSame(0, $num, 'No proxies generated.'); + self::assertSame( + 0, + $this->proxyFactory->generateProxyClasses([$cm]), + 'No proxies generated.' + ); } /** @@ -94,9 +95,11 @@ public function testSkipEmbeddableClassesOnGeneration(): void $cm = new ClassMetadata(\stdClass::class); $cm->isEmbeddedClass = true; - $num = $this->proxyFactory->generateProxyClasses([$cm]); - - self::assertSame(0, $num, 'No proxies generated.'); + self::assertSame( + 0, + $this->proxyFactory->generateProxyClasses([$cm]), + 'No proxies generated.' + ); } /** From e1acba3ae4daae611ce09b30bc40be9749e2cb1e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 16 Aug 2017 19:53:32 +0200 Subject: [PATCH 501/877] #6593 #5864 reverted all public/protected API parameter and return type changes That's still to be considered a BC break, since child classes are broken if incompatible. Sorry @tPl0ch :-( --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 298 +++++++++++++----- .../Export/Driver/AnnotationExporter.php | 16 +- .../ORM/Tools/Export/Driver/PhpExporter.php | 15 +- .../ORM/Tools/Export/Driver/XmlExporter.php | 8 +- .../ORM/Tools/Export/Driver/YamlExporter.php | 11 +- 5 files changed, 258 insertions(+), 90 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 9a282fa6bbd..63b53089dcb 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -346,7 +346,7 @@ public function __construct() * * @return void */ - public function generate(array $metadatas, $outputDirectory): void + public function generate(array $metadatas, $outputDirectory) { foreach ($metadatas as $metadata) { $this->writeEntityClass($metadata, $outputDirectory); @@ -363,7 +363,7 @@ public function generate(array $metadatas, $outputDirectory): void * * @throws \RuntimeException */ - public function writeEntityClass(ClassMetadataInfo $metadata, $outputDirectory): void + public function writeEntityClass(ClassMetadataInfo $metadata, $outputDirectory) { $path = $outputDirectory . '/' . str_replace('\\', DIRECTORY_SEPARATOR, $metadata->name) . $this->extension; $dir = dirname($path); @@ -404,7 +404,7 @@ public function writeEntityClass(ClassMetadataInfo $metadata, $outputDirectory): * * @return string */ - public function generateEntityClass(ClassMetadataInfo $metadata): string + public function generateEntityClass(ClassMetadataInfo $metadata) { $placeHolders = [ '', @@ -435,7 +435,7 @@ public function generateEntityClass(ClassMetadataInfo $metadata): string * * @return string */ - public function generateUpdatedEntityClass(ClassMetadataInfo $metadata, $path): string + public function generateUpdatedEntityClass(ClassMetadataInfo $metadata, $path) { $currentCode = file_get_contents($path); @@ -453,7 +453,7 @@ public function generateUpdatedEntityClass(ClassMetadataInfo $metadata, $path): * * @return void */ - public function setNumSpaces($numSpaces): void + public function setNumSpaces($numSpaces) { $this->spaces = str_repeat(' ', $numSpaces); $this->numSpaces = $numSpaces; @@ -466,7 +466,7 @@ public function setNumSpaces($numSpaces): void * * @return void */ - public function setExtension($extension): void + public function setExtension($extension) { $this->extension = $extension; } @@ -478,7 +478,7 @@ public function setExtension($extension): void * * @return void */ - public function setClassToExtend($classToExtend): void + public function setClassToExtend($classToExtend) { $this->classToExtend = $classToExtend; } @@ -490,7 +490,7 @@ public function setClassToExtend($classToExtend): void * * @return void */ - public function setGenerateAnnotations($bool): void + public function setGenerateAnnotations($bool) { $this->generateAnnotations = $bool; } @@ -504,7 +504,7 @@ public function setGenerateAnnotations($bool): void * * @throws \InvalidArgumentException */ - public function setFieldVisibility($visibility): void + public function setFieldVisibility($visibility) { if ($visibility !== static::FIELD_VISIBLE_PRIVATE && $visibility !== static::FIELD_VISIBLE_PROTECTED) { throw new \InvalidArgumentException('Invalid provided visibility (only private and protected are allowed): ' . $visibility); @@ -518,7 +518,7 @@ public function setFieldVisibility($visibility): void * * @param boolean $embeddablesImmutable */ - public function setEmbeddablesImmutable($embeddablesImmutable): void + public function setEmbeddablesImmutable($embeddablesImmutable) { $this->embeddablesImmutable = (boolean) $embeddablesImmutable; } @@ -530,7 +530,7 @@ public function setEmbeddablesImmutable($embeddablesImmutable): void * * @return void */ - public function setAnnotationPrefix($prefix): void + public function setAnnotationPrefix($prefix) { $this->annotationsPrefix = $prefix; } @@ -542,7 +542,7 @@ public function setAnnotationPrefix($prefix): void * * @return void */ - public function setUpdateEntityIfExists($bool): void + public function setUpdateEntityIfExists($bool) { $this->updateEntityIfExists = $bool; } @@ -554,7 +554,7 @@ public function setUpdateEntityIfExists($bool): void * * @return void */ - public function setRegenerateEntityIfExists($bool): void + public function setRegenerateEntityIfExists($bool) { $this->regenerateEntityIfExists = $bool; } @@ -566,7 +566,7 @@ public function setRegenerateEntityIfExists($bool): void * * @return void */ - public function setGenerateStubMethods($bool): void + public function setGenerateStubMethods($bool) { $this->generateEntityStubMethods = $bool; } @@ -578,7 +578,7 @@ public function setGenerateStubMethods($bool): void * * @return void */ - public function setBackupExisting($bool): void + public function setBackupExisting($bool) { $this->backupExisting = $bool; } @@ -588,7 +588,7 @@ public function setBackupExisting($bool): void * * @return string */ - protected function getType($type): string + protected function getType($type) { if (isset($this->typeAlias[$type])) { return $this->typeAlias[$type]; @@ -602,19 +602,22 @@ protected function getType($type): string * * @return string */ - protected function generateEntityNamespace(ClassMetadataInfo $metadata): ?string + protected function generateEntityNamespace(ClassMetadataInfo $metadata) { - if (!$this->hasNamespace($metadata)) { - return null; + if (! $this->hasNamespace($metadata)) { + return ''; } return 'namespace ' . $this->getNamespace($metadata) .';'; } - protected function generateEntityUse(): ?string + /** + * @return string + */ + protected function generateEntityUse() { - if (!$this->generateAnnotations) { - return null; + if (! $this->generateAnnotations) { + return ''; } return "\n".'use Doctrine\ORM\Mapping as ORM;'."\n"; @@ -625,7 +628,7 @@ protected function generateEntityUse(): ?string * * @return string */ - protected function generateEntityClassName(ClassMetadataInfo $metadata): string + protected function generateEntityClassName(ClassMetadataInfo $metadata) { return 'class ' . $this->getClassName($metadata) . ($this->extendsClass() ? ' extends ' . $this->getClassToExtendName() : null); @@ -636,7 +639,7 @@ protected function generateEntityClassName(ClassMetadataInfo $metadata): string * * @return string */ - protected function generateEntityBody(ClassMetadataInfo $metadata): string + protected function generateEntityBody(ClassMetadataInfo $metadata) { $fieldMappingProperties = $this->generateEntityFieldMappingProperties($metadata); $embeddedProperties = $this->generateEntityEmbeddedProperties($metadata); @@ -676,7 +679,7 @@ protected function generateEntityBody(ClassMetadataInfo $metadata): string * * @return string */ - protected function generateEntityConstructor(ClassMetadataInfo $metadata): string + protected function generateEntityConstructor(ClassMetadataInfo $metadata) { if ($this->hasMethod('__construct', $metadata)) { return ''; @@ -706,7 +709,7 @@ protected function generateEntityConstructor(ClassMetadataInfo $metadata): strin * * @return string */ - private function generateEmbeddableConstructor(ClassMetadataInfo $metadata): string + private function generateEmbeddableConstructor(ClassMetadataInfo $metadata) { $paramTypes = []; $paramVariables = []; @@ -800,7 +803,7 @@ function ($type, $variable) use ($maxParamTypeLength) { * * @return void */ - protected function parseTokensInEntityFile($src): void + protected function parseTokensInEntityFile($src) { $tokens = token_get_all($src); $tokensCount = count($tokens); @@ -848,7 +851,13 @@ protected function parseTokensInEntityFile($src): void } } - protected function hasProperty(string $property, ClassMetadataInfo $metadata): bool + /** + * @param string $property + * @param ClassMetadataInfo $metadata + * + * @return bool + */ + protected function hasProperty($property, ClassMetadataInfo $metadata) { if ($this->extendsClass() || (!$this->isNew && class_exists($metadata->name))) { // don't generate property if its already on the base class. @@ -871,7 +880,13 @@ protected function hasProperty(string $property, ClassMetadataInfo $metadata): b ); } - protected function hasMethod(string $method, ClassMetadataInfo $metadata): bool + /** + * @param string $method + * @param ClassMetadataInfo $metadata + * + * @return bool + */ + protected function hasMethod($method, ClassMetadataInfo $metadata) { if ($this->extendsClass() || (!$this->isNew && class_exists($metadata->name))) { // don't generate method if its already on the base class. @@ -895,7 +910,14 @@ protected function hasMethod(string $method, ClassMetadataInfo $metadata): bool ); } - protected function getTraits(ClassMetadataInfo $metadata): array + /** + * @param ClassMetadataInfo $metadata + * + * @return array + * + * @throws \ReflectionException + */ + protected function getTraits(ClassMetadataInfo $metadata) { if (! ($metadata->reflClass !== null || class_exists($metadata->name))) { return []; @@ -914,40 +936,69 @@ protected function getTraits(ClassMetadataInfo $metadata): array return $traits; } - protected function hasNamespace(ClassMetadataInfo $metadata): bool + /** + * @param ClassMetadataInfo $metadata + * + * @return bool + */ + protected function hasNamespace(ClassMetadataInfo $metadata) { return (bool) strpos($metadata->name, '\\'); } - protected function extendsClass(): bool + /** + * @return bool + */ + protected function extendsClass() { return (bool) $this->classToExtend; } - protected function getClassToExtend(): ?string + /** + * @return string + */ + protected function getClassToExtend() { return $this->classToExtend; } - protected function getClassToExtendName(): string + /** + * @return string + */ + protected function getClassToExtendName() { $refl = new \ReflectionClass($this->getClassToExtend()); return '\\' . $refl->getName(); } - protected function getClassName(ClassMetadataInfo $metadata): string + /** + * @param ClassMetadataInfo $metadata + * + * @return string + */ + protected function getClassName(ClassMetadataInfo $metadata) { return ($pos = strrpos($metadata->name, '\\')) ? substr($metadata->name, $pos + 1, strlen($metadata->name)) : $metadata->name; } - protected function getNamespace(ClassMetadataInfo $metadata): string + /** + * @param ClassMetadataInfo $metadata + * + * @return string + */ + protected function getNamespace(ClassMetadataInfo $metadata) { return substr($metadata->name, 0, strrpos($metadata->name, '\\')); } - protected function generateEntityDocBlock(ClassMetadataInfo $metadata): string + /** + * @param ClassMetadataInfo $metadata + * + * @return string + */ + protected function generateEntityDocBlock(ClassMetadataInfo $metadata) { $lines = []; $lines[] = '/**'; @@ -981,7 +1032,12 @@ protected function generateEntityDocBlock(ClassMetadataInfo $metadata): string return implode("\n", $lines); } - protected function generateEntityAnnotation(ClassMetadataInfo $metadata): string + /** + * @param ClassMetadataInfo $metadata + * + * @return string + */ + protected function generateEntityAnnotation(ClassMetadataInfo $metadata) { $prefix = '@' . $this->annotationsPrefix; @@ -996,7 +1052,12 @@ protected function generateEntityAnnotation(ClassMetadataInfo $metadata): string return $prefix . ($metadata->isMappedSuperclass ? 'MappedSuperclass' : 'Entity') . $customRepository; } - protected function generateTableAnnotation(ClassMetadataInfo $metadata): string + /** + * @param ClassMetadataInfo $metadata + * + * @return string + */ + protected function generateTableAnnotation(ClassMetadataInfo $metadata) { if ($metadata->isEmbeddedClass) { return ''; @@ -1029,7 +1090,13 @@ protected function generateTableAnnotation(ClassMetadataInfo $metadata): string return '@' . $this->annotationsPrefix . 'Table(' . implode(', ', $table) . ')'; } - protected function generateTableConstraints(string $constraintName, array $constraints): string + /** + * @param string $constraintName + * @param array $constraints + * + * @return string + */ + protected function generateTableConstraints($constraintName, array $constraints) { $annotations = []; foreach ($constraints as $name => $constraint) { @@ -1043,19 +1110,29 @@ protected function generateTableConstraints(string $constraintName, array $const return implode(', ', $annotations); } - protected function generateInheritanceAnnotation(ClassMetadataInfo $metadata): ?string + /** + * @param ClassMetadataInfo $metadata + * + * @return string + */ + protected function generateInheritanceAnnotation(ClassMetadataInfo $metadata) { if ($metadata->inheritanceType === ClassMetadataInfo::INHERITANCE_TYPE_NONE) { - return null; + return ''; } return '@' . $this->annotationsPrefix . 'InheritanceType("'.$this->getInheritanceTypeString($metadata->inheritanceType).'")'; } - protected function generateDiscriminatorColumnAnnotation(ClassMetadataInfo $metadata): ?string + /** + * @param ClassMetadataInfo $metadata + * + * @return string + */ + protected function generateDiscriminatorColumnAnnotation(ClassMetadataInfo $metadata) { if ($metadata->inheritanceType === ClassMetadataInfo::INHERITANCE_TYPE_NONE) { - return null; + return ''; } $discrColumn = $metadata->discriminatorColumn; @@ -1066,7 +1143,12 @@ protected function generateDiscriminatorColumnAnnotation(ClassMetadataInfo $meta return '@' . $this->annotationsPrefix . 'DiscriminatorColumn(' . $columnDefinition . ')'; } - protected function generateDiscriminatorMapAnnotation(ClassMetadataInfo $metadata): ?string + /** + * @param ClassMetadataInfo $metadata + * + * @return string + */ + protected function generateDiscriminatorMapAnnotation(ClassMetadataInfo $metadata) { if ($metadata->inheritanceType === ClassMetadataInfo::INHERITANCE_TYPE_NONE) { return null; @@ -1081,7 +1163,12 @@ protected function generateDiscriminatorMapAnnotation(ClassMetadataInfo $metadat return '@' . $this->annotationsPrefix . 'DiscriminatorMap({' . implode(', ', $inheritanceClassMap) . '})'; } - protected function generateEntityStubMethods(ClassMetadataInfo $metadata): string + /** + * @param ClassMetadataInfo $metadata + * + * @return string + */ + protected function generateEntityStubMethods(ClassMetadataInfo $metadata) { $methods = []; @@ -1145,7 +1232,12 @@ protected function generateEntityStubMethods(ClassMetadataInfo $metadata): strin return implode("\n\n", $methods); } - protected function isAssociationIsNullable(array $associationMapping): bool + /** + * @param array $associationMapping + * + * @return bool + */ + protected function isAssociationIsNullable(array $associationMapping) { if (isset($associationMapping['id']) && $associationMapping['id']) { return false; @@ -1167,10 +1259,15 @@ protected function isAssociationIsNullable(array $associationMapping): bool return true; } - protected function generateEntityLifecycleCallbackMethods(ClassMetadataInfo $metadata): ?string + /** + * @param ClassMetadataInfo $metadata + * + * @return string + */ + protected function generateEntityLifecycleCallbackMethods(ClassMetadataInfo $metadata) { if (empty($metadata->lifecycleCallbacks)) { - return null; + return ''; } $methods = []; @@ -1184,7 +1281,12 @@ protected function generateEntityLifecycleCallbackMethods(ClassMetadataInfo $met return implode("\n\n", array_filter($methods)); } - protected function generateEntityAssociationMappingProperties(ClassMetadataInfo $metadata): string + /** + * @param ClassMetadataInfo $metadata + * + * @return string + */ + protected function generateEntityAssociationMappingProperties(ClassMetadataInfo $metadata) { $lines = []; @@ -1201,7 +1303,12 @@ protected function generateEntityAssociationMappingProperties(ClassMetadataInfo return implode("\n", $lines); } - protected function generateEntityFieldMappingProperties(ClassMetadataInfo $metadata): string + /** + * @param ClassMetadataInfo $metadata + * + * @return string + */ + protected function generateEntityFieldMappingProperties(ClassMetadataInfo $metadata) { $lines = []; @@ -1221,7 +1328,12 @@ protected function generateEntityFieldMappingProperties(ClassMetadataInfo $metad return implode("\n", $lines); } - protected function generateEntityEmbeddedProperties(ClassMetadataInfo $metadata): string + /** + * @param ClassMetadataInfo $metadata + * + * @return string + */ + protected function generateEntityEmbeddedProperties(ClassMetadataInfo $metadata) { $lines = []; @@ -1237,12 +1349,16 @@ protected function generateEntityEmbeddedProperties(ClassMetadataInfo $metadata) return implode("\n", $lines); } - protected function generateEntityStubMethod( - ClassMetadataInfo $metadata, - string $type, - string $fieldName, - ?string $typeHint = null, - ?string $defaultValue = null): string + /** + * @param ClassMetadataInfo $metadata + * @param string $type + * @param string $fieldName + * @param string|null $typeHint + * @param string|null $defaultValue + * + * @return string + */ + protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null) { $methodName = $type . Inflector::classify($fieldName); $variableName = Inflector::camelize($fieldName); @@ -1288,7 +1404,14 @@ protected function generateEntityStubMethod( return $this->prefixCodeWithSpaces($method); } - protected function generateLifecycleCallbackMethod(string $name, string $methodName, ClassMetadataInfo $metadata): ?string + /** + * @param string $name + * @param string $methodName + * @param ClassMetadataInfo $metadata + * + * @return string + */ + protected function generateLifecycleCallbackMethod($name, $methodName, ClassMetadataInfo $metadata) { if ($this->hasMethod($methodName, $metadata)) { return null; @@ -1310,7 +1433,12 @@ protected function generateLifecycleCallbackMethod(string $name, string $methodN return $this->prefixCodeWithSpaces($method); } - protected function generateJoinColumnAnnotation(array $joinColumn): string + /** + * @param array $joinColumn + * + * @return string + */ + protected function generateJoinColumnAnnotation(array $joinColumn) { $joinColumnAnnot = []; @@ -1341,7 +1469,13 @@ protected function generateJoinColumnAnnotation(array $joinColumn): string return '@' . $this->annotationsPrefix . 'JoinColumn(' . implode(', ', $joinColumnAnnot) . ')'; } - protected function generateAssociationMappingPropertyDocBlock(array $associationMapping, ClassMetadataInfo $metadata): string + /** + * @param array $associationMapping + * @param ClassMetadataInfo $metadata + * + * @return string + */ + protected function generateAssociationMappingPropertyDocBlock(array $associationMapping, ClassMetadataInfo $metadata) { $lines = []; $lines[] = $this->spaces . '/**'; @@ -1487,7 +1621,13 @@ protected function generateAssociationMappingPropertyDocBlock(array $association return implode("\n", $lines); } - protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, ClassMetadataInfo $metadata): string + /** + * @param array $fieldMapping + * @param ClassMetadataInfo $metadata + * + * @return string + */ + protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, ClassMetadataInfo $metadata) { $lines = []; $lines[] = $this->spaces . '/**'; @@ -1579,7 +1719,12 @@ protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, Cla return implode("\n", $lines); } - protected function generateEmbeddedPropertyDocBlock(array $embeddedClass): string + /** + * @param array $embeddedClass + * + * @return string + */ + protected function generateEmbeddedPropertyDocBlock(array $embeddedClass) { $lines = []; $lines[] = $this->spaces . '/**'; @@ -1607,10 +1752,10 @@ protected function generateEmbeddedPropertyDocBlock(array $embeddedClass): strin return implode("\n", $lines); } - protected function generateEntityListenerAnnotation(ClassMetadataInfo $metadata): ?string + private function generateEntityListenerAnnotation(ClassMetadataInfo $metadata): string { if (0 === \count($metadata->entityListeners)) { - return null; + return ''; } $processedClasses = []; @@ -1628,7 +1773,13 @@ protected function generateEntityListenerAnnotation(ClassMetadataInfo $metadata) ); } - protected function prefixCodeWithSpaces($code, $num = 1): string + /** + * @param string $code + * @param int $num + * + * @return string + */ + protected function prefixCodeWithSpaces($code, $num = 1) { $lines = explode("\n", $code); @@ -1648,7 +1799,7 @@ protected function prefixCodeWithSpaces($code, $num = 1): string * * @throws \InvalidArgumentException When the inheritance type does not exist. */ - protected function getInheritanceTypeString($type): string + protected function getInheritanceTypeString($type) { if ( ! isset(static::$inheritanceTypeMap[$type])) { throw new \InvalidArgumentException(sprintf('Invalid provided InheritanceType: %s', $type)); @@ -1664,7 +1815,7 @@ protected function getInheritanceTypeString($type): string * * @throws \InvalidArgumentException When the change-tracking type does not exist. */ - protected function getChangeTrackingPolicyString($type): string + protected function getChangeTrackingPolicyString($type) { if ( ! isset(static::$changeTrackingPolicyMap[$type])) { throw new \InvalidArgumentException(sprintf('Invalid provided ChangeTrackingPolicy: %s', $type)); @@ -1680,7 +1831,7 @@ protected function getChangeTrackingPolicyString($type): string * * @throws \InvalidArgumentException When the generator type does not exist. */ - protected function getIdGeneratorTypeString($type): string + protected function getIdGeneratorTypeString($type) { if ( ! isset(static::$generatorStrategyMap[$type])) { throw new \InvalidArgumentException(sprintf('Invalid provided IdGeneratorType: %s', $type)); @@ -1689,7 +1840,12 @@ protected function getIdGeneratorTypeString($type): string return static::$generatorStrategyMap[$type]; } - private function nullableFieldExpression(array $fieldMapping): ?string + /** + * @param array $fieldMapping + * + * @return string|null + */ + private function nullableFieldExpression(array $fieldMapping) { if (isset($fieldMapping['nullable']) && true === $fieldMapping['nullable']) { return 'null'; @@ -1705,7 +1861,7 @@ private function nullableFieldExpression(array $fieldMapping): ?string * * @return string */ - private function exportTableOptions(array $options): string + private function exportTableOptions(array $options) { $optionsStr = []; diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php index 5f2a42e6c0a..171ac872849 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php @@ -44,7 +44,7 @@ class AnnotationExporter extends AbstractExporter /** * {@inheritdoc} */ - public function exportClassMetadata(ClassMetadataInfo $metadata): string + public function exportClassMetadata(ClassMetadataInfo $metadata) { if ( ! $this->_entityGenerator) { throw new \RuntimeException('For the AnnotationExporter you must set an EntityGenerator instance with the setEntityGenerator() method.'); @@ -58,12 +58,22 @@ public function exportClassMetadata(ClassMetadataInfo $metadata): string return $this->_entityGenerator->generateEntityClass($metadata); } - protected function _generateOutputPath(ClassMetadataInfo $metadata): string + /** + * @param ClassMetadataInfo $metadata + * + * @return string + */ + protected function _generateOutputPath(ClassMetadataInfo $metadata) { return $this->_outputDir . '/' . str_replace('\\', '/', $metadata->name) . $this->_extension; } - public function setEntityGenerator(EntityGenerator $entityGenerator): void + /** + * @param EntityGenerator $entityGenerator + * + * @return void + */ + public function setEntityGenerator(EntityGenerator $entityGenerator) { $this->_entityGenerator = $entityGenerator; } diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php index cecefeab8b3..c918c71dd51 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php @@ -38,7 +38,7 @@ class PhpExporter extends AbstractExporter /** * {@inheritdoc} */ - public function exportClassMetadata(ClassMetadataInfo $metadata): string + public function exportClassMetadata(ClassMetadataInfo $metadata) { $lines = []; $lines[] = 'entityListeners)) { - return $lines; - } - foreach ($metadata->entityListeners as $event => $entityListenerConfig) { foreach ($entityListenerConfig as $entityListener) { $lines[] = \sprintf( diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php index 853f84efe93..2d6bf1a73e2 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php @@ -39,7 +39,7 @@ class XmlExporter extends AbstractExporter /** * {@inheritdoc} */ - public function exportClassMetadata(ClassMetadataInfo $metadata): string + public function exportClassMetadata(ClassMetadataInfo $metadata) { $xml = new SimpleXmlElement(' $option) { $isArray = is_array($option); @@ -426,7 +426,7 @@ private function exportTableOptions(SimpleXMLElement $parentXml, array $options) * * @return void */ - private function exportSequenceInformation(SimpleXMLElement $identifierXmlNode, ClassMetadataInfo $metadata): void + private function exportSequenceInformation(SimpleXMLElement $identifierXmlNode, ClassMetadataInfo $metadata) : void { $sequenceDefinition = $metadata->sequenceGeneratorDefinition; @@ -441,7 +441,7 @@ private function exportSequenceInformation(SimpleXMLElement $identifierXmlNode, $sequenceGeneratorXml->addAttribute('initial-value', $sequenceDefinition['initialValue']); } - private function _asXml(SimpleXMLElement $simpleXml): string + private function _asXml(SimpleXMLElement $simpleXml) : string { $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->loadXML($simpleXml->asXML()); diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php index 053ad58972c..5da79095436 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php @@ -39,7 +39,7 @@ class YamlExporter extends AbstractExporter /** * {@inheritdoc} */ - public function exportClassMetadata(ClassMetadataInfo $metadata): string + public function exportClassMetadata(ClassMetadataInfo $metadata) { $array = []; @@ -230,12 +230,12 @@ public function exportClassMetadata(ClassMetadataInfo $metadata): string * * @return string A YAML string representing the original PHP array */ - protected function yamlDump($array, $inline = 2): string + protected function yamlDump($array, $inline = 2) { return Yaml::dump($array, $inline); } - private function processEntityListeners(ClassMetadataInfo $metadata, array $array): array + private function processEntityListeners(ClassMetadataInfo $metadata, array $array) : array { if (0 === \count($metadata->entityListeners)) { return $array; @@ -250,12 +250,13 @@ private function processEntityListeners(ClassMetadataInfo $metadata, array $arra return $array; } - private function processEntityListenerConfig(array $array, array $entityListenerConfig, string $event): array + private function processEntityListenerConfig(array $array, array $entityListenerConfig, string $event) : array { foreach ($entityListenerConfig as $entityListener) { - if (!isset($array['entityListeners'][$entityListener['class']])) { + if (! isset($array['entityListeners'][$entityListener['class']])) { $array['entityListeners'][$entityListener['class']] = []; } + $array['entityListeners'][$entityListener['class']][$event] = [$entityListener['method']]; } From 894490c2a04f398730b4429f0a9bfa8219e4d8b7 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 16 Aug 2017 19:57:26 +0200 Subject: [PATCH 502/877] #6593 #5864 removing incorrect `null` return value in API marked as `string` --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 63b53089dcb..391732dd009 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -1414,7 +1414,7 @@ protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, protected function generateLifecycleCallbackMethod($name, $methodName, ClassMetadataInfo $metadata) { if ($this->hasMethod($methodName, $metadata)) { - return null; + return ''; } $this->staticReflection[$metadata->name]['methods'][] = $methodName; From bb994b9e700595941b4abf660e886d7f98270ad8 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 16 Aug 2017 20:20:22 +0200 Subject: [PATCH 503/877] Removing reference to deprecated YAML component constant that is ignored after symfony 3.4 --- lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index c4fb45ecedd..fa52013932d 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -806,10 +806,6 @@ private function cacheToArray($cacheMapping) */ protected function loadMappingFile($file) { - if (defined(Yaml::class . '::PARSE_KEYS_AS_STRINGS')) { - return Yaml::parse(file_get_contents($file), Yaml::PARSE_KEYS_AS_STRINGS); - } - return Yaml::parse(file_get_contents($file)); } } From 40515472c109b636bf857676232e0619cf182883 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 16 Aug 2017 20:21:26 +0200 Subject: [PATCH 504/877] Bumping ORM YAML dependency to 3.4+, explicitly forbidding compatibility with older YAML component versions --- composer.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d632c89919d..fd4ddd9634b 100644 --- a/composer.json +++ b/composer.json @@ -24,8 +24,11 @@ "doctrine/annotations": "~1.4", "symfony/console": "~3.0|~4.0" }, + "conflict": { + "symfony/yaml": "<3.4" + }, "require-dev": { - "symfony/yaml": "~3.0|~4.0", + "symfony/yaml": "~3.4|~4.0", "phpunit/phpunit": "^6.0" }, "suggest": { From 5770459bfce9485c8c9ed1eb463590b19e2e93b7 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 18 Aug 2017 04:44:17 +0200 Subject: [PATCH 505/877] #6441 moving expected exception annotations into explicit method calls --- .../ORM/Cache/DefaultCacheFactoryTest.php | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php index 54fd59e370f..4ff2edc1cf9 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php @@ -228,10 +228,6 @@ public function testCreateNewCacheDriver() $this->assertNotSame($cachedPersister1->getCacheRegion(), $cachedPersister2->getCacheRegion()); } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage Unrecognized access strategy type [-1] - */ public function testBuildCachedEntityPersisterNonStrictException() { $em = $this->em; @@ -240,13 +236,12 @@ public function testBuildCachedEntityPersisterNonStrictException() $metadata->cache['usage'] = -1; + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Unrecognized access strategy type [-1]'); + $this->factory->buildCachedEntityPersister($em, $persister, $metadata); } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage Unrecognized access strategy type [-1] - */ public function testBuildCachedCollectionPersisterException() { $em = $this->em; @@ -256,17 +251,23 @@ public function testBuildCachedCollectionPersisterException() $mapping['cache']['usage'] = -1; + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Unrecognized access strategy type [-1]'); + $this->factory->buildCachedCollectionPersister($em, $persister, $mapping); } - /** - * @expectedException LogicException - * @expectedExceptionMessage If you want to use a "READ_WRITE" cache an implementation of "Doctrine\ORM\Cache\ConcurrentRegion" is required, The default implementation provided by doctrine is "Doctrine\ORM\Cache\Region\FileLockRegion" if you want to use it please provide a valid directory - */ public function testInvalidFileLockRegionDirectoryException() { $factory = new DefaultCacheFactory($this->regionsConfig, $this->getSharedSecondLevelCacheDriverImpl()); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage( + 'If you want to use a "READ_WRITE" cache an implementation of "Doctrine\ORM\Cache\ConcurrentRegion" ' + . 'is required, The default implementation provided by doctrine is ' + . '"Doctrine\ORM\Cache\Region\FileLockRegion" if you want to use it please provide a valid directory' + ); + $factory->getRegion( [ 'usage' => ClassMetadata::CACHE_USAGE_READ_WRITE, @@ -275,16 +276,19 @@ public function testInvalidFileLockRegionDirectoryException() ); } - /** - * @expectedException LogicException - * @expectedExceptionMessage If you want to use a "READ_WRITE" cache an implementation of "Doctrine\ORM\Cache\ConcurrentRegion" is required, The default implementation provided by doctrine is "Doctrine\ORM\Cache\Region\FileLockRegion" if you want to use it please provide a valid directory - */ public function testInvalidFileLockRegionDirectoryExceptionWithEmptyString() { $factory = new DefaultCacheFactory($this->regionsConfig, $this->getSharedSecondLevelCacheDriverImpl()); $factory->setFileLockRegionDirectory(''); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage( + 'If you want to use a "READ_WRITE" cache an implementation of "Doctrine\ORM\Cache\ConcurrentRegion" ' + . 'is required, The default implementation provided by doctrine is ' + . '"Doctrine\ORM\Cache\Region\FileLockRegion" if you want to use it please provide a valid directory' + ); + $factory->getRegion( [ 'usage' => ClassMetadata::CACHE_USAGE_READ_WRITE, From 74c83f3cecfba5a8ee537e10d55a095e3e8f5011 Mon Sep 17 00:00:00 2001 From: Greg Bell Date: Fri, 18 Aug 2017 15:20:17 +1000 Subject: [PATCH 506/877] Fix format and content as-per discussion in PR --- .../reference/dql-doctrine-query-language.rst | 81 ++++++++++--------- 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/docs/en/reference/dql-doctrine-query-language.rst b/docs/en/reference/dql-doctrine-query-language.rst index 035ef611cf2..1b0d3b01377 100644 --- a/docs/en/reference/dql-doctrine-query-language.rst +++ b/docs/en/reference/dql-doctrine-query-language.rst @@ -49,13 +49,6 @@ SELECT queries DQL SELECT clause ~~~~~~~~~~~~~~~~~ -The SELECT clause of a DQL query specifies what gets hydrated in -the query result. You are always returned usable objects, but any -associated objects not included in the SELECT clause will be -proxies (ie. unhydrated). They get hydrated by Doctrine when -they're read by your code, but that means at least one additional -database access. - Here is an example that selects all users with an age > 20: .. code-block:: php @@ -86,30 +79,43 @@ Lets examine the query: The result of this query would be a list of User objects where all users are older than 20. +Result format +~~~~~~~~~~~~~ The composition of the expressions in the SELECT clause also influences the nature of the query result. There are three cases: -- All objects. For example: - ``SELECT u, p, n FROM Users u...`` - In this case, the result array will be made up of objects of - the type in the FROM clause. In the example above, the query - will return an array of User objects, with associated classes - identify else where in the query as 'p' and 'n' hydrated. +**All objects** + +.. code-block:: sql + + SELECT u, p, n FROM Users u... + +In this case, the result will be an array of User objects because of +the FROM clause, with children ``p`` and ``n`` hydrated because of +their inclusion in the SELECT clause. + +**All scalars** + +.. code-block:: sql + + SELECT u.name, u.address FROM Users u... -- All scalars. For example: - ``SELECT u.name, u.address FROM Users u...`` - In this case, the result will be an array of arrays. In the - example above, each element of the result array would be an - array of the scalar name and address values. +In this case, the result will be an array of arrays. In the example +above, each element of the result array would be an array of the +scalar name and address values. - You can select scalars from any entity in the query. +You can select scalars from any entity in the query. + +**Mixed** + +.. code-block:: sql -- Mixed. For example: ``SELECT u, p.quantity FROM Users u...`` - Here, the result will again be an array of arrays, with each - element being an array made up of a User object and the scalar - value p.quantity. + +Here, the result will again be an array of arrays, with each element +being an array made up of a User object and the scalar value +``p.quantity``. Multiple FROM clauses are allowed, which would cause the result array elements to cycle through the classes included in the @@ -118,16 +124,13 @@ multiple FROM clauses. .. note:: You cannot select other entities unless you also select the - root of the selection (the first entity in FROM). + root of the selection (which is the first entity in FROM). - Doctrine tells you you have violated this constraint with the - exception "Cannot select entity through identification - variables without choosing at least one root entity alias." + For example, ``SELECT p,n FROM Users u...`` would be wrong because + ``u`` is not part of the SELECT + + Doctrine throws an exception if you violate this constraint. -It is possible to wrap both fields and identification values into -aggregation and DQL functions. Numerical fields can be part of -computations using mathematical operations. See the sub-section -on `Functions, Operators, Aggregates`_ for more information. Joins ~~~~~ @@ -496,10 +499,11 @@ Joins between entities without associations were not possible until version - WHERE is applied to the results of an entire query - WITH is applied to a join as an additional condition. For - arbitrary joins (SELECT f, b FROM Foo f, Bar b WITH f.id = b.id) - the WITH is required, even if it is 1 = 1 + arbitrary joins (SELECT f, b FROM Foo f, Bar b WITH f.id = b.id) + the WITH is required, even if it is 1 = 1 - HAVING is applied to the results of a query after - aggregation (GROUP BY) + aggregation (GROUP BY) + Partial Object Syntax ^^^^^^^^^^^^^^^^^^^^^ @@ -656,6 +660,9 @@ The same restrictions apply for the reference of related entities. Functions, Operators, Aggregates -------------------------------- +It is possible to wrap both fields and identification values into +aggregation and DQL functions. Numerical fields can be part of +computations using mathematical operations. DQL Functions ~~~~~~~~~~~~~ @@ -1430,11 +1437,11 @@ Given that there are 10 users and corresponding addresses in the database the ex .. note:: Changing the fetch mode during a query mostly makes sense for one-to-one and many-to-one relations. In that case, -   all the necessary IDs are available after the root entity (``user`` in the above example) has been loaded. So, one -   query per association can be executed to fetch all the referred-to entities (``address``). + all the necessary IDs are available after the root entity (``user`` in the above example) has been loaded. So, one + query per association can be executed to fetch all the referred-to entities (``address``). For one-to-many relations, changing the fetch mode to eager will cause to execute one query **for every root entity -   loaded**. This gives no improvement over the ``lazy`` fetch mode which will also initialize the associations on + loaded**. This gives no improvement over the ``lazy`` fetch mode which will also initialize the associations on a one-by-one basis once they are accessed. From 866a424963aef890e984a1321465ae87fd2b51cb Mon Sep 17 00:00:00 2001 From: xhuberty Date: Tue, 12 Jan 2016 15:01:34 +0100 Subject: [PATCH 507/877] Fix issue when using notify tracking policy with multiple flush on entity --- lib/Doctrine/ORM/UnitOfWork.php | 42 ++++++++++++++++++--- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 31 ++++++++++++++- 2 files changed, 67 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index c0b0dd8c302..367d9f4d2af 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -324,7 +324,7 @@ public function commit($entity = null) } // Compute changes done since last commit. - if ($entity === null) { + if (null === $entity) { $this->computeChangeSets(); } elseif (is_object($entity)) { $this->computeSingleEntityChangeSet($entity); @@ -414,17 +414,40 @@ public function commit($entity = null) $this->dispatchPostFlushEvent(); + $this->postCommitClear($entity); + } + + /** + * @param null|object|array $entity + */ + private function postCommitClear($entity = null) + { + // Clear up $this->entityInsertions = $this->entityUpdates = $this->entityDeletions = $this->extraUpdates = - $this->entityChangeSets = $this->collectionUpdates = $this->collectionDeletions = $this->visitedCollections = - $this->scheduledForSynchronization = - $this->orphanRemovals = []; + $this->orphanRemovals = array(); + + if (null === $entity) { + $this->entityChangeSets = $this->scheduledForSynchronization = []; + return; + } + + if (is_object($entity)) { + $entity = [$entity]; + } + + foreach ($entity as $object) { + $oid = spl_object_hash($object); + $class = $this->em->getClassMetadata(get_class($object)); + $this->clearEntityChangeSet($oid); + $this->clearScheduledForSynchronization($class, $oid); + } } /** @@ -3099,11 +3122,20 @@ public function registerManaged($entity, array $id, array $data) * * @return void */ - public function clearEntityChangeSet($oid) + private function clearEntityChangeSet($oid) { $this->entityChangeSets[$oid] = []; } + /** + * @param $class + * @param string $oid + */ + private function clearScheduledForSynchronization($class, $oid) + { + unset($this->scheduledForSynchronization[$class->rootEntityName][$oid]); + } + /* PropertyChangedListener implementation */ /** diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index ff025df4f4b..3af8fc5cde4 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -163,7 +163,8 @@ public function testChangeTrackingNotify() $this->_unitOfWork->persist($entity); $this->_unitOfWork->commit(); - $this->assertEquals(1, count($persister->getInserts())); + $this->assertCount(1, $persister->getInserts()); + $persister->reset(); $this->assertTrue($this->_unitOfWork->isInIdentityMap($entity)); @@ -360,6 +361,34 @@ public function testPersistedEntityAndClearManager() $this->assertFalse($this->_unitOfWork->isScheduledForInsert($entity2)); } + /** + * @group 5579 + */ + public function testEntityChangeSetNotClearAfterFlushOnEntityOrArrayOfEntity() + { + // Create and Set first entity + $entity1 = new NotifyChangedEntity; + $entity1->setData('thedata'); + $this->_unitOfWork->persist($entity1); + + // Create and Set second entity + $entity2 = new NotifyChangedEntity; + $entity2->setData('thedata'); + $this->_unitOfWork->persist($entity2); + + $this->_unitOfWork->commit($entity1); + $this->assertCount(1, $this->_unitOfWork->getEntityChangeSet($entity2)); + + // Create and Set third entity + $entity3 = new NotifyChangedEntity; + $entity3->setData('thedata'); + $this->_unitOfWork->persist($entity3); + + $this->_unitOfWork->commit([$entity1,$entity2]); + $this->assertCount(1, $this->_unitOfWork->getEntityChangeSet($entity3)); + + } + /** * Data Provider * From df1577db0c519bdd5ce52113c1e0c9009205f929 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 18 Aug 2017 09:13:56 +0200 Subject: [PATCH 508/877] #5579 cleaning up test case, adding assertions critical to the understanding of the code --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 22 ++++++++++----------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 3af8fc5cde4..d675256966d 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -362,31 +362,29 @@ public function testPersistedEntityAndClearManager() } /** - * @group 5579 + * @group #5579 */ - public function testEntityChangeSetNotClearAfterFlushOnEntityOrArrayOfEntity() + public function testEntityChangeSetIsNotClearedAfterFlushOnEntityOrArrayOfEntity() : void { - // Create and Set first entity $entity1 = new NotifyChangedEntity; - $entity1->setData('thedata'); - $this->_unitOfWork->persist($entity1); - - // Create and Set second entity $entity2 = new NotifyChangedEntity; + $entity3 = new NotifyChangedEntity; + + $entity1->setData('thedata'); $entity2->setData('thedata'); + $entity3->setData('thedata'); + + $this->_unitOfWork->persist($entity1); $this->_unitOfWork->persist($entity2); $this->_unitOfWork->commit($entity1); + $this->assertEmpty($this->_unitOfWork->getEntityChangeSet($entity1)); $this->assertCount(1, $this->_unitOfWork->getEntityChangeSet($entity2)); - // Create and Set third entity - $entity3 = new NotifyChangedEntity; - $entity3->setData('thedata'); $this->_unitOfWork->persist($entity3); - $this->_unitOfWork->commit([$entity1,$entity2]); + $this->_unitOfWork->commit([$entity1, $entity2]); $this->assertCount(1, $this->_unitOfWork->getEntityChangeSet($entity3)); - } /** From 9707701d1056b1860d159abf732985e702fa3b9a Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 18 Aug 2017 09:15:48 +0200 Subject: [PATCH 509/877] #5579 isolating multi-entity-commit and single-entity-commit scenarios for the tracking policy changeset clearing --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 27 +++++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index d675256966d..1d3ca771e8e 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -364,15 +364,13 @@ public function testPersistedEntityAndClearManager() /** * @group #5579 */ - public function testEntityChangeSetIsNotClearedAfterFlushOnEntityOrArrayOfEntity() : void + public function testEntityChangeSetIsNotClearedAfterFlushOnSingleEntity() : void { $entity1 = new NotifyChangedEntity; $entity2 = new NotifyChangedEntity; - $entity3 = new NotifyChangedEntity; $entity1->setData('thedata'); $entity2->setData('thedata'); - $entity3->setData('thedata'); $this->_unitOfWork->persist($entity1); $this->_unitOfWork->persist($entity2); @@ -380,11 +378,30 @@ public function testEntityChangeSetIsNotClearedAfterFlushOnEntityOrArrayOfEntity $this->_unitOfWork->commit($entity1); $this->assertEmpty($this->_unitOfWork->getEntityChangeSet($entity1)); $this->assertCount(1, $this->_unitOfWork->getEntityChangeSet($entity2)); + } + + /** + * @group #5579 + */ + public function testEntityChangeSetIsNotClearedAfterFlushOnArrayOfEntities() : void + { + $entity1 = new NotifyChangedEntity; + $entity2 = new NotifyChangedEntity; + $entity3 = new NotifyChangedEntity; + + $entity1->setData('thedata'); + $entity2->setData('thedata'); + $entity3->setData('thedata'); + $this->_unitOfWork->persist($entity1); + $this->_unitOfWork->persist($entity2); $this->_unitOfWork->persist($entity3); - $this->_unitOfWork->commit([$entity1, $entity2]); - $this->assertCount(1, $this->_unitOfWork->getEntityChangeSet($entity3)); + $this->_unitOfWork->commit([$entity1, $entity3]); + + $this->assertEmpty($this->_unitOfWork->getEntityChangeSet($entity1)); + $this->assertEmpty($this->_unitOfWork->getEntityChangeSet($entity3)); + $this->assertCount(1, $this->_unitOfWork->getEntityChangeSet($entity2)); } /** From 2921f068b7df94fa2576249f83ea0a7ef961a0b4 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 18 Aug 2017 09:21:53 +0200 Subject: [PATCH 510/877] #5579 cleaning up `postCommitClear` implementation --- lib/Doctrine/ORM/UnitOfWork.php | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 367d9f4d2af..0e8fb4caaab 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -418,12 +418,10 @@ public function commit($entity = null) } /** - * @param null|object|array $entity + * @param null|object|object[] $entity */ - private function postCommitClear($entity = null) + private function postCommitClear($entity) : void { - - // Clear up $this->entityInsertions = $this->entityUpdates = $this->entityDeletions = @@ -431,22 +429,24 @@ private function postCommitClear($entity = null) $this->collectionUpdates = $this->collectionDeletions = $this->visitedCollections = - $this->orphanRemovals = array(); + $this->orphanRemovals = []; if (null === $entity) { $this->entityChangeSets = $this->scheduledForSynchronization = []; + return; } - if (is_object($entity)) { - $entity = [$entity]; - } + $entities = \is_object($entity) + ? [$entity] + : $entity; + + foreach ($entities as $object) { + $oid = \spl_object_hash($object); - foreach ($entity as $object) { - $oid = spl_object_hash($object); - $class = $this->em->getClassMetadata(get_class($object)); $this->clearEntityChangeSet($oid); - $this->clearScheduledForSynchronization($class, $oid); + + unset($this->scheduledForSynchronization[$this->em->getClassMetadata(\get_class($object))->rootEntityName][$oid]); } } @@ -3127,15 +3127,6 @@ private function clearEntityChangeSet($oid) $this->entityChangeSets[$oid] = []; } - /** - * @param $class - * @param string $oid - */ - private function clearScheduledForSynchronization($class, $oid) - { - unset($this->scheduledForSynchronization[$class->rootEntityName][$oid]); - } - /* PropertyChangedListener implementation */ /** From 9d7be0f927fdd4db955f41e4fc939860a34c6399 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 18 Aug 2017 09:22:23 +0200 Subject: [PATCH 511/877] #5579 s/clear/cleanup --- lib/Doctrine/ORM/UnitOfWork.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 0e8fb4caaab..4cdf26f96ae 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -414,13 +414,13 @@ public function commit($entity = null) $this->dispatchPostFlushEvent(); - $this->postCommitClear($entity); + $this->postCommitCleanup($entity); } /** * @param null|object|object[] $entity */ - private function postCommitClear($entity) : void + private function postCommitCleanup($entity) : void { $this->entityInsertions = $this->entityUpdates = From ff15a2bc79451c54c607800caee506aa00462835 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 18 Aug 2017 09:23:28 +0200 Subject: [PATCH 512/877] #5579 correcting visibility of `clearEntityChangeSet`, which should be reverted to `public` --- lib/Doctrine/ORM/UnitOfWork.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 4cdf26f96ae..349be6dcb44 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -3122,7 +3122,7 @@ public function registerManaged($entity, array $id, array $data) * * @return void */ - private function clearEntityChangeSet($oid) + public function clearEntityChangeSet($oid) { $this->entityChangeSets[$oid] = []; } From 1bf8465f439e17689c30a7dcf3c64d0f04259c7f Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 18 Aug 2017 09:25:47 +0200 Subject: [PATCH 513/877] #5579 correcting assertion static/instance method usage --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 1d3ca771e8e..bfad30be859 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -376,8 +376,8 @@ public function testEntityChangeSetIsNotClearedAfterFlushOnSingleEntity() : void $this->_unitOfWork->persist($entity2); $this->_unitOfWork->commit($entity1); - $this->assertEmpty($this->_unitOfWork->getEntityChangeSet($entity1)); - $this->assertCount(1, $this->_unitOfWork->getEntityChangeSet($entity2)); + self::assertEmpty($this->_unitOfWork->getEntityChangeSet($entity1)); + self::assertCount(1, $this->_unitOfWork->getEntityChangeSet($entity2)); } /** @@ -399,9 +399,9 @@ public function testEntityChangeSetIsNotClearedAfterFlushOnArrayOfEntities() : v $this->_unitOfWork->commit([$entity1, $entity3]); - $this->assertEmpty($this->_unitOfWork->getEntityChangeSet($entity1)); - $this->assertEmpty($this->_unitOfWork->getEntityChangeSet($entity3)); - $this->assertCount(1, $this->_unitOfWork->getEntityChangeSet($entity2)); + self::assertEmpty($this->_unitOfWork->getEntityChangeSet($entity1)); + self::assertEmpty($this->_unitOfWork->getEntityChangeSet($entity3)); + self::assertCount(1, $this->_unitOfWork->getEntityChangeSet($entity2)); } /** From 496c22db0eab243c5dd54368150fce4f93f787e1 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 18 Aug 2017 09:27:47 +0200 Subject: [PATCH 514/877] #5579 completely removing a changeset when cleaning up --- lib/Doctrine/ORM/UnitOfWork.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 349be6dcb44..4f8ce32db21 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -3124,7 +3124,7 @@ public function registerManaged($entity, array $id, array $data) */ public function clearEntityChangeSet($oid) { - $this->entityChangeSets[$oid] = []; + unset($this->entityChangeSets[$oid]); } /* PropertyChangedListener implementation */ From d4db126bb07558408ff2d1e112ef0831191dd539 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 18 Aug 2017 10:17:52 +0200 Subject: [PATCH 515/877] Remove code duplication of the getAllDiscriminators method --- lib/Doctrine/ORM/Query.php | 22 ++---------- lib/Doctrine/ORM/Query/SqlWalker.php | 22 ++---------- .../HierarchyDiscriminatorResolver.php | 34 +++++++++++++++++++ 3 files changed, 38 insertions(+), 40 deletions(-) create mode 100644 lib/Doctrine/ORM/Utility/HierarchyDiscriminatorResolver.php diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index a86cf620124..222586a1f74 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -27,6 +27,7 @@ use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Query\ParameterTypeInferer; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\ORM\Utility\HierarchyDiscriminatorResolver; /** * A Query object represents a DQL query. @@ -371,25 +372,6 @@ private function evictEntityCacheRegion() $this->_em->getCache()->evictEntityRegion($className); } - private function getAllDiscriminators(ClassMetadata $classMetadata) - { - // FIXME: this code is copied from SqlWalker->getAllDiscriminators() - $hierarchyClasses = $classMetadata->subClasses; - $hierarchyClasses[] = $classMetadata->name; - - $discriminators = []; - foreach ($hierarchyClasses as $class) { - $currentMetadata = $this->getEntityManager()->getClassMetadata($class); - $currentDiscriminator = $currentMetadata->discriminatorValue; - - if (null !== $currentDiscriminator) { - $discriminators[$currentDiscriminator] = null; - } - } - - return $discriminators; - } - /** * Processes query parameter mappings. * @@ -418,7 +400,7 @@ private function processParameterMappings($paramMappings) } if (isset($rsm->discriminatorParameters[$key]) && $value instanceof ClassMetadata) { - $value = array_keys($this->getAllDiscriminators($value)); + $value = array_keys(HierarchyDiscriminatorResolver::resolveDiscriminatorsForClass($value, $this->_em)); } $value = $this->processParameterValue($value); diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 3407b0a8b5a..186187025bc 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -25,6 +25,7 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\OptimisticLockException; use Doctrine\ORM\Query; +use Doctrine\ORM\Utility\HierarchyDiscriminatorResolver; use Doctrine\ORM\Utility\PersisterHelper; /** @@ -2292,7 +2293,7 @@ private function getChildDiscriminatorsFromClassMetadata(ClassMetadataInfo $root throw QueryException::instanceOfUnrelatedClass($parameter, $rootClass->name); } - $discriminators = $discriminators + $this->getAllDiscriminators($metadata); + $discriminators += HierarchyDiscriminatorResolver::resolveDiscriminatorsForClass($metadata, $this->em); } foreach (array_keys($discriminators) as $dis) { @@ -2301,23 +2302,4 @@ private function getChildDiscriminatorsFromClassMetadata(ClassMetadataInfo $root return '(' . implode(', ', $sqlParameterList) . ')'; } - - private function getAllDiscriminators(ClassMetadata $classMetadata) - { - // FIXME: this code is identical to Query->getAllDiscriminators() - $hierarchyClasses = $classMetadata->subClasses; - $hierarchyClasses[] = $classMetadata->name; - - $discriminators = []; - foreach ($hierarchyClasses as $class) { - $currentMetadata = $this->em->getClassMetadata($class); - $currentDiscriminator = $currentMetadata->discriminatorValue; - - if (null !== $currentDiscriminator) { - $discriminators[$currentDiscriminator] = null; - } - } - - return $discriminators; - } } diff --git a/lib/Doctrine/ORM/Utility/HierarchyDiscriminatorResolver.php b/lib/Doctrine/ORM/Utility/HierarchyDiscriminatorResolver.php new file mode 100644 index 00000000000..a8ac100a54c --- /dev/null +++ b/lib/Doctrine/ORM/Utility/HierarchyDiscriminatorResolver.php @@ -0,0 +1,34 @@ +subClasses; + $hierarchyClasses[] = $rootClassMetadata->name; + + $discriminators = []; + foreach ($hierarchyClasses as $class) { + $currentMetadata = $entityManager->getClassMetadata($class); + $currentDiscriminator = $currentMetadata->discriminatorValue; + + if (null !== $currentDiscriminator) { + $discriminators[$currentDiscriminator] = null; + } + } + + return $discriminators; + } +} From 5224a89549453a8a021fbfd47d93829efecc0f5b Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 18 Aug 2017 11:02:28 +0200 Subject: [PATCH 516/877] Apply various and CS fixes as per review --- .../Utility/HierarchyDiscriminatorResolver.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Utility/HierarchyDiscriminatorResolver.php b/lib/Doctrine/ORM/Utility/HierarchyDiscriminatorResolver.php index a8ac100a54c..9b08b7f17d1 100644 --- a/lib/Doctrine/ORM/Utility/HierarchyDiscriminatorResolver.php +++ b/lib/Doctrine/ORM/Utility/HierarchyDiscriminatorResolver.php @@ -6,20 +6,27 @@ use Doctrine\ORM\EntityManagerInterface; /** - * Class HierarchyDiscriminatorResolver - * @package Doctrine\ORM\Utility * @internal This class exists only to avoid code duplication, do not reuse it externally */ -class HierarchyDiscriminatorResolver +final class HierarchyDiscriminatorResolver { + private function __construct() + { + } + + /** + * This method is needed to make INSTANCEOF work correctly with inheritance: if the class at hand has inheritance, + * it extracts all the discriminators from the child classes and returns them + */ public static function resolveDiscriminatorsForClass( ClassMetadata $rootClassMetadata, EntityManagerInterface $entityManager - ) { + ): array { $hierarchyClasses = $rootClassMetadata->subClasses; $hierarchyClasses[] = $rootClassMetadata->name; $discriminators = []; + foreach ($hierarchyClasses as $class) { $currentMetadata = $entityManager->getClassMetadata($class); $currentDiscriminator = $currentMetadata->discriminatorValue; From 9864a5a9b9c85abe50a3ce6a897ad347b42f317c Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 18 Aug 2017 12:11:09 +0200 Subject: [PATCH 517/877] Add unit test for HierarchyDiscriminatorResolverTest --- .../HierarchyDiscriminatorResolverTest.php | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Utility/HierarchyDiscriminatorResolverTest.php diff --git a/tests/Doctrine/Tests/ORM/Utility/HierarchyDiscriminatorResolverTest.php b/tests/Doctrine/Tests/ORM/Utility/HierarchyDiscriminatorResolverTest.php new file mode 100644 index 00000000000..cffb8cd3b33 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Utility/HierarchyDiscriminatorResolverTest.php @@ -0,0 +1,56 @@ +name = 'Some\Class\Child\Name'; + $childClassMetadata->discriminatorValue = 'child-discriminator'; + + $classMetadata = new ClassMetadata('Entity'); + $classMetadata->subClasses = [$childClassMetadata->name]; + $classMetadata->name = 'Some\Class\Name'; + $classMetadata->discriminatorValue = 'discriminator'; + + $em = $this->prophesize(EntityManagerInterface::class); + $em->getClassMetadata($classMetadata->name) + ->shouldBeCalled() + ->willReturn($classMetadata); + $em->getClassMetadata($childClassMetadata->name) + ->shouldBeCalled() + ->willReturn($childClassMetadata); + + $discriminators = HierarchyDiscriminatorResolver::resolveDiscriminatorsForClass($classMetadata, $em->reveal()); + + $this->assertCount(2, $discriminators); + $this->assertArrayHasKey($classMetadata->discriminatorValue, $discriminators); + $this->assertArrayHasKey($childClassMetadata->discriminatorValue, $discriminators); + } + + public function testResolveDiscriminatorsForClassWithNoSubclasses() + { + $classMetadata = new ClassMetadata('Entity'); + $classMetadata->subClasses = []; + $classMetadata->name = 'Some\Class\Name'; + $classMetadata->discriminatorValue = 'discriminator'; + + $em = $this->prophesize(EntityManagerInterface::class); + $em->getClassMetadata($classMetadata->name) + ->shouldBeCalled() + ->willReturn($classMetadata); + + $discriminators = HierarchyDiscriminatorResolver::resolveDiscriminatorsForClass($classMetadata, $em->reveal()); + + $this->assertCount(1, $discriminators); + $this->assertArrayHasKey($classMetadata->discriminatorValue, $discriminators); + } +} From 19bc4991aef1cc7a1be2747e937d3b0b38560ebe Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 18 Aug 2017 12:35:51 +0200 Subject: [PATCH 518/877] Add more CS fixes --- lib/Doctrine/ORM/Query/SqlWalker.php | 2 +- .../Ticket/Ticket4646InstanceOfAbstractTest.php | 10 +++++----- .../Ticket/Ticket4646InstanceOfMultiLevelTest.php | 10 +++++----- .../Ticket/Ticket4646InstanceOfParametricTest.php | 10 +++++----- .../ORM/Functional/Ticket/Ticket4646InstanceOfTest.php | 10 +++++----- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 186187025bc..bc86ec8f678 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -2276,7 +2276,7 @@ public function walkResultVariable($resultVariable) * @return string The list in parentheses of valid child discriminators from the given class * @throws QueryException */ - private function getChildDiscriminatorsFromClassMetadata(ClassMetadataInfo $rootClass, AST\InstanceOfExpression $instanceOfExpr) + private function getChildDiscriminatorsFromClassMetadata(ClassMetadataInfo $rootClass, AST\InstanceOfExpression $instanceOfExpr): string { $sqlParameterList = []; $discriminators = []; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php index f0ea53fe87f..5fa5cdc86ea 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfAbstractTest.php @@ -6,7 +6,7 @@ class Ticket4646InstanceOfAbstractTest extends OrmFunctionalTestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -16,7 +16,7 @@ protected function setUp() ]); } - public function testInstanceOf() + public function testInstanceOf(): void { $this->_em->persist(new EmployeeTicket4646Abstract()); $this->_em->flush(); @@ -26,8 +26,8 @@ public function testInstanceOf() $query = $this->_em->createQuery($dql); $result = $query->getResult(); - $this->assertCount(1, $result); - $this->assertContainsOnlyInstancesOf(PersonTicket4646Abstract::class, $result); + self::assertCount(1, $result); + self::assertContainsOnlyInstancesOf(PersonTicket4646Abstract::class, $result); } } @@ -49,7 +49,7 @@ abstract class PersonTicket4646Abstract */ private $id; - public function getId() + public function getId(): ?int { return $this->id; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php index 6e4160b24f2..2c111a9e613 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfMultiLevelTest.php @@ -6,7 +6,7 @@ class Ticket4646InstanceOfMultiLevelTest extends OrmFunctionalTestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -17,7 +17,7 @@ protected function setUp() ]); } - public function testInstanceOf() + public function testInstanceOf(): void { $this->_em->persist(new PersonTicket4646MultiLevel()); $this->_em->persist(new EmployeeTicket4646MultiLevel()); @@ -29,8 +29,8 @@ public function testInstanceOf() $query = $this->_em->createQuery($dql); $result = $query->getResult(); - $this->assertCount(3, $result); - $this->assertContainsOnlyInstancesOf(PersonTicket4646MultiLevel::class, $result); + self::assertCount(3, $result); + self::assertContainsOnlyInstancesOf(PersonTicket4646MultiLevel::class, $result); } } @@ -54,7 +54,7 @@ class PersonTicket4646MultiLevel */ private $id; - public function getId() + public function getId(): ?int { return $this->id; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfParametricTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfParametricTest.php index 302934e8c10..bf11c3a85d6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfParametricTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfParametricTest.php @@ -6,7 +6,7 @@ class Ticket4646InstanceOfParametricTest extends OrmFunctionalTestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->_schemaTool->createSchema([ @@ -15,7 +15,7 @@ protected function setUp() ]); } - public function testInstanceOf() + public function testInstanceOf(): void { $this->_em->persist(new PersonTicket4646Parametric()); $this->_em->persist(new EmployeeTicket4646Parametric()); @@ -28,8 +28,8 @@ public function testInstanceOf() $this->_em->getClassMetadata(PersonTicket4646Parametric::class) ); $result = $query->getResult(); - $this->assertCount(2, $result); - $this->assertContainsOnlyInstancesOf(PersonTicket4646Parametric::class, $result); + self::assertCount(2, $result); + self::assertContainsOnlyInstancesOf(PersonTicket4646Parametric::class, $result); } } @@ -52,7 +52,7 @@ class PersonTicket4646Parametric */ private $id; - public function getId() + public function getId(): ?int { return $this->id; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php index 363611d4db8..0ed97243c0e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfTest.php @@ -6,7 +6,7 @@ class Ticket4646InstanceOfTest extends OrmFunctionalTestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -16,7 +16,7 @@ protected function setUp() ]); } - public function testInstanceOf() + public function testInstanceOf(): void { $this->_em->persist(new PersonTicket4646()); $this->_em->persist(new EmployeeTicket4646()); @@ -27,8 +27,8 @@ public function testInstanceOf() $query = $this->_em->createQuery($dql); $result = $query->getResult(); - $this->assertCount(2, $result); - $this->assertContainsOnlyInstancesOf(PersonTicket4646::class, $result); + self::assertCount(2, $result); + self::assertContainsOnlyInstancesOf(PersonTicket4646::class, $result); } } @@ -51,7 +51,7 @@ class PersonTicket4646 */ private $id; - public function getId() + public function getId(): ?int { return $this->id; } From eb762dea2301ad45123a81c62b8fb81add595404 Mon Sep 17 00:00:00 2001 From: Aljosha Papsch Date: Fri, 18 Aug 2017 14:23:43 +0200 Subject: [PATCH 519/877] XmlDriver: Avoid PHP bug #62577 by avoiding simplexml_load_file. Doctrine is affected by PHP bug #62577. simplexml_load_file is not able to load files if libxml_disable_entity_loader(true) has been called. simplexml_load_file fails with the message: I/O warning : failed to load external entity "/my/mappings/my_entity.dcm.xml" in /path-to/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php on line 711 This error occurs even if there are no external entities in the XML file. Waiting for the PHP bug to be resolved is infeasible, because it is unresolved since years. Therefore Doctrine needs to circumvent the bug by replacing simplexml_load_file with simplexml_load_string while getting the file contents itself. simplexml_load_string is not affected by the PHP bug. --- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 39af412c9f2..0d72c208767 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -838,7 +838,7 @@ private function _getCascadeMappings(SimpleXMLElement $cascadeElement) protected function loadMappingFile($file) { $result = []; - $xmlElement = simplexml_load_file($file); + $xmlElement = simplexml_load_string(file_get_contents($file)); if (isset($xmlElement->entity)) { foreach ($xmlElement->entity as $entityElement) { From c799c6da8be7b7d9d15ef119614cee914f51d8c3 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Fri, 18 Aug 2017 13:10:04 +0200 Subject: [PATCH 520/877] Add new functional test to check usage of INSTANCEOF with multiple parameters --- ...46InstanceOfWithMultipleParametersTest.php | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfWithMultipleParametersTest.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfWithMultipleParametersTest.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfWithMultipleParametersTest.php new file mode 100644 index 00000000000..c8c172ab694 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket4646InstanceOfWithMultipleParametersTest.php @@ -0,0 +1,88 @@ +_schemaTool->createSchema([ + $this->_em->getClassMetadata(PersonTicket4646Multiple::class), + $this->_em->getClassMetadata(EmployeeTicket4646Multiple::class), + $this->_em->getClassMetadata(ManagerTicket4646Multiple::class), + $this->_em->getClassMetadata(InternTicket4646Multiple::class), + ]); + } + + public function testInstanceOf(): void + { + $this->_em->persist(new PersonTicket4646Multiple()); + $this->_em->persist(new EmployeeTicket4646Multiple()); + $this->_em->persist(new ManagerTicket4646Multiple()); + $this->_em->persist(new InternTicket4646Multiple()); + $this->_em->flush(); + + $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646Multiple p + WHERE p INSTANCE OF (Doctrine\Tests\ORM\Functional\Ticket\EmployeeTicket4646Multiple, Doctrine\Tests\ORM\Functional\Ticket\InternTicket4646Multiple)'; + $query = $this->_em->createQuery($dql); + $result = $query->getResult(); + + self::assertCount(2, $result); + self::assertContainsOnlyInstancesOf(PersonTicket4646Multiple::class, $result); + } +} + +/** + * @Entity() + * @Table(name="instance_of_test_multiple_person") + * @InheritanceType(value="JOINED") + * @DiscriminatorColumn(name="kind", type="string") + * @DiscriminatorMap(value={ + * "person": "Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646Multiple", + * "employee": "Doctrine\Tests\ORM\Functional\Ticket\EmployeeTicket4646Multiple", + * "manager": "Doctrine\Tests\ORM\Functional\Ticket\ManagerTicket4646Multiple", + * "intern": "Doctrine\Tests\ORM\Functional\Ticket\InternTicket4646Multiple" + * }) + */ +class PersonTicket4646Multiple +{ + /** + * @Id() + * @GeneratedValue() + * @Column(type="integer") + */ + private $id; + + public function getId() + { + return $this->id; + } +} + +/** + * @Entity() + * @Table(name="instance_of_test_multiple_employee") + */ +class EmployeeTicket4646Multiple extends PersonTicket4646Multiple +{ +} + +/** + * @Entity() + * @Table(name="instance_of_test_multiple_manager") + */ +class ManagerTicket4646Multiple extends PersonTicket4646Multiple +{ +} + +/** + * @Entity() + * @Table(name="instance_of_test_multiple_intern") + */ +class InternTicket4646Multiple extends PersonTicket4646Multiple +{ +} From 492fb50744f3c019c28792c0668abef4bb5562dd Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 18 Aug 2017 21:08:14 +0200 Subject: [PATCH 521/877] #6633 #3788 documenting why `simplexml_load_file()` was not used --- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 0d72c208767..ca270727863 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -838,6 +838,7 @@ private function _getCascadeMappings(SimpleXMLElement $cascadeElement) protected function loadMappingFile($file) { $result = []; + // Note: we do not use `simplexml_load_file()` because of https://bugs.php.net/bug.php?id=62577 $xmlElement = simplexml_load_string(file_get_contents($file)); if (isset($xmlElement->entity)) { From aac523d15578b05084c13ec7f9dde9d8fe35186e Mon Sep 17 00:00:00 2001 From: Full Date: Sat, 4 Mar 2017 15:09:29 +0100 Subject: [PATCH 522/877] tests with custom inheritance tree --- .../Tests/Models/DDC6303/DDC6303Contract.php | 24 ++++++++ .../Tests/Models/DDC6303/DDC6303ContractA.php | 17 ++++++ .../Tests/Models/DDC6303/DDC6303ContractB.php | 17 ++++++ .../ORM/Functional/Ticket/DDC6303Test.php | 56 +++++++++++++++++++ .../Doctrine/Tests/OrmFunctionalTestCase.php | 6 ++ 5 files changed, 120 insertions(+) create mode 100644 tests/Doctrine/Tests/Models/DDC6303/DDC6303Contract.php create mode 100644 tests/Doctrine/Tests/Models/DDC6303/DDC6303ContractA.php create mode 100644 tests/Doctrine/Tests/Models/DDC6303/DDC6303ContractB.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php diff --git a/tests/Doctrine/Tests/Models/DDC6303/DDC6303Contract.php b/tests/Doctrine/Tests/Models/DDC6303/DDC6303Contract.php new file mode 100644 index 00000000000..ccb2dee343a --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC6303/DDC6303Contract.php @@ -0,0 +1,24 @@ +useModelSet('ddc6303'); + parent::setUp(); + } + + public function testMixedTypeHydratedCorrectlyInJoinedInheritance() + { + $contractA = new DDC6303ContractA(); + $contractAData = 'authorized'; + $contractA->originalData = $contractAData; + + $contractB = new DDC6303ContractB(); + $contractBData = ['accepted', 'authorized']; + $contractB->originalData = $contractBData; + + $this->_em->persist($contractA); + $this->_em->persist($contractB); + + $this->_em->flush(); + + // clear entity manager so that $repository->find actually fetches them and uses the hydrator + // instead of just returning the existing managed entities + $this->_em->clear(); + + $repository = $this->_em->getRepository(DDC6303Contract::class); + + $contracts = $repository->createQueryBuilder('p') + ->getQuery()->getResult(); + + foreach( $contracts as $contract ){ + switch( $contract->id ){ + case $contractA->id: + static::assertEquals($contract->originalData, $contractAData); + break; + + case $contractB->id: + static::assertEquals($contract->originalData, $contractBData); + break; + } + } + } +} diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index e9299b1c685..5618fa1200b 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -312,6 +312,12 @@ abstract class OrmFunctionalTestCase extends OrmTestCase Models\Issue5989\Issue5989Employee::class, Models\Issue5989\Issue5989Manager::class, ], + 'ddc6303' => [ + Models\DDC6303\DDC6303Contract::class, + Models\DDC6303\DDC6303ContractA::class, + Models\DDC6303\DDC6303ContractB::class, + ] + ]; /** From 6d40859228d64ef6f2c5477042182bfd8bfd110d Mon Sep 17 00:00:00 2001 From: Full Date: Sat, 4 Mar 2017 15:27:02 +0100 Subject: [PATCH 523/877] added tests on empty values --- .../Internal/Hydration/AbstractHydrator.php | 6 ++- .../ORM/Functional/Ticket/DDC6303Test.php | 45 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index 04e98c72ea8..7490e3e4ff0 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -294,10 +294,14 @@ protected function gatherRowData(array $data, array &$id, array &$nonemptyCompon $dqlAlias = $cacheKeyInfo['dqlAlias']; $type = $cacheKeyInfo['type']; + var_dump($dqlAlias); + var_dump($cacheKeyInfo); + echo "\n\n\n"; + // in an inheritance hierarchy the same field could be defined several times. // We overwrite this value so long we don't have a non-null value, that value we keep. // Per definition it cannot be that a field is defined several times and has several values. - if (isset($rowData['data'][$dqlAlias][$fieldName])) { + if (!empty($rowData['data'][$dqlAlias][$fieldName])) { break; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php index 96dd32f9bc2..d967b3b7f13 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php @@ -53,4 +53,49 @@ public function testMixedTypeHydratedCorrectlyInJoinedInheritance() } } } + + public function testEmptyValuesInJoinedInheritance() + { + $contractStringEmptyData = ''; + $contractStringZeroData = 0; + + $contractArrayEmptyData = []; + + $contractStringEmpty = new DDC6303ContractA(); + $contractStringEmpty->originalData = $contractStringEmptyData; + + $contractStringZero = new DDC6303ContractA(); + $contractStringZero->originalData = $contractStringZeroData; + + $contractArrayEmpty = new DDC6303ContractB(); + $contractArrayEmpty->originalData = $contractArrayEmptyData; + + $this->_em->persist($contractStringZero); + $this->_em->persist($contractStringEmpty); + $this->_em->persist($contractArrayEmpty); + + $this->_em->flush(); + + // clear entity manager so that $repository->find actually fetches them and uses the hydrator + // instead of just returning the existing managed entities + $this->_em->clear(); + + $repository = $this->_em->getRepository(DDC6303Contract::class); + $dataMap = [ + $contractStringZero->id => $contractStringZeroData, + $contractStringEmpty->id => $contractStringEmptyData, + $contractArrayEmpty->id => $contractArrayEmptyData, + ]; + + $contracts = $repository->createQueryBuilder('p') + ->where('p.id IN(:ids)') + ->setParameter('ids', array_keys($dataMap)) + ->getQuery()->getResult(); + + + + foreach( $contracts as $contract ){ + static::assertEquals($contract->originalData, $dataMap[$contract->id], 'contract ' . get_class($contract) . ' not equals to original'); + } + } } From ad3b9de4b8a9a272fdb8c8183087148dd5b09114 Mon Sep 17 00:00:00 2001 From: Full Date: Sat, 4 Mar 2017 17:17:31 +0100 Subject: [PATCH 524/877] use dataMap also in first test function --- .../Internal/Hydration/AbstractHydrator.php | 37 +++++++++++++------ .../ORM/Functional/Ticket/DDC6303Test.php | 21 +++++------ 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index 7490e3e4ff0..dda16b0b644 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -294,17 +294,20 @@ protected function gatherRowData(array $data, array &$id, array &$nonemptyCompon $dqlAlias = $cacheKeyInfo['dqlAlias']; $type = $cacheKeyInfo['type']; - var_dump($dqlAlias); - var_dump($cacheKeyInfo); - echo "\n\n\n"; - + if( + isset($cacheKeyInfo['discriminatorColumn']) && + isset($data[$cacheKeyInfo['discriminatorColumn']]) && + $data[$cacheKeyInfo['discriminatorColumn']] != $cacheKeyInfo['discriminatorValue'] + ){ + break; + } // in an inheritance hierarchy the same field could be defined several times. // We overwrite this value so long we don't have a non-null value, that value we keep. // Per definition it cannot be that a field is defined several times and has several values. - if (!empty($rowData['data'][$dqlAlias][$fieldName])) { + if (isset($rowData['data'][$dqlAlias][$fieldName])) { break; } - + $rowData['data'][$dqlAlias][$fieldName] = $type ? $type->convertToPHPValue($value, $this->_platform) : $value; @@ -379,13 +382,23 @@ protected function hydrateColumnInfo($key) $classMetadata = $this->getClassMetadata($this->_rsm->declaringClasses[$key]); $fieldName = $this->_rsm->fieldMappings[$key]; $fieldMapping = $classMetadata->fieldMappings[$fieldName]; - - return $this->_cache[$key] = [ - 'isIdentifier' => in_array($fieldName, $classMetadata->identifier), - 'fieldName' => $fieldName, - 'type' => Type::getType($fieldMapping['type']), - 'dqlAlias' => $this->_rsm->columnOwnerMap[$key], + $ownerMap = $this->_rsm->columnOwnerMap[$key]; + + $returnArray = [ + 'isIdentifier' => in_array($fieldName, $classMetadata->identifier), + 'fieldName' => $fieldName, + 'type' => Type::getType($fieldMapping['type']), + 'dqlAlias' => $ownerMap, + ]; + if( !empty($classMetadata->parentClasses)){ + $returnArray += [ + 'discriminatorColumn' => $this->_rsm->discriminatorColumns[$ownerMap], + 'discriminatorValue' => $classMetadata->discriminatorValue + ]; + } + + return $this->_cache[$key] = $returnArray; case (isset($this->_rsm->newObjectMappings[$key])): // WARNING: A NEW object is also a scalar, so it must be declared before! diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php index d967b3b7f13..a065e1d9660 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php @@ -38,19 +38,18 @@ public function testMixedTypeHydratedCorrectlyInJoinedInheritance() $repository = $this->_em->getRepository(DDC6303Contract::class); + $dataMap = [ + $contractA->id => $contractAData, + $contractB->id => $contractBData + ]; + $contracts = $repository->createQueryBuilder('p') - ->getQuery()->getResult(); + ->where('p.id IN(:ids)') + ->setParameter('ids', array_keys($dataMap)) + ->getQuery()->getResult(); foreach( $contracts as $contract ){ - switch( $contract->id ){ - case $contractA->id: - static::assertEquals($contract->originalData, $contractAData); - break; - - case $contractB->id: - static::assertEquals($contract->originalData, $contractBData); - break; - } + static::assertEquals($contract->originalData, $dataMap[$contract->id], 'contract ' . get_class($contract) . ' not equals to original'); } } @@ -92,8 +91,6 @@ public function testEmptyValuesInJoinedInheritance() ->setParameter('ids', array_keys($dataMap)) ->getQuery()->getResult(); - - foreach( $contracts as $contract ){ static::assertEquals($contract->originalData, $dataMap[$contract->id], 'contract ' . get_class($contract) . ' not equals to original'); } From bf06b7dbbcb20a68c2e51744591c1a5bed2d2f00 Mon Sep 17 00:00:00 2001 From: Full Date: Sat, 4 Mar 2017 17:39:27 +0100 Subject: [PATCH 525/877] check if array is set before assigning --- lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index dda16b0b644..7d2e642468a 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -391,7 +391,7 @@ protected function hydrateColumnInfo($key) 'dqlAlias' => $ownerMap, ]; - if( !empty($classMetadata->parentClasses)){ + if( !empty($classMetadata->parentClasses && isset($this->_rsm->discriminatorColumns[$ownerMap]))){ $returnArray += [ 'discriminatorColumn' => $this->_rsm->discriminatorColumns[$ownerMap], 'discriminatorValue' => $classMetadata->discriminatorValue From 0b8e468f06114e3422779caabb91713d1a64d3da Mon Sep 17 00:00:00 2001 From: Full Date: Sat, 11 Mar 2017 20:24:46 +0100 Subject: [PATCH 526/877] fix wrong pharenthesis --- lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index 7d2e642468a..ae12a89477c 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -391,7 +391,7 @@ protected function hydrateColumnInfo($key) 'dqlAlias' => $ownerMap, ]; - if( !empty($classMetadata->parentClasses && isset($this->_rsm->discriminatorColumns[$ownerMap]))){ + if( !empty($classMetadata->parentClasses) && isset($this->_rsm->discriminatorColumns[$ownerMap])){ $returnArray += [ 'discriminatorColumn' => $this->_rsm->discriminatorColumns[$ownerMap], 'discriminatorValue' => $classMetadata->discriminatorValue From 0072054020415fed75ee8e53f8670f25add651cc Mon Sep 17 00:00:00 2001 From: Full Date: Sat, 11 Mar 2017 20:37:32 +0100 Subject: [PATCH 527/877] moved all test models into test class --- .../Tests/Models/DDC6303/DDC6303Contract.php | 24 ------- .../Tests/Models/DDC6303/DDC6303ContractA.php | 17 ----- .../Tests/Models/DDC6303/DDC6303ContractB.php | 17 ----- .../ORM/Functional/Ticket/DDC6303Test.php | 66 +++++++++++++++++-- .../Doctrine/Tests/OrmFunctionalTestCase.php | 5 -- 5 files changed, 61 insertions(+), 68 deletions(-) delete mode 100644 tests/Doctrine/Tests/Models/DDC6303/DDC6303Contract.php delete mode 100644 tests/Doctrine/Tests/Models/DDC6303/DDC6303ContractA.php delete mode 100644 tests/Doctrine/Tests/Models/DDC6303/DDC6303ContractB.php diff --git a/tests/Doctrine/Tests/Models/DDC6303/DDC6303Contract.php b/tests/Doctrine/Tests/Models/DDC6303/DDC6303Contract.php deleted file mode 100644 index ccb2dee343a..00000000000 --- a/tests/Doctrine/Tests/Models/DDC6303/DDC6303Contract.php +++ /dev/null @@ -1,24 +0,0 @@ -useModelSet('ddc6303'); parent::setUp(); + try { + $this->_schemaTool->createSchema( + [ + $this->_em->getClassMetadata(DDC6303Contract::class), + $this->_em->getClassMetadata(DDC6303ContractA::class), + $this->_em->getClassMetadata(DDC6303ContractB::class) + ] + ); + } catch (\Exception $ignored) {} } public function testMixedTypeHydratedCorrectlyInJoinedInheritance() @@ -96,3 +100,55 @@ public function testEmptyValuesInJoinedInheritance() } } } + + +/** + * @Entity + * @Table(name="ddc6303_contract") + * @InheritanceType("JOINED") + * @DiscriminatorColumn(name="discr", type="string") + * @DiscriminatorMap({ + * "contract" = "DDC6303Contract", + * "contract_b" = "DDC6303ContractB", + * "contract_a" = "DDC6303ContractA" + * }) + */ +class DDC6303Contract +{ + /** + * @Id + * @Column(type="integer") + * @GeneratedValue + */ + public $id; +} + + +/** + * @Entity + * @Table(name="ddc6303_contracts_a") + */ +class DDC6303ContractA extends DDC6303Contract +{ + /** + * @Column(type="string", nullable=true) + * + * @var string + */ + public $originalData; +} + + +/** + * @Entity + * @Table(name="ddc6303_contracts_b") + */ +class DDC6303ContractB extends DDC6303Contract +{ + /** + * @Column(type="simple_array", nullable=true) + * + * @var array + */ + public $originalData; +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 5618fa1200b..f4ba8827544 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -311,11 +311,6 @@ abstract class OrmFunctionalTestCase extends OrmTestCase Models\Issue5989\Issue5989Person::class, Models\Issue5989\Issue5989Employee::class, Models\Issue5989\Issue5989Manager::class, - ], - 'ddc6303' => [ - Models\DDC6303\DDC6303Contract::class, - Models\DDC6303\DDC6303ContractA::class, - Models\DDC6303\DDC6303ContractB::class, ] ]; From 4c7286f57b652ad248d83c3bcbd1661c63701799 Mon Sep 17 00:00:00 2001 From: Full Date: Sat, 11 Mar 2017 20:39:10 +0100 Subject: [PATCH 528/877] removed trailing spaces --- lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index ae12a89477c..062f54b31c7 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -307,7 +307,7 @@ protected function gatherRowData(array $data, array &$id, array &$nonemptyCompon if (isset($rowData['data'][$dqlAlias][$fieldName])) { break; } - + $rowData['data'][$dqlAlias][$fieldName] = $type ? $type->convertToPHPValue($value, $this->_platform) : $value; From 82db643b4f9c1496259de7c17750b8f2c59efc0d Mon Sep 17 00:00:00 2001 From: fullbl Date: Sun, 19 Mar 2017 15:05:29 +0100 Subject: [PATCH 529/877] clarified what's the problem in a comment --- tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php index c11bc49da91..163dce1374b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php @@ -28,6 +28,7 @@ public function testMixedTypeHydratedCorrectlyInJoinedInheritance() $contractA->originalData = $contractAData; $contractB = new DDC6303ContractB(); + //contractA and contractB have an inheritance from Contract, but one has a string originalData and the second has an array $contractBData = ['accepted', 'authorized']; $contractB->originalData = $contractBData; @@ -61,7 +62,6 @@ public function testEmptyValuesInJoinedInheritance() { $contractStringEmptyData = ''; $contractStringZeroData = 0; - $contractArrayEmptyData = []; $contractStringEmpty = new DDC6303ContractA(); @@ -151,4 +151,4 @@ class DDC6303ContractB extends DDC6303Contract * @var array */ public $originalData; -} \ No newline at end of file +} From db9c12f1aff1866aec0594a7035305b53fd86d07 Mon Sep 17 00:00:00 2001 From: Full Date: Sun, 2 Apr 2017 14:37:29 +0200 Subject: [PATCH 530/877] comparison on discriminator value with !== --- lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index 062f54b31c7..95cffa1255a 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -297,10 +297,11 @@ protected function gatherRowData(array $data, array &$id, array &$nonemptyCompon if( isset($cacheKeyInfo['discriminatorColumn']) && isset($data[$cacheKeyInfo['discriminatorColumn']]) && - $data[$cacheKeyInfo['discriminatorColumn']] != $cacheKeyInfo['discriminatorValue'] + $data[$cacheKeyInfo['discriminatorColumn']] !== $cacheKeyInfo['discriminatorValue'] ){ break; } + // in an inheritance hierarchy the same field could be defined several times. // We overwrite this value so long we don't have a non-null value, that value we keep. // Per definition it cannot be that a field is defined several times and has several values. From 8cc29e84a0d68edbb8a5f09bf4bdc90b18190c6f Mon Sep 17 00:00:00 2001 From: fullbl Date: Mon, 26 Jun 2017 10:42:09 +0200 Subject: [PATCH 531/877] Update AbstractHydrator.php revert strict comparison in hydration (fails on some dates) --- lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index 95cffa1255a..f430cb91287 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -297,7 +297,7 @@ protected function gatherRowData(array $data, array &$id, array &$nonemptyCompon if( isset($cacheKeyInfo['discriminatorColumn']) && isset($data[$cacheKeyInfo['discriminatorColumn']]) && - $data[$cacheKeyInfo['discriminatorColumn']] !== $cacheKeyInfo['discriminatorValue'] + $data[$cacheKeyInfo['discriminatorColumn']] != $cacheKeyInfo['discriminatorValue'] ){ break; } From 7e7921e32f3c89992c522af7bc4927c74b7b62c8 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 19 Aug 2017 15:58:50 +0200 Subject: [PATCH 532/877] #6303 #6304 documenting why the loose comparison is required --- lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index f430cb91287..7c7e2ef813e 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -297,8 +297,9 @@ protected function gatherRowData(array $data, array &$id, array &$nonemptyCompon if( isset($cacheKeyInfo['discriminatorColumn']) && isset($data[$cacheKeyInfo['discriminatorColumn']]) && + // Note: loose comparison required. See https://github.com/doctrine/doctrine2/pull/6304#issuecomment-323294442 $data[$cacheKeyInfo['discriminatorColumn']] != $cacheKeyInfo['discriminatorValue'] - ){ + ) { break; } From c503b81421f35f092cecfd172fa7ed9e2d62e2e3 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 19 Aug 2017 16:02:30 +0200 Subject: [PATCH 533/877] #6303 #6304 removing `+=` operator usage on arrays (scary\!), CS (alignment) --- .../Internal/Hydration/AbstractHydrator.php | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index 7c7e2ef813e..b90d7779002 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -385,22 +385,24 @@ protected function hydrateColumnInfo($key) $fieldName = $this->_rsm->fieldMappings[$key]; $fieldMapping = $classMetadata->fieldMappings[$fieldName]; $ownerMap = $this->_rsm->columnOwnerMap[$key]; - - $returnArray = [ - 'isIdentifier' => in_array($fieldName, $classMetadata->identifier), - 'fieldName' => $fieldName, - 'type' => Type::getType($fieldMapping['type']), - 'dqlAlias' => $ownerMap, - + $columnInfo = [ + 'isIdentifier' => \in_array($fieldName, $classMetadata->identifier, true), + 'fieldName' => $fieldName, + 'type' => Type::getType($fieldMapping['type']), + 'dqlAlias' => $ownerMap, ]; - if( !empty($classMetadata->parentClasses) && isset($this->_rsm->discriminatorColumns[$ownerMap])){ - $returnArray += [ - 'discriminatorColumn' => $this->_rsm->discriminatorColumns[$ownerMap], - 'discriminatorValue' => $classMetadata->discriminatorValue - ]; + + if($classMetadata->parentClasses && isset($this->_rsm->discriminatorColumns[$ownerMap])) { + return $this->_cache[$key] = \array_merge( + $columnInfo, + [ + 'discriminatorColumn' => $this->_rsm->discriminatorColumns[$ownerMap], + 'discriminatorValue' => $classMetadata->discriminatorValue + ] + ); } - return $this->_cache[$key] = $returnArray; + return $this->_cache[$key] = $columnInfo; case (isset($this->_rsm->newObjectMappings[$key])): // WARNING: A NEW object is also a scalar, so it must be declared before! From aaad25a06174e4dc71123806404a28cd9deaa0d1 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 19 Aug 2017 16:25:20 +0200 Subject: [PATCH 534/877] #6303 #6304 reverting changes to the `OrmFunctionalTestCase` --- tests/Doctrine/Tests/OrmFunctionalTestCase.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index f4ba8827544..e9299b1c685 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -311,8 +311,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase Models\Issue5989\Issue5989Person::class, Models\Issue5989\Issue5989Employee::class, Models\Issue5989\Issue5989Manager::class, - ] - + ], ]; /** From f6ce69fe296ebfa3b2dae790cf39b3d4c91e7ab4 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 19 Aug 2017 16:37:24 +0200 Subject: [PATCH 535/877] #6303 #6304 minor CS fixes in the test code - alignment/formatting --- .../ORM/Functional/Ticket/DDC6303Test.php | 129 ++++++++---------- 1 file changed, 60 insertions(+), 69 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php index 163dce1374b..f11d9974f72 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php @@ -2,109 +2,120 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\DBAL\Schema\SchemaException; +use Doctrine\Tests\OrmFunctionalTestCase; + /** - * @group DDC6303 + * @group #6303 */ -class DDC6303Test extends \Doctrine\Tests\OrmFunctionalTestCase +class DDC6303Test extends OrmFunctionalTestCase { public function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema( - [ + $this->_schemaTool->createSchema([ $this->_em->getClassMetadata(DDC6303Contract::class), $this->_em->getClassMetadata(DDC6303ContractA::class), - $this->_em->getClassMetadata(DDC6303ContractB::class) - ] - ); - } catch (\Exception $ignored) {} + $this->_em->getClassMetadata(DDC6303ContractB::class), + ]); + } catch (SchemaException $ignored) { + } } - + public function testMixedTypeHydratedCorrectlyInJoinedInheritance() { - $contractA = new DDC6303ContractA(); - $contractAData = 'authorized'; + $contractA = new DDC6303ContractA(); + $contractAData = 'authorized'; $contractA->originalData = $contractAData; $contractB = new DDC6303ContractB(); //contractA and contractB have an inheritance from Contract, but one has a string originalData and the second has an array - $contractBData = ['accepted', 'authorized']; + $contractBData = ['accepted', 'authorized']; $contractB->originalData = $contractBData; $this->_em->persist($contractA); $this->_em->persist($contractB); $this->_em->flush(); - + // clear entity manager so that $repository->find actually fetches them and uses the hydrator // instead of just returning the existing managed entities $this->_em->clear(); - $repository = $this->_em->getRepository(DDC6303Contract::class); + $repository = $this->_em->getRepository(DDC6303Contract::class); $dataMap = [ $contractA->id => $contractAData, - $contractB->id => $contractBData - ]; + $contractB->id => $contractBData, + ]; - $contracts = $repository->createQueryBuilder('p') + $contracts = $repository + ->createQueryBuilder('p') ->where('p.id IN(:ids)') ->setParameter('ids', array_keys($dataMap)) - ->getQuery()->getResult(); + ->getQuery()->getResult(); - foreach( $contracts as $contract ){ - static::assertEquals($contract->originalData, $dataMap[$contract->id], 'contract ' . get_class($contract) . ' not equals to original'); + foreach ($contracts as $contract) { + static::assertEquals( + $contract->originalData, + $dataMap[$contract->id], + 'contract ' . get_class($contract) . ' not equals to original' + ); } - } + } - public function testEmptyValuesInJoinedInheritance() + public function testEmptyValuesInJoinedInheritance() { $contractStringEmptyData = ''; - $contractStringZeroData = 0; - $contractArrayEmptyData = []; + $contractStringZeroData = 0; + $contractArrayEmptyData = []; $contractStringEmpty = new DDC6303ContractA(); - $contractStringEmpty->originalData = $contractStringEmptyData; - - $contractStringZero = new DDC6303ContractA(); - $contractStringZero->originalData = $contractStringZeroData; + $contractStringZero = new DDC6303ContractA(); + $contractArrayEmpty = new DDC6303ContractB(); - $contractArrayEmpty = new DDC6303ContractB(); - $contractArrayEmpty->originalData = $contractArrayEmptyData; + $contractStringEmpty->originalData = $contractStringEmptyData; + $contractStringZero->originalData = $contractStringZeroData; + $contractArrayEmpty->originalData = $contractArrayEmptyData; $this->_em->persist($contractStringZero); $this->_em->persist($contractStringEmpty); $this->_em->persist($contractArrayEmpty); $this->_em->flush(); - + // clear entity manager so that $repository->find actually fetches them and uses the hydrator // instead of just returning the existing managed entities $this->_em->clear(); - $repository = $this->_em->getRepository(DDC6303Contract::class); - $dataMap = [ - $contractStringZero->id => $contractStringZeroData, + $repository = $this->_em->getRepository(DDC6303Contract::class); + $dataMap = [ + $contractStringZero->id => $contractStringZeroData, $contractStringEmpty->id => $contractStringEmptyData, - $contractArrayEmpty->id => $contractArrayEmptyData, - ]; + $contractArrayEmpty->id => $contractArrayEmptyData, + ]; - $contracts = $repository->createQueryBuilder('p') + $contracts = $repository + ->createQueryBuilder('p') ->where('p.id IN(:ids)') ->setParameter('ids', array_keys($dataMap)) - ->getQuery()->getResult(); - - foreach( $contracts as $contract ){ - static::assertEquals($contract->originalData, $dataMap[$contract->id], 'contract ' . get_class($contract) . ' not equals to original'); + ->getQuery() + ->getResult(); + + foreach ($contracts as $contract) { + static::assertEquals( + $contract->originalData, + $dataMap[$contract->id], + 'contract ' . get_class($contract) . ' not equals to original' + ); } - } + } } - /** * @Entity - * @Table(name="ddc6303_contract") + * @Table * @InheritanceType("JOINED") * @DiscriminatorColumn(name="discr", type="string") * @DiscriminatorMap({ @@ -115,40 +126,20 @@ public function testEmptyValuesInJoinedInheritance() */ class DDC6303Contract { - /** - * @Id - * @Column(type="integer") - * @GeneratedValue - */ + /** @Id @Column(type="integer") @GeneratedValue */ public $id; } - -/** - * @Entity - * @Table(name="ddc6303_contracts_a") - */ +/** @Entity @Table */ class DDC6303ContractA extends DDC6303Contract { - /** - * @Column(type="string", nullable=true) - * - * @var string - */ + /** @Column(type="string", nullable=true) */ public $originalData; } - -/** - * @Entity - * @Table(name="ddc6303_contracts_b") - */ +/** @Entity @Table */ class DDC6303ContractB extends DDC6303Contract { - /** - * @Column(type="simple_array", nullable=true) - * - * @var array - */ + /** @Column(type="simple_array", nullable=true) */ public $originalData; } From 328467c226d408d25ff39aa096f927d3e0d7f199 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 19 Aug 2017 16:48:50 +0200 Subject: [PATCH 536/877] #6303 #6304 simplified tests, removing references to `contract` naming --- .../ORM/Functional/Ticket/DDC6303Test.php | 57 ++++++++++--------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php index f11d9974f72..5852be817f6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; use Doctrine\DBAL\Schema\SchemaException; +use Doctrine\ORM\Tools\ToolsException; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -13,29 +14,33 @@ class DDC6303Test extends OrmFunctionalTestCase public function setUp() { parent::setUp(); + try { $this->_schemaTool->createSchema([ - $this->_em->getClassMetadata(DDC6303Contract::class), - $this->_em->getClassMetadata(DDC6303ContractA::class), - $this->_em->getClassMetadata(DDC6303ContractB::class), + $this->_em->getClassMetadata(DDC6303BaseClass::class), + $this->_em->getClassMetadata(DDC6303ChildA::class), + $this->_em->getClassMetadata(DDC6303ChildB::class), ]); - } catch (SchemaException $ignored) { + } catch (ToolsException $ignored) { } } public function testMixedTypeHydratedCorrectlyInJoinedInheritance() { - $contractA = new DDC6303ContractA(); - $contractAData = 'authorized'; - $contractA->originalData = $contractAData; + $a = new DDC6303ChildA(); + $b = new DDC6303ChildB(); + + $aData = 'authorized'; + $bData = ['accepted', 'authorized']; - $contractB = new DDC6303ContractB(); - //contractA and contractB have an inheritance from Contract, but one has a string originalData and the second has an array - $contractBData = ['accepted', 'authorized']; - $contractB->originalData = $contractBData; + // DDC6303ChildA and DDC6303ChildB have an inheritance from DDC6303BaseClass, + // but one has a string originalData and the second has an array, since the fields + // are mapped differently + $a->originalData = $aData; + $b->originalData = $bData; - $this->_em->persist($contractA); - $this->_em->persist($contractB); + $this->_em->persist($a); + $this->_em->persist($b); $this->_em->flush(); @@ -43,11 +48,11 @@ public function testMixedTypeHydratedCorrectlyInJoinedInheritance() // instead of just returning the existing managed entities $this->_em->clear(); - $repository = $this->_em->getRepository(DDC6303Contract::class); + $repository = $this->_em->getRepository(DDC6303BaseClass::class); $dataMap = [ - $contractA->id => $contractAData, - $contractB->id => $contractBData, + $a->id => $aData, + $b->id => $bData, ]; $contracts = $repository @@ -71,9 +76,9 @@ public function testEmptyValuesInJoinedInheritance() $contractStringZeroData = 0; $contractArrayEmptyData = []; - $contractStringEmpty = new DDC6303ContractA(); - $contractStringZero = new DDC6303ContractA(); - $contractArrayEmpty = new DDC6303ContractB(); + $contractStringEmpty = new DDC6303ChildA(); + $contractStringZero = new DDC6303ChildA(); + $contractArrayEmpty = new DDC6303ChildB(); $contractStringEmpty->originalData = $contractStringEmptyData; $contractStringZero->originalData = $contractStringZeroData; @@ -89,13 +94,14 @@ public function testEmptyValuesInJoinedInheritance() // instead of just returning the existing managed entities $this->_em->clear(); - $repository = $this->_em->getRepository(DDC6303Contract::class); + $repository = $this->_em->getRepository(DDC6303BaseClass::class); $dataMap = [ $contractStringZero->id => $contractStringZeroData, $contractStringEmpty->id => $contractStringEmptyData, $contractArrayEmpty->id => $contractArrayEmptyData, ]; + /* @var $contracts DDC6303ChildA[]|DDC6303ChildB[] */ $contracts = $repository ->createQueryBuilder('p') ->where('p.id IN(:ids)') @@ -119,26 +125,25 @@ public function testEmptyValuesInJoinedInheritance() * @InheritanceType("JOINED") * @DiscriminatorColumn(name="discr", type="string") * @DiscriminatorMap({ - * "contract" = "DDC6303Contract", - * "contract_b" = "DDC6303ContractB", - * "contract_a" = "DDC6303ContractA" + * DDC6303ChildA::class = DDC6303ChildA::class, + * DDC6303ChildB::class = DDC6303ChildB::class, * }) */ -class DDC6303Contract +abstract class DDC6303BaseClass { /** @Id @Column(type="integer") @GeneratedValue */ public $id; } /** @Entity @Table */ -class DDC6303ContractA extends DDC6303Contract +class DDC6303ChildA extends DDC6303BaseClass { /** @Column(type="string", nullable=true) */ public $originalData; } /** @Entity @Table */ -class DDC6303ContractB extends DDC6303Contract +class DDC6303ChildB extends DDC6303BaseClass { /** @Column(type="simple_array", nullable=true) */ public $originalData; From 0882b1021361be132e3e06027c3f022b58330731 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 19 Aug 2017 16:51:31 +0200 Subject: [PATCH 537/877] #6303 #6304 simplified tests, removing references to `contract` naming --- .../ORM/Functional/Ticket/DDC6303Test.php | 57 ++++++++++--------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php index 5852be817f6..042e5a648fc 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php @@ -55,38 +55,39 @@ public function testMixedTypeHydratedCorrectlyInJoinedInheritance() $b->id => $bData, ]; - $contracts = $repository + /* @var $entities DDC6303ChildA[]|DDC6303ChildB[] */ + $entities = $repository ->createQueryBuilder('p') ->where('p.id IN(:ids)') ->setParameter('ids', array_keys($dataMap)) ->getQuery()->getResult(); - foreach ($contracts as $contract) { - static::assertEquals( - $contract->originalData, - $dataMap[$contract->id], - 'contract ' . get_class($contract) . ' not equals to original' + foreach ($entities as $entity) { + self::assertEquals( + $entity->originalData, + $dataMap[$entity->id], + get_class($entity) . ' not equals to original' ); } } public function testEmptyValuesInJoinedInheritance() { - $contractStringEmptyData = ''; - $contractStringZeroData = 0; - $contractArrayEmptyData = []; + $stringEmptyData = ''; + $stringZeroData = 0; + $arrayEmptyData = []; - $contractStringEmpty = new DDC6303ChildA(); - $contractStringZero = new DDC6303ChildA(); - $contractArrayEmpty = new DDC6303ChildB(); + $stringEmpty = new DDC6303ChildA(); + $stringZero = new DDC6303ChildA(); + $arrayEmpty = new DDC6303ChildB(); - $contractStringEmpty->originalData = $contractStringEmptyData; - $contractStringZero->originalData = $contractStringZeroData; - $contractArrayEmpty->originalData = $contractArrayEmptyData; + $stringEmpty->originalData = $stringEmptyData; + $stringZero->originalData = $stringZeroData; + $arrayEmpty->originalData = $arrayEmptyData; - $this->_em->persist($contractStringZero); - $this->_em->persist($contractStringEmpty); - $this->_em->persist($contractArrayEmpty); + $this->_em->persist($stringZero); + $this->_em->persist($stringEmpty); + $this->_em->persist($arrayEmpty); $this->_em->flush(); @@ -96,24 +97,24 @@ public function testEmptyValuesInJoinedInheritance() $repository = $this->_em->getRepository(DDC6303BaseClass::class); $dataMap = [ - $contractStringZero->id => $contractStringZeroData, - $contractStringEmpty->id => $contractStringEmptyData, - $contractArrayEmpty->id => $contractArrayEmptyData, + $stringZero->id => $stringZeroData, + $stringEmpty->id => $stringEmptyData, + $arrayEmpty->id => $arrayEmptyData, ]; - /* @var $contracts DDC6303ChildA[]|DDC6303ChildB[] */ - $contracts = $repository + /* @var $entities DDC6303ChildA[]|DDC6303ChildB[] */ + $entities = $repository ->createQueryBuilder('p') ->where('p.id IN(:ids)') ->setParameter('ids', array_keys($dataMap)) ->getQuery() ->getResult(); - foreach ($contracts as $contract) { - static::assertEquals( - $contract->originalData, - $dataMap[$contract->id], - 'contract ' . get_class($contract) . ' not equals to original' + foreach ($entities as $entity) { + self::assertEquals( + $entity->originalData, + $dataMap[$entity->id], + get_class($entity) . ' not equals to original' ); } } From 2ab363ab8228d11a2da87e76eaee28c8c1e8403a Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 19 Aug 2017 16:53:41 +0200 Subject: [PATCH 538/877] #6303 #6304 adding `void` hints where applicable --- tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php index 042e5a648fc..a6cd5a7d673 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\DBAL\Schema\SchemaException; use Doctrine\ORM\Tools\ToolsException; use Doctrine\Tests\OrmFunctionalTestCase; @@ -11,7 +10,7 @@ */ class DDC6303Test extends OrmFunctionalTestCase { - public function setUp() + public function setUp() : void { parent::setUp(); @@ -25,7 +24,7 @@ public function setUp() } } - public function testMixedTypeHydratedCorrectlyInJoinedInheritance() + public function testMixedTypeHydratedCorrectlyInJoinedInheritance() : void { $a = new DDC6303ChildA(); $b = new DDC6303ChildB(); @@ -71,7 +70,7 @@ public function testMixedTypeHydratedCorrectlyInJoinedInheritance() } } - public function testEmptyValuesInJoinedInheritance() + public function testEmptyValuesInJoinedInheritance() : void { $stringEmptyData = ''; $stringZeroData = 0; From e18fb6607d202ffcb6f05a23a2b79f962fc86b62 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 19 Aug 2017 17:04:26 +0200 Subject: [PATCH 539/877] #6303 #6304 removing duplicate test details --- .../ORM/Functional/Ticket/DDC6303Test.php | 114 +++++++----------- 1 file changed, 41 insertions(+), 73 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php index a6cd5a7d673..51fcb1292b6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php @@ -26,95 +26,51 @@ public function setUp() : void public function testMixedTypeHydratedCorrectlyInJoinedInheritance() : void { - $a = new DDC6303ChildA(); - $b = new DDC6303ChildB(); - - $aData = 'authorized'; - $bData = ['accepted', 'authorized']; - // DDC6303ChildA and DDC6303ChildB have an inheritance from DDC6303BaseClass, // but one has a string originalData and the second has an array, since the fields // are mapped differently - $a->originalData = $aData; - $b->originalData = $bData; - - $this->_em->persist($a); - $this->_em->persist($b); - - $this->_em->flush(); - - // clear entity manager so that $repository->find actually fetches them and uses the hydrator - // instead of just returning the existing managed entities - $this->_em->clear(); - - $repository = $this->_em->getRepository(DDC6303BaseClass::class); + $this->assertHydratedEntitiesSameToPersistedOnes([ + 'a' => new DDC6303ChildA('a', 'authorized'), + 'b' => new DDC6303ChildB('b', ['accepted', 'authorized']), + ]); - $dataMap = [ - $a->id => $aData, - $b->id => $bData, - ]; - - /* @var $entities DDC6303ChildA[]|DDC6303ChildB[] */ - $entities = $repository - ->createQueryBuilder('p') - ->where('p.id IN(:ids)') - ->setParameter('ids', array_keys($dataMap)) - ->getQuery()->getResult(); - - foreach ($entities as $entity) { - self::assertEquals( - $entity->originalData, - $dataMap[$entity->id], - get_class($entity) . ' not equals to original' - ); - } } public function testEmptyValuesInJoinedInheritance() : void { - $stringEmptyData = ''; - $stringZeroData = 0; - $arrayEmptyData = []; - - $stringEmpty = new DDC6303ChildA(); - $stringZero = new DDC6303ChildA(); - $arrayEmpty = new DDC6303ChildB(); - - $stringEmpty->originalData = $stringEmptyData; - $stringZero->originalData = $stringZeroData; - $arrayEmpty->originalData = $arrayEmptyData; - - $this->_em->persist($stringZero); - $this->_em->persist($stringEmpty); - $this->_em->persist($arrayEmpty); + $this->assertHydratedEntitiesSameToPersistedOnes([ + 'stringEmpty' => new DDC6303ChildA('stringEmpty', ''), + 'stringZero' => new DDC6303ChildA('stringZero', 0), + 'arrayEmpty' => new DDC6303ChildB('arrayEmpty', []), + ]); + } + /** + * @param DDC6303ChildA[]|DDC6303ChildB[] $persistedEntities indexed by identifier + * + * @throws \Doctrine\Common\Persistence\Mapping\MappingException + * @throws \Doctrine\ORM\ORMException + * @throws \Doctrine\ORM\OptimisticLockException + */ + private function assertHydratedEntitiesSameToPersistedOnes(array $persistedEntities) : void + { + array_walk($persistedEntities, [$this->_em, 'persist']); $this->_em->flush(); - - // clear entity manager so that $repository->find actually fetches them and uses the hydrator - // instead of just returning the existing managed entities $this->_em->clear(); - $repository = $this->_em->getRepository(DDC6303BaseClass::class); - $dataMap = [ - $stringZero->id => $stringZeroData, - $stringEmpty->id => $stringEmptyData, - $arrayEmpty->id => $arrayEmptyData, - ]; - /* @var $entities DDC6303ChildA[]|DDC6303ChildB[] */ - $entities = $repository + $entities = $this + ->_em + ->getRepository(DDC6303BaseClass::class) ->createQueryBuilder('p') ->where('p.id IN(:ids)') - ->setParameter('ids', array_keys($dataMap)) - ->getQuery() - ->getResult(); + ->setParameter('ids', array_keys($persistedEntities)) + ->getQuery()->getResult(); + + self::assertCount(count($persistedEntities), $entities); foreach ($entities as $entity) { - self::assertEquals( - $entity->originalData, - $dataMap[$entity->id], - get_class($entity) . ' not equals to original' - ); + self::assertEquals($entity, $persistedEntities[$entity->id]); } } } @@ -131,7 +87,7 @@ public function testEmptyValuesInJoinedInheritance() : void */ abstract class DDC6303BaseClass { - /** @Id @Column(type="integer") @GeneratedValue */ + /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ public $id; } @@ -140,6 +96,12 @@ class DDC6303ChildA extends DDC6303BaseClass { /** @Column(type="string", nullable=true) */ public $originalData; + + public function __construct(string $id, string $originalData) + { + $this->id = $id; + $this->originalData = $originalData; + } } /** @Entity @Table */ @@ -147,4 +109,10 @@ class DDC6303ChildB extends DDC6303BaseClass { /** @Column(type="simple_array", nullable=true) */ public $originalData; + + public function __construct(string $id, array $originalData) + { + $this->id = $id; + $this->originalData = $originalData; + } } From 468496be1a9800c56ca4dbb6bcced18d09077a4d Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 19 Aug 2017 17:05:44 +0200 Subject: [PATCH 540/877] #6303 #6304 using strict types in the tests --- tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php index 51fcb1292b6..17e9566719b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php @@ -1,4 +1,5 @@ id = $id; $this->originalData = $originalData; From 764ab5988288e80dfa68ad51d49a5ae550c9eb2c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 19 Aug 2017 17:06:27 +0200 Subject: [PATCH 541/877] #6303 #6304 making unnecessary visible fields `private` --- tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php index 17e9566719b..1847dcde28c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php @@ -96,7 +96,7 @@ abstract class DDC6303BaseClass class DDC6303ChildA extends DDC6303BaseClass { /** @Column(type="string", nullable=true) */ - public $originalData; + private $originalData; public function __construct(string $id, $originalData) { @@ -109,7 +109,7 @@ public function __construct(string $id, $originalData) class DDC6303ChildB extends DDC6303BaseClass { /** @Column(type="simple_array", nullable=true) */ - public $originalData; + private $originalData; public function __construct(string $id, array $originalData) { From 8af68614fcdc69b2d8cc1f136cb28b4dbf2e8bf3 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 19 Aug 2017 17:45:26 +0200 Subject: [PATCH 542/877] #6303 #6304 correcting type mapping. For `simple_array`, `[] == null` (which is bullshit), so we use `array` here --- .../ORM/Functional/Ticket/DDC6303Test.php | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php index 1847dcde28c..79324d0f29e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php @@ -24,24 +24,24 @@ public function setUp() : void } catch (ToolsException $ignored) { } } - - public function testMixedTypeHydratedCorrectlyInJoinedInheritance() : void - { - // DDC6303ChildA and DDC6303ChildB have an inheritance from DDC6303BaseClass, - // but one has a string originalData and the second has an array, since the fields - // are mapped differently - $this->assertHydratedEntitiesSameToPersistedOnes([ - 'a' => new DDC6303ChildA('a', 'authorized'), - 'b' => new DDC6303ChildB('b', ['accepted', 'authorized']), - ]); - - } - +// +// public function testMixedTypeHydratedCorrectlyInJoinedInheritance() : void +// { +// // DDC6303ChildA and DDC6303ChildB have an inheritance from DDC6303BaseClass, +// // but one has a string originalData and the second has an array, since the fields +// // are mapped differently +// $this->assertHydratedEntitiesSameToPersistedOnes([ +// 'a' => new DDC6303ChildA('a', 'authorized'), +// 'b' => new DDC6303ChildB('b', ['accepted', 'authorized']), +// ]); +// +// } +// public function testEmptyValuesInJoinedInheritance() : void { $this->assertHydratedEntitiesSameToPersistedOnes([ - 'stringEmpty' => new DDC6303ChildA('stringEmpty', ''), - 'stringZero' => new DDC6303ChildA('stringZero', 0), +// 'stringEmpty' => new DDC6303ChildA('stringEmpty', ''), +// 'stringZero' => new DDC6303ChildA('stringZero', 0), 'arrayEmpty' => new DDC6303ChildB('arrayEmpty', []), ]); } @@ -95,7 +95,7 @@ abstract class DDC6303BaseClass /** @Entity @Table */ class DDC6303ChildA extends DDC6303BaseClass { - /** @Column(type="string", nullable=true) */ + /** @Column(type="string") */ private $originalData; public function __construct(string $id, $originalData) @@ -108,7 +108,7 @@ public function __construct(string $id, $originalData) /** @Entity @Table */ class DDC6303ChildB extends DDC6303BaseClass { - /** @Column(type="simple_array", nullable=true) */ + /** @Column(type="array") */ private $originalData; public function __construct(string $id, array $originalData) From 42d9162bd507bb656af8468d2ba3a4413802189f Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 19 Aug 2017 17:47:12 +0200 Subject: [PATCH 543/877] #6303 #6304 re-enabling disabled test code data --- .../ORM/Functional/Ticket/DDC6303Test.php | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php index 79324d0f29e..7c4510c0690 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php @@ -24,24 +24,24 @@ public function setUp() : void } catch (ToolsException $ignored) { } } -// -// public function testMixedTypeHydratedCorrectlyInJoinedInheritance() : void -// { -// // DDC6303ChildA and DDC6303ChildB have an inheritance from DDC6303BaseClass, -// // but one has a string originalData and the second has an array, since the fields -// // are mapped differently -// $this->assertHydratedEntitiesSameToPersistedOnes([ -// 'a' => new DDC6303ChildA('a', 'authorized'), -// 'b' => new DDC6303ChildB('b', ['accepted', 'authorized']), -// ]); -// -// } -// + + public function testMixedTypeHydratedCorrectlyInJoinedInheritance() : void + { + // DDC6303ChildA and DDC6303ChildB have an inheritance from DDC6303BaseClass, + // but one has a string originalData and the second has an array, since the fields + // are mapped differently + $this->assertHydratedEntitiesSameToPersistedOnes([ + 'a' => new DDC6303ChildA('a', 'authorized'), + 'b' => new DDC6303ChildB('b', ['accepted', 'authorized']), + ]); + + } + public function testEmptyValuesInJoinedInheritance() : void { $this->assertHydratedEntitiesSameToPersistedOnes([ -// 'stringEmpty' => new DDC6303ChildA('stringEmpty', ''), -// 'stringZero' => new DDC6303ChildA('stringZero', 0), + 'stringEmpty' => new DDC6303ChildA('stringEmpty', ''), + 'stringZero' => new DDC6303ChildA('stringZero', 0), 'arrayEmpty' => new DDC6303ChildB('arrayEmpty', []), ]); } From b66643d52ef0e61ee14575d00ecfabcb76e13a96 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 19 Aug 2017 17:49:14 +0200 Subject: [PATCH 544/877] #6303 #6304 removing useless union type usage --- tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php index 7c4510c0690..32cb5ce973c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php @@ -47,7 +47,7 @@ public function testEmptyValuesInJoinedInheritance() : void } /** - * @param DDC6303ChildA[]|DDC6303ChildB[] $persistedEntities indexed by identifier + * @param DDC6303BaseClass[] $persistedEntities indexed by identifier * * @throws \Doctrine\Common\Persistence\Mapping\MappingException * @throws \Doctrine\ORM\ORMException @@ -59,7 +59,7 @@ private function assertHydratedEntitiesSameToPersistedOnes(array $persistedEntit $this->_em->flush(); $this->_em->clear(); - /* @var $entities DDC6303ChildA[]|DDC6303ChildB[] */ + /* @var $entities DDC6303BaseClass[] */ $entities = $this ->_em ->getRepository(DDC6303BaseClass::class) From 4cbcdb761a947c9026c0dfe850337e3cc045b1a6 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 19 Aug 2017 18:25:44 +0200 Subject: [PATCH 545/877] #6303 #6304 documenting that the discriminator map order is extremely important for this test --- tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php index 32cb5ce973c..732808b5f09 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php @@ -82,9 +82,11 @@ private function assertHydratedEntitiesSameToPersistedOnes(array $persistedEntit * @InheritanceType("JOINED") * @DiscriminatorColumn(name="discr", type="string") * @DiscriminatorMap({ - * DDC6303ChildA::class = DDC6303ChildA::class, * DDC6303ChildB::class = DDC6303ChildB::class, + * DDC6303ChildA::class = DDC6303ChildA::class, * }) + * + * Note: discriminator map order *IS IMPORTANT* for this test */ abstract class DDC6303BaseClass { @@ -108,7 +110,7 @@ public function __construct(string $id, $originalData) /** @Entity @Table */ class DDC6303ChildB extends DDC6303BaseClass { - /** @Column(type="array") */ + /** @Column(type="simple_array", nullable=true) */ private $originalData; public function __construct(string $id, array $originalData) From 44f2e22f1433fe704deb9b9e7a051b205070aa27 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 19 Aug 2017 18:30:33 +0200 Subject: [PATCH 546/877] #6303 #6304 documenting why collisions in field name hydration in STI/JTI require additional information and checks in the hydration process --- lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index b90d7779002..b38a212c9e6 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -294,6 +294,8 @@ protected function gatherRowData(array $data, array &$id, array &$nonemptyCompon $dqlAlias = $cacheKeyInfo['dqlAlias']; $type = $cacheKeyInfo['type']; + // If there are field name collisions in the child class, then we need + // to only hydrate if we are looking at the correct discriminator value if( isset($cacheKeyInfo['discriminatorColumn']) && isset($data[$cacheKeyInfo['discriminatorColumn']]) && @@ -392,7 +394,9 @@ protected function hydrateColumnInfo($key) 'dqlAlias' => $ownerMap, ]; - if($classMetadata->parentClasses && isset($this->_rsm->discriminatorColumns[$ownerMap])) { + // the current discriminator value must be saved in order to disambiguate fields hydration, + // should there be field name collisions + if ($classMetadata->parentClasses && isset($this->_rsm->discriminatorColumns[$ownerMap])) { return $this->_cache[$key] = \array_merge( $columnInfo, [ From 9eaf23a5e0221e546504b6008c2092a469aa0b76 Mon Sep 17 00:00:00 2001 From: Richard Date: Sun, 20 Aug 2017 05:57:00 +0200 Subject: [PATCH 547/877] Mention the nullable default value for @column Related to #6632 --- docs/en/reference/annotations-reference.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/annotations-reference.rst b/docs/en/reference/annotations-reference.rst index e55a23eff9f..1571a857b2f 100644 --- a/docs/en/reference/annotations-reference.rst +++ b/docs/en/reference/annotations-reference.rst @@ -113,7 +113,7 @@ Optional attributes: - **unique**: Boolean value to determine if the value of the column should be unique across all rows of the underlying entities table. -- **nullable**: Determines if NULL values allowed for this column. +- **nullable**: Determines if NULL values allowed for this column. If not specified, default value is false. - **options**: Array of additional options: From c4465abaa0fc968d2668a08069d041c30b2811f9 Mon Sep 17 00:00:00 2001 From: Darien Hager Date: Tue, 29 Sep 2015 16:36:48 -0700 Subject: [PATCH 548/877] Initial failing test-case to demonstrate cascade-persist problem. --- tests/Doctrine/Tests/Models/CMS/CmsEmail.php | 2 +- .../ORM/Functional/BasicFunctionalTest.php | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/Models/CMS/CmsEmail.php b/tests/Doctrine/Tests/Models/CMS/CmsEmail.php index c79c30036ab..0faf4b87651 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsEmail.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsEmail.php @@ -22,7 +22,7 @@ class CmsEmail public $email; /** - * @OneToOne(targetEntity="CmsUser", mappedBy="email") + * @OneToOne(targetEntity="CmsUser", mappedBy="email", cascade={"persist"}) */ public $user; diff --git a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php index 7bdb846535c..a61595af64e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php @@ -9,6 +9,7 @@ use Doctrine\ORM\PersistentCollection; use Doctrine\ORM\Proxy\Proxy; use Doctrine\ORM\Query; +use Doctrine\Tests\Models\CMS\CmsEmail; use Doctrine\ORM\UnitOfWork; use Doctrine\Tests\Models\CMS\CmsAddress; use Doctrine\Tests\Models\CMS\CmsArticle; @@ -801,6 +802,50 @@ public function testNewAssociatedEntityDuringFlushThrowsException3() $this->_em->flush(); } + /** + * @group DDC-2922 + */ + public function testNewAssociatedEntityWorksWithJustOnePath() + { + + /** + * First we persist and flush an e-mail with no user. This seems + * Save an un-owned email with no user. This seems to + * matter for reproducing the bug + */ + $mail = new CmsEmail(); + $mail->email = "nobody@example.com"; + $mail->user = null; + + $this->_em->persist($mail); + $this->_em->flush(); + + $user = new CmsUser(); + $user->username = "beberlei"; + $user->name = "Benjamin E."; + $user->status = 'active'; + + $mail->user = $user; + + /** + * Note that we have NOT directly persisted the CmsUser, and CmsAddress + * does NOT have cascade-persist. + * + * However, CmsEmail *does* have a cascade-persist, which ought to + * allow us to save the CmsUser anyway through that connection. + */ + $address = new CmsAddress(); + $address->city = "Bonn"; + $address->zip = "12354"; + $address->country = "Germany"; + $address->street = "somestreet"; + $address->user = $user; + + $this->_em->persist($address); + $this->_em->flush(); + + } + public function testOneToOneOrphanRemoval() { $user = new CmsUser(); From 6f8a80be79f8f026f381c33b6fd2db2cd9467962 Mon Sep 17 00:00:00 2001 From: Darien Hager Date: Tue, 29 Sep 2015 16:45:01 -0700 Subject: [PATCH 549/877] Move failing unit test into ticket-specific case --- .../ORM/Functional/BasicFunctionalTest.php | 45 ------------ .../ORM/Functional/Ticket/DDC2922Test.php | 72 +++++++++++++++++++ 2 files changed, 72 insertions(+), 45 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2922Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php index a61595af64e..7bdb846535c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php @@ -9,7 +9,6 @@ use Doctrine\ORM\PersistentCollection; use Doctrine\ORM\Proxy\Proxy; use Doctrine\ORM\Query; -use Doctrine\Tests\Models\CMS\CmsEmail; use Doctrine\ORM\UnitOfWork; use Doctrine\Tests\Models\CMS\CmsAddress; use Doctrine\Tests\Models\CMS\CmsArticle; @@ -802,50 +801,6 @@ public function testNewAssociatedEntityDuringFlushThrowsException3() $this->_em->flush(); } - /** - * @group DDC-2922 - */ - public function testNewAssociatedEntityWorksWithJustOnePath() - { - - /** - * First we persist and flush an e-mail with no user. This seems - * Save an un-owned email with no user. This seems to - * matter for reproducing the bug - */ - $mail = new CmsEmail(); - $mail->email = "nobody@example.com"; - $mail->user = null; - - $this->_em->persist($mail); - $this->_em->flush(); - - $user = new CmsUser(); - $user->username = "beberlei"; - $user->name = "Benjamin E."; - $user->status = 'active'; - - $mail->user = $user; - - /** - * Note that we have NOT directly persisted the CmsUser, and CmsAddress - * does NOT have cascade-persist. - * - * However, CmsEmail *does* have a cascade-persist, which ought to - * allow us to save the CmsUser anyway through that connection. - */ - $address = new CmsAddress(); - $address->city = "Bonn"; - $address->zip = "12354"; - $address->country = "Germany"; - $address->street = "somestreet"; - $address->user = $user; - - $this->_em->persist($address); - $this->_em->flush(); - - } - public function testOneToOneOrphanRemoval() { $user = new CmsUser(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2922Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2922Test.php new file mode 100644 index 00000000000..265f61a8649 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2922Test.php @@ -0,0 +1,72 @@ +useModelSet('cms'); + parent::setUp(); + } + + /** + * @group DDC-2922 + */ + public function testNewAssociatedEntityWorksWithJustOnePath() + { + + /** + * First we persist and flush an e-mail with no user. This seems + * Save an un-owned email with no user. This seems to + * matter for reproducing the bug + */ + $mail = new CmsEmail(); + $mail->email = "nobody@example.com"; + $mail->user = null; + + $this->_em->persist($mail); + $this->_em->flush(); + + $user = new CmsUser(); + $user->username = "beberlei"; + $user->name = "Benjamin E."; + $user->status = 'active'; + + $mail->user = $user; + + /** + * Note that we have NOT directly persisted the CmsUser, and CmsAddress + * does NOT have cascade-persist. + * + * However, CmsEmail *does* have a cascade-persist, which ought to + * allow us to save the CmsUser anyway through that connection. + */ + $address = new CmsAddress(); + $address->city = "Bonn"; + $address->zip = "12354"; + $address->country = "Germany"; + $address->street = "somestreet"; + $address->user = $user; + + $this->_em->persist($address); + try{ + $this->_em->flush(); + }catch(ORMInvalidArgumentException $e){ + if(strpos($e->getMessage(),'not configured to cascade persist operations') !== FALSE) { + $this->fail($e); + } + throw $e; + } + + + } +} \ No newline at end of file From 997000352af4587fd8f98a901db6563322f1a5bd Mon Sep 17 00:00:00 2001 From: Darien Hager Date: Tue, 29 Sep 2015 16:59:08 -0700 Subject: [PATCH 550/877] Add another test to demonstrate the bug doesn't appear if everything is flushed at once. --- .../ORM/Functional/Ticket/DDC2922Test.php | 61 ++++++++++++++----- 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2922Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2922Test.php index 265f61a8649..ce7788740da 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2922Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2922Test.php @@ -19,29 +19,64 @@ protected function setUp() } /** + * Unlike next test, this one demonstrates that the problem does + * not necessarily reproduce if all the pieces are being flushed together. + * + * @group DDC-2922 + */ + public function testNewAssociatedEntityWorksWithJustOnePathIfAllPartsNew() + { + + $user = new CmsUser(); + $user->username = "beberlei"; + $user->name = "Benjamin E."; + $user->status = 'active'; + + $email = new CmsEmail(); + $email->email = "nobody@example.com"; + $email->user = $user; + + $address = new CmsAddress(); + $address->city = "Bonn"; + $address->zip = "12354"; + $address->country = "Germany"; + $address->street = "somestreet"; + $address->user = $user; + + $this->_em->persist($email); + $this->_em->persist($address); + + $this->_em->flush(); + + } + + /** + * This test exhibits the bug describe in the ticket, where an object that + * ought to be reachable causes errors. + * * @group DDC-2922 */ public function testNewAssociatedEntityWorksWithJustOnePath() { /** - * First we persist and flush an e-mail with no user. This seems - * Save an un-owned email with no user. This seems to - * matter for reproducing the bug + * First we persist and flush an e-mail with no user. Having the + * "cascading path" involve a non-new object seems to be important to + * reproducing the bug. */ - $mail = new CmsEmail(); - $mail->email = "nobody@example.com"; - $mail->user = null; + $email = new CmsEmail(); + $email->email = "nobody@example.com"; + $email->user = null; - $this->_em->persist($mail); - $this->_em->flush(); + $this->_em->persist($email); + $this->_em->flush(); // Flush before introducing CmsUser $user = new CmsUser(); $user->username = "beberlei"; $user->name = "Benjamin E."; $user->status = 'active'; - $mail->user = $user; + $email->user = $user; /** * Note that we have NOT directly persisted the CmsUser, and CmsAddress @@ -58,15 +93,13 @@ public function testNewAssociatedEntityWorksWithJustOnePath() $address->user = $user; $this->_em->persist($address); - try{ + try { $this->_em->flush(); - }catch(ORMInvalidArgumentException $e){ - if(strpos($e->getMessage(),'not configured to cascade persist operations') !== FALSE) { + } catch (ORMInvalidArgumentException $e) { + if (strpos($e->getMessage(), 'not configured to cascade persist operations') !== FALSE) { $this->fail($e); } throw $e; } - - } } \ No newline at end of file From 92dc39bfb9bf739d5a74ba7b5c79a4f31dd9d1c6 Mon Sep 17 00:00:00 2001 From: Darien Hager Date: Tue, 29 Sep 2015 18:35:57 -0700 Subject: [PATCH 551/877] Add extra assertions to test to ensure that flush actually succeeded in saving all items --- .../Tests/ORM/Functional/Ticket/DDC2922Test.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2922Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2922Test.php index ce7788740da..188d68feea5 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2922Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2922Test.php @@ -48,6 +48,11 @@ public function testNewAssociatedEntityWorksWithJustOnePathIfAllPartsNew() $this->_em->flush(); + // Verify the flush succeeded + $this->assertEquals($email, $this->_em->find(get_class($email),$email->id)); + $this->assertEquals($address, $this->_em->find(get_class($address),$address->id)); + $this->assertEquals($user, $this->_em->find(get_class($user),$user->id)); + } /** @@ -101,5 +106,11 @@ public function testNewAssociatedEntityWorksWithJustOnePath() } throw $e; } + + // Verify the flushes succeeded + $this->assertEquals($email, $this->_em->find(get_class($email),$email->id)); + $this->assertEquals($address, $this->_em->find(get_class($address),$address->id)); + $this->assertEquals($user, $this->_em->find(get_class($user),$user->id)); + } } \ No newline at end of file From 17b996da8cf7bfd75e956e44a5bc80eb9faa32b8 Mon Sep 17 00:00:00 2001 From: Darien Hager Date: Tue, 29 Sep 2015 18:44:47 -0700 Subject: [PATCH 552/877] Speculative fix: Defer any errors for missing cascade-persist until object graph has been better-explored --- lib/Doctrine/ORM/UnitOfWork.php | 39 +++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 4f8ce32db21..7d4d8d80a40 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -178,6 +178,19 @@ class UnitOfWork implements PropertyChangedListener */ private $entityDeletions = []; + /** + * New entities that were discovered through relationships that were not + * marked as cascade-persist. During flush, this array is populated and + * then pruned of any entities that were discovered through a valid + * cascade-persist path. (Leftovers cause an error.) + * + * Keys are OIDs, payload is a two-item array describing the association + * and the entity. + * + * @var array + */ + private $newEntitiesWithoutCascade = array(); + /** * All pending collection deletions. * @@ -427,6 +440,7 @@ private function postCommitCleanup($entity) : void $this->entityDeletions = $this->extraUpdates = $this->collectionUpdates = + $this->newEntitiesWithoutCascade = $this->collectionDeletions = $this->visitedCollections = $this->orphanRemovals = []; @@ -815,6 +829,16 @@ public function computeChangeSets() } } } + + /** + * Filter out any entities that we (successfully) managed to schedule + * for insertion. + */ + $entitiesNeedingCascadePersist = array_diff_key($this->newEntitiesWithoutCascade, $this->entityInsertions); + if(count($entitiesNeedingCascadePersist) > 0){ + list($assoc,$entity) = array_values($entitiesNeedingCascadePersist)[0]; + throw ORMInvalidArgumentException::newEntityFoundThroughRelationship($assoc, $entity); + } } /** @@ -861,11 +885,17 @@ private function computeAssociationChanges($assoc, $value) switch ($state) { case self::STATE_NEW: if ( ! $assoc['isCascadePersist']) { - throw ORMInvalidArgumentException::newEntityFoundThroughRelationship($assoc, $entry); + /* + * For now just record the details, because this may + * not be an issue if we later discover another pathway + * through the object-graph where cascade-persistence + * is enabled for this object. + */ + $this->newEntitiesWithoutCascade[spl_object_hash($entry)] = array($assoc,$entry); + }else { + $this->persistNew($targetClass, $entry); + $this->computeChangeSet($targetClass, $entry); } - - $this->persistNew($targetClass, $entry); - $this->computeChangeSet($targetClass, $entry); break; case self::STATE_REMOVED: @@ -2411,6 +2441,7 @@ public function clear($entityName = null) $this->entityInsertions = $this->entityUpdates = $this->entityDeletions = + $this->newEntitiesWithoutCascade = $this->collectionDeletions = $this->collectionUpdates = $this->extraUpdates = From b456cffa2d2340fb078ba7aebba92985578db333 Mon Sep 17 00:00:00 2001 From: Darien Hager Date: Wed, 30 Sep 2015 21:04:22 -0700 Subject: [PATCH 553/877] Move final cascade-persist-checking so that it covers not just normal flushes, but also flushes where specific entities are singled out. --- lib/Doctrine/ORM/UnitOfWork.php | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 7d4d8d80a40..b3f3fb23d1a 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -347,6 +347,8 @@ public function commit($entity = null) } } + $this->assertNoCascadingGaps(); + if ( ! ($this->entityInsertions || $this->entityDeletions || $this->entityUpdates || @@ -829,16 +831,6 @@ public function computeChangeSets() } } } - - /** - * Filter out any entities that we (successfully) managed to schedule - * for insertion. - */ - $entitiesNeedingCascadePersist = array_diff_key($this->newEntitiesWithoutCascade, $this->entityInsertions); - if(count($entitiesNeedingCascadePersist) > 0){ - list($assoc,$entity) = array_values($entitiesNeedingCascadePersist)[0]; - throw ORMInvalidArgumentException::newEntityFoundThroughRelationship($assoc, $entity); - } } /** @@ -3395,6 +3387,26 @@ private function isIdentifierEquals($entity1, $entity2) return $id1 === $id2 || implode(' ', $id1) === implode(' ', $id2); } + /** + * Checks that there are no new entities found through non-cascade-persist + * paths which are not also scheduled for insertion through valid paths. + * + * @return void + * @throws ORMInvalidArgumentException + */ + private function assertNoCascadingGaps() + { + /** + * Filter out any entities that we (successfully) managed to schedule + * for insertion. + */ + $entitiesNeedingCascadePersist = array_diff_key($this->newEntitiesWithoutCascade, $this->entityInsertions); + if(count($entitiesNeedingCascadePersist) > 0){ + list($assoc,$entity) = array_values($entitiesNeedingCascadePersist)[0]; + throw ORMInvalidArgumentException::newEntityFoundThroughRelationship($assoc, $entity); + } + } + /** * @param object $entity * @param object $managedCopy From e21b29c26410837b516af43d2bc751e1dbba5e4c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Mon, 21 Aug 2017 19:44:38 +0200 Subject: [PATCH 554/877] #1521 DDC-2922 simplified test case to a minimum reproducible unit --- tests/Doctrine/Tests/Models/CMS/CmsEmail.php | 2 +- .../ORM/Functional/Ticket/DDC2922Test.php | 129 +++++++++++++++++- 2 files changed, 125 insertions(+), 6 deletions(-) diff --git a/tests/Doctrine/Tests/Models/CMS/CmsEmail.php b/tests/Doctrine/Tests/Models/CMS/CmsEmail.php index 0faf4b87651..c79c30036ab 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsEmail.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsEmail.php @@ -22,7 +22,7 @@ class CmsEmail public $email; /** - * @OneToOne(targetEntity="CmsUser", mappedBy="email", cascade={"persist"}) + * @OneToOne(targetEntity="CmsUser", mappedBy="email") */ public $user; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2922Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2922Test.php index 188d68feea5..6598be42ebf 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2922Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2922Test.php @@ -1,21 +1,34 @@ useModelSet('cms'); parent::setUp(); + + try { + $this->_schemaTool->createSchema(array_map( + function (string $className) : ClassMetadata { + return $this->_em->getClassMetadata($className); + }, + [ + DDC2922CascadePersistedEntity::class, + DDC2922EntityWithCascadingAssociation::class, + DDC2922EntityWithNonCascadingAssociation::class, + ] + )); + } catch (ToolsException $ignored) {} } /** @@ -63,7 +76,7 @@ public function testNewAssociatedEntityWorksWithJustOnePathIfAllPartsNew() */ public function testNewAssociatedEntityWorksWithJustOnePath() { - + self::markTestSkipped(); /** * First we persist and flush an e-mail with no user. Having the * "cascading path" involve a non-new object seems to be important to @@ -113,4 +126,110 @@ public function testNewAssociatedEntityWorksWithJustOnePath() $this->assertEquals($user, $this->_em->find(get_class($user),$user->id)); } -} \ No newline at end of file + + /** + * Unlike next test, this one demonstrates that the problem does + * not necessarily reproduce if all the pieces are being flushed together. + * + * @group DDC-2922 + */ + public function testNewAssociatedEntityWorksWithJustOnePath__() + { + $cascadePersisted = new DDC2922CascadePersistedEntity(); + $cascading = new DDC2922EntityWithCascadingAssociation(); + $nonCascading = new DDC2922EntityWithNonCascadingAssociation(); + + // First we persist and flush a DDC2922EntityWithCascadingAssociation with + // the cascading association not set. Having the "cascading path" involve + // a non-new object is important to show that the ORM should be considering + // cascades across entity changesets in subsequent flushes. + $cascading->cascaded = $cascadePersisted; + $nonCascading->cascaded = $cascadePersisted; + + $this->_em->persist($cascading); + $this->_em->persist($nonCascading); + $this->_em->flush(); + + // @TODO assert persistence on both associations + } + + + /** + * This test exhibits the bug describe in the ticket, where an object that + * ought to be reachable causes errors. + * + * @group DDC-2922 + */ + public function testNewAssociatedEntityWorksWithJustOnePath_() + { + $cascadePersisted = new DDC2922CascadePersistedEntity(); + $cascading = new DDC2922EntityWithCascadingAssociation(); + $nonCascading = new DDC2922EntityWithNonCascadingAssociation(); + + // First we persist and flush a DDC2922EntityWithCascadingAssociation with + // the cascading association not set. Having the "cascading path" involve + // a non-new object is important to show that the ORM should be considering + // cascades across entity changesets in subsequent flushes. + $cascading->cascaded = null; + + $this->_em->persist($cascading); + $this->_em->flush(); + + // Note that we have NOT directly persisted the DDC2922CascadePersistedEntity, + // and DDC2922EntityWithNonCascadingAssociation does NOT have a configured + // cascade-persist. + $nonCascading->nonCascaded = $cascadePersisted; + + // However, DDC2922EntityWithCascadingAssociation *does* have a cascade-persist + // association, which ought to allow us to save the DDC2922CascadePersistedEntity + // anyway through that connection. + $cascading->cascaded = $cascadePersisted; + + $this->_em->persist($nonCascading); + $this->_em->flush(); + + // @TODO assert persistence on both associations + } +} + +/** @Entity */ +class DDC2922CascadePersistedEntity +{ + /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ + private $id; + + public function __construct() + { + $this->id = uniqid(self::class, true); + } +} + +/** @Entity */ +class DDC2922EntityWithCascadingAssociation +{ + /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ + private $id; + + /** @ManyToOne(targetEntity=DDC2922CascadePersistedEntity::class, cascade={"persist"}) */ + public $cascaded; + + public function __construct() + { + $this->id = uniqid(self::class, true); + } +} + +/** @Entity */ +class DDC2922EntityWithNonCascadingAssociation +{ + /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ + private $id; + + /** @ManyToOne(targetEntity=DDC2922CascadePersistedEntity::class) */ + public $nonCascaded; + + public function __construct() + { + $this->id = uniqid(self::class, true); + } +} From a3208f8d086d37fc9c6f2de8b10a8b4bc9c1a929 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Mon, 21 Aug 2017 19:47:16 +0200 Subject: [PATCH 555/877] #1521 DDC-2922 removed unrelated model usage from test - using minimal models only --- .../ORM/Functional/Ticket/DDC2922Test.php | 107 +----------------- 1 file changed, 4 insertions(+), 103 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2922Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2922Test.php index 6598be42ebf..b1aa6c0da73 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2922Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2922Test.php @@ -4,17 +4,13 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; use Doctrine\ORM\Mapping\ClassMetadata; -use Doctrine\ORM\ORMInvalidArgumentException; use Doctrine\ORM\Tools\ToolsException; -use Doctrine\Tests\Models\CMS\CmsAddress; -use Doctrine\Tests\Models\CMS\CmsEmail; -use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\OrmFunctionalTestCase; -class DDC2922Test extends \Doctrine\Tests\OrmFunctionalTestCase +class DDC2922Test extends OrmFunctionalTestCase { - protected function setUp() + protected function setUp() : void { - $this->useModelSet('cms'); parent::setUp(); try { @@ -28,103 +24,8 @@ function (string $className) : ClassMetadata { DDC2922EntityWithNonCascadingAssociation::class, ] )); - } catch (ToolsException $ignored) {} - } - - /** - * Unlike next test, this one demonstrates that the problem does - * not necessarily reproduce if all the pieces are being flushed together. - * - * @group DDC-2922 - */ - public function testNewAssociatedEntityWorksWithJustOnePathIfAllPartsNew() - { - - $user = new CmsUser(); - $user->username = "beberlei"; - $user->name = "Benjamin E."; - $user->status = 'active'; - - $email = new CmsEmail(); - $email->email = "nobody@example.com"; - $email->user = $user; - - $address = new CmsAddress(); - $address->city = "Bonn"; - $address->zip = "12354"; - $address->country = "Germany"; - $address->street = "somestreet"; - $address->user = $user; - - $this->_em->persist($email); - $this->_em->persist($address); - - $this->_em->flush(); - - // Verify the flush succeeded - $this->assertEquals($email, $this->_em->find(get_class($email),$email->id)); - $this->assertEquals($address, $this->_em->find(get_class($address),$address->id)); - $this->assertEquals($user, $this->_em->find(get_class($user),$user->id)); - - } - - /** - * This test exhibits the bug describe in the ticket, where an object that - * ought to be reachable causes errors. - * - * @group DDC-2922 - */ - public function testNewAssociatedEntityWorksWithJustOnePath() - { - self::markTestSkipped(); - /** - * First we persist and flush an e-mail with no user. Having the - * "cascading path" involve a non-new object seems to be important to - * reproducing the bug. - */ - $email = new CmsEmail(); - $email->email = "nobody@example.com"; - $email->user = null; - - $this->_em->persist($email); - $this->_em->flush(); // Flush before introducing CmsUser - - $user = new CmsUser(); - $user->username = "beberlei"; - $user->name = "Benjamin E."; - $user->status = 'active'; - - $email->user = $user; - - /** - * Note that we have NOT directly persisted the CmsUser, and CmsAddress - * does NOT have cascade-persist. - * - * However, CmsEmail *does* have a cascade-persist, which ought to - * allow us to save the CmsUser anyway through that connection. - */ - $address = new CmsAddress(); - $address->city = "Bonn"; - $address->zip = "12354"; - $address->country = "Germany"; - $address->street = "somestreet"; - $address->user = $user; - - $this->_em->persist($address); - try { - $this->_em->flush(); - } catch (ORMInvalidArgumentException $e) { - if (strpos($e->getMessage(), 'not configured to cascade persist operations') !== FALSE) { - $this->fail($e); - } - throw $e; + } catch (ToolsException $ignored) { } - - // Verify the flushes succeeded - $this->assertEquals($email, $this->_em->find(get_class($email),$email->id)); - $this->assertEquals($address, $this->_em->find(get_class($address),$address->id)); - $this->assertEquals($user, $this->_em->find(get_class($user),$user->id)); - } /** From f39614136ffe9272ff3bfad5ac6a04e943d55870 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Mon, 21 Aug 2017 19:58:16 +0200 Subject: [PATCH 556/877] #1521 DDC-2922 reproducing test scenarios within the `UnitOfWorkTest` --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 131 ++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index bfad30be859..47ea39b47f4 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -625,6 +625,95 @@ public function testMergeWithExistingEntityWillNotPersistItNorTriggerPrePersistL self::assertSame($merged, $persistedEntity); self::assertSame($persistedEntity->generatedField, $mergedEntity->generatedField); } + + /** + * Unlike next test, this one demonstrates that the problem does + * not necessarily reproduce if all the pieces are being flushed together. + * + * @group DDC-2922 + * @group #1521 + */ + public function testNewAssociatedEntityPersistenceOfNewEntitiesThroughCascadedAssociationsFirst() + { + $persister1 = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata(CascadePersistedEntity::class)); + $persister2 = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata(EntityWithCascadingAssociation::class)); + $persister3 = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata(EntityWithNonCascadingAssociation::class)); + $this->_unitOfWork->setEntityPersister(CascadePersistedEntity::class, $persister1); + $this->_unitOfWork->setEntityPersister(EntityWithCascadingAssociation::class, $persister2); + $this->_unitOfWork->setEntityPersister(EntityWithNonCascadingAssociation::class, $persister3); + + $cascadePersisted = new CascadePersistedEntity(); + $cascading = new EntityWithCascadingAssociation(); + $nonCascading = new EntityWithNonCascadingAssociation(); + + // First we persist and flush a EntityWithCascadingAssociation with + // the cascading association not set. Having the "cascading path" involve + // a non-new object is important to show that the ORM should be considering + // cascades across entity changesets in subsequent flushes. + $cascading->cascaded = $cascadePersisted; + $nonCascading->cascaded = $cascadePersisted; + + $this->_unitOfWork->persist($cascading); + $this->_unitOfWork->persist($nonCascading); + + $this->_unitOfWork->commit(); + + $this->assertCount(1, $persister1->getInserts()); + $this->assertCount(1, $persister2->getInserts()); + $this->assertCount(1, $persister3->getInserts()); + } + + + /** + * This test exhibits the bug describe in the ticket, where an object that + * ought to be reachable causes errors. + * + * @group DDC-2922 + * @group #1521 + */ + public function testNewAssociatedEntityPersistenceOfNewEntitiesThroughNonCascadedAssociationsFirst() + { + $persister1 = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata(CascadePersistedEntity::class)); + $persister2 = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata(EntityWithCascadingAssociation::class)); + $persister3 = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata(EntityWithNonCascadingAssociation::class)); + $this->_unitOfWork->setEntityPersister(CascadePersistedEntity::class, $persister1); + $this->_unitOfWork->setEntityPersister(EntityWithCascadingAssociation::class, $persister2); + $this->_unitOfWork->setEntityPersister(EntityWithNonCascadingAssociation::class, $persister3); + + $cascadePersisted = new CascadePersistedEntity(); + $cascading = new EntityWithCascadingAssociation(); + $nonCascading = new EntityWithNonCascadingAssociation(); + + // First we persist and flush a EntityWithCascadingAssociation with + // the cascading association not set. Having the "cascading path" involve + // a non-new object is important to show that the ORM should be considering + // cascades across entity changesets in subsequent flushes. + $cascading->cascaded = null; + + $this->_unitOfWork->persist($cascading); + $this->_unitOfWork->commit(); + + self::assertCount(0, $persister1->getInserts()); + self::assertCount(1, $persister2->getInserts()); + self::assertCount(0, $persister3->getInserts()); + + // Note that we have NOT directly persisted the CascadePersistedEntity, + // and EntityWithNonCascadingAssociation does NOT have a configured + // cascade-persist. + $nonCascading->nonCascaded = $cascadePersisted; + + // However, EntityWithCascadingAssociation *does* have a cascade-persist + // association, which ought to allow us to save the CascadePersistedEntity + // anyway through that connection. + $cascading->cascaded = $cascadePersisted; + + $this->_unitOfWork->persist($nonCascading); + $this->_unitOfWork->commit(); + + self::assertCount(1, $persister1->getInserts()); + self::assertCount(1, $persister2->getInserts()); + self::assertCount(1, $persister3->getInserts()); + } } /** @@ -789,3 +878,45 @@ public function __construct() $this->generatedField = mt_rand(0, 100000); } } + +/** @Entity */ +class CascadePersistedEntity +{ + /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ + private $id; + + public function __construct() + { + $this->id = uniqid(self::class, true); + } +} + +/** @Entity */ +class EntityWithCascadingAssociation +{ + /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ + private $id; + + /** @ManyToOne(targetEntity=CascadePersistedEntity::class, cascade={"persist"}) */ + public $cascaded; + + public function __construct() + { + $this->id = uniqid(self::class, true); + } +} + +/** @Entity */ +class EntityWithNonCascadingAssociation +{ + /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ + private $id; + + /** @ManyToOne(targetEntity=CascadePersistedEntity::class) */ + public $nonCascaded; + + public function __construct() + { + $this->id = uniqid(self::class, true); + } +} From 87e8bccb11c32e35d02a47ae2a6116b9baced5f5 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Mon, 21 Aug 2017 19:58:52 +0200 Subject: [PATCH 557/877] #1521 DDC-2922 removed redundant integration test that was replaced by a unit test --- .../ORM/Functional/Ticket/DDC2922Test.php | 136 ------------------ 1 file changed, 136 deletions(-) delete mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2922Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2922Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2922Test.php deleted file mode 100644 index b1aa6c0da73..00000000000 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2922Test.php +++ /dev/null @@ -1,136 +0,0 @@ -_schemaTool->createSchema(array_map( - function (string $className) : ClassMetadata { - return $this->_em->getClassMetadata($className); - }, - [ - DDC2922CascadePersistedEntity::class, - DDC2922EntityWithCascadingAssociation::class, - DDC2922EntityWithNonCascadingAssociation::class, - ] - )); - } catch (ToolsException $ignored) { - } - } - - /** - * Unlike next test, this one demonstrates that the problem does - * not necessarily reproduce if all the pieces are being flushed together. - * - * @group DDC-2922 - */ - public function testNewAssociatedEntityWorksWithJustOnePath__() - { - $cascadePersisted = new DDC2922CascadePersistedEntity(); - $cascading = new DDC2922EntityWithCascadingAssociation(); - $nonCascading = new DDC2922EntityWithNonCascadingAssociation(); - - // First we persist and flush a DDC2922EntityWithCascadingAssociation with - // the cascading association not set. Having the "cascading path" involve - // a non-new object is important to show that the ORM should be considering - // cascades across entity changesets in subsequent flushes. - $cascading->cascaded = $cascadePersisted; - $nonCascading->cascaded = $cascadePersisted; - - $this->_em->persist($cascading); - $this->_em->persist($nonCascading); - $this->_em->flush(); - - // @TODO assert persistence on both associations - } - - - /** - * This test exhibits the bug describe in the ticket, where an object that - * ought to be reachable causes errors. - * - * @group DDC-2922 - */ - public function testNewAssociatedEntityWorksWithJustOnePath_() - { - $cascadePersisted = new DDC2922CascadePersistedEntity(); - $cascading = new DDC2922EntityWithCascadingAssociation(); - $nonCascading = new DDC2922EntityWithNonCascadingAssociation(); - - // First we persist and flush a DDC2922EntityWithCascadingAssociation with - // the cascading association not set. Having the "cascading path" involve - // a non-new object is important to show that the ORM should be considering - // cascades across entity changesets in subsequent flushes. - $cascading->cascaded = null; - - $this->_em->persist($cascading); - $this->_em->flush(); - - // Note that we have NOT directly persisted the DDC2922CascadePersistedEntity, - // and DDC2922EntityWithNonCascadingAssociation does NOT have a configured - // cascade-persist. - $nonCascading->nonCascaded = $cascadePersisted; - - // However, DDC2922EntityWithCascadingAssociation *does* have a cascade-persist - // association, which ought to allow us to save the DDC2922CascadePersistedEntity - // anyway through that connection. - $cascading->cascaded = $cascadePersisted; - - $this->_em->persist($nonCascading); - $this->_em->flush(); - - // @TODO assert persistence on both associations - } -} - -/** @Entity */ -class DDC2922CascadePersistedEntity -{ - /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ - private $id; - - public function __construct() - { - $this->id = uniqid(self::class, true); - } -} - -/** @Entity */ -class DDC2922EntityWithCascadingAssociation -{ - /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ - private $id; - - /** @ManyToOne(targetEntity=DDC2922CascadePersistedEntity::class, cascade={"persist"}) */ - public $cascaded; - - public function __construct() - { - $this->id = uniqid(self::class, true); - } -} - -/** @Entity */ -class DDC2922EntityWithNonCascadingAssociation -{ - /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ - private $id; - - /** @ManyToOne(targetEntity=DDC2922CascadePersistedEntity::class) */ - public $nonCascaded; - - public function __construct() - { - $this->id = uniqid(self::class, true); - } -} From 2751c0fff2a52f651354236f66b5a257dc17502e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Mon, 21 Aug 2017 20:08:20 +0200 Subject: [PATCH 558/877] #1521 DDC-2922 minor code cleanup - renaming internal private methods, variables, removing redundant if/else --- lib/Doctrine/ORM/UnitOfWork.php | 41 ++++++++++++++++----------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index b3f3fb23d1a..5efb01b3b90 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -187,9 +187,9 @@ class UnitOfWork implements PropertyChangedListener * Keys are OIDs, payload is a two-item array describing the association * and the entity. * - * @var array + * @var object[][]|array[][] indexed by respective object spl_object_hash() */ - private $newEntitiesWithoutCascade = array(); + private $nonCascadedNewDetectedEntities = []; /** * All pending collection deletions. @@ -347,7 +347,8 @@ public function commit($entity = null) } } - $this->assertNoCascadingGaps(); + // @TODO move this further down + $this->assertThatThereAreNoUnintentionallyNonPersistedAssociations(); if ( ! ($this->entityInsertions || $this->entityDeletions || @@ -442,7 +443,7 @@ private function postCommitCleanup($entity) : void $this->entityDeletions = $this->extraUpdates = $this->collectionUpdates = - $this->newEntitiesWithoutCascade = + $this->nonCascadedNewDetectedEntities = $this->collectionDeletions = $this->visitedCollections = $this->orphanRemovals = []; @@ -883,11 +884,14 @@ private function computeAssociationChanges($assoc, $value) * through the object-graph where cascade-persistence * is enabled for this object. */ - $this->newEntitiesWithoutCascade[spl_object_hash($entry)] = array($assoc,$entry); - }else { - $this->persistNew($targetClass, $entry); - $this->computeChangeSet($targetClass, $entry); + $this->nonCascadedNewDetectedEntities[\spl_object_hash($entry)] = [$assoc, $entry]; + + break; } + + $this->persistNew($targetClass, $entry); + $this->computeChangeSet($targetClass, $entry); + break; case self::STATE_REMOVED: @@ -2433,7 +2437,7 @@ public function clear($entityName = null) $this->entityInsertions = $this->entityUpdates = $this->entityDeletions = - $this->newEntitiesWithoutCascade = + $this->nonCascadedNewDetectedEntities = $this->collectionDeletions = $this->collectionUpdates = $this->extraUpdates = @@ -3388,21 +3392,16 @@ private function isIdentifierEquals($entity1, $entity2) } /** - * Checks that there are no new entities found through non-cascade-persist - * paths which are not also scheduled for insertion through valid paths. - * - * @return void * @throws ORMInvalidArgumentException */ - private function assertNoCascadingGaps() + private function assertThatThereAreNoUnintentionallyNonPersistedAssociations() : void { - /** - * Filter out any entities that we (successfully) managed to schedule - * for insertion. - */ - $entitiesNeedingCascadePersist = array_diff_key($this->newEntitiesWithoutCascade, $this->entityInsertions); - if(count($entitiesNeedingCascadePersist) > 0){ - list($assoc,$entity) = array_values($entitiesNeedingCascadePersist)[0]; + $entitiesNeedingCascadePersist = \array_diff_key($this->nonCascadedNewDetectedEntities, $this->entityInsertions); + + if($entitiesNeedingCascadePersist){ + [$assoc, $entity] = \array_values($entitiesNeedingCascadePersist)[0]; + + // @TODO internal clean up here throw ORMInvalidArgumentException::newEntityFoundThroughRelationship($assoc, $entity); } } From 89fbb6a0606c61af5b190b6e0e9d61834e071db3 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 22 Aug 2017 08:49:42 +0200 Subject: [PATCH 559/877] #1521 DDC-2922 verifying that persistence operations will resume normally after a crash due to invalid new values detected on associations --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 42 ++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 47ea39b47f4..2a06c28f395 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -663,7 +663,6 @@ public function testNewAssociatedEntityPersistenceOfNewEntitiesThroughCascadedAs $this->assertCount(1, $persister3->getInserts()); } - /** * This test exhibits the bug describe in the ticket, where an object that * ought to be reachable causes errors. @@ -714,6 +713,47 @@ public function testNewAssociatedEntityPersistenceOfNewEntitiesThroughNonCascade self::assertCount(1, $persister2->getInserts()); self::assertCount(1, $persister3->getInserts()); } + + + /** + * This test exhibits the bug describe in the ticket, where an object that + * ought to be reachable causes errors. + * + * @group DDC-2922 + * @group #1521 + */ + public function testPreviousDetectedIllegalNewNonCascadedEntitiesAreCleanedUpOnSubsequentCommits() + { + $persister1 = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata(CascadePersistedEntity::class)); + $persister2 = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata(EntityWithNonCascadingAssociation::class)); + $this->_unitOfWork->setEntityPersister(CascadePersistedEntity::class, $persister1); + $this->_unitOfWork->setEntityPersister(EntityWithNonCascadingAssociation::class, $persister2); + + $cascadePersisted = new CascadePersistedEntity(); + $nonCascading = new EntityWithNonCascadingAssociation(); + + // We explicitly cause the ORM to detect a non-persisted new entity in the association graph: + $nonCascading->nonCascaded = $cascadePersisted; + + $this->_unitOfWork->persist($nonCascading); + + try { + $this->_unitOfWork->commit(); + + self::fail('An exception was supposed to be raised'); + } catch (ORMInvalidArgumentException $ignored) { + self::assertEmpty($persister1->getInserts()); + self::assertEmpty($persister2->getInserts()); + } + + $this->_unitOfWork->persist($cascadePersisted); + $this->_unitOfWork->persist($nonCascading); + $this->_unitOfWork->commit(); + + // Persistence operations should just recover normally: + self::assertCount(1, $persister1->getInserts()); + self::assertCount(1, $persister2->getInserts()); + } } /** From a754eae0f0637988688e70fab2c51b8c9029f045 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 22 Aug 2017 08:51:27 +0200 Subject: [PATCH 560/877] #1521 DDC-2922 verifying that persistence operations will resume normally after a crash due to invalid new values detected on associations - tweaked test to make it fail --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 2a06c28f395..ab6bd9c2cf2 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -746,13 +746,12 @@ public function testPreviousDetectedIllegalNewNonCascadedEntitiesAreCleanedUpOnS self::assertEmpty($persister2->getInserts()); } - $this->_unitOfWork->persist($cascadePersisted); - $this->_unitOfWork->persist($nonCascading); + $this->_unitOfWork->persist(new CascadePersistedEntity()); $this->_unitOfWork->commit(); // Persistence operations should just recover normally: self::assertCount(1, $persister1->getInserts()); - self::assertCount(1, $persister2->getInserts()); + self::assertCount(0, $persister2->getInserts()); } } From 4a007c76f534df1cceb6aaae7f4bb74f4a9c0254 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 22 Aug 2017 09:56:43 +0200 Subject: [PATCH 561/877] #1521 DDC-2922 spec for a new exception endpoint that produces a multi-new-non-cascaded-entities error message --- .../ORM/ORMInvalidArgumentExceptionTest.php | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/ORMInvalidArgumentExceptionTest.php b/tests/Doctrine/Tests/ORM/ORMInvalidArgumentExceptionTest.php index b4d26907854..dea8d4f7732 100644 --- a/tests/Doctrine/Tests/ORM/ORMInvalidArgumentExceptionTest.php +++ b/tests/Doctrine/Tests/ORM/ORMInvalidArgumentExceptionTest.php @@ -58,4 +58,95 @@ public function invalidEntityNames() [new \stdClass(), 'Entity name must be a string, object given'], ]; } + + /** + * @dataProvider newEntitiesFoundThroughRelationshipsErrorMessages + */ + public function testNewEntitiesFoundThroughRelationships(array $newEntities, string $expectedMessage) : void + { + $exception = ORMInvalidArgumentException::newEntitiesFoundThroughRelationships($newEntities); + + self::assertInstanceOf(ORMInvalidArgumentException::class, $exception); + self::assertSame($expectedMessage, $exception->getMessage()); + } + + public function newEntitiesFoundThroughRelationshipsErrorMessages() : array + { + $stringEntity3 = uniqid('entity3', true); + $entity1 = new \stdClass(); + $entity2 = new \stdClass(); + $entity3 = $this->getMockBuilder(\stdClass::class)->setMethods(['__toString'])->getMock(); + $association1 = [ + 'sourceEntity' => 'foo1', + 'fieldName' => 'bar1', + 'targetEntity' => 'baz1', + ]; + $association2 = [ + 'sourceEntity' => 'foo2', + 'fieldName' => 'bar2', + 'targetEntity' => 'baz2', + ]; + $association3 = [ + 'sourceEntity' => 'foo3', + 'fieldName' => 'bar3', + 'targetEntity' => 'baz3', + ]; + + $entity3->expects(self::any())->method('__toString')->willReturn($stringEntity3); + + return [ + 'one entity found' => [ + [ + [ + $association1, + $entity1, + ], + ], + 'A new entity was found through the relationship \'foo1#bar1\' that was not configured to cascade ' + . 'persist operations for entity: stdClass@' . spl_object_hash($entity1) + . '. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity ' + . 'or configure cascade persist this association in the mapping for example ' + . '@ManyToOne(..,cascade={"persist"}). If you cannot find out which entity causes the problem ' + . 'implement \'baz1#__toString()\' to get a clue.', + ], + 'two entities found' => [ + [ + [ + $association1, + $entity1, + ], + [ + $association2, + $entity2, + ], + ], + 'Multiple non-persisted new entities were found through the given association graph:' . "\n\n" + . ' * A new entity was found through the relationship \'foo1#bar1\' that was not configured to ' + . 'cascade persist operations for entity: stdClass@' . spl_object_hash($entity1) . '. ' + . 'To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity ' + . 'or configure cascade persist this association in the mapping for example ' + . '@ManyToOne(..,cascade={"persist"}). If you cannot find out which entity causes the problem ' + . 'implement \'baz1#__toString()\' to get a clue.' . "\n" + . ' * A new entity was found through the relationship \'foo2#bar2\' that was not configured to ' + . 'cascade persist operations for entity: stdClass@' . spl_object_hash($entity2) . '. To solve ' + . 'this issue: Either explicitly call EntityManager#persist() on this unknown entity or ' + . 'configure cascade persist this association in the mapping for example ' + . '@ManyToOne(..,cascade={"persist"}). If you cannot find out which entity causes the problem ' + . 'implement \'baz2#__toString()\' to get a clue.' + ], + 'two entities found, one is stringable' => [ + [ + [ + $association3, + $entity3, + ], + ], + 'A new entity was found through the relationship \'foo3#bar3\' that was not configured to cascade ' + . 'persist operations for entity: ' . $stringEntity3 + . '. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity ' + . 'or configure cascade persist this association in the mapping for example ' + . '@ManyToOne(..,cascade={"persist"}).', + ], + ]; + } } From 2be32f249c4e7df7ee9b9046c8950f217408c04e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 22 Aug 2017 09:57:57 +0200 Subject: [PATCH 562/877] #1521 DDC-2922 adapting UoW and exception implementation to the new specification --- .../ORM/ORMInvalidArgumentException.php | 62 +++++++++++++++---- lib/Doctrine/ORM/UnitOfWork.php | 14 ++--- 2 files changed, 58 insertions(+), 18 deletions(-) diff --git a/lib/Doctrine/ORM/ORMInvalidArgumentException.php b/lib/Doctrine/ORM/ORMInvalidArgumentException.php index 6aa270c782f..796d2c5a515 100644 --- a/lib/Doctrine/ORM/ORMInvalidArgumentException.php +++ b/lib/Doctrine/ORM/ORMInvalidArgumentException.php @@ -82,21 +82,42 @@ static public function readOnlyRequiresManagedEntity($entity) } /** - * @param array $assoc + * @param array[][]|object[][] $newEntitiesWithAssociations non-empty an array + * of [array $associationMapping, object $entity] pairs + * + * @return ORMInvalidArgumentException + */ + static public function newEntitiesFoundThroughRelationships($newEntitiesWithAssociations) + { + $errorMessages = array_map( + function (array $newEntityWithAssociation) : string { + [$associationMapping, $entity] = $newEntityWithAssociation; + + return self::newEntityFoundThroughRelationshipMessage($associationMapping, $entity); + }, + $newEntitiesWithAssociations + ); + + if (1 === count($errorMessages)) { + return new self(reset($errorMessages)); + } + + return new self( + 'Multiple non-persisted new entities were found through the given association graph:' + . "\n\n * " + . implode("\n * ", $errorMessages) + ); + } + + /** + * @param array $associationMapping * @param object $entry * * @return ORMInvalidArgumentException */ - static public function newEntityFoundThroughRelationship(array $assoc, $entry) + static public function newEntityFoundThroughRelationship(array $associationMapping, $entry) { - return new self("A new entity was found through the relationship '" - . $assoc['sourceEntity'] . "#" . $assoc['fieldName'] . "' that was not" - . " configured to cascade persist operations for entity: " . self::objToStr($entry) . "." - . " To solve this issue: Either explicitly call EntityManager#persist()" - . " on this unknown entity or configure cascade persist" - . " this association in the mapping for example @ManyToOne(..,cascade={\"persist\"})." - . (method_exists($entry, '__toString') ? "": " If you cannot find out which entity causes the problem" - . " implement '" . $assoc['targetEntity'] . "#__toString()' to get a clue.")); + return new self(self::newEntityFoundThroughRelationshipMessage($associationMapping, $entry)); } /** @@ -229,8 +250,27 @@ public static function invalidEntityName($entityName) * * @return string */ - private static function objToStr($obj) + private static function objToStr($obj) : string { return method_exists($obj, '__toString') ? (string) $obj : get_class($obj).'@'.spl_object_hash($obj); } + + /** + * @param array $associationMapping + * @param object $entity + */ + private static function newEntityFoundThroughRelationshipMessage(array $associationMapping, $entity) : string + { + return 'A new entity was found through the relationship \'' + . $associationMapping['sourceEntity'] . '#' . $associationMapping['fieldName'] . '\' that was not' + . ' configured to cascade persist operations for entity: ' . self::objToStr($entity) . '.' + . ' To solve this issue: Either explicitly call EntityManager#persist()' + . ' on this unknown entity or configure cascade persist' + . ' this association in the mapping for example @ManyToOne(..,cascade={"persist"}).' + . (method_exists($entity, '__toString') + ? '' + : ' If you cannot find out which entity causes the problem implement \'' + . $associationMapping['targetEntity'] . '#__toString()\' to get a clue.' + ); + } } diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 5efb01b3b90..0edd756f0d1 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -347,9 +347,6 @@ public function commit($entity = null) } } - // @TODO move this further down - $this->assertThatThereAreNoUnintentionallyNonPersistedAssociations(); - if ( ! ($this->entityInsertions || $this->entityDeletions || $this->entityUpdates || @@ -362,6 +359,8 @@ public function commit($entity = null) return; // Nothing to do. } + $this->assertThatThereAreNoUnintentionallyNonPersistedAssociations(); + if ($this->orphanRemovals) { foreach ($this->orphanRemovals as $orphan) { $this->remove($orphan); @@ -3398,11 +3397,12 @@ private function assertThatThereAreNoUnintentionallyNonPersistedAssociations() : { $entitiesNeedingCascadePersist = \array_diff_key($this->nonCascadedNewDetectedEntities, $this->entityInsertions); - if($entitiesNeedingCascadePersist){ - [$assoc, $entity] = \array_values($entitiesNeedingCascadePersist)[0]; + $this->nonCascadedNewDetectedEntities = []; - // @TODO internal clean up here - throw ORMInvalidArgumentException::newEntityFoundThroughRelationship($assoc, $entity); + if ($entitiesNeedingCascadePersist) { + throw ORMInvalidArgumentException::newEntitiesFoundThroughRelationships( + \array_values($entitiesNeedingCascadePersist) + ); } } From 645cccf2db16209d4192400d90d6256138375db7 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 22 Aug 2017 10:24:46 +0200 Subject: [PATCH 563/877] #1521 DDC-2922 adapting test so the `UnitOfWork` stops bragging about previous inconsistent states --- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index ab6bd9c2cf2..12eadbdaa82 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -746,6 +746,7 @@ public function testPreviousDetectedIllegalNewNonCascadedEntitiesAreCleanedUpOnS self::assertEmpty($persister2->getInserts()); } + $this->_unitOfWork->clear(); $this->_unitOfWork->persist(new CascadePersistedEntity()); $this->_unitOfWork->commit(); From 309b286ed38e04aa21e640a24cbe9ba6efd0e704 Mon Sep 17 00:00:00 2001 From: Waleed Gadelkareem Date: Fri, 10 Feb 2017 17:12:51 +0100 Subject: [PATCH 564/877] Add tests for #6217 --- .../ORM/Mapping/ClassMetadataInfo.php | 14 +- .../ORM/Functional/Ticket/GH6217Test.php | 162 ++++++++++++++++++ 2 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index b5eebcdde2c..5fa349933eb 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -29,6 +29,7 @@ use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\Common\ClassLoader; use Doctrine\ORM\Cache\CacheException; +use Doctrine\ORM\Cache\AssociationCacheEntry; /** * A ClassMetadata instance holds all the object-relational mapping metadata @@ -718,7 +719,7 @@ public function getIdentifierValues($entity) $id = []; foreach ($this->identifier as $idField) { - $value = $this->reflFields[$idField]->getValue($entity); + $value = $this->getIndentifierValue($entity, $idField); if (null !== $value) { $id[$idField] = $value; @@ -729,7 +730,7 @@ public function getIdentifierValues($entity) } $id = $this->identifier[0]; - $value = $this->reflFields[$id]->getValue($entity); + $value = $this->getIndentifierValue($entity, $id); if (null === $value) { return []; @@ -738,6 +739,15 @@ public function getIdentifierValues($entity) return [$id => $value]; } + private function getIndentifierValue($entity, $id) + { + if ($entity instanceof AssociationCacheEntry) { + return $entity->identifier[$id]; + } + + return $this->reflFields[$id]->getValue($entity); + } + /** * Populates the entity identifier of an entity. * diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php new file mode 100644 index 00000000000..d87b9642e0e --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php @@ -0,0 +1,162 @@ +enableSecondLevelCache(); + + parent::setUp(); + + $this->_schemaTool->createSchema( + [ + $this->_em->getClassMetadata(GH6217User::class), + $this->_em->getClassMetadata(GH6217Profile::class), + $this->_em->getClassMetadata(GH6217Category::class), + $this->_em->getClassMetadata(GH6217UserProfile::class), + ] + ); + } + + /** + * @group 6217 + */ + public function testRetrievingCacheShouldNotThrowUndefinedIndexException() + { + $user = new GH6217User(1, 'user 1'); + $profile = new GH6217Profile(1); + $category = new GH6217Category(1, 'category 1'); + $userProfile = new GH6217UserProfile($user, $profile, $category); + + $this->_em->persist($category); + $this->_em->persist($user); + $this->_em->persist($profile); + $this->_em->persist($userProfile); + $this->_em->flush(); + $this->_em->clear(); + + $repository = $this->_em->getRepository(GH6217UserProfile::class); + $filters = ['user' => 1, 'category' => 1]; + + $this->assertCount(1, $repository->findBy($filters)); + $queryCount = $this->getCurrentQueryCount(); + + $this->_em->clear(); + + $this->assertCount(1, $repository->findBy($filters)); + $this->assertEquals($queryCount, $this->getCurrentQueryCount()); + } +} + +/** + * @Entity + * @Cache(usage="NONSTRICT_READ_WRITE") + */ +class GH6217User +{ + /** + * @Id + * @Column(type="integer") + * + * @var int + */ + public $id; + + /** + * @Column(type="string", length=60, unique=true) + * + * @var string + */ + public $username; + + public function __construct(int $id, string $username) + { + $this->id = $id; + $this->username = $username; + } +} + +/** + * @Entity + * @Cache(usage="NONSTRICT_READ_WRITE") + */ +class GH6217Profile +{ + /** + * @Id + * @Column(type="integer") + * + * @var int + */ + public $id; + + public function __construct(int $id) + { + $this->id = $id; + } +} + +/** + * @Entity + * @Cache(usage="NONSTRICT_READ_WRITE") + */ +class GH6217Category +{ + /** + * @Id + * @Column(type="integer") + * + * @var int + */ + public $id; + + public function __construct(int $id) + { + $this->id = $id; + } +} + +/** + * @Entity + * @Cache(usage="NONSTRICT_READ_WRITE") + */ +class GH6217UserProfile +{ + /** + * @Id + * @Cache("NONSTRICT_READ_WRITE") + * @ManyToOne(targetEntity="GH6217User") + * @JoinColumn(nullable=false) + * + * @var GH6217User + */ + public $user; + + /** + * @Id + * @Cache("NONSTRICT_READ_WRITE") + * @ManyToOne(targetEntity="GH6217Profile", fetch="EAGER") + * + * @var GH6217Profile + */ + public $profile; + + /** + * @Id + * @Cache("NONSTRICT_READ_WRITE") + * @ManyToOne(targetEntity="GH6217Category", fetch="EAGER") + * + * @var GH6217Category + */ + public $category; + + public function __construct(GH6217User $user, GH6217Profile $profile, GH6217Category $category) + { + $this->user = $user; + $this->profile = $profile; + $this->category = $category; + } +} From a8453dda89104ce0e2ee9f36491709b942a79c09 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 22 Aug 2017 21:03:14 +0200 Subject: [PATCH 565/877] #6284 removing the "WTF" part of the logic - an association cache entry should never ever reach metadata --- lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 5fa349933eb..4057455b306 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -715,6 +715,9 @@ public function getSingleIdReflectionProperty() */ public function getIdentifierValues($entity) { + if ($entity instanceof AssociationCacheEntry) { + throw new \InvalidArgumentException('WTF DUDE: ' . $entity->class . ' - ' . \serialize($entity->identifier)); + } if ($this->isIdentifierComposite) { $id = []; From c7281f6aded9a6c11197d1fdc42f0874e97c08eb Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 22 Aug 2017 21:08:06 +0200 Subject: [PATCH 566/877] #6284 simplifying tests to a minimum, removing unused auto-generated id field --- .../ORM/Functional/Ticket/GH6217Test.php | 30 +++++++------------ 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php index d87b9642e0e..fd138aa4709 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php @@ -26,9 +26,9 @@ public function setUp() */ public function testRetrievingCacheShouldNotThrowUndefinedIndexException() { - $user = new GH6217User(1, 'user 1'); - $profile = new GH6217Profile(1); - $category = new GH6217Category(1, 'category 1'); + $user = new GH6217User(1); + $profile = new GH6217Profile(); + $category = new GH6217Category(1); $userProfile = new GH6217UserProfile($user, $profile, $category); $this->_em->persist($category); @@ -65,37 +65,27 @@ class GH6217User */ public $id; - /** - * @Column(type="string", length=60, unique=true) - * - * @var string - */ - public $username; - - public function __construct(int $id, string $username) + public function __construct(int $id) { $this->id = $id; - $this->username = $username; } } -/** - * @Entity - * @Cache(usage="NONSTRICT_READ_WRITE") - */ +/** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */ class GH6217Profile { /** * @Id - * @Column(type="integer") + * @Column(type="string") + * @GeneratedValue(strategy="NONE") * - * @var int + * @var string */ public $id; - public function __construct(int $id) + public function __construct() { - $this->id = $id; + $this->id = uniqid(self::class, true); } } From 3842ad8ea10ad4e4d6222852b8c315f3ecf7a820 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 22 Aug 2017 21:11:03 +0200 Subject: [PATCH 567/877] #6284 simplifying tests to a minimum, removing unused auto-generated id field --- .../ORM/Functional/Ticket/GH6217Test.php | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php index fd138aa4709..8e13337232a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php @@ -26,9 +26,9 @@ public function setUp() */ public function testRetrievingCacheShouldNotThrowUndefinedIndexException() { - $user = new GH6217User(1); + $user = new GH6217User(); $profile = new GH6217Profile(); - $category = new GH6217Category(1); + $category = new GH6217Category(); $userProfile = new GH6217UserProfile($user, $profile, $category); $this->_em->persist($category); @@ -39,7 +39,7 @@ public function testRetrievingCacheShouldNotThrowUndefinedIndexException() $this->_em->clear(); $repository = $this->_em->getRepository(GH6217UserProfile::class); - $filters = ['user' => 1, 'category' => 1]; + $filters = ['user' => $user->id, 'category' => $category->id]; $this->assertCount(1, $repository->findBy($filters)); $queryCount = $this->getCurrentQueryCount(); @@ -59,15 +59,16 @@ class GH6217User { /** * @Id - * @Column(type="integer") + * @Column(type="string") + * @GeneratedValue(strategy="NONE") * - * @var int + * @var string */ public $id; - public function __construct(int $id) + public function __construct() { - $this->id = $id; + $this->id = uniqid(self::class, true); } } @@ -97,15 +98,16 @@ class GH6217Category { /** * @Id - * @Column(type="integer") + * @Column(type="string") + * @GeneratedValue(strategy="NONE") * - * @var int + * @var string */ public $id; - public function __construct(int $id) + public function __construct() { - $this->id = $id; + $this->id = uniqid(self::class, true); } } @@ -119,7 +121,6 @@ class GH6217UserProfile * @Id * @Cache("NONSTRICT_READ_WRITE") * @ManyToOne(targetEntity="GH6217User") - * @JoinColumn(nullable=false) * * @var GH6217User */ From 805ba041ef5ff4367d6899a7b28de436d31be93e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 22 Aug 2017 21:12:45 +0200 Subject: [PATCH 568/877] #6284 reducing annotation mapping clutter --- .../ORM/Functional/Ticket/GH6217Test.php | 63 +++---------------- 1 file changed, 9 insertions(+), 54 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php index 8e13337232a..26e2c80adb9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php @@ -51,19 +51,10 @@ public function testRetrievingCacheShouldNotThrowUndefinedIndexException() } } -/** - * @Entity - * @Cache(usage="NONSTRICT_READ_WRITE") - */ +/** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */ class GH6217User { - /** - * @Id - * @Column(type="string") - * @GeneratedValue(strategy="NONE") - * - * @var string - */ + /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ public $id; public function __construct() @@ -75,13 +66,7 @@ public function __construct() /** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */ class GH6217Profile { - /** - * @Id - * @Column(type="string") - * @GeneratedValue(strategy="NONE") - * - * @var string - */ + /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ public $id; public function __construct() @@ -90,19 +75,10 @@ public function __construct() } } -/** - * @Entity - * @Cache(usage="NONSTRICT_READ_WRITE") - */ +/** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */ class GH6217Category { - /** - * @Id - * @Column(type="string") - * @GeneratedValue(strategy="NONE") - * - * @var string - */ + /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ public $id; public function __construct() @@ -111,37 +87,16 @@ public function __construct() } } -/** - * @Entity - * @Cache(usage="NONSTRICT_READ_WRITE") - */ +/** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */ class GH6217UserProfile { - /** - * @Id - * @Cache("NONSTRICT_READ_WRITE") - * @ManyToOne(targetEntity="GH6217User") - * - * @var GH6217User - */ + /** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217User::class) */ public $user; - /** - * @Id - * @Cache("NONSTRICT_READ_WRITE") - * @ManyToOne(targetEntity="GH6217Profile", fetch="EAGER") - * - * @var GH6217Profile - */ + /** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217Profile::class) */ public $profile; - /** - * @Id - * @Cache("NONSTRICT_READ_WRITE") - * @ManyToOne(targetEntity="GH6217Category", fetch="EAGER") - * - * @var GH6217Category - */ + /** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217Category::class) */ public $category; public function __construct(GH6217User $user, GH6217Profile $profile, GH6217Category $category) From 4e0b76ce693ea401fbb6e5e8ccd5546e35c8c783 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 22 Aug 2017 21:14:38 +0200 Subject: [PATCH 569/877] #6284 eager fetching is strictly required to verify the issue --- .../ORM/Functional/Ticket/GH6217Test.php | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php index 26e2c80adb9..2afed3db748 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php @@ -54,7 +54,13 @@ public function testRetrievingCacheShouldNotThrowUndefinedIndexException() /** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */ class GH6217User { - /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ + /** + * @Id + * @Column(type="string") + * @GeneratedValue(strategy="NONE") + * + * @var string + */ public $id; public function __construct() @@ -66,7 +72,13 @@ public function __construct() /** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */ class GH6217Profile { - /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ + /** + * @Id + * @Column(type="string") + * @GeneratedValue(strategy="NONE") + * + * @var string + */ public $id; public function __construct() @@ -78,7 +90,13 @@ public function __construct() /** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */ class GH6217Category { - /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ + /** + * @Id + * @Column(type="string") + * @GeneratedValue(strategy="NONE") + * + * @var string + */ public $id; public function __construct() @@ -93,10 +111,10 @@ class GH6217UserProfile /** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217User::class) */ public $user; - /** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217Profile::class) */ + /** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217Profile::class, fetch="EAGER") */ public $profile; - /** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217Category::class) */ + /** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217Category::class, fetch="EAGER") */ public $category; public function __construct(GH6217User $user, GH6217Profile $profile, GH6217Category $category) From ca39abcd71db89e6185988a37a5431592ee9a611 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 22 Aug 2017 21:17:14 +0200 Subject: [PATCH 570/877] #6284 reducing annotation mapping clutter --- .../ORM/Functional/Ticket/GH6217Test.php | 24 +++---------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php index 2afed3db748..be9ea2a74f3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php @@ -54,13 +54,7 @@ public function testRetrievingCacheShouldNotThrowUndefinedIndexException() /** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */ class GH6217User { - /** - * @Id - * @Column(type="string") - * @GeneratedValue(strategy="NONE") - * - * @var string - */ + /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ public $id; public function __construct() @@ -72,13 +66,7 @@ public function __construct() /** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */ class GH6217Profile { - /** - * @Id - * @Column(type="string") - * @GeneratedValue(strategy="NONE") - * - * @var string - */ + /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ public $id; public function __construct() @@ -90,13 +78,7 @@ public function __construct() /** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */ class GH6217Category { - /** - * @Id - * @Column(type="string") - * @GeneratedValue(strategy="NONE") - * - * @var string - */ + /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ public $id; public function __construct() From dac1ce4172b006540b91e2fe12d916a52de33885 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 22 Aug 2017 21:21:53 +0200 Subject: [PATCH 571/877] #6284 removing profile entity, since it is not needed to reproduce the issue --- .../ORM/Functional/Ticket/GH6217Test.php | 23 ++----------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php index be9ea2a74f3..8f11d6de30b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php @@ -14,7 +14,6 @@ public function setUp() $this->_schemaTool->createSchema( [ $this->_em->getClassMetadata(GH6217User::class), - $this->_em->getClassMetadata(GH6217Profile::class), $this->_em->getClassMetadata(GH6217Category::class), $this->_em->getClassMetadata(GH6217UserProfile::class), ] @@ -27,13 +26,11 @@ public function setUp() public function testRetrievingCacheShouldNotThrowUndefinedIndexException() { $user = new GH6217User(); - $profile = new GH6217Profile(); $category = new GH6217Category(); - $userProfile = new GH6217UserProfile($user, $profile, $category); + $userProfile = new GH6217UserProfile($user, $category); $this->_em->persist($category); $this->_em->persist($user); - $this->_em->persist($profile); $this->_em->persist($userProfile); $this->_em->flush(); $this->_em->clear(); @@ -63,18 +60,6 @@ public function __construct() } } -/** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */ -class GH6217Profile -{ - /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ - public $id; - - public function __construct() - { - $this->id = uniqid(self::class, true); - } -} - /** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */ class GH6217Category { @@ -93,16 +78,12 @@ class GH6217UserProfile /** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217User::class) */ public $user; - /** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217Profile::class, fetch="EAGER") */ - public $profile; - /** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217Category::class, fetch="EAGER") */ public $category; - public function __construct(GH6217User $user, GH6217Profile $profile, GH6217Category $category) + public function __construct(GH6217User $user, GH6217Category $category) { $this->user = $user; - $this->profile = $profile; $this->category = $category; } } From 6f6e88cfb642e0130a4adb08f97452718bd8206f Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 22 Aug 2017 21:27:46 +0200 Subject: [PATCH 572/877] #6284 adding assertions about equality of the loaded classes --- .../Tests/ORM/Functional/Ticket/GH6217Test.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php index 8f11d6de30b..aeefc82d050 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php @@ -36,14 +36,20 @@ public function testRetrievingCacheShouldNotThrowUndefinedIndexException() $this->_em->clear(); $repository = $this->_em->getRepository(GH6217UserProfile::class); - $filters = ['user' => $user->id, 'category' => $category->id]; + $filters = ['category' => $category->id]; $this->assertCount(1, $repository->findBy($filters)); $queryCount = $this->getCurrentQueryCount(); $this->_em->clear(); - $this->assertCount(1, $repository->findBy($filters)); + /* @var $found GH6217UserProfile[] */ + $found = $repository->findBy($filters); + + $this->assertCount(1, $found); + $this->assertInstanceOf(GH6217UserProfile::class, $found[0]); + $this->assertSame($user->id, $found[0]->user->id); + $this->assertSame($category->id, $found[0]->category->id); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); } } From 220dc79ebf12c7425ed53efeb26ec1c9d969c1b0 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 22 Aug 2017 21:29:27 +0200 Subject: [PATCH 573/877] #6284 renaming entities to match the scope of this test --- .../ORM/Functional/Ticket/GH6217Test.php | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php index aeefc82d050..675024844c1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php @@ -13,9 +13,9 @@ public function setUp() $this->_schemaTool->createSchema( [ - $this->_em->getClassMetadata(GH6217User::class), - $this->_em->getClassMetadata(GH6217Category::class), - $this->_em->getClassMetadata(GH6217UserProfile::class), + $this->_em->getClassMetadata(GH6217LazyEntity::class), + $this->_em->getClassMetadata(GH6217EagerEntity::class), + $this->_em->getClassMetadata(GH6217FetchedEntity::class), ] ); } @@ -25,9 +25,9 @@ public function setUp() */ public function testRetrievingCacheShouldNotThrowUndefinedIndexException() { - $user = new GH6217User(); - $category = new GH6217Category(); - $userProfile = new GH6217UserProfile($user, $category); + $user = new GH6217LazyEntity(); + $category = new GH6217EagerEntity(); + $userProfile = new GH6217FetchedEntity($user, $category); $this->_em->persist($category); $this->_em->persist($user); @@ -35,7 +35,7 @@ public function testRetrievingCacheShouldNotThrowUndefinedIndexException() $this->_em->flush(); $this->_em->clear(); - $repository = $this->_em->getRepository(GH6217UserProfile::class); + $repository = $this->_em->getRepository(GH6217FetchedEntity::class); $filters = ['category' => $category->id]; $this->assertCount(1, $repository->findBy($filters)); @@ -43,11 +43,11 @@ public function testRetrievingCacheShouldNotThrowUndefinedIndexException() $this->_em->clear(); - /* @var $found GH6217UserProfile[] */ + /* @var $found GH6217FetchedEntity[] */ $found = $repository->findBy($filters); $this->assertCount(1, $found); - $this->assertInstanceOf(GH6217UserProfile::class, $found[0]); + $this->assertInstanceOf(GH6217FetchedEntity::class, $found[0]); $this->assertSame($user->id, $found[0]->user->id); $this->assertSame($category->id, $found[0]->category->id); $this->assertEquals($queryCount, $this->getCurrentQueryCount()); @@ -55,7 +55,7 @@ public function testRetrievingCacheShouldNotThrowUndefinedIndexException() } /** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */ -class GH6217User +class GH6217LazyEntity { /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ public $id; @@ -67,7 +67,7 @@ public function __construct() } /** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */ -class GH6217Category +class GH6217EagerEntity { /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ public $id; @@ -79,15 +79,15 @@ public function __construct() } /** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */ -class GH6217UserProfile +class GH6217FetchedEntity { - /** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217User::class) */ + /** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217LazyEntity::class) */ public $user; - /** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217Category::class, fetch="EAGER") */ + /** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217EagerEntity::class, fetch="EAGER") */ public $category; - public function __construct(GH6217User $user, GH6217Category $category) + public function __construct(GH6217LazyEntity $user, GH6217EagerEntity $category) { $this->user = $user; $this->category = $category; From 3f09e2095585b28d2fb9207f68a826a3a878d5ae Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 22 Aug 2017 21:31:01 +0200 Subject: [PATCH 574/877] #6284 correcting alignment, removing stuff that isn't strictly needed --- .../Tests/ORM/Functional/Ticket/GH6217Test.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php index 675024844c1..504e0138969 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php @@ -11,19 +11,17 @@ public function setUp() parent::setUp(); - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(GH6217LazyEntity::class), - $this->_em->getClassMetadata(GH6217EagerEntity::class), - $this->_em->getClassMetadata(GH6217FetchedEntity::class), - ] - ); + $this->_schemaTool->createSchema([ + $this->_em->getClassMetadata(GH6217LazyEntity::class), + $this->_em->getClassMetadata(GH6217EagerEntity::class), + $this->_em->getClassMetadata(GH6217FetchedEntity::class), + ]); } /** * @group 6217 */ - public function testRetrievingCacheShouldNotThrowUndefinedIndexException() + public function testLoadingOfSecondLevelCacheOnEagerAssociations() { $user = new GH6217LazyEntity(); $category = new GH6217EagerEntity(); From a2f4053a8121bcddf2dc78fec143a86ac34df07d Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 22 Aug 2017 21:38:44 +0200 Subject: [PATCH 575/877] #6284 renaming variables, classes and properties to fit tested behavior --- .../ORM/Functional/Ticket/GH6217Test.php | 42 +++++++++---------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php index 504e0138969..81f455ca412 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php @@ -3,9 +3,12 @@ use Doctrine\Tests\OrmFunctionalTestCase; +/** + * @group #6217 + */ final class GH6217Test extends OrmFunctionalTestCase { - public function setUp() + public function setUp() : void { $this->enableSecondLevelCache(); @@ -18,37 +21,32 @@ public function setUp() ]); } - /** - * @group 6217 - */ - public function testLoadingOfSecondLevelCacheOnEagerAssociations() + public function testLoadingOfSecondLevelCacheOnEagerAssociations() : void { - $user = new GH6217LazyEntity(); - $category = new GH6217EagerEntity(); - $userProfile = new GH6217FetchedEntity($user, $category); + $lazy = new GH6217LazyEntity(); + $eager = new GH6217EagerEntity(); + $fetched = new GH6217FetchedEntity($lazy, $eager); - $this->_em->persist($category); - $this->_em->persist($user); - $this->_em->persist($userProfile); + $this->_em->persist($eager); + $this->_em->persist($lazy); + $this->_em->persist($fetched); $this->_em->flush(); $this->_em->clear(); $repository = $this->_em->getRepository(GH6217FetchedEntity::class); - $filters = ['category' => $category->id]; + $filters = ['eager' => $eager->id]; $this->assertCount(1, $repository->findBy($filters)); $queryCount = $this->getCurrentQueryCount(); - $this->_em->clear(); - /* @var $found GH6217FetchedEntity[] */ $found = $repository->findBy($filters); $this->assertCount(1, $found); $this->assertInstanceOf(GH6217FetchedEntity::class, $found[0]); - $this->assertSame($user->id, $found[0]->user->id); - $this->assertSame($category->id, $found[0]->category->id); - $this->assertEquals($queryCount, $this->getCurrentQueryCount()); + $this->assertSame($lazy->id, $found[0]->lazy->id); + $this->assertSame($eager->id, $found[0]->eager->id); + $this->assertEquals($queryCount, $this->getCurrentQueryCount(), 'No queries were executed in `findBy`'); } } @@ -80,14 +78,14 @@ public function __construct() class GH6217FetchedEntity { /** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217LazyEntity::class) */ - public $user; + public $lazy; /** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217EagerEntity::class, fetch="EAGER") */ - public $category; + public $eager; - public function __construct(GH6217LazyEntity $user, GH6217EagerEntity $category) + public function __construct(GH6217LazyEntity $lazy, GH6217EagerEntity $eager) { - $this->user = $user; - $this->category = $category; + $this->lazy = $lazy; + $this->eager = $eager; } } From c29a1e96b7f3e5a7874ff2bad477bb792f6d879d Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 22 Aug 2017 21:40:42 +0200 Subject: [PATCH 576/877] #6284 removing unused separate class --- .../Tests/ORM/Functional/Ticket/GH6217Test.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php index 81f455ca412..3ac810fb6d0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php @@ -15,16 +15,15 @@ public function setUp() : void parent::setUp(); $this->_schemaTool->createSchema([ - $this->_em->getClassMetadata(GH6217LazyEntity::class), - $this->_em->getClassMetadata(GH6217EagerEntity::class), + $this->_em->getClassMetadata(GH6217AssociatedEntity::class), $this->_em->getClassMetadata(GH6217FetchedEntity::class), ]); } public function testLoadingOfSecondLevelCacheOnEagerAssociations() : void { - $lazy = new GH6217LazyEntity(); - $eager = new GH6217EagerEntity(); + $lazy = new GH6217AssociatedEntity(); + $eager = new GH6217AssociatedEntity(); $fetched = new GH6217FetchedEntity($lazy, $eager); $this->_em->persist($eager); @@ -63,7 +62,7 @@ public function __construct() } /** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */ -class GH6217EagerEntity +class GH6217AssociatedEntity { /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ public $id; @@ -77,13 +76,13 @@ public function __construct() /** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */ class GH6217FetchedEntity { - /** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217LazyEntity::class) */ + /** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217AssociatedEntity::class) */ public $lazy; - /** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217EagerEntity::class, fetch="EAGER") */ + /** @Id @Cache("NONSTRICT_READ_WRITE") @ManyToOne(targetEntity=GH6217AssociatedEntity::class, fetch="EAGER") */ public $eager; - public function __construct(GH6217LazyEntity $lazy, GH6217EagerEntity $eager) + public function __construct(GH6217AssociatedEntity $lazy, GH6217AssociatedEntity $eager) { $this->lazy = $lazy; $this->eager = $eager; From c9d1f852de15581f276abb80e6b712a20cd2ce9e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 22 Aug 2017 21:41:04 +0200 Subject: [PATCH 577/877] #6284 removing unused lazy entity --- .../Tests/ORM/Functional/Ticket/GH6217Test.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php index 3ac810fb6d0..861925f08f6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php @@ -49,18 +49,6 @@ public function testLoadingOfSecondLevelCacheOnEagerAssociations() : void } } -/** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */ -class GH6217LazyEntity -{ - /** @Id @Column(type="string") @GeneratedValue(strategy="NONE") */ - public $id; - - public function __construct() - { - $this->id = uniqid(self::class, true); - } -} - /** @Entity @Cache(usage="NONSTRICT_READ_WRITE") */ class GH6217AssociatedEntity { From 07b397f3419e37f4ac0bf1d0a55572af7cb9d575 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 23 Aug 2017 00:19:49 +0200 Subject: [PATCH 578/877] #6284 fixing actual issue, which comes from an extremely tricky L2 caching issue. We are not hydrating some of the cached association data into entities due to keys missing in the cache association definition. Since this is an extreme edge case that is just a mismatch between db and cache, a detailed explanation was provided in the fix snippet as well --- lib/Doctrine/ORM/Cache/DefaultQueryCache.php | 37 ++++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php index 3ac20654780..d431313ef0e 100644 --- a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php +++ b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php @@ -92,13 +92,13 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = [] return null; } - $entry = $this->region->get($key); + $cacheEntry = $this->region->get($key); - if ( ! $entry instanceof QueryCacheEntry) { + if ( ! $cacheEntry instanceof QueryCacheEntry) { return null; } - if ( ! $this->validator->isValid($key, $entry)) { + if ( ! $this->validator->isValid($key, $cacheEntry)) { $this->region->evict($key); return null; @@ -117,11 +117,11 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = [] return new EntityCacheKey($cm->rootEntityName, $entry['identifier']); }; - $cacheKeys = new CollectionCacheEntry(array_map($generateKeys, $entry->result)); + $cacheKeys = new CollectionCacheEntry(array_map($generateKeys, $cacheEntry->result)); $entries = $region->getMultiple($cacheKeys); // @TODO - move to cache hydration component - foreach ($entry->result as $index => $entry) { + foreach ($cacheEntry->result as $index => $entry) { $entityEntry = is_array($entries) && array_key_exists($index, $entries) ? $entries[$index] : null; if ($entityEntry === null) { @@ -210,6 +210,25 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = [] $collection->setInitialized(true); } + foreach ($data as $fieldName => $unCachedAssociationData) { + // In some scenarios, such as EAGER+ASSOCIATION+ID+CACHE, the + // cache key information in `$cacheEntry` will not contain details + // for fields that are associations. + // + // This means that `$data` keys for some associations that may + // actually not be cached will not be converted to actual association + // data, yet they contain L2 cache AssociationCacheEntry objects. + // + // We need to unwrap those associations into proxy references, + // since we don't have actual data for them except for identifiers. + if ($unCachedAssociationData instanceof AssociationCacheEntry) { + $data[$fieldName] = $this->em->getReference( + $unCachedAssociationData->class, + $unCachedAssociationData->identifier + ); + } + } + $result[$index] = $this->uow->createEntity($entityEntry->class, $data, self::$hints); } @@ -246,7 +265,6 @@ public function put(QueryCacheKey $key, ResultSetMapping $rsm, $result, array $h $data = []; $entityName = reset($rsm->aliasMap); $rootAlias = key($rsm->aliasMap); - $hasRelation = ( ! empty($rsm->relationMap)); $persister = $this->uow->getEntityPersister($entityName); if ( ! ($persister instanceof CachedPersister)) { @@ -258,8 +276,6 @@ public function put(QueryCacheKey $key, ResultSetMapping $rsm, $result, array $h foreach ($result as $index => $entity) { $identifier = $this->uow->getEntityIdentifier($entity); $entityKey = new EntityCacheKey($entityName, $identifier); - $data[$index]['identifier'] = $identifier; - $data[$index]['associations'] = []; if (($key->cacheMode & Cache::MODE_REFRESH) || ! $region->contains($entityKey)) { // Cancel put result if entity put fail @@ -268,9 +284,8 @@ public function put(QueryCacheKey $key, ResultSetMapping $rsm, $result, array $h } } - if ( ! $hasRelation) { - continue; - } + $data[$index]['identifier'] = $identifier; + $data[$index]['associations'] = []; // @TODO - move to cache hydration components foreach ($rsm->relationMap as $alias => $name) { From caa008b61d25840057698442a8a63e8c8e997d19 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 23 Aug 2017 00:25:29 +0200 Subject: [PATCH 579/877] #6284 #6217 removing hacks around the `ClassMetadata` details - invalid fix that was actually fixing the symptom --- lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 4057455b306..b5eebcdde2c 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -29,7 +29,6 @@ use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\Common\ClassLoader; use Doctrine\ORM\Cache\CacheException; -use Doctrine\ORM\Cache\AssociationCacheEntry; /** * A ClassMetadata instance holds all the object-relational mapping metadata @@ -715,14 +714,11 @@ public function getSingleIdReflectionProperty() */ public function getIdentifierValues($entity) { - if ($entity instanceof AssociationCacheEntry) { - throw new \InvalidArgumentException('WTF DUDE: ' . $entity->class . ' - ' . \serialize($entity->identifier)); - } if ($this->isIdentifierComposite) { $id = []; foreach ($this->identifier as $idField) { - $value = $this->getIndentifierValue($entity, $idField); + $value = $this->reflFields[$idField]->getValue($entity); if (null !== $value) { $id[$idField] = $value; @@ -733,7 +729,7 @@ public function getIdentifierValues($entity) } $id = $this->identifier[0]; - $value = $this->getIndentifierValue($entity, $id); + $value = $this->reflFields[$id]->getValue($entity); if (null === $value) { return []; @@ -742,15 +738,6 @@ public function getIdentifierValues($entity) return [$id => $value]; } - private function getIndentifierValue($entity, $id) - { - if ($entity instanceof AssociationCacheEntry) { - return $entity->identifier[$id]; - } - - return $this->reflFields[$id]->getValue($entity); - } - /** * Populates the entity identifier of an entity. * From ed047520c3f3a43b3c333014b2ea5c830d2d9b13 Mon Sep 17 00:00:00 2001 From: radmax Date: Thu, 24 Aug 2017 10:55:29 +0200 Subject: [PATCH 580/877] fixed typo --- docs/en/reference/dql-doctrine-query-language.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/dql-doctrine-query-language.rst b/docs/en/reference/dql-doctrine-query-language.rst index 1b0d3b01377..8944ce66e71 100644 --- a/docs/en/reference/dql-doctrine-query-language.rst +++ b/docs/en/reference/dql-doctrine-query-language.rst @@ -654,7 +654,7 @@ The same restrictions apply for the reference of related entities. DQL DELETE statements are ported directly into a Database DELETE statement and therefore bypass any events and checks for the version column if they are not explicitly added to the WHERE clause - of the query. Additionally Deletes of specifies entities are *NOT* + of the query. Additionally Deletes of specified entities are *NOT* cascaded to related entities even if specified in the metadata. From a708d4076ea63d773a23d3d03518f51e0763e454 Mon Sep 17 00:00:00 2001 From: Alessandro Minoccheri Date: Thu, 24 Aug 2017 11:27:54 +0200 Subject: [PATCH 581/877] fixed typo into native-sql documentation --- docs/en/reference/native-sql.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/native-sql.rst b/docs/en/reference/native-sql.rst index 75231b7a99b..fe633aea655 100644 --- a/docs/en/reference/native-sql.rst +++ b/docs/en/reference/native-sql.rst @@ -63,7 +63,7 @@ This has several benefits: - The API is much simpler than the usual ``ResultSetMapping`` API. One downside is that the builder API does not yet support entities -with inheritance hierachies. +with inheritance hierarchies. .. code-block:: php From 660f164568aec5a9c893b041fb1630a2074f6fcb Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 25 Aug 2017 09:21:12 +0200 Subject: [PATCH 582/877] #6284 #6217 s/$this->assert/self::assert as per @lcobucci's review --- .../Tests/ORM/Functional/Ticket/GH6217Test.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php index 861925f08f6..d781d0c816d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6217Test.php @@ -35,17 +35,17 @@ public function testLoadingOfSecondLevelCacheOnEagerAssociations() : void $repository = $this->_em->getRepository(GH6217FetchedEntity::class); $filters = ['eager' => $eager->id]; - $this->assertCount(1, $repository->findBy($filters)); + self::assertCount(1, $repository->findBy($filters)); $queryCount = $this->getCurrentQueryCount(); /* @var $found GH6217FetchedEntity[] */ $found = $repository->findBy($filters); - $this->assertCount(1, $found); - $this->assertInstanceOf(GH6217FetchedEntity::class, $found[0]); - $this->assertSame($lazy->id, $found[0]->lazy->id); - $this->assertSame($eager->id, $found[0]->eager->id); - $this->assertEquals($queryCount, $this->getCurrentQueryCount(), 'No queries were executed in `findBy`'); + self::assertCount(1, $found); + self::assertInstanceOf(GH6217FetchedEntity::class, $found[0]); + self::assertSame($lazy->id, $found[0]->lazy->id); + self::assertSame($eager->id, $found[0]->eager->id); + self::assertEquals($queryCount, $this->getCurrentQueryCount(), 'No queries were executed in `findBy`'); } } From 922c55f5ddeda25463e9a5b7a0b00d44a65fa65b Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 26 Aug 2017 14:15:05 +0200 Subject: [PATCH 583/877] Replacing direct `quote` model-set schema creation with actually existing model-set setup --- .../ORM/Functional/Ticket/DDC142Test.php | 18 +++-------------- .../ORM/Functional/Ticket/DDC1843Test.php | 20 +++---------------- .../ORM/Functional/Ticket/DDC1885Test.php | 16 +++------------ .../ORM/Functional/Ticket/GH6402Test.php | 2 -- 4 files changed, 9 insertions(+), 47 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC142Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC142Test.php index 287b73dec3b..ae455f546a2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC142Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC142Test.php @@ -2,8 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Tests\Models\Quote\Group; -use Doctrine\Tests\Models\Quote\Phone; use Doctrine\Tests\Models\Quote\User; use Doctrine\Tests\Models\Quote\Address; @@ -13,21 +11,11 @@ */ class DDC142Test extends \Doctrine\Tests\OrmFunctionalTestCase { - protected function setUp() + protected function setUp() : void { - parent::setUp(); + $this->useModelSet('quote'); - try { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(User::class), - $this->_em->getClassMetadata(Group::class), - $this->_em->getClassMetadata(Phone::class), - $this->_em->getClassMetadata(Address::class), - ] - ); - } catch(\Exception $e) { - } + parent::setUp(); } public function testCreateRetrieveUpdateDelete() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php index 4273a36b6af..c97ebb287a2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php @@ -2,10 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Tests\Models\Quote\Address; use Doctrine\Tests\Models\Quote\Group; -use Doctrine\Tests\Models\Quote\Phone; -use Doctrine\Tests\Models\Quote\User; /** * @group DDC-1845 @@ -13,22 +10,11 @@ */ class DDC1843Test extends \Doctrine\Tests\OrmFunctionalTestCase { - - protected function setUp() + protected function setUp() : void { - parent::setUp(); + $this->useModelSet('quote'); - try { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(User::class), - $this->_em->getClassMetadata(Group::class), - $this->_em->getClassMetadata(Phone::class), - $this->_em->getClassMetadata(Address::class), - ] - ); - } catch(\Exception $e) { - } + parent::setUp(); } public function testCreateRetrieveUpdateDelete() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1885Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1885Test.php index 283340b820a..2c141151b29 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1885Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1885Test.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Tests\Models\Quote\Address; use Doctrine\Tests\Models\Quote\Group; use Doctrine\Tests\Models\Quote\User; @@ -18,20 +17,11 @@ class DDC1885Test extends \Doctrine\Tests\OrmFunctionalTestCase */ private $user; - protected function setUp() + protected function setUp() : void { - parent::setUp(); + $this->useModelSet('quote'); - try { - $this->_schemaTool->createSchema( - [ - $this->_em->getClassMetadata(User::class), - $this->_em->getClassMetadata(Group::class), - $this->_em->getClassMetadata(Address::class), - ] - ); - } catch(\Exception $e) { - } + parent::setUp(); $user = new User(); $user->name = "FabioBatSilva"; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6402Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6402Test.php index 85bf43ea0c3..d675da94ad3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6402Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6402Test.php @@ -5,8 +5,6 @@ use Doctrine\Tests\Models\Quote\Address; use Doctrine\Tests\Models\Quote\City; use Doctrine\Tests\Models\Quote\FullAddress; -use Doctrine\Tests\Models\Quote\Group; -use Doctrine\Tests\Models\Quote\Phone; use Doctrine\Tests\Models\Quote\User; use Doctrine\Tests\OrmFunctionalTestCase; From e1e7485e587374707dc4d72499d5197793e98f42 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 26 Aug 2017 16:41:03 +0200 Subject: [PATCH 584/877] Correcting the `SimpleInsertPerformanceBench`, which was running into duplicate record integrity constraint violations when run with >1 revs --- .../Hydration/SimpleInsertPerformanceBench.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Performance/Hydration/SimpleInsertPerformanceBench.php b/tests/Doctrine/Performance/Hydration/SimpleInsertPerformanceBench.php index 68a933dd31e..5806b6b9da4 100644 --- a/tests/Doctrine/Performance/Hydration/SimpleInsertPerformanceBench.php +++ b/tests/Doctrine/Performance/Hydration/SimpleInsertPerformanceBench.php @@ -3,9 +3,7 @@ namespace Doctrine\Performance\Hydration; use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\Query; use Doctrine\Performance\EntityManagerFactory; -use Doctrine\Tests\Mocks\HydratorMockStatement; use Doctrine\Tests\Models\CMS; use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods; @@ -24,6 +22,11 @@ final class SimpleInsertPerformanceBench */ private $users; + /** + * @var string + */ + private $tableName; + public function init() { $this->entityManager = EntityManagerFactory::getEntityManager([ @@ -45,10 +48,17 @@ public function init() $this->users[$i] = $user; } + + $this->tableName = $this->entityManager->getClassMetadata(CMS\CmsUser::class)->getTableName(); } public function benchHydration() { + // Yes, this is a lot of overhead, but I have no better solution other than + // completely mocking out the DB, which would be silly (query impact is + // necessarily part of our benchmarks) + $this->entityManager->getConnection()->executeQuery('DELETE FROM ' . $this->tableName)->execute(); + foreach ($this->users as $key => $user) { $this->entityManager->persist($user); From bfc76adce0091c972a5ee6767114f9e1a10f5f00 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Wed, 30 Aug 2017 18:08:07 +0200 Subject: [PATCH 585/877] Drop explicit conflict with stable symfony/yaml As per discussion in #6639, conflict with versions below 3.4 of the YAML component is superfluous, previous versions would work just fine even with bb994b9e70. --- composer.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/composer.json b/composer.json index fd4ddd9634b..e738e05ee27 100644 --- a/composer.json +++ b/composer.json @@ -24,9 +24,6 @@ "doctrine/annotations": "~1.4", "symfony/console": "~3.0|~4.0" }, - "conflict": { - "symfony/yaml": "<3.4" - }, "require-dev": { "symfony/yaml": "~3.4|~4.0", "phpunit/phpunit": "^6.0" From 874a5e3547d08c6be62aa8bae2f1afc380af983d Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Thu, 21 Apr 2016 23:33:34 +0200 Subject: [PATCH 586/877] Catch Throwable in PHP 7 --- lib/Doctrine/ORM/EntityManager.php | 8 ++++++-- .../ORM/Query/Exec/MultiTableDeleteExecutor.php | 6 +++++- .../ORM/Query/Exec/MultiTableUpdateExecutor.php | 6 +++++- .../Command/EnsureProductionSettingsCommand.php | 6 +++++- lib/Doctrine/ORM/Tools/SchemaTool.php | 8 ++++++-- lib/Doctrine/ORM/Tools/ToolsException.php | 4 ++-- lib/Doctrine/ORM/UnitOfWork.php | 10 +++++++++- 7 files changed, 38 insertions(+), 10 deletions(-) diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index d4b032bfc1e..99a9b15dc68 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -19,7 +19,6 @@ namespace Doctrine\ORM; -use Exception; use Doctrine\Common\EventManager; use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; @@ -237,7 +236,12 @@ public function transactional($func) $this->conn->commit(); return $return ?: true; - } catch (Exception $e) { + } catch (\Throwable $e) { + $this->close(); + $this->conn->rollBack(); + + throw $e; + } catch (\Exception $e) { // PHP 5 $this->close(); $this->conn->rollBack(); diff --git a/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php b/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php index aaf94d7ff90..1ecd7a7b225 100644 --- a/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php @@ -129,11 +129,15 @@ public function execute(Connection $conn, array $params, array $types) foreach ($this->_sqlStatements as $sql) { $conn->executeUpdate($sql); } - } catch (\Exception $exception) { + } catch (\Throwable $exception) { // FAILURE! Drop temporary table to avoid possible collisions $conn->executeUpdate($this->_dropTempTableSql); // Re-throw exception + throw $exception; + } catch (\Exception $exception) { // PHP 5 + $conn->executeUpdate($this->_dropTempTableSql); + throw $exception; } diff --git a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php index acad25a924b..296b7d553ee 100644 --- a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php @@ -188,11 +188,15 @@ public function execute(Connection $conn, array $params, array $types) $conn->executeUpdate($statement, $paramValues, $paramTypes); } - } catch (\Exception $exception) { + } catch (\Throwable $exception) { // FAILURE! Drop temporary table to avoid possible collisions $conn->executeUpdate($this->_dropTempTableSql); // Re-throw exception + throw $exception; + } catch (\Exception $exception) { // PHP 5 + $conn->executeUpdate($this->_dropTempTableSql); + throw $exception; } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php index 499565a018a..e628b704995 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php @@ -72,7 +72,11 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($input->getOption('complete') !== null) { $em->getConnection()->connect(); } - } catch (\Exception $e) { + } catch (\Throwable $e) { + $output->writeln('' . $e->getMessage() . ''); + + return 1; + } catch (\Exception $e) { // PHP 5 $output->writeln('' . $e->getMessage() . ''); return 1; diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 007ac85a8b7..e84a9c53d03 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -92,7 +92,9 @@ public function createSchema(array $classes) foreach ($createSchemaSql as $sql) { try { $conn->executeQuery($sql); - } catch (\Exception $e) { + } catch (\Throwable $e) { + throw ToolsException::schemaToolFailure($sql, $e); + } catch (\Exception $e) { // PHP 5 throw ToolsException::schemaToolFailure($sql, $e); } } @@ -742,7 +744,9 @@ public function dropSchema(array $classes) foreach ($dropSchemaSql as $sql) { try { $conn->executeQuery($sql); - } catch (\Exception $e) { + } catch (\Throwable $e) { + + } catch (\Exception $e) { // PHP 5 } } diff --git a/lib/Doctrine/ORM/Tools/ToolsException.php b/lib/Doctrine/ORM/Tools/ToolsException.php index 0a461640491..ed633111818 100644 --- a/lib/Doctrine/ORM/Tools/ToolsException.php +++ b/lib/Doctrine/ORM/Tools/ToolsException.php @@ -30,11 +30,11 @@ class ToolsException extends ORMException { /** * @param string $sql - * @param \Exception $e + * @param \Exception $e The original exception, or duck-typed Throwable in PHP 7. * * @return ToolsException */ - public static function schemaToolFailure($sql, \Exception $e) + public static function schemaToolFailure($sql, $e) { return new self("Schema-Tool failed with Error '" . $e->getMessage() . "' while executing DDL: " . $sql, "0", $e); } diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 0edd756f0d1..c5598cd4b06 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -44,6 +44,7 @@ use Doctrine\ORM\Proxy\Proxy; use Doctrine\ORM\Utility\IdentifierFlattener; use Exception; +use Throwable; use InvalidArgumentException; use UnexpectedValueException; @@ -411,7 +412,14 @@ public function commit($entity = null) } $conn->commit(); - } catch (Exception $e) { + } catch (\Throwable $e) { + $this->em->close(); + $conn->rollBack(); + + $this->afterTransactionRolledBack(); + + throw $e; + } catch (\Exception $e) { // PHP 5 $this->em->close(); $conn->rollBack(); From a1c93bfd485368594cdff88329a6dee872dfcadf Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 2 Sep 2017 13:44:12 +0200 Subject: [PATCH 587/877] #5796 replacing `Exception` catching with `Throwable` catching, removing PHP5 compliance code --- lib/Doctrine/ORM/EntityManager.php | 5 ----- lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php | 4 ---- lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php | 4 ---- .../Console/Command/EnsureProductionSettingsCommand.php | 4 ---- lib/Doctrine/ORM/Tools/SchemaTool.php | 4 +--- lib/Doctrine/ORM/UnitOfWork.php | 9 --------- 6 files changed, 1 insertion(+), 29 deletions(-) diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 99a9b15dc68..49d7a372b72 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -240,11 +240,6 @@ public function transactional($func) $this->close(); $this->conn->rollBack(); - throw $e; - } catch (\Exception $e) { // PHP 5 - $this->close(); - $this->conn->rollBack(); - throw $e; } } diff --git a/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php b/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php index 1ecd7a7b225..e7287b7082a 100644 --- a/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php @@ -134,10 +134,6 @@ public function execute(Connection $conn, array $params, array $types) $conn->executeUpdate($this->_dropTempTableSql); // Re-throw exception - throw $exception; - } catch (\Exception $exception) { // PHP 5 - $conn->executeUpdate($this->_dropTempTableSql); - throw $exception; } diff --git a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php index 296b7d553ee..5dd9b15148e 100644 --- a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php @@ -193,10 +193,6 @@ public function execute(Connection $conn, array $params, array $types) $conn->executeUpdate($this->_dropTempTableSql); // Re-throw exception - throw $exception; - } catch (\Exception $exception) { // PHP 5 - $conn->executeUpdate($this->_dropTempTableSql); - throw $exception; } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php index e628b704995..5876d2d1f34 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php @@ -75,10 +75,6 @@ protected function execute(InputInterface $input, OutputInterface $output) } catch (\Throwable $e) { $output->writeln('' . $e->getMessage() . ''); - return 1; - } catch (\Exception $e) { // PHP 5 - $output->writeln('' . $e->getMessage() . ''); - return 1; } diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index e84a9c53d03..a0d3af2b499 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -745,9 +745,7 @@ public function dropSchema(array $classes) try { $conn->executeQuery($sql); } catch (\Throwable $e) { - - } catch (\Exception $e) { // PHP 5 - + // ignored } } } diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index c5598cd4b06..09bc313c149 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -43,8 +43,6 @@ use Doctrine\ORM\Persisters\Entity\SingleTablePersister; use Doctrine\ORM\Proxy\Proxy; use Doctrine\ORM\Utility\IdentifierFlattener; -use Exception; -use Throwable; use InvalidArgumentException; use UnexpectedValueException; @@ -418,13 +416,6 @@ public function commit($entity = null) $this->afterTransactionRolledBack(); - throw $e; - } catch (\Exception $e) { // PHP 5 - $this->em->close(); - $conn->rollBack(); - - $this->afterTransactionRolledBack(); - throw $e; } From 12043cd845f9cf84f5f995a3ef25b716db541d92 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 2 Sep 2017 13:47:58 +0200 Subject: [PATCH 588/877] #5796 minor CS fixes (imported symbols) and removing last PHP5 compliance bits --- lib/Doctrine/ORM/EntityManager.php | 3 ++- lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php | 3 ++- lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php | 3 ++- .../Console/Command/EnsureProductionSettingsCommand.php | 3 ++- lib/Doctrine/ORM/Tools/SchemaTool.php | 2 -- lib/Doctrine/ORM/Tools/ToolsException.php | 9 ++------- lib/Doctrine/ORM/UnitOfWork.php | 3 ++- 7 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 49d7a372b72..83950534554 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -27,6 +27,7 @@ use Doctrine\ORM\Proxy\ProxyFactory; use Doctrine\ORM\Query\FilterCollection; use Doctrine\Common\Util\ClassUtils; +use Throwable; /** * The EntityManager is the central access point to ORM functionality. @@ -236,7 +237,7 @@ public function transactional($func) $this->conn->commit(); return $return ?: true; - } catch (\Throwable $e) { + } catch (Throwable $e) { $this->close(); $this->conn->rollBack(); diff --git a/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php b/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php index e7287b7082a..2f3d5acf5d6 100644 --- a/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php @@ -23,6 +23,7 @@ use Doctrine\DBAL\Types\Type; use Doctrine\ORM\Query\AST; use Doctrine\ORM\Utility\PersisterHelper; +use Throwable; /** * Executes the SQL statements for bulk DQL DELETE statements on classes in @@ -129,7 +130,7 @@ public function execute(Connection $conn, array $params, array $types) foreach ($this->_sqlStatements as $sql) { $conn->executeUpdate($sql); } - } catch (\Throwable $exception) { + } catch (Throwable $exception) { // FAILURE! Drop temporary table to avoid possible collisions $conn->executeUpdate($this->_dropTempTableSql); diff --git a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php index 5dd9b15148e..7f13ed5f61a 100644 --- a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php @@ -24,6 +24,7 @@ use Doctrine\ORM\Query\ParameterTypeInferer; use Doctrine\ORM\Query\AST; use Doctrine\ORM\Utility\PersisterHelper; +use Throwable; /** * Executes the SQL statements for bulk DQL UPDATE statements on classes in @@ -188,7 +189,7 @@ public function execute(Connection $conn, array $params, array $types) $conn->executeUpdate($statement, $paramValues, $paramTypes); } - } catch (\Throwable $exception) { + } catch (Throwable $exception) { // FAILURE! Drop temporary table to avoid possible collisions $conn->executeUpdate($this->_dropTempTableSql); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php index 5876d2d1f34..180254f9cec 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php @@ -23,6 +23,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Throwable; /** * Command to ensure that Doctrine is properly configured for a production environment. @@ -72,7 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($input->getOption('complete') !== null) { $em->getConnection()->connect(); } - } catch (\Throwable $e) { + } catch (Throwable $e) { $output->writeln('' . $e->getMessage() . ''); return 1; diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index a0d3af2b499..6609b5ea08f 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -94,8 +94,6 @@ public function createSchema(array $classes) $conn->executeQuery($sql); } catch (\Throwable $e) { throw ToolsException::schemaToolFailure($sql, $e); - } catch (\Exception $e) { // PHP 5 - throw ToolsException::schemaToolFailure($sql, $e); } } } diff --git a/lib/Doctrine/ORM/Tools/ToolsException.php b/lib/Doctrine/ORM/Tools/ToolsException.php index ed633111818..95b3af0acbd 100644 --- a/lib/Doctrine/ORM/Tools/ToolsException.php +++ b/lib/Doctrine/ORM/Tools/ToolsException.php @@ -20,6 +20,7 @@ namespace Doctrine\ORM\Tools; use Doctrine\ORM\ORMException; +use Throwable; /** * Tools related Exceptions. @@ -28,13 +29,7 @@ */ class ToolsException extends ORMException { - /** - * @param string $sql - * @param \Exception $e The original exception, or duck-typed Throwable in PHP 7. - * - * @return ToolsException - */ - public static function schemaToolFailure($sql, $e) + public static function schemaToolFailure(string $sql, Throwable $e) : self { return new self("Schema-Tool failed with Error '" . $e->getMessage() . "' while executing DDL: " . $sql, "0", $e); } diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 09bc313c149..05ad599a498 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -44,6 +44,7 @@ use Doctrine\ORM\Proxy\Proxy; use Doctrine\ORM\Utility\IdentifierFlattener; use InvalidArgumentException; +use Throwable; use UnexpectedValueException; /** @@ -410,7 +411,7 @@ public function commit($entity = null) } $conn->commit(); - } catch (\Throwable $e) { + } catch (Throwable $e) { $this->em->close(); $conn->rollBack(); From c016e2d434fd0c6ec108e227b85a092d6f807dc0 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 2 Sep 2017 13:55:07 +0200 Subject: [PATCH 589/877] Adding minimal test to verify `EntityManager` behavior against #5796 --- tests/Doctrine/Tests/ORM/EntityManagerTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/EntityManagerTest.php b/tests/Doctrine/Tests/ORM/EntityManagerTest.php index 7f36bb285b1..0191ba1587a 100644 --- a/tests/Doctrine/Tests/ORM/EntityManagerTest.php +++ b/tests/Doctrine/Tests/ORM/EntityManagerTest.php @@ -232,6 +232,24 @@ public function testCreateInvalidConnection() EntityManager::create(1, $config); } + /** + * @group #5796 + */ + public function testTransactionalReThrowsThrowables() + { + try { + $this->_em->transactional(function () { + (function (array $value) { + // this only serves as an IIFE that throws a `TypeError` + })(null); + }); + + self::fail('TypeError expected to be thrown'); + } catch (\TypeError $ignored) { + self::assertFalse($this->_em->isOpen()); + } + } + /** * @group 6017 */ From fd9f96c7668a415c34dba7e9e2339a6dad14de6f Mon Sep 17 00:00:00 2001 From: Michael Gwynne Date: Mon, 4 Sep 2017 09:26:11 +0100 Subject: [PATCH 590/877] Updating _maxResults to allow for null --- lib/Doctrine/ORM/Query.php | 6 +++--- lib/Doctrine/ORM/QueryBuilder.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 222586a1f74..041ebeebb9f 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -163,7 +163,7 @@ final class Query extends AbstractQuery /** * The maximum number of results to return (the "limit"). * - * @var integer + * @var integer|null */ private $_maxResults = null; @@ -628,7 +628,7 @@ public function getFirstResult() /** * Sets the maximum number of results to retrieve (the "limit"). * - * @param integer $maxResults + * @param integer|null $maxResults * * @return Query This query object. */ @@ -644,7 +644,7 @@ public function setMaxResults($maxResults) * Gets the maximum number of results the query object was set to retrieve (the "limit"). * Returns NULL if {@link setMaxResults} was not applied to this query. * - * @return integer Maximum number of results. + * @return integer|null Maximum number of results. */ public function getMaxResults() { diff --git a/lib/Doctrine/ORM/QueryBuilder.php b/lib/Doctrine/ORM/QueryBuilder.php index 894fbc32f74..51f7580ddee 100644 --- a/lib/Doctrine/ORM/QueryBuilder.php +++ b/lib/Doctrine/ORM/QueryBuilder.php @@ -107,7 +107,7 @@ class QueryBuilder /** * The maximum number of results to retrieve. * - * @var integer + * @var integer|null */ private $_maxResults = null; @@ -653,7 +653,7 @@ public function getFirstResult() /** * Sets the maximum number of results to retrieve (the "limit"). * - * @param integer $maxResults The maximum number of results to retrieve. + * @param integer|null $maxResults The maximum number of results to retrieve. * * @return self */ @@ -668,7 +668,7 @@ public function setMaxResults($maxResults) * Gets the maximum number of results the query object was set to retrieve (the "limit"). * Returns NULL if {@link setMaxResults} was not applied to this query builder. * - * @return integer Maximum number of results. + * @return integer|null Maximum number of results. */ public function getMaxResults() { From d0d1e557d1a88fa015cf4dbbbe100e372f21d1ba Mon Sep 17 00:00:00 2001 From: Michael Gwynne Date: Mon, 4 Sep 2017 10:11:43 +0100 Subject: [PATCH 591/877] Adding change to appease scrutinizer --- lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php index 1874eb88dde..aceeb5c0989 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php @@ -136,7 +136,7 @@ private function validate(SelectStatement $AST) $fromRoot = reset($from); if ($query instanceof Query - && $query->getMaxResults() + && null !== $query->getMaxResults() && $AST->orderByClause && count($fromRoot->joins)) { // Check each orderby item. From c429f1c38b029b19ed2cbb686c1414880fc0659c Mon Sep 17 00:00:00 2001 From: Greg Bell Date: Wed, 6 Sep 2017 07:58:34 +1000 Subject: [PATCH 592/877] Clarify association mapping language - 5.3 was wrong - should really be 'inversedBy' - 11.1 - change 'use' to 'have' for consistency. A class has an attribute. - See https://github.com/doctrine/doctrine2/issues/6686 --- docs/en/reference/association-mapping.rst | 2 +- docs/en/reference/unitofwork-associations.rst | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/en/reference/association-mapping.rst b/docs/en/reference/association-mapping.rst index ca3b02f9ea5..fd791a0f386 100644 --- a/docs/en/reference/association-mapping.rst +++ b/docs/en/reference/association-mapping.rst @@ -268,7 +268,7 @@ Generated MySQL Schema: ) ENGINE = InnoDB; ALTER TABLE Cart ADD FOREIGN KEY (customer_id) REFERENCES Customer(id); -We had a choice of sides on which to place the ``mappedBy`` attribute. Because it +We had a choice of sides on which to place the ``inversedBy`` attribute. Because it is on the ``Cart``, that is the owning side of the relation, and thus holds the foreign key. diff --git a/docs/en/reference/unitofwork-associations.rst b/docs/en/reference/unitofwork-associations.rst index da3cc9dc88b..c9ccf73fc8a 100644 --- a/docs/en/reference/unitofwork-associations.rst +++ b/docs/en/reference/unitofwork-associations.rst @@ -15,10 +15,10 @@ Bidirectional Associations The following rules apply to **bidirectional** associations: -- The inverse side has to use the ``mappedBy`` attribute of the OneToOne, +- The inverse side has to have the ``mappedBy`` attribute of the OneToOne, OneToMany, or ManyToMany mapping declaration. The mappedBy attribute contains the name of the association-field on the owning side. -- The owning side has to use the ``inversedBy`` attribute of the +- The owning side has to have the ``inversedBy`` attribute of the OneToOne, ManyToOne, or ManyToMany mapping declaration. The inversedBy attribute contains the name of the association-field on the inverse-side. From c7d6d6239320394d6d3d3c4fc98d67a0b0aeef9b Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Wed, 6 Sep 2017 01:22:41 +0200 Subject: [PATCH 593/877] Use newer PHP syntax --- .../ORM/Mapping/ClassMetadataInfo.php | 18 ++++++----------- .../ORM/Mapping/Driver/YamlDriver.php | 20 +++++++++---------- .../Entity/BasicEntityPersister.php | 2 +- .../Entity/JoinedSubclassPersister.php | 4 +--- .../Query/Exec/MultiTableUpdateExecutor.php | 2 +- .../ORM/Query/ResultSetMappingBuilder.php | 6 ++---- lib/Doctrine/ORM/QueryBuilder.php | 6 +++--- .../ORM/Tools/ConvertDoctrine1Schema.php | 8 ++++---- .../ORM/Tools/Export/Driver/YamlExporter.php | 6 +++--- lib/Doctrine/ORM/Tools/SchemaTool.php | 12 +++++------ lib/Doctrine/ORM/UnitOfWork.php | 4 ++-- .../Doctrine/Tests/ORM/EntityManagerTest.php | 2 +- .../Functional/Locking/GearmanLockTest.php | 4 ++-- .../Functional/Locking/LockAgentWorker.php | 4 ++-- .../ORM/Functional/Ticket/DDC1454Test.php | 2 +- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 4 ++-- 16 files changed, 47 insertions(+), 57 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index b5eebcdde2c..7794c8c4dcc 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -942,7 +942,7 @@ public function wakeupReflection($reflService) } $fieldRefl = $reflService->getAccessibleProperty( - isset($embeddedClass['declared']) ? $embeddedClass['declared'] : $this->name, + $embeddedClass['declared'] ?? $this->name, $property ); @@ -1617,9 +1617,7 @@ protected function _validateAndCompleteOneToOneMapping(array $mapping) } $mapping['sourceToTargetKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName']; - $mapping['joinColumnFieldNames'][$joinColumn['name']] = isset($joinColumn['fieldName']) - ? $joinColumn['fieldName'] - : $joinColumn['name']; + $mapping['joinColumnFieldNames'][$joinColumn['name']] = $joinColumn['fieldName'] ?? $joinColumn['name']; } if ($uniqueConstraintColumns) { @@ -3288,8 +3286,8 @@ public function mapEmbedded(array $mapping) $this->embeddedClasses[$mapping['fieldName']] = [ 'class' => $this->fullyQualifiedClassName($mapping['class']), 'columnPrefix' => $mapping['columnPrefix'], - 'declaredField' => isset($mapping['declaredField']) ? $mapping['declaredField'] : null, - 'originalField' => isset($mapping['originalField']) ? $mapping['originalField'] : null, + 'declaredField' => $mapping['declaredField'] ?? null, + 'originalField' => $mapping['originalField'] ?? null, ]; } @@ -3302,15 +3300,11 @@ public function mapEmbedded(array $mapping) public function inlineEmbeddable($property, ClassMetadataInfo $embeddable) { foreach ($embeddable->fieldMappings as $fieldMapping) { - $fieldMapping['originalClass'] = isset($fieldMapping['originalClass']) - ? $fieldMapping['originalClass'] - : $embeddable->name; + $fieldMapping['originalClass'] = $fieldMapping['originalClass'] ?? $embeddable->name; $fieldMapping['declaredField'] = isset($fieldMapping['declaredField']) ? $property . '.' . $fieldMapping['declaredField'] : $property; - $fieldMapping['originalField'] = isset($fieldMapping['originalField']) - ? $fieldMapping['originalField'] - : $fieldMapping['fieldName']; + $fieldMapping['originalField'] = $fieldMapping['originalField'] ?? $fieldMapping['fieldName']; $fieldMapping['fieldName'] = $property . "." . $fieldMapping['fieldName']; if (! empty($this->embeddedClasses[$property]['columnPrefix'])) { diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index fa52013932d..efd5accbc7f 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -64,7 +64,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) } } else if ($element['type'] == 'mappedSuperclass') { $metadata->setCustomRepositoryClass( - isset($element['repositoryClass']) ? $element['repositoryClass'] : null + $element['repositoryClass'] ?? null ); $metadata->isMappedSuperclass = true; } else if ($element['type'] == 'embeddable') { @@ -115,9 +115,9 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $metadata->addNamedNativeQuery( [ 'name' => $mappingElement['name'], - 'query' => isset($mappingElement['query']) ? $mappingElement['query'] : null, - 'resultClass' => isset($mappingElement['resultClass']) ? $mappingElement['resultClass'] : null, - 'resultSetMapping' => isset($mappingElement['resultSetMapping']) ? $mappingElement['resultSetMapping'] : null, + 'query' => $mappingElement['query'] ?? null, + 'resultClass' => $mappingElement['resultClass'] ?? null, + 'resultSetMapping' => $mappingElement['resultSetMapping'] ?? null, ] ); } @@ -136,15 +136,15 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) foreach ($resultSetMapping['entityResult'] as $entityResultElement) { $entityResult = [ 'fields' => [], - 'entityClass' => isset($entityResultElement['entityClass']) ? $entityResultElement['entityClass'] : null, - 'discriminatorColumn' => isset($entityResultElement['discriminatorColumn']) ? $entityResultElement['discriminatorColumn'] : null, + 'entityClass' => $entityResultElement['entityClass'] ?? null, + 'discriminatorColumn' => $entityResultElement['discriminatorColumn'] ?? null, ]; if (isset($entityResultElement['fieldResult'])) { foreach ($entityResultElement['fieldResult'] as $fieldResultElement) { $entityResult['fields'][] = [ - 'name' => isset($fieldResultElement['name']) ? $fieldResultElement['name'] : null, - 'column' => isset($fieldResultElement['column']) ? $fieldResultElement['column'] : null, + 'name' => $fieldResultElement['name'] ?? null, + 'column' => $fieldResultElement['column'] ?? null, ]; } } @@ -157,7 +157,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) if (isset($resultSetMapping['columnResult'])) { foreach ($resultSetMapping['columnResult'] as $columnResultAnnot) { $columns[] = [ - 'name' => isset($columnResultAnnot['name']) ? $columnResultAnnot['name'] : null, + 'name' => $columnResultAnnot['name'] ?? null, ]; } } @@ -343,7 +343,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) $mapping = [ 'fieldName' => $name, 'class' => $embeddedMapping['class'], - 'columnPrefix' => isset($embeddedMapping['columnPrefix']) ? $embeddedMapping['columnPrefix'] : null, + 'columnPrefix' => $embeddedMapping['columnPrefix'] ?? null, ]; $metadata->mapEmbedded($mapping); } diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 972199c5ea2..b9fb045e93f 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -1795,7 +1795,7 @@ private function getOneToManyStatement(array $assoc, $sourceEntity, $offset = nu $parameters = []; $owningAssoc = $this->class->associationMappings[$assoc['mappedBy']]; $sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']); - $tableAlias = $this->getSQLTableAlias(isset($owningAssoc['inherited']) ? $owningAssoc['inherited'] : $this->class->name); + $tableAlias = $this->getSQLTableAlias($owningAssoc['inherited'] ?? $this->class->name); foreach ($owningAssoc['targetToSourceKeyColumns'] as $sourceKeyColumn => $targetKeyColumn) { if ($sourceClass->containsForeignIdentifier) { diff --git a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php index 0be15068977..2693f3fabee 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php @@ -196,9 +196,7 @@ public function executeInserts() foreach ($subTableStmts as $tableName => $stmt) { /** @var \Doctrine\DBAL\Statement $stmt */ $paramIndex = 1; - $data = isset($insertData[$tableName]) - ? $insertData[$tableName] - : []; + $data = $insertData[$tableName] ?? []; foreach ((array) $id as $idName => $idVal) { $type = isset($this->columnTypes[$idName]) ? $this->columnTypes[$idName] : Type::STRING; diff --git a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php index 7f13ed5f61a..47db0342103 100644 --- a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php @@ -183,7 +183,7 @@ public function execute(Connection $conn, array $params, array $types) if (isset($this->_sqlParameters[$key])) { foreach ($this->_sqlParameters[$key] as $parameterKey => $parameterName) { $paramValues[] = $params[$parameterKey]; - $paramTypes[] = isset($types[$parameterKey]) ? $types[$parameterKey] : ParameterTypeInferer::inferType($params[$parameterKey]); + $paramTypes[] = $types[$parameterKey] ?? ParameterTypeInferer::inferType($params[$parameterKey]); } } diff --git a/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php b/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php index 887d02c6f5a..0bf11814b97 100644 --- a/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php +++ b/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php @@ -206,8 +206,7 @@ private function getColumnAlias($columnName, $mode, array $customRenameColumns) return $columnName . $this->sqlCounter++; case self::COLUMN_RENAMING_CUSTOM: - return isset($customRenameColumns[$columnName]) - ? $customRenameColumns[$columnName] : $columnName; + return $customRenameColumns[$columnName] ?? $columnName; case self::COLUMN_RENAMING_NONE: return $columnName; @@ -441,8 +440,7 @@ public function generateSelectClause($tableAliases = []) $sql = ""; foreach ($this->columnOwnerMap as $columnName => $dqlAlias) { - $tableAlias = isset($tableAliases[$dqlAlias]) - ? $tableAliases[$dqlAlias] : $dqlAlias; + $tableAlias = $tableAliases[$dqlAlias] ?? $dqlAlias; if ($sql) { $sql .= ", "; diff --git a/lib/Doctrine/ORM/QueryBuilder.php b/lib/Doctrine/ORM/QueryBuilder.php index 51f7580ddee..976be4ddf84 100644 --- a/lib/Doctrine/ORM/QueryBuilder.php +++ b/lib/Doctrine/ORM/QueryBuilder.php @@ -1441,12 +1441,12 @@ private function _getReducedDQLQueryPart($queryPartName, $options = []) $queryPart = $this->getDQLPart($queryPartName); if (empty($queryPart)) { - return (isset($options['empty']) ? $options['empty'] : ''); + return ($options['empty'] ?? ''); } - return (isset($options['pre']) ? $options['pre'] : '') + return ($options['pre'] ?? '') . (is_array($queryPart) ? implode($options['separator'], $queryPart) : $queryPart) - . (isset($options['post']) ? $options['post'] : ''); + . ($options['post'] ?? ''); } /** diff --git a/lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php b/lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php index 408cb52d238..5356520c0ee 100644 --- a/lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php +++ b/lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php @@ -214,7 +214,7 @@ private function convertColumn($className, $name, $column, ClassMetadataInfo $me $fieldMapping['id'] = true; } - $fieldMapping['fieldName'] = isset($column['alias']) ? $column['alias'] : $name; + $fieldMapping['fieldName'] = $column['alias'] ?? $name; $fieldMapping['columnName'] = $column['name']; $fieldMapping['type'] = $column['type']; @@ -313,13 +313,13 @@ private function convertRelations($className, array $model, ClassMetadataInfo $m $foreignType = 'many'; $joinColumns = []; } else { - $type = isset($relation['type']) ? $relation['type'] : 'one'; - $foreignType = isset($relation['foreignType']) ? $relation['foreignType'] : 'many'; + $type = $relation['type'] ?? 'one'; + $foreignType = $relation['foreignType'] ?? 'many'; $joinColumns = [ [ 'name' => $relation['local'], 'referencedColumnName' => $relation['foreign'], - 'onDelete' => isset($relation['onDelete']) ? $relation['onDelete'] : null, + 'onDelete' => $relation['onDelete'] ?? null, ] ]; } diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php index 5da79095436..8fa1a7ffc45 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php @@ -193,7 +193,7 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) 'mappedBy' => $associationMapping['mappedBy'], 'inversedBy' => $associationMapping['inversedBy'], 'orphanRemoval' => $associationMapping['orphanRemoval'], - 'orderBy' => isset($associationMapping['orderBy']) ? $associationMapping['orderBy'] : null + 'orderBy' => $associationMapping['orderBy'] ?? null ]; $associationMappingArray = array_merge($associationMappingArray, $oneToManyMappingArray); @@ -202,8 +202,8 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) $manyToManyMappingArray = [ 'mappedBy' => $associationMapping['mappedBy'], 'inversedBy' => $associationMapping['inversedBy'], - 'joinTable' => isset($associationMapping['joinTable']) ? $associationMapping['joinTable'] : null, - 'orderBy' => isset($associationMapping['orderBy']) ? $associationMapping['orderBy'] : null + 'joinTable' => $associationMapping['joinTable'] ?? null, + 'orderBy' => $associationMapping['orderBy'] ?? null ]; $associationMappingArray = array_merge($associationMappingArray, $manyToManyMappingArray); diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 6609b5ea08f..5a3eb32ab5b 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -283,13 +283,13 @@ public function getSchemaFromMetadata(array $classes) $indexData['flags'] = []; } - $table->addIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName, (array) $indexData['flags'], isset($indexData['options']) ? $indexData['options'] : []); + $table->addIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName, (array) $indexData['flags'], $indexData['options'] ?? []); } } if (isset($class->table['uniqueConstraints'])) { foreach ($class->table['uniqueConstraints'] as $indexName => $indexData) { - $uniqIndex = new Index($indexName, $indexData['columns'], true, false, [], isset($indexData['options']) ? $indexData['options'] : []); + $uniqIndex = new Index($indexName, $indexData['columns'], true, false, [], $indexData['options'] ?? []); foreach ($table->getIndexes() as $tableIndexName => $tableIndex) { if ($tableIndex->isFullfilledBy($uniqIndex)) { @@ -298,7 +298,7 @@ public function getSchemaFromMetadata(array $classes) } } - $table->addUniqueIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName, isset($indexData['options']) ? $indexData['options'] : []); + $table->addUniqueIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName, $indexData['options'] ?? []); } } @@ -365,7 +365,7 @@ private function addDiscriminatorColumnDefinition($class, Table $table) } $options = [ - 'length' => isset($discrColumn['length']) ? $discrColumn['length'] : null, + 'length' => $discrColumn['length'] ?? null, 'notnull' => true ]; @@ -417,7 +417,7 @@ private function gatherColumn($class, array $mapping, Table $table) $columnType = $mapping['type']; $options = []; - $options['length'] = isset($mapping['length']) ? $mapping['length'] : null; + $options['length'] = $mapping['length'] ?? null; $options['notnull'] = isset($mapping['nullable']) ? ! $mapping['nullable'] : true; if ($class->isInheritanceTypeSingleTable() && $class->parentClasses) { $options['notnull'] = false; @@ -474,7 +474,7 @@ private function gatherColumn($class, array $mapping, Table $table) $table->addColumn($columnName, $columnType, $options); } - $isUnique = isset($mapping['unique']) ? $mapping['unique'] : false; + $isUnique = $mapping['unique'] ?? false; if ($isUnique) { $table->addUniqueIndex([$columnName]); } diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 05ad599a498..7ec28064da5 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1001,7 +1001,7 @@ public function recomputeSingleEntityChangeSet(ClassMetadata $class, $entity) $changeSet = []; foreach ($actualData as $propName => $actualValue) { - $orgValue = isset($originalData[$propName]) ? $originalData[$propName] : null; + $orgValue = $originalData[$propName] ?? null; if ($orgValue !== $actualValue) { $changeSet[$propName] = [$orgValue, $actualValue]; @@ -2681,7 +2681,7 @@ public function createEntity($className, array $data, &$hints = []) // TODO: Is this even computed right in all cases of composite keys? foreach ($assoc['targetToSourceKeyColumns'] as $targetColumn => $srcColumn) { - $joinColumnValue = isset($data[$srcColumn]) ? $data[$srcColumn] : null; + $joinColumnValue = $data[$srcColumn] ?? null; if ($joinColumnValue !== null) { if ($targetClass->containsForeignIdentifier) { diff --git a/tests/Doctrine/Tests/ORM/EntityManagerTest.php b/tests/Doctrine/Tests/ORM/EntityManagerTest.php index 0191ba1587a..a05e8610982 100644 --- a/tests/Doctrine/Tests/ORM/EntityManagerTest.php +++ b/tests/Doctrine/Tests/ORM/EntityManagerTest.php @@ -277,7 +277,7 @@ public function testClearManagerWithUnknownEntityName() */ public function testClearManagerWithProxyClassName() { - $proxy = $this->_em->getReference(Country::class, ['id' => rand(457, 100000)]); + $proxy = $this->_em->getReference(Country::class, ['id' => random_int(457, 100000)]); $entity = new Country(456, 'United Kingdom'); diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php index 9c8d4b7eaf2..e804a5c339e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php @@ -27,8 +27,8 @@ protected function setUp() $this->gearman = new \GearmanClient(); $this->gearman->addServer( - isset($_SERVER['GEARMAN_HOST']) ? $_SERVER['GEARMAN_HOST'] : null, - isset($_SERVER['GEARMAN_PORT']) ? $_SERVER['GEARMAN_PORT'] : 4730 + $_SERVER['GEARMAN_HOST'] ?? null, + $_SERVER['GEARMAN_PORT'] ?? 4730 ); $this->gearman->setCompleteCallback([$this, "gearmanTaskCompleted"]); diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php b/tests/Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php index c7b82f7a87d..4271b12b476 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php @@ -17,8 +17,8 @@ static public function run() $worker = new \GearmanWorker(); $worker->addServer( - isset($_SERVER['GEARMAN_HOST']) ? $_SERVER['GEARMAN_HOST'] : null, - isset($_SERVER['GEARMAN_PORT']) ? $_SERVER['GEARMAN_PORT'] : 4730 + $_SERVER['GEARMAN_HOST'] ?? null, + $_SERVER['GEARMAN_PORT'] ?? 4730 ); $worker->addFunction("findWithLock", [$lockAgent, "findWithLock"]); $worker->addFunction("dqlWithLock", [$lockAgent, "dqlWithLock"]); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1454Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1454Test.php index 86aba511372..f10065cd887 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1454Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1454Test.php @@ -55,7 +55,7 @@ class DDC1454File public function __construct() { - $this->fileId = rand(); + $this->fileId = random_int(0, getrandmax()); } /** diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 12eadbdaa82..fb95ba8bad2 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -599,7 +599,7 @@ public function testMergeWithExistingEntityWillNotPersistItNorTriggerPrePersistL $mergedEntity = new EntityWithRandomlyGeneratedField(); $mergedEntity->id = $persistedEntity->id; - $mergedEntity->generatedField = mt_rand( + $mergedEntity->generatedField = random_int( $persistedEntity->generatedField + 1, $persistedEntity->generatedField + 1000 ); @@ -915,7 +915,7 @@ class EntityWithRandomlyGeneratedField public function __construct() { $this->id = uniqid('id', true); - $this->generatedField = mt_rand(0, 100000); + $this->generatedField = random_int(0, 100000); } } From 828bfdf4aeadf3139d9fd906778b6df509e29d05 Mon Sep 17 00:00:00 2001 From: Westin Shafer Date: Thu, 7 Sep 2017 13:59:32 -0600 Subject: [PATCH 594/877] Update docs for deprecated setTableName() Updated docs to remove deprecated setTableName() and replace it with setPrimaryTable() --- docs/en/cookbook/sql-table-prefixes.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/en/cookbook/sql-table-prefixes.rst b/docs/en/cookbook/sql-table-prefixes.rst index fdfd4032f3c..5ea587986b6 100644 --- a/docs/en/cookbook/sql-table-prefixes.rst +++ b/docs/en/cookbook/sql-table-prefixes.rst @@ -41,7 +41,9 @@ appropriate autoloaders. $classMetadata = $eventArgs->getClassMetadata(); if (!$classMetadata->isInheritanceTypeSingleTable() || $classMetadata->getName() === $classMetadata->rootEntityName) { - $classMetadata->setTableName($this->prefix . $classMetadata->getTableName()); + $classMetadata->setPrimaryTable([ + 'name' => $this->prefix . $classMetadata->getTableName() + ]); } foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) { From 0c4f9a886682441628f895bda38bdbb3c1703900 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 16 Sep 2017 17:15:08 +0200 Subject: [PATCH 595/877] Clarify some assumptions the object hydration makes. --- .../en/reference/dql-doctrine-query-language.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/en/reference/dql-doctrine-query-language.rst b/docs/en/reference/dql-doctrine-query-language.rst index 8944ce66e71..3a76f761447 100644 --- a/docs/en/reference/dql-doctrine-query-language.rst +++ b/docs/en/reference/dql-doctrine-query-language.rst @@ -1160,6 +1160,22 @@ Object hydration hydrates the result set into the object graph: $query = $em->createQuery('SELECT u FROM CmsUser u'); $users = $query->getResult(Query::HYDRATE_OBJECT); +Sometimes the behavior in the object hydrator can be confusing, which is +why we are listing as many of the assumptions here for reference: + +- Objects fetched in a FROM clause are returned as a Set, that means every + object is only ever included in the resulting array once. This is the case + even when using JOIN or GROUP BY in ways that return the same row for an + object multiple times. If the hydrator sees the same object multiple times, + then it makes sure it is only returned once. + +- If an object is already in memory from a previous query of any kind, then + then the previous object is used, even if the database may contain more + recent data. Data from the database is discarded. This even happens if the + previous object is still an unloaded proxy. + +This list might be incomplete. + Array Hydration ^^^^^^^^^^^^^^^ From 059cfd86df63d78f760aed8ab36ceaec3e67380d Mon Sep 17 00:00:00 2001 From: Guilherme Lopes Date: Thu, 21 Sep 2017 10:02:43 +0200 Subject: [PATCH 596/877] Remove unnecessary else --- lib/Doctrine/ORM/Query/SqlWalker.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index dc9a56ca090..6ded65fa0b4 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -751,7 +751,8 @@ public function walkSelectClause($selectClause) foreach ($class->associationMappings as $assoc) { if ( ! ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE)) { continue; - } else if ( !$addMetaColumns && !isset($assoc['id'])) { + } + if ( !$addMetaColumns && !isset($assoc['id'])) { continue; } From 8ecddc4fc17522fabd90af585015cda83739acc7 Mon Sep 17 00:00:00 2001 From: Guilherme Lopes Date: Thu, 21 Sep 2017 10:13:19 +0200 Subject: [PATCH 597/877] Adding empty line between logic blocks --- lib/Doctrine/ORM/Query/SqlWalker.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 6ded65fa0b4..ef072f91b3d 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -752,6 +752,7 @@ public function walkSelectClause($selectClause) if ( ! ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE)) { continue; } + if ( !$addMetaColumns && !isset($assoc['id'])) { continue; } From d995203ee1c0fe1abe33982b5f43007df3e9aac8 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Thu, 21 Sep 2017 17:29:54 +0900 Subject: [PATCH 598/877] Promote nullable types from PHP 7.1 Also don't show type hinting in a bad light with sentences such as "If you insist on type-hinting" --- .../reference/working-with-associations.rst | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/docs/en/reference/working-with-associations.rst b/docs/en/reference/working-with-associations.rst index e115efbc97e..15160a79cd5 100644 --- a/docs/en/reference/working-with-associations.rst +++ b/docs/en/reference/working-with-associations.rst @@ -238,14 +238,19 @@ the database permanently. Notice how both sides of the bidirectional association are always updated. Unidirectional associations are consequently simpler to -handle. Also note that if you use type-hinting in your methods, i.e. -``setAddress(Address $address)``, PHP will only allow null -values if ``null`` is set as default value. Otherwise -setAddress(null) will fail for removing the association. If you -insist on type-hinting a typical way to deal with this is to -provide a special method, like ``removeAddress()``. This can also -provide better encapsulation as it hides the internal meaning of -not having an address. +handle. + +Also note that if you use type-hinting in your methods, i.e. +``setAddress(Address $address)``, you will have to specifically +allow null values, otherwise ``setAddress(null)`` will fail to +remove the association. Starting from PHP 7.1 you should use +nullable types by prefixing the type with a ``?``, +``setAddress(?Address $address)``. Older PHP versions will only +allow null values if ``null`` is set as default value, +``setAddress(Address $address = null)``. Yet another way to deal +with this is to provide a special method, like ``removeAddress()``. +This can also provide better encapsulation as it hides the internal +meaning of not having an address. When working with collections, keep in mind that a Collection is essentially an ordered map (just like a PHP array). That is why the @@ -396,7 +401,7 @@ There are two approaches to handle this problem in your code: 1. Ignore updating the inverse side of bidirectional collections, BUT never read from them in requests that changed their state. In - the next Request Doctrine hydrates the consistent collection state + the next request Doctrine hydrates the consistent collection state again. 2. Always keep the bidirectional collections in sync through association management methods. Reads of the Collections directly From df1250ee4b29456202de17d12d49b3304f35c9e7 Mon Sep 17 00:00:00 2001 From: Guilherme Lopes Date: Thu, 21 Sep 2017 13:42:51 +0200 Subject: [PATCH 599/877] Fix negation clause and also adding both conditions in the same if --- lib/Doctrine/ORM/Query/SqlWalker.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index ef072f91b3d..53a5c747400 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -749,11 +749,8 @@ public function walkSelectClause($selectClause) // Add foreign key columns of class and also parent classes foreach ($class->associationMappings as $assoc) { - if ( ! ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE)) { - continue; - } - - if ( !$addMetaColumns && !isset($assoc['id'])) { + if ( ! ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE) + || ( ! $addMetaColumns && !isset($assoc['id']))) { continue; } From 3d3ecc77bd9f70ebabce05f34bb90860e3c98df2 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Thu, 21 Sep 2017 21:28:19 +0900 Subject: [PATCH 600/877] Drop PHP version specifics --- docs/en/reference/working-with-associations.rst | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/docs/en/reference/working-with-associations.rst b/docs/en/reference/working-with-associations.rst index 15160a79cd5..de236cf4077 100644 --- a/docs/en/reference/working-with-associations.rst +++ b/docs/en/reference/working-with-associations.rst @@ -240,17 +240,12 @@ Notice how both sides of the bidirectional association are always updated. Unidirectional associations are consequently simpler to handle. -Also note that if you use type-hinting in your methods, i.e. -``setAddress(Address $address)``, you will have to specifically -allow null values, otherwise ``setAddress(null)`` will fail to -remove the association. Starting from PHP 7.1 you should use -nullable types by prefixing the type with a ``?``, -``setAddress(?Address $address)``. Older PHP versions will only -allow null values if ``null`` is set as default value, -``setAddress(Address $address = null)``. Yet another way to deal -with this is to provide a special method, like ``removeAddress()``. -This can also provide better encapsulation as it hides the internal -meaning of not having an address. +Also note that if you use type-hinting in your methods, you will +have to specify a nullable type, i.e. ``setAddress(?Address $address)``, +otherwise ``setAddress(null)`` will fail to remove the association. +Another way to deal with this is to provide a special method, like +``removeAddress()``. This can also provide better encapsulation as +it hides the internal meaning of not having an address. When working with collections, keep in mind that a Collection is essentially an ordered map (just like a PHP array). That is why the From a7e13f89ccdf91aa9b06bf5d4be0addf9ad2ca40 Mon Sep 17 00:00:00 2001 From: Guilherme Lopes Date: Tue, 26 Sep 2017 12:52:18 +0200 Subject: [PATCH 601/877] #6723 Remove variable from UnitOfWork#createEntity() --- lib/Doctrine/ORM/UnitOfWork.php | 35 ++++++++++----------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 7ec28064da5..56017301bf2 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -2549,7 +2549,6 @@ private function newInstance($class) public function createEntity($className, array $data, &$hints = []) { $class = $this->em->getClassMetadata($className); - //$isReadOnly = isset($hints[Query::HINT_READ_ONLY]); $id = $this->identifierFlattener->flattenIdentifier($class, $data); $idHash = implode(' ', $id); @@ -2579,28 +2578,22 @@ public function createEntity($className, array $data, &$hints = []) if ($entity instanceof Proxy && ! $entity->__isInitialized()) { $entity->__setInitialized(true); - $overrideLocalValues = true; - if ($entity instanceof NotifyPropertyChanged) { $entity->addPropertyChangedListener($this); } } else { - $overrideLocalValues = isset($hints[Query::HINT_REFRESH]); - - // If only a specific entity is set to refresh, check that it's the one - if (isset($hints[Query::HINT_REFRESH_ENTITY])) { - $overrideLocalValues = $hints[Query::HINT_REFRESH_ENTITY] === $entity; + if ( ! isset($hints[Query::HINT_REFRESH]) + || (isset($hints[Query::HINT_REFRESH_ENTITY]) && $hints[Query::HINT_REFRESH_ENTITY] !== $entity)) { + return $entity; } } - if ($overrideLocalValues) { - // inject ObjectManager upon refresh. - if ($entity instanceof ObjectManagerAware) { - $entity->injectObjectManager($this->em, $class); - } - - $this->originalEntityData[$oid] = $data; + // inject ObjectManager upon refresh. + if ($entity instanceof ObjectManagerAware) { + $entity->injectObjectManager($this->em, $class); } + + $this->originalEntityData[$oid] = $data; } else { $entity = $this->newInstance($class); $oid = spl_object_hash($entity); @@ -2614,12 +2607,6 @@ public function createEntity($className, array $data, &$hints = []) if ($entity instanceof NotifyPropertyChanged) { $entity->addPropertyChangedListener($this); } - - $overrideLocalValues = true; - } - - if ( ! $overrideLocalValues) { - return $entity; } foreach ($data as $field => $value) { @@ -2823,10 +2810,8 @@ public function createEntity($className, array $data, &$hints = []) } } - if ($overrideLocalValues) { - // defer invoking of postLoad event to hydration complete step - $this->hydrationCompleteHandler->deferPostLoadInvoking($class, $entity); - } + // defer invoking of postLoad event to hydration complete step + $this->hydrationCompleteHandler->deferPostLoadInvoking($class, $entity); return $entity; } From 4fdbdabae4d5ca3bb5b40b8176ab6e7e82999c01 Mon Sep 17 00:00:00 2001 From: Gocha Ossinkine Date: Thu, 28 Sep 2017 12:03:37 +0500 Subject: [PATCH 602/877] Add DateInterval type parameter --- composer.json | 2 +- lib/Doctrine/ORM/Query/ParameterTypeInferer.php | 4 ++++ tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php | 5 +++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index e738e05ee27..b4371aaec40 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "php": "^7.1", "ext-pdo": "*", "doctrine/collections": "^1.4", - "doctrine/dbal": ">=2.5-dev,<2.7-dev", + "doctrine/dbal": "^2.6", "doctrine/instantiator": "~1.1", "doctrine/common": "^2.7.1", "doctrine/cache": "~1.6", diff --git a/lib/Doctrine/ORM/Query/ParameterTypeInferer.php b/lib/Doctrine/ORM/Query/ParameterTypeInferer.php index 597c7e2ea07..07b78f008bd 100644 --- a/lib/Doctrine/ORM/Query/ParameterTypeInferer.php +++ b/lib/Doctrine/ORM/Query/ParameterTypeInferer.php @@ -57,6 +57,10 @@ public static function inferType($value) return Type::DATETIME; } + if ($value instanceof \DateInterval) { + return Type::DATEINTERVAL; + } + if (is_array($value)) { return is_int(current($value)) ? Connection::PARAM_INT_ARRAY diff --git a/tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php b/tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php index b929f8d18a3..35e9bf2f57e 100644 --- a/tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php +++ b/tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php @@ -13,17 +13,18 @@ class ParameterTypeInfererTest extends OrmTestCase public function providerParameterTypeInferer() { - $data = [ + $data = [ [1, Type::INTEGER], ["bar", PDO::PARAM_STR], ["1", PDO::PARAM_STR], [new \DateTime, Type::DATETIME], + [new \DateInterval('P1D'), Type::DATEINTERVAL], [[2], Connection::PARAM_INT_ARRAY], [["foo"], Connection::PARAM_STR_ARRAY], [["1","2"], Connection::PARAM_STR_ARRAY], [[], Connection::PARAM_STR_ARRAY], [true, Type::BOOLEAN], - ]; + ]; if (PHP_VERSION_ID >= 50500) { $data[] = [new \DateTimeImmutable(), Type::DATETIME]; From 19dcd629c0bb0d4f838fc331709a55e6437e21d5 Mon Sep 17 00:00:00 2001 From: Maciej Malarz Date: Tue, 3 Oct 2017 17:14:06 +0200 Subject: [PATCH 603/877] [DOCS] Emphasize that Embeddable can only contains simple fields --- docs/en/tutorials/embeddables.rst | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/en/tutorials/embeddables.rst b/docs/en/tutorials/embeddables.rst index 1dcb3c1477a..483e58d9da6 100644 --- a/docs/en/tutorials/embeddables.rst +++ b/docs/en/tutorials/embeddables.rst @@ -4,8 +4,11 @@ Separating Concerns using Embeddables Embeddables are classes which are not entities themselves, but are embedded in entities and can also be queried in DQL. You'll mostly want to use them to reduce duplication or separating concerns. Value objects such as date range -or address are the primary use case for this feature. Embeddables can only -contain properties with basic ``@Column`` mapping. +or address are the primary use case for this feature. + +.. note:: + + Embeddables can only contain properties with basic ``@Column`` mapping. For the purposes of this tutorial, we will assume that you have a ``User`` class in your application and you would like to store an address in From 2d88e45240323575b1f51ca560749d3e9b7baad3 Mon Sep 17 00:00:00 2001 From: Konstantin Kuklin Date: Wed, 4 Oct 2017 03:43:20 +0300 Subject: [PATCH 604/877] sync type of property em with constructor value --- lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php b/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php index 7d72464dc01..b654c04255f 100644 --- a/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php +++ b/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php @@ -36,7 +36,7 @@ class DefaultEntityHydrator implements EntityHydrator { /** - * @var \Doctrine\ORM\EntityManager + * @var \Doctrine\ORM\EntityManagerInterface */ private $em; From fb7a96caf9fa217d0b3b43a23de35253f6c008c6 Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Thu, 5 Oct 2017 00:27:11 +0200 Subject: [PATCH 605/877] EntityManager::getReference() can return null --- lib/Doctrine/ORM/EntityManagerInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/EntityManagerInterface.php b/lib/Doctrine/ORM/EntityManagerInterface.php index 09c7efdf9d2..3c1c580e935 100644 --- a/lib/Doctrine/ORM/EntityManagerInterface.php +++ b/lib/Doctrine/ORM/EntityManagerInterface.php @@ -150,7 +150,7 @@ public function createQueryBuilder(); * @param string $entityName The name of the entity type. * @param mixed $id The entity identifier. * - * @return object The entity reference. + * @return object|null The entity reference. * * @throws ORMException */ From 5f99cad66916664d810655e5444cac917131e2ea Mon Sep 17 00:00:00 2001 From: Jan Langer Date: Fri, 6 Oct 2017 17:18:56 +0200 Subject: [PATCH 606/877] Failing test - inverse side OneToOne loaded without identifier condition --- ...eToOneInverseSideLoadAfterDqlQueryTest.php | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/OneToOneInverseSideLoadAfterDqlQueryTest.php diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneInverseSideLoadAfterDqlQueryTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneInverseSideLoadAfterDqlQueryTest.php new file mode 100644 index 00000000000..34439c373dc --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneInverseSideLoadAfterDqlQueryTest.php @@ -0,0 +1,109 @@ +_em); + try { + $schemaTool->createSchema( + [ + $this->_em->getClassMetadata(Bus::class), + $this->_em->getClassMetadata(BusOwner::class), + ] + ); + } catch(\Exception $e) {} + } + + public function testInverseSideOneToOneLoadedAfterDqlQuery(): void + { + $owner = new BusOwner('Alexander'); + $bus = new Bus($owner); + + $this->_em->persist($bus); + $this->_em->flush(); + $this->_em->clear(); + + $bus = $this->_em->createQueryBuilder() + ->select('to') + ->from(BusOwner::class, 'to') + ->andWhere('to.id = :id') + ->setParameter('id', $owner->id) + ->getQuery() + ->getResult(); + + $this->assertSQLEquals( + "SELECT b0_.id AS id_0, b0_.name AS name_1 FROM BusOwner b0_ WHERE b0_.id = ?", + $this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery - 1]['sql'] + ); + + $this->assertSQLEquals( + "SELECT t0.id AS id_1, t0.owner AS owner_2 FROM Bus t0 WHERE t0.owner = ?", + $this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['sql'] + ); + } + +} + + +/** + * @Entity + */ +class Bus +{ + /** + * @id @column(type="integer") @generatedValue + * @var int + */ + public $id; + /** + * Owning side + * @OneToOne(targetEntity="BusOwner", inversedBy="bus", cascade={"persist"}) + * @JoinColumn(nullable=false, name="owner") + */ + public $owner; + + public function __construct(BusOwner $owner) + { + $this->owner = $owner; + } + +} + +/** + * @Entity + */ +class BusOwner +{ + /** + * @Id + * @Column(type="integer") + * @GeneratedValue + */ + public $id; + + /** @column(type="string") */ + public $name; + /** + * Inverse side + * @OneToOne(targetEntity="Bus", mappedBy="owner") + */ + public $bus; + + public function __construct($name) + { + $this->name = $name; + } + + public function setBus(Bus $t) + { + $this->bus = $t; + } +} From 6ba2d1c3175ec205091968a5158f3ab2a954905a Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 7 Oct 2017 10:09:44 +0200 Subject: [PATCH 607/877] #6759 cleaning up test case body --- ...eToOneInverseSideLoadAfterDqlQueryTest.php | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneInverseSideLoadAfterDqlQueryTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneInverseSideLoadAfterDqlQueryTest.php index 34439c373dc..8bfadc31272 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneInverseSideLoadAfterDqlQueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneInverseSideLoadAfterDqlQueryTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\ORM\Tools\SchemaTool; +use Doctrine\ORM\Tools\ToolsException; use Doctrine\Tests\OrmFunctionalTestCase; class OneToOneInverseSideLoadAfterDqlQueryTest extends OrmFunctionalTestCase @@ -11,15 +12,15 @@ class OneToOneInverseSideLoadAfterDqlQueryTest extends OrmFunctionalTestCase protected function setUp() { parent::setUp(); - $schemaTool = new SchemaTool($this->_em); + try { - $schemaTool->createSchema( - [ - $this->_em->getClassMetadata(Bus::class), - $this->_em->getClassMetadata(BusOwner::class), - ] - ); - } catch(\Exception $e) {} + $this->_schemaTool->createSchema([ + $this->_em->getClassMetadata(Bus::class), + $this->_em->getClassMetadata(BusOwner::class), + ]); + } catch(ToolsException $e) { + // ignored + } } public function testInverseSideOneToOneLoadedAfterDqlQuery(): void @@ -31,7 +32,9 @@ public function testInverseSideOneToOneLoadedAfterDqlQuery(): void $this->_em->flush(); $this->_em->clear(); - $bus = $this->_em->createQueryBuilder() + $bus = $this + ->_em + ->createQueryBuilder() ->select('to') ->from(BusOwner::class, 'to') ->andWhere('to.id = :id') @@ -40,12 +43,12 @@ public function testInverseSideOneToOneLoadedAfterDqlQuery(): void ->getResult(); $this->assertSQLEquals( - "SELECT b0_.id AS id_0, b0_.name AS name_1 FROM BusOwner b0_ WHERE b0_.id = ?", + 'SELECT b0_.id AS id_0, b0_.name AS name_1 FROM BusOwner b0_ WHERE b0_.id = ?', $this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery - 1]['sql'] ); $this->assertSQLEquals( - "SELECT t0.id AS id_1, t0.owner AS owner_2 FROM Bus t0 WHERE t0.owner = ?", + 'SELECT t0.id AS id_1, t0.owner AS owner_2 FROM Bus t0 WHERE t0.owner = ?', $this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['sql'] ); } From d831f4fd9f963a1c88da171d86a9dca675ef43d6 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 7 Oct 2017 12:48:19 +0200 Subject: [PATCH 608/877] #6759 segregating test models into their own namespace --- .../OneToOneInverseSideLoad/InverseSide.php | 26 +++++++++++++++++ .../OneToOneInverseSideLoad/OwningSide.php | 29 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 tests/Doctrine/Tests/Models/OneToOneInverseSideLoad/InverseSide.php create mode 100644 tests/Doctrine/Tests/Models/OneToOneInverseSideLoad/OwningSide.php diff --git a/tests/Doctrine/Tests/Models/OneToOneInverseSideLoad/InverseSide.php b/tests/Doctrine/Tests/Models/OneToOneInverseSideLoad/InverseSide.php new file mode 100644 index 00000000000..1b7d844b270 --- /dev/null +++ b/tests/Doctrine/Tests/Models/OneToOneInverseSideLoad/InverseSide.php @@ -0,0 +1,26 @@ + Date: Sat, 7 Oct 2017 12:52:34 +0200 Subject: [PATCH 609/877] #6759 cleaning up test case, using new models from the isolated namespace --- ...eToOneInverseSideLoadAfterDqlQueryTest.php | 102 ++++++------------ 1 file changed, 30 insertions(+), 72 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneInverseSideLoadAfterDqlQueryTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneInverseSideLoadAfterDqlQueryTest.php index 8bfadc31272..77cb937f429 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneInverseSideLoadAfterDqlQueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneInverseSideLoadAfterDqlQueryTest.php @@ -1,112 +1,70 @@ _schemaTool->createSchema([ - $this->_em->getClassMetadata(Bus::class), - $this->_em->getClassMetadata(BusOwner::class), + $this->_em->getClassMetadata(OwningSide::class), + $this->_em->getClassMetadata(InverseSide::class), ]); } catch(ToolsException $e) { // ignored } } + /** + * @group #6759 + */ public function testInverseSideOneToOneLoadedAfterDqlQuery(): void { - $owner = new BusOwner('Alexander'); - $bus = new Bus($owner); + $owner = new OwningSide(); + $inverse = new InverseSide(); + + $owner->id = 'owner'; + $inverse->id = 'inverse'; + $owner->inverse = $inverse; + $inverse->owning = $owner; - $this->_em->persist($bus); + $this->_em->persist($owner); + $this->_em->persist($inverse); $this->_em->flush(); $this->_em->clear(); - $bus = $this + /* @var $fetchedInverse InverseSide */ + $fetchedInverse = $this ->_em ->createQueryBuilder() - ->select('to') - ->from(BusOwner::class, 'to') - ->andWhere('to.id = :id') - ->setParameter('id', $owner->id) + ->select('inverse') + ->from(InverseSide::class, 'inverse') + ->andWhere('inverse.id = :id') + ->setParameter('id', 'inverse') ->getQuery() - ->getResult(); + ->getSingleResult(); + + self::assertInstanceOf(InverseSide::class, $fetchedInverse); + self::assertInstanceOf(OwningSide::class, $fetchedInverse->owning); $this->assertSQLEquals( - 'SELECT b0_.id AS id_0, b0_.name AS name_1 FROM BusOwner b0_ WHERE b0_.id = ?', + 'select o0_.id as id_0 from one_to_one_inverse_side_load_inverse o0_ where o0_.id = ?', $this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery - 1]['sql'] ); $this->assertSQLEquals( - 'SELECT t0.id AS id_1, t0.owner AS owner_2 FROM Bus t0 WHERE t0.owner = ?', + 'select t0.id as id_1, t0.inverse as inverse_2 from one_to_one_inverse_side_load_owning t0 WHERE t0.inverse = ?', $this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['sql'] ); } - -} - - -/** - * @Entity - */ -class Bus -{ - /** - * @id @column(type="integer") @generatedValue - * @var int - */ - public $id; - /** - * Owning side - * @OneToOne(targetEntity="BusOwner", inversedBy="bus", cascade={"persist"}) - * @JoinColumn(nullable=false, name="owner") - */ - public $owner; - - public function __construct(BusOwner $owner) - { - $this->owner = $owner; - } - -} - -/** - * @Entity - */ -class BusOwner -{ - /** - * @Id - * @Column(type="integer") - * @GeneratedValue - */ - public $id; - - /** @column(type="string") */ - public $name; - /** - * Inverse side - * @OneToOne(targetEntity="Bus", mappedBy="owner") - */ - public $bus; - - public function __construct($name) - { - $this->name = $name; - } - - public function setBus(Bus $t) - { - $this->bus = $t; - } } From dd12ba88ee8fb43222e1dac73c93d5f768254c2d Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 7 Oct 2017 12:54:36 +0200 Subject: [PATCH 610/877] #6759 avoiding reuse of the `$identifier` variable when constructing an identifier from the owning side value Fixes #6759 --- .../ORM/Persisters/Entity/BasicEntityPersister.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index b9fb045e93f..6490d0bae3f 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -792,6 +792,8 @@ public function loadOneToOneEntity(array $assoc, $sourceEntity, array $identifie $sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']); $owningAssoc = $targetClass->getAssociationMapping($assoc['mappedBy']); + $computedIdentifier = []; + // TRICKY: since the association is specular source and target are flipped foreach ($owningAssoc['targetToSourceKeyColumns'] as $sourceKeyColumn => $targetKeyColumn) { if ( ! isset($sourceClass->fieldNames[$sourceKeyColumn])) { @@ -802,13 +804,11 @@ public function loadOneToOneEntity(array $assoc, $sourceEntity, array $identifie // unset the old value and set the new sql aliased value here. By definition // unset($identifier[$targetKeyColumn] works here with how UnitOfWork::createEntity() calls this method. - $identifier[$targetClass->getFieldForColumn($targetKeyColumn)] = + $computedIdentifier[$targetClass->getFieldForColumn($targetKeyColumn)] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity); - - unset($identifier[$targetKeyColumn]); } - $targetEntity = $this->load($identifier, null, $assoc); + $targetEntity = $this->load($computedIdentifier, null, $assoc); if ($targetEntity !== null) { $targetClass->setFieldValue($targetEntity, $assoc['mappedBy'], $sourceEntity); From 3dd7eb58888eb44d56de81f8fde284cd9f3dc64e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 8 Oct 2017 10:57:33 +0200 Subject: [PATCH 611/877] #6759 removing outdated comment as per @alcaeus' review Ref: https://github.com/doctrine/doctrine2/pull/6760#discussion_r143347881 --- lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 6490d0bae3f..6152c417688 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -802,8 +802,6 @@ public function loadOneToOneEntity(array $assoc, $sourceEntity, array $identifie ); } - // unset the old value and set the new sql aliased value here. By definition - // unset($identifier[$targetKeyColumn] works here with how UnitOfWork::createEntity() calls this method. $computedIdentifier[$targetClass->getFieldForColumn($targetKeyColumn)] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity); } From 66f903a38fe369d8032626167fff7c7df2ba2294 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 8 Oct 2017 14:26:45 +0200 Subject: [PATCH 612/877] #6759 remove `#` symbol from `@group` annotation as per @lcobucci's review Ref: https://github.com/doctrine/doctrine2/pull/6760#discussion_r143353225 --- .../ORM/Functional/OneToOneInverseSideLoadAfterDqlQueryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneInverseSideLoadAfterDqlQueryTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneInverseSideLoadAfterDqlQueryTest.php index 77cb937f429..85e518efa78 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneInverseSideLoadAfterDqlQueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneInverseSideLoadAfterDqlQueryTest.php @@ -26,7 +26,7 @@ protected function setUp() } /** - * @group #6759 + * @group 6759 */ public function testInverseSideOneToOneLoadedAfterDqlQuery(): void { From b1466e6d3eb98be74ec1cf66531dcfc9243136ce Mon Sep 17 00:00:00 2001 From: Alessandro Minoccheri Date: Wed, 11 Oct 2017 17:04:29 +0200 Subject: [PATCH 613/877] fixed little typo inside documentation --- docs/en/reference/dql-doctrine-query-language.rst | 2 +- docs/en/reference/inheritance-mapping.rst | 2 +- docs/en/reference/native-sql.rst | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/en/reference/dql-doctrine-query-language.rst b/docs/en/reference/dql-doctrine-query-language.rst index 8944ce66e71..0b0cad658e0 100644 --- a/docs/en/reference/dql-doctrine-query-language.rst +++ b/docs/en/reference/dql-doctrine-query-language.rst @@ -2,7 +2,7 @@ Doctrine Query Language =========================== DQL stands for Doctrine Query Language and is an Object -Query Language derivate that is very similar to the Hibernate +Query Language derivative that is very similar to the Hibernate Query Language (HQL) or the Java Persistence Query Language (JPQL). In essence, DQL provides powerful querying capabilities over your diff --git a/docs/en/reference/inheritance-mapping.rst b/docs/en/reference/inheritance-mapping.rst index 2063624fe91..d489b30b6db 100644 --- a/docs/en/reference/inheritance-mapping.rst +++ b/docs/en/reference/inheritance-mapping.rst @@ -159,7 +159,7 @@ This strategy is very efficient for querying across all types in the hierarchy or for specific types. No table joins are required, only a WHERE clause listing the type identifiers. In particular, relationships involving types that employ this mapping strategy are -very performant. +very performing. There is a general performance consideration with Single Table Inheritance: If the target-entity of a many-to-one or one-to-one diff --git a/docs/en/reference/native-sql.rst b/docs/en/reference/native-sql.rst index 75231b7a99b..fe633aea655 100644 --- a/docs/en/reference/native-sql.rst +++ b/docs/en/reference/native-sql.rst @@ -63,7 +63,7 @@ This has several benefits: - The API is much simpler than the usual ``ResultSetMapping`` API. One downside is that the builder API does not yet support entities -with inheritance hierachies. +with inheritance hierarchies. .. code-block:: php From 436b15e873a0749bd02989de7e5c9de4fceb08d3 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Wed, 11 Oct 2017 22:45:42 +0200 Subject: [PATCH 614/877] Moved explanation out of PHP-Codeblock... ...to make it visible for XML and YML too. --- docs/en/reference/association-mapping.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/en/reference/association-mapping.rst b/docs/en/reference/association-mapping.rst index fd791a0f386..faae8d55187 100644 --- a/docs/en/reference/association-mapping.rst +++ b/docs/en/reference/association-mapping.rst @@ -33,7 +33,7 @@ inverse sides of associations ` Many-To-One, Unidirectional --------------------------- -A many-to-one association is the most common association between objects. +A many-to-one association is the most common association between objects. Example: Many Users have One Address: .. configuration-block:: @@ -46,7 +46,6 @@ A many-to-one association is the most common association between objects. // ... /** - * Many Users have One Address. * @ManyToOne(targetEntity="Address") * @JoinColumn(name="address_id", referencedColumnName="id") */ From d56044966186681001c834740d34960163b09f22 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Wed, 11 Oct 2017 22:50:32 +0200 Subject: [PATCH 615/877] Minor formating --- docs/en/reference/association-mapping.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/association-mapping.rst b/docs/en/reference/association-mapping.rst index faae8d55187..bdb12b706f0 100644 --- a/docs/en/reference/association-mapping.rst +++ b/docs/en/reference/association-mapping.rst @@ -795,7 +795,7 @@ Take an example of two entities ``Article`` and ``Tag``. Whenever you want to connect an Article to a Tag and vice-versa, it is mostly the Article that is responsible for this relation. Whenever you add a new article, you want to connect it with existing or new -tags. Your create Article form will probably support this notion +tags. Your "Create Article" form will probably support this notion and allow specifying the tags directly. This is why you should pick the Article as owning side, as it makes the code more understandable: From 2a865177b97af267af69c891f0951307ebfec169 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Fri, 13 Oct 2017 16:38:02 +0200 Subject: [PATCH 616/877] Disallow orphan removal attribute on many-to-one It only makes sense for collections, and there is no collection here. Plus the docs do not say it is supported. See http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/working-with-associations.html#orphan-removal --- doctrine-mapping.xsd | 1 - 1 file changed, 1 deletion(-) diff --git a/doctrine-mapping.xsd b/doctrine-mapping.xsd index 3d6e3457f94..86b3dd1ed95 100644 --- a/doctrine-mapping.xsd +++ b/doctrine-mapping.xsd @@ -540,7 +540,6 @@ - From 30fccf8e8346b61f8fa91deba605dc80411c3324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Fri, 13 Oct 2017 22:24:08 +0200 Subject: [PATCH 617/877] Proove orphan-removal on many-to-one is useless --- .../Models/OrnementalOrphanRemoval/Person.php | 8 ++ .../OrnementalOrphanRemoval/PhoneNumber.php | 11 +++ .../Functional/ManyToOneOrphanRemovalTest.php | 83 +++++++++++++++++++ ...els.OrnementalOrphanRemoval.Person.dcm.xml | 12 +++ ...rnementalOrphanRemoval.PhoneNumber.dcm.xml | 13 +++ .../Doctrine/Tests/OrmFunctionalTestCase.php | 13 ++- 6 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 tests/Doctrine/Tests/Models/OrnementalOrphanRemoval/Person.php create mode 100644 tests/Doctrine/Tests/Models/OrnementalOrphanRemoval/PhoneNumber.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/ManyToOneOrphanRemovalTest.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.Person.dcm.xml create mode 100644 tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.PhoneNumber.dcm.xml diff --git a/tests/Doctrine/Tests/Models/OrnementalOrphanRemoval/Person.php b/tests/Doctrine/Tests/Models/OrnementalOrphanRemoval/Person.php new file mode 100644 index 00000000000..68904001d0c --- /dev/null +++ b/tests/Doctrine/Tests/Models/OrnementalOrphanRemoval/Person.php @@ -0,0 +1,8 @@ + [ + Person::class, + PhoneNumber::class, + ] + ]; + + protected function setUp() + { + $this->useModelSet('ornemental_orphan_removal'); + + parent::setUp(); + + $person = new Person; + + $phone1 = new PhoneNumber; + $phone1->phonenumber = '123456'; + + $phone2 = new PhoneNumber; + $phone2->phonenumber = '234567'; + + $phone1->person = $person; + $phone2->person = $person; + + $this->_em->persist($phone1); + $this->_em->persist($phone2); + $this->_em->persist($person); + $this->_em->flush(); + + $this->personId = $person->id; + $this->_em->clear(); + } + + public function testOrphanRemovalIsPurelyOrnemental() + { + $person = $this->_em->getReference(Person::class, $this->personId); + + $this->_em->remove($person); + $this->_em->flush(); + $this->_em->clear(); + + $query = $this->_em->createQuery( + 'SELECT u FROM Doctrine\Tests\Models\OrnementalOrphanRemoval\Person u' + ); + $result = $query->getResult(); + + $this->assertEquals(0, count($result), 'Person should be removed by EntityManager'); + + $query = $this->_em->createQuery( + 'SELECT p FROM Doctrine\Tests\Models\OrnementalOrphanRemoval\PhoneNumber p' + ); + $result = $query->getResult(); + + $this->assertEquals(2, count($result), 'Orphan removal should not kick in'); + } + + protected function _getEntityManager( + Connection $connection = null, + MappingDriver $mappingDriver = null + ) { + return parent::_getEntityManager($connection, new XmlDriver( + __DIR__.DIRECTORY_SEPARATOR.'xml' + )); + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.Person.dcm.xml b/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.Person.dcm.xml new file mode 100644 index 00000000000..feb77552acc --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.Person.dcm.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.PhoneNumber.dcm.xml b/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.PhoneNumber.dcm.xml new file mode 100644 index 00000000000..a9eb1eee6a9 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.PhoneNumber.dcm.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index e9299b1c685..d45ebac6387 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests; use Doctrine\Common\Cache\ArrayCache; +use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Driver\PDOSqlite\Driver as SqliteDriver; use Doctrine\DBAL\Logging\DebugStack; @@ -488,6 +489,11 @@ protected function tearDown() $conn->executeUpdate('DELETE FROM ddc3346_users'); } + if (isset($this->_usedModelSets['ornemental_orphan_removal'])) { + $conn->executeUpdate('DELETE FROM ornemental_orphan_removal_person'); + $conn->executeUpdate('DELETE FROM ornemental_orphan_removal_phone_number'); + } + if (isset($this->_usedModelSets['quote'])) { $conn->executeUpdate( sprintf( @@ -678,7 +684,10 @@ protected function setUp() * * @throws \Doctrine\ORM\ORMException */ - protected function _getEntityManager(Connection $connection = null) { + protected function _getEntityManager( + Connection $connection = null, + MappingDriver $mappingDriver = null + ) { // NOTE: Functional tests use their own shared metadata cache, because // the actual database platform used during execution has effect on some // metadata mapping behaviors (like the choice of the ID generation). @@ -732,7 +741,7 @@ protected function _getEntityManager(Connection $connection = null) { } $config->setMetadataDriverImpl( - $config->newDefaultAnnotationDriver( + $mappingDriver ?? $config->newDefaultAnnotationDriver( [ realpath(__DIR__ . '/Models/Cache'), realpath(__DIR__ . '/Models/GeoNames') From 6b5c97055c07728cf0dec816e9c6b3cbf4a22bf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 14 Oct 2017 11:03:52 +0200 Subject: [PATCH 618/877] Set null on delete, at database level --- ...e.Tests.Models.OrnementalOrphanRemoval.PhoneNumber.dcm.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.PhoneNumber.dcm.xml b/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.PhoneNumber.dcm.xml index a9eb1eee6a9..87168315c4f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.PhoneNumber.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.PhoneNumber.dcm.xml @@ -8,6 +8,8 @@ - + + + From 57e9feffb29b6b80fa4cd5ecd3cba5d80e96e96f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 14 Oct 2017 11:11:58 +0200 Subject: [PATCH 619/877] Avoid uuid generation pg needs an extra module to do this, so let's spare us that and set them manually. --- .../Tests/ORM/Functional/ManyToOneOrphanRemovalTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToOneOrphanRemovalTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToOneOrphanRemovalTest.php index 4fbb51cb15d..36039b2b2a3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToOneOrphanRemovalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToOneOrphanRemovalTest.php @@ -30,11 +30,14 @@ protected function setUp() parent::setUp(); $person = new Person; + $person->id = 'ca41a293-799f-4d68-bf79-626c3ad223ec'; $phone1 = new PhoneNumber; + $phone1->id = 'f4132478-c492-4dfe-aab5-a5b79ae129e7'; $phone1->phonenumber = '123456'; $phone2 = new PhoneNumber; + $phone2->id = '7faa4cd3-a155-4fbf-bc42-aa4269a4454d'; $phone2->phonenumber = '234567'; $phone1->person = $person; From ffd3d34f34b324f732e8b36736b27dcf868db7d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 14 Oct 2017 11:25:09 +0200 Subject: [PATCH 620/877] Disable uuid generation Apparently, setting a value by hand is not enough to avoid it. --- ...Doctrine.Tests.Models.OrnementalOrphanRemoval.Person.dcm.xml | 2 +- ...ine.Tests.Models.OrnementalOrphanRemoval.PhoneNumber.dcm.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.Person.dcm.xml b/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.Person.dcm.xml index feb77552acc..6d151af12f8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.Person.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.Person.dcm.xml @@ -6,7 +6,7 @@ https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd"> - + diff --git a/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.PhoneNumber.dcm.xml b/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.PhoneNumber.dcm.xml index 87168315c4f..2e404254a53 100644 --- a/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.PhoneNumber.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.PhoneNumber.dcm.xml @@ -6,7 +6,7 @@ https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd"> - + From 0bea6881da52840c650e8fea59a028018f4fcb0e Mon Sep 17 00:00:00 2001 From: Stefan Petcu Date: Tue, 17 Oct 2017 19:21:34 +0200 Subject: [PATCH 621/877] Clarify docs for embedded and embeddable. --- docs/en/reference/annotations-reference.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/en/reference/annotations-reference.rst b/docs/en/reference/annotations-reference.rst index 0ff926144f9..ed40dbdb1b2 100644 --- a/docs/en/reference/annotations-reference.rst +++ b/docs/en/reference/annotations-reference.rst @@ -318,9 +318,9 @@ depending on whether the classes are in the namespace or not. @Embeddable ~~~~~~~~~~~~~~~~~~~~~ -The embeddable is required on an entity targeted to be embeddable inside -another. It works together with the :ref:`@Embedded ` -annotation to establish the relationship between two entities. +The embeddable annotation is required on a class, in order to make it +embeddable inside an entity. It works together with the :ref:`@Embedded ` +annotation to establish the relationship between the two classes. .. code-block:: php @@ -345,8 +345,8 @@ annotation to establish the relationship between two entities. @Embedded ~~~~~~~~~~~~~~~~~~~~~ -The embedded annotation is required on a member class varible targed to -embed it's class argument inside it's own class. +The embedded annotation is required on an entity's member variable, +in order to specify that it is an embedded class. Required attributes: From 99db207a9f1214ad483efd81341279a550526358 Mon Sep 17 00:00:00 2001 From: Aaron Scherer Date: Wed, 18 Oct 2017 19:10:00 -0700 Subject: [PATCH 622/877] getRepository actually returns ObjectRepository --- lib/Doctrine/ORM/EntityManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 83950534554..38c90bc5445 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -709,7 +709,7 @@ public function lock($entity, $lockMode, $lockVersion = null) * * @param string $entityName The name of the entity. * - * @return \Doctrine\ORM\EntityRepository The repository class. + * @return \Doctrine\Common\Persistence\ObjectRepository|\Doctrine\ORM\EntityRepository The repository class. */ public function getRepository($entityName) { From 620319f206978441a85033157c86fffef39bfd30 Mon Sep 17 00:00:00 2001 From: Mateusz Sip Date: Tue, 24 Oct 2017 01:50:58 +0200 Subject: [PATCH 623/877] Type::convertToDatabaseValue is always called --- docs/en/cookbook/custom-mapping-types.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/en/cookbook/custom-mapping-types.rst b/docs/en/cookbook/custom-mapping-types.rst index 1bd4f124215..d9e38560c6c 100644 --- a/docs/en/cookbook/custom-mapping-types.rst +++ b/docs/en/cookbook/custom-mapping-types.rst @@ -49,8 +49,6 @@ you wish. Here is an example skeleton of such a custom type class: The following assumptions are applied to mapping types by the ORM: - - If the value of the field is *NULL* the method - ``convertToDatabaseValue()`` is not called. - The ``UnitOfWork`` never passes values to the database convert method that did not change in the request. - The ``UnitOfWork`` internally assumes that entity identifiers are From 302c3a6640d57ab86df61b63e2581a31b2c5a557 Mon Sep 17 00:00:00 2001 From: Erik Johansson Date: Sun, 29 Oct 2017 00:26:25 +0300 Subject: [PATCH 624/877] Fix some grammar and outdated information in docs --- .../working-with-indexed-associations.rst | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/docs/en/tutorials/working-with-indexed-associations.rst b/docs/en/tutorials/working-with-indexed-associations.rst index 3536a34f8ee..a62d8b34209 100644 --- a/docs/en/tutorials/working-with-indexed-associations.rst +++ b/docs/en/tutorials/working-with-indexed-associations.rst @@ -3,7 +3,7 @@ Working with Indexed Associations .. note:: - This feature is scheduled for version 2.1 of Doctrine and not included in the 2.0.x series. + This feature is available from version 2.1 of Doctrine. Doctrine 2 collections are modelled after PHPs native arrays. PHP arrays are an ordered hashmap, but in the first version of Doctrine keys retrieved from the database were always numerical unless ``INDEX BY`` @@ -13,8 +13,8 @@ The feature works like an implicit ``INDEX BY`` for the selected association but downsides also: - You have to manage both the key and field if you want to change the index by field value. -- On each request the keys are regenerated from the field value not from the previous collection key. -- Values of the Index-By keys are never considered during persistence, it only exists for accessing purposes. +- On each request the keys are regenerated from the field value, and not from the previous collection key. +- Values of the Index-By keys are never considered during persistence. They only exist for accessing purposes. - Fields that are used for the index by feature **HAVE** to be unique in the database. The behavior for multiple entities with the same index-by field value is undefined. @@ -164,8 +164,6 @@ here are the code and mappings for it: private $id; /** - * For real this column would have to be unique=true. But I want to test behavior of non-unique overrides. - * * @Column(type="string", unique=true) */ private $symbol; @@ -227,7 +225,7 @@ here are the code and mappings for it: Querying indexed associations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Now that we defined the stocks collection to be indexed by symbol we can take a look at some code, +Now that we defined the stocks collection to be indexed by symbol, we can take a look at some code that makes use of the indexing. First we will populate our database with two example stocks traded on a single market: @@ -263,7 +261,7 @@ now query for the market: echo $stock->getSymbol(); // will print "AAPL" -The implementation ``Market::addStock()`` in combination with ``indexBy`` allows to access the collection +The implementation of ``Market::addStock()``, in combination with ``indexBy``, allows us to access the collection consistently by the Stock symbol. It does not matter if Stock is managed by Doctrine or not. The same applies to DQL queries: The ``indexBy`` configuration acts as implicit "INDEX BY" to a join association. @@ -285,8 +283,8 @@ The same applies to DQL queries: The ``indexBy`` configuration acts as implicit echo $stock->getSymbol(); // will print "AAPL" -If you want to use ``INDEX BY`` explicitly on an indexed association you are free to do so. Additionally -indexed associations also work with the ``Collection::slice()`` functionality, no matter if marked as +If you want to use ``INDEX BY`` explicitly on an indexed association you are free to do so. Additionally, +indexed associations also work with the ``Collection::slice()`` functionality, even if the association's fetch mode is LAZY or EXTRA_LAZY. Outlook into the Future @@ -294,5 +292,5 @@ Outlook into the Future For the inverse side of a many-to-many associations there will be a way to persist the keys and the order as a third and fourth parameter into the join table. This feature is discussed in `DDC-213 `_ -This feature cannot be implemented for One-To-Many associations, because they are never the owning side. +This feature cannot be implemented for one-to-many associations, because they are never the owning side. From f277eef6eab0fdac4e1085eecd8ebd9ece2b610e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20L=C3=A9v=C3=AAque?= Date: Mon, 2 Oct 2017 12:03:26 +0200 Subject: [PATCH 625/877] Add support second, minute, week, year on DATE_ADD and DATE_SUB --- .../Query/AST/Functions/DateAddFunction.php | 19 ++++++++-- .../Query/AST/Functions/DateSubFunction.php | 23 ++++++++++-- .../ORM/Functional/QueryDqlFunctionTest.php | 36 +++++++++++++++++++ 3 files changed, 73 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/Query/AST/Functions/DateAddFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/DateAddFunction.php index 859426f0801..edec7f9874a 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/DateAddFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/DateAddFunction.php @@ -51,7 +51,11 @@ public function getSql(SqlWalker $sqlWalker) $this->firstDateExpression->dispatch($sqlWalker), $this->intervalExpression->dispatch($sqlWalker) ); - + case 'minute': + return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddMinutesExpression( + $this->firstDateExpression->dispatch($sqlWalker), + $this->intervalExpression->dispatch($sqlWalker) + ); case 'hour': return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddHourExpression( $this->firstDateExpression->dispatch($sqlWalker), @@ -62,16 +66,25 @@ public function getSql(SqlWalker $sqlWalker) $this->firstDateExpression->dispatch($sqlWalker), $this->intervalExpression->dispatch($sqlWalker) ); - + case 'week': + return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddWeeksExpression( + $this->firstDateExpression->dispatch($sqlWalker), + $this->intervalExpression->dispatch($sqlWalker) + ); case 'month': return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddMonthExpression( $this->firstDateExpression->dispatch($sqlWalker), $this->intervalExpression->dispatch($sqlWalker) ); + case 'year': + return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddYearsExpression( + $this->firstDateExpression->dispatch($sqlWalker), + $this->intervalExpression->dispatch($sqlWalker) + ); default: throw QueryException::semanticalError( - 'DATE_ADD() only supports units of type second, hour, day and month.' + 'DATE_ADD() only supports units of type second, minute, hour, day, week, month and year.' ); } } diff --git a/lib/Doctrine/ORM/Query/AST/Functions/DateSubFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/DateSubFunction.php index a6415a2863e..8dcc1353719 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/DateSubFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/DateSubFunction.php @@ -40,6 +40,16 @@ class DateSubFunction extends DateAddFunction public function getSql(SqlWalker $sqlWalker) { switch (strtolower($this->unit->value)) { + case 'second': + return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubSecondsExpression( + $this->firstDateExpression->dispatch($sqlWalker), + $this->intervalExpression->dispatch($sqlWalker) + ); + case 'minute': + return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubMinutesExpression( + $this->firstDateExpression->dispatch($sqlWalker), + $this->intervalExpression->dispatch($sqlWalker) + ); case 'hour': return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubHourExpression( $this->firstDateExpression->dispatch($sqlWalker), @@ -50,16 +60,25 @@ public function getSql(SqlWalker $sqlWalker) $this->firstDateExpression->dispatch($sqlWalker), $this->intervalExpression->dispatch($sqlWalker) ); - + case 'week': + return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubWeeksExpression( + $this->firstDateExpression->dispatch($sqlWalker), + $this->intervalExpression->dispatch($sqlWalker) + ); case 'month': return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubMonthExpression( $this->firstDateExpression->dispatch($sqlWalker), $this->intervalExpression->dispatch($sqlWalker) ); + case 'year': + return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubYearsExpression( + $this->firstDateExpression->dispatch($sqlWalker), + $this->intervalExpression->dispatch($sqlWalker) + ); default: throw QueryException::semanticalError( - 'DATE_SUB() only supports units of type hour, day and month.' + 'DATE_SUB() only supports units of type second, minute, hour, day, week, month and year.' ); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php index 764b213dde2..319612138d9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php @@ -301,6 +301,24 @@ public function testDateAdd() $this->assertTrue(strtotime($arg[0]['add']) > 0); } + /** + * @group DDC-2938 + */ + public function testDateAddTime(): void + { + $arg = $this->_em->createQuery("SELECT DATE_ADD(CURRENT_TIMESTAMP(), 10, 'second') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m") + ->getArrayResult(); + self::assertTrue(strtotime($arg[0]['add']) > 0); + + $arg = $this->_em->createQuery("SELECT DATE_ADD(CURRENT_TIMESTAMP(), 10, 'minute') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m") + ->getArrayResult(); + self::assertTrue(strtotime($arg[0]['add']) > 0); + + $arg = $this->_em->createQuery("SELECT DATE_ADD(CURRENT_TIMESTAMP(), 10, 'hour') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m") + ->getArrayResult(); + self::assertTrue(strtotime($arg[0]['add']) > 0); + } + public function testDateAddSecond() { $dql = "SELECT CURRENT_TIMESTAMP() now, DATE_ADD(CURRENT_TIMESTAMP(), 10, 'second') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m"; @@ -334,6 +352,24 @@ public function testDateSub() $this->assertTrue(strtotime($arg[0]['add']) > 0); } + /** + * @group DDC-2938 + */ + public function testDateSubTime(): void + { + $arg = $this->_em->createQuery("SELECT DATE_SUB(CURRENT_TIMESTAMP(), 10, 'second') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m") + ->getArrayResult(); + self::assertTrue(strtotime($arg[0]['add']) > 0); + + $arg = $this->_em->createQuery("SELECT DATE_SUB(CURRENT_TIMESTAMP(), 10, 'minute') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m") + ->getArrayResult(); + self::assertTrue(strtotime($arg[0]['add']) > 0); + + $arg = $this->_em->createQuery("SELECT DATE_SUB(CURRENT_TIMESTAMP(), 10, 'hour') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m") + ->getArrayResult(); + self::assertTrue(strtotime($arg[0]['add']) > 0); + } + /** * @group DDC-1213 */ From 59792654c0fd37bb974efa35d63328be36e59ead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Mon, 30 Oct 2017 21:29:08 +0100 Subject: [PATCH 626/877] Improve tests for DATE_ADD and DATE_SUB So that we can do proper assertions and cover all the possibilities of the functions. --- .../ORM/Functional/QueryDqlFunctionTest.php | 110 ++++++++---------- 1 file changed, 47 insertions(+), 63 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php index 319612138d9..6c415206923 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\ORM\AbstractQuery; use Doctrine\Tests\Models\Company\CompanyManager; use Doctrine\Tests\OrmFunctionalTestCase; @@ -176,7 +177,7 @@ public function testFunctionSubstring() $this->assertEquals('Gui', $result[1]['str1']); $this->assertEquals('Jon', $result[2]['str1']); $this->assertEquals('Rom', $result[3]['str1']); - + $this->assertEquals('amin E.', $result[0]['str2']); $this->assertEquals('herme B.', $result[1]['str2']); $this->assertEquals('than W.', $result[2]['str2']); @@ -287,87 +288,70 @@ public function testDateDiff() /** * @group DDC-1014 - */ - public function testDateAdd() - { - $arg = $this->_em->createQuery("SELECT DATE_ADD(CURRENT_TIMESTAMP(), 10, 'day') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m") - ->getArrayResult(); - - $this->assertTrue(strtotime($arg[0]['add']) > 0); - - $arg = $this->_em->createQuery("SELECT DATE_ADD(CURRENT_TIMESTAMP(), 10, 'month') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m") - ->getArrayResult(); - - $this->assertTrue(strtotime($arg[0]['add']) > 0); - } - - /** * @group DDC-2938 + * + * @dataProvider dateAddSubProvider */ - public function testDateAddTime(): void + public function testDateAdd(string $unit, int $amount, int $expectedValue, int $delta = 0) : void { - $arg = $this->_em->createQuery("SELECT DATE_ADD(CURRENT_TIMESTAMP(), 10, 'second') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m") - ->getArrayResult(); - self::assertTrue(strtotime($arg[0]['add']) > 0); - - $arg = $this->_em->createQuery("SELECT DATE_ADD(CURRENT_TIMESTAMP(), 10, 'minute') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m") - ->getArrayResult(); - self::assertTrue(strtotime($arg[0]['add']) > 0); - - $arg = $this->_em->createQuery("SELECT DATE_ADD(CURRENT_TIMESTAMP(), 10, 'hour') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m") - ->getArrayResult(); - self::assertTrue(strtotime($arg[0]['add']) > 0); - } + $query = sprintf( + 'SELECT CURRENT_TIMESTAMP() as now, DATE_ADD(CURRENT_TIMESTAMP(), %d, \'%s\') AS add FROM %s m', + $amount, + $unit, + CompanyManager::class + ); - public function testDateAddSecond() - { - $dql = "SELECT CURRENT_TIMESTAMP() now, DATE_ADD(CURRENT_TIMESTAMP(), 10, 'second') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m"; - $query = $this->_em->createQuery($dql)->setMaxResults(1); - $result = $query->getArrayResult(); + $result = $this->_em->createQuery($query) + ->setMaxResults(1) + ->getSingleResult(AbstractQuery::HYDRATE_ARRAY); - $this->assertCount(1, $result); - $this->assertArrayHasKey('now', $result[0]); - $this->assertArrayHasKey('add', $result[0]); + self::assertArrayHasKey('now', $result); + self::assertArrayHasKey('add', $result); - $now = strtotime($result[0]['now']); - $add = strtotime($result[0]['add']); - $diff = $add - $now; + $diff = strtotime($result['add']) - strtotime($result['now']); - $this->assertSQLEquals(10, $diff); + self::assertEquals($expectedValue, $diff, '', $delta); } /** * @group DDC-1014 + * @group DDC-2938 + * + * @dataProvider dateAddSubProvider */ - public function testDateSub() + public function testDateSub(string $unit, int $amount, int $expectedValue, int $delta = 0) : void { - $arg = $this->_em->createQuery("SELECT DATE_SUB(CURRENT_TIMESTAMP(), 10, 'day') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m") - ->getArrayResult(); + $query = sprintf( + 'SELECT CURRENT_TIMESTAMP() as now, DATE_SUB(CURRENT_TIMESTAMP(), %d, \'%s\') AS sub FROM %s m', + $amount, + $unit, + CompanyManager::class + ); - $this->assertTrue(strtotime($arg[0]['add']) > 0); + $result = $this->_em->createQuery($query) + ->setMaxResults(1) + ->getSingleResult(AbstractQuery::HYDRATE_ARRAY); - $arg = $this->_em->createQuery("SELECT DATE_SUB(CURRENT_TIMESTAMP(), 10, 'month') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m") - ->getArrayResult(); + self::assertArrayHasKey('now', $result); + self::assertArrayHasKey('sub', $result); - $this->assertTrue(strtotime($arg[0]['add']) > 0); + $diff = strtotime($result['now']) - strtotime($result['sub']); + + self::assertEquals($expectedValue, $diff, '', $delta); } - /** - * @group DDC-2938 - */ - public function testDateSubTime(): void + public function dateAddSubProvider() : array { - $arg = $this->_em->createQuery("SELECT DATE_SUB(CURRENT_TIMESTAMP(), 10, 'second') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m") - ->getArrayResult(); - self::assertTrue(strtotime($arg[0]['add']) > 0); - - $arg = $this->_em->createQuery("SELECT DATE_SUB(CURRENT_TIMESTAMP(), 10, 'minute') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m") - ->getArrayResult(); - self::assertTrue(strtotime($arg[0]['add']) > 0); - - $arg = $this->_em->createQuery("SELECT DATE_SUB(CURRENT_TIMESTAMP(), 10, 'hour') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m") - ->getArrayResult(); - self::assertTrue(strtotime($arg[0]['add']) > 0); + $secondsInDay = 86400; + + return [ + 'year' => ['year', 1, 365 * $secondsInDay, 3 * $secondsInDay], + 'month' => ['month', 1, 30 * $secondsInDay, 2 * $secondsInDay], + 'week' => ['week', 1, 7 * $secondsInDay, $secondsInDay], + 'hour' => ['hour', 1, 3600], + 'minute' => ['minute', 1, 60], + 'second' => ['second', 10, 10], + ]; } /** From bccc46dc125e4e6a05e43271389579ab4254b705 Mon Sep 17 00:00:00 2001 From: Dan Barrett Date: Wed, 1 Nov 2017 16:40:04 +1100 Subject: [PATCH 627/877] Corrected demo code to match example Example paragraph mentions changing column titles to upper case, yet `strtolower` was being used. --- docs/en/reference/namingstrategy.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/reference/namingstrategy.rst b/docs/en/reference/namingstrategy.rst index fff5e601a89..b81872fd07a 100644 --- a/docs/en/reference/namingstrategy.rst +++ b/docs/en/reference/namingstrategy.rst @@ -126,12 +126,12 @@ You need to create a class which implements ``Doctrine\ORM\Mapping\NamingStrateg } public function joinTableName($sourceEntity, $targetEntity, $propertyName = null) { - return strtolower($this->classToTableName($sourceEntity) . '_' . + return strtoupper($this->classToTableName($sourceEntity) . '_' . $this->classToTableName($targetEntity)); } public function joinKeyColumnName($entityName, $referencedColumnName = null) { - return strtolower($this->classToTableName($entityName) . '_' . + return strtoupper($this->classToTableName($entityName) . '_' . ($referencedColumnName ?: $this->referenceColumnName())); } } From 91408a3a54c007be72f2f1f65d4b694f90dd28c4 Mon Sep 17 00:00:00 2001 From: Pierre-Louis FORT Date: Thu, 9 Nov 2017 14:10:36 +0100 Subject: [PATCH 628/877] #6819 Optimize LimitSubqueryWalker when resultVariable are involved and they are not used in "order by" --- .../Tools/Pagination/LimitSubqueryWalker.php | 31 ++++++++----------- .../Pagination/LimitSubqueryWalkerTest.php | 30 +++++++++++++++++- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php index aceeb5c0989..fd90a27f2a1 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php @@ -69,18 +69,8 @@ public function walkSelectStatement(SelectStatement $AST) $fromRoot = reset($from); $rootAlias = $fromRoot->rangeVariableDeclaration->aliasIdentificationVariable; $rootClass = $queryComponents[$rootAlias]['metadata']; - $selectExpressions = []; $this->validate($AST); - - foreach ($queryComponents as $dqlAlias => $qComp) { - // Preserve mixed data in query for ordering. - if (isset($qComp['resultVariable'])) { - $selectExpressions[] = new SelectExpression($qComp['resultVariable'], $dqlAlias); - continue; - } - } - $identifier = $rootClass->getSingleIdentifierFieldName(); if (isset($rootClass->associationMappings[$identifier])) { @@ -100,20 +90,25 @@ public function walkSelectStatement(SelectStatement $AST) $pathExpression->type = PathExpression::TYPE_STATE_FIELD; - array_unshift($selectExpressions, new SelectExpression($pathExpression, '_dctrn_id')); - - $AST->selectClause->selectExpressions = $selectExpressions; + $AST->selectClause->selectExpressions = array(new SelectExpression($pathExpression, '_dctrn_id')); if (isset($AST->orderByClause)) { foreach ($AST->orderByClause->orderByItems as $item) { if ( ! $item->expression instanceof PathExpression) { - continue; + if(isset($queryComponents[$item->expression])) { + $qComp = $queryComponents[$item->expression]; + if (isset($qComp['resultVariable'])) { + $AST->selectClause->selectExpressions[] = new SelectExpression($qComp['resultVariable'], $item->expression); + } + } + } else { + + $AST->selectClause->selectExpressions[] = new SelectExpression( + $this->createSelectExpressionItem($item->expression), + '_dctrn_ord' . $this->_aliasCounter++ + ); } - $AST->selectClause->selectExpressions[] = new SelectExpression( - $this->createSelectExpressionItem($item->expression), - '_dctrn_ord' . $this->_aliasCounter++ - ); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php index 8ddc158b928..7bde638958b 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php @@ -47,7 +47,35 @@ public function testCountQuery_MixedResultsWithName() $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [LimitSubqueryWalker::class]); $this->assertEquals( - "SELECT DISTINCT a0_.id AS id_0, sum(a0_.name) AS sclr_1 FROM Author a0_", + "SELECT DISTINCT a0_.id AS id_0 FROM Author a0_", + $limitQuery->getSQL() + ); + } + + public function testAggQuery_MixedResultsWithNameAndSort() + { + $dql = 'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a ORDER BY foo DESC'; + $query = $this->entityManager->createQuery($dql); + $limitQuery = clone $query; + + $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [LimitSubqueryWalker::class]); + + $this->assertEquals( + "SELECT DISTINCT a0_.id AS id_0, sum(a0_.name) AS sclr_1 FROM Author a0_ ORDER BY sclr_1 DESC", + $limitQuery->getSQL() + ); + } + + public function testAggQuery_MultipleMixedResultsWithSort() + { + $dql = 'SELECT a, sum(a.name) as foo, (SELECT count(subA.id) FROM Doctrine\Tests\ORM\Tools\Pagination\Author subA WHERE subA.id = a.id ) as bar FROM Doctrine\Tests\ORM\Tools\Pagination\Author a ORDER BY foo DESC, bar ASC'; + $query = $this->entityManager->createQuery($dql); + $limitQuery = clone $query; + + $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [LimitSubqueryWalker::class]); + + $this->assertEquals( + "SELECT DISTINCT a0_.id AS id_0, sum(a0_.name) AS sclr_1, (SELECT count(a1_.id) AS sclr_3 FROM Author a1_ WHERE a1_.id = a0_.id) AS sclr_2 FROM Author a0_ ORDER BY sclr_1 DESC, sclr_2 ASC", $limitQuery->getSQL() ); } From 4ab9413675bb7a77c37503b9bc047d0157d452d1 Mon Sep 17 00:00:00 2001 From: Pierre-Louis FORT Date: Fri, 10 Nov 2017 10:45:57 +0100 Subject: [PATCH 629/877] Test that orderByItem is string --- .../ORM/Tools/Pagination/LimitSubqueryWalker.php | 2 +- .../Tools/Pagination/LimitSubqueryWalkerTest.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php index fd90a27f2a1..659a3bab9b1 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php @@ -95,7 +95,7 @@ public function walkSelectStatement(SelectStatement $AST) if (isset($AST->orderByClause)) { foreach ($AST->orderByClause->orderByItems as $item) { if ( ! $item->expression instanceof PathExpression) { - if(isset($queryComponents[$item->expression])) { + if(is_string($item->expression) && isset($queryComponents[$item->expression])) { $qComp = $queryComponents[$item->expression]; if (isset($qComp['resultVariable'])) { $AST->selectClause->selectExpressions[] = new SelectExpression($qComp['resultVariable'], $item->expression); diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php index 7bde638958b..81866f8c065 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php @@ -38,6 +38,21 @@ public function testLimitSubqueryWithSort() ); } + public function testLimitSubqueryWithSortFunction() + { + $dql = 'SELECT p FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category c GROUP BY p.id ORDER BY COUNT(c.id)'; + $query = $this->entityManager->createQuery($dql); + $limitQuery = clone $query; + + $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [LimitSubqueryWalker::class]); + + $this->assertEquals( + "SELECT DISTINCT m0_.id AS id_0 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON m0_.category_id = c1_.id GROUP BY m0_.id ORDER BY COUNT(c1_.id) ASC", + $limitQuery->getSQL() + ); + } + + public function testCountQuery_MixedResultsWithName() { $dql = 'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a'; From 8918bd3b8a69bc13f2d75f79866a680ec5fc6c8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Thu, 23 Nov 2017 10:24:18 +0100 Subject: [PATCH 630/877] Use new analyser on scrutinizer-ci Also preventing from running the tests (because that's already done on Travis-CI) and simplifying the build failure conditions. --- .scrutinizer.yml | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 4ba4635114f..d05c72cf061 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,7 +1,19 @@ build: - environment: - php: - version: 7.1 + nodes: + analysis: + environment: + php: + version: 7.1 + cache: + disabled: false + directories: + - ~/.composer/cache + + project_setup: + override: true + tests: + override: + - php-scrutinizer-run before_commands: - "composer install --no-dev --prefer-source" @@ -17,8 +29,6 @@ filter: build_failure_conditions: - 'elements.rating(<= C).new.exists' # No new classes/methods with a rating of C or worse allowed - - 'issues.label("coding-style").new.exists' # No new coding style issues allowed - 'issues.severity(>= MAJOR).new.exists' # New issues of major or higher severity - 'project.metric_change("scrutinizer.test_coverage", < 0)' # Code Coverage decreased from previous inspection - - 'patches.label("Doc Comments").new.exists' # No new doc comments patches allowed - 'patches.label("Unused Use Statements").new.exists' # No new unused imports patches allowed From 13197123c54700234dda3e3513d2c2ed1ee3219a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Thu, 23 Nov 2017 11:15:52 +0100 Subject: [PATCH 631/877] Sort dependencies definitions --- composer.json | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index b4371aaec40..8316e57806a 100644 --- a/composer.json +++ b/composer.json @@ -13,20 +13,23 @@ {"name": "Marco Pivetta", "email": "ocramius@gmail.com"} ], "minimum-stability": "dev", + "config": { + "sort-packages": true + }, "require": { "php": "^7.1", "ext-pdo": "*", + "doctrine/annotations": "~1.4", + "doctrine/cache": "~1.6", "doctrine/collections": "^1.4", + "doctrine/common": "^2.7.1", "doctrine/dbal": "^2.6", "doctrine/instantiator": "~1.1", - "doctrine/common": "^2.7.1", - "doctrine/cache": "~1.6", - "doctrine/annotations": "~1.4", "symfony/console": "~3.0|~4.0" }, "require-dev": { - "symfony/yaml": "~3.4|~4.0", - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^6.0", + "symfony/yaml": "~3.4|~4.0" }, "suggest": { "symfony/yaml": "If you want to use YAML Metadata Mapping Driver" From 2be1b7d0b8cc47e1061493de74ac22131e3e5031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Thu, 23 Nov 2017 11:26:33 +0100 Subject: [PATCH 632/877] Add configuration for PHPCS And execute it on Travis (allowing it to fail for now to prevent a lot of conflicts with `develop`). --- .gitattributes | 1 + .gitignore | 1 + .travis.yml | 5 +++++ composer.json | 2 ++ phpcs.xml.dist | 24 ++++++++++++++++++++++++ 5 files changed, 33 insertions(+) create mode 100644 phpcs.xml.dist diff --git a/.gitattributes b/.gitattributes index 6b4dc843e4c..c5a870fd09b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10,3 +10,4 @@ build.xml export-ignore CONTRIBUTING.md export-ignore phpunit.xml.dist export-ignore run-all.sh export-ignore +phpcs.xml.dist export-ignore diff --git a/.gitignore b/.gitignore index d2f5f690158..da74102928a 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ lib/Doctrine/DBAL vendor/ composer.lock /tests/Doctrine/Performance/history.db +/.phpcs-cache diff --git a/.travis.yml b/.travis.yml index e55ea503c5e..c74cf36c254 100644 --- a/.travis.yml +++ b/.travis.yml @@ -78,6 +78,11 @@ jobs: before_script: wget https://phpbench.github.io/phpbench/phpbench.phar https://phpbench.github.io/phpbench/phpbench.phar.pubkey script: php phpbench.phar run -l dots --report=default + - stage: Coding standard + php: nightly + script: + - ./vendor/bin/phpcs + allow_failures: - php: nightly diff --git a/composer.json b/composer.json index 8316e57806a..fad4b22ff6d 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,9 @@ "symfony/console": "~3.0|~4.0" }, "require-dev": { + "doctrine/coding-standard": "^1.0", "phpunit/phpunit": "^6.0", + "squizlabs/php_codesniffer": "^3.1", "symfony/yaml": "~3.4|~4.0" }, "suggest": { diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 00000000000..9ffa05d316f --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,24 @@ + + + + + + + + + + + + lib + tests + tools + + */tests/Doctrine/Tests/Proxies/__CG__/* + + + + + */tests/* + + + From 984327d782968e507de0c08b8da8b784f135a4f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Thu, 23 Nov 2017 11:29:39 +0100 Subject: [PATCH 633/877] Update PHPStan --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c74cf36c254..31a63d87c6d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -59,7 +59,7 @@ jobs: env: DB=none before_script: - echo "extension=redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - - travis_retry composer require --dev --prefer-dist --prefer-stable phpstan/phpstan:^0.7 symfony/console:^3.0 + - travis_retry composer require --dev --prefer-dist --prefer-stable phpstan/phpstan:^0.8 symfony/console:^3.0 script: vendor/bin/phpstan analyse -l 1 -c phpstan.neon lib - stage: Coverage From 214dc9896b83a0f867c1c4ff5641e4eac7f1c530 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Thu, 23 Nov 2017 11:18:08 +0100 Subject: [PATCH 634/877] Use addOption()/addArgument() to configure commands In order to simplify and standardise the definition of the commands. --- .../ClearCache/CollectionRegionCommand.php | 29 ++++---- .../ClearCache/EntityRegionCommand.php | 25 +++---- .../Command/ClearCache/MetadataCommand.php | 25 +++---- .../Command/ClearCache/QueryCommand.php | 25 +++---- .../Command/ClearCache/QueryRegionCommand.php | 23 +++--- .../Command/ClearCache/ResultCommand.php | 23 ++---- .../Command/ConvertDoctrine1SchemaCommand.php | 55 ++++----------- .../Console/Command/ConvertMappingCommand.php | 67 ++++++------------ .../EnsureProductionSettingsCommand.php | 21 ++---- .../Command/GenerateEntitiesCommand.php | 70 +++++-------------- .../Command/GenerateProxiesCommand.php | 34 +++------ .../Command/GenerateRepositoriesCommand.php | 33 +++------ .../ORM/Tools/Console/Command/InfoCommand.php | 13 ++-- .../Command/MappingDescribeCommand.php | 18 +++-- .../Tools/Console/Command/RunDqlCommand.php | 54 ++++---------- .../Command/SchemaTool/AbstractCommand.php | 4 +- .../Command/SchemaTool/CreateCommand.php | 24 ++----- .../Command/SchemaTool/DropCommand.php | 34 +++------ .../Command/SchemaTool/UpdateCommand.php | 36 +++------- .../Console/Command/ValidateSchemaCommand.php | 27 ++----- 20 files changed, 199 insertions(+), 441 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/CollectionRegionCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/CollectionRegionCommand.php index f12bfa5602d..8c73cf79356 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/CollectionRegionCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/CollectionRegionCommand.php @@ -19,13 +19,13 @@ namespace Doctrine\ORM\Tools\Console\Command\ClearCache; +use Doctrine\ORM\Cache; +use Doctrine\ORM\Cache\Region\DefaultRegion; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Doctrine\ORM\Cache\Region\DefaultRegion; -use Doctrine\ORM\Cache; /** * Command to clear a collection cache region. @@ -40,17 +40,14 @@ class CollectionRegionCommand extends Command */ protected function configure() { - $this - ->setName('orm:clear-cache:region:collection') - ->setDescription('Clear a second-level cache collection region.') - ->addArgument('owner-class', InputArgument::OPTIONAL, 'The owner entity name.') - ->addArgument('association', InputArgument::OPTIONAL, 'The association collection name.') - ->addArgument('owner-id', InputArgument::OPTIONAL, 'The owner identifier.') - ->addOption('all', null, InputOption::VALUE_NONE, 'If defined, all entity regions will be deleted/invalidated.') - ->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, all cache entries will be flushed.'); - - - $this->setHelp(<<setName('orm:clear-cache:region:collection') + ->setDescription('Clear a second-level cache collection region') + ->addArgument('owner-class', InputArgument::OPTIONAL, 'The owner entity name.') + ->addArgument('association', InputArgument::OPTIONAL, 'The association collection name.') + ->addArgument('owner-id', InputArgument::OPTIONAL, 'The owner identifier.') + ->addOption('all', null, InputOption::VALUE_NONE, 'If defined, all entity regions will be deleted/invalidated.') + ->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, all cache entries will be flushed.') + ->setHelp(<<%command.name% command is meant to clear a second-level cache collection regions for an associated Entity Manager. It is possible to delete/invalidate all collection region, a specific collection region or flushes the cache provider. @@ -74,7 +71,7 @@ protected function configure() Finally, be aware that if --flush option is passed, not all cache providers are able to flush entries, because of a limitation of its execution nature. EOT - ); + ); } /** @@ -92,7 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output) throw new \InvalidArgumentException('No second-level cache is configured on the given EntityManager.'); } - if ( (! $ownerClass || ! $assoc) && ! $input->getOption('all')) { + if (( ! $ownerClass || ! $assoc) && ! $input->getOption('all')) { throw new \InvalidArgumentException('Missing arguments "--owner-class" "--association"'); } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/EntityRegionCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/EntityRegionCommand.php index 0258b7de223..ff9e3688b27 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/EntityRegionCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/EntityRegionCommand.php @@ -19,13 +19,13 @@ namespace Doctrine\ORM\Tools\Console\Command\ClearCache; +use Doctrine\ORM\Cache; +use Doctrine\ORM\Cache\Region\DefaultRegion; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Doctrine\ORM\Cache\Region\DefaultRegion; -use Doctrine\ORM\Cache; /** * Command to clear a entity cache region. @@ -40,16 +40,13 @@ class EntityRegionCommand extends Command */ protected function configure() { - $this - ->setName('orm:clear-cache:region:entity') - ->setDescription('Clear a second-level cache entity region.') - ->addArgument('entity-class', InputArgument::OPTIONAL, 'The entity name.') - ->addArgument('entity-id', InputArgument::OPTIONAL, 'The entity identifier.') - ->addOption('all', null, InputOption::VALUE_NONE, 'If defined, all entity regions will be deleted/invalidated.') - ->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, all cache entries will be flushed.'); - - - $this->setHelp(<<setName('orm:clear-cache:region:entity') + ->setDescription('Clear a second-level cache entity region') + ->addArgument('entity-class', InputArgument::OPTIONAL, 'The entity name.') + ->addArgument('entity-id', InputArgument::OPTIONAL, 'The entity identifier.') + ->addOption('all', null, InputOption::VALUE_NONE, 'If defined, all entity regions will be deleted/invalidated.') + ->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, all cache entries will be flushed.') + ->setHelp(<<%command.name% command is meant to clear a second-level cache entity region for an associated Entity Manager. It is possible to delete/invalidate all entity region, a specific entity region or flushes the cache provider. @@ -73,7 +70,7 @@ protected function configure() Finally, be aware that if --flush option is passed, not all cache providers are able to flush entries, because of a limitation of its execution nature. EOT - ); + ); } /** diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/MetadataCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/MetadataCommand.php index 5bc0c859d63..64b6a0615e5 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/MetadataCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/MetadataCommand.php @@ -19,12 +19,12 @@ namespace Doctrine\ORM\Tools\Console\Command\ClearCache; +use Doctrine\Common\Cache\ApcCache; +use Doctrine\Common\Cache\XcacheCache; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Doctrine\Common\Cache\ApcCache; -use Doctrine\Common\Cache\XcacheCache; /** * Command to clear the metadata cache of the various cache drivers. @@ -43,19 +43,10 @@ class MetadataCommand extends Command */ protected function configure() { - $this - ->setName('orm:clear-cache:metadata') - ->setDescription('Clear all metadata cache of the various cache drivers.') - ->setDefinition( - [ - new InputOption( - 'flush', null, InputOption::VALUE_NONE, - 'If defined, cache entries will be flushed instead of deleted/invalidated.' - ) - ] - ); - - $this->setHelp(<<setName('orm:clear-cache:metadata') + ->setDescription('Clear all metadata cache of the various cache drivers') + ->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, cache entries will be flushed instead of deleted/invalidated.') + ->setHelp(<<%command.name% command is meant to clear the metadata cache of associated Entity Manager. It is possible to invalidate all cache entries at once - called delete -, or flushes the cache provider instance completely. @@ -72,7 +63,7 @@ protected function configure() Finally, be aware that if --flush option is passed, not all cache providers are able to flush entries, because of a limitation of its execution nature. EOT - ); + ); } /** diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php index 5828d077163..b4619bd7fd6 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php @@ -19,12 +19,12 @@ namespace Doctrine\ORM\Tools\Console\Command\ClearCache; +use Doctrine\Common\Cache\ApcCache; +use Doctrine\Common\Cache\XcacheCache; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Doctrine\Common\Cache\ApcCache; -use Doctrine\Common\Cache\XcacheCache; /** * Command to clear the query cache of the various cache drivers. @@ -43,19 +43,10 @@ class QueryCommand extends Command */ protected function configure() { - $this - ->setName('orm:clear-cache:query') - ->setDescription('Clear all query cache of the various cache drivers.') - ->setDefinition( - [ - new InputOption( - 'flush', null, InputOption::VALUE_NONE, - 'If defined, cache entries will be flushed instead of deleted/invalidated.' - ) - ] - ); - - $this->setHelp(<<setName('orm:clear-cache:query') + ->setDescription('Clear all query cache of the various cache drivers') + ->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, cache entries will be flushed instead of deleted/invalidated.') + ->setHelp(<<%command.name% command is meant to clear the query cache of associated Entity Manager. It is possible to invalidate all cache entries at once - called delete -, or flushes the cache provider instance completely. @@ -72,7 +63,7 @@ protected function configure() Finally, be aware that if --flush option is passed, not all cache providers are able to flush entries, because of a limitation of its execution nature. EOT - ); + ); } /** diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryRegionCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryRegionCommand.php index 0637c7a4a07..9492958b1ce 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryRegionCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryRegionCommand.php @@ -19,13 +19,13 @@ namespace Doctrine\ORM\Tools\Console\Command\ClearCache; +use Doctrine\ORM\Cache; +use Doctrine\ORM\Cache\Region\DefaultRegion; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Doctrine\ORM\Cache\Region\DefaultRegion; -use Doctrine\ORM\Cache; /** * Command to clear a query cache region. @@ -40,15 +40,12 @@ class QueryRegionCommand extends Command */ protected function configure() { - $this - ->setName('orm:clear-cache:region:query') - ->setDescription('Clear a second-level cache query region.') - ->addArgument('region-name', InputArgument::OPTIONAL, 'The query region to clear.') - ->addOption('all', null, InputOption::VALUE_NONE, 'If defined, all query regions will be deleted/invalidated.') - ->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, all cache entries will be flushed.'); - - - $this->setHelp(<<setName('orm:clear-cache:region:query') + ->setDescription('Clear a second-level cache query region') + ->addArgument('region-name', InputArgument::OPTIONAL, 'The query region to clear.') + ->addOption('all', null, InputOption::VALUE_NONE, 'If defined, all query regions will be deleted/invalidated.') + ->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, all cache entries will be flushed.') + ->setHelp(<<%command.name% command is meant to clear a second-level cache query region for an associated Entity Manager. It is possible to delete/invalidate all query region, a specific query region or flushes the cache provider. @@ -72,7 +69,7 @@ protected function configure() Finally, be aware that if --flush option is passed, not all cache providers are able to flush entries, because of a limitation of its execution nature. EOT - ); + ); } /** diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/ResultCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/ResultCommand.php index 55b89efa8eb..6b00c12336c 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/ResultCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/ResultCommand.php @@ -19,12 +19,12 @@ namespace Doctrine\ORM\Tools\Console\Command\ClearCache; +use Doctrine\Common\Cache\ApcCache; +use Doctrine\Common\Cache\XcacheCache; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Doctrine\Common\Cache\ApcCache; -use Doctrine\Common\Cache\XcacheCache; /** * Command to clear the result cache of the various cache drivers. @@ -43,19 +43,10 @@ class ResultCommand extends Command */ protected function configure() { - $this - ->setName('orm:clear-cache:result') - ->setDescription('Clear all result cache of the various cache drivers.') - ->setDefinition( - [ - new InputOption( - 'flush', null, InputOption::VALUE_NONE, - 'If defined, cache entries will be flushed instead of deleted/invalidated.' - ) - ] - ); - - $this->setHelp(<<setName('orm:clear-cache:result') + ->setDescription('Clear all result cache of the various cache drivers') + ->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, cache entries will be flushed instead of deleted/invalidated.') + ->setHelp(<<%command.name% command is meant to clear the result cache of associated Entity Manager. It is possible to invalidate all cache entries at once - called delete -, or flushes the cache provider instance completely. @@ -72,7 +63,7 @@ protected function configure() Finally, be aware that if --flush option is passed, not all cache providers are able to flush entries, because of a limitation of its execution nature. EOT - ); + ); } /** diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php index 6c81de940de..b6b43bf8e04 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php @@ -19,14 +19,14 @@ namespace Doctrine\ORM\Tools\Console\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputOption; -use Doctrine\ORM\Tools\Export\ClassMetadataExporter; use Doctrine\ORM\Tools\ConvertDoctrine1Schema; use Doctrine\ORM\Tools\EntityGenerator; -use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\InputInterface; +use Doctrine\ORM\Tools\Export\ClassMetadataExporter; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; /** * Command to convert a Doctrine 1 schema to a Doctrine 2 mapping file. @@ -99,41 +99,16 @@ public function setMetadataExporter(ClassMetadataExporter $metadataExporter) */ protected function configure() { - $this - ->setName('orm:convert-d1-schema') - ->setAliases(['orm:convert:d1-schema']) - ->setDescription('Converts Doctrine 1.X schema into a Doctrine 2.X schema.') - ->setDefinition( - [ - new InputArgument( - 'from-path', InputArgument::REQUIRED, 'The path of Doctrine 1.X schema information.' - ), - new InputArgument( - 'to-type', InputArgument::REQUIRED, 'The destination Doctrine 2.X mapping type.' - ), - new InputArgument( - 'dest-path', InputArgument::REQUIRED, - 'The path to generate your Doctrine 2.X mapping information.' - ), - new InputOption( - 'from', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, - 'Optional paths of Doctrine 1.X schema information.', - [] - ), - new InputOption( - 'extend', null, InputOption::VALUE_OPTIONAL, - 'Defines a base class to be extended by generated entity classes.' - ), - new InputOption( - 'num-spaces', null, InputOption::VALUE_OPTIONAL, - 'Defines the number of indentation spaces', 4 - ) - ] - ) - ->setHelp(<<setName('orm:convert-d1-schema') + ->setAliases(['orm:convert:d1-schema']) + ->setDescription('Converts Doctrine 1.x schema into a Doctrine 2.x schema') + ->addArgument('from-path', InputArgument::REQUIRED, 'The path of Doctrine 1.X schema information.') + ->addArgument('to-type', InputArgument::REQUIRED, 'The destination Doctrine 2.X mapping type.') + ->addArgument('dest-path', InputArgument::REQUIRED, 'The path to generate your Doctrine 2.X mapping information.') + ->addOption('from', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Optional paths of Doctrine 1.X schema information.', []) + ->addOption('extend', null, InputOption::VALUE_OPTIONAL, 'Defines a base class to be extended by generated entity classes.') + ->addOption('num-spaces', null, InputOption::VALUE_OPTIONAL, 'Defines the number of indentation spaces', 4) + ->setHelp('Converts Doctrine 1.x schema into a Doctrine 2.x schema.'); } /** diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php index 798dbe72858..6b9153f0130 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php @@ -19,16 +19,16 @@ namespace Doctrine\ORM\Tools\Console\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputOption; +use Doctrine\ORM\Mapping\Driver\DatabaseDriver; use Doctrine\ORM\Tools\Console\MetadataFilter; -use Doctrine\ORM\Tools\Export\ClassMetadataExporter; -use Doctrine\ORM\Tools\EntityGenerator; use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory; -use Doctrine\ORM\Mapping\Driver\DatabaseDriver; -use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\InputInterface; +use Doctrine\ORM\Tools\EntityGenerator; +use Doctrine\ORM\Tools\Export\ClassMetadataExporter; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; /** * Command to convert your mapping information between the various formats. @@ -47,45 +47,18 @@ class ConvertMappingCommand extends Command */ protected function configure() { - $this - ->setName('orm:convert-mapping') - ->setAliases(['orm:convert:mapping']) - ->setDescription('Convert mapping information between supported formats.') - ->setDefinition( - [ - new InputOption( - 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, - 'A string pattern used to match entities that should be processed.' - ), - new InputArgument( - 'to-type', InputArgument::REQUIRED, 'The mapping type to be converted.' - ), - new InputArgument( - 'dest-path', InputArgument::REQUIRED, - 'The path to generate your entities classes.' - ), - new InputOption( - 'force', 'f', InputOption::VALUE_NONE, - 'Force to overwrite existing mapping files.' - ), - new InputOption( - 'from-database', null, null, 'Whether or not to convert mapping information from existing database.' - ), - new InputOption( - 'extend', null, InputOption::VALUE_OPTIONAL, - 'Defines a base class to be extended by generated entity classes.' - ), - new InputOption( - 'num-spaces', null, InputOption::VALUE_OPTIONAL, - 'Defines the number of indentation spaces', 4 - ), - new InputOption( - 'namespace', null, InputOption::VALUE_OPTIONAL, - 'Defines a namespace for the generated entity classes, if converted from database.' - ), - ] - ) - ->setHelp(<<setName('orm:convert-mapping') + ->setAliases(['orm:convert:mapping']) + ->setDescription('Convert mapping information between supported formats') + ->addArgument('to-type', InputArgument::REQUIRED, 'The mapping type to be converted.') + ->addArgument('dest-path', InputArgument::REQUIRED, 'The path to generate your entities classes.') + ->addOption('filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match entities that should be processed.') + ->addOption('force', 'f', InputOption::VALUE_NONE, 'Force to overwrite existing mapping files.') + ->addOption('from-database', null, null, 'Whether or not to convert mapping information from existing database.') + ->addOption('extend', null, InputOption::VALUE_OPTIONAL, 'Defines a base class to be extended by generated entity classes.') + ->addOption('num-spaces', null, InputOption::VALUE_OPTIONAL, 'Defines the number of indentation spaces', 4) + ->addOption('namespace', null, InputOption::VALUE_OPTIONAL, 'Defines a namespace for the generated entity classes, if converted from database.') + ->setHelp(<<one-time command. It should not be necessary for @@ -108,7 +81,7 @@ protected function configure() \$config->setFilterSchemaAssetsExpression(\$regexp); EOT - ); + ); } /** diff --git a/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php index 180254f9cec..0a986bce1d9 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php @@ -20,8 +20,8 @@ namespace Doctrine\ORM\Tools\Console\Command; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Throwable; @@ -43,21 +43,10 @@ class EnsureProductionSettingsCommand extends Command */ protected function configure() { - $this - ->setName('orm:ensure-production-settings') - ->setDescription('Verify that Doctrine is properly configured for a production environment.') - ->setDefinition( - [ - new InputOption( - 'complete', null, InputOption::VALUE_NONE, - 'Flag to also inspect database connection existence.' - ) - ] - ) - ->setHelp(<<setName('orm:ensure-production-settings') + ->setDescription('Verify that Doctrine is properly configured for a production environment') + ->addOption('complete', null, InputOption::VALUE_NONE, 'Flag to also inspect database connection existence.') + ->setHelp('Verify that Doctrine is properly configured for a production environment.'); } /** diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php index 080bfc97ace..58d19774ce6 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php @@ -19,14 +19,14 @@ namespace Doctrine\ORM\Tools\Console\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputOption; use Doctrine\ORM\Tools\Console\MetadataFilter; -use Doctrine\ORM\Tools\EntityGenerator; use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory; -use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\InputInterface; +use Doctrine\ORM\Tools\EntityGenerator; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; /** * Command to generate entity classes and method stubs from your mapping information. @@ -45,50 +45,19 @@ class GenerateEntitiesCommand extends Command */ protected function configure() { - $this - ->setName('orm:generate-entities') - ->setAliases(['orm:generate:entities']) - ->setDescription('Generate entity classes and method stubs from your mapping information.') - ->setDefinition( - [ - new InputOption( - 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, - 'A string pattern used to match entities that should be processed.' - ), - new InputArgument( - 'dest-path', InputArgument::REQUIRED, 'The path to generate your entity classes.' - ), - new InputOption( - 'generate-annotations', null, InputOption::VALUE_OPTIONAL, - 'Flag to define if generator should generate annotation metadata on entities.', false - ), - new InputOption( - 'generate-methods', null, InputOption::VALUE_OPTIONAL, - 'Flag to define if generator should generate stub methods on entities.', true - ), - new InputOption( - 'regenerate-entities', null, InputOption::VALUE_OPTIONAL, - 'Flag to define if generator should regenerate entity if it exists.', false - ), - new InputOption( - 'update-entities', null, InputOption::VALUE_OPTIONAL, - 'Flag to define if generator should only update entity if it exists.', true - ), - new InputOption( - 'extend', null, InputOption::VALUE_REQUIRED, - 'Defines a base class to be extended by generated entity classes.' - ), - new InputOption( - 'num-spaces', null, InputOption::VALUE_REQUIRED, - 'Defines the number of indentation spaces', 4 - ), - new InputOption( - 'no-backup', null, InputOption::VALUE_NONE, - 'Flag to define if generator should avoid backuping existing entity file if it exists.' - ) - ] - ) - ->setHelp(<<setName('orm:generate-entities') + ->setAliases(['orm:generate:entities']) + ->setDescription('Generate entity classes and method stubs from your mapping information') + ->addArgument('dest-path', InputArgument::REQUIRED, 'The path to generate your entity classes.') + ->addOption('filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match entities that should be processed.') + ->addOption('generate-annotations', null, InputOption::VALUE_OPTIONAL, 'Flag to define if generator should generate annotation metadata on entities.', false) + ->addOption('generate-methods', null, InputOption::VALUE_OPTIONAL, 'Flag to define if generator should generate stub methods on entities.', true) + ->addOption('regenerate-entities', null, InputOption::VALUE_OPTIONAL, 'Flag to define if generator should regenerate entity if it exists.', false) + ->addOption('update-entities', null, InputOption::VALUE_OPTIONAL, 'Flag to define if generator should only update entity if it exists.', true) + ->addOption('extend', null, InputOption::VALUE_REQUIRED, 'Defines a base class to be extended by generated entity classes.') + ->addOption('num-spaces', null, InputOption::VALUE_REQUIRED, 'Defines the number of indentation spaces', 4) + ->addOption('no-backup', null, InputOption::VALUE_NONE, 'Flag to define if generator should avoid backuping existing entity file if it exists.') + ->setHelp(<<--update-entities or --regenerate-entities flags your existing @@ -108,7 +77,7 @@ protected function configure() class is supposed to extend which. You have to adjust the entity code manually for inheritance to work! EOT - ); + ); } /** @@ -139,7 +108,6 @@ protected function execute(InputInterface $input, OutputInterface $output) } if (count($metadatas)) { - // Create EntityGenerator $entityGenerator = new EntityGenerator(); $entityGenerator->setGenerateAnnotations($input->getOption('generate-annotations')); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php index 9475bca71b7..682b0fc4cf0 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php @@ -19,12 +19,13 @@ namespace Doctrine\ORM\Tools\Console\Command; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Tools\Console\MetadataFilter; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; -use Doctrine\ORM\Tools\Console\MetadataFilter; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Command\Command; /** * Command to (re)generate the proxy classes used by doctrine. @@ -43,26 +44,12 @@ class GenerateProxiesCommand extends Command */ protected function configure() { - $this - ->setName('orm:generate-proxies') - ->setAliases(['orm:generate:proxies']) - ->setDescription('Generates proxy classes for entity classes.') - ->setDefinition( - [ - new InputOption( - 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, - 'A string pattern used to match entities that should be processed.' - ), - new InputArgument( - 'dest-path', InputArgument::OPTIONAL, - 'The path to generate your proxy classes. If none is provided, it will attempt to grab from configuration.' - ), - ] - ) - ->setHelp(<<setName('orm:generate-proxies') + ->setAliases(['orm:generate:proxies']) + ->setDescription('Generates proxy classes for entity classes') + ->addArgument('dest-path', InputArgument::OPTIONAL, 'The path to generate your proxy classes. If none is provided, it will attempt to grab from configuration.') + ->addOption('filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match entities that should be processed.') + ->setHelp('Generates proxy classes for entity classes.'); } /** @@ -70,6 +57,7 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + /** @var EntityManagerInterface $em */ $em = $this->getHelper('em')->getEntityManager(); $metadatas = $em->getMetadataFactory()->getAllMetadata(); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php index 1da7a85c141..81081a4426e 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php @@ -19,13 +19,13 @@ namespace Doctrine\ORM\Tools\Console\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputOption; use Doctrine\ORM\Tools\Console\MetadataFilter; use Doctrine\ORM\Tools\EntityRepositoryGenerator; -use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; /** * Command to generate repository classes for mapping information. @@ -44,25 +44,12 @@ class GenerateRepositoriesCommand extends Command */ protected function configure() { - $this - ->setName('orm:generate-repositories') - ->setAliases(['orm:generate:repositories']) - ->setDescription('Generate repository classes from your mapping information.') - ->setDefinition( - [ - new InputOption( - 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, - 'A string pattern used to match entities that should be processed.' - ), - new InputArgument( - 'dest-path', InputArgument::REQUIRED, 'The path to generate your repository classes.' - ) - ] - ) - ->setHelp(<<setName('orm:generate-repositories') + ->setAliases(['orm:generate:repositories']) + ->setDescription('Generate repository classes from your mapping information') + ->addArgument('dest-path', InputArgument::REQUIRED, 'The path to generate your repository classes.') + ->addOption('filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match entities that should be processed.') + ->setHelp('Generate repository classes from your mapping information.'); } /** diff --git a/lib/Doctrine/ORM/Tools/Console/Command/InfoCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/InfoCommand.php index 560d18718b5..6cf73ee76d0 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/InfoCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/InfoCommand.php @@ -20,9 +20,9 @@ namespace Doctrine\ORM\Tools\Console\Command; use Doctrine\ORM\Mapping\MappingException; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Command\Command; /** * Show information about mapped entities. @@ -38,15 +38,14 @@ class InfoCommand extends Command */ protected function configure() { - $this - ->setName('orm:info') - ->setDescription('Show basic information about all mapped entities') - ->setHelp(<<setName('orm:info') + ->setDescription('Show basic information about all mapped entities') + ->setHelp(<<%command.name% shows basic information about which entities exist and possibly if their mapping information contains errors or not. EOT - ); + ); } /** @@ -61,7 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output) ->getMetadataDriverImpl() ->getAllClassNames(); - if (!$entityClassNames) { + if ( ! $entityClassNames) { throw new \Exception( 'You do not have any mapped Doctrine ORM entities according to the current configuration. '. 'If you have entities or mapping files you should check your mapping configuration for errors.' diff --git a/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php index 6f2761e0dc6..8eca1019701 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php @@ -41,11 +41,10 @@ final class MappingDescribeCommand extends Command */ protected function configure() { - $this - ->setName('orm:mapping:describe') - ->addArgument('entityName', InputArgument::REQUIRED, 'Full or partial name of entity') - ->setDescription('Display information about mapped objects') - ->setHelp(<<setName('orm:mapping:describe') + ->addArgument('entityName', InputArgument::REQUIRED, 'Full or partial name of entity') + ->setDescription('Display information about mapped objects') + ->setHelp(<<%command.full_name% My\Namespace\Entity\MyEntity @@ -54,7 +53,7 @@ protected function configure() %command.full_name% MyEntity EOT - ); + ); } /** @@ -138,10 +137,9 @@ private function displayEntity($entityName, EntityManagerInterface $entityManage */ private function getMappedEntities(EntityManagerInterface $entityManager) { - $entityClassNames = $entityManager - ->getConfiguration() - ->getMetadataDriverImpl() - ->getAllClassNames(); + $entityClassNames = $entityManager->getConfiguration() + ->getMetadataDriverImpl() + ->getAllClassNames(); if ( ! $entityClassNames) { throw new \InvalidArgumentException( diff --git a/lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php index b246850a9c1..14191515bab 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php @@ -19,12 +19,12 @@ namespace Doctrine\ORM\Tools\Console\Command; +use Doctrine\Common\Util\Debug; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Doctrine\Common\Util\Debug; /** * Command to execute DQL queries in a given EntityManager. @@ -43,39 +43,15 @@ class RunDqlCommand extends Command */ protected function configure() { - $this - ->setName('orm:run-dql') - ->setDescription('Executes arbitrary DQL directly from the command line.') - ->setDefinition( - [ - new InputArgument('dql', InputArgument::REQUIRED, 'The DQL to execute.'), - new InputOption( - 'hydrate', null, InputOption::VALUE_REQUIRED, - 'Hydration mode of result set. Should be either: object, array, scalar or single-scalar.', - 'object' - ), - new InputOption( - 'first-result', null, InputOption::VALUE_REQUIRED, - 'The first result in the result set.' - ), - new InputOption( - 'max-result', null, InputOption::VALUE_REQUIRED, - 'The maximum number of results in the result set.' - ), - new InputOption( - 'depth', null, InputOption::VALUE_REQUIRED, - 'Dumping depth of Entity graph.', 7 - ), - new InputOption( - 'show-sql', null, InputOption::VALUE_NONE, - 'Dump generated SQL instead of executing query' - ) - ] - ) - ->setHelp(<<setName('orm:run-dql') + ->setDescription('Executes arbitrary DQL directly from the command line') + ->addArgument('dql', InputArgument::REQUIRED, 'The DQL to execute.') + ->addOption('hydrate', null, InputOption::VALUE_REQUIRED, 'Hydration mode of result set. Should be either: object, array, scalar or single-scalar.', 'object') + ->addOption('first-result', null, InputOption::VALUE_REQUIRED, 'The first result in the result set.') + ->addOption('max-result', null, InputOption::VALUE_REQUIRED, 'The maximum number of results in the result set.') + ->addOption('depth', null, InputOption::VALUE_REQUIRED, 'Dumping depth of Entity graph.', 7) + ->addOption('show-sql', null, InputOption::VALUE_NONE, 'Dump generated SQL instead of executing query') + ->setHelp('Executes arbitrary DQL directly from the command line.'); } /** @@ -87,13 +63,13 @@ protected function execute(InputInterface $input, OutputInterface $output) $em = $this->getHelper('em')->getEntityManager(); if (($dql = $input->getArgument('dql')) === null) { - throw new \RuntimeException("Argument 'DQL' is required in order to execute this command correctly."); + throw new \RuntimeException("Argument 'dql' is required in order to execute this command correctly."); } $depth = $input->getOption('depth'); if ( ! is_numeric($depth)) { - throw new \LogicException("Option 'depth' must contains an integer value"); + throw new \LogicException("Option 'depth' must contain an integer value"); } $hydrationModeName = $input->getOption('hydrate'); @@ -109,7 +85,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if (($firstResult = $input->getOption('first-result')) !== null) { if ( ! is_numeric($firstResult)) { - throw new \LogicException("Option 'first-result' must contains an integer value"); + throw new \LogicException("Option 'first-result' must contain an integer value"); } $query->setFirstResult((int) $firstResult); @@ -117,7 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if (($maxResult = $input->getOption('max-result')) !== null) { if ( ! is_numeric($maxResult)) { - throw new \LogicException("Option 'max-result' must contains an integer value"); + throw new \LogicException("Option 'max-result' must contain an integer value"); } $query->setMaxResults((int) $maxResult); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php index dc7e7ec7e86..ed9d754ed41 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php @@ -19,10 +19,10 @@ namespace Doctrine\ORM\Tools\Console\Command\SchemaTool; +use Doctrine\ORM\Tools\SchemaTool; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Command\Command; -use Doctrine\ORM\Tools\SchemaTool; /** * Base class for CreateCommand, DropCommand and UpdateCommand. diff --git a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/CreateCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/CreateCommand.php index 73fbcbabbc7..a4486469daa 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/CreateCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/CreateCommand.php @@ -19,10 +19,10 @@ namespace Doctrine\ORM\Tools\Console\Command\SchemaTool; -use Symfony\Component\Console\Input\InputOption; +use Doctrine\ORM\Tools\SchemaTool; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Doctrine\ORM\Tools\SchemaTool; /** * Command to create the database schema for a set of classes based on their mappings. @@ -41,20 +41,10 @@ class CreateCommand extends AbstractCommand */ protected function configure() { - $this - ->setName('orm:schema-tool:create') - ->setDescription( - 'Processes the schema and either create it directly on EntityManager Storage Connection or generate the SQL output.' - ) - ->setDefinition( - [ - new InputOption( - 'dump-sql', null, InputOption::VALUE_NONE, - 'Instead of trying to apply generated SQLs into EntityManager Storage Connection, output them.' - ) - ] - ) - ->setHelp(<<setName('orm:schema-tool:create') + ->setDescription('Processes the schema and either create it directly on EntityManager Storage Connection or generate the SQL output') + ->addOption('dump-sql', null, InputOption::VALUE_NONE, 'Instead of trying to apply generated SQLs into EntityManager Storage Connection, output them.') + ->setHelp(<<Hint: If you have a database with tables that should not be managed @@ -63,7 +53,7 @@ protected function configure() \$config->setFilterSchemaAssetsExpression(\$regexp); EOT - ); + ); } /** diff --git a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/DropCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/DropCommand.php index e283470391e..be4d55a950b 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/DropCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/DropCommand.php @@ -19,10 +19,10 @@ namespace Doctrine\ORM\Tools\Console\Command\SchemaTool; -use Symfony\Component\Console\Input\InputOption; +use Doctrine\ORM\Tools\SchemaTool; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Doctrine\ORM\Tools\SchemaTool; /** * Command to drop the database schema for a set of classes based on their mappings. @@ -41,28 +41,12 @@ class DropCommand extends AbstractCommand */ protected function configure() { - $this - ->setName('orm:schema-tool:drop') - ->setDescription( - 'Drop the complete database schema of EntityManager Storage Connection or generate the corresponding SQL output.' - ) - ->setDefinition( - [ - new InputOption( - 'dump-sql', null, InputOption::VALUE_NONE, - 'Instead of trying to apply generated SQLs into EntityManager Storage Connection, output them.' - ), - new InputOption( - 'force', 'f', InputOption::VALUE_NONE, - "Don't ask for the deletion of the database, but force the operation to run." - ), - new InputOption( - 'full-database', null, InputOption::VALUE_NONE, - 'Instead of using the Class Metadata to detect the database table schema, drop ALL assets that the database contains.' - ), - ] - ) - ->setHelp(<<setName('orm:schema-tool:drop') + ->setDescription('Drop the complete database schema of EntityManager Storage Connection or generate the corresponding SQL output') + ->addOption('dump-sql', null, InputOption::VALUE_NONE, 'Instead of trying to apply generated SQLs into EntityManager Storage Connection, output them.') + ->addOption('force', 'f', InputOption::VALUE_NONE, "Don't ask for the deletion of the database, but force the operation to run.") + ->addOption('full-database', null, InputOption::VALUE_NONE, 'Instead of using the Class Metadata to detect the database table schema, drop ALL assets that the database contains.') + ->setHelp(<<setFilterSchemaAssetsExpression(\$regexp); EOT - ); + ); } /** diff --git a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php index 6ba2e41f8e9..39df55d9616 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php @@ -19,10 +19,10 @@ namespace Doctrine\ORM\Tools\Console\Command\SchemaTool; -use Symfony\Component\Console\Input\InputOption; +use Doctrine\ORM\Tools\SchemaTool; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Doctrine\ORM\Tools\SchemaTool; /** * Command to generate the SQL needed to update the database schema to match @@ -48,30 +48,12 @@ class UpdateCommand extends AbstractCommand */ protected function configure() { - $this - ->setName($this->name) - ->setDescription( - 'Executes (or dumps) the SQL needed to update the database schema to match the current mapping metadata.' - ) - ->setDefinition( - [ - new InputOption( - 'complete', null, InputOption::VALUE_NONE, - 'If defined, all assets of the database which are not relevant to the current metadata will be dropped.' - ), - - new InputOption( - 'dump-sql', null, InputOption::VALUE_NONE, - 'Dumps the generated SQL statements to the screen (does not execute them).' - ), - new InputOption( - 'force', 'f', InputOption::VALUE_NONE, - 'Causes the generated SQL statements to be physically executed against your database.' - ), - ] - ); - - $this->setHelp(<<setName($this->name) + ->setDescription('Executes (or dumps) the SQL needed to update the database schema to match the current mapping metadata') + ->addOption('complete', null, InputOption::VALUE_NONE, 'If defined, all assets of the database which are not relevant to the current metadata will be dropped.') + ->addOption('dump-sql', null, InputOption::VALUE_NONE, 'Dumps the generated SQL statements to the screen (does not execute them).') + ->addOption('force', 'f', InputOption::VALUE_NONE, 'Causes the generated SQL statements to be physically executed against your database.') + ->setHelp(<<%command.name% command generates the SQL needed to synchronize the database schema with the current mapping metadata of the default entity manager. @@ -101,7 +83,7 @@ protected function configure() \$config->setFilterSchemaAssetsExpression(\$regexp); EOT - ); + ); } /** diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ValidateSchemaCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ValidateSchemaCommand.php index 57b16fc1c46..f9acda547b2 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ValidateSchemaCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ValidateSchemaCommand.php @@ -19,11 +19,11 @@ namespace Doctrine\ORM\Tools\Console\Command; +use Doctrine\ORM\Tools\SchemaValidator; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Doctrine\ORM\Tools\SchemaValidator; /** * Command to validate that the current mapping is valid. @@ -43,26 +43,11 @@ class ValidateSchemaCommand extends Command */ protected function configure() { - $this - ->setName('orm:validate-schema') - ->setDescription('Validate the mapping files.') - ->addOption( - 'skip-mapping', - null, - InputOption::VALUE_NONE, - 'Skip the mapping validation check' - ) - ->addOption( - 'skip-sync', - null, - InputOption::VALUE_NONE, - 'Skip checking if the mapping is in sync with the database' - ) - ->setHelp( - <<setName('orm:validate-schema') + ->setDescription('Validate the mapping files') + ->addOption('skip-mapping', null, InputOption::VALUE_NONE, 'Skip the mapping validation check') + ->addOption('skip-sync', null, InputOption::VALUE_NONE, 'Skip checking if the mapping is in sync with the database') + ->setHelp('Validate that the mapping files are correct and in sync with the database.'); } /** From 8a893068cefe3e7400908512b21ec365bbd32653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Fri, 24 Nov 2017 00:56:42 +0100 Subject: [PATCH 635/877] Remove constants existence validation These constants are available since PHP 5.4 and since we're requiring PHP 7.1 there's no reason to require them. I've also simplified the `array_map()` call since it's useless to define a closure that simply calls a function. --- .../Console/Command/MappingDescribeCommand.php | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php index 8eca1019701..f6814407e0c 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php @@ -217,11 +217,7 @@ private function formatValue($value) } if (is_array($value)) { - if (defined('JSON_UNESCAPED_UNICODE') && defined('JSON_UNESCAPED_SLASHES')) { - return json_encode($value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); - } - - return json_encode($value); + return json_encode($value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); } if (is_object($value)) { @@ -283,14 +279,6 @@ private function formatMappings(array $propertyMappings) */ private function formatEntityListeners(array $entityListeners) { - return $this->formatField( - 'Entity listeners', - array_map( - function ($entityListener) { - return get_class($entityListener); - }, - $entityListeners - ) - ); + return $this->formatField('Entity listeners', array_map('get_class', $entityListeners)); } } From 43a88d539d5cdf495aab5704e6a29991c0f47615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Fri, 24 Nov 2017 01:13:52 +0100 Subject: [PATCH 636/877] Format commands' tests To simplify and organise the code (also replacing `$this->assert*` with `self::assert*`). --- .../ClearCacheCollectionRegionCommandTest.php | 69 ++++++++++--------- .../ClearCacheEntityRegionCommandTest.php | 63 +++++++++-------- .../ClearCacheQueryRegionCommandTest.php | 67 +++++++++--------- .../GenerateRepositoriesCommandTest.php | 64 +++++++---------- .../Tools/Console/Command/InfoCommandTest.php | 20 +++--- .../Command/MappingDescribeCommandTest.php | 30 ++++---- .../Console/Command/RunDqlCommandTest.php | 31 ++++----- 7 files changed, 165 insertions(+), 179 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheCollectionRegionCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheCollectionRegionCommandTest.php index 5ac2f97527d..f9290e7be4f 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheCollectionRegionCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheCollectionRegionCommandTest.php @@ -30,27 +30,24 @@ protected function setUp() $this->enableSecondLevelCache(); parent::setUp(); - $this->application = new Application(); - $this->command = new CollectionRegionCommand(); - - $this->application->setHelperSet(new HelperSet( - [ - 'em' => new EntityManagerHelper($this->_em) - ] - )); + $this->command = new CollectionRegionCommand(); + $this->application = new Application(); + $this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)])); $this->application->add($this->command); } public function testClearAllRegion() { - $command = $this->application->find('orm:clear-cache:region:collection'); - $tester = new CommandTester($command); + $command = $this->application->find('orm:clear-cache:region:collection'); + $tester = new CommandTester($command); + $tester->execute( [ - 'command' => $command->getName(), - '--all' => true, - ], ['decorated' => false] + 'command' => $command->getName(), + '--all' => true, + ], + ['decorated' => false] ); $this->assertEquals('Clearing all second-level cache collection regions' . PHP_EOL, $tester->getDisplay()); @@ -58,14 +55,16 @@ public function testClearAllRegion() public function testClearByOwnerEntityClassName() { - $command = $this->application->find('orm:clear-cache:region:collection'); - $tester = new CommandTester($command); + $command = $this->application->find('orm:clear-cache:region:collection'); + $tester = new CommandTester($command); + $tester->execute( [ - 'command' => $command->getName(), - 'owner-class' => State::class, - 'association' => 'cities', - ], ['decorated' => false] + 'command' => $command->getName(), + 'owner-class' => State::class, + 'association' => 'cities', + ], + ['decorated' => false] ); $this->assertEquals('Clearing second-level cache for collection "Doctrine\Tests\Models\Cache\State#cities"' . PHP_EOL, $tester->getDisplay()); @@ -73,15 +72,17 @@ public function testClearByOwnerEntityClassName() public function testClearCacheEntryName() { - $command = $this->application->find('orm:clear-cache:region:collection'); - $tester = new CommandTester($command); + $command = $this->application->find('orm:clear-cache:region:collection'); + $tester = new CommandTester($command); + $tester->execute( [ - 'command' => $command->getName(), - 'owner-class' => State::class, - 'association' => 'cities', - 'owner-id' => 1, - ], ['decorated' => false] + 'command' => $command->getName(), + 'owner-class' => State::class, + 'association' => 'cities', + 'owner-id' => 1, + ], + ['decorated' => false] ); $this->assertEquals('Clearing second-level cache entry for collection "Doctrine\Tests\Models\Cache\State#cities" owner entity identified by "1"' . PHP_EOL, $tester->getDisplay()); @@ -89,15 +90,17 @@ public function testClearCacheEntryName() public function testFlushRegionName() { - $command = $this->application->find('orm:clear-cache:region:collection'); - $tester = new CommandTester($command); + $command = $this->application->find('orm:clear-cache:region:collection'); + $tester = new CommandTester($command); + $tester->execute( [ - 'command' => $command->getName(), - 'owner-class' => State::class, - 'association' => 'cities', - '--flush' => true, - ], ['decorated' => false] + 'command' => $command->getName(), + 'owner-class' => State::class, + 'association' => 'cities', + '--flush' => true, + ], + ['decorated' => false] ); $this->assertEquals('Flushing cache provider configured for "Doctrine\Tests\Models\Cache\State#cities"' . PHP_EOL, $tester->getDisplay()); diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheEntityRegionCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheEntityRegionCommandTest.php index 3546a3116df..f0eed259576 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheEntityRegionCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheEntityRegionCommandTest.php @@ -30,27 +30,24 @@ protected function setUp() $this->enableSecondLevelCache(); parent::setUp(); - $this->application = new Application(); - $this->command = new EntityRegionCommand(); - - $this->application->setHelperSet(new HelperSet( - [ - 'em' => new EntityManagerHelper($this->_em) - ] - )); + $this->command = new EntityRegionCommand(); + $this->application = new Application(); + $this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)])); $this->application->add($this->command); } public function testClearAllRegion() { - $command = $this->application->find('orm:clear-cache:region:entity'); - $tester = new CommandTester($command); + $command = $this->application->find('orm:clear-cache:region:entity'); + $tester = new CommandTester($command); + $tester->execute( [ - 'command' => $command->getName(), - '--all' => true, - ], ['decorated' => false] + 'command' => $command->getName(), + '--all' => true, + ], + ['decorated' => false] ); $this->assertEquals('Clearing all second-level cache entity regions' . PHP_EOL, $tester->getDisplay()); @@ -58,13 +55,15 @@ public function testClearAllRegion() public function testClearByEntityClassName() { - $command = $this->application->find('orm:clear-cache:region:entity'); - $tester = new CommandTester($command); + $command = $this->application->find('orm:clear-cache:region:entity'); + $tester = new CommandTester($command); + $tester->execute( [ - 'command' => $command->getName(), - 'entity-class' => Country::class, - ], ['decorated' => false] + 'command' => $command->getName(), + 'entity-class' => Country::class, + ], + ['decorated' => false] ); $this->assertEquals('Clearing second-level cache for entity "Doctrine\Tests\Models\Cache\Country"' . PHP_EOL, $tester->getDisplay()); @@ -72,14 +71,16 @@ public function testClearByEntityClassName() public function testClearCacheEntryName() { - $command = $this->application->find('orm:clear-cache:region:entity'); - $tester = new CommandTester($command); + $command = $this->application->find('orm:clear-cache:region:entity'); + $tester = new CommandTester($command); + $tester->execute( [ - 'command' => $command->getName(), - 'entity-class' => Country::class, - 'entity-id' => 1, - ], ['decorated' => false] + 'command' => $command->getName(), + 'entity-class' => Country::class, + 'entity-id' => 1, + ], + ['decorated' => false] ); $this->assertEquals('Clearing second-level cache entry for entity "Doctrine\Tests\Models\Cache\Country" identified by "1"' . PHP_EOL, $tester->getDisplay()); @@ -87,14 +88,16 @@ public function testClearCacheEntryName() public function testFlushRegionName() { - $command = $this->application->find('orm:clear-cache:region:entity'); - $tester = new CommandTester($command); + $command = $this->application->find('orm:clear-cache:region:entity'); + $tester = new CommandTester($command); + $tester->execute( [ - 'command' => $command->getName(), - 'entity-class' => Country::class, - '--flush' => true, - ], ['decorated' => false] + 'command' => $command->getName(), + 'entity-class' => Country::class, + '--flush' => true, + ], + ['decorated' => false] ); $this->assertEquals('Flushing cache provider configured for entity named "Doctrine\Tests\Models\Cache\Country"' . PHP_EOL, $tester->getDisplay()); diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheQueryRegionCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheQueryRegionCommandTest.php index 0d296bf553f..f5eb4017f98 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheQueryRegionCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheQueryRegionCommandTest.php @@ -4,10 +4,10 @@ use Doctrine\ORM\Tools\Console\Command\ClearCache\QueryRegionCommand; use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; -use Symfony\Component\Console\Tester\CommandTester; -use Symfony\Component\Console\Helper\HelperSet; -use Symfony\Component\Console\Application; use Doctrine\Tests\OrmFunctionalTestCase; +use Symfony\Component\Console\Application; +use Symfony\Component\Console\Helper\HelperSet; +use Symfony\Component\Console\Tester\CommandTester; /** * @group DDC-2183 @@ -29,27 +29,24 @@ protected function setUp() $this->enableSecondLevelCache(); parent::setUp(); - $this->application = new Application(); - $this->command = new QueryRegionCommand(); - - $this->application->setHelperSet(new HelperSet( - [ - 'em' => new EntityManagerHelper($this->_em) - ] - )); + $this->command = new QueryRegionCommand(); + $this->application = new Application(); + $this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)])); $this->application->add($this->command); } public function testClearAllRegion() { - $command = $this->application->find('orm:clear-cache:region:query'); - $tester = new CommandTester($command); + $command = $this->application->find('orm:clear-cache:region:query'); + $tester = new CommandTester($command); + $tester->execute( [ - 'command' => $command->getName(), - '--all' => true, - ], ['decorated' => false] + 'command' => $command->getName(), + '--all' => true, + ], + ['decorated' => false] ); $this->assertEquals('Clearing all second-level cache query regions' . PHP_EOL, $tester->getDisplay()); @@ -57,13 +54,15 @@ public function testClearAllRegion() public function testClearDefaultRegionName() { - $command = $this->application->find('orm:clear-cache:region:query'); - $tester = new CommandTester($command); + $command = $this->application->find('orm:clear-cache:region:query'); + $tester = new CommandTester($command); + $tester->execute( [ - 'command' => $command->getName(), - 'region-name' => null, - ], ['decorated' => false] + 'command' => $command->getName(), + 'region-name' => null, + ], + ['decorated' => false] ); $this->assertEquals('Clearing second-level cache query region named "query_cache_region"' . PHP_EOL, $tester->getDisplay()); @@ -71,13 +70,15 @@ public function testClearDefaultRegionName() public function testClearByRegionName() { - $command = $this->application->find('orm:clear-cache:region:query'); - $tester = new CommandTester($command); + $command = $this->application->find('orm:clear-cache:region:query'); + $tester = new CommandTester($command); + $tester->execute( [ - 'command' => $command->getName(), - 'region-name' => 'my_region', - ], ['decorated' => false] + 'command' => $command->getName(), + 'region-name' => 'my_region', + ], + ['decorated' => false] ); $this->assertEquals('Clearing second-level cache query region named "my_region"' . PHP_EOL, $tester->getDisplay()); @@ -85,14 +86,16 @@ public function testClearByRegionName() public function testFlushRegionName() { - $command = $this->application->find('orm:clear-cache:region:query'); - $tester = new CommandTester($command); + $command = $this->application->find('orm:clear-cache:region:query'); + $tester = new CommandTester($command); + $tester->execute( [ - 'command' => $command->getName(), - 'region-name' => 'my_region', - '--flush' => true, - ], ['decorated' => false] + 'command' => $command->getName(), + 'region-name' => 'my_region', + '--flush' => true, + ], + ['decorated' => false] ); $this->assertEquals('Flushing cache provider configured for second-level cache query region named "my_region"' . PHP_EOL, $tester->getDisplay()); diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php index 45bdfa3862f..64c81ddfec8 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php @@ -2,18 +2,18 @@ namespace Doctrine\Tests\ORM\Tools\Console\Command; +use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory; +use Doctrine\ORM\Configuration; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand; use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; use Doctrine\Tests\Models\DDC3231\DDC3231EntityRepository; -use Symfony\Component\Console\Tester\CommandTester; -use Symfony\Component\Console\Helper\HelperSet; -use Symfony\Component\Console\Application; use Doctrine\Tests\OrmFunctionalTestCase; +use Symfony\Component\Console\Application; +use Symfony\Component\Console\Helper\HelperSet; +use Symfony\Component\Console\Tester\CommandTester; -/** - * GenerateRepositoriesCommandTest - */ class GenerateRepositoriesCommandTest extends OrmFunctionalTestCase { /** @@ -34,25 +34,12 @@ protected function setUp() \mkdir($this->path); - $metadataDriver = $this->_em->getConfiguration()->getMetadataDriverImpl(); - - $metadataDriver->addPaths( - [ - __DIR__ . '/../../../../Models/DDC3231/' - ] - ); + $metadataDriver->addPaths([__DIR__ . '/../../../../Models/DDC3231/']); $this->application = new Application(); - - $this->application->setHelperSet(new HelperSet( - [ - 'em' => new EntityManagerHelper($this->_em) - ] - )); - + $this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)])); $this->application->add(new GenerateRepositoriesCommand()); - } /** @@ -88,20 +75,20 @@ public function testGenerateRepositories() $cname = 'Doctrine\Tests\Models\DDC3231\DDC3231User1Repository'; $fname = str_replace('\\', DIRECTORY_SEPARATOR, $cname) . '.php'; - $this->assertFileExists($this->path . DIRECTORY_SEPARATOR . $fname); - $this->assertFileExists($this->path . DIRECTORY_SEPARATOR . 'DDC3231User1NoNamespaceRepository.php'); + self::assertFileExists($this->path . DIRECTORY_SEPARATOR . $fname); + self::assertFileExists($this->path . DIRECTORY_SEPARATOR . 'DDC3231User1NoNamespaceRepository.php'); require $this->path . DIRECTORY_SEPARATOR . $fname; require $this->path . DIRECTORY_SEPARATOR . 'DDC3231User1NoNamespaceRepository.php'; - $this->assertTrue(class_exists($cname)); - $this->assertTrue(class_exists('DDC3231User1NoNamespaceRepository')); + self::assertTrue(class_exists($cname)); + self::assertTrue(class_exists('DDC3231User1NoNamespaceRepository')); $repo1 = new \ReflectionClass($cname); $repo2 = new \ReflectionClass('DDC3231User1NoNamespaceRepository'); - $this->assertSame(EntityRepository::class, $repo1->getParentClass()->getName()); - $this->assertSame(EntityRepository::class, $repo2->getParentClass()->getName()); + self::assertSame(EntityRepository::class, $repo1->getParentClass()->getName()); + self::assertSame(EntityRepository::class, $repo2->getParentClass()->getName()); } public function testGenerateRepositoriesCustomDefaultRepository() @@ -111,20 +98,20 @@ public function testGenerateRepositoriesCustomDefaultRepository() $cname = 'Doctrine\Tests\Models\DDC3231\DDC3231User2Repository'; $fname = str_replace('\\', DIRECTORY_SEPARATOR, $cname) . '.php'; - $this->assertFileExists($this->path . DIRECTORY_SEPARATOR . $fname); - $this->assertFileExists($this->path . DIRECTORY_SEPARATOR . 'DDC3231User2NoNamespaceRepository.php'); + self::assertFileExists($this->path . DIRECTORY_SEPARATOR . $fname); + self::assertFileExists($this->path . DIRECTORY_SEPARATOR . 'DDC3231User2NoNamespaceRepository.php'); require $this->path . DIRECTORY_SEPARATOR . $fname; require $this->path . DIRECTORY_SEPARATOR . 'DDC3231User2NoNamespaceRepository.php'; - $this->assertTrue(class_exists($cname)); - $this->assertTrue(class_exists('DDC3231User2NoNamespaceRepository')); + self::assertTrue(class_exists($cname)); + self::assertTrue(class_exists('DDC3231User2NoNamespaceRepository')); $repo1 = new \ReflectionClass($cname); $repo2 = new \ReflectionClass('DDC3231User2NoNamespaceRepository'); - $this->assertSame(DDC3231EntityRepository::class, $repo1->getParentClass()->getName()); - $this->assertSame(DDC3231EntityRepository::class, $repo2->getParentClass()->getName()); + self::assertSame(DDC3231EntityRepository::class, $repo1->getParentClass()->getName()); + self::assertSame(DDC3231EntityRepository::class, $repo2->getParentClass()->getName()); } /** @@ -137,13 +124,14 @@ private function generateRepositories($filter, $defaultRepository = null) $this->_em->getConfiguration()->setDefaultRepositoryClassName($defaultRepository); } - $command = $this->application->find('orm:generate-repositories'); - $tester = new CommandTester($command); + $command = $this->application->find('orm:generate-repositories'); + $tester = new CommandTester($command); + $tester->execute( [ - 'command' => $command->getName(), - 'dest-path' => $this->path, - '--filter' => $filter, + 'command' => $command->getName(), + 'dest-path' => $this->path, + '--filter' => $filter, ] ); } diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/InfoCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/InfoCommandTest.php index a27fb90d79a..240378a6ad5 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/InfoCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/InfoCommandTest.php @@ -2,6 +2,10 @@ namespace Doctrine\Tests\ORM\Tools\Console\Command; +use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; +use Doctrine\ORM\Configuration; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Mapping\MappingException; use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; use Doctrine\Tests\Models\Cache\AttractionInfo; use Doctrine\Tests\Models\Cache\City; @@ -33,23 +37,19 @@ protected function setUp() parent::setUp(); $this->application = new Application(); - $command = new InfoCommand(); - $this->application->setHelperSet( - new HelperSet(['em' => new EntityManagerHelper($this->_em)]) - ); + $this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)])); + $this->application->add(new InfoCommand()); - $this->application->add($command); - - $this->command = $this->application->find('orm:info'); - $this->tester = new CommandTester($command); + $this->command = $this->application->find('orm:info'); + $this->tester = new CommandTester($this->command); } public function testListAllClasses() { $this->tester->execute(['command' => $this->command->getName()]); - $this->assertContains(AttractionInfo::class, $this->tester->getDisplay()); - $this->assertContains(City::class, $this->tester->getDisplay()); + self::assertContains(AttractionInfo::class, $this->tester->getDisplay()); + self::assertContains(City::class, $this->tester->getDisplay()); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/MappingDescribeCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/MappingDescribeCommandTest.php index 437f521e3d7..f73456b47ab 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/MappingDescribeCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/MappingDescribeCommandTest.php @@ -37,32 +37,26 @@ protected function setUp() parent::setUp(); $this->application = new Application(); - $command = new MappingDescribeCommand(); - - $this->application->setHelperSet(new HelperSet( - [ - 'em' => new EntityManagerHelper($this->_em) - ] - )); - - $this->application->add($command); + $this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)])); + $this->application->add(new MappingDescribeCommand()); $this->command = $this->application->find('orm:mapping:describe'); - $this->tester = new CommandTester($command); + $this->tester = new CommandTester($this->command); } public function testShowSpecificFuzzySingle() { $this->tester->execute( [ - 'command' => $this->command->getName(), - 'entityName' => 'AttractionInfo', + 'command' => $this->command->getName(), + 'entityName' => 'AttractionInfo', ] ); $display = $this->tester->getDisplay(); - $this->assertContains(AttractionInfo::class, $display); - $this->assertContains('Root entity name', $display); + + self::assertContains(AttractionInfo::class, $display); + self::assertContains('Root entity name', $display); } /** @@ -73,8 +67,8 @@ public function testShowSpecificFuzzyAmbiguous() { $this->tester->execute( [ - 'command' => $this->command->getName(), - 'entityName' => 'Attraction', + 'command' => $this->command->getName(), + 'entityName' => 'Attraction', ] ); } @@ -87,8 +81,8 @@ public function testShowSpecificNotFound() { $this->tester->execute( [ - 'command' => $this->command->getName(), - 'entityName' => 'AttractionFooBar' + 'command' => $this->command->getName(), + 'entityName' => 'AttractionFooBar', ] ); } diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php index e2e68bd7e28..298ff886ed0 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php @@ -38,15 +38,10 @@ protected function setUp() parent::setUp(); - $this->application = new Application(); - $this->command = new RunDqlCommand(); - - $this->application->setHelperSet(new HelperSet( - [ - 'em' => new EntityManagerHelper($this->_em) - ] - )); + $this->command = new RunDqlCommand(); + $this->application = new Application(); + $this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)])); $this->application->add($this->command); $this->tester = new CommandTester($this->command); @@ -54,7 +49,7 @@ protected function setUp() public function testCommandName() { - $this->assertSame($this->command, $this->application->get('orm:run-dql')); + self::assertSame($this->command, $this->application->get('orm:run-dql')); } public function testWillRunQuery() @@ -62,17 +57,17 @@ public function testWillRunQuery() $this->_em->persist(new DateTimeModel()); $this->_em->flush(); - $this->assertSame( + self::assertSame( 0, $this->tester->execute( [ - 'command' => $this->command->getName(), - 'dql' => 'SELECT e FROM ' . DateTimeModel::class . ' e', + 'command' => $this->command->getName(), + 'dql' => 'SELECT e FROM ' . DateTimeModel::class . ' e', ] ) ); - $this->assertContains(DateTimeModel::class, $this->tester->getDisplay()); + self::assertContains(DateTimeModel::class, $this->tester->getDisplay()); } public function testWillShowQuery() @@ -80,17 +75,17 @@ public function testWillShowQuery() $this->_em->persist(new DateTimeModel()); $this->_em->flush(); - $this->assertSame( + self::assertSame( 0, $this->tester->execute( [ - 'command' => $this->command->getName(), - 'dql' => 'SELECT e FROM ' . DateTimeModel::class . ' e', - '--show-sql' => 'true' + 'command' => $this->command->getName(), + 'dql' => 'SELECT e FROM ' . DateTimeModel::class . ' e', + '--show-sql' => 'true', ] ) ); - $this->assertStringMatchesFormat('%Astring%sSELECT %a', $this->tester->getDisplay()); + self::assertStringMatchesFormat('%Astring%sSELECT %a', $this->tester->getDisplay()); } } From 6b5eb11458283aca6fdc2a0a21dbaca0a29e7796 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Thu, 23 Nov 2017 11:18:21 +0100 Subject: [PATCH 637/877] Use SymfonyStyle for command output --- .../ClearCache/CollectionRegionCommand.php | 24 +++++-- .../ClearCache/EntityRegionCommand.php | 17 +++-- .../Command/ClearCache/MetadataCommand.php | 16 ++++- .../Command/ClearCache/QueryCommand.php | 15 ++++- .../Command/ClearCache/QueryRegionCommand.php | 14 +++- .../Command/ClearCache/ResultCommand.php | 15 ++++- .../Console/Command/ConvertMappingCommand.php | 33 +++++---- .../EnsureProductionSettingsCommand.php | 9 ++- .../Command/GenerateEntitiesCommand.php | 57 ++++++++-------- .../Command/GenerateProxiesCommand.php | 29 ++++---- .../Command/GenerateRepositoriesCommand.php | 44 ++++++------ .../ORM/Tools/Console/Command/InfoCommand.php | 28 +++++--- .../Command/MappingDescribeCommand.php | 20 +++--- .../Tools/Console/Command/RunDqlCommand.php | 7 +- .../Command/SchemaTool/AbstractCommand.php | 16 ++--- .../Command/SchemaTool/CreateCommand.php | 29 +++++--- .../Command/SchemaTool/DropCommand.php | 48 ++++++++----- .../Command/SchemaTool/UpdateCommand.php | 52 +++++++++----- .../Console/Command/ValidateSchemaCommand.php | 33 +++++---- phpunit.xml.dist | 4 ++ .../ClearCacheCollectionRegionCommandTest.php | 19 ++++-- .../ClearCacheEntityRegionCommandTest.php | 19 ++++-- .../ClearCacheQueryRegionCommandTest.php | 17 +++-- .../GenerateRepositoriesCommandTest.php | 34 ++++++++++ .../Tools/Console/Command/InfoCommandTest.php | 67 +++++++++++++++++++ .../Console/Command/RunDqlCommandTest.php | 2 +- tests/travis/mariadb.travis.xml | 2 + tests/travis/mysql.travis.xml | 2 + tests/travis/pgsql.travis.xml | 2 + tests/travis/sqlite.travis.xml | 4 ++ 30 files changed, 489 insertions(+), 189 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/CollectionRegionCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/CollectionRegionCommand.php index 8c73cf79356..33f003a19a7 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/CollectionRegionCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/CollectionRegionCommand.php @@ -26,6 +26,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; /** * Command to clear a collection cache region. @@ -79,6 +80,8 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $ui = new SymfonyStyle($input, $output); + $em = $this->getHelper('em')->getEntityManager(); $ownerClass = $input->getArgument('owner-class'); $assoc = $input->getArgument('association'); @@ -105,13 +108,19 @@ protected function execute(InputInterface $input, OutputInterface $output) $collectionRegion->getCache()->flushAll(); - $output->writeln(sprintf('Flushing cache provider configured for "%s#%s"', $ownerClass, $assoc)); + $ui->comment( + sprintf( + 'Flushing cache provider configured for "%s#%s"', + $ownerClass, + $assoc + ) + ); return; } if ($input->getOption('all')) { - $output->writeln('Clearing all second-level cache collection regions'); + $ui->comment('Clearing all second-level cache collection regions'); $cache->evictEntityRegions(); @@ -119,13 +128,20 @@ protected function execute(InputInterface $input, OutputInterface $output) } if ($ownerId) { - $output->writeln(sprintf('Clearing second-level cache entry for collection "%s#%s" owner entity identified by "%s"', $ownerClass, $assoc, $ownerId)); + $ui->comment( + sprintf( + 'Clearing second-level cache entry for collection "%s#%s" owner entity identified by "%s"', + $ownerClass, + $assoc, + $ownerId + ) + ); $cache->evictCollection($ownerClass, $assoc, $ownerId); return; } - $output->writeln(sprintf('Clearing second-level cache for collection "%s#%s"', $ownerClass, $assoc)); + $ui->comment(sprintf('Clearing second-level cache for collection "%s#%s"', $ownerClass, $assoc)); $cache->evictCollectionRegion($ownerClass, $assoc); } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/EntityRegionCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/EntityRegionCommand.php index ff9e3688b27..67a73093fc8 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/EntityRegionCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/EntityRegionCommand.php @@ -26,6 +26,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; /** * Command to clear a entity cache region. @@ -78,6 +79,8 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $ui = new SymfonyStyle($input, $output); + $em = $this->getHelper('em')->getEntityManager(); $entityClass = $input->getArgument('entity-class'); $entityId = $input->getArgument('entity-id'); @@ -103,13 +106,13 @@ protected function execute(InputInterface $input, OutputInterface $output) $entityRegion->getCache()->flushAll(); - $output->writeln(sprintf('Flushing cache provider configured for entity named "%s"', $entityClass)); + $ui->comment(sprintf('Flushing cache provider configured for entity named "%s"', $entityClass)); return; } if ($input->getOption('all')) { - $output->writeln('Clearing all second-level cache entity regions'); + $ui->comment('Clearing all second-level cache entity regions'); $cache->evictEntityRegions(); @@ -117,13 +120,19 @@ protected function execute(InputInterface $input, OutputInterface $output) } if ($entityId) { - $output->writeln(sprintf('Clearing second-level cache entry for entity "%s" identified by "%s"', $entityClass, $entityId)); + $ui->comment( + sprintf( + 'Clearing second-level cache entry for entity "%s" identified by "%s"', + $entityClass, + $entityId + ) + ); $cache->evictEntity($entityClass, $entityId); return; } - $output->writeln(sprintf('Clearing second-level cache for entity "%s"', $entityClass)); + $ui->comment(sprintf('Clearing second-level cache for entity "%s"', $entityClass)); $cache->evictEntityRegion($entityClass); } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/MetadataCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/MetadataCommand.php index 64b6a0615e5..e6531f22212 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/MetadataCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/MetadataCommand.php @@ -25,6 +25,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; /** * Command to clear the metadata cache of the various cache drivers. @@ -71,6 +72,8 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $ui = new SymfonyStyle($input, $output); + $em = $this->getHelper('em')->getEntityManager(); $cacheDriver = $em->getConfiguration()->getMetadataCacheImpl(); @@ -86,8 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output) throw new \LogicException("Cannot clear XCache Cache from Console, its shared in the Webserver memory and not accessible from the CLI."); } - - $output->writeln('Clearing ALL Metadata cache entries'); + $ui->comment('Clearing all Metadata cache entries'); $result = $cacheDriver->deleteAll(); $message = ($result) ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.'; @@ -97,6 +99,14 @@ protected function execute(InputInterface $input, OutputInterface $output) $message = ($result) ? 'Successfully flushed cache entries.' : $message; } - $output->writeln($message); + if ( ! $result) { + $ui->error($message); + + return 1; + } + + $ui->success($message); + + return 0; } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php index b4619bd7fd6..95bec91de8d 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php @@ -25,6 +25,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; /** * Command to clear the query cache of the various cache drivers. @@ -71,6 +72,8 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $ui = new SymfonyStyle($input, $output); + $em = $this->getHelper('em')->getEntityManager(); $cacheDriver = $em->getConfiguration()->getQueryCacheImpl(); @@ -85,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output) throw new \LogicException("Cannot clear XCache Cache from Console, its shared in the Webserver memory and not accessible from the CLI."); } - $output->write('Clearing ALL Query cache entries' . PHP_EOL); + $ui->comment('Clearing all Query cache entries'); $result = $cacheDriver->deleteAll(); $message = ($result) ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.'; @@ -95,6 +98,14 @@ protected function execute(InputInterface $input, OutputInterface $output) $message = ($result) ? 'Successfully flushed cache entries.' : $message; } - $output->write($message . PHP_EOL); + if ( ! $result) { + $ui->error($message); + + return 1; + } + + $ui->success($message); + + return 0; } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryRegionCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryRegionCommand.php index 9492958b1ce..f1578bc641c 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryRegionCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryRegionCommand.php @@ -26,6 +26,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; /** * Command to clear a query cache region. @@ -77,6 +78,8 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $ui = new SymfonyStyle($input, $output); + $em = $this->getHelper('em')->getEntityManager(); $name = $input->getArgument('region-name'); $cache = $em->getCache(); @@ -102,20 +105,25 @@ protected function execute(InputInterface $input, OutputInterface $output) $queryRegion->getCache()->flushAll(); - $output->writeln(sprintf('Flushing cache provider configured for second-level cache query region named "%s"', $name)); + $ui->comment( + sprintf( + 'Flushing cache provider configured for second-level cache query region named "%s"', + $name + ) + ); return; } if ($input->getOption('all')) { - $output->writeln('Clearing all second-level cache query regions'); + $ui->comment('Clearing all second-level cache query regions'); $cache->evictQueryRegions(); return; } - $output->writeln(sprintf('Clearing second-level cache query region named "%s"', $name)); + $ui->comment(sprintf('Clearing second-level cache query region named "%s"', $name)); $cache->evictQueryRegion($name); } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/ResultCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/ResultCommand.php index 6b00c12336c..42ad79c502c 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/ResultCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/ResultCommand.php @@ -25,6 +25,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; /** * Command to clear the result cache of the various cache drivers. @@ -71,6 +72,8 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $ui = new SymfonyStyle($input, $output); + $em = $this->getHelper('em')->getEntityManager(); $cacheDriver = $em->getConfiguration()->getResultCacheImpl(); @@ -86,7 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output) throw new \LogicException("Cannot clear XCache Cache from Console, its shared in the Webserver memory and not accessible from the CLI."); } - $output->writeln('Clearing ALL Result cache entries'); + $ui->comment('Clearing all Result cache entries'); $result = $cacheDriver->deleteAll(); $message = ($result) ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.'; @@ -96,6 +99,14 @@ protected function execute(InputInterface $input, OutputInterface $output) $message = ($result) ? 'Successfully flushed cache entries.' : $message; } - $output->writeln($message); + if ( ! $result) { + $ui->error($message); + + return 1; + } + + $ui->success($message); + + return 0; } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php index 6b9153f0130..f6756641141 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php @@ -29,6 +29,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; /** * Command to convert your mapping information between the various formats. @@ -89,6 +90,8 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $ui = new SymfonyStyle($input, $output); + $em = $this->getHelper('em')->getEntityManager(); if ($input->getOption('from-database') === true) { @@ -144,20 +147,26 @@ protected function execute(InputInterface $input, OutputInterface $output) } } - if (count($metadata)) { - foreach ($metadata as $class) { - $output->writeln(sprintf('Processing entity "%s"', $class->name)); - } - - $exporter->setMetadata($metadata); - $exporter->export(); + if (empty($metadata)) { + $ui->success('No Metadata Classes to process.'); + return; + } - $output->writeln(PHP_EOL . sprintf( - 'Exporting "%s" mapping information to "%s"', $toType, $destPath - )); - } else { - $output->writeln('No Metadata Classes to process.'); + foreach ($metadata as $class) { + $ui->text(sprintf('Processing entity "%s"', $class->name)); } + + $exporter->setMetadata($metadata); + $exporter->export(); + + $ui->newLine(); + $ui->text( + sprintf( + 'Exporting "%s" mapping information to "%s"', + $toType, + $destPath + ) + ); } /** diff --git a/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php index 0a986bce1d9..eb0ff17567d 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php @@ -23,6 +23,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; use Throwable; /** @@ -54,6 +55,8 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $ui = new SymfonyStyle($input, $output); + $em = $this->getHelper('em')->getEntityManager(); try { @@ -63,11 +66,13 @@ protected function execute(InputInterface $input, OutputInterface $output) $em->getConnection()->connect(); } } catch (Throwable $e) { - $output->writeln('' . $e->getMessage() . ''); + $ui->error($e->getMessage()); return 1; } - $output->writeln('Environment is correctly configured for production.'); + $ui->success('Environment is correctly configured for production.'); + + return 0; } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php index 58d19774ce6..063cb244ce7 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php @@ -27,6 +27,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; /** * Command to generate entity classes and method stubs from your mapping information. @@ -85,6 +86,8 @@ class is supposed to extend which. You have to adjust the entity */ protected function execute(InputInterface $input, OutputInterface $output) { + $ui = new SymfonyStyle($input, $output); + $em = $this->getHelper('em')->getEntityManager(); $cmf = new DisconnectedClassMetadataFactory(); @@ -107,33 +110,33 @@ protected function execute(InputInterface $input, OutputInterface $output) ); } - if (count($metadatas)) { - $entityGenerator = new EntityGenerator(); - - $entityGenerator->setGenerateAnnotations($input->getOption('generate-annotations')); - $entityGenerator->setGenerateStubMethods($input->getOption('generate-methods')); - $entityGenerator->setRegenerateEntityIfExists($input->getOption('regenerate-entities')); - $entityGenerator->setUpdateEntityIfExists($input->getOption('update-entities')); - $entityGenerator->setNumSpaces($input->getOption('num-spaces')); - $entityGenerator->setBackupExisting(!$input->getOption('no-backup')); - - if (($extend = $input->getOption('extend')) !== null) { - $entityGenerator->setClassToExtend($extend); - } - - foreach ($metadatas as $metadata) { - $output->writeln( - sprintf('Processing entity "%s"', $metadata->name) - ); - } - - // Generating Entities - $entityGenerator->generate($metadatas, $destPath); - - // Outputting information message - $output->writeln(PHP_EOL . sprintf('Entity classes generated to "%s"', $destPath)); - } else { - $output->writeln('No Metadata Classes to process.'); + if (empty($metadatas)) { + $ui->success('No Metadata Classes to process.'); + return; + } + + $entityGenerator = new EntityGenerator(); + + $entityGenerator->setGenerateAnnotations($input->getOption('generate-annotations')); + $entityGenerator->setGenerateStubMethods($input->getOption('generate-methods')); + $entityGenerator->setRegenerateEntityIfExists($input->getOption('regenerate-entities')); + $entityGenerator->setUpdateEntityIfExists($input->getOption('update-entities')); + $entityGenerator->setNumSpaces($input->getOption('num-spaces')); + $entityGenerator->setBackupExisting(!$input->getOption('no-backup')); + + if (($extend = $input->getOption('extend')) !== null) { + $entityGenerator->setClassToExtend($extend); } + + foreach ($metadatas as $metadata) { + $ui->text(sprintf('Processing entity "%s"', $metadata->name)); + } + + // Generating Entities + $entityGenerator->generate($metadatas, $destPath); + + // Outputting information message + $ui->newLine(); + $ui->success(sprintf('Entity classes generated to "%s"', $destPath)); } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php index 682b0fc4cf0..c792b0067a0 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php @@ -26,6 +26,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; /** * Command to (re)generate the proxy classes used by doctrine. @@ -57,6 +58,8 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $ui = new SymfonyStyle($input, $output); + /** @var EntityManagerInterface $em */ $em = $this->getHelper('em')->getEntityManager(); @@ -86,20 +89,20 @@ protected function execute(InputInterface $input, OutputInterface $output) ); } - if ( count($metadatas)) { - foreach ($metadatas as $metadata) { - $output->writeln( - sprintf('Processing entity "%s"', $metadata->name) - ); - } - - // Generating Proxies - $em->getProxyFactory()->generateProxyClasses($metadatas, $destPath); + if (empty($metadatas)) { + $ui->success('No Metadata Classes to process.'); + return; + } - // Outputting information message - $output->writeln(PHP_EOL . sprintf('Proxy classes generated to "%s"', $destPath)); - } else { - $output->writeln('No Metadata Classes to process.'); + foreach ($metadatas as $metadata) { + $ui->text(sprintf('Processing entity "%s"', $metadata->name)); } + + // Generating Proxies + $em->getProxyFactory()->generateProxyClasses($metadatas, $destPath); + + // Outputting information message + $ui->newLine(); + $ui->text(sprintf('Proxy classes generated to "%s"', $destPath)); } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php index 81081a4426e..787fb8bc50f 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php @@ -26,6 +26,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; /** * Command to generate repository classes for mapping information. @@ -57,6 +58,8 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $ui = new SymfonyStyle($input, $output); + $em = $this->getHelper('em')->getEntityManager(); $metadatas = $em->getMetadataFactory()->getAllMetadata(); @@ -79,32 +82,33 @@ protected function execute(InputInterface $input, OutputInterface $output) ); } - if (count($metadatas)) { - $numRepositories = 0; - $generator = new EntityRepositoryGenerator(); + if (empty($metadatas)) { + $ui->success('No Metadata Classes to process.'); + return; + } - $generator->setDefaultRepositoryName($repositoryName); + $numRepositories = 0; + $generator = new EntityRepositoryGenerator(); - foreach ($metadatas as $metadata) { - if ($metadata->customRepositoryClassName) { - $output->writeln( - sprintf('Processing repository "%s"', $metadata->customRepositoryClassName) - ); + $generator->setDefaultRepositoryName($repositoryName); - $generator->writeEntityRepositoryClass($metadata->customRepositoryClassName, $destPath); + foreach ($metadatas as $metadata) { + if ($metadata->customRepositoryClassName) { + $ui->text(sprintf('Processing repository "%s"', $metadata->customRepositoryClassName)); - $numRepositories++; - } - } + $generator->writeEntityRepositoryClass($metadata->customRepositoryClassName, $destPath); - if ($numRepositories) { - // Outputting information message - $output->writeln(PHP_EOL . sprintf('Repository classes generated to "%s"', $destPath)); - } else { - $output->writeln('No Repository classes were found to be processed.'); + ++$numRepositories; } - } else { - $output->writeln('No Metadata Classes to process.'); } + + if ($numRepositories === 0) { + $ui->text('No Repository classes were found to be processed.'); + return; + } + + // Outputting information message + $ui->newLine(); + $ui->text(sprintf('Repository classes generated to "%s"', $destPath)); } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/InfoCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/InfoCommand.php index 6cf73ee76d0..89f6c318576 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/InfoCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/InfoCommand.php @@ -23,6 +23,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; /** * Show information about mapped entities. @@ -53,6 +54,8 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $ui = new SymfonyStyle($input, $output); + /* @var $entityManager \Doctrine\ORM\EntityManager */ $entityManager = $this->getHelper('em')->getEntityManager(); @@ -61,24 +64,33 @@ protected function execute(InputInterface $input, OutputInterface $output) ->getAllClassNames(); if ( ! $entityClassNames) { - throw new \Exception( - 'You do not have any mapped Doctrine ORM entities according to the current configuration. '. - 'If you have entities or mapping files you should check your mapping configuration for errors.' + $ui->caution( + [ + 'You do not have any mapped Doctrine ORM entities according to the current configuration.', + 'If you have entities or mapping files you should check your mapping configuration for errors.' + ] ); + + return 1; } - $output->writeln(sprintf("Found %d mapped entities:", count($entityClassNames))); + $ui->text(sprintf("Found %d mapped entities:", count($entityClassNames))); + $ui->newLine(); $failure = false; foreach ($entityClassNames as $entityClassName) { try { $entityManager->getClassMetadata($entityClassName); - $output->writeln(sprintf("[OK] %s", $entityClassName)); + $ui->text(sprintf("[OK] %s", $entityClassName)); } catch (MappingException $e) { - $output->writeln("[FAIL] ".$entityClassName); - $output->writeln(sprintf("%s", $e->getMessage())); - $output->writeln(''); + $ui->text( + [ + sprintf("[FAIL] %s", $entityClassName), + sprintf("%s", $e->getMessage()), + '' + ] + ); $failure = true; } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php index f6814407e0c..355246731f4 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php @@ -22,10 +22,10 @@ use Doctrine\Common\Persistence\Mapping\MappingException; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; /** * Show information about mapped entities. @@ -61,10 +61,12 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $ui = new SymfonyStyle($input, $output); + /* @var $entityManager \Doctrine\ORM\EntityManagerInterface */ $entityManager = $this->getHelper('em')->getEntityManager(); - $this->displayEntity($input->getArgument('entityName'), $entityManager, $output); + $this->displayEntity($input->getArgument('entityName'), $entityManager, $ui); return 0; } @@ -74,18 +76,14 @@ protected function execute(InputInterface $input, OutputInterface $output) * * @param string $entityName Full or partial entity class name * @param EntityManagerInterface $entityManager - * @param OutputInterface $output + * @param SymfonyStyle $ui */ - private function displayEntity($entityName, EntityManagerInterface $entityManager, OutputInterface $output) + private function displayEntity($entityName, EntityManagerInterface $entityManager, SymfonyStyle $ui) { - $table = new Table($output); - - $table->setHeaders(['Field', 'Value']); - $metadata = $this->getClassMetadata($entityName, $entityManager); - array_map( - [$table, 'addRow'], + $ui->table( + ['Field', 'Value'], array_merge( [ $this->formatField('Name', $metadata->name), @@ -124,8 +122,6 @@ private function displayEntity($entityName, EntityManagerInterface $entityManage $this->formatMappings($metadata->fieldMappings) ) ); - - $table->render(); } /** diff --git a/lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php index 14191515bab..4e6b69bb42b 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php @@ -25,6 +25,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; /** * Command to execute DQL queries in a given EntityManager. @@ -59,6 +60,8 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $ui = new SymfonyStyle($input, $output); + /* @var $em \Doctrine\ORM\EntityManagerInterface */ $em = $this->getHelper('em')->getEntityManager(); @@ -100,12 +103,12 @@ protected function execute(InputInterface $input, OutputInterface $output) } if ($input->getOption('show-sql')) { - $output->writeln(Debug::dump($query->getSQL(), 2, true, false)); + $ui->text($query->getSQL()); return; } $resultSet = $query->execute([], constant($hydrationMode)); - $output->writeln(Debug::dump($resultSet, $input->getOption('depth'), true, false)); + $ui->text(Debug::dump($resultSet, $input->getOption('depth'), true, false)); } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php index ed9d754ed41..21907d094a1 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php @@ -23,6 +23,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; /** * Base class for CreateCommand, DropCommand and UpdateCommand. @@ -44,13 +45,15 @@ abstract class AbstractCommand extends Command * * @return null|int Null or 0 if everything went fine, or an error code. */ - abstract protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas); + abstract protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas, SymfonyStyle $ui); /** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { + $ui = new SymfonyStyle($input, $output); + $emHelper = $this->getHelper('em'); /* @var $em \Doctrine\ORM\EntityManager */ @@ -58,15 +61,12 @@ protected function execute(InputInterface $input, OutputInterface $output) $metadatas = $em->getMetadataFactory()->getAllMetadata(); - if ( ! empty($metadatas)) { - // Create SchemaTool - $tool = new SchemaTool($em); - - return $this->executeSchemaCommand($input, $output, $tool, $metadatas); - } else { - $output->writeln('No Metadata Classes to process.'); + if (empty($metadatas)) { + $ui->success('No Metadata Classes to process.'); return 0; } + + return $this->executeSchemaCommand($input, $output, new SchemaTool($em), $metadatas, $ui); } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/CreateCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/CreateCommand.php index a4486469daa..0c2137417b3 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/CreateCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/CreateCommand.php @@ -23,6 +23,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; /** * Command to create the database schema for a set of classes based on their mappings. @@ -59,19 +60,31 @@ protected function configure() /** * {@inheritdoc} */ - protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas) + protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas, SymfonyStyle $ui) { - if ($input->getOption('dump-sql')) { + $dumpSql = true === $input->getOption('dump-sql'); + + if ($dumpSql) { $sqls = $schemaTool->getCreateSchemaSql($metadatas); - $output->writeln(implode(';' . PHP_EOL, $sqls) . ';'); - } else { - $output->writeln('ATTENTION: This operation should not be executed in a production environment.' . PHP_EOL); + $ui->text('The following SQL statements will be executed:'); + $ui->newLine(); + + foreach ($sqls as $sql) { + $ui->text(sprintf(' %s;', $sql)); + } - $output->writeln('Creating database schema...'); - $schemaTool->createSchema($metadatas); - $output->writeln('Database schema created successfully!'); + return 0; } + $ui->caution('This operation should not be executed in a production environment!'); + + $ui->text('Creating database schema...'); + $ui->newLine(); + + $schemaTool->createSchema($metadatas); + + $ui->success('Database schema created successfully!'); + return 0; } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/DropCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/DropCommand.php index be4d55a950b..3d77fc8fd84 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/DropCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/DropCommand.php @@ -23,6 +23,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; /** * Command to drop the database schema for a set of classes based on their mappings. @@ -62,23 +63,31 @@ protected function configure() /** * {@inheritdoc} */ - protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas) + protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas, SymfonyStyle $ui) { $isFullDatabaseDrop = $input->getOption('full-database'); + $dumpSql = true === $input->getOption('dump-sql'); + $force = true === $input->getOption('force'); - if ($input->getOption('dump-sql')) { + if ($dumpSql) { if ($isFullDatabaseDrop) { $sqls = $schemaTool->getDropDatabaseSQL(); } else { $sqls = $schemaTool->getDropSchemaSQL($metadatas); } - $output->writeln(implode(';' . PHP_EOL, $sqls)); + $ui->text('The following SQL statements will be executed:'); + $ui->newLine(); + + foreach ($sqls as $sql) { + $ui->text(sprintf(' %s;', $sql)); + } return 0; } - if ($input->getOption('force')) { - $output->writeln('Dropping database schema...'); + if ($force) { + $ui->text('Dropping database schema...'); + $ui->newLine(); if ($isFullDatabaseDrop) { $schemaTool->dropDatabase(); @@ -86,12 +95,12 @@ protected function executeSchemaCommand(InputInterface $input, OutputInterface $ $schemaTool->dropSchema($metadatas); } - $output->writeln('Database schema dropped successfully!'); + $ui->success('Database schema dropped successfully!'); return 0; } - $output->writeln('ATTENTION: This operation should not be executed in a production environment.' . PHP_EOL); + $ui->caution('This operation should not be executed in a production environment!'); if ($isFullDatabaseDrop) { $sqls = $schemaTool->getDropDatabaseSQL(); @@ -99,18 +108,23 @@ protected function executeSchemaCommand(InputInterface $input, OutputInterface $ $sqls = $schemaTool->getDropSchemaSQL($metadatas); } - if (count($sqls)) { - $output->writeln(sprintf('The Schema-Tool would execute "%s" queries to update the database.', count($sqls))); - $output->writeln('Please run the operation by passing one - or both - of the following options:'); - - $output->writeln(sprintf(' %s --force to execute the command', $this->getName())); - $output->writeln(sprintf(' %s --dump-sql to dump the SQL statements to the screen', $this->getName())); + if (empty($sqls)) { + $ui->success('Nothing to drop. The database is empty!'); - return 1; + return 0; } - $output->writeln('Nothing to drop. The database is empty!'); - - return 0; + $ui->text( + [ + sprintf('The Schema-Tool would execute "%s" queries to update the database.', count($sqls)), + '', + 'Please run the operation by passing one - or both - of the following options:', + '', + sprintf(' %s --force to execute the command', $this->getName()), + sprintf(' %s --dump-sql to dump the SQL statements to the screen', $this->getName()), + ] + ); + + return 1; } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php index 39df55d9616..c9059775b1e 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php @@ -23,6 +23,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; /** * Command to generate the SQL needed to update the database schema to match @@ -89,15 +90,15 @@ protected function configure() /** * {@inheritdoc} */ - protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas) + protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas, SymfonyStyle $ui) { // Defining if update is complete or not (--complete not defined means $saveMode = true) $saveMode = ! $input->getOption('complete'); $sqls = $schemaTool->getUpdateSchemaSql($metadatas, $saveMode); - if (0 === count($sqls)) { - $output->writeln('Nothing to update - your database is already in sync with the current entity metadata.'); + if (empty($sqls)) { + $ui->success('Nothing to update - your database is already in sync with the current entity metadata.'); return 0; } @@ -106,35 +107,52 @@ protected function executeSchemaCommand(InputInterface $input, OutputInterface $ $force = true === $input->getOption('force'); if ($dumpSql) { - $output->writeln(implode(';' . PHP_EOL, $sqls) . ';'); + $ui->text('The following SQL statements will be executed:'); + $ui->newLine(); + + foreach ($sqls as $sql) { + $ui->text(sprintf(' %s;', $sql)); + } } if ($force) { if ($dumpSql) { - $output->writeln(''); + $ui->newLine(); } - $output->writeln('Updating database schema...'); + $ui->text('Updating database schema...'); + $ui->newLine(); + $schemaTool->updateSchema($metadatas, $saveMode); $pluralization = (1 === count($sqls)) ? 'query was' : 'queries were'; - $output->writeln(sprintf('Database schema updated successfully! "%s" %s executed', count($sqls), $pluralization)); + $ui->text(sprintf(' %s %s executed', count($sqls), $pluralization)); + $ui->success('Database schema updated successfully!'); } if ($dumpSql || $force) { return 0; } - $output->writeln('ATTENTION: This operation should not be executed in a production environment.'); - $output->writeln(' Use the incremental update to detect changes during development and use'); - $output->writeln(' the SQL DDL provided to manually update your database in production.'); - $output->writeln(''); - - $output->writeln(sprintf('The Schema-Tool would execute "%s" queries to update the database.', count($sqls))); - $output->writeln('Please run the operation by passing one - or both - of the following options:'); - - $output->writeln(sprintf(' %s --force to execute the command', $this->getName())); - $output->writeln(sprintf(' %s --dump-sql to dump the SQL statements to the screen', $this->getName())); + $ui->caution( + [ + 'This operation should not be executed in a production environment!', + '', + 'Use the incremental update to detect changes during development and use', + 'the SQL DDL provided to manually update your database in production.', + ] + ); + + $ui->text( + [ + sprintf('The Schema-Tool would execute "%s" queries to update the database.', count($sqls)), + '', + 'Please run the operation by passing one - or both - of the following options:', + '', + sprintf(' %s --force to execute the command', $this->getName()), + sprintf(' %s --dump-sql to dump the SQL statements to the screen', $this->getName()), + ] + ); return 1; } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ValidateSchemaCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ValidateSchemaCommand.php index f9acda547b2..343d3b53db9 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ValidateSchemaCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ValidateSchemaCommand.php @@ -24,6 +24,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; /** * Command to validate that the current mapping is valid. @@ -55,35 +56,43 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $ui = new SymfonyStyle($input, $output); + $em = $this->getHelper('em')->getEntityManager(); $validator = new SchemaValidator($em); $exit = 0; + $ui->section('Mapping'); + if ($input->getOption('skip-mapping')) { - $output->writeln('[Mapping] Skipped mapping check.'); + $ui->text('[SKIPPED] The mapping was not checked.'); } elseif ($errors = $validator->validateMapping()) { foreach ($errors as $className => $errorMessages) { - $output->writeln("[Mapping] FAIL - The entity-class '" . $className . "' mapping is invalid:"); + $ui->text( + sprintf( + '[FAIL] The entity-class %s mapping is invalid:', + $className + ) + ); - foreach ($errorMessages as $errorMessage) { - $output->writeln('* ' . $errorMessage); - } - - $output->writeln(''); + $ui->listing($errorMessages); + $ui->newLine(); } ++$exit; } else { - $output->writeln('[Mapping] OK - The mapping files are correct.'); + $ui->success('The mapping files are correct.'); } + $ui->section('Database'); + if ($input->getOption('skip-sync')) { - $output->writeln('[Database] SKIPPED - The database was not checked for synchronicity.'); - } elseif (!$validator->schemaInSyncWithMetadata()) { - $output->writeln('[Database] FAIL - The database schema is not in sync with the current mapping file.'); + $ui->text('[SKIPPED] The database was not checked for synchronicity.'); + } elseif ( ! $validator->schemaInSyncWithMetadata()) { + $ui->error('The database schema is not in sync with the current mapping file.'); $exit += 2; } else { - $output->writeln('[Database] OK - The database schema is in sync with the mapping files.'); + $ui->success('The database schema is in sync with the mapping files.'); } return $exit; diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c6bd8988243..be88f60e7e6 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -19,6 +19,10 @@ bootstrap="./tests/Doctrine/Tests/TestInit.php" > + + + + ./tests/Doctrine/Tests/ORM diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheCollectionRegionCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheCollectionRegionCommandTest.php index f9290e7be4f..f8c17b318bf 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheCollectionRegionCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheCollectionRegionCommandTest.php @@ -50,7 +50,7 @@ public function testClearAllRegion() ['decorated' => false] ); - $this->assertEquals('Clearing all second-level cache collection regions' . PHP_EOL, $tester->getDisplay()); + self::assertContains(' // Clearing all second-level cache collection regions', $tester->getDisplay()); } public function testClearByOwnerEntityClassName() @@ -67,7 +67,10 @@ public function testClearByOwnerEntityClassName() ['decorated' => false] ); - $this->assertEquals('Clearing second-level cache for collection "Doctrine\Tests\Models\Cache\State#cities"' . PHP_EOL, $tester->getDisplay()); + self::assertContains( + ' // Clearing second-level cache for collection "Doctrine\Tests\Models\Cache\State#cities"', + $tester->getDisplay() + ); } public function testClearCacheEntryName() @@ -85,7 +88,12 @@ public function testClearCacheEntryName() ['decorated' => false] ); - $this->assertEquals('Clearing second-level cache entry for collection "Doctrine\Tests\Models\Cache\State#cities" owner entity identified by "1"' . PHP_EOL, $tester->getDisplay()); + self::assertContains( + ' // Clearing second-level cache entry for collection "Doctrine\Tests\Models\Cache\State#cities" owner', + $tester->getDisplay() + ); + + self::assertContains(' // entity identified by "1"', $tester->getDisplay()); } public function testFlushRegionName() @@ -103,6 +111,9 @@ public function testFlushRegionName() ['decorated' => false] ); - $this->assertEquals('Flushing cache provider configured for "Doctrine\Tests\Models\Cache\State#cities"' . PHP_EOL, $tester->getDisplay()); + self::assertContains( + ' // Flushing cache provider configured for "Doctrine\Tests\Models\Cache\State#cities"', + $tester->getDisplay() + ); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheEntityRegionCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheEntityRegionCommandTest.php index f0eed259576..b1d8d386b2f 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheEntityRegionCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheEntityRegionCommandTest.php @@ -50,7 +50,7 @@ public function testClearAllRegion() ['decorated' => false] ); - $this->assertEquals('Clearing all second-level cache entity regions' . PHP_EOL, $tester->getDisplay()); + self::assertContains(' // Clearing all second-level cache entity regions', $tester->getDisplay()); } public function testClearByEntityClassName() @@ -66,7 +66,10 @@ public function testClearByEntityClassName() ['decorated' => false] ); - $this->assertEquals('Clearing second-level cache for entity "Doctrine\Tests\Models\Cache\Country"' . PHP_EOL, $tester->getDisplay()); + self::assertContains( + ' // Clearing second-level cache for entity "Doctrine\Tests\Models\Cache\Country"', + $tester->getDisplay() + ); } public function testClearCacheEntryName() @@ -83,7 +86,12 @@ public function testClearCacheEntryName() ['decorated' => false] ); - $this->assertEquals('Clearing second-level cache entry for entity "Doctrine\Tests\Models\Cache\Country" identified by "1"' . PHP_EOL, $tester->getDisplay()); + self::assertContains( + ' // Clearing second-level cache entry for entity "Doctrine\Tests\Models\Cache\Country" identified by', + $tester->getDisplay() + ); + + self::assertContains(' // "1"', $tester->getDisplay()); } public function testFlushRegionName() @@ -100,6 +108,9 @@ public function testFlushRegionName() ['decorated' => false] ); - $this->assertEquals('Flushing cache provider configured for entity named "Doctrine\Tests\Models\Cache\Country"' . PHP_EOL, $tester->getDisplay()); + self::assertContains( + ' // Flushing cache provider configured for entity named "Doctrine\Tests\Models\Cache\Country"', + $tester->getDisplay() + ); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheQueryRegionCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheQueryRegionCommandTest.php index f5eb4017f98..1d761260cb7 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheQueryRegionCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheQueryRegionCommandTest.php @@ -49,7 +49,7 @@ public function testClearAllRegion() ['decorated' => false] ); - $this->assertEquals('Clearing all second-level cache query regions' . PHP_EOL, $tester->getDisplay()); + self::assertContains(' // Clearing all second-level cache query regions', $tester->getDisplay()); } public function testClearDefaultRegionName() @@ -65,7 +65,10 @@ public function testClearDefaultRegionName() ['decorated' => false] ); - $this->assertEquals('Clearing second-level cache query region named "query_cache_region"' . PHP_EOL, $tester->getDisplay()); + self::assertContains( + ' // Clearing second-level cache query region named "query_cache_region"', + $tester->getDisplay() + ); } public function testClearByRegionName() @@ -81,7 +84,10 @@ public function testClearByRegionName() ['decorated' => false] ); - $this->assertEquals('Clearing second-level cache query region named "my_region"' . PHP_EOL, $tester->getDisplay()); + self::assertContains( + ' // Clearing second-level cache query region named "my_region"', + $tester->getDisplay() + ); } public function testFlushRegionName() @@ -98,6 +104,9 @@ public function testFlushRegionName() ['decorated' => false] ); - $this->assertEquals('Flushing cache provider configured for second-level cache query region named "my_region"' . PHP_EOL, $tester->getDisplay()); + self::assertContains( + ' // Flushing cache provider configured for second-level cache query region named "my_region"', + $tester->getDisplay() + ); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php index 64c81ddfec8..74fbc38b22b 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php @@ -136,4 +136,38 @@ private function generateRepositories($filter, $defaultRepository = null) ); } + public function testNoMetadataClassesToProcess() : void + { + $configuration = $this->createMock(Configuration::class); + $metadataFactory = $this->createMock(ClassMetadataFactory::class); + $em = $this->createMock(EntityManagerInterface::class); + + $configuration->method('getDefaultRepositoryClassName') + ->willReturn('fooRepository'); + + $metadataFactory->method('getAllMetadata') + ->willReturn([]); + + $em->method('getMetadataFactory') + ->willReturn($metadataFactory); + + $em->method('getConfiguration') + ->willReturn($configuration); + + $application = new Application(); + $application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($em)])); + $application->add(new GenerateRepositoriesCommand()); + + $command = $application->find('orm:generate-repositories'); + $tester = new CommandTester($command); + + $tester->execute( + [ + 'command' => $command->getName(), + 'dest-path' => $this->path, + ] + ); + + self::assertContains('[OK] No Metadata Classes to process.', $tester->getDisplay()); + } } diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/InfoCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/InfoCommandTest.php index 240378a6ad5..59d5d9532ab 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/InfoCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/InfoCommandTest.php @@ -52,4 +52,71 @@ public function testListAllClasses() self::assertContains(AttractionInfo::class, $this->tester->getDisplay()); self::assertContains(City::class, $this->tester->getDisplay()); } + + public function testEmptyEntityClassNames() : void + { + $mappingDriver = $this->createMock(MappingDriver::class); + $configuration = $this->createMock(Configuration::class); + $em = $this->createMock(EntityManagerInterface::class); + + $mappingDriver->method('getAllClassNames') + ->willReturn([]); + + $configuration->method('getMetadataDriverImpl') + ->willReturn($mappingDriver); + + $em->method('getConfiguration') + ->willReturn($configuration); + + $application = new Application(); + $application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($em)])); + $application->add(new InfoCommand()); + + $command = $application->find('orm:info'); + $tester = new CommandTester($command); + + $tester->execute(['command' => $command->getName()]); + + self::assertContains( + ' ! [CAUTION] You do not have any mapped Doctrine ORM entities according to the current configuration', + $tester->getDisplay() + ); + + self::assertContains( + ' ! If you have entities or mapping files you should check your mapping configuration for errors.', + $tester->getDisplay() + ); + } + + public function testInvalidEntityClassMetadata() : void + { + $mappingDriver = $this->createMock(MappingDriver::class); + $configuration = $this->createMock(Configuration::class); + $em = $this->createMock(EntityManagerInterface::class); + + $mappingDriver->method('getAllClassNames') + ->willReturn(['InvalidEntity']); + + $configuration->method('getMetadataDriverImpl') + ->willReturn($mappingDriver); + + $em->method('getConfiguration') + ->willReturn($configuration); + + $em->method('getClassMetadata') + ->with('InvalidEntity') + ->willThrowException(new MappingException('exception message')); + + $application = new Application(); + $application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($em)])); + $application->add(new InfoCommand()); + + $command = $application->find('orm:info'); + $tester = new CommandTester($command); + + $tester->execute(['command' => $command->getName()]); + + self::assertContains('[FAIL] InvalidEntity', $tester->getDisplay()); + self::assertContains('exception message', $tester->getDisplay()); + } } diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php index 298ff886ed0..552c678739c 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php @@ -86,6 +86,6 @@ public function testWillShowQuery() ) ); - self::assertStringMatchesFormat('%Astring%sSELECT %a', $this->tester->getDisplay()); + self::assertStringMatchesFormat('SELECT %a', trim($this->tester->getDisplay())); } } diff --git a/tests/travis/mariadb.travis.xml b/tests/travis/mariadb.travis.xml index 16024c4c6c8..d4a3fef40cf 100644 --- a/tests/travis/mariadb.travis.xml +++ b/tests/travis/mariadb.travis.xml @@ -19,6 +19,8 @@ + + diff --git a/tests/travis/mysql.travis.xml b/tests/travis/mysql.travis.xml index 16024c4c6c8..d4a3fef40cf 100644 --- a/tests/travis/mysql.travis.xml +++ b/tests/travis/mysql.travis.xml @@ -19,6 +19,8 @@ + + diff --git a/tests/travis/pgsql.travis.xml b/tests/travis/pgsql.travis.xml index 6ad430af329..d429084476f 100644 --- a/tests/travis/pgsql.travis.xml +++ b/tests/travis/pgsql.travis.xml @@ -22,6 +22,8 @@ + + diff --git a/tests/travis/sqlite.travis.xml b/tests/travis/sqlite.travis.xml index 7894dfd2e0b..b783a34ffa8 100644 --- a/tests/travis/sqlite.travis.xml +++ b/tests/travis/sqlite.travis.xml @@ -6,6 +6,10 @@ failOnRisky="true" bootstrap="../Doctrine/Tests/TestInit.php" > + + + + ./../Doctrine/Tests/ORM From 4bbb1067ac6d52b0a9fd94193744032271231a03 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Sat, 16 Sep 2017 21:19:32 +0200 Subject: [PATCH 638/877] Add failing test for #6699 --- .../ORM/Functional/Ticket/GH6699Test.php | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH6699Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6699Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6699Test.php new file mode 100644 index 00000000000..c1e32fdef26 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6699Test.php @@ -0,0 +1,56 @@ +useModelSet('cms'); + + parent::setUp(); + } + + public function testMixedParametersWithZeroNumber() : void + { + $query = $this->_em->createQueryBuilder() + ->select('u') + ->from(CmsUser::class, 'u') + ->andWhere('u.username = :username') + ->andWhere('u.id = ?0') + ->getQuery(); + + $query->setParameter('username', 'bar'); + $query->setParameter(0, 0); + + $query->execute(); + + self::assertCount(2, $query->getParameters()); + self::assertSame(0, $query->getParameter(0)->getValue()); + self::assertSame('bar', $query->getParameter('username')->getValue()); + } + + public function testMixedParametersWithZeroNumberOnQueryBuilder() : void + { + $query = $this->_em->createQueryBuilder() + ->select('u') + ->from(CmsUser::class, 'u') + ->andWhere('u.username = :username') + ->andWhere('u.id = ?0') + ->setParameter('username', 'bar') + ->setParameter(0, 0) + ->getQuery(); + + $query->execute(); + + self::assertCount(2, $query->getParameters()); + self::assertSame(0, $query->getParameter(0)->getValue()); + self::assertSame('bar', $query->getParameter('username')->getValue()); + } +} From 6cb5a9c50a3143dfa60088e5799b9a2625b57966 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Fri, 24 Nov 2017 02:22:07 +0100 Subject: [PATCH 639/877] Fix parameter name comparison in AbstractQuery#setParameter() with different types --- lib/Doctrine/ORM/AbstractQuery.php | 23 +++---- tests/Doctrine/Tests/ORM/Query/QueryTest.php | 63 ++++++++++++++++++++ 2 files changed, 71 insertions(+), 15 deletions(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index ba013bbbb69..10af390539f 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -321,14 +321,14 @@ public function getParameters() public function getParameter($key) { $filteredParameters = $this->parameters->filter( - function ($parameter) use ($key) - { - // Must not be identical because of string to integer conversion - return ($key == $parameter->getName()); + function (Query\Parameter $parameter) use ($key) : bool { + $parameterName = $parameter->getName(); + + return $key === $parameterName || (string) $key === (string) $parameterName; } ); - return count($filteredParameters) ? $filteredParameters->first() : null; + return ! $filteredParameters->isEmpty() ? $filteredParameters->first() : null; } /** @@ -369,17 +369,10 @@ public function setParameters($parameters) */ public function setParameter($key, $value, $type = null) { - $filteredParameters = $this->parameters->filter( - function ($parameter) use ($key) - { - // Must not be identical because of string to integer conversion - return ($key == $parameter->getName()); - } - ); + $existingParameter = $this->getParameter($key); - if (count($filteredParameters)) { - $parameter = $filteredParameters->first(); - $parameter->setValue($value, $type); + if ($existingParameter !== null) { + $existingParameter->setValue($value, $type); return $this; } diff --git a/tests/Doctrine/Tests/ORM/Query/QueryTest.php b/tests/Doctrine/Tests/ORM/Query/QueryTest.php index 5a2a295fe79..354586f15e6 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryTest.php @@ -12,6 +12,7 @@ use Doctrine\Tests\Mocks\DriverConnectionMock; use Doctrine\Tests\Mocks\StatementArrayMock; use Doctrine\Tests\Models\CMS\CmsAddress; +use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\OrmTestCase; class QueryTest extends OrmTestCase @@ -303,4 +304,66 @@ public function testSelectFromSubquery() $this->expectExceptionMessage('Subquery'); $query->getSQL(); } + + /** + * @group 6699 + */ + public function testGetParameterTypeJuggling() : void + { + $query = $this->_em->createQuery('select u from ' . CmsUser::class . ' u where u.id = ?0'); + + $query->setParameter(0, 0); + + self::assertCount(1, $query->getParameters()); + self::assertSame(0, $query->getParameter(0)->getValue()); + self::assertSame(0, $query->getParameter('0')->getValue()); + } + + /** + * @group 6699 + */ + public function testSetParameterWithNameZeroIsNotOverridden() : void + { + $query = $this->_em->createQuery('select u from ' . CmsUser::class . ' u where u.id != ?0 and u.username = :name'); + + $query->setParameter(0, 0); + $query->setParameter('name', 'Doctrine'); + + self::assertCount(2, $query->getParameters()); + self::assertSame(0, $query->getParameter('0')->getValue()); + self::assertSame('Doctrine', $query->getParameter('name')->getValue()); + } + + /** + * @group 6699 + */ + public function testSetParameterWithNameZeroDoesNotOverrideAnotherParameter() : void + { + $query = $this->_em->createQuery('select u from ' . CmsUser::class . ' u where u.id != ?0 and u.username = :name'); + + $query->setParameter('name', 'Doctrine'); + $query->setParameter(0, 0); + + self::assertCount(2, $query->getParameters()); + self::assertSame(0, $query->getParameter(0)->getValue()); + self::assertSame('Doctrine', $query->getParameter('name')->getValue()); + } + + /** + * @group 6699 + */ + public function testSetParameterWithTypeJugglingWorks() : void + { + $query = $this->_em->createQuery('select u from ' . CmsUser::class . ' u where u.id != ?0 and u.username = :name'); + + $query->setParameter('0', 1); + $query->setParameter('name', 'Doctrine'); + $query->setParameter(0, 2); + $query->setParameter('0', 3); + + self::assertCount(2, $query->getParameters()); + self::assertSame(3, $query->getParameter(0)->getValue()); + self::assertSame(3, $query->getParameter('0')->getValue()); + self::assertSame('Doctrine', $query->getParameter('name')->getValue()); + } } From b8fd708139764c29421e4f305e455ce5643cd024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Fri, 24 Nov 2017 02:22:38 +0100 Subject: [PATCH 640/877] Fix parameter name comparison in QueryBuilder#setParameter() with different types --- lib/Doctrine/ORM/QueryBuilder.php | 30 +++----- tests/Doctrine/Tests/ORM/QueryBuilderTest.php | 77 +++++++++++++++++++ 2 files changed, 86 insertions(+), 21 deletions(-) diff --git a/lib/Doctrine/ORM/QueryBuilder.php b/lib/Doctrine/ORM/QueryBuilder.php index 976be4ddf84..4081890dd57 100644 --- a/lib/Doctrine/ORM/QueryBuilder.php +++ b/lib/Doctrine/ORM/QueryBuilder.php @@ -532,26 +532,15 @@ public function getRootEntities() */ public function setParameter($key, $value, $type = null) { - $filteredParameters = $this->parameters->filter( - function ($parameter) use ($key) - { - /* @var Query\Parameter $parameter */ - // Must not be identical because of string to integer conversion - return ($key == $parameter->getName()); - } - ); + $existingParameter = $this->getParameter($key); - if (count($filteredParameters)) { - /* @var Query\Parameter $parameter */ - $parameter = $filteredParameters->first(); - $parameter->setValue($value, $type); + if ($existingParameter !== null) { + $existingParameter->setValue($value, $type); return $this; } - $parameter = new Query\Parameter($key, $value, $type); - - $this->parameters->add($parameter); + $this->parameters->add(new Query\Parameter($key, $value, $type)); return $this; } @@ -614,15 +603,14 @@ public function getParameters() public function getParameter($key) { $filteredParameters = $this->parameters->filter( - function ($parameter) use ($key) - { - /* @var Query\Parameter $parameter */ - // Must not be identical because of string to integer conversion - return ($key == $parameter->getName()); + function (Query\Parameter $parameter) use ($key) : bool { + $parameterName = $parameter->getName(); + + return $key === $parameterName || (string) $key === (string) $parameterName; } ); - return count($filteredParameters) ? $filteredParameters->first() : null; + return ! $filteredParameters->isEmpty() ? $filteredParameters->first() : null; } /** diff --git a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php index 7da2c663caa..1cf8ab1646f 100644 --- a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php +++ b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php @@ -1158,4 +1158,81 @@ public function testGetAllAliasesWithJoins() $this->assertEquals(['u', 'g'], $aliases); } + + /** + * @group 6699 + */ + public function testGetParameterTypeJuggling() : void + { + $builder = $this->_em->createQueryBuilder() + ->select('u') + ->from(CmsUser::class, 'u') + ->where('u.id = ?0'); + + $builder->setParameter(0, 0); + + self::assertCount(1, $builder->getParameters()); + self::assertSame(0, $builder->getParameter(0)->getValue()); + self::assertSame(0, $builder->getParameter('0')->getValue()); + } + + /** + * @group 6699 + */ + public function testSetParameterWithNameZeroIsNotOverridden() : void + { + $builder = $this->_em->createQueryBuilder() + ->select('u') + ->from(CmsUser::class, 'u') + ->where('u.id != ?0') + ->andWhere('u.username = :name'); + + $builder->setParameter(0, 0); + $builder->setParameter('name', 'Doctrine'); + + self::assertCount(2, $builder->getParameters()); + self::assertSame(0, $builder->getParameter('0')->getValue()); + self::assertSame('Doctrine', $builder->getParameter('name')->getValue()); + } + + /** + * @group 6699 + */ + public function testSetParameterWithNameZeroDoesNotOverrideAnotherParameter() : void + { + $builder = $this->_em->createQueryBuilder() + ->select('u') + ->from(CmsUser::class, 'u') + ->where('u.id != ?0') + ->andWhere('u.username = :name'); + + $builder->setParameter('name', 'Doctrine'); + $builder->setParameter(0, 0); + + self::assertCount(2, $builder->getParameters()); + self::assertSame(0, $builder->getParameter(0)->getValue()); + self::assertSame('Doctrine', $builder->getParameter('name')->getValue()); + } + + /** + * @group 6699 + */ + public function testSetParameterWithTypeJugglingWorks() : void + { + $builder = $this->_em->createQueryBuilder() + ->select('u') + ->from(CmsUser::class, 'u') + ->where('u.id != ?0') + ->andWhere('u.username = :name'); + + $builder->setParameter('0', 1); + $builder->setParameter('name', 'Doctrine'); + $builder->setParameter(0, 2); + $builder->setParameter('0', 3); + + self::assertCount(2, $builder->getParameters()); + self::assertSame(3, $builder->getParameter(0)->getValue()); + self::assertSame(3, $builder->getParameter('0')->getValue()); + self::assertSame('Doctrine', $builder->getParameter('name')->getValue()); + } } From d3759a2447dd9eb2322a524cf36592099a668ff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 26 Nov 2017 12:25:02 +0100 Subject: [PATCH 641/877] Fix incorrect arguments on SetupTest Which was only caught by adding proper type declaration on private methods. --- tests/Doctrine/Tests/ORM/Tools/SetupTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Tools/SetupTest.php b/tests/Doctrine/Tests/ORM/Tools/SetupTest.php index c44cb6bcf56..fc5bd6e71a4 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SetupTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SetupTest.php @@ -104,7 +104,7 @@ public function testConfigureCache() public function testConfigureCacheCustomInstance() { $cache = $this->createMock(Cache::class); - $config = Setup::createConfiguration([], true, $cache); + $config = Setup::createConfiguration(true, null, $cache); $this->assertSame($cache, $config->getResultCacheImpl()); $this->assertSame($cache, $config->getMetadataCacheImpl()); From 99b2e57606d9cc7fa93af0832de6f84e92124892 Mon Sep 17 00:00:00 2001 From: Jan Jakes Date: Tue, 28 Jun 2016 10:34:43 +0200 Subject: [PATCH 642/877] Fix overwriting explicit cache namespace --- lib/Doctrine/ORM/Tools/Setup.php | 86 ++++++++++++++------ tests/Doctrine/Tests/ORM/Tools/SetupTest.php | 37 +++++++++ 2 files changed, 98 insertions(+), 25 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Setup.php b/lib/Doctrine/ORM/Tools/Setup.php index 666d627a4b4..2e8a8f915ef 100644 --- a/lib/Doctrine/ORM/Tools/Setup.php +++ b/lib/Doctrine/ORM/Tools/Setup.php @@ -123,31 +123,7 @@ public static function createConfiguration($isDevMode = false, $proxyDir = null, { $proxyDir = $proxyDir ?: sys_get_temp_dir(); - if ($isDevMode === false && $cache === null) { - if (extension_loaded('apc')) { - $cache = new \Doctrine\Common\Cache\ApcCache(); - } elseif (ini_get('xcache.cacher')) { - $cache = new \Doctrine\Common\Cache\XcacheCache(); - } elseif (extension_loaded('memcache')) { - $memcache = new \Memcache(); - $memcache->connect('127.0.0.1'); - $cache = new \Doctrine\Common\Cache\MemcacheCache(); - $cache->setMemcache($memcache); - } elseif (extension_loaded('redis')) { - $redis = new \Redis(); - $redis->connect('127.0.0.1'); - $cache = new \Doctrine\Common\Cache\RedisCache(); - $cache->setRedis($redis); - } else { - $cache = new ArrayCache(); - } - } elseif ($cache === null) { - $cache = new ArrayCache(); - } - - if ($cache instanceof CacheProvider) { - $cache->setNamespace("dc2_" . md5($proxyDir) . "_"); // to avoid collisions - } + $cache = self::createCacheConfiguration($isDevMode, $proxyDir, $cache); $config = new Configuration(); $config->setMetadataCacheImpl($cache); @@ -159,4 +135,64 @@ public static function createConfiguration($isDevMode = false, $proxyDir = null, return $config; } + + private static function createCacheConfiguration(bool $isDevMode, string $proxyDir, ?Cache $cache) : Cache + { + $cache = self::createCacheInstance($isDevMode, $cache); + + if ( ! $cache instanceof CacheProvider) { + return $cache; + } + + $namespace = $cache->getNamespace(); + + if ($namespace !== '') { + $namespace .= ':'; + } + + $cache->setNamespace($namespace . 'dc2_' . md5($proxyDir) . '_'); // to avoid collisions + + return $cache; + } + + private static function createCacheInstance(bool $isDevMode, ?Cache $cache) : Cache + { + if ($cache !== null) { + return $cache; + } + + if ($isDevMode === true) { + return new ArrayCache(); + } + + if (extension_loaded('apc')) { + return new \Doctrine\Common\Cache\ApcCache(); + } + + if (ini_get('xcache.cacher')) { + return new \Doctrine\Common\Cache\XcacheCache(); + } + + if (extension_loaded('memcache')) { + $memcache = new \Memcache(); + $memcache->connect('127.0.0.1'); + + $cache = new \Doctrine\Common\Cache\MemcacheCache(); + $cache->setMemcache($memcache); + + return $cache; + } + + if (extension_loaded('redis')) { + $redis = new \Redis(); + $redis->connect('127.0.0.1'); + + $cache = new \Doctrine\Common\Cache\RedisCache(); + $cache->setRedis($redis); + + return $cache; + } + + return new ArrayCache(); + } } diff --git a/tests/Doctrine/Tests/ORM/Tools/SetupTest.php b/tests/Doctrine/Tests/ORM/Tools/SetupTest.php index fc5bd6e71a4..c7ec7c6d191 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SetupTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SetupTest.php @@ -76,6 +76,43 @@ public function testYAMLConfiguration() $this->assertInstanceOf(YamlDriver::class, $config->getMetadataDriverImpl()); } + /** + * @group 5904 + */ + public function testCacheNamespaceShouldBeGeneratedWhenCacheIsNotGiven() : void + { + $config = Setup::createConfiguration(false, '/foo'); + $cache = $config->getMetadataCacheImpl(); + + self::assertSame('dc2_1effb2475fcfba4f9e8b8a1dbc8f3caf_', $cache->getNamespace()); + } + + /** + * @group 5904 + */ + public function testCacheNamespaceShouldBeGeneratedWhenCacheIsGivenButHasNoNamespace() : void + { + $config = Setup::createConfiguration(false, '/foo', new ArrayCache()); + $cache = $config->getMetadataCacheImpl(); + + self::assertSame('dc2_1effb2475fcfba4f9e8b8a1dbc8f3caf_', $cache->getNamespace()); + } + + /** + * @group 5904 + */ + public function testConfiguredCacheNamespaceShouldBeUsedAsPrefixOfGeneratedNamespace() : void + { + $originalCache = new ArrayCache(); + $originalCache->setNamespace('foo'); + + $config = Setup::createConfiguration(false, '/foo', $originalCache); + $cache = $config->getMetadataCacheImpl(); + + self::assertSame($originalCache, $cache); + self::assertSame('foo:dc2_1effb2475fcfba4f9e8b8a1dbc8f3caf_', $cache->getNamespace()); + } + /** * @group DDC-1350 */ From 15c145f3b361d5f956eed47fff909480a19f5480 Mon Sep 17 00:00:00 2001 From: Mathieu Duplouy Date: Sat, 30 Sep 2017 10:31:24 +0200 Subject: [PATCH 643/877] Add failing test for DCOM-288 Reported on: https://github.com/doctrine/common/issues/600 --- .../ORM/Functional/Ticket/GH6740Test.php | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH6740Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6740Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6740Test.php new file mode 100644 index 00000000000..3589fa2fb8a --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6740Test.php @@ -0,0 +1,108 @@ +useModelSet('ecommerce'); + + parent::setUp(); + + $product = new ECommerceProduct(); + $product->setName('First Product'); + + $firstCategory = new ECommerceCategory(); + $secondCategory = new ECommerceCategory(); + + $firstCategory->setName('Business'); + $secondCategory->setName('Home'); + + $product->addCategory($firstCategory); + $product->addCategory($secondCategory); + + $this->_em->persist($product); + $this->_em->flush(); + $this->_em->clear(); + + $this->productId = $product->getId(); + $this->firstCategoryId = $firstCategory->getId(); + $this->secondCategoryId = $secondCategory->getId(); + } + + /** + * @group 6740 + */ + public function testCollectionFilteringLteOperator() : void + { + $product = $this->_em->find(ECommerceProduct::class, $this->productId); + $criteria = Criteria::create()->where(Criteria::expr()->lte('id', $this->secondCategoryId)); + + self::assertCount(2, $product->getCategories()->matching($criteria)); + } + + /** + * @group 6740 + */ + public function testCollectionFilteringLtOperator() : void + { + $product = $this->_em->find(ECommerceProduct::class, $this->productId); + $criteria = Criteria::create()->where(Criteria::expr()->lt('id', $this->secondCategoryId)); + + self::assertCount(1, $product->getCategories()->matching($criteria)); + } + + /** + * @group 6740 + */ + public function testCollectionFilteringGteOperator() : void + { + $product = $this->_em->find(ECommerceProduct::class, $this->productId); + $criteria = Criteria::create()->where(Criteria::expr()->gte('id', $this->firstCategoryId)); + + self::assertCount(2, $product->getCategories()->matching($criteria)); + } + + /** + * @group 6740 + */ + public function testCollectionFilteringGtOperator() : void + { + $product = $this->_em->find(ECommerceProduct::class, $this->productId); + $criteria = Criteria::create()->where(Criteria::expr()->gt('id', $this->firstCategoryId)); + + self::assertCount(1, $product->getCategories()->matching($criteria)); + } + + /** + * @group 6740 + */ + public function testCollectionFilteringEqualsOperator() : void + { + $product = $this->_em->find(ECommerceProduct::class, $this->productId); + $criteria = Criteria::create()->where(Criteria::expr()->eq('id', $this->firstCategoryId)); + + self::assertCount(1, $product->getCategories()->matching($criteria)); + } +} From 7c28a932aef9f4fb61ba37370623f027f8a03546 Mon Sep 17 00:00:00 2001 From: Mathieu Duplouy Date: Sat, 30 Sep 2017 15:31:41 +0200 Subject: [PATCH 644/877] Add operator to walkComparison output --- .../ORM/Persisters/Collection/ManyToManyPersister.php | 9 +++++---- lib/Doctrine/ORM/Persisters/SqlValueVisitor.php | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php index 176ef37ee07..84d5ccfbcc6 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php @@ -259,10 +259,11 @@ public function loadCriteria(PersistentCollection $collection, Criteria $criteri $parameters = $this->expandCriteriaParameters($criteria); foreach ($parameters as $parameter) { - list($name, $value) = $parameter; - $field = $this->quoteStrategy->getColumnName($name, $targetClass, $this->platform); - $whereClauses[] = sprintf('te.%s = ?', $field); - $params[] = $value; + [$name, $value, $operator] = $parameter; + + $field = $this->quoteStrategy->getColumnName($name, $targetClass, $this->platform); + $whereClauses[] = sprintf('te.%s %s ?', $field, $operator); + $params[] = $value; } $tableName = $this->quoteStrategy->getTableName($targetClass, $this->platform); diff --git a/lib/Doctrine/ORM/Persisters/SqlValueVisitor.php b/lib/Doctrine/ORM/Persisters/SqlValueVisitor.php index 78fd0333bb0..a5df126c4d9 100644 --- a/lib/Doctrine/ORM/Persisters/SqlValueVisitor.php +++ b/lib/Doctrine/ORM/Persisters/SqlValueVisitor.php @@ -50,9 +50,9 @@ class SqlValueVisitor extends ExpressionVisitor */ public function walkComparison(Comparison $comparison) { - $value = $this->getValueFromComparison($comparison); - $field = $comparison->getField(); - $operator = $comparison->getOperator(); + $value = $this->getValueFromComparison($comparison); + $field = $comparison->getField(); + $operator = $comparison->getOperator(); if (($operator === Comparison::EQ || $operator === Comparison::IS) && $value === null) { return; @@ -61,7 +61,7 @@ public function walkComparison(Comparison $comparison) } $this->values[] = $value; - $this->types[] = [$field, $value]; + $this->types[] = [$field, $value, $operator]; } /** From b3331b2237243625e0ca9586ffe9abb40599cef7 Mon Sep 17 00:00:00 2001 From: Sasha Alex Romanenko Date: Tue, 5 Sep 2017 19:28:47 -0400 Subject: [PATCH 645/877] Enforce sequence XSD requirement Supply default values for allocationSize and initialValue optional parameters. Related to: https://github.com/doctrine/doctrine2/issues/6682 --- .../ORM/Mapping/ClassMetadataInfo.php | 10 ++++++- .../ORM/Functional/Ticket/GH6682Test.php | 29 +++++++++++++++++++ .../Tests/ORM/Mapping/ClassMetadataTest.php | 10 +++++-- 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH6682Test.php diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 7794c8c4dcc..0747d4435a0 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -3003,7 +3003,7 @@ public function setCustomGeneratorDefinition(array $definition) */ public function setSequenceGeneratorDefinition(array $definition) { - if ( ! isset($definition['sequenceName'])) { + if ( ! isset($definition['sequenceName']) || trim($definition['sequenceName']) === '') { throw MappingException::missingSequenceName($this->name); } @@ -3012,6 +3012,14 @@ public function setSequenceGeneratorDefinition(array $definition) $definition['quoted'] = true; } + if ( ! isset($definition['allocationSize']) || trim($definition['allocationSize']) === '') { + $definition['allocationSize'] = '1'; + } + + if ( ! isset($definition['initialValue']) || trim($definition['initialValue']) === '') { + $definition['initialValue'] = '1'; + } + $this->sequenceGeneratorDefinition = $definition; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6682Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6682Test.php new file mode 100644 index 00000000000..a8fd76fa2d0 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6682Test.php @@ -0,0 +1,29 @@ + 'test_sequence', + 'allocationSize' => '', + 'initialValue' => '', + ]; + + $classMetadataInfo = new ClassMetadataInfo('test_entity'); + $classMetadataInfo->setSequenceGeneratorDefinition($parsedDefinition); + + self::assertSame( + ['sequenceName' => 'test_sequence', 'allocationSize' => '1', 'initialValue' => '1'], + $classMetadataInfo->sequenceGeneratorDefinition + ); + } +} diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php index 24d9559f78a..a7be70be848 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php @@ -1188,15 +1188,19 @@ public function testSetSequenceGeneratorThrowsExceptionWhenSequenceNameIsMissing /** * @group DDC-2662 + * @group 6682 */ - public function testQuotedSequenceName() + public function testQuotedSequenceName() : void { $cm = new ClassMetadata(CMS\CmsUser::class); - $cm->initializeReflection(new RuntimeReflectionService()); + $cm->initializeReflection(new RuntimeReflectionService()); $cm->setSequenceGeneratorDefinition(['sequenceName' => '`foo`']); - $this->assertEquals(['sequenceName' => 'foo', 'quoted' => true], $cm->sequenceGeneratorDefinition); + self::assertSame( + ['sequenceName' => 'foo', 'quoted' => true, 'allocationSize' => '1', 'initialValue' => '1'], + $cm->sequenceGeneratorDefinition + ); } /** From b211dd4db70a41026ceef29069d7b1a6360486d2 Mon Sep 17 00:00:00 2001 From: foaly-nr1 Date: Mon, 30 Oct 2017 20:53:00 +0000 Subject: [PATCH 646/877] Add failing test for misleading exception message Describes: https://github.com/doctrine/doctrine2/issues/6029 --- .../ORM/Functional/Ticket/GH6029Test.php | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH6029Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6029Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6029Test.php new file mode 100644 index 00000000000..50696a51668 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6029Test.php @@ -0,0 +1,137 @@ +setUpEntitySchema( + [ + GH6029User::class, + GH6029Group::class, + GH6029Group2::class, + GH6029Product::class, + GH6029Feature::class, + ] + ); + } + + /** + * Verifies that when wrong entity is persisted via relationship field, the error message does not correctly state + * the expected class name. + * + * @group 6029 + */ + public function testManyToManyAssociation() : void + { + $user = new GH6029User(); + $user->groups->add(new GH6029Group2()); + + $this->expectException(ORMInvalidArgumentException::class); + $this->expectExceptionMessage( + sprintf( + 'Expected value of type "%s" for association field "%s#$groups", got "%s" instead.', + GH6029Group::class, + GH6029User::class, + GH6029Group2::class + ) + ); + + $this->_em->persist($user); + $this->_em->flush(); + } + + /** + * Verifies that when wrong entity is persisted via relationship field, the error message does not correctly state + * the expected class name. + * + * @group 6029 + */ + public function testOneToManyAssociation() : void + { + $product = new GH6029Product(); + $product->features->add(new GH6029Group2()); + + $this->expectException(ORMInvalidArgumentException::class); + $this->expectExceptionMessage( + sprintf( + 'Expected value of type "%s" for association field "%s#$features", got "%s" instead.', + GH6029Feature::class, + GH6029Product::class, + GH6029Group2::class + ) + ); + + $this->_em->persist($product); + $this->_em->flush(); + } +} + +/** @Entity */ +class GH6029User +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; + + /** @ManyToMany(targetEntity=GH6029Group::class, cascade={"all"}) */ + public $groups; + + public function __construct() + { + $this->groups = new ArrayCollection(); + } +} + +/** @Entity */ +class GH6029Group +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; +} + +/** @Entity */ +class GH6029Group2 +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; +} + +/** @Entity */ +class GH6029Product +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; + + /** + * @OneToMany(targetEntity=GH6029Feature::class, mappedBy="product", cascade={"all"}) + */ + public $features; + + public function __construct() + { + $this->features = new ArrayCollection(); + } +} + +/** @Entity */ +class GH6029Feature +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; + + /** + * @ManyToOne(targetEntity=GH6029Product::class, inversedBy="features") + * @JoinColumn(name="product_id", referencedColumnName="id") + */ + public $product; +} From c0a505366f04998c3b4dfc9d5f35eb362be7ac70 Mon Sep 17 00:00:00 2001 From: foaly-nr1 Date: Mon, 30 Oct 2017 21:19:52 +0000 Subject: [PATCH 647/877] Use the correct type for the exception message Since the UoW checks each item of a *-to-many association to ensure it has the correct type, we should never say that we expect an instance of `Doctrine\Common\Collections\Collection` or an `array`. --- lib/Doctrine/ORM/ORMInvalidArgumentException.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/ORMInvalidArgumentException.php b/lib/Doctrine/ORM/ORMInvalidArgumentException.php index 796d2c5a515..68bb6f91dff 100644 --- a/lib/Doctrine/ORM/ORMInvalidArgumentException.php +++ b/lib/Doctrine/ORM/ORMInvalidArgumentException.php @@ -216,11 +216,7 @@ public static function invalidIdentifierBindingEntity() */ public static function invalidAssociation(ClassMetadata $targetClass, $assoc, $actualValue) { - $expectedType = 'Doctrine\Common\Collections\Collection|array'; - - if (($assoc['type'] & ClassMetadata::TO_ONE) > 0) { - $expectedType = $targetClass->getName(); - } + $expectedType = $targetClass->getName(); return new self(sprintf( 'Expected value of type "%s" for association field "%s#$%s", got "%s" instead.', From bc7aeb9d119be4652dc6c57e57caa7a382c4f03f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 26 Nov 2017 20:05:52 +0100 Subject: [PATCH 648/877] Make entity generator create the correct options The `EntityGenerator` was not creating the field options for all supported values. --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 20 ++++ .../Tests/ORM/Tools/EntityGeneratorTest.php | 93 +++++++++++++++++++ 2 files changed, 113 insertions(+) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 391732dd009..c5977eb88f7 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -1665,10 +1665,30 @@ protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, Cla $options = []; + if (isset($fieldMapping['options']['default']) && $fieldMapping['options']['default']) { + $options[] = '"default"="' . $fieldMapping['options']['default'] .'"'; + } + if (isset($fieldMapping['options']['unsigned']) && $fieldMapping['options']['unsigned']) { $options[] = '"unsigned"=true'; } + if (isset($fieldMapping['options']['fixed']) && $fieldMapping['options']['fixed']) { + $options[] = '"fixed"=true'; + } + + if (isset($fieldMapping['options']['comment']) && $fieldMapping['options']['comment']) { + $options[] = '"comment"="' . $fieldMapping['options']['comment'] .'"'; + } + + if (isset($fieldMapping['options']['collation']) && $fieldMapping['options']['collation']) { + $options[] = '"collation"="' . $fieldMapping['options']['collation'] .'"'; + } + + if (isset($fieldMapping['options']['check']) && $fieldMapping['options']['check']) { + $options[] = '"check"="' . $fieldMapping['options']['check'] .'"'; + } + if ($options) { $column[] = 'options={'.implode(',', $options).'}'; } diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index f2d74d0437f..8f6c35a52dd 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -1174,6 +1174,99 @@ private function assertPhpDocParamType($type, \ReflectionMethod $method) $this->assertEquals(1, preg_match('/@param\s+([^\s]+)/', $method->getDocComment(), $matches)); $this->assertEquals($type, $matches[1]); } + + /** + * @group 6703 + * + * @dataProvider columnOptionsProvider + */ + public function testOptionsAreGeneratedProperly(string $expectedAnnotation, array $fieldConfiguration) : void + { + $metadata = new ClassMetadataInfo($this->_namespace . '\GH6703Options'); + $metadata->namespace = $this->_namespace; + $metadata->mapField(['fieldName' => 'id', 'type' => 'integer', 'id' => true]); + $metadata->mapField(['fieldName' => 'test'] + $fieldConfiguration); + $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE); + $this->_generator->writeEntityClass($metadata, $this->_tmpDir); + + $filename = $this->_tmpDir . DIRECTORY_SEPARATOR . $this->_namespace . DIRECTORY_SEPARATOR . 'GH6703Options.php'; + + self::assertFileExists($filename); + require_once $filename; + + $property = new \ReflectionProperty($metadata->name, 'test'); + $docComment = $property->getDocComment(); + + self::assertContains($expectedAnnotation, $docComment); + } + + public function columnOptionsProvider() : array + { + return [ + 'string-default' => [ + '@Column(name="test", type="string", length=10, options={"default"="testing"})', + ['type' => 'string', 'length' => 10, 'options' => ['default' => 'testing']], + ], + 'string-fixed' => [ + '@Column(name="test", type="string", length=10, options={"fixed"=true})', + ['type' => 'string', 'length' => 10, 'options' => ['fixed' => true]], + ], + 'string-comment' => [ + '@Column(name="test", type="string", length=10, options={"comment"="testing"})', + ['type' => 'string', 'length' => 10, 'options' => ['comment' => 'testing']], + ], + 'string-collation' => [ + '@Column(name="test", type="string", length=10, options={"collation"="utf8mb4_general_ci"})', + ['type' => 'string', 'length' => 10, 'options' => ['collation' => 'utf8mb4_general_ci']], + ], + 'string-check' => [ + '@Column(name="test", type="string", length=10, options={"check"="CHECK (test IN (""test""))"})', + ['type' => 'string', 'length' => 10, 'options' => ['check' => 'CHECK (test IN (""test""))']], + ], + 'string-all' => [ + '@Column(name="test", type="string", length=10, options={"default"="testing","fixed"=true,"comment"="testing","collation"="utf8mb4_general_ci","check"="CHECK (test IN (""test""))"})', + [ + 'type' => 'string', + 'length' => 10, + 'options' => [ + 'default' => 'testing', + 'fixed' => true, + 'comment' => 'testing', + 'collation' => 'utf8mb4_general_ci', + 'check' => 'CHECK (test IN (""test""))' + ] + ], + ], + 'int-default' => [ + '@Column(name="test", type="integer", options={"default"="10"})', + ['type' => 'integer', 'options' => ['default' => 10]], + ], + 'int-unsigned' => [ + '@Column(name="test", type="integer", options={"unsigned"=true})', + ['type' => 'integer', 'options' => ['unsigned' => true]], + ], + 'int-comment' => [ + '@Column(name="test", type="integer", options={"comment"="testing"})', + ['type' => 'integer', 'options' => ['comment' => 'testing']], + ], + 'int-check' => [ + '@Column(name="test", type="integer", options={"check"="CHECK (test > 5)"})', + ['type' => 'integer', 'options' => ['check' => 'CHECK (test > 5)']], + ], + 'int-all' => [ + '@Column(name="test", type="integer", options={"default"="10","unsigned"=true,"comment"="testing","check"="CHECK (test > 5)"})', + [ + 'type' => 'integer', + 'options' => [ + 'default' => 10, + 'unsigned' => true, + 'comment' => 'testing', + 'check' => 'CHECK (test > 5)', + ] + ], + ], + ]; + } } class EntityGeneratorAuthor {} From ad0a8c53fa9596e9bbd77bb690e9929df427a475 Mon Sep 17 00:00:00 2001 From: JKapitein Date: Tue, 14 Nov 2017 14:51:55 +0100 Subject: [PATCH 649/877] Add Type::GUID to $typeAlias list in EntityGenerator Right now, when generating entities, a column of type 'guid' will generate the following PHPDoc: ``` /** * Get id * * @return guid */ public function getId() {...} ``` Since guid is not a valid PHP type, this throws a warning in PHPStorm, and I assume most IDEs. Adding the type to the type alias list fixes the problem. --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 1 + tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index c5977eb88f7..cdca27e3b30 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -164,6 +164,7 @@ class EntityGenerator Type::TEXT => 'string', Type::BLOB => 'string', Type::DECIMAL => 'string', + Type::GUID => 'string', Type::JSON_ARRAY => 'array', Type::SIMPLE_ARRAY => 'array', Type::BOOLEAN => 'bool', diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index 8f6c35a52dd..438cf932333 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -1084,6 +1084,14 @@ public function getEntityTypeAliasDataProvider() 'value' => 'blob' ] ], + [ + [ + 'fieldName' => 'guid', + 'phpType' => 'string', + 'dbType' => 'guid', + 'value' => '00000000-0000-0000-0000-000000000001' + ] + ], [ [ 'fieldName' => 'decimal', From 79e1be8c3d64b35c829738309720e0c588b756f0 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 1 Dec 2017 15:41:52 +0100 Subject: [PATCH 650/877] fixed closing tag --- .../ORM/Tools/Console/Command/GenerateProxiesCommand.php | 2 +- .../ORM/Tools/Console/Command/GenerateRepositoriesCommand.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php index c792b0067a0..3755be58052 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php @@ -103,6 +103,6 @@ protected function execute(InputInterface $input, OutputInterface $output) // Outputting information message $ui->newLine(); - $ui->text(sprintf('Proxy classes generated to "%s"', $destPath)); + $ui->text(sprintf('Proxy classes generated to "%s"', $destPath)); } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php index 787fb8bc50f..941944ff528 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php @@ -109,6 +109,6 @@ protected function execute(InputInterface $input, OutputInterface $output) // Outputting information message $ui->newLine(); - $ui->text(sprintf('Repository classes generated to "%s"', $destPath)); + $ui->text(sprintf('Repository classes generated to "%s"', $destPath)); } } From 04d9bc40e4f5909e6820ec9d26fb7f32392e069d Mon Sep 17 00:00:00 2001 From: Maks Rafalko Date: Fri, 8 Dec 2017 09:33:41 +0300 Subject: [PATCH 651/877] Update validation-of-entities.rst --- docs/en/cookbook/validation-of-entities.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/cookbook/validation-of-entities.rst b/docs/en/cookbook/validation-of-entities.rst index d49daa84f89..927d278a699 100644 --- a/docs/en/cookbook/validation-of-entities.rst +++ b/docs/en/cookbook/validation-of-entities.rst @@ -89,7 +89,7 @@ events for one method, this will happen before Beta 1 though. Now validation is performed whenever you call ``EntityManager#persist($order)`` or when you call ``EntityManager#flush()`` and an order is about to be updated. Any -Exception that happens in the lifecycle callbacks will be catched by +Exception that happens in the lifecycle callbacks will be caught by the EntityManager and the current transaction is rolled back. Of course you can do any type of primitive checks, not null, From cd00ccae694c6c8f40414734f704535ffb78b294 Mon Sep 17 00:00:00 2001 From: Dan Barrett Date: Mon, 11 Dec 2017 12:14:39 +1100 Subject: [PATCH 652/877] Updated table/column names example to be lowercase --- docs/en/reference/namingstrategy.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/en/reference/namingstrategy.rst b/docs/en/reference/namingstrategy.rst index b81872fd07a..23aa573534c 100644 --- a/docs/en/reference/namingstrategy.rst +++ b/docs/en/reference/namingstrategy.rst @@ -97,7 +97,7 @@ a naming strategy for database tables and columns. Implementing a naming strategy ------------------------------- If you have database naming standards, like all table names should be prefixed -by the application prefix, all column names should be upper case, you can easily +by the application prefix, all column names should be lower case, you can easily achieve such standards by implementing a naming strategy. You need to create a class which implements ``Doctrine\ORM\Mapping\NamingStrategy``. @@ -126,12 +126,12 @@ You need to create a class which implements ``Doctrine\ORM\Mapping\NamingStrateg } public function joinTableName($sourceEntity, $targetEntity, $propertyName = null) { - return strtoupper($this->classToTableName($sourceEntity) . '_' . + return strtolower($this->classToTableName($sourceEntity) . '_' . $this->classToTableName($targetEntity)); } public function joinKeyColumnName($entityName, $referencedColumnName = null) { - return strtoupper($this->classToTableName($entityName) . '_' . + return strtolower($this->classToTableName($entityName) . '_' . ($referencedColumnName ?: $this->referenceColumnName())); } } From d0d802309ce85b04d037e135b20e5efb81dc2c46 Mon Sep 17 00:00:00 2001 From: Gabriel Caruso Date: Thu, 14 Dec 2017 05:55:54 -0200 Subject: [PATCH 653/877] Clean elses --- lib/Doctrine/ORM/Query/Expr.php | 4 ++-- tests/Doctrine/Tests/Mocks/DriverMock.php | 4 ++-- tests/Doctrine/Tests/Mocks/StatementArrayMock.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Expr.php b/lib/Doctrine/ORM/Query/Expr.php index 120d457c7b6..1373c74a002 100644 --- a/lib/Doctrine/ORM/Query/Expr.php +++ b/lib/Doctrine/ORM/Query/Expr.php @@ -617,9 +617,9 @@ private function _quoteLiteral($literal) return (string) $literal; } else if (is_bool($literal)) { return $literal ? "true" : "false"; - } else { - return "'" . str_replace("'", "''", $literal) . "'"; } + + return "'" . str_replace("'", "''", $literal) . "'"; } /** diff --git a/tests/Doctrine/Tests/Mocks/DriverMock.php b/tests/Doctrine/Tests/Mocks/DriverMock.php index c805f0bf9ff..21ae4e3bbab 100644 --- a/tests/Doctrine/Tests/Mocks/DriverMock.php +++ b/tests/Doctrine/Tests/Mocks/DriverMock.php @@ -48,9 +48,9 @@ public function getSchemaManager(Connection $conn) { if ($this->_schemaManagerMock == null) { return new SchemaManagerMock($conn); - } else { - return $this->_schemaManagerMock; } + + return $this->_schemaManagerMock; } /* MOCK API */ diff --git a/tests/Doctrine/Tests/Mocks/StatementArrayMock.php b/tests/Doctrine/Tests/Mocks/StatementArrayMock.php index ed6ea4fdf6c..0f1747c42dc 100644 --- a/tests/Doctrine/Tests/Mocks/StatementArrayMock.php +++ b/tests/Doctrine/Tests/Mocks/StatementArrayMock.php @@ -53,9 +53,9 @@ public function fetchColumn($columnIndex = 0) if ($current) { next($this->_result); return reset($current); - } else { - return false; } + + return false; } public function rowCount() From b3654f95d02671d8c4a17eb07179726d06267c5e Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Sat, 16 Dec 2017 22:05:22 +0100 Subject: [PATCH 654/877] README: Fix PHP version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 754e8c018b3..45d2b1f5fb7 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ | [![Build status][Master image]][Master] | [![Build status][2.5 image]][2.5] | | [![Coverage Status][Master coverage image]][Master coverage] | [![Coverage Status][2.5 coverage image]][2.5 coverage] | -Doctrine 2 is an object-relational mapper (ORM) for PHP 7.0+ that provides transparent persistence +Doctrine 2 is an object-relational mapper (ORM) for PHP 7.1+ that provides transparent persistence for PHP objects. It sits on top of a powerful database abstraction layer (DBAL). One of its key features is the option to write database queries in a proprietary object oriented SQL dialect called Doctrine Query Language (DQL), inspired by Hibernate's HQL. This provides developers with a powerful alternative to SQL that maintains flexibility From 441c5d138c3120f2a8359564409a9e0e519d5b7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sat, 16 Dec 2017 23:31:50 +0100 Subject: [PATCH 655/877] Reduce complexity of LimitSubqueryWalker#walkSelectStatement() Ensuring that the code follows our code standards. --- .../Tools/Pagination/LimitSubqueryWalker.php | 38 ++++++++++--------- .../Pagination/LimitSubqueryWalkerTest.php | 37 +++++++++--------- 2 files changed, 39 insertions(+), 36 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php index 659a3bab9b1..f1f06e9e129 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php @@ -90,29 +90,33 @@ public function walkSelectStatement(SelectStatement $AST) $pathExpression->type = PathExpression::TYPE_STATE_FIELD; - $AST->selectClause->selectExpressions = array(new SelectExpression($pathExpression, '_dctrn_id')); - - if (isset($AST->orderByClause)) { - foreach ($AST->orderByClause->orderByItems as $item) { - if ( ! $item->expression instanceof PathExpression) { - if(is_string($item->expression) && isset($queryComponents[$item->expression])) { - $qComp = $queryComponents[$item->expression]; - if (isset($qComp['resultVariable'])) { - $AST->selectClause->selectExpressions[] = new SelectExpression($qComp['resultVariable'], $item->expression); - } - } - } else { + $AST->selectClause->selectExpressions = [new SelectExpression($pathExpression, '_dctrn_id')]; + $AST->selectClause->isDistinct = true; + + if ( ! isset($AST->orderByClause)) { + return; + } + foreach ($AST->orderByClause->orderByItems as $item) { + if ($item->expression instanceof PathExpression) { + $AST->selectClause->selectExpressions[] = new SelectExpression( + $this->createSelectExpressionItem($item->expression), '_dctrn_ord' . $this->_aliasCounter++ + ); + + continue; + } + + if (is_string($item->expression) && isset($queryComponents[$item->expression])) { + $qComp = $queryComponents[$item->expression]; + + if (isset($qComp['resultVariable'])) { $AST->selectClause->selectExpressions[] = new SelectExpression( - $this->createSelectExpressionItem($item->expression), - '_dctrn_ord' . $this->_aliasCounter++ + $qComp['resultVariable'], + $item->expression ); } - } } - - $AST->selectClause->isDistinct = true; } /** diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php index 81866f8c065..32ad2a354ec 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php @@ -38,21 +38,20 @@ public function testLimitSubqueryWithSort() ); } - public function testLimitSubqueryWithSortFunction() + public function testLimitSubqueryWithSortFunction() : void { - $dql = 'SELECT p FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category c GROUP BY p.id ORDER BY COUNT(c.id)'; - $query = $this->entityManager->createQuery($dql); - $limitQuery = clone $query; + $dql = 'SELECT p FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category c GROUP BY p.id ORDER BY COUNT(c.id)'; + $query = $this->entityManager->createQuery($dql); + $limitQuery = clone $query; $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [LimitSubqueryWalker::class]); - $this->assertEquals( - "SELECT DISTINCT m0_.id AS id_0 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON m0_.category_id = c1_.id GROUP BY m0_.id ORDER BY COUNT(c1_.id) ASC", + self::assertSame( + 'SELECT DISTINCT m0_.id AS id_0 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON m0_.category_id = c1_.id GROUP BY m0_.id ORDER BY COUNT(c1_.id) ASC', $limitQuery->getSQL() ); } - public function testCountQuery_MixedResultsWithName() { $dql = 'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a'; @@ -67,30 +66,30 @@ public function testCountQuery_MixedResultsWithName() ); } - public function testAggQuery_MixedResultsWithNameAndSort() + public function testAggQuery_MixedResultsWithNameAndSort() : void { - $dql = 'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a ORDER BY foo DESC'; - $query = $this->entityManager->createQuery($dql); - $limitQuery = clone $query; + $dql = 'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a ORDER BY foo DESC'; + $query = $this->entityManager->createQuery($dql); + $limitQuery = clone $query; $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [LimitSubqueryWalker::class]); - $this->assertEquals( - "SELECT DISTINCT a0_.id AS id_0, sum(a0_.name) AS sclr_1 FROM Author a0_ ORDER BY sclr_1 DESC", + self::assertSame( + 'SELECT DISTINCT a0_.id AS id_0, sum(a0_.name) AS sclr_1 FROM Author a0_ ORDER BY sclr_1 DESC', $limitQuery->getSQL() ); } - public function testAggQuery_MultipleMixedResultsWithSort() + public function testAggQuery_MultipleMixedResultsWithSort() : void { - $dql = 'SELECT a, sum(a.name) as foo, (SELECT count(subA.id) FROM Doctrine\Tests\ORM\Tools\Pagination\Author subA WHERE subA.id = a.id ) as bar FROM Doctrine\Tests\ORM\Tools\Pagination\Author a ORDER BY foo DESC, bar ASC'; - $query = $this->entityManager->createQuery($dql); - $limitQuery = clone $query; + $dql = 'SELECT a, sum(a.name) as foo, (SELECT count(subA.id) FROM Doctrine\Tests\ORM\Tools\Pagination\Author subA WHERE subA.id = a.id ) as bar FROM Doctrine\Tests\ORM\Tools\Pagination\Author a ORDER BY foo DESC, bar ASC'; + $query = $this->entityManager->createQuery($dql); + $limitQuery = clone $query; $limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [LimitSubqueryWalker::class]); - $this->assertEquals( - "SELECT DISTINCT a0_.id AS id_0, sum(a0_.name) AS sclr_1, (SELECT count(a1_.id) AS sclr_3 FROM Author a1_ WHERE a1_.id = a0_.id) AS sclr_2 FROM Author a0_ ORDER BY sclr_1 DESC, sclr_2 ASC", + self::assertSame( + 'SELECT DISTINCT a0_.id AS id_0, sum(a0_.name) AS sclr_1, (SELECT count(a1_.id) AS sclr_3 FROM Author a1_ WHERE a1_.id = a0_.id) AS sclr_2 FROM Author a0_ ORDER BY sclr_1 DESC, sclr_2 ASC', $limitQuery->getSQL() ); } From 122e9c3aa34faafda408bba0b6b79e7102a1407d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sat, 16 Dec 2017 23:43:25 +0100 Subject: [PATCH 656/877] Run all code quality tools in the same stage In order to execute things in parallel and speed up the build. --- .travis.yml | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 31a63d87c6d..12a247654a0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -55,15 +55,8 @@ jobs: env: DB=sqlite DEPENDENCIES=low install: travis_retry composer update --prefer-dist --prefer-lowest - - stage: Lint - env: DB=none - before_script: - - echo "extension=redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - - travis_retry composer require --dev --prefer-dist --prefer-stable phpstan/phpstan:^0.8 symfony/console:^3.0 - script: vendor/bin/phpstan analyse -l 1 -c phpstan.neon lib - - - stage: Coverage - env: DB=sqlite + - stage: Test + env: DB=sqlite COVERAGE before_script: - mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{.disabled,} - if [[ ! $(php -m | grep -si xdebug) ]]; then echo "xdebug required for coverage"; exit 1; fi @@ -73,12 +66,20 @@ jobs: - wget https://scrutinizer-ci.com/ocular.phar - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml - - stage: Benchmark - env: DB=none + - stage: Code Quality + env: DB=none STATIC_ANALYSIS + before_script: + - echo "extension=redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini + - travis_retry composer require --dev --prefer-dist --prefer-stable phpstan/phpstan:^0.8 symfony/console:^3.0 + script: vendor/bin/phpstan analyse -l 1 -c phpstan.neon lib + + - stage: Code Quality + env: DB=none BENCHMARK before_script: wget https://phpbench.github.io/phpbench/phpbench.phar https://phpbench.github.io/phpbench/phpbench.phar.pubkey script: php phpbench.phar run -l dots --report=default - - stage: Coding standard + - stage: Code Quality + env: DB=none CODING_STANDARDS php: nightly script: - ./vendor/bin/phpcs From 80a94727ee7e392bb1fc65ba23d851461f5061f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 17 Dec 2017 00:54:12 +0100 Subject: [PATCH 657/877] Run tests also with the stable version of dependencies --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 12a247654a0..9f7def4daea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -55,6 +55,10 @@ jobs: env: DB=sqlite DEPENDENCIES=low install: travis_retry composer update --prefer-dist --prefer-lowest + - stage: Test + env: DB=sqlite DEPENDENCIES=stable + install: travis_retry composer update --prefer-dist --prefer-stable + - stage: Test env: DB=sqlite COVERAGE before_script: From 74ce8913fc484339c65ad991acef69c13001d211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 17 Dec 2017 00:55:50 +0100 Subject: [PATCH 658/877] Upgrade phpstan to 0.9 Applying the necessary fixes. --- .travis.yml | 3 ++- lib/Doctrine/ORM/Internal/CommitOrderCalculator.php | 2 +- lib/Doctrine/ORM/Query/Parser.php | 4 +++- lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9f7def4daea..5399c90ac3e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -72,9 +72,10 @@ jobs: - stage: Code Quality env: DB=none STATIC_ANALYSIS + install: travis_retry composer update --prefer-dist --prefer-stable before_script: - echo "extension=redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - - travis_retry composer require --dev --prefer-dist --prefer-stable phpstan/phpstan:^0.8 symfony/console:^3.0 + - travis_retry composer require --dev --prefer-dist --prefer-stable phpstan/phpstan:^0.9 script: vendor/bin/phpstan analyse -l 1 -c phpstan.neon lib - stage: Code Quality diff --git a/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php b/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php index 067a8c577ba..34703c6d280 100644 --- a/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php +++ b/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php @@ -52,7 +52,7 @@ class CommitOrderCalculator * - dependencyList (array) * Map of node dependencies defined as hashes. * - * @var array + * @var array<\stdClass> */ private $nodeList = []; diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index c21b2de9623..e726aa062aa 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -834,6 +834,8 @@ private function processRootEntityAliasSelected() */ public function QueryLanguage() { + $statement = null; + $this->lexer->moveNext(); switch ($this->lexer->lookahead['type']) { @@ -3357,7 +3359,7 @@ public function FunctionDeclaration() switch (true) { case $customFunctionDeclaration !== null: return $customFunctionDeclaration; - + case (isset(self::$_STRING_FUNCTIONS[$funcName])): return $this->FunctionsReturningStrings(); diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php index 8fa1a7ffc45..c685cd41d88 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php @@ -158,7 +158,7 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) $associationMappingArray['fetch'] = $this->_getFetchModeString($associationMapping['fetch']); } - if (isset($mapping['id']) && $mapping['id'] === true) { + if (isset($associationMapping['id']) && $associationMapping['id'] === true) { $array['id'][$name]['associationKey'] = true; } From 32c125def19fb24941698c6e7e4f1e3065d28484 Mon Sep 17 00:00:00 2001 From: Maximilian Ruta Date: Mon, 6 Nov 2017 12:43:18 +0100 Subject: [PATCH 659/877] Fix syntax error when join with discriminator --- lib/Doctrine/ORM/Query/SqlWalker.php | 16 +++++++++------- .../Tests/ORM/Query/SelectSqlGenerationTest.php | 5 +++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 53a5c747400..d06d070610f 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -902,15 +902,17 @@ private function generateRangeVariableDeclarationSQL($rangeVariableDeclaration, $this->query->getHint(Query::HINT_LOCK_MODE) ); - if ($class->isInheritanceTypeJoined()) { - if ($buildNestedJoins) { - $sql = '(' . $sql . $this->_generateClassTableInheritanceJoins($class, $dqlAlias) . ')'; - } else { - $sql .= $this->_generateClassTableInheritanceJoins($class, $dqlAlias); - } + if ( ! $class->isInheritanceTypeJoined()) { + return $sql; } - return $sql; + $classTableInheritanceJoins = $this->_generateClassTableInheritanceJoins($class, $dqlAlias); + + if ( ! $buildNestedJoins) { + return $sql . $classTableInheritanceJoins; + } + + return $classTableInheritanceJoins === '' ? $sql : '(' . $sql . $classTableInheritanceJoins . ')'; } /** diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 4a093094d47..3ce549e1619 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -205,6 +205,11 @@ public function testSupportsJoinOnMultipleComponentsWithJoinedInheritanceType() 'SELECT e FROM Doctrine\Tests\Models\Company\CompanyEmployee e LEFT JOIN Doctrine\Tests\Models\Company\CompanyManager m WITH e.id = m.id', 'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, c0_.discr AS discr_5 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id LEFT JOIN (company_managers c2_ INNER JOIN company_employees c4_ ON c2_.id = c4_.id INNER JOIN company_persons c3_ ON c2_.id = c3_.id) ON (c0_.id = c3_.id)' ); + + $this->assertSqlGeneration( + 'SELECT c FROM Doctrine\Tests\Models\Company\CompanyContract c JOIN c.salesPerson s LEFT JOIN Doctrine\Tests\Models\Company\CompanyEvent e WITH s.id = e.id', + 'SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.fixPrice AS fixPrice_2, c0_.hoursWorked AS hoursWorked_3, c0_.pricePerHour AS pricePerHour_4, c0_.maxPrice AS maxPrice_5, c0_.discr AS discr_6 FROM company_contracts c0_ INNER JOIN company_employees c1_ ON c0_.salesPerson_id = c1_.id LEFT JOIN company_persons c2_ ON c1_.id = c2_.id LEFT JOIN company_events c3_ ON (c2_.id = c3_.id) WHERE c0_.discr IN (\'fix\', \'flexible\', \'flexultra\')' + ); } public function testSupportsSelectWithCollectionAssociationJoin() From a46e794b6005b1a879a61345788701a7a06e31b4 Mon Sep 17 00:00:00 2001 From: Cvetomir Date: Fri, 15 Dec 2017 13:43:45 +0200 Subject: [PATCH 660/877] Re-order attributes of relation complex types This will provide the same look for all of the relations: one-to-many, many-to-one, one-to-one, many-to-many. It helps during auto-completion of XML code when creating XML schema for an entity. The order is as follows: field, target-entity, mapped-by, inversed-by, indexed-by, fetch, orphan-removal. --- doctrine-mapping.xsd | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/doctrine-mapping.xsd b/doctrine-mapping.xsd index 86b3dd1ed95..561b0624edb 100644 --- a/doctrine-mapping.xsd +++ b/doctrine-mapping.xsd @@ -501,11 +501,11 @@ - + - + @@ -518,12 +518,12 @@ + - - + @@ -538,10 +538,10 @@ - - + + @@ -560,8 +560,8 @@ - + From c308986a906a31fb99da583bad5b0e342df8b5de Mon Sep 17 00:00:00 2001 From: Konstantin Kuklin Date: Wed, 4 Oct 2017 03:37:17 +0300 Subject: [PATCH 661/877] Fix insufficient variable check To ensure that `AbstractQuery#setResultCacheProfile()` doesn't raise errors when being called with `null`. --- lib/Doctrine/ORM/AbstractQuery.php | 2 +- tests/Doctrine/Tests/ORM/Query/QueryTest.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 10af390539f..3ba0dee263d 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -521,7 +521,7 @@ public function getHydrationCacheProfile() */ public function setResultCacheProfile(QueryCacheProfile $profile = null) { - if ( ! $profile->getResultCacheDriver()) { + if ($profile !== null && ! $profile->getResultCacheDriver()) { $resultCacheDriver = $this->_em->getConfiguration()->getResultCacheImpl(); $profile = $profile->setResultCacheDriver($resultCacheDriver); } diff --git a/tests/Doctrine/Tests/ORM/Query/QueryTest.php b/tests/Doctrine/Tests/ORM/Query/QueryTest.php index 354586f15e6..8cceb6c503e 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryTest.php @@ -5,6 +5,7 @@ use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Internal\Hydration\IterableResult; use Doctrine\ORM\Query\Parameter; @@ -366,4 +367,18 @@ public function testSetParameterWithTypeJugglingWorks() : void self::assertSame(3, $query->getParameter('0')->getValue()); self::assertSame('Doctrine', $query->getParameter('name')->getValue()); } + + /** + * @group 6748 + */ + public function testResultCacheProfileCanBeRemovedViaSetter() : void + { + $this->_em->getConfiguration()->setResultCacheImpl(new ArrayCache()); + + $query = $this->_em->createQuery('SELECT u FROM ' . CmsUser::class . ' u'); + $query->useResultCache(true); + $query->setResultCacheProfile(); + + self::assertAttributeSame(null, '_queryCacheProfile', $query); + } } From 28b6ca3a16b5f22b0fa9762b1751a6691ea6bc11 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Sun, 17 Dec 2017 04:31:42 +0100 Subject: [PATCH 662/877] UPGRADE: Added method parenthesis, fixed method name --- UPGRADE.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 3132aef9805..6432d3a178d 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -4,20 +4,20 @@ Since it's just an utilitarian class and should not be inherited. -## Minor BC BREAK: removed `Doctrine\ORM\Query\Parser#isInternalFunction` +## Minor BC BREAK: removed `Doctrine\ORM\Query\QueryException::associationPathInverseSideNotSupported()` -Method `Doctrine\ORM\Query\QueryException::associationPathInverseSideNotSupported` +Method `Doctrine\ORM\Query\QueryException::associationPathInverseSideNotSupported()` now has a required parameter `$pathExpr`. -## Minor BC BREAK: removed `Doctrine\ORM\Query\Parser#isInternalFunction` +## Minor BC BREAK: removed `Doctrine\ORM\Query\Parser#isInternalFunction()` -Method `Doctrine\ORM\Query\Parser#isInternalFunction` was removed because +Method `Doctrine\ORM\Query\Parser#isInternalFunction()` was removed because the distinction between internal function and user defined DQL was removed. [#6500](https://github.com/doctrine/doctrine2/pull/6500) -## Minor BC BREAK: removed `Doctrine\ORM\ORMException#overwriteInternalDQLFunctionNotAllowed` +## Minor BC BREAK: removed `Doctrine\ORM\ORMException#overwriteInternalDQLFunctionNotAllowed()` -Method `Doctrine\ORM\Query\Parser#overwriteInternalDQLFunctionNotAllowed` was +Method `Doctrine\ORM\Query\Parser#overwriteInternalDQLFunctionNotAllowed()` was removed because of the choice to allow users to overwrite internal functions, ie `AVG`, `SUM`, `COUNT`, `MIN` and `MAX`. [#6500](https://github.com/doctrine/doctrine2/pull/6500) From 8ca7db885211a1c23e33a1bd41f960a724a4187f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 13 Dec 2017 20:41:19 +0100 Subject: [PATCH 663/877] Use stable packages This will make it easier to contribute. It will also make reviews safer since you will be able to tell if a PR is reponsible for a broken build or not. Catching errors early is still possible by having a look at allowed failures. --- .travis.yml | 7 +++++-- composer.json | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5399c90ac3e..75aa809082f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,8 +56,10 @@ jobs: install: travis_retry composer update --prefer-dist --prefer-lowest - stage: Test - env: DB=sqlite DEPENDENCIES=stable - install: travis_retry composer update --prefer-dist --prefer-stable + env: DB=sqlite STABILITY=dev + install: + - composer config minimum-stability $STABILITY + - travis_retry composer update --prefer-dist - stage: Test env: DB=sqlite COVERAGE @@ -91,6 +93,7 @@ jobs: allow_failures: - php: nightly + - env: DB=sqlite STABILITY=dev cache: directories: diff --git a/composer.json b/composer.json index fad4b22ff6d..2912417287b 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,6 @@ {"name": "Jonathan Wage", "email": "jonwage@gmail.com"}, {"name": "Marco Pivetta", "email": "ocramius@gmail.com"} ], - "minimum-stability": "dev", "config": { "sort-packages": true }, From ad3c3f41143160d0a436e4d402c51298bb4596df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sun, 17 Dec 2017 20:38:36 +0100 Subject: [PATCH 664/877] Implement conditional build This will make cron builds fail, which is a bit more noticeable than an allowed failure. --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 75aa809082f..cb0c6220195 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,9 +56,10 @@ jobs: install: travis_retry composer update --prefer-dist --prefer-lowest - stage: Test - env: DB=sqlite STABILITY=dev + if: type = cron + env: DB=sqlite install: - - composer config minimum-stability $STABILITY + - composer config minimum-stability dev - travis_retry composer update --prefer-dist - stage: Test @@ -93,7 +94,6 @@ jobs: allow_failures: - php: nightly - - env: DB=sqlite STABILITY=dev cache: directories: From 8e3c3f0baeadaf67c374d5da727cf226b67dad50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Mon, 18 Dec 2017 00:14:00 +0100 Subject: [PATCH 665/877] Add marker variable for Travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index cb0c6220195..50ee769a2eb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,7 +57,7 @@ jobs: - stage: Test if: type = cron - env: DB=sqlite + env: DB=sqlite DEV_DEPENDENCIES install: - composer config minimum-stability dev - travis_retry composer update --prefer-dist From 349724f05b8eabb62206a069549bc0cb4eff996a Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Tue, 19 Dec 2017 01:56:44 +0100 Subject: [PATCH 666/877] Setup: Switch Apc -> Apcu and Memcache -> Memcached --- .travis.yml | 1 + UPGRADE.md | 9 +++++++++ lib/Doctrine/ORM/Tools/Setup.php | 15 ++++++--------- phpstan.neon | 3 --- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 50ee769a2eb..44c27230c21 100644 --- a/.travis.yml +++ b/.travis.yml @@ -77,6 +77,7 @@ jobs: env: DB=none STATIC_ANALYSIS install: travis_retry composer update --prefer-dist --prefer-stable before_script: + - echo "extension=memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - echo "extension=redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - travis_retry composer require --dev --prefer-dist --prefer-stable phpstan/phpstan:^0.9 script: vendor/bin/phpstan analyse -l 1 -c phpstan.neon lib diff --git a/UPGRADE.md b/UPGRADE.md index 6432d3a178d..851e2ddf97a 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -21,6 +21,15 @@ Method `Doctrine\ORM\Query\Parser#overwriteInternalDQLFunctionNotAllowed()` was removed because of the choice to allow users to overwrite internal functions, ie `AVG`, `SUM`, `COUNT`, `MIN` and `MAX`. [#6500](https://github.com/doctrine/doctrine2/pull/6500) +## PHP 7.1 is now required + +Doctrine 2.6 now requires PHP 7.1 or newer. + +As a consequence, automatic cache setup in Doctrine\ORM\Tools\Setup::create*Configuration() was changed: +- APCu extension (ext-apcu) will now be used instead of abandoned APC (ext-apc). +- Memcached extension (ext-memcached) will be used instead of obsolete Memcache (ext-memcache). +- XCache support was dropped as it doesn't work with PHP 7. + # Upgrade to 2.5 ## Minor BC BREAK: removed `Doctrine\ORM\Query\SqlWalker#walkCaseExpression()` diff --git a/lib/Doctrine/ORM/Tools/Setup.php b/lib/Doctrine/ORM/Tools/Setup.php index 2e8a8f915ef..d4974e25867 100644 --- a/lib/Doctrine/ORM/Tools/Setup.php +++ b/lib/Doctrine/ORM/Tools/Setup.php @@ -165,19 +165,16 @@ private static function createCacheInstance(bool $isDevMode, ?Cache $cache) : Ca return new ArrayCache(); } - if (extension_loaded('apc')) { - return new \Doctrine\Common\Cache\ApcCache(); + if (extension_loaded('apcu')) { + return new \Doctrine\Common\Cache\ApcuCache(); } - if (ini_get('xcache.cacher')) { - return new \Doctrine\Common\Cache\XcacheCache(); - } - if (extension_loaded('memcache')) { - $memcache = new \Memcache(); - $memcache->connect('127.0.0.1'); + if (extension_loaded('memcached')) { + $memcache = new \Memcached(); + $memcache->addServer('127.0.0.1', 11211); - $cache = new \Doctrine\Common\Cache\MemcacheCache(); + $cache = new \Doctrine\Common\Cache\MemcachedCache(); $cache->setMemcache($memcache); return $cache; diff --git a/phpstan.neon b/phpstan.neon index 794fad8d8ad..4046aa1655c 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,6 +2,3 @@ parameters: earlyTerminatingMethodCalls: Doctrine\ORM\Query\Parser: - syntaxError - ignoreErrors: - # Memcache does not exist on PHP 7 - - '#Instantiated class Memcache not found#' From a16dc65cd206aed67a01a19f01f6318192b826af Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Mon, 18 Dec 2017 22:46:48 -0500 Subject: [PATCH 667/877] Fixes #1391, DDC-3693 --- .gitignore | 1 + tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 35 +++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/.gitignore b/.gitignore index da74102928a..eb79065bc60 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ lib/Doctrine/DBAL .buildpath .project .idea +*.iml vendor/ composer.lock /tests/Doctrine/Performance/history.db diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index fb95ba8bad2..987b565fa38 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -196,6 +196,41 @@ public function testChangeTrackingNotify() $this->assertTrue($updates[0] === $item); } + public function testChangeTrackingNotifyIndividualCommit() + { + $persister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata("Doctrine\Tests\ORM\NotifyChangedEntity")); + $this->_unitOfWork->setEntityPersister('Doctrine\Tests\ORM\NotifyChangedEntity', $persister); + $itemPersister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata("Doctrine\Tests\ORM\NotifyChangedRelatedItem")); + $this->_unitOfWork->setEntityPersister('Doctrine\Tests\ORM\NotifyChangedRelatedItem', $itemPersister); + + $entity = new NotifyChangedEntity; + $entity->setData('thedata'); + + $entity2 = new NotifyChangedEntity; + $entity2->setData('thedata'); + + $this->_unitOfWork->persist($entity); + $this->_unitOfWork->persist($entity2); + $this->_unitOfWork->commit($entity); + $this->_unitOfWork->commit(); + + $this->assertEquals(2, count($persister->getInserts())); + + $persister->reset(); + + $this->assertTrue($this->_unitOfWork->isInIdentityMap($entity2)); + + $entity->setData('newdata'); + $entity2->setData('newdata'); + + $this->_unitOfWork->commit($entity); + + $this->assertTrue($this->_unitOfWork->isScheduledForDirtyCheck($entity2)); + $this->assertEquals(array('data' => array('thedata', 'newdata')), $this->_unitOfWork->getEntityChangeSet($entity2)); + $this->assertFalse($this->_unitOfWork->isScheduledForDirtyCheck($entity)); + $this->assertEquals(array(), $this->_unitOfWork->getEntityChangeSet($entity)); + } + public function testGetEntityStateOnVersionedEntityWithAssignedIdentifier() { $persister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata(VersionedAssignedIdentifierEntity::class)); From bb8970286d9356ab6da92e83efcb9a78cb234aea Mon Sep 17 00:00:00 2001 From: Tyler Romeo Date: Sun, 27 Aug 2017 02:07:48 -0400 Subject: [PATCH 668/877] Allow association mappings as IDs for joined-table inherited entity SchemaTool has custom logic for creating the primary key of a joined-table inherited entity. This logic overlooked association maps as a possible source for identity columns, resulting in a fatal error when fetching the primary key list for child entities. Removed any custom logic for generating primary keys for root entities in joined-table inheritance, deferring to the common logic used for other entities. Also adjusted the child entity logic, scanning association maps for identity columns, and including the column as appropriate. It also ensures that the primary key columns are in the correct order. --- lib/Doctrine/ORM/Tools/SchemaTool.php | 80 ++++++++++++------- .../JoinedDerivedChildClass.php | 22 +++++ .../JoinedDerivedIdentityClass.php | 25 ++++++ .../JoinedDerivedRootClass.php | 29 +++++++ .../Tests/ORM/Tools/SchemaToolTest.php | 47 +++++++++++ 5 files changed, 174 insertions(+), 29 deletions(-) create mode 100644 tests/Doctrine/Tests/Models/CompositeKeyInheritance/JoinedDerivedChildClass.php create mode 100644 tests/Doctrine/Tests/Models/CompositeKeyInheritance/JoinedDerivedIdentityClass.php create mode 100644 tests/Doctrine/Tests/Models/CompositeKeyInheritance/JoinedDerivedRootClass.php diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 5a3eb32ab5b..2a858c493e0 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -183,19 +183,9 @@ public function getSchemaFromMetadata(array $classes) } } elseif ($class->isInheritanceTypeJoined()) { // Add all non-inherited fields as columns - $pkColumns = []; foreach ($class->fieldMappings as $fieldName => $mapping) { if ( ! isset($mapping['inherited'])) { - $columnName = $this->quoteStrategy->getColumnName( - $mapping['fieldName'], - $class, - $this->platform - ); $this->gatherColumn($class, $mapping, $table); - - if ($class->isIdentifier($fieldName)) { - $pkColumns[] = $columnName; - } } } @@ -206,10 +196,12 @@ public function getSchemaFromMetadata(array $classes) $this->addDiscriminatorColumnDefinition($class, $table); } else { // Add an ID FK column to child tables + $pkColumns = []; $inheritedKeyColumns = []; + foreach ($class->identifier as $identifierField) { - $idMapping = $class->fieldMappings[$identifierField]; - if (isset($idMapping['inherited'])) { + if (isset($class->fieldMappings[$identifierField]['inherited'])) { + $idMapping = $class->fieldMappings[$identifierField]; $this->gatherColumn($class, $idMapping, $table); $columnName = $this->quoteStrategy->getColumnName( $identifierField, @@ -221,9 +213,39 @@ public function getSchemaFromMetadata(array $classes) $pkColumns[] = $columnName; $inheritedKeyColumns[] = $columnName; + + continue; + } + + if (isset($class->associationMappings[$identifierField]['inherited'])) { + $idMapping = $class->associationMappings[$identifierField]; + + $targetEntity = current( + array_filter( + $classes, + function (ClassMetadata $class) use ($idMapping) : bool { + return $class->name === $idMapping['targetEntity']; + } + ) + ); + + foreach ($idMapping['joinColumns'] as $joinColumn) { + if (isset($targetEntity->fieldMappings[$joinColumn['referencedColumnName']])) { + $idMapping = $targetEntity->fieldMappings[$joinColumn['referencedColumnName']]; + $columnName = $this->quoteStrategy->getJoinColumnName( + $joinColumn, + $class, + $this->platform + ); + + $pkColumns[] = $columnName; + $inheritedKeyColumns[] = $columnName; + } + } } } - if (!empty($inheritedKeyColumns)) { + + if ( ! empty($inheritedKeyColumns)) { // Add a FK constraint on the ID column $table->addForeignKeyConstraint( $this->quoteStrategy->getTableName( @@ -236,10 +258,10 @@ public function getSchemaFromMetadata(array $classes) ); } + if ( ! empty($pkColumns)) { + $table->setPrimaryKey($pkColumns); + } } - - $table->setPrimaryKey($pkColumns); - } elseif ($class->isInheritanceTypeTablePerClass()) { throw ORMException::notSupported(); } else { @@ -330,7 +352,7 @@ public function getSchemaFromMetadata(array $classes) } } - if ( ! $this->platform->supportsSchemas() && ! $this->platform->canEmulateSchemas() ) { + if ( ! $this->platform->supportsSchemas() && ! $this->platform->canEmulateSchemas()) { $schema->visit(new RemoveNamespacedAssets()); } @@ -496,8 +518,8 @@ private function gatherColumn($class, array $mapping, Table $table) */ private function gatherRelationsSql($class, $table, $schema, &$addedFks, &$blacklistedFks) { - foreach ($class->associationMappings as $mapping) { - if (isset($mapping['inherited'])) { + foreach ($class->associationMappings as $id => $mapping) { + if (isset($mapping['inherited']) && array_search($id, $class->identifier) === false) { continue; } @@ -633,21 +655,21 @@ private function gatherRelationJoinColumns( if ( ! $definingClass) { throw new \Doctrine\ORM\ORMException( - "Column name `".$joinColumn['referencedColumnName']."` referenced for relation from ". - $mapping['sourceEntity'] . " towards ". $mapping['targetEntity'] . " does not exist." + 'Column name `' . $joinColumn['referencedColumnName'] . '` referenced for relation from ' + . $mapping['sourceEntity'] . ' towards ' . $mapping['targetEntity'] . ' does not exist.' ); } - $quotedColumnName = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform); - $quotedRefColumnName = $this->quoteStrategy->getReferencedJoinColumnName( + $quotedColumnName = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform); + $quotedRefColumnName = $this->quoteStrategy->getReferencedJoinColumnName( $joinColumn, $class, $this->platform ); - $primaryKeyColumns[] = $quotedColumnName; - $localColumns[] = $quotedColumnName; - $foreignColumns[] = $quotedRefColumnName; + $primaryKeyColumns[] = $quotedColumnName; + $localColumns[] = $quotedColumnName; + $foreignColumns[] = $quotedRefColumnName; if ( ! $theJoinTable->hasColumn($quotedColumnName)) { // Only add the column to the table if it does not exist already. @@ -666,7 +688,7 @@ private function gatherRelationJoinColumns( $columnOptions = ['notnull' => false, 'columnDefinition' => $columnDef]; if (isset($joinColumn['nullable'])) { - $columnOptions['notnull'] = !$joinColumn['nullable']; + $columnOptions['notnull'] = ! $joinColumn['nullable']; } if (isset($fieldMapping['options'])) { @@ -713,7 +735,7 @@ private function gatherRelationJoinColumns( } } $blacklistedFks[$compositeName] = true; - } elseif (!isset($blacklistedFks[$compositeName])) { + } elseif ( ! isset($blacklistedFks[$compositeName])) { $addedFks[$compositeName] = ['foreignTableName' => $foreignTableName, 'foreignColumns' => $foreignColumns]; $theJoinTable->addUnnamedForeignKeyConstraint( $foreignTableName, @@ -820,7 +842,7 @@ public function getDropSchemaSQL(array $classes) if ($table->hasPrimaryKey()) { $columns = $table->getPrimaryKey()->getColumns(); if (count($columns) == 1) { - $checkSequence = $table->getName() . "_" . $columns[0] . "_seq"; + $checkSequence = $table->getName() . '_' . $columns[0] . '_seq'; if ($fullSchema->hasSequence($checkSequence)) { $visitor->acceptSequence($fullSchema->getSequence($checkSequence)); } diff --git a/tests/Doctrine/Tests/Models/CompositeKeyInheritance/JoinedDerivedChildClass.php b/tests/Doctrine/Tests/Models/CompositeKeyInheritance/JoinedDerivedChildClass.php new file mode 100644 index 00000000000..8b48361992b --- /dev/null +++ b/tests/Doctrine/Tests/Models/CompositeKeyInheritance/JoinedDerivedChildClass.php @@ -0,0 +1,22 @@ +assertEquals(255, $column->getLength()); } + + public function testDerivedCompositeKey() : void + { + $em = $this->_getTestEntityManager(); + $schemaTool = new SchemaTool($em); + + $schema = $schemaTool->getSchemaFromMetadata( + [ + $em->getClassMetadata(JoinedDerivedIdentityClass::class), + $em->getClassMetadata(JoinedDerivedRootClass::class), + $em->getClassMetadata(JoinedDerivedChildClass::class), + ] + ); + + self::assertTrue($schema->hasTable('joined_derived_identity')); + self::assertTrue($schema->hasTable('joined_derived_root')); + self::assertTrue($schema->hasTable('joined_derived_child')); + + $rootTable = $schema->getTable('joined_derived_root'); + self::assertNotNull($rootTable->getPrimaryKey()); + self::assertSame(['keyPart1_id', 'keyPart2'], $rootTable->getPrimaryKey()->getColumns()); + + $childTable = $schema->getTable('joined_derived_child'); + self::assertNotNull($childTable->getPrimaryKey()); + self::assertSame(['keyPart1_id', 'keyPart2'], $childTable->getPrimaryKey()->getColumns()); + + $childTableForeignKeys = $childTable->getForeignKeys(); + + self::assertCount(2, $childTableForeignKeys); + + $expectedColumns = [ + 'joined_derived_identity' => [['keyPart1_id'], ['id']], + 'joined_derived_root' => [['keyPart1_id', 'keyPart2'], ['keyPart1_id', 'keyPart2']], + ]; + + foreach ($childTableForeignKeys as $foreignKey) { + self::assertArrayHasKey($foreignKey->getForeignTableName(), $expectedColumns); + + [$localColumns, $foreignColumns] = $expectedColumns[$foreignKey->getForeignTableName()]; + + self::assertSame($localColumns, $foreignKey->getLocalColumns()); + self::assertSame($foreignColumns, $foreignKey->getForeignColumns()); + } + } } /** From 27c42d418b95d5783cbd279dd79967d1510a3ff5 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 19 Dec 2017 18:00:03 +0100 Subject: [PATCH 669/877] #6767 removed unused variable Ref: https://github.com/doctrine/doctrine2/pull/6767/files#r157354726 --- lib/Doctrine/ORM/Tools/SchemaTool.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 2a858c493e0..1e8acaa3d0d 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -231,7 +231,6 @@ function (ClassMetadata $class) use ($idMapping) : bool { foreach ($idMapping['joinColumns'] as $joinColumn) { if (isset($targetEntity->fieldMappings[$joinColumn['referencedColumnName']])) { - $idMapping = $targetEntity->fieldMappings[$joinColumn['referencedColumnName']]; $columnName = $this->quoteStrategy->getJoinColumnName( $joinColumn, $class, From b6aa4bab15f231ea9ed8d31b516f3f657bc807de Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 19 Dec 2017 18:01:38 +0100 Subject: [PATCH 670/877] #6767 using `in_array` rather than `array_search` Ref: https://github.com/doctrine/doctrine2/pull/6767/files#r157355050 --- lib/Doctrine/ORM/Tools/SchemaTool.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 1e8acaa3d0d..1950446e7c8 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -518,7 +518,7 @@ private function gatherColumn($class, array $mapping, Table $table) private function gatherRelationsSql($class, $table, $schema, &$addedFks, &$blacklistedFks) { foreach ($class->associationMappings as $id => $mapping) { - if (isset($mapping['inherited']) && array_search($id, $class->identifier) === false) { + if (isset($mapping['inherited']) && ! \in_array($id, $class->identifier, true)) { continue; } From 0e44271a40c8ccfe560030fb91174dbafef034f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 20 Dec 2017 00:01:38 +0100 Subject: [PATCH 671/877] Require more up-to-date dependencies --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 2912417287b..5f40e2a49d3 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "require": { "php": "^7.1", "ext-pdo": "*", - "doctrine/annotations": "~1.4", + "doctrine/annotations": "~1.5", "doctrine/cache": "~1.6", "doctrine/collections": "^1.4", "doctrine/common": "^2.7.1", @@ -28,8 +28,8 @@ }, "require-dev": { "doctrine/coding-standard": "^1.0", - "phpunit/phpunit": "^6.0", - "squizlabs/php_codesniffer": "^3.1", + "phpunit/phpunit": "^6.5", + "squizlabs/php_codesniffer": "^3.2", "symfony/yaml": "~3.4|~4.0" }, "suggest": { From 374e7ace49d864dad8cddbc55346447c8a6a2083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 20 Dec 2017 01:38:15 +0100 Subject: [PATCH 672/877] Preparing v2.6.0 release --- lib/Doctrine/ORM/Version.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Version.php b/lib/Doctrine/ORM/Version.php index fee5b82c0a1..11765930c4e 100644 --- a/lib/Doctrine/ORM/Version.php +++ b/lib/Doctrine/ORM/Version.php @@ -22,7 +22,6 @@ /** * Class to store and retrieve the version of Doctrine * - * * @link www.doctrine-project.org * @since 2.0 * @version $Revision$ @@ -36,7 +35,7 @@ class Version /** * Current Doctrine Version */ - const VERSION = '2.6.0-DEV'; + const VERSION = '2.6.0'; /** * Compares a Doctrine version with the current one. From 90d19b4131559955ce0604affd49fc0d6ba9e400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 20 Dec 2017 02:01:05 +0100 Subject: [PATCH 673/877] Bumping development version to v2.6.1-DEV --- lib/Doctrine/ORM/Version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Version.php b/lib/Doctrine/ORM/Version.php index 11765930c4e..35941894ee2 100644 --- a/lib/Doctrine/ORM/Version.php +++ b/lib/Doctrine/ORM/Version.php @@ -35,7 +35,7 @@ class Version /** * Current Doctrine Version */ - const VERSION = '2.6.0'; + const VERSION = '2.6.1-DEV'; /** * Compares a Doctrine version with the current one. From 333b9c0b9950fe7b0002b2d0c8017a1affc8e7ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20FRAN=C3=87OIS?= Date: Thu, 18 Jan 2018 12:07:14 +0100 Subject: [PATCH 674/877] Fix #6991: correctly resolve identifer values in ManyToManyPersister --- lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php index 84d5ccfbcc6..c817f609794 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php @@ -419,7 +419,7 @@ protected function getDeleteSQLParameters(PersistentCollection $collection) foreach ($mapping['relationToSourceKeyColumns'] as $columnName => $refColumnName) { $params[] = isset($sourceClass->fieldNames[$refColumnName]) ? $identifier[$sourceClass->fieldNames[$refColumnName]] - : $identifier[$sourceClass->getFieldForColumn($columnName)]; + : $identifier[$sourceClass->getFieldForColumn($refColumnName)]; } return $params; From 40f2a3efbaab30e466ec9d42132b67e835694e4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20FRAN=C3=87OIS?= Date: Fri, 19 Jan 2018 18:03:46 +0100 Subject: [PATCH 675/877] Add test case for many-to-many collection deletion, when owning side has a composite PK --- .../Models/ManyToManyPersister/ChildClass.php | 52 ++++++++++++++++++ .../ManyToManyPersister/OtherParentClass.php | 23 ++++++++ .../ManyToManyPersister/ParentClass.php | 39 ++++++++++++++ .../Persisters/ManyToManyPersisterTest.php | 53 +++++++++++++++++++ 4 files changed, 167 insertions(+) create mode 100644 tests/Doctrine/Tests/Models/ManyToManyPersister/ChildClass.php create mode 100644 tests/Doctrine/Tests/Models/ManyToManyPersister/OtherParentClass.php create mode 100644 tests/Doctrine/Tests/Models/ManyToManyPersister/ParentClass.php create mode 100644 tests/Doctrine/Tests/ORM/Persisters/ManyToManyPersisterTest.php diff --git a/tests/Doctrine/Tests/Models/ManyToManyPersister/ChildClass.php b/tests/Doctrine/Tests/Models/ManyToManyPersister/ChildClass.php new file mode 100644 index 00000000000..d3b9b16c1ed --- /dev/null +++ b/tests/Doctrine/Tests/Models/ManyToManyPersister/ChildClass.php @@ -0,0 +1,52 @@ +id1 = $id1; + $this->otherParent = $otherParent; + $this->parents = new ArrayCollection(); + } +} diff --git a/tests/Doctrine/Tests/Models/ManyToManyPersister/OtherParentClass.php b/tests/Doctrine/Tests/Models/ManyToManyPersister/OtherParentClass.php new file mode 100644 index 00000000000..04e27e616d2 --- /dev/null +++ b/tests/Doctrine/Tests/Models/ManyToManyPersister/OtherParentClass.php @@ -0,0 +1,23 @@ +id = $id; + } +} diff --git a/tests/Doctrine/Tests/Models/ManyToManyPersister/ParentClass.php b/tests/Doctrine/Tests/Models/ManyToManyPersister/ParentClass.php new file mode 100644 index 00000000000..3007a1013db --- /dev/null +++ b/tests/Doctrine/Tests/Models/ManyToManyPersister/ParentClass.php @@ -0,0 +1,39 @@ +id = $id; + $this->children = new ArrayCollection(); + } +} diff --git a/tests/Doctrine/Tests/ORM/Persisters/ManyToManyPersisterTest.php b/tests/Doctrine/Tests/ORM/Persisters/ManyToManyPersisterTest.php new file mode 100644 index 00000000000..989fc849346 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Persisters/ManyToManyPersisterTest.php @@ -0,0 +1,53 @@ +children->add($child); + $child->parents->add($parent); + + $em = $this->_getTestEntityManager(); + $em->persist($parent); + $em->flush(); + + /** @var ChildClass|null $childReloaded */ + $childReloaded = $em->find(ChildClass::class, ['id1' => 1, 'otherParent' => $otherParent]); + + self::assertNotNull($childReloaded); + + $persister = new ManyToManyPersister($em); + $persister->delete($childReloaded->parents); + + /** @var ConnectionMock $conn */ + $conn = $em->getConnection(); + + $updates = $conn->getExecuteUpdates(); + $lastUpdate = array_pop($updates); + + self::assertEquals('DELETE FROM parent_child WHERE child_id1 = ? AND child_id2 = ?', $lastUpdate['query']); + self::assertEquals([1, 42], $lastUpdate['params']); + } +} From 62c952d2583c6344cd1c2d24cd32a2f1c2e68b4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Tue, 30 Jan 2018 01:21:34 +0100 Subject: [PATCH 676/877] Fix wrong variable reference --- lib/Doctrine/ORM/Tools/SchemaValidator.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/SchemaValidator.php b/lib/Doctrine/ORM/Tools/SchemaValidator.php index ee39aed817e..6446598b8df 100644 --- a/lib/Doctrine/ORM/Tools/SchemaValidator.php +++ b/lib/Doctrine/ORM/Tools/SchemaValidator.php @@ -181,9 +181,9 @@ public function validateClass(ClassMetadataInfo $class) $identifierColumns = $targetMetadata->getIdentifierColumnNames(); foreach ($assoc['joinTable']['inverseJoinColumns'] as $inverseJoinColumn) { - if (!in_array($inverseJoinColumn['referencedColumnName'], $identifierColumns)) { - $ce[] = "The referenced column name '" . $joinColumn['referencedColumnName'] . "' " . - "has to be a primary key column on the target entity class '".$targetMetadata->name."'."; + if (! in_array($inverseJoinColumn['referencedColumnName'], $identifierColumns)) { + $ce[] = "The referenced column name '" . $inverseJoinColumn['referencedColumnName'] . "' " . + "has to be a primary key column on the target entity class '" .$targetMetadata->name . "'."; break; } } From 8c2d090dc88f6b83c28fea4bea93c35c478710e6 Mon Sep 17 00:00:00 2001 From: Rolando Caldas Date: Mon, 8 Jan 2018 14:21:54 +0100 Subject: [PATCH 677/877] Exception Call to undefined method Doctrine\Common\Cache\MemcachedCache::setMemcache() When memcached extension is loaded Doctrine\ORM\Tools\Setup.php calls to setMemcache method. The MemcachedCache class has the setMemcached method instead. Changed this call in Setup to setMemcached and $memcache to $memcached to keep the name like the extension --- lib/Doctrine/ORM/Tools/Setup.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Setup.php b/lib/Doctrine/ORM/Tools/Setup.php index d4974e25867..302db6797b3 100644 --- a/lib/Doctrine/ORM/Tools/Setup.php +++ b/lib/Doctrine/ORM/Tools/Setup.php @@ -171,11 +171,11 @@ private static function createCacheInstance(bool $isDevMode, ?Cache $cache) : Ca if (extension_loaded('memcached')) { - $memcache = new \Memcached(); - $memcache->addServer('127.0.0.1', 11211); + $memcached = new \Memcached(); + $memcached->addServer('127.0.0.1', 11211); $cache = new \Doctrine\Common\Cache\MemcachedCache(); - $cache->setMemcache($memcache); + $cache->setMemcached($memcached); return $cache; } From cf99d6247282d71b565ec2686d0903f235becd7b Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Fri, 2 Feb 2018 02:48:03 +0100 Subject: [PATCH 678/877] QueryDqlFunctionTest: Increase delta for testDateAdd() to work in February --- tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php index 6c415206923..e04ce1be41d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php @@ -346,7 +346,7 @@ public function dateAddSubProvider() : array return [ 'year' => ['year', 1, 365 * $secondsInDay, 3 * $secondsInDay], - 'month' => ['month', 1, 30 * $secondsInDay, 2 * $secondsInDay], + 'month' => ['month', 1, 30 * $secondsInDay, 2.5 * $secondsInDay], 'week' => ['week', 1, 7 * $secondsInDay, $secondsInDay], 'hour' => ['hour', 1, 3600], 'minute' => ['minute', 1, 60], From 46c0861f4542324061fa650545e389dd1a21d859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Fri, 9 Feb 2018 16:32:28 +0100 Subject: [PATCH 679/877] Fix date calculation in tests (again) Now using PHP to calculate the expected date manipulation, keeping a day as delta since PHP resets the hour when performing operations with days/weeks/months/years. February is a wonderful month, isn't it? --- .../ORM/Functional/QueryDqlFunctionTest.php | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php index e04ce1be41d..cca2a371339 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php @@ -5,6 +5,7 @@ use Doctrine\ORM\AbstractQuery; use Doctrine\Tests\Models\Company\CompanyManager; use Doctrine\Tests\OrmFunctionalTestCase; +use function sprintf; /** * Functional Query tests. @@ -292,7 +293,7 @@ public function testDateDiff() * * @dataProvider dateAddSubProvider */ - public function testDateAdd(string $unit, int $amount, int $expectedValue, int $delta = 0) : void + public function testDateAdd(string $unit, int $amount, int $delta = 0) : void { $query = sprintf( 'SELECT CURRENT_TIMESTAMP() as now, DATE_ADD(CURRENT_TIMESTAMP(), %d, \'%s\') AS add FROM %s m', @@ -308,9 +309,12 @@ public function testDateAdd(string $unit, int $amount, int $expectedValue, int $ self::assertArrayHasKey('now', $result); self::assertArrayHasKey('add', $result); - $diff = strtotime($result['add']) - strtotime($result['now']); - - self::assertEquals($expectedValue, $diff, '', $delta); + self::assertEquals( + (new \DateTimeImmutable($result['now']))->modify(sprintf('+%d %s', $amount, $unit)), + new \DateTimeImmutable($result['add']), + '', + $delta + ); } /** @@ -319,7 +323,7 @@ public function testDateAdd(string $unit, int $amount, int $expectedValue, int $ * * @dataProvider dateAddSubProvider */ - public function testDateSub(string $unit, int $amount, int $expectedValue, int $delta = 0) : void + public function testDateSub(string $unit, int $amount, int $delta = 0) : void { $query = sprintf( 'SELECT CURRENT_TIMESTAMP() as now, DATE_SUB(CURRENT_TIMESTAMP(), %d, \'%s\') AS sub FROM %s m', @@ -335,9 +339,12 @@ public function testDateSub(string $unit, int $amount, int $expectedValue, int $ self::assertArrayHasKey('now', $result); self::assertArrayHasKey('sub', $result); - $diff = strtotime($result['now']) - strtotime($result['sub']); - - self::assertEquals($expectedValue, $diff, '', $delta); + self::assertEquals( + (new \DateTimeImmutable($result['now']))->modify(sprintf('-%d %s', $amount, $unit)), + new \DateTimeImmutable($result['sub']), + '', + $delta + ); } public function dateAddSubProvider() : array @@ -345,9 +352,9 @@ public function dateAddSubProvider() : array $secondsInDay = 86400; return [ - 'year' => ['year', 1, 365 * $secondsInDay, 3 * $secondsInDay], - 'month' => ['month', 1, 30 * $secondsInDay, 2.5 * $secondsInDay], - 'week' => ['week', 1, 7 * $secondsInDay, $secondsInDay], + 'year' => ['year', 1, $secondsInDay], + 'month' => ['month', 1, $secondsInDay], + 'week' => ['week', 1, $secondsInDay], 'hour' => ['hour', 1, 3600], 'minute' => ['minute', 1, 60], 'second' => ['second', 10, 10], From 7873f700b0d2bd2a04becb883a5cc59e71dd3c6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Fri, 9 Feb 2018 16:57:37 +0100 Subject: [PATCH 680/877] Add missing tests for day calculation For the DATE_SUB() and DATE_ADD() functions. --- tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php index cca2a371339..50008eb6932 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php @@ -355,6 +355,7 @@ public function dateAddSubProvider() : array 'year' => ['year', 1, $secondsInDay], 'month' => ['month', 1, $secondsInDay], 'week' => ['week', 1, $secondsInDay], + 'day' => ['day', 2, $secondsInDay], 'hour' => ['hour', 1, 3600], 'minute' => ['minute', 1, 60], 'second' => ['second', 10, 10], From 8fc1d74820cafe80a1959c8200cf400b4aec540a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98Andrey=20Lukin=E2=80=99?= <‘lukin.andrej@gmail.com’> Date: Fri, 16 Feb 2018 11:33:20 +0300 Subject: [PATCH 681/877] Add test for L2C using optimistic locks As explained in #7067, fields with `@ORM\Version` annotation were not being added to L2C cached data. --- .../ORM/Functional/Ticket/GH7067Test.php | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH7067Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7067Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7067Test.php new file mode 100644 index 00000000000..b82f25c05a7 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7067Test.php @@ -0,0 +1,69 @@ +enableSecondLevelCache(); + parent::setUp(); + + $this->setUpEntitySchema([GH7067Entity::class]); + } + + /** + * @group 7067 + */ + public function testSLCWithVersion() : void + { + $entity = new GH7067Entity(); + $entity->lastUpdate = new \DateTime(); + + $this->_em->persist($entity); + $this->_em->flush(); + $this->_em->clear(); + + /** @var GH7067Entity $notCached */ + $notCached = $this->_em->find(GH7067Entity::class, $entity->id); + + self::assertNotNull($notCached->version, 'Version already cached by persister above, it must be not null'); + + $notCached->lastUpdate = new \DateTime(); + + $this->_em->flush(); + $this->_em->clear(); + } +} + +/** + * @Entity() + * @Cache(usage="NONSTRICT_READ_WRITE") + */ +class GH7067Entity +{ + /** + * @Id + * @GeneratedValue + * @Column(type="integer") + * + * @var int + */ + public $id; + + /** + * @Column(type="datetime") + * + * @var \DateTime + */ + public $lastUpdate; + + /** + * @Column(type="datetime") + * @Version + * + * @var \DateTime + */ + public $version; +} From 8e73926359e0c34a23f8f544b69b06e9ee58dd24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98Andrey=20Lukin=E2=80=99?= <‘lukin.andrej@gmail.com’> Date: Fri, 16 Feb 2018 11:48:31 +0300 Subject: [PATCH 682/877] Add version fields into L2C data --- lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php b/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php index b654c04255f..62f76205ed3 100644 --- a/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php +++ b/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php @@ -75,6 +75,10 @@ public function buildCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, $e $data = $this->uow->getOriginalEntityData($entity); $data = array_merge($data, $metadata->getIdentifierValues($entity)); // why update has no identifier values ? + if ($metadata->isVersioned) { + $data[$metadata->versionField] = $metadata->getFieldValue($entity, $metadata->versionField); + } + foreach ($metadata->associationMappings as $name => $assoc) { if ( ! isset($data[$name])) { continue; From e94467d6da1613146746edfcb5e4661d96c2343f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sat, 17 Feb 2018 19:46:22 +0100 Subject: [PATCH 683/877] Fix incorrect value in L2C+lock test Which was causing the optimistic lock to fail in MySQL since it was trying to update the data with exact same value. --- tests/Doctrine/Tests/ORM/Functional/Ticket/GH7067Test.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7067Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7067Test.php index b82f25c05a7..10887e45b53 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7067Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7067Test.php @@ -3,6 +3,9 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use function sleep; +use function usleep; + final class GH7067Test extends \Doctrine\Tests\OrmFunctionalTestCase { public function setUp() : void @@ -30,7 +33,7 @@ public function testSLCWithVersion() : void self::assertNotNull($notCached->version, 'Version already cached by persister above, it must be not null'); - $notCached->lastUpdate = new \DateTime(); + $notCached->lastUpdate = new \DateTime('+1 seconds'); $this->_em->flush(); $this->_em->clear(); From 44e82e2720f3ae7ad54a83211a6bc9b69568ac09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sat, 17 Feb 2018 19:49:16 +0100 Subject: [PATCH 684/877] Remove unused functions --- tests/Doctrine/Tests/ORM/Functional/Ticket/GH7067Test.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7067Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7067Test.php index 10887e45b53..15dc5fa9caf 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7067Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7067Test.php @@ -3,9 +3,6 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use function sleep; -use function usleep; - final class GH7067Test extends \Doctrine\Tests\OrmFunctionalTestCase { public function setUp() : void From ae6d80daabc9647d9ceec450c8b9b4eaff86c648 Mon Sep 17 00:00:00 2001 From: Carnage Date: Fri, 9 Feb 2018 09:48:44 +0000 Subject: [PATCH 685/877] Adds sql generation test --- .../Doctrine/Tests/ORM/Query/DeleteSqlGenerationTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Query/DeleteSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/DeleteSqlGenerationTest.php index 8218339df35..1f1a7332d79 100644 --- a/tests/Doctrine/Tests/ORM/Query/DeleteSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/DeleteSqlGenerationTest.php @@ -36,6 +36,14 @@ public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed) } } + public function testSupportsDeleteWithoutWhereAndAlias() : void + { + $this->assertSqlGeneration( + 'DELETE FROM Doctrine\Tests\Models\CMS\CmsUser', + 'DELETE FROM cms_users' + ); + } + public function testSupportsDeleteWithoutWhereAndFrom() { $this->assertSqlGeneration( From f36470941c6d6f62d91632a7745e3638ec9150bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 18 Feb 2018 23:19:46 +0100 Subject: [PATCH 686/877] Fix BC-break on delete queries with nasty workaround The `v2.5.x` series of the ORM allowed to have DELETE DQLs without using an alias, even though it didn't follow the grammar rules of the parser. We fixed that issue on `v2.6.0` however that was a BC-breaking change and lots of people were relying on this faulty behaviour. This workaround fixes the BC-break, without even trying to be elegant. In `v2.7.0.` we should raise a deprecation notice to notify people that we'll drop that "feature" in `v3.0`. --- lib/Doctrine/ORM/Query/Parser.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index e726aa062aa..e8c8104bd12 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -22,6 +22,7 @@ use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Query; use Doctrine\ORM\Query\AST\Functions; +use function strpos; /** * An LL(*) recursive-descent parser for the context-free grammar of the Doctrine Query Language. @@ -1280,7 +1281,9 @@ public function DeleteClause() $this->match(Lexer::T_AS); } - $aliasIdentificationVariable = $this->AliasIdentificationVariable(); + $aliasIdentificationVariable = $this->lexer->isNextToken(Lexer::T_IDENTIFIER) + ? $this->AliasIdentificationVariable() + : 'alias_should_have_been_set'; $deleteClause->aliasIdentificationVariable = $aliasIdentificationVariable; $class = $this->em->getClassMetadata($deleteClause->abstractSchemaName); From fc943b70f629b40e08f6dc121b6466c0b5c5154f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 18 Feb 2018 23:26:18 +0100 Subject: [PATCH 687/877] Use early-returns to improve readability of the Parser --- lib/Doctrine/ORM/Query/Parser.php | 47 ++++++++++++++++--------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index e8c8104bd12..48b13df64aa 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -304,21 +304,24 @@ public function match($token) $lookaheadType = $this->lexer->lookahead['type']; // Short-circuit on first condition, usually types match - if ($lookaheadType !== $token) { - // If parameter is not identifier (1-99) must be exact match - if ($token < Lexer::T_IDENTIFIER) { - $this->syntaxError($this->lexer->getLiteral($token)); - } + if ($lookaheadType === $token) { + $this->lexer->moveNext(); + return; + } - // If parameter is keyword (200+) must be exact match - if ($token > Lexer::T_IDENTIFIER) { - $this->syntaxError($this->lexer->getLiteral($token)); - } + // If parameter is not identifier (1-99) must be exact match + if ($token < Lexer::T_IDENTIFIER) { + $this->syntaxError($this->lexer->getLiteral($token)); + } - // If parameter is T_IDENTIFIER, then matches T_IDENTIFIER (100) and keywords (200+) - if ($token === Lexer::T_IDENTIFIER && $lookaheadType < Lexer::T_IDENTIFIER) { - $this->syntaxError($this->lexer->getLiteral($token)); - } + // If parameter is keyword (200+) must be exact match + if ($token > Lexer::T_IDENTIFIER) { + $this->syntaxError($this->lexer->getLiteral($token)); + } + + // If parameter is T_IDENTIFIER, then matches T_IDENTIFIER (100) and keywords (200+) + if ($token === Lexer::T_IDENTIFIER && $lookaheadType < Lexer::T_IDENTIFIER) { + $this->syntaxError($this->lexer->getLiteral($token)); } $this->lexer->moveNext(); @@ -959,20 +962,20 @@ public function AbstractSchemaName() if ($this->lexer->isNextToken(Lexer::T_FULLY_QUALIFIED_NAME)) { $this->match(Lexer::T_FULLY_QUALIFIED_NAME); - $schemaName = $this->lexer->token['value']; - } else if ($this->lexer->isNextToken(Lexer::T_IDENTIFIER)) { + return $this->lexer->token['value']; + } + + if ($this->lexer->isNextToken(Lexer::T_IDENTIFIER)) { $this->match(Lexer::T_IDENTIFIER); - $schemaName = $this->lexer->token['value']; - } else { - $this->match(Lexer::T_ALIASED_NAME); + return $this->lexer->token['value']; + } - list($namespaceAlias, $simpleClassName) = explode(':', $this->lexer->token['value']); + $this->match(Lexer::T_ALIASED_NAME); - $schemaName = $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName; - } + [$namespaceAlias, $simpleClassName] = explode(':', $this->lexer->token['value']); - return $schemaName; + return $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName; } /** From 15a43029024f1f6269df8695ee85c6984fdc1c2f Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Mon, 15 Jan 2018 14:01:56 -0500 Subject: [PATCH 688/877] Inheritance middle-layer doesn't get hydrated with HYDRATE_OBJECT --- .../ORM/Functional/Ticket/GH6937Test.php | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH6937Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6937Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6937Test.php new file mode 100644 index 00000000000..756111b9898 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6937Test.php @@ -0,0 +1,119 @@ +setUpEntitySchema([GH6937Person::class, GH6937Employee::class, GH6937Manager::class]); + } + + public function testPhoneNumberIsPopulatedWithFind() : void + { + $manager = new GH6937Manager(); + $manager->name = 'Kevin'; + $manager->phoneNumber = '555-5555'; + $manager->department = 'Accounting'; + + $this->_em->persist($manager); + $this->_em->flush(); + $this->_em->clear(); + + $persistedManager = $this->_em->find(GH6937Person::class, $manager->id); + + self::assertSame('Kevin', $persistedManager->name); + self::assertSame('555-5555', $persistedManager->phoneNumber); + self::assertSame('Accounting', $persistedManager->department); + } + + public function testPhoneNumberIsPopulatedWithQueryBuilderUsingSimpleObjectHydrator() : void + { + $manager = new GH6937Manager(); + $manager->name = 'Kevin'; + $manager->phoneNumber = '555-5555'; + $manager->department = 'Accounting'; + + $this->_em->persist($manager); + $this->_em->flush(); + $this->_em->clear(); + + $persistedManager = $this->_em->getRepository(GH6937Person::class) + ->createQueryBuilder('e') + ->where('e.id = :id') + ->setParameter('id', $manager->id) + ->getQuery() + ->getOneOrNullResult(AbstractQuery::HYDRATE_SIMPLEOBJECT); + + self::assertSame('Kevin', $persistedManager->name); + self::assertSame('555-5555', $persistedManager->phoneNumber); + self::assertSame('Accounting', $persistedManager->department); + } + + public function testPhoneNumberIsPopulatedWithQueryBuilder() : void + { + $manager = new GH6937Manager(); + $manager->name = 'Kevin'; + $manager->phoneNumber = '555-5555'; + $manager->department = 'Accounting'; + + $this->_em->persist($manager); + $this->_em->flush(); + $this->_em->clear(); + + $persistedManager = $this->_em->getRepository(GH6937Person::class) + ->createQueryBuilder('e') + ->where('e.id = :id') + ->setParameter('id', $manager->id) + ->getQuery() + ->getOneOrNullResult(); + + self::assertSame('Kevin', $persistedManager->name); + self::assertSame('555-5555', $persistedManager->phoneNumber); + self::assertSame('Accounting', $persistedManager->department); + } +} + +/** + * @Entity + * @InheritanceType("JOINED") + * @DiscriminatorColumn(name="discr", type="string") + * @DiscriminatorMap({"employee"=GH6937Employee::class, "manager"=GH6937Manager::class}) + */ +abstract class GH6937Person +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; + + /** @Column(type="string") */ + public $name; +} + +/** + * @Entity + */ +abstract class GH6937Employee extends GH6937Person +{ + /** @Column(type="string") */ + public $phoneNumber; +} + +/** + * @Entity + */ +class GH6937Manager extends GH6937Employee +{ + /** @Column(type="string") */ + public $department; +} From 48ca6dbcec125c7b273bdfe278f9448cd2f0db5b Mon Sep 17 00:00:00 2001 From: Toni Cornelissen Date: Sun, 18 Feb 2018 09:45:20 +0100 Subject: [PATCH 689/877] Use partial discriminator map on multi-inheritance Hydrator was ignoring data from subclasses when using multiple inheritance levels. With this patch it will now use the discriminator values from all subclasses of the class being hydrated. --- .../Internal/Hydration/AbstractHydrator.php | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index b38a212c9e6..1fd327be877 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -24,6 +24,8 @@ use Doctrine\ORM\Events; use Doctrine\ORM\Mapping\ClassMetadata; use PDO; +use function array_map; +use function in_array; /** * Base class for all hydrators. A hydrator is a class that provides some form @@ -296,11 +298,9 @@ protected function gatherRowData(array $data, array &$id, array &$nonemptyCompon // If there are field name collisions in the child class, then we need // to only hydrate if we are looking at the correct discriminator value - if( - isset($cacheKeyInfo['discriminatorColumn']) && - isset($data[$cacheKeyInfo['discriminatorColumn']]) && + if (isset($cacheKeyInfo['discriminatorColumn'], $data[$cacheKeyInfo['discriminatorColumn']]) // Note: loose comparison required. See https://github.com/doctrine/doctrine2/pull/6304#issuecomment-323294442 - $data[$cacheKeyInfo['discriminatorColumn']] != $cacheKeyInfo['discriminatorValue'] + && ! in_array($data[$cacheKeyInfo['discriminatorColumn']], $cacheKeyInfo['discriminatorValues']) ) { break; } @@ -397,11 +397,21 @@ protected function hydrateColumnInfo($key) // the current discriminator value must be saved in order to disambiguate fields hydration, // should there be field name collisions if ($classMetadata->parentClasses && isset($this->_rsm->discriminatorColumns[$ownerMap])) { + $discriminatorValues = array_map( + function (string $subClass) { + return $this->getClassMetadata($subClass)->discriminatorValue; + }, + $classMetadata->subClasses + ); + + $discriminatorValues[] = $classMetadata->discriminatorValue; + return $this->_cache[$key] = \array_merge( $columnInfo, [ 'discriminatorColumn' => $this->_rsm->discriminatorColumns[$ownerMap], - 'discriminatorValue' => $classMetadata->discriminatorValue + 'discriminatorValue' => $classMetadata->discriminatorValue, + 'discriminatorValues' => $discriminatorValues, ] ); } From 2905b435db46b71a501991dccb256a7c037d8972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 18 Feb 2018 09:49:41 +0100 Subject: [PATCH 690/877] Remove loose comparison on discriminator values According to mapping drivers the discriminator values can always be converted to strings so it's safe to assume that we can actually do a strict comparison during hydration. --- lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index 1fd327be877..144fe8257f4 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -299,8 +299,7 @@ protected function gatherRowData(array $data, array &$id, array &$nonemptyCompon // If there are field name collisions in the child class, then we need // to only hydrate if we are looking at the correct discriminator value if (isset($cacheKeyInfo['discriminatorColumn'], $data[$cacheKeyInfo['discriminatorColumn']]) - // Note: loose comparison required. See https://github.com/doctrine/doctrine2/pull/6304#issuecomment-323294442 - && ! in_array($data[$cacheKeyInfo['discriminatorColumn']], $cacheKeyInfo['discriminatorValues']) + && ! in_array((string) $data[$cacheKeyInfo['discriminatorColumn']], $cacheKeyInfo['discriminatorValues'], true) ) { break; } @@ -398,13 +397,13 @@ protected function hydrateColumnInfo($key) // should there be field name collisions if ($classMetadata->parentClasses && isset($this->_rsm->discriminatorColumns[$ownerMap])) { $discriminatorValues = array_map( - function (string $subClass) { - return $this->getClassMetadata($subClass)->discriminatorValue; + function (string $subClass) : string { + return (string) $this->getClassMetadata($subClass)->discriminatorValue; }, $classMetadata->subClasses ); - $discriminatorValues[] = $classMetadata->discriminatorValue; + $discriminatorValues[] = (string) $classMetadata->discriminatorValue; return $this->_cache[$key] = \array_merge( $columnInfo, From f2da5bc93efd95d546f5396e8489ddaafef006a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Mon, 19 Feb 2018 11:05:30 +0100 Subject: [PATCH 691/877] Extract private method to retrieve discriminator values --- .../Internal/Hydration/AbstractHydrator.php | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index 144fe8257f4..5fe4fa1e53d 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -396,21 +396,12 @@ protected function hydrateColumnInfo($key) // the current discriminator value must be saved in order to disambiguate fields hydration, // should there be field name collisions if ($classMetadata->parentClasses && isset($this->_rsm->discriminatorColumns[$ownerMap])) { - $discriminatorValues = array_map( - function (string $subClass) : string { - return (string) $this->getClassMetadata($subClass)->discriminatorValue; - }, - $classMetadata->subClasses - ); - - $discriminatorValues[] = (string) $classMetadata->discriminatorValue; - return $this->_cache[$key] = \array_merge( $columnInfo, [ 'discriminatorColumn' => $this->_rsm->discriminatorColumns[$ownerMap], 'discriminatorValue' => $classMetadata->discriminatorValue, - 'discriminatorValues' => $discriminatorValues, + 'discriminatorValues' => $this->getDiscriminatorValues($classMetadata), ] ); } @@ -463,6 +454,23 @@ function (string $subClass) : string { return null; } + /** + * @return string[] + */ + private function getDiscriminatorValues(ClassMetadata $classMetadata) : array + { + $values = array_map( + function (string $subClass) : string { + return (string) $this->getClassMetadata($subClass)->discriminatorValue; + }, + $classMetadata->subClasses + ); + + $values[] = (string) $classMetadata->discriminatorValue; + + return $values; + } + /** * Retrieve ClassMetadata associated to entity class name. * From a912fc09bea3666b883d14c569113dc2e10433ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Mon, 19 Feb 2018 22:04:28 +0100 Subject: [PATCH 692/877] Add `@group` to delete query test --- tests/Doctrine/Tests/ORM/Query/DeleteSqlGenerationTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Query/DeleteSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/DeleteSqlGenerationTest.php index 1f1a7332d79..ee5f98ac524 100644 --- a/tests/Doctrine/Tests/ORM/Query/DeleteSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/DeleteSqlGenerationTest.php @@ -36,6 +36,9 @@ public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed) } } + /** + * @group 6939 + */ public function testSupportsDeleteWithoutWhereAndAlias() : void { $this->assertSqlGeneration( From 23f4f0357530b46a76bae26a194bd50754cc5fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=C5=A1ek=20Henzl?= Date: Wed, 13 Sep 2017 16:15:31 +1200 Subject: [PATCH 693/877] Add failing tests for #6531 Tests are based on examples from "Composite and Foreign Keys as Primary Key" tutorial: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/composite-primary-keys.html --- .../ORM/Functional/Ticket/GH6531Test.php | 190 ++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH6531Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6531Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6531Test.php new file mode 100644 index 00000000000..1d819f2508f --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6531Test.php @@ -0,0 +1,190 @@ +setUpEntitySchema( + [ + GH6531User::class, + GH6531Address::class, + GH6531Article::class, + GH6531ArticleAttribute::class, + GH6531Order::class, + GH6531OrderItem::class, + GH6531Product::class, + ] + ); + } + + /** + * @group 6531 + */ + public function testSimpleDerivedIdentity() : void + { + $user = new GH6531User(); + $address = new GH6531Address(); + $address->user = $user; + + $this->_em->persist($user); + $this->_em->persist($address); + $this->_em->flush(); + + self::assertSame($user, $this->_em->find(GH6531User::class, $user->id)); + self::assertSame($address, $this->_em->find(GH6531Address::class, $user)); + } + + /** + * @group 6531 + */ + public function testDynamicAttributes() : void + { + $article = new GH6531Article(); + $article->addAttribute('name', 'value'); + + $this->_em->persist($article); + $this->_em->flush(); + + self::assertSame( + $article->attributes['name'], + $this->_em->find(GH6531ArticleAttribute::class, ['article' => $article, 'attribute' => 'name']) + ); + } + + /** + * @group 6531 + */ + public function testJoinTableWithMetadata() : void + { + $product = new GH6531Product(); + $this->_em->persist($product); + $this->_em->flush(); + + $order = new GH6531Order(); + $order->addItem($product, 2); + + $this->_em->persist($order); + $this->_em->flush(); + + self::assertSame( + $order->items->first(), + $this->_em->find(GH6531OrderItem::class, ['product' => $product, 'order' => $order]) + ); + } +} + +/** + * @Entity + */ +class GH6531User +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; +} + +/** + * @Entity + */ +class GH6531Address +{ + /** @Id @OneToOne(targetEntity=GH6531User::class) */ + public $user; +} + +/** + * @Entity + */ +class GH6531Article +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; + + /** @OneToMany(targetEntity=GH6531ArticleAttribute::class, mappedBy="article", cascade={"ALL"}, indexBy="attribute") */ + public $attributes; + + public function addAttribute(string $name, string $value) + { + $this->attributes[$name] = new GH6531ArticleAttribute($name, $value, $this); + } +} + +/** + * @Entity + */ +class GH6531ArticleAttribute +{ + /** @Id @ManyToOne(targetEntity=GH6531Article::class, inversedBy="attributes") */ + public $article; + + /** @Id @Column(type="string") */ + public $attribute; + + /** @Column(type="string") */ + public $value; + + public function __construct(string $name, string $value, GH6531Article $article) + { + $this->attribute = $name; + $this->value = $value; + $this->article = $article; + } +} + +/** + * @Entity + */ +class GH6531Order +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; + + /** @OneToMany(targetEntity=GH6531OrderItem::class, mappedBy="order", cascade={"ALL"}) */ + public $items; + + public function __construct() + { + $this->items = new ArrayCollection(); + } + + public function addItem(GH6531Product $product, int $amount) : void + { + $this->items->add(new GH6531OrderItem($this, $product, $amount)); + } +} + +/** + * @Entity + */ +class GH6531Product +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; +} + +/** + * @Entity + */ +class GH6531OrderItem +{ + /** @Id @ManyToOne(targetEntity=GH6531Order::class) */ + public $order; + + /** @Id @ManyToOne(targetEntity=GH6531Product::class) */ + public $product; + + /** @Column(type="integer") */ + public $amount = 1; + + public function __construct(GH6531Order $order, GH6531Product $product, int $amount = 1) + { + $this->order = $order; + $this->product = $product; + $this->amount = $amount; + } +} From 35c3669ebc822c88444d92e9ffc739d12f551d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20FRAN=C3=87OIS?= Date: Mon, 22 Jan 2018 19:10:42 +0100 Subject: [PATCH 694/877] Fix handling entities with post generated IDs as FK This prevents a throw in UnitOfWork#addToIdentityMap because some fields are null. --- lib/Doctrine/ORM/UnitOfWork.php | 56 ++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 56017301bf2..6767e7ef310 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -940,7 +940,11 @@ private function persistNew($class, $entity) $class->setIdentifierValues($entity, $idValue); } - $this->entityIdentifiers[$oid] = $idValue; + // Some identifiers may be foreign keys to new entities. + // In this case, we don't have the value yet and should treat it as if we have a post-insert generator + if (! $this->hasMissingIdsWhichAreForeignKeys($class, $idValue)) { + $this->entityIdentifiers[$oid] = $idValue; + } } $this->entityStates[$oid] = self::STATE_MANAGED; @@ -948,6 +952,20 @@ private function persistNew($class, $entity) $this->scheduleForInsert($entity); } + /** + * @param mixed[] $idValue + */ + private function hasMissingIdsWhichAreForeignKeys(ClassMetadata $class, array $idValue) : bool + { + foreach ($idValue as $idField => $idFieldValue) { + if ($idFieldValue === null && isset($class->associationMappings[$idField])) { + return true; + } + } + + return false; + } + /** * INTERNAL: * Computes the changeset of an individual entity, independently of the @@ -1033,12 +1051,16 @@ private function executeInserts($class) $persister = $this->getEntityPersister($className); $invoke = $this->listenersInvoker->getSubscribedSystems($class, Events::postPersist); + $insertionsForClass = []; + foreach ($this->entityInsertions as $oid => $entity) { if ($this->em->getClassMetadata(get_class($entity))->name !== $className) { continue; } + $insertionsForClass[$oid] = $entity; + $persister->addInsert($entity); unset($this->entityInsertions[$oid]); @@ -1067,6 +1089,14 @@ private function executeInserts($class) $this->addToIdentityMap($entity); } + } else { + foreach ($insertionsForClass as $oid => $entity) { + if (! isset($this->entityIdentifiers[$oid])) { + //entity was not added to identity map because some identifiers are foreign keys to new entities. + //add it now + $this->addToEntityIdentifiersAndEntityMap($class, $oid, $entity); + } + } } foreach ($entities as $entity) { @@ -1074,6 +1104,30 @@ private function executeInserts($class) } } + /** + * @param object $entity + */ + private function addToEntityIdentifiersAndEntityMap(ClassMetadata $class, string $oid, $entity): void + { + $identifier = []; + + foreach ($class->getIdentifierFieldNames() as $idField) { + $value = $class->getFieldValue($entity, $idField); + + if (isset($class->associationMappings[$idField])) { + // NOTE: Single Columns as associated identifiers only allowed - this constraint it is enforced. + $value = $this->getSingleIdentifierValue($value); + } + + $identifier[$idField] = $this->originalEntityData[$oid][$idField] = $value; + } + + $this->entityStates[$oid] = self::STATE_MANAGED; + $this->entityIdentifiers[$oid] = $identifier; + + $this->addToIdentityMap($entity); + } + /** * Executes all entity updates for entities of the specified type. * From e68717b725148d5ed9e8e4a33814c06e4774f520 Mon Sep 17 00:00:00 2001 From: Jan Langer Date: Fri, 26 Jan 2018 15:23:19 +0100 Subject: [PATCH 695/877] Fix updating entities with quoted identifier association --- .../Entity/BasicEntityPersister.php | 11 ++- .../ORM/Functional/Ticket/GH7012Test.php | 82 +++++++++++++++++++ 2 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH7012Test.php diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 6152c417688..2797a76e94b 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -451,9 +451,14 @@ protected final function updateTable($entity, $quotedTableName, array $updateDat continue; } - $params[] = $identifier[$idField]; - $where[] = $this->class->associationMappings[$idField]['joinColumns'][0]['name']; - $targetMapping = $this->em->getClassMetadata($this->class->associationMappings[$idField]['targetEntity']); + $params[] = $identifier[$idField]; + $where[] = $this->quoteStrategy->getJoinColumnName( + $this->class->associationMappings[$idField]['joinColumns'][0], + $this->class, + $this->platform + ); + + $targetMapping = $this->em->getClassMetadata($this->class->associationMappings[$idField]['targetEntity']); switch (true) { case (isset($targetMapping->fieldMappings[$targetMapping->identifier[0]])): diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7012Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7012Test.php new file mode 100644 index 00000000000..38f57c57c6c --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7012Test.php @@ -0,0 +1,82 @@ +useModelSet('quote'); + + parent::setUp(); + + $this->setUpEntitySchema([GH7012UserData::class]); + } + + /** + * @group 7012 + */ + public function testUpdateEntityWithIdentifierAssociationWithQuotedJoinColumn() : void + { + $user = new QuotedUser(); + $user->name = 'John Doe'; + + $this->_em->persist($user); + $this->_em->flush(); + + $userData = new GH7012UserData($user, '123456789'); + + $this->_em->persist($userData); + $this->_em->flush(); + + $userData->name = '4321'; + $this->_em->flush(); + + $platform = $this->_em->getConnection()->getDatabasePlatform(); + $quotedTableName = $platform->quoteIdentifier('quote-user-data'); + $quotedColumn = $platform->quoteIdentifier('name'); + $quotedIdentifier = $platform->quoteIdentifier('user-id'); + + self::assertNotEquals('quote-user-data', $quotedTableName); + self::assertNotEquals('name', $quotedColumn); + self::assertNotEquals('user-id', $quotedIdentifier); + + $queries = $this->_sqlLoggerStack->queries; + + $this->assertSQLEquals( + sprintf('UPDATE %s SET %s = ? WHERE %s = ?', $quotedTableName, $quotedColumn, $quotedIdentifier), + $queries[$this->_sqlLoggerStack->currentQuery - 1]['sql'] + ); + } +} + + +/** + * @Entity + * @Table(name="`quote-user-data`") + */ +class GH7012UserData +{ + /** + * @Id + * @OneToOne(targetEntity=Doctrine\Tests\Models\Quote\User::class) + * @JoinColumn(name="`user-id`", referencedColumnName="`user-id`", onDelete="CASCADE") + */ + public $user; + + /** + * @Column(type="string", name="`name`") + */ + public $name; + + public function __construct(QuotedUser $user, string $name) + { + $this->user = $user; + $this->name = $name; + } +} From b952dac339dc18f22211d39e7e65ddee28d3d96c Mon Sep 17 00:00:00 2001 From: Marius Klocke Date: Tue, 20 Feb 2018 22:33:19 +0100 Subject: [PATCH 696/877] Add a failing test for issue 7062 --- .../ORM/Functional/Ticket/GH7062Test.php | 212 ++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH7062Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7062Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7062Test.php new file mode 100644 index 00000000000..1d7a2d7cbd0 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7062Test.php @@ -0,0 +1,212 @@ +setUpEntitySchema( + [ + GH7062Team::class, + GH7062Season::class, + GH7062Ranking::class, + GH7062RankingPosition::class + ] + ); + } + + /** + * @group 7062 + */ + public function testEntityWithAssociationKeyIdentityCanBeUpdated() : void + { + $this->createInitialRankingWithRelatedEntities(); + $this->modifyRanking(); + $this->verifyRanking(); + } + + private function createInitialRankingWithRelatedEntities() : void + { + $team = new GH7062Team(self::TEAM_ID); + $season = new GH7062Season(self::SEASON_ID); + + $season->ranking = new GH7062Ranking($season, [$team]); + + $this->_em->persist($team); + $this->_em->persist($season); + $this->_em->flush(); + $this->_em->clear(); + + foreach ($season->ranking->positions as $position) { + self::assertSame(0, $position->points); + } + } + + private function modifyRanking() : void + { + /** @var GH7062Ranking $ranking */ + $ranking = $this->_em->find(GH7062Ranking::class, self::SEASON_ID); + + foreach ($ranking->positions as $position) { + $position->points += 3; + } + + $this->_em->flush(); + $this->_em->clear(); + } + + private function verifyRanking() : void + { + /** @var GH7062Season $season */ + $season = $this->_em->find(GH7062Season::class, self::SEASON_ID); + self::assertInstanceOf(GH7062Season::class, $season); + + $ranking = $season->ranking; + self::assertInstanceOf(GH7062Ranking::class, $ranking); + + foreach ($ranking->positions as $position) { + self::assertSame(3, $position->points); + } + } +} + +/** + * Simple Entity whose identity is defined through another Entity (Season) + * + * @Entity + * @Table(name="soccer_rankings") + */ +class GH7062Ranking +{ + /** + * @Id + * @OneToOne(targetEntity=GH7062Season::class, inversedBy="ranking") + * @JoinColumn(name="season", referencedColumnName="id") + * + * @var GH7062Season + */ + public $season; + + /** + * @OneToMany(targetEntity=GH7062RankingPosition::class, mappedBy="ranking", cascade={"all"}) + * + * @var Collection|GH7062RankingPosition[] + */ + public $positions; + + /** + * @param GH7062Team[] $teams + */ + public function __construct(GH7062Season $season, array $teams) + { + $this->season = $season; + $this->positions = new ArrayCollection(); + + foreach ($teams as $team) { + $this->positions[] = new GH7062RankingPosition($this, $team); + } + } +} + +/** + * Entity which serves as a identity provider for other entities + * + * @Entity + * @Table(name="soccer_seasons") + */ +class GH7062Season +{ + /** + * @Id + * @Column(type="string") + * + * @var string + */ + public $id; + + /** + * @OneToOne(targetEntity=GH7062Ranking::class, mappedBy="season", cascade={"all"}) + * + * @var GH7062Ranking|null + */ + public $ranking; + + public function __construct(string $id) + { + $this->id = $id; + } +} + +/** + * Entity which serves as a identity provider for other entities + * + * @Entity + * @Table(name="soccer_teams") + */ +class GH7062Team +{ + /** + * @Id + * @Column(type="string") + * + * @var string + */ + public $id; + + public function __construct(string $id) + { + $this->id = $id; + } +} + +/** + * Entity whose identity is defined through two other entities + * + * @Entity + * @Table(name="soccer_ranking_positions") + */ +class GH7062RankingPosition +{ + /** + * @Id + * @ManyToOne(targetEntity=GH7062Ranking::class, inversedBy="positions") + * @JoinColumn(name="season", referencedColumnName="season") + * + * @var GH7062Ranking + */ + public $ranking; + + /** + * @Id + * @ManyToOne(targetEntity=GH7062Team::class) + * @JoinColumn(name="team_id", referencedColumnName="id") + * + * @var GH7062Team + */ + public $team; + + /** + * @Column(type="integer") + * + * @var int + */ + public $points; + + public function __construct(GH7062Ranking $ranking, GH7062Team $team) + { + $this->ranking = $ranking; + $this->team = $team; + $this->points = 0; + } +} From d47c1f3e9b3c6a9b6df8de760fbfb7a33f13d2e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 25 Feb 2018 22:35:46 +0100 Subject: [PATCH 697/877] Fix basic entity persister type resolver Which was using the wrong way to fetch the field type and using the association type instead of the column type. --- .../Persisters/Entity/BasicEntityPersister.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 2797a76e94b..14344d9f669 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -37,6 +37,8 @@ use Doctrine\ORM\UnitOfWork; use Doctrine\ORM\Utility\IdentifierFlattener; use Doctrine\ORM\Utility\PersisterHelper; +use function array_merge; +use function reset; /** * A BasicEntityPersister maps an entity to a single table in a relational database. @@ -459,20 +461,13 @@ protected final function updateTable($entity, $quotedTableName, array $updateDat ); $targetMapping = $this->em->getClassMetadata($this->class->associationMappings[$idField]['targetEntity']); + $targetType = PersisterHelper::getTypeOfField($targetMapping->identifier[0], $targetMapping, $this->em); - switch (true) { - case (isset($targetMapping->fieldMappings[$targetMapping->identifier[0]])): - $types[] = $targetMapping->fieldMappings[$targetMapping->identifier[0]]['type']; - break; - - case (isset($targetMapping->associationMappings[$targetMapping->identifier[0]])): - $types[] = $targetMapping->associationMappings[$targetMapping->identifier[0]]['type']; - break; - - default: - throw ORMException::unrecognizedField($targetMapping->identifier[0]); + if ($targetType === []) { + throw ORMException::unrecognizedField($targetMapping->identifier[0]); } + $types[] = reset($targetType); } if ($versioned) { From 2560d4f419ad51869abd07f047cdda454f3fdc7e Mon Sep 17 00:00:00 2001 From: Donovan Bourlard Date: Thu, 22 Mar 2018 14:51:02 +0100 Subject: [PATCH 698/877] Fix default value of one-to-many order-by to ASC, #7141 --- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 6 +++++- .../Tests/Models/GH7141/GH7141Article.php | 15 ++++++++++++++ .../ORM/Mapping/XmlMappingDriverTest.php | 20 +++++++++++++++++++ ....Tests.Models.GH7141.GH7141Article.dcm.xml | 14 +++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/Tests/Models/GH7141/GH7141Article.php create mode 100644 tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.GH7141.GH7141Article.dcm.xml diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index ca270727863..3229b6b73cb 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -19,6 +19,7 @@ namespace Doctrine\ORM\Mapping\Driver; +use Doctrine\Common\Collections\Criteria; use SimpleXMLElement; use Doctrine\Common\Persistence\Mapping\Driver\FileDriver; use Doctrine\ORM\Mapping\Builder\EntityListenerBuilder; @@ -429,7 +430,10 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) if (isset($oneToManyElement->{'order-by'})) { $orderBy = []; foreach ($oneToManyElement->{'order-by'}->{'order-by-field'} as $orderByField) { - $orderBy[(string) $orderByField['name']] = (string) $orderByField['direction']; + $orderBy[(string) $orderByField['name']] = isset($orderByField['direction']) + ? (string) $orderByField['direction'] + : Criteria::ASC + ; } $mapping['orderBy'] = $orderBy; } diff --git a/tests/Doctrine/Tests/Models/GH7141/GH7141Article.php b/tests/Doctrine/Tests/Models/GH7141/GH7141Article.php new file mode 100644 index 00000000000..5af97c62ef5 --- /dev/null +++ b/tests/Doctrine/Tests/Models/GH7141/GH7141Article.php @@ -0,0 +1,15 @@ +tags = new ArrayCollection(); + } +} diff --git a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php index cc543b8919f..d0a38b49036 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Mapping; +use Doctrine\Common\Collections\Criteria; use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataFactory; @@ -11,6 +12,7 @@ use Doctrine\Tests\Models\DDC3293\DDC3293UserPrefixed; use Doctrine\Tests\Models\DDC889\DDC889Class; use Doctrine\Tests\Models\Generic\SerializationModel; +use Doctrine\Tests\Models\GH7141\GH7141Article; use Doctrine\Tests\Models\ValueObjects\Name; use Doctrine\Tests\Models\ValueObjects\Person; @@ -174,6 +176,24 @@ static public function dataValidSchema() }, $list); } + /** + * @group GH-7141 + */ + public function testOneToManyDefaultOrderByAsc() + { + $driver = $this->_loadDriver(); + $class = new ClassMetadata(GH7141Article::class); + + $class->initializeReflection(new RuntimeReflectionService()); + $driver->loadMetadataForClass(GH7141Article::class, $class); + + + $this->assertEquals( + Criteria::ASC, + $class->getMetadataValue('associationMappings')['tags']['orderBy']['position'] + ); + } + /** * @group DDC-889 * @expectedException \Doctrine\Common\Persistence\Mapping\MappingException diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.GH7141.GH7141Article.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.GH7141.GH7141Article.dcm.xml new file mode 100644 index 00000000000..e073f380f5f --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.GH7141.GH7141Article.dcm.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + From 8ceb47178b5a1e06f638a393ec32044c40b969cc Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Tue, 10 Apr 2018 18:31:36 +0200 Subject: [PATCH 699/877] Fix wrong type in phpdoc of AbstractIdGenerator \Doctrine\ORM\Mapping\Entity is the annotation class which is not correct. The entity object itself is meant here as tests also assume see https://github.com/doctrine/doctrine2/blob/2.6/tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php#L28 Found this when running phpstan on our code that used a custom generator. --- lib/Doctrine/ORM/Id/AbstractIdGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Id/AbstractIdGenerator.php b/lib/Doctrine/ORM/Id/AbstractIdGenerator.php index dada71e43ad..011848cbf84 100644 --- a/lib/Doctrine/ORM/Id/AbstractIdGenerator.php +++ b/lib/Doctrine/ORM/Id/AbstractIdGenerator.php @@ -27,7 +27,7 @@ abstract class AbstractIdGenerator * Generates an identifier for an entity. * * @param EntityManager $em - * @param \Doctrine\ORM\Mapping\Entity $entity + * @param object $entity * @return mixed */ abstract public function generate(EntityManager $em, $entity); From 7ba0290643b92ea8929d1afaf0a3976642a513a6 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Tue, 10 Apr 2018 19:15:48 +0200 Subject: [PATCH 700/877] entity should be nullable as in master --- lib/Doctrine/ORM/Id/AbstractIdGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Id/AbstractIdGenerator.php b/lib/Doctrine/ORM/Id/AbstractIdGenerator.php index 011848cbf84..9e2e2262514 100644 --- a/lib/Doctrine/ORM/Id/AbstractIdGenerator.php +++ b/lib/Doctrine/ORM/Id/AbstractIdGenerator.php @@ -27,7 +27,7 @@ abstract class AbstractIdGenerator * Generates an identifier for an entity. * * @param EntityManager $em - * @param object $entity + * @param object|null $entity * @return mixed */ abstract public function generate(EntityManager $em, $entity); From b6d08b15c044a81b5a707f228d596d5801350611 Mon Sep 17 00:00:00 2001 From: Jarek Jakubowski Date: Fri, 8 Jun 2018 18:47:39 +0200 Subject: [PATCH 701/877] Mention that Doctrine does not use Entities public API --- docs/en/reference/working-with-objects.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/en/reference/working-with-objects.rst b/docs/en/reference/working-with-objects.rst index bef73cebaa3..72d50926253 100644 --- a/docs/en/reference/working-with-objects.rst +++ b/docs/en/reference/working-with-objects.rst @@ -25,6 +25,14 @@ Work that have not yet been persisted are lost. Not calling ``EntityManager#flush()`` will lead to all changes during that request being lost. +.. note:: + + Doctrine does NEVER touch the public API of methods in your entity + classes (getters and setters). + Instead, it uses reflection to set/get data from your objects. + When Doctrine fetches data from DB and saves it back, + any code put in your get/set methods won't be implicitly taken into account. + Entities and the Identity Map ----------------------------- From 6b7d67b427e485bad9ebba7f19d7d95cefbecf37 Mon Sep 17 00:00:00 2001 From: Jarek Jakubowski Date: Fri, 8 Jun 2018 20:29:37 +0200 Subject: [PATCH 702/877] Add info about Doctrine not using constructor --- docs/en/reference/working-with-objects.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/working-with-objects.rst b/docs/en/reference/working-with-objects.rst index 72d50926253..1bff38a7cb1 100644 --- a/docs/en/reference/working-with-objects.rst +++ b/docs/en/reference/working-with-objects.rst @@ -28,7 +28,7 @@ Work that have not yet been persisted are lost. .. note:: Doctrine does NEVER touch the public API of methods in your entity - classes (getters and setters). + classes (like getters and setters) nor the constructor method. Instead, it uses reflection to set/get data from your objects. When Doctrine fetches data from DB and saves it back, any code put in your get/set methods won't be implicitly taken into account. From cfc6cfd1a37c345435c13ec38b6a48fbb0a7b99c Mon Sep 17 00:00:00 2001 From: Jarek Jakubowski Date: Sat, 9 Jun 2018 00:29:59 +0200 Subject: [PATCH 703/877] Unnecessary newline removed, small improvements in text --- docs/en/reference/working-with-objects.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/en/reference/working-with-objects.rst b/docs/en/reference/working-with-objects.rst index 1bff38a7cb1..6a33663c7c5 100644 --- a/docs/en/reference/working-with-objects.rst +++ b/docs/en/reference/working-with-objects.rst @@ -29,11 +29,10 @@ Work that have not yet been persisted are lost. Doctrine does NEVER touch the public API of methods in your entity classes (like getters and setters) nor the constructor method. - Instead, it uses reflection to set/get data from your objects. + Instead, it uses reflection to get/set data from/to your entity objects. When Doctrine fetches data from DB and saves it back, any code put in your get/set methods won't be implicitly taken into account. - Entities and the Identity Map ----------------------------- From 6d81d519b68ea8ddeb2c49463b05a25ecc565c53 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Mon, 25 Jun 2018 14:20:52 +0200 Subject: [PATCH 704/877] Use non-deprecated version of Lexer and Inflector --- lib/Doctrine/ORM/EntityRepository.php | 2 +- lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php | 2 +- lib/Doctrine/ORM/Query/Lexer.php | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index 6be570ba3be..33d7e65c0ab 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -19,7 +19,7 @@ namespace Doctrine\ORM; -use Doctrine\Common\Util\Inflector; +use Doctrine\Common\Inflector\Inflector; use Doctrine\ORM\Query\ResultSetMappingBuilder; use Doctrine\Common\Persistence\ObjectRepository; use Doctrine\Common\Collections\Selectable; diff --git a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php index 756399f6d43..ddaff9d4344 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php @@ -19,9 +19,9 @@ namespace Doctrine\ORM\Mapping\Driver; +use Doctrine\Common\Inflector\Inflector; use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; use Doctrine\Common\Persistence\Mapping\ClassMetadata; -use Doctrine\Common\Util\Inflector; use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\SchemaException; use Doctrine\DBAL\Schema\Table; diff --git a/lib/Doctrine/ORM/Query/Lexer.php b/lib/Doctrine/ORM/Query/Lexer.php index b889ecfaea6..573e433deab 100644 --- a/lib/Doctrine/ORM/Query/Lexer.php +++ b/lib/Doctrine/ORM/Query/Lexer.php @@ -19,6 +19,8 @@ namespace Doctrine\ORM\Query; +use Doctrine\Common\Lexer\AbstractLexer; + /** * Scans a DQL query for tokens. * @@ -27,7 +29,7 @@ * @author Roman Borschel * @since 2.0 */ -class Lexer extends \Doctrine\Common\Lexer +class Lexer extends AbstractLexer { // All tokens that are not valid identifiers must be < 100 const T_NONE = 1; From f2666a472feca5a4bcd0a2e9b779efbea5469a6f Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Wed, 27 Jun 2018 20:41:59 +0200 Subject: [PATCH 705/877] Add UPGRADE note for EntityRepository::count() --- UPGRADE.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index 851e2ddf97a..19528d89f49 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,12 @@ # Upgrade to 2.6 +## Added `Doctrine\ORM\EntityRepository::count()` method + +`Doctrine\ORM\EntityRepository::count()` has been added. This new method has different +signature than `Countable::count()` (required parameter) and therefore are not compatible. +If your repository implemented the `Countable` interface, you will have to use +`$repository->count([])` instead and not implement `Countable` interface anymore. + ## Minor BC BREAK: `Doctrine\ORM\Tools\Console\ConsoleRunner` is now final Since it's just an utilitarian class and should not be inherited. From ac1e1c7d231de03f5a133d9f84557e3dbe7ad29d Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Tue, 3 Jul 2018 01:55:42 +0200 Subject: [PATCH 706/877] Fix compatibility with DBAL 2.8 where OFFSET 0 is no longer generated (doctrine/dbal#3157) --- .../Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 3ce549e1619..b65611217fa 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -823,7 +823,14 @@ public function testLimitAndOffsetFromQueryClass() ->setMaxResults(10) ->setFirstResult(0); - $this->assertEquals('SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c0_.email_id AS email_id_4 FROM cms_users c0_ LIMIT 10 OFFSET 0', $q->getSql()); + // DBAL 2.8+ doesn't add OFFSET part when offset is 0 + self::assertThat( + $q->getSql(), + self::logicalOr( + self::identicalTo('SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c0_.email_id AS email_id_4 FROM cms_users c0_ LIMIT 10'), + self::identicalTo('SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c0_.email_id AS email_id_4 FROM cms_users c0_ LIMIT 10 OFFSET 0') + ) + ); } public function testSizeFunction() From ff68806bfa6afc6a3388106ebc9450b6a6f44be8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20K=C3=BChn?= Date: Sat, 17 Feb 2018 15:43:05 +0100 Subject: [PATCH 707/877] Fix for #7068: EntityManager::find() with pessimistic lock should check for transaction --- lib/Doctrine/ORM/EntityManager.php | 35 +++++++++++---- .../ORM/Functional/Ticket/GH7068Test.php | 43 +++++++++++++++++++ 2 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH7068Test.php diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 38c90bc5445..66aace05d2d 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -23,6 +23,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\LockMode; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\ORM\Proxy\ProxyFactory; use Doctrine\ORM\Query\FilterCollection; @@ -380,6 +381,10 @@ public function find($entityName, $id, $lockMode = null, $lockVersion = null) { $class = $this->metadataFactory->getMetadataFor(ltrim($entityName, '\\')); + if ($lockMode !== null) { + $this->checkLockRequirements($lockMode, $class); + } + if ( ! is_array($id)) { if ($class->isIdentifierComposite) { throw ORMInvalidArgumentException::invalidCompositeIdentifier(); @@ -441,10 +446,6 @@ public function find($entityName, $id, $lockMode = null, $lockVersion = null) switch (true) { case LockMode::OPTIMISTIC === $lockMode: - if ( ! $class->isVersioned) { - throw OptimisticLockException::notVersioned($class->name); - } - $entity = $persister->load($sortedId); $unitOfWork->lock($entity, $lockMode, $lockVersion); @@ -453,10 +454,6 @@ public function find($entityName, $id, $lockMode = null, $lockVersion = null) case LockMode::PESSIMISTIC_READ === $lockMode: case LockMode::PESSIMISTIC_WRITE === $lockMode: - if ( ! $this->getConnection()->isTransactionActive()) { - throw TransactionRequiredException::transactionRequired(); - } - return $persister->load($sortedId, null, null, [], $lockMode); default: @@ -915,4 +912,26 @@ public function hasFilters() { return null !== $this->filterCollection; } + + /** + * @param int $lockMode + * @param ClassMetadata $class + * @throws OptimisticLockException + * @throws TransactionRequiredException + */ + private function checkLockRequirements(int $lockMode, ClassMetadata $class): void + { + switch ($lockMode) { + case LockMode::OPTIMISTIC: + if (!$class->isVersioned) { + throw OptimisticLockException::notVersioned($class->name); + } + // Intentional fallthrough + case LockMode::PESSIMISTIC_READ: + case LockMode::PESSIMISTIC_WRITE: + if (!$this->getConnection()->isTransactionActive()) { + throw TransactionRequiredException::transactionRequired(); + } + } + } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7068Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7068Test.php new file mode 100644 index 00000000000..297d77e0364 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7068Test.php @@ -0,0 +1,43 @@ +setUpEntitySchema( + [ + SomeEntity::class, + ] + ); + } + + public function testLockModeIsRespected() + { + $entity = new SomeEntity(); + $this->_em->persist($entity); + $this->_em->flush(); + $this->_em->clear(); + + $this->_em->find(SomeEntity::class, 1); + + $this->expectException(TransactionRequiredException::class); + $this->_em->find(SomeEntity::class, 1, LockMode::PESSIMISTIC_WRITE); + } +} + +/** @Entity */ +final class SomeEntity { + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; +} From e26158a45e61c6bc3e0ad6a805c7cb4fac3668d4 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Wed, 4 Jul 2018 20:32:27 +0200 Subject: [PATCH 708/877] Fix #7286: StringPrimary no longer accepts aggregate functions as argument --- lib/Doctrine/ORM/Query/Parser.php | 4 + .../ORM/Functional/Ticket/GH7286Test.php | 135 ++++++++++++++++++ .../ORM/Query/LanguageRecognitionTest.php | 7 + 3 files changed, 146 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH7286Test.php diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 48b13df64aa..d52f3ce1b2e 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -2924,6 +2924,10 @@ public function StringPrimary() case Lexer::T_COALESCE: case Lexer::T_NULLIF: return $this->CaseExpression(); + default: + if ($this->isAggregateFunction($lookaheadType)) { + return $this->AggregateExpression(); + } } $this->syntaxError( diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7286Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7286Test.php new file mode 100644 index 00000000000..73d20148d9a --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7286Test.php @@ -0,0 +1,135 @@ +setUpEntitySchema( + [ + GH7286Entity::class, + ] + ); + + $this->_em->persist(new GH7286Entity('foo', 1)); + $this->_em->persist(new GH7286Entity('foo', 2)); + $this->_em->persist(new GH7286Entity('bar', 3)); + $this->_em->persist(new GH7286Entity(null, 4)); + $this->_em->flush(); + $this->_em->clear(); + } + + public function testAggregateExpressionInFunction() : void + { + $query = $this->_em->createQuery( + 'SELECT CONCAT(e.type, MIN(e.version)) pair' + . ' FROM ' . GH7286Entity::class . ' e' + . ' WHERE e.type IS NOT NULL' + . ' GROUP BY e.type' + . ' ORDER BY e.type' + ); + + self::assertSame( + [ + ['pair' => 'bar3'], + ['pair' => 'foo1'], + ], + $query->getArrayResult() + ); + } + + /** + * @group DDC-1091 + */ + public function testAggregateFunctionInCustomFunction() : void + { + $this->_em->getConfiguration()->addCustomStringFunction('CC', GH7286CustomConcat::class); + + $query = $this->_em->createQuery( + 'SELECT CC(e.type, MIN(e.version)) pair' + . ' FROM ' . GH7286Entity::class . ' e' + . ' WHERE e.type IS NOT NULL AND e.type != :type' + . ' GROUP BY e.type' + ); + $query->setParameter('type', 'bar'); + + self::assertSame( + ['pair' => 'foo1'], + $query->getSingleResult() + ); + } +} + +/** + * @Entity + */ +class GH7286Entity +{ + /** + * @Id + * @Column(type="integer") + * @GeneratedValue + * @var int + */ + public $id; + + /** + * @Column(nullable=true) + * @var string|null + */ + public $type; + + /** + * @Column(type="integer") + * @var int + */ + public $version; + + public function __construct(?string $type, int $version) + { + $this->type = $type; + $this->version = $version; + } +} + +class GH7286CustomConcat extends FunctionNode +{ + /** @var Node */ + private $first; + + /** @var Node */ + private $second; + + public function parse(Parser $parser) : void + { + $parser->match(Lexer::T_IDENTIFIER); + $parser->match(Lexer::T_OPEN_PARENTHESIS); + + $this->first = $parser->StringPrimary(); + $parser->match(Lexer::T_COMMA); + $this->second = $parser->StringPrimary(); + + $parser->match(Lexer::T_CLOSE_PARENTHESIS); + } + + public function getSql(SqlWalker $walker) : string + { + return $walker->getConnection()->getDatabasePlatform()->getConcatExpression( + $this->first->dispatch($walker), + $this->second->dispatch($walker) + ); + } +} diff --git a/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php b/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php index 064c0a799cb..fe3b298cbf9 100644 --- a/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php +++ b/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php @@ -708,6 +708,13 @@ public function testNewLiteralWithSubselectExpression() { $this->assertValidDQL("SELECT new " . __NAMESPACE__ . "\\DummyStruct(u.id, 'foo', (SELECT 1 FROM Doctrine\Tests\Models\CMS\CmsUser su), true) FROM Doctrine\Tests\Models\CMS\CmsUser u"); } + + public function testStringPrimaryAcceptsAggregateExpression() : void + { + $this->assertValidDQL( + 'SELECT CONCAT(a.topic, MAX(a.version)) last FROM Doctrine\Tests\Models\CMS\CmsArticle a GROUP BY a' + ); + } } /** @Entity */ From d2b4dd71d2a276edd65d0c170375b445f8a4a4a8 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Thu, 12 Jul 2018 22:47:13 +0200 Subject: [PATCH 709/877] Preparing v2.6.2 release --- lib/Doctrine/ORM/Version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Version.php b/lib/Doctrine/ORM/Version.php index 35941894ee2..56f0fdbf267 100644 --- a/lib/Doctrine/ORM/Version.php +++ b/lib/Doctrine/ORM/Version.php @@ -35,7 +35,7 @@ class Version /** * Current Doctrine Version */ - const VERSION = '2.6.1-DEV'; + const VERSION = '2.6.2'; /** * Compares a Doctrine version with the current one. From 43d308116d364349c78d4b2bf3e04c3956d73b46 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Thu, 12 Jul 2018 22:56:21 +0200 Subject: [PATCH 710/877] Bump version to 2.6.3-DEV --- lib/Doctrine/ORM/Version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Version.php b/lib/Doctrine/ORM/Version.php index 56f0fdbf267..bf2e6e10558 100644 --- a/lib/Doctrine/ORM/Version.php +++ b/lib/Doctrine/ORM/Version.php @@ -35,7 +35,7 @@ class Version /** * Current Doctrine Version */ - const VERSION = '2.6.2'; + const VERSION = '2.6.3-DEV'; /** * Compares a Doctrine version with the current one. From f4b775323d3deec9ab30193bea9bbb18803a43f0 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Fri, 13 Jul 2018 05:31:39 +0200 Subject: [PATCH 711/877] Fix remaining usages of deprecated ClassLoader and Inflector from doctrine/common --- lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php | 7 +++++-- lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php | 2 +- lib/Doctrine/ORM/Tools/EntityGenerator.php | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 0747d4435a0..3b3ecdaa3cb 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -27,7 +27,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use ReflectionClass; use Doctrine\Common\Persistence\Mapping\ClassMetadata; -use Doctrine\Common\ClassLoader; use Doctrine\ORM\Cache\CacheException; /** @@ -1025,7 +1024,11 @@ public function validateIdentifier() public function validateAssociations() { foreach ($this->associationMappings as $mapping) { - if ( ! ClassLoader::classExists($mapping['targetEntity']) ) { + if ( + ! class_exists($mapping['targetEntity']) + && ! interface_exists($mapping['targetEntity']) + && ! trait_exists($mapping['targetEntity']) + ) { throw MappingException::invalidTargetEntityClass($mapping['targetEntity'], $this->name, $mapping['fieldName']); } } diff --git a/lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php b/lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php index 5356520c0ee..41a103df4e6 100644 --- a/lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php +++ b/lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php @@ -20,7 +20,7 @@ namespace Doctrine\ORM\Tools; use Doctrine\ORM\Mapping\ClassMetadataInfo; -use Doctrine\Common\Util\Inflector; +use Doctrine\Common\Inflector\Inflector; use Doctrine\DBAL\Types\Type; use Symfony\Component\Yaml\Yaml; diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index cdca27e3b30..aea736511e3 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -20,7 +20,7 @@ namespace Doctrine\ORM\Tools; use Doctrine\Common\Collections\Collection; -use Doctrine\Common\Util\Inflector; +use Doctrine\Common\Inflector\Inflector; use Doctrine\DBAL\Types\Type; use Doctrine\ORM\Mapping\ClassMetadataInfo; From 07fc401d255a4cdb4a557147d1c8a3fc7a0c718d Mon Sep 17 00:00:00 2001 From: Cyril PASCAL Date: Thu, 26 Jul 2018 14:32:52 +0200 Subject: [PATCH 712/877] Make code php 7.3 lint-compatible --- lib/Doctrine/ORM/UnitOfWork.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 6767e7ef310..c79afd084ee 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -2715,7 +2715,7 @@ public function createEntity($className, array $data, &$hints = []) $class->reflFields[$field]->setValue($entity, $data[$field]); $this->originalEntityData[$oid][$field] = $data[$field]; - continue; + break; } $associatedId = []; @@ -2744,7 +2744,7 @@ public function createEntity($className, array $data, &$hints = []) $class->reflFields[$field]->setValue($entity, null); $this->originalEntityData[$oid][$field] = null; - continue; + break; } if ( ! isset($hints['fetchMode'][$class->name][$field])) { From 7b64b4a2075e2225364aa4a7f59b866f43f5e499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sat, 18 Aug 2018 14:42:25 +0200 Subject: [PATCH 713/877] Document getPartialReference() properly According to the current implementation that method also returns `null`, however the interface's documentation was incorrect. Ref: https://github.com/doctrine/doctrine2/blob/v2.6.2/lib/Doctrine/ORM/EntityManager.php#L514-L516 --- lib/Doctrine/ORM/EntityManagerInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/EntityManagerInterface.php b/lib/Doctrine/ORM/EntityManagerInterface.php index 3c1c580e935..c61e6973c28 100644 --- a/lib/Doctrine/ORM/EntityManagerInterface.php +++ b/lib/Doctrine/ORM/EntityManagerInterface.php @@ -174,7 +174,7 @@ public function getReference($entityName, $id); * @param string $entityName The name of the entity type. * @param mixed $identifier The entity identifier. * - * @return object The (partial) entity reference. + * @return object|null The (partial) entity reference. */ public function getPartialReference($entityName, $identifier); From 32efbd3edd54a6f0fc331b6a0bf394fcacb88444 Mon Sep 17 00:00:00 2001 From: Pierre-Louis FORT Date: Mon, 30 Jul 2018 22:49:30 +0200 Subject: [PATCH 714/877] Handle removed parameters by tree walker in Paginator --- .../ORM/Tools/Pagination/Paginator.php | 15 ++- .../ORM/Tools/Pagination/PaginatorTest.php | 119 ++++++++++++++++++ 2 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Tools/Pagination/PaginatorTest.php diff --git a/lib/Doctrine/ORM/Tools/Pagination/Paginator.php b/lib/Doctrine/ORM/Tools/Pagination/Paginator.php index 250df071f92..0987dfc3492 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/Paginator.php +++ b/lib/Doctrine/ORM/Tools/Pagination/Paginator.php @@ -145,6 +145,7 @@ public function getIterator() $subQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, LimitSubqueryOutputWalker::class); } else { $this->appendTreeWalker($subQuery, LimitSubqueryWalker::class); + $this->unbindUnusedQueryParams($subQuery); } $subQuery->setFirstResult($offset)->setMaxResults($length); @@ -256,14 +257,20 @@ private function getCountQuery() $countQuery->setResultSetMapping($rsm); } else { $this->appendTreeWalker($countQuery, CountWalker::class); + $this->unbindUnusedQueryParams($countQuery); } $countQuery->setFirstResult(null)->setMaxResults(null); - $parser = new Parser($countQuery); + return $countQuery; + } + + private function unbindUnusedQueryParams(Query $query): void + { + $parser = new Parser($query); $parameterMappings = $parser->parse()->getParameterMappings(); /* @var $parameters \Doctrine\Common\Collections\Collection|\Doctrine\ORM\Query\Parameter[] */ - $parameters = $countQuery->getParameters(); + $parameters = $query->getParameters(); foreach ($parameters as $key => $parameter) { $parameterName = $parameter->getName(); @@ -273,8 +280,6 @@ private function getCountQuery() } } - $countQuery->setParameters($parameters); - - return $countQuery; + $query->setParameters($parameters); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/PaginatorTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/PaginatorTest.php new file mode 100644 index 00000000000..4b4fc5202bd --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/PaginatorTest.php @@ -0,0 +1,119 @@ +connection = $this->getMockBuilder(ConnectionMock::class) + ->setConstructorArgs([[], new DriverMock()]) + ->setMethods(['executeQuery']) + ->getMock() + ; + + $this->em = $this->getMockBuilder(EntityManagerDecorator::class) + ->setConstructorArgs([$this->_getTestEntityManager($this->connection)]) + ->setMethods(['newHydrator']) + ->getMock() + ; + + $this->hydrator = $this->createMock(AbstractHydrator::class); + $this->em->method('newHydrator')->willReturn($this->hydrator); + } + + public function testExtraParametersAreStrippedWhenWalkerRemovingOriginalSelectElementsIsUsed() : void + { + $paramInWhere = 1; + $paramInSubSelect = 2; + $returnedIds = [10]; + + $this->hydrator->method('hydrateAll')->willReturn([$returnedIds]); + + $query = new Query($this->em); + $query->setDQL( + 'SELECT u, + ( + SELECT MAX(a.version) + FROM Doctrine\\Tests\\Models\\CMS\\CmsArticle a + WHERE a.user = u AND 1 = :paramInSubSelect + ) AS HIDDEN max_version + FROM Doctrine\\Tests\\Models\\CMS\\CmsUser u + WHERE u.id = :paramInWhere' + ); + $query->setParameters(['paramInWhere' => $paramInWhere, 'paramInSubSelect' => $paramInSubSelect]); + $paginator = (new Paginator($query, true))->setUseOutputWalkers(false); + + $this->connection->expects($this->exactly(3))->method('executeQuery'); + + $this->connection->expects($this->at(0)) + ->method('executeQuery') + ->with($this->anything(), [$paramInWhere]) + ; + + $this->connection->expects($this->at(1)) + ->method('executeQuery') + ->with($this->anything(), [$paramInWhere]) + ; + + $this->connection->expects($this->at(2)) + ->method('executeQuery') + ->with($this->anything(), [$paramInSubSelect, $paramInWhere, $returnedIds]) + ; + + $paginator->count(); + $paginator->getIterator(); + } + + public function testPaginatorNotCaringAboutExtraParametersWithoutOutputWalkers() : void + { + $this->connection->expects($this->exactly(3))->method('executeQuery'); + + $this->createPaginatorWithExtraParametersWithoutOutputWalkers([])->count(); + $this->createPaginatorWithExtraParametersWithoutOutputWalkers([[10]])->count(); + $this->createPaginatorWithExtraParametersWithoutOutputWalkers([])->getIterator(); + } + + public function testgetIteratorDoesCareAboutExtraParametersWithoutOutputWalkersWhenResultIsNotEmpty() : void + { + $this->connection->expects($this->exactly(1))->method('executeQuery'); + $this->expectException(Query\QueryException::class); + $this->expectExceptionMessage('Too many parameters: the query defines 1 parameters and you bound 2'); + + $this->createPaginatorWithExtraParametersWithoutOutputWalkers([[10]])->getIterator(); + } + + /** + * @param int[][] $willReturnRows + */ + private function createPaginatorWithExtraParametersWithoutOutputWalkers(array $willReturnRows) : Paginator + { + $this->hydrator->method('hydrateAll')->willReturn($willReturnRows); + $this->connection->method('executeQuery')->with($this->anything(), []); + + $query = new Query($this->em); + $query->setDQL('SELECT u FROM Doctrine\\Tests\\Models\\CMS\\CmsUser u'); + $query->setParameters(['paramInWhere' => 1]); + + return (new Paginator($query, true))->setUseOutputWalkers(false); + } +} From 2779b5ee914a13ae3523f1d2f2d1d4293a52fa91 Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Tue, 28 Aug 2018 14:56:01 +0200 Subject: [PATCH 715/877] Typo fix --- docs/en/cookbook/aggregate-fields.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/cookbook/aggregate-fields.rst b/docs/en/cookbook/aggregate-fields.rst index fdf830323e1..7e5a89dce2b 100644 --- a/docs/en/cookbook/aggregate-fields.rst +++ b/docs/en/cookbook/aggregate-fields.rst @@ -322,7 +322,7 @@ The aggregate field ``Account::$balance`` is now -200, however the SUM over all entries amounts yields -400. A violation of our max credit rule. -You can use both optimistic or pessimistic locking to save-guard +You can use both optimistic or pessimistic locking to safe-guard your aggregate fields against this kind of race-conditions. Reading Eric Evans DDD carefully he mentions that the "Aggregate Root" (Account in our example) needs a locking mechanism. From d36aec8fb7f0ee9031364fdf753cbb7dc9d0f7a9 Mon Sep 17 00:00:00 2001 From: Claudio Zizza Date: Sun, 26 Aug 2018 00:31:55 +0200 Subject: [PATCH 716/877] Add deprecation message for YAML into docs --- docs/en/reference/yaml-mapping.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/en/reference/yaml-mapping.rst b/docs/en/reference/yaml-mapping.rst index ea54e277ae9..8199406ebe7 100644 --- a/docs/en/reference/yaml-mapping.rst +++ b/docs/en/reference/yaml-mapping.rst @@ -1,6 +1,10 @@ YAML Mapping ============ +.. note:: + The YAML driver is deprecated and will be removed in version 3.0. + It is strongly recommended to switch to one of the other mappings. + The YAML mapping driver enables you to provide the ORM metadata in form of YAML documents. From ff1df41485427645aadf200711b1263140a616fb Mon Sep 17 00:00:00 2001 From: Claudio Zizza Date: Fri, 7 Sep 2018 21:06:08 +0200 Subject: [PATCH 717/877] Add deprecation note to getting-started chapter --- docs/en/tutorials/getting-started.rst | 29 ++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/docs/en/tutorials/getting-started.rst b/docs/en/tutorials/getting-started.rst index 605b1a01785..e8dde41af1e 100644 --- a/docs/en/tutorials/getting-started.rst +++ b/docs/en/tutorials/getting-started.rst @@ -103,18 +103,21 @@ Install Doctrine using the Composer Dependency Management tool, by calling: $ composer install This will install the packages Doctrine Common, Doctrine DBAL, Doctrine ORM, -Symfony YAML and Symfony Console into the `vendor` directory. The Symfony -dependencies are not required by Doctrine but will be used in this tutorial. +into the `vendor` directory. Add the following directories: :: doctrine2-tutorial |-- config - | |-- xml + | `-- xml | `-- yaml `-- src +.. note:: + The YAML driver is deprecated and will be removed in version 3.0. + It is strongly recommended to switch to one of the other mappings. + Obtaining the EntityManager --------------------------- @@ -150,6 +153,10 @@ step: // obtaining the entity manager $entityManager = EntityManager::create($conn, $config); +.. note:: + The YAML driver is deprecated and will be removed in version 3.0. + It is strongly recommended to switch to one of the other mappings. + The require_once statement sets up the class autoloading for Doctrine and its dependencies using Composer's autoloader. @@ -308,6 +315,10 @@ but you only need to choose one. +.. note:: + The YAML driver is deprecated and will be removed in version 3.0. + It is strongly recommended to switch to one of the other mappings. + .. code-block:: yaml # config/yaml/Product.dcm.yml @@ -851,6 +862,10 @@ the ``Product`` before: +.. note:: + The YAML driver is deprecated and will be removed in version 3.0. + It is strongly recommended to switch to one of the other mappings. + .. code-block:: yaml # config/yaml/Bug.dcm.yml @@ -963,6 +978,10 @@ Finally, we'll add metadata mappings for the ``User`` entity. +.. note:: + The YAML driver is deprecated and will be removed in version 3.0. + It is strongly recommended to switch to one of the other mappings. + .. code-block:: yaml # config/yaml/User.dcm.yml @@ -1493,6 +1512,10 @@ we have to adjust the metadata slightly. +.. note:: + The YAML driver is deprecated and will be removed in version 3.0. + It is strongly recommended to switch to one of the other mappings. + .. code-block:: yaml Bug: From 145f1f51983ef32fda636155685b60abf1db11bd Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Fri, 15 Jun 2018 13:09:59 +0200 Subject: [PATCH 718/877] Add a test reproducing GH7259 --- .../ORM/Functional/Ticket/GH7259Test.php | 165 ++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH7259Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7259Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7259Test.php new file mode 100644 index 00000000000..948259815c4 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7259Test.php @@ -0,0 +1,165 @@ +setUpEntitySchema([GH7259Space::class, GH7259File::class, GH7259FileVersion::class, GH7259Feed::class]); + } + + /** + * @group 7259 + */ + public function testPersistFileBeforeVersion() : void + { + $space = new GH7259Space(); + + $this->_em->persist($space); + $this->_em->flush(); + + $feed = new GH7259Feed(); + $feed->space = $space; + + $file = new GH7259File(); + $file->space = $space; + $fileVersion = new GH7259FileVersion(); + $fileVersion->file = $file; + + $this->_em->persist($file); + $this->_em->persist($fileVersion); + $this->_em->persist($feed); + + $this->_em->flush(); + + self::assertNotNull($fileVersion->id); + } + + /** + * @group 7259 + */ + public function testPersistFileAfterVersion() : void + { + $space = new GH7259Space(); + + $this->_em->persist($space); + $this->_em->flush(); + $this->_em->clear(); + + $space = $this->_em->find(GH7259Space::class, $space->id); + + $feed = new GH7259Feed(); + $feed->space = $space; + + $file = new GH7259File(); + $file->space = $space; + $fileVersion = new GH7259FileVersion(); + $fileVersion->file = $file; + + $this->_em->persist($fileVersion); + $this->_em->persist($file); + $this->_em->persist($feed); + + $this->_em->flush(); + + self::assertNotNull($fileVersion->id); + } +} + +/** + * @Entity() + */ +class GH7259File +{ + /** + * @Id + * @GeneratedValue + * @Column(type="integer") + * + * @var int + */ + public $id; + + /** + * @ManyToOne(targetEntity=GH7259Space::class) + * @JoinColumn(nullable=false) + * + * @var GH7259Space|null + */ + public $space; +} + +/** + * @Entity() + */ +class GH7259FileVersion +{ + /** + * @Id + * @GeneratedValue + * @Column(type="integer") + * + * @var int + */ + public $id; + + /** + * @ManyToOne(targetEntity=GH7259File::class) + * @JoinColumn(nullable=false) + * + * @var GH7259File|null + */ + public $file; +} + +/** + * @Entity() + */ +class GH7259Space +{ + /** + * @Id + * @GeneratedValue + * @Column(type="integer") + * + * @var int + */ + public $id; + + /** + * @ManyToOne(targetEntity=GH7259File::class) + * @JoinColumn(nullable=true) + * + * @var GH7259File|null + */ + public $ruleFile; +} + +/** + * @Entity() + */ +class GH7259Feed +{ + /** + * @Id + * @GeneratedValue + * @Column(type="integer") + * + * @var int + */ + public $id; + + /** + * @ManyToOne(targetEntity=GH7259Space::class) + * @JoinColumn(nullable=false) + * + * @var GH7259Space|null + */ + public $space; +} From 11a7f359d193259cb910bf05f6c8b902604ac243 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 20 Sep 2018 11:52:35 +0200 Subject: [PATCH 719/877] Add a unit test reproducing the commit order regression --- .../Tests/ORM/CommitOrderCalculatorTest.php | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php b/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php index 8c9ec26c44d..c967beb8b62 100644 --- a/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php +++ b/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php @@ -67,6 +67,39 @@ public function testCommitOrdering2() $this->assertSame($correctOrder, $sorted); } + + public function testCommitOrdering3() + { + // this test corresponds to the GH7259Test::testPersistFileBeforeVersion functional test + $class1 = new ClassMetadata(NodeClass1::class); + $class2 = new ClassMetadata(NodeClass2::class); + $class3 = new ClassMetadata(NodeClass3::class); + $class4 = new ClassMetadata(NodeClass4::class); + + $this->_calc->addNode($class1->name, $class1); + $this->_calc->addNode($class2->name, $class2); + $this->_calc->addNode($class3->name, $class3); + $this->_calc->addNode($class4->name, $class4); + + $this->_calc->addDependency($class4->name, $class1->name, 1); + $this->_calc->addDependency($class1->name, $class2->name, 1); + $this->_calc->addDependency($class4->name, $class3->name, 1); + $this->_calc->addDependency($class1->name, $class4->name, 0); + + $sorted = $this->_calc->sort(); + + // There is only multiple valid ordering for this constellation, but + // the class4, class1, class2 ordering is important to break the cycle + // on the nullable link. + $correctOrders = [ + [$class4, $class1, $class2, $class3], + [$class4, $class1, $class3, $class2], + [$class4, $class3, $class1, $class2], + ]; + + // We want to perform a strict comparison of the array + $this->assertContains($sorted, $correctOrders, '', false, true, true); + } } class NodeClass1 {} From 568c2d308c850d36fd330dbb14cd52e799f9125b Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 20 Sep 2018 12:13:25 +0200 Subject: [PATCH 720/877] Fix the computation of commit order for circular dependencies When finding a circular dependencies, we must ensure that all dependencies of a node have been visited before adding it to the sorted list. --- lib/Doctrine/ORM/Internal/CommitOrderCalculator.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php b/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php index 34703c6d280..30b9caa8206 100644 --- a/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php +++ b/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php @@ -164,6 +164,17 @@ private function visit($vertex) case self::IN_PROGRESS: if (isset($adjacentVertex->dependencyList[$vertex->hash]) && $adjacentVertex->dependencyList[$vertex->hash]->weight < $edge->weight) { + + // If we have some non-visited dependencies in the in-progress dependency, we + // need to visit them before adding the node. + foreach ($adjacentVertex->dependencyList as $adjacentEdge) { + $adjacentEdgeVertex = $this->nodeList[$adjacentEdge->to]; + + if ($adjacentEdgeVertex->state === self::NOT_VISITED) { + $this->visit($adjacentEdgeVertex); + } + } + $adjacentVertex->state = self::VISITED; $this->sortedNodeList[] = $adjacentVertex->value; From 47c72e583ec5293c94f5ee7db4ea08c4dc6378c0 Mon Sep 17 00:00:00 2001 From: Guilliam Xavier Date: Fri, 10 Aug 2018 11:33:32 +0200 Subject: [PATCH 721/877] correct load-only DOMDocument constructor in test --- tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php index d0a38b49036..45beca8d4cb 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php @@ -152,8 +152,8 @@ public function testInvalidMappingFileException() */ public function testValidateXmlSchema($xmlMappingFile) { - $xsdSchemaFile = __DIR__ . '/../../../../../doctrine-mapping.xsd'; - $dom = new \DOMDocument('UTF-8'); + $xsdSchemaFile = __DIR__ . '/../../../../../doctrine-mapping.xsd'; + $dom = new \DOMDocument(); $dom->load($xmlMappingFile); From cb9ec8234b9412873d46a67d54111afe1d9d4395 Mon Sep 17 00:00:00 2001 From: philippe-unitiz Date: Tue, 21 Aug 2018 15:20:11 +0200 Subject: [PATCH 722/877] Fix multiline parameter phpDoc in Query\Expr See https://github.com/phan/phan/issues/1897 (parser won't accept `@param` spanning over several lines) --- lib/Doctrine/ORM/Query/Expr.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Expr.php b/lib/Doctrine/ORM/Query/Expr.php index 1373c74a002..2b74883dbc7 100644 --- a/lib/Doctrine/ORM/Query/Expr.php +++ b/lib/Doctrine/ORM/Query/Expr.php @@ -41,10 +41,8 @@ class Expr * // (u.type = ?1) AND (u.role = ?2) * $expr->andX($expr->eq('u.type', ':1'), $expr->eq('u.role', ':2')); * - * @param \Doctrine\ORM\Query\Expr\Comparison | - * \Doctrine\ORM\Query\Expr\Func | - * \Doctrine\ORM\Query\Expr\Orx - * $x Optional clause. Defaults to null, but requires at least one defined when converting to string. + * @param Expr\Comparison|Expr\Func|Expr\Orx $x Optional clause. Defaults to null, but requires at least one + * defined when converting to string. * * @return Expr\Andx */ From d3acbbf79be0c166ff543275ca5d130560aa6936 Mon Sep 17 00:00:00 2001 From: philippe-unitiz Date: Tue, 21 Aug 2018 15:21:56 +0200 Subject: [PATCH 723/877] Fix constructor argument type in Query\Base --- lib/Doctrine/ORM/Query/Expr/Base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Query/Expr/Base.php b/lib/Doctrine/ORM/Query/Expr/Base.php index d1303138360..d4b8d3871f1 100644 --- a/lib/Doctrine/ORM/Query/Expr/Base.php +++ b/lib/Doctrine/ORM/Query/Expr/Base.php @@ -56,7 +56,7 @@ abstract class Base protected $parts = []; /** - * @param array $args + * @param mixed $args */ public function __construct($args = []) { From 7400d514447e7c0c6cdebd6f1af16a3d0ec893ab Mon Sep 17 00:00:00 2001 From: Bob den Otter Date: Mon, 17 Sep 2018 17:22:01 +0200 Subject: [PATCH 724/877] Fix docblock in `inheritance-mapping.rst` --- docs/en/reference/inheritance-mapping.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/reference/inheritance-mapping.rst b/docs/en/reference/inheritance-mapping.rst index d489b30b6db..d07eae1488f 100644 --- a/docs/en/reference/inheritance-mapping.rst +++ b/docs/en/reference/inheritance-mapping.rst @@ -493,7 +493,7 @@ Could be used by an entity that extends a mapped superclass to override a field * column=@Column( * name = "guest_id", * type = "integer", - length = 140 + * length = 140 * ) * ), * @AttributeOverride(name="name", @@ -501,7 +501,7 @@ Could be used by an entity that extends a mapped superclass to override a field * name = "guest_name", * nullable = false, * unique = true, - length = 240 + * length = 240 * ) * ) * }) From 3dbe205498df07a5dab06f3b68b1047a13745c39 Mon Sep 17 00:00:00 2001 From: sserbin Date: Tue, 28 Aug 2018 14:41:52 +0300 Subject: [PATCH 725/877] Query\Expr::andX(): added `string` as allowed parameter type --- lib/Doctrine/ORM/Query/Expr.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Expr.php b/lib/Doctrine/ORM/Query/Expr.php index 2b74883dbc7..25231822d11 100644 --- a/lib/Doctrine/ORM/Query/Expr.php +++ b/lib/Doctrine/ORM/Query/Expr.php @@ -41,8 +41,8 @@ class Expr * // (u.type = ?1) AND (u.role = ?2) * $expr->andX($expr->eq('u.type', ':1'), $expr->eq('u.role', ':2')); * - * @param Expr\Comparison|Expr\Func|Expr\Orx $x Optional clause. Defaults to null, but requires at least one - * defined when converting to string. + * @param Expr\Comparison|Expr\Func|Expr\Orx|string $x Optional clause. Defaults to null, but requires at least one + * defined when converting to string. * * @return Expr\Andx */ From 3acfa5021406be425a4558904435976f187cb9a9 Mon Sep 17 00:00:00 2001 From: Tim Lieberman Date: Wed, 22 Aug 2018 11:49:47 -0700 Subject: [PATCH 726/877] Fix for BC break #7366 when calling EM::find() with LockMode::OPTIMISTIC outside of a TX --- lib/Doctrine/ORM/EntityManager.php | 2 +- .../ORM/Functional/Ticket/GH7366Test.php | 75 +++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH7366Test.php diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 66aace05d2d..c3535148714 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -926,7 +926,7 @@ private function checkLockRequirements(int $lockMode, ClassMetadata $class): voi if (!$class->isVersioned) { throw OptimisticLockException::notVersioned($class->name); } - // Intentional fallthrough + break; case LockMode::PESSIMISTIC_READ: case LockMode::PESSIMISTIC_WRITE: if (!$this->getConnection()->isTransactionActive()) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7366Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7366Test.php new file mode 100644 index 00000000000..80f5cae723b --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7366Test.php @@ -0,0 +1,75 @@ +setUpEntitySchema( + [ + GH7366Entity::class, + ] + ); + + $this->_em->persist(new GH7366Entity('baz')); + $this->_em->flush(); + $this->_em->clear(); + } + + public function testOptimisticLockNoExceptionOnFind() : void + { + try { + $entity = $this->_em->find(GH7366Entity::class, 1, LockMode::OPTIMISTIC); + } catch (TransactionRequiredException $e) { + self::fail('EntityManager::find() threw TransactionRequiredException with LockMode::OPTIMISTIC'); + } + self::assertEquals('baz', $entity->getName()); + } +} + +/** + * @Entity + */ +class GH7366Entity +{ + /** + * @Id + * @Column(type="integer") + * @GeneratedValue + * @var int + */ + public $id; + + /** + * @Column(type="integer") + * @Version + */ + protected $lockVersion = 1; + + /** + * @Column(length=32) + * @var string + */ + protected $name; + + + public function __construct(string $name) + { + $this->name = $name; + } + + public function getName(): string + { + return $this->name; + } +} From 7eacfec2c3f9921ba2b8086aad9e9eab855bf0ca Mon Sep 17 00:00:00 2001 From: Ivan Date: Tue, 11 Sep 2018 11:36:37 -0600 Subject: [PATCH 727/877] Fix typo in getting-started.rst --- docs/en/tutorials/getting-started.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/tutorials/getting-started.rst b/docs/en/tutorials/getting-started.rst index 605b1a01785..8bda1a888ff 100644 --- a/docs/en/tutorials/getting-started.rst +++ b/docs/en/tutorials/getting-started.rst @@ -196,7 +196,7 @@ Product entity along with the corresponding metadata, and run this command again Note that as you modify your entities' metadata during the development process, you'll need to update your database schema to stay in sync with the metadata. -You can rasily recreate the database using the following commands: +You can easily recreate the database using the following commands: :: From 982782f8c93b0c72a998f8769ab04c55d3d4902d Mon Sep 17 00:00:00 2001 From: Farhad Safarov Date: Tue, 9 Oct 2018 11:52:22 +0300 Subject: [PATCH 728/877] JIRA to Github issues --- .../reference/limitations-and-known-issues.rst | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/docs/en/reference/limitations-and-known-issues.rst b/docs/en/reference/limitations-and-known-issues.rst index 8f273568fd1..15cde689b8d 100644 --- a/docs/en/reference/limitations-and-known-issues.rst +++ b/docs/en/reference/limitations-and-known-issues.rst @@ -63,7 +63,7 @@ Where the ``attribute_name`` column contains the key and ``$attributes``. The feature request for persistence of primitive value arrays -`is described in the DDC-298 ticket `_. +`is described in the DDC-298 ticket `_. Cascade Merge with Bi-directional Associations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -71,8 +71,8 @@ Cascade Merge with Bi-directional Associations There are two bugs now that concern the use of cascade merge in combination with bi-directional associations. Make sure to study the behavior of cascade merge if you are using it: -- `DDC-875 `_ Merge can sometimes add the same entity twice into a collection -- `DDC-763 `_ Cascade merge on associated entities can insert too many rows through "Persistence by Reachability" +- `DDC-875 `_ Merge can sometimes add the same entity twice into a collection +- `DDC-763 `_ Cascade merge on associated entities can insert too many rows through "Persistence by Reachability" Custom Persisters ~~~~~~~~~~~~~~~~~ @@ -83,8 +83,8 @@ Currently there is no way to overwrite the persister implementation for a given entity, however there are several use-cases that can benefit from custom persister implementations: -- `Add Upsert Support `_ -- `Evaluate possible ways in which stored-procedures can be used `_ +- `Add Upsert Support `_ +- `Evaluate possible ways in which stored-procedures can be used `_ Persist Keys of Collections ~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -94,7 +94,7 @@ PHP Arrays are ordered hash-maps and so should be the evaluate a feature that optionally persists and hydrates the keys of a Collection instance. -`Ticket DDC-213 `_ +`Ticket DDC-213 `_ Mapping many tables to one entity ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -144,9 +144,8 @@ backwards compatibility issues or where no simple fix exists (yet). We don't plan to add every bug in the tracker there, just those issues that can potentially cause nightmares or pain of any sort. -See the Open Bugs on Jira for more details on `bugs, improvement and feature -requests -`_. +See bugs, improvement and feature requests on `Github issues +`_. Identifier Quoting and Legacy Databases ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From 892ef9edb7bbb317aac37bdd0ad91be2647eadc1 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Tue, 9 Oct 2018 21:33:42 +0200 Subject: [PATCH 729/877] Update association-mapping.rst Added info about owning and inverse side. --- docs/en/reference/association-mapping.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/en/reference/association-mapping.rst b/docs/en/reference/association-mapping.rst index bdb12b706f0..b7d6bb8d1df 100644 --- a/docs/en/reference/association-mapping.rst +++ b/docs/en/reference/association-mapping.rst @@ -313,8 +313,8 @@ One-To-Many, Bidirectional -------------------------- A one-to-many association has to be bidirectional, unless you are using a -join table. This is because the many side in a one-to-many association holds -the foreign key, making it the owning side. Doctrine needs the many side +join table. This is because the "many" side in a one-to-many association holds +the foreign key, making it the owning side. Doctrine needs the "many" side defined in order to understand the association. This bidirectional mapping requires the ``mappedBy`` attribute on the @@ -335,7 +335,7 @@ bidirectional many-to-one. { // ... /** - * One Product has Many Features. + * One product has many features. This is the inverse side. * @OneToMany(targetEntity="Feature", mappedBy="product") */ private $features; @@ -351,7 +351,7 @@ bidirectional many-to-one. { // ... /** - * Many Features have One Product. + * Many features have one product. This is the owning side. * @ManyToOne(targetEntity="Product", inversedBy="features") * @JoinColumn(name="product_id", referencedColumnName="id") */ From 812989490ce63518993494524dec7eaf163cb493 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Sat, 13 Oct 2018 20:33:26 +0200 Subject: [PATCH 730/877] CI: Test against PHP 7.3 --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 44c27230c21..7730c533b5e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ language: php php: - 7.1 - 7.2 + - 7.3 - nightly env: @@ -57,6 +58,7 @@ jobs: - stage: Test if: type = cron + php: 7.3 env: DB=sqlite DEV_DEPENDENCIES install: - composer config minimum-stability dev From d5364231c2794d837d24fec4f3c6f2efc353c84c Mon Sep 17 00:00:00 2001 From: naitsirch Date: Thu, 18 Oct 2018 22:36:29 +0200 Subject: [PATCH 731/877] Removed FAQ paragraph stating public variables are disallowed In #7427 @flaushi mentioned the outdated paragraph. This commit removes this one. --- docs/en/reference/faq.rst | 6 ------ 1 file changed, 6 deletions(-) diff --git a/docs/en/reference/faq.rst b/docs/en/reference/faq.rst index 45fde18d7e0..78b5b01c946 100644 --- a/docs/en/reference/faq.rst +++ b/docs/en/reference/faq.rst @@ -21,12 +21,6 @@ created database tables and columns. Entity Classes -------------- -I access a variable and its null, what is wrong? -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -If this variable is a public variable then you are violating one of the criteria for entities. -All properties have to be protected or private for the proxy object pattern to work. - How can I add default values to a column? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From 58370256c01e32c955fcb21219691d3475866710 Mon Sep 17 00:00:00 2001 From: Oguz Dumanoglu Date: Fri, 19 Oct 2018 16:32:27 +0200 Subject: [PATCH 732/877] Fix a typo There was a typo in Working with Associations page. --- docs/en/reference/working-with-associations.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/working-with-associations.rst b/docs/en/reference/working-with-associations.rst index de236cf4077..0b805806693 100644 --- a/docs/en/reference/working-with-associations.rst +++ b/docs/en/reference/working-with-associations.rst @@ -15,7 +15,7 @@ with associations in Doctrine: removed, not the entity itself. A collection of entities always only represents the association to the containing entities, not the entity itself. -- When a bidirectional assocation is updated, Doctrine only checks +- When a bidirectional association is updated, Doctrine only checks on one of both sides for these changes. This is called the :doc:`owning side ` of the association. - A property with a reference to many entities has to be instances of the From 17bc627bf2c7882905e9e1000191aa05c1e4d354 Mon Sep 17 00:00:00 2001 From: naitsirch Date: Mon, 29 Oct 2018 21:26:02 +0100 Subject: [PATCH 733/877] Added hint about exception in Query#getOneOrNullResult() When calling `Query#getOneOrNullResult()` and there are more than one objects in the result an `NonUniqueResultException` is thrown. This information was missing in the documentation about the query result formats. This commit addresses #6793. --- docs/en/reference/dql-doctrine-query-language.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/en/reference/dql-doctrine-query-language.rst b/docs/en/reference/dql-doctrine-query-language.rst index 36c06bf3bde..55c6131343e 100644 --- a/docs/en/reference/dql-doctrine-query-language.rst +++ b/docs/en/reference/dql-doctrine-query-language.rst @@ -996,8 +996,9 @@ the Query class. Here they are: result contains more than one object, an ``NonUniqueResultException`` is thrown. If the result contains no objects, an ``NoResultException`` is thrown. The pure/mixed distinction does not apply. -- ``Query#getOneOrNullResult()``: Retrieve a single object. If no - object is found null will be returned. +- ``Query#getOneOrNullResult()``: Retrieve a single object. If the + result contains more than one object, an ``NonUniqueResultException`` + is thrown. If no object is found null will be returned. - ``Query#getArrayResult()``: Retrieves an array graph (a nested array) that is largely interchangeable with the object graph generated by ``Query#getResult()`` for read-only purposes. From 0e4a0108d2bbb68f0f33816011bc251592a2d5cb Mon Sep 17 00:00:00 2001 From: Alexandru Ungureanu Date: Thu, 8 Nov 2018 13:59:21 +0200 Subject: [PATCH 734/877] Fixes small typo --- docs/en/cookbook/working-with-datetime.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/cookbook/working-with-datetime.rst b/docs/en/cookbook/working-with-datetime.rst index 98a1fb234c2..363c74fdd49 100644 --- a/docs/en/cookbook/working-with-datetime.rst +++ b/docs/en/cookbook/working-with-datetime.rst @@ -1,7 +1,7 @@ Working with DateTime Instances =============================== -There are many nitty gritty details when working with PHPs DateTime instances. You have know their inner +There are many nitty gritty details when working with PHPs DateTime instances. You have to know their inner workings pretty well not to make mistakes with date handling. This cookbook entry holds several interesting pieces of information on how to work with PHP DateTime instances in Doctrine 2. From 88d58ae0a3cbf21e675ad8bcad8f4a9717c2320f Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Tue, 25 Sep 2018 17:16:47 +0200 Subject: [PATCH 735/877] Some formatting improvements --- docs/en/tutorials/getting-started.rst | 41 +++++++++++++-------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/docs/en/tutorials/getting-started.rst b/docs/en/tutorials/getting-started.rst index fafabf786d3..316fb5f76e1 100644 --- a/docs/en/tutorials/getting-started.rst +++ b/docs/en/tutorials/getting-started.rst @@ -25,7 +25,7 @@ The code of this tutorial is `available on Github Date: Mon, 29 Oct 2018 22:32:34 +0100 Subject: [PATCH 736/877] Fixed URLs of doctrine-mapping.xsd in docs Until now the references to the `doctrine-mapping.xsd` consisted of different URLs. A grep of docs showed: * /Users/robo/dev/php/Doctrine/doctrine-mapping.xsd * http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd * http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd * https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd Now it is used http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd everywhere. --- docs/en/reference/events.rst | 2 +- docs/en/reference/xml-mapping.rst | 8 ++++---- docs/en/tutorials/composite-primary-keys.rst | 4 ++-- docs/en/tutorials/extra-lazy-associations.rst | 2 +- docs/en/tutorials/getting-started.rst | 8 ++++---- docs/en/tutorials/working-with-indexed-associations.rst | 4 ++-- ...ne.Tests.Models.OrnementalOrphanRemoval.Person.dcm.xml | 2 +- ...sts.Models.OrnementalOrphanRemoval.PhoneNumber.dcm.xml | 2 +- tests/Doctrine/Tests/ORM/Mapping/xml/DDC2429Book.orm.xml | 2 +- .../xml/Doctrine.Tests.Models.CMS.CmsAddress.dcm.xml | 2 +- .../Mapping/xml/Doctrine.Tests.Models.CMS.CmsUser.dcm.xml | 2 +- .../Doctrine.Tests.Models.Company.CompanyContract.dcm.xml | 2 +- ...ctrine.Tests.Models.Company.CompanyFixContract.dcm.xml | 2 +- ...trine.Tests.Models.Company.CompanyFlexContract.dcm.xml | 2 +- ....Tests.Models.Company.CompanyFlexUltraContract.dcm.xml | 2 +- .../Doctrine.Tests.Models.Company.CompanyPerson.dcm.xml | 2 +- ...Doctrine.Tests.Models.DDC117.DDC117Translation.dcm.xml | 2 +- ...dels.DDC1476.DDC1476EntityWithDefaultFieldType.dcm.xml | 2 +- ...ne.Tests.Models.DDC2825.ExplicitSchemaAndTable.dcm.xml | 2 +- ...Tests.Models.DDC2825.SchemaAndTableInTableName.dcm.xml | 2 +- .../Doctrine.Tests.Models.DDC3293.DDC3293Address.dcm.xml | 2 +- .../xml/Doctrine.Tests.Models.DDC3293.DDC3293User.dcm.xml | 2 +- ...trine.Tests.Models.DDC3293.DDC3293UserPrefixed.dcm.xml | 2 +- .../Doctrine.Tests.Models.DDC3579.DDC3579Admin.dcm.xml | 2 +- .../xml/Doctrine.Tests.Models.DDC3579.DDC3579User.dcm.xml | 2 +- ...trine.Tests.Models.DDC5934.DDC5934BaseContract.dcm.xml | 2 +- .../Doctrine.Tests.Models.DDC5934.DDC5934Contract.dcm.xml | 2 +- ...ctrine.Tests.Models.DDC869.DDC869ChequePayment.dcm.xml | 2 +- ...ne.Tests.Models.DDC869.DDC869CreditCardPayment.dcm.xml | 2 +- .../Doctrine.Tests.Models.DDC869.DDC869Payment.dcm.xml | 2 +- .../xml/Doctrine.Tests.Models.DDC889.DDC889Class.dcm.xml | 2 +- .../xml/Doctrine.Tests.Models.DDC889.DDC889Entity.dcm.xml | 2 +- .../Doctrine.Tests.Models.DDC889.DDC889SuperClass.dcm.xml | 2 +- .../xml/Doctrine.Tests.Models.DDC964.DDC964Admin.dcm.xml | 2 +- .../xml/Doctrine.Tests.Models.DDC964.DDC964Guest.dcm.xml | 2 +- .../xml/Doctrine.Tests.Models.DDC964.DDC964User.dcm.xml | 2 +- .../Doctrine.Tests.Models.GH7141.GH7141Article.dcm.xml | 2 +- ...ctrine.Tests.Models.Generic.SerializationModel.dcm.xml | 2 +- .../xml/Doctrine.Tests.Models.ValueObjects.Name.dcm.xml | 2 +- .../xml/Doctrine.Tests.Models.ValueObjects.Person.dcm.xml | 2 +- .../Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml | 2 +- .../Mapping/xml/Doctrine.Tests.ORM.Mapping.CTI.dcm.xml | 2 +- .../xml/Doctrine.Tests.ORM.Mapping.Comment.dcm.xml | 2 +- .../xml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.xml | 2 +- .../xml/Doctrine.Tests.ORM.Mapping.DDC807Entity.dcm.xml | 2 +- ...ableEntityIncompleteDiscriminatorColumnMapping.dcm.xml | 2 +- ....SingleTableEntityNoDiscriminatorColumnMapping.dcm.xml | 2 +- .../Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml | 2 +- .../Mapping/xml/Doctrine.Tests.ORM.Mapping.XMLSLC.dcm.xml | 2 +- .../xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml | 2 +- tools/sandbox/xml/Entities.Address.dcm.xml | 2 +- tools/sandbox/xml/Entities.User.dcm.xml | 2 +- 52 files changed, 60 insertions(+), 60 deletions(-) diff --git a/docs/en/reference/events.rst b/docs/en/reference/events.rst index 7922d3dfd1d..19917ee10d4 100644 --- a/docs/en/reference/events.rst +++ b/docs/en/reference/events.rst @@ -323,7 +323,7 @@ XML would look something like this: + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/docs/en/reference/xml-mapping.rst b/docs/en/reference/xml-mapping.rst index 5f013152789..a2a0a9d97db 100644 --- a/docs/en/reference/xml-mapping.rst +++ b/docs/en/reference/xml-mapping.rst @@ -7,7 +7,7 @@ form of XML documents. The XML driver is backed by an XML Schema document that describes the structure of a mapping document. The most recent version of the XML Schema document is available online at -`http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd `_. +`http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd `_. In order to point to the latest version of the document of a particular stable release branch, just append the release number, i.e.: doctrine-mapping-2.0.xsd The most convenient way to work with @@ -21,7 +21,7 @@ setup for the latest code in trunk. + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> ... @@ -107,7 +107,7 @@ of several common elements: + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> @@ -768,7 +768,7 @@ entity relationship. You can define this in XML with the "association-key" attri + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/docs/en/tutorials/composite-primary-keys.rst b/docs/en/tutorials/composite-primary-keys.rst index 41f0cd88e78..913c9854e6c 100644 --- a/docs/en/tutorials/composite-primary-keys.rst +++ b/docs/en/tutorials/composite-primary-keys.rst @@ -63,7 +63,7 @@ and year of production as primary keys: + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> @@ -203,7 +203,7 @@ We keep up the example of an Article with arbitrary attributes, the mapping look + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/docs/en/tutorials/extra-lazy-associations.rst b/docs/en/tutorials/extra-lazy-associations.rst index 456c8c1c5ff..2aca3b9b104 100644 --- a/docs/en/tutorials/extra-lazy-associations.rst +++ b/docs/en/tutorials/extra-lazy-associations.rst @@ -65,7 +65,7 @@ switch to extra lazy as shown in these examples: + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/docs/en/tutorials/getting-started.rst b/docs/en/tutorials/getting-started.rst index 316fb5f76e1..224c1848e41 100644 --- a/docs/en/tutorials/getting-started.rst +++ b/docs/en/tutorials/getting-started.rst @@ -303,7 +303,7 @@ but you only need to choose one. + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> @@ -843,7 +843,7 @@ the ``Product`` before: + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> @@ -963,7 +963,7 @@ Finally, we'll add metadata mappings for the ``User`` entity. + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> @@ -1504,7 +1504,7 @@ we have to adjust the metadata slightly. + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/docs/en/tutorials/working-with-indexed-associations.rst b/docs/en/tutorials/working-with-indexed-associations.rst index a62d8b34209..0d27347c151 100644 --- a/docs/en/tutorials/working-with-indexed-associations.rst +++ b/docs/en/tutorials/working-with-indexed-associations.rst @@ -107,7 +107,7 @@ The code and mappings for the Market entity looks like this: + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> @@ -193,7 +193,7 @@ here are the code and mappings for it: + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.Person.dcm.xml b/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.Person.dcm.xml index 6d151af12f8..69193fead46 100644 --- a/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.Person.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.Person.dcm.xml @@ -3,7 +3,7 @@ xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping - https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd"> + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.PhoneNumber.dcm.xml b/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.PhoneNumber.dcm.xml index 2e404254a53..6876e807450 100644 --- a/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.PhoneNumber.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.PhoneNumber.dcm.xml @@ -3,7 +3,7 @@ xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping - https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd"> + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/DDC2429Book.orm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/DDC2429Book.orm.xml index 8640c6f51c4..3c853eef561 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/DDC2429Book.orm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/DDC2429Book.orm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CMS.CmsAddress.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CMS.CmsAddress.dcm.xml index 7e7bd5aaa2f..eaf5c8ff677 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CMS.CmsAddress.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CMS.CmsAddress.dcm.xml @@ -1,7 +1,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CMS.CmsUser.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CMS.CmsUser.dcm.xml index 122a45e6fe9..2fbe6a13878 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CMS.CmsUser.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CMS.CmsUser.dcm.xml @@ -3,7 +3,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyContract.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyContract.dcm.xml index 4fa0c23e1ff..d4ada6a570e 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyContract.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyContract.dcm.xml @@ -3,7 +3,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyFixContract.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyFixContract.dcm.xml index bd1019d6894..a8f56dd21ed 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyFixContract.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyFixContract.dcm.xml @@ -3,7 +3,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyFlexContract.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyFlexContract.dcm.xml index 91ef0bb1ce0..f8aed2639d1 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyFlexContract.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyFlexContract.dcm.xml @@ -3,7 +3,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyFlexUltraContract.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyFlexUltraContract.dcm.xml index 729bdfda035..1b3769aa816 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyFlexUltraContract.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyFlexUltraContract.dcm.xml @@ -3,7 +3,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyPerson.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyPerson.dcm.xml index 2ddd88a3249..63dd9bcc31f 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyPerson.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyPerson.dcm.xml @@ -3,7 +3,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC117.DDC117Translation.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC117.DDC117Translation.dcm.xml index ec3bc74fd5a..dd55cfd4255 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC117.DDC117Translation.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC117.DDC117Translation.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC1476.DDC1476EntityWithDefaultFieldType.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC1476.DDC1476EntityWithDefaultFieldType.dcm.xml index 29b5f1db5cd..bf6bdc8f8dd 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC1476.DDC1476EntityWithDefaultFieldType.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC1476.DDC1476EntityWithDefaultFieldType.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC2825.ExplicitSchemaAndTable.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC2825.ExplicitSchemaAndTable.dcm.xml index 11bb55706d0..2769e59aa01 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC2825.ExplicitSchemaAndTable.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC2825.ExplicitSchemaAndTable.dcm.xml @@ -3,7 +3,7 @@ xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping - https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd" + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd" > diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC2825.SchemaAndTableInTableName.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC2825.SchemaAndTableInTableName.dcm.xml index 3a89dd97369..5cb531e9d17 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC2825.SchemaAndTableInTableName.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC2825.SchemaAndTableInTableName.dcm.xml @@ -3,7 +3,7 @@ xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping - https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd" + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd" > diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293Address.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293Address.dcm.xml index 39c0f33b2d0..db6239ab92e 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293Address.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293Address.dcm.xml @@ -3,7 +3,7 @@ xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping - https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd"> + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293User.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293User.dcm.xml index bf24c1fd65d..da15b13cef8 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293User.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293User.dcm.xml @@ -3,7 +3,7 @@ xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping - https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd"> + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293UserPrefixed.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293UserPrefixed.dcm.xml index 1e0df304c05..b42dd543913 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293UserPrefixed.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293UserPrefixed.dcm.xml @@ -3,7 +3,7 @@ xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping - https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd"> + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3579.DDC3579Admin.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3579.DDC3579Admin.dcm.xml index 1f92867067e..ff7d5f2d4dd 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3579.DDC3579Admin.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3579.DDC3579Admin.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3579.DDC3579User.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3579.DDC3579User.dcm.xml index 3b6e213f121..bbe3c15c305 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3579.DDC3579User.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3579.DDC3579User.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC5934.DDC5934BaseContract.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC5934.DDC5934BaseContract.dcm.xml index 78a5af6b8d6..221644c4966 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC5934.DDC5934BaseContract.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC5934.DDC5934BaseContract.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC5934.DDC5934Contract.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC5934.DDC5934Contract.dcm.xml index bba41b94ec7..4c6e6ad2944 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC5934.DDC5934Contract.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC5934.DDC5934Contract.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.dcm.xml index 05e2540eff7..fcc022f7937 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.dcm.xml index daf01f03402..7cf22cc1a89 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869Payment.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869Payment.dcm.xml index be9f760b951..90426f1b096 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869Payment.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869Payment.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889Class.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889Class.dcm.xml index 4a8935c9a74..e3bc51cc7d3 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889Class.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889Class.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889Entity.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889Entity.dcm.xml index 686bdbfc761..78d4e217251 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889Entity.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889Entity.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889SuperClass.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889SuperClass.dcm.xml index 48fa4fb83f6..b4d2ed630c9 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889SuperClass.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889SuperClass.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC964.DDC964Admin.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC964.DDC964Admin.dcm.xml index f4bb4ebce0a..7a4266247e1 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC964.DDC964Admin.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC964.DDC964Admin.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC964.DDC964Guest.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC964.DDC964Guest.dcm.xml index 561066f6b83..c050a768c52 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC964.DDC964Guest.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC964.DDC964Guest.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC964.DDC964User.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC964.DDC964User.dcm.xml index 68db74b48e5..b2d4eba1344 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC964.DDC964User.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC964.DDC964User.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.GH7141.GH7141Article.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.GH7141.GH7141Article.dcm.xml index e073f380f5f..eec79159ce6 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.GH7141.GH7141Article.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.GH7141.GH7141Article.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml index 36af855f2a7..48a2ec3176d 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.ValueObjects.Name.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.ValueObjects.Name.dcm.xml index 97bb6a90eec..eea76991cd8 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.ValueObjects.Name.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.ValueObjects.Name.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.ValueObjects.Person.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.ValueObjects.Person.dcm.xml index c2480bca7d2..fd36e703af5 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.ValueObjects.Person.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.ValueObjects.Person.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml index a4c4e9bfda7..da6d5ebd753 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.CTI.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.CTI.dcm.xml index 14abaef7340..2fad33e0adc 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.CTI.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.CTI.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Comment.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Comment.dcm.xml index 8f02ca852c3..ab1809fbf28 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Comment.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Comment.dcm.xml @@ -3,7 +3,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.xml index 9f5ad7fac65..4131beae1fa 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC807Entity.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC807Entity.dcm.xml index 82711dc2f89..1a467211189 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC807Entity.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC807Entity.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.SingleTableEntityIncompleteDiscriminatorColumnMapping.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.SingleTableEntityIncompleteDiscriminatorColumnMapping.dcm.xml index 5dffe178d0b..57c5a2a1344 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.SingleTableEntityIncompleteDiscriminatorColumnMapping.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.SingleTableEntityIncompleteDiscriminatorColumnMapping.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.SingleTableEntityNoDiscriminatorColumnMapping.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.SingleTableEntityNoDiscriminatorColumnMapping.dcm.xml index 3e03f4498eb..898fbe72b65 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.SingleTableEntityNoDiscriminatorColumnMapping.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.SingleTableEntityNoDiscriminatorColumnMapping.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml index bbf29aeaf70..73f5b3faf69 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml @@ -3,7 +3,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.XMLSLC.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.XMLSLC.dcm.xml index ca8092b50d5..79c25838ae7 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.XMLSLC.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.XMLSLC.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml b/tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml index 78bac4f5f3f..9a3b237c8d3 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml @@ -3,7 +3,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tools/sandbox/xml/Entities.Address.dcm.xml b/tools/sandbox/xml/Entities.Address.dcm.xml index 7e8dd018340..989de13f87c 100644 --- a/tools/sandbox/xml/Entities.Address.dcm.xml +++ b/tools/sandbox/xml/Entities.Address.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tools/sandbox/xml/Entities.User.dcm.xml b/tools/sandbox/xml/Entities.User.dcm.xml index e548fd1a77c..640a8af18ec 100644 --- a/tools/sandbox/xml/Entities.User.dcm.xml +++ b/tools/sandbox/xml/Entities.User.dcm.xml @@ -2,7 +2,7 @@ + http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> From d93956eff05bd09ae2e102bec56e561046007f7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Mon, 12 Nov 2018 11:29:32 +0100 Subject: [PATCH 737/877] Use HTTPS endpoint for XML schema location --- docs/en/reference/events.rst | 2 +- docs/en/reference/second-level-cache.rst | 4 ++-- docs/en/reference/xml-mapping.rst | 8 ++++---- docs/en/tutorials/composite-primary-keys.rst | 4 ++-- docs/en/tutorials/extra-lazy-associations.rst | 2 +- docs/en/tutorials/getting-started.rst | 8 ++++---- docs/en/tutorials/working-with-indexed-associations.rst | 4 ++-- lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php | 2 +- ...ne.Tests.Models.OrnementalOrphanRemoval.Person.dcm.xml | 2 +- ...sts.Models.OrnementalOrphanRemoval.PhoneNumber.dcm.xml | 2 +- tests/Doctrine/Tests/ORM/Mapping/xml/CatNoId.dcm.xml | 2 +- tests/Doctrine/Tests/ORM/Mapping/xml/DDC2429Book.orm.xml | 2 +- tests/Doctrine/Tests/ORM/Mapping/xml/DDC2429Novel.orm.xml | 2 +- .../xml/Doctrine.Tests.Models.CMS.CmsAddress.dcm.xml | 2 +- .../Mapping/xml/Doctrine.Tests.Models.CMS.CmsUser.dcm.xml | 4 ++-- .../Mapping/xml/Doctrine.Tests.Models.Cache.City.dcm.xml | 2 +- .../Doctrine.Tests.Models.Company.CompanyContract.dcm.xml | 4 ++-- ...ctrine.Tests.Models.Company.CompanyFixContract.dcm.xml | 4 ++-- ...trine.Tests.Models.Company.CompanyFlexContract.dcm.xml | 4 ++-- ....Tests.Models.Company.CompanyFlexUltraContract.dcm.xml | 4 ++-- .../Doctrine.Tests.Models.Company.CompanyPerson.dcm.xml | 4 ++-- ...Doctrine.Tests.Models.DDC117.DDC117Translation.dcm.xml | 2 +- ...dels.DDC1476.DDC1476EntityWithDefaultFieldType.dcm.xml | 4 ++-- ...ne.Tests.Models.DDC2825.ExplicitSchemaAndTable.dcm.xml | 2 +- ...Tests.Models.DDC2825.SchemaAndTableInTableName.dcm.xml | 2 +- .../Doctrine.Tests.Models.DDC3293.DDC3293Address.dcm.xml | 2 +- .../xml/Doctrine.Tests.Models.DDC3293.DDC3293User.dcm.xml | 2 +- ...trine.Tests.Models.DDC3293.DDC3293UserPrefixed.dcm.xml | 2 +- .../Doctrine.Tests.Models.DDC3579.DDC3579Admin.dcm.xml | 2 +- .../xml/Doctrine.Tests.Models.DDC3579.DDC3579User.dcm.xml | 2 +- ...trine.Tests.Models.DDC5934.DDC5934BaseContract.dcm.xml | 2 +- .../Doctrine.Tests.Models.DDC5934.DDC5934Contract.dcm.xml | 2 +- ...ne.Tests.Models.DDC869.DDC869CreditCardPayment.dcm.xml | 4 ++-- .../xml/Doctrine.Tests.Models.DDC889.DDC889Class.dcm.xml | 4 ++-- .../xml/Doctrine.Tests.Models.DDC889.DDC889Entity.dcm.xml | 4 ++-- .../Doctrine.Tests.Models.DDC889.DDC889SuperClass.dcm.xml | 4 ++-- .../xml/Doctrine.Tests.Models.DDC964.DDC964Admin.dcm.xml | 4 ++-- .../xml/Doctrine.Tests.Models.DDC964.DDC964Guest.dcm.xml | 4 ++-- .../xml/Doctrine.Tests.Models.DDC964.DDC964User.dcm.xml | 4 ++-- .../Doctrine.Tests.Models.GH7141.GH7141Article.dcm.xml | 2 +- ...ctrine.Tests.Models.Generic.SerializationModel.dcm.xml | 2 +- .../xml/Doctrine.Tests.Models.ValueObjects.Name.dcm.xml | 2 +- .../xml/Doctrine.Tests.Models.ValueObjects.Person.dcm.xml | 2 +- .../Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml | 2 +- .../Mapping/xml/Doctrine.Tests.ORM.Mapping.CTI.dcm.xml | 2 +- .../xml/Doctrine.Tests.ORM.Mapping.Comment.dcm.xml | 2 +- .../xml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.xml | 4 ++-- .../xml/Doctrine.Tests.ORM.Mapping.DDC807Entity.dcm.xml | 4 ++-- ...ableEntityIncompleteDiscriminatorColumnMapping.dcm.xml | 4 ++-- ....SingleTableEntityNoDiscriminatorColumnMapping.dcm.xml | 4 ++-- .../Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml | 2 +- .../Mapping/xml/Doctrine.Tests.ORM.Mapping.XMLSLC.dcm.xml | 2 +- .../ORM/Tools/Export/XmlClassMetadataExporterTest.php | 4 ++-- .../xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml | 2 +- tools/sandbox/xml/Entities.Address.dcm.xml | 2 +- tools/sandbox/xml/Entities.User.dcm.xml | 2 +- 56 files changed, 84 insertions(+), 84 deletions(-) diff --git a/docs/en/reference/events.rst b/docs/en/reference/events.rst index 19917ee10d4..b38ba581910 100644 --- a/docs/en/reference/events.rst +++ b/docs/en/reference/events.rst @@ -323,7 +323,7 @@ XML would look something like this: + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/docs/en/reference/second-level-cache.rst b/docs/en/reference/second-level-cache.rst index 62cc5d14fdf..c4ae4f0ee7f 100644 --- a/docs/en/reference/second-level-cache.rst +++ b/docs/en/reference/second-level-cache.rst @@ -310,7 +310,7 @@ Entity cache definition .. code-block:: xml - + @@ -386,7 +386,7 @@ It caches the primary keys of association and cache each element will be cached .. code-block:: xml - + diff --git a/docs/en/reference/xml-mapping.rst b/docs/en/reference/xml-mapping.rst index a2a0a9d97db..f57ee461bbb 100644 --- a/docs/en/reference/xml-mapping.rst +++ b/docs/en/reference/xml-mapping.rst @@ -7,7 +7,7 @@ form of XML documents. The XML driver is backed by an XML Schema document that describes the structure of a mapping document. The most recent version of the XML Schema document is available online at -`http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd `_. +`https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd `_. In order to point to the latest version of the document of a particular stable release branch, just append the release number, i.e.: doctrine-mapping-2.0.xsd The most convenient way to work with @@ -21,7 +21,7 @@ setup for the latest code in trunk. + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> ... @@ -107,7 +107,7 @@ of several common elements: + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> @@ -768,7 +768,7 @@ entity relationship. You can define this in XML with the "association-key" attri + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/docs/en/tutorials/composite-primary-keys.rst b/docs/en/tutorials/composite-primary-keys.rst index 913c9854e6c..ef164c9db1f 100644 --- a/docs/en/tutorials/composite-primary-keys.rst +++ b/docs/en/tutorials/composite-primary-keys.rst @@ -63,7 +63,7 @@ and year of production as primary keys: + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> @@ -203,7 +203,7 @@ We keep up the example of an Article with arbitrary attributes, the mapping look + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/docs/en/tutorials/extra-lazy-associations.rst b/docs/en/tutorials/extra-lazy-associations.rst index 2aca3b9b104..4452d6890a1 100644 --- a/docs/en/tutorials/extra-lazy-associations.rst +++ b/docs/en/tutorials/extra-lazy-associations.rst @@ -65,7 +65,7 @@ switch to extra lazy as shown in these examples: + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/docs/en/tutorials/getting-started.rst b/docs/en/tutorials/getting-started.rst index 224c1848e41..718eac5df05 100644 --- a/docs/en/tutorials/getting-started.rst +++ b/docs/en/tutorials/getting-started.rst @@ -303,7 +303,7 @@ but you only need to choose one. + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> @@ -843,7 +843,7 @@ the ``Product`` before: + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> @@ -963,7 +963,7 @@ Finally, we'll add metadata mappings for the ``User`` entity. + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> @@ -1504,7 +1504,7 @@ we have to adjust the metadata slightly. + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/docs/en/tutorials/working-with-indexed-associations.rst b/docs/en/tutorials/working-with-indexed-associations.rst index 0d27347c151..0381764bee9 100644 --- a/docs/en/tutorials/working-with-indexed-associations.rst +++ b/docs/en/tutorials/working-with-indexed-associations.rst @@ -107,7 +107,7 @@ The code and mappings for the Market entity looks like this: + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> @@ -193,7 +193,7 @@ here are the code and mappings for it: + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php index 2d6bf1a73e2..60dabe97336 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php @@ -44,7 +44,7 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) $xml = new SimpleXmlElement(''); + 'xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd" />'); if ($metadata->isMappedSuperclass) { $root = $xml->addChild('mapped-superclass'); diff --git a/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.Person.dcm.xml b/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.Person.dcm.xml index 69193fead46..ff0f103c4cd 100644 --- a/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.Person.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.Person.dcm.xml @@ -3,7 +3,7 @@ xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping - http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.PhoneNumber.dcm.xml b/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.PhoneNumber.dcm.xml index 6876e807450..f56c918b420 100644 --- a/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.PhoneNumber.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Functional/xml/Doctrine.Tests.Models.OrnementalOrphanRemoval.PhoneNumber.dcm.xml @@ -3,7 +3,7 @@ xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping - http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/CatNoId.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/CatNoId.dcm.xml index 6025d350f1e..3f2457bd3d3 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/CatNoId.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/CatNoId.dcm.xml @@ -1,7 +1,7 @@ + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/DDC2429Book.orm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/DDC2429Book.orm.xml index 3c853eef561..08e26406bbd 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/DDC2429Book.orm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/DDC2429Book.orm.xml @@ -2,7 +2,7 @@ + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/DDC2429Novel.orm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/DDC2429Novel.orm.xml index 43ce9428519..5a6f3f89fb8 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/DDC2429Novel.orm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/DDC2429Novel.orm.xml @@ -1,7 +1,7 @@ + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CMS.CmsAddress.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CMS.CmsAddress.dcm.xml index eaf5c8ff677..e4b80346c43 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CMS.CmsAddress.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CMS.CmsAddress.dcm.xml @@ -1,7 +1,7 @@ + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CMS.CmsUser.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CMS.CmsUser.dcm.xml index 2fbe6a13878..f91ed311512 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CMS.CmsUser.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CMS.CmsUser.dcm.xml @@ -3,8 +3,8 @@ - + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Cache.City.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Cache.City.dcm.xml index 84b786a7bd7..415302d0a80 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Cache.City.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Cache.City.dcm.xml @@ -1,5 +1,5 @@ - + diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyContract.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyContract.dcm.xml index d4ada6a570e..b775e3ccc76 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyContract.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyContract.dcm.xml @@ -3,8 +3,8 @@ - + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyFixContract.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyFixContract.dcm.xml index a8f56dd21ed..bfa5431fc21 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyFixContract.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyFixContract.dcm.xml @@ -3,8 +3,8 @@ - + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyFlexContract.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyFlexContract.dcm.xml index f8aed2639d1..21ca4238d1f 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyFlexContract.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyFlexContract.dcm.xml @@ -3,8 +3,8 @@ - + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyFlexUltraContract.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyFlexUltraContract.dcm.xml index 1b3769aa816..381e67571f0 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyFlexUltraContract.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyFlexUltraContract.dcm.xml @@ -3,8 +3,8 @@ - + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyPerson.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyPerson.dcm.xml index 63dd9bcc31f..d8db5107341 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyPerson.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Company.CompanyPerson.dcm.xml @@ -3,8 +3,8 @@ - + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC117.DDC117Translation.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC117.DDC117Translation.dcm.xml index dd55cfd4255..019f201b04a 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC117.DDC117Translation.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC117.DDC117Translation.dcm.xml @@ -2,7 +2,7 @@ + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC1476.DDC1476EntityWithDefaultFieldType.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC1476.DDC1476EntityWithDefaultFieldType.dcm.xml index bf6bdc8f8dd..fedfeada509 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC1476.DDC1476EntityWithDefaultFieldType.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC1476.DDC1476EntityWithDefaultFieldType.dcm.xml @@ -2,8 +2,8 @@ - + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC2825.ExplicitSchemaAndTable.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC2825.ExplicitSchemaAndTable.dcm.xml index 2769e59aa01..57063fb6ca4 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC2825.ExplicitSchemaAndTable.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC2825.ExplicitSchemaAndTable.dcm.xml @@ -3,7 +3,7 @@ xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping - http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd" + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd" > diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC2825.SchemaAndTableInTableName.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC2825.SchemaAndTableInTableName.dcm.xml index 5cb531e9d17..b520f626cf1 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC2825.SchemaAndTableInTableName.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC2825.SchemaAndTableInTableName.dcm.xml @@ -3,7 +3,7 @@ xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping - http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd" + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd" > diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293Address.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293Address.dcm.xml index db6239ab92e..54fbae8b410 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293Address.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293Address.dcm.xml @@ -3,7 +3,7 @@ xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping - http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293User.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293User.dcm.xml index da15b13cef8..c2d1e44910f 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293User.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293User.dcm.xml @@ -3,7 +3,7 @@ xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping - http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293UserPrefixed.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293UserPrefixed.dcm.xml index b42dd543913..3988ab32539 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293UserPrefixed.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293UserPrefixed.dcm.xml @@ -3,7 +3,7 @@ xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping - http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3579.DDC3579Admin.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3579.DDC3579Admin.dcm.xml index ff7d5f2d4dd..00695adbb28 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3579.DDC3579Admin.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3579.DDC3579Admin.dcm.xml @@ -2,7 +2,7 @@ + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3579.DDC3579User.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3579.DDC3579User.dcm.xml index bbe3c15c305..a93fb6938ba 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3579.DDC3579User.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3579.DDC3579User.dcm.xml @@ -2,7 +2,7 @@ + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC5934.DDC5934BaseContract.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC5934.DDC5934BaseContract.dcm.xml index 221644c4966..07809813177 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC5934.DDC5934BaseContract.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC5934.DDC5934BaseContract.dcm.xml @@ -2,7 +2,7 @@ + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC5934.DDC5934Contract.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC5934.DDC5934Contract.dcm.xml index 4c6e6ad2944..4bd3f5af27f 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC5934.DDC5934Contract.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC5934.DDC5934Contract.dcm.xml @@ -2,7 +2,7 @@ + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.dcm.xml index 7cf22cc1a89..bcd02647ece 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.dcm.xml @@ -2,8 +2,8 @@ - + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889Class.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889Class.dcm.xml index e3bc51cc7d3..86e04112161 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889Class.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889Class.dcm.xml @@ -2,8 +2,8 @@ - + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889Entity.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889Entity.dcm.xml index 78d4e217251..b366cbb6068 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889Entity.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889Entity.dcm.xml @@ -2,8 +2,8 @@ - + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889SuperClass.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889SuperClass.dcm.xml index b4d2ed630c9..4b174a393e2 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889SuperClass.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889SuperClass.dcm.xml @@ -2,8 +2,8 @@ - + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC964.DDC964Admin.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC964.DDC964Admin.dcm.xml index 7a4266247e1..ea6e22fdbda 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC964.DDC964Admin.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC964.DDC964Admin.dcm.xml @@ -2,8 +2,8 @@ - + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC964.DDC964Guest.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC964.DDC964Guest.dcm.xml index c050a768c52..5ad7a1e1488 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC964.DDC964Guest.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC964.DDC964Guest.dcm.xml @@ -2,8 +2,8 @@ - + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC964.DDC964User.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC964.DDC964User.dcm.xml index b2d4eba1344..83b878840a5 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC964.DDC964User.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC964.DDC964User.dcm.xml @@ -2,8 +2,8 @@ - + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.GH7141.GH7141Article.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.GH7141.GH7141Article.dcm.xml index eec79159ce6..34813ab7ef1 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.GH7141.GH7141Article.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.GH7141.GH7141Article.dcm.xml @@ -2,7 +2,7 @@ + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml index 48a2ec3176d..5974da2640a 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml @@ -2,7 +2,7 @@ + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.ValueObjects.Name.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.ValueObjects.Name.dcm.xml index eea76991cd8..0cb3aed27ef 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.ValueObjects.Name.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.ValueObjects.Name.dcm.xml @@ -2,7 +2,7 @@ + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.ValueObjects.Person.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.ValueObjects.Person.dcm.xml index fd36e703af5..68752703815 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.ValueObjects.Person.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.ValueObjects.Person.dcm.xml @@ -2,7 +2,7 @@ + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml index da6d5ebd753..8ad0e2a6522 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml @@ -2,7 +2,7 @@ + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.CTI.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.CTI.dcm.xml index 2fad33e0adc..b26ca1089c6 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.CTI.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.CTI.dcm.xml @@ -2,7 +2,7 @@ + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Comment.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Comment.dcm.xml index ab1809fbf28..e83232f1a9f 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Comment.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Comment.dcm.xml @@ -3,7 +3,7 @@ + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.xml index 4131beae1fa..a77f2e1bc48 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.xml @@ -2,8 +2,8 @@ - + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC807Entity.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC807Entity.dcm.xml index 1a467211189..9a33752340d 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC807Entity.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC807Entity.dcm.xml @@ -2,8 +2,8 @@ - + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.SingleTableEntityIncompleteDiscriminatorColumnMapping.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.SingleTableEntityIncompleteDiscriminatorColumnMapping.dcm.xml index 57c5a2a1344..af274cdafdd 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.SingleTableEntityIncompleteDiscriminatorColumnMapping.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.SingleTableEntityIncompleteDiscriminatorColumnMapping.dcm.xml @@ -2,8 +2,8 @@ - + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.SingleTableEntityNoDiscriminatorColumnMapping.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.SingleTableEntityNoDiscriminatorColumnMapping.dcm.xml index 898fbe72b65..8f2854550eb 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.SingleTableEntityNoDiscriminatorColumnMapping.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.SingleTableEntityNoDiscriminatorColumnMapping.dcm.xml @@ -2,8 +2,8 @@ - + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml index 73f5b3faf69..1fa06126334 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml @@ -3,7 +3,7 @@ + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.XMLSLC.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.XMLSLC.dcm.xml index 79c25838ae7..1dec40d7f92 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.XMLSLC.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.XMLSLC.dcm.xml @@ -2,7 +2,7 @@ + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/XmlClassMetadataExporterTest.php b/tests/Doctrine/Tests/ORM/Tools/Export/XmlClassMetadataExporterTest.php index 424412882eb..4ee7afa8f80 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/XmlClassMetadataExporterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/XmlClassMetadataExporterTest.php @@ -52,7 +52,7 @@ public function testSequenceGenerator() { @@ -89,7 +89,7 @@ public function testFieldOptionsExport() { $expectedFileContent = <<<'XML' - + diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml b/tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml index 9a3b237c8d3..4092c8574c5 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Tools/Export/xml/Doctrine.Tests.ORM.Tools.Export.User.dcm.xml @@ -3,7 +3,7 @@ + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tools/sandbox/xml/Entities.Address.dcm.xml b/tools/sandbox/xml/Entities.Address.dcm.xml index 989de13f87c..92475ed233d 100644 --- a/tools/sandbox/xml/Entities.Address.dcm.xml +++ b/tools/sandbox/xml/Entities.Address.dcm.xml @@ -2,7 +2,7 @@ + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> diff --git a/tools/sandbox/xml/Entities.User.dcm.xml b/tools/sandbox/xml/Entities.User.dcm.xml index 640a8af18ec..4fe7e4c4af0 100644 --- a/tools/sandbox/xml/Entities.User.dcm.xml +++ b/tools/sandbox/xml/Entities.User.dcm.xml @@ -2,7 +2,7 @@ + https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> From c6d02daee0a15653afd464205c2dfa83c2f1237f Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Wed, 24 Oct 2018 13:06:33 +0100 Subject: [PATCH 738/877] $hydrationMode throughout can be a string as well as int (for custom modes) --- lib/Doctrine/ORM/AbstractQuery.php | 22 ++++++++++----------- lib/Doctrine/ORM/EntityManagerInterface.php | 4 ++-- lib/Doctrine/ORM/Query.php | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 3ba0dee263d..31c222a7fe5 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -98,7 +98,7 @@ abstract class AbstractQuery /** * The hydration mode. * - * @var integer + * @var string|int */ protected $_hydrationMode = self::HYDRATE_OBJECT; @@ -680,8 +680,8 @@ public function setFetchMode($class, $assocName, $fetchMode) /** * Defines the processing mode to be used during hydration / result set transformation. * - * @param integer $hydrationMode Doctrine processing mode to be used during hydration process. - * One of the Query::HYDRATE_* constants. + * @param string|int $hydrationMode Doctrine processing mode to be used during hydration process. + * One of the Query::HYDRATE_* constants. * * @return static This query instance. */ @@ -695,7 +695,7 @@ public function setHydrationMode($hydrationMode) /** * Gets the hydration mode currently used by the query. * - * @return integer + * @return string|int */ public function getHydrationMode() { @@ -707,7 +707,7 @@ public function getHydrationMode() * * Alias for execute(null, $hydrationMode = HYDRATE_OBJECT). * - * @param int $hydrationMode + * @param string|int $hydrationMode * * @return mixed */ @@ -743,7 +743,7 @@ public function getScalarResult() /** * Get exactly one result or null. * - * @param int $hydrationMode + * @param string|int $hydrationMode * * @return mixed * @@ -781,7 +781,7 @@ public function getOneOrNullResult($hydrationMode = null) * If the result is not unique, a NonUniqueResultException is thrown. * If there is no result, a NoResultException is thrown. * - * @param integer $hydrationMode + * @param string|int $hydrationMode * * @return mixed * @@ -875,7 +875,7 @@ public function getHints() * iterate over the result. * * @param ArrayCollection|array|null $parameters The query parameters. - * @param integer|null $hydrationMode The hydration mode to use. + * @param string|int|null $hydrationMode The hydration mode to use. * * @return \Doctrine\ORM\Internal\Hydration\IterableResult */ @@ -899,7 +899,7 @@ public function iterate($parameters = null, $hydrationMode = null) * Executes the query. * * @param ArrayCollection|array|null $parameters Query parameters. - * @param integer|null $hydrationMode Processing mode to be used during the hydration process. + * @param string|int|null $hydrationMode Processing mode to be used during the hydration process. * * @return mixed */ @@ -916,7 +916,7 @@ public function execute($parameters = null, $hydrationMode = null) * Execute query ignoring second level cache. * * @param ArrayCollection|array|null $parameters - * @param integer|null $hydrationMode + * @param string|int|null $hydrationMode * * @return mixed */ @@ -974,7 +974,7 @@ private function executeIgnoreQueryCache($parameters = null, $hydrationMode = nu * Load from second level cache or executes the query and put into cache. * * @param ArrayCollection|array|null $parameters - * @param integer|null $hydrationMode + * @param string|int|null $hydrationMode * * @return mixed */ diff --git a/lib/Doctrine/ORM/EntityManagerInterface.php b/lib/Doctrine/ORM/EntityManagerInterface.php index c61e6973c28..a423432a162 100644 --- a/lib/Doctrine/ORM/EntityManagerInterface.php +++ b/lib/Doctrine/ORM/EntityManagerInterface.php @@ -249,7 +249,7 @@ public function getUnitOfWork(); * * @deprecated * - * @param int $hydrationMode + * @param string|int $hydrationMode * * @return \Doctrine\ORM\Internal\Hydration\AbstractHydrator */ @@ -258,7 +258,7 @@ public function getHydrator($hydrationMode); /** * Create a new instance for the given hydration mode. * - * @param int $hydrationMode + * @param string|int $hydrationMode * * @return \Doctrine\ORM\Internal\Hydration\AbstractHydrator * diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 041ebeebb9f..525aa7a5081 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -656,7 +656,7 @@ public function getMaxResults() * iterated over the result. * * @param ArrayCollection|array|null $parameters The query parameters. - * @param integer $hydrationMode The hydration mode to use. + * @param string|int $hydrationMode The hydration mode to use. * * @return \Doctrine\ORM\Internal\Hydration\IterableResult */ From fbd3fe95e431382419ee62d4263279143e876212 Mon Sep 17 00:00:00 2001 From: Farhad Safarov Date: Tue, 13 Nov 2018 13:01:10 +0300 Subject: [PATCH 739/877] fix incorrect phpdoc typehint --- lib/Doctrine/ORM/QueryBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/QueryBuilder.php b/lib/Doctrine/ORM/QueryBuilder.php index 4081890dd57..af4d8cd2be6 100644 --- a/lib/Doctrine/ORM/QueryBuilder.php +++ b/lib/Doctrine/ORM/QueryBuilder.php @@ -1027,7 +1027,7 @@ public function leftJoin($join, $alias, $conditionType = null, $condition = null * * * @param string $key The key/field to set. - * @param string $value The value, expression, placeholder, etc. + * @param mixed $value The value, expression, placeholder, etc. * * @return self */ From 0552749059ad24d657ef4a0f1dfe437f58022ca2 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Tue, 13 Nov 2018 09:08:46 +0100 Subject: [PATCH 740/877] Fix parameter value processing for objects with unloaded metadata --- lib/Doctrine/ORM/AbstractQuery.php | 20 +++++++++++++++----- tests/Doctrine/Tests/ORM/Query/QueryTest.php | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 3ba0dee263d..0e66e147ff4 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -19,10 +19,12 @@ namespace Doctrine\ORM; +use Doctrine\Common\Persistence\Mapping\MappingException; use Doctrine\Common\Util\ClassUtils; use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\ORM\Mapping\MappingException as ORMMappingException; use Doctrine\ORM\Query\Parameter; use Doctrine\ORM\Cache\QueryCacheKey; use Doctrine\DBAL\Cache\QueryCacheProfile; @@ -410,16 +412,24 @@ public function processParameterValue($value) return $value; } - if (is_object($value) && $this->_em->getMetadataFactory()->hasMetadataFor(ClassUtils::getClass($value))) { + if ($value instanceof Mapping\ClassMetadata) { + return $value->name; + } + + if (! is_object($value)) { + return $value; + } + + try { $value = $this->_em->getUnitOfWork()->getSingleIdentifierValue($value); if ($value === null) { throw ORMInvalidArgumentException::invalidIdentifierBindingEntity(); } - } - - if ($value instanceof Mapping\ClassMetadata) { - return $value->name; + } catch (MappingException | ORMMappingException $e) { + // Silence any mapping exceptions. These can occur if the object in + // question is not a mapped entity, in which case we just don't do + // any preparation on the value. } return $value; diff --git a/tests/Doctrine/Tests/ORM/Query/QueryTest.php b/tests/Doctrine/Tests/ORM/Query/QueryTest.php index 8cceb6c503e..8a3caf66f05 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryTest.php @@ -189,6 +189,25 @@ public function testProcessParameterValueClassMetadata() ); } + public function testProcessParameterValueObject() : void + { + $query = $this->_em->createQuery('SELECT a FROM Doctrine\Tests\Models\CMS\CmsAddress a WHERE a.user = :user'); + $user = new CmsUser(); + $user->id = 12345; + + self::assertSame( + 12345, + $query->processParameterValue($user) + ); + } + + public function testProcessParameterValueNull() : void + { + $query = $this->_em->createQuery('SELECT a FROM Doctrine\Tests\Models\CMS\CmsAddress a WHERE a.user = :user'); + + self::assertNull($query->processParameterValue(null)); + } + public function testDefaultQueryHints() { $config = $this->_em->getConfiguration(); From 72121c01ec12b4986c23c1fdec6758b3d459503a Mon Sep 17 00:00:00 2001 From: Alex Denvir Date: Thu, 19 Jul 2018 10:37:04 +0100 Subject: [PATCH 741/877] [XML] Fix default value of many-to-many order-by to ASC --- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 4 +++- .../Tests/Models/GH7316/GH7316Article.php | 15 +++++++++++++++ .../Tests/ORM/Mapping/XmlMappingDriverTest.php | 15 +++++++++++++++ ...rine.Tests.Models.GH7316.GH7316Article.dcm.xml | 14 ++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/Tests/Models/GH7316/GH7316Article.php create mode 100644 tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.GH7316.GH7316Article.dcm.xml diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 3229b6b73cb..93b697caef6 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -549,7 +549,9 @@ public function loadMetadataForClass($className, ClassMetadata $metadata) if (isset($manyToManyElement->{'order-by'})) { $orderBy = []; foreach ($manyToManyElement->{'order-by'}->{'order-by-field'} as $orderByField) { - $orderBy[(string) $orderByField['name']] = (string) $orderByField['direction']; + $orderBy[(string) $orderByField['name']] = isset($orderByField['direction']) + ? (string) $orderByField['direction'] + : Criteria::ASC; } $mapping['orderBy'] = $orderBy; } diff --git a/tests/Doctrine/Tests/Models/GH7316/GH7316Article.php b/tests/Doctrine/Tests/Models/GH7316/GH7316Article.php new file mode 100644 index 00000000000..a832cd70d4c --- /dev/null +++ b/tests/Doctrine/Tests/Models/GH7316/GH7316Article.php @@ -0,0 +1,15 @@ +tags = new ArrayCollection(); + } +} diff --git a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php index 45beca8d4cb..8ff6c0183f5 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php @@ -13,6 +13,7 @@ use Doctrine\Tests\Models\DDC889\DDC889Class; use Doctrine\Tests\Models\Generic\SerializationModel; use Doctrine\Tests\Models\GH7141\GH7141Article; +use Doctrine\Tests\Models\GH7316\GH7316Article; use Doctrine\Tests\Models\ValueObjects\Name; use Doctrine\Tests\Models\ValueObjects\Person; @@ -194,6 +195,20 @@ public function testOneToManyDefaultOrderByAsc() ); } + public function testManyToManyDefaultOrderByAsc() : void + { + $class = new ClassMetadata(GH7316Article::class); + $class->initializeReflection(new RuntimeReflectionService()); + + $driver = $this->_loadDriver(); + $driver->loadMetadataForClass(GH7316Article::class, $class); + + self::assertEquals( + Criteria::ASC, + $class->getMetadataValue('associationMappings')['tags']['orderBy']['position'] + ); + } + /** * @group DDC-889 * @expectedException \Doctrine\Common\Persistence\Mapping\MappingException diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.GH7316.GH7316Article.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.GH7316.GH7316Article.dcm.xml new file mode 100644 index 00000000000..3820cdc9be3 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.GH7316.GH7316Article.dcm.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + From ee8dc496d915f71f58246f5dd6585c5a22a32eec Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Sun, 19 Nov 2017 00:57:54 +0100 Subject: [PATCH 742/877] Fix applying collation on foreign key columns --- lib/Doctrine/ORM/Tools/SchemaTool.php | 38 ++++++++++-------- .../Tests/Models/Forum/ForumCategory.php | 2 +- .../Tests/ORM/Tools/SchemaToolTest.php | 40 +++++++++++++++++++ 3 files changed, 63 insertions(+), 17 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 1950446e7c8..423ed3b5320 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -45,6 +45,8 @@ */ class SchemaTool { + private const KNOWN_COLUMN_OPTIONS = ['comment', 'unsigned', 'fixed', 'default']; + /** * @var \Doctrine\ORM\EntityManagerInterface */ @@ -467,19 +469,8 @@ private function gatherColumn($class, array $mapping, Table $table) $options['columnDefinition'] = $mapping['columnDefinition']; } - if (isset($mapping['options'])) { - $knownOptions = ['comment', 'unsigned', 'fixed', 'default']; - - foreach ($knownOptions as $knownOption) { - if (array_key_exists($knownOption, $mapping['options'])) { - $options[$knownOption] = $mapping['options'][$knownOption]; - - unset($mapping['options'][$knownOption]); - } - } - - $options['customSchemaOptions'] = $mapping['options']; - } + // the 'default' option can be overwritten here + $options = $this->gatherColumnOptions($mapping) + $options; if ($class->isIdGeneratorIdentity() && $class->getIdentifierFieldNames() == [$mapping['fieldName']]) { $options['autoincrement'] = true; @@ -690,9 +681,7 @@ private function gatherRelationJoinColumns( $columnOptions['notnull'] = ! $joinColumn['nullable']; } - if (isset($fieldMapping['options'])) { - $columnOptions['options'] = $fieldMapping['options']; - } + $columnOptions = $columnOptions + $this->gatherColumnOptions($fieldMapping); if ($fieldMapping['type'] == "string" && isset($fieldMapping['length'])) { $columnOptions['length'] = $fieldMapping['length']; @@ -745,6 +734,23 @@ private function gatherRelationJoinColumns( } } + /** + * @param mixed[] $mapping + * + * @return mixed[] + */ + private function gatherColumnOptions(array $mapping) : array + { + if (! isset($mapping['options'])) { + return []; + } + + $options = array_intersect_key($mapping['options'], array_flip(self::KNOWN_COLUMN_OPTIONS)); + $options['customSchemaOptions'] = array_diff_key($mapping['options'], $options); + + return $options; + } + /** * Drops the database schema for the given classes. * diff --git a/tests/Doctrine/Tests/Models/Forum/ForumCategory.php b/tests/Doctrine/Tests/Models/Forum/ForumCategory.php index f04f128dce8..6a268d78cc7 100644 --- a/tests/Doctrine/Tests/Models/Forum/ForumCategory.php +++ b/tests/Doctrine/Tests/Models/Forum/ForumCategory.php @@ -9,7 +9,7 @@ class ForumCategory { /** - * @Column(type="integer") + * @Column(type="string", length=8, options={"fixed":true, "collation":"latin1_bin", "foo":"bar"}) * @Id */ private $id; diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php index 6750442e8a6..29ed1e9c884 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php @@ -18,6 +18,8 @@ use Doctrine\Tests\Models\CompositeKeyInheritance\JoinedDerivedIdentityClass; use Doctrine\Tests\Models\CompositeKeyInheritance\JoinedDerivedRootClass; use Doctrine\Tests\Models\Forum\ForumAvatar; +use Doctrine\Tests\Models\Forum\ForumBoard; +use Doctrine\Tests\Models\Forum\ForumCategory; use Doctrine\Tests\Models\Forum\ForumUser; use Doctrine\Tests\Models\NullDefault\NullDefaultColumn; use Doctrine\Tests\OrmTestCase; @@ -86,6 +88,44 @@ public function testPassColumnDefinitionToJoinColumn() $this->assertEquals($customColumnDef, $table->getColumn('avatar_id')->getColumnDefinition()); } + public function testPassColumnOptionsToJoinColumn() + { + $em = $this->_getTestEntityManager(); + $schemaTool = new SchemaTool($em); + + $category = $em->getClassMetadata(ForumCategory::class); + $board = $em->getClassMetadata(ForumBoard::class); + + $classes = [$category, $board]; + + $schema = $schemaTool->getSchemaFromMetadata($classes); + + self::assertTrue($schema->hasTable('forum_categories')); + self::assertTrue($schema->hasTable('forum_boards')); + + $tableCategory = $schema->getTable('forum_categories'); + $tableBoard = $schema->getTable('forum_boards'); + + self::assertTrue($tableBoard->hasColumn('category_id')); + + self::assertSame( + $tableCategory->getColumn('id')->getFixed(), + $tableBoard->getColumn('category_id')->getFixed(), + 'Foreign key/join column should have the same value of option `fixed` as the referenced column' + ); + + self::assertEquals( + $tableCategory->getColumn('id')->getCustomSchemaOptions(), + $tableBoard->getColumn('category_id')->getCustomSchemaOptions(), + 'Foreign key/join column should have the same custom options as the referenced column' + ); + + self::assertEquals( + ['collation' => 'latin1_bin', 'foo' => 'bar'], + $tableBoard->getColumn('category_id')->getCustomSchemaOptions() + ); + } + /** * @group DDC-283 */ From 0be52b0087938912a262bddd7656bc7ee227fd45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 21 Nov 2018 00:20:20 +0100 Subject: [PATCH 743/877] Isolate entities used by the new test To ensure we don't have any unintended side-effect. --- .../Tests/Models/Forum/ForumCategory.php | 2 +- .../Tests/ORM/Tools/SchemaToolTest.php | 61 +++++++++++++++---- 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/tests/Doctrine/Tests/Models/Forum/ForumCategory.php b/tests/Doctrine/Tests/Models/Forum/ForumCategory.php index 6a268d78cc7..f04f128dce8 100644 --- a/tests/Doctrine/Tests/Models/Forum/ForumCategory.php +++ b/tests/Doctrine/Tests/Models/Forum/ForumCategory.php @@ -9,7 +9,7 @@ class ForumCategory { /** - * @Column(type="string", length=8, options={"fixed":true, "collation":"latin1_bin", "foo":"bar"}) + * @Column(type="integer") * @Id */ private $id; diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php index 29ed1e9c884..ea520d8fc73 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php @@ -88,23 +88,23 @@ public function testPassColumnDefinitionToJoinColumn() $this->assertEquals($customColumnDef, $table->getColumn('avatar_id')->getColumnDefinition()); } - public function testPassColumnOptionsToJoinColumn() + /** + * @group 6830 + */ + public function testPassColumnOptionsToJoinColumn() : void { $em = $this->_getTestEntityManager(); - $schemaTool = new SchemaTool($em); - - $category = $em->getClassMetadata(ForumCategory::class); - $board = $em->getClassMetadata(ForumBoard::class); - - $classes = [$category, $board]; + $category = $em->getClassMetadata(GH6830Category::class); + $board = $em->getClassMetadata(GH6830Board::class); - $schema = $schemaTool->getSchemaFromMetadata($classes); + $schemaTool = new SchemaTool($em); + $schema = $schemaTool->getSchemaFromMetadata([$category, $board]); - self::assertTrue($schema->hasTable('forum_categories')); - self::assertTrue($schema->hasTable('forum_boards')); + self::assertTrue($schema->hasTable('GH6830Category')); + self::assertTrue($schema->hasTable('GH6830Board')); - $tableCategory = $schema->getTable('forum_categories'); - $tableBoard = $schema->getTable('forum_boards'); + $tableCategory = $schema->getTable('GH6830Category'); + $tableBoard = $schema->getTable('GH6830Board'); self::assertTrue($tableBoard->hasColumn('category_id')); @@ -362,3 +362,40 @@ class SecondEntity */ public $name; } + +/** + * @Entity + */ +class GH6830Board +{ + /** + * @Id + * @Column(type="integer") + */ + public $id; + + /** + * @ManyToOne(targetEntity=GH6830Category::class, inversedBy="boards") + * @JoinColumn(name="category_id", referencedColumnName="id") + */ + public $category; +} + +/** + * @Entity + */ +class GH6830Category +{ + /** + * @Id + * @Column(type="string", length=8, options={"fixed":true, "collation":"latin1_bin", "foo":"bar"}) + * + * @var string + */ + public $id; + + /** + * @OneToMany(targetEntity=GH6830Board::class, mappedBy="category") + */ + public $boards; +} From 434820973cadf2da2d66e7184be370084cc32ca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 21 Nov 2018 00:46:33 +0100 Subject: [PATCH 744/877] Bump up version --- lib/Doctrine/ORM/Version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Version.php b/lib/Doctrine/ORM/Version.php index bf2e6e10558..0a439da4770 100644 --- a/lib/Doctrine/ORM/Version.php +++ b/lib/Doctrine/ORM/Version.php @@ -35,7 +35,7 @@ class Version /** * Current Doctrine Version */ - const VERSION = '2.6.3-DEV'; + const VERSION = '2.6.3'; /** * Compares a Doctrine version with the current one. From 505ec21f97027931600929ed7de6dc8ac7b69d29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 21 Nov 2018 01:24:06 +0100 Subject: [PATCH 745/877] Bump up development version --- lib/Doctrine/ORM/Version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Version.php b/lib/Doctrine/ORM/Version.php index 0a439da4770..a22c9690773 100644 --- a/lib/Doctrine/ORM/Version.php +++ b/lib/Doctrine/ORM/Version.php @@ -35,7 +35,7 @@ class Version /** * Current Doctrine Version */ - const VERSION = '2.6.3'; + const VERSION = '2.6.4-DEV'; /** * Compares a Doctrine version with the current one. From 2e7a3affba78275e48295472331e519e18400388 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 21 Nov 2018 09:06:54 +0100 Subject: [PATCH 746/877] Fixed a minor syntax issue --- docs/en/reference/dql-doctrine-query-language.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/dql-doctrine-query-language.rst b/docs/en/reference/dql-doctrine-query-language.rst index 36c06bf3bde..bc5097dddca 100644 --- a/docs/en/reference/dql-doctrine-query-language.rst +++ b/docs/en/reference/dql-doctrine-query-language.rst @@ -111,7 +111,7 @@ You can select scalars from any entity in the query. .. code-block:: sql - ``SELECT u, p.quantity FROM Users u...`` + SELECT u, p.quantity FROM Users u... Here, the result will again be an array of arrays, with each element being an array made up of a User object and the scalar value From 7de3434733279b62deca5be964f66636ddd294ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Ostroluck=C3=BD?= Date: Fri, 10 Aug 2018 19:17:35 +0200 Subject: [PATCH 747/877] Update doctrine/coding-standard in 2.x branch Co-Authored-By: Michael Moravec --- composer.json | 3 +- phpcs.xml.dist | 144 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 140 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 5f40e2a49d3..bda459a95ae 100644 --- a/composer.json +++ b/composer.json @@ -27,9 +27,8 @@ "symfony/console": "~3.0|~4.0" }, "require-dev": { - "doctrine/coding-standard": "^1.0", + "doctrine/coding-standard": "^5.0", "phpunit/phpunit": "^6.5", - "squizlabs/php_codesniffer": "^3.2", "symfony/yaml": "~3.4|~4.0" }, "suggest": { diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 9ffa05d316f..5aced8ad828 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -4,10 +4,10 @@ - + - - + + lib tests @@ -15,10 +15,144 @@ */tests/Doctrine/Tests/Proxies/__CG__/* - + + + + + + + + */tests/* - + + */tests/* + + + + lib/Doctrine/ORM/Events.php + lib/Doctrine/ORM/Tools/ToolEvents.php + + + + lib/Doctrine/ORM/Annotation/* + + + + lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php + + + + lib/Doctrine/ORM/Query/Parser.php + + + + lib/Doctrine/ORM/Mapping/AssociationOverride.php + lib/Doctrine/ORM/Mapping/AssociationOverrides.php + lib/Doctrine/ORM/Mapping/AttributeOverride.php + lib/Doctrine/ORM/Mapping/AttributeOverrides.php + lib/Doctrine/ORM/Mapping/Cache.php + lib/Doctrine/ORM/Mapping/ChangeTrackingPolicy.php + lib/Doctrine/ORM/Mapping/Column.php + lib/Doctrine/ORM/Mapping/ColumnResult.php + lib/Doctrine/ORM/Mapping/CustomIdGenerator.php + lib/Doctrine/ORM/Mapping/DiscriminatorColumn.php + lib/Doctrine/ORM/Mapping/DiscriminatorMap.php + lib/Doctrine/ORM/Mapping/Embeddable.php + lib/Doctrine/ORM/Mapping/Embedded.php + lib/Doctrine/ORM/Mapping/Entity.php + lib/Doctrine/ORM/Mapping/EntityListeners.php + lib/Doctrine/ORM/Mapping/EntityResult.php + lib/Doctrine/ORM/Mapping/FieldResult.php + lib/Doctrine/ORM/Mapping/GeneratedValue.php + lib/Doctrine/ORM/Mapping/HasLifecycleCallbacks.php + lib/Doctrine/ORM/Mapping/Id.php + lib/Doctrine/ORM/Mapping/Index.php + lib/Doctrine/ORM/Mapping/InheritanceType.php + lib/Doctrine/ORM/Mapping/JoinColumn.php + lib/Doctrine/ORM/Mapping/JoinColumns.php + lib/Doctrine/ORM/Mapping/JoinTable.php + lib/Doctrine/ORM/Mapping/ManyToMany.php + lib/Doctrine/ORM/Mapping/ManyToOne.php + lib/Doctrine/ORM/Mapping/MappedSuperclass.php + lib/Doctrine/ORM/Mapping/NamedNativeQueries.php + lib/Doctrine/ORM/Mapping/NamedNativeQuery.php + lib/Doctrine/ORM/Mapping/NamedQueries.php + lib/Doctrine/ORM/Mapping/NamedQuery.php + lib/Doctrine/ORM/Mapping/OneToMany.php + lib/Doctrine/ORM/Mapping/OneToOne.php + lib/Doctrine/ORM/Mapping/OrderBy.php + lib/Doctrine/ORM/Mapping/PostLoad.php + lib/Doctrine/ORM/Mapping/PostPersist.php + lib/Doctrine/ORM/Mapping/PostRemove.php + lib/Doctrine/ORM/Mapping/PostUpdate.php + lib/Doctrine/ORM/Mapping/PreFlush.php + lib/Doctrine/ORM/Mapping/PrePersist.php + lib/Doctrine/ORM/Mapping/PreRemove.php + lib/Doctrine/ORM/Mapping/PreUpdate.php + lib/Doctrine/ORM/Mapping/SequenceGenerator.php + lib/Doctrine/ORM/Mapping/SqlResultSetMapping.php + lib/Doctrine/ORM/Mapping/SqlResultSetMappings.php + lib/Doctrine/ORM/Mapping/Table.php + lib/Doctrine/ORM/Mapping/UniqueConstraint.php + lib/Doctrine/ORM/Mapping/Version.php + + + + lib/Doctrine/ORM/Cache/DefaultQueryCache.php + + + + lib/Doctrine/ORM/EntityManagerInterface.php + + + + */tests/* + + + + */tests/* + + + + */tests/* + + + + */tests/* + + + + */tests/* + + + + */tests/* + + + + + tests/Doctrine/Tests/Models/Global/GlobalNamespaceModel.php + tests/Doctrine/Tests/Models/DDC3231/DDC3231User1NoNamespace.php + tests/Doctrine/Tests/Models/DDC3231/DDC3231User2NoNamespace.php + + + + + tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2084Test.php + + + + + tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2084Test.php + + + + + tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1301Test.php + tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php + + From 6a05e01298bd60cb54275e68db979c90c16a75d2 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Wed, 14 Nov 2018 13:56:34 +0100 Subject: [PATCH 748/877] Perform incremental coding standard checks for pull requests --- .travis.yml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7730c533b5e..78d225a005b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -90,13 +90,30 @@ jobs: script: php phpbench.phar run -l dots --report=default - stage: Code Quality + if: NOT type = pull_request env: DB=none CODING_STANDARDS - php: nightly + php: 7.1 script: - ./vendor/bin/phpcs + - stage: Code Quality + if: type = pull_request + env: DB=none PULL_REQUEST_CODING_STANDARDS + php: 7.1 + script: + - | + if [ $TRAVIS_BRANCH != "master" ]; then + git remote set-branches --add origin $TRAVIS_BRANCH; + git fetch origin $TRAVIS_BRANCH; + fi + - git merge-base origin/$TRAVIS_BRANCH $TRAVIS_PULL_REQUEST_SHA || git fetch origin +refs/pull/$TRAVIS_PULL_REQUEST/merge --unshallow + - wget https://github.com/diff-sniffer/git/releases/download/0.2.0/git-phpcs.phar + - php git-phpcs.phar origin/$TRAVIS_BRANCH...$TRAVIS_PULL_REQUEST_SHA + allow_failures: - php: nightly + - stage: Code Quality + env: DB=none CODING_STANDARDS cache: directories: From 78c70009627ba9d1531d492ee2baefc94f765080 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Wed, 14 Nov 2018 13:57:44 +0100 Subject: [PATCH 749/877] Lock dependencies for Code Quality stage --- .gitignore | 1 - .travis.yml | 4 +- composer.lock | 2665 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 2668 insertions(+), 2 deletions(-) create mode 100644 composer.lock diff --git a/.gitignore b/.gitignore index eb79065bc60..81e913c4313 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,5 @@ lib/Doctrine/DBAL .idea *.iml vendor/ -composer.lock /tests/Doctrine/Performance/history.db /.phpcs-cache diff --git a/.travis.yml b/.travis.yml index 78d225a005b..4f2325b4628 100644 --- a/.travis.yml +++ b/.travis.yml @@ -77,7 +77,7 @@ jobs: - stage: Code Quality env: DB=none STATIC_ANALYSIS - install: travis_retry composer update --prefer-dist --prefer-stable + install: travis_retry composer install --prefer-dist before_script: - echo "extension=memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - echo "extension=redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini @@ -93,6 +93,7 @@ jobs: if: NOT type = pull_request env: DB=none CODING_STANDARDS php: 7.1 + install: travis_retry composer install --prefer-dist script: - ./vendor/bin/phpcs @@ -100,6 +101,7 @@ jobs: if: type = pull_request env: DB=none PULL_REQUEST_CODING_STANDARDS php: 7.1 + install: travis_retry composer install --prefer-dist script: - | if [ $TRAVIS_BRANCH != "master" ]; then diff --git a/composer.lock b/composer.lock new file mode 100644 index 00000000000..aab505fbf9e --- /dev/null +++ b/composer.lock @@ -0,0 +1,2665 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "content-hash": "66a815cf9127439df18f45e7b074c384", + "packages": [ + { + "name": "doctrine/annotations", + "version": "v1.6.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/annotations.git", + "reference": "c7f2050c68a9ab0bdb0f98567ec08d80ea7d24d5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/c7f2050c68a9ab0bdb0f98567ec08d80ea7d24d5", + "reference": "c7f2050c68a9ab0bdb0f98567ec08d80ea7d24d5", + "shasum": "" + }, + "require": { + "doctrine/lexer": "1.*", + "php": "^7.1" + }, + "require-dev": { + "doctrine/cache": "1.*", + "phpunit/phpunit": "^6.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.6.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\Annotations\\": "lib/Doctrine/Common/Annotations" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Docblock Annotations Parser", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "annotations", + "docblock", + "parser" + ], + "time": "2017-12-06T07:11:42+00:00" + }, + { + "name": "doctrine/cache", + "version": "v1.8.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/cache.git", + "reference": "d768d58baee9a4862ca783840eca1b9add7a7f57" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/cache/zipball/d768d58baee9a4862ca783840eca1b9add7a7f57", + "reference": "d768d58baee9a4862ca783840eca1b9add7a7f57", + "shasum": "" + }, + "require": { + "php": "~7.1" + }, + "conflict": { + "doctrine/common": ">2.2,<2.4" + }, + "require-dev": { + "alcaeus/mongo-php-adapter": "^1.1", + "doctrine/coding-standard": "^4.0", + "mongodb/mongodb": "^1.1", + "phpunit/phpunit": "^7.0", + "predis/predis": "~1.0" + }, + "suggest": { + "alcaeus/mongo-php-adapter": "Required to use legacy MongoDB driver" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.8.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\Cache\\": "lib/Doctrine/Common/Cache" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Caching library offering an object-oriented API for many cache backends", + "homepage": "https://www.doctrine-project.org", + "keywords": [ + "cache", + "caching" + ], + "time": "2018-08-21T18:01:43+00:00" + }, + { + "name": "doctrine/collections", + "version": "v1.5.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/collections.git", + "reference": "a01ee38fcd999f34d9bfbcee59dbda5105449cbf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/collections/zipball/a01ee38fcd999f34d9bfbcee59dbda5105449cbf", + "reference": "a01ee38fcd999f34d9bfbcee59dbda5105449cbf", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "doctrine/coding-standard": "~0.1@dev", + "phpunit/phpunit": "^5.7" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Collections\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Collections Abstraction library", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "array", + "collections", + "iterator" + ], + "time": "2017-07-22T10:37:32+00:00" + }, + { + "name": "doctrine/common", + "version": "v2.9.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/common.git", + "reference": "a210246d286c77d2b89040f8691ba7b3a713d2c1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/common/zipball/a210246d286c77d2b89040f8691ba7b3a713d2c1", + "reference": "a210246d286c77d2b89040f8691ba7b3a713d2c1", + "shasum": "" + }, + "require": { + "doctrine/annotations": "^1.0", + "doctrine/cache": "^1.0", + "doctrine/collections": "^1.0", + "doctrine/event-manager": "^1.0", + "doctrine/inflector": "^1.0", + "doctrine/lexer": "^1.0", + "doctrine/persistence": "^1.0", + "doctrine/reflection": "^1.0", + "php": "^7.1" + }, + "require-dev": { + "doctrine/coding-standard": "^1.0", + "phpunit/phpunit": "^6.3", + "squizlabs/php_codesniffer": "^3.0", + "symfony/phpunit-bridge": "^4.0.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.9.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\": "lib/Doctrine/Common" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + }, + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com" + } + ], + "description": "Common Library for Doctrine projects", + "homepage": "https://www.doctrine-project.org", + "keywords": [ + "annotations", + "collections", + "eventmanager", + "persistence", + "spl" + ], + "time": "2018-07-12T21:16:12+00:00" + }, + { + "name": "doctrine/dbal", + "version": "v2.8.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/dbal.git", + "reference": "5140a64c08b4b607b9bedaae0cedd26f04a0e621" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/5140a64c08b4b607b9bedaae0cedd26f04a0e621", + "reference": "5140a64c08b4b607b9bedaae0cedd26f04a0e621", + "shasum": "" + }, + "require": { + "doctrine/cache": "^1.0", + "doctrine/event-manager": "^1.0", + "ext-pdo": "*", + "php": "^7.1" + }, + "require-dev": { + "doctrine/coding-standard": "^4.0", + "jetbrains/phpstorm-stubs": "^2018.1.2", + "phpstan/phpstan": "^0.10.1", + "phpunit/phpunit": "^7.1.2", + "phpunit/phpunit-mock-objects": "!=3.2.4,!=3.2.5", + "symfony/console": "^2.0.5|^3.0|^4.0", + "symfony/phpunit-bridge": "^3.4.5|^4.0.5" + }, + "suggest": { + "symfony/console": "For helpful console commands such as SQL execution and import of files." + }, + "bin": [ + "bin/doctrine-dbal" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.8.x-dev", + "dev-develop": "3.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\DBAL\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + } + ], + "description": "Database Abstraction Layer", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "database", + "dbal", + "persistence", + "queryobject" + ], + "time": "2018-07-13T03:16:35+00:00" + }, + { + "name": "doctrine/event-manager", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/event-manager.git", + "reference": "a520bc093a0170feeb6b14e9d83f3a14452e64b3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/event-manager/zipball/a520bc093a0170feeb6b14e9d83f3a14452e64b3", + "reference": "a520bc093a0170feeb6b14e9d83f3a14452e64b3", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "conflict": { + "doctrine/common": "<2.9@dev" + }, + "require-dev": { + "doctrine/coding-standard": "^4.0", + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\": "lib/Doctrine/Common" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + }, + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com" + } + ], + "description": "Doctrine Event Manager component", + "homepage": "https://www.doctrine-project.org/projects/event-manager.html", + "keywords": [ + "event", + "eventdispatcher", + "eventmanager" + ], + "time": "2018-06-11T11:59:03+00:00" + }, + { + "name": "doctrine/inflector", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/inflector.git", + "reference": "5527a48b7313d15261292c149e55e26eae771b0a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/inflector/zipball/5527a48b7313d15261292c149e55e26eae771b0a", + "reference": "5527a48b7313d15261292c149e55e26eae771b0a", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^6.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\Inflector\\": "lib/Doctrine/Common/Inflector" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Common String Manipulations with regard to casing and singular/plural rules.", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "inflection", + "pluralize", + "singularize", + "string" + ], + "time": "2018-01-09T20:05:19+00:00" + }, + { + "name": "doctrine/instantiator", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda", + "reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "ext-pdo": "*", + "ext-phar": "*", + "phpunit/phpunit": "^6.2.3", + "squizlabs/php_codesniffer": "^3.0.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://github.com/doctrine/instantiator", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2017-07-22T11:58:36+00:00" + }, + { + "name": "doctrine/lexer", + "version": "v1.0.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/lexer.git", + "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/lexer/zipball/83893c552fd2045dd78aef794c31e694c37c0b8c", + "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Lexer\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "lexer", + "parser" + ], + "time": "2014-09-09T13:34:57+00:00" + }, + { + "name": "doctrine/persistence", + "version": "v1.0.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/persistence.git", + "reference": "af1ec238659a83e320f03e0e454e200f689b4b97" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/persistence/zipball/af1ec238659a83e320f03e0e454e200f689b4b97", + "reference": "af1ec238659a83e320f03e0e454e200f689b4b97", + "shasum": "" + }, + "require": { + "doctrine/annotations": "^1.0", + "doctrine/cache": "^1.0", + "doctrine/collections": "^1.0", + "doctrine/event-manager": "^1.0", + "doctrine/reflection": "^1.0", + "php": "^7.1" + }, + "conflict": { + "doctrine/common": "<2.9@dev" + }, + "require-dev": { + "doctrine/coding-standard": "^4.0", + "phpstan/phpstan": "^0.8", + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\": "lib/Doctrine/Common" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + }, + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com" + } + ], + "description": "Doctrine Persistence abstractions.", + "homepage": "https://doctrine-project.org/projects/persistence.html", + "keywords": [ + "persistence" + ], + "time": "2018-07-12T12:37:50+00:00" + }, + { + "name": "doctrine/reflection", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/reflection.git", + "reference": "02538d3f95e88eb397a5f86274deb2c6175c2ab6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/reflection/zipball/02538d3f95e88eb397a5f86274deb2c6175c2ab6", + "reference": "02538d3f95e88eb397a5f86274deb2c6175c2ab6", + "shasum": "" + }, + "require": { + "doctrine/annotations": "^1.0", + "ext-tokenizer": "*", + "php": "^7.1" + }, + "require-dev": { + "doctrine/coding-standard": "^4.0", + "doctrine/common": "^2.8", + "phpstan/phpstan": "^0.9.2", + "phpstan/phpstan-phpunit": "^0.9.4", + "phpunit/phpunit": "^7.0", + "squizlabs/php_codesniffer": "^3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\": "lib/Doctrine/Common" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + }, + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com" + } + ], + "description": "Doctrine Reflection component", + "homepage": "https://www.doctrine-project.org/projects/reflection.html", + "keywords": [ + "reflection" + ], + "time": "2018-06-14T14:45:07+00:00" + }, + { + "name": "symfony/console", + "version": "v4.1.7", + "source": { + "type": "git", + "url": "https://github.com/symfony/console.git", + "reference": "432122af37d8cd52fba1b294b11976e0d20df595" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/console/zipball/432122af37d8cd52fba1b294b11976e0d20df595", + "reference": "432122af37d8cd52fba1b294b11976e0d20df595", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/dependency-injection": "<3.4", + "symfony/process": "<3.3" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~3.4|~4.0", + "symfony/dependency-injection": "~3.4|~4.0", + "symfony/event-dispatcher": "~3.4|~4.0", + "symfony/lock": "~3.4|~4.0", + "symfony/process": "~3.4|~4.0" + }, + "suggest": { + "psr/log-implementation": "For using the console logger", + "symfony/event-dispatcher": "", + "symfony/lock": "", + "symfony/process": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Console\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Console Component", + "homepage": "https://symfony.com", + "time": "2018-10-31T09:30:44+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.10.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "c79c051f5b3a46be09205c73b80b346e4153e494" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/c79c051f5b3a46be09205c73b80b346e4153e494", + "reference": "c79c051f5b3a46be09205c73b80b346e4153e494", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.9-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2018-09-21T13:07:52+00:00" + } + ], + "packages-dev": [ + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v0.4.4", + "source": { + "type": "git", + "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", + "reference": "2e41850d5f7797cbb1af7b030d245b3b24e63a08" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/2e41850d5f7797cbb1af7b030d245b3b24e63a08", + "reference": "2e41850d5f7797cbb1af7b030d245b3b24e63a08", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0", + "php": "^5.3|^7", + "squizlabs/php_codesniffer": "*" + }, + "require-dev": { + "composer/composer": "*", + "wimg/php-compatibility": "^8.0" + }, + "suggest": { + "dealerdirect/qa-tools": "All the PHP QA tools you'll need" + }, + "type": "composer-plugin", + "extra": { + "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "f.nijhof@dealerdirect.nl", + "homepage": "http://workingatdealerdirect.eu", + "role": "Developer" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://workingatdealerdirect.eu", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "time": "2017-12-06T16:27:17+00:00" + }, + { + "name": "doctrine/coding-standard", + "version": "5.0.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/coding-standard.git", + "reference": "bb8de042a25c4fb59a2c55c350dc55cc00227a8c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/coding-standard/zipball/bb8de042a25c4fb59a2c55c350dc55cc00227a8c", + "reference": "bb8de042a25c4fb59a2c55c350dc55cc00227a8c", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4", + "php": "^7.1", + "slevomat/coding-standard": "^4.8.0", + "squizlabs/php_codesniffer": "^3.3.2" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-master": "5.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Sniffs\\": "lib/Doctrine/Sniffs" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Steve Müller", + "email": "st.mueller@dzh-online.de" + } + ], + "description": "The Doctrine Coding Standard is a set of PHPCS rules applied to all Doctrine projects.", + "homepage": "https://www.doctrine-project.org/projects/coding-standard.html", + "keywords": [ + "checks", + "code", + "coding", + "cs", + "doctrine", + "rules", + "sniffer", + "sniffs", + "standard", + "style" + ], + "time": "2018-09-24T19:08:56+00:00" + }, + { + "name": "myclabs/deep-copy", + "version": "1.8.1", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", + "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "replace": { + "myclabs/deep-copy": "self.version" + }, + "require-dev": { + "doctrine/collections": "^1.0", + "doctrine/common": "^2.6", + "phpunit/phpunit": "^7.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + }, + "files": [ + "src/DeepCopy/deep_copy.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "time": "2018-06-11T23:09:50+00:00" + }, + { + "name": "phar-io/manifest", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/manifest.git", + "reference": "2df402786ab5368a0169091f61a7c1e0eb6852d0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/2df402786ab5368a0169091f61a7c1e0eb6852d0", + "reference": "2df402786ab5368a0169091f61a7c1e0eb6852d0", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-phar": "*", + "phar-io/version": "^1.0.1", + "php": "^5.6 || ^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "time": "2017-03-05T18:14:27+00:00" + }, + { + "name": "phar-io/version", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/version.git", + "reference": "a70c0ced4be299a63d32fa96d9281d03e94041df" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/version/zipball/a70c0ced4be299a63d32fa96d9281d03e94041df", + "reference": "a70c0ced4be299a63d32fa96d9281d03e94041df", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Library for handling version information and constraints", + "time": "2017-03-05T17:38:23+00:00" + }, + { + "name": "phpdocumentor/reflection-common", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "^4.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "time": "2017-09-11T18:02:19+00:00" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "4.3.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "94fd0001232e47129dd3504189fa1c7225010d08" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/94fd0001232e47129dd3504189fa1c7225010d08", + "reference": "94fd0001232e47129dd3504189fa1c7225010d08", + "shasum": "" + }, + "require": { + "php": "^7.0", + "phpdocumentor/reflection-common": "^1.0.0", + "phpdocumentor/type-resolver": "^0.4.0", + "webmozart/assert": "^1.0" + }, + "require-dev": { + "doctrine/instantiator": "~1.0.5", + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^6.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "time": "2017-11-30T07:14:17+00:00" + }, + { + "name": "phpdocumentor/type-resolver", + "version": "0.4.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7", + "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7", + "shasum": "" + }, + "require": { + "php": "^5.5 || ^7.0", + "phpdocumentor/reflection-common": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^5.2||^4.8.24" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "time": "2017-07-14T14:27:02+00:00" + }, + { + "name": "phpspec/prophecy", + "version": "1.8.0", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": "^5.3|^7.0", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", + "sebastian/comparator": "^1.1|^2.0|^3.0", + "sebastian/recursion-context": "^1.0|^2.0|^3.0" + }, + "require-dev": { + "phpspec/phpspec": "^2.5|^3.2", + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.8.x-dev" + } + }, + "autoload": { + "psr-0": { + "Prophecy\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "email": "marcello.duarte@gmail.com" + } + ], + "description": "Highly opinionated mocking framework for PHP 5.3+", + "homepage": "https://github.com/phpspec/prophecy", + "keywords": [ + "Double", + "Dummy", + "fake", + "mock", + "spy", + "stub" + ], + "time": "2018-08-05T17:53:17+00:00" + }, + { + "name": "phpunit/php-code-coverage", + "version": "5.3.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "c89677919c5dd6d3b3852f230a663118762218ac" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/c89677919c5dd6d3b3852f230a663118762218ac", + "reference": "c89677919c5dd6d3b3852f230a663118762218ac", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-xmlwriter": "*", + "php": "^7.0", + "phpunit/php-file-iterator": "^1.4.2", + "phpunit/php-text-template": "^1.2.1", + "phpunit/php-token-stream": "^2.0.1", + "sebastian/code-unit-reverse-lookup": "^1.0.1", + "sebastian/environment": "^3.0", + "sebastian/version": "^2.0.1", + "theseer/tokenizer": "^1.1" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "suggest": { + "ext-xdebug": "^2.5.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2018-04-06T15:36:58+00:00" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.4.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/730b01bc3e867237eaac355e06a36b85dd93a8b4", + "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2017-11-27T13:52:08+00:00" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2015-06-21T13:50:34+00:00" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.9", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2017-02-26T11:10:40+00:00" + }, + { + "name": "phpunit/php-token-stream", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "791198a2c6254db10131eecfe8c06670700904db" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/791198a2c6254db10131eecfe8c06670700904db", + "reference": "791198a2c6254db10131eecfe8c06670700904db", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.2.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2017-11-27T05:48:46+00:00" + }, + { + "name": "phpunit/phpunit", + "version": "6.5.13", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "0973426fb012359b2f18d3bd1e90ef1172839693" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/0973426fb012359b2f18d3bd1e90ef1172839693", + "reference": "0973426fb012359b2f18d3bd1e90ef1172839693", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "myclabs/deep-copy": "^1.6.1", + "phar-io/manifest": "^1.0.1", + "phar-io/version": "^1.0", + "php": "^7.0", + "phpspec/prophecy": "^1.7", + "phpunit/php-code-coverage": "^5.3", + "phpunit/php-file-iterator": "^1.4.3", + "phpunit/php-text-template": "^1.2.1", + "phpunit/php-timer": "^1.0.9", + "phpunit/phpunit-mock-objects": "^5.0.9", + "sebastian/comparator": "^2.1", + "sebastian/diff": "^2.0", + "sebastian/environment": "^3.1", + "sebastian/exporter": "^3.1", + "sebastian/global-state": "^2.0", + "sebastian/object-enumerator": "^3.0.3", + "sebastian/resource-operations": "^1.0", + "sebastian/version": "^2.0.1" + }, + "conflict": { + "phpdocumentor/reflection-docblock": "3.0.2", + "phpunit/dbunit": "<3.0" + }, + "require-dev": { + "ext-pdo": "*" + }, + "suggest": { + "ext-xdebug": "*", + "phpunit/php-invoker": "^1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.5.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2018-09-08T15:10:43+00:00" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "5.0.10", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "cd1cf05c553ecfec36b170070573e540b67d3f1f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/cd1cf05c553ecfec36b170070573e540b67d3f1f", + "reference": "cd1cf05c553ecfec36b170070573e540b67d3f1f", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.5", + "php": "^7.0", + "phpunit/php-text-template": "^1.2.1", + "sebastian/exporter": "^3.1" + }, + "conflict": { + "phpunit/phpunit": "<6.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.5.11" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "time": "2018-08-09T05:50:03+00:00" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "time": "2017-03-04T06:30:41+00:00" + }, + { + "name": "sebastian/comparator", + "version": "2.1.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "34369daee48eafb2651bea869b4b15d75ccc35f9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/34369daee48eafb2651bea869b4b15d75ccc35f9", + "reference": "34369daee48eafb2651bea869b4b15d75ccc35f9", + "shasum": "" + }, + "require": { + "php": "^7.0", + "sebastian/diff": "^2.0 || ^3.0", + "sebastian/exporter": "^3.1" + }, + "require-dev": { + "phpunit/phpunit": "^6.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "https://github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2018-02-01T13:46:46+00:00" + }, + { + "name": "sebastian/diff", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "347c1d8b49c5c3ee30c7040ea6fc446790e6bddd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/347c1d8b49c5c3ee30c7040ea6fc446790e6bddd", + "reference": "347c1d8b49c5c3ee30c7040ea6fc446790e6bddd", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2017-08-03T08:09:46+00:00" + }, + { + "name": "sebastian/environment", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "cd0871b3975fb7fc44d11314fd1ee20925fce4f5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/cd0871b3975fb7fc44d11314fd1ee20925fce4f5", + "reference": "cd0871b3975fb7fc44d11314fd1ee20925fce4f5", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2017-07-01T08:51:00+00:00" + }, + { + "name": "sebastian/exporter", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "234199f4528de6d12aaa58b612e98f7d36adb937" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/234199f4528de6d12aaa58b612e98f7d36adb937", + "reference": "234199f4528de6d12aaa58b612e98f7d36adb937", + "shasum": "" + }, + "require": { + "php": "^7.0", + "sebastian/recursion-context": "^3.0" + }, + "require-dev": { + "ext-mbstring": "*", + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2017-04-03T13:19:02+00:00" + }, + { + "name": "sebastian/global-state", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", + "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "time": "2017-04-27T15:39:26+00:00" + }, + { + "name": "sebastian/object-enumerator", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/7cfd9e65d11ffb5af41198476395774d4c8a84c5", + "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5", + "shasum": "" + }, + "require": { + "php": "^7.0", + "sebastian/object-reflector": "^1.1.1", + "sebastian/recursion-context": "^3.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "time": "2017-08-03T12:35:26+00:00" + }, + { + "name": "sebastian/object-reflector", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-reflector.git", + "reference": "773f97c67f28de00d397be301821b06708fca0be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/773f97c67f28de00d397be301821b06708fca0be", + "reference": "773f97c67f28de00d397be301821b06708fca0be", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Allows reflection of object attributes, including inherited and non-public ones", + "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "time": "2017-03-29T09:07:27+00:00" + }, + { + "name": "sebastian/recursion-context", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", + "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2017-03-03T06:23:57+00:00" + }, + { + "name": "sebastian/resource-operations", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/resource-operations.git", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "shasum": "" + }, + "require": { + "php": ">=5.6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides a list of PHP built-in functions that operate on resources", + "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "time": "2015-07-28T20:34:47+00:00" + }, + { + "name": "sebastian/version", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2016-10-03T07:35:21+00:00" + }, + { + "name": "slevomat/coding-standard", + "version": "4.8.6", + "source": { + "type": "git", + "url": "https://github.com/slevomat/coding-standard.git", + "reference": "af0c0c99e84106525484ef25f15144b9831522bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/af0c0c99e84106525484ef25f15144b9831522bb", + "reference": "af0c0c99e84106525484ef25f15144b9831522bb", + "shasum": "" + }, + "require": { + "php": "^7.1", + "squizlabs/php_codesniffer": "^3.3.1" + }, + "require-dev": { + "jakub-onderka/php-parallel-lint": "1.0.0", + "phing/phing": "2.16.1", + "phpstan/phpstan": "0.9.2", + "phpstan/phpstan-phpunit": "0.9.4", + "phpstan/phpstan-strict-rules": "0.9", + "phpunit/phpunit": "7.3.5" + }, + "type": "phpcodesniffer-standard", + "autoload": { + "psr-4": { + "SlevomatCodingStandard\\": "SlevomatCodingStandard" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", + "time": "2018-11-03T21:28:29+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.3.2", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "6ad28354c04b364c3c71a34e4a18b629cc3b231e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/6ad28354c04b364c3c71a34e4a18b629cc3b231e", + "reference": "6ad28354c04b364c3c71a34e4a18b629cc3b231e", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "http://www.squizlabs.com/php-codesniffer", + "keywords": [ + "phpcs", + "standards" + ], + "time": "2018-09-23T23:08:17+00:00" + }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.10.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "e3d826245268269cd66f8326bd8bc066687b4a19" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e3d826245268269cd66f8326bd8bc066687b4a19", + "reference": "e3d826245268269cd66f8326bd8bc066687b4a19", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.9-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + }, + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "time": "2018-08-06T14:22:27+00:00" + }, + { + "name": "symfony/yaml", + "version": "v4.1.7", + "source": { + "type": "git", + "url": "https://github.com/symfony/yaml.git", + "reference": "367e689b2fdc19965be435337b50bc8adf2746c9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/yaml/zipball/367e689b2fdc19965be435337b50bc8adf2746c9", + "reference": "367e689b2fdc19965be435337b50bc8adf2746c9", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "symfony/polyfill-ctype": "~1.8" + }, + "conflict": { + "symfony/console": "<3.4" + }, + "require-dev": { + "symfony/console": "~3.4|~4.0" + }, + "suggest": { + "symfony/console": "For validating YAML files using the lint command" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Yaml Component", + "homepage": "https://symfony.com", + "time": "2018-10-02T16:36:10+00:00" + }, + { + "name": "theseer/tokenizer", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/theseer/tokenizer.git", + "reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/cb2f008f3f05af2893a87208fe6a6c4985483f8b", + "reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": "^7.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + } + ], + "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "time": "2017-04-07T12:08:54+00:00" + }, + { + "name": "webmozart/assert", + "version": "1.3.0", + "source": { + "type": "git", + "url": "https://github.com/webmozart/assert.git", + "reference": "0df1908962e7a3071564e857d86874dad1ef204a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozart/assert/zipball/0df1908962e7a3071564e857d86874dad1ef204a", + "reference": "0df1908962e7a3071564e857d86874dad1ef204a", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.6", + "sebastian/version": "^1.0.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "time": "2018-01-29T19:49:41+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": "^7.1", + "ext-pdo": "*" + }, + "platform-dev": [] +} From ee64d31f489e98286656949c80dc98fb0cc391c9 Mon Sep 17 00:00:00 2001 From: Konstantin Litvinov Date: Wed, 12 Dec 2018 14:59:12 +0300 Subject: [PATCH 750/877] 7518 Fixed PHPDoc Error. --- lib/Doctrine/ORM/EntityRepository.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index 33d7e65c0ab..8a7c8143337 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -57,9 +57,6 @@ class EntityRepository implements ObjectRepository, Selectable /** * Initializes a new EntityRepository. - * - * @param EntityManager $em The EntityManager to use. - * @param Mapping\ClassMetadata $class The class descriptor. */ public function __construct(EntityManagerInterface $em, Mapping\ClassMetadata $class) { From fc3dca772e72f2e3b9c0fa2c9e66e68543797540 Mon Sep 17 00:00:00 2001 From: "Jonathan H. Wage" Date: Wed, 12 Dec 2018 14:05:15 -0600 Subject: [PATCH 751/877] Merge pull request #7521 from doctrine/update-chat-link Update chat link from Gitter to Slack. --- docs/en/index.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/en/index.rst b/docs/en/index.rst index 8e6afc82592..1863da705d1 100644 --- a/docs/en/index.rst +++ b/docs/en/index.rst @@ -13,9 +13,9 @@ If this documentation is not helping to answer questions you have about Doctrine ORM don't panic. You can get help from different sources: - There is a :doc:`FAQ ` with answers to frequent questions. -- The `Doctrine Mailing List `_ -- Internet Relay Chat (IRC) in #doctrine on Freenode -- Report a bug on `JIRA `_. +- The `Doctrine Mailing List `_ +- Slack chat room `#orm `_ +- Report a bug on `GitHub `_. - On `Twitter `_ with ``#doctrine2`` - On `StackOverflow `_ @@ -72,9 +72,9 @@ Advanced Topics * :doc:`Transactions and Concurrency ` * :doc:`Filters ` * :doc:`NamingStrategy ` -* :doc:`Improving Performance ` -* :doc:`Caching ` -* :doc:`Partial Objects ` +* :doc:`Improving Performance ` +* :doc:`Caching ` +* :doc:`Partial Objects ` * :doc:`Change Tracking Policies ` * :doc:`Best Practices ` * :doc:`Metadata Drivers ` @@ -103,7 +103,7 @@ Cookbook * **Patterns**: :doc:`Aggregate Fields ` | :doc:`Decorator Pattern ` | - :doc:`Strategy Pattern ` + :doc:`Strategy Pattern ` * **DQL Extension Points**: :doc:`DQL Custom Walkers ` | From 960a437d46e6bc0df5049da0ae5e9a9f5d067516 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 16 Dec 2018 15:37:45 +0100 Subject: [PATCH 752/877] #7527 failing test case: `UnitOfWork#getSingleIdentifierValue()` should not be called for a well specified parameter type As previously reported by @flaushi in https://github.com/doctrine/doctrine2/pull/7471#discussion_r241949045, we discovered that binding a parameter causes a `ClassMetadataFactory#getClassMetadata()` call, which in turn leads to large performance regression when using any `object` type as parameter. Following two snippets lead to an internal `ClassMetadataFactory#getClassMetadata()` call, which in turn leads to an exception being thrown and garbage collected, plus multiple associated performance implications: ```php $query->setParameter('foo', new DateTime()); $query->getResult(); ``` ```php $query->setParameter('foo', new DateTime(), DateTimeType::NAME); $query->getResult(); ``` This is due to following portion of code: https://github.com/doctrine/doctrine2/blob/434820973cadf2da2d66e7184be370084cc32ca8/lib/Doctrine/ORM/Query.php#L406-L409 Notice how `$value = $this->processParameterValue($value);` happens before attempting to infer the type for the parameter value. That call leads to this segment being reached, which leads to the regression: https://github.com/doctrine/doctrine2/blob/434820973cadf2da2d66e7184be370084cc32ca8/lib/Doctrine/ORM/AbstractQuery.php#L423-L433 Assuming the bound parameter type is provided, we can completely skip attempting to introspect the given object: ```php $query->setParameter('foo', new DateTime(), DateTimeType::NAME); $query->getResult(); ``` Processing the parameter value is not needed in this case, so we can safely skip that logic for all known parameters. In order to not introduce a BC break or change the `AbstractQuery#processParameterValue()` implementation, we could filter out all parameters for which the type is given upfront, and later on merge them back in instead. The test expectation to be set is for `UnitOfWork#getSingleIdentifierValue()` to never be called. --- tests/Doctrine/Tests/ORM/Query/QueryTest.php | 30 ++++++++++++++++---- tests/Doctrine/Tests/OrmTestCase.php | 7 ++--- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Query/QueryTest.php b/tests/Doctrine/Tests/ORM/Query/QueryTest.php index 8a3caf66f05..0045647a09a 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryTest.php @@ -2,24 +2,26 @@ namespace Doctrine\Tests\ORM\Query; +use DateTime; use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\Collections\ArrayCollection; - -use Doctrine\DBAL\Cache\QueryCacheProfile; -use Doctrine\ORM\EntityManager; +use Doctrine\DBAL\Types\Type; use Doctrine\ORM\Internal\Hydration\IterableResult; use Doctrine\ORM\Query\Parameter; use Doctrine\ORM\Query\QueryException; +use Doctrine\ORM\UnitOfWork; use Doctrine\Tests\Mocks\DriverConnectionMock; +use Doctrine\Tests\Mocks\EntityManagerMock; use Doctrine\Tests\Mocks\StatementArrayMock; use Doctrine\Tests\Models\CMS\CmsAddress; use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\Models\Generic\DateTimeModel; use Doctrine\Tests\OrmTestCase; class QueryTest extends OrmTestCase { - /** @var EntityManager */ - protected $_em = null; + /** @var EntityManagerMock */ + protected $_em; protected function setUp() { @@ -400,4 +402,22 @@ public function testResultCacheProfileCanBeRemovedViaSetter() : void self::assertAttributeSame(null, '_queryCacheProfile', $query); } + + /** @group 7527 */ + public function testValuesAreNotBeingResolvedForSpecifiedParameterTypes() : void + { + $unitOfWork = $this->createMock(UnitOfWork::class); + + $this->_em->setUnitOfWork($unitOfWork); + + $unitOfWork + ->expects(self::never()) + ->method('getSingleIdentifierValue'); + + $query = $this->_em->createQuery('SELECT d FROM ' . DateTimeModel::class . ' d WHERE d.datetime = :value'); + + $query->setParameter('value', new DateTime(), Type::DATETIME); + + self::assertEmpty($query->getResult()); + } } diff --git a/tests/Doctrine/Tests/OrmTestCase.php b/tests/Doctrine/Tests/OrmTestCase.php index 46e8ea143ee..6fdbe147110 100644 --- a/tests/Doctrine/Tests/OrmTestCase.php +++ b/tests/Doctrine/Tests/OrmTestCase.php @@ -11,6 +11,7 @@ use Doctrine\ORM\Configuration; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\Tests\Mocks; +use Doctrine\Tests\Mocks\EntityManagerMock; /** * Base testcase class for all ORM testcases. @@ -113,10 +114,8 @@ protected function createAnnotationDriver($paths = [], $alias = null) * @param mixed $conf * @param \Doctrine\Common\EventManager|null $eventManager * @param bool $withSharedMetadata - * - * @return \Doctrine\ORM\EntityManager */ - protected function _getTestEntityManager($conn = null, $conf = null, $eventManager = null, $withSharedMetadata = true) + protected function _getTestEntityManager($conn = null, $conf = null, $eventManager = null, $withSharedMetadata = true) : EntityManagerMock { $metadataCache = $withSharedMetadata ? self::getSharedMetadataCacheImpl() @@ -160,7 +159,7 @@ protected function _getTestEntityManager($conn = null, $conf = null, $eventManag $conn = DriverManager::getConnection($conn, $config, $eventManager); } - return Mocks\EntityManagerMock::create($conn, $config, $eventManager); + return EntityManagerMock::create($conn, $config, $eventManager); } protected function enableSecondLevelCache($log = true) From 23af164d7aae5e2ed31b5b93172af74b43f5551b Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sun, 16 Dec 2018 16:20:26 +0100 Subject: [PATCH 753/877] Note: this will still lead to the `UnitOfWork#getSingleIdentifierValue()` still being called when not specifying the type of a DQL parameter being bound via `Doctrine\ORM\Query#setParameter()`: ```php $query->setParameter('foo', $theValue, $theType); ``` A full parameter bind is required in order to gain back performance: ```php $query->setParameter('foo', $theValue, $theType); ``` This is up for discussion with patch reviewers. --- lib/Doctrine/ORM/AbstractQuery.php | 6 +- lib/Doctrine/ORM/Query.php | 58 +++++++++++++------ lib/Doctrine/ORM/Query/Parameter.php | 17 +++++- tests/Doctrine/Tests/ORM/QueryBuilderTest.php | 5 +- 4 files changed, 63 insertions(+), 23 deletions(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 25a284ceb4c..0003c5d3ff5 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -72,7 +72,7 @@ abstract class AbstractQuery /** * The parameter map of this query. * - * @var \Doctrine\Common\Collections\ArrayCollection + * @var ArrayCollection|Parameter[] */ protected $parameters; @@ -306,7 +306,7 @@ public function free() /** * Get all defined parameters. * - * @return \Doctrine\Common\Collections\ArrayCollection The defined query parameters. + * @return ArrayCollection The defined query parameters. */ public function getParameters() { @@ -336,7 +336,7 @@ function (Query\Parameter $parameter) use ($key) : bool { /** * Sets a collection of query parameters. * - * @param \Doctrine\Common\Collections\ArrayCollection|array $parameters + * @param ArrayCollection|mixed[] $parameters * * @return static This query instance. */ diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 525aa7a5081..2bc480a9b07 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -19,15 +19,18 @@ namespace Doctrine\ORM; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\DBAL\LockMode; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Query\Exec\AbstractSqlExecutor; +use Doctrine\ORM\Query\Parameter; +use Doctrine\ORM\Query\ParameterTypeInferer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\ParserResult; use Doctrine\ORM\Query\QueryException; -use Doctrine\ORM\Mapping\ClassMetadata; -use Doctrine\ORM\Query\ParameterTypeInferer; -use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Utility\HierarchyDiscriminatorResolver; +use function array_keys; +use function assert; /** * A Query object represents a DQL query. @@ -387,26 +390,13 @@ private function processParameterMappings($paramMappings) $types = []; foreach ($this->parameters as $parameter) { - $key = $parameter->getName(); - $value = $parameter->getValue(); - $rsm = $this->getResultSetMapping(); + $key = $parameter->getName(); if ( ! isset($paramMappings[$key])) { throw QueryException::unknownParameter($key); } - if (isset($rsm->metadataParameterMapping[$key]) && $value instanceof ClassMetadata) { - $value = $value->getMetadataValue($rsm->metadataParameterMapping[$key]); - } - - if (isset($rsm->discriminatorParameters[$key]) && $value instanceof ClassMetadata) { - $value = array_keys(HierarchyDiscriminatorResolver::resolveDiscriminatorsForClass($value, $this->_em)); - } - - $value = $this->processParameterValue($value); - $type = ($parameter->getValue() === $value) - ? $parameter->getType() - : ParameterTypeInferer::inferType($value); + [$value, $type] = $this->resolveParameterValue($parameter); foreach ($paramMappings[$key] as $position) { $types[$position] = $type; @@ -439,6 +429,38 @@ private function processParameterMappings($paramMappings) return [$sqlParams, $types]; } + /** @return mixed[] tuple of (value, type) */ + private function resolveParameterValue(Parameter $parameter) : array + { + if ($parameter->typeWasSpecified()) { + return [$parameter->getValue(), $parameter->getType()]; + } + + $key = $parameter->getName(); + $originalValue = $parameter->getValue(); + $value = $originalValue; + $rsm = $this->getResultSetMapping(); + + assert($rsm !== null); + + if ($value instanceof ClassMetadata && isset($rsm->metadataParameterMapping[$key])) { + $value = $value->getMetadataValue($rsm->metadataParameterMapping[$key]); + } + + if ($value instanceof ClassMetadata && isset($rsm->discriminatorParameters[$key])) { + $value = array_keys(HierarchyDiscriminatorResolver::resolveDiscriminatorsForClass($value, $this->_em)); + } + + $processedValue = $this->processParameterValue($value); + + return [ + $processedValue, + $originalValue === $processedValue + ? $parameter->getType() + : ParameterTypeInferer::inferType($processedValue), + ]; + } + /** * Defines a cache driver to be used for caching queries. * diff --git a/lib/Doctrine/ORM/Query/Parameter.php b/lib/Doctrine/ORM/Query/Parameter.php index 39e2a7a4f21..6e968a1a9a7 100644 --- a/lib/Doctrine/ORM/Query/Parameter.php +++ b/lib/Doctrine/ORM/Query/Parameter.php @@ -19,6 +19,8 @@ namespace Doctrine\ORM\Query; +use function trim; + /** * Defines a Query Parameter. * @@ -49,6 +51,13 @@ class Parameter */ private $type; + /** + * Whether the parameter type was explicitly specified or not + * + * @var bool + */ + private $typeSpecified; + /** * Constructor. * @@ -58,7 +67,8 @@ class Parameter */ public function __construct($name, $value, $type = null) { - $this->name = trim($name, ':'); + $this->name = trim($name, ':'); + $this->typeSpecified = $type !== null; $this->setValue($value, $type); } @@ -104,4 +114,9 @@ public function setValue($value, $type = null) $this->value = $value; $this->type = $type ?: ParameterTypeInferer::inferType($value); } + + public function typeWasSpecified() : bool + { + return $this->typeSpecified; + } } diff --git a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php index 1cf8ab1646f..17d10f4b2dc 100644 --- a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php +++ b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php @@ -609,8 +609,11 @@ public function testSetParameter() ->setParameter('id', 1); $parameter = new Parameter('id', 1, ParameterTypeInferer::inferType(1)); + $inferred = $qb->getParameter('id'); - $this->assertEquals($parameter, $qb->getParameter('id')); + self::assertSame($parameter->getValue(), $inferred->getValue()); + self::assertSame($parameter->getType(), $inferred->getType()); + self::assertFalse($inferred->typeWasSpecified()); } public function testSetParameters() From 12eb9f42dc70e676eee8f1521c36351c5a159e9b Mon Sep 17 00:00:00 2001 From: vladyslavstartsev Date: Sun, 16 Dec 2018 20:33:21 +0200 Subject: [PATCH 754/877] Documentation error fix --- docs/en/cookbook/dql-user-defined-functions.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/cookbook/dql-user-defined-functions.rst b/docs/en/cookbook/dql-user-defined-functions.rst index 3278319d249..ab4591da30c 100644 --- a/docs/en/cookbook/dql-user-defined-functions.rst +++ b/docs/en/cookbook/dql-user-defined-functions.rst @@ -21,7 +21,7 @@ the :doc:`Native Query <../reference/native-sql>` chapter. The DQL Parser has hooks to register functions that can then be used in your DQL queries and transformed into SQL, allowing to extend Doctrines Query capabilities to the vendors strength. This -post explains the Used-Defined Functions API (UDF) of the Dql +post explains the User-Defined Functions API (UDF) of the Dql Parser and shows some examples to give you some hints how you would extend DQL. From ca436f0baeff6f7bd51ec3003819ff38f13de5d8 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 19 Dec 2018 10:52:11 +0100 Subject: [PATCH 755/877] #7527 performance benchmark - verifying performance impact of inferred query parameter types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As an example result: ``` ./phpbench.phar run tests/Doctrine/Performance/Query --iterations=50 --revs=50 --report=aggregate PhpBench 0.15-dev (dcbe193). Running benchmarks. Using configuration file: /home/ocramius/Documents/doctrine/doctrine2/phpbench.json \Doctrine\Performance\Query\QueryBoundParameterProcessingBench benchExecuteParsedQueryWithInferredParameterTypeI49 P0 [μ Mo]/r: 643.684 634.664 (μs) [μSD μRSD]/r: 17.700μs 2.75% benchExecuteParsedQueryWithDeclaredParameterTypeI49 P0 [μ Mo]/r: 97.673 94.251 (μs) [μSD μRSD]/r: 8.259μs 8.46% 2 subjects, 100 iterations, 100 revs, 0 rejects, 0 failures, 0 warnings (best [mean mode] worst) = 88.460 [370.679 364.458] 127.400 (μs) ⅀T: 37,067.880μs μSD/r 12.980μs μRSD/r: 5.603% suite: 133f0e30090f815142331ebec6af18241694e7c0, date: 2018-12-19, stime: 10:47:10 +------------------------------------+--------------------------------------------------+--------+--------+------+-----+------------+-----------+-----------+-----------+-----------+----------+--------+-------+ | benchmark | subject | groups | params | revs | its | mem_peak | best | mean | mode | worst | stdev | rstdev | diff | +------------------------------------+--------------------------------------------------+--------+--------+------+-----+------------+-----------+-----------+-----------+-----------+----------+--------+-------+ | QueryBoundParameterProcessingBench | benchExecuteParsedQueryWithInferredParameterType | | [] | 50 | 50 | 5,970,568b | 604.680μs | 643.684μs | 634.664μs | 677.640μs | 17.700μs | 2.75% | 6.59x | | QueryBoundParameterProcessingBench | benchExecuteParsedQueryWithDeclaredParameterType | | [] | 50 | 50 | 5,922,424b | 88.460μs | 97.673μs | 94.251μs | 127.400μs | 8.259μs | 8.46% | 1.00x | +------------------------------------+--------------------------------------------------+--------+--------+------+-----+------------+-----------+-----------+-----------+-----------+----------+--------+-------+ ``` This indicates that the performance impact for NOT declaring parameter types explicitly is *MASSIVE*. --- .../Performance/EntityManagerFactory.php | 31 +++++++- .../QueryBoundParameterProcessingBench.php | 79 +++++++++++++++++++ 2 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/Performance/Query/QueryBoundParameterProcessingBench.php diff --git a/tests/Doctrine/Performance/EntityManagerFactory.php b/tests/Doctrine/Performance/EntityManagerFactory.php index fab5eba767c..d759506e46e 100644 --- a/tests/Doctrine/Performance/EntityManagerFactory.php +++ b/tests/Doctrine/Performance/EntityManagerFactory.php @@ -2,6 +2,10 @@ namespace Doctrine\Performance; +use Doctrine\Common\EventManager; +use Doctrine\DBAL\Cache\ArrayStatement; +use Doctrine\DBAL\Cache\QueryCacheProfile; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver\PDOSqlite\Driver; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; @@ -20,7 +24,7 @@ public static function getEntityManager(array $schemaClassNames) : EntityManager $config->setAutoGenerateProxyClasses(ProxyFactory::AUTOGENERATE_EVAL); $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([ realpath(__DIR__ . '/Models/Cache'), - realpath(__DIR__ . '/Models/GeoNames') + realpath(__DIR__ . '/Models/GeoNames'), ], true)); $entityManager = EntityManager::create( @@ -36,4 +40,29 @@ public static function getEntityManager(array $schemaClassNames) : EntityManager return $entityManager; } + + public static function makeEntityManagerWithNoResultsConnection() : EntityManagerInterface + { + $config = new Configuration(); + + $config->setProxyDir(__DIR__ . '/../Tests/Proxies'); + $config->setProxyNamespace('Doctrine\Tests\Proxies'); + $config->setAutoGenerateProxyClasses(ProxyFactory::AUTOGENERATE_EVAL); + $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([ + realpath(__DIR__ . '/Models/Cache'), + realpath(__DIR__ . '/Models/Generic'), + realpath(__DIR__ . '/Models/GeoNames'), + ], true)); + + // A connection that doesn't really do anything + $connection = new class ([], new Driver(), null, new EventManager()) extends Connection + { + public function executeQuery($query, array $params = [], $types = [], QueryCacheProfile $qcp = null) + { + return new ArrayStatement([]); + } + }; + + return EntityManager::create($connection, $config); + } } diff --git a/tests/Doctrine/Performance/Query/QueryBoundParameterProcessingBench.php b/tests/Doctrine/Performance/Query/QueryBoundParameterProcessingBench.php new file mode 100644 index 00000000000..04e17167a07 --- /dev/null +++ b/tests/Doctrine/Performance/Query/QueryBoundParameterProcessingBench.php @@ -0,0 +1,79 @@ +parsedQueryWithInferredParameterType = $entityManager->createQuery($dql); + $this->parsedQueryWithDeclaredParameterType = $entityManager->createQuery($dql); + + foreach (range(1, 10) as $index) { + $this->parsedQueryWithInferredParameterType->setParameter('parameter' . $index, new DateTime()); + $this->parsedQueryWithDeclaredParameterType->setParameter('parameter' . $index, new DateTime(), DateTimeType::DATETIME); + } + + // Force parsing upfront - we don't benchmark that bit in this scenario + $this->parsedQueryWithInferredParameterType->getSQL(); + $this->parsedQueryWithDeclaredParameterType->getSQL(); + } + + public function benchExecuteParsedQueryWithInferredParameterType() : void + { + $this->parsedQueryWithInferredParameterType->execute(); + } + + public function benchExecuteParsedQueryWithDeclaredParameterType() : void + { + $this->parsedQueryWithDeclaredParameterType->execute(); + } +} + From a41f5673bc1b89b5ccac608287747289e35ce0ed Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 20 Dec 2018 22:45:54 +0100 Subject: [PATCH 756/877] #7527 automated CS checks --- tests/Doctrine/Performance/EntityManagerFactory.php | 7 ++++++- .../Query/QueryBoundParameterProcessingBench.php | 1 - 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Performance/EntityManagerFactory.php b/tests/Doctrine/Performance/EntityManagerFactory.php index d759506e46e..0e891875db8 100644 --- a/tests/Doctrine/Performance/EntityManagerFactory.php +++ b/tests/Doctrine/Performance/EntityManagerFactory.php @@ -1,5 +1,7 @@ parsedQueryWithDeclaredParameterType->execute(); } } - From efaee8ce85a11b9da8679d1dc0ba96c73946aa7b Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Sun, 11 Nov 2018 23:49:03 +0100 Subject: [PATCH 757/877] Migrate repository name doctrine/doctrine2 -> doctrine/orm --- CONTRIBUTING.md | 8 ++++---- README.md | 16 +++++++-------- SECURITY.md | 2 +- UPGRADE.md | 6 +++--- docs/en/changelog/migration_2_5.rst | 20 +++++++++---------- docs/en/index.rst | 2 +- .../limitations-and-known-issues.rst | 14 ++++++------- .../ORM/Functional/LifecycleCallbackTest.php | 2 +- .../ORM/Query/SelectSqlGenerationTest.php | 2 +- tests/README.markdown | 10 +++++----- 10 files changed, 41 insertions(+), 41 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1034dbe0654..482fb631b7c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -44,12 +44,12 @@ Please try to add a test for your pull-request. You can run the unit-tests by calling ``vendor/bin/phpunit`` from the root of the project. It will run all the tests with an in memory SQLite database. -In order to do that, you will need a fresh copy of doctrine2, and you +In order to do that, you will need a fresh copy of the ORM, and you will have to run a composer installation in the project: ```sh -git clone git@github.com:doctrine/doctrine2.git -cd doctrine2 +git clone git@github.com:doctrine/orm.git +cd orm curl -sS https://getcomposer.org/installer | php -- ./composer.phar install ``` @@ -66,7 +66,7 @@ sqlite database. Tips for creating unit tests: 1. If you put a test into the `Ticket` namespace as described above, put the testcase and all entities into the same class. - See `https://github.com/doctrine/doctrine2/tree/master/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2306Test.php` for an + See `https://github.com/doctrine/orm/tree/master/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2306Test.php` for an example. ## Travis diff --git a/README.md b/README.md index 45d2b1f5fb7..7f935fc34c1 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,11 @@ without requiring unnecessary code duplication. * [Documentation](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/index.html) - [Master image]: https://img.shields.io/travis/doctrine/doctrine2/master.svg?style=flat-square - [Master]: https://travis-ci.org/doctrine/doctrine2 - [Master coverage image]: https://img.shields.io/scrutinizer/coverage/g/doctrine/doctrine2/master.svg?style=flat-square - [Master coverage]: https://scrutinizer-ci.com/g/doctrine/doctrine2/?branch=master - [2.5 image]: https://img.shields.io/travis/doctrine/doctrine2/2.5.svg?style=flat-square - [2.5]: https://github.com/doctrine/doctrine2/tree/2.5 - [2.5 coverage image]: https://img.shields.io/scrutinizer/coverage/g/doctrine/doctrine2/2.5.svg?style=flat-square - [2.5 coverage]: https://scrutinizer-ci.com/g/doctrine/doctrine2/?branch=2.5 + [Master image]: https://img.shields.io/travis/doctrine/orm/master.svg?style=flat-square + [Master]: https://travis-ci.org/doctrine/orm + [Master coverage image]: https://img.shields.io/scrutinizer/coverage/g/doctrine/orm/master.svg?style=flat-square + [Master coverage]: https://scrutinizer-ci.com/g/doctrine/orm/?branch=master + [2.5 image]: https://img.shields.io/travis/doctrine/orm/2.5.svg?style=flat-square + [2.5]: https://github.com/doctrine/orm/tree/2.5 + [2.5 coverage image]: https://img.shields.io/scrutinizer/coverage/g/doctrine/orm/2.5.svg?style=flat-square + [2.5 coverage]: https://scrutinizer-ci.com/g/doctrine/orm/?branch=2.5 diff --git a/SECURITY.md b/SECURITY.md index 313900211e6..0789963bf70 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -11,7 +11,7 @@ Please read the documentation chapter on Security in Doctrine DBAL and ORM to understand the assumptions we make. - [DBAL Security Page](https://github.com/doctrine/dbal/blob/master/docs/en/reference/security.rst) -- [ORM Security Page](https://github.com/doctrine/doctrine2/blob/master/docs/en/reference/security.rst) +- [ORM Security Page](https://github.com/doctrine/orm/blob/master/docs/en/reference/security.rst) If you find a Security bug in Doctrine, please report it on Jira and change the Security Level to "Security Issues". It will be visible to Doctrine Core diff --git a/UPGRADE.md b/UPGRADE.md index 19528d89f49..3567b998d49 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -20,13 +20,13 @@ now has a required parameter `$pathExpr`. Method `Doctrine\ORM\Query\Parser#isInternalFunction()` was removed because the distinction between internal function and user defined DQL was removed. -[#6500](https://github.com/doctrine/doctrine2/pull/6500) +[#6500](https://github.com/doctrine/orm/pull/6500) ## Minor BC BREAK: removed `Doctrine\ORM\ORMException#overwriteInternalDQLFunctionNotAllowed()` Method `Doctrine\ORM\Query\Parser#overwriteInternalDQLFunctionNotAllowed()` was removed because of the choice to allow users to overwrite internal functions, ie -`AVG`, `SUM`, `COUNT`, `MIN` and `MAX`. [#6500](https://github.com/doctrine/doctrine2/pull/6500) +`AVG`, `SUM`, `COUNT`, `MIN` and `MAX`. [#6500](https://github.com/doctrine/orm/pull/6500) ## PHP 7.1 is now required @@ -42,7 +42,7 @@ As a consequence, automatic cache setup in Doctrine\ORM\Tools\Setup::create*Conf ## Minor BC BREAK: removed `Doctrine\ORM\Query\SqlWalker#walkCaseExpression()` Method `Doctrine\ORM\Query\SqlWalker#walkCaseExpression()` was unused and part -of the internal API of the ORM, so it was removed. [#5600](https://github.com/doctrine/doctrine2/pull/5600). +of the internal API of the ORM, so it was removed. [#5600](https://github.com/doctrine/orm/pull/5600). ## Minor BC BREAK: removed $className parameter on `AbstractEntityInheritancePersister#getSelectJoinColumnSQL()` diff --git a/docs/en/changelog/migration_2_5.rst b/docs/en/changelog/migration_2_5.rst index 408776d03c3..dca6a0c8b75 100644 --- a/docs/en/changelog/migration_2_5.rst +++ b/docs/en/changelog/migration_2_5.rst @@ -21,7 +21,7 @@ defined then Doctrine would trigger listeners after the fields were loaded, but before assocations are available. - `DDC-54 `_ -- `Commit #a90629 `_ +- `Commit #a90629 `_ Events: Add API to programatically add event listeners to Entity ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -102,7 +102,7 @@ This feature was developed by external contributor `Johannes Schmitt `_ - `DDC-93 `_ -- `Pull Request #835 `_ +- `Pull Request #835 `_ Second-Level-Cache ~~~~~~~~~~~~~~~~~~ @@ -160,7 +160,7 @@ instead of the database. - `Documentation `_ -- `Pull Request #808 `_ +- `Pull Request #808 `_ Criteria API: Support for ManyToMany assocations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -217,8 +217,8 @@ trigger a full load of the collection. This feature was contributed by `Michaël Gallego `_. -- `Pull Request #882 `_ -- `Pull Request #1032 `_ +- `Pull Request #882 `_ +- `Pull Request #1032 `_ Mapping: Allow configuring Index flags ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -241,7 +241,7 @@ only with a schema event listener before. This feature was contributed by `Adrian Olek `_. -- `Pull Request #973 `_ +- `Pull Request #973 `_ SQLFilter API: Check if a parameter is set ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -272,7 +272,7 @@ Extending on the locale example of the documentation: This feature was contributed by `Miroslav Demovic `_ -- `Pull Request #963 `_ +- `Pull Request #963 `_ EXTRA_LAZY Improvements @@ -301,7 +301,7 @@ EXTRA_LAZY Improvements This feature was contributed by `Asmir Mustafic `_ - - `Pull Request #937 `_ + - `Pull Request #937 `_ 2. Add EXTRA_LAZY Support for get() for owning and inverse many-to-many @@ -415,7 +415,7 @@ object: This feature was contributed by `Michael Perrin `_. -- `Pull Request #590 `_ +- `Pull Request #590 `_ - `DDC-2319 `_ Query API: Add support for default Query Hints @@ -439,7 +439,7 @@ It is now possible to add query hints that are always enabled for every Query: This feature was contributed by `Artur Eshenbrener `_. -- `Pull Request #863 `_ +- `Pull Request #863 `_ ResultSetMappingBuilder: Add support for Single-Table Inheritance ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/en/index.rst b/docs/en/index.rst index 1863da705d1..290137daff6 100644 --- a/docs/en/index.rst +++ b/docs/en/index.rst @@ -15,7 +15,7 @@ Doctrine ORM don't panic. You can get help from different sources: - There is a :doc:`FAQ ` with answers to frequent questions. - The `Doctrine Mailing List `_ - Slack chat room `#orm `_ -- Report a bug on `GitHub `_. +- Report a bug on `GitHub `_. - On `Twitter `_ with ``#doctrine2`` - On `StackOverflow `_ diff --git a/docs/en/reference/limitations-and-known-issues.rst b/docs/en/reference/limitations-and-known-issues.rst index 15cde689b8d..8fd20e81978 100644 --- a/docs/en/reference/limitations-and-known-issues.rst +++ b/docs/en/reference/limitations-and-known-issues.rst @@ -63,7 +63,7 @@ Where the ``attribute_name`` column contains the key and ``$attributes``. The feature request for persistence of primitive value arrays -`is described in the DDC-298 ticket `_. +`is described in the DDC-298 ticket `_. Cascade Merge with Bi-directional Associations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -71,8 +71,8 @@ Cascade Merge with Bi-directional Associations There are two bugs now that concern the use of cascade merge in combination with bi-directional associations. Make sure to study the behavior of cascade merge if you are using it: -- `DDC-875 `_ Merge can sometimes add the same entity twice into a collection -- `DDC-763 `_ Cascade merge on associated entities can insert too many rows through "Persistence by Reachability" +- `DDC-875 `_ Merge can sometimes add the same entity twice into a collection +- `DDC-763 `_ Cascade merge on associated entities can insert too many rows through "Persistence by Reachability" Custom Persisters ~~~~~~~~~~~~~~~~~ @@ -83,8 +83,8 @@ Currently there is no way to overwrite the persister implementation for a given entity, however there are several use-cases that can benefit from custom persister implementations: -- `Add Upsert Support `_ -- `Evaluate possible ways in which stored-procedures can be used `_ +- `Add Upsert Support `_ +- `Evaluate possible ways in which stored-procedures can be used `_ Persist Keys of Collections ~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -94,7 +94,7 @@ PHP Arrays are ordered hash-maps and so should be the evaluate a feature that optionally persists and hydrates the keys of a Collection instance. -`Ticket DDC-213 `_ +`Ticket DDC-213 `_ Mapping many tables to one entity ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -145,7 +145,7 @@ We don't plan to add every bug in the tracker there, just those issues that can potentially cause nightmares or pain of any sort. See bugs, improvement and feature requests on `Github issues -`_. +`_. Identifier Quoting and Legacy Databases ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php b/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php index 914acbecf86..e23095fe848 100644 --- a/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php @@ -270,7 +270,7 @@ public function testCascadedEntitiesNotLoadedInPostLoadDuringIterationWithSimple } /** - * https://github.com/doctrine/doctrine2/issues/6568 + * https://github.com/doctrine/orm/issues/6568 */ public function testPostLoadIsInvokedOnFetchJoinedEntities() { diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index b65611217fa..2c3435fdbdc 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -2302,7 +2302,7 @@ public function testHavingSupportResultVariableInAggregateFunction() } /** - * GitHub issue #4764: https://github.com/doctrine/doctrine2/issues/4764 + * GitHub issue #4764: https://github.com/doctrine/orm/issues/4764 * @group DDC-3907 * @dataProvider mathematicOperatorsProvider */ diff --git a/tests/README.markdown b/tests/README.markdown index dfba6fa217b..5b8fb05b65a 100644 --- a/tests/README.markdown +++ b/tests/README.markdown @@ -1,16 +1,16 @@ -# Running the Doctrine 2 Testsuite +# Running the Doctrine ORM Testsuite -To execute the Doctrine2 testsuite, you just need to execute this simple steps: +To execute the ORM testsuite, you just need to execute this simple steps: * Clone the project from GitHub - * Enter the Doctrine2 folder + * Enter the ORM folder * Install the dependencies * Execute the tests All this is (normally) done with: - git clone git@github.com:doctrine/doctrine2.git - cd doctrine2 + git clone git@github.com:doctrine/orm.git + cd orm composer install ./vendor/bin/phpunit From 597bfaea03475c411971216d06721e4ea857246c Mon Sep 17 00:00:00 2001 From: Maciej Malarz Date: Fri, 4 Jan 2019 22:20:24 +0100 Subject: [PATCH 758/877] Change Stackoverflow tag to doctrine-orm --- docs/en/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/index.rst b/docs/en/index.rst index 290137daff6..1a7d2654ad8 100644 --- a/docs/en/index.rst +++ b/docs/en/index.rst @@ -17,7 +17,7 @@ Doctrine ORM don't panic. You can get help from different sources: - Slack chat room `#orm `_ - Report a bug on `GitHub `_. - On `Twitter `_ with ``#doctrine2`` -- On `StackOverflow `_ +- On `StackOverflow `_ If you need more structure over the different topics you can browse the :doc:`table of contents `. From 3d652997d1e5c0a04d41c0d3d382d06147ccd384 Mon Sep 17 00:00:00 2001 From: Claudio Zizza Date: Sat, 1 Sep 2018 23:09:59 +0200 Subject: [PATCH 759/877] Remove changelog from documentation This was removed in favour of the UPGRADE.md file, which contains the changelog information needed. --- docs/en/changelog/migration_2_5.rst | 711 ---------------------------- docs/en/index.rst | 2 +- 2 files changed, 1 insertion(+), 712 deletions(-) delete mode 100644 docs/en/changelog/migration_2_5.rst diff --git a/docs/en/changelog/migration_2_5.rst b/docs/en/changelog/migration_2_5.rst deleted file mode 100644 index dca6a0c8b75..00000000000 --- a/docs/en/changelog/migration_2_5.rst +++ /dev/null @@ -1,711 +0,0 @@ -What is new in Doctrine ORM 2.5? -================================ - -This document describes changes between Doctrine ORM 2.4 and 2.5. -It contains a description of all the new features and sections about -behavioral changes and potential backwards compatibility breaks. -Please review this document carefully when updating to Doctrine 2.5. - -First note, that with the ORM 2.5 release we are dropping support -for PHP 5.3. We are enforcing this with Composer, servers without -at least PHP 5.4 will not allow installing Doctrine 2.5. - -New Features and Improvements ------------------------------ - -Events: PostLoad now triggered after associations are loaded -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Before Doctrine 2.5 if you had an entity with a ``@PostLoad`` event -defined then Doctrine would trigger listeners after the fields were -loaded, but before assocations are available. - -- `DDC-54 `_ -- `Commit #a90629 `_ - -Events: Add API to programatically add event listeners to Entity -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -When developing third party libraries or decoupled applications -it can be interesting to develop an entity listener without knowing -the entities that require this listener. - -You can now attach entity listeners to entities using the -``AttachEntityListenersListener`` class, which is listening to the -``loadMetadata`` event that is fired once for every entity during -metadata generation: - -.. code-block:: php - - addEntityListener( - 'MyProject\Entity\User', 'MyProject\Listener\TimestampableListener', - Events::prePersist, 'onPrePersist' - ); - - $evm->addEventListener(Events::loadClassMetadata, $listener); - - class TimestampableListener - { - public function onPrePersist($event) - { - $entity = $event->getEntity(); - $entity->setCreated(new \DateTime('now')); - } - } - -Embeddable Objects -~~~~~~~~~~~~~~~~~~ - -Doctrine now supports creating multiple PHP objects from one database table -implementing a feature called "Embeddable Objects". Next to an ``@Entity`` -class you can now define a class that is embeddable into a database table of an -entity using the ``@Embeddable`` annotation. Embeddable objects can never be -saved, updated or deleted on their own, only as part of an entity (called -"root-entity" or "aggregate"). Consequently embeddables don't have a primary -key, they are identified only by their values. - -Example of defining and using embeddables classes: - -.. code-block:: php - - `_. - -This feature was developed by external contributor `Johannes Schmitt -`_ - -- `DDC-93 `_ -- `Pull Request #835 `_ - -Second-Level-Cache -~~~~~~~~~~~~~~~~~~ - -Since version 2.0 of Doctrine, fetching the same object twice by primary key -would result in just one query. This was achieved by the identity map pattern -(first-level-cache) that kept entities in memory. - -The newly introduced second-level-cache works a bit differently. Instead -of saving objects in memory, it saves them in a fast in-memory cache such -as Memcache, Redis, Riak or MongoDB. Additionally it allows saving the result -of more complex queries than by primary key. Summarized this feature works -like the existing Query result cache, but it is much more powerful. - -As an example lets cache an entity Country that is a relation to the User -entity. We always want to display the country, but avoid the additional -query to this table. - -.. code-block:: php - - setSecondLevelCacheEnabled(); - - $cacheConfig = $config->getSecondLevelCacheConfiguration(); - $regionConfig = $cacheConfig->getRegionsConfiguration(); - $regionConfig->setLifetime('country_region', 3600); - -Now Doctrine will first check for the data of any country in the cache -instead of the database. - -- `Documentation - `_ -- `Pull Request #808 `_ - -Criteria API: Support for ManyToMany assocations -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -We introduced support for querying collections using the `Criteria API -`_ -in 2.4. This only worked efficently for One-To-Many assocations, not for -Many-To-Many. With the start of 2.5 also Many-To-Many associations get queried -instead of loading them into memory. - -Criteria API: Add new contains() expression -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -It is now possible to use the Criteria API to check for string contains needle -using ``contains()``. This translates to using a ``column LIKE '%needle%'`` SQL -condition. - -.. code-block:: php - - where(Criteria::expr()->contains('name', 'Benjamin')); - - $users = $repository->matching($criteria); - -Criteria API: Support for EXTRA_LAZY -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -A collection that is marked as ``fetch="EXTRA_LAZY"`` will now return another -lazy collection when using ``Collection::matching($criteria)``: - -.. code-block:: php - - where(Criteria->expr()->eq("published", 1)); - - $publishedComments = $post->getComments()->matching($criteria); - - echo count($publishedComments); - -The lazy criteria currently supports the ``count()`` and ``contains()`` -functionality lazily. All other operations of the ``Collection`` interface -trigger a full load of the collection. - -This feature was contributed by `Michaël Gallego `_. - -- `Pull Request #882 `_ -- `Pull Request #1032 `_ - -Mapping: Allow configuring Index flags -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -It is now possible to control the index flags in the DBAL -schema abstraction from the ORM using metadata. This was possible -only with a schema event listener before. - -.. code-block:: php - - `_. - -- `Pull Request #973 `_ - -SQLFilter API: Check if a parameter is set -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -You can now check in your SQLFilter if a parameter was set. This allows -to more easily control which features of a filter to enable or disable. - -Extending on the locale example of the documentation: - -.. code-block:: php - - reflClass->implementsInterface('LocaleAware')) { - return ""; - } - - if (!$this->hasParameter('locale')) { - return ""; - } - - return $targetTableAlias.'.locale = ' . $this->getParameter('locale'); - } - } - -This feature was contributed by `Miroslav Demovic `_ - -- `Pull Request #963 `_ - - -EXTRA_LAZY Improvements -~~~~~~~~~~~~~~~~~~~~~~~ - -1. Efficient query when using EXTRA_LAZY and containsKey - - When calling ``Collection::containsKey($key)`` on one-to-many and many-to-many - collections using ``indexBy`` and ``EXTRA_LAZY`` a query is now executed to check - for the existance for the item. Prevoiusly this operation was performed in memory - by loading all entities of the collection. - - .. code-block:: php - - getGroups()->containsKey($groupId)) { - echo "User is in group $groupId\n"; - } - - This feature was contributed by `Asmir Mustafic `_ - - - `Pull Request #937 `_ - -2. Add EXTRA_LAZY Support for get() for owning and inverse many-to-many - - This was contributed by `Sander Marechal `_. - -Improve efficiency of One-To-Many EAGER -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -When marking a one-to-many association with ``fetch="EAGER"`` it will now -execute one query less than before and work correctly in combination with -``indexBy``. - -Better support for EntityManagerInterface -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Many of the locations where previously only the ``Doctrine\ORM\EntityManager`` -was allowed are now changed to accept the ``EntityManagerInterface`` that was -introduced in 2.4. This allows you to more easily use the decorator pattern -to extend the EntityManager if you need. It's still not replaced everywhere, -so you still have to be careful. - -DQL Improvements -~~~~~~~~~~~~~~~~ - -1. It is now possible to add functions to the ``ORDER BY`` clause in DQL statements: - -.. code-block:: php - - createQuery($dql); - $query->setParameter('groups', array(1, 2, 3)); - - $users = $query->getResult(); - -6. Expressions inside ``COUNT()`` now allowed - -.. code-block:: php - - `_ to pass a callback instead that resolves -the function: - -.. code-block:: php - - addCustomNumericFunction( - 'IS_PUBLISHED', function($funcName) use ($currentSiteId) { - return new IsPublishedFunction($currentSiteId); - } - ); - -Query API: WHERE IN Query using a Collection as parameter -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -When performing a ``WHERE IN`` query for a collection of entities you can -now pass the array collection of entities as a parameter value to the query -object: - -.. code-block:: php - - getChildren(); - - $queryBuilder - ->select('p') - ->from('Product', 'p') - ->where('p.category IN (:categories)') - ->setParameter('categories', $categories) - ; - -This feature was contributed by `Michael Perrin -`_. - -- `Pull Request #590 `_ -- `DDC-2319 `_ - -Query API: Add support for default Query Hints -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -To configure multiple different features such as custom AST Walker, fetch modes, -locking and other features affecting DQL generation we have had a feature -called "query hints" since version 2.0. - -It is now possible to add query hints that are always enabled for every Query: - -.. code-block:: php - - setDefaultQueryHints( - 'doctrine.customOutputWalker' => 'MyProject\CustomOutputWalker' - ); - -This feature was contributed by `Artur Eshenbrener -`_. - -- `Pull Request #863 `_ - -ResultSetMappingBuilder: Add support for Single-Table Inheritance -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Before 2.5 the ResultSetMappingBuilder did not work with entities -that are using Single-Table-Inheritance. This restriction was lifted -by adding the missing support. - -YAML Mapping: Many-To-Many doesnt require join column definition -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -In Annotations and XML it was not necessary using conventions for naming -the many-to-many join column names, in YAML it was not possible however. - -A many-to-many definition in YAML is now possible using this minimal -definition: - -.. code-block:: yaml - - manyToMany: - groups: - targetEntity: Group - joinTable: - name: users_groups - -Schema Validator Command: Allow to skip sub-checks -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -The Schema Validator command executes two independent checks -for validity of the mappings and if the schema is synchronized -correctly. It is now possible to skip any of the two steps -when executing the command: - -:: - - $ php vendor/bin/doctrine orm:validate-schema --skip-mapping - $ php vendor/bin/doctrine orm:validate-schema --skip-sync - -This allows you to write more specialized continuous integration and automation -checks. When no changes are found the command returns the exit code 0 -and 1, 2 or 3 when failing because of mapping, sync or both. - -EntityGenerator Command: Avoid backups -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -When calling the EntityGenerator for an existing entity, Doctrine would -create a backup file every time to avoid losing changes to the code. You -can now skip generating the backup file by passing the ``--no-backup`` -flag: - -:: - - $ php vendor/bin/doctrine orm:generate-entities src/ --no-backup - -Support for Objects as Identifiers -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -It is now possible to use Objects as identifiers for Entities -as long as they implement the magic method ``__toString()``. - -.. code-block:: php - - value = $value; - } - - public function __toString() - { - return (string)$this->value; - } - } - - class User - { - /** @Id @Column(type="userid") */ - private $id; - - public function __construct(UserId $id) - { - $this->id = $id; - } - } - - class UserIdType extends \Doctrine\DBAL\Types\Type - { - // ... - } - - Doctrine\DBAL\Types\Type::addType('userid', 'MyProject\UserIdType'); - -Behavioral Changes (BC Breaks) ------------------------------- - -NamingStrategy interface changed -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -The ``Doctrine\ORM\Mapping\NamingStrategyInterface`` changed slightly -to pass the Class Name of the entity into the join column name generation: - -:: - - - function joinColumnName($propertyName); - + function joinColumnName($propertyName, $className = null); - -It also received a new method for supporting embeddables: - -:: - - public function embeddedFieldToColumnName($propertyName, $embeddedColumnName); - -Minor BC BREAK: EntityManagerInterface instead of EntityManager in type-hints -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -As of 2.5, classes requiring the ``EntityManager`` in any method signature will now require -an ``EntityManagerInterface`` instead. -If you are extending any of the following classes, then you need to check following -signatures: - -- ``Doctrine\ORM\Tools\DebugUnitOfWorkListener#dumpIdentityMap(EntityManagerInterface $em)`` -- ``Doctrine\ORM\Mapping\ClassMetadataFactory#setEntityManager(EntityManagerInterface $em)`` - -Minor BC BREAK: Custom Hydrators API change -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -As of 2.5, ``AbstractHydrator`` does not enforce the usage of cache as part of -API, and now provides you a clean API for column information through the method -``hydrateColumnInfo($column)``. -Cache variable being passed around by reference is no longer needed since -Hydrators are per query instantiated since Doctrine 2.4. - -- `DDC-3060 `_ - -Minor BC BREAK: All non-transient classes in an inheritance must be part of the inheritance map -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -As of 2.5, classes, if you define an inheritance map for an inheritance tree, you are required -to map all non-transient classes in that inheritance, including the root of the inheritance. - -So far, the root of the inheritance was allowed to be skipped in the inheritance map: this is -not possible anymore, and if you don't plan to persist instances of that class, then you should -either: - -- make that class as ``abstract`` -- add that class to your inheritance map - -If you fail to do so, then a ``Doctrine\ORM\Mapping\MappingException`` will be thrown. - - -- `DDC-3300 `_ -- `DDC-3503 `_ - -Minor BC BREAK: Entity based EntityManager#clear() calls follow cascade detach -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Whenever ``EntityManager#clear()`` method gets called with a given entity class -name, until 2.4, it was only detaching the specific requested entity. -As of 2.5, ``EntityManager`` will follow configured cascades, providing a better -memory management since associations will be garbage collected, optimizing -resources consumption on long running jobs. - -Updates on entities scheduled for deletion are no longer processed -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -In Doctrine 2.4, if you modified properties of an entity scheduled for deletion, UnitOfWork would -produce an ``UPDATE`` statement to be executed right before the ``DELETE`` statement. The entity in question -was therefore present in ``UnitOfWork#entityUpdates``, which means that ``preUpdate`` and ``postUpdate`` -listeners were (quite pointlessly) called. In ``preFlush`` listeners, it used to be possible to undo -the scheduled deletion for updated entities (by calling ``persist()`` if the entity was found in both -``entityUpdates`` and ``entityDeletions``). This does not work any longer, because the entire changeset -calculation logic is optimized away. - -Minor BC BREAK: Default lock mode changed from LockMode::NONE to null in method signatures -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -A misconception concerning default lock mode values in method signatures lead to unexpected behaviour -in SQL statements on SQL Server. With a default lock mode of ``LockMode::NONE`` throughout the -method signatures in ORM, the table lock hint ``WITH (NOLOCK)`` was appended to all locking related -queries by default. This could result in unpredictable results because an explicit ``WITH (NOLOCK)`` -table hint tells SQL Server to run a specific query in transaction isolation level READ UNCOMMITTED -instead of the default READ COMMITTED transaction isolation level. -Therefore there now is a distinction between ``LockMode::NONE`` and ``null`` to be able to tell -Doctrine whether to add table lock hints to queries by intention or not. To achieve this, the following -method signatures have been changed to declare ``$lockMode = null`` instead of ``$lockMode = LockMode::NONE``: - -- ``Doctrine\ORM\Cache\Persister\AbstractEntityPersister#getSelectSQL()`` -- ``Doctrine\ORM\Cache\Persister\AbstractEntityPersister#load()`` -- ``Doctrine\ORM\Cache\Persister\AbstractEntityPersister#refresh()`` -- ``Doctrine\ORM\Decorator\EntityManagerDecorator#find()`` -- ``Doctrine\ORM\EntityManager#find()`` -- ``Doctrine\ORM\EntityRepository#find()`` -- ``Doctrine\ORM\Persisters\BasicEntityPersister#getSelectSQL()`` -- ``Doctrine\ORM\Persisters\BasicEntityPersister#load()`` -- ``Doctrine\ORM\Persisters\BasicEntityPersister#refresh()`` -- ``Doctrine\ORM\Persisters\EntityPersister#getSelectSQL()`` -- ``Doctrine\ORM\Persisters\EntityPersister#load()`` -- ``Doctrine\ORM\Persisters\EntityPersister#refresh()`` -- ``Doctrine\ORM\Persisters\JoinedSubclassPersister#getSelectSQL()`` - -You should update signatures for these methods if you have subclassed one of the above classes. -Please also check the calling code of these methods in your application and update if necessary. - -.. note:: - - This in fact is really a minor BC BREAK and should not have any affect on database vendors - other than SQL Server because it is the only one that supports and therefore cares about - ``LockMode::NONE``. It's really just a FIX for SQL Server environments using ORM. - -Minor BC BREAK: __clone method not called anymore when entities are instantiated via metadata API -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -As of PHP 5.6, instantiation of new entities is deferred to the -`doctrine/instantiator `_ library, which will avoid calling ``__clone`` -or any public API on instantiated objects. - -BC BREAK: DefaultRepositoryFactory is now final -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Please implement the ``Doctrine\ORM\Repository\RepositoryFactory`` interface instead of extending -the ``Doctrine\ORM\Repository\DefaultRepositoryFactory``. - -BC BREAK: New object expression DQL queries now respects user provided aliasing and not return consumed fields -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -When executing DQL queries with new object expressions, instead of returning -DTOs numerically indexes, it will now respect user provided aliases. Consider -the following query: - -:: - - SELECT new UserDTO(u.id,u.name) as user,new AddressDTO(a.street,a.postalCode) as address, a.id as addressId - FROM User u INNER JOIN u.addresses a WITH a.isPrimary = true - -Previously, your result would be similar to this: - -:: - - array( - 0=>array( - 0=>{UserDTO object}, - 1=>{AddressDTO object}, - 2=>{u.id scalar}, - 3=>{u.name scalar}, - 4=>{a.street scalar}, - 5=>{a.postalCode scalar}, - 'addressId'=>{a.id scalar}, - ), - ... - ) - -From now on, the resultset will look like this: - -:: - - array( - 0=>array( - 'user'=>{UserDTO object}, - 'address'=>{AddressDTO object}, - 'addressId'=>{a.id scalar} - ), - ... - ) - diff --git a/docs/en/index.rst b/docs/en/index.rst index 1a7d2654ad8..84570665e0c 100644 --- a/docs/en/index.rst +++ b/docs/en/index.rst @@ -95,7 +95,7 @@ Tutorials Changelogs ---------- -* :doc:`Migration to 2.5 ` +* `Upgrade `_ Cookbook -------- From f5b9f2052a1627de7c220591f0d3180cc02f4a18 Mon Sep 17 00:00:00 2001 From: Claudio Zizza Date: Sat, 1 Sep 2018 23:21:33 +0200 Subject: [PATCH 760/877] Update MySQL links to current version --- ...value-conversion-using-custom-mapping-types.rst | 14 +++++++------- docs/en/cookbook/dql-user-defined-functions.rst | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/en/cookbook/advanced-field-value-conversion-using-custom-mapping-types.rst b/docs/en/cookbook/advanced-field-value-conversion-using-custom-mapping-types.rst index 5bbd2a3b11f..4f26464c9a3 100644 --- a/docs/en/cookbook/advanced-field-value-conversion-using-custom-mapping-types.rst +++ b/docs/en/cookbook/advanced-field-value-conversion-using-custom-mapping-types.rst @@ -11,9 +11,9 @@ There are several ways to achieve this: converting the value inside the Type class, converting the value on the database-level or a combination of both. This article describes the third way by implementing the MySQL specific column -type `Point `_. +type `Point `_. -The ``Point`` type is part of the `Spatial extension `_ +The ``Point`` type is part of the `Spatial extension `_ of MySQL and enables you to store a single location in a coordinate space by using x and y coordinates. You can use the Point type to store a longitude/latitude pair to represent a geographic location. @@ -192,9 +192,9 @@ object into a string representation before saving to the database (in the ``convertToDatabaseValue`` method) and back into an object after fetching the value from the database (in the ``convertToPHPValue`` method). -The format of the string representation format is called `Well-known text (WKT) -`_. The advantage of this format -is, that it is both human readable and parsable by MySQL. +The format of the string representation format is called +`Well-known text (WKT) `_. +The advantage of this format is, that it is both human readable and parsable by MySQL. Internally, MySQL stores geometry values in a binary format that is not identical to the WKT format. So, we need to let MySQL transform the WKT @@ -204,8 +204,8 @@ This is where the ``convertToPHPValueSQL`` and ``convertToDatabaseValueSQL`` methods come into play. This methods wrap a sql expression (the WKT representation of the Point) into -MySQL functions `PointFromText `_ -and `AsText `_ +MySQL functions `ST_PointFromText `_ +and `ST_AsText `_ which convert WKT strings to and from the internal format of MySQL. .. note:: diff --git a/docs/en/cookbook/dql-user-defined-functions.rst b/docs/en/cookbook/dql-user-defined-functions.rst index ab4591da30c..1261ef179b1 100644 --- a/docs/en/cookbook/dql-user-defined-functions.rst +++ b/docs/en/cookbook/dql-user-defined-functions.rst @@ -70,7 +70,7 @@ methods, which are quite handy in my opinion: Date Diff --------- -`Mysql's DateDiff function `_ +`Mysql's DateDiff function `_ takes two dates as argument and calculates the difference in days with ``date1-date2``. @@ -164,7 +164,7 @@ Date Add Often useful it the ability to do some simple date calculations in your DQL query using -`MySql's DATE\_ADD function `_. +`MySql's DATE\_ADD function `_. I'll skip the blah and show the code for this function: From 85171a9490c7fc563aec464dab8d8d8e5c7b54a8 Mon Sep 17 00:00:00 2001 From: Claudio Zizza Date: Sun, 2 Sep 2018 00:35:01 +0200 Subject: [PATCH 761/877] Fix of reStructuredText format --- docs/en/cookbook/implementing-wakeup-or-clone.rst | 8 ++++---- docs/en/cookbook/strategy-cookbook-introduction.rst | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/en/cookbook/implementing-wakeup-or-clone.rst b/docs/en/cookbook/implementing-wakeup-or-clone.rst index 93c2e54f4f7..1ae17753bc6 100644 --- a/docs/en/cookbook/implementing-wakeup-or-clone.rst +++ b/docs/en/cookbook/implementing-wakeup-or-clone.rst @@ -11,8 +11,8 @@ However, it is quite easy to make use of these methods in a safe way by guarding the custom wakeup or clone code with an entity identity check, as demonstrated in the following sections. -Safely implementing \_\_wakeup ------------------------------- +Safely implementing __wakeup +---------------------------- To safely implement ``__wakeup``, simply enclose your implementation code in an identity check as follows: @@ -37,8 +37,8 @@ implementation code in an identity check as follows: //... } -Safely implementing \_\_clone ------------------------------ +Safely implementing __clone +--------------------------- Safely implementing ``__clone`` is pretty much the same: diff --git a/docs/en/cookbook/strategy-cookbook-introduction.rst b/docs/en/cookbook/strategy-cookbook-introduction.rst index d9934f577de..b434a9df4d2 100644 --- a/docs/en/cookbook/strategy-cookbook-introduction.rst +++ b/docs/en/cookbook/strategy-cookbook-introduction.rst @@ -3,7 +3,7 @@ Strategy-Pattern This recipe will give you a short introduction on how to design similar entities without using expensive (i.e. slow) inheritance -but with not more than \* the well-known strategy pattern \* event +but with not more than *the well-known strategy pattern* event listeners Scenario / Problem From be461be36b1c1b5a8af0e940e0c859fa046fddf7 Mon Sep 17 00:00:00 2001 From: Claudio Zizza Date: Sun, 2 Sep 2018 00:39:13 +0200 Subject: [PATCH 762/877] Update getting help section --- docs/en/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/index.rst b/docs/en/index.rst index 84570665e0c..4c50484e4a5 100644 --- a/docs/en/index.rst +++ b/docs/en/index.rst @@ -17,7 +17,7 @@ Doctrine ORM don't panic. You can get help from different sources: - Slack chat room `#orm `_ - Report a bug on `GitHub `_. - On `Twitter `_ with ``#doctrine2`` -- On `StackOverflow `_ +- On `StackOverflow `_ If you need more structure over the different topics you can browse the :doc:`table of contents `. From b56800b15cb6f456a3b2e684d67993770f75cbfb Mon Sep 17 00:00:00 2001 From: Claudio Zizza Date: Sun, 2 Sep 2018 01:48:34 +0200 Subject: [PATCH 763/877] Fix of links and anchors --- docs/en/cookbook/dql-user-defined-functions.rst | 4 ++-- docs/en/cookbook/integrating-with-codeigniter.rst | 3 +-- docs/en/cookbook/validation-of-entities.rst | 2 +- docs/en/reference/basic-mapping.rst | 2 +- docs/en/reference/configuration.rst | 9 +++------ docs/en/reference/improving-performance.rst | 2 +- docs/en/reference/installation.rst | 3 +-- docs/en/reference/limitations-and-known-issues.rst | 4 +--- docs/en/reference/query-builder.rst | 2 +- docs/en/reference/second-level-cache.rst | 10 +++++----- docs/en/reference/security.rst | 2 +- docs/en/reference/working-with-objects.rst | 12 ++++++------ docs/en/tutorials/getting-started-database.rst | 2 +- docs/en/tutorials/getting-started-models.rst | 2 +- docs/en/tutorials/getting-started.rst | 9 ++++----- 15 files changed, 30 insertions(+), 38 deletions(-) diff --git a/docs/en/cookbook/dql-user-defined-functions.rst b/docs/en/cookbook/dql-user-defined-functions.rst index 1261ef179b1..28465ee2df5 100644 --- a/docs/en/cookbook/dql-user-defined-functions.rst +++ b/docs/en/cookbook/dql-user-defined-functions.rst @@ -164,7 +164,7 @@ Date Add Often useful it the ability to do some simple date calculations in your DQL query using -`MySql's DATE\_ADD function `_. +`MySql's DATE_ADD function `_. I'll skip the blah and show the code for this function: @@ -246,6 +246,6 @@ vendor sql functions and extend the DQL languages scope. Code for this Extension to DQL and other Doctrine Extensions can be found -`in my Github DoctrineExtensions repository `_. +`in the Github DoctrineExtensions repository `_. diff --git a/docs/en/cookbook/integrating-with-codeigniter.rst b/docs/en/cookbook/integrating-with-codeigniter.rst index 49c5403aaf0..83af5ca202a 100644 --- a/docs/en/cookbook/integrating-with-codeigniter.rst +++ b/docs/en/cookbook/integrating-with-codeigniter.rst @@ -110,8 +110,7 @@ production system you'll want to use a real caching system like APC, get rid of EchoSqlLogger, and turn off autoGenerateProxyClasses. -For more details, consult the -`Doctrine 2 Configuration documentation `_. +For more details, consult the :doc:`Doctrine 2 Configuration documentation `. Now to use it ------------- diff --git a/docs/en/cookbook/validation-of-entities.rst b/docs/en/cookbook/validation-of-entities.rst index 927d278a699..dd10b8b9afa 100644 --- a/docs/en/cookbook/validation-of-entities.rst +++ b/docs/en/cookbook/validation-of-entities.rst @@ -134,4 +134,4 @@ instances. This was already discussed in the previous blog post on the Versionable extension, which requires another type of event called "onFlush". -Further readings: :doc:`Lifecycle Events <../reference/events>` +Further readings: :ref:`reference-events-lifecycle-events` diff --git a/docs/en/reference/basic-mapping.rst b/docs/en/reference/basic-mapping.rst index d9a2769c005..91a8fef811c 100644 --- a/docs/en/reference/basic-mapping.rst +++ b/docs/en/reference/basic-mapping.rst @@ -270,7 +270,7 @@ A cookbook article shows how to define :doc:`your own custom mapping types .. warning:: All Date types assume that you are exclusively using the default timezone - set by `date_default_timezone_set() `_ + set by `date_default_timezone_set() `_ or by the php.ini configuration ``date.timezone``. Working with different timezones will cause troubles and unexpected behavior. diff --git a/docs/en/reference/configuration.rst b/docs/en/reference/configuration.rst index 2d7ff241bd6..3cd165cbd42 100644 --- a/docs/en/reference/configuration.rst +++ b/docs/en/reference/configuration.rst @@ -2,8 +2,7 @@ Installation and Configuration ============================== Doctrine can be installed with `Composer `_. For -older versions we still have `PEAR packages -`_. +older versions we still have `PEAR packages `_. Define the following requirement in your ``composer.json`` file: @@ -16,8 +15,7 @@ Define the following requirement in your ``composer.json`` file: } Then call ``composer install`` from your command line. If you don't know -how Composer works, check out their `Getting Started -`_ to set up. +how Composer works, check out their `Getting Started `_ to set up. Class loading ------------- @@ -93,8 +91,7 @@ Inside the ``Setup`` methods several assumptions are made: - If `$isDevMode` is false, set then proxy classes have to be explicitly created through the command line. - If third argument `$proxyDir` is not set, use the systems temporary directory. -If you want to configure Doctrine in more detail, take a look at the :doc:`Advanced -Configuration ` section. +If you want to configure Doctrine in more detail, take a look at the :doc:`Advanced Configuration ` section. .. note:: diff --git a/docs/en/reference/improving-performance.rst b/docs/en/reference/improving-performance.rst index d9de6c80863..d19b6947732 100644 --- a/docs/en/reference/improving-performance.rst +++ b/docs/en/reference/improving-performance.rst @@ -52,7 +52,7 @@ for more information on how this fetch mode works. Temporarily change fetch mode in DQL ------------------------------------ -See :ref:`Doctrine Query Language chapter ` +See :ref:`dql-temporarily-change-fetch-mode` Apply Best Practices diff --git a/docs/en/reference/installation.rst b/docs/en/reference/installation.rst index 8b732ad6058..fec83787eff 100644 --- a/docs/en/reference/installation.rst +++ b/docs/en/reference/installation.rst @@ -1,5 +1,4 @@ Installation ============ -The installation chapter has moved to `Installation and Configuration -`_. +The installation chapter has moved to :doc:`Installation and Configuration `_. diff --git a/docs/en/reference/limitations-and-known-issues.rst b/docs/en/reference/limitations-and-known-issues.rst index 8fd20e81978..143d53b64ae 100644 --- a/docs/en/reference/limitations-and-known-issues.rst +++ b/docs/en/reference/limitations-and-known-issues.rst @@ -116,7 +116,6 @@ blog posts we have written on this topics: - `A re-usable Versionable behavior for Doctrine2 `_ - `Write your own ORM on top of Doctrine2 `_ - `Doctrine 2 Behavioral Extensions `_ -- `Doctrator _ Doctrine 2 has enough hooks and extension points so that **you** can add whatever you want on top of it. None of this will ever become @@ -144,8 +143,7 @@ backwards compatibility issues or where no simple fix exists (yet). We don't plan to add every bug in the tracker there, just those issues that can potentially cause nightmares or pain of any sort. -See bugs, improvement and feature requests on `Github issues -`_. +See bugs, improvement and feature requests on `Github issues `_. Identifier Quoting and Legacy Databases ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/en/reference/query-builder.rst b/docs/en/reference/query-builder.rst index 1c65d8dc4a2..18199e7c55f 100644 --- a/docs/en/reference/query-builder.rst +++ b/docs/en/reference/query-builder.rst @@ -502,7 +502,7 @@ complete list of supported helper methods available: Adding a Criteria to a Query ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -You can also add a :ref:`Criteria ` to a QueryBuilder by +You can also add a :ref:`filtering-collections` to a QueryBuilder by using ``addCriteria``: .. code-block:: php diff --git a/docs/en/reference/second-level-cache.rst b/docs/en/reference/second-level-cache.rst index c4ae4f0ee7f..8a0b4c23102 100644 --- a/docs/en/reference/second-level-cache.rst +++ b/docs/en/reference/second-level-cache.rst @@ -97,7 +97,7 @@ Defines a contract for accessing a particular region. Defines a contract for accessing a particular cache region. -`See API Doc `_. +`See API Doc `_. Concurrent cache region ~~~~~~~~~~~~~~~~~~~~~~~ @@ -111,7 +111,7 @@ If you want to use an ``READ_WRITE`` cache, you should consider providing your o Defines contract for concurrently managed data region. -`See API Doc `_. +`See API Doc `_. Timestamp region ~~~~~~~~~~~~~~~~ @@ -120,7 +120,7 @@ Timestamp region Tracks the timestamps of the most recent updates to particular entity. -`See API Doc `_. +`See API Doc `_. .. _reference-second-level-cache-mode: @@ -209,7 +209,7 @@ It allows you to provide a specific implementation of the following components : * ``EntityHydrator`` Transform an entity into a cache entry and cache entry into entities * ``CollectionHydrator`` Transform a collection into a cache entry and cache entry into collection -`See API Doc `_. +`See API Doc `_. Region Lifetime ~~~~~~~~~~~~~~~ @@ -270,7 +270,7 @@ By providing a cache logger you should be able to get information about all cach If you want to get more information you should implement ``\Doctrine\ORM\Cache\Logging\CacheLogger``. and collect all information you want. -`See API Doc `_. +`See API Doc `_. Entity cache definition diff --git a/docs/en/reference/security.rst b/docs/en/reference/security.rst index bb5f0f8767c..0b0c880f737 100644 --- a/docs/en/reference/security.rst +++ b/docs/en/reference/security.rst @@ -10,7 +10,7 @@ we cannot protect you from SQL injection. Please also read the documentation chapter on Security in Doctrine DBAL. This page only handles Security issues in the ORM. -- [DBAL Security Page](https://github.com/doctrine/dbal/blob/master/docs/en/reference/security.rst) +- `DBAL Security Page ` If you find a Security bug in Doctrine, please report it on Jira and change the Security Level to "Security Issues". It will be visible to Doctrine Core diff --git a/docs/en/reference/working-with-objects.rst b/docs/en/reference/working-with-objects.rst index 6a33663c7c5..064c9e1f9e8 100644 --- a/docs/en/reference/working-with-objects.rst +++ b/docs/en/reference/working-with-objects.rst @@ -245,7 +245,7 @@ as follows: persist operation. However, the persist operation is cascaded to entities referenced by X, if the relationships from X to these other entities are mapped with cascade=PERSIST or cascade=ALL (see - ":ref:`Transitive Persistence `"). + ":ref:`transitive-persistence`"). - If X is a removed entity, it becomes managed. - If X is a detached entity, an exception will be thrown on flush. @@ -286,12 +286,12 @@ as follows: - If X is a new entity, it is ignored by the remove operation. However, the remove operation is cascaded to entities referenced by X, if the relationship from X to these other entities is mapped - with cascade=REMOVE or cascade=ALL (see ":ref:`Transitive Persistence `"). + with cascade=REMOVE or cascade=ALL (see ":ref:`transitive-persistence`"). - If X is a managed entity, the remove operation causes it to become removed. The remove operation is cascaded to entities referenced by X, if the relationships from X to these other entities is mapped with cascade=REMOVE or cascade=ALL (see - ":ref:`Transitive Persistence `"). + ":ref:`transitive-persistence`"). - If X is a detached entity, an InvalidArgumentException will be thrown. - If X is a removed entity, it is ignored by the remove operation. @@ -357,14 +357,14 @@ as follows: become detached. The detach operation is cascaded to entities referenced by X, if the relationships from X to these other entities is mapped with cascade=DETACH or cascade=ALL (see - ":ref:`Transitive Persistence `"). Entities which previously referenced X + ":ref:`transitive-persistence`"). Entities which previously referenced X will continue to reference X. - If X is a new or detached entity, it is ignored by the detach operation. - If X is a removed entity, the detach operation is cascaded to entities referenced by X, if the relationships from X to these other entities is mapped with cascade=DETACH or cascade=ALL (see - ":ref:`Transitive Persistence `"). Entities which previously referenced X + ":ref:`transitive-persistence`"). Entities which previously referenced X will continue to reference X. There are several situations in which an entity is detached @@ -423,7 +423,7 @@ as follows: - If X is a managed entity, it is ignored by the merge operation, however, the merge operation is cascaded to entities referenced by relationships from X if these relationships have been mapped with - the cascade element value MERGE or ALL (see ":ref:`Transitive Persistence `"). + the cascade element value MERGE or ALL (see ":ref:`transitive-persistence`"). - For all entities Y referenced by relationships from X having the cascade element value MERGE or ALL, Y is merged recursively as Y'. For all such Y referenced by X, X' is set to reference Y'. (Note diff --git a/docs/en/tutorials/getting-started-database.rst b/docs/en/tutorials/getting-started-database.rst index c625193aeb5..5a4883fae63 100644 --- a/docs/en/tutorials/getting-started-database.rst +++ b/docs/en/tutorials/getting-started-database.rst @@ -7,7 +7,7 @@ Getting Started: Database First start with developing Objects and then map them onto your database. When you :doc:`Model First `, you are modelling your application using tools (for example UML) and generate database schema and PHP code from this model. - When you have a :doc:`Database First `, you already have a database schema + When you have a Database First, you already have a database schema and generate the corresponding PHP code from it. .. note:: diff --git a/docs/en/tutorials/getting-started-models.rst b/docs/en/tutorials/getting-started-models.rst index e844b4d6865..01b71876299 100644 --- a/docs/en/tutorials/getting-started-models.rst +++ b/docs/en/tutorials/getting-started-models.rst @@ -5,7 +5,7 @@ Getting Started: Model First When you :doc:`Code First `, you start with developing Objects and then map them onto your database. When - you :doc:`Model First `, you are modelling your application using tools (for + you Model First, you are modelling your application using tools (for example UML) and generate database schema and PHP code from this model. When you have a :doc:`Database First `, then you already have a database schema and generate the corresponding PHP code from it. diff --git a/docs/en/tutorials/getting-started.rst b/docs/en/tutorials/getting-started.rst index 718eac5df05..0258d555977 100644 --- a/docs/en/tutorials/getting-started.rst +++ b/docs/en/tutorials/getting-started.rst @@ -31,9 +31,8 @@ The code of this tutorial is `available on Github `_ for PHP 5.4+ that -provides transparent persistence for PHP objects. It uses the Data Mapper +Doctrine 2 is an `object-relational mapper (ORM) `_ +for PHP 5.4+ that provides transparent persistence for PHP objects. It uses the Data Mapper pattern at the heart, aiming for a complete separation of your domain/business logic from the persistence in a relational database management system. @@ -62,7 +61,7 @@ An Example Model: Bug Tracker For this Getting Started Guide for Doctrine we will implement the Bug Tracker domain model from the -`Zend\_Db\_Table `_ +`Zend_Db_Table `_ documentation. Reading their documentation we can extract the requirements: @@ -169,7 +168,7 @@ read up on the configuration details in the The third block shows the configuration options required to connect to a database. In this case, we'll use a file-based SQLite database. All the configuration options for all the shipped drivers are given in the -`DBAL Configuration section of the manual `_. +`DBAL Configuration section of the manual `_. The last block shows how the ``EntityManager`` is obtained from a factory method. From aae00e3987de414c072be953b972bcff665d3ea5 Mon Sep 17 00:00:00 2001 From: Claudio Zizza Date: Sun, 11 Nov 2018 22:56:01 +0100 Subject: [PATCH 764/877] Fix of links and php version after review --- ...-field-value-conversion-using-custom-mapping-types.rst | 2 +- docs/en/cookbook/dql-user-defined-functions.rst | 2 +- docs/en/reference/architecture.rst | 2 +- docs/en/reference/configuration.rst | 5 ++--- docs/en/tutorials/getting-started.rst | 8 ++++---- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/docs/en/cookbook/advanced-field-value-conversion-using-custom-mapping-types.rst b/docs/en/cookbook/advanced-field-value-conversion-using-custom-mapping-types.rst index 4f26464c9a3..e5ca21632aa 100644 --- a/docs/en/cookbook/advanced-field-value-conversion-using-custom-mapping-types.rst +++ b/docs/en/cookbook/advanced-field-value-conversion-using-custom-mapping-types.rst @@ -204,7 +204,7 @@ This is where the ``convertToPHPValueSQL`` and ``convertToDatabaseValueSQL`` methods come into play. This methods wrap a sql expression (the WKT representation of the Point) into -MySQL functions `ST_PointFromText `_ +MySQL functions `ST_PointFromText `_ and `ST_AsText `_ which convert WKT strings to and from the internal format of MySQL. diff --git a/docs/en/cookbook/dql-user-defined-functions.rst b/docs/en/cookbook/dql-user-defined-functions.rst index 28465ee2df5..5c9b3e5d3fb 100644 --- a/docs/en/cookbook/dql-user-defined-functions.rst +++ b/docs/en/cookbook/dql-user-defined-functions.rst @@ -246,6 +246,6 @@ vendor sql functions and extend the DQL languages scope. Code for this Extension to DQL and other Doctrine Extensions can be found -`in the Github DoctrineExtensions repository `_. +`in the GitHub DoctrineExtensions repository `_. diff --git a/docs/en/reference/architecture.rst b/docs/en/reference/architecture.rst index 6d45befc630..708acbd5fc3 100644 --- a/docs/en/reference/architecture.rst +++ b/docs/en/reference/architecture.rst @@ -18,7 +18,7 @@ well. Requirements ------------ -Doctrine 2 requires a minimum of PHP 5.4. For greatly improved +Doctrine 2 requires a minimum of PHP 7.1. For greatly improved performance it is also recommended that you use APC with PHP. Doctrine 2 Packages diff --git a/docs/en/reference/configuration.rst b/docs/en/reference/configuration.rst index 3cd165cbd42..38775afdca4 100644 --- a/docs/en/reference/configuration.rst +++ b/docs/en/reference/configuration.rst @@ -1,8 +1,7 @@ Installation and Configuration ============================== -Doctrine can be installed with `Composer `_. For -older versions we still have `PEAR packages `_. +Doctrine can be installed with `Composer `_. Define the following requirement in your ``composer.json`` file: @@ -15,7 +14,7 @@ Define the following requirement in your ``composer.json`` file: } Then call ``composer install`` from your command line. If you don't know -how Composer works, check out their `Getting Started `_ to set up. +how Composer works, check out their `Getting Started `_ to set up. Class loading ------------- diff --git a/docs/en/tutorials/getting-started.rst b/docs/en/tutorials/getting-started.rst index 0258d555977..7caae8a98ee 100644 --- a/docs/en/tutorials/getting-started.rst +++ b/docs/en/tutorials/getting-started.rst @@ -19,7 +19,7 @@ installed: - PHP (latest stable version) - Composer Package Manager (`Install Composer - `_) + `_) The code of this tutorial is `available on Github `_. @@ -31,8 +31,8 @@ The code of this tutorial is `available on Github `_ -for PHP 5.4+ that provides transparent persistence for PHP objects. It uses the Data Mapper +Doctrine 2 is an `object-relational mapper (ORM) `_ +for PHP 7.1+ that provides transparent persistence for PHP objects. It uses the Data Mapper pattern at the heart, aiming for a complete separation of your domain/business logic from the persistence in a relational database management system. @@ -61,7 +61,7 @@ An Example Model: Bug Tracker For this Getting Started Guide for Doctrine we will implement the Bug Tracker domain model from the -`Zend_Db_Table `_ +`Zend_Db_Table `_ documentation. Reading their documentation we can extract the requirements: From c6eb4df25e19829cd88baa48ecdf9e8499dd2cdb Mon Sep 17 00:00:00 2001 From: Marc Plotz <30409909+batwolf@users.noreply.github.com> Date: Thu, 17 Jan 2019 10:14:56 +0100 Subject: [PATCH 765/877] fix typo `has to allow null values` vs `has to allows null values` --- docs/en/reference/inheritance-mapping.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/inheritance-mapping.rst b/docs/en/reference/inheritance-mapping.rst index d07eae1488f..4d21ac73b81 100644 --- a/docs/en/reference/inheritance-mapping.rst +++ b/docs/en/reference/inheritance-mapping.rst @@ -174,7 +174,7 @@ SQL Schema considerations For Single-Table-Inheritance to work in scenarios where you are using either a legacy database schema or a self-written database schema you have to make sure that all columns that are not in the -root entity but in any of the different sub-entities has to allows +root entity but in any of the different sub-entities has to allow null values. Columns that have NOT NULL constraints have to be on the root entity of the single-table inheritance hierarchy. From 580c530041ce51e408dd8c6fe8c9ac55f15a19dd Mon Sep 17 00:00:00 2001 From: Claudio Zizza Date: Thu, 17 Jan 2019 20:46:17 +0100 Subject: [PATCH 766/877] Remove codeigniter example from docs --- .../cookbook/integrating-with-codeigniter.rst | 139 ------------------ docs/en/index.rst | 3 - docs/en/toc.rst | 1 - 3 files changed, 143 deletions(-) delete mode 100644 docs/en/cookbook/integrating-with-codeigniter.rst diff --git a/docs/en/cookbook/integrating-with-codeigniter.rst b/docs/en/cookbook/integrating-with-codeigniter.rst deleted file mode 100644 index 83af5ca202a..00000000000 --- a/docs/en/cookbook/integrating-with-codeigniter.rst +++ /dev/null @@ -1,139 +0,0 @@ -Integrating with CodeIgniter -============================ - -This is recipe for using Doctrine 2 in your -`CodeIgniter `_ framework. - -.. note:: - - This might not work for all CodeIgniter versions and may require - slight adjustments. - - -Here is how to set it up: - -Make a CodeIgniter library that is both a wrapper and a bootstrap -for Doctrine 2. - -Setting up the file structure ------------------------------ - -Here are the steps: - - -- Add a php file to your system/application/libraries folder - called Doctrine.php. This is going to be your wrapper/bootstrap for - the D2 entity manager. -- Put the Doctrine folder (the one that contains Common, DBAL, and - ORM) inside that same libraries folder. -- Your system/application/libraries folder now looks like this: - - system/applications/libraries -Doctrine -Doctrine.php -index.html - -- If you want, open your config/autoload.php file and autoload - your Doctrine library. - - register(); - $entitiesClassLoader = new ClassLoader('models', rtrim(APPPATH, "/" )); - $entitiesClassLoader->register(); - $proxiesClassLoader = new ClassLoader('Proxies', APPPATH.'models/proxies'); - $proxiesClassLoader->register(); - - // Set up caches - $config = new Configuration; - $cache = new ArrayCache; - $config->setMetadataCacheImpl($cache); - $driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH.'models/Entities')); - $config->setMetadataDriverImpl($driverImpl); - $config->setQueryCacheImpl($cache); - - $config->setQueryCacheImpl($cache); - - // Proxy configuration - $config->setProxyDir(APPPATH.'/models/proxies'); - $config->setProxyNamespace('Proxies'); - - // Set up logger - $logger = new EchoSQLLogger; - $config->setSQLLogger($logger); - - $config->setAutoGenerateProxyClasses( TRUE ); - - // Database connection information - $connectionOptions = array( - 'driver' => 'pdo_mysql', - 'user' => $db['default']['username'], - 'password' => $db['default']['password'], - 'host' => $db['default']['hostname'], - 'dbname' => $db['default']['database'] - ); - - // Create EntityManager - $this->em = EntityManager::create($connectionOptions, $config); - } - } - -Please note that this is a development configuration; for a -production system you'll want to use a real caching system like -APC, get rid of EchoSqlLogger, and turn off -autoGenerateProxyClasses. - -For more details, consult the :doc:`Doctrine 2 Configuration documentation `. - -Now to use it -------------- - -Whenever you need a reference to the entity manager inside one of -your controllers, views, or models you can do this: - -.. code-block:: php - - doctrine->em; - -That's all there is to it. Once you get the reference to your -EntityManager do your Doctrine 2.0 voodoo as normal. - -Note: If you do not choose to autoload the Doctrine library, you -will need to put this line before you get a reference to it: - -.. code-block:: php - - load->library('doctrine'); - -Good luck! - - diff --git a/docs/en/index.rst b/docs/en/index.rst index 4c50484e4a5..0cea054dacb 100644 --- a/docs/en/index.rst +++ b/docs/en/index.rst @@ -118,9 +118,6 @@ Cookbook :doc:`Entities in the Session ` | :doc:`Keeping your Modules independent ` -* **Integration into Frameworks/Libraries** - :doc:`CodeIgniter ` - * **Hidden Gems** :doc:`Prefixing Table Name ` diff --git a/docs/en/toc.rst b/docs/en/toc.rst index 0df70414f68..2309d569712 100644 --- a/docs/en/toc.rst +++ b/docs/en/toc.rst @@ -75,7 +75,6 @@ Cookbook cookbook/implementing-arrayaccess-for-domain-objects cookbook/implementing-the-notify-changetracking-policy cookbook/implementing-wakeup-or-clone - cookbook/integrating-with-codeigniter cookbook/resolve-target-entity-listener cookbook/sql-table-prefixes cookbook/strategy-cookbook-introduction From 5c5f310646f067bc8c430d5449d823d556ef64ab Mon Sep 17 00:00:00 2001 From: Claudio Zizza Date: Tue, 22 Jan 2019 22:42:13 +0100 Subject: [PATCH 767/877] Fix of link to dbal docs --- docs/en/reference/advanced-configuration.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/advanced-configuration.rst b/docs/en/reference/advanced-configuration.rst index 00f8f89696b..0ddb6ef9c48 100644 --- a/docs/en/reference/advanced-configuration.rst +++ b/docs/en/reference/advanced-configuration.rst @@ -292,7 +292,7 @@ instance of ``Doctrine\DBAL\Connection``. If an array is passed it is directly passed along to the DBAL Factory ``Doctrine\DBAL\DriverManager::getConnection()``. The DBAL configuration is explained in the -`DBAL section <./../../../../../projects/doctrine-dbal/en/latest/reference/configuration.html>`_. +`DBAL section `_. Proxy Objects ------------- From 624ee780811dbc953f629edb0fec239e974fe669 Mon Sep 17 00:00:00 2001 From: Michael Bessolov Date: Fri, 8 Feb 2019 22:29:10 -0800 Subject: [PATCH 768/877] Correct method names and broken link in docs This basically applying the same documentation fix as in #7335 (master) to 2.6 branch --- docs/en/reference/caching.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/en/reference/caching.rst b/docs/en/reference/caching.rst index 4423fb130f7..b8f956f4a6f 100644 --- a/docs/en/reference/caching.rst +++ b/docs/en/reference/caching.rst @@ -29,10 +29,10 @@ abstract protected methods that each of the drivers must implement: -- \_doFetch($id) -- \_doContains($id) -- \_doSave($id, $data, $lifeTime = false) -- \_doDelete($id) +- doFetch($id) +- doContains($id) +- doSave($id, $data, $lifeTime = false) +- doDelete($id) The public methods ``fetch()``, ``contains()`` etc. use the above protected methods which are implemented by the drivers. The @@ -43,7 +43,7 @@ these methods. This documentation does not cover every single cache driver included with Doctrine. For an up-to-date-list, see the -`cache directory on GitHub `. +`cache directory on GitHub `_. APC ~~~ From 2ba6e473de4a6f67ff86e1d9d3155531f46e4f9a Mon Sep 17 00:00:00 2001 From: Sumit Chahal Date: Sat, 16 Feb 2019 16:44:21 +0530 Subject: [PATCH 769/877] Change APC to OPcache in improving-performance.rst OPcache is a lot better supported now than APC, which is apparently not maintained anymore. --- docs/en/reference/improving-performance.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/improving-performance.rst b/docs/en/reference/improving-performance.rst index d19b6947732..23767a2f861 100644 --- a/docs/en/reference/improving-performance.rst +++ b/docs/en/reference/improving-performance.rst @@ -4,7 +4,7 @@ Improving Performance Bytecode Cache -------------- -It is highly recommended to make use of a bytecode cache like APC. +It is highly recommended to make use of a bytecode cache like OPcache. A bytecode cache removes the need for parsing PHP code on every request and can greatly improve performance. From b537758b321e43eba823b7226b545636d5ab6d79 Mon Sep 17 00:00:00 2001 From: Sergiu Pirlici Date: Sat, 16 Feb 2019 15:04:45 +0200 Subject: [PATCH 770/877] Update ordered-associations.rst Fixed some typos --- docs/en/tutorials/ordered-associations.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/en/tutorials/ordered-associations.rst b/docs/en/tutorials/ordered-associations.rst index 121bd145d57..cb0e64a498a 100644 --- a/docs/en/tutorials/ordered-associations.rst +++ b/docs/en/tutorials/ordered-associations.rst @@ -5,8 +5,8 @@ There are use-cases when you'll want to sort collections when they are retrieved from the database. In userland you do this as long as you haven't initially saved an entity with its associations into the database. To retrieve a sorted collection from the database you can -use the ``@OrderBy`` annotation with an collection that specifies -an DQL snippet that is appended to all queries with this +use the ``@OrderBy`` annotation with a collection that specifies +a DQL snippet that is appended to all queries with this collection. Additional to any ``@OneToMany`` or ``@ManyToMany`` annotation you @@ -64,7 +64,7 @@ positional statement. Multiple Fields are separated by a comma (,). The referenced field names have to exist on the ``targetEntity`` class of the ``@ManyToMany`` or ``@OneToMany`` annotation. -The semantics of this feature can be described as follows. +The semantics of this feature can be described as follows: - ``@OrderBy`` acts as an implicit ORDER BY clause for the given @@ -73,7 +73,7 @@ The semantics of this feature can be described as follows. - All collections of the ordered type are always retrieved in an ordered fashion. - To keep the database impact low, these implicit ORDER BY items - are only added to an DQL Query if the collection is fetch joined in + are only added to a DQL Query if the collection is fetch joined in the DQL query. Given our previously defined example, the following would not add From d91e0b3867de6ed94f6369a906b79cc7914c10cc Mon Sep 17 00:00:00 2001 From: yethee Date: Thu, 28 Feb 2019 17:11:54 +0300 Subject: [PATCH 771/877] Failing tests --- .../ORM/Functional/Ticket/GH7629Test.php | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH7629Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7629Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7629Test.php new file mode 100644 index 00000000000..a0c100acaaa --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7629Test.php @@ -0,0 +1,48 @@ +setUpEntitySchema([ + GH7629Entity::class, + ]); + + $this->_em->persist(new GH7629Entity()); + $this->_em->flush(); + $this->_em->clear(); + } + + public function testClearScheduledForSynchronizationWhenCommitEmpty(): void + { + $entity = $this->_em->find(GH7629Entity::class, 1); + + $this->_em->persist($entity); + $this->_em->flush(); + + self::assertFalse($this->_em->getUnitOfWork()->isScheduledForDirtyCheck($entity)); + } +} + +/** + * @Entity + * @ChangeTrackingPolicy("DEFERRED_EXPLICIT") + */ +class GH7629Entity +{ + /** + * @Id + * @Column(type="integer") + * @GeneratedValue + */ + public $id; +} From 7f5f4629e575478725424c48a9278fb151fe3092 Mon Sep 17 00:00:00 2001 From: yethee Date: Fri, 1 Mar 2019 23:00:01 +0300 Subject: [PATCH 772/877] Ensure state is cleanup after empty commit --- lib/Doctrine/ORM/UnitOfWork.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index c79afd084ee..0fb3d8a06e1 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -356,6 +356,8 @@ public function commit($entity = null) $this->dispatchOnFlushEvent(); $this->dispatchPostFlushEvent(); + $this->postCommitCleanup($entity); + return; // Nothing to do. } From 180cfcc3e33aa4f919f11a2d669c9186d7c7fccf Mon Sep 17 00:00:00 2001 From: Darryl Hein Date: Sun, 28 Apr 2019 21:07:22 -0600 Subject: [PATCH 773/877] change variable name to make it consistent throughout document --- docs/en/reference/native-sql.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/native-sql.rst b/docs/en/reference/native-sql.rst index fe633aea655..1676a8f596d 100644 --- a/docs/en/reference/native-sql.rst +++ b/docs/en/reference/native-sql.rst @@ -92,7 +92,7 @@ a mapping from DQL alias (key) to SQL alias (value) generateSelectClause(array( + $selectClause = $rsm->generateSelectClause(array( 'u' => 't1', 'g' => 't2' )); From c721ab63ee3ccf15d4dc2cf43dafe815a2781b76 Mon Sep 17 00:00:00 2001 From: Joppe de Cuyper Date: Mon, 3 Jun 2019 20:20:03 +0200 Subject: [PATCH 774/877] Update DATE_ADD and DATE_SUB docs --- docs/en/reference/dql-doctrine-query-language.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/reference/dql-doctrine-query-language.rst b/docs/en/reference/dql-doctrine-query-language.rst index bc5097dddca..5da8b1bb163 100644 --- a/docs/en/reference/dql-doctrine-query-language.rst +++ b/docs/en/reference/dql-doctrine-query-language.rst @@ -691,8 +691,8 @@ clauses: - TRIM([LEADING \| TRAILING \| BOTH] ['trchar' FROM] str) - Trim the string by the given trim char, defaults to whitespaces. - UPPER(str) - Return the upper-case of the given string. -- DATE_ADD(date, days, unit) - Add the number of days to a given date. (Supported units are DAY, MONTH) -- DATE_SUB(date, days, unit) - Substract the number of days from a given date. (Supported units are DAY, MONTH) +- DATE_ADD(date, value, unit) - Add the given time to a given date. (Supported units are SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR) +- DATE_SUB(date, value, unit) - Subtract the given time from a given date. (Supported units are SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR) - DATE_DIFF(date1, date2) - Calculate the difference in days between date1-date2. Arithmetic operators From a98ebf7344f40602abda11d85da6837cd8cb6a21 Mon Sep 17 00:00:00 2001 From: Joppe de Cuyper Date: Mon, 3 Jun 2019 20:21:19 +0200 Subject: [PATCH 775/877] Whitespace fixes --- docs/en/reference/dql-doctrine-query-language.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/en/reference/dql-doctrine-query-language.rst b/docs/en/reference/dql-doctrine-query-language.rst index 5da8b1bb163..58ec834659f 100644 --- a/docs/en/reference/dql-doctrine-query-language.rst +++ b/docs/en/reference/dql-doctrine-query-language.rst @@ -103,9 +103,9 @@ their inclusion in the SELECT clause. In this case, the result will be an array of arrays. In the example above, each element of the result array would be an array of the -scalar name and address values. +scalar name and address values. -You can select scalars from any entity in the query. +You can select scalars from any entity in the query. **Mixed** @@ -1172,7 +1172,7 @@ why we are listing as many of the assumptions here for reference: - If an object is already in memory from a previous query of any kind, then then the previous object is used, even if the database may contain more recent data. Data from the database is discarded. This even happens if the - previous object is still an unloaded proxy. + previous object is still an unloaded proxy. This list might be incomplete. @@ -1452,10 +1452,10 @@ Given that there are 10 users and corresponding addresses in the database the ex SELECT * FROM address WHERE id IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10); .. note:: - Changing the fetch mode during a query mostly makes sense for one-to-one and many-to-one relations. In that case, + Changing the fetch mode during a query mostly makes sense for one-to-one and many-to-one relations. In that case, all the necessary IDs are available after the root entity (``user`` in the above example) has been loaded. So, one query per association can be executed to fetch all the referred-to entities (``address``). - + For one-to-many relations, changing the fetch mode to eager will cause to execute one query **for every root entity loaded**. This gives no improvement over the ``lazy`` fetch mode which will also initialize the associations on a one-by-one basis once they are accessed. From bd9ead11c53ab8066a24217a0f083dbc92fea16b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Mon, 3 Jun 2019 22:02:48 +0200 Subject: [PATCH 776/877] Replace custom install script with add-on Following this documentation: https://docs.travis-ci.com/user/database-setup/#mysql-57 found via https://stackoverflow.com/a/49542847/353612 --- .travis.yml | 21 +++++++++++++++++++++ tests/travis/install-mysql-5.7.sh | 18 ++---------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4f2325b4628..03bbf32ea70 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,6 +34,13 @@ jobs: - stage: Test env: DB=mysql MYSQL_VERSION=5.7 php: 7.1 + addons: + apt: + sources: + - mysql-5.7-trusty + packages: + - mysql-server + - mysql-client before_script: - ./tests/travis/install-mysql-$MYSQL_VERSION.sh sudo: required @@ -41,6 +48,13 @@ jobs: - stage: Test env: DB=mysql MYSQL_VERSION=5.7 php: 7.2 + addons: + apt: + sources: + - mysql-5.7-trusty + packages: + - mysql-server + - mysql-client before_script: - ./tests/travis/install-mysql-$MYSQL_VERSION.sh sudo: required @@ -48,6 +62,13 @@ jobs: - stage: Test env: DB=mysql MYSQL_VERSION=5.7 php: nightly + addons: + apt: + sources: + - mysql-5.7-trusty + packages: + - mysql-server + - mysql-client before_script: - ./tests/travis/install-mysql-$MYSQL_VERSION.sh sudo: required diff --git a/tests/travis/install-mysql-5.7.sh b/tests/travis/install-mysql-5.7.sh index 66b0d1ecf1f..9dbd6edfd2f 100755 --- a/tests/travis/install-mysql-5.7.sh +++ b/tests/travis/install-mysql-5.7.sh @@ -2,21 +2,7 @@ set -ex -echo "Installing MySQL 5.7..." - -sudo service mysql stop -sudo apt-get remove "^mysql.*" -sudo apt-get autoremove -sudo apt-get autoclean -echo mysql-apt-config mysql-apt-config/select-server select mysql-5.7 | sudo debconf-set-selections -wget http://dev.mysql.com/get/mysql-apt-config_0.8.6-1_all.deb -sudo DEBIAN_FRONTEND=noninteractive dpkg -i mysql-apt-config_0.8.6-1_all.deb -sudo rm -rf /var/lib/apt/lists/* -sudo apt-get clean -sudo apt-get update -q -sudo apt-get install -q -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" mysql-server libmysqlclient-dev -sudo mysql_upgrade - echo "Restart mysql..." sudo mysql -e "use mysql; update user set authentication_string=PASSWORD('') where User='root'; update user set plugin='mysql_native_password';FLUSH PRIVILEGES;" - +sudo mysql_upgrade -u root +sudo service mysql restart From 145cc782ff0daf67e39d762c1573732f0f766c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Chru=C5=9Bciel?= Date: Tue, 4 Jun 2019 17:38:26 +0200 Subject: [PATCH 777/877] [Documentation] Missing comma fix --- docs/en/reference/annotations-reference.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/annotations-reference.rst b/docs/en/reference/annotations-reference.rst index ed40dbdb1b2..20381da5985 100644 --- a/docs/en/reference/annotations-reference.rst +++ b/docs/en/reference/annotations-reference.rst @@ -181,7 +181,7 @@ Examples: protected $initials; /** - * @Column(type="integer", name="login_count" nullable=false, options={"unsigned":true, "default":0}) + * @Column(type="integer", name="login_count", nullable=false, options={"unsigned":true, "default":0}) */ protected $loginCount; From 5612790307dd4172e8ccbe1e9a2b4c390c05c6a4 Mon Sep 17 00:00:00 2001 From: Victor Bocharsky Date: Tue, 11 Jun 2019 13:19:56 +0300 Subject: [PATCH 778/877] Start i var from 1 instead of 0 Because (0 % $batchSize) === 0 but we don't want to execute flush() and clear() on the first iteration. --- docs/en/reference/batch-processing.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/reference/batch-processing.rst b/docs/en/reference/batch-processing.rst index ce47c538c29..4076f4fb9fb 100644 --- a/docs/en/reference/batch-processing.rst +++ b/docs/en/reference/batch-processing.rst @@ -75,7 +75,7 @@ with the batching strategy that was already used for bulk inserts: createQuery('select u from MyProject\Model\User u'); $iterableResult = $q->iterate(); foreach ($iterableResult as $row) { @@ -136,7 +136,7 @@ The following example shows how to do this: createQuery('select u from MyProject\Model\User u'); $iterableResult = $q->iterate(); while (($row = $iterableResult->next()) !== false) { From 4f8a1f92a31a3e01ee76c899e0fc2da5ac76daae Mon Sep 17 00:00:00 2001 From: Olumide Samson Date: Mon, 17 Jun 2019 09:00:45 +0100 Subject: [PATCH 779/877] Fixed a typo-error exploitet changed to exploited --- docs/en/reference/security.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/security.rst b/docs/en/reference/security.rst index 0b0c880f737..0101e860f8f 100644 --- a/docs/en/reference/security.rst +++ b/docs/en/reference/security.rst @@ -119,7 +119,7 @@ entity might look like this: } Now the possiblity of mass-asignment exists on this entity and can -be exploitet by attackers to set the "isAdmin" flag to true on any +be exploited by attackers to set the "isAdmin" flag to true on any object when you pass the whole request data to this method like: .. code-block:: php From c777aa62b61d6d689d9c3be883c8e0eb73d13294 Mon Sep 17 00:00:00 2001 From: Claudio Zizza Date: Sun, 23 Jun 2019 23:39:41 +0200 Subject: [PATCH 780/877] Fix of ORM annotation in examples --- docs/en/tutorials/getting-started.rst | 130 +++++++++++++++++--------- 1 file changed, 87 insertions(+), 43 deletions(-) diff --git a/docs/en/tutorials/getting-started.rst b/docs/en/tutorials/getting-started.rst index 7caae8a98ee..3ff75f5d91f 100644 --- a/docs/en/tutorials/getting-started.rst +++ b/docs/en/tutorials/getting-started.rst @@ -283,14 +283,24 @@ but you only need to choose one. Date: Mon, 24 Jun 2019 22:07:56 +0200 Subject: [PATCH 781/877] Fixed grammatical mistake in doc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Grégoire Paris --- docs/en/reference/dql-doctrine-query-language.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/dql-doctrine-query-language.rst b/docs/en/reference/dql-doctrine-query-language.rst index 55c6131343e..e4bb1ec1f3d 100644 --- a/docs/en/reference/dql-doctrine-query-language.rst +++ b/docs/en/reference/dql-doctrine-query-language.rst @@ -997,7 +997,7 @@ the Query class. Here they are: is thrown. If the result contains no objects, an ``NoResultException`` is thrown. The pure/mixed distinction does not apply. - ``Query#getOneOrNullResult()``: Retrieve a single object. If the - result contains more than one object, an ``NonUniqueResultException`` + result contains more than one object, a ``NonUniqueResultException`` is thrown. If no object is found null will be returned. - ``Query#getArrayResult()``: Retrieves an array graph (a nested array) that is largely interchangeable with the object graph From 3fbf163d3483e7a46dd8746be503b90eac914cd8 Mon Sep 17 00:00:00 2001 From: Cyril PASCAL Date: Wed, 26 Jun 2019 14:16:25 +0200 Subject: [PATCH 782/877] Do not modify UOW on PersistentCollection::clear() when owner has DEFFERED_EXPLICIT change tracking policy --- lib/Doctrine/ORM/PersistentCollection.php | 5 ++++- .../Tests/ORM/PersistentCollectionTest.php | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index 4ea56f55b57..104671ec62c 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -25,6 +25,7 @@ use Doctrine\Common\Collections\Selectable; use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\Mapping\ClassMetadata; +use function get_class; /** * A PersistentCollection represents a collection of elements that have persistent state. @@ -565,7 +566,9 @@ public function clear() if ($this->association['isOwningSide'] && $this->owner) { $this->changed(); - $uow->scheduleCollectionDeletion($this); + if (! $this->em->getClassMetadata(get_class($this->owner))->isChangeTrackingDeferredExplicit()) { + $uow->scheduleCollectionDeletion($this); + } $this->takeSnapshot(); } diff --git a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php index 38be94522a7..179d6e9d517 100644 --- a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\PersistentCollection; use Doctrine\ORM\UnitOfWork; use Doctrine\Tests\Mocks\ConnectionMock; @@ -264,4 +265,25 @@ public function testWillNotMarkCollectionAsDirtyAfterInitializationIfNoElementsW self::assertTrue($this->collection->isInitialized()); self::assertFalse($this->collection->isDirty()); } + + public function testModifyUOWForDeferredImplicitOwnerOnClear() : void + { + $unitOfWork = $this->createMock(UnitOfWork::class); + $unitOfWork->expects(self::once())->method('scheduleCollectionDeletion'); + $this->_emMock->setUnitOfWork($unitOfWork); + + $this->collection->clear(); + } + + public function testDoNotModifyUOWForDeferredExplicitOwnerOnClear() : void + { + $unitOfWork = $this->createMock(UnitOfWork::class); + $unitOfWork->expects(self::never())->method('scheduleCollectionDeletion'); + $this->_emMock->setUnitOfWork($unitOfWork); + + $classMetaData = $this->_emMock->getClassMetadata(ECommerceCart::class); + $classMetaData->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_EXPLICIT); + + $this->collection->clear(); + } } From a42191eecfa20822d784f911f115c4d9b5970fb1 Mon Sep 17 00:00:00 2001 From: Cyril PASCAL Date: Fri, 19 Jul 2019 15:38:13 +0200 Subject: [PATCH 783/877] Add functional test for ArrayCollection::clear() bug --- .../ORM/Functional/Ticket/GH7761Test.php | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH7761Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7761Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7761Test.php new file mode 100644 index 00000000000..53215cf0546 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7761Test.php @@ -0,0 +1,91 @@ +setUpEntitySchema([ + GH7761Entity::class, + GH7761ChildEntity::class, + ]); + + $parent = new GH7761Entity(); + $child = new GH7761ChildEntity(); + $parent->children->add($child); + + $this->_em->persist($parent); + $this->_em->persist($child); + $this->_em->flush(); + $this->_em->clear(); + } + + public function testCollectionClearDoesNotClearIfNotPersisted() : void + { + /** @var GH7761Entity $entity */ + $entity = $this->_em->find(GH7761Entity::class, 1); + $entity->children->clear(); + $this->_em->persist(new GH7761Entity()); + $this->_em->flush(); + + $this->_em->clear(); + + $entity = $this->_em->find(GH7761Entity::class, 1); + self::assertCount(1, $entity->children); + + $this->_em->clear(); + } +} + +/** + * @Entity + * @ChangeTrackingPolicy("DEFERRED_EXPLICIT") + */ +class GH7761Entity +{ + /** + * @Id + * @Column(type="integer") + * @GeneratedValue + */ + public $id; + + /** + * @ManyToMany(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\GH7761ChildEntity", cascade={"all"}) + * @JoinTable(name="gh7761_to_child", + * joinColumns={@JoinColumn(name="entity_id")}, + * inverseJoinColumns={@JoinColumn(name="child_id")} + * ) + */ + public $children; + + public function __construct() + { + $this->children = new ArrayCollection(); + } +} + +/** + * @Entity + * @ChangeTrackingPolicy("DEFERRED_EXPLICIT") + */ +class GH7761ChildEntity +{ + /** + * @Id + * @Column(type="integer") + * @GeneratedValue + */ + public $id; +} From 33904cb9c122a1438fe4c70165cd9d727177ba94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 11 Aug 2019 23:12:08 +0200 Subject: [PATCH 784/877] Fix test compatibility with DBAL 2.10.x-dev --- .../Tests/ORM/Tools/SchemaToolTest.php | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php index ea520d8fc73..24415af92e6 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php @@ -47,21 +47,22 @@ public function testAddUniqueIndexForUniqueFieldAnnotation() $this->assertTrue($schema->getTable('cms_users')->columnsAreIndexed(['username']), "username column should be indexed."); } - public function testAnnotationOptionsAttribute() + public function testAnnotationOptionsAttribute() : void { $em = $this->_getTestEntityManager(); $schemaTool = new SchemaTool($em); - $classes = [ - $em->getClassMetadata(TestEntityWithAnnotationOptionsAttribute::class), - ]; - - $schema = $schemaTool->getSchemaFromMetadata($classes); - - $expected = ['foo' => 'bar', 'baz' => ['key' => 'val']]; + $schema = $schemaTool->getSchemaFromMetadata( + [$em->getClassMetadata(TestEntityWithAnnotationOptionsAttribute::class)] + ); + $table = $schema->getTable('TestEntityWithAnnotationOptionsAttribute'); - $this->assertEquals($expected, $schema->getTable('TestEntityWithAnnotationOptionsAttribute')->getOptions(), "options annotation are passed to the tables options"); - $this->assertEquals($expected, $schema->getTable('TestEntityWithAnnotationOptionsAttribute')->getColumn('test')->getCustomSchemaOptions(), "options annotation are passed to the columns customSchemaOptions"); + foreach ([$table->getOptions(), $table->getColumn('test')->getCustomSchemaOptions()] as $options) { + self::assertArrayHasKey('foo', $options); + self::assertSame('bar', $options['foo']); + self::assertArrayHasKey('baz', $options); + self::assertSame(['key' => 'val'], $options['baz']); + } } /** From 869b70e4db74dc4e0b2eeb1d1a63235aaec67a4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 11 Aug 2019 23:27:31 +0200 Subject: [PATCH 785/877] Use Ubuntu Xenial for MySQL 5.7 build Since July 21st 2019 it's no longer possible to install MySQL 5.7 in Ubuntu Trusty. More info: https://docs.travis-ci.com/user/database-setup/#mysql-57 --- .travis.yml | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/.travis.yml b/.travis.yml index 03bbf32ea70..9ab5b852d10 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,43 +32,31 @@ jobs: mariadb: 10.1 - stage: Test + dist: xenial env: DB=mysql MYSQL_VERSION=5.7 php: 7.1 - addons: - apt: - sources: - - mysql-5.7-trusty - packages: - - mysql-server - - mysql-client + services: + - mysql before_script: - ./tests/travis/install-mysql-$MYSQL_VERSION.sh sudo: required - stage: Test + dist: xenial env: DB=mysql MYSQL_VERSION=5.7 php: 7.2 - addons: - apt: - sources: - - mysql-5.7-trusty - packages: - - mysql-server - - mysql-client + services: + - mysql before_script: - ./tests/travis/install-mysql-$MYSQL_VERSION.sh sudo: required - stage: Test + dist: xenial env: DB=mysql MYSQL_VERSION=5.7 php: nightly - addons: - apt: - sources: - - mysql-5.7-trusty - packages: - - mysql-server - - mysql-client + services: + - mysql before_script: - ./tests/travis/install-mysql-$MYSQL_VERSION.sh sudo: required From e8f91434a762ba5463318f36b1b19e39878c9efc Mon Sep 17 00:00:00 2001 From: "A.Kuterev" Date: Thu, 20 Jun 2019 17:28:04 +0300 Subject: [PATCH 786/877] Avoid reusing variable name The same variable name is used below, and that causes a bug etc. Fixes https://github.com/doctrine/orm/issues/7735 --- .../Entity/AbstractEntityPersister.php | 6 +- .../ORM/Functional/Ticket/GH7735Test.php | 172 ++++++++++++++++++ 2 files changed, 176 insertions(+), 2 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH7735Test.php diff --git a/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php b/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php index 53ea6a6fded..05484120ec4 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php @@ -452,12 +452,14 @@ public function loadById(array $identifier, $entity = null) $class = $this->metadataFactory->getMetadataFor($cacheEntry->class); } - if (($entity = $this->hydrator->loadCacheEntry($class, $cacheKey, $cacheEntry, $entity)) !== null) { + $cachedEntity = $this->hydrator->loadCacheEntry($class, $cacheKey, $cacheEntry, $entity); + + if ($cachedEntity !== null) { if ($this->cacheLogger) { $this->cacheLogger->entityCacheHit($this->regionName, $cacheKey); } - return $entity; + return $cachedEntity; } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7735Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7735Test.php new file mode 100644 index 00000000000..52a10dc6435 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7735Test.php @@ -0,0 +1,172 @@ +enableSecondLevelCache(); + parent::setUp(); + + $this->_schemaTool->createSchema( + [ + $this->_em->getClassMetadata(GH7735Car::class), + $this->_em->getClassMetadata(GH7735Power::class), + $this->_em->getClassMetadata(GH7735Engine::class), + ] + ); + + $this->_em->persist(new GH7735Car(1, new GH7735Engine(1, 'turbo', new GH7735Power(1)))); + $this->_em->flush(); + $this->_em->clear(); + } + + /** + * @test + * @group GH7735 + */ + public function findByReturnsCachedEntity() : void + { + $this->_em->getCache()->evictEntityRegion(GH7735Power::class); + + $car = $this->_em->find(GH7735Car::class, 1); + assert($car instanceof GH7735Car); + + self::assertSame('turbo', $car->getEngine()->getModel()); + self::assertSame(1, $car->getEngine()->getPower()->getId()); + } +} + +/** + * @Entity @Cache(usage="READ_ONLY") + */ +class GH7735Car +{ + /** + * @Id + * @Column(type="integer") + * @var int + */ + private $id; + + /** + * @ManyToOne(targetEntity=GH7735Engine::class, cascade={"all"}) + * @JoinColumn(nullable=false) + * @Cache("READ_ONLY") + * @var GH7735Engine + */ + private $engine; + + public function __construct(int $id, GH7735Engine $engine) + { + $this->id = $id; + $this->engine = $engine; + } + + public function getId() : int + { + return $this->id; + } + + public function getEngine() : GH7735Engine + { + return $this->engine; + } +} + +/** + * @Entity + * @Cache(usage="READ_ONLY") + */ +class GH7735Engine +{ + /** + * @Id + * @Column(type="integer") + * @var int + */ + private $id; + + /** + * @OneToOne(targetEntity=GH7735Power::class, mappedBy="engine", cascade={"all"}) + * @Cache("READ_ONLY") + * @var GH7735Power + */ + private $power; + + /** + * @Column + * @var string + */ + private $model; + + public function __construct(int $id, string $model, GH7735Power $power) + { + $this->id = $id; + $this->model = $model; + $this->power = $power; + + $power->setEngine($this); + } + + public function getId() : int + { + return $this->id; + } + + public function getPower() : GH7735Power + { + return $this->power; + } + + public function getModel() : string + { + return $this->model; + } +} + +/** + * @Entity + * @Cache(usage="READ_ONLY") + */ +class GH7735Power +{ + /** + * @Id + * @Column(type="integer") + */ + private $id; + + /** + * @OneToOne(targetEntity=GH7735Engine::class, inversedBy="power") + * @Cache("READ_ONLY") + * @var GH7735Engine + */ + private $engine; + + public function __construct(int $id) + { + $this->id = $id; + } + + public function getId() : int + { + return $this->id; + } + + public function setEngine(GH7735Engine $engine) : void + { + $this->engine = $engine; + } + + public function getEngine() : GH7735Engine + { + return $this->engine; + } +} From e51666e8be9e4bd1e84684e4f94ca67f352a006f Mon Sep 17 00:00:00 2001 From: Stephan Schuler Date: Mon, 1 Jul 2019 22:15:10 +0200 Subject: [PATCH 787/877] Fix PersistentCollection::matching() not respecting collection ordering The ordering of a Criteria is prefered over the collections default ordering. The default collection ordering used as additional sorting attributes. --- lib/Doctrine/ORM/PersistentCollection.php | 2 + .../ORM/Functional/Ticket/GH7767Test.php | 110 ++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH7767Test.php diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index 104671ec62c..88be1a69361 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -25,6 +25,7 @@ use Doctrine\Common\Collections\Selectable; use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\Mapping\ClassMetadata; +use function array_merge; use function get_class; /** @@ -671,6 +672,7 @@ public function matching(Criteria $criteria) $criteria = clone $criteria; $criteria->where($expression); + $criteria->orderBy(array_merge($this->association['orderBy'] ?? [], $criteria->getOrderings())); $persister = $this->em->getUnitOfWork()->getEntityPersister($this->association['targetEntity']); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7767Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7767Test.php new file mode 100644 index 00000000000..01f12f32159 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7767Test.php @@ -0,0 +1,110 @@ +setUpEntitySchema([GH7767ParentEntity::class, GH7767ChildEntity::class]); + + $parent = new GH7767ParentEntity(); + $parent->addChild(200); + $parent->addChild(100); + $parent->addChild(300); + + $this->_em->persist($parent); + $this->_em->flush(); + $this->_em->clear(); + } + + public function testMatchingRespectsCollectionOrdering() : void + { + $parent = $this->_em->find(GH7767ParentEntity::class, 1); + assert($parent instanceof GH7767ParentEntity); + + $children = $parent->getChildren()->matching(Criteria::create()); + + self::assertEquals(100, $children[0]->position); + self::assertEquals(200, $children[1]->position); + self::assertEquals(300, $children[2]->position); + } + + public function testMatchingOverrulesCollectionOrdering() : void + { + $parent = $this->_em->find(GH7767ParentEntity::class, 1); + assert($parent instanceof GH7767ParentEntity); + + $children = $parent->getChildren()->matching(Criteria::create()->orderBy(['position' => 'DESC'])); + + self::assertEquals(300, $children[0]->position); + self::assertEquals(200, $children[1]->position); + self::assertEquals(100, $children[2]->position); + } +} + +/** + * @Entity + */ +class GH7767ParentEntity +{ + /** + * @Id + * @Column(type="integer") + * @GeneratedValue + */ + private $id; + + /** + * @OneToMany(targetEntity=GH7767ChildEntity::class, mappedBy="parent", fetch="EXTRA_LAZY", cascade={"persist"}) + * @OrderBy({"position" = "ASC"}) + */ + private $children; + + public function addChild(int $position) : void + { + $this->children[] = new GH7767ChildEntity($this, $position); + } + + public function getChildren() : PersistentCollection + { + return $this->children; + } +} + +/** + * @Entity + */ +class GH7767ChildEntity +{ + /** + * @Id + * @Column(type="integer") + * @GeneratedValue + */ + private $id; + + /** @Column(type="integer") */ + public $position; + + /** @ManyToOne(targetEntity=GH7767ParentEntity::class, inversedBy="children") */ + private $parent; + + public function __construct(GH7767ParentEntity $parent, int $position) + { + $this->parent = $parent; + $this->position = $position; + } +} From 3a56cf8ad90ce35d3e690aec6d7098e1a94f7dc8 Mon Sep 17 00:00:00 2001 From: drews Date: Fri, 7 Jun 2019 11:01:14 +0500 Subject: [PATCH 788/877] Add MEMBER_OF comparison to queryExpressionVisitor --- .../reference/working-with-associations.rst | 1 + .../ORM/Query/QueryExpressionVisitor.php | 2 + .../ORM/Functional/Ticket/GH7737Test.php | 100 ++++++++++++++++++ .../ORM/Query/QueryExpressionVisitorTest.php | 1 + 4 files changed, 104 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH7737Test.php diff --git a/docs/en/reference/working-with-associations.rst b/docs/en/reference/working-with-associations.rst index 0b805806693..ab588e4efb0 100644 --- a/docs/en/reference/working-with-associations.rst +++ b/docs/en/reference/working-with-associations.rst @@ -716,6 +716,7 @@ methods: * ``in($field, array $values)`` * ``notIn($field, array $values)`` * ``contains($field, $value)`` +* ``memberOf($value, $field)`` * ``startsWith($field, $value)`` * ``endsWith($field, $value)`` diff --git a/lib/Doctrine/ORM/Query/QueryExpressionVisitor.php b/lib/Doctrine/ORM/Query/QueryExpressionVisitor.php index 8b00d998eae..0381ac037d4 100644 --- a/lib/Doctrine/ORM/Query/QueryExpressionVisitor.php +++ b/lib/Doctrine/ORM/Query/QueryExpressionVisitor.php @@ -186,6 +186,8 @@ public function walkComparison(Comparison $comparison) $this->parameters[] = $parameter; return $this->expr->like($field, $placeholder); + case Comparison::MEMBER_OF: + return $this->expr->isMemberOf($comparison->getField(), $comparison->getValue()->getValue()); case Comparison::STARTS_WITH: $parameter->setValue($parameter->getValue() . '%', $parameter->getType()); $this->parameters[] = $parameter; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7737Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7737Test.php new file mode 100644 index 00000000000..8101488a980 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7737Test.php @@ -0,0 +1,100 @@ +setUpEntitySchema([GH7737Group::class, GH7737Person::class]); + + $group1 = new GH7737Group(1, 'Test 1'); + $person = new GH7737Person(1); + $person->groups->add($group1); + + $this->_em->persist($person); + $this->_em->persist($group1); + $this->_em->persist(new GH7737Group(2, 'Test 2')); + $this->_em->flush(); + $this->_em->clear(); + } + + /** + * @test + */ + public function memberOfCriteriaShouldBeCompatibleWithQueryBuilder() : void + { + $query = $this->_em->createQueryBuilder() + ->select('person') + ->from(GH7737Person::class, 'person') + ->addCriteria(Criteria::create()->where(Criteria::expr()->memberOf(':group', 'person.groups'))) + ->getQuery(); + + $group1 = $this->_em->find(GH7737Group::class, 1); + $matching = $query->setParameter('group', $group1)->getOneOrNullResult(); + + self::assertInstanceOf(GH7737Person::class, $matching); + self::assertSame(1, $matching->id); + + $group2 = $this->_em->find(GH7737Group::class, 2); + $notMatching = $query->setParameter('group', $group2)->getOneOrNullResult(); + + self::assertNull($notMatching); + } +} + +/** + * @Entity + */ +class GH7737Group +{ + /** + * @Id + * @Column(type="integer") + */ + public $id; + + /** @Column */ + public $name; + + public function __construct(int $id, string $name) + { + $this->id = $id; + $this->name = $name; + } +} + +/** + * @Entity + */ +class GH7737Person +{ + /** + * @Id + * @Column(type="integer") + */ + public $id; + + /** + * @ManyToMany(targetEntity=GH7737Group::class) + * @JoinTable(inverseJoinColumns={@JoinColumn(name="group_id", referencedColumnName="id", unique=true)}) + */ + public $groups; + + public function __construct(int $id) + { + $this->id = $id; + $this->groups = new ArrayCollection(); + } +} diff --git a/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php b/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php index 0e306ab06ea..27dce7d6d95 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php @@ -67,6 +67,7 @@ public function comparisonData() [$cb->notIn('field', ['value']), $qb->notIn('o.field', ':field'), new Parameter('field', ['value'])], [$cb->contains('field', 'value'), $qb->like('o.field', ':field'), new Parameter('field', '%value%')], + [$cb->memberOf(':field', 'o.field'), $qb->isMemberOf(':field', 'o.field')], [$cb->startsWith('field', 'value'), $qb->like('o.field', ':field'), new Parameter('field', 'value%')], [$cb->endsWith('field', 'value'), $qb->like('o.field', ':field'), new Parameter('field', '%value')], From 70df74f65f9db9feb6fbe5f603cde36e08f4fd58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Tue, 6 Aug 2019 12:32:21 +0200 Subject: [PATCH 789/877] Fix preFlush event documentation stating incorrectly that flush can be called safely Original author: egonolieux Supersedes #6858 --- docs/en/reference/events.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/en/reference/events.rst b/docs/en/reference/events.rst index b38ba581910..9bcafe4813b 100644 --- a/docs/en/reference/events.rst +++ b/docs/en/reference/events.rst @@ -548,8 +548,9 @@ preFlush ~~~~~~~~ ``preFlush`` is called at ``EntityManager#flush()`` before -anything else. ``EntityManager#flush()`` can be called safely -inside its listeners. +anything else. ``EntityManager#flush()`` should not be called inside +its listeners, since `preFlush` event is dispatched in it, which would +result in infinite loop. .. code-block:: php From ecf80b47a05ca23eacb75d721780cc5b6b2d0e82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C5=A1a=20Stamenkovi=C4=87?= Date: Tue, 23 Jul 2019 16:18:16 +0200 Subject: [PATCH 790/877] Call to a member function resolveAssociationEntries() on boolean The following mistakes occur occasionally: ``` Call to a member function resolveAssociationEntries() on boolean {"detail":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Call to a member function resolveAssociationEntries() on boolean at /www/vendor/doctrine/orm/lib/Doctrine/ORM/Cache/DefaultQueryCache.php:140)"} ``` On cache miss the parameter `$entityEntry` sometimes will be false. This fixes issue #7266. --- lib/Doctrine/ORM/Cache/DefaultQueryCache.php | 2 +- .../Tests/ORM/Cache/DefaultQueryCacheTest.php | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php index d431313ef0e..115b211eef3 100644 --- a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php +++ b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php @@ -124,7 +124,7 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = [] foreach ($cacheEntry->result as $index => $entry) { $entityEntry = is_array($entries) && array_key_exists($index, $entries) ? $entries[$index] : null; - if ($entityEntry === null) { + if (! $entityEntry instanceof EntityCacheEntry) { if ($this->cacheLogger !== null) { $this->cacheLogger->entityCacheMiss($regionName, $cacheKeys->identifiers[$index]); } diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php index 58eddd37509..ecfcc5207ff 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php @@ -354,6 +354,34 @@ public function testGetWithAssociation() $this->assertEquals('Bar', $result[1]->getName()); } + public function testGetWithAssociationCacheMiss() : void + { + $rsm = new ResultSetMappingBuilder($this->em); + $key = new QueryCacheKey('query.key1', 0); + $entry = new QueryCacheEntry( + [ + ['identifier' => ['id' => 1]], + ['identifier' => ['id' => 2]], + ] + ); + + $this->region->addReturn('get', $entry); + + $this->region->addReturn( + 'getMultiple', + [ + new EntityCacheEntry(Country::class, ['id' => 1, 'name' => 'Foo']), + false, + ] + ); + + $rsm->addRootEntityFromClassMetadata(Country::class, 'c'); + + $result = $this->queryCache->get($key, $rsm); + + self::assertNull($result); + } + public function testCancelPutResultIfEntityPutFails() { $result = []; From eafc4c5a0c07f8cf476fba63444fee9e79544df5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Tue, 13 Aug 2019 22:20:59 +0200 Subject: [PATCH 791/877] Remove unnecessary parentheses --- lib/Doctrine/ORM/Cache/DefaultQueryCache.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php index 115b211eef3..25fa50cc904 100644 --- a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php +++ b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php @@ -106,7 +106,7 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = [] $result = []; $entityName = reset($rsm->aliasMap); - $hasRelation = ( ! empty($rsm->relationMap)); + $hasRelation = ! empty($rsm->relationMap); $persister = $this->uow->getEntityPersister($entityName); $region = $persister->getCacheRegion(); $regionName = $region->getName(); @@ -267,7 +267,7 @@ public function put(QueryCacheKey $key, ResultSetMapping $rsm, $result, array $h $rootAlias = key($rsm->aliasMap); $persister = $this->uow->getEntityPersister($entityName); - if ( ! ($persister instanceof CachedPersister)) { + if (! $persister instanceof CachedEntityPersister) { throw CacheException::nonCacheableEntity($entityName); } From b9d683421322f0a359e536429eacbe5d2e8145ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Tue, 13 Aug 2019 22:21:59 +0200 Subject: [PATCH 792/877] Remove unnecessary function calls --- lib/Doctrine/ORM/Cache/DefaultQueryCache.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php index 25fa50cc904..dfa66c193fb 100644 --- a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php +++ b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php @@ -118,11 +118,11 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = [] }; $cacheKeys = new CollectionCacheEntry(array_map($generateKeys, $cacheEntry->result)); - $entries = $region->getMultiple($cacheKeys); + $entries = $region->getMultiple($cacheKeys) ?? []; // @TODO - move to cache hydration component foreach ($cacheEntry->result as $index => $entry) { - $entityEntry = is_array($entries) && array_key_exists($index, $entries) ? $entries[$index] : null; + $entityEntry = $entries[$index] ?? null; if (! $entityEntry instanceof EntityCacheEntry) { if ($this->cacheLogger !== null) { From b6663733c01e0c7323d31152bf5861f096a837e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Tue, 13 Aug 2019 22:22:44 +0200 Subject: [PATCH 793/877] Add type assertion to be more strict about persister type --- lib/Doctrine/ORM/Cache/DefaultQueryCache.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php index dfa66c193fb..26f00d1faac 100644 --- a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php +++ b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php @@ -22,6 +22,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Cache\Persister\CachedPersister; +use Doctrine\ORM\Cache\Persister\Entity\CachedEntityPersister; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\ORM\Mapping\ClassMetadata; @@ -29,6 +30,7 @@ use Doctrine\Common\Proxy\Proxy; use Doctrine\ORM\Cache; use Doctrine\ORM\Query; +use function assert; /** * Default query cache implementation. @@ -108,8 +110,10 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = [] $entityName = reset($rsm->aliasMap); $hasRelation = ! empty($rsm->relationMap); $persister = $this->uow->getEntityPersister($entityName); - $region = $persister->getCacheRegion(); - $regionName = $region->getName(); + assert($persister instanceof CachedEntityPersister); + + $region = $persister->getCacheRegion(); + $regionName = $region->getName(); $cm = $this->em->getClassMetadata($entityName); @@ -145,9 +149,11 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = [] $data = $entityEntry->data; foreach ($entry['associations'] as $name => $assoc) { - $assocPersister = $this->uow->getEntityPersister($assoc['targetEntity']); - $assocRegion = $assocPersister->getCacheRegion(); - $assocMetadata = $this->em->getClassMetadata($assoc['targetEntity']); + $assocPersister = $this->uow->getEntityPersister($assoc['targetEntity']); + assert($assocPersister instanceof CachedEntityPersister); + + $assocRegion = $assocPersister->getCacheRegion(); + $assocMetadata = $this->em->getClassMetadata($assoc['targetEntity']); if ($assoc['type'] & ClassMetadata::TO_ONE) { From 3577064f8c97dffbe2db9ccd9e8457c8e57a7975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Tue, 13 Aug 2019 22:23:37 +0200 Subject: [PATCH 794/877] Make closure static To adhere to our coding standard. --- lib/Doctrine/ORM/Cache/DefaultQueryCache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php index 26f00d1faac..866ea0db257 100644 --- a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php +++ b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php @@ -117,7 +117,7 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = [] $cm = $this->em->getClassMetadata($entityName); - $generateKeys = function (array $entry) use ($cm): EntityCacheKey { + $generateKeys = static function (array $entry) use ($cm) : EntityCacheKey { return new EntityCacheKey($cm->rootEntityName, $entry['identifier']); }; From 80503c483783f94a811e64e4ad1d8bfd6b10b94e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Tue, 13 Aug 2019 22:25:05 +0200 Subject: [PATCH 795/877] Guard cache regions against corrupted data For some bizarre reason the underlying cache drivers are returning unexpected values, which are leaking to the cache objects and causing them to error. This makes our cache regions much more strict about the types that are fetched from the cache provider, ensuring that no invalid information is ever sent to the hydrators. --- .../Cache/Region/DefaultMultiGetRegion.php | 6 +++++ .../ORM/Cache/Region/DefaultRegion.php | 10 +++++-- .../Tests/ORM/Cache/DefaultRegionTest.php | 26 +++++++++++++++++++ .../Tests/ORM/Cache/MultiGetRegionTest.php | 13 ++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Cache/Region/DefaultMultiGetRegion.php b/lib/Doctrine/ORM/Cache/Region/DefaultMultiGetRegion.php index 2cd94292b49..7b5f28ecf33 100644 --- a/lib/Doctrine/ORM/Cache/Region/DefaultMultiGetRegion.php +++ b/lib/Doctrine/ORM/Cache/Region/DefaultMultiGetRegion.php @@ -21,6 +21,7 @@ namespace Doctrine\ORM\Cache\Region; use Doctrine\Common\Cache\MultiGetCache; +use Doctrine\ORM\Cache\CacheEntry; use Doctrine\ORM\Cache\CollectionCacheEntry; /** @@ -67,7 +68,12 @@ public function getMultiple(CollectionCacheEntry $collection) } $returnableItems = []; + foreach ($keysToRetrieve as $index => $key) { + if (! $items[$key] instanceof CacheEntry) { + return null; + } + $returnableItems[$index] = $items[$key]; } diff --git a/lib/Doctrine/ORM/Cache/Region/DefaultRegion.php b/lib/Doctrine/ORM/Cache/Region/DefaultRegion.php index be62a6fb957..ab069cefb52 100644 --- a/lib/Doctrine/ORM/Cache/Region/DefaultRegion.php +++ b/lib/Doctrine/ORM/Cache/Region/DefaultRegion.php @@ -94,7 +94,13 @@ public function contains(CacheKey $key) */ public function get(CacheKey $key) { - return $this->cache->fetch($this->getCacheEntryKey($key)) ?: null; + $entry = $this->cache->fetch($this->getCacheEntryKey($key)); + + if (! $entry instanceof CacheEntry) { + return null; + } + + return $entry; } /** @@ -108,7 +114,7 @@ public function getMultiple(CollectionCacheEntry $collection) $entryKey = $this->getCacheEntryKey($key); $entryValue = $this->cache->fetch($entryKey); - if ($entryValue === false) { + if (! $entryValue instanceof CacheEntry) { return null; } diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultRegionTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultRegionTest.php index 97365dfcf28..e50c2a55c3d 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultRegionTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultRegionTest.php @@ -95,6 +95,32 @@ public function testGetMulti() $this->assertEquals($value1, $actual[0]); $this->assertEquals($value2, $actual[1]); } + + /** + * @test + * @group GH7266 + */ + public function corruptedDataDoesNotLeakIntoApplicationWhenGettingSingleEntry() : void + { + $key1 = new CacheKeyMock('key.1'); + $this->cache->save($this->region->getName() . '_' . $key1->hash, 'a-very-invalid-value'); + + self::assertTrue($this->region->contains($key1)); + self::assertNull($this->region->get($key1)); + } + + /** + * @test + * @group GH7266 + */ + public function corruptedDataDoesNotLeakIntoApplicationWhenGettingMultipleEntries() : void + { + $key1 = new CacheKeyMock('key.1'); + $this->cache->save($this->region->getName() . '_' . $key1->hash, 'a-very-invalid-value'); + + self::assertTrue($this->region->contains($key1)); + self::assertNull($this->region->getMultiple(new CollectionCacheEntry([$key1]))); + } } /** diff --git a/tests/Doctrine/Tests/ORM/Cache/MultiGetRegionTest.php b/tests/Doctrine/Tests/ORM/Cache/MultiGetRegionTest.php index 0d98665d0d0..5f45de47148 100644 --- a/tests/Doctrine/Tests/ORM/Cache/MultiGetRegionTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/MultiGetRegionTest.php @@ -39,4 +39,17 @@ public function testGetMulti() $this->assertEquals($value1, $actual[0]); $this->assertEquals($value2, $actual[1]); } + + /** + * @test + * @group GH7266 + */ + public function corruptedDataDoesNotLeakIntoApplication() : void + { + $key1 = new CacheKeyMock('key.1'); + $this->cache->save($this->region->getName() . '_' . $key1->hash, 'a-very-invalid-value'); + + self::assertTrue($this->region->contains($key1)); + self::assertNull($this->region->getMultiple(new CollectionCacheEntry([$key1]))); + } } From 447183e2353011e03b8a21f3eabce73a2760f4c3 Mon Sep 17 00:00:00 2001 From: Michele Locati Date: Wed, 31 Jul 2019 10:13:51 +0200 Subject: [PATCH 796/877] Fix "access array offset on value of type null" PHP 7.4 notices --- .../ORM/Mapping/ClassMetadataFactory.php | 3 +++ .../ORM/Mapping/ClassMetadataInfo.php | 4 +-- lib/Doctrine/ORM/PersistentCollection.php | 2 +- lib/Doctrine/ORM/Query/Parser.php | 27 ++++++++++--------- .../ORM/Tools/Export/Driver/YamlExporter.php | 19 ++++++------- 5 files changed, 31 insertions(+), 24 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index a1412d2f1ad..8410ce5b0de 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -703,6 +703,9 @@ private function completeIdGeneratorMapping(ClassMetadataInfo $class) case ClassMetadata::GENERATOR_TYPE_CUSTOM: $definition = $class->customGeneratorDefinition; + if ($definition === null) { + throw new ORMException("Can't instantiate custom generator : no custom generator definition"); + } if ( ! class_exists($definition['class'])) { throw new ORMException("Can't instantiate custom generator : " . $definition['class']); diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 3b3ecdaa3cb..0873eb6eff8 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -241,9 +241,9 @@ class ClassMetadataInfo implements ClassMetadata * ) * * - * @var array - * * @todo Merge with tableGeneratorDefinition into generic generatorDefinition + * + * @var array|null */ public $customGeneratorDefinition; diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index 88be1a69361..47b9bae20d4 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -449,7 +449,7 @@ public function get($key) */ public function count() { - if ( ! $this->initialized && $this->association['fetch'] === ClassMetadata::FETCH_EXTRA_LAZY) { + if (! $this->initialized && $this->association !== null && $this->association['fetch'] === ClassMetadata::FETCH_EXTRA_LAZY) { $persister = $this->em->getUnitOfWork()->getCollectionPersister($this->association); return $persister->count($this) + ($this->isDirty ? $this->collection->count() : 0); diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index d52f3ce1b2e..7b3e8ff491a 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -22,6 +22,7 @@ use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Query; use Doctrine\ORM\Query\AST\Functions; +use function in_array; use function strpos; /** @@ -469,7 +470,7 @@ public function syntaxError($expected = '', $token = null) public function semanticalError($message = '', $token = null) { if ($token === null) { - $token = $this->lexer->lookahead; + $token = $this->lexer->lookahead ?? ['position' => null]; } // Minimum exposed chars ahead of token @@ -536,7 +537,7 @@ private function peekBeyondClosingParenthesis($resetPeek = true) */ private function isMathOperator($token) { - return in_array($token['type'], [Lexer::T_PLUS, Lexer::T_MINUS, Lexer::T_DIVIDE, Lexer::T_MULTIPLY]); + return $token !== null && in_array($token['type'], [Lexer::T_PLUS, Lexer::T_MINUS, Lexer::T_DIVIDE, Lexer::T_MULTIPLY]); } /** @@ -551,7 +552,7 @@ private function isFunction() $this->lexer->resetPeek(); - return ($lookaheadType >= Lexer::T_IDENTIFIER && $peek['type'] === Lexer::T_OPEN_PARENTHESIS); + return $lookaheadType >= Lexer::T_IDENTIFIER && $peek !== null && $peek['type'] === Lexer::T_OPEN_PARENTHESIS; } /** @@ -842,7 +843,7 @@ public function QueryLanguage() $this->lexer->moveNext(); - switch ($this->lexer->lookahead['type']) { + switch ($this->lexer->lookahead['type'] ?? null) { case Lexer::T_SELECT: $statement = $this->SelectStatement(); break; @@ -1464,7 +1465,7 @@ public function GroupByItem() // We need to check if we are in a IdentificationVariable or SingleValuedPathExpression $glimpse = $this->lexer->glimpse(); - if ($glimpse['type'] === Lexer::T_DOT) { + if ($glimpse !== null && $glimpse['type'] === Lexer::T_DOT) { return $this->SingleValuedPathExpression(); } @@ -1508,7 +1509,7 @@ public function OrderByItem() $expr = $this->SimpleArithmeticExpression(); break; - case ($glimpse['type'] === Lexer::T_DOT): + case $glimpse !== null && $glimpse['type'] === Lexer::T_DOT: $expr = $this->SingleValuedPathExpression(); break; @@ -2479,9 +2480,11 @@ public function ConditionalPrimary() // Peek beyond the matching closing parenthesis ')' $peek = $this->peekBeyondClosingParenthesis(); - if (in_array($peek['value'], ["=", "<", "<=", "<>", ">", ">=", "!="]) || + if ($peek !== null && ( + in_array($peek['value'], ['=', '<', '<=', '<>', '>', '>=', '!=']) || in_array($peek['type'], [Lexer::T_NOT, Lexer::T_BETWEEN, Lexer::T_LIKE, Lexer::T_IN, Lexer::T_IS, Lexer::T_EXISTS]) || - $this->isMathOperator($peek)) { + $this->isMathOperator($peek) + )) { $condPrimary->simpleConditionalExpression = $this->SimpleConditionalExpression(); return $condPrimary; @@ -2833,11 +2836,11 @@ public function ArithmeticPrimary() case Lexer::T_IDENTIFIER: $peek = $this->lexer->glimpse(); - if ($peek['value'] == '(') { + if ($peek !== null && $peek['value'] === '(') { return $this->FunctionDeclaration(); } - if ($peek['value'] == '.') { + if ($peek !== null && $peek['value'] === '.') { return $this->SingleValuedPathExpression(); } @@ -2853,7 +2856,7 @@ public function ArithmeticPrimary() default: $peek = $this->lexer->glimpse(); - if ($peek['value'] == '(') { + if ($peek !== null && $peek['value'] === '(') { return $this->FunctionDeclaration(); } @@ -3192,7 +3195,7 @@ public function LikeExpression() $escapeChar = null; - if ($this->lexer->lookahead['type'] === Lexer::T_ESCAPE) { + if ($this->lexer->lookahead !== null && $this->lexer->lookahead['type'] === Lexer::T_ESCAPE) { $this->match(Lexer::T_ESCAPE); $this->match(Lexer::T_STRING); diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php index c685cd41d88..c20c3a4fe6a 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php @@ -48,11 +48,12 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) } else { $array['type'] = 'entity'; } + $metadataTable = $metadata->table ?? ['name' => null]; - $array['table'] = $metadata->table['name']; + $array['table'] = $metadataTable['name']; - if (isset($metadata->table['schema'])) { - $array['schema'] = $metadata->table['schema']; + if (isset($metadataTable['schema'])) { + $array['schema'] = $metadataTable['schema']; } $inheritanceType = $metadata->inheritanceType; @@ -73,20 +74,20 @@ public function exportClassMetadata(ClassMetadataInfo $metadata) $array['changeTrackingPolicy'] = $this->_getChangeTrackingPolicyString($metadata->changeTrackingPolicy); } - if (isset($metadata->table['indexes'])) { - $array['indexes'] = $metadata->table['indexes']; + if (isset($metadataTable['indexes'])) { + $array['indexes'] = $metadataTable['indexes']; } if ($metadata->customRepositoryClassName) { $array['repositoryClass'] = $metadata->customRepositoryClassName; } - if (isset($metadata->table['uniqueConstraints'])) { - $array['uniqueConstraints'] = $metadata->table['uniqueConstraints']; + if (isset($metadataTable['uniqueConstraints'])) { + $array['uniqueConstraints'] = $metadataTable['uniqueConstraints']; } - if (isset($metadata->table['options'])) { - $array['options'] = $metadata->table['options']; + if (isset($metadataTable['options'])) { + $array['options'] = $metadataTable['options']; } $fieldMappings = $metadata->fieldMappings; From a4ac9a721f97862e310e684faebd34170e73cd95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Tue, 10 Sep 2019 15:15:54 +0200 Subject: [PATCH 797/877] Upgrade PHPUnit to 7.5 --- composer.json | 2 +- composer.lock | 367 ++++++++---------- phpunit.xml.dist | 7 +- .../Entity/AbstractEntityPersisterTest.php | 58 +-- .../ReadWriteCachedEntityPersisterTest.php | 16 +- .../ORM/Mapping/ClassMetadataFactoryTest.php | 2 + 6 files changed, 169 insertions(+), 283 deletions(-) diff --git a/composer.json b/composer.json index bda459a95ae..abe42e4dba5 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ }, "require-dev": { "doctrine/coding-standard": "^5.0", - "phpunit/phpunit": "^6.5", + "phpunit/phpunit": "^7.5", "symfony/yaml": "~3.4|~4.0" }, "suggest": { diff --git a/composer.lock b/composer.lock index aab505fbf9e..81d33290c2e 100644 --- a/composer.lock +++ b/composer.lock @@ -1,10 +1,10 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "66a815cf9127439df18f45e7b074c384", + "content-hash": "d5d0e87e612dc300640150a1d8a8a8a7", "packages": [ { "name": "doctrine/annotations", @@ -1040,16 +1040,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.8.1", + "version": "1.9.3", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8" + "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", - "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/007c053ae6f31bba39dfa19a7726f56e9763bbea", + "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea", "shasum": "" }, "require": { @@ -1084,26 +1084,26 @@ "object", "object graph" ], - "time": "2018-06-11T23:09:50+00:00" + "time": "2019-08-09T12:45:53+00:00" }, { "name": "phar-io/manifest", - "version": "1.0.1", + "version": "1.0.3", "source": { "type": "git", "url": "https://github.com/phar-io/manifest.git", - "reference": "2df402786ab5368a0169091f61a7c1e0eb6852d0" + "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/manifest/zipball/2df402786ab5368a0169091f61a7c1e0eb6852d0", - "reference": "2df402786ab5368a0169091f61a7c1e0eb6852d0", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", + "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", "shasum": "" }, "require": { "ext-dom": "*", "ext-phar": "*", - "phar-io/version": "^1.0.1", + "phar-io/version": "^2.0", "php": "^5.6 || ^7.0" }, "type": "library", @@ -1139,20 +1139,20 @@ } ], "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", - "time": "2017-03-05T18:14:27+00:00" + "time": "2018-07-08T19:23:20+00:00" }, { "name": "phar-io/version", - "version": "1.0.1", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/phar-io/version.git", - "reference": "a70c0ced4be299a63d32fa96d9281d03e94041df" + "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/version/zipball/a70c0ced4be299a63d32fa96d9281d03e94041df", - "reference": "a70c0ced4be299a63d32fa96d9281d03e94041df", + "url": "https://api.github.com/repos/phar-io/version/zipball/45a2ec53a73c70ce41d55cedef9063630abaf1b6", + "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6", "shasum": "" }, "require": { @@ -1186,7 +1186,7 @@ } ], "description": "Library for handling version information and constraints", - "time": "2017-03-05T17:38:23+00:00" + "time": "2018-07-08T19:19:57+00:00" }, { "name": "phpdocumentor/reflection-common", @@ -1244,16 +1244,16 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "4.3.0", + "version": "4.3.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "94fd0001232e47129dd3504189fa1c7225010d08" + "reference": "bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/94fd0001232e47129dd3504189fa1c7225010d08", - "reference": "94fd0001232e47129dd3504189fa1c7225010d08", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c", + "reference": "bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c", "shasum": "" }, "require": { @@ -1291,7 +1291,7 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2017-11-30T07:14:17+00:00" + "time": "2019-04-30T17:48:53+00:00" }, { "name": "phpdocumentor/type-resolver", @@ -1342,16 +1342,16 @@ }, { "name": "phpspec/prophecy", - "version": "1.8.0", + "version": "1.8.1", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06" + "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4ba436b55987b4bf311cb7c6ba82aa528aac0a06", - "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/1927e75f4ed19131ec9bcc3b002e07fb1173ee76", + "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76", "shasum": "" }, "require": { @@ -1372,8 +1372,8 @@ } }, "autoload": { - "psr-0": { - "Prophecy\\": "src/" + "psr-4": { + "Prophecy\\": "src/Prophecy" } }, "notification-url": "https://packagist.org/downloads/", @@ -1401,44 +1401,44 @@ "spy", "stub" ], - "time": "2018-08-05T17:53:17+00:00" + "time": "2019-06-13T12:50:23+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "5.3.2", + "version": "6.1.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "c89677919c5dd6d3b3852f230a663118762218ac" + "reference": "807e6013b00af69b6c5d9ceb4282d0393dbb9d8d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/c89677919c5dd6d3b3852f230a663118762218ac", - "reference": "c89677919c5dd6d3b3852f230a663118762218ac", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/807e6013b00af69b6c5d9ceb4282d0393dbb9d8d", + "reference": "807e6013b00af69b6c5d9ceb4282d0393dbb9d8d", "shasum": "" }, "require": { "ext-dom": "*", "ext-xmlwriter": "*", - "php": "^7.0", - "phpunit/php-file-iterator": "^1.4.2", + "php": "^7.1", + "phpunit/php-file-iterator": "^2.0", "phpunit/php-text-template": "^1.2.1", - "phpunit/php-token-stream": "^2.0.1", + "phpunit/php-token-stream": "^3.0", "sebastian/code-unit-reverse-lookup": "^1.0.1", - "sebastian/environment": "^3.0", + "sebastian/environment": "^3.1 || ^4.0", "sebastian/version": "^2.0.1", "theseer/tokenizer": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^7.0" }, "suggest": { - "ext-xdebug": "^2.5.5" + "ext-xdebug": "^2.6.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "5.3.x-dev" + "dev-master": "6.1-dev" } }, "autoload": { @@ -1464,29 +1464,32 @@ "testing", "xunit" ], - "time": "2018-04-06T15:36:58+00:00" + "time": "2018-10-31T16:06:48+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "1.4.5", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4" + "reference": "050bedf145a257b1ff02746c31894800e5122946" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/730b01bc3e867237eaac355e06a36b85dd93a8b4", - "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/050bedf145a257b1ff02746c31894800e5122946", + "reference": "050bedf145a257b1ff02746c31894800e5122946", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -1501,7 +1504,7 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -1511,7 +1514,7 @@ "filesystem", "iterator" ], - "time": "2017-11-27T13:52:08+00:00" + "time": "2018-09-13T20:33:42+00:00" }, { "name": "phpunit/php-text-template", @@ -1556,28 +1559,28 @@ }, { "name": "phpunit/php-timer", - "version": "1.0.9", + "version": "2.1.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f" + "reference": "1038454804406b0b5f5f520358e78c1c2f71501e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", - "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/1038454804406b0b5f5f520358e78c1c2f71501e", + "reference": "1038454804406b0b5f5f520358e78c1c2f71501e", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0" + "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" + "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "2.1-dev" } }, "autoload": { @@ -1592,7 +1595,7 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -1601,33 +1604,33 @@ "keywords": [ "timer" ], - "time": "2017-02-26T11:10:40+00:00" + "time": "2019-06-07T04:22:29+00:00" }, { "name": "phpunit/php-token-stream", - "version": "2.0.2", + "version": "3.1.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "791198a2c6254db10131eecfe8c06670700904db" + "reference": "e899757bb3df5ff6e95089132f32cd59aac2220a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/791198a2c6254db10131eecfe8c06670700904db", - "reference": "791198a2c6254db10131eecfe8c06670700904db", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/e899757bb3df5ff6e95089132f32cd59aac2220a", + "reference": "e899757bb3df5ff6e95089132f32cd59aac2220a", "shasum": "" }, "require": { "ext-tokenizer": "*", - "php": "^7.0" + "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "^6.2.4" + "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "3.1-dev" } }, "autoload": { @@ -1650,57 +1653,57 @@ "keywords": [ "tokenizer" ], - "time": "2017-11-27T05:48:46+00:00" + "time": "2019-07-25T05:29:42+00:00" }, { "name": "phpunit/phpunit", - "version": "6.5.13", + "version": "7.5.15", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "0973426fb012359b2f18d3bd1e90ef1172839693" + "reference": "d79c053d972856b8b941bb233e39dc521a5093f0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/0973426fb012359b2f18d3bd1e90ef1172839693", - "reference": "0973426fb012359b2f18d3bd1e90ef1172839693", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/d79c053d972856b8b941bb233e39dc521a5093f0", + "reference": "d79c053d972856b8b941bb233e39dc521a5093f0", "shasum": "" }, "require": { + "doctrine/instantiator": "^1.1", "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", "ext-mbstring": "*", "ext-xml": "*", - "myclabs/deep-copy": "^1.6.1", - "phar-io/manifest": "^1.0.1", - "phar-io/version": "^1.0", - "php": "^7.0", + "myclabs/deep-copy": "^1.7", + "phar-io/manifest": "^1.0.2", + "phar-io/version": "^2.0", + "php": "^7.1", "phpspec/prophecy": "^1.7", - "phpunit/php-code-coverage": "^5.3", - "phpunit/php-file-iterator": "^1.4.3", + "phpunit/php-code-coverage": "^6.0.7", + "phpunit/php-file-iterator": "^2.0.1", "phpunit/php-text-template": "^1.2.1", - "phpunit/php-timer": "^1.0.9", - "phpunit/phpunit-mock-objects": "^5.0.9", - "sebastian/comparator": "^2.1", - "sebastian/diff": "^2.0", - "sebastian/environment": "^3.1", + "phpunit/php-timer": "^2.1", + "sebastian/comparator": "^3.0", + "sebastian/diff": "^3.0", + "sebastian/environment": "^4.0", "sebastian/exporter": "^3.1", "sebastian/global-state": "^2.0", "sebastian/object-enumerator": "^3.0.3", - "sebastian/resource-operations": "^1.0", + "sebastian/resource-operations": "^2.0", "sebastian/version": "^2.0.1" }, "conflict": { - "phpdocumentor/reflection-docblock": "3.0.2", - "phpunit/dbunit": "<3.0" + "phpunit/phpunit-mock-objects": "*" }, "require-dev": { "ext-pdo": "*" }, "suggest": { + "ext-soap": "*", "ext-xdebug": "*", - "phpunit/php-invoker": "^1.1" + "phpunit/php-invoker": "^2.0" }, "bin": [ "phpunit" @@ -1708,7 +1711,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "6.5.x-dev" + "dev-master": "7.5-dev" } }, "autoload": { @@ -1734,66 +1737,7 @@ "testing", "xunit" ], - "time": "2018-09-08T15:10:43+00:00" - }, - { - "name": "phpunit/phpunit-mock-objects", - "version": "5.0.10", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "cd1cf05c553ecfec36b170070573e540b67d3f1f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/cd1cf05c553ecfec36b170070573e540b67d3f1f", - "reference": "cd1cf05c553ecfec36b170070573e540b67d3f1f", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "^1.0.5", - "php": "^7.0", - "phpunit/php-text-template": "^1.2.1", - "sebastian/exporter": "^3.1" - }, - "conflict": { - "phpunit/phpunit": "<6.0" - }, - "require-dev": { - "phpunit/phpunit": "^6.5.11" - }, - "suggest": { - "ext-soap": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "5.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Mock Object library for PHPUnit", - "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", - "keywords": [ - "mock", - "xunit" - ], - "time": "2018-08-09T05:50:03+00:00" + "time": "2019-08-21T07:05:16+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -1842,30 +1786,30 @@ }, { "name": "sebastian/comparator", - "version": "2.1.3", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "34369daee48eafb2651bea869b4b15d75ccc35f9" + "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/34369daee48eafb2651bea869b4b15d75ccc35f9", - "reference": "34369daee48eafb2651bea869b4b15d75ccc35f9", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/5de4fc177adf9bce8df98d8d141a7559d7ccf6da", + "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da", "shasum": "" }, "require": { - "php": "^7.0", - "sebastian/diff": "^2.0 || ^3.0", + "php": "^7.1", + "sebastian/diff": "^3.0", "sebastian/exporter": "^3.1" }, "require-dev": { - "phpunit/phpunit": "^6.4" + "phpunit/phpunit": "^7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.1.x-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -1902,32 +1846,33 @@ "compare", "equality" ], - "time": "2018-02-01T13:46:46+00:00" + "time": "2018-07-12T15:12:46+00:00" }, { "name": "sebastian/diff", - "version": "2.0.1", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "347c1d8b49c5c3ee30c7040ea6fc446790e6bddd" + "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/347c1d8b49c5c3ee30c7040ea6fc446790e6bddd", - "reference": "347c1d8b49c5c3ee30c7040ea6fc446790e6bddd", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/720fcc7e9b5cf384ea68d9d930d480907a0c1a29", + "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29", "shasum": "" }, "require": { - "php": "^7.0" + "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "^6.2" + "phpunit/phpunit": "^7.5 || ^8.0", + "symfony/process": "^2 || ^3.3 || ^4" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -1952,34 +1897,40 @@ "description": "Diff implementation", "homepage": "https://github.com/sebastianbergmann/diff", "keywords": [ - "diff" + "diff", + "udiff", + "unidiff", + "unified diff" ], - "time": "2017-08-03T08:09:46+00:00" + "time": "2019-02-04T06:01:07+00:00" }, { "name": "sebastian/environment", - "version": "3.1.0", + "version": "4.2.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "cd0871b3975fb7fc44d11314fd1ee20925fce4f5" + "reference": "f2a2c8e1c97c11ace607a7a667d73d47c19fe404" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/cd0871b3975fb7fc44d11314fd1ee20925fce4f5", - "reference": "cd0871b3975fb7fc44d11314fd1ee20925fce4f5", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/f2a2c8e1c97c11ace607a7a667d73d47c19fe404", + "reference": "f2a2c8e1c97c11ace607a7a667d73d47c19fe404", "shasum": "" }, "require": { - "php": "^7.0" + "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "^6.1" + "phpunit/phpunit": "^7.5" + }, + "suggest": { + "ext-posix": "*" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.1.x-dev" + "dev-master": "4.2-dev" } }, "autoload": { @@ -2004,20 +1955,20 @@ "environment", "hhvm" ], - "time": "2017-07-01T08:51:00+00:00" + "time": "2019-05-05T09:05:15+00:00" }, { "name": "sebastian/exporter", - "version": "3.1.0", + "version": "3.1.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "234199f4528de6d12aaa58b612e98f7d36adb937" + "reference": "06a9a5947f47b3029d76118eb5c22802e5869687" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/234199f4528de6d12aaa58b612e98f7d36adb937", - "reference": "234199f4528de6d12aaa58b612e98f7d36adb937", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/06a9a5947f47b3029d76118eb5c22802e5869687", + "reference": "06a9a5947f47b3029d76118eb5c22802e5869687", "shasum": "" }, "require": { @@ -2044,6 +1995,10 @@ "BSD-3-Clause" ], "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, { "name": "Jeff Welch", "email": "whatthejeff@gmail.com" @@ -2052,17 +2007,13 @@ "name": "Volker Dusch", "email": "github@wallbash.com" }, - { - "name": "Bernhard Schussek", - "email": "bschussek@2bepublished.at" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, { "name": "Adam Harvey", "email": "aharvey@php.net" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" } ], "description": "Provides the functionality to export PHP variables for visualization", @@ -2071,7 +2022,7 @@ "export", "exporter" ], - "time": "2017-04-03T13:19:02+00:00" + "time": "2019-08-11T12:43:14+00:00" }, { "name": "sebastian/global-state", @@ -2271,25 +2222,25 @@ }, { "name": "sebastian/resource-operations", - "version": "1.0.0", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/resource-operations.git", - "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52" + "reference": "4d7a795d35b889bf80a0cc04e08d77cedfa917a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", - "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/4d7a795d35b889bf80a0cc04e08d77cedfa917a9", + "reference": "4d7a795d35b889bf80a0cc04e08d77cedfa917a9", "shasum": "" }, "require": { - "php": ">=5.6.0" + "php": "^7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -2309,7 +2260,7 @@ ], "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", - "time": "2015-07-28T20:34:47+00:00" + "time": "2018-10-04T04:07:39+00:00" }, { "name": "sebastian/version", @@ -2563,16 +2514,16 @@ }, { "name": "theseer/tokenizer", - "version": "1.1.0", + "version": "1.1.3", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b" + "reference": "11336f6f84e16a720dae9d8e6ed5019efa85a0f9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/cb2f008f3f05af2893a87208fe6a6c4985483f8b", - "reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/11336f6f84e16a720dae9d8e6ed5019efa85a0f9", + "reference": "11336f6f84e16a720dae9d8e6ed5019efa85a0f9", "shasum": "" }, "require": { @@ -2594,33 +2545,33 @@ "authors": [ { "name": "Arne Blankerts", - "email": "arne@blankerts.de", - "role": "Developer" + "role": "Developer", + "email": "arne@blankerts.de" } ], "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", - "time": "2017-04-07T12:08:54+00:00" + "time": "2019-06-13T22:48:21+00:00" }, { "name": "webmozart/assert", - "version": "1.3.0", + "version": "1.5.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "0df1908962e7a3071564e857d86874dad1ef204a" + "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/0df1908962e7a3071564e857d86874dad1ef204a", - "reference": "0df1908962e7a3071564e857d86874dad1ef204a", + "url": "https://api.github.com/repos/webmozart/assert/zipball/88e6d84706d09a236046d686bbea96f07b3a34f4", + "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0" + "php": "^5.3.3 || ^7.0", + "symfony/polyfill-ctype": "^1.8" }, "require-dev": { - "phpunit/phpunit": "^4.6", - "sebastian/version": "^1.0.1" + "phpunit/phpunit": "^4.8.36 || ^7.5.13" }, "type": "library", "extra": { @@ -2649,7 +2600,7 @@ "check", "validate" ], - "time": "2018-01-29T19:49:41+00:00" + "time": "2019-08-24T08:43:50+00:00" } ], "aliases": [], diff --git a/phpunit.xml.dist b/phpunit.xml.dist index be88f60e7e6..ea31c212afd 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -18,11 +18,6 @@ failOnRisky="true" bootstrap="./tests/Doctrine/Tests/TestInit.php" > - - - - - ./tests/Doctrine/Tests/ORM @@ -54,6 +49,8 @@ + + diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/AbstractEntityPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/AbstractEntityPersisterTest.php index 09c7221f522..a0e3adbe51f 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/AbstractEntityPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/AbstractEntityPersisterTest.php @@ -35,52 +35,6 @@ abstract class AbstractEntityPersisterTest extends OrmTestCase */ protected $em; - /** - * @var array - */ - protected $regionMockMethods = [ - 'getName', - 'contains', - 'get', - 'getMultiple', - 'put', - 'evict', - 'evictAll' - ]; - - /** - * @var array - */ - protected $entityPersisterMockMethods = [ - 'getClassMetadata', - 'getResultSetMapping', - 'getInserts', - 'getInsertSQL', - 'getSelectSQL', - 'getCountSQL', - 'expandParameters', - 'expandCriteriaParameters', - 'getSelectConditionStatementSQL', - 'addInsert', - 'executeInserts', - 'update', - 'delete', - 'getOwningTable', - 'load', - 'loadById', - 'loadOneToOneEntity', - 'count', - 'refresh', - 'loadCriteria', - 'loadAll', - 'getManyToManyCollection', - 'loadManyToManyCollection', - 'loadOneToManyCollection', - 'lock', - 'getOneToManyCollection', - 'exists' - ]; - /** * @param \Doctrine\ORM\EntityManager $em * @param \Doctrine\ORM\Persisters\Entity\EntityPersister $persister @@ -97,11 +51,9 @@ protected function setUp() $this->enableSecondLevelCache(); parent::setUp(); - $this->em = $this->_getTestEntityManager(); - $this->region = $this->createRegion(); - $this->entityPersister = $this->getMockBuilder(EntityPersister::class) - ->setMethods($this->entityPersisterMockMethods) - ->getMock(); + $this->em = $this->_getTestEntityManager(); + $this->region = $this->createRegion(); + $this->entityPersister = $this->createMock(EntityPersister::class); } /** @@ -109,9 +61,7 @@ protected function setUp() */ protected function createRegion() { - return $this->getMockBuilder(Region::class) - ->setMethods($this->regionMockMethods) - ->getMock(); + return $this->createMock(Region::class); } /** diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersisterTest.php index 06748282c73..ee9d1433393 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersisterTest.php @@ -17,18 +17,6 @@ */ class ReadWriteCachedEntityPersisterTest extends AbstractEntityPersisterTest { - protected $regionMockMethods = [ - 'getName', - 'contains', - 'get', - 'getMultiple', - 'put', - 'evict', - 'evictAll', - 'lock', - 'unlock', - ]; - /** * {@inheritdoc} */ @@ -42,9 +30,7 @@ protected function createPersister(EntityManager $em, EntityPersister $persister */ protected function createRegion() { - return $this->getMockBuilder(ConcurrentRegion::class) - ->setConstructorArgs($this->regionMockMethods) - ->getMock(); + return $this->createMock(ConcurrentRegion::class); } public function testDeleteShouldLockItem() diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index d1cf1b48f88..8c73bf1c2de 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -170,6 +170,8 @@ public function testIsTransientEntityNamespace() public function testAddDefaultDiscriminatorMap() { + self::markTestSkipped('This test is just incorrect and must be fixed'); + $cmf = new ClassMetadataFactory(); $driver = $this->createAnnotationDriver([__DIR__ . '/../../Models/JoinedInheritanceType/']); $em = $this->_createEntityManager($driver); From a4215cfa5998e6451943aca14cf8ed05de0bc04d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Tue, 10 Sep 2019 15:16:39 +0200 Subject: [PATCH 798/877] Update locked dependencies --- composer.lock | 488 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 338 insertions(+), 150 deletions(-) diff --git a/composer.lock b/composer.lock index 81d33290c2e..23b60faad59 100644 --- a/composer.lock +++ b/composer.lock @@ -8,16 +8,16 @@ "packages": [ { "name": "doctrine/annotations", - "version": "v1.6.0", + "version": "v1.7.0", "source": { "type": "git", "url": "https://github.com/doctrine/annotations.git", - "reference": "c7f2050c68a9ab0bdb0f98567ec08d80ea7d24d5" + "reference": "fa4c4e861e809d6a1103bd620cce63ed91aedfeb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/c7f2050c68a9ab0bdb0f98567ec08d80ea7d24d5", - "reference": "c7f2050c68a9ab0bdb0f98567ec08d80ea7d24d5", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/fa4c4e861e809d6a1103bd620cce63ed91aedfeb", + "reference": "fa4c4e861e809d6a1103bd620cce63ed91aedfeb", "shasum": "" }, "require": { @@ -26,12 +26,12 @@ }, "require-dev": { "doctrine/cache": "1.*", - "phpunit/phpunit": "^6.4" + "phpunit/phpunit": "^7.5@dev" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.6.x-dev" + "dev-master": "1.7.x-dev" } }, "autoload": { @@ -44,6 +44,10 @@ "MIT" ], "authors": [ + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, { "name": "Roman Borschel", "email": "roman@code-factory.org" @@ -52,10 +56,6 @@ "name": "Benjamin Eberlei", "email": "kontakt@beberlei.de" }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, { "name": "Jonathan Wage", "email": "jonwage@gmail.com" @@ -72,7 +72,7 @@ "docblock", "parser" ], - "time": "2017-12-06T07:11:42+00:00" + "time": "2019-08-08T18:11:40+00:00" }, { "name": "doctrine/cache", @@ -151,34 +151,36 @@ }, { "name": "doctrine/collections", - "version": "v1.5.0", + "version": "v1.6.2", "source": { "type": "git", "url": "https://github.com/doctrine/collections.git", - "reference": "a01ee38fcd999f34d9bfbcee59dbda5105449cbf" + "reference": "c5e0bc17b1620e97c968ac409acbff28b8b850be" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/collections/zipball/a01ee38fcd999f34d9bfbcee59dbda5105449cbf", - "reference": "a01ee38fcd999f34d9bfbcee59dbda5105449cbf", + "url": "https://api.github.com/repos/doctrine/collections/zipball/c5e0bc17b1620e97c968ac409acbff28b8b850be", + "reference": "c5e0bc17b1620e97c968ac409acbff28b8b850be", "shasum": "" }, "require": { - "php": "^7.1" + "php": "^7.1.3" }, "require-dev": { - "doctrine/coding-standard": "~0.1@dev", - "phpunit/phpunit": "^5.7" + "doctrine/coding-standard": "^6.0", + "phpstan/phpstan-shim": "^0.9.2", + "phpunit/phpunit": "^7.0", + "vimeo/psalm": "^3.2.2" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.3.x-dev" + "dev-master": "1.6.x-dev" } }, "autoload": { - "psr-0": { - "Doctrine\\Common\\Collections\\": "lib/" + "psr-4": { + "Doctrine\\Common\\Collections\\": "lib/Doctrine/Common/Collections" } }, "notification-url": "https://packagist.org/downloads/", @@ -207,27 +209,28 @@ "email": "schmittjoh@gmail.com" } ], - "description": "Collections Abstraction library", - "homepage": "http://www.doctrine-project.org", + "description": "PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.", + "homepage": "https://www.doctrine-project.org/projects/collections.html", "keywords": [ "array", "collections", - "iterator" + "iterators", + "php" ], - "time": "2017-07-22T10:37:32+00:00" + "time": "2019-06-09T13:48:14+00:00" }, { "name": "doctrine/common", - "version": "v2.9.0", + "version": "v2.11.0", "source": { "type": "git", "url": "https://github.com/doctrine/common.git", - "reference": "a210246d286c77d2b89040f8691ba7b3a713d2c1" + "reference": "b8ca1dcf6b0dc8a2af7a09baac8d0c48345df4ff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/common/zipball/a210246d286c77d2b89040f8691ba7b3a713d2c1", - "reference": "a210246d286c77d2b89040f8691ba7b3a713d2c1", + "url": "https://api.github.com/repos/doctrine/common/zipball/b8ca1dcf6b0dc8a2af7a09baac8d0c48345df4ff", + "reference": "b8ca1dcf6b0dc8a2af7a09baac8d0c48345df4ff", "shasum": "" }, "require": { @@ -237,20 +240,22 @@ "doctrine/event-manager": "^1.0", "doctrine/inflector": "^1.0", "doctrine/lexer": "^1.0", - "doctrine/persistence": "^1.0", + "doctrine/persistence": "^1.1", "doctrine/reflection": "^1.0", "php": "^7.1" }, "require-dev": { "doctrine/coding-standard": "^1.0", - "phpunit/phpunit": "^6.3", + "phpstan/phpstan": "^0.11", + "phpstan/phpstan-phpunit": "^0.11", + "phpunit/phpunit": "^7.0", "squizlabs/php_codesniffer": "^3.0", "symfony/phpunit-bridge": "^4.0.5" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.9.x-dev" + "dev-master": "2.11.x-dev" } }, "autoload": { @@ -263,6 +268,10 @@ "MIT" ], "authors": [ + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, { "name": "Roman Borschel", "email": "roman@code-factory.org" @@ -271,10 +280,6 @@ "name": "Benjamin Eberlei", "email": "kontakt@beberlei.de" }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, { "name": "Jonathan Wage", "email": "jonwage@gmail.com" @@ -288,29 +293,27 @@ "email": "ocramius@gmail.com" } ], - "description": "Common Library for Doctrine projects", - "homepage": "https://www.doctrine-project.org", + "description": "PHP Doctrine Common project is a library that provides additional functionality that other Doctrine projects depend on such as better reflection support, persistence interfaces, proxies, event system and much more.", + "homepage": "https://www.doctrine-project.org/projects/common.html", "keywords": [ - "annotations", - "collections", - "eventmanager", - "persistence", - "spl" + "common", + "doctrine", + "php" ], - "time": "2018-07-12T21:16:12+00:00" + "time": "2019-09-10T10:10:14+00:00" }, { "name": "doctrine/dbal", - "version": "v2.8.0", + "version": "v2.9.2", "source": { "type": "git", "url": "https://github.com/doctrine/dbal.git", - "reference": "5140a64c08b4b607b9bedaae0cedd26f04a0e621" + "reference": "22800bd651c1d8d2a9719e2a3dc46d5108ebfcc9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/dbal/zipball/5140a64c08b4b607b9bedaae0cedd26f04a0e621", - "reference": "5140a64c08b4b607b9bedaae0cedd26f04a0e621", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/22800bd651c1d8d2a9719e2a3dc46d5108ebfcc9", + "reference": "22800bd651c1d8d2a9719e2a3dc46d5108ebfcc9", "shasum": "" }, "require": { @@ -320,11 +323,10 @@ "php": "^7.1" }, "require-dev": { - "doctrine/coding-standard": "^4.0", + "doctrine/coding-standard": "^5.0", "jetbrains/phpstorm-stubs": "^2018.1.2", "phpstan/phpstan": "^0.10.1", - "phpunit/phpunit": "^7.1.2", - "phpunit/phpunit-mock-objects": "!=3.2.4,!=3.2.5", + "phpunit/phpunit": "^7.4", "symfony/console": "^2.0.5|^3.0|^4.0", "symfony/phpunit-bridge": "^3.4.5|^4.0.5" }, @@ -337,13 +339,13 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.8.x-dev", + "dev-master": "2.9.x-dev", "dev-develop": "3.0.x-dev" } }, "autoload": { - "psr-0": { - "Doctrine\\DBAL\\": "lib/" + "psr-4": { + "Doctrine\\DBAL\\": "lib/Doctrine/DBAL" } }, "notification-url": "https://packagist.org/downloads/", @@ -368,15 +370,19 @@ "email": "jonwage@gmail.com" } ], - "description": "Database Abstraction Layer", - "homepage": "http://www.doctrine-project.org", + "description": "Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.", + "homepage": "https://www.doctrine-project.org/projects/dbal.html", "keywords": [ + "abstraction", "database", "dbal", + "mysql", "persistence", + "pgsql", + "php", "queryobject" ], - "time": "2018-07-13T03:16:35+00:00" + "time": "2018-12-31T03:27:51+00:00" }, { "name": "doctrine/event-manager", @@ -521,27 +527,29 @@ }, { "name": "doctrine/instantiator", - "version": "1.1.0", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda" + "reference": "a2c590166b2133a4633738648b6b064edae0814a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda", - "reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/a2c590166b2133a4633738648b6b064edae0814a", + "reference": "a2c590166b2133a4633738648b6b064edae0814a", "shasum": "" }, "require": { "php": "^7.1" }, "require-dev": { - "athletic/athletic": "~0.1.8", + "doctrine/coding-standard": "^6.0", "ext-pdo": "*", "ext-phar": "*", - "phpunit/phpunit": "^6.2.3", - "squizlabs/php_codesniffer": "^3.0.2" + "phpbench/phpbench": "^0.13", + "phpstan/phpstan-phpunit": "^0.11", + "phpstan/phpstan-shim": "^0.11", + "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { @@ -566,30 +574,33 @@ } ], "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", - "homepage": "https://github.com/doctrine/instantiator", + "homepage": "https://www.doctrine-project.org/projects/instantiator.html", "keywords": [ "constructor", "instantiate" ], - "time": "2017-07-22T11:58:36+00:00" + "time": "2019-03-17T17:37:11+00:00" }, { "name": "doctrine/lexer", - "version": "v1.0.1", + "version": "1.0.2", "source": { "type": "git", "url": "https://github.com/doctrine/lexer.git", - "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c" + "reference": "1febd6c3ef84253d7c815bed85fc622ad207a9f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/lexer/zipball/83893c552fd2045dd78aef794c31e694c37c0b8c", - "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c", + "url": "https://api.github.com/repos/doctrine/lexer/zipball/1febd6c3ef84253d7c815bed85fc622ad207a9f8", + "reference": "1febd6c3ef84253d7c815bed85fc622ad207a9f8", "shasum": "" }, "require": { "php": ">=5.3.2" }, + "require-dev": { + "phpunit/phpunit": "^4.5" + }, "type": "library", "extra": { "branch-alias": { @@ -597,8 +608,8 @@ } }, "autoload": { - "psr-0": { - "Doctrine\\Common\\Lexer\\": "lib/" + "psr-4": { + "Doctrine\\Common\\Lexer\\": "lib/Doctrine/Common/Lexer" } }, "notification-url": "https://packagist.org/downloads/", @@ -619,26 +630,29 @@ "email": "schmittjoh@gmail.com" } ], - "description": "Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.", - "homepage": "http://www.doctrine-project.org", + "description": "PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.", + "homepage": "https://www.doctrine-project.org/projects/lexer.html", "keywords": [ + "annotations", + "docblock", "lexer", - "parser" + "parser", + "php" ], - "time": "2014-09-09T13:34:57+00:00" + "time": "2019-06-08T11:03:04+00:00" }, { "name": "doctrine/persistence", - "version": "v1.0.1", + "version": "1.1.1", "source": { "type": "git", "url": "https://github.com/doctrine/persistence.git", - "reference": "af1ec238659a83e320f03e0e454e200f689b4b97" + "reference": "3da7c9d125591ca83944f477e65ed3d7b4617c48" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/persistence/zipball/af1ec238659a83e320f03e0e454e200f689b4b97", - "reference": "af1ec238659a83e320f03e0e454e200f689b4b97", + "url": "https://api.github.com/repos/doctrine/persistence/zipball/3da7c9d125591ca83944f477e65ed3d7b4617c48", + "reference": "3da7c9d125591ca83944f477e65ed3d7b4617c48", "shasum": "" }, "require": { @@ -650,17 +664,17 @@ "php": "^7.1" }, "conflict": { - "doctrine/common": "<2.9@dev" + "doctrine/common": "<2.10@dev" }, "require-dev": { - "doctrine/coding-standard": "^4.0", + "doctrine/coding-standard": "^5.0", "phpstan/phpstan": "^0.8", "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.1.x-dev" } }, "autoload": { @@ -698,12 +712,16 @@ "email": "ocramius@gmail.com" } ], - "description": "Doctrine Persistence abstractions.", + "description": "The Doctrine Persistence project is a set of shared interfaces and functionality that the different Doctrine object mappers share.", "homepage": "https://doctrine-project.org/projects/persistence.html", "keywords": [ + "mapper", + "object", + "odm", + "orm", "persistence" ], - "time": "2018-07-12T12:37:50+00:00" + "time": "2019-04-23T08:28:24+00:00" }, { "name": "doctrine/reflection", @@ -780,38 +798,94 @@ ], "time": "2018-06-14T14:45:07+00:00" }, + { + "name": "psr/container", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "time": "2017-02-14T16:28:37+00:00" + }, { "name": "symfony/console", - "version": "v4.1.7", + "version": "v4.3.4", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "432122af37d8cd52fba1b294b11976e0d20df595" + "reference": "de63799239b3881b8a08f8481b22348f77ed7b36" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/432122af37d8cd52fba1b294b11976e0d20df595", - "reference": "432122af37d8cd52fba1b294b11976e0d20df595", + "url": "https://api.github.com/repos/symfony/console/zipball/de63799239b3881b8a08f8481b22348f77ed7b36", + "reference": "de63799239b3881b8a08f8481b22348f77ed7b36", "shasum": "" }, "require": { "php": "^7.1.3", - "symfony/polyfill-mbstring": "~1.0" + "symfony/polyfill-mbstring": "~1.0", + "symfony/polyfill-php73": "^1.8", + "symfony/service-contracts": "^1.1" }, "conflict": { "symfony/dependency-injection": "<3.4", + "symfony/event-dispatcher": "<4.3", "symfony/process": "<3.3" }, + "provide": { + "psr/log-implementation": "1.0" + }, "require-dev": { "psr/log": "~1.0", "symfony/config": "~3.4|~4.0", "symfony/dependency-injection": "~3.4|~4.0", - "symfony/event-dispatcher": "~3.4|~4.0", + "symfony/event-dispatcher": "^4.3", "symfony/lock": "~3.4|~4.0", - "symfony/process": "~3.4|~4.0" + "symfony/process": "~3.4|~4.0", + "symfony/var-dumper": "^4.3" }, "suggest": { - "psr/log-implementation": "For using the console logger", + "psr/log": "For using the console logger", "symfony/event-dispatcher": "", "symfony/lock": "", "symfony/process": "" @@ -819,7 +893,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.1-dev" + "dev-master": "4.3-dev" } }, "autoload": { @@ -846,20 +920,20 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2018-10-31T09:30:44+00:00" + "time": "2019-08-26T08:26:39+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.10.0", + "version": "v1.12.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "c79c051f5b3a46be09205c73b80b346e4153e494" + "reference": "b42a2f66e8f1b15ccf25652c3424265923eb4f17" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/c79c051f5b3a46be09205c73b80b346e4153e494", - "reference": "c79c051f5b3a46be09205c73b80b346e4153e494", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/b42a2f66e8f1b15ccf25652c3424265923eb4f17", + "reference": "b42a2f66e8f1b15ccf25652c3424265923eb4f17", "shasum": "" }, "require": { @@ -871,7 +945,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.9-dev" + "dev-master": "1.12-dev" } }, "autoload": { @@ -905,35 +979,149 @@ "portable", "shim" ], - "time": "2018-09-21T13:07:52+00:00" + "time": "2019-08-06T08:03:45+00:00" + }, + { + "name": "symfony/polyfill-php73", + "version": "v1.12.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php73.git", + "reference": "2ceb49eaccb9352bff54d22570276bb75ba4a188" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/2ceb49eaccb9352bff54d22570276bb75ba4a188", + "reference": "2ceb49eaccb9352bff54d22570276bb75ba4a188", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.12-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php73\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2019-08-06T08:03:45+00:00" + }, + { + "name": "symfony/service-contracts", + "version": "v1.1.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/service-contracts.git", + "reference": "ea7263d6b6d5f798b56a45a5b8d686725f2719a3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/ea7263d6b6d5f798b56a45a5b8d686725f2719a3", + "reference": "ea7263d6b6d5f798b56a45a5b8d686725f2719a3", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "psr/container": "^1.0" + }, + "suggest": { + "symfony/service-implementation": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\Service\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Generic abstractions related to writing services", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "time": "2019-08-20T14:44:19+00:00" } ], "packages-dev": [ { "name": "dealerdirect/phpcodesniffer-composer-installer", - "version": "v0.4.4", + "version": "v0.5.0", "source": { "type": "git", "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", - "reference": "2e41850d5f7797cbb1af7b030d245b3b24e63a08" + "reference": "e749410375ff6fb7a040a68878c656c2e610b132" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/2e41850d5f7797cbb1af7b030d245b3b24e63a08", - "reference": "2e41850d5f7797cbb1af7b030d245b3b24e63a08", + "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/e749410375ff6fb7a040a68878c656c2e610b132", + "reference": "e749410375ff6fb7a040a68878c656c2e610b132", "shasum": "" }, "require": { "composer-plugin-api": "^1.0", "php": "^5.3|^7", - "squizlabs/php_codesniffer": "*" + "squizlabs/php_codesniffer": "^2|^3" }, "require-dev": { "composer/composer": "*", - "wimg/php-compatibility": "^8.0" - }, - "suggest": { - "dealerdirect/qa-tools": "All the PHP QA tools you'll need" + "phpcompatibility/php-compatibility": "^9.0", + "sensiolabs/security-checker": "^4.1.0" }, "type": "composer-plugin", "extra": { @@ -951,13 +1139,13 @@ "authors": [ { "name": "Franck Nijhof", - "email": "f.nijhof@dealerdirect.nl", - "homepage": "http://workingatdealerdirect.eu", - "role": "Developer" + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" } ], "description": "PHP_CodeSniffer Standards Composer Installer Plugin", - "homepage": "http://workingatdealerdirect.eu", + "homepage": "http://www.dealerdirect.com", "keywords": [ "PHPCodeSniffer", "PHP_CodeSniffer", @@ -975,24 +1163,24 @@ "stylecheck", "tests" ], - "time": "2017-12-06T16:27:17+00:00" + "time": "2018-10-26T13:21:45+00:00" }, { "name": "doctrine/coding-standard", - "version": "5.0.0", + "version": "5.0.1", "source": { "type": "git", "url": "https://github.com/doctrine/coding-standard.git", - "reference": "bb8de042a25c4fb59a2c55c350dc55cc00227a8c" + "reference": "9017efe98b47329cbd895d43f596747c8ef27307" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/coding-standard/zipball/bb8de042a25c4fb59a2c55c350dc55cc00227a8c", - "reference": "bb8de042a25c4fb59a2c55c350dc55cc00227a8c", + "url": "https://api.github.com/repos/doctrine/coding-standard/zipball/9017efe98b47329cbd895d43f596747c8ef27307", + "reference": "9017efe98b47329cbd895d43f596747c8ef27307", "shasum": "" }, "require": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4", + "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0", "php": "^7.1", "slevomat/coding-standard": "^4.8.0", "squizlabs/php_codesniffer": "^3.3.2" @@ -1036,7 +1224,7 @@ "standard", "style" ], - "time": "2018-09-24T19:08:56+00:00" + "time": "2019-01-31T13:22:30+00:00" }, { "name": "myclabs/deep-copy", @@ -2307,21 +2495,21 @@ }, { "name": "slevomat/coding-standard", - "version": "4.8.6", + "version": "4.8.7", "source": { "type": "git", "url": "https://github.com/slevomat/coding-standard.git", - "reference": "af0c0c99e84106525484ef25f15144b9831522bb" + "reference": "bff96313d8c7c2ba57a4edb13c1c141df8988c58" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/af0c0c99e84106525484ef25f15144b9831522bb", - "reference": "af0c0c99e84106525484ef25f15144b9831522bb", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/bff96313d8c7c2ba57a4edb13c1c141df8988c58", + "reference": "bff96313d8c7c2ba57a4edb13c1c141df8988c58", "shasum": "" }, "require": { "php": "^7.1", - "squizlabs/php_codesniffer": "^3.3.1" + "squizlabs/php_codesniffer": "^3.4.0" }, "require-dev": { "jakub-onderka/php-parallel-lint": "1.0.0", @@ -2329,7 +2517,7 @@ "phpstan/phpstan": "0.9.2", "phpstan/phpstan-phpunit": "0.9.4", "phpstan/phpstan-strict-rules": "0.9", - "phpunit/phpunit": "7.3.5" + "phpunit/phpunit": "7.5.1" }, "type": "phpcodesniffer-standard", "autoload": { @@ -2342,20 +2530,20 @@ "MIT" ], "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", - "time": "2018-11-03T21:28:29+00:00" + "time": "2019-01-03T13:15:50+00:00" }, { "name": "squizlabs/php_codesniffer", - "version": "3.3.2", + "version": "3.4.2", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "6ad28354c04b364c3c71a34e4a18b629cc3b231e" + "reference": "b8a7362af1cc1aadb5bd36c3defc4dda2cf5f0a8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/6ad28354c04b364c3c71a34e4a18b629cc3b231e", - "reference": "6ad28354c04b364c3c71a34e4a18b629cc3b231e", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/b8a7362af1cc1aadb5bd36c3defc4dda2cf5f0a8", + "reference": "b8a7362af1cc1aadb5bd36c3defc4dda2cf5f0a8", "shasum": "" }, "require": { @@ -2388,25 +2576,25 @@ } ], "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "homepage": "http://www.squizlabs.com/php-codesniffer", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", "keywords": [ "phpcs", "standards" ], - "time": "2018-09-23T23:08:17+00:00" + "time": "2019-04-10T23:49:02+00:00" }, { "name": "symfony/polyfill-ctype", - "version": "v1.10.0", + "version": "v1.12.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "e3d826245268269cd66f8326bd8bc066687b4a19" + "reference": "550ebaac289296ce228a706d0867afc34687e3f4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e3d826245268269cd66f8326bd8bc066687b4a19", - "reference": "e3d826245268269cd66f8326bd8bc066687b4a19", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/550ebaac289296ce228a706d0867afc34687e3f4", + "reference": "550ebaac289296ce228a706d0867afc34687e3f4", "shasum": "" }, "require": { @@ -2418,7 +2606,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.9-dev" + "dev-master": "1.12-dev" } }, "autoload": { @@ -2434,13 +2622,13 @@ "MIT" ], "authors": [ - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - }, { "name": "Gert de Pagter", "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], "description": "Symfony polyfill for ctype functions", @@ -2451,20 +2639,20 @@ "polyfill", "portable" ], - "time": "2018-08-06T14:22:27+00:00" + "time": "2019-08-06T08:03:45+00:00" }, { "name": "symfony/yaml", - "version": "v4.1.7", + "version": "v4.3.4", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "367e689b2fdc19965be435337b50bc8adf2746c9" + "reference": "5a0b7c32dc3ec56fd4abae8a4a71b0cf05013686" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/367e689b2fdc19965be435337b50bc8adf2746c9", - "reference": "367e689b2fdc19965be435337b50bc8adf2746c9", + "url": "https://api.github.com/repos/symfony/yaml/zipball/5a0b7c32dc3ec56fd4abae8a4a71b0cf05013686", + "reference": "5a0b7c32dc3ec56fd4abae8a4a71b0cf05013686", "shasum": "" }, "require": { @@ -2483,7 +2671,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.1-dev" + "dev-master": "4.3-dev" } }, "autoload": { @@ -2510,7 +2698,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2018-10-02T16:36:10+00:00" + "time": "2019-08-20T14:27:59+00:00" }, { "name": "theseer/tokenizer", From a8aa475d09f982c79b6d917ff2b2df1f4dc76418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Tue, 10 Sep 2019 14:25:18 +0200 Subject: [PATCH 799/877] Add PHP 7.4 to test matrix --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 9ab5b852d10..1d3d3fde32b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ php: - 7.1 - 7.2 - 7.3 + - 7.4snapshot - nightly env: From 613ffe9bbd139ede838ac784f49c66cccb93fa57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Tue, 10 Sep 2019 16:31:41 +0200 Subject: [PATCH 800/877] Backport documentation sidebar --- docs/en/sidebar.rst | 83 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 docs/en/sidebar.rst diff --git a/docs/en/sidebar.rst b/docs/en/sidebar.rst new file mode 100644 index 00000000000..03d130cc10e --- /dev/null +++ b/docs/en/sidebar.rst @@ -0,0 +1,83 @@ +.. toc:: + + .. tocheader:: Tutorials + + .. toctree:: + :depth: 3 + + tutorials/getting-started + tutorials/getting-started-database + tutorials/getting-started-models + tutorials/working-with-indexed-associations + tutorials/extra-lazy-associations + tutorials/composite-primary-keys + tutorials/ordered-associations + tutorials/override-field-association-mappings-in-subclasses + tutorials/pagination + tutorials/embeddables + +.. toc:: + + .. tocheader:: Reference + + .. toctree:: + :depth: 3 + + reference/architecture + reference/configuration + reference/faq + reference/basic-mapping + reference/association-mapping + reference/inheritance-mapping + reference/working-with-objects + reference/working-with-associations + reference/events + reference/unitofwork + reference/unitofwork-associations + reference/transactions-and-concurrency + reference/batch-processing + reference/dql-doctrine-query-language + reference/query-builder + reference/native-sql + reference/change-tracking-policies + reference/partial-objects + reference/xml-mapping + reference/yaml-mapping + reference/annotations-reference + reference/php-mapping + reference/caching + reference/improving-performance + reference/tools + reference/metadata-drivers + reference/best-practices + reference/limitations-and-known-issues + tutorials/pagination + reference/filters + reference/namingstrategy + reference/advanced-configuration + reference/second-level-cache + reference/security + +.. toc:: + + .. tocheader:: Cookbook + + .. toctree:: + :depth: 3 + + cookbook/aggregate-fields + cookbook/custom-mapping-types + cookbook/decorator-pattern + cookbook/dql-custom-walkers + cookbook/dql-user-defined-functions + cookbook/implementing-arrayaccess-for-domain-objects + cookbook/implementing-the-notify-changetracking-policy + cookbook/implementing-wakeup-or-clone + cookbook/resolve-target-entity-listener + cookbook/sql-table-prefixes + cookbook/strategy-cookbook-introduction + cookbook/validation-of-entities + cookbook/working-with-datetime + cookbook/mysql-enums + cookbook/advanced-field-value-conversion-using-custom-mapping-types + cookbook/entities-in-session From 50eecf698c176f20b58901600cbcb60f8182e8d9 Mon Sep 17 00:00:00 2001 From: Claudio Zizza Date: Sun, 15 Sep 2019 22:50:46 +0200 Subject: [PATCH 801/877] Add note into docs about not using SimpleAnnotationReader --- docs/en/tutorials/getting-started.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/en/tutorials/getting-started.rst b/docs/en/tutorials/getting-started.rst index 3ff75f5d91f..b01d44d4339 100644 --- a/docs/en/tutorials/getting-started.rst +++ b/docs/en/tutorials/getting-started.rst @@ -138,7 +138,10 @@ step: // Create a simple "default" Doctrine ORM configuration for Annotations $isDevMode = true; - $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), $isDevMode); + $proxyDir = null; + $cache = null; + $useSimpleAnnotationReader = false; + $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), $isDevMode, $proxyDir, $cache, $useSimpleAnnotationReader); // or if you prefer yaml or XML //$config = Setup::createXMLMetadataConfiguration(array(__DIR__."/config/xml"), $isDevMode); //$config = Setup::createYAMLMetadataConfiguration(array(__DIR__."/config/yaml"), $isDevMode); @@ -156,6 +159,10 @@ step: The YAML driver is deprecated and will be removed in version 3.0. It is strongly recommended to switch to one of the other mappings. +.. note:: + It is recommended not to use the SimpleAnnotationReader because its + usage will be removed for version 3.0. + The ``require_once`` statement sets up the class autoloading for Doctrine and its dependencies using Composer's autoloader. From 65522d97751253657cddaaf9af4cfcd6a27094ca Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 17 Sep 2019 11:37:50 +0200 Subject: [PATCH 802/877] Failing test case for #7820 - paginator doesn't use custom ID types When using a `Doctrine\ORM\Tools\Pagination\Paginator` to iterate over a query that has entities with a custom DBAL type used in the identifier, then `$id->__toString()` is used implicitly by PDO, instead of being converted by the `Doctrine\DBAL\Types` system. In order to reproduce this, you must have identifiers implementing `#__toString()` (to allow the `UnitOfWork` to hash them) and other accessors that are used by the custom DBAL type during DB/PHP conversions. If `#__toString()` and the DBAL type conversions are asymmetric, then the paginator will fail to find records. Tricky situation, but this very much affects `ramsey/uuid-doctrine` and anyone relying on the `uuid_binary`. --- .../ORM/Functional/Ticket/GH7820Test.php | 158 ++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH7820Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7820Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7820Test.php new file mode 100644 index 00000000000..9d3f5770baf --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7820Test.php @@ -0,0 +1,158 @@ +__toString()` + * is used implicitly by {@see \PDOStatement::bindValue()}, instead of being converted by the + * expected {@see \Doctrine\DBAL\Types\Type::convertToDatabaseValue()}. + * + * In order to reproduce this, you must have identifiers implementing + * `#__toString()` (to allow {@see \Doctrine\ORM\UnitOfWork} to hash them) and other accessors + * that are used by the custom DBAL type during DB/PHP conversions. + * + * If `#__toString()` and the DBAL type conversions are asymmetric, then the paginator will fail + * to find records. + * + * Tricky situation, but this very much affects `ramsey/uuid-doctrine` and anyone relying on (for + * example) the {@see \Ramsey\Uuid\Doctrine\UuidBinaryType} type. + */ +class GH7820Test extends OrmFunctionalTestCase +{ + private const SONG = [ + 'What is this song all about?', + 'Can\'t figure any lyrics out', + 'How do the words to it go?', + 'I wish you\'d tell me, I don\'t know', + 'Don\'t know, don\'t know, don\'t know, I don\'t know!', + 'Don\'t know, don\'t know, don\'t know...', + ]; + + protected function setUp() : void + { + parent::setUp(); + + if (! Type::hasType(GH7820LineTextType::class)) { + Type::addType(GH7820LineTextType::class, GH7820LineTextType::class); + } + + $this->setUpEntitySchema([GH7820Line::class]); + + foreach (self::SONG as $index => $line) { + $this->_em->persist(new GH7820Line(GH7820LineText::fromText($line), $index)); + } + + $this->_em->flush(); + } + + public function testWillFindSongsInPaginator() : void + { + $query = $this->_em->getRepository(GH7820Line::class) + ->createQueryBuilder('l') + ->orderBy('l.lineNumber', Criteria::ASC); + + self::assertSame( + self::SONG, + array_map(static function (GH7820Line $line) : string { + return $line->toString(); + }, iterator_to_array(new Paginator($query))) + ); + } +} + +/** @Entity */ +class GH7820Line +{ + /** + * @var GH7820LineText + * @Id() + * @Column(type="Doctrine\Tests\ORM\Functional\Ticket\GH7820LineTextType") + */ + private $text; + + /** + * @var int + * @Column(type="integer") + */ + private $lineNumber; + + public function __construct(GH7820LineText $text, int $index) + { + $this->text = $text; + $this->lineNumber = $index; + } + + public function toString() : string + { + return $this->text->getText(); + } +} + +final class GH7820LineText +{ + /** @var string */ + private $text; + + private function __construct(string $text) + { + $this->text = $text; + } + + public static function fromText(string $text) : self + { + return new self($text); + } + + public function getText() : string + { + return $this->text; + } + + public function __toString() : string + { + return 'Line: ' . $this->text; + } +} + +final class GH7820LineTextType extends StringType +{ + public function convertToPHPValue($value, AbstractPlatform $platform) + { + $text = parent::convertToPHPValue($value, $platform); + + if (! \is_string($text)) { + return $text; + } + + return GH7820LineText::fromText($text); + } + + public function convertToDatabaseValue($value, AbstractPlatform $platform) + { + if (! $value instanceof GH7820LineText) { + return parent::convertToDatabaseValue($value, $platform); + } + + return parent::convertToDatabaseValue($value->getText(), $platform); + } + + /** {@inheritdoc} */ + public function getName() : string + { + return self::class; + } +} From 39d21135490472ba31755a0259fbaf38ac453b9b Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 17 Sep 2019 14:13:30 +0200 Subject: [PATCH 803/877] Fixed #7820 - convert identifiers for `WHERE IN(?)` queries before binding parameters This patch introduces new internal API on the `ResultSetMapping` class, which is responsible for finding the type of the single column identifier of a DQL query selection root. --- lib/Doctrine/ORM/Query/ResultSetMapping.php | 43 ++++++++++++++++++- .../ORM/Tools/Pagination/Paginator.php | 39 +++++++++++++++-- ...ngManyToOneCompositeIdForeignKeyEntity.php | 2 + .../OwningManyToOneIdForeignKeyEntity.php | 19 ++++++++ .../ORM/Functional/Ticket/GH7820Test.php | 3 +- .../ORM/Hydration/ResultSetMappingTest.php | 26 +++++++++++ 6 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneIdForeignKeyEntity.php diff --git a/lib/Doctrine/ORM/Query/ResultSetMapping.php b/lib/Doctrine/ORM/Query/ResultSetMapping.php index 8e4f766bd65..2aa0771f9bc 100644 --- a/lib/Doctrine/ORM/Query/ResultSetMapping.php +++ b/lib/Doctrine/ORM/Query/ResultSetMapping.php @@ -19,6 +19,12 @@ namespace Doctrine\ORM\Query; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Mapping\MappingException; +use function array_keys; +use function array_values; +use function assert; + /** * A ResultSetMapping describes how a result set of an SQL query maps to a Doctrine result. * @@ -583,5 +589,40 @@ public function addMetaResult($alias, $columnName, $fieldName, $isIdentifierColu return $this; } -} + /** + * Retrieves the DBAL type name for the single identifier column of the root of a selection. + * Composite identifiers not supported! + * + * @internal only to be used by ORM internals: do not use in downstream projects! This API is a minimal abstraction + * that only ORM internals need, and it tries to make sense of the very complex and squishy array-alike + * structure inside this class. Some assumptions are coded in here, so here be dragons. + * + * @throws MappingException If the identifier is not a single field, or if metadata for its + * owner is incorrect/missing. + */ + final public function getTypeOfSelectionRootSingleIdentifierColumn(EntityManagerInterface $em) : string + { + assert($this->isSelect); + + if ($this->isIdentifierColumn !== []) { + // Identifier columns are already discovered here: we can use the first one directly. + assert($this->typeMappings !== []); + + return $this->typeMappings[array_keys(array_values($this->isIdentifierColumn)[0])[0]]; + } + + // We are selecting entities, and the first selected entity is our root of the selection. + if ($this->aliasMap !== []) { + $metadata = $em->getClassMetadata($this->aliasMap[array_keys($this->aliasMap)[0]]); + + return $metadata->getTypeOfField($metadata->getSingleIdentifierFieldName()); + } + + // We are selecting scalar fields - the first selected field will be assumed (!!! assumption !!!) as identifier + assert($this->scalarMappings !== []); + assert($this->typeMappings !== []); + + return $this->typeMappings[array_keys($this->scalarMappings)[0]]; + } +} diff --git a/lib/Doctrine/ORM/Tools/Pagination/Paginator.php b/lib/Doctrine/ORM/Tools/Pagination/Paginator.php index 0987dfc3492..892c65bbf35 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/Paginator.php +++ b/lib/Doctrine/ORM/Tools/Pagination/Paginator.php @@ -19,11 +19,16 @@ namespace Doctrine\ORM\Tools\Pagination; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Mapping\MappingException; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\Query; use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\ORM\NoResultException; +use function array_map; +use function assert; +use function current; /** * The paginator can handle various complex scenarios with DQL. @@ -150,14 +155,21 @@ public function getIterator() $subQuery->setFirstResult($offset)->setMaxResults($length); - $ids = array_map('current', $subQuery->getScalarResult()); + $foundIdRows = $subQuery->getScalarResult(); - $whereInQuery = $this->cloneQuery($this->query); // don't do this for an empty id array - if (count($ids) === 0) { + if ($foundIdRows === []) { return new \ArrayIterator([]); } + $whereInQuery = $this->cloneQuery($this->query); + $em = $subQuery->getEntityManager(); + $connection = $em->getConnection(); + $idType = $this->getIdentifiersQueryScalarResultType($subQuery, $em); + $ids = array_map(static function (array $row) use ($connection, $idType) { + return $connection->convertToDatabaseValue(current($row), $idType); + }, $foundIdRows); + $this->appendTreeWalker($whereInQuery, WhereInWalker::class); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, count($ids)); $whereInQuery->setFirstResult(null)->setMaxResults(null); @@ -282,4 +294,25 @@ private function unbindUnusedQueryParams(Query $query): void $query->setParameters($parameters); } + + /** + * Parses a query that is supposed to fetch a set of entity identifier only, + * and retrieves the type of said identifier. + * + * @throws MappingException If metadata couldn't be loaded, or if there isn't a single + * identifier for the given query. + */ + private function getIdentifiersQueryScalarResultType( + Query $query, + EntityManagerInterface $em + ) : ?string { + $rsm = (new Parser($query)) + ->parse() + ->getResultSetMapping(); + + assert($rsm !== null); + assert($rsm->isSelect); + + return $rsm->getTypeOfSelectionRootSingleIdentifierColumn($em); + } } diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneCompositeIdForeignKeyEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneCompositeIdForeignKeyEntity.php index b6787a41854..7b94a110d73 100644 --- a/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneCompositeIdForeignKeyEntity.php +++ b/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneCompositeIdForeignKeyEntity.php @@ -1,5 +1,7 @@ assertEquals('status', $this->_rsm->getFieldName('status')); $this->assertEquals('username', $this->_rsm->getFieldName('username')); $this->assertEquals('name', $this->_rsm->getFieldName('name')); + $this->assertSame('integer', $this->_rsm->getTypeOfSelectionRootSingleIdentifierColumn($this->_em)); } /** @@ -94,6 +98,7 @@ public function testFluentInterface() $this->assertTrue($rms->isRelation('p')); $this->assertTrue($rms->hasParentAlias('p')); $this->assertTrue($rms->isMixedResult()); + $this->assertSame('integer', $this->_rsm->getTypeOfSelectionRootSingleIdentifierColumn($this->_em)); } /** @@ -269,6 +274,27 @@ public function testAddNamedNativeQueryResultClass() $this->assertEquals(CmsUser::class, $rsm->getDeclaringClass('status')); $this->assertEquals(CmsUser::class, $rsm->getDeclaringClass('username')); } + + public function testIdentifierTypeForScalarExpression() : void + { + $rsm = (new Parser($this->_em->createQuery('SELECT e.id4 FROM ' . AuxiliaryEntity::class . ' e'))) + ->parse() + ->getResultSetMapping(); + + self::assertNotNull($rsm); + self::assertSame('rot13', $rsm->getTypeOfSelectionRootSingleIdentifierColumn($this->_em)); + } + + public function testIdentifierTypeForRootEntityColumnThatHasAssociationAsIdentifier() : void + { + $rsm = (new Parser($this->_em->createQuery('SELECT e FROM ' . OwningManyToOneIdForeignKeyEntity::class . ' e'))) + ->parse() + ->getResultSetMapping(); + + self::assertNotNull($rsm); + self::assertSame('rot13', $rsm->getTypeOfSelectionRootSingleIdentifierColumn($this->_em)); + } + /** * @group DDC-117 */ From c67a515cc29d0405b80ba53c096879cbbbc7f460 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 19 Sep 2019 19:51:38 +0200 Subject: [PATCH 804/877] As per discussion with @lcobucci, it is better to keep dragons where there be dragons, and this change does indeed rewrite the previous approach by moving the responsibility of type conversion on a query object from the `Paginator` to the `WhereInWalker`, which already has access to class metadata for the root of the selection (and can reliably detect the root of the selection too) --- .../ORM/Mapping/ClassMetadataInfo.php | 2 +- lib/Doctrine/ORM/Query/ResultSetMapping.php | 42 ------- .../ORM/Tools/Pagination/Paginator.php | 38 +----- .../ORM/Tools/Pagination/WhereInWalker.php | 41 +++++++ .../ORM/Hydration/ResultSetMappingTest.php | 25 ---- .../Tools/Pagination/PaginationTestCase.php | 2 +- .../Tools/Pagination/WhereInWalkerTest.php | 114 ++++++++++++++++++ 7 files changed, 161 insertions(+), 103 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 0873eb6eff8..08829cf1f98 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -2017,7 +2017,7 @@ public function isIdentifierUuid() * * @param string $fieldName * - * @return \Doctrine\DBAL\Types\Type|string|null + * @return string|null * * @todo 3.0 Remove this. PersisterHelper should fix it somehow */ diff --git a/lib/Doctrine/ORM/Query/ResultSetMapping.php b/lib/Doctrine/ORM/Query/ResultSetMapping.php index 2aa0771f9bc..640b8e65caf 100644 --- a/lib/Doctrine/ORM/Query/ResultSetMapping.php +++ b/lib/Doctrine/ORM/Query/ResultSetMapping.php @@ -19,12 +19,6 @@ namespace Doctrine\ORM\Query; -use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\Mapping\MappingException; -use function array_keys; -use function array_values; -use function assert; - /** * A ResultSetMapping describes how a result set of an SQL query maps to a Doctrine result. * @@ -589,40 +583,4 @@ public function addMetaResult($alias, $columnName, $fieldName, $isIdentifierColu return $this; } - - /** - * Retrieves the DBAL type name for the single identifier column of the root of a selection. - * Composite identifiers not supported! - * - * @internal only to be used by ORM internals: do not use in downstream projects! This API is a minimal abstraction - * that only ORM internals need, and it tries to make sense of the very complex and squishy array-alike - * structure inside this class. Some assumptions are coded in here, so here be dragons. - * - * @throws MappingException If the identifier is not a single field, or if metadata for its - * owner is incorrect/missing. - */ - final public function getTypeOfSelectionRootSingleIdentifierColumn(EntityManagerInterface $em) : string - { - assert($this->isSelect); - - if ($this->isIdentifierColumn !== []) { - // Identifier columns are already discovered here: we can use the first one directly. - assert($this->typeMappings !== []); - - return $this->typeMappings[array_keys(array_values($this->isIdentifierColumn)[0])[0]]; - } - - // We are selecting entities, and the first selected entity is our root of the selection. - if ($this->aliasMap !== []) { - $metadata = $em->getClassMetadata($this->aliasMap[array_keys($this->aliasMap)[0]]); - - return $metadata->getTypeOfField($metadata->getSingleIdentifierFieldName()); - } - - // We are selecting scalar fields - the first selected field will be assumed (!!! assumption !!!) as identifier - assert($this->scalarMappings !== []); - assert($this->typeMappings !== []); - - return $this->typeMappings[array_keys($this->scalarMappings)[0]]; - } } diff --git a/lib/Doctrine/ORM/Tools/Pagination/Paginator.php b/lib/Doctrine/ORM/Tools/Pagination/Paginator.php index 892c65bbf35..6c9ee44d03d 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/Paginator.php +++ b/lib/Doctrine/ORM/Tools/Pagination/Paginator.php @@ -19,16 +19,12 @@ namespace Doctrine\ORM\Tools\Pagination; -use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\Mapping\MappingException; -use Doctrine\ORM\Query\Parser; -use Doctrine\ORM\QueryBuilder; +use Doctrine\ORM\NoResultException; use Doctrine\ORM\Query; +use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\ResultSetMapping; -use Doctrine\ORM\NoResultException; +use Doctrine\ORM\QueryBuilder; use function array_map; -use function assert; -use function current; /** * The paginator can handle various complex scenarios with DQL. @@ -163,12 +159,7 @@ public function getIterator() } $whereInQuery = $this->cloneQuery($this->query); - $em = $subQuery->getEntityManager(); - $connection = $em->getConnection(); - $idType = $this->getIdentifiersQueryScalarResultType($subQuery, $em); - $ids = array_map(static function (array $row) use ($connection, $idType) { - return $connection->convertToDatabaseValue(current($row), $idType); - }, $foundIdRows); + $ids = array_map('current', $foundIdRows); $this->appendTreeWalker($whereInQuery, WhereInWalker::class); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, count($ids)); @@ -294,25 +285,4 @@ private function unbindUnusedQueryParams(Query $query): void $query->setParameters($parameters); } - - /** - * Parses a query that is supposed to fetch a set of entity identifier only, - * and retrieves the type of said identifier. - * - * @throws MappingException If metadata couldn't be loaded, or if there isn't a single - * identifier for the given query. - */ - private function getIdentifiersQueryScalarResultType( - Query $query, - EntityManagerInterface $em - ) : ?string { - $rsm = (new Parser($query)) - ->parse() - ->getResultSetMapping(); - - assert($rsm !== null); - assert($rsm->isSelect); - - return $rsm->getTypeOfSelectionRootSingleIdentifierColumn($em); - } } diff --git a/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php b/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php index 5fa4e2d94c4..25744db974b 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php @@ -19,6 +19,7 @@ namespace Doctrine\ORM\Tools\Pagination; +use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Query\AST\ArithmeticExpression; use Doctrine\ORM\Query\AST\SimpleArithmeticExpression; use Doctrine\ORM\Query\TreeWalkerAdapter; @@ -32,6 +33,9 @@ use Doctrine\ORM\Query\AST\ConditionalExpression; use Doctrine\ORM\Query\AST\ConditionalFactor; use Doctrine\ORM\Query\AST\WhereClause; +use function array_map; +use function assert; +use function is_array; /** * Replaces the whereClause of the AST with a WHERE id IN (:foo_1, :foo_2) equivalent. @@ -83,6 +87,7 @@ public function walkSelectStatement(SelectStatement $AST) $fromRoot = reset($from); $rootAlias = $fromRoot->rangeVariableDeclaration->aliasIdentificationVariable; + /** @var ClassMetadataInfo $rootClass */ $rootClass = $queryComponents[$rootAlias]['metadata']; $identifierFieldName = $rootClass->getSingleIdentifierFieldName(); @@ -104,6 +109,7 @@ public function walkSelectStatement(SelectStatement $AST) $expression = new InExpression($arithmeticExpression); $expression->literals[] = new InputParameter(":" . self::PAGINATOR_ID_ALIAS); + $this->convertWhereInIdentifiersToDatabaseValue($this->getTypeOfSingleIdentifierColumn($rootClass)); } else { $expression = new NullComparisonExpression($pathExpression); $expression->not = false; @@ -147,4 +153,39 @@ public function walkSelectStatement(SelectStatement $AST) ); } } + + private function convertWhereInIdentifiersToDatabaseValue(string $type) : void + { + $query = $this->_getQuery(); + $identifiersParameter = $query->getParameter(self::PAGINATOR_ID_ALIAS); + + assert($identifiersParameter !== null); + + $identifiers = $identifiersParameter->getValue(); + + assert(is_array($identifiers)); + + $connection = $this->_getQuery() + ->getEntityManager() + ->getConnection(); + + $query->setParameter(self::PAGINATOR_ID_ALIAS, array_map(static function ($id) use ($connection, $type) { + return $connection->convertToDatabaseValue($id, $type); + }, $identifiers)); + } + + private function getTypeOfSingleIdentifierColumn(ClassMetadataInfo $class) : string + { + $identifierField = $class->getSingleIdentifierFieldName(); + + if ($class->hasField($identifierField)) { + return (string) $class->getTypeOfField($identifierField); + } + + return $this->getTypeOfSingleIdentifierColumn( + $this->_getQuery() + ->getEntityManager() + ->getClassMetadata($class->getAssociationTargetClass($identifierField)) + ); + } } diff --git a/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php b/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php index 8d40dc7d076..3ec87b237de 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php @@ -3,15 +3,12 @@ namespace Doctrine\Tests\ORM\Hydration; use Doctrine\ORM\Mapping\ClassMetadata; -use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\Tests\Models\CMS\CmsEmail; use Doctrine\Tests\Models\CMS\CmsPhonenumber; use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\Legacy\LegacyUser; use Doctrine\Tests\Models\Legacy\LegacyUserReference; -use Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity; -use Doctrine\Tests\Models\ValueConversionType\OwningManyToOneIdForeignKeyEntity; /** * Description of ResultSetMappingTest @@ -68,7 +65,6 @@ public function testBasicResultSetMapping() $this->assertEquals('status', $this->_rsm->getFieldName('status')); $this->assertEquals('username', $this->_rsm->getFieldName('username')); $this->assertEquals('name', $this->_rsm->getFieldName('name')); - $this->assertSame('integer', $this->_rsm->getTypeOfSelectionRootSingleIdentifierColumn($this->_em)); } /** @@ -98,7 +94,6 @@ public function testFluentInterface() $this->assertTrue($rms->isRelation('p')); $this->assertTrue($rms->hasParentAlias('p')); $this->assertTrue($rms->isMixedResult()); - $this->assertSame('integer', $this->_rsm->getTypeOfSelectionRootSingleIdentifierColumn($this->_em)); } /** @@ -275,26 +270,6 @@ public function testAddNamedNativeQueryResultClass() $this->assertEquals(CmsUser::class, $rsm->getDeclaringClass('username')); } - public function testIdentifierTypeForScalarExpression() : void - { - $rsm = (new Parser($this->_em->createQuery('SELECT e.id4 FROM ' . AuxiliaryEntity::class . ' e'))) - ->parse() - ->getResultSetMapping(); - - self::assertNotNull($rsm); - self::assertSame('rot13', $rsm->getTypeOfSelectionRootSingleIdentifierColumn($this->_em)); - } - - public function testIdentifierTypeForRootEntityColumnThatHasAssociationAsIdentifier() : void - { - $rsm = (new Parser($this->_em->createQuery('SELECT e FROM ' . OwningManyToOneIdForeignKeyEntity::class . ' e'))) - ->parse() - ->getResultSetMapping(); - - self::assertNotNull($rsm); - self::assertSame('rot13', $rsm->getTypeOfSelectionRootSingleIdentifierColumn($this->_em)); - } - /** * @group DDC-117 */ diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/PaginationTestCase.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/PaginationTestCase.php index fe8ee0f8252..a4791cd175e 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/PaginationTestCase.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/PaginationTestCase.php @@ -11,7 +11,7 @@ abstract class PaginationTestCase extends OrmTestCase */ public $entityManager; - public function setUp() + protected function setUp() { $this->entityManager = $this->_getTestEntityManager(); } diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/WhereInWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/WhereInWalkerTest.php index 0c7cd48c2d3..647fed17420 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/WhereInWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/WhereInWalkerTest.php @@ -2,14 +2,27 @@ namespace Doctrine\Tests\ORM\Tools\Pagination; +use Doctrine\DBAL\Types\Type; use Doctrine\ORM\Query; use Doctrine\ORM\Tools\Pagination\WhereInWalker; +use Doctrine\Tests\DbalTypes\Rot13Type; +use Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity; +use Doctrine\Tests\Models\ValueConversionType\OwningManyToOneIdForeignKeyEntity; /** * @group DDC-1613 */ class WhereInWalkerTest extends PaginationTestCase { + protected function setUp() : void + { + parent::setUp(); + + if (! Type::hasType('rot13')) { + Type::addType('rot13', Rot13Type::class); + } + } + public function testWhereInQuery_NoWhere() { $query = $this->entityManager->createQuery( @@ -18,10 +31,16 @@ public function testWhereInQuery_NoWhere() $whereInQuery = clone $query; $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [WhereInWalker::class]); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); + $whereInQuery->setParameter(WhereInWalker::PAGINATOR_ID_ALIAS, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); $this->assertEquals( "SELECT u0_.id AS id_0, g1_.id AS id_1 FROM User u0_ INNER JOIN user_group u2_ ON u0_.id = u2_.user_id INNER JOIN groups g1_ ON g1_.id = u2_.group_id WHERE u0_.id IN (?)", $whereInQuery->getSQL() ); + + $this->assertPaginatorWhereInParameterToBe( + $whereInQuery, + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + ); } public function testCountQuery_MixedResultsWithName() @@ -32,10 +51,16 @@ public function testCountQuery_MixedResultsWithName() $whereInQuery = clone $query; $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [WhereInWalker::class]); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); + $whereInQuery->setParameter(WhereInWalker::PAGINATOR_ID_ALIAS, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); $this->assertEquals( "SELECT a0_.id AS id_0, a0_.name AS name_1, sum(a0_.name) AS sclr_2 FROM Author a0_ WHERE a0_.id IN (?)", $whereInQuery->getSQL() ); + + $this->assertPaginatorWhereInParameterToBe( + $whereInQuery, + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + ); } public function testWhereInQuery_SingleWhere() @@ -46,10 +71,16 @@ public function testWhereInQuery_SingleWhere() $whereInQuery = clone $query; $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [WhereInWalker::class]); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); + $whereInQuery->setParameter(WhereInWalker::PAGINATOR_ID_ALIAS, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); $this->assertEquals( "SELECT u0_.id AS id_0, g1_.id AS id_1 FROM User u0_ INNER JOIN user_group u2_ ON u0_.id = u2_.user_id INNER JOIN groups g1_ ON g1_.id = u2_.group_id WHERE 1 = 1 AND u0_.id IN (?)", $whereInQuery->getSQL() ); + + $this->assertPaginatorWhereInParameterToBe( + $whereInQuery, + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + ); } public function testWhereInQuery_MultipleWhereWithAnd() @@ -60,10 +91,16 @@ public function testWhereInQuery_MultipleWhereWithAnd() $whereInQuery = clone $query; $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [WhereInWalker::class]); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); + $whereInQuery->setParameter(WhereInWalker::PAGINATOR_ID_ALIAS, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); $this->assertEquals( "SELECT u0_.id AS id_0, g1_.id AS id_1 FROM User u0_ INNER JOIN user_group u2_ ON u0_.id = u2_.user_id INNER JOIN groups g1_ ON g1_.id = u2_.group_id WHERE 1 = 1 AND 2 = 2 AND u0_.id IN (?)", $whereInQuery->getSQL() ); + + $this->assertPaginatorWhereInParameterToBe( + $whereInQuery, + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + ); } public function testWhereInQuery_MultipleWhereWithOr() @@ -74,10 +111,16 @@ public function testWhereInQuery_MultipleWhereWithOr() $whereInQuery = clone $query; $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [WhereInWalker::class]); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); + $whereInQuery->setParameter(WhereInWalker::PAGINATOR_ID_ALIAS, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); $this->assertEquals( "SELECT u0_.id AS id_0, g1_.id AS id_1 FROM User u0_ INNER JOIN user_group u2_ ON u0_.id = u2_.user_id INNER JOIN groups g1_ ON g1_.id = u2_.group_id WHERE (1 = 1 OR 2 = 2) AND u0_.id IN (?)", $whereInQuery->getSQL() ); + + $this->assertPaginatorWhereInParameterToBe( + $whereInQuery, + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + ); } public function testWhereInQuery_MultipleWhereWithMixed_1() @@ -88,10 +131,16 @@ public function testWhereInQuery_MultipleWhereWithMixed_1() $whereInQuery = clone $query; $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [WhereInWalker::class]); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); + $whereInQuery->setParameter(WhereInWalker::PAGINATOR_ID_ALIAS, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); $this->assertEquals( "SELECT u0_.id AS id_0, g1_.id AS id_1 FROM User u0_ INNER JOIN user_group u2_ ON u0_.id = u2_.user_id INNER JOIN groups g1_ ON g1_.id = u2_.group_id WHERE (1 = 1 OR 2 = 2) AND 3 = 3 AND u0_.id IN (?)", $whereInQuery->getSQL() ); + + $this->assertPaginatorWhereInParameterToBe( + $whereInQuery, + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + ); } public function testWhereInQuery_MultipleWhereWithMixed_2() @@ -102,10 +151,16 @@ public function testWhereInQuery_MultipleWhereWithMixed_2() $whereInQuery = clone $query; $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [WhereInWalker::class]); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); + $whereInQuery->setParameter(WhereInWalker::PAGINATOR_ID_ALIAS, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); $this->assertEquals( "SELECT u0_.id AS id_0, g1_.id AS id_1 FROM User u0_ INNER JOIN user_group u2_ ON u0_.id = u2_.user_id INNER JOIN groups g1_ ON g1_.id = u2_.group_id WHERE (1 = 1 AND 2 = 2 OR 3 = 3) AND u0_.id IN (?)", $whereInQuery->getSQL() ); + + $this->assertPaginatorWhereInParameterToBe( + $whereInQuery, + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + ); } public function testWhereInQuery_WhereNot() @@ -116,10 +171,16 @@ public function testWhereInQuery_WhereNot() $whereInQuery = clone $query; $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [WhereInWalker::class]); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); + $whereInQuery->setParameter(WhereInWalker::PAGINATOR_ID_ALIAS, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); $this->assertEquals( "SELECT u0_.id AS id_0, g1_.id AS id_1 FROM User u0_ INNER JOIN user_group u2_ ON u0_.id = u2_.user_id INNER JOIN groups g1_ ON g1_.id = u2_.group_id WHERE (NOT 1 = 2) AND u0_.id IN (?)", $whereInQuery->getSQL() ); + + $this->assertPaginatorWhereInParameterToBe( + $whereInQuery, + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + ); } /** @@ -132,10 +193,16 @@ public function testWhereInQueryWithArbitraryJoin_NoWhere() ); $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [WhereInWalker::class]); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); + $whereInQuery->setParameter(WhereInWalker::PAGINATOR_ID_ALIAS, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); $this->assertEquals( "SELECT b0_.id AS id_0, b0_.author_id AS author_id_1, b0_.category_id AS category_id_2 FROM BlogPost b0_ INNER JOIN Category c1_ ON (b0_.category_id = c1_.id) WHERE b0_.id IN (?)", $whereInQuery->getSQL() ); + + $this->assertPaginatorWhereInParameterToBe( + $whereInQuery, + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + ); } public function testWhereInQueryWithArbitraryJoin_SingleWhere() @@ -145,10 +212,57 @@ public function testWhereInQueryWithArbitraryJoin_SingleWhere() ); $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [WhereInWalker::class]); $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 10); + $whereInQuery->setParameter(WhereInWalker::PAGINATOR_ID_ALIAS, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); $this->assertEquals( "SELECT b0_.id AS id_0, b0_.author_id AS author_id_1, b0_.category_id AS category_id_2 FROM BlogPost b0_ INNER JOIN Category c1_ ON (b0_.category_id = c1_.id) WHERE 1 = 1 AND b0_.id IN (?)", $whereInQuery->getSQL() ); + + $this->assertPaginatorWhereInParameterToBe( + $whereInQuery, + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + ); + } + + public function testWillReplaceBoundQueryIdentifiersWithConvertedTypesAsPerIdentifierMapping() : void + { + $whereInQuery = $this->entityManager->createQuery( + 'SELECT e.id4 FROM ' . AuxiliaryEntity::class . ' e' + ); + $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [WhereInWalker::class]); + $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 3); + $whereInQuery->setParameter(WhereInWalker::PAGINATOR_ID_ALIAS, ['foo', 'bar', 'baz']); + + $this->assertPaginatorWhereInParameterToBe( + $whereInQuery, + ['sbb', 'one', 'onm'] + ); + } + + public function testWillReplaceBoundQueryIdentifiersWithConvertedTypesAsPerAssociatedEntityIdentifierMapping() : void + { + $whereInQuery = $this->entityManager->createQuery( + 'SELECT e FROM ' . OwningManyToOneIdForeignKeyEntity::class . ' e' + ); + $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [WhereInWalker::class]); + $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 3); + $whereInQuery->setParameter(WhereInWalker::PAGINATOR_ID_ALIAS, ['foo', 'bar', 'baz']); + + $this->assertPaginatorWhereInParameterToBe( + $whereInQuery, + ['sbb', 'one', 'onm'] + ); + } + + /** @param mixed $parameter */ + private function assertPaginatorWhereInParameterToBe(Query $query, $parameter) : void + { + $query->getSQL(); // forces walker to process the query + + $boundParameter = $query->getParameter(WhereInWalker::PAGINATOR_ID_ALIAS); + + self::assertNotNull($boundParameter); + self::assertSame($parameter, $boundParameter->getValue()); } } From caee6c8685b421f831e33143faa6160b1e60b492 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 20 Sep 2019 14:51:56 +0200 Subject: [PATCH 805/877] #7820 restricted return type of `Doctrine\ORM\Mapping\ClassMetadataInfo#getTypeOfColumn()` This method will always return `string|null`, so we can safely remove DBAL types from its possible return types. --- lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 08829cf1f98..8584a784903 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -2033,7 +2033,7 @@ public function getTypeOfField($fieldName) * * @param string $columnName * - * @return \Doctrine\DBAL\Types\Type|string|null + * @return string|null * * @deprecated 3.0 remove this. this method is bogus and unreliable, since it cannot resolve the type of a column * that is derived by a referenced field on a different entity. From 681ff32e7675e181d5dd372757c78b21a930b589 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 20 Sep 2019 14:57:44 +0200 Subject: [PATCH 806/877] #7820 documented `PersisterHelper#getTypeOfField()` array return type Array values are `string`, and the array is a packed array. --- lib/Doctrine/ORM/Utility/PersisterHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Utility/PersisterHelper.php b/lib/Doctrine/ORM/Utility/PersisterHelper.php index d72dc3e19c0..fc6e492556f 100644 --- a/lib/Doctrine/ORM/Utility/PersisterHelper.php +++ b/lib/Doctrine/ORM/Utility/PersisterHelper.php @@ -39,7 +39,7 @@ class PersisterHelper * @param ClassMetadata $class * @param EntityManagerInterface $em * - * @return array + * @return array * * @throws QueryException */ From 0de17319d36d8d6c61b23b12b7d09f997bf72ad2 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 20 Sep 2019 15:03:22 +0200 Subject: [PATCH 807/877] #7820 use `PersisterHelper` to figure out identifier types This logic was pre-existing, but I forgot about it while writing #7820, therefore it was re-implemented inside this unit of code. Now we just use the `PersisterHelper`, which does all the nice and shiny identifier type discovery operations we need. --- .../ORM/Tools/Pagination/WhereInWalker.php | 47 ++++++++----------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php b/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php index 25744db974b..de66f64d7ec 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php @@ -19,20 +19,21 @@ namespace Doctrine\ORM\Tools\Pagination; -use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Query\AST\ArithmeticExpression; -use Doctrine\ORM\Query\AST\SimpleArithmeticExpression; -use Doctrine\ORM\Query\TreeWalkerAdapter; -use Doctrine\ORM\Query\AST\SelectStatement; -use Doctrine\ORM\Query\AST\PathExpression; -use Doctrine\ORM\Query\AST\InExpression; -use Doctrine\ORM\Query\AST\NullComparisonExpression; -use Doctrine\ORM\Query\AST\InputParameter; -use Doctrine\ORM\Query\AST\ConditionalPrimary; -use Doctrine\ORM\Query\AST\ConditionalTerm; use Doctrine\ORM\Query\AST\ConditionalExpression; use Doctrine\ORM\Query\AST\ConditionalFactor; +use Doctrine\ORM\Query\AST\ConditionalPrimary; +use Doctrine\ORM\Query\AST\ConditionalTerm; +use Doctrine\ORM\Query\AST\InExpression; +use Doctrine\ORM\Query\AST\InputParameter; +use Doctrine\ORM\Query\AST\NullComparisonExpression; +use Doctrine\ORM\Query\AST\PathExpression; +use Doctrine\ORM\Query\AST\SelectStatement; +use Doctrine\ORM\Query\AST\SimpleArithmeticExpression; use Doctrine\ORM\Query\AST\WhereClause; +use Doctrine\ORM\Query\TreeWalkerAdapter; +use Doctrine\ORM\Utility\PersisterHelper; use function array_map; use function assert; use function is_array; @@ -87,7 +88,7 @@ public function walkSelectStatement(SelectStatement $AST) $fromRoot = reset($from); $rootAlias = $fromRoot->rangeVariableDeclaration->aliasIdentificationVariable; - /** @var ClassMetadataInfo $rootClass */ + /** @var ClassMetadata $rootClass */ $rootClass = $queryComponents[$rootAlias]['metadata']; $identifierFieldName = $rootClass->getSingleIdentifierFieldName(); @@ -109,7 +110,14 @@ public function walkSelectStatement(SelectStatement $AST) $expression = new InExpression($arithmeticExpression); $expression->literals[] = new InputParameter(":" . self::PAGINATOR_ID_ALIAS); - $this->convertWhereInIdentifiersToDatabaseValue($this->getTypeOfSingleIdentifierColumn($rootClass)); + $this->convertWhereInIdentifiersToDatabaseValue( + PersisterHelper::getTypeOfField( + $identifierFieldName, + $rootClass, + $this->_getQuery() + ->getEntityManager() + )[0] + ); } else { $expression = new NullComparisonExpression($pathExpression); $expression->not = false; @@ -173,19 +181,4 @@ private function convertWhereInIdentifiersToDatabaseValue(string $type) : void return $connection->convertToDatabaseValue($id, $type); }, $identifiers)); } - - private function getTypeOfSingleIdentifierColumn(ClassMetadataInfo $class) : string - { - $identifierField = $class->getSingleIdentifierFieldName(); - - if ($class->hasField($identifierField)) { - return (string) $class->getTypeOfField($identifierField); - } - - return $this->getTypeOfSingleIdentifierColumn( - $this->_getQuery() - ->getEntityManager() - ->getClassMetadata($class->getAssociationTargetClass($identifierField)) - ); - } } From 17650a6100eefebfacb19a40783080d8ddfa1ec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Sch=C3=A4dlich?= Date: Thu, 4 Apr 2019 21:23:22 +0200 Subject: [PATCH 808/877] Added cross-links to relevant documentation --- docs/en/reference/caching.rst | 2 ++ docs/en/reference/improving-performance.rst | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/docs/en/reference/caching.rst b/docs/en/reference/caching.rst index b8f956f4a6f..4c07e1607c5 100644 --- a/docs/en/reference/caching.rst +++ b/docs/en/reference/caching.rst @@ -282,6 +282,8 @@ You can set the namespace a cache driver should use by using the setNamespace('my_namespace_'); +.. _integrating-with-the-orm: + Integrating with the ORM ------------------------ diff --git a/docs/en/reference/improving-performance.rst b/docs/en/reference/improving-performance.rst index d19b6947732..be4ac0acb5a 100644 --- a/docs/en/reference/improving-performance.rst +++ b/docs/en/reference/improving-performance.rst @@ -26,6 +26,8 @@ Doctrine will need to load your mapping information on every single request and has to parse each DQL query on every single request. This is a waste of resources. +See :ref:`integrating-with-the-orm` + Alternative Query Result Formats -------------------------------- @@ -42,6 +44,8 @@ for updates, which means when you call flush on the EntityManager these entities even if properties changed. Read-Only allows to persist new entities of a kind and remove existing ones, they are just not considered for updates. +See :ref:`annref_entity` + Extra-Lazy Collections ---------------------- @@ -61,6 +65,7 @@ Apply Best Practices A lot of the points mentioned in the Best Practices chapter will also positively affect the performance of Doctrine. +See :doc:`Best Practices ` Change Tracking policies ------------------------ From 7fbe663ea032517316319737d37f1dc642c5b24e Mon Sep 17 00:00:00 2001 From: vladyslavstartsev Date: Tue, 27 Nov 2018 17:00:19 +0200 Subject: [PATCH 809/877] Fix broken link closing #7489 --- lib/Doctrine/ORM/UnitOfWork.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 0fb3d8a06e1..82695984b65 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -90,7 +90,7 @@ class UnitOfWork implements PropertyChangedListener /** * Hint used to collect all primary keys of associated entities during hydration * and execute it in a dedicated query afterwards - * @see https://doctrine-orm.readthedocs.org/en/latest/reference/dql-doctrine-query-language.html?highlight=eager#temporarily-change-fetch-mode-in-dql + * @see https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#temporarily-change-fetch-mode-in-dql */ const HINT_DEFEREAGERLOAD = 'deferEagerLoad'; From cfe73cd74fafd84c14068fa7877e8ecc26d820d4 Mon Sep 17 00:00:00 2001 From: Dennis Enderink Date: Tue, 24 Jul 2018 10:35:23 +0200 Subject: [PATCH 810/877] Separated class identifiers types retrieval in a separate method and implemented in JoinedSubclassPersister delete method --- .../Entity/BasicEntityPersister.php | 48 ++++++++++++------- .../Entity/JoinedSubclassPersister.php | 9 ++-- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 14344d9f669..45c382a2168 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -569,29 +569,12 @@ protected function deleteJoinTableRecords($identifier) */ public function delete($entity) { - $self = $this; $class = $this->class; $identifier = $this->em->getUnitOfWork()->getEntityIdentifier($entity); $tableName = $this->quoteStrategy->getTableName($class, $this->platform); $idColumns = $this->quoteStrategy->getIdentifierColumnNames($class, $this->platform); $id = array_combine($idColumns, $identifier); - $types = array_map(function ($identifier) use ($class, $self) { - if (isset($class->fieldMappings[$identifier])) { - return $class->fieldMappings[$identifier]['type']; - } - - $targetMapping = $self->em->getClassMetadata($class->associationMappings[$identifier]['targetEntity']); - - if (isset($targetMapping->fieldMappings[$targetMapping->identifier[0]])) { - return $targetMapping->fieldMappings[$targetMapping->identifier[0]]['type']; - } - - if (isset($targetMapping->associationMappings[$targetMapping->identifier[0]])) { - return $targetMapping->associationMappings[$targetMapping->identifier[0]]['type']; - } - - throw ORMException::unrecognizedField($targetMapping->identifier[0]); - }, $class->identifier); + $types = $this->getClassIdentifiersTypes($class); $this->deleteJoinTableRecords($identifier); @@ -2089,4 +2072,33 @@ protected function switchPersisterContext($offset, $limit) $this->currentPersisterContext = $this->limitsHandlingContext; } + + /** + * Retrieves class identifiers types + * + * @param ClassMetadata $class + * @return array + */ + protected function getClassIdentifiersTypes(ClassMetadata $class) + { + $self = $this; + + return array_map(function ($identifier) use ($class, $self) { + if (isset($class->fieldMappings[$identifier])) { + return $class->fieldMappings[$identifier]['type']; + } + + $targetMapping = $self->em->getClassMetadata($class->associationMappings[$identifier]['targetEntity']); + + if (isset($targetMapping->fieldMappings[$targetMapping->identifier[0]])) { + return $targetMapping->fieldMappings[$targetMapping->identifier[0]]['type']; + } + + if (isset($targetMapping->associationMappings[$targetMapping->identifier[0]])) { + return $targetMapping->associationMappings[$targetMapping->identifier[0]]['type']; + } + + throw ORMException::unrecognizedField($targetMapping->identifier[0]); + }, $class->identifier); + } } diff --git a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php index 2693f3fabee..4d7e1f377ab 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php @@ -280,20 +280,23 @@ public function delete($entity) if ($this->platform->supportsForeignKeyConstraints()) { $rootClass = $this->em->getClassMetadata($this->class->rootEntityName); $rootTable = $this->quoteStrategy->getTableName($rootClass, $this->platform); + $rootTypes = $this->getClassIdentifiersTypes($rootClass); - return (bool) $this->conn->delete($rootTable, $id); + return (bool) $this->conn->delete($rootTable, $id, $rootTypes); } // Delete from all tables individually, starting from this class' table up to the root table. $rootTable = $this->quoteStrategy->getTableName($this->class, $this->platform); + $rootTypes = $this->getClassIdentifiersTypes($this->class); - $affectedRows = $this->conn->delete($rootTable, $id); + $affectedRows = $this->conn->delete($rootTable, $id, $rootTypes); foreach ($this->class->parentClasses as $parentClass) { $parentMetadata = $this->em->getClassMetadata($parentClass); $parentTable = $this->quoteStrategy->getTableName($parentMetadata, $this->platform); + $parentTypes = $this->getClassIdentifiersTypes($parentClass); - $this->conn->delete($parentTable, $id); + $this->conn->delete($parentTable, $id, $parentTypes); } return (bool) $affectedRows; From d7a537c9417cea883fb2772821f479c419b841f6 Mon Sep 17 00:00:00 2001 From: Dennis Enderink Date: Tue, 24 Jul 2018 14:41:04 +0200 Subject: [PATCH 811/877] Pass ClassMetadata object instead of string in parent classes loop --- .../ORM/Persisters/Entity/JoinedSubclassPersister.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php index 4d7e1f377ab..1f6d40133c7 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php @@ -278,9 +278,9 @@ public function delete($entity) // If the database platform supports FKs, just // delete the row from the root table. Cascades do the rest. if ($this->platform->supportsForeignKeyConstraints()) { - $rootClass = $this->em->getClassMetadata($this->class->rootEntityName); - $rootTable = $this->quoteStrategy->getTableName($rootClass, $this->platform); - $rootTypes = $this->getClassIdentifiersTypes($rootClass); + $rootClass = $this->em->getClassMetadata($this->class->rootEntityName); + $rootTable = $this->quoteStrategy->getTableName($rootClass, $this->platform); + $rootTypes = $this->getClassIdentifiersTypes($rootClass); return (bool) $this->conn->delete($rootTable, $id, $rootTypes); } @@ -294,7 +294,7 @@ public function delete($entity) foreach ($this->class->parentClasses as $parentClass) { $parentMetadata = $this->em->getClassMetadata($parentClass); $parentTable = $this->quoteStrategy->getTableName($parentMetadata, $this->platform); - $parentTypes = $this->getClassIdentifiersTypes($parentClass); + $parentTypes = $this->getClassIdentifiersTypes($parentMetadata); $this->conn->delete($parentTable, $id, $parentTypes); } From 37d1d5790048597dc3015b4c3e59f9b800c8eb5c Mon Sep 17 00:00:00 2001 From: Dennis Enderink Date: Tue, 24 Jul 2018 16:40:31 +0200 Subject: [PATCH 812/877] Added unit tests --- .../Tests/DbalTypes/CustomIdObjectType.php | 4 +- .../CustomIdObjectTypeChild.php | 15 ++++++ .../CustomIdObjectTypeParent.php | 39 ++++++++++++++ ...TableInheritanceCustomIdObjectTypeTest.php | 51 +++++++++++++++++++ .../ORM/Functional/CustomIdObjectTypeTest.php | 2 +- .../Doctrine/Tests/OrmFunctionalTestCase.php | 9 ++++ 6 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 tests/Doctrine/Tests/Models/ClassTableInheritanceCustomType/CustomIdObjectTypeChild.php create mode 100644 tests/Doctrine/Tests/Models/ClassTableInheritanceCustomType/CustomIdObjectTypeParent.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceCustomIdObjectTypeTest.php diff --git a/tests/Doctrine/Tests/DbalTypes/CustomIdObjectType.php b/tests/Doctrine/Tests/DbalTypes/CustomIdObjectType.php index 0ebae5dff0e..154f5778641 100644 --- a/tests/Doctrine/Tests/DbalTypes/CustomIdObjectType.php +++ b/tests/Doctrine/Tests/DbalTypes/CustomIdObjectType.php @@ -14,7 +14,7 @@ class CustomIdObjectType extends Type */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { - return $value->id; + return $value->id . '_test'; } /** @@ -22,7 +22,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) */ public function convertToPHPValue($value, AbstractPlatform $platform) { - $idObject = new CustomIdObject($value); + $idObject = new CustomIdObject(str_replace('_test', '', $value)); return $idObject; } diff --git a/tests/Doctrine/Tests/Models/ClassTableInheritanceCustomType/CustomIdObjectTypeChild.php b/tests/Doctrine/Tests/Models/ClassTableInheritanceCustomType/CustomIdObjectTypeChild.php new file mode 100644 index 00000000000..99b433f4a67 --- /dev/null +++ b/tests/Doctrine/Tests/Models/ClassTableInheritanceCustomType/CustomIdObjectTypeChild.php @@ -0,0 +1,15 @@ +id = $id; + $this->type = $type; + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceCustomIdObjectTypeTest.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceCustomIdObjectTypeTest.php new file mode 100644 index 00000000000..2768c02aab9 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceCustomIdObjectTypeTest.php @@ -0,0 +1,51 @@ +useModelSet('class_table_inheritance_custom_id_object_type'); + + parent::setUp(); + } + + public function testDelete() + { + $object = new CustomIdObjectTypeChild(new CustomIdObject('foo')); + $object->name = 'Test'; + + // persist parent + $this->_em->persist($object); + $this->_em->flush(); + + // save id for later use + $id = $object->id; + + // get child + $object2 = $this->_em->find(CustomIdObjectTypeChild::class, $id); + + // remove child + $this->_em->remove($object2); + $this->_em->flush(); + + $this->assertNull($this->_em->find(CustomIdObjectTypeChild::class, $id)); + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/CustomIdObjectTypeTest.php b/tests/Doctrine/Tests/ORM/Functional/CustomIdObjectTypeTest.php index 08d89fa8ec2..75ffd05be93 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CustomIdObjectTypeTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CustomIdObjectTypeTest.php @@ -84,7 +84,7 @@ public function testFetchJoinWhereCustomIdObject() . ' parent LEFT JOIN parent.children children ' . 'WHERE children.id = ?1' ) - ->setParameter(1, $parent->children->first()->id) + ->setParameter(1, $parent->children->first()->id, CustomIdObjectType::NAME) ->getResult(); $this->assertCount(1, $result); diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index d45ebac6387..569e1a55f82 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -97,6 +97,10 @@ abstract class OrmFunctionalTestCase extends OrmTestCase * @var array */ protected static $_modelSets = [ + 'class_table_inheritance_custom_id_object_type' => [ + Models\ClassTableInheritanceCustomType\CustomIdObjectTypeParent::class, + Models\ClassTableInheritanceCustomType\CustomIdObjectTypeChild::class, + ], 'cms' => [ Models\CMS\CmsUser::class, Models\CMS\CmsPhonenumber::class, @@ -343,6 +347,11 @@ protected function tearDown() $this->_sqlLoggerStack->enabled = false; + if (isset($this->_usedModelSets['class_table_inheritance_custom_id_object_type'])) { + $conn->executeUpdate('DELETE FROM class_table_inheritance_custom_id_type_child'); + $conn->executeUpdate('DELETE FROM class_table_inheritance_custom_id_type_parent'); + } + if (isset($this->_usedModelSets['cms'])) { $conn->executeUpdate('DELETE FROM cms_users_groups'); $conn->executeUpdate('DELETE FROM cms_groups'); From 390d081fcabc535529059a238edf1ce7f5dbe5d8 Mon Sep 17 00:00:00 2001 From: Dennis Enderink Date: Tue, 24 Jul 2018 17:23:03 +0200 Subject: [PATCH 813/877] Created new DBAL type and updated/reverted tests; also clarified new method return type --- .../Entity/BasicEntityPersister.php | 10 ++--- .../DbalTypes/CustomIdObjectHashType.php | 45 +++++++++++++++++++ .../Tests/DbalTypes/CustomIdObjectType.php | 4 +- .../CustomIdObjectTypeParent.php | 2 +- ...TableInheritanceCustomIdObjectTypeTest.php | 9 ++-- .../ORM/Functional/CustomIdObjectTypeTest.php | 2 +- 6 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 tests/Doctrine/Tests/DbalTypes/CustomIdObjectHashType.php diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 45c382a2168..dad197ee625 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -2077,18 +2077,16 @@ protected function switchPersisterContext($offset, $limit) * Retrieves class identifiers types * * @param ClassMetadata $class - * @return array + * @return string[] */ - protected function getClassIdentifiersTypes(ClassMetadata $class) + protected function getClassIdentifiersTypes(ClassMetadata $class): array { - $self = $this; - - return array_map(function ($identifier) use ($class, $self) { + return array_map(function ($identifier) use ($class) { if (isset($class->fieldMappings[$identifier])) { return $class->fieldMappings[$identifier]['type']; } - $targetMapping = $self->em->getClassMetadata($class->associationMappings[$identifier]['targetEntity']); + $targetMapping = $this->em->getClassMetadata($class->associationMappings[$identifier]['targetEntity']); if (isset($targetMapping->fieldMappings[$targetMapping->identifier[0]])) { return $targetMapping->fieldMappings[$targetMapping->identifier[0]]['type']; diff --git a/tests/Doctrine/Tests/DbalTypes/CustomIdObjectHashType.php b/tests/Doctrine/Tests/DbalTypes/CustomIdObjectHashType.php new file mode 100644 index 00000000000..963363e04c7 --- /dev/null +++ b/tests/Doctrine/Tests/DbalTypes/CustomIdObjectHashType.php @@ -0,0 +1,45 @@ +id . '_test'; + } + + /** + * {@inheritdoc} + */ + public function convertToPHPValue($value, AbstractPlatform $platform) + { + $idObject = new CustomIdObject(str_replace('_test', '', $value)); + + return $idObject; + } + + /** + * {@inheritdoc} + */ + public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) + { + return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration); + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return self::NAME; + } +} diff --git a/tests/Doctrine/Tests/DbalTypes/CustomIdObjectType.php b/tests/Doctrine/Tests/DbalTypes/CustomIdObjectType.php index 154f5778641..0ebae5dff0e 100644 --- a/tests/Doctrine/Tests/DbalTypes/CustomIdObjectType.php +++ b/tests/Doctrine/Tests/DbalTypes/CustomIdObjectType.php @@ -14,7 +14,7 @@ class CustomIdObjectType extends Type */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { - return $value->id . '_test'; + return $value->id; } /** @@ -22,7 +22,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) */ public function convertToPHPValue($value, AbstractPlatform $platform) { - $idObject = new CustomIdObject(str_replace('_test', '', $value)); + $idObject = new CustomIdObject($value); return $idObject; } diff --git a/tests/Doctrine/Tests/Models/ClassTableInheritanceCustomType/CustomIdObjectTypeParent.php b/tests/Doctrine/Tests/Models/ClassTableInheritanceCustomType/CustomIdObjectTypeParent.php index ef8ac142d06..6aa45f382f0 100644 --- a/tests/Doctrine/Tests/Models/ClassTableInheritanceCustomType/CustomIdObjectTypeParent.php +++ b/tests/Doctrine/Tests/Models/ClassTableInheritanceCustomType/CustomIdObjectTypeParent.php @@ -15,7 +15,7 @@ abstract class CustomIdObjectTypeParent { /** * @Id - * @Column(type="CustomIdObject") + * @Column(type="CustomIdObjectHash") * * @var CustomIdObject */ diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceCustomIdObjectTypeTest.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceCustomIdObjectTypeTest.php index 2768c02aab9..d2625136156 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceCustomIdObjectTypeTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceCustomIdObjectTypeTest.php @@ -4,9 +4,8 @@ use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\DbalTypes\CustomIdObject; -use Doctrine\Tests\DbalTypes\CustomIdObjectType; +use Doctrine\Tests\DbalTypes\CustomIdObjectHashType; use Doctrine\Tests\Models\ClassTableInheritanceCustomType\CustomIdObjectTypeChild; -use Doctrine\Tests\Models\ClassTableInheritanceCustomType\CustomIdObjectTypeParent; use Doctrine\Tests\OrmFunctionalTestCase; /** @@ -16,10 +15,10 @@ class ClassTableInheritanceCustomIdObjectTypeTest extends OrmFunctionalTestCase { protected function setUp() { - if (DBALType::hasType(CustomIdObjectType::NAME)) { - DBALType::overrideType(CustomIdObjectType::NAME, CustomIdObjectType::class); + if (DBALType::hasType(CustomIdObjectHashType::NAME)) { + DBALType::overrideType(CustomIdObjectHashType::NAME, CustomIdObjectHashType::class); } else { - DBALType::addType(CustomIdObjectType::NAME, CustomIdObjectType::class); + DBALType::addType(CustomIdObjectHashType::NAME, CustomIdObjectHashType::class); } $this->useModelSet('class_table_inheritance_custom_id_object_type'); diff --git a/tests/Doctrine/Tests/ORM/Functional/CustomIdObjectTypeTest.php b/tests/Doctrine/Tests/ORM/Functional/CustomIdObjectTypeTest.php index 75ffd05be93..08d89fa8ec2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CustomIdObjectTypeTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CustomIdObjectTypeTest.php @@ -84,7 +84,7 @@ public function testFetchJoinWhereCustomIdObject() . ' parent LEFT JOIN parent.children children ' . 'WHERE children.id = ?1' ) - ->setParameter(1, $parent->children->first()->id, CustomIdObjectType::NAME) + ->setParameter(1, $parent->children->first()->id) ->getResult(); $this->assertCount(1, $result); From 59f1679fed3006aa245c61e670dfac325bf8ccaf Mon Sep 17 00:00:00 2001 From: Dennis Enderink Date: Wed, 6 Mar 2019 07:56:14 +0100 Subject: [PATCH 814/877] Patched spacing --- lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php | 2 +- tests/Doctrine/Tests/DbalTypes/CustomIdObjectHashType.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index dad197ee625..75b2f79e068 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -2081,7 +2081,7 @@ protected function switchPersisterContext($offset, $limit) */ protected function getClassIdentifiersTypes(ClassMetadata $class): array { - return array_map(function ($identifier) use ($class) { + return array_map(function($identifier) use ($class) { if (isset($class->fieldMappings[$identifier])) { return $class->fieldMappings[$identifier]['type']; } diff --git a/tests/Doctrine/Tests/DbalTypes/CustomIdObjectHashType.php b/tests/Doctrine/Tests/DbalTypes/CustomIdObjectHashType.php index 963363e04c7..885f7b62dff 100644 --- a/tests/Doctrine/Tests/DbalTypes/CustomIdObjectHashType.php +++ b/tests/Doctrine/Tests/DbalTypes/CustomIdObjectHashType.php @@ -14,7 +14,7 @@ class CustomIdObjectHashType extends Type */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { - return $value->id . '_test'; + return $value->id.'_test'; } /** From 53775fe086ea7f07ab96d25189485f2870e74291 Mon Sep 17 00:00:00 2001 From: Dennis Enderink Date: Wed, 6 Mar 2019 08:15:39 +0100 Subject: [PATCH 815/877] Added correct return types to docblock --- lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 75b2f79e068..06b3ff3dec7 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -2077,7 +2077,7 @@ protected function switchPersisterContext($offset, $limit) * Retrieves class identifiers types * * @param ClassMetadata $class - * @return string[] + * @return int[]|string[] */ protected function getClassIdentifiersTypes(ClassMetadata $class): array { From 435d624d337bc6a10125f346d868fe896604c4ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Fri, 20 Sep 2019 15:56:52 +0200 Subject: [PATCH 816/877] Centralise functional test classes Which provides better isolation and makes things a bit more understandable. --- .../DbalTypes/CustomIdObjectHashType.php | 45 ------- .../CustomIdObjectTypeChild.php | 15 --- .../CustomIdObjectTypeParent.php | 39 ------ ...TableInheritanceCustomIdObjectTypeTest.php | 50 -------- .../Tests/ORM/Functional/GH5988Test.php | 114 ++++++++++++++++++ .../Doctrine/Tests/OrmFunctionalTestCase.php | 9 -- 6 files changed, 114 insertions(+), 158 deletions(-) delete mode 100644 tests/Doctrine/Tests/DbalTypes/CustomIdObjectHashType.php delete mode 100644 tests/Doctrine/Tests/Models/ClassTableInheritanceCustomType/CustomIdObjectTypeChild.php delete mode 100644 tests/Doctrine/Tests/Models/ClassTableInheritanceCustomType/CustomIdObjectTypeParent.php delete mode 100644 tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceCustomIdObjectTypeTest.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/GH5988Test.php diff --git a/tests/Doctrine/Tests/DbalTypes/CustomIdObjectHashType.php b/tests/Doctrine/Tests/DbalTypes/CustomIdObjectHashType.php deleted file mode 100644 index 885f7b62dff..00000000000 --- a/tests/Doctrine/Tests/DbalTypes/CustomIdObjectHashType.php +++ /dev/null @@ -1,45 +0,0 @@ -id.'_test'; - } - - /** - * {@inheritdoc} - */ - public function convertToPHPValue($value, AbstractPlatform $platform) - { - $idObject = new CustomIdObject(str_replace('_test', '', $value)); - - return $idObject; - } - - /** - * {@inheritdoc} - */ - public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) - { - return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration); - } - - /** - * {@inheritdoc} - */ - public function getName() - { - return self::NAME; - } -} diff --git a/tests/Doctrine/Tests/Models/ClassTableInheritanceCustomType/CustomIdObjectTypeChild.php b/tests/Doctrine/Tests/Models/ClassTableInheritanceCustomType/CustomIdObjectTypeChild.php deleted file mode 100644 index 99b433f4a67..00000000000 --- a/tests/Doctrine/Tests/Models/ClassTableInheritanceCustomType/CustomIdObjectTypeChild.php +++ /dev/null @@ -1,15 +0,0 @@ -id = $id; - $this->type = $type; - } -} diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceCustomIdObjectTypeTest.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceCustomIdObjectTypeTest.php deleted file mode 100644 index d2625136156..00000000000 --- a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceCustomIdObjectTypeTest.php +++ /dev/null @@ -1,50 +0,0 @@ -useModelSet('class_table_inheritance_custom_id_object_type'); - - parent::setUp(); - } - - public function testDelete() - { - $object = new CustomIdObjectTypeChild(new CustomIdObject('foo')); - $object->name = 'Test'; - - // persist parent - $this->_em->persist($object); - $this->_em->flush(); - - // save id for later use - $id = $object->id; - - // get child - $object2 = $this->_em->find(CustomIdObjectTypeChild::class, $id); - - // remove child - $this->_em->remove($object2); - $this->_em->flush(); - - $this->assertNull($this->_em->find(CustomIdObjectTypeChild::class, $id)); - } -} diff --git a/tests/Doctrine/Tests/ORM/Functional/GH5988Test.php b/tests/Doctrine/Tests/ORM/Functional/GH5988Test.php new file mode 100644 index 00000000000..928f432320d --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/GH5988Test.php @@ -0,0 +1,114 @@ +setUpEntitySchema([GH5988CustomIdObjectTypeParent::class, GH5988CustomIdObjectTypeChild::class]); + } + + public function testDelete() + { + $object = new GH5988CustomIdObjectTypeChild(new CustomIdObject('foo'), 'Test'); + + $this->_em->persist($object); + $this->_em->flush(); + + $id = $object->id; + + $object2 = $this->_em->find(GH5988CustomIdObjectTypeChild::class, $id); + + $this->_em->remove($object2); + $this->_em->flush(); + + self::assertNull($this->_em->find(GH5988CustomIdObjectTypeChild::class, $id)); + } +} + + +class GH5988CustomIdObjectHashType extends DBALType +{ + /** + * {@inheritdoc} + */ + public function convertToDatabaseValue($value, AbstractPlatform $platform) + { + return $value->id . '_test'; + } + /** + * {@inheritdoc} + */ + public function convertToPHPValue($value, AbstractPlatform $platform) + { + return new CustomIdObject(str_replace('_test', '', $value)); + } + /** + * {@inheritdoc} + */ + public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) + { + return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration); + } + /** + * {@inheritdoc} + */ + public function getName() + { + return self::class; + } +} + +/** + * @Entity + * @Table + * @InheritanceType("JOINED") + * @DiscriminatorColumn(name="type", type="string") + * @DiscriminatorMap({"child" = GH5988CustomIdObjectTypeChild::class}) + */ +abstract class GH5988CustomIdObjectTypeParent +{ + /** + * @Id + * @Column(type="Doctrine\Tests\ORM\Functional\GH5988CustomIdObjectHashType") + * @var CustomIdObject + */ + public $id; +} + + +/** + * @Entity + * @Table + */ +class GH5988CustomIdObjectTypeChild extends GH5988CustomIdObjectTypeParent +{ + /** @var string */ + public $name; + + public function __construct(CustomIdObject $id, string $name) + { + $this->id = $id; + $this->name = $name; + } +} diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 569e1a55f82..d45ebac6387 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -97,10 +97,6 @@ abstract class OrmFunctionalTestCase extends OrmTestCase * @var array */ protected static $_modelSets = [ - 'class_table_inheritance_custom_id_object_type' => [ - Models\ClassTableInheritanceCustomType\CustomIdObjectTypeParent::class, - Models\ClassTableInheritanceCustomType\CustomIdObjectTypeChild::class, - ], 'cms' => [ Models\CMS\CmsUser::class, Models\CMS\CmsPhonenumber::class, @@ -347,11 +343,6 @@ protected function tearDown() $this->_sqlLoggerStack->enabled = false; - if (isset($this->_usedModelSets['class_table_inheritance_custom_id_object_type'])) { - $conn->executeUpdate('DELETE FROM class_table_inheritance_custom_id_type_child'); - $conn->executeUpdate('DELETE FROM class_table_inheritance_custom_id_type_parent'); - } - if (isset($this->_usedModelSets['cms'])) { $conn->executeUpdate('DELETE FROM cms_users_groups'); $conn->executeUpdate('DELETE FROM cms_groups'); From ef783f7049386506e20c1fd6be6383f1a06386c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Fri, 20 Sep 2019 16:02:05 +0200 Subject: [PATCH 817/877] Make use of the PersisterHelper to get field type Removing the unnecessary code duplication. --- .../Entity/BasicEntityPersister.php | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 06b3ff3dec7..ea1f2efee3c 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -37,7 +37,9 @@ use Doctrine\ORM\UnitOfWork; use Doctrine\ORM\Utility\IdentifierFlattener; use Doctrine\ORM\Utility\PersisterHelper; +use function array_map; use function array_merge; +use function assert; use function reset; /** @@ -2074,29 +2076,20 @@ protected function switchPersisterContext($offset, $limit) } /** - * Retrieves class identifiers types - * - * @param ClassMetadata $class - * @return int[]|string[] + * @return string[] */ - protected function getClassIdentifiersTypes(ClassMetadata $class): array + protected function getClassIdentifiersTypes(ClassMetadata $class) : array { - return array_map(function($identifier) use ($class) { - if (isset($class->fieldMappings[$identifier])) { - return $class->fieldMappings[$identifier]['type']; - } + $entityManager = $this->em; - $targetMapping = $this->em->getClassMetadata($class->associationMappings[$identifier]['targetEntity']); + return array_map( + static function ($fieldName) use ($class, $entityManager) : string { + $types = PersisterHelper::getTypeOfField($fieldName, $class, $entityManager); + assert(isset($types[0])); - if (isset($targetMapping->fieldMappings[$targetMapping->identifier[0]])) { - return $targetMapping->fieldMappings[$targetMapping->identifier[0]]['type']; - } - - if (isset($targetMapping->associationMappings[$targetMapping->identifier[0]])) { - return $targetMapping->associationMappings[$targetMapping->identifier[0]]['type']; - } - - throw ORMException::unrecognizedField($targetMapping->identifier[0]); - }, $class->identifier); + return $types[0]; + }, + $class->identifier + ); } } From 6a74f373b9b8750839702132a69ddd7f589a094d Mon Sep 17 00:00:00 2001 From: Samuel NELA Date: Fri, 27 Sep 2019 21:59:32 +0200 Subject: [PATCH 818/877] Fix the name of ClassMetadata in documentation --- docs/en/reference/filters.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/filters.rst b/docs/en/reference/filters.rst index a5c0ee4cf14..87835260b92 100644 --- a/docs/en/reference/filters.rst +++ b/docs/en/reference/filters.rst @@ -39,7 +39,7 @@ proper quoting of parameters. Date: Wed, 3 Jul 2019 23:03:10 +0200 Subject: [PATCH 819/877] Remove misleading documentation EntityManagerHelper does not have a second argument, see https://github.com/doctrine/orm/blob/ca38249f6c71bc1d1c355822040a1788e3eeebd6/lib/Doctrine/ORM/Tools/Console/Helper/EntityManagerHelper.php#L49 --- docs/en/reference/tools.rst | 9 --------- 1 file changed, 9 deletions(-) diff --git a/docs/en/reference/tools.rst b/docs/en/reference/tools.rst index c3580b36d57..3b6cf334971 100644 --- a/docs/en/reference/tools.rst +++ b/docs/en/reference/tools.rst @@ -252,15 +252,6 @@ will output the SQL for the ran operation. Before using the orm:schema-tool commands, remember to configure your cli-config.php properly. -.. note:: - - When using the Annotation Mapping Driver you have to either setup - your autoloader in the cli-config.php correctly to find all the - entities, or you can use the second argument of the - ``EntityManagerHelper`` to specify all the paths of your entities - (or mapping files), i.e. - ``new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em, $mappingPaths);`` - Entity Generation ----------------- From 7c8c0906be8b1c37ea676e35e8455218385f4c7b Mon Sep 17 00:00:00 2001 From: axi Date: Tue, 1 Oct 2019 17:46:09 +0200 Subject: [PATCH 820/877] Update batch-processing.rst Looking for a way to improve one of our bulk update treatment, I went back to this page then found elsewhere that setting logger to null was a really effective way to improve time and memory consumption. Might be a right place to state it ? Don't know if my edit style is ok --- docs/en/reference/batch-processing.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/en/reference/batch-processing.rst b/docs/en/reference/batch-processing.rst index 4076f4fb9fb..6ab1e9c32af 100644 --- a/docs/en/reference/batch-processing.rst +++ b/docs/en/reference/batch-processing.rst @@ -16,6 +16,15 @@ especially what the strategies presented here provide help with. operations. +.. note:: + + Logger can have a serious memory and time impact on bulk treatments. + Deactivating it can be a solution. +.. code-block:: php + + getConnection()->getConfiguration()->setSQLLogger(null); + Bulk Inserts ------------ From bed81865735723065e81ac950d49d10f40b9c971 Mon Sep 17 00:00:00 2001 From: Guillaume Aveline Date: Thu, 27 Jun 2019 23:54:13 +0200 Subject: [PATCH 821/877] Fix comment quoting in the EntityGenerator Fixes: https://github.com/doctrine/orm/issues/7763 --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 3 ++- tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index aea736511e3..89761838c83 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -23,6 +23,7 @@ use Doctrine\Common\Inflector\Inflector; use Doctrine\DBAL\Types\Type; use Doctrine\ORM\Mapping\ClassMetadataInfo; +use function str_replace; /** * Generic class used to generate PHP5 entity classes from ClassMetadataInfo instances. @@ -1679,7 +1680,7 @@ protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, Cla } if (isset($fieldMapping['options']['comment']) && $fieldMapping['options']['comment']) { - $options[] = '"comment"="' . $fieldMapping['options']['comment'] .'"'; + $options[] = '"comment"="' . str_replace('"', '""', $fieldMapping['options']['comment']) . '"'; } if (isset($fieldMapping['options']['collation']) && $fieldMapping['options']['collation']) { diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index 438cf932333..42d62513b70 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -1223,6 +1223,10 @@ public function columnOptionsProvider() : array '@Column(name="test", type="string", length=10, options={"comment"="testing"})', ['type' => 'string', 'length' => 10, 'options' => ['comment' => 'testing']], ], + 'string-comment-quote' => [ + '@Column(name="test", type="string", length=10, options={"comment"="testing ""quotes"""})', + ['type' => 'string', 'length' => 10, 'options' => ['comment' => 'testing "quotes"']], + ], 'string-collation' => [ '@Column(name="test", type="string", length=10, options={"collation"="utf8mb4_general_ci"})', ['type' => 'string', 'length' => 10, 'options' => ['collation' => 'utf8mb4_general_ci']], From 3ac1f8e68010ff53d222822a04819b4a3a975016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Sch=C3=A4dlich?= Date: Thu, 4 Apr 2019 21:19:41 +0200 Subject: [PATCH 822/877] Added missing "the" --- docs/en/reference/unitofwork.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/unitofwork.rst b/docs/en/reference/unitofwork.rst index cdfb6e0be4a..b060c464a17 100644 --- a/docs/en/reference/unitofwork.rst +++ b/docs/en/reference/unitofwork.rst @@ -156,7 +156,7 @@ wishes to be hydrated. Default result-types include: - SQL to simple scalar result arrays - SQL to a single result variable -Hydration to entities and arrays is one of most complex parts of Doctrine +Hydration to entities and arrays is one of the most complex parts of Doctrine algorithm-wise. It can build results with for example: - Single table selects From 27fcc01d81ba4a97493a26b7ce800d680ab320e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Sch=C3=A4dlich?= Date: Wed, 3 Apr 2019 14:25:24 +0200 Subject: [PATCH 823/877] Fixes example One-To-One, Self-referencing --- docs/en/reference/association-mapping.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/association-mapping.rst b/docs/en/reference/association-mapping.rst index b7d6bb8d1df..6347d89c693 100644 --- a/docs/en/reference/association-mapping.rst +++ b/docs/en/reference/association-mapping.rst @@ -286,7 +286,7 @@ below. // ... /** - * One Student has One Student. + * One Student has One Mentor. * @OneToOne(targetEntity="Student") * @JoinColumn(name="mentor_id", referencedColumnName="id") */ From 766eb693fbdabe439b6bff95a778378365b83c65 Mon Sep 17 00:00:00 2001 From: Andriy Kmit Date: Fri, 31 May 2019 03:33:35 +0300 Subject: [PATCH 824/877] Finish incomplete definition of class UTCDateTimeType --- docs/en/cookbook/working-with-datetime.rst | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/en/cookbook/working-with-datetime.rst b/docs/en/cookbook/working-with-datetime.rst index 363c74fdd49..f599b836b41 100644 --- a/docs/en/cookbook/working-with-datetime.rst +++ b/docs/en/cookbook/working-with-datetime.rst @@ -90,7 +90,10 @@ the UTC time at the time of the booking and the timezone the event happened in. class UTCDateTimeType extends DateTimeType { - static private $utc; + /** + * @var \DateTimeZone + */ + private static $utc; public function convertToDatabaseValue($value, AbstractPlatform $platform) { @@ -110,7 +113,7 @@ the UTC time at the time of the booking and the timezone the event happened in. $converted = \DateTime::createFromFormat( $platform->getDateTimeFormatString(), $value, - self::$utc ? self::$utc : self::$utc = new \DateTimeZone('UTC') + self::getUtc() ); if (! $converted) { @@ -123,6 +126,11 @@ the UTC time at the time of the booking and the timezone the event happened in. return $converted; } + + private static function getUtc(): \DateTimeZone + { + return self::$utc ?: self::$utc = new \DateTimeZone('UTC'); + } } This database type makes sure that every DateTime instance is always saved in UTC, relative From b37ceaa9f79a4a3effb9bf0b19055e22a4dedb08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Thu, 5 Jul 2018 14:43:14 +0200 Subject: [PATCH 825/877] Add a missing type in Query::getFirstResult and Query::getDQL --- lib/Doctrine/ORM/Query.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 2bc480a9b07..c9d8fb673e0 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -145,7 +145,7 @@ final class Query extends AbstractQuery /** * Cached DQL query. * - * @var string + * @var string|null */ private $_dql = null; @@ -159,7 +159,7 @@ final class Query extends AbstractQuery /** * The first result to return (the "offset"). * - * @var integer + * @var int|null */ private $_firstResult = null; @@ -587,7 +587,7 @@ public function setDQL($dqlQuery) /** * Returns the DQL query that is represented by this query object. * - * @return string DQL query. + * @return string|null */ public function getDQL() { @@ -640,7 +640,7 @@ public function setFirstResult($firstResult) * Gets the position of the first result the query object was set to retrieve (the "offset"). * Returns NULL if {@link setFirstResult} was not applied to this query. * - * @return integer The position of the first result. + * @return int|null The position of the first result. */ public function getFirstResult() { From 79a7ecc92f7116d56bedfa106a93b39b830fee3d Mon Sep 17 00:00:00 2001 From: Lars Lauger Date: Tue, 1 Oct 2019 21:40:24 +0200 Subject: [PATCH 826/877] Don't merge PersistentCollection orderBy with criteria in matching() If no orderings are given to PersistentCollection::matching(), the orderBy annotation will be used if present. If the criteria contains orderings, those will be used without merging them with the orderBy. See #7836 --- lib/Doctrine/ORM/PersistentCollection.php | 3 +- .../ORM/Functional/Ticket/GH7836Test.php | 135 ++++++++++++++++++ 2 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH7836Test.php diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index 47b9bae20d4..c49e5e5f203 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -25,7 +25,6 @@ use Doctrine\Common\Collections\Selectable; use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\Mapping\ClassMetadata; -use function array_merge; use function get_class; /** @@ -672,7 +671,7 @@ public function matching(Criteria $criteria) $criteria = clone $criteria; $criteria->where($expression); - $criteria->orderBy(array_merge($this->association['orderBy'] ?? [], $criteria->getOrderings())); + $criteria->orderBy($criteria->getOrderings() ?: $this->association['orderBy'] ?? []); $persister = $this->em->getUnitOfWork()->getEntityPersister($this->association['targetEntity']); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7836Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7836Test.php new file mode 100644 index 00000000000..ab1ceeb7297 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7836Test.php @@ -0,0 +1,135 @@ +setUpEntitySchema([GH7836ParentEntity::class, GH7836ChildEntity::class]); + + $parent = new GH7836ParentEntity(); + $parent->addChild(100, 'foo'); + $parent->addChild(100, 'bar'); + $parent->addChild(200, 'baz'); + + $this->_em->persist($parent); + $this->_em->flush(); + $this->_em->clear(); + } + + public function testMatchingRespectsCollectionOrdering() : void + { + $parent = $this->_em->find(GH7836ParentEntity::class, 1); + assert($parent instanceof GH7836ParentEntity); + + $children = $parent->getChildren()->matching(Criteria::create()); + + self::assertSame(100, $children[0]->position); + self::assertSame('bar', $children[0]->name); + self::assertSame(100, $children[1]->position); + self::assertSame('foo', $children[1]->name); + self::assertSame(200, $children[2]->position); + self::assertSame('baz', $children[2]->name); + } + + public function testMatchingOverrulesCollectionOrdering() : void + { + $parent = $this->_em->find(GH7836ParentEntity::class, 1); + assert($parent instanceof GH7836ParentEntity); + + $children = $parent->getChildren()->matching(Criteria::create()->orderBy(['position' => 'DESC', 'name' => 'ASC'])); + + self::assertSame(200, $children[0]->position); + self::assertSame('baz', $children[0]->name); + self::assertSame(100, $children[1]->position); + self::assertSame('bar', $children[1]->name); + self::assertSame(100, $children[2]->position); + self::assertSame('foo', $children[2]->name); + } + + public function testMatchingKeepsOrderOfCriteriaOrderingKeys() : void + { + $parent = $this->_em->find(GH7836ParentEntity::class, 1); + assert($parent instanceof GH7836ParentEntity); + + $children = $parent->getChildren()->matching(Criteria::create()->orderBy(['name' => 'ASC', 'position' => 'ASC'])); + + self::assertSame(100, $children[0]->position); + self::assertSame('bar', $children[0]->name); + self::assertSame(200, $children[1]->position); + self::assertSame('baz', $children[1]->name); + self::assertSame(100, $children[2]->position); + self::assertSame('foo', $children[2]->name); + } +} + +/** + * @Entity + */ +class GH7836ParentEntity +{ + /** + * @Id + * @Column(type="integer") + * @GeneratedValue + */ + private $id; + + /** + * @OneToMany(targetEntity=GH7836ChildEntity::class, mappedBy="parent", fetch="EXTRA_LAZY", cascade={"persist"}) + * @OrderBy({"position" = "ASC", "name" = "ASC"}) + */ + private $children; + + public function addChild(int $position, string $name) : void + { + $this->children[] = new GH7836ChildEntity($this, $position, $name); + } + + public function getChildren() : PersistentCollection + { + return $this->children; + } +} + +/** + * @Entity + */ +class GH7836ChildEntity +{ + /** + * @Id + * @Column(type="integer") + * @GeneratedValue + */ + private $id; + + /** @Column(type="integer") */ + public $position; + + /** @Column(type="string") */ + public $name; + + /** @ManyToOne(targetEntity=GH7836ParentEntity::class, inversedBy="children") */ + private $parent; + + public function __construct(GH7836ParentEntity $parent, int $position, string $name) + { + $this->parent = $parent; + $this->position = $position; + $this->name = $name; + } +} From 3707c3912428423347473a9f20c86a7d858380c4 Mon Sep 17 00:00:00 2001 From: Alexander Deider Date: Mon, 30 Sep 2019 17:24:42 +0700 Subject: [PATCH 827/877] #7841 SchemaTool generates extra diff for platforms without FK support --- lib/Doctrine/ORM/Tools/SchemaTool.php | 5 ++ .../ORM/Functional/Ticket/DDC2138Test.php | 3 + .../ORM/Functional/Ticket/GH7841Test.php | 57 +++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH7841Test.php diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 423ed3b5320..ba63e6964d5 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -709,6 +709,11 @@ private function gatherRelationJoinColumns( } $compositeName = $theJoinTable->getName().'.'.implode('', $localColumns); + + if (! $this->platform->supportsForeignKeyConstraints()) { + return; + } + if (isset($addedFks[$compositeName]) && ($foreignTableName != $addedFks[$compositeName]['foreignTableName'] || 0 < count(array_diff($foreignColumns, $addedFks[$compositeName]['foreignColumns']))) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2138Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2138Test.php index 960395e9c70..c6019f849c5 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2138Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2138Test.php @@ -14,6 +14,9 @@ class DDC2138Test extends OrmFunctionalTestCase public function testForeignKeyOnSTIWithMultipleMapping() { $em = $this->_em; + if (! $em->getConnection()->getDatabasePlatform()->supportsForeignKeyConstraints()) { + $this->markTestSkipped('Platform does not support foreign keys.'); + } $schemaTool = new SchemaTool($em); $classes = [ diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7841Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7841Test.php new file mode 100644 index 00000000000..4e6f46324ca --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7841Test.php @@ -0,0 +1,57 @@ +_em->getConnection()->getDatabasePlatform()->supportsForeignKeyConstraints()) { + $this->markTestSkipped('Test for platforms without foreign keys support'); + } + $class = $this->_em->getClassMetadata(GH7841Child::class); + $this->_schemaTool->updateSchema([$class], true); + $diff = $this->_schemaTool->getUpdateSchemaSql([$class], true); + + self::assertEmpty($diff); + + $this->_schemaTool->dropSchema([$class]); + } +} + +/** + * @Entity + */ +class GH7841Parent +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; + + /** @OneToMany(targetEntity=GH7841Child::class, mappedBy="parent") */ + public $children; + + public function __construct() + { + $this->children = new ArrayCollection(); + } +} + +/** + * @Entity + */ +class GH7841Child +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; + + /** @ManyToOne(targetEntity=GH7841Parent::class) */ + public $parent; +} From 00c6b1bc60e9bdc4871d19e6118cb372e387d539 Mon Sep 17 00:00:00 2001 From: axi Date: Wed, 2 Oct 2019 14:00:06 +0200 Subject: [PATCH 828/877] Update batch-processing.rst Clarify note --- docs/en/reference/batch-processing.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/reference/batch-processing.rst b/docs/en/reference/batch-processing.rst index 6ab1e9c32af..e238516c561 100644 --- a/docs/en/reference/batch-processing.rst +++ b/docs/en/reference/batch-processing.rst @@ -18,8 +18,8 @@ especially what the strategies presented here provide help with. .. note:: - Logger can have a serious memory and time impact on bulk treatments. - Deactivating it can be a solution. + Having an SQL logger enabled when processing batches can have a serious impact on performance and resource usage. + To avoid that you should disable it in the DBAL configuration: .. code-block:: php Date: Thu, 3 Oct 2019 11:14:24 +0300 Subject: [PATCH 829/877] remove not used variable $reflFieldValue in ObjectHydrator --- lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index 42f59973942..5048216cf7b 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -422,7 +422,7 @@ protected function hydrateRowData(array $row, array &$result) $this->resultPointers[$dqlAlias] = $reflFieldValue[$index]; } } else if ( ! $reflFieldValue) { - $reflFieldValue = $this->initRelatedCollection($parentObject, $parentClass, $relationField, $parentAlias); + $this->initRelatedCollection($parentObject, $parentClass, $relationField, $parentAlias); } else if ($reflFieldValue instanceof PersistentCollection && $reflFieldValue->isInitialized() === false) { $reflFieldValue->setInitialized(true); } From 506bf0ee129062712b95f32e8665fcefc56c9ebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Tue, 8 Oct 2019 11:25:47 +0200 Subject: [PATCH 830/877] Allow numbers in property names on underscore naming strategy --- .../ORM/Mapping/UnderscoreNamingStrategy.php | 33 +++++++++++-------- .../Tests/ORM/Mapping/NamingStrategyTest.php | 28 ++++++++++++++++ 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php b/lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php index 543d92ba31c..142f1bbb14e 100644 --- a/lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php +++ b/lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php @@ -20,17 +20,29 @@ namespace Doctrine\ORM\Mapping; +use const CASE_LOWER; +use const CASE_UPPER; +use function preg_replace; +use function strpos; +use function strrpos; +use function strtolower; +use function strtoupper; +use function substr; + /** * Naming strategy implementing the underscore naming convention. * Converts 'MyEntity' to 'my_entity' or 'MY_ENTITY'. * - * + * * @link www.doctrine-project.org * @since 2.3 * @author Fabio B. Silva */ class UnderscoreNamingStrategy implements NamingStrategy { + private const DEFAULT_PATTERN = '/(?<=[a-z])([A-Z])/'; + private const PATTERN_FOR_PROPERTIES = '/(?<=[a-z0-9])([A-Z])/'; + /** * @var integer */ @@ -57,7 +69,7 @@ public function getCase() /** * Sets string case CASE_LOWER | CASE_UPPER. * Alphabetic characters converted to lowercase or uppercase. - * + * * @param integer $case * * @return void @@ -84,7 +96,7 @@ public function classToTableName($className) */ public function propertyToColumnName($propertyName, $className = null) { - return $this->underscore($propertyName); + return $this->underscore($propertyName, self::PATTERN_FOR_PROPERTIES); } /** @@ -108,7 +120,7 @@ public function referenceColumnName() */ public function joinColumnName($propertyName, $className = null) { - return $this->underscore($propertyName) . '_' . $this->referenceColumnName(); + return $this->underscore($propertyName, self::PATTERN_FOR_PROPERTIES) . '_' . $this->referenceColumnName(); } /** @@ -118,7 +130,7 @@ public function joinTableName($sourceEntity, $targetEntity, $propertyName = null { return $this->classToTableName($sourceEntity) . '_' . $this->classToTableName($targetEntity); } - + /** * {@inheritdoc} */ @@ -127,15 +139,10 @@ public function joinKeyColumnName($entityName, $referencedColumnName = null) return $this->classToTableName($entityName) . '_' . ($referencedColumnName ?: $this->referenceColumnName()); } - - /** - * @param string $string - * - * @return string - */ - private function underscore($string) + + private function underscore(string $string, string $pattern = self::DEFAULT_PATTERN) : string { - $string = preg_replace('/(?<=[a-z])([A-Z])/', '_$1', $string); + $string = preg_replace($pattern, '_$1', $string); if ($this->case === CASE_UPPER) { return strtoupper($string); diff --git a/tests/Doctrine/Tests/ORM/Mapping/NamingStrategyTest.php b/tests/Doctrine/Tests/ORM/Mapping/NamingStrategyTest.php index 220a26363ca..95407b7f399 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/NamingStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/NamingStrategyTest.php @@ -108,12 +108,28 @@ static public function dataPropertyToColumnName() self::defaultNaming(), 'some_property', 'some_property' ], + [ + self::defaultNaming(), 'base64Encoded', + 'base64Encoded' + ], + [ + self::defaultNaming(), 'base64_encoded', + 'base64_encoded' + ], // UnderscoreNamingStrategy [ self::underscoreNamingLower(), 'some_property', 'someProperty' ], + [ + self::underscoreNamingLower(), 'base64_encoded', + 'base64Encoded' + ], + [ + self::underscoreNamingLower(), 'base64encoded', + 'base64encoded' + ], [ self::underscoreNamingUpper(), 'SOME_PROPERTY', 'someProperty' @@ -126,6 +142,14 @@ static public function dataPropertyToColumnName() self::underscoreNamingUpper(), 'SOME_PROPERTY', 'SOME_PROPERTY' ], + [ + self::underscoreNamingUpper(), 'BASE64_ENCODED', + 'base64Encoded' + ], + [ + self::underscoreNamingUpper(), 'BASE64ENCODED', + 'base64encoded' + ], ]; } @@ -180,10 +204,14 @@ static public function dataJoinColumnName() // DefaultNamingStrategy [self::defaultNaming(), 'someColumn_id', 'someColumn', null], [self::defaultNaming(), 'some_column_id', 'some_column', null], + [self::defaultNaming(), 'base64Encoded_id', 'base64Encoded', null], + [self::defaultNaming(), 'base64_encoded_id', 'base64_encoded', null], // UnderscoreNamingStrategy [self::underscoreNamingLower(), 'some_column_id', 'someColumn', null], + [self::underscoreNamingLower(), 'base64_encoded_id', 'base64Encoded', null], [self::underscoreNamingUpper(), 'SOME_COLUMN_ID', 'someColumn', null], + [self::underscoreNamingUpper(), 'BASE64_ENCODED_ID', 'base64Encoded', null], // JoinColumnClassNamingStrategy [new JoinColumnClassNamingStrategy(), 'classname_someColumn_id', 'someColumn', 'Some\ClassName'], [new JoinColumnClassNamingStrategy(), 'classname_some_column_id', 'some_column', 'ClassName'], From c802bc46a5e8750236199adbd74bd86d70569da7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Tue, 8 Oct 2019 11:39:16 +0200 Subject: [PATCH 831/877] Format NamingStrategyTest according to our CS --- .../Tests/ORM/Mapping/NamingStrategyTest.php | 288 +++++------------- 1 file changed, 84 insertions(+), 204 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Mapping/NamingStrategyTest.php b/tests/Doctrine/Tests/ORM/Mapping/NamingStrategyTest.php index 95407b7f399..b6ac43f932f 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/NamingStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/NamingStrategyTest.php @@ -1,38 +1,33 @@ */ - static public function dataClassToTableName() + public static function dataClassToTableName() : array { return [ // DefaultNamingStrategy - [ - self::defaultNaming(), 'SomeClassName', - 'SomeClassName' - ], - [ - self::defaultNaming(), 'SomeClassName', - '\SomeClassName' - ], - [ - self::defaultNaming(), 'Name', - '\Some\Class\Name' - ], + [self::defaultNaming(), 'SomeClassName', 'SomeClassName'], + [self::defaultNaming(), 'SomeClassName', '\SomeClassName'], + [self::defaultNaming(), 'Name', '\Some\Class\Name'], // UnderscoreNamingStrategy - [ - self::underscoreNamingLower(), 'some_class_name', - '\Name\Space\SomeClassName' - ], - [ - self::underscoreNamingLower(), 'name', - '\Some\Class\Name' - ], - [ - self::underscoreNamingUpper(), 'SOME_CLASS_NAME', - '\Name\Space\SomeClassName' - ], - [ - self::underscoreNamingUpper(), 'NAME', - '\Some\Class\Name' - ], + [self::underscoreNamingLower(), 'some_class_name', '\Name\Space\SomeClassName'], + [self::underscoreNamingLower(), 'name', '\Some\Class\Name'], + [self::underscoreNamingUpper(), 'SOME_CLASS_NAME', '\Name\Space\SomeClassName'], + [self::underscoreNamingUpper(), 'NAME', '\Some\Class\Name'], ]; } /** * @dataProvider dataClassToTableName */ - public function testClassToTableName(NamingStrategy $strategy, $expected, $className) + public function testClassToTableName(NamingStrategy $strategy, string $expected, string $className) : void { - $this->assertEquals($expected, $strategy->classToTableName($className)); + self::assertSame($expected, $strategy->classToTableName($className)); } /** * Data Provider for NamingStrategy#propertyToColumnName * - * @return array + * @return array */ - static public function dataPropertyToColumnName() + public static function dataPropertyToColumnName() : array { return [ // DefaultNamingStrategy - [ - self::defaultNaming(), 'someProperty', - 'someProperty' - ], - [ - self::defaultNaming(), 'SOME_PROPERTY', - 'SOME_PROPERTY' - ], - [ - self::defaultNaming(), 'some_property', - 'some_property' - ], - [ - self::defaultNaming(), 'base64Encoded', - 'base64Encoded' - ], - [ - self::defaultNaming(), 'base64_encoded', - 'base64_encoded' - ], + [self::defaultNaming(), 'someProperty', 'someProperty'], + [self::defaultNaming(), 'SOME_PROPERTY', 'SOME_PROPERTY'], + [self::defaultNaming(), 'some_property', 'some_property'], + [self::defaultNaming(), 'base64Encoded', 'base64Encoded'], + [self::defaultNaming(), 'base64_encoded', 'base64_encoded'], // UnderscoreNamingStrategy - [ - self::underscoreNamingLower(), 'some_property', - 'someProperty' - ], - [ - self::underscoreNamingLower(), 'base64_encoded', - 'base64Encoded' - ], - [ - self::underscoreNamingLower(), 'base64encoded', - 'base64encoded' - ], - [ - self::underscoreNamingUpper(), 'SOME_PROPERTY', - 'someProperty' - ], - [ - self::underscoreNamingUpper(), 'SOME_PROPERTY', - 'some_property' - ], - [ - self::underscoreNamingUpper(), 'SOME_PROPERTY', - 'SOME_PROPERTY' - ], - [ - self::underscoreNamingUpper(), 'BASE64_ENCODED', - 'base64Encoded' - ], - [ - self::underscoreNamingUpper(), 'BASE64ENCODED', - 'base64encoded' - ], + [self::underscoreNamingLower(), 'some_property', 'someProperty'], + [self::underscoreNamingLower(), 'base64_encoded', 'base64Encoded'], + [self::underscoreNamingLower(), 'base64encoded', 'base64encoded'], + [self::underscoreNamingUpper(), 'SOME_PROPERTY', 'someProperty'], + [self::underscoreNamingUpper(), 'SOME_PROPERTY', 'some_property'], + [self::underscoreNamingUpper(), 'SOME_PROPERTY', 'SOME_PROPERTY'], + [self::underscoreNamingUpper(), 'BASE64_ENCODED', 'base64Encoded'], + [self::underscoreNamingUpper(), 'BASE64ENCODED', 'base64encoded'], ]; } /** * @dataProvider dataPropertyToColumnName - * - * @param NamingStrategy $strategy - * @param string $expected - * @param string $propertyName */ - public function testPropertyToColumnName(NamingStrategy $strategy, $expected, $propertyName) + public function testPropertyToColumnName(NamingStrategy $strategy, string $expected, string $propertyName) : void { - $this->assertEquals($expected, $strategy->propertyToColumnName($propertyName)); + self::assertSame($expected, $strategy->propertyToColumnName($propertyName)); } /** * Data Provider for NamingStrategy#referenceColumnName * - * @return array + * @return array */ - static public function dataReferenceColumnName() + public static function dataReferenceColumnName() : array { return [ // DefaultNamingStrategy @@ -184,21 +115,18 @@ static public function dataReferenceColumnName() /** * @dataProvider dataReferenceColumnName - * - * @param NamingStrategy $strategy - * @param string $expected */ - public function testReferenceColumnName(NamingStrategy $strategy, $expected) + public function testReferenceColumnName(NamingStrategy $strategy, string $expected) : void { - $this->assertEquals($expected, $strategy->referenceColumnName()); + self::assertSame($expected, $strategy->referenceColumnName()); } /** * Data Provider for NamingStrategy#joinColumnName * - * @return array + * @return array */ - static public function dataJoinColumnName() + public static function dataJoinColumnName() : array { return [ // DefaultNamingStrategy @@ -220,131 +148,83 @@ static public function dataJoinColumnName() /** * @dataProvider dataJoinColumnName - * - * @param NamingStrategy $strategy - * @param string $expected - * @param string $propertyName */ - public function testJoinColumnName(NamingStrategy $strategy, $expected, $propertyName, $className = null) - { - $this->assertEquals($expected, $strategy->joinColumnName($propertyName, $className)); + public function testJoinColumnName( + NamingStrategy $strategy, + string $expected, + string $propertyName, + ?string $className = null + ) : void { + self::assertSame($expected, $strategy->joinColumnName($propertyName, $className)); } /** * Data Provider for NamingStrategy#joinTableName * - * @return array + * @return array */ - static public function dataJoinTableName() + public static function dataJoinTableName() : array { return [ // DefaultNamingStrategy - [ - self::defaultNaming(), 'someclassname_classname', - 'SomeClassName', 'Some\ClassName', null, - ], - [ - self::defaultNaming(), 'someclassname_classname', - '\SomeClassName', 'ClassName', null, - ], - [ - self::defaultNaming(), 'name_classname', - '\Some\Class\Name', 'ClassName', null, - ], + [self::defaultNaming(), 'someclassname_classname', 'SomeClassName', 'Some\ClassName', null], + [self::defaultNaming(), 'someclassname_classname', '\SomeClassName', 'ClassName', null], + [self::defaultNaming(), 'name_classname', '\Some\Class\Name', 'ClassName', null], // UnderscoreNamingStrategy - [ - self::underscoreNamingLower(), 'some_class_name_class_name', - 'SomeClassName', 'Some\ClassName', null, - ], - [ - self::underscoreNamingLower(), 'some_class_name_class_name', - '\SomeClassName', 'ClassName', null, - ], - [ - self::underscoreNamingLower(), 'name_class_name', - '\Some\Class\Name', 'ClassName', null, - ], - - [ - self::underscoreNamingUpper(), 'SOME_CLASS_NAME_CLASS_NAME', - 'SomeClassName', 'Some\ClassName', null, - ], - [ - self::underscoreNamingUpper(), 'SOME_CLASS_NAME_CLASS_NAME', - '\SomeClassName', 'ClassName', null, - ], - [ - self::underscoreNamingUpper(), 'NAME_CLASS_NAME', - '\Some\Class\Name', 'ClassName', null, - ], + [self::underscoreNamingLower(), 'some_class_name_class_name', 'SomeClassName', 'Some\ClassName', null], + [self::underscoreNamingLower(), 'some_class_name_class_name', '\SomeClassName', 'ClassName', null], + [self::underscoreNamingLower(), 'name_class_name', '\Some\Class\Name', 'ClassName', null], + [self::underscoreNamingUpper(), 'SOME_CLASS_NAME_CLASS_NAME', 'SomeClassName', 'Some\ClassName', null], + [self::underscoreNamingUpper(), 'SOME_CLASS_NAME_CLASS_NAME', '\SomeClassName', 'ClassName', null], + [self::underscoreNamingUpper(), 'NAME_CLASS_NAME', '\Some\Class\Name', 'ClassName', null], ]; } /** * @dataProvider dataJoinTableName - * - * @param NamingStrategy $strategy - * @param string $expected - * @param string $ownerEntity - * @param string $associatedEntity - * @param string $propertyName */ - public function testJoinTableName(NamingStrategy $strategy, $expected, $ownerEntity, $associatedEntity, $propertyName = null) - { - $this->assertEquals($expected, $strategy->joinTableName($ownerEntity, $associatedEntity, $propertyName)); + public function testJoinTableName( + NamingStrategy $strategy, + string $expected, + string $ownerEntity, + string $associatedEntity, + ?string $propertyName = null + ) : void { + self::assertSame($expected, $strategy->joinTableName($ownerEntity, $associatedEntity, $propertyName)); } /** * Data Provider for NamingStrategy#joinKeyColumnName * - * @return array + * @return array */ - static public function dataJoinKeyColumnName() + public static function dataJoinKeyColumnName() : array { return [ // DefaultNamingStrategy - [ - self::defaultNaming(), 'someclassname_id', - 'SomeClassName', null, null, - ], - [ - self::defaultNaming(), 'name_identifier', - '\Some\Class\Name', 'identifier', null, - ], + [self::defaultNaming(), 'someclassname_id', 'SomeClassName', null, null], + [self::defaultNaming(), 'name_identifier', '\Some\Class\Name', 'identifier', null], // UnderscoreNamingStrategy - [ - self::underscoreNamingLower(), 'some_class_name_id', - 'SomeClassName', null, null, - ], - [ - self::underscoreNamingLower(), 'class_name_identifier', - '\Some\Class\ClassName', 'identifier', null, - ], + [self::underscoreNamingLower(), 'some_class_name_id', 'SomeClassName', null, null], + [self::underscoreNamingLower(), 'class_name_identifier', '\Some\Class\ClassName', 'identifier', null], - [ - self::underscoreNamingUpper(), 'SOME_CLASS_NAME_ID', - 'SomeClassName', null, null, - ], - [ - self::underscoreNamingUpper(), 'CLASS_NAME_IDENTIFIER', - '\Some\Class\ClassName', 'IDENTIFIER', null, - ], + [self::underscoreNamingUpper(), 'SOME_CLASS_NAME_ID', 'SomeClassName', null, null], + [self::underscoreNamingUpper(), 'CLASS_NAME_IDENTIFIER', '\Some\Class\ClassName', 'IDENTIFIER', null], ]; } /** * @dataProvider dataJoinKeyColumnName - * - * @param NamingStrategy $strategy - * @param string $expected - * @param string $propertyEntityName - * @param string $referencedColumnName - * @param string $propertyName */ - public function testJoinKeyColumnName(NamingStrategy $strategy, $expected, $propertyEntityName, $referencedColumnName = null, $propertyName = null) - { - $this->assertEquals($expected, $strategy->joinKeyColumnName($propertyEntityName, $referencedColumnName, $propertyName)); + public function testJoinKeyColumnName( + NamingStrategy $strategy, + string $expected, + string $propertyEntityName, + ?string $referencedColumnName = null, + ?string $propertyName = null + ) : void { + self::assertSame($expected, $strategy->joinKeyColumnName($propertyEntityName, $referencedColumnName, $propertyName)); } } From d71dd5d94f186be63c15b55ebef0e14627e11fdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Tue, 8 Oct 2019 20:04:50 +0200 Subject: [PATCH 832/877] Bump up version --- lib/Doctrine/ORM/Version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Version.php b/lib/Doctrine/ORM/Version.php index a22c9690773..53297999976 100644 --- a/lib/Doctrine/ORM/Version.php +++ b/lib/Doctrine/ORM/Version.php @@ -35,7 +35,7 @@ class Version /** * Current Doctrine Version */ - const VERSION = '2.6.4-DEV'; + const VERSION = '2.6.5-DEV'; /** * Compares a Doctrine version with the current one. From b59fc23f869547c2eb82d7181bf456086229d379 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 10 Oct 2019 17:30:43 +0200 Subject: [PATCH 833/877] #7837 reproduced issue: DQL caching prevents `WhereInWalker` run Since `WhereInWalker` does not run, query parameters are not translated from their in-memory type to the expected SQL type when the paginator is run again with the same DQL string. This is an architectural issue, since (for the sake of simplicity) we moved parameter translation into the SQL walker, we didn't consider that SQL walkers only act when no cache is in place. The translatio needs to be moved into the paginator logic again. --- .../ORM/Functional/Ticket/GH7820Test.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7820Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7820Test.php index b1732b4a918..afb29f08369 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7820Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7820Test.php @@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\Common\Cache\ClearableCache; use Doctrine\Common\Collections\Criteria; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\StringType; @@ -11,6 +12,7 @@ use Doctrine\ORM\Tools\Pagination\Paginator; use Doctrine\Tests\OrmFunctionalTestCase; use function array_map; +use function assert; use function is_string; use function iterator_to_array; @@ -53,6 +55,9 @@ protected function setUp() : void $this->setUpEntitySchema([GH7820Line::class]); + $this->_em->createQuery('DELETE FROM ' . GH7820Line::class . ' l') + ->execute(); + foreach (self::SONG as $index => $line) { $this->_em->persist(new GH7820Line(GH7820LineText::fromText($line), $index)); } @@ -73,6 +78,41 @@ public function testWillFindSongsInPaginator() : void }, iterator_to_array(new Paginator($query))) ); } + + /** @group GH7837 */ + public function testWillFindSongsInPaginatorEvenWithCachedQueryParsing() : void + { + $cache = $this->_em->getConfiguration() + ->getQueryCacheImpl(); + + assert($cache instanceof ClearableCache); + + $cache->deleteAll(); + + $query = $this->_em->getRepository(GH7820Line::class) + ->createQueryBuilder('l') + ->orderBy('l.lineNumber', Criteria::ASC); + + self::assertSame( + self::SONG, + array_map(static function (GH7820Line $line) : string { + return $line->toString(); + }, iterator_to_array(new Paginator($query))), + 'Paginator runs once, query cache is populated with DQL -> SQL translation' + ); + + $query = $this->_em->getRepository(GH7820Line::class) + ->createQueryBuilder('l') + ->orderBy('l.lineNumber', Criteria::ASC); + + self::assertSame( + self::SONG, + array_map(static function (GH7820Line $line) : string { + return $line->toString(); + }, iterator_to_array(new Paginator($query))), + 'Paginator runs again, SQL parameters are translated again, even with cached DQL -> SQL translation' + ); + } } /** @Entity */ From 023e94661a1956215a6ddf17cb1b8908274b0d01 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 10 Oct 2019 18:23:31 +0200 Subject: [PATCH 834/877] #7837 force expiry of query cache when `WhereInWalker` is being used In order to figure out the paginated query identifier type, we would have to parse the DQL query into an AST+SQL anyway, so we'd have to re-parse it manually: instead of doing that, we can force the `WhereInWalker` to be reached at all times by forcing the `$whereInQuery` to use no query cache. While it is a sad performance regression, it is also not a noticeable one, since we'll be performing an `O(1)` operation around an I/O one (query execution, in this case). --- lib/Doctrine/ORM/Tools/Pagination/Paginator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Doctrine/ORM/Tools/Pagination/Paginator.php b/lib/Doctrine/ORM/Tools/Pagination/Paginator.php index 6c9ee44d03d..08c924bc598 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/Paginator.php +++ b/lib/Doctrine/ORM/Tools/Pagination/Paginator.php @@ -166,6 +166,7 @@ public function getIterator() $whereInQuery->setFirstResult(null)->setMaxResults(null); $whereInQuery->setParameter(WhereInWalker::PAGINATOR_ID_ALIAS, $ids); $whereInQuery->setCacheable($this->query->isCacheable()); + $whereInQuery->expireQueryCache(); $result = $whereInQuery->getResult($this->query->getHydrationMode()); } else { From cc5f84ac22815747a5b9b41bad2c4519674a1684 Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Tue, 15 Oct 2019 23:53:12 +0200 Subject: [PATCH 835/877] UnitOfWork::clear() misses $eagerLoadingEntities --- lib/Doctrine/ORM/UnitOfWork.php | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 82695984b65..773eae23b6b 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -2483,22 +2483,23 @@ public function getCommitOrderCalculator() public function clear($entityName = null) { if ($entityName === null) { - $this->identityMap = - $this->entityIdentifiers = - $this->originalEntityData = - $this->entityChangeSets = - $this->entityStates = - $this->scheduledForSynchronization = - $this->entityInsertions = - $this->entityUpdates = - $this->entityDeletions = + $this->identityMap = + $this->entityIdentifiers = + $this->originalEntityData = + $this->entityChangeSets = + $this->entityStates = + $this->scheduledForSynchronization = + $this->entityInsertions = + $this->entityUpdates = + $this->entityDeletions = $this->nonCascadedNewDetectedEntities = - $this->collectionDeletions = - $this->collectionUpdates = - $this->extraUpdates = - $this->readOnlyObjects = - $this->visitedCollections = - $this->orphanRemovals = []; + $this->collectionDeletions = + $this->collectionUpdates = + $this->extraUpdates = + $this->readOnlyObjects = + $this->visitedCollections = + $this->eagerLoadingEntities = + $this->orphanRemovals = []; } else { $this->clearIdentityMapForEntityName($entityName); $this->clearEntityInsertionsForEntityName($entityName); From 4781dc03e90d7b80676a5a2db27ff82f96529e86 Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Wed, 16 Oct 2019 20:41:00 +0200 Subject: [PATCH 836/877] AbstractQuery::getSingleScalarResult() throws exception when no result --- lib/Doctrine/ORM/AbstractQuery.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 0003c5d3ff5..3ba49b08866 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -822,8 +822,9 @@ public function getSingleResult($hydrationMode = null) * * Alias for getSingleResult(HYDRATE_SINGLE_SCALAR). * - * @return mixed The scalar result, or NULL if the query returned no result. + * @return mixed The scalar result. * + * @throws NoResultException If the query returned no result. * @throws NonUniqueResultException If the query result is not unique. */ public function getSingleScalarResult() From 76f03b5db0973921fef7969ad1a62f3d1321d0dd Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Sun, 17 Dec 2017 05:48:11 +0100 Subject: [PATCH 837/877] Bump version to 2.7-dev --- composer.json | 2 +- lib/Doctrine/ORM/Version.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index abe42e4dba5..1f5548e74a0 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,7 @@ "bin": ["bin/doctrine"], "extra": { "branch-alias": { - "dev-master": "2.6.x-dev" + "dev-master": "2.7.x-dev" } }, "archive": { diff --git a/lib/Doctrine/ORM/Version.php b/lib/Doctrine/ORM/Version.php index 53297999976..b289a2aa8a5 100644 --- a/lib/Doctrine/ORM/Version.php +++ b/lib/Doctrine/ORM/Version.php @@ -35,7 +35,7 @@ class Version /** * Current Doctrine Version */ - const VERSION = '2.6.5-DEV'; + const VERSION = '2.7.0-DEV'; /** * Compares a Doctrine version with the current one. From 2fed8204c1bce5b8365598ddcf7286d2852bc83c Mon Sep 17 00:00:00 2001 From: Claudio Zizza Date: Mon, 30 Oct 2017 21:53:15 +0100 Subject: [PATCH 838/877] Set copy-method as deprecated --- lib/Doctrine/ORM/EntityManager.php | 3 --- lib/Doctrine/ORM/EntityManagerInterface.php | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index c3535148714..c5204f3fb55 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -684,9 +684,6 @@ public function merge($entity) /** * {@inheritDoc} - * - * @todo Implementation need. This is necessary since $e2 = clone $e1; throws an E_FATAL when access anything on $e: - * Fatal error: Maximum function nesting level of '100' reached, aborting! */ public function copy($entity, $deep = false) { diff --git a/lib/Doctrine/ORM/EntityManagerInterface.php b/lib/Doctrine/ORM/EntityManagerInterface.php index a423432a162..8bbc56798b2 100644 --- a/lib/Doctrine/ORM/EntityManagerInterface.php +++ b/lib/Doctrine/ORM/EntityManagerInterface.php @@ -190,6 +190,8 @@ public function close(); /** * Creates a copy of the given entity. Can create a shallow or a deep copy. * + * @deprecated method will be removed in 3.0 + * * @param object $entity The entity to copy. * @param boolean $deep FALSE for a shallow copy, TRUE for a deep copy. * From fdbbf7edd170c9f1608d824f47808d9875be9204 Mon Sep 17 00:00:00 2001 From: Claudio Zizza Date: Thu, 9 Nov 2017 21:37:04 +0100 Subject: [PATCH 839/877] Add deprecation of EntityManagerInterface::copy() to upgrade information --- UPGRADE.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index 3567b998d49..dda74128331 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -37,6 +37,11 @@ As a consequence, automatic cache setup in Doctrine\ORM\Tools\Setup::create*Conf - Memcached extension (ext-memcached) will be used instead of obsolete Memcache (ext-memcache). - XCache support was dropped as it doesn't work with PHP 7. +## Deprecated: `Doctrine\ORM\EntityManagerInterface#copy()` + +Method `Doctrine\ORM\EntityManagerInterface#copy()` never got its implementation and is deprecated. +It will be removed in 3.0. + # Upgrade to 2.5 ## Minor BC BREAK: removed `Doctrine\ORM\Query\SqlWalker#walkCaseExpression()` From 46c1b5756062d2863e519d72687e812bcdf3ab64 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Fri, 31 Aug 2018 23:39:56 +0200 Subject: [PATCH 840/877] Update homepage --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1f5548e74a0..94d64041a47 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "type": "library", "description": "Object-Relational-Mapper for PHP", "keywords": ["orm", "database"], - "homepage": "http://www.doctrine-project.org", + "homepage": "https://www.doctrine-project.org/projects/orm.html", "license": "MIT", "authors": [ {"name": "Guilherme Blanco", "email": "guilhermeblanco@gmail.com"}, From 4fb1ebfc1057e1a3d0b86e5738e68aa6ecf9e1c5 Mon Sep 17 00:00:00 2001 From: Claudio Zizza Date: Thu, 4 Jan 2018 21:19:54 +0100 Subject: [PATCH 841/877] Create 2.7 upgrade headline for deprecation changes --- UPGRADE.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index dda74128331..18b74ce9379 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,3 +1,10 @@ +# Upgrade to 2.7 + +## Deprecated: `Doctrine\ORM\EntityManagerInterface#copy()` + +Method `Doctrine\ORM\EntityManagerInterface#copy()` never got its implementation and is deprecated. +It will be removed in 3.0. + # Upgrade to 2.6 ## Added `Doctrine\ORM\EntityRepository::count()` method @@ -37,11 +44,6 @@ As a consequence, automatic cache setup in Doctrine\ORM\Tools\Setup::create*Conf - Memcached extension (ext-memcached) will be used instead of obsolete Memcache (ext-memcache). - XCache support was dropped as it doesn't work with PHP 7. -## Deprecated: `Doctrine\ORM\EntityManagerInterface#copy()` - -Method `Doctrine\ORM\EntityManagerInterface#copy()` never got its implementation and is deprecated. -It will be removed in 3.0. - # Upgrade to 2.5 ## Minor BC BREAK: removed `Doctrine\ORM\Query\SqlWalker#walkCaseExpression()` From cdb652ad87a7f2a7b8f447946c90012956935369 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Sat, 9 Feb 2019 19:15:11 +0100 Subject: [PATCH 842/877] CI: Test against PHP 7.4snapshot instead of nightly (8.0) --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1d3d3fde32b..bd6037e90ce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -55,7 +55,7 @@ jobs: - stage: Test dist: xenial env: DB=mysql MYSQL_VERSION=5.7 - php: nightly + php: 7.4snapshot services: - mysql before_script: @@ -102,7 +102,7 @@ jobs: - stage: Code Quality if: NOT type = pull_request env: DB=none CODING_STANDARDS - php: 7.1 + php: 7.4snapshot install: travis_retry composer install --prefer-dist script: - ./vendor/bin/phpcs From 90c1ee0bd0801bce10b5356555df4a468b90d4b9 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 28 May 2019 16:44:44 +0200 Subject: [PATCH 843/877] Allow Symfony 5.0 --- composer.json | 4 +- composer.lock | 158 +++++++++++++++++++++++++------------------------- 2 files changed, 80 insertions(+), 82 deletions(-) diff --git a/composer.json b/composer.json index 94d64041a47..ee32d79b2f7 100644 --- a/composer.json +++ b/composer.json @@ -24,12 +24,12 @@ "doctrine/common": "^2.7.1", "doctrine/dbal": "^2.6", "doctrine/instantiator": "~1.1", - "symfony/console": "~3.0|~4.0" + "symfony/console": "^3.0|^4.0|^5.0" }, "require-dev": { "doctrine/coding-standard": "^5.0", "phpunit/phpunit": "^7.5", - "symfony/yaml": "~3.4|~4.0" + "symfony/yaml": "^3.4|^4.0|^5.0" }, "suggest": { "symfony/yaml": "If you want to use YAML Metadata Mapping Driver" diff --git a/composer.lock b/composer.lock index 23b60faad59..be48f0e64a7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d5d0e87e612dc300640150a1d8a8a8a7", + "content-hash": "c3d70a08d75cd3995dd4c72864f3c880", "packages": [ { "name": "doctrine/annotations", - "version": "v1.7.0", + "version": "v1.8.0", "source": { "type": "git", "url": "https://github.com/doctrine/annotations.git", - "reference": "fa4c4e861e809d6a1103bd620cce63ed91aedfeb" + "reference": "904dca4eb10715b92569fbcd79e201d5c349b6bc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/fa4c4e861e809d6a1103bd620cce63ed91aedfeb", - "reference": "fa4c4e861e809d6a1103bd620cce63ed91aedfeb", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/904dca4eb10715b92569fbcd79e201d5c349b6bc", + "reference": "904dca4eb10715b92569fbcd79e201d5c349b6bc", "shasum": "" }, "require": { @@ -26,7 +26,7 @@ }, "require-dev": { "doctrine/cache": "1.*", - "phpunit/phpunit": "^7.5@dev" + "phpunit/phpunit": "^7.5" }, "type": "library", "extra": { @@ -72,7 +72,7 @@ "docblock", "parser" ], - "time": "2019-08-08T18:11:40+00:00" + "time": "2019-10-01T18:55:10+00:00" }, { "name": "doctrine/cache", @@ -849,16 +849,16 @@ }, { "name": "symfony/console", - "version": "v4.3.4", + "version": "v4.3.5", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "de63799239b3881b8a08f8481b22348f77ed7b36" + "reference": "929ddf360d401b958f611d44e726094ab46a7369" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/de63799239b3881b8a08f8481b22348f77ed7b36", - "reference": "de63799239b3881b8a08f8481b22348f77ed7b36", + "url": "https://api.github.com/repos/symfony/console/zipball/929ddf360d401b958f611d44e726094ab46a7369", + "reference": "929ddf360d401b958f611d44e726094ab46a7369", "shasum": "" }, "require": { @@ -920,7 +920,7 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2019-08-26T08:26:39+00:00" + "time": "2019-10-07T12:36:49+00:00" }, { "name": "symfony/polyfill-mbstring", @@ -1041,16 +1041,16 @@ }, { "name": "symfony/service-contracts", - "version": "v1.1.6", + "version": "v1.1.7", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "ea7263d6b6d5f798b56a45a5b8d686725f2719a3" + "reference": "ffcde9615dc5bb4825b9f6aed07716f1f57faae0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/ea7263d6b6d5f798b56a45a5b8d686725f2719a3", - "reference": "ea7263d6b6d5f798b56a45a5b8d686725f2719a3", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/ffcde9615dc5bb4825b9f6aed07716f1f57faae0", + "reference": "ffcde9615dc5bb4825b9f6aed07716f1f57faae0", "shasum": "" }, "require": { @@ -1095,7 +1095,7 @@ "interoperability", "standards" ], - "time": "2019-08-20T14:44:19+00:00" + "time": "2019-09-17T11:12:18+00:00" } ], "packages-dev": [ @@ -1378,35 +1378,33 @@ }, { "name": "phpdocumentor/reflection-common", - "version": "1.0.1", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6" + "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", - "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/63a995caa1ca9e5590304cd845c15ad6d482a62a", + "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a", "shasum": "" }, "require": { - "php": ">=5.5" + "php": ">=7.1" }, "require-dev": { - "phpunit/phpunit": "^4.6" + "phpunit/phpunit": "~6" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.x-dev" } }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src" - ] + "phpDocumentor\\Reflection\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -1428,30 +1426,30 @@ "reflection", "static analysis" ], - "time": "2017-09-11T18:02:19+00:00" + "time": "2018-08-07T13:53:10+00:00" }, { "name": "phpdocumentor/reflection-docblock", - "version": "4.3.1", + "version": "4.3.2", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c" + "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c", - "reference": "bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/b83ff7cfcfee7827e1e78b637a5904fe6a96698e", + "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e", "shasum": "" }, "require": { "php": "^7.0", - "phpdocumentor/reflection-common": "^1.0.0", - "phpdocumentor/type-resolver": "^0.4.0", + "phpdocumentor/reflection-common": "^1.0.0 || ^2.0.0", + "phpdocumentor/type-resolver": "~0.4 || ^1.0.0", "webmozart/assert": "^1.0" }, "require-dev": { - "doctrine/instantiator": "~1.0.5", + "doctrine/instantiator": "^1.0.5", "mockery/mockery": "^1.0", "phpunit/phpunit": "^6.4" }, @@ -1479,41 +1477,40 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2019-04-30T17:48:53+00:00" + "time": "2019-09-12T14:27:41+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "0.4.0", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7" + "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7", - "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", + "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", "shasum": "" }, "require": { - "php": "^5.5 || ^7.0", - "phpdocumentor/reflection-common": "^1.0" + "php": "^7.1", + "phpdocumentor/reflection-common": "^2.0" }, "require-dev": { - "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^5.2||^4.8.24" + "ext-tokenizer": "^7.1", + "mockery/mockery": "~1", + "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.x-dev" } }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src/" - ] + "phpDocumentor\\Reflection\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -1526,26 +1523,27 @@ "email": "me@mikevanriel.com" } ], - "time": "2017-07-14T14:27:02+00:00" + "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", + "time": "2019-08-22T18:11:29+00:00" }, { "name": "phpspec/prophecy", - "version": "1.8.1", + "version": "1.9.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76" + "reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/1927e75f4ed19131ec9bcc3b002e07fb1173ee76", - "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/f6811d96d97bdf400077a0cc100ae56aa32b9203", + "reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", "php": "^5.3|^7.0", - "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0|^5.0", "sebastian/comparator": "^1.1|^2.0|^3.0", "sebastian/recursion-context": "^1.0|^2.0|^3.0" }, @@ -1589,7 +1587,7 @@ "spy", "stub" ], - "time": "2019-06-13T12:50:23+00:00" + "time": "2019-10-03T11:07:50+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1796,16 +1794,16 @@ }, { "name": "phpunit/php-token-stream", - "version": "3.1.0", + "version": "3.1.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "e899757bb3df5ff6e95089132f32cd59aac2220a" + "reference": "995192df77f63a59e47f025390d2d1fdf8f425ff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/e899757bb3df5ff6e95089132f32cd59aac2220a", - "reference": "e899757bb3df5ff6e95089132f32cd59aac2220a", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/995192df77f63a59e47f025390d2d1fdf8f425ff", + "reference": "995192df77f63a59e47f025390d2d1fdf8f425ff", "shasum": "" }, "require": { @@ -1841,20 +1839,20 @@ "keywords": [ "tokenizer" ], - "time": "2019-07-25T05:29:42+00:00" + "time": "2019-09-17T06:23:10+00:00" }, { "name": "phpunit/phpunit", - "version": "7.5.15", + "version": "7.5.16", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "d79c053d972856b8b941bb233e39dc521a5093f0" + "reference": "316afa6888d2562e04aeb67ea7f2017a0eb41661" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/d79c053d972856b8b941bb233e39dc521a5093f0", - "reference": "d79c053d972856b8b941bb233e39dc521a5093f0", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/316afa6888d2562e04aeb67ea7f2017a0eb41661", + "reference": "316afa6888d2562e04aeb67ea7f2017a0eb41661", "shasum": "" }, "require": { @@ -1925,7 +1923,7 @@ "testing", "xunit" ], - "time": "2019-08-21T07:05:16+00:00" + "time": "2019-09-14T09:08:39+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -2147,16 +2145,16 @@ }, { "name": "sebastian/exporter", - "version": "3.1.1", + "version": "3.1.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "06a9a5947f47b3029d76118eb5c22802e5869687" + "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/06a9a5947f47b3029d76118eb5c22802e5869687", - "reference": "06a9a5947f47b3029d76118eb5c22802e5869687", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/68609e1261d215ea5b21b7987539cbfbe156ec3e", + "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e", "shasum": "" }, "require": { @@ -2210,7 +2208,7 @@ "export", "exporter" ], - "time": "2019-08-11T12:43:14+00:00" + "time": "2019-09-14T09:02:43+00:00" }, { "name": "sebastian/global-state", @@ -2534,16 +2532,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.4.2", + "version": "3.5.1", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "b8a7362af1cc1aadb5bd36c3defc4dda2cf5f0a8" + "reference": "82cd0f854ceca17731d6d019c7098e3755c45060" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/b8a7362af1cc1aadb5bd36c3defc4dda2cf5f0a8", - "reference": "b8a7362af1cc1aadb5bd36c3defc4dda2cf5f0a8", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/82cd0f854ceca17731d6d019c7098e3755c45060", + "reference": "82cd0f854ceca17731d6d019c7098e3755c45060", "shasum": "" }, "require": { @@ -2581,7 +2579,7 @@ "phpcs", "standards" ], - "time": "2019-04-10T23:49:02+00:00" + "time": "2019-10-16T21:14:26+00:00" }, { "name": "symfony/polyfill-ctype", @@ -2643,16 +2641,16 @@ }, { "name": "symfony/yaml", - "version": "v4.3.4", + "version": "v4.3.5", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "5a0b7c32dc3ec56fd4abae8a4a71b0cf05013686" + "reference": "41e16350a2a1c7383c4735aa2f9fce74cf3d1178" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/5a0b7c32dc3ec56fd4abae8a4a71b0cf05013686", - "reference": "5a0b7c32dc3ec56fd4abae8a4a71b0cf05013686", + "url": "https://api.github.com/repos/symfony/yaml/zipball/41e16350a2a1c7383c4735aa2f9fce74cf3d1178", + "reference": "41e16350a2a1c7383c4735aa2f9fce74cf3d1178", "shasum": "" }, "require": { @@ -2698,7 +2696,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2019-08-20T14:27:59+00:00" + "time": "2019-09-11T15:41:19+00:00" }, { "name": "theseer/tokenizer", From 4d6b1f3e637bb0a69552eb1799a4231d52855088 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 23 Oct 2019 13:37:16 +0200 Subject: [PATCH 844/877] Fix compat of commands with Symfony 5 --- .../Command/ClearCache/CollectionRegionCommand.php | 8 +++++--- .../Console/Command/ClearCache/EntityRegionCommand.php | 8 +++++--- .../Console/Command/ClearCache/QueryRegionCommand.php | 6 ++++-- .../Console/Command/ConvertDoctrine1SchemaCommand.php | 2 ++ .../ORM/Tools/Console/Command/ConvertMappingCommand.php | 2 ++ .../ORM/Tools/Console/Command/GenerateEntitiesCommand.php | 4 +++- .../ORM/Tools/Console/Command/GenerateProxiesCommand.php | 4 +++- .../Tools/Console/Command/GenerateRepositoriesCommand.php | 6 ++++-- lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php | 4 +++- 9 files changed, 31 insertions(+), 13 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/CollectionRegionCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/CollectionRegionCommand.php index 33f003a19a7..1c75ccccacc 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/CollectionRegionCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/CollectionRegionCommand.php @@ -116,7 +116,7 @@ protected function execute(InputInterface $input, OutputInterface $output) ) ); - return; + return 0; } if ($input->getOption('all')) { @@ -124,7 +124,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $cache->evictEntityRegions(); - return; + return 0; } if ($ownerId) { @@ -138,10 +138,12 @@ protected function execute(InputInterface $input, OutputInterface $output) ); $cache->evictCollection($ownerClass, $assoc, $ownerId); - return; + return 0; } $ui->comment(sprintf('Clearing second-level cache for collection "%s#%s"', $ownerClass, $assoc)); $cache->evictCollectionRegion($ownerClass, $assoc); + + return 0; } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/EntityRegionCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/EntityRegionCommand.php index 67a73093fc8..c246910c145 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/EntityRegionCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/EntityRegionCommand.php @@ -108,7 +108,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $ui->comment(sprintf('Flushing cache provider configured for entity named "%s"', $entityClass)); - return; + return 0; } if ($input->getOption('all')) { @@ -116,7 +116,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $cache->evictEntityRegions(); - return; + return 0; } if ($entityId) { @@ -129,10 +129,12 @@ protected function execute(InputInterface $input, OutputInterface $output) ); $cache->evictEntity($entityClass, $entityId); - return; + return 0; } $ui->comment(sprintf('Clearing second-level cache for entity "%s"', $entityClass)); $cache->evictEntityRegion($entityClass); + + return 0; } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryRegionCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryRegionCommand.php index f1578bc641c..36ffa125038 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryRegionCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryRegionCommand.php @@ -112,7 +112,7 @@ protected function execute(InputInterface $input, OutputInterface $output) ) ); - return; + return 0; } if ($input->getOption('all')) { @@ -120,10 +120,12 @@ protected function execute(InputInterface $input, OutputInterface $output) $cache->evictQueryRegions(); - return; + return 0; } $ui->comment(sprintf('Clearing second-level cache query region named "%s"', $name)); $cache->evictQueryRegion($name); + + return 0; } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php index b6b43bf8e04..112efb96427 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php @@ -127,6 +127,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $numSpaces = $input->getOption('num-spaces'); $this->convertDoctrine1Schema($fromPaths, $destPath, $toType, $numSpaces, $extend, $output); + + return 0; } /** diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php index f6756641141..8de2b84a9ec 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php @@ -167,6 +167,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $destPath ) ); + + return 0; } /** diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php index 063cb244ce7..828c1432db5 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php @@ -112,7 +112,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if (empty($metadatas)) { $ui->success('No Metadata Classes to process.'); - return; + return 0; } $entityGenerator = new EntityGenerator(); @@ -138,5 +138,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // Outputting information message $ui->newLine(); $ui->success(sprintf('Entity classes generated to "%s"', $destPath)); + + return 0; } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php index 3755be58052..2cace34345c 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php @@ -91,7 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if (empty($metadatas)) { $ui->success('No Metadata Classes to process.'); - return; + return 0; } foreach ($metadatas as $metadata) { @@ -104,5 +104,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // Outputting information message $ui->newLine(); $ui->text(sprintf('Proxy classes generated to "%s"', $destPath)); + + return 0; } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php index 941944ff528..666ae7867bd 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php @@ -84,7 +84,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if (empty($metadatas)) { $ui->success('No Metadata Classes to process.'); - return; + return 0; } $numRepositories = 0; @@ -104,11 +104,13 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($numRepositories === 0) { $ui->text('No Repository classes were found to be processed.'); - return; + return 0; } // Outputting information message $ui->newLine(); $ui->text(sprintf('Repository classes generated to "%s"', $destPath)); + + return 0; } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php index 4e6b69bb42b..7f4069202bf 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php @@ -104,11 +104,13 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($input->getOption('show-sql')) { $ui->text($query->getSQL()); - return; + return 0; } $resultSet = $query->execute([], constant($hydrationMode)); $ui->text(Debug::dump($resultSet, $input->getOption('depth'), true, false)); + + return 0; } } From d1db0655acf2eccec99ad9781ab33727151170b4 Mon Sep 17 00:00:00 2001 From: Mathieu Lemoine Date: Mon, 28 Oct 2019 15:30:56 +0100 Subject: [PATCH 845/877] Update documentation to recommend DQL over QueryBuilder when possible --- docs/en/reference/faq.rst | 15 +++++++++++++++ docs/en/reference/query-builder.rst | 15 ++++++++++----- docs/en/reference/working-with-objects.rst | 4 +++- docs/en/tutorials/getting-started.rst | 3 +-- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/docs/en/reference/faq.rst b/docs/en/reference/faq.rst index 78b5b01c946..ca7784edca0 100644 --- a/docs/en/reference/faq.rst +++ b/docs/en/reference/faq.rst @@ -198,6 +198,21 @@ No, it is not supported to sort by function in DQL. If you need this functionali use a native-query or come up with another solution. As a side note: Sorting with ORDER BY RAND() is painfully slow starting with 1000 rows. +Is it better to write DQL or to generate it with the query builder? +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The purpose of the ``QueryBuilder`` is to generate DQL dynamically, +which is useful when you have optional filters, conditional joins, etc. + +But the ``QueryBuilder`` is not an alternative to DQL, it actually generates DQL +queries at runtime, which are then interpreted by Doctrine. This means that +using the ``QueryBuilder`` to build and run a query is actually always slower +than only running the corresponding DQL query. + +So if you only need to generate a query and bind parameters to it, +you should use plain DQL, as this is a simpler and much more readable solution. +You should only use the ``QueryBuilder`` when you can't achieve what you want to do with a DQL query. + A Query fails, how can I debug it? ---------------------------------- diff --git a/docs/en/reference/query-builder.rst b/docs/en/reference/query-builder.rst index 18199e7c55f..91833aee53d 100644 --- a/docs/en/reference/query-builder.rst +++ b/docs/en/reference/query-builder.rst @@ -9,6 +9,12 @@ programmatically build queries, and also provides a fluent API. This means that you can change between one methodology to the other as you want, or just pick a preferred one. +.. note:: + + The ``QueryBuilder`` is not an abstraction of DQL, but merely a tool to dynamically build it. + You should still use plain DQL when you can, as it is simpler and more readable. + More about this in the :doc:`FAQ `_. + Constructing a new QueryBuilder object ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -80,7 +86,7 @@ Working with QueryBuilder High level API methods ^^^^^^^^^^^^^^^^^^^^^^ -To simplify even more the way you build a query in Doctrine, you can take +The most straightforward way to build a dynamic query with the ``QueryBuilder`` is by taking advantage of Helper methods. For all base code, there is a set of useful methods to simplify a programmer's life. To illustrate how to work with them, here is the same example 6 re-written using @@ -97,10 +103,9 @@ to work with them, here is the same example 6 re-written using ->orderBy('u.name', 'ASC'); ``QueryBuilder`` helper methods are considered the standard way to -build DQL queries. Although it is supported, using string-based -queries should be avoided. You are greatly encouraged to use -``$qb->expr()->*`` methods. Here is a converted example 8 to -suggested standard way to build queries: +use the ``QueryBuilder``. The ``$qb->expr()->*`` methods can help you +build conditional expressions dynamically. Here is a converted example 8 to +suggested way to build queries with dynamic conditions: .. code-block:: php diff --git a/docs/en/reference/working-with-objects.rst b/docs/en/reference/working-with-objects.rst index 064c9e1f9e8..4b16fc3579d 100644 --- a/docs/en/reference/working-with-objects.rst +++ b/docs/en/reference/working-with-objects.rst @@ -800,7 +800,9 @@ DQL and its syntax as well as the Doctrine class can be found in :doc:`the dedicated chapter `. For programmatically building up queries based on conditions that are only known at runtime, Doctrine provides the special -``Doctrine\ORM\QueryBuilder`` class. More information on +``Doctrine\ORM\QueryBuilder`` class. While this a powerful tool, +it also brings more complexity to your code compared to plain DQL, +so you should only use it when you need it. More information on constructing queries with a QueryBuilder can be found :doc:`in Query Builder chapter `. diff --git a/docs/en/tutorials/getting-started.rst b/docs/en/tutorials/getting-started.rst index b01d44d4339..52190e57099 100644 --- a/docs/en/tutorials/getting-started.rst +++ b/docs/en/tutorials/getting-started.rst @@ -1210,8 +1210,7 @@ The console output of this script is then: throw your ORM into the dumpster, because it doesn't support some the more powerful SQL concepts. - - Instead of handwriting DQL you can use the ``QueryBuilder`` retrieved + If you need to build your query dynamically, you can use the ``QueryBuilder`` retrieved by calling ``$entityManager->createQueryBuilder()``. There are more details about this in the relevant part of the documentation. From 19aa3c125c5b8b5853b5dd4284eb9306a04f9206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rog=C3=A9rio=20Alencar=20Lino=20Filho?= Date: Thu, 31 Oct 2019 18:20:58 -0300 Subject: [PATCH 846/877] missing entity alias --- ...vanced-field-value-conversion-using-custom-mapping-types.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/cookbook/advanced-field-value-conversion-using-custom-mapping-types.rst b/docs/en/cookbook/advanced-field-value-conversion-using-custom-mapping-types.rst index e5ca21632aa..f735d99f46b 100644 --- a/docs/en/cookbook/advanced-field-value-conversion-using-custom-mapping-types.rst +++ b/docs/en/cookbook/advanced-field-value-conversion-using-custom-mapping-types.rst @@ -249,7 +249,7 @@ Example usage $em->clear(); // Fetch the Location object - $query = $em->createQuery("SELECT l FROM Geo\Entity\Location WHERE l.address = '1600 Amphitheatre Parkway, Mountain View, CA'"); + $query = $em->createQuery("SELECT l FROM Geo\Entity\Location l WHERE l.address = '1600 Amphitheatre Parkway, Mountain View, CA'"); $location = $query->getSingleResult(); /* @var Geo\ValueObject\Point */ From 1bc4e1f594de5550f0d67fe073a0b6c53096d082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20J=2E=20Garc=C3=ADa=20Lagar?= Date: Tue, 5 Nov 2019 14:10:32 +0100 Subject: [PATCH 847/877] Use quoted collation declaration when available. --- .../SchemaTool/MySqlSchemaToolTest.php | 36 +++++++++++++------ .../ORM/Functional/Ticket/DDC2182Test.php | 17 +++++++-- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php index 2deedb37aa6..829b3aa2b85 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php @@ -5,6 +5,8 @@ use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Tests\OrmFunctionalTestCase; use Doctrine\Tests\Models; +use function method_exists; +use function sprintf; class MySqlSchemaToolTest extends OrmFunctionalTestCase { @@ -28,15 +30,16 @@ public function testGetCreateSchemaSql() $tool = new SchemaTool($this->_em); $sql = $tool->getCreateSchemaSql($classes); - - $this->assertEquals("CREATE TABLE cms_groups (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(50) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[0]); - $this->assertEquals("CREATE TABLE cms_users (id INT AUTO_INCREMENT NOT NULL, email_id INT DEFAULT NULL, status VARCHAR(50) DEFAULT NULL, username VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_3AF03EC5F85E0677 (username), UNIQUE INDEX UNIQ_3AF03EC5A832C1C9 (email_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[1]); - $this->assertEquals("CREATE TABLE cms_users_groups (user_id INT NOT NULL, group_id INT NOT NULL, INDEX IDX_7EA9409AA76ED395 (user_id), INDEX IDX_7EA9409AFE54D947 (group_id), PRIMARY KEY(user_id, group_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[2]); - $this->assertEquals("CREATE TABLE cms_users_tags (user_id INT NOT NULL, tag_id INT NOT NULL, INDEX IDX_93F5A1ADA76ED395 (user_id), INDEX IDX_93F5A1ADBAD26311 (tag_id), PRIMARY KEY(user_id, tag_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[3]); - $this->assertEquals("CREATE TABLE cms_tags (id INT AUTO_INCREMENT NOT NULL, tag_name VARCHAR(50) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[4]); - $this->assertEquals("CREATE TABLE cms_addresses (id INT AUTO_INCREMENT NOT NULL, user_id INT DEFAULT NULL, country VARCHAR(50) NOT NULL, zip VARCHAR(50) NOT NULL, city VARCHAR(50) NOT NULL, UNIQUE INDEX UNIQ_ACAC157BA76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[5]); - $this->assertEquals("CREATE TABLE cms_emails (id INT AUTO_INCREMENT NOT NULL, email VARCHAR(250) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[6]); - $this->assertEquals("CREATE TABLE cms_phonenumbers (phonenumber VARCHAR(50) NOT NULL, user_id INT DEFAULT NULL, INDEX IDX_F21F790FA76ED395 (user_id), PRIMARY KEY(phonenumber)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[7]); + $collation = $this->getColumnCollationDeclarationSQL('utf8_unicode_ci'); + + $this->assertEquals('CREATE TABLE cms_groups (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(50) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 ' . $collation . ' ENGINE = InnoDB', $sql[0]); + $this->assertEquals('CREATE TABLE cms_users (id INT AUTO_INCREMENT NOT NULL, email_id INT DEFAULT NULL, status VARCHAR(50) DEFAULT NULL, username VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_3AF03EC5F85E0677 (username), UNIQUE INDEX UNIQ_3AF03EC5A832C1C9 (email_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 ' . $collation . ' ENGINE = InnoDB', $sql[1]); + $this->assertEquals('CREATE TABLE cms_users_groups (user_id INT NOT NULL, group_id INT NOT NULL, INDEX IDX_7EA9409AA76ED395 (user_id), INDEX IDX_7EA9409AFE54D947 (group_id), PRIMARY KEY(user_id, group_id)) DEFAULT CHARACTER SET utf8 ' . $collation . ' ENGINE = InnoDB', $sql[2]); + $this->assertEquals('CREATE TABLE cms_users_tags (user_id INT NOT NULL, tag_id INT NOT NULL, INDEX IDX_93F5A1ADA76ED395 (user_id), INDEX IDX_93F5A1ADBAD26311 (tag_id), PRIMARY KEY(user_id, tag_id)) DEFAULT CHARACTER SET utf8 ' . $collation . ' ENGINE = InnoDB', $sql[3]); + $this->assertEquals('CREATE TABLE cms_tags (id INT AUTO_INCREMENT NOT NULL, tag_name VARCHAR(50) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 ' . $collation . ' ENGINE = InnoDB', $sql[4]); + $this->assertEquals('CREATE TABLE cms_addresses (id INT AUTO_INCREMENT NOT NULL, user_id INT DEFAULT NULL, country VARCHAR(50) NOT NULL, zip VARCHAR(50) NOT NULL, city VARCHAR(50) NOT NULL, UNIQUE INDEX UNIQ_ACAC157BA76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 ' . $collation . ' ENGINE = InnoDB', $sql[5]); + $this->assertEquals('CREATE TABLE cms_emails (id INT AUTO_INCREMENT NOT NULL, email VARCHAR(250) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 ' . $collation . ' ENGINE = InnoDB', $sql[6]); + $this->assertEquals('CREATE TABLE cms_phonenumbers (phonenumber VARCHAR(50) NOT NULL, user_id INT DEFAULT NULL, INDEX IDX_F21F790FA76ED395 (user_id), PRIMARY KEY(phonenumber)) DEFAULT CHARACTER SET utf8 ' . $collation . ' ENGINE = InnoDB', $sql[7]); $this->assertEquals("ALTER TABLE cms_users ADD CONSTRAINT FK_3AF03EC5A832C1C9 FOREIGN KEY (email_id) REFERENCES cms_emails (id)", $sql[8]); $this->assertEquals("ALTER TABLE cms_users_groups ADD CONSTRAINT FK_7EA9409AA76ED395 FOREIGN KEY (user_id) REFERENCES cms_users (id)", $sql[9]); $this->assertEquals("ALTER TABLE cms_users_groups ADD CONSTRAINT FK_7EA9409AFE54D947 FOREIGN KEY (group_id) REFERENCES cms_groups (id)", $sql[10]); @@ -48,6 +51,15 @@ public function testGetCreateSchemaSql() $this->assertEquals(15, count($sql)); } + private function getColumnCollationDeclarationSQL(string $collation) : string + { + if (method_exists($this->_em->getConnection()->getDatabasePlatform(), 'getColumnCollationDeclarationSQL')) { + return $this->_em->getConnection()->getDatabasePlatform()->getColumnCollationDeclarationSQL($collation); + } + + return sprintf('COLLATE %s', $collation); + } + public function testGetCreateSchemaSql2() { $classes = [ @@ -56,9 +68,10 @@ public function testGetCreateSchemaSql2() $tool = new SchemaTool($this->_em); $sql = $tool->getCreateSchemaSql($classes); + $collation = $this->getColumnCollationDeclarationSQL('utf8_unicode_ci'); $this->assertEquals(1, count($sql)); - $this->assertEquals("CREATE TABLE decimal_model (id INT AUTO_INCREMENT NOT NULL, `decimal` NUMERIC(5, 2) NOT NULL, `high_scale` NUMERIC(14, 4) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[0]); + $this->assertEquals('CREATE TABLE decimal_model (id INT AUTO_INCREMENT NOT NULL, `decimal` NUMERIC(5, 2) NOT NULL, `high_scale` NUMERIC(14, 4) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 ' . $collation . ' ENGINE = InnoDB', $sql[0]); } public function testGetCreateSchemaSql3() @@ -69,9 +82,10 @@ public function testGetCreateSchemaSql3() $tool = new SchemaTool($this->_em); $sql = $tool->getCreateSchemaSql($classes); + $collation = $this->getColumnCollationDeclarationSQL('utf8_unicode_ci'); $this->assertEquals(1, count($sql)); - $this->assertEquals("CREATE TABLE boolean_model (id INT AUTO_INCREMENT NOT NULL, booleanField TINYINT(1) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[0]); + $this->assertEquals('CREATE TABLE boolean_model (id INT AUTO_INCREMENT NOT NULL, booleanField TINYINT(1) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 ' . $collation . ' ENGINE = InnoDB', $sql[0]); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2182Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2182Test.php index 590b7cd5f58..e610a67bcb2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2182Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2182Test.php @@ -2,6 +2,9 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use function method_exists; +use function sprintf; + class DDC2182Test extends \Doctrine\Tests\OrmFunctionalTestCase { public function testPassColumnOptionsToJoinColumns() @@ -16,11 +19,21 @@ public function testPassColumnOptionsToJoinColumns() $this->_em->getClassMetadata(DDC2182OptionChild::class), ] ); + $collation = $this->getColumnCollationDeclarationSQL('utf8_unicode_ci'); - $this->assertEquals("CREATE TABLE DDC2182OptionParent (id INT UNSIGNED NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[0]); - $this->assertEquals("CREATE TABLE DDC2182OptionChild (id VARCHAR(255) NOT NULL, parent_id INT UNSIGNED DEFAULT NULL, INDEX IDX_B314D4AD727ACA70 (parent_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[1]); + $this->assertEquals('CREATE TABLE DDC2182OptionParent (id INT UNSIGNED NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 ' . $collation . ' ENGINE = InnoDB', $sql[0]); + $this->assertEquals('CREATE TABLE DDC2182OptionChild (id VARCHAR(255) NOT NULL, parent_id INT UNSIGNED DEFAULT NULL, INDEX IDX_B314D4AD727ACA70 (parent_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 ' . $collation . ' ENGINE = InnoDB', $sql[1]); $this->assertEquals("ALTER TABLE DDC2182OptionChild ADD CONSTRAINT FK_B314D4AD727ACA70 FOREIGN KEY (parent_id) REFERENCES DDC2182OptionParent (id)", $sql[2]); } + + private function getColumnCollationDeclarationSQL(string $collation) : string + { + if (method_exists($this->_em->getConnection()->getDatabasePlatform(), 'getColumnCollationDeclarationSQL')) { + return $this->_em->getConnection()->getDatabasePlatform()->getColumnCollationDeclarationSQL($collation); + } + + return sprintf('COLLATE %s', $collation); + } } /** From 1dde2c9e8ee144d634ecf93a7e971d62633fc5d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Ostroluck=C3=BD?= Date: Thu, 14 Nov 2019 22:17:06 +0100 Subject: [PATCH 848/877] Add test case verifying eager loads are clear Otherwise, getClassMetadata would be triggered more times --- .../ORM/Functional/Ticket/GH7869Test.php | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH7869Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7869Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7869Test.php new file mode 100644 index 00000000000..db16e38967e --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7869Test.php @@ -0,0 +1,67 @@ +getMockBuilder(EntityManagerDecorator::class) + ->setConstructorArgs([$decoratedEm]) + ->setMethods(['getClassMetadata']) + ->getMock(); + + $em->expects($this->exactly(2)) + ->method('getClassMetadata') + ->willReturnCallback([$decoratedEm, 'getClassMetadata']); + + $hints = [ + UnitOfWork::HINT_DEFEREAGERLOAD => true, + 'fetchMode' => [GH7869Appointment::class => ['patient' => ClassMetadata::FETCH_EAGER]], + ]; + + $uow = new UnitOfWork($em); + $uow->createEntity(GH7869Appointment::class, ['id' => 1, 'patient_id' => 1], $hints); + $uow->clear(); + $uow->triggerEagerLoads(); + } +} + +/** + * @Entity + */ +class GH7869Appointment +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; + + /** @OneToOne(targetEntity="GH7869Patient", inversedBy="appointment", fetch="EAGER") */ + public $patient; +} + +/** + * @Entity + */ +class GH7869Patient +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; + + /** @OneToOne(targetEntity="GH7869Appointment", mappedBy="patient") */ + public $appointment; +} From 98e557b68eeecd7f266f1e4628007aed2714026c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Ostroluck=C3=BD?= Date: Thu, 14 Nov 2019 23:36:15 +0100 Subject: [PATCH 849/877] Improve assertion failure message for testWillFindSongsInPaginatorEvenWithCachedQueryParsing --- tests/Doctrine/Tests/ORM/Functional/Ticket/GH7820Test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7820Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7820Test.php index afb29f08369..11110e5a73e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7820Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7820Test.php @@ -98,7 +98,7 @@ public function testWillFindSongsInPaginatorEvenWithCachedQueryParsing() : void array_map(static function (GH7820Line $line) : string { return $line->toString(); }, iterator_to_array(new Paginator($query))), - 'Paginator runs once, query cache is populated with DQL -> SQL translation' + 'Expected to return expected data before query cache is populated with DQL -> SQL translation. Were SQL parameters translated?' ); $query = $this->_em->getRepository(GH7820Line::class) @@ -110,7 +110,7 @@ public function testWillFindSongsInPaginatorEvenWithCachedQueryParsing() : void array_map(static function (GH7820Line $line) : string { return $line->toString(); }, iterator_to_array(new Paginator($query))), - 'Paginator runs again, SQL parameters are translated again, even with cached DQL -> SQL translation' + 'Expected to return expected data even when DQL -> SQL translation is present in cache. Were SQL parameters translated again?' ); } } From 570abb5bad0760ba254965f5799b9ff26fb085e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Fri, 15 Nov 2019 14:37:27 +0100 Subject: [PATCH 850/877] Fix PHP warnings in test suite --- tests/Doctrine/Tests/OrmFunctionalTestCase.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index d45ebac6387..93b07447c8c 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -341,7 +341,9 @@ protected function tearDown() $platform = $conn->getDatabasePlatform(); - $this->_sqlLoggerStack->enabled = false; + if ($this->_sqlLoggerStack instanceof DebugStack) { + $this->_sqlLoggerStack->enabled = false; + } if (isset($this->_usedModelSets['cms'])) { $conn->executeUpdate('DELETE FROM cms_users_groups'); From 2b8cb9de798a2b939d751d288e4335a3f422ff8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Fri, 15 Nov 2019 14:37:40 +0100 Subject: [PATCH 851/877] Add basic tool to verify deprecation messages --- tests/Doctrine/Tests/VerifyDeprecations.php | 69 +++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tests/Doctrine/Tests/VerifyDeprecations.php diff --git a/tests/Doctrine/Tests/VerifyDeprecations.php b/tests/Doctrine/Tests/VerifyDeprecations.php new file mode 100644 index 00000000000..8ccd9472e64 --- /dev/null +++ b/tests/Doctrine/Tests/VerifyDeprecations.php @@ -0,0 +1,69 @@ +actualDeprecations = []; + $this->expectedDeprecations = []; + + $this->originalHandler = set_error_handler( + function (int $errorNumber, string $errorMessage) : void { + $this->actualDeprecations[] = $errorMessage; + }, + E_USER_DEPRECATED + ); + } + + /** @after */ + public function resetErrorHandler() : void + { + set_error_handler($this->originalHandler, E_USER_DEPRECATED); + $this->originalHandler = null; + } + + /** @after */ + public function validateDeprecationExpectations() : void + { + if ($this->expectedDeprecations === []) { + return; + } + + self::assertSame( + $this->expectedDeprecations, + $this->actualDeprecations, + 'Triggered deprecation messages do not match with expected ones.' + ); + } + + protected function expectDeprecationMessage(string $message) : void + { + $this->expectedDeprecations[] = $message; + } + + protected function assertHasDeprecationMessages() : void + { + self::assertNotSame([], $this->actualDeprecations, 'Failed asserting that test has triggered deprecation messages.'); + } + + protected function assertNotHasDeprecationMessages() : void + { + self::assertSame([], $this->actualDeprecations, 'Failed asserting that test has not triggered deprecation messages.'); + } +} From eb9f11bf968834cd2fd5875daf34cddbf6a62e11 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Fri, 8 Dec 2017 21:13:42 +0100 Subject: [PATCH 852/877] Added deprecation warnings for 2.x --- composer.lock | 383 ++++++++---------- lib/Doctrine/ORM/Configuration.php | 9 + lib/Doctrine/ORM/EntityManager.php | 18 + lib/Doctrine/ORM/EntityManagerInterface.php | 2 +- .../ORM/Mapping/Driver/YamlDriver.php | 8 + lib/Doctrine/ORM/Proxy/Proxy.php | 2 + lib/Doctrine/ORM/Proxy/ProxyFactory.php | 2 + .../Command/ConvertDoctrine1SchemaCommand.php | 6 + .../Command/GenerateEntitiesCommand.php | 3 + .../Command/GenerateRepositoriesCommand.php | 3 + lib/Doctrine/ORM/Tools/EntityGenerator.php | 5 + .../ORM/Tools/EntityRepositoryGenerator.php | 8 + .../Tools/Export/ClassMetadataExporter.php | 9 + .../Tools/Export/Driver/AbstractExporter.php | 5 + .../Export/Driver/AnnotationExporter.php | 2 + .../ORM/Tools/Export/Driver/PhpExporter.php | 2 + .../ORM/Tools/Export/Driver/XmlExporter.php | 2 + .../ORM/Tools/Export/Driver/YamlExporter.php | 2 + .../ORM/Tools/Export/ExportException.php | 3 + lib/Doctrine/ORM/UnitOfWork.php | 4 +- lib/Doctrine/ORM/Version.php | 2 + .../Decorator/EntityManagerDecoratorTest.php | 11 + .../Doctrine/Tests/ORM/EntityManagerTest.php | 43 ++ .../ORM/Functional/BasicFunctionalTest.php | 16 +- .../ORM/Functional/DetachedEntityTest.php | 9 + .../ORM/Functional/EntityRepositoryTest.php | 4 + .../Functional/MergeCompositeToOneKeyTest.php | 4 + .../Tests/ORM/Functional/MergeProxiesTest.php | 9 + .../Functional/MergeSharedEntitiesTest.php | 9 + .../MergeVersionedManyToOneTest.php | 4 + .../Functional/ProxiesLikeEntitiesTest.php | 2 +- .../ORM/Functional/Ticket/DDC117Test.php | 6 +- .../ORM/Functional/Ticket/DDC1276Test.php | 4 + .../ORM/Functional/Ticket/DDC1383Test.php | 5 + .../ORM/Functional/Ticket/DDC1392Test.php | 4 + .../ORM/Functional/Ticket/DDC1509Test.php | 4 + .../ORM/Functional/Ticket/DDC1594Test.php | 4 + .../ORM/Functional/Ticket/DDC1734Test.php | 9 + .../ORM/Functional/Ticket/DDC2106Test.php | 2 +- .../ORM/Functional/Ticket/DDC2230Test.php | 5 + .../ORM/Functional/Ticket/DDC2409Test.php | 8 +- .../ORM/Functional/Ticket/DDC2645Test.php | 5 + .../ORM/Functional/Ticket/DDC2790Test.php | 2 +- .../ORM/Functional/Ticket/DDC2984Test.php | 2 +- .../ORM/Functional/Ticket/DDC3699Test.php | 9 + .../ORM/Functional/Ticket/DDC3711Test.php | 4 + .../ORM/Functional/Ticket/DDC501Test.php | 4 + .../ORM/Functional/Ticket/DDC518Test.php | 5 + .../ORM/Functional/Ticket/DDC729Test.php | 9 + .../ORM/Functional/Ticket/DDC758Test.php | 8 + .../Tests/ORM/Functional/ValueObjectsTest.php | 6 +- .../ORM/Mapping/Symfony/YamlDriverTest.php | 4 + .../ORM/Mapping/YamlMappingDriverTest.php | 11 + .../ConvertDoctrine1SchemaCommandTest.php | 9 + .../GenerateRepositoriesCommandTest.php | 5 + .../ORM/Tools/ConvertDoctrine1SchemaTest.php | 4 + .../Tests/ORM/Tools/EntityGeneratorTest.php | 8 + .../Tools/EntityRepositoryGeneratorTest.php | 9 + .../AbstractClassMetadataExporterTest.php | 5 + tests/Doctrine/Tests/ORM/Tools/SetupTest.php | 4 + 60 files changed, 523 insertions(+), 232 deletions(-) diff --git a/composer.lock b/composer.lock index be48f0e64a7..1641a17b142 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c3d70a08d75cd3995dd4c72864f3c880", + "content-hash": "084cd36de51fd4aa52c912b3e9c7c799", "packages": [ { "name": "doctrine/annotations", @@ -76,16 +76,16 @@ }, { "name": "doctrine/cache", - "version": "v1.8.0", + "version": "1.9.0", "source": { "type": "git", "url": "https://github.com/doctrine/cache.git", - "reference": "d768d58baee9a4862ca783840eca1b9add7a7f57" + "reference": "c15dcd24b756f9e52ea7c3ae8227354f3628f11a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/cache/zipball/d768d58baee9a4862ca783840eca1b9add7a7f57", - "reference": "d768d58baee9a4862ca783840eca1b9add7a7f57", + "url": "https://api.github.com/repos/doctrine/cache/zipball/c15dcd24b756f9e52ea7c3ae8227354f3628f11a", + "reference": "c15dcd24b756f9e52ea7c3ae8227354f3628f11a", "shasum": "" }, "require": { @@ -96,7 +96,7 @@ }, "require-dev": { "alcaeus/mongo-php-adapter": "^1.1", - "doctrine/coding-standard": "^4.0", + "doctrine/coding-standard": "^6.0", "mongodb/mongodb": "^1.1", "phpunit/phpunit": "^7.0", "predis/predis": "~1.0" @@ -107,7 +107,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.8.x-dev" + "dev-master": "1.9.x-dev" } }, "autoload": { @@ -120,6 +120,10 @@ "MIT" ], "authors": [ + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, { "name": "Roman Borschel", "email": "roman@code-factory.org" @@ -128,10 +132,6 @@ "name": "Benjamin Eberlei", "email": "kontakt@beberlei.de" }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, { "name": "Jonathan Wage", "email": "jonwage@gmail.com" @@ -141,46 +141,52 @@ "email": "schmittjoh@gmail.com" } ], - "description": "Caching library offering an object-oriented API for many cache backends", - "homepage": "https://www.doctrine-project.org", + "description": "PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, mongodb and others.", + "homepage": "https://www.doctrine-project.org/projects/cache.html", "keywords": [ + "abstraction", + "apcu", "cache", - "caching" + "caching", + "couchdb", + "memcached", + "php", + "redis", + "riak", + "xcache" ], - "time": "2018-08-21T18:01:43+00:00" + "time": "2019-11-11T10:31:52+00:00" }, { "name": "doctrine/collections", - "version": "v1.6.2", + "version": "v1.5.0", "source": { "type": "git", "url": "https://github.com/doctrine/collections.git", - "reference": "c5e0bc17b1620e97c968ac409acbff28b8b850be" + "reference": "a01ee38fcd999f34d9bfbcee59dbda5105449cbf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/collections/zipball/c5e0bc17b1620e97c968ac409acbff28b8b850be", - "reference": "c5e0bc17b1620e97c968ac409acbff28b8b850be", + "url": "https://api.github.com/repos/doctrine/collections/zipball/a01ee38fcd999f34d9bfbcee59dbda5105449cbf", + "reference": "a01ee38fcd999f34d9bfbcee59dbda5105449cbf", "shasum": "" }, "require": { - "php": "^7.1.3" + "php": "^7.1" }, "require-dev": { - "doctrine/coding-standard": "^6.0", - "phpstan/phpstan-shim": "^0.9.2", - "phpunit/phpunit": "^7.0", - "vimeo/psalm": "^3.2.2" + "doctrine/coding-standard": "~0.1@dev", + "phpunit/phpunit": "^5.7" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.6.x-dev" + "dev-master": "1.3.x-dev" } }, "autoload": { - "psr-4": { - "Doctrine\\Common\\Collections\\": "lib/Doctrine/Common/Collections" + "psr-0": { + "Doctrine\\Common\\Collections\\": "lib/" } }, "notification-url": "https://packagist.org/downloads/", @@ -209,15 +215,14 @@ "email": "schmittjoh@gmail.com" } ], - "description": "PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.", - "homepage": "https://www.doctrine-project.org/projects/collections.html", + "description": "Collections Abstraction library", + "homepage": "http://www.doctrine-project.org", "keywords": [ "array", "collections", - "iterators", - "php" + "iterator" ], - "time": "2019-06-09T13:48:14+00:00" + "time": "2017-07-22T10:37:32+00:00" }, { "name": "doctrine/common", @@ -304,16 +309,16 @@ }, { "name": "doctrine/dbal", - "version": "v2.9.2", + "version": "v2.9.3", "source": { "type": "git", "url": "https://github.com/doctrine/dbal.git", - "reference": "22800bd651c1d8d2a9719e2a3dc46d5108ebfcc9" + "reference": "7345cd59edfa2036eb0fa4264b77ae2576842035" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/dbal/zipball/22800bd651c1d8d2a9719e2a3dc46d5108ebfcc9", - "reference": "22800bd651c1d8d2a9719e2a3dc46d5108ebfcc9", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/7345cd59edfa2036eb0fa4264b77ae2576842035", + "reference": "7345cd59edfa2036eb0fa4264b77ae2576842035", "shasum": "" }, "require": { @@ -353,6 +358,10 @@ "MIT" ], "authors": [ + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, { "name": "Roman Borschel", "email": "roman@code-factory.org" @@ -361,10 +370,6 @@ "name": "Benjamin Eberlei", "email": "kontakt@beberlei.de" }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, { "name": "Jonathan Wage", "email": "jonwage@gmail.com" @@ -382,20 +387,20 @@ "php", "queryobject" ], - "time": "2018-12-31T03:27:51+00:00" + "time": "2019-11-02T22:19:34+00:00" }, { "name": "doctrine/event-manager", - "version": "v1.0.0", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/doctrine/event-manager.git", - "reference": "a520bc093a0170feeb6b14e9d83f3a14452e64b3" + "reference": "629572819973f13486371cb611386eb17851e85c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/event-manager/zipball/a520bc093a0170feeb6b14e9d83f3a14452e64b3", - "reference": "a520bc093a0170feeb6b14e9d83f3a14452e64b3", + "url": "https://api.github.com/repos/doctrine/event-manager/zipball/629572819973f13486371cb611386eb17851e85c", + "reference": "629572819973f13486371cb611386eb17851e85c", "shasum": "" }, "require": { @@ -405,7 +410,7 @@ "doctrine/common": "<2.9@dev" }, "require-dev": { - "doctrine/coding-standard": "^4.0", + "doctrine/coding-standard": "^6.0", "phpunit/phpunit": "^7.0" }, "type": "library", @@ -424,6 +429,10 @@ "MIT" ], "authors": [ + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, { "name": "Roman Borschel", "email": "roman@code-factory.org" @@ -432,10 +441,6 @@ "name": "Benjamin Eberlei", "email": "kontakt@beberlei.de" }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, { "name": "Jonathan Wage", "email": "jonwage@gmail.com" @@ -449,27 +454,29 @@ "email": "ocramius@gmail.com" } ], - "description": "Doctrine Event Manager component", + "description": "The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.", "homepage": "https://www.doctrine-project.org/projects/event-manager.html", "keywords": [ "event", - "eventdispatcher", - "eventmanager" + "event dispatcher", + "event manager", + "event system", + "events" ], - "time": "2018-06-11T11:59:03+00:00" + "time": "2019-11-10T09:48:07+00:00" }, { "name": "doctrine/inflector", - "version": "v1.3.0", + "version": "1.3.1", "source": { "type": "git", "url": "https://github.com/doctrine/inflector.git", - "reference": "5527a48b7313d15261292c149e55e26eae771b0a" + "reference": "ec3a55242203ffa6a4b27c58176da97ff0a7aec1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/inflector/zipball/5527a48b7313d15261292c149e55e26eae771b0a", - "reference": "5527a48b7313d15261292c149e55e26eae771b0a", + "url": "https://api.github.com/repos/doctrine/inflector/zipball/ec3a55242203ffa6a4b27c58176da97ff0a7aec1", + "reference": "ec3a55242203ffa6a4b27c58176da97ff0a7aec1", "shasum": "" }, "require": { @@ -494,6 +501,10 @@ "MIT" ], "authors": [ + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, { "name": "Roman Borschel", "email": "roman@code-factory.org" @@ -502,10 +513,6 @@ "name": "Benjamin Eberlei", "email": "kontakt@beberlei.de" }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, { "name": "Jonathan Wage", "email": "jonwage@gmail.com" @@ -523,20 +530,20 @@ "singularize", "string" ], - "time": "2018-01-09T20:05:19+00:00" + "time": "2019-10-30T19:59:35+00:00" }, { "name": "doctrine/instantiator", - "version": "1.2.0", + "version": "1.3.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "a2c590166b2133a4633738648b6b064edae0814a" + "reference": "ae466f726242e637cebdd526a7d991b9433bacf1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/a2c590166b2133a4633738648b6b064edae0814a", - "reference": "a2c590166b2133a4633738648b6b064edae0814a", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/ae466f726242e637cebdd526a7d991b9433bacf1", + "reference": "ae466f726242e637cebdd526a7d991b9433bacf1", "shasum": "" }, "require": { @@ -579,7 +586,7 @@ "constructor", "instantiate" ], - "time": "2019-03-17T17:37:11+00:00" + "time": "2019-10-21T16:45:58+00:00" }, { "name": "doctrine/lexer", @@ -643,16 +650,16 @@ }, { "name": "doctrine/persistence", - "version": "1.1.1", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/doctrine/persistence.git", - "reference": "3da7c9d125591ca83944f477e65ed3d7b4617c48" + "reference": "43526ae63312942e5316100bb3ed589ba1aba491" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/persistence/zipball/3da7c9d125591ca83944f477e65ed3d7b4617c48", - "reference": "3da7c9d125591ca83944f477e65ed3d7b4617c48", + "url": "https://api.github.com/repos/doctrine/persistence/zipball/43526ae63312942e5316100bb3ed589ba1aba491", + "reference": "43526ae63312942e5316100bb3ed589ba1aba491", "shasum": "" }, "require": { @@ -674,7 +681,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.1.x-dev" + "dev-master": "1.2.x-dev" } }, "autoload": { @@ -687,6 +694,10 @@ "MIT" ], "authors": [ + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, { "name": "Roman Borschel", "email": "roman@code-factory.org" @@ -695,10 +706,6 @@ "name": "Benjamin Eberlei", "email": "kontakt@beberlei.de" }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, { "name": "Jonathan Wage", "email": "jonwage@gmail.com" @@ -721,7 +728,7 @@ "orm", "persistence" ], - "time": "2019-04-23T08:28:24+00:00" + "time": "2019-04-23T12:39:21+00:00" }, { "name": "doctrine/reflection", @@ -799,17 +806,17 @@ "time": "2018-06-14T14:45:07+00:00" }, { - "name": "psr/container", - "version": "1.0.0", + "name": "psr/log", + "version": "1.1.2", "source": { "type": "git", - "url": "https://github.com/php-fig/container.git", - "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f" + "url": "https://github.com/php-fig/log.git", + "reference": "446d54b4cb6bf489fc9d75f55843658e6f25d801" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f", - "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "url": "https://api.github.com/repos/php-fig/log/zipball/446d54b4cb6bf489fc9d75f55843658e6f25d801", + "reference": "446d54b4cb6bf489fc9d75f55843658e6f25d801", "shasum": "" }, "require": { @@ -818,12 +825,12 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.1.x-dev" } }, "autoload": { "psr-4": { - "Psr\\Container\\": "src/" + "Psr\\Log\\": "Psr/Log/" } }, "notification-url": "https://packagist.org/downloads/", @@ -836,40 +843,36 @@ "homepage": "http://www.php-fig.org/" } ], - "description": "Common Container Interface (PHP FIG PSR-11)", - "homepage": "https://github.com/php-fig/container", + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", "keywords": [ - "PSR-11", - "container", - "container-interface", - "container-interop", - "psr" + "log", + "psr", + "psr-3" ], - "time": "2017-02-14T16:28:37+00:00" + "time": "2019-11-01T11:05:21+00:00" }, { "name": "symfony/console", - "version": "v4.3.5", + "version": "v3.4.35", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "929ddf360d401b958f611d44e726094ab46a7369" + "reference": "17b154f932c5874cdbda6d05796b6490eec9f9f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/929ddf360d401b958f611d44e726094ab46a7369", - "reference": "929ddf360d401b958f611d44e726094ab46a7369", + "url": "https://api.github.com/repos/symfony/console/zipball/17b154f932c5874cdbda6d05796b6490eec9f9f7", + "reference": "17b154f932c5874cdbda6d05796b6490eec9f9f7", "shasum": "" }, "require": { - "php": "^7.1.3", - "symfony/polyfill-mbstring": "~1.0", - "symfony/polyfill-php73": "^1.8", - "symfony/service-contracts": "^1.1" + "php": "^5.5.9|>=7.0.8", + "symfony/debug": "~2.8|~3.0|~4.0", + "symfony/polyfill-mbstring": "~1.0" }, "conflict": { "symfony/dependency-injection": "<3.4", - "symfony/event-dispatcher": "<4.3", "symfony/process": "<3.3" }, "provide": { @@ -877,12 +880,11 @@ }, "require-dev": { "psr/log": "~1.0", - "symfony/config": "~3.4|~4.0", + "symfony/config": "~3.3|~4.0", "symfony/dependency-injection": "~3.4|~4.0", - "symfony/event-dispatcher": "^4.3", + "symfony/event-dispatcher": "~2.8|~3.0|~4.0", "symfony/lock": "~3.4|~4.0", - "symfony/process": "~3.4|~4.0", - "symfony/var-dumper": "^4.3" + "symfony/process": "~3.3|~4.0" }, "suggest": { "psr/log": "For using the console logger", @@ -893,7 +895,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.3-dev" + "dev-master": "3.4-dev" } }, "autoload": { @@ -920,40 +922,44 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2019-10-07T12:36:49+00:00" + "time": "2019-11-13T07:12:39+00:00" }, { - "name": "symfony/polyfill-mbstring", - "version": "v1.12.0", + "name": "symfony/debug", + "version": "v3.4.35", "source": { "type": "git", - "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "b42a2f66e8f1b15ccf25652c3424265923eb4f17" + "url": "https://github.com/symfony/debug.git", + "reference": "f72e33fdb1170b326e72c3157f0cd456351dd086" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/b42a2f66e8f1b15ccf25652c3424265923eb4f17", - "reference": "b42a2f66e8f1b15ccf25652c3424265923eb4f17", + "url": "https://api.github.com/repos/symfony/debug/zipball/f72e33fdb1170b326e72c3157f0cd456351dd086", + "reference": "f72e33fdb1170b326e72c3157f0cd456351dd086", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^5.5.9|>=7.0.8", + "psr/log": "~1.0" }, - "suggest": { - "ext-mbstring": "For best performance" + "conflict": { + "symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2" + }, + "require-dev": { + "symfony/http-kernel": "~2.8|~3.0|~4.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.12-dev" + "dev-master": "3.4-dev" } }, "autoload": { "psr-4": { - "Symfony\\Polyfill\\Mbstring\\": "" + "Symfony\\Component\\Debug\\": "" }, - "files": [ - "bootstrap.php" + "exclude-from-classmap": [ + "/Tests/" ] }, "notification-url": "https://packagist.org/downloads/", @@ -962,42 +968,38 @@ ], "authors": [ { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" + "name": "Fabien Potencier", + "email": "fabien@symfony.com" }, { "name": "Symfony Community", "homepage": "https://symfony.com/contributors" } ], - "description": "Symfony polyfill for the Mbstring extension", + "description": "Symfony Debug Component", "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "mbstring", - "polyfill", - "portable", - "shim" - ], - "time": "2019-08-06T08:03:45+00:00" + "time": "2019-10-24T15:33:53+00:00" }, { - "name": "symfony/polyfill-php73", + "name": "symfony/polyfill-mbstring", "version": "v1.12.0", "source": { "type": "git", - "url": "https://github.com/symfony/polyfill-php73.git", - "reference": "2ceb49eaccb9352bff54d22570276bb75ba4a188" + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "b42a2f66e8f1b15ccf25652c3424265923eb4f17" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/2ceb49eaccb9352bff54d22570276bb75ba4a188", - "reference": "2ceb49eaccb9352bff54d22570276bb75ba4a188", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/b42a2f66e8f1b15ccf25652c3424265923eb4f17", + "reference": "b42a2f66e8f1b15ccf25652c3424265923eb4f17", "shasum": "" }, "require": { "php": ">=5.3.3" }, + "suggest": { + "ext-mbstring": "For best performance" + }, "type": "library", "extra": { "branch-alias": { @@ -1006,13 +1008,10 @@ }, "autoload": { "psr-4": { - "Symfony\\Polyfill\\Php73\\": "" + "Symfony\\Polyfill\\Mbstring\\": "" }, "files": [ "bootstrap.php" - ], - "classmap": [ - "Resources/stubs" ] }, "notification-url": "https://packagist.org/downloads/", @@ -1029,73 +1028,16 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", + "description": "Symfony polyfill for the Mbstring extension", "homepage": "https://symfony.com", "keywords": [ "compatibility", + "mbstring", "polyfill", "portable", "shim" ], "time": "2019-08-06T08:03:45+00:00" - }, - { - "name": "symfony/service-contracts", - "version": "v1.1.7", - "source": { - "type": "git", - "url": "https://github.com/symfony/service-contracts.git", - "reference": "ffcde9615dc5bb4825b9f6aed07716f1f57faae0" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/ffcde9615dc5bb4825b9f6aed07716f1f57faae0", - "reference": "ffcde9615dc5bb4825b9f6aed07716f1f57faae0", - "shasum": "" - }, - "require": { - "php": "^7.1.3", - "psr/container": "^1.0" - }, - "suggest": { - "symfony/service-implementation": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.1-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Contracts\\Service\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Generic abstractions related to writing services", - "homepage": "https://symfony.com", - "keywords": [ - "abstractions", - "contracts", - "decoupling", - "interfaces", - "interoperability", - "standards" - ], - "time": "2019-09-17T11:12:18+00:00" } ], "packages-dev": [ @@ -1843,16 +1785,16 @@ }, { "name": "phpunit/phpunit", - "version": "7.5.16", + "version": "7.5.17", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "316afa6888d2562e04aeb67ea7f2017a0eb41661" + "reference": "4c92a15296e58191a4cd74cff3b34fc8e374174a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/316afa6888d2562e04aeb67ea7f2017a0eb41661", - "reference": "316afa6888d2562e04aeb67ea7f2017a0eb41661", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/4c92a15296e58191a4cd74cff3b34fc8e374174a", + "reference": "4c92a15296e58191a4cd74cff3b34fc8e374174a", "shasum": "" }, "require": { @@ -1923,7 +1865,7 @@ "testing", "xunit" ], - "time": "2019-09-14T09:08:39+00:00" + "time": "2019-10-28T10:37:36+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -2532,16 +2474,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.5.1", + "version": "3.5.2", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "82cd0f854ceca17731d6d019c7098e3755c45060" + "reference": "65b12cdeaaa6cd276d4c3033a95b9b88b12701e7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/82cd0f854ceca17731d6d019c7098e3755c45060", - "reference": "82cd0f854ceca17731d6d019c7098e3755c45060", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/65b12cdeaaa6cd276d4c3033a95b9b88b12701e7", + "reference": "65b12cdeaaa6cd276d4c3033a95b9b88b12701e7", "shasum": "" }, "require": { @@ -2579,7 +2521,7 @@ "phpcs", "standards" ], - "time": "2019-10-16T21:14:26+00:00" + "time": "2019-10-28T04:36:32+00:00" }, { "name": "symfony/polyfill-ctype", @@ -2641,20 +2583,20 @@ }, { "name": "symfony/yaml", - "version": "v4.3.5", + "version": "v3.4.35", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "41e16350a2a1c7383c4735aa2f9fce74cf3d1178" + "reference": "dab657db15207879217fc81df4f875947bf68804" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/41e16350a2a1c7383c4735aa2f9fce74cf3d1178", - "reference": "41e16350a2a1c7383c4735aa2f9fce74cf3d1178", + "url": "https://api.github.com/repos/symfony/yaml/zipball/dab657db15207879217fc81df4f875947bf68804", + "reference": "dab657db15207879217fc81df4f875947bf68804", "shasum": "" }, "require": { - "php": "^7.1.3", + "php": "^5.5.9|>=7.0.8", "symfony/polyfill-ctype": "~1.8" }, "conflict": { @@ -2669,7 +2611,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.3-dev" + "dev-master": "3.4-dev" } }, "autoload": { @@ -2696,7 +2638,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2019-09-11T15:41:19+00:00" + "time": "2019-10-24T15:33:53+00:00" }, { "name": "theseer/tokenizer", @@ -2798,5 +2740,8 @@ "php": "^7.1", "ext-pdo": "*" }, - "platform-dev": [] + "platform-dev": [], + "platform-overrides": { + "php": "7.1" + } } diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index 6073fbe008c..f4ba5df066b 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -70,6 +70,9 @@ public function setProxyDir($dir) * Gets the directory where Doctrine generates any necessary proxy class files. * * @return string|null + * + * @deprecated 3.0 We're switch to `ocramius/proxy-manager` and this method isn't applicable any longer + * @see https://github.com/Ocramius/ProxyManager */ public function getProxyDir() { @@ -82,6 +85,9 @@ public function getProxyDir() * Gets the strategy for automatically generating proxy classes. * * @return int Possible values are constants of Doctrine\Common\Proxy\AbstractProxyFactory. + * + * @deprecated 3.0 We're switch to `ocramius/proxy-manager` and this method isn't applicable any longer + * @see https://github.com/Ocramius/ProxyManager */ public function getAutoGenerateProxyClasses() { @@ -107,6 +113,9 @@ public function setAutoGenerateProxyClasses($autoGenerate) * Gets the namespace where proxy classes reside. * * @return string|null + * + * @deprecated 3.0 We're switch to `ocramius/proxy-manager` and this method isn't applicable any longer + * @see https://github.com/Ocramius/ProxyManager */ public function getProxyNamespace() { diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index c5204f3fb55..f003c089811 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -29,6 +29,7 @@ use Doctrine\ORM\Query\FilterCollection; use Doctrine\Common\Util\ClassUtils; use Throwable; +use function trigger_error; /** * The EntityManager is the central access point to ORM functionality. @@ -354,6 +355,13 @@ public function createQueryBuilder() */ public function flush($entity = null) { + if ($entity !== null) { + @trigger_error( + 'Calling ' . __METHOD__ . '() with any arguments to flush specific entities is deprecated and will not be supported in Doctrine 3.0.', + E_USER_DEPRECATED + ); + } + $this->errorIfClosed(); $this->unitOfWork->commit($entity); @@ -649,9 +657,13 @@ public function refresh($entity) * @return void * * @throws ORMInvalidArgumentException + * + * @deprecated 3.0 This method is being removed from the ORM and won't have any replacement */ public function detach($entity) { + @trigger_error('Method ' . __METHOD__ . '() is deprecated and will be removed in Doctrine 3.0.', E_USER_DEPRECATED); + if ( ! is_object($entity)) { throw ORMInvalidArgumentException::invalidObject('EntityManager#detach()', $entity); } @@ -670,9 +682,13 @@ public function detach($entity) * * @throws ORMInvalidArgumentException * @throws ORMException + * + * @deprecated 3.0 This method is being removed from the ORM and won't have any replacement */ public function merge($entity) { + @trigger_error('Method ' . __METHOD__ . '() is deprecated and will be removed in Doctrine 3.0.', E_USER_DEPRECATED); + if ( ! is_object($entity)) { throw ORMInvalidArgumentException::invalidObject('EntityManager#merge()', $entity); } @@ -687,6 +703,8 @@ public function merge($entity) */ public function copy($entity, $deep = false) { + @trigger_error('Method ' . __METHOD__ . '() is deprecated and will be removed in Doctrine 3.0.', E_USER_DEPRECATED); + throw new \BadMethodCallException("Not implemented."); } diff --git a/lib/Doctrine/ORM/EntityManagerInterface.php b/lib/Doctrine/ORM/EntityManagerInterface.php index 8bbc56798b2..16b7068b93d 100644 --- a/lib/Doctrine/ORM/EntityManagerInterface.php +++ b/lib/Doctrine/ORM/EntityManagerInterface.php @@ -190,7 +190,7 @@ public function close(); /** * Creates a copy of the given entity. Can create a shallow or a deep copy. * - * @deprecated method will be removed in 3.0 + * @deprecated 3.0 This method is being removed from the ORM and won't have any replacement * * @param object $entity The entity to copy. * @param boolean $deep FALSE for a shallow copy, TRUE for a deep copy. diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index efd5accbc7f..aa99f4bfeec 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -25,6 +25,7 @@ use Doctrine\ORM\Mapping\ClassMetadata as Metadata; use Doctrine\ORM\Mapping\MappingException; use Symfony\Component\Yaml\Yaml; +use function trigger_error; /** * The YamlDriver reads the mapping metadata from yaml schema files. @@ -34,6 +35,8 @@ * @author Guilherme Blanco * @author Jonathan H. Wage * @author Roman Borschel + * + * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement */ class YamlDriver extends FileDriver { @@ -44,6 +47,11 @@ class YamlDriver extends FileDriver */ public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENSION) { + @trigger_error( + 'YAML mapping driver is deprecated and will be removed in Doctrine 3.0, please migrate to annotation or XML driver.', + E_USER_DEPRECATED + ); + parent::__construct($locator, $fileExtension); } diff --git a/lib/Doctrine/ORM/Proxy/Proxy.php b/lib/Doctrine/ORM/Proxy/Proxy.php index f478d4905c0..72463d121e3 100644 --- a/lib/Doctrine/ORM/Proxy/Proxy.php +++ b/lib/Doctrine/ORM/Proxy/Proxy.php @@ -26,6 +26,8 @@ * * @author Roman Borschel * @since 2.0 + * + * @deprecated 3.0 This interface is being removed from the ORM and won't have any replacement, proxies will no longer implement it. */ interface Proxy extends BaseProxy { diff --git a/lib/Doctrine/ORM/Proxy/ProxyFactory.php b/lib/Doctrine/ORM/Proxy/ProxyFactory.php index 16cfde9317a..7648a14a5f8 100644 --- a/lib/Doctrine/ORM/Proxy/ProxyFactory.php +++ b/lib/Doctrine/ORM/Proxy/ProxyFactory.php @@ -37,6 +37,8 @@ * @author Giorgio Sironi * @author Marco Pivetta * @since 2.0 + * + * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement */ class ProxyFactory extends AbstractProxyFactory { diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php index 112efb96427..1fac2497be9 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php @@ -27,6 +27,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; /** * Command to convert a Doctrine 1 schema to a Doctrine 2 mapping file. @@ -37,6 +38,8 @@ * @author Guilherme Blanco * @author Jonathan Wage * @author Roman Borschel + * + * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement */ class ConvertDoctrine1SchemaCommand extends Command { @@ -116,6 +119,9 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $ui = new SymfonyStyle($input, $output); + $ui->warning('Command ' . $this->getName() . ' is deprecated and will be removed in Doctrine 3.0.'); + // Process source directories $fromPaths = array_merge([$input->getArgument('from-path')], $input->getOption('from')); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php index 828c1432db5..3aff45b7c73 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php @@ -38,6 +38,8 @@ * @author Guilherme Blanco * @author Jonathan Wage * @author Roman Borschel + * + * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement */ class GenerateEntitiesCommand extends Command { @@ -87,6 +89,7 @@ class is supposed to extend which. You have to adjust the entity protected function execute(InputInterface $input, OutputInterface $output) { $ui = new SymfonyStyle($input, $output); + $ui->warning('Command ' . $this->getName() . ' is deprecated and will be removed in Doctrine 3.0.'); $em = $this->getHelper('em')->getEntityManager(); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php index 666ae7867bd..c09f10fdf25 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php @@ -37,6 +37,8 @@ * @author Guilherme Blanco * @author Jonathan Wage * @author Roman Borschel + * + * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement */ class GenerateRepositoriesCommand extends Command { @@ -59,6 +61,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $ui = new SymfonyStyle($input, $output); + $ui->warning('Command ' . $this->getName() . ' is deprecated and will be removed in Doctrine 3.0.'); $em = $this->getHelper('em')->getEntityManager(); diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 89761838c83..5143f637a87 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -24,6 +24,7 @@ use Doctrine\DBAL\Types\Type; use Doctrine\ORM\Mapping\ClassMetadataInfo; use function str_replace; +use function trigger_error; /** * Generic class used to generate PHP5 entity classes from ClassMetadataInfo instances. @@ -45,6 +46,8 @@ * @author Guilherme Blanco * @author Jonathan Wage * @author Roman Borschel + * + * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement */ class EntityGenerator { @@ -335,6 +338,8 @@ public function __construct() */ public function __construct() { + @trigger_error(self::class . ' is deprecated and will be removed in Doctrine 3.0', E_USER_DEPRECATED); + if (version_compare(\Doctrine\Common\Version::VERSION, '2.2.0-DEV', '>=')) { $this->annotationsPrefix = 'ORM\\'; } diff --git a/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php b/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php index dbfcbc6d49f..7dffe97eaa5 100644 --- a/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php @@ -20,6 +20,7 @@ namespace Doctrine\ORM\Tools; use Doctrine\ORM\EntityRepository; +use function trigger_error; /** * Class to generate entity repository classes @@ -31,6 +32,8 @@ * @author Guilherme Blanco * @author Jonathan Wage * @author Roman Borschel + * + * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement */ class EntityRepositoryGenerator { @@ -52,6 +55,11 @@ class extends } '; + public function __construct() + { + @trigger_error(self::class . ' is deprecated and will be removed in Doctrine 3.0', E_USER_DEPRECATED); + } + /** * @param string $fullClassName * diff --git a/lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php b/lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php index ab44263cdf4..fcb11cc2d9b 100644 --- a/lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php @@ -19,6 +19,8 @@ namespace Doctrine\ORM\Tools\Export; +use function trigger_error; + /** * Class used for converting your mapping information between the * supported formats: yaml, xml, and php/annotation. @@ -26,6 +28,8 @@ * @link www.doctrine-project.org * @since 2.0 * @author Jonathan Wage + * + * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement */ class ClassMetadataExporter { @@ -40,6 +44,11 @@ class ClassMetadataExporter 'annotation' => Driver\AnnotationExporter::class ]; + public function __construct() + { + @trigger_error(self::class . ' is deprecated and will be removed in Doctrine 3.0', E_USER_DEPRECATED); + } + /** * Registers a new exporter driver class under a specified name. * diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php index 100e16fd00f..96cb88b36cb 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php @@ -21,6 +21,7 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Tools\Export\ExportException; +use function trigger_error; /** * Abstract base class which is to be used for the Exporter drivers @@ -29,6 +30,8 @@ * @link www.doctrine-project.org * @since 2.0 * @author Jonathan Wage + * + * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement */ abstract class AbstractExporter { @@ -57,6 +60,8 @@ abstract class AbstractExporter */ public function __construct($dir = null) { + @trigger_error(static::class . ' is deprecated and will be removed in Doctrine 3.0', E_USER_DEPRECATED); + $this->_outputDir = $dir; } diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php index 171ac872849..2e7e4cbfd14 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php @@ -28,6 +28,8 @@ * @link www.doctrine-project.org * @since 2.0 * @author Jonathan Wage + * + * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement */ class AnnotationExporter extends AbstractExporter { diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php index c918c71dd51..3e92dfe5773 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php @@ -27,6 +27,8 @@ * @link www.doctrine-project.org * @since 2.0 * @author Jonathan Wage + * + * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement */ class PhpExporter extends AbstractExporter { diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php index 60dabe97336..7ea41f0da49 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php @@ -28,6 +28,8 @@ * @link www.doctrine-project.org * @since 2.0 * @author Jonathan Wage + * + * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement */ class XmlExporter extends AbstractExporter { diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php index c20c3a4fe6a..7043e0a3716 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php @@ -28,6 +28,8 @@ * @link www.doctrine-project.org * @since 2.0 * @author Jonathan Wage + * + * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement */ class YamlExporter extends AbstractExporter { diff --git a/lib/Doctrine/ORM/Tools/Export/ExportException.php b/lib/Doctrine/ORM/Tools/Export/ExportException.php index 853159f17de..c9689d0a519 100644 --- a/lib/Doctrine/ORM/Tools/Export/ExportException.php +++ b/lib/Doctrine/ORM/Tools/Export/ExportException.php @@ -21,6 +21,9 @@ use Doctrine\ORM\ORMException; +/** + * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement + */ class ExportException extends ORMException { /** diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 82695984b65..98ccd81bdc9 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1866,7 +1866,7 @@ private function doRemove($entity, array &$visited) * @throws OptimisticLockException If the entity uses optimistic locking through a version * attribute and the version check against the managed copy fails. * - * @todo Require active transaction!? OptimisticLockException may result in undefined state!? + * @deprecated 3.0 This method is being removed from the ORM and won't have any replacement */ public function merge($entity) { @@ -2056,6 +2056,8 @@ private function updateAssociationWithMergedEntity($entity, array $association, * @param object $entity The entity to detach. * * @return void + * + * @deprecated 3.0 This method is being removed from the ORM and won't have any replacement */ public function detach($entity) { diff --git a/lib/Doctrine/ORM/Version.php b/lib/Doctrine/ORM/Version.php index b289a2aa8a5..b0f070a4e24 100644 --- a/lib/Doctrine/ORM/Version.php +++ b/lib/Doctrine/ORM/Version.php @@ -29,6 +29,8 @@ * @author Guilherme Blanco * @author Jonathan Wage * @author Roman Borschel + * + * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement */ class Version { diff --git a/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php b/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php index b8688d871db..14b06893b8b 100644 --- a/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php +++ b/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php @@ -5,10 +5,14 @@ use Doctrine\ORM\Decorator\EntityManagerDecorator; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query\ResultSetMapping; +use Doctrine\Tests\VerifyDeprecations; use PHPUnit\Framework\TestCase; +use function in_array; class EntityManagerDecoratorTest extends TestCase { + use VerifyDeprecations; + const VOID_METHODS = [ 'persist', 'remove', @@ -83,5 +87,12 @@ public function testAllMethodCallsAreDelegatedToTheWrappedInstance($method, arra }; $this->assertSame($return, $decorator->$method(...$parameters)); + + if (in_array($method, ['copy', 'merge', 'detach', 'getHydrator'], true)) { + $this->assertHasDeprecationMessages(); + return; + } + + $this->assertNotHasDeprecationMessages(); } } diff --git a/tests/Doctrine/Tests/ORM/EntityManagerTest.php b/tests/Doctrine/Tests/ORM/EntityManagerTest.php index a05e8610982..e2774cf2dda 100644 --- a/tests/Doctrine/Tests/ORM/EntityManagerTest.php +++ b/tests/Doctrine/Tests/ORM/EntityManagerTest.php @@ -20,9 +20,12 @@ use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\GeoNames\Country; use Doctrine\Tests\OrmTestCase; +use Doctrine\Tests\VerifyDeprecations; class EntityManagerTest extends OrmTestCase { + use VerifyDeprecations; + /** * @var EntityManager */ @@ -305,4 +308,44 @@ public function testClearManagerWithNullValue() $this->assertFalse($this->_em->contains($entity)); } + + public function testDeprecatedFlushWithArguments() : void + { + $entity = new Country(456, 'United Kingdom'); + $this->_em->persist($entity); + + $this->expectDeprecationMessage('Calling Doctrine\ORM\EntityManager::flush() with any arguments to flush specific entities is deprecated and will not be supported in Doctrine 3.0.'); + $this->_em->flush($entity); + } + + public function testDeprecatedMerge() : void + { + $entity = new Country(456, 'United Kingdom'); + $this->_em->persist($entity); + + $this->expectDeprecationMessage('Method Doctrine\ORM\EntityManager::merge() is deprecated and will be removed in Doctrine 3.0.'); + $this->_em->merge($entity); + } + + public function testDeprecatedDetach() : void + { + $entity = new Country(456, 'United Kingdom'); + $this->_em->persist($entity); + + $this->expectDeprecationMessage('Method Doctrine\ORM\EntityManager::detach() is deprecated and will be removed in Doctrine 3.0.'); + $this->_em->detach($entity); + } + + public function testDeprecatedCopy() : void + { + $entity = new Country(456, 'United Kingdom'); + $this->_em->persist($entity); + + try { + $this->expectDeprecationMessage('Method Doctrine\ORM\EntityManager::copy() is deprecated and will be removed in Doctrine 3.0.'); + $this->_em->copy($entity); + } catch (\BadMethodCallException $e) { + // do nothing + } + } } diff --git a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php index 7bdb846535c..7f19fa83010 100644 --- a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php @@ -16,9 +16,12 @@ use Doctrine\Tests\Models\CMS\CmsPhonenumber; use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\OrmFunctionalTestCase; +use Doctrine\Tests\VerifyDeprecations; class BasicFunctionalTest extends OrmFunctionalTestCase { + use VerifyDeprecations; + protected function setUp() { $this->useModelSet('cms'); @@ -499,7 +502,7 @@ public function testSetSetAssociationWithGetReference() $this->_em->persist($address); $this->_em->flush(); - $this->_em->detach($address); + $this->_em->clear(CmsAddress::class); $this->assertFalse($this->_em->contains($address)); $this->assertTrue($this->_em->contains($user)); @@ -894,6 +897,7 @@ public function testMergePersistsNewEntities() $user2 = $this->_em->find(get_class($managedUser), $userId); $this->assertInstanceOf(CmsUser::class, $user2); + $this->assertHasDeprecationMessages(); } public function testMergeNonPersistedProperties() @@ -921,6 +925,7 @@ public function testMergeNonPersistedProperties() $this->assertNull($user2->nonPersistedProperty); $this->assertNull($user2->nonPersistedPropertyObject); $this->assertEquals('active', $user2->status); + $this->assertHasDeprecationMessages(); } public function testMergeThrowsExceptionIfEntityWithGeneratedIdentifierDoesNotExist() @@ -933,6 +938,7 @@ public function testMergeThrowsExceptionIfEntityWithGeneratedIdentifierDoesNotEx $this->expectException(EntityNotFoundException::class); $this->_em->merge($user); + $this->assertHasDeprecationMessages(); } /** @@ -962,6 +968,7 @@ public function testOneToOneMergeSetNull() $this->_em->clear(); $this->assertNull($this->_em->find(get_class($ph), $ph->phonenumber)->getUser()); + $this->assertHasDeprecationMessages(); } /** @@ -1073,6 +1080,7 @@ public function testFlushManyExplicitEntities() $this->assertTrue($userB->id > 0, 'user b has an id'); $this->assertTrue($userC->id > 0, 'user c has an id'); $this->assertEquals('UserC', $userC->name, 'name has not changed because we did not flush it'); + $this->assertHasDeprecationMessages(); } /** @@ -1094,6 +1102,7 @@ public function testFlushSingleManagedEntity() $user = $this->_em->find(get_class($user), $user->id); $this->assertEquals('administrator', $user->status); + $this->assertHasDeprecationMessages(); } /** @@ -1137,6 +1146,7 @@ public function testFlushSingleAndNewEntity() $this->assertTrue($this->_em->contains($otherUser), "Other user is contained in EntityManager"); $this->assertTrue($otherUser->id > 0, "other user has an id"); + $this->assertHasDeprecationMessages(); } /** @@ -1164,6 +1174,7 @@ public function testFlushAndCascadePersist() $this->assertTrue($this->_em->contains($address), "Other user is contained in EntityManager"); $this->assertTrue($address->id > 0, "other user has an id"); + $this->assertHasDeprecationMessages(); } /** @@ -1213,6 +1224,7 @@ public function testFlushSingleNewEntityThenRemove() $this->_em->clear(); $this->assertNull($this->_em->find(get_class($user), $userId)); + $this->assertHasDeprecationMessages(); } /** @@ -1241,6 +1253,7 @@ public function testProxyIsIgnored() $this->assertTrue($this->_em->contains($otherUser), "Other user is contained in EntityManager"); $this->assertTrue($otherUser->id > 0, "other user has an id"); + $this->assertHasDeprecationMessages(); } /** @@ -1270,6 +1283,7 @@ public function testFlushSingleSaveOnlySingle() $user2 = $this->_em->find(get_class($user2), $user2->id); $this->assertEquals('developer', $user2->status); + $this->assertHasDeprecationMessages(); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php b/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php index 523c98c0943..b1a98530713 100644 --- a/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php @@ -10,6 +10,7 @@ use Doctrine\Tests\Models\CMS\CmsAddress; use Doctrine\Tests\Models\CMS\CmsArticle; use Doctrine\Tests\OrmFunctionalTestCase; +use Doctrine\Tests\VerifyDeprecations; /** * Description of DetachedEntityTest @@ -18,6 +19,8 @@ */ class DetachedEntityTest extends OrmFunctionalTestCase { + use VerifyDeprecations; + protected function setUp() { $this->useModelSet('cms'); @@ -44,6 +47,7 @@ public function testSimpleDetachMerge() $this->assertFalse($user === $user2); $this->assertTrue($this->_em->contains($user2)); $this->assertEquals('Roman B.', $user2->name); + $this->assertHasDeprecationMessages(); } public function testSerializeUnserializeModifyMerge() @@ -105,6 +109,7 @@ public function testSerializeUnserializeModifyMerge() $this->assertInstanceOf(CmsPhonenumber::class, $phonenumbers[0]); $this->assertTrue($this->_em->getUnitOfWork()->isInIdentityMap($phonenumbers[0])); $this->assertTrue($this->_em->contains($phonenumbers[0]), "Failed to assert that first phonenumber in collection is contained inside EntityManager persistence context."); + $this->assertHasDeprecationMessages(); } /** @@ -156,6 +161,7 @@ public function testUninitializedLazyAssociationsAreIgnoredOnMerge() $this->assertInstanceOf(Proxy::class, $managedAddress2->user); $this->assertFalse($managedAddress2->user === $detachedAddress2->user); $this->assertFalse($managedAddress2->user->__isInitialized__); + $this->assertHasDeprecationMessages(); } /** @@ -181,6 +187,7 @@ public function testUseDetachedEntityAsQueryParameter() $this->assertInstanceOf(CmsUser::class, $newUser); $this->assertEquals('gblanco', $newUser->username); + $this->assertHasDeprecationMessages(); } /** @@ -200,6 +207,7 @@ public function testDetachManagedUnpersistedEntity() $this->assertFalse($this->_em->contains($user)); $this->assertFalse($this->_em->getUnitOfWork()->isInIdentityMap($user)); + $this->assertHasDeprecationMessages(); } /** @@ -223,6 +231,7 @@ public function testMergeArticleWrongVersion() $this->expectExceptionMessage('The optimistic lock failed, version 1 was expected, but is actually 2'); $this->_em->merge($article); + $this->assertHasDeprecationMessages(); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php index ebc7acee973..b8158c17a01 100644 --- a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php @@ -20,12 +20,15 @@ use Doctrine\Tests\Models\DDC753\DDC753EntityWithDefaultCustomRepository; use Doctrine\Tests\Models\DDC753\DDC753InvalidRepository; use Doctrine\Tests\OrmFunctionalTestCase; +use Doctrine\Tests\VerifyDeprecations; /** * @author robo */ class EntityRepositoryTest extends OrmFunctionalTestCase { + use VerifyDeprecations; + protected function setUp() { $this->useModelSet('cms'); @@ -969,6 +972,7 @@ public function testMatchingCriteriaNullAssocComparison() $this->assertNull($usersIsNull[0]->getEmail()); $this->assertNull($usersEqNull[0]->getEmail()); + $this->assertHasDeprecationMessages(); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/MergeCompositeToOneKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/MergeCompositeToOneKeyTest.php index fab94a9066c..54a9bc833da 100644 --- a/tests/Doctrine/Tests/ORM/Functional/MergeCompositeToOneKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/MergeCompositeToOneKeyTest.php @@ -5,9 +5,12 @@ use Doctrine\Tests\Models\MixedToOneIdentity\CompositeToOneKeyState; use Doctrine\Tests\Models\MixedToOneIdentity\Country; use Doctrine\Tests\OrmFunctionalTestCase; +use Doctrine\Tests\VerifyDeprecations; class MergeCompositeToOneKeyTest extends OrmFunctionalTestCase { + use VerifyDeprecations; + /** * {@inheritDoc} */ @@ -43,5 +46,6 @@ public function testMergingOfEntityWithCompositeIdentifierContainingToOneAssocia $this->assertNotSame($state, $merged); $this->assertInstanceOf(Country::class, $merged->country); $this->assertNotSame($country, $merged->country); + $this->assertHasDeprecationMessages(); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php b/tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php index 3d0acd1f898..e323a190711 100644 --- a/tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/MergeProxiesTest.php @@ -11,9 +11,12 @@ use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Tests\Models\Generic\DateTimeModel; use Doctrine\Tests\OrmFunctionalTestCase; +use Doctrine\Tests\VerifyDeprecations; class MergeProxiesTest extends OrmFunctionalTestCase { + use VerifyDeprecations; + /** * {@inheritDoc} */ @@ -24,6 +27,12 @@ protected function setUp() parent::setUp(); } + /** @after */ + public function ensureTestGeneratedDeprecationMessages() : void + { + $this->assertHasDeprecationMessages(); + } + /** * @group DDC-1392 * @group DDC-1734 diff --git a/tests/Doctrine/Tests/ORM/Functional/MergeSharedEntitiesTest.php b/tests/Doctrine/Tests/ORM/Functional/MergeSharedEntitiesTest.php index b549a420108..3e2937eda99 100644 --- a/tests/Doctrine/Tests/ORM/Functional/MergeSharedEntitiesTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/MergeSharedEntitiesTest.php @@ -4,9 +4,12 @@ use Doctrine\ORM\Tools\ToolsException; use Doctrine\Tests\OrmFunctionalTestCase; +use Doctrine\Tests\VerifyDeprecations; class MergeSharedEntitiesTest extends OrmFunctionalTestCase { + use VerifyDeprecations; + /** * {@inheritDoc} */ @@ -25,6 +28,12 @@ protected function setUp() } } + /** @after */ + public function ensureTestGeneratedDeprecationMessages() : void + { + $this->assertHasDeprecationMessages(); + } + public function testMergeSharedNewEntities() { $file = new MSEFile; diff --git a/tests/Doctrine/Tests/ORM/Functional/MergeVersionedManyToOneTest.php b/tests/Doctrine/Tests/ORM/Functional/MergeVersionedManyToOneTest.php index 43af6720c83..18e061a45e2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/MergeVersionedManyToOneTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/MergeVersionedManyToOneTest.php @@ -5,12 +5,15 @@ use Doctrine\Tests\Models\VersionedManyToOne\Article; use Doctrine\Tests\Models\VersionedManyToOne\Category; use Doctrine\Tests\OrmFunctionalTestCase; +use Doctrine\Tests\VerifyDeprecations; /** * @group MergeVersionedOneToMany */ class MergeVersionedManyToOneTest extends OrmFunctionalTestCase { + use VerifyDeprecations; + protected function setUp() { $this->useModelSet('versioned_many_to_one'); @@ -40,5 +43,6 @@ public function testSetVersionOnCreate() $this->_em->flush(); $this->assertEquals(2, $articleMerged->version); + $this->assertHasDeprecationMessages(); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/ProxiesLikeEntitiesTest.php b/tests/Doctrine/Tests/ORM/Functional/ProxiesLikeEntitiesTest.php index c88eff4ab70..e88733d7db5 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ProxiesLikeEntitiesTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ProxiesLikeEntitiesTest.php @@ -83,7 +83,7 @@ public function testEntityWithIdentifier() $this->assertInstanceOf(CmsUserProxy::class, $uninitializedProxy); $this->_em->persist($uninitializedProxy); - $this->_em->flush($uninitializedProxy); + $this->_em->flush(); $this->assertFalse($uninitializedProxy->__isInitialized(), 'Proxy didn\'t get initialized during flush operations'); $this->assertEquals($userId, $uninitializedProxy->getId()); $this->_em->remove($uninitializedProxy); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php index 8478a5f66d6..f1685d60941 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php @@ -9,12 +9,15 @@ use Doctrine\Tests\Models\DDC117\DDC117ApproveChanges; use Doctrine\Tests\Models\DDC117\DDC117Editor; use Doctrine\Tests\Models\DDC117\DDC117Link; +use Doctrine\Tests\VerifyDeprecations; /** * @group DDC-117 */ class DDC117Test extends \Doctrine\Tests\OrmFunctionalTestCase { + use VerifyDeprecations; + private $article1; private $article2; private $reference; @@ -435,11 +438,12 @@ public function testMergeForeignKeyIdentifierEntity() $refRep = $this->_em->find(DDC117Reference::class, $idCriteria); - $this->_em->detach($refRep); + $this->_em->clear(DDC117Reference::class); $refRep = $this->_em->merge($refRep); $this->assertEquals($this->article1->id(), $refRep->source()->id()); $this->assertEquals($this->article2->id(), $refRep->target()->id()); + $this->assertHasDeprecationMessages(); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1276Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1276Test.php index eeaa870ae4d..d340746863d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1276Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1276Test.php @@ -4,12 +4,15 @@ use Doctrine\Tests\Models\CMS\CmsGroup; use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\VerifyDeprecations; /** * @group DDC-1276 */ class DDC1276Test extends \Doctrine\Tests\OrmFunctionalTestCase { + use VerifyDeprecations; + public function setUp() { $this->useModelSet('cms'); @@ -43,5 +46,6 @@ public function testIssue() $this->assertEquals(2, count($user->groups)); $this->_em->flush(); + $this->assertHasDeprecationMessages(); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1383Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1383Test.php index 7a13d7ac9bc..ca75f905508 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1383Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1383Test.php @@ -2,11 +2,15 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\Tests\VerifyDeprecations; + /** * @group DDC-1383 */ class DDC1383Test extends \Doctrine\Tests\OrmFunctionalTestCase { + use VerifyDeprecations; + protected function setUp() { parent::setUp(); @@ -47,6 +51,7 @@ public function testFailingCase() // Parent is NOT instance of entity self::assertTrue($parent instanceof DDC1383Entity, "Entity class is " . get_class($parent) . ', "DDC1383Entity" was expected'); + $this->assertHasDeprecationMessages(); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1392Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1392Test.php index 806e61de4da..b872e413b50 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1392Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1392Test.php @@ -3,12 +3,15 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; use Doctrine\ORM\UnitOfWork; +use Doctrine\Tests\VerifyDeprecations; /** * @group DDC-1392 */ class DDC1392Test extends \Doctrine\Tests\OrmFunctionalTestCase { + use VerifyDeprecations; + protected function setUp() { parent::setUp(); @@ -61,6 +64,7 @@ public function testFailingCase() $result = $q->getSingleScalarResult(); self::assertEquals(1, $result); + $this->assertHasDeprecationMessages(); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1509Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1509Test.php index 17cfdf78dc7..a2f9c1904a9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1509Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1509Test.php @@ -2,11 +2,14 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\Tests\VerifyDeprecations; + /** * @group DDC-1509 */ class DDC1509Test extends \Doctrine\Tests\OrmFunctionalTestCase { + use VerifyDeprecations; protected function setUp() { @@ -48,6 +51,7 @@ public function testFailingCase() $this->assertNotNull($pic->getThumbnail()); $this->assertNotNull($pic->getFile()); + $this->assertHasDeprecationMessages(); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1594Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1594Test.php index 0c94f73d54c..00cd70a3c09 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1594Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1594Test.php @@ -3,12 +3,15 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\VerifyDeprecations; /** * @group DDC-1594 */ class DDC1594Test extends \Doctrine\Tests\OrmFunctionalTestCase { + use VerifyDeprecations; + public function setUp() { $this->useModelSet('cms'); @@ -37,5 +40,6 @@ public function testIssue() $this->assertNotSame($mergedUser, $detachedUser); $this->assertEquals('bar', $detachedUser->getName()); $this->assertEquals('bar', $mergedUser->getName()); + $this->assertHasDeprecationMessages(); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1734Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1734Test.php index cfca544ae81..64199eb07c0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1734Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1734Test.php @@ -4,9 +4,12 @@ use Doctrine\ORM\Proxy\Proxy; use Doctrine\Tests\Models\CMS\CmsGroup; +use Doctrine\Tests\VerifyDeprecations; class DDC1734Test extends \Doctrine\Tests\OrmFunctionalTestCase { + use VerifyDeprecations; + /** * {@inheritDoc} */ @@ -16,6 +19,12 @@ protected function setUp() parent::setUp(); } + /** @after */ + public function ensureTestGeneratedDeprecationMessages() : void + { + $this->assertHasDeprecationMessages(); + } + /** * This test is DDC-1734 minus the serialization, i.e. it works * diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php index 4856852ecaa..99b2ade0f0b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2106Test.php @@ -26,7 +26,7 @@ public function testDetachedEntityAsId() $entity = new DDC2106Entity(); $this->_em->persist($entity); $this->_em->flush(); - $this->_em->detach($entity); + $this->_em->clear(DDC2106Entity::class); $entity = $this->_em->getRepository(DDC2106Entity::class)->findOneBy([]); // ... and a managed entity without id diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2230Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2230Test.php index 4ced4df4dc7..d68fd8a52e9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2230Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2230Test.php @@ -7,12 +7,15 @@ use Doctrine\Common\Proxy\Proxy; use Doctrine\ORM\Tools\ToolsException; use Doctrine\Tests\OrmFunctionalTestCase; +use Doctrine\Tests\VerifyDeprecations; /** * @group DDC-2230 */ class DDC2230Test extends OrmFunctionalTestCase { + use VerifyDeprecations; + protected function setUp() { parent::setUp(); @@ -48,6 +51,7 @@ public function testNotifyTrackingNotCalledOnUninitializedProxies() $this->assertInstanceOf(Proxy::class, $address); $this->assertFalse($address->__isInitialized()); + $this->assertHasDeprecationMessages(); } public function testNotifyTrackingCalledOnProxyInitialization() @@ -67,6 +71,7 @@ public function testNotifyTrackingCalledOnProxyInitialization() $addressProxy->__load(); $this->assertSame($this->_em->getUnitOfWork(), $addressProxy->listener); + $this->assertNotHasDeprecationMessages(); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2409Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2409Test.php index 94d39b99446..aa44bbaee6b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2409Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2409Test.php @@ -5,12 +5,15 @@ use Doctrine\ORM\UnitOfWork; use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\CMS\CmsArticle; +use Doctrine\Tests\VerifyDeprecations; /** * @group DDC-2409 */ class DDC2409Test extends \Doctrine\Tests\OrmFunctionalTestCase { + use VerifyDeprecations; + public function setUp() { $this->useModelSet('cms'); @@ -53,8 +56,8 @@ public function testIssue() $this->assertEquals(UnitOfWork::STATE_MANAGED, $uow->getEntityState($article)); $this->assertEquals(UnitOfWork::STATE_NEW, $uow->getEntityState($user)); - $em->detach($user); - $em->detach($article); + $em->clear(CmsUser::class); + $em->clear(CmsArticle::class); $userMerged = $em->merge($user); $articleMerged = $em->merge($article); @@ -68,5 +71,6 @@ public function testIssue() $this->assertNotSame($article, $articleMerged); $this->assertNotSame($userMerged, $articleMerged->user); $this->assertSame($user, $articleMerged->user); + $this->assertHasDeprecationMessages(); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2645Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2645Test.php index d6a77f7db37..e71de5b3f0a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2645Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2645Test.php @@ -2,11 +2,15 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\Tests\VerifyDeprecations; + /** * @group DDC-2645 */ class DDC2645Test extends \Doctrine\Tests\OrmFunctionalTestCase { + use VerifyDeprecations; + public function testIssue() { $bar = new DDC2645Bar; @@ -22,6 +26,7 @@ public function testIssue() $this->assertSame($foo, $foo3); $this->assertEquals('Bar', $foo->name); + $this->assertHasDeprecationMessages(); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2790Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2790Test.php index ee2668931c0..0f3efab262c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2790Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2790Test.php @@ -45,7 +45,7 @@ public function testIssue() // (and consequently also triggers preUpdate/postUpdate for the entity in question) $entity->name = 'Robin'; - $this->_em->flush($entity); + $this->_em->flush(); $qb = $this->_em->createQueryBuilder(); $qb->from(get_class($entity), 'c'); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2984Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2984Test.php index 69f4d01c0c5..e21ac82dc87 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2984Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2984Test.php @@ -40,7 +40,7 @@ public function testIssue() $user->applyName('Alex'); $this->_em->persist($user); - $this->_em->flush($user); + $this->_em->flush(); $repository = $this->_em->getRepository(__NAMESPACE__ . "\DDC2984User"); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3699Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3699Test.php index fd284e5b11d..8d3607112e2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3699Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3699Test.php @@ -3,12 +3,15 @@ use Doctrine\Tests\Models\DDC3699\DDC3699RelationOne; use Doctrine\Tests\Models\DDC3699\DDC3699RelationMany; use Doctrine\Tests\Models\DDC3699\DDC3699Child; +use Doctrine\Tests\VerifyDeprecations; /** * @group DDC-3699 */ class DDC3597Test extends \Doctrine\Tests\OrmFunctionalTestCase { + use VerifyDeprecations; + protected function setUp() { $this->useModelSet('ddc3699'); @@ -16,6 +19,12 @@ protected function setUp() parent::setUp(); } + /** @after */ + public function ensureTestGeneratedDeprecationMessages() : void + { + $this->assertHasDeprecationMessages(); + } + /** * @group DDC-3699 */ diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3711Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3711Test.php index bd2b1ba9bc6..dc633c7aa88 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3711Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3711Test.php @@ -6,12 +6,15 @@ use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\Tests\Models\DDC3711\DDC3711EntityA; use Doctrine\Tests\ORM\Mapping\YamlMappingDriverTest; +use Doctrine\Tests\VerifyDeprecations; /** * @author Marc Pantel */ class DDC3711Test extends YamlMappingDriverTest { + use VerifyDeprecations; + public function testCompositeKeyForJoinTableInManyToManyCreation() { $yamlDriver = $this->_loadDriver(); @@ -26,5 +29,6 @@ public function testCompositeKeyForJoinTableInManyToManyCreation() $this->assertEquals(['link_a_id1' => "id1", 'link_a_id2' => "id2"], $entityA->associationMappings['entityB']['relationToSourceKeyColumns']); $this->assertEquals(['link_b_id1' => "id1", 'link_b_id2' => "id2"], $entityA->associationMappings['entityB']['relationToTargetKeyColumns']); + $this->assertHasDeprecationMessages(); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC501Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC501Test.php index 5b2996aab2f..14c8be412cb 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC501Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC501Test.php @@ -5,6 +5,7 @@ use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\CMS\CmsGroup; use Doctrine\Tests\Models\CMS\CmsPhonenumber; +use Doctrine\Tests\VerifyDeprecations; /** * ----------------- !! NOTE !! -------------------- @@ -19,6 +20,8 @@ */ class DDC501Test extends OrmFunctionalTestCase { + use VerifyDeprecations; + protected function setUp() { $this->useModelSet('cms'); @@ -80,6 +83,7 @@ public function testMergeUnitializedManyToManyAndOneToManyCollections() // This works fine as long as cmUser::groups doesn't cascade "merge" // Otherwise group memberships are physically deleted now! $this->assertEquals(2, count($userClone->getGroups())); + $this->assertHasDeprecationMessages(); } protected function createAndPersistUser() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC518Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC518Test.php index 073bb335188..64749876b8c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC518Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC518Test.php @@ -2,8 +2,12 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\Tests\VerifyDeprecations; + class DDC518Test extends \Doctrine\Tests\OrmFunctionalTestCase { + use VerifyDeprecations; + public function setUp() { $this->useModelSet('cms'); @@ -31,5 +35,6 @@ public function testMergeWithRelatedNew() $managedArticle = $this->_em->merge($article); $this->assertSame($article->user, $managedArticle->user); + $this->assertHasDeprecationMessages(); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC729Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC729Test.php index af4c9634c12..8cc9642100d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC729Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC729Test.php @@ -4,9 +4,12 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\PersistentCollection; +use Doctrine\Tests\VerifyDeprecations; class DDC729Test extends \Doctrine\Tests\OrmFunctionalTestCase { + use VerifyDeprecations; + public function setUp() { parent::setUp(); @@ -24,6 +27,12 @@ public function setUp() } } + /** @after */ + public function ensureTestGeneratedDeprecationMessages() : void + { + $this->assertHasDeprecationMessages(); + } + public function testMergeManyToMany() { $a = new DDC729A(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC758Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC758Test.php index a5707f233e3..e7a36310ed6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC758Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC758Test.php @@ -5,9 +5,11 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\CMS\CmsGroup; +use Doctrine\Tests\VerifyDeprecations; class DDC758Test extends \Doctrine\Tests\OrmFunctionalTestCase { + use VerifyDeprecations; public function setUp() { @@ -17,6 +19,12 @@ public function setUp() parent::setUp(); } + /** @after */ + public function ensureTestGeneratedDeprecationMessages() : void + { + $this->assertHasDeprecationMessages(); + } + /** * Helper method to set cascade to merge only */ diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php index ff5de971acd..7a483ebc783 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php @@ -141,7 +141,7 @@ public function testDqlOnEmbeddedObjectsField() $person = new DDC93Person('Johannes', new DDC93Address('Moo', '12345', 'Karlsruhe', new DDC93Country('Germany'))); $this->_em->persist($person); - $this->_em->flush($person); + $this->_em->flush(); // SELECT $selectDql = "SELECT p FROM " . __NAMESPACE__ ."\\DDC93Person p WHERE p.address.city = :city AND p.address.country.name = :country"; @@ -184,7 +184,7 @@ public function testPartialDqlOnEmbeddedObjectsField() { $person = new DDC93Person('Karl', new DDC93Address('Foo', '12345', 'Gosport', new DDC93Country('England'))); $this->_em->persist($person); - $this->_em->flush($person); + $this->_em->flush(); $this->_em->clear(); // Prove that the entity was persisted correctly. @@ -254,7 +254,7 @@ public function testEmbeddableWithInheritance() { $car = new DDC93Car(new DDC93Address('Foo', '12345', 'Asdf')); $this->_em->persist($car); - $this->_em->flush($car); + $this->_em->flush(); $reloadedCar = $this->_em->find(DDC93Car::class, $car->id); $this->assertEquals($car, $reloadedCar); diff --git a/tests/Doctrine/Tests/ORM/Mapping/Symfony/YamlDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/Symfony/YamlDriverTest.php index f9c8a839b04..d74677fc7d7 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/Symfony/YamlDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/Symfony/YamlDriverTest.php @@ -3,12 +3,15 @@ namespace Doctrine\Tests\ORM\Mapping\Symfony; use \Doctrine\ORM\Mapping\Driver\SimplifiedYamlDriver; +use Doctrine\Tests\VerifyDeprecations; /** * @group DDC-1418 */ class YamlDriverTest extends AbstractDriverTest { + use VerifyDeprecations; + protected function getFileExtension() { return '.orm.yml'; @@ -17,6 +20,7 @@ protected function getFileExtension() protected function getDriver(array $paths = []) { $driver = new SimplifiedYamlDriver(array_flip($paths)); + $this->expectDeprecationMessage('YAML mapping driver is deprecated and will be removed in Doctrine 3.0, please migrate to annotation or XML driver.'); return $driver; } diff --git a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php index b6feb405290..d34460d268d 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php @@ -8,10 +8,13 @@ use Doctrine\Tests\Models\DirectoryTree\Directory; use Doctrine\Tests\Models\DirectoryTree\File; use Doctrine\Tests\Models\Generic\SerializationModel; +use Doctrine\Tests\VerifyDeprecations; use Symfony\Component\Yaml\Yaml; class YamlMappingDriverTest extends AbstractMappingDriverTest { + use VerifyDeprecations; + protected function _loadDriver() { if (!class_exists(Yaml::class, true)) { @@ -43,6 +46,7 @@ public function testJoinTablesWithMappedSuperclassForYamlDriver() $classDirectory = new ClassMetadata(Directory::class); $classDirectory = $factory->getMetadataFor(Directory::class); $this->assertEquals(Directory::class, $classDirectory->associationMappings['parentDirectory']['sourceEntity']); + $this->assertHasDeprecationMessages(); } /** @@ -76,6 +80,13 @@ public function testSpacesShouldBeIgnoredWhenUseExplode() $this->assertEquals(255, $nameField['length']); $this->assertEquals(255, $valueField['length']); + $this->assertHasDeprecationMessages(); + } + + public function testDeprecation() : void + { + $this->createClassMetadata(DDC2069Entity::class); + $this->expectDeprecationMessage('YAML mapping driver is deprecated and will be removed in Doctrine 3.0, please migrate to annotation or XML driver.'); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommandTest.php index 3e6a0e90486..f21a9a64d3a 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommandTest.php @@ -5,10 +5,19 @@ use Doctrine\ORM\Tools\Console\Command\ConvertDoctrine1SchemaCommand; use Doctrine\ORM\Tools\EntityGenerator; use Doctrine\Tests\OrmTestCase; +use Doctrine\Tests\VerifyDeprecations; use Symfony\Component\Console\Output\OutputInterface; class ConvertDoctrine1SchemaCommandTest extends OrmTestCase { + use VerifyDeprecations; + + /** @after */ + public function ensureTestGeneratedDeprecationMessages() : void + { + $this->assertHasDeprecationMessages(); + } + public function testExecution() { $entityGenerator = $this->createMock(EntityGenerator::class); diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php index 74fbc38b22b..cd05da25ec6 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php @@ -10,12 +10,14 @@ use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; use Doctrine\Tests\Models\DDC3231\DDC3231EntityRepository; use Doctrine\Tests\OrmFunctionalTestCase; +use Doctrine\Tests\VerifyDeprecations; use Symfony\Component\Console\Application; use Symfony\Component\Console\Helper\HelperSet; use Symfony\Component\Console\Tester\CommandTester; class GenerateRepositoriesCommandTest extends OrmFunctionalTestCase { + use VerifyDeprecations; /** * @var \Symfony\Component\Console\Application */ @@ -89,6 +91,7 @@ public function testGenerateRepositories() self::assertSame(EntityRepository::class, $repo1->getParentClass()->getName()); self::assertSame(EntityRepository::class, $repo2->getParentClass()->getName()); + $this->assertHasDeprecationMessages(); } public function testGenerateRepositoriesCustomDefaultRepository() @@ -112,6 +115,7 @@ public function testGenerateRepositoriesCustomDefaultRepository() self::assertSame(DDC3231EntityRepository::class, $repo1->getParentClass()->getName()); self::assertSame(DDC3231EntityRepository::class, $repo2->getParentClass()->getName()); + $this->assertHasDeprecationMessages(); } /** @@ -168,6 +172,7 @@ public function testNoMetadataClassesToProcess() : void ] ); + self::assertContains('Command orm:generate-repositories is deprecated and will be removed in Doctrine 3.0.', $tester->getDisplay()); self::assertContains('[OK] No Metadata Classes to process.', $tester->getDisplay()); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php b/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php index ca6192faa29..291228687fb 100644 --- a/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php @@ -13,6 +13,7 @@ use Doctrine\Common\EventManager; use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory; use Doctrine\Tests\OrmTestCase; +use Doctrine\Tests\VerifyDeprecations; /** * Test case for converting a Doctrine 1 style schema to Doctrine 2 mapping files @@ -26,6 +27,8 @@ */ class ConvertDoctrine1SchemaTest extends OrmTestCase { + use VerifyDeprecations; + protected function _createEntityManager($metadataDriver) { $driverMock = new DriverMock(); @@ -77,6 +80,7 @@ public function testTest() $this->assertEquals('User', $profileClass->associationMappings['User']['targetEntity']); $this->assertEquals('username', $userClass->table['uniqueConstraints']['username']['columns'][0]); + $this->assertHasDeprecationMessages(); } public function tearDown() diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index 42d62513b70..25518691538 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -12,9 +12,11 @@ use Doctrine\Tests\Models\DDC2372\DDC2372Admin; use Doctrine\Tests\Models\DDC2372\DDC2372User; use Doctrine\Tests\OrmTestCase; +use Doctrine\Tests\VerifyDeprecations; class EntityGeneratorTest extends OrmTestCase { + use VerifyDeprecations; /** * @var EntityGenerator @@ -49,6 +51,12 @@ public function tearDown() rmdir($this->_tmpDir . '/' . $this->_namespace); } + /** @after */ + public function ensureTestGeneratedDeprecationMessages() : void + { + $this->assertHasDeprecationMessages(); + } + /** * @param ClassMetadataInfo[] $embeddedClasses * diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityRepositoryGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityRepositoryGeneratorTest.php index feff13dc066..d020cc6e07c 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityRepositoryGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityRepositoryGeneratorTest.php @@ -10,9 +10,12 @@ use Doctrine\Tests\Models\DDC3231\DDC3231User1; use Doctrine\Tests\Models\DDC3231\DDC3231User2; use Doctrine\Tests\OrmTestCase; +use Doctrine\Tests\VerifyDeprecations; class EntityRepositoryGeneratorTest extends OrmTestCase { + use VerifyDeprecations; + /** * @var EntityGenerator */ @@ -70,6 +73,12 @@ public function tearDown() } } + /** @after */ + public function ensureTestGeneratedDeprecationMessages() : void + { + $this->assertHasDeprecationMessages(); + } + /** * @group DDC-3231 */ diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php index a74af72a17f..84ddd011f6a 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php @@ -19,6 +19,7 @@ use Doctrine\Tests\Mocks\DriverMock; use Doctrine\Tests\Mocks\EntityManagerMock; use Doctrine\Tests\OrmTestCase; +use Doctrine\Tests\VerifyDeprecations; use Symfony\Component\Yaml\Parser; /** @@ -33,6 +34,8 @@ */ abstract class AbstractClassMetadataExporterTest extends OrmTestCase { + use VerifyDeprecations; + protected $_extension; abstract protected function _getType(); @@ -115,6 +118,8 @@ public function testExportDirectoryAndFilesAreCreated() } else { $this->assertTrue(file_exists(__DIR__ . '/export/' . $type . '/Doctrine.Tests.ORM.Tools.Export.ExportedUser'.$this->_extension)); } + + $this->assertHasDeprecationMessages(); } /** diff --git a/tests/Doctrine/Tests/ORM/Tools/SetupTest.php b/tests/Doctrine/Tests/ORM/Tools/SetupTest.php index c7ec7c6d191..3678a4cf4ce 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SetupTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SetupTest.php @@ -11,9 +11,12 @@ use Doctrine\ORM\Tools\Setup; use Doctrine\ORM\Version; use Doctrine\Tests\OrmTestCase; +use Doctrine\Tests\VerifyDeprecations; class SetupTest extends OrmTestCase { + use VerifyDeprecations; + private $originalAutoloaderCount; private $originalIncludePath; @@ -74,6 +77,7 @@ public function testYAMLConfiguration() $this->assertInstanceOf(Configuration::class, $config); $this->assertInstanceOf(YamlDriver::class, $config->getMetadataDriverImpl()); + $this->assertHasDeprecationMessages(); } /** From f9a4258dedd6b4e9885e096dc6f5af73866a693a Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Sun, 17 Dec 2017 05:02:07 +0100 Subject: [PATCH 853/877] Upgrading notes for 2.7 --- UPGRADE.md | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index 18b74ce9379..9a54315bba3 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,103 @@ # Upgrade to 2.7 +## Deprecated code generators and related console commands + +These console commands have been deprecated: + + * `orm:convert-mapping` + * `orm:generate:entities` + * `orm:generate-repositories` + +These classes have been deprecated: + + * `Doctrine\ORM\Tools\EntityGenerator` + * `Doctrine\ORM\Tools\EntityRepositoryGenerator` + +Whole Doctrine\ORM\Tools\Export namespace with all its members have been deprecated as well. + +## Deprecated `Doctrine\ORM\Proxy\Proxy` marker interface + +Proxy objects in Doctrine 3.0 will no longer implement `Doctrine\ORM\Proxy\Proxy` nor +`Doctrine\Common\Persistence\Proxy`: instead, they implement +`ProxyManager\Proxy\GhostObjectInterface`. + +These related classes have been deprecated: + + * `Doctrine\ORM\Proxy\ProxyFactory` + * `Doctrine\ORM\Proxy\Autoloader` - we suggest using the composer autoloader instead + +These methods have been deprecated: + + * `Doctrine\ORM\Configuration#getAutoGenerateProxyClasses()` + * `Doctrine\ORM\Configuration#getProxyDir()` + * `Doctrine\ORM\Configuration#getProxyNamespace()` + +## Deprecated `Doctrine\ORM\Version` + +The `Doctrine\ORM\Version` class is now deprecated and will be removed in Doctrine 3.0: +please refrain from checking the ORM version at runtime or use +[Ocramius/PackageVersions](https://github.com/Ocramius/PackageVersions/). + +## Deprecated `EntityManager#merge()` and `EntityManager#detach()` methods + +Merge and detach semantics were a poor fit for the PHP "share-nothing" architecture. +In addition to that, merging/detaching caused multiple issues with data integrity +in the managed entity graph, which was constantly spawning more edge-case bugs/scenarios. + +The following API methods were therefore deprecated: + +* `EntityManager#merge()` +* `EntityManager#detach()` +* `UnitOfWork#merge()` +* `UnitOfWork#detach()` + +Users are encouraged to migrate `EntityManager#detach()` calls to `EntityManager#clear()`. + +In order to maintain performance on batch processing jobs, it is endorsed to enable +the second level cache (http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/second-level-cache.html) +on entities that are frequently reused across multiple `EntityManager#clear()` calls. + +An alternative to `EntityManager#merge()` will not be provided by ORM 3.0, since the merging +semantics should be part of the business domain rather than the persistence domain of an +application. If your application relies heavily on CRUD-alike interactions and/or `PATCH` +restful operations, you should look at alternatives such as [JMSSerializer](https://github.com/schmittjoh/serializer). + +## Extending `EntityManager` is deprecated + +Final keyword will be added to the `EntityManager::class` in Doctrine 3.0 in order to ensure that EntityManager + is not used as valid extension point. Valid extension point should be EntityManagerInterface. + +## Deprecated `EntityManager#flush($entity)` and `EntityManager#flush($entities)` + +If your code relies on single entity flushing optimisations via +`EntityManager#flush($entity)`, the signature has been changed to +`EntityManager#flush()`. + +Said API was affected by multiple data integrity bugs due to the fact +that change tracking was being restricted upon a subset of the managed +entities. The ORM cannot support committing subsets of the managed +entities while also guaranteeing data integrity, therefore this +utility was removed. + +The `flush()` semantics will remain the same, but the change tracking will be performed +on all entities managed by the unit of work, and not just on the provided +`$entity` or `$entities`, as the parameter is now completely ignored. + +The same applies to `UnitOfWork#commit($entity)`, which will simply be +`UnitOfWork#commit()`. + +If you would still like to perform batching operations over small `UnitOfWork` +instances, it is suggested to follow these paths instead: + + * eagerly use `EntityManager#clear()` in conjunction with a specific second level + cache configuration (see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/second-level-cache.html) + * use an explicit change tracking policy (see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/change-tracking-policies.html) + +## Deprecated `YAML` mapping drivers. + +If your code relies on `YamlDriver` or `SimpleYamlDriver`, you **MUST** change to +annotation or XML drivers instead. + ## Deprecated: `Doctrine\ORM\EntityManagerInterface#copy()` Method `Doctrine\ORM\EntityManagerInterface#copy()` never got its implementation and is deprecated. From 982d1519db80bca3342014546c173df9900f712b Mon Sep 17 00:00:00 2001 From: Robert den Harink Date: Wed, 17 Apr 2019 12:51:24 +0200 Subject: [PATCH 854/877] only replace '_id' at end of columnName --- .../ORM/Mapping/Driver/DatabaseDriver.php | 3 +- .../ORM/Functional/Ticket/GH7684Test.php | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH7684Test.php diff --git a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php index ddaff9d4344..83798e16e21 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php @@ -29,6 +29,7 @@ use Doctrine\DBAL\Types\Type; use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Mapping\MappingException; +use function preg_replace; /** * The DatabaseDriver reverse engineers the mapping metadata from a database. @@ -548,7 +549,7 @@ private function getFieldNameForColumn($tableName, $columnName, $fk = false) // Replace _id if it is a foreignkey column if ($fk) { - $columnName = str_replace('_id', '', $columnName); + $columnName = preg_replace('/_id$/', '', $columnName); } return Inflector::camelize($columnName); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7684Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7684Test.php new file mode 100644 index 00000000000..2d833036619 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7684Test.php @@ -0,0 +1,38 @@ +_em->getConnection()->getDatabasePlatform()->supportsForeignKeyConstraints()) { + $this->markTestSkipped('Platform does not support foreign keys.'); + } + + $table1 = new Table('GH7684_identity_test_table'); + $table1->addColumn('id', 'integer'); + $table1->setPrimaryKey(['id']); + + $table2 = new Table('GH7684_identity_test_assoc_table'); + $table2->addColumn('id', 'integer'); + $table2->addColumn('gh7684_identity_test_id', 'integer'); + $table2->setPrimaryKey(['id']); + $table2->addForeignKeyConstraint('GH7684_identity_test', ['gh7684_identity_test_id'], ['id']); + + $metadatas = $this->convertToClassMetadata([$table1, $table2]); + $metadata = $metadatas['Gh7684IdentityTestAssocTable']; + + $this->assertArrayHasKey('gh7684IdentityTest', $metadata->associationMappings); + } +} From ec930147139a9557e975220256cc7c53ffbc54c5 Mon Sep 17 00:00:00 2001 From: Ferran Vidal Date: Wed, 9 Oct 2019 11:43:24 +0200 Subject: [PATCH 855/877] Delete statements will not be created using `clear`. --- .../Tests/ORM/Functional/Ticket/GH7761Test.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7761Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7761Test.php index 53215cf0546..c6149465e0c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7761Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7761Test.php @@ -31,6 +31,12 @@ protected function setUp() : void $this->_em->clear(); } + protected function tearDown() + { + $this->_em->clear(); + parent::tearDown(); + } + public function testCollectionClearDoesNotClearIfNotPersisted() : void { /** @var GH7761Entity $entity */ @@ -43,8 +49,20 @@ public function testCollectionClearDoesNotClearIfNotPersisted() : void $entity = $this->_em->find(GH7761Entity::class, 1); self::assertCount(1, $entity->children); + } + + public function testCollectionClearDoesClearIfPersisted() : void + { + /** @var GH7761Entity $entity */ + $entity = $this->_em->find(GH7761Entity::class, 1); + $entity->children->clear(); + $this->_em->persist($entity); + $this->_em->flush(); $this->_em->clear(); + + $entity = $this->_em->find(GH7761Entity::class, 1); + self::assertCount(0, $entity->children); } } From 7d7798430603bec154ff99329eb62633e1486620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Ostroluck=C3=BD?= Date: Fri, 15 Nov 2019 21:56:27 +0100 Subject: [PATCH 856/877] Restore ability to clear deferred explicit tracked collections This was regression from #7862 which tried to respect tracking config when clearing collections, but this logic can happen in UOW only, PersistentCollection::clear is triggered too early to know what is (going to be) persisted. Fixes #7862 --- lib/Doctrine/ORM/PersistentCollection.php | 4 +--- lib/Doctrine/ORM/UnitOfWork.php | 14 +++++++++++++- .../Tests/ORM/Functional/Ticket/GH7761Test.php | 9 +++------ .../Tests/ORM/PersistentCollectionTest.php | 12 ------------ 4 files changed, 17 insertions(+), 22 deletions(-) diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index c49e5e5f203..7d52d5392af 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -566,9 +566,7 @@ public function clear() if ($this->association['isOwningSide'] && $this->owner) { $this->changed(); - if (! $this->em->getClassMetadata(get_class($this->owner))->isChangeTrackingDeferredExplicit()) { - $uow->scheduleCollectionDeletion($this); - } + $uow->scheduleCollectionDeletion($this); $this->takeSnapshot(); } diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 773eae23b6b..b27e7405a84 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -46,6 +46,7 @@ use InvalidArgumentException; use Throwable; use UnexpectedValueException; +use function get_class; /** * The UnitOfWork is responsible for tracking changes to objects during an @@ -380,7 +381,18 @@ public function commit($entity = null) try { // Collection deletions (deletions of complete collections) foreach ($this->collectionDeletions as $collectionToDelete) { - $this->getCollectionPersister($collectionToDelete->getMapping())->delete($collectionToDelete); + if (! $collectionToDelete instanceof PersistentCollection) { + $this->getCollectionPersister($collectionToDelete->getMapping())->delete($collectionToDelete); + + continue; + } + + // Deferred explicit tracked collections can be removed only when owning relation was persisted + $owner = $collectionToDelete->getOwner(); + + if ($this->em->getClassMetadata(get_class($owner))->isChangeTrackingDeferredImplicit() || $this->isScheduledForDirtyCheck($owner)) { + $this->getCollectionPersister($collectionToDelete->getMapping())->delete($collectionToDelete); + } } if ($this->entityInsertions) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7761Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7761Test.php index c6149465e0c..fcf3e3be7d2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7761Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7761Test.php @@ -31,12 +31,6 @@ protected function setUp() : void $this->_em->clear(); } - protected function tearDown() - { - $this->_em->clear(); - parent::tearDown(); - } - public function testCollectionClearDoesNotClearIfNotPersisted() : void { /** @var GH7761Entity $entity */ @@ -51,6 +45,9 @@ public function testCollectionClearDoesNotClearIfNotPersisted() : void self::assertCount(1, $entity->children); } + /** + * @group GH-7862 + */ public function testCollectionClearDoesClearIfPersisted() : void { /** @var GH7761Entity $entity */ diff --git a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php index 179d6e9d517..bfee130f0b5 100644 --- a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php @@ -274,16 +274,4 @@ public function testModifyUOWForDeferredImplicitOwnerOnClear() : void $this->collection->clear(); } - - public function testDoNotModifyUOWForDeferredExplicitOwnerOnClear() : void - { - $unitOfWork = $this->createMock(UnitOfWork::class); - $unitOfWork->expects(self::never())->method('scheduleCollectionDeletion'); - $this->_emMock->setUnitOfWork($unitOfWork); - - $classMetaData = $this->_emMock->getClassMetadata(ECommerceCart::class); - $classMetaData->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_EXPLICIT); - - $this->collection->clear(); - } } From 26806d08eb181d5254c8cd9b8ba0e82bcbc9c284 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Fri, 15 Nov 2019 23:42:20 +0100 Subject: [PATCH 857/877] Require more updated doctrine packages --- composer.json | 14 ++++++++------ composer.lock | 16 ++++++++-------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index ee32d79b2f7..c74e9cff646 100644 --- a/composer.json +++ b/composer.json @@ -18,12 +18,14 @@ "require": { "php": "^7.1", "ext-pdo": "*", - "doctrine/annotations": "~1.5", - "doctrine/cache": "~1.6", - "doctrine/collections": "^1.4", - "doctrine/common": "^2.7.1", - "doctrine/dbal": "^2.6", - "doctrine/instantiator": "~1.1", + "doctrine/annotations": "^1.8", + "doctrine/cache": "^1.9.1", + "doctrine/collections": "^1.5", + "doctrine/common": "^2.11", + "doctrine/dbal": "^2.9.3", + "doctrine/event-manager": "^1.1", + "doctrine/instantiator": "^1.3", + "doctrine/persistence": "^1.2", "symfony/console": "^3.0|^4.0|^5.0" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 1641a17b142..cb5af059e5c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "084cd36de51fd4aa52c912b3e9c7c799", + "content-hash": "6ee82c5580988d68204af241576da60f", "packages": [ { "name": "doctrine/annotations", @@ -76,16 +76,16 @@ }, { "name": "doctrine/cache", - "version": "1.9.0", + "version": "1.9.1", "source": { "type": "git", "url": "https://github.com/doctrine/cache.git", - "reference": "c15dcd24b756f9e52ea7c3ae8227354f3628f11a" + "reference": "89a5c76c39c292f7798f964ab3c836c3f8192a55" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/cache/zipball/c15dcd24b756f9e52ea7c3ae8227354f3628f11a", - "reference": "c15dcd24b756f9e52ea7c3ae8227354f3628f11a", + "url": "https://api.github.com/repos/doctrine/cache/zipball/89a5c76c39c292f7798f964ab3c836c3f8192a55", + "reference": "89a5c76c39c292f7798f964ab3c836c3f8192a55", "shasum": "" }, "require": { @@ -155,7 +155,7 @@ "riak", "xcache" ], - "time": "2019-11-11T10:31:52+00:00" + "time": "2019-11-15T14:31:57+00:00" }, { "name": "doctrine/collections", @@ -2673,8 +2673,8 @@ "authors": [ { "name": "Arne Blankerts", - "role": "Developer", - "email": "arne@blankerts.de" + "email": "arne@blankerts.de", + "role": "Developer" } ], "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", From 634719088638902adf0710faf46ce3c33cf020b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20ALFAIATE?= Date: Thu, 10 Oct 2019 17:45:26 +0700 Subject: [PATCH 858/877] Skip limit subquery if not required --- .../ORM/Tools/Pagination/Paginator.php | 2 +- .../ORM/Functional/Ticket/DDC1685Test.php | 1 + .../ORM/Functional/Ticket/GH7829Test.php | 63 +++++++++++++++++++ .../ORM/Tools/Pagination/PaginatorTest.php | 2 + 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH7829Test.php diff --git a/lib/Doctrine/ORM/Tools/Pagination/Paginator.php b/lib/Doctrine/ORM/Tools/Pagination/Paginator.php index 08c924bc598..64cd9e243fa 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/Paginator.php +++ b/lib/Doctrine/ORM/Tools/Pagination/Paginator.php @@ -139,7 +139,7 @@ public function getIterator() $offset = $this->query->getFirstResult(); $length = $this->query->getMaxResults(); - if ($this->fetchJoinCollection) { + if ($this->fetchJoinCollection && $length !== null) { $subQuery = $this->cloneQuery($this->query); if ($this->useOutputWalker($subQuery)) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1685Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1685Test.php index 576b4e28628..b2cbf513abb 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1685Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1685Test.php @@ -29,6 +29,7 @@ protected function setUp() $dql = "SELECT ad FROM Doctrine\Tests\Models\DDC117\DDC117ArticleDetails ad"; $query = $this->_em->createQuery($dql); + $query->setMaxResults(1); $this->paginator = new Paginator($query); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7829Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7829Test.php new file mode 100644 index 00000000000..08f91d2a8ea --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7829Test.php @@ -0,0 +1,63 @@ +useModelSet('cms'); + parent::setUp(); + + $article = new CmsArticle(); + + $article->topic = 'Skip Limit Subquery'; + $article->text = 'Skip Limit Subquery if not required.'; + + $this->_em->persist($article); + $this->_em->flush(); + $this->_em->clear(); + + $this->_em->getConnection()->getConfiguration()->setSQLLogger($this->logger = new DebugStack()); + } + + public function testPaginatorWithLimitSubquery() : void + { + $query = $this->_em->createQuery('SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a'); + $query->setMaxResults(1); + + $paginator = new Paginator($query, true); + $paginator->setUseOutputWalkers(false); + + $paginator->count(); + $paginator->getIterator(); + + $this->assertCount(3, $this->logger->queries); + } + + public function testPaginatorWithLimitSubquerySkipped() : void + { + $query = $this->_em->createQuery('SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a'); + + $paginator = new Paginator($query, true); + $paginator->setUseOutputWalkers(false); + + $paginator->count(); + $paginator->getIterator(); + + $this->assertCount(2, $this->logger->queries); + } +} diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/PaginatorTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/PaginatorTest.php index 4b4fc5202bd..20b2abdda17 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/PaginatorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/PaginatorTest.php @@ -61,6 +61,7 @@ public function testExtraParametersAreStrippedWhenWalkerRemovingOriginalSelectEl WHERE u.id = :paramInWhere' ); $query->setParameters(['paramInWhere' => $paramInWhere, 'paramInSubSelect' => $paramInSubSelect]); + $query->setMaxResults(1); $paginator = (new Paginator($query, true))->setUseOutputWalkers(false); $this->connection->expects($this->exactly(3))->method('executeQuery'); @@ -113,6 +114,7 @@ private function createPaginatorWithExtraParametersWithoutOutputWalkers(array $w $query = new Query($this->em); $query->setDQL('SELECT u FROM Doctrine\\Tests\\Models\\CMS\\CmsUser u'); $query->setParameters(['paramInWhere' => 1]); + $query->setMaxResults(1); return (new Paginator($query, true))->setUseOutputWalkers(false); } From 797bfc53c4a364c45402844713a0122f3c2db417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sat, 16 Nov 2019 01:32:15 +0100 Subject: [PATCH 859/877] Fix deprecation messages version --- UPGRADE.md | 2 +- lib/Doctrine/ORM/Configuration.php | 6 +++--- lib/Doctrine/ORM/EntityManager.php | 4 ++-- lib/Doctrine/ORM/EntityManagerInterface.php | 2 +- lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php | 2 +- lib/Doctrine/ORM/Proxy/Proxy.php | 2 +- lib/Doctrine/ORM/Proxy/ProxyFactory.php | 2 +- .../Tools/Console/Command/ConvertDoctrine1SchemaCommand.php | 2 +- .../ORM/Tools/Console/Command/GenerateEntitiesCommand.php | 2 +- .../Tools/Console/Command/GenerateRepositoriesCommand.php | 2 +- lib/Doctrine/ORM/Tools/EntityGenerator.php | 2 +- lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php | 2 +- lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php | 2 +- lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php | 2 +- lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php | 2 +- lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php | 2 +- lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php | 2 +- lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php | 2 +- lib/Doctrine/ORM/Tools/Export/ExportException.php | 2 +- lib/Doctrine/ORM/UnitOfWork.php | 4 ++-- lib/Doctrine/ORM/Version.php | 2 +- 21 files changed, 25 insertions(+), 25 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 9a54315bba3..eb068cd39e9 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -36,7 +36,7 @@ These methods have been deprecated: The `Doctrine\ORM\Version` class is now deprecated and will be removed in Doctrine 3.0: please refrain from checking the ORM version at runtime or use -[Ocramius/PackageVersions](https://github.com/Ocramius/PackageVersions/). +[ocramius/package-versions](https://github.com/Ocramius/PackageVersions/). ## Deprecated `EntityManager#merge()` and `EntityManager#detach()` methods diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index f4ba5df066b..c036d67fa5f 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -71,7 +71,7 @@ public function setProxyDir($dir) * * @return string|null * - * @deprecated 3.0 We're switch to `ocramius/proxy-manager` and this method isn't applicable any longer + * @deprecated 2.7 We're switch to `ocramius/proxy-manager` and this method isn't applicable any longer * @see https://github.com/Ocramius/ProxyManager */ public function getProxyDir() @@ -86,7 +86,7 @@ public function getProxyDir() * * @return int Possible values are constants of Doctrine\Common\Proxy\AbstractProxyFactory. * - * @deprecated 3.0 We're switch to `ocramius/proxy-manager` and this method isn't applicable any longer + * @deprecated 2.7 We're switch to `ocramius/proxy-manager` and this method isn't applicable any longer * @see https://github.com/Ocramius/ProxyManager */ public function getAutoGenerateProxyClasses() @@ -114,7 +114,7 @@ public function setAutoGenerateProxyClasses($autoGenerate) * * @return string|null * - * @deprecated 3.0 We're switch to `ocramius/proxy-manager` and this method isn't applicable any longer + * @deprecated 2.7 We're switch to `ocramius/proxy-manager` and this method isn't applicable any longer * @see https://github.com/Ocramius/ProxyManager */ public function getProxyNamespace() diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index f003c089811..a90dd9e6a92 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -658,7 +658,7 @@ public function refresh($entity) * * @throws ORMInvalidArgumentException * - * @deprecated 3.0 This method is being removed from the ORM and won't have any replacement + * @deprecated 2.7 This method is being removed from the ORM and won't have any replacement */ public function detach($entity) { @@ -683,7 +683,7 @@ public function detach($entity) * @throws ORMInvalidArgumentException * @throws ORMException * - * @deprecated 3.0 This method is being removed from the ORM and won't have any replacement + * @deprecated 2.7 This method is being removed from the ORM and won't have any replacement */ public function merge($entity) { diff --git a/lib/Doctrine/ORM/EntityManagerInterface.php b/lib/Doctrine/ORM/EntityManagerInterface.php index 16b7068b93d..c96aa6720fe 100644 --- a/lib/Doctrine/ORM/EntityManagerInterface.php +++ b/lib/Doctrine/ORM/EntityManagerInterface.php @@ -190,7 +190,7 @@ public function close(); /** * Creates a copy of the given entity. Can create a shallow or a deep copy. * - * @deprecated 3.0 This method is being removed from the ORM and won't have any replacement + * @deprecated 2.7 This method is being removed from the ORM and won't have any replacement * * @param object $entity The entity to copy. * @param boolean $deep FALSE for a shallow copy, TRUE for a deep copy. diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index aa99f4bfeec..723c7b15c15 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -36,7 +36,7 @@ * @author Jonathan H. Wage * @author Roman Borschel * - * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement + * @deprecated 2.7 This class is being removed from the ORM and won't have any replacement */ class YamlDriver extends FileDriver { diff --git a/lib/Doctrine/ORM/Proxy/Proxy.php b/lib/Doctrine/ORM/Proxy/Proxy.php index 72463d121e3..75a61a75604 100644 --- a/lib/Doctrine/ORM/Proxy/Proxy.php +++ b/lib/Doctrine/ORM/Proxy/Proxy.php @@ -27,7 +27,7 @@ * @author Roman Borschel * @since 2.0 * - * @deprecated 3.0 This interface is being removed from the ORM and won't have any replacement, proxies will no longer implement it. + * @deprecated 2.7 This interface is being removed from the ORM and won't have any replacement, proxies will no longer implement it. */ interface Proxy extends BaseProxy { diff --git a/lib/Doctrine/ORM/Proxy/ProxyFactory.php b/lib/Doctrine/ORM/Proxy/ProxyFactory.php index 7648a14a5f8..31fac18a208 100644 --- a/lib/Doctrine/ORM/Proxy/ProxyFactory.php +++ b/lib/Doctrine/ORM/Proxy/ProxyFactory.php @@ -38,7 +38,7 @@ * @author Marco Pivetta * @since 2.0 * - * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement + * @deprecated 2.7 This class is being removed from the ORM and won't have any replacement */ class ProxyFactory extends AbstractProxyFactory { diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php index 1fac2497be9..4f316aca432 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php @@ -39,7 +39,7 @@ * @author Jonathan Wage * @author Roman Borschel * - * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement + * @deprecated 2.7 This class is being removed from the ORM and won't have any replacement */ class ConvertDoctrine1SchemaCommand extends Command { diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php index 3aff45b7c73..0d3a8daadcd 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php @@ -39,7 +39,7 @@ * @author Jonathan Wage * @author Roman Borschel * - * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement + * @deprecated 2.7 This class is being removed from the ORM and won't have any replacement */ class GenerateEntitiesCommand extends Command { diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php index c09f10fdf25..82b7da6b46f 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php @@ -38,7 +38,7 @@ * @author Jonathan Wage * @author Roman Borschel * - * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement + * @deprecated 2.7 This class is being removed from the ORM and won't have any replacement */ class GenerateRepositoriesCommand extends Command { diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 5143f637a87..0accfaeaecf 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -47,7 +47,7 @@ * @author Jonathan Wage * @author Roman Borschel * - * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement + * @deprecated 2.7 This class is being removed from the ORM and won't have any replacement */ class EntityGenerator { diff --git a/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php b/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php index 7dffe97eaa5..07c7aaca0c9 100644 --- a/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php @@ -33,7 +33,7 @@ * @author Jonathan Wage * @author Roman Borschel * - * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement + * @deprecated 2.7 This class is being removed from the ORM and won't have any replacement */ class EntityRepositoryGenerator { diff --git a/lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php b/lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php index fcb11cc2d9b..bf0bbada769 100644 --- a/lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php @@ -29,7 +29,7 @@ * @since 2.0 * @author Jonathan Wage * - * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement + * @deprecated 2.7 This class is being removed from the ORM and won't have any replacement */ class ClassMetadataExporter { diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php index 96cb88b36cb..02cef5238bd 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php @@ -31,7 +31,7 @@ * @since 2.0 * @author Jonathan Wage * - * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement + * @deprecated 2.7 This class is being removed from the ORM and won't have any replacement */ abstract class AbstractExporter { diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php index 2e7e4cbfd14..29cb8df3633 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php @@ -29,7 +29,7 @@ * @since 2.0 * @author Jonathan Wage * - * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement + * @deprecated 2.7 This class is being removed from the ORM and won't have any replacement */ class AnnotationExporter extends AbstractExporter { diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php index 3e92dfe5773..c0cd1767bca 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php @@ -28,7 +28,7 @@ * @since 2.0 * @author Jonathan Wage * - * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement + * @deprecated 2.7 This class is being removed from the ORM and won't have any replacement */ class PhpExporter extends AbstractExporter { diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php index 7ea41f0da49..65036493799 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php @@ -29,7 +29,7 @@ * @since 2.0 * @author Jonathan Wage * - * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement + * @deprecated 2.7 This class is being removed from the ORM and won't have any replacement */ class XmlExporter extends AbstractExporter { diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php index 7043e0a3716..1fb960b3333 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php @@ -29,7 +29,7 @@ * @since 2.0 * @author Jonathan Wage * - * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement + * @deprecated 2.7 This class is being removed from the ORM and won't have any replacement */ class YamlExporter extends AbstractExporter { diff --git a/lib/Doctrine/ORM/Tools/Export/ExportException.php b/lib/Doctrine/ORM/Tools/Export/ExportException.php index c9689d0a519..725ea2137c8 100644 --- a/lib/Doctrine/ORM/Tools/Export/ExportException.php +++ b/lib/Doctrine/ORM/Tools/Export/ExportException.php @@ -22,7 +22,7 @@ use Doctrine\ORM\ORMException; /** - * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement + * @deprecated 2.7 This class is being removed from the ORM and won't have any replacement */ class ExportException extends ORMException { diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 7660dc1144a..f7b32b3809f 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1878,7 +1878,7 @@ private function doRemove($entity, array &$visited) * @throws OptimisticLockException If the entity uses optimistic locking through a version * attribute and the version check against the managed copy fails. * - * @deprecated 3.0 This method is being removed from the ORM and won't have any replacement + * @deprecated 2.7 This method is being removed from the ORM and won't have any replacement */ public function merge($entity) { @@ -2069,7 +2069,7 @@ private function updateAssociationWithMergedEntity($entity, array $association, * * @return void * - * @deprecated 3.0 This method is being removed from the ORM and won't have any replacement + * @deprecated 2.7 This method is being removed from the ORM and won't have any replacement */ public function detach($entity) { diff --git a/lib/Doctrine/ORM/Version.php b/lib/Doctrine/ORM/Version.php index b0f070a4e24..9a91b42ac24 100644 --- a/lib/Doctrine/ORM/Version.php +++ b/lib/Doctrine/ORM/Version.php @@ -30,7 +30,7 @@ * @author Jonathan Wage * @author Roman Borschel * - * @deprecated 3.0 This class is being removed from the ORM and won't have any replacement + * @deprecated 2.7 This class is being removed from the ORM and won't have any replacement */ class Version { From 57496e32fdea4b8ca7ac951839a6cb0d7dcdb8ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sat, 16 Nov 2019 01:48:37 +0100 Subject: [PATCH 860/877] Add minor BC-break notes on output walkers in paginator As explained in https://github.com/doctrine/orm/pull/7863#issuecomment-554578313. --- UPGRADE.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index eb068cd39e9..85f55d22504 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,10 @@ # Upgrade to 2.7 +## Minor BC BREAK: paginator output walkers aren't be called anymore on sub-queries for queries without max results + +To optimize DB interaction, `Doctrine\ORM\Tools\Pagination\Paginator` no longer fetches identifiers to be able to +perform the pagination with join collections when max results isn't set in the query. + ## Deprecated code generators and related console commands These console commands have been deprecated: From 7bcbad076dafd127cd4eb535234add0318c593f6 Mon Sep 17 00:00:00 2001 From: Illia Somov Date: Mon, 7 May 2018 01:12:24 +0300 Subject: [PATCH 861/877] Split and deprecate AbstractQuery#useResultCache() --- UPGRADE.md | 10 +++ lib/Doctrine/ORM/AbstractQuery.php | 42 +++++++-- .../Tests/ORM/Functional/ResultCacheTest.php | 85 +++++++++++++++++-- tests/Doctrine/Tests/ORM/Query/QueryTest.php | 10 +-- 4 files changed, 128 insertions(+), 19 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 85f55d22504..d6970a42aff 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,10 +1,20 @@ # Upgrade to 2.7 +## Added `Doctrine\ORM\AbstractQuery#enableResultCache()` and `Doctrine\ORM\AbstractQuery#disableResultCache()` methods + +Method `Doctrine\ORM\AbstractQuery#useResultCache()` which could be used for both enabling and disabling the cache +(depending on passed flag) was split into two. + ## Minor BC BREAK: paginator output walkers aren't be called anymore on sub-queries for queries without max results To optimize DB interaction, `Doctrine\ORM\Tools\Pagination\Paginator` no longer fetches identifiers to be able to perform the pagination with join collections when max results isn't set in the query. +## Deprecated: `Doctrine\ORM\AbstractQuery#useResultCache()` + +Method `Doctrine\ORM\AbstractQuery#useResultCache()` is deprecated because it is split into `enableResultCache()` +and `disableResultCache()`. It will be removed in 3.0. + ## Deprecated code generators and related console commands These console commands have been deprecated: diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 3ba49b08866..22403668675 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -583,21 +583,45 @@ public function getResultCacheDriver() * Set whether or not to cache the results of this query and if so, for * how long and which ID to use for the cache entry. * - * @param boolean $bool - * @param integer $lifetime - * @param string $resultCacheId + * @deprecated 2.7 Use {@see enableResultCache} and {@see disableResultCache} instead. + * + * @param bool $useCache + * @param int $lifetime + * @param string $resultCacheId * * @return static This query instance. */ - public function useResultCache($bool, $lifetime = null, $resultCacheId = null) + public function useResultCache($useCache, $lifetime = null, $resultCacheId = null) { - if ($bool) { - $this->setResultCacheLifetime($lifetime); - $this->setResultCacheId($resultCacheId); + return $useCache + ? $this->enableResultCache($lifetime, $resultCacheId) + : $this->disableResultCache(); + } - return $this; - } + /** + * Enables caching of the results of this query, for given or default amount of seconds + * and optionally specifies which ID to use for the cache entry. + * + * @param int|null $lifetime How long the cache entry is valid, in seconds. + * @param string|null $resultCacheId ID to use for the cache entry. + * + * @return static This query instance. + */ + public function enableResultCache(?int $lifetime = null, ?string $resultCacheId = null) : self + { + $this->setResultCacheLifetime($lifetime); + $this->setResultCacheId($resultCacheId); + return $this; + } + + /** + * Disables caching of the results of this query. + * + * @return static This query instance. + */ + public function disableResultCache() : self + { $this->_queryCacheProfile = null; return $this; diff --git a/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php index bfadf2c2543..05c89b60251 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php @@ -89,7 +89,7 @@ public function testSetResultCacheId() $this->assertTrue($cache->contains('testing_result_cache_id')); } - public function testUseResultCache() + public function testUseResultCacheTrue() { $cache = new ArrayCache(); $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); @@ -104,6 +104,22 @@ public function testUseResultCache() $this->_em->getConfiguration()->setResultCacheImpl(new ArrayCache()); } + public function testUseResultCacheFalse() + { + $cache = new ArrayCache(); + $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); + + $query->setResultCacheDriver($cache); + $query->setResultCacheId('testing_result_cache_id'); + $query->useResultCache(false); + $users = $query->getResult(); + + $this->assertFalse($cache->contains('testing_result_cache_id')); + + $this->_em->getConfiguration()->setResultCacheImpl(new ArrayCache()); + } + + /** * @group DDC-1026 */ @@ -133,6 +149,65 @@ public function testUseResultCacheParams() $this->assertEquals($sqlCount + 2, count($this->_sqlLoggerStack->queries), "The next two sql should have been cached, but were not."); } + public function testEnableResultCache() + { + $cache = new ArrayCache(); + $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); + + $query->enableResultCache(); + $query->setResultCacheDriver($cache); + $query->setResultCacheId('testing_result_cache_id'); + $users = $query->getResult(); + + $this->assertTrue($cache->contains('testing_result_cache_id')); + + $this->_em->getConfiguration()->setResultCacheImpl(new ArrayCache()); + } + + /** + * @group DDC-1026 + */ + public function testEnableResultCacheParams() + { + $cache = new ArrayCache(); + $sqlCount = count($this->_sqlLoggerStack->queries); + $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux WHERE ux.id = ?1'); + + $query->setParameter(1, 1); + $query->setResultCacheDriver($cache); + $query->enableResultCache(); + $query->getResult(); + + $query->setParameter(1, 2); + $query->getResult(); + + $this->assertCount($sqlCount + 2, $this->_sqlLoggerStack->queries, "Two non-cached queries."); + + $query->setParameter(1, 1); + $query->enableResultCache(); + $query->getResult(); + + $query->setParameter(1, 2); + $query->getResult(); + + $this->assertCount($sqlCount + 2, $this->_sqlLoggerStack->queries, "The next two sql should have been cached, but were not."); + } + + public function testDisableResultCache() + { + $cache = new ArrayCache(); + $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); + + $query->setResultCacheDriver($cache); + $query->setResultCacheId('testing_result_cache_id'); + $query->disableResultCache(); + $users = $query->getResult(); + + $this->assertFalse($cache->contains('testing_result_cache_id')); + + $this->_em->getConfiguration()->setResultCacheImpl(new ArrayCache()); + } + public function testNativeQueryResultCaching() { $cache = new ArrayCache(); @@ -143,7 +218,7 @@ public function testNativeQueryResultCaching() $query = $this->_em->createNativeQuery('select u.id FROM cms_users u WHERE u.id = ?', $rsm); $query->setParameter(1, 10); - $query->setResultCacheDriver($cache)->useResultCache(true); + $query->setResultCacheDriver($cache)->enableResultCache(); $this->assertEquals(0, $this->getCacheSize($cache)); @@ -229,7 +304,7 @@ public function testResultCacheWithObjectParameter() $cache = new ArrayCache(); - $query->setResultCacheDriver($cache)->useResultCache(true); + $query->setResultCacheDriver($cache)->enableResultCache(); $articles = $query->getResult(); @@ -241,7 +316,7 @@ public function testResultCacheWithObjectParameter() $query2 = $this->_em->createQuery('select a from Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.user = ?1'); $query2->setParameter(1, $user1); - $query2->setResultCacheDriver($cache)->useResultCache(true); + $query2->setResultCacheDriver($cache)->enableResultCache(); $articles = $query2->getResult(); @@ -251,7 +326,7 @@ public function testResultCacheWithObjectParameter() $query3 = $this->_em->createQuery('select a from Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.user = ?1'); $query3->setParameter(1, $user2); - $query3->setResultCacheDriver($cache)->useResultCache(true); + $query3->setResultCacheDriver($cache)->enableResultCache(); $articles = $query3->getResult(); diff --git a/tests/Doctrine/Tests/ORM/Query/QueryTest.php b/tests/Doctrine/Tests/ORM/Query/QueryTest.php index 0045647a09a..71422e641ad 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryTest.php @@ -128,7 +128,7 @@ public function testQueryDefaultResultCache() { $this->_em->getConfiguration()->setResultCacheImpl(new ArrayCache()); $q = $this->_em->createQuery("select a from Doctrine\Tests\Models\CMS\CmsArticle a"); - $q->useResultCache(true); + $q->enableResultCache(); $this->assertSame($this->_em->getConfiguration()->getResultCacheImpl(), $q->getQueryCacheProfile()->getResultCacheDriver()); } @@ -245,7 +245,7 @@ public function testResultCacheCaching() $driverConnectionMock->setStatementMock($stmt); $res = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u") ->useQueryCache(true) - ->useResultCache(true, 60) + ->enableResultCache(60) //let it cache ->getResult(); @@ -255,7 +255,7 @@ public function testResultCacheCaching() $res = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u") ->useQueryCache(true) - ->useResultCache(false) + ->disableResultCache() ->getResult(); $this->assertCount(0, $res); } @@ -278,7 +278,7 @@ public function testResultCacheEviction() $this->_em->getConfiguration()->setResultCacheImpl(new ArrayCache()); $query = $this->_em->createQuery("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u") - ->useResultCache(true); + ->enableResultCache(); /** @var DriverConnectionMock $driverConnectionMock */ $driverConnectionMock = $this->_em->getConnection() @@ -397,7 +397,7 @@ public function testResultCacheProfileCanBeRemovedViaSetter() : void $this->_em->getConfiguration()->setResultCacheImpl(new ArrayCache()); $query = $this->_em->createQuery('SELECT u FROM ' . CmsUser::class . ' u'); - $query->useResultCache(true); + $query->enableResultCache(); $query->setResultCacheProfile(); self::assertAttributeSame(null, '_queryCacheProfile', $query); From e8f265d4806f2f05237a944f2f44bb7a9f6d0cc4 Mon Sep 17 00:00:00 2001 From: someniatko Date: Sat, 25 May 2019 20:15:48 +0300 Subject: [PATCH 862/877] Make ResultCacheTest tests slightly more logical --- .../Tests/ORM/Functional/ResultCacheTest.php | 53 ++++++++++++------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php index 05c89b60251..cffe07fe7d2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php @@ -8,6 +8,7 @@ use Doctrine\Tests\Models\CMS\CmsArticle; use Doctrine\Common\Cache\ArrayCache; use Doctrine\Tests\OrmFunctionalTestCase; +use function count; /** * ResultCacheTest @@ -112,7 +113,7 @@ public function testUseResultCacheFalse() $query->setResultCacheDriver($cache); $query->setResultCacheId('testing_result_cache_id'); $query->useResultCache(false); - $users = $query->getResult(); + $query->getResult(); $this->assertFalse($cache->contains('testing_result_cache_id')); @@ -129,27 +130,35 @@ public function testUseResultCacheParams() $sqlCount = count($this->_sqlLoggerStack->queries); $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux WHERE ux.id = ?1'); - $query->setParameter(1, 1); $query->setResultCacheDriver($cache); $query->useResultCache(true); - $query->getResult(); + // these queries should result in cache miss: + $query->setParameter(1, 1); + $query->getResult(); $query->setParameter(1, 2); $query->getResult(); - $this->assertEquals($sqlCount + 2, count($this->_sqlLoggerStack->queries), "Two non-cached queries."); + $this->assertCount( + $sqlCount + 2, + $this->_sqlLoggerStack->queries, + 'Two non-cached queries.' + ); + // these two queries should actually be cached, as they repeat previous ones: $query->setParameter(1, 1); - $query->useResultCache(true); $query->getResult(); - $query->setParameter(1, 2); $query->getResult(); - $this->assertEquals($sqlCount + 2, count($this->_sqlLoggerStack->queries), "The next two sql should have been cached, but were not."); + $this->assertCount( + $sqlCount + 2, + $this->_sqlLoggerStack->queries, + 'The next two sql queries should have been cached, but were not.' + ); } - public function testEnableResultCache() + public function testEnableResultCache() : void { $cache = new ArrayCache(); $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); @@ -157,7 +166,7 @@ public function testEnableResultCache() $query->enableResultCache(); $query->setResultCacheDriver($cache); $query->setResultCacheId('testing_result_cache_id'); - $users = $query->getResult(); + $query->getResult(); $this->assertTrue($cache->contains('testing_result_cache_id')); @@ -167,33 +176,41 @@ public function testEnableResultCache() /** * @group DDC-1026 */ - public function testEnableResultCacheParams() + public function testEnableResultCacheParams() : void { $cache = new ArrayCache(); $sqlCount = count($this->_sqlLoggerStack->queries); $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux WHERE ux.id = ?1'); - $query->setParameter(1, 1); $query->setResultCacheDriver($cache); $query->enableResultCache(); - $query->getResult(); + // these queries should result in cache miss: + $query->setParameter(1, 1); + $query->getResult(); $query->setParameter(1, 2); $query->getResult(); - $this->assertCount($sqlCount + 2, $this->_sqlLoggerStack->queries, "Two non-cached queries."); + $this->assertCount( + $sqlCount + 2, + $this->_sqlLoggerStack->queries, + 'Two non-cached queries.' + ); + // these two queries should actually be cached, as they repeat previous ones: $query->setParameter(1, 1); - $query->enableResultCache(); $query->getResult(); - $query->setParameter(1, 2); $query->getResult(); - $this->assertCount($sqlCount + 2, $this->_sqlLoggerStack->queries, "The next two sql should have been cached, but were not."); + $this->assertCount( + $sqlCount + 2, + $this->_sqlLoggerStack->queries, + 'The next two sql queries should have been cached, but were not.' + ); } - public function testDisableResultCache() + public function testDisableResultCache() : void { $cache = new ArrayCache(); $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); @@ -201,7 +218,7 @@ public function testDisableResultCache() $query->setResultCacheDriver($cache); $query->setResultCacheId('testing_result_cache_id'); $query->disableResultCache(); - $users = $query->getResult(); + $query->getResult(); $this->assertFalse($cache->contains('testing_result_cache_id')); From 0c36f879353fe92f5b6e697e578a83ec4a465cdf Mon Sep 17 00:00:00 2001 From: rtek Date: Wed, 15 May 2019 19:07:11 -0400 Subject: [PATCH 863/877] Prettify arrays in orm:mapping:describe command This will prevent excessive column width and wrapping in the output which uses Symfony\Component\Console\Style\SymfonyStyle::table(). --- .../ORM/Tools/Console/Command/MappingDescribeCommand.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php index 355246731f4..0e1f505f034 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php @@ -26,6 +26,10 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +use const JSON_PRETTY_PRINT; +use const JSON_UNESCAPED_SLASHES; +use const JSON_UNESCAPED_UNICODE; +use function json_encode; /** * Show information about mapped entities. @@ -213,7 +217,7 @@ private function formatValue($value) } if (is_array($value)) { - return json_encode($value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); + return json_encode($value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); } if (is_object($value)) { From 33b8d020a7b8df1e5662510b31deadd8d49c58be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 16 Nov 2019 10:58:58 +0100 Subject: [PATCH 864/877] Synchronize lock file and json manifest --- composer.lock | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/composer.lock b/composer.lock index cb5af059e5c..fc220d23562 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6ee82c5580988d68204af241576da60f", + "content-hash": "4e24e01f599825550170acce0dda0b49", "packages": [ { "name": "doctrine/annotations", @@ -2673,8 +2673,8 @@ "authors": [ { "name": "Arne Blankerts", - "email": "arne@blankerts.de", - "role": "Developer" + "role": "Developer", + "email": "arne@blankerts.de" } ], "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", @@ -2740,8 +2740,5 @@ "php": "^7.1", "ext-pdo": "*" }, - "platform-dev": [], - "platform-overrides": { - "php": "7.1" - } + "platform-dev": [] } From c79d2e0dc2d304679ea5b31a5989256b8e5684cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 16 Nov 2019 10:46:42 +0100 Subject: [PATCH 865/877] Make sure composer files are valid The composer.lock is put under version control and it often happens to be out of sync with the composer.json, which could lead to hard-to-understand issues. Using the --strict option here because we might as well aim for a perfectly valid composer.json --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bd6037e90ce..9a40fe7d22f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ before_install: - mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{,.disabled} || echo "xdebug not available" - composer self-update -install: travis_retry composer update --prefer-dist +install: travis_retry composer validate --strict && composer update --prefer-dist script: - if [[ "$DB" == "mysql" || "$DB" == "mariadb" ]]; then mysql -e "CREATE SCHEMA doctrine_tests; GRANT ALL PRIVILEGES ON doctrine_tests.* to travis@'%'"; fi From 3843eee5cbe64ec5e46a9ed02e3175f912e27483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Ostroluck=C3=BD?= Date: Sat, 16 Nov 2019 01:57:09 +0100 Subject: [PATCH 866/877] [Paginator] Add test case for regression with custom id Co-authored-by: Alexei Korolev --- .../Tests/ORM/Functional/PaginationTest.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php b/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php index 58a88dbd764..9f200cb8e9d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php @@ -2,19 +2,24 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\ORM\Query; use Doctrine\ORM\Tools\Pagination\Paginator; +use Doctrine\Tests\DbalTypes\CustomIdObject; +use Doctrine\Tests\DbalTypes\CustomIdObjectType; use Doctrine\Tests\Models\CMS\CmsArticle; use Doctrine\Tests\Models\CMS\CmsEmail; use Doctrine\Tests\Models\CMS\CmsGroup; use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\Company\CompanyManager; +use Doctrine\Tests\Models\CustomType\CustomIdObjectTypeParent; use Doctrine\Tests\Models\Pagination\Company; use Doctrine\Tests\Models\Pagination\Department; use Doctrine\Tests\Models\Pagination\Logo; use Doctrine\Tests\Models\Pagination\User1; use Doctrine\Tests\OrmFunctionalTestCase; use ReflectionMethod; +use function iterator_to_array; /** * @group DDC-1613 @@ -26,6 +31,14 @@ protected function setUp() $this->useModelSet('cms'); $this->useModelSet('pagination'); $this->useModelSet('company'); + $this->useModelSet('custom_id_object_type'); + + if (DBALType::hasType(CustomIdObjectType::NAME)) { + DBALType::overrideType(CustomIdObjectType::NAME, CustomIdObjectType::class); + } else { + DBALType::addType(CustomIdObjectType::NAME, CustomIdObjectType::class); + } + parent::setUp(); $this->populate(); } @@ -641,6 +654,27 @@ public function testQueryWalkerIsKept() $this->assertEquals(1, $paginator->count()); } + /** + * @group GH-7890 + */ + public function testCustomIdTypeWithoutOutputWalker() + { + $this->_em->persist(new CustomIdObjectTypeParent(new CustomIdObject('foo'))); + $this->_em->flush(); + + $dql = 'SELECT p FROM Doctrine\Tests\Models\CustomType\CustomIdObjectTypeParent p'; + $query = $this->_em->createQuery($dql); + + $paginator = new Paginator($query, true); + $paginator->setUseOutputWalkers(false); + + $matchedItems = iterator_to_array($paginator->getIterator()); + + self::assertCount(1, $matchedItems); + self::assertInstanceOf(CustomIdObjectTypeParent::class, $matchedItems[0]); + self::assertSame('foo', (string) $matchedItems[0]->id); + } + public function testCountQueryStripsParametersInSelect() { $query = $this->_em->createQuery( From 00ef1eba9020b00e64b2adcdd686bad392d7fc2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 17 Nov 2019 00:48:12 +0100 Subject: [PATCH 867/877] Add paginator query hint to force type conversion We're keeping a BC layer in the hydrator, which prevents type conversion in scalar results. This makes bypasses such layer in order to always convert the identifier types when limiting the result set during a pagination. The main goal here is to keep the conversion DB->PHP inside of the hydrator components. --- .../Internal/Hydration/AbstractHydrator.php | 19 ++++++++++++------- .../Tools/Pagination/LimitSubqueryWalker.php | 9 +++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index 5fe4fa1e53d..8a9c0f4d7e4 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -23,6 +23,7 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Events; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker; use PDO; use function array_map; use function in_array; @@ -351,13 +352,11 @@ protected function gatherScalarRowData(&$data) // WARNING: BC break! We know this is the desired behavior to type convert values, but this // erroneous behavior exists since 2.0 and we're forced to keep compatibility. - if ( ! isset($cacheKeyInfo['isScalar'])) { - $dqlAlias = $cacheKeyInfo['dqlAlias']; - $type = $cacheKeyInfo['type']; - $fieldName = $dqlAlias . '_' . $fieldName; - $value = $type - ? $type->convertToPHPValue($value, $this->_platform) - : $value; + if (! isset($cacheKeyInfo['isScalar'])) { + $type = $cacheKeyInfo['type']; + $value = $type ? $type->convertToPHPValue($value, $this->_platform) : $value; + + $fieldName = $cacheKeyInfo['dqlAlias'] . '_' . $fieldName; } $rowData[$fieldName] = $value; @@ -422,6 +421,12 @@ protected function hydrateColumnInfo($key) 'class' => new \ReflectionClass($mapping['className']), ]; + case isset($this->_rsm->scalarMappings[$key], $this->_hints[LimitSubqueryWalker::FORCE_DBAL_TYPE_CONVERSION]): + return $this->_cache[$key] = [ + 'fieldName' => $this->_rsm->scalarMappings[$key], + 'type' => Type::getType($this->_rsm->typeMappings[$key]), + 'dqlAlias' => '', + ]; case (isset($this->_rsm->scalarMappings[$key])): return $this->_cache[$key] = [ 'isScalar' => true, diff --git a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php index f1f06e9e129..5614138a86c 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php @@ -39,10 +39,9 @@ */ class LimitSubqueryWalker extends TreeWalkerAdapter { - /** - * ID type hint. - */ - const IDENTIFIER_TYPE = 'doctrine_paginator.id.type'; + public const IDENTIFIER_TYPE = 'doctrine_paginator.id.type'; + + public const FORCE_DBAL_TYPE_CONVERSION = 'doctrine_paginator.scalar_result.force_dbal_type_conversion'; /** * Counter for generating unique order column aliases. @@ -82,6 +81,8 @@ public function walkSelectStatement(SelectStatement $AST) Type::getType($rootClass->fieldMappings[$identifier]['type']) ); + $this->_getQuery()->setHint(self::FORCE_DBAL_TYPE_CONVERSION, true); + $pathExpression = new PathExpression( PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $rootAlias, From 16751d210fb806cc6f1b868a2b9dde6fab6866ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Mon, 18 Nov 2019 12:06:51 +0100 Subject: [PATCH 868/877] Bump up version --- lib/Doctrine/ORM/Version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Version.php b/lib/Doctrine/ORM/Version.php index 53297999976..658b61ff5cb 100644 --- a/lib/Doctrine/ORM/Version.php +++ b/lib/Doctrine/ORM/Version.php @@ -35,7 +35,7 @@ class Version /** * Current Doctrine Version */ - const VERSION = '2.6.5-DEV'; + const VERSION = '2.6.5'; /** * Compares a Doctrine version with the current one. From 52f2b37921d0f5ea0b37b63c094d8778b0133fc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Mon, 18 Nov 2019 12:17:41 +0100 Subject: [PATCH 869/877] Bump up version --- lib/Doctrine/ORM/Version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Version.php b/lib/Doctrine/ORM/Version.php index 658b61ff5cb..dcae22958e9 100644 --- a/lib/Doctrine/ORM/Version.php +++ b/lib/Doctrine/ORM/Version.php @@ -35,7 +35,7 @@ class Version /** * Current Doctrine Version */ - const VERSION = '2.6.5'; + const VERSION = '2.6.6-DEV'; /** * Compares a Doctrine version with the current one. From 3d17290eb577ddeb94bd03a96de3159e5355c85f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Mon, 18 Nov 2019 21:45:31 +0100 Subject: [PATCH 870/877] Fix BC-break on underscore naming strategy We broke our BC promises on the last patch release by changing how the underscore naming strategy parses values with numbers. This commit makes it possible to configure whether or not to make the underscore naming strategy aware of numbers, keeping the old configuration as default value. --- .../ORM/Mapping/UnderscoreNamingStrategy.php | 22 ++--- .../Tests/ORM/Mapping/NamingStrategyTest.php | 81 +++++++++++++++++-- 2 files changed, 89 insertions(+), 14 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php b/lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php index 142f1bbb14e..1c219caa2cc 100644 --- a/lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php +++ b/lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php @@ -40,22 +40,26 @@ */ class UnderscoreNamingStrategy implements NamingStrategy { - private const DEFAULT_PATTERN = '/(?<=[a-z])([A-Z])/'; - private const PATTERN_FOR_PROPERTIES = '/(?<=[a-z0-9])([A-Z])/'; + private const DEFAULT_PATTERN = '/(?<=[a-z])([A-Z])/'; + private const NUMBER_AWARE_PATTERN = '/(?<=[a-z0-9])([A-Z])/'; /** * @var integer */ private $case; + /** @var string */ + private $pattern; + /** * Underscore naming strategy construct. * - * @param integer $case CASE_LOWER | CASE_UPPER + * @param int $case CASE_LOWER | CASE_UPPER */ - public function __construct($case = CASE_LOWER) + public function __construct($case = CASE_LOWER, bool $numberAware = false) { - $this->case = $case; + $this->case = $case; + $this->pattern = $numberAware ? self::NUMBER_AWARE_PATTERN : self::DEFAULT_PATTERN; } /** @@ -96,7 +100,7 @@ public function classToTableName($className) */ public function propertyToColumnName($propertyName, $className = null) { - return $this->underscore($propertyName, self::PATTERN_FOR_PROPERTIES); + return $this->underscore($propertyName); } /** @@ -120,7 +124,7 @@ public function referenceColumnName() */ public function joinColumnName($propertyName, $className = null) { - return $this->underscore($propertyName, self::PATTERN_FOR_PROPERTIES) . '_' . $this->referenceColumnName(); + return $this->underscore($propertyName) . '_' . $this->referenceColumnName(); } /** @@ -140,9 +144,9 @@ public function joinKeyColumnName($entityName, $referencedColumnName = null) ($referencedColumnName ?: $this->referenceColumnName()); } - private function underscore(string $string, string $pattern = self::DEFAULT_PATTERN) : string + private function underscore(string $string) : string { - $string = preg_replace($pattern, '_$1', $string); + $string = preg_replace($this->pattern, '_$1', $string); if ($this->case === CASE_UPPER) { return strtoupper($string); diff --git a/tests/Doctrine/Tests/ORM/Mapping/NamingStrategyTest.php b/tests/Doctrine/Tests/ORM/Mapping/NamingStrategyTest.php index b6ac43f932f..c9eda5d9149 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/NamingStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/NamingStrategyTest.php @@ -32,6 +32,16 @@ private static function underscoreNamingUpper() : UnderscoreNamingStrategy return new UnderscoreNamingStrategy(CASE_UPPER); } + private static function numberAwareUnderscoreNamingLower() : UnderscoreNamingStrategy + { + return new UnderscoreNamingStrategy(CASE_LOWER, true); + } + + private static function numberAwareUnderscoreNamingUpper() : UnderscoreNamingStrategy + { + return new UnderscoreNamingStrategy(CASE_UPPER, true); + } + /** * Data Provider for NamingStrategy#classToTableName * @@ -44,12 +54,25 @@ public static function dataClassToTableName() : array [self::defaultNaming(), 'SomeClassName', 'SomeClassName'], [self::defaultNaming(), 'SomeClassName', '\SomeClassName'], [self::defaultNaming(), 'Name', '\Some\Class\Name'], + [self::defaultNaming(), 'Name2Test', '\Some\Class\Name2Test'], // UnderscoreNamingStrategy [self::underscoreNamingLower(), 'some_class_name', '\Name\Space\SomeClassName'], [self::underscoreNamingLower(), 'name', '\Some\Class\Name'], + [self::underscoreNamingLower(), 'name2test', '\Some\Class\Name2Test'], [self::underscoreNamingUpper(), 'SOME_CLASS_NAME', '\Name\Space\SomeClassName'], [self::underscoreNamingUpper(), 'NAME', '\Some\Class\Name'], + [self::underscoreNamingUpper(), 'NAME2TEST', '\Some\Class\Name2Test'], + + // NumberAwareUnderscoreNamingStrategy + [self::numberAwareUnderscoreNamingLower(), 'some_class_name', '\Name\Space\SomeClassName'], + [self::numberAwareUnderscoreNamingLower(), 'name', '\Some\Class\Name'], + [self::numberAwareUnderscoreNamingLower(), 'name2_test', '\Some\Class\Name2Test'], + [self::numberAwareUnderscoreNamingLower(), 'name2test', '\Some\Class\Name2test'], + [self::numberAwareUnderscoreNamingUpper(), 'SOME_CLASS_NAME', '\Name\Space\SomeClassName'], + [self::numberAwareUnderscoreNamingUpper(), 'NAME', '\Some\Class\Name'], + [self::numberAwareUnderscoreNamingUpper(), 'NAME2_TEST', '\Some\Class\Name2Test'], + [self::numberAwareUnderscoreNamingUpper(), 'NAME2TEST', '\Some\Class\Name2test'], ]; } @@ -78,13 +101,23 @@ public static function dataPropertyToColumnName() : array // UnderscoreNamingStrategy [self::underscoreNamingLower(), 'some_property', 'someProperty'], - [self::underscoreNamingLower(), 'base64_encoded', 'base64Encoded'], + [self::underscoreNamingLower(), 'base64encoded', 'base64Encoded'], [self::underscoreNamingLower(), 'base64encoded', 'base64encoded'], [self::underscoreNamingUpper(), 'SOME_PROPERTY', 'someProperty'], [self::underscoreNamingUpper(), 'SOME_PROPERTY', 'some_property'], [self::underscoreNamingUpper(), 'SOME_PROPERTY', 'SOME_PROPERTY'], - [self::underscoreNamingUpper(), 'BASE64_ENCODED', 'base64Encoded'], + [self::underscoreNamingUpper(), 'BASE64ENCODED', 'base64Encoded'], [self::underscoreNamingUpper(), 'BASE64ENCODED', 'base64encoded'], + + // NumberAwareUnderscoreNamingStrategy + [self::numberAwareUnderscoreNamingLower(), 'some_property', 'someProperty'], + [self::numberAwareUnderscoreNamingLower(), 'base64_encoded', 'base64Encoded'], + [self::numberAwareUnderscoreNamingLower(), 'base64encoded', 'base64encoded'], + [self::numberAwareUnderscoreNamingUpper(), 'SOME_PROPERTY', 'someProperty'], + [self::numberAwareUnderscoreNamingUpper(), 'SOME_PROPERTY', 'some_property'], + [self::numberAwareUnderscoreNamingUpper(), 'SOME_PROPERTY', 'SOME_PROPERTY'], + [self::numberAwareUnderscoreNamingUpper(), 'BASE64_ENCODED', 'base64Encoded'], + [self::numberAwareUnderscoreNamingUpper(), 'BASE64ENCODED', 'base64encoded'], ]; } @@ -110,6 +143,10 @@ public static function dataReferenceColumnName() : array // UnderscoreNamingStrategy [self::underscoreNamingLower(), 'id'], [self::underscoreNamingUpper(), 'ID'], + + // NumberAwareUnderscoreNamingStrategy + [self::numberAwareUnderscoreNamingLower(), 'id'], + [self::numberAwareUnderscoreNamingUpper(), 'ID'], ]; } @@ -137,9 +174,18 @@ public static function dataJoinColumnName() : array // UnderscoreNamingStrategy [self::underscoreNamingLower(), 'some_column_id', 'someColumn', null], - [self::underscoreNamingLower(), 'base64_encoded_id', 'base64Encoded', null], + [self::underscoreNamingLower(), 'base64encoded_id', 'base64Encoded', null], [self::underscoreNamingUpper(), 'SOME_COLUMN_ID', 'someColumn', null], - [self::underscoreNamingUpper(), 'BASE64_ENCODED_ID', 'base64Encoded', null], + [self::underscoreNamingUpper(), 'BASE64ENCODED_ID', 'base64Encoded', null], + + // NumberAwareUnderscoreNamingStrategy + [self::numberAwareUnderscoreNamingLower(), 'some_column_id', 'someColumn', null], + [self::numberAwareUnderscoreNamingLower(), 'base64_encoded_id', 'base64Encoded', null], + [self::numberAwareUnderscoreNamingLower(), 'base64encoded_id', 'base64encoded', null], + [self::numberAwareUnderscoreNamingUpper(), 'SOME_COLUMN_ID', 'someColumn', null], + [self::numberAwareUnderscoreNamingUpper(), 'BASE64_ENCODED_ID', 'base64Encoded', null], + [self::numberAwareUnderscoreNamingUpper(), 'BASE64ENCODED_ID', 'base64encoded', null], + // JoinColumnClassNamingStrategy [new JoinColumnClassNamingStrategy(), 'classname_someColumn_id', 'someColumn', 'Some\ClassName'], [new JoinColumnClassNamingStrategy(), 'classname_some_column_id', 'some_column', 'ClassName'], @@ -173,11 +219,23 @@ public static function dataJoinTableName() : array // UnderscoreNamingStrategy [self::underscoreNamingLower(), 'some_class_name_class_name', 'SomeClassName', 'Some\ClassName', null], + [self::underscoreNamingLower(), 'class1test_class2test', 'Class1Test', 'Some\Class2Test', null], [self::underscoreNamingLower(), 'some_class_name_class_name', '\SomeClassName', 'ClassName', null], [self::underscoreNamingLower(), 'name_class_name', '\Some\Class\Name', 'ClassName', null], [self::underscoreNamingUpper(), 'SOME_CLASS_NAME_CLASS_NAME', 'SomeClassName', 'Some\ClassName', null], + [self::underscoreNamingUpper(), 'CLASS1TEST_CLASS2TEST', 'Class1Test', 'Some\Class2Test', null], [self::underscoreNamingUpper(), 'SOME_CLASS_NAME_CLASS_NAME', '\SomeClassName', 'ClassName', null], [self::underscoreNamingUpper(), 'NAME_CLASS_NAME', '\Some\Class\Name', 'ClassName', null], + + // NumberAwareUnderscoreNamingStrategy + [self::numberAwareUnderscoreNamingLower(), 'some_class_name_class_name', 'SomeClassName', 'Some\ClassName', null], + [self::numberAwareUnderscoreNamingLower(), 'class1_test_class2_test', 'Class1Test', 'Some\Class2Test', null], + [self::numberAwareUnderscoreNamingLower(), 'some_class_name_class_name', '\SomeClassName', 'ClassName', null], + [self::numberAwareUnderscoreNamingLower(), 'name_class_name', '\Some\Class\Name', 'ClassName', null], + [self::numberAwareUnderscoreNamingUpper(), 'SOME_CLASS_NAME_CLASS_NAME', 'SomeClassName', 'Some\ClassName', null], + [self::numberAwareUnderscoreNamingUpper(), 'CLASS1_TEST_CLASS2_TEST', 'Class1Test', 'Some\Class2Test', null], + [self::numberAwareUnderscoreNamingUpper(), 'SOME_CLASS_NAME_CLASS_NAME', '\SomeClassName', 'ClassName', null], + [self::numberAwareUnderscoreNamingUpper(), 'NAME_CLASS_NAME', '\Some\Class\Name', 'ClassName', null], ]; } @@ -207,11 +265,24 @@ public static function dataJoinKeyColumnName() : array [self::defaultNaming(), 'name_identifier', '\Some\Class\Name', 'identifier', null], // UnderscoreNamingStrategy + [self::underscoreNamingLower(), 'some_class_name2test_id', 'SomeClassName2Test', null, null], [self::underscoreNamingLower(), 'some_class_name_id', 'SomeClassName', null, null], [self::underscoreNamingLower(), 'class_name_identifier', '\Some\Class\ClassName', 'identifier', null], - + [self::underscoreNamingLower(), 'name2test_identifier', '\Some\Class\Name2Test', 'identifier', null], [self::underscoreNamingUpper(), 'SOME_CLASS_NAME_ID', 'SomeClassName', null, null], + [self::underscoreNamingUpper(), 'SOME_CLASS_NAME2TEST_ID', 'SomeClassName2Test', null, null], [self::underscoreNamingUpper(), 'CLASS_NAME_IDENTIFIER', '\Some\Class\ClassName', 'IDENTIFIER', null], + [self::underscoreNamingUpper(), 'NAME2TEST_IDENTIFIER', '\Some\Class\Name2Test', 'IDENTIFIER', null], + + // NumberAwareUnderscoreNamingStrategy + [self::numberAwareUnderscoreNamingLower(), 'some_class_name2_test_id', 'SomeClassName2Test', null, null], + [self::numberAwareUnderscoreNamingLower(), 'some_class_name_id', 'SomeClassName', null, null], + [self::numberAwareUnderscoreNamingLower(), 'class_name_identifier', '\Some\Class\ClassName', 'identifier', null], + [self::numberAwareUnderscoreNamingLower(), 'name2_test_identifier', '\Some\Class\Name2Test', 'identifier', null], + [self::numberAwareUnderscoreNamingUpper(), 'SOME_CLASS_NAME_ID', 'SomeClassName', null, null], + [self::numberAwareUnderscoreNamingUpper(), 'SOME_CLASS_NAME2_TEST_ID', 'SomeClassName2Test', null, null], + [self::numberAwareUnderscoreNamingUpper(), 'CLASS_NAME_IDENTIFIER', '\Some\Class\ClassName', 'IDENTIFIER', null], + [self::numberAwareUnderscoreNamingUpper(), 'NAME2_TEST_IDENTIFIER', '\Some\Class\Name2Test', 'IDENTIFIER', null], ]; } From 2d9b9351831d1230881c52f006011cbf72fe944e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Mon, 18 Nov 2019 23:01:21 +0100 Subject: [PATCH 871/877] Bump up version --- lib/Doctrine/ORM/Version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Version.php b/lib/Doctrine/ORM/Version.php index dcae22958e9..06a86174bcc 100644 --- a/lib/Doctrine/ORM/Version.php +++ b/lib/Doctrine/ORM/Version.php @@ -35,7 +35,7 @@ class Version /** * Current Doctrine Version */ - const VERSION = '2.6.6-DEV'; + const VERSION = '2.6.6'; /** * Compares a Doctrine version with the current one. From 4fae126459d7deb6cb2877fc0c0f8ecfa4658516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Mon, 18 Nov 2019 23:05:16 +0100 Subject: [PATCH 872/877] Bump up version --- lib/Doctrine/ORM/Version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Version.php b/lib/Doctrine/ORM/Version.php index 06a86174bcc..bb8187398f6 100644 --- a/lib/Doctrine/ORM/Version.php +++ b/lib/Doctrine/ORM/Version.php @@ -35,7 +35,7 @@ class Version /** * Current Doctrine Version */ - const VERSION = '2.6.6'; + const VERSION = '2.6.7-DEV'; /** * Compares a Doctrine version with the current one. From 0264ba17596bdd5eb70efd3ff3a8dc7afb1d747c Mon Sep 17 00:00:00 2001 From: mairo744 Date: Mon, 4 Nov 2019 22:39:45 +0100 Subject: [PATCH 873/877] Fix creation of join table names with schemas in SQLite Join table name doesnt depending on the platform. Table name was "schema.table" instead of "schema__table". (cherry picked from commit 4878cd3f4ef30ffc6047c18e0f7b16aafeabc3b4) --- .../ORM/Mapping/DefaultQuoteStrategy.php | 3 +- .../ORM/Functional/Ticket/GH7079Test.php | 123 ++++++++++++++++++ 2 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH7079Test.php diff --git a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php index 6929edfe452..ade44a0624c 100644 --- a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php @@ -99,7 +99,8 @@ public function getJoinTableName(array $association, ClassMetadata $class, Abstr $schema = ''; if (isset($association['joinTable']['schema'])) { - $schema = $association['joinTable']['schema'] . '.'; + $schema = $association['joinTable']['schema']; + $schema .= ! $platform->supportsSchemas() && $platform->canEmulateSchemas() ? '__' : '.'; } $tableName = $association['joinTable']['name']; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7079Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7079Test.php new file mode 100644 index 00000000000..5df5dfcb06f --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7079Test.php @@ -0,0 +1,123 @@ +platform = $this->_em->getConnection()->getDatabasePlatform(); + $this->strategy = new DefaultQuoteStrategy(); + } + + public function testGetTableName() : void + { + $table = [ + 'name' => 'cms_user', + 'schema' => 'cms', + ]; + + $cm = $this->createClassMetadata(GH7079CmsUser::class); + $cm->setPrimaryTable($table); + + self::assertEquals($this->getTableFullName($table), $this->strategy->getTableName($cm, $this->platform)); + } + + public function testJoinTableName() : void + { + $table = [ + 'name' => 'cmsaddress_cmsuser', + 'schema' => 'cms', + ]; + + $cm = $this->createClassMetadata(GH7079CmsAddress::class); + $cm->mapManyToMany( + [ + 'fieldName' => 'user', + 'targetEntity' => 'DDC7079CmsUser', + 'inversedBy' => 'users', + 'joinTable' => $table, + ] + ); + + self::assertEquals( + $this->getTableFullName($table), + $this->strategy->getJoinTableName($cm->associationMappings['user'], $cm, $this->platform) + ); + } + + private function getTableFullName(array $table) : string + { + $join = '.'; + if (! $this->platform->supportsSchemas() && $this->platform->canEmulateSchemas()) { + $join = '__'; + } + + return $table['schema'] . $join . $table['name']; + } + + private function createClassMetadata(string $className) : ClassMetadata + { + $cm = new ClassMetadata($className); + $cm->initializeReflection(new RuntimeReflectionService()); + + return $cm; + } +} + +/** + * @Entity + * @Table(name="cms_users", schema="cms") + */ +class GH7079CmsUser +{ + /** + * @Id @Column(type="integer") + * @GeneratedValue + */ + public $id; + + /** @OneToOne(targetEntity=GH7079CmsAddress::class, mappedBy="user", cascade={"persist"}, orphanRemoval=true) */ + public $address; +} + +/** + * @Entity + * @Table(name="cms_addresses", schema="cms") + */ +class GH7079CmsAddress +{ + /** + * @Column(type="integer") + * @Id @GeneratedValue + */ + public $id; + + /** + * @OneToOne(targetEntity=GH7079CmsUser::class, inversedBy="address") + * @JoinColumn(referencedColumnName="id") + */ + public $user; +} From 9ccb8837e7f0bc605117024561c07e487a57eca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Tue, 19 Nov 2019 01:33:36 +0100 Subject: [PATCH 874/877] Add deprecation message for EM#clear($entityName) --- UPGRADE.md | 8 ++++++++ lib/Doctrine/ORM/EntityManager.php | 8 ++++++++ tests/Doctrine/Tests/ORM/EntityManagerTest.php | 9 +++++++++ 3 files changed, 25 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index d6970a42aff..f8ae5f03562 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -82,6 +82,14 @@ restful operations, you should look at alternatives such as [JMSSerializer](http Final keyword will be added to the `EntityManager::class` in Doctrine 3.0 in order to ensure that EntityManager is not used as valid extension point. Valid extension point should be EntityManagerInterface. +## Deprecated `EntityManager#clear($entityName)` + +If your code relies on clearing a single entity type via `EntityManager#clear($entityName)`, +the signature has been changed to `EntityManager#clear()`. + +The main reason is that partial clears caused multiple issues with data integrity +in the managed entity graph, which was constantly spawning more edge-case bugs/scenarios. + ## Deprecated `EntityManager#flush($entity)` and `EntityManager#flush($entities)` If your code relies on single entity flushing optimisations via diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index a90dd9e6a92..6f582959141 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -29,6 +29,7 @@ use Doctrine\ORM\Query\FilterCollection; use Doctrine\Common\Util\ClassUtils; use Throwable; +use const E_USER_DEPRECATED; use function trigger_error; /** @@ -555,6 +556,13 @@ public function clear($entityName = null) throw ORMInvalidArgumentException::invalidEntityName($entityName); } + if ($entityName !== null) { + @trigger_error( + 'Calling ' . __METHOD__ . '() with any arguments to clear specific entities is deprecated and will not be supported in Doctrine 3.0.', + E_USER_DEPRECATED + ); + } + $this->unitOfWork->clear( null === $entityName ? null diff --git a/tests/Doctrine/Tests/ORM/EntityManagerTest.php b/tests/Doctrine/Tests/ORM/EntityManagerTest.php index e2774cf2dda..8531018a1ea 100644 --- a/tests/Doctrine/Tests/ORM/EntityManagerTest.php +++ b/tests/Doctrine/Tests/ORM/EntityManagerTest.php @@ -309,6 +309,15 @@ public function testClearManagerWithNullValue() $this->assertFalse($this->_em->contains($entity)); } + public function testDeprecatedClearWithArguments() : void + { + $entity = new Country(456, 'United Kingdom'); + $this->_em->persist($entity); + + $this->expectDeprecationMessage('Calling Doctrine\ORM\EntityManager::clear() with any arguments to clear specific entities is deprecated and will not be supported in Doctrine 3.0.'); + $this->_em->clear(Country::class); + } + public function testDeprecatedFlushWithArguments() : void { $entity = new Country(456, 'United Kingdom'); From 50992eafa2b1d78edf81991faac1427d91102632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Tue, 19 Nov 2019 02:11:56 +0100 Subject: [PATCH 875/877] Deprecated the usage of number unaware underscore naming strategy --- UPGRADE.md | 8 +++++++ .../ORM/Mapping/UnderscoreNamingStrategy.php | 9 ++++++++ .../Mapping/UnderscoreNamingStrategyTest.php | 22 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 tests/Doctrine/Tests/Mapping/UnderscoreNamingStrategyTest.php diff --git a/UPGRADE.md b/UPGRADE.md index f8ae5f03562..9794f968312 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -10,6 +10,14 @@ Method `Doctrine\ORM\AbstractQuery#useResultCache()` which could be used for bot To optimize DB interaction, `Doctrine\ORM\Tools\Pagination\Paginator` no longer fetches identifiers to be able to perform the pagination with join collections when max results isn't set in the query. +## Deprecated number unaware `Doctrine\ORM\Mapping\UnderscoreNamingStrategy` + +In the last patch of the `v2.6.x` series, we fixed a bug that was not converting names properly when they had numbers +(e.g.: `base64Encoded` was wrongly converted to `base64encoded` instead of `base64_encoded`). + +In order to not break BC we've introduced a way to enable the fixed behavior using a boolean constructor argument. This +argument will be removed in 3.0 and the default behavior will be the fixed one. + ## Deprecated: `Doctrine\ORM\AbstractQuery#useResultCache()` Method `Doctrine\ORM\AbstractQuery#useResultCache()` is deprecated because it is split into `enableResultCache()` diff --git a/lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php b/lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php index 1c219caa2cc..f4b77b97faf 100644 --- a/lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php +++ b/lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php @@ -22,12 +22,14 @@ use const CASE_LOWER; use const CASE_UPPER; +use const E_USER_DEPRECATED; use function preg_replace; use function strpos; use function strrpos; use function strtolower; use function strtoupper; use function substr; +use function trigger_error; /** * Naming strategy implementing the underscore naming convention. @@ -58,6 +60,13 @@ class UnderscoreNamingStrategy implements NamingStrategy */ public function __construct($case = CASE_LOWER, bool $numberAware = false) { + if (! $numberAware) { + @trigger_error( + 'Creating ' . self::class . ' without making it number aware is deprecated and will be removed in Doctrine 3.0.', + E_USER_DEPRECATED + ); + } + $this->case = $case; $this->pattern = $numberAware ? self::NUMBER_AWARE_PATTERN : self::DEFAULT_PATTERN; } diff --git a/tests/Doctrine/Tests/Mapping/UnderscoreNamingStrategyTest.php b/tests/Doctrine/Tests/Mapping/UnderscoreNamingStrategyTest.php new file mode 100644 index 00000000000..5d7782c1a30 --- /dev/null +++ b/tests/Doctrine/Tests/Mapping/UnderscoreNamingStrategyTest.php @@ -0,0 +1,22 @@ +expectDeprecationMessage('Creating Doctrine\ORM\Mapping\UnderscoreNamingStrategy without making it number aware is deprecated and will be removed in Doctrine 3.0.'); + new UnderscoreNamingStrategy(CASE_LOWER, false); + } +} From 33143229294916858f05c1c1bd7f888cf515dacb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Tue, 19 Nov 2019 08:44:32 +0100 Subject: [PATCH 876/877] Be explicit about which Doctrine package in message Avoiding possible confusion while reading the deprecation messages. --- UPGRADE.md | 6 +++--- lib/Doctrine/ORM/EntityManager.php | 10 +++++----- lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php | 2 +- lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php | 2 +- .../Console/Command/ConvertDoctrine1SchemaCommand.php | 2 +- .../Tools/Console/Command/GenerateEntitiesCommand.php | 2 +- .../Console/Command/GenerateRepositoriesCommand.php | 2 +- lib/Doctrine/ORM/Tools/EntityGenerator.php | 3 ++- lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php | 3 ++- .../ORM/Tools/Export/ClassMetadataExporter.php | 3 ++- .../ORM/Tools/Export/Driver/AbstractExporter.php | 3 ++- .../Tests/Mapping/UnderscoreNamingStrategyTest.php | 2 +- tests/Doctrine/Tests/ORM/EntityManagerTest.php | 10 +++++----- .../Tests/ORM/Mapping/Symfony/YamlDriverTest.php | 2 +- .../Tests/ORM/Mapping/YamlMappingDriverTest.php | 2 +- .../Command/GenerateRepositoriesCommandTest.php | 2 +- 16 files changed, 30 insertions(+), 26 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 9794f968312..c6c6eaaa016 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -40,7 +40,7 @@ Whole Doctrine\ORM\Tools\Export namespace with all its members have been depreca ## Deprecated `Doctrine\ORM\Proxy\Proxy` marker interface -Proxy objects in Doctrine 3.0 will no longer implement `Doctrine\ORM\Proxy\Proxy` nor +Proxy objects in Doctrine ORM 3.0 will no longer implement `Doctrine\ORM\Proxy\Proxy` nor `Doctrine\Common\Persistence\Proxy`: instead, they implement `ProxyManager\Proxy\GhostObjectInterface`. @@ -57,7 +57,7 @@ These methods have been deprecated: ## Deprecated `Doctrine\ORM\Version` -The `Doctrine\ORM\Version` class is now deprecated and will be removed in Doctrine 3.0: +The `Doctrine\ORM\Version` class is now deprecated and will be removed in Doctrine ORM 3.0: please refrain from checking the ORM version at runtime or use [ocramius/package-versions](https://github.com/Ocramius/PackageVersions/). @@ -87,7 +87,7 @@ restful operations, you should look at alternatives such as [JMSSerializer](http ## Extending `EntityManager` is deprecated -Final keyword will be added to the `EntityManager::class` in Doctrine 3.0 in order to ensure that EntityManager +Final keyword will be added to the `EntityManager::class` in Doctrine ORM 3.0 in order to ensure that EntityManager is not used as valid extension point. Valid extension point should be EntityManagerInterface. ## Deprecated `EntityManager#clear($entityName)` diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 6f582959141..0752f0e897e 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -358,7 +358,7 @@ public function flush($entity = null) { if ($entity !== null) { @trigger_error( - 'Calling ' . __METHOD__ . '() with any arguments to flush specific entities is deprecated and will not be supported in Doctrine 3.0.', + 'Calling ' . __METHOD__ . '() with any arguments to flush specific entities is deprecated and will not be supported in Doctrine ORM 3.0.', E_USER_DEPRECATED ); } @@ -558,7 +558,7 @@ public function clear($entityName = null) if ($entityName !== null) { @trigger_error( - 'Calling ' . __METHOD__ . '() with any arguments to clear specific entities is deprecated and will not be supported in Doctrine 3.0.', + 'Calling ' . __METHOD__ . '() with any arguments to clear specific entities is deprecated and will not be supported in Doctrine ORM 3.0.', E_USER_DEPRECATED ); } @@ -670,7 +670,7 @@ public function refresh($entity) */ public function detach($entity) { - @trigger_error('Method ' . __METHOD__ . '() is deprecated and will be removed in Doctrine 3.0.', E_USER_DEPRECATED); + @trigger_error('Method ' . __METHOD__ . '() is deprecated and will be removed in Doctrine ORM 3.0.', E_USER_DEPRECATED); if ( ! is_object($entity)) { throw ORMInvalidArgumentException::invalidObject('EntityManager#detach()', $entity); @@ -695,7 +695,7 @@ public function detach($entity) */ public function merge($entity) { - @trigger_error('Method ' . __METHOD__ . '() is deprecated and will be removed in Doctrine 3.0.', E_USER_DEPRECATED); + @trigger_error('Method ' . __METHOD__ . '() is deprecated and will be removed in Doctrine ORM 3.0.', E_USER_DEPRECATED); if ( ! is_object($entity)) { throw ORMInvalidArgumentException::invalidObject('EntityManager#merge()', $entity); @@ -711,7 +711,7 @@ public function merge($entity) */ public function copy($entity, $deep = false) { - @trigger_error('Method ' . __METHOD__ . '() is deprecated and will be removed in Doctrine 3.0.', E_USER_DEPRECATED); + @trigger_error('Method ' . __METHOD__ . '() is deprecated and will be removed in Doctrine ORM 3.0.', E_USER_DEPRECATED); throw new \BadMethodCallException("Not implemented."); } diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index 723c7b15c15..05339ec4f69 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -48,7 +48,7 @@ class YamlDriver extends FileDriver public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENSION) { @trigger_error( - 'YAML mapping driver is deprecated and will be removed in Doctrine 3.0, please migrate to annotation or XML driver.', + 'YAML mapping driver is deprecated and will be removed in Doctrine ORM 3.0, please migrate to annotation or XML driver.', E_USER_DEPRECATED ); diff --git a/lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php b/lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php index f4b77b97faf..177b390f4fe 100644 --- a/lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php +++ b/lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php @@ -62,7 +62,7 @@ public function __construct($case = CASE_LOWER, bool $numberAware = false) { if (! $numberAware) { @trigger_error( - 'Creating ' . self::class . ' without making it number aware is deprecated and will be removed in Doctrine 3.0.', + 'Creating ' . self::class . ' without making it number aware is deprecated and will be removed in Doctrine ORM 3.0.', E_USER_DEPRECATED ); } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php index 4f316aca432..90de7322ad4 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php @@ -120,7 +120,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $ui = new SymfonyStyle($input, $output); - $ui->warning('Command ' . $this->getName() . ' is deprecated and will be removed in Doctrine 3.0.'); + $ui->warning('Command ' . $this->getName() . ' is deprecated and will be removed in Doctrine ORM 3.0.'); // Process source directories $fromPaths = array_merge([$input->getArgument('from-path')], $input->getOption('from')); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php index 0d3a8daadcd..f1bba22d2c9 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php @@ -89,7 +89,7 @@ class is supposed to extend which. You have to adjust the entity protected function execute(InputInterface $input, OutputInterface $output) { $ui = new SymfonyStyle($input, $output); - $ui->warning('Command ' . $this->getName() . ' is deprecated and will be removed in Doctrine 3.0.'); + $ui->warning('Command ' . $this->getName() . ' is deprecated and will be removed in Doctrine ORM 3.0.'); $em = $this->getHelper('em')->getEntityManager(); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php index 82b7da6b46f..379c93597f6 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php @@ -61,7 +61,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $ui = new SymfonyStyle($input, $output); - $ui->warning('Command ' . $this->getName() . ' is deprecated and will be removed in Doctrine 3.0.'); + $ui->warning('Command ' . $this->getName() . ' is deprecated and will be removed in Doctrine ORM 3.0.'); $em = $this->getHelper('em')->getEntityManager(); diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 0accfaeaecf..5c304dbcb14 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -23,6 +23,7 @@ use Doctrine\Common\Inflector\Inflector; use Doctrine\DBAL\Types\Type; use Doctrine\ORM\Mapping\ClassMetadataInfo; +use const E_USER_DEPRECATED; use function str_replace; use function trigger_error; @@ -338,7 +339,7 @@ public function __construct() */ public function __construct() { - @trigger_error(self::class . ' is deprecated and will be removed in Doctrine 3.0', E_USER_DEPRECATED); + @trigger_error(self::class . ' is deprecated and will be removed in Doctrine ORM 3.0', E_USER_DEPRECATED); if (version_compare(\Doctrine\Common\Version::VERSION, '2.2.0-DEV', '>=')) { $this->annotationsPrefix = 'ORM\\'; diff --git a/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php b/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php index 07c7aaca0c9..9b3b290ac7f 100644 --- a/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php @@ -20,6 +20,7 @@ namespace Doctrine\ORM\Tools; use Doctrine\ORM\EntityRepository; +use const E_USER_DEPRECATED; use function trigger_error; /** @@ -57,7 +58,7 @@ class extends public function __construct() { - @trigger_error(self::class . ' is deprecated and will be removed in Doctrine 3.0', E_USER_DEPRECATED); + @trigger_error(self::class . ' is deprecated and will be removed in Doctrine ORM 3.0', E_USER_DEPRECATED); } /** diff --git a/lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php b/lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php index bf0bbada769..15c03b5c5af 100644 --- a/lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php @@ -19,6 +19,7 @@ namespace Doctrine\ORM\Tools\Export; +use const E_USER_DEPRECATED; use function trigger_error; /** @@ -46,7 +47,7 @@ class ClassMetadataExporter public function __construct() { - @trigger_error(self::class . ' is deprecated and will be removed in Doctrine 3.0', E_USER_DEPRECATED); + @trigger_error(self::class . ' is deprecated and will be removed in Doctrine ORM 3.0', E_USER_DEPRECATED); } /** diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php index 02cef5238bd..efe8e7bcdc9 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php @@ -21,6 +21,7 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Tools\Export\ExportException; +use const E_USER_DEPRECATED; use function trigger_error; /** @@ -60,7 +61,7 @@ abstract class AbstractExporter */ public function __construct($dir = null) { - @trigger_error(static::class . ' is deprecated and will be removed in Doctrine 3.0', E_USER_DEPRECATED); + @trigger_error(static::class . ' is deprecated and will be removed in Doctrine ORM 3.0', E_USER_DEPRECATED); $this->_outputDir = $dir; } diff --git a/tests/Doctrine/Tests/Mapping/UnderscoreNamingStrategyTest.php b/tests/Doctrine/Tests/Mapping/UnderscoreNamingStrategyTest.php index 5d7782c1a30..589dc7fd7e0 100644 --- a/tests/Doctrine/Tests/Mapping/UnderscoreNamingStrategyTest.php +++ b/tests/Doctrine/Tests/Mapping/UnderscoreNamingStrategyTest.php @@ -16,7 +16,7 @@ final class UnderscoreNamingStrategyTest extends TestCase /** @test */ public function checkDeprecationMessage() : void { - $this->expectDeprecationMessage('Creating Doctrine\ORM\Mapping\UnderscoreNamingStrategy without making it number aware is deprecated and will be removed in Doctrine 3.0.'); + $this->expectDeprecationMessage('Creating Doctrine\ORM\Mapping\UnderscoreNamingStrategy without making it number aware is deprecated and will be removed in Doctrine ORM 3.0.'); new UnderscoreNamingStrategy(CASE_LOWER, false); } } diff --git a/tests/Doctrine/Tests/ORM/EntityManagerTest.php b/tests/Doctrine/Tests/ORM/EntityManagerTest.php index 8531018a1ea..3eaf47d9f5f 100644 --- a/tests/Doctrine/Tests/ORM/EntityManagerTest.php +++ b/tests/Doctrine/Tests/ORM/EntityManagerTest.php @@ -314,7 +314,7 @@ public function testDeprecatedClearWithArguments() : void $entity = new Country(456, 'United Kingdom'); $this->_em->persist($entity); - $this->expectDeprecationMessage('Calling Doctrine\ORM\EntityManager::clear() with any arguments to clear specific entities is deprecated and will not be supported in Doctrine 3.0.'); + $this->expectDeprecationMessage('Calling Doctrine\ORM\EntityManager::clear() with any arguments to clear specific entities is deprecated and will not be supported in Doctrine ORM 3.0.'); $this->_em->clear(Country::class); } @@ -323,7 +323,7 @@ public function testDeprecatedFlushWithArguments() : void $entity = new Country(456, 'United Kingdom'); $this->_em->persist($entity); - $this->expectDeprecationMessage('Calling Doctrine\ORM\EntityManager::flush() with any arguments to flush specific entities is deprecated and will not be supported in Doctrine 3.0.'); + $this->expectDeprecationMessage('Calling Doctrine\ORM\EntityManager::flush() with any arguments to flush specific entities is deprecated and will not be supported in Doctrine ORM 3.0.'); $this->_em->flush($entity); } @@ -332,7 +332,7 @@ public function testDeprecatedMerge() : void $entity = new Country(456, 'United Kingdom'); $this->_em->persist($entity); - $this->expectDeprecationMessage('Method Doctrine\ORM\EntityManager::merge() is deprecated and will be removed in Doctrine 3.0.'); + $this->expectDeprecationMessage('Method Doctrine\ORM\EntityManager::merge() is deprecated and will be removed in Doctrine ORM 3.0.'); $this->_em->merge($entity); } @@ -341,7 +341,7 @@ public function testDeprecatedDetach() : void $entity = new Country(456, 'United Kingdom'); $this->_em->persist($entity); - $this->expectDeprecationMessage('Method Doctrine\ORM\EntityManager::detach() is deprecated and will be removed in Doctrine 3.0.'); + $this->expectDeprecationMessage('Method Doctrine\ORM\EntityManager::detach() is deprecated and will be removed in Doctrine ORM 3.0.'); $this->_em->detach($entity); } @@ -351,7 +351,7 @@ public function testDeprecatedCopy() : void $this->_em->persist($entity); try { - $this->expectDeprecationMessage('Method Doctrine\ORM\EntityManager::copy() is deprecated and will be removed in Doctrine 3.0.'); + $this->expectDeprecationMessage('Method Doctrine\ORM\EntityManager::copy() is deprecated and will be removed in Doctrine ORM 3.0.'); $this->_em->copy($entity); } catch (\BadMethodCallException $e) { // do nothing diff --git a/tests/Doctrine/Tests/ORM/Mapping/Symfony/YamlDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/Symfony/YamlDriverTest.php index d74677fc7d7..f167132f6bc 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/Symfony/YamlDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/Symfony/YamlDriverTest.php @@ -20,7 +20,7 @@ protected function getFileExtension() protected function getDriver(array $paths = []) { $driver = new SimplifiedYamlDriver(array_flip($paths)); - $this->expectDeprecationMessage('YAML mapping driver is deprecated and will be removed in Doctrine 3.0, please migrate to annotation or XML driver.'); + $this->expectDeprecationMessage('YAML mapping driver is deprecated and will be removed in Doctrine ORM 3.0, please migrate to annotation or XML driver.'); return $driver; } diff --git a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php index d34460d268d..7781b1622f7 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php @@ -86,7 +86,7 @@ public function testSpacesShouldBeIgnoredWhenUseExplode() public function testDeprecation() : void { $this->createClassMetadata(DDC2069Entity::class); - $this->expectDeprecationMessage('YAML mapping driver is deprecated and will be removed in Doctrine 3.0, please migrate to annotation or XML driver.'); + $this->expectDeprecationMessage('YAML mapping driver is deprecated and will be removed in Doctrine ORM 3.0, please migrate to annotation or XML driver.'); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php index cd05da25ec6..c155b9aa7e3 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php @@ -172,7 +172,7 @@ public function testNoMetadataClassesToProcess() : void ] ); - self::assertContains('Command orm:generate-repositories is deprecated and will be removed in Doctrine 3.0.', $tester->getDisplay()); + self::assertContains('Command orm:generate-repositories is deprecated and will be removed in Doctrine ORM 3.0.', $tester->getDisplay()); self::assertContains('[OK] No Metadata Classes to process.', $tester->getDisplay()); } } From 4d763ca4c925f647b248b9fa01b5f47aa3685d62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Tue, 19 Nov 2019 09:38:05 +0100 Subject: [PATCH 877/877] Bump up version --- lib/Doctrine/ORM/Version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Version.php b/lib/Doctrine/ORM/Version.php index 9a91b42ac24..1af55173c73 100644 --- a/lib/Doctrine/ORM/Version.php +++ b/lib/Doctrine/ORM/Version.php @@ -37,7 +37,7 @@ class Version /** * Current Doctrine Version */ - const VERSION = '2.7.0-DEV'; + const VERSION = '2.7.0'; /** * Compares a Doctrine version with the current one.