diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index b086fff7a..000000000 --- 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/.travis.yml b/.travis.yml index 7d54f4386..5a9fb2dcb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,9 @@ language: php php: - - 5.4 - - 5.5 - 5.6 - 7.0 + - nightly - hhvm env: @@ -28,14 +27,6 @@ after_script: matrix: include: - - php: 5.4 - env: DB=mariadb - addons: - mariadb: 5.5 - - php: 5.5 - env: DB=mariadb - addons: - mariadb: 5.5 - php: 5.6 env: DB=mariadb addons: @@ -49,14 +40,6 @@ matrix: addons: mariadb: 5.5 - - php: 5.4 - env: DB=mariadb - addons: - mariadb: 10.1 - - php: 5.5 - env: DB=mariadb - addons: - mariadb: 10.1 - php: 5.6 env: DB=mariadb addons: @@ -72,6 +55,8 @@ matrix: exclude: - php: hhvm env: DB=pgsql # driver for PostgreSQL currently unsupported by HHVM, requires 3rd party dependency + allow_failures: + - php: nightly sudo: false diff --git a/README.md b/README.md index 6c46f637c..dffd57ed1 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 @@ -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/UPGRADE.md b/UPGRADE.md index ed9a538b3..b71e10adb 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.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/bin/doctrine-pear.php b/bin/doctrine-pear.php index 10ce1dd88..b7c6ba3dc 100644 --- a/bin/doctrine-pear.php +++ b/bin/doctrine-pear.php @@ -31,7 +31,7 @@ $helperSet = null; if (file_exists($configFile)) { if ( ! is_readable($configFile)) { trigger_error( - 'Configuration file [' . $configFile . '] does not have read permission.', E_ERROR + 'Configuration file [' . $configFile . '] does not have read permission.', E_USER_ERROR ); } diff --git a/composer.json b/composer.json index cd1f81ade..f5b3b08f7 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ ], "minimum-stability": "dev", "require": { - "php": ">=5.4", + "php": "^5.6 || ^7.0", "ext-pdo": "*", "doctrine/collections": "~1.2", "doctrine/dbal": ">=2.5-dev,<2.7-dev", @@ -25,7 +25,7 @@ }, "require-dev": { "symfony/yaml": "~2.3|~3.0", - "phpunit/phpunit": "~4.0" + "phpunit/phpunit": "^5.4" }, "suggest": { "symfony/yaml": "If you want to use YAML Metadata Mapping Driver" @@ -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"] } } diff --git a/docs/en/cookbook/mysql-enums.rst b/docs/en/cookbook/mysql-enums.rst index fcc04517b..1765ecc90 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 "ENUM('visible', 'invisible') COMMENT '(DC2Type:enumvisibility)'"; + 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: diff --git a/docs/en/cookbook/working-with-datetime.rst b/docs/en/cookbook/working-with-datetime.rst index 660f2bbcf..98a1fb234 100644 --- a/docs/en/cookbook/working-with-datetime.rst +++ b/docs/en/cookbook/working-with-datetime.rst @@ -49,7 +49,7 @@ By default Doctrine assumes that you are working with a default timezone. Each D is created by Doctrine will be assigned the timezone that is currently the default, either through the ``date.timezone`` ini setting or by calling ``date_default_timezone_set()``. -This is very important to handle correctly if your application runs on different serves or is moved from one to another server +This is very important to handle correctly if your application runs on different servers or is moved from one to another server (with different timezone settings). You have to make sure that the timezone is the correct one on all this systems. diff --git a/docs/en/reference/advanced-configuration.rst b/docs/en/reference/advanced-configuration.rst index 9d200f870..abb72636c 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 ` - :ref:`@Cache ` - :ref:`@ChangeTrackingPolicy ` +- :ref:`@CustomIdGenerator ` - :ref:`@DiscriminatorColumn ` - :ref:`@DiscriminatorMap ` +- :ref:`@Embeddable ` +- :ref:`@Embedded ` - :ref:`@Entity ` - :ref:`@EntityResult ` - :ref:`@FieldResult ` @@ -231,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 + + ` +annotation to establish the relationship between two entities. + +.. code-block:: php + + createQuery('select u from MyProject\Model\User u'); - // example2: using setDql + // example2: using setDQL $q = $em->createQuery(); - $q->setDql('select u from MyProject\Model\User u'); + $q->setDQL('select u from MyProject\Model\User u'); Query Result Formats ~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/en/reference/events.rst b/docs/en/reference/events.rst index 171adca02..e6c8b0aa4 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. @@ -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 diff --git a/docs/en/reference/query-builder.rst b/docs/en/reference/query-builder.rst index 57eee179f..6b868c653 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``: diff --git a/docs/en/reference/second-level-cache.rst b/docs/en/reference/second-level-cache.rst index e89beba31..07f39a34f 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\\ReadOnlyCachedEntityPersister | - +-----------------------+-------------------------------------------------------------------------------+ - | READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\ReadWriteCachedEntityPersister | - +-----------------------+-------------------------------------------------------------------------------+ - | NONSTRICT_READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\NonStrictReadWriteCachedEntityPersister | - +-----------------------+-------------------------------------------------------------------------------+ - | READ_ONLY | Doctrine\\ORM\\Cache\\Persister\\ReadOnlyCachedCollectionPersister | - +-----------------------+-------------------------------------------------------------------------------+ - | READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\ReadWriteCachedCollectionPersister | - +-----------------------+-------------------------------------------------------------------------------+ - | NONSTRICT_READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\NonStrictReadWriteCacheCollectionPersister | - +-----------------------+-------------------------------------------------------------------------------+ + +-----------------------+-------------------------------------------------------------------------------------------+ + | 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\\NonStrictReadWriteCachedCollectionPersister | + +-----------------------+-------------------------------------------------------------------------------------------+ Configuration ------------- diff --git a/docs/en/reference/security.rst b/docs/en/reference/security.rst index efc0989cf..bb5f0f876 100644 --- a/docs/en/reference/security.rst +++ b/docs/en/reference/security.rst @@ -32,7 +32,7 @@ You can consider the following APIs to be safe from SQL injection: - Queries through the Criteria API on ``Doctrine\ORM\PersistentCollection`` and ``Doctrine\ORM\EntityRepository``. -You are **NOT** save from SQL injection when using user input with: +You are **NOT** safe from SQL injection when using user input with: - Expression API of ``Doctrine\ORM\QueryBuilder`` - Concatenating user input into DQL SELECT, UPDATE or DELETE statements or diff --git a/docs/en/reference/working-with-objects.rst b/docs/en/reference/working-with-objects.rst index 4e11341a3..2b52fac41 100644 --- a/docs/en/reference/working-with-objects.rst +++ b/docs/en/reference/working-with-objects.rst @@ -699,8 +699,6 @@ You can also load by owning side associations through the repository: $number = $em->find('MyProject\Domain\Phonenumber', 1234); $user = $em->getRepository('MyProject\Domain\User')->findOneBy(array('phone' => $number->getId())); -Be careful that this only works by passing the ID of the associated entity, not yet by passing the associated entity itself. - The ``EntityRepository#findBy()`` method additionally accepts orderings, limit and offset as second to fourth parameters: .. code-block:: php @@ -729,6 +727,14 @@ examples are equivalent: // 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(['nickname' => 'nonexistent']); + By Criteria ~~~~~~~~~~~ diff --git a/docs/en/tutorials/embeddables.rst b/docs/en/tutorials/embeddables.rst index 681aa7536..1dcb3c147 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 diff --git a/docs/en/tutorials/getting-started.rst b/docs/en/tutorials/getting-started.rst index 0a40218ac..05492b133 100644 --- a/docs/en/tutorials/getting-started.rst +++ b/docs/en/tutorials/getting-started.rst @@ -17,7 +17,7 @@ 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 installed: -- PHP 5.4 or above +- PHP (latest stable version) - Composer Package Manager (`Install Composer `_) @@ -344,7 +344,7 @@ Now that we have defined our first entity, let's update the database: $ vendor/bin/doctrine orm:schema-tool:update --force --dump-sql -Specifying both flags ``--force`` and ``-dump-sql`` prints and executes the DDL +Specifying both flags ``--force`` and ``--dump-sql`` prints and executes the DDL statements. Now create a new script that will insert products into the database: @@ -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:: @@ -1535,6 +1535,16 @@ As an example here is the code of the first use case "List of Bugs": Using EntityRepositories you can avoid coupling your model with specific query logic. You can also re-use query logic easily throughout your application. +The method ``count()`` takes an array of fields or association keys and the values to match against. +This provides you with a convenient and lightweight way to count a resultset when you don't need to +deal with it: + +.. code-block:: php + + getRepository(Product::class) + ->count(['name' => $productName]); + Conclusion ---------- diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index b5a8902fd..0089eeede 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -28,7 +28,7 @@ use Doctrine\ORM\Cache\QueryCacheKey; use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\ORM\Cache; -use Doctrine\ORM\Query\QueryException; +use Doctrine\ORM\Query\ResultSetMapping; /** * Base contract for ORM queries. Base class for Query and NativeQuery. @@ -719,7 +719,7 @@ abstract class AbstractQuery * * @param int $hydrationMode * - * @return array + * @return mixed */ public function getResult($hydrationMode = self::HYDRATE_OBJECT) { @@ -992,32 +992,54 @@ abstract class AbstractQuery 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/CacheConfiguration.php b/lib/Doctrine/ORM/Cache/CacheConfiguration.php index 4891cac49..eb3ec428d 100644 --- a/lib/Doctrine/ORM/Cache/CacheConfiguration.php +++ b/lib/Doctrine/ORM/Cache/CacheConfiguration.php @@ -110,7 +110,9 @@ class CacheConfiguration 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/DefaultCacheFactory.php b/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php index 82843d359..98ece43c7 100644 --- a/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php +++ b/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php @@ -217,8 +217,8 @@ class DefaultCacheFactory implements CacheFactory if ( ! $this->fileLockRegionDirectory) { throw new \LogicException( - 'If you what 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 what to use it please provide a valid directory, DefaultCacheFactory#setFileLockRegionDirectory(). ' + '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/lib/Doctrine/ORM/Cache/DefaultQueryCache.php b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php index 83fc0d946..dabf1721e 100644 --- a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php +++ b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php @@ -233,8 +233,8 @@ class DefaultQueryCache implements QueryCache $data = array(); $entityName = reset($rsm->aliasMap); + $rootAlias = key($rsm->aliasMap); $hasRelation = ( ! empty($rsm->relationMap)); - $metadata = $this->em->getClassMetadata($entityName); $persister = $this->uow->getEntityPersister($entityName); if ( ! ($persister instanceof CachedPersister)) { @@ -245,10 +245,11 @@ class DefaultQueryCache implements QueryCache foreach ($result as $index => $entity) { $identifier = $this->uow->getEntityIdentifier($entity); + $entityKey = new EntityCacheKey($entityName, $identifier); $data[$index]['identifier'] = $identifier; $data[$index]['associations'] = array(); - if (($key->cacheMode & Cache::MODE_REFRESH) || ! $region->contains($entityKey = new EntityCacheKey($entityName, $identifier))) { + if (($key->cacheMode & Cache::MODE_REFRESH) || ! $region->contains($entityKey)) { // Cancel put result if entity put fail if ( ! $persister->storeEntityCache($entity, $entityKey)) { return false; @@ -261,67 +262,170 @@ class DefaultQueryCache implements QueryCache // @TODO - move to cache hydration components foreach ($rsm->relationMap as $alias => $name) { - $metadata = $this->em->getClassMetadata($rsm->aliasMap[$rsm->parentAliasMap[$alias]]); - $assoc = $metadata->associationMappings[$name]; + $parentAlias = $rsm->parentAliasMap[$alias]; + $parentClass = $rsm->aliasMap[$parentAlias]; + $metadata = $this->em->getClassMetadata($parentClass); + $assoc = $metadata->associationMappings[$name]; + $assocValue = $this->getAssociationValue($rsm, $alias, $entity); - if (($assocValue = $metadata->getFieldValue($entity, $name)) === null || $assocValue instanceof Proxy) { + if ($assocValue === null) { continue; } - $assocPersister = $this->uow->getEntityPersister($assoc['targetEntity']); - $assocRegion = $assocPersister->getCacheRegion(); - $assocMetadata = $assocPersister->getClassMetadata(); - - // Handle *-to-one associations - if ($assoc['type'] & ClassMetadata::TO_ONE) { - - $assocIdentifier = $this->uow->getEntityIdentifier($assocValue); - - if (($key->cacheMode & Cache::MODE_REFRESH) || ! $assocRegion->contains($entityKey = new EntityCacheKey($assocMetadata->rootEntityName, $assocIdentifier))) { - - // Cancel put result if association entity put fail - if ( ! $assocPersister->storeEntityCache($assocValue, $entityKey)) { - return false; - } + // root entity association + if ($rootAlias === $parentAlias) { + // Cancel put result if association put fail + if ( ($assocInfo = $this->storeAssociationCache($key, $assoc, $assocValue)) === null) { + return false; } - $data[$index]['associations'][$name] = array( - 'targetEntity' => $assocMetadata->rootEntityName, - 'identifier' => $assocIdentifier, - 'type' => $assoc['type'] - ); + $data[$index]['associations'][$name] = $assocInfo; continue; } - // Handle *-to-many associations - $list = array(); - - foreach ($assocValue as $assocItemIndex => $assocItem) { - $assocIdentifier = $this->uow->getEntityIdentifier($assocItem); - - if (($key->cacheMode & Cache::MODE_REFRESH) || ! $assocRegion->contains($entityKey = new EntityCacheKey($assocMetadata->rootEntityName, $assocIdentifier))) { - - // Cancel put result if entity put fail - if ( ! $assocPersister->storeEntityCache($assocItem, $entityKey)) { - return false; - } + // store single nested association + if ( ! is_array($assocValue)) { + // Cancel put result if association put fail + if ($this->storeAssociationCache($key, $assoc, $assocValue) === null) { + return false; } - $list[$assocItemIndex] = $assocIdentifier; + continue; } - $data[$index]['associations'][$name] = array( - 'targetEntity' => $assocMetadata->rootEntityName, - 'type' => $assoc['type'], - 'list' => $list, - ); + // store array of nested association + foreach ($assocValue as $aVal) { + // Cancel put result if association put fail + if ($this->storeAssociationCache($key, $assoc, $aVal) === null) { + return false; + } + } } } return $this->region->put($key, new QueryCacheEntry($data)); } + /** + * @param \Doctrine\ORM\Cache\QueryCacheKey $key + * @param array $assoc + * @param mixed $assocValue + * + * @return array|null + */ + private function storeAssociationCache(QueryCacheKey $key, array $assoc, $assocValue) + { + $assocPersister = $this->uow->getEntityPersister($assoc['targetEntity']); + $assocMetadata = $assocPersister->getClassMetadata(); + $assocRegion = $assocPersister->getCacheRegion(); + + // Handle *-to-one associations + if ($assoc['type'] & ClassMetadata::TO_ONE) { + $assocIdentifier = $this->uow->getEntityIdentifier($assocValue); + $entityKey = new EntityCacheKey($assocMetadata->rootEntityName, $assocIdentifier); + + if ( ! $assocValue instanceof Proxy && ($key->cacheMode & Cache::MODE_REFRESH) || ! $assocRegion->contains($entityKey)) { + // Entity put fail + if ( ! $assocPersister->storeEntityCache($assocValue, $entityKey)) { + return null; + } + } + + return array( + 'targetEntity' => $assocMetadata->rootEntityName, + 'identifier' => $assocIdentifier, + 'type' => $assoc['type'] + ); + } + + // Handle *-to-many associations + $list = array(); + + foreach ($assocValue as $assocItemIndex => $assocItem) { + $assocIdentifier = $this->uow->getEntityIdentifier($assocItem); + $entityKey = new EntityCacheKey($assocMetadata->rootEntityName, $assocIdentifier); + + if (($key->cacheMode & Cache::MODE_REFRESH) || ! $assocRegion->contains($entityKey)) { + // Entity put fail + if ( ! $assocPersister->storeEntityCache($assocItem, $entityKey)) { + return null; + } + } + + $list[$assocItemIndex] = $assocIdentifier; + } + + return array( + 'targetEntity' => $assocMetadata->rootEntityName, + 'type' => $assoc['type'], + 'list' => $list, + ); + } + + /** + * @param \Doctrine\ORM\Query\ResultSetMapping $rsm + * @param string $assocAlias + * @param object $entity + * + * @return array|object + */ + private function getAssociationValue(ResultSetMapping $rsm, $assocAlias, $entity) + { + $path = array(); + $alias = $assocAlias; + + while (isset($rsm->parentAliasMap[$alias])) { + $parent = $rsm->parentAliasMap[$alias]; + $field = $rsm->relationMap[$alias]; + $class = $rsm->aliasMap[$parent]; + + array_unshift($path, array( + 'field' => $field, + 'class' => $class + )); + + $alias = $parent; + } + + return $this->getAssociationPathValue($entity, $path); + } + + /** + * @param mixed $value + * @param array $path + * + * @return array|object|null + */ + private function getAssociationPathValue($value, array $path) + { + $mapping = array_shift($path); + $metadata = $this->em->getClassMetadata($mapping['class']); + $assoc = $metadata->associationMappings[$mapping['field']]; + $value = $metadata->getFieldValue($value, $mapping['field']); + + if ($value === null) { + return null; + } + + if (empty($path)) { + return $value; + } + + // Handle *-to-one associations + if ($assoc['type'] & ClassMetadata::TO_ONE) { + return $this->getAssociationPathValue($value, $path); + } + + $values = array(); + + foreach ($value as $item) { + $values[] = $this->getAssociationPathValue($item, $path); + } + + return $values; + } + /** * {@inheritdoc} */ diff --git a/lib/Doctrine/ORM/Cache/EntityCacheEntry.php b/lib/Doctrine/ORM/Cache/EntityCacheEntry.php index 3c552073d..155618be9 100644 --- a/lib/Doctrine/ORM/Cache/EntityCacheEntry.php +++ b/lib/Doctrine/ORM/Cache/EntityCacheEntry.php @@ -71,7 +71,7 @@ class EntityCacheEntry implements CacheEntry /** * Retrieves the entity data resolving cache entries * - * @param \Doctrine\ORM\EntityManagerInterfac $em + * @param \Doctrine\ORM\EntityManagerInterface $em * * @return array */ diff --git a/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php b/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php index 5690f9169..1a41014b9 100644 --- a/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php +++ b/lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php @@ -287,17 +287,16 @@ abstract class AbstractEntityPersister implements CachedEntityPersister * @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,17 +367,16 @@ abstract class AbstractEntityPersister implements CachedEntityPersister } //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); + $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 +386,15 @@ abstract class AbstractEntityPersister implements CachedEntityPersister 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); } } @@ -408,32 +406,31 @@ abstract class AbstractEntityPersister implements CachedEntityPersister */ 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); + $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); } } @@ -511,31 +508,30 @@ abstract class AbstractEntityPersister implements CachedEntityPersister $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); + $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/QueryCacheEntry.php b/lib/Doctrine/ORM/Cache/QueryCacheEntry.php index 74e4cdda5..b6af393fd 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/QueryCacheKey.php b/lib/Doctrine/ORM/Cache/QueryCacheKey.php index 9a7d2b7bc..0e072a36f 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 function __construct($hash, $lifetime = 0, $cacheMode = Cache::MODE_NORMAL) - { - $this->hash = $hash; - $this->lifetime = $lifetime; - $this->cacheMode = $cacheMode; + 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, + TimestampCacheKey $timestampKey = null + ) { + $this->hash = $hash; + $this->lifetime = $lifetime; + $this->cacheMode = $cacheMode; + $this->timestampKey = $timestampKey; } } diff --git a/lib/Doctrine/ORM/Cache/TimestampQueryCacheValidator.php b/lib/Doctrine/ORM/Cache/TimestampQueryCacheValidator.php index 4e504e4f8..c6404d3b2 100644 --- a/lib/Doctrine/ORM/Cache/TimestampQueryCacheValidator.php +++ b/lib/Doctrine/ORM/Cache/TimestampQueryCacheValidator.php @@ -26,15 +26,49 @@ namespace Doctrine\ORM\Cache; */ 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) > time(); + 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/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index d66f454e7..4de4932bc 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -22,6 +22,7 @@ namespace Doctrine\ORM; use Exception; use Doctrine\Common\EventManager; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\LockMode; use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\ORM\Proxy\ProxyFactory; @@ -289,7 +290,7 @@ use Doctrine\Common\Util\ClassUtils; $query = new Query($this); if ( ! empty($dql)) { - $query->setDql($dql); + $query->setDQL($dql); } return $query; @@ -310,7 +311,7 @@ use Doctrine\Common\Util\ClassUtils; { $query = new NativeQuery($this); - $query->setSql($sql); + $query->setSQL($sql); $query->setResultSetMapping($rsm); return $query; @@ -820,39 +821,53 @@ use Doctrine\Common\Util\ClassUtils; /** * Factory method to create EntityManager instances. * - * @param mixed $conn An array with the connection parameters or an existing Connection instance. - * @param Configuration $config The Configuration instance to use. - * @param EventManager $eventManager The EventManager instance to use. + * @param array|Connection $connection An array with the connection parameters or an existing Connection instance. + * @param Configuration $config The Configuration instance to use. + * @param EventManager $eventManager The EventManager instance to use. * * @return EntityManager The created EntityManager. * * @throws \InvalidArgumentException * @throws ORMException */ - public static function create($conn, Configuration $config, EventManager $eventManager = null) + public static function create($connection, Configuration $config, EventManager $eventManager = null) { if ( ! $config->getMetadataDriverImpl()) { throw ORMException::missingMappingDriverImpl(); } - switch (true) { - case (is_array($conn)): - $conn = \Doctrine\DBAL\DriverManager::getConnection( - $conn, $config, ($eventManager ?: new EventManager()) - ); - break; + $connection = static::createConnection($connection, $config, $eventManager); - case ($conn instanceof Connection): - if ($eventManager !== null && $conn->getEventManager() !== $eventManager) { - throw ORMException::mismatchedEventManager(); - } - break; + return new EntityManager($connection, $config, $connection->getEventManager()); + } - default: - throw new \InvalidArgumentException("Invalid argument: " . $conn); + /** + * Factory method to create Connection instances. + * + * @param array|Connection $connection An array with the connection parameters or an existing Connection instance. + * @param Configuration $config The Configuration instance to use. + * @param EventManager $eventManager The EventManager instance to use. + * + * @return Connection + * + * @throws \InvalidArgumentException + * @throws ORMException + */ + protected static function createConnection($connection, Configuration $config, EventManager $eventManager = null) + { + if (is_array($connection)) { + return DriverManager::getConnection($connection, $config, $eventManager ?: new EventManager()); } - return new EntityManager($conn, $config, $conn->getEventManager()); + if ( ! $connection instanceof Connection) { + throw new \InvalidArgumentException("Invalid argument: " . $connection); + } + + if ($eventManager !== null && $connection->getEventManager() !== $eventManager) { + throw ORMException::mismatchedEventManager(); + } + + return $connection; } /** diff --git a/lib/Doctrine/ORM/EntityManagerInterface.php b/lib/Doctrine/ORM/EntityManagerInterface.php index 016cfd4ec..09c7efdf9 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/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index 6a60d5050..1934a18d0 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -19,7 +19,7 @@ namespace Doctrine\ORM; -use Doctrine\ORM\EntityManagerInterface; +use Doctrine\Common\Util\Inflector; use Doctrine\ORM\Query\ResultSetMappingBuilder; use Doctrine\Common\Persistence\ObjectRepository; use Doctrine\Common\Collections\Selectable; @@ -197,64 +197,48 @@ class EntityRepository implements ObjectRepository, Selectable } /** - * 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 cardinality of the objects that match the given criteria. + */ + public function count(array $criteria) + { + return $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName)->count($criteria); + } + + /** + * Adds support for magic method calls. * * @param string $method * @param array $arguments * - * @return array|object The found entity/entities. + * @return mixed The returned value from the resolved method. * * @throws ORMException - * @throws \BadMethodCallException If the method called is an invalid find* method - * or no find* 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; - - 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); } - if (empty($arguments)) { - 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 (count($arguments)) { - 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, findOneBy or countBy!" + ); } /** @@ -303,4 +287,30 @@ class EntityRepository implements ObjectRepository, Selectable 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 or the requested field/association does not exist + * + * @return mixed + */ + private function resolveMagicCall($method, $by, array $arguments) + { + if (! $arguments) { + throw ORMException::findByRequiresParameter($method . $by); + } + + $fieldName = lcfirst(Inflector::classify($by)); + + if (! ($this->_class->hasField($fieldName) || $this->_class->hasAssociation($fieldName))) { + throw ORMException::invalidMagicCall($this->_entityName, $fieldName, $method . $by); + } + + return $this->$method([$fieldName => $arguments[0]], ...array_slice($arguments, 1)); + } } diff --git a/lib/Doctrine/ORM/Event/LifecycleEventArgs.php b/lib/Doctrine/ORM/Event/LifecycleEventArgs.php index 9a5c8cf06..c7eb80bf6 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/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index 3cedaada0..14aed2a67 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -24,9 +24,6 @@ use PDO; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\PersistentCollection; use Doctrine\ORM\Query; -use Doctrine\ORM\Events; -use Doctrine\ORM\Event\LifecycleEventArgs; -use Doctrine\ORM\Event\PostLoadEventDispatcher; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Proxy\Proxy; @@ -332,6 +329,9 @@ class ObjectHydrator extends AbstractHydrator // Split the row data into chunks of class data. $rowData = $this->gatherRowData($row, $id, $nonemptyComponents); + // reset result pointers for each data row + $this->resultPointers = []; + // Hydrate the data chunks foreach ($rowData['data'] as $dqlAlias => $data) { $entityName = $this->_rsm->aliasMap[$dqlAlias]; @@ -586,10 +586,7 @@ class ObjectHydrator extends AbstractHydrator parent::onClear($eventArgs); $aliases = array_keys($this->identifierMap); - $this->identifierMap = array(); - foreach ($aliases as $alias) { - $this->identifierMap[$alias] = array(); - } + $this->identifierMap = array_fill_keys($aliases, []); } } diff --git a/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php index 1c21369e3..785a2b796 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php @@ -20,7 +20,6 @@ namespace Doctrine\ORM\Internal\Hydration; use PDO; -use Doctrine\DBAL\Types\Type; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Query; @@ -122,6 +121,9 @@ class SimpleObjectHydrator extends AbstractHydrator continue; } + // Check if value is null before conversion (because some types convert null to something else) + $valueIsNull = null === $value; + // Convert field to a valid PHP value if (isset($cacheKeyInfo['type'])) { $type = $cacheKeyInfo['type']; @@ -131,7 +133,7 @@ class SimpleObjectHydrator extends AbstractHydrator $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; } } diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 90db1f8a6..9e036b652 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -941,8 +941,13 @@ class ClassMetadataInfo implements ClassMetadata continue; } - $parentReflFields[$property] = $reflService->getAccessibleProperty($this->name, $property); - $this->reflFields[$property] = $reflService->getAccessibleProperty($this->name, $property); + $fieldRefl = $reflService->getAccessibleProperty( + isset($embeddedClass['declared']) ? $embeddedClass['declared'] : $this->name, + $property + ); + + $parentReflFields[$property] = $fieldRefl; + $this->reflFields[$property] = $fieldRefl; } foreach ($this->fieldMappings as $field => $mapping) { @@ -1460,8 +1465,7 @@ class ClassMetadataInfo implements ClassMetadata $mapping['isOwningSide'] = true; // assume owning side until we hit mappedBy - // unset optional indexBy attribute if its empty - if ( ! isset($mapping['indexBy']) || !$mapping['indexBy']) { + if (empty($mapping['indexBy'])) { unset($mapping['indexBy']); } @@ -1539,13 +1543,12 @@ class ClassMetadataInfo implements ClassMetadata // Cascades $cascades = isset($mapping['cascade']) ? array_map('strtolower', $mapping['cascade']) : array(); + $allCascades = array('remove', 'persist', 'refresh', 'merge', 'detach'); if (in_array('all', $cascades)) { - $cascades = array('remove', 'persist', 'refresh', 'merge', 'detach'); - } - - if (count($cascades) !== count(array_intersect($cascades, array('remove', 'persist', 'refresh', 'merge', 'detach')))) { + $cascades = $allCascades; + } elseif (count($cascades) !== count(array_intersect($cascades, $allCascades))) { throw MappingException::invalidCascadeOption( - array_diff($cascades, array_intersect($cascades, array('remove', 'persist', 'refresh', 'merge', 'detach'))), + array_diff($cascades, $allCascades), $this->name, $mapping['fieldName'] ); @@ -1580,7 +1583,7 @@ class ClassMetadataInfo implements ClassMetadata } if ($mapping['isOwningSide']) { - if ( ! isset($mapping['joinColumns']) || ! $mapping['joinColumns']) { + if (empty($mapping['joinColumns'])) { // Apply default join column $mapping['joinColumns'] = array( array( @@ -1594,8 +1597,8 @@ class ClassMetadataInfo implements ClassMetadata foreach ($mapping['joinColumns'] as &$joinColumn) { if ($mapping['type'] === self::ONE_TO_ONE && ! $this->isInheritanceTypeSingleTable()) { - if (count($mapping['joinColumns']) == 1) { - if ( ! isset($mapping['id']) || ! $mapping['id']) { + if (count($mapping['joinColumns']) === 1) { + if (empty($mapping['id'])) { $joinColumn['unique'] = true; } } else { @@ -1640,8 +1643,8 @@ class ClassMetadataInfo implements ClassMetadata $mapping['targetToSourceKeyColumns'] = array_flip($mapping['sourceToTargetKeyColumns']); } - $mapping['orphanRemoval'] = isset($mapping['orphanRemoval']) ? (bool) $mapping['orphanRemoval'] : false; - $mapping['isCascadeRemove'] = $mapping['orphanRemoval'] ? true : $mapping['isCascadeRemove']; + $mapping['orphanRemoval'] = isset($mapping['orphanRemoval']) && $mapping['orphanRemoval']; + $mapping['isCascadeRemove'] = $mapping['orphanRemoval'] || $mapping['isCascadeRemove']; if ($mapping['orphanRemoval']) { unset($mapping['unique']); @@ -1673,14 +1676,10 @@ class ClassMetadataInfo implements ClassMetadata throw MappingException::oneToManyRequiresMappedBy($mapping['fieldName']); } - $mapping['orphanRemoval'] = isset($mapping['orphanRemoval']) ? (bool) $mapping['orphanRemoval'] : false; - $mapping['isCascadeRemove'] = $mapping['orphanRemoval'] ? true : $mapping['isCascadeRemove']; + $mapping['orphanRemoval'] = isset($mapping['orphanRemoval']) && $mapping['orphanRemoval']; + $mapping['isCascadeRemove'] = $mapping['orphanRemoval'] || $mapping['isCascadeRemove']; - if (isset($mapping['orderBy'])) { - if ( ! is_array($mapping['orderBy'])) { - throw new InvalidArgumentException("'orderBy' is expected to be an array, not ".gettype($mapping['orderBy'])); - } - } + $this->assertMappingOrderBy($mapping); return $mapping; } @@ -1784,13 +1783,9 @@ class ClassMetadataInfo implements ClassMetadata } } - $mapping['orphanRemoval'] = isset($mapping['orphanRemoval']) ? (bool) $mapping['orphanRemoval'] : false; + $mapping['orphanRemoval'] = isset($mapping['orphanRemoval']) && $mapping['orphanRemoval']; - if (isset($mapping['orderBy'])) { - if ( ! is_array($mapping['orderBy'])) { - throw new InvalidArgumentException("'orderBy' is expected to be an array, not ".gettype($mapping['orderBy'])); - } - } + $this->assertMappingOrderBy($mapping); return $mapping; } @@ -2208,11 +2203,11 @@ class ClassMetadataInfo implements ClassMetadata $overrideMapping['id'] = $mapping['id']; } - if ( ! isset($overrideMapping['type']) || $overrideMapping['type'] === null) { + if ( ! isset($overrideMapping['type'])) { $overrideMapping['type'] = $mapping['type']; } - if ( ! isset($overrideMapping['fieldName']) || $overrideMapping['fieldName'] === null) { + if ( ! isset($overrideMapping['fieldName'])) { $overrideMapping['fieldName'] = $mapping['fieldName']; } @@ -2948,17 +2943,17 @@ class ClassMetadataInfo implements ClassMetadata { if (isset($this->fieldNames[$columnName])) { return $this->fieldNames[$columnName]; - } else { - foreach ($this->associationMappings as $assocName => $mapping) { - if ($this->isAssociationWithSingleJoinColumn($assocName) && - $this->associationMappings[$assocName]['joinColumns'][0]['name'] == $columnName) { - - return $assocName; - } - } - - throw MappingException::noFieldNameFoundForColumn($this->name, $columnName); } + + foreach ($this->associationMappings as $assocName => $mapping) { + if ($this->isAssociationWithSingleJoinColumn($assocName) && + $this->associationMappings[$assocName]['joinColumns'][0]['name'] == $columnName) { + + return $assocName; + } + } + + throw MappingException::noFieldNameFoundForColumn($this->name, $columnName); } /** @@ -3385,4 +3380,14 @@ class ClassMetadataInfo implements ClassMetadata return $sequencePrefix; } + + /** + * @param array $mapping + */ + private function assertMappingOrderBy(array $mapping) + { + if (isset($mapping['orderBy']) && !is_array($mapping['orderBy'])) { + throw new InvalidArgumentException("'orderBy' is expected to be an array, not " . gettype($mapping['orderBy'])); + } + } } diff --git a/lib/Doctrine/ORM/Mapping/Driver/SimplifiedXmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/SimplifiedXmlDriver.php index 85221f3a2..9bfd84cae 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 d2b8c0fcf..8f38784f4 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 ace42db27..97686d654 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/ORMException.php b/lib/Doctrine/ORM/ORMException.php index 6d8a6d631..919789d92 100644 --- a/lib/Doctrine/ORM/ORMException.php +++ b/lib/Doctrine/ORM/ORMException.php @@ -187,6 +187,21 @@ class ORMException extends Exception ); } + /** + * @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 diff --git a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php index 25c03a450..525ab34b3 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php @@ -21,7 +21,6 @@ namespace Doctrine\ORM\Persisters\Collection; use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\Mapping\ClassMetadata; -use Doctrine\ORM\Persisters\SqlExpressionVisitor; use Doctrine\ORM\Persisters\SqlValueVisitor; use Doctrine\ORM\PersistentCollection; use Doctrine\ORM\Query; @@ -740,7 +739,7 @@ class ManyToManyPersister extends AbstractCollectionPersister $valueVisitor->dispatch($expression); - list($values, $types) = $valueVisitor->getParamsAndTypes(); + list(, $types) = $valueVisitor->getParamsAndTypes(); return $types; } diff --git a/lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php index d4213f15d..0e2fda868 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php @@ -20,7 +20,6 @@ namespace Doctrine\ORM\Persisters\Collection; use Doctrine\Common\Collections\Criteria; -use Doctrine\Common\Proxy\Proxy; use Doctrine\DBAL\Types\Type; use Doctrine\ORM\PersistentCollection; use Doctrine\ORM\Utility\PersisterHelper; diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 3b2faf878..d577df6d9 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -822,7 +822,7 @@ class BasicEntityPersister implements EntityPersister ? $this->expandCriteriaParameters($criteria) : $this->expandParameters($criteria); - return $this->conn->executeQuery($sql, $params, $types)->fetchColumn(); + return (int) $this->conn->executeQuery($sql, $params, $types)->fetchColumn(); } /** @@ -1442,7 +1442,7 @@ class BasicEntityPersister implements EntityPersister 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']; } diff --git a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php index 072407405..0975cf56e 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php @@ -20,7 +20,6 @@ namespace Doctrine\ORM\Persisters\Entity; use Doctrine\ORM\Mapping\ClassMetadata; -use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\DBAL\LockMode; use Doctrine\DBAL\Types\Type; diff --git a/lib/Doctrine/ORM/Proxy/ProxyFactory.php b/lib/Doctrine/ORM/Proxy/ProxyFactory.php index 72f161eab..58dfc0932 100644 --- a/lib/Doctrine/ORM/Proxy/ProxyFactory.php +++ b/lib/Doctrine/ORM/Proxy/ProxyFactory.php @@ -196,7 +196,7 @@ class ProxyFactory extends AbstractProxyFactory ); } - foreach ($class->getReflectionClass()->getProperties() as $property) { + foreach ($class->getReflectionProperties() as $property) { if ( ! $class->hasField($property->name) && ! $class->hasAssociation($property->name)) { continue; } diff --git a/lib/Doctrine/ORM/Query/AST/NewObjectExpression.php b/lib/Doctrine/ORM/Query/AST/NewObjectExpression.php index 65b94ac63..ec011ce29 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/Query/Exec/MultiTableDeleteExecutor.php b/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php index 12713e1a7..b14ddb534 100644 --- a/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php @@ -118,8 +118,6 @@ class MultiTableDeleteExecutor extends AbstractSqlExecutor */ public function execute(Connection $conn, array $params, array $types) { - $numDeleted = 0; - // Create temporary id table $conn->executeUpdate($this->_createTempTableSql); diff --git a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php index b47ba1795..995f9cad1 100644 --- a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php @@ -163,8 +163,6 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor */ public function execute(Connection $conn, array $params, array $types) { - $numUpdated = 0; - // Create temporary id table $conn->executeUpdate($this->_createTempTableSql); diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 8b6feaf83..6f8eda514 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -827,17 +827,13 @@ class Parser return; } - $foundRootEntity = false; - foreach ($this->identVariableExpressions as $dqlAlias => $expr) { if (isset($this->queryComponents[$dqlAlias]) && $this->queryComponents[$dqlAlias]['parent'] === null) { - $foundRootEntity = true; + return; } } - if ( ! $foundRootEntity) { - $this->semanticalError('Cannot select entity through identification variables without choosing at least one root entity alias.'); - } + $this->semanticalError('Cannot select entity through identification variables without choosing at least one root entity alias.'); } /** @@ -2953,7 +2949,7 @@ class Parser /** * EntityExpression ::= SingleValuedAssociationPathExpression | SimpleEntityExpression * - * @return \Doctrine\ORM\Query\AST\SingleValuedAssociationPathExpression | + * @return \Doctrine\ORM\Query\AST\PathExpression | * \Doctrine\ORM\Query\AST\SimpleEntityExpression */ public function EntityExpression() diff --git a/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php b/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php index 97bfb4709..73eb5ae5a 100644 --- a/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php +++ b/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php @@ -19,7 +19,6 @@ namespace Doctrine\ORM\Query; -use Doctrine\DBAL\Types\Type; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Mapping\MappingException; diff --git a/lib/Doctrine/ORM/QueryBuilder.php b/lib/Doctrine/ORM/QueryBuilder.php index 2dfbf800e..ca754d66d 100644 --- a/lib/Doctrine/ORM/QueryBuilder.php +++ b/lib/Doctrine/ORM/QueryBuilder.php @@ -469,14 +469,15 @@ class QueryBuilder * $qb = $em->createQueryBuilder() * ->select('u') * ->from('User', 'u') - * ->join('u.articles','a'; + * ->join('u.articles','a'); * * $qb->getAllAliases(); // array('u','a') * * @return array */ - public function getAllAliases() { - return array_merge($this->getRootAliases(),array_keys($this->joinRootAliases)); + public function getAllAliases() + { + return array_merge($this->getRootAliases(), array_keys($this->joinRootAliases)); } /** diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php index 29eb37afc..5d88901a5 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php @@ -117,7 +117,7 @@ class PhpExporter extends AbstractExporter $oneToOneMappingArray = array( 'mappedBy' => $associationMapping['mappedBy'], 'inversedBy' => $associationMapping['inversedBy'], - 'joinColumns' => $associationMapping['joinColumns'], + 'joinColumns' => $associationMapping['isOwningSide'] ? $associationMapping['joinColumns'] : [], 'orphanRemoval' => $associationMapping['orphanRemoval'], ); diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php index 177cebfab..7677ad950 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php @@ -163,7 +163,7 @@ class YamlExporter extends AbstractExporter } if ($associationMapping['type'] & ClassMetadataInfo::TO_ONE) { - $joinColumns = $associationMapping['joinColumns']; + $joinColumns = $associationMapping['isOwningSide'] ? $associationMapping['joinColumns'] : []; $newJoinColumns = array(); foreach ($joinColumns as $joinColumn) { diff --git a/lib/Doctrine/ORM/Tools/Export/ExportException.php b/lib/Doctrine/ORM/Tools/Export/ExportException.php index 89ddfe22e..853159f17 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 @@ class ExportException extends ORMException { 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 e44be6c57..2cfd029df 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 ff0c6b363..628bd4cd1 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 fc431227f..5d59722ed 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; @@ -18,18 +24,9 @@ use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Platforms\PostgreSqlPlatform; use Doctrine\DBAL\Platforms\SQLAnywherePlatform; use Doctrine\DBAL\Platforms\SQLServerPlatform; -use Doctrine\ORM\Query\AST\ArithmeticExpression; -use Doctrine\ORM\Query\AST\ArithmeticFactor; -use Doctrine\ORM\Query\AST\ArithmeticTerm; -use Doctrine\ORM\Query\AST\Literal; use Doctrine\ORM\Query\AST\OrderByClause; -use Doctrine\ORM\Query\AST\OrderByItem; use Doctrine\ORM\Query\AST\PartialObjectExpression; -use Doctrine\ORM\Query\AST\PathExpression; use Doctrine\ORM\Query\AST\SelectExpression; -use Doctrine\ORM\Query\AST\SimpleArithmeticExpression; -use Doctrine\ORM\Query\Expr\OrderBy; -use Doctrine\ORM\Query\Expr\Select; use Doctrine\ORM\Query\SqlWalker; use Doctrine\ORM\Query\AST\SelectStatement; diff --git a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php index d65ab6cfe..b2a292ad9 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php @@ -1,26 +1,26 @@ - * @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; use Doctrine\DBAL\Types\Type; use Doctrine\ORM\Mapping\ClassMetadataInfo; -use Doctrine\ORM\ORMException; use Doctrine\ORM\Query; use Doctrine\ORM\Query\TreeWalkerAdapter; use Doctrine\ORM\Query\AST\Functions\IdentityFunction; diff --git a/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php b/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php index 9f42a1eea..1f54da100 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 03222700c..3f5799a4d 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 79d4670ad..99262f103 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; diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 7d7da9754..59ee1c1cb 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -49,7 +49,6 @@ use Doctrine\ORM\Persisters\Entity\JoinedSubclassPersister; use Doctrine\ORM\Persisters\Collection\OneToManyPersister; use Doctrine\ORM\Persisters\Collection\ManyToManyPersister; use Doctrine\ORM\Utility\IdentifierFlattener; -use Doctrine\ORM\Cache\AssociationCacheEntry; /** * The UnitOfWork is responsible for tracking changes to objects during an @@ -1156,9 +1155,8 @@ class UnitOfWork implements PropertyChangedListener } $joinColumns = reset($assoc['joinColumns']); - $isNullable = isset($joinColumns['nullable']) ? $joinColumns['nullable'] : false; - $calc->addDependency($targetClass->name, $class->name, $isNullable ? 0 : 1); + $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) { @@ -1281,7 +1279,7 @@ class UnitOfWork implements PropertyChangedListener $extraUpdate = array($entity, $changeset); if (isset($this->extraUpdates[$oid])) { - list($ignored, $changeset2) = $this->extraUpdates[$oid]; + list(, $changeset2) = $this->extraUpdates[$oid]; $extraUpdate = array($entity, $changeset + $changeset2); } @@ -1345,9 +1343,7 @@ class UnitOfWork implements PropertyChangedListener $this->removeFromIdentityMap($entity); - if (isset($this->entityUpdates[$oid])) { - unset($this->entityUpdates[$oid]); - } + unset($this->entityUpdates[$oid]); if ( ! isset($this->entityDeletions[$oid])) { $this->entityDeletions[$oid] = $entity; @@ -1402,12 +1398,13 @@ class UnitOfWork implements PropertyChangedListener 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 (empty($identifier) || in_array(null, $identifier, true)) { throw ORMInvalidArgumentException::entityWithoutIdentity($classMetadata->name, $entity); } + $idHash = implode(' ', $identifier); $className = $classMetadata->rootEntityName; if (isset($this->identityMap[$className][$idHash])) { @@ -1569,11 +1566,9 @@ class UnitOfWork implements PropertyChangedListener { $stringIdHash = (string) $idHash; - if (isset($this->identityMap[$rootClassName][$stringIdHash])) { - return $this->identityMap[$rootClassName][$stringIdHash]; - } - - return false; + return isset($this->identityMap[$rootClassName][$stringIdHash]) + ? $this->identityMap[$rootClassName][$stringIdHash] + : false; } /** @@ -1797,7 +1792,7 @@ class UnitOfWork implements PropertyChangedListener * @throws ORMInvalidArgumentException If the entity instance is NEW. * @throws EntityNotFoundException */ - private function doMerge($entity, array &$visited, $prevManagedCopy = null, $assoc = null) + private function doMerge($entity, array &$visited, $prevManagedCopy = null, array $assoc = []) { $oid = spl_object_hash($entity); @@ -2391,17 +2386,8 @@ class UnitOfWork implements PropertyChangedListener $this->visitedCollections = $this->orphanRemovals = array(); } else { - $visited = array(); - - foreach ($this->identityMap as $className => $entities) { - if ($className !== $entityName) { - continue; - } - - foreach ($entities as $entity) { - $this->doDetach($entity, $visited, false); - } - } + $this->clearIdentityMapForEntityName($entityName); + $this->clearEntityInsertionsForEntityName($entityName); } if ($this->evm->hasListeners(Events::onClear)) { @@ -2455,9 +2441,7 @@ class UnitOfWork implements PropertyChangedListener // TODO: if $coll is already scheduled for recreation ... what to do? // Just remove $coll from the scheduled recreations? - if (isset($this->collectionUpdates[$coid])) { - unset($this->collectionUpdates[$coid]); - } + unset($this->collectionUpdates[$coid]); $this->collectionDeletions[$coid] = $coll; } @@ -2864,11 +2848,9 @@ class UnitOfWork implements PropertyChangedListener { $oid = spl_object_hash($entity); - if (isset($this->originalEntityData[$oid])) { - return $this->originalEntityData[$oid]; - } - - return array(); + return isset($this->originalEntityData[$oid]) + ? $this->originalEntityData[$oid] + : []; } /** @@ -2954,11 +2936,9 @@ class UnitOfWork implements PropertyChangedListener { $idHash = implode(' ', (array) $id); - if (isset($this->identityMap[$rootClassName][$idHash])) { - return $this->identityMap[$rootClassName][$idHash]; - } - - return false; + return isset($this->identityMap[$rootClassName][$idHash]) + ? $this->identityMap[$rootClassName][$idHash] + : false; } /** @@ -2995,7 +2975,7 @@ class UnitOfWork implements PropertyChangedListener */ public function size() { - $countArray = array_map(function ($item) { return count($item); }, $this->identityMap); + $countArray = array_map('count', $this->identityMap); return array_sum($countArray); } @@ -3424,8 +3404,6 @@ class UnitOfWork implements PropertyChangedListener ); $managedCol->setOwner($managedCopy, $assoc2); $prop->setValue($managedCopy, $managedCol); - - $this->originalEntityData[spl_object_hash($entity)][$name] = $managedCol; } if ($assoc2['isCascadeMerge']) { @@ -3464,4 +3442,33 @@ class UnitOfWork implements PropertyChangedListener { $this->hydrationCompleteHandler->hydrationComplete(); } + + /** + * @param string $entityName + */ + private function clearIdentityMapForEntityName($entityName) + { + if (! isset($this->identityMap[$entityName])) { + return; + } + + $visited = []; + + foreach ($this->identityMap[$entityName] as $entity) { + $this->doDetach($entity, $visited, false); + } + } + + /** + * @param string $entityName + */ + private function clearEntityInsertionsForEntityName($entityName) + { + foreach ($this->entityInsertions as $hash => $entity) { + // note: performance optimization - `instanceof` is much faster than a function call + if ($entity instanceof $entityName && get_class($entity) === $entityName) { + unset($this->entityInsertions[$hash]); + } + } + } } diff --git a/tests/Doctrine/Tests/DbalTypes/CustomIdObject.php b/tests/Doctrine/Tests/DbalTypes/CustomIdObject.php index df34ebccb..d777d2dc4 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 3d5aa0c19..f59ab151c 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/EventListener/CacheMetadataListener.php b/tests/Doctrine/Tests/EventListener/CacheMetadataListener.php index 7a7caf18e..f27e38c47 100644 --- a/tests/Doctrine/Tests/EventListener/CacheMetadataListener.php +++ b/tests/Doctrine/Tests/EventListener/CacheMetadataListener.php @@ -40,7 +40,7 @@ class CacheMetadataListener * * @return bool */ - private function isVisited(ClassMetaData $metadata) + private function isVisited(ClassMetadata $metadata) { return isset($this->enabledItems[$metadata->getName()]); } @@ -48,7 +48,7 @@ class CacheMetadataListener /** * @param ClassMetadata $metadata */ - private function recordVisit(ClassMetaData $metadata) + private function recordVisit(ClassMetadata $metadata) { $this->enabledItems[$metadata->getName()] = true; } diff --git a/tests/Doctrine/Tests/Mocks/ClassMetadataMock.php b/tests/Doctrine/Tests/Mocks/ClassMetadataMock.php index deab5239a..599c4996f 100644 --- a/tests/Doctrine/Tests/Mocks/ClassMetadataMock.php +++ b/tests/Doctrine/Tests/Mocks/ClassMetadataMock.php @@ -2,10 +2,12 @@ namespace Doctrine\Tests\Mocks; +use Doctrine\ORM\Mapping\ClassMetadata; + /** * Mock class for ClassMetadata. */ -class ClassMetadataMock extends \Doctrine\ORM\Mapping\ClassMetadata +class ClassMetadataMock extends ClassMetadata { /* Mock API */ diff --git a/tests/Doctrine/Tests/Mocks/ConnectionMock.php b/tests/Doctrine/Tests/Mocks/ConnectionMock.php index 5cf9dae4d..49ca3e4ea 100644 --- a/tests/Doctrine/Tests/Mocks/ConnectionMock.php +++ b/tests/Doctrine/Tests/Mocks/ConnectionMock.php @@ -1,11 +1,12 @@ _schemaManagerMock == null) { return new SchemaManagerMock($conn); @@ -55,7 +60,7 @@ class DriverMock implements \Doctrine\DBAL\Driver * * @return void */ - public function setDatabasePlatform(\Doctrine\DBAL\Platforms\AbstractPlatform $platform) + public function setDatabasePlatform(AbstractPlatform $platform) { $this->_platformMock = $platform; } @@ -65,7 +70,7 @@ class DriverMock implements \Doctrine\DBAL\Driver * * @return void */ - public function setSchemaManager(\Doctrine\DBAL\Schema\AbstractSchemaManager $sm) + public function setSchemaManager(AbstractSchemaManager $sm) { $this->_schemaManagerMock = $sm; } @@ -81,7 +86,7 @@ class DriverMock implements \Doctrine\DBAL\Driver /** * {@inheritdoc} */ - public function getDatabase(\Doctrine\DBAL\Connection $conn) + public function getDatabase(Connection $conn) { return; } diff --git a/tests/Doctrine/Tests/Mocks/EntityManagerMock.php b/tests/Doctrine/Tests/Mocks/EntityManagerMock.php index 74f4efcf0..6f98e3c50 100644 --- a/tests/Doctrine/Tests/Mocks/EntityManagerMock.php +++ b/tests/Doctrine/Tests/Mocks/EntityManagerMock.php @@ -1,32 +1,15 @@ . - */ namespace Doctrine\Tests\Mocks; -use Doctrine\ORM\Proxy\ProxyFactory; +use Doctrine\Common\EventManager; +use Doctrine\ORM\Configuration; +use Doctrine\ORM\EntityManager; /** * Special EntityManager mock used for testing purposes. */ -class EntityManagerMock extends \Doctrine\ORM\EntityManager +class EntityManagerMock extends EntityManager { /** * @var \Doctrine\ORM\UnitOfWork|null @@ -83,17 +66,16 @@ class EntityManagerMock extends \Doctrine\ORM\EntityManager * * {@inheritdoc} */ - public static function create($conn, \Doctrine\ORM\Configuration $config = null, - \Doctrine\Common\EventManager $eventManager = null) + public static function create($conn, Configuration $config = null, EventManager $eventManager = null) { if (null === $config) { - $config = new \Doctrine\ORM\Configuration(); + $config = new Configuration(); $config->setProxyDir(__DIR__ . '/../Proxies'); $config->setProxyNamespace('Doctrine\Tests\Proxies'); $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(array(), true)); } if (null === $eventManager) { - $eventManager = new \Doctrine\Common\EventManager(); + $eventManager = new EventManager(); } return new EntityManagerMock($conn, $config, $eventManager); diff --git a/tests/Doctrine/Tests/Mocks/EntityPersisterMock.php b/tests/Doctrine/Tests/Mocks/EntityPersisterMock.php index 761ec4bc1..6130f58f3 100644 --- a/tests/Doctrine/Tests/Mocks/EntityPersisterMock.php +++ b/tests/Doctrine/Tests/Mocks/EntityPersisterMock.php @@ -3,11 +3,13 @@ namespace Doctrine\Tests\Mocks; use Doctrine\Common\Collections\Criteria; +use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Persisters\Entity\BasicEntityPersister; /** * EntityPersister implementation used for mocking during tests. */ -class EntityPersisterMock extends \Doctrine\ORM\Persisters\Entity\BasicEntityPersister +class EntityPersisterMock extends BasicEntityPersister { /** * @var array @@ -52,7 +54,7 @@ class EntityPersisterMock extends \Doctrine\ORM\Persisters\Entity\BasicEntityPer public function addInsert($entity) { $this->inserts[] = $entity; - if ( ! is_null($this->mockIdGeneratorType) && $this->mockIdGeneratorType == \Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_IDENTITY + if ( ! is_null($this->mockIdGeneratorType) && $this->mockIdGeneratorType == ClassMetadata::GENERATOR_TYPE_IDENTITY || $this->class->isIdGeneratorIdentity()) { $id = $this->identityColumnValueCounter++; $this->postInsertIds[] = array( diff --git a/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php b/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php index 5930db12c..7afec2c60 100644 --- a/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php +++ b/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php @@ -2,13 +2,15 @@ namespace Doctrine\Tests\Mocks; +use Doctrine\DBAL\Driver\Statement; + /** * This class is a mock of the Statement interface that can be passed in to the Hydrator * to test the hydration standalone with faked result sets. * * @author Roman Borschel */ -class HydratorMockStatement implements \IteratorAggregate, \Doctrine\DBAL\Driver\Statement +class HydratorMockStatement implements \IteratorAggregate, Statement { /** * @var array diff --git a/tests/Doctrine/Tests/Mocks/MetadataDriverMock.php b/tests/Doctrine/Tests/Mocks/MetadataDriverMock.php index 21339c5f9..b691ec02c 100644 --- a/tests/Doctrine/Tests/Mocks/MetadataDriverMock.php +++ b/tests/Doctrine/Tests/Mocks/MetadataDriverMock.php @@ -2,15 +2,18 @@ namespace Doctrine\Tests\Mocks; +use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; +use Doctrine\Common\Persistence\Mapping\ClassMetadata; + /** * Mock class for MappingDriver. */ -class MetadataDriverMock implements \Doctrine\Common\Persistence\Mapping\Driver\MappingDriver +class MetadataDriverMock implements MappingDriver { /** * {@inheritdoc} */ - public function loadMetadataForClass($className, \Doctrine\Common\Persistence\Mapping\ClassMetadata $metadata) + public function loadMetadataForClass($className, ClassMetadata $metadata) { } diff --git a/tests/Doctrine/Tests/Mocks/MockTreeWalker.php b/tests/Doctrine/Tests/Mocks/MockTreeWalker.php index fd6c81815..0edb8581a 100644 --- a/tests/Doctrine/Tests/Mocks/MockTreeWalker.php +++ b/tests/Doctrine/Tests/Mocks/MockTreeWalker.php @@ -2,10 +2,12 @@ namespace Doctrine\Tests\Mocks; +use Doctrine\ORM\Query\TreeWalkerAdapter; + /** * Mock class for TreeWalker. */ -class MockTreeWalker extends \Doctrine\ORM\Query\TreeWalkerAdapter +class MockTreeWalker extends TreeWalkerAdapter { /** * {@inheritdoc} diff --git a/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php b/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php index 02c7c0a79..5de33a049 100644 --- a/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php +++ b/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php @@ -2,15 +2,18 @@ namespace Doctrine\Tests\Mocks; +use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Schema\AbstractSchemaManager; + /** * Mock class for AbstractSchemaManager. */ -class SchemaManagerMock extends \Doctrine\DBAL\Schema\AbstractSchemaManager +class SchemaManagerMock extends AbstractSchemaManager { /** * @param \Doctrine\DBAL\Connection $conn */ - public function __construct(\Doctrine\DBAL\Connection $conn) + public function __construct(Connection $conn) { parent::__construct($conn); } diff --git a/tests/Doctrine/Tests/Mocks/SequenceMock.php b/tests/Doctrine/Tests/Mocks/SequenceMock.php index 4f5123004..fc6c10f41 100644 --- a/tests/Doctrine/Tests/Mocks/SequenceMock.php +++ b/tests/Doctrine/Tests/Mocks/SequenceMock.php @@ -3,11 +3,12 @@ namespace Doctrine\Tests\Mocks; use Doctrine\ORM\EntityManager; +use Doctrine\ORM\Id\SequenceGenerator; /** * Mock class for SequenceGenerator. */ -class SequenceMock extends \Doctrine\ORM\Id\SequenceGenerator +class SequenceMock extends SequenceGenerator { /** * @var int diff --git a/tests/Doctrine/Tests/Mocks/StatementArrayMock.php b/tests/Doctrine/Tests/Mocks/StatementArrayMock.php index 4054b9a9e..9ef37da46 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/StatementMock.php b/tests/Doctrine/Tests/Mocks/StatementMock.php index 40ad1f3e5..8107ff1be 100644 --- a/tests/Doctrine/Tests/Mocks/StatementMock.php +++ b/tests/Doctrine/Tests/Mocks/StatementMock.php @@ -2,12 +2,14 @@ namespace Doctrine\Tests\Mocks; +use Doctrine\DBAL\Driver\Statement; + /** * This class is a mock of the Statement interface. * * @author Alexander */ -class StatementMock implements \IteratorAggregate, \Doctrine\DBAL\Driver\Statement +class StatementMock implements \IteratorAggregate, Statement { /** * {@inheritdoc} diff --git a/tests/Doctrine/Tests/Mocks/TaskMock.php b/tests/Doctrine/Tests/Mocks/TaskMock.php index 22676f67a..f097abc03 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/Mocks/UnitOfWorkMock.php b/tests/Doctrine/Tests/Mocks/UnitOfWorkMock.php index c846bca1c..3d7361e7f 100644 --- a/tests/Doctrine/Tests/Mocks/UnitOfWorkMock.php +++ b/tests/Doctrine/Tests/Mocks/UnitOfWorkMock.php @@ -2,10 +2,12 @@ namespace Doctrine\Tests\Mocks; +use Doctrine\ORM\UnitOfWork; + /** * Mock class for UnitOfWork. */ -class UnitOfWorkMock extends \Doctrine\ORM\UnitOfWork +class UnitOfWorkMock extends UnitOfWork { /** * @var array diff --git a/tests/Doctrine/Tests/Models/CMS/CmsGroup.php b/tests/Doctrine/Tests/Models/CMS/CmsGroup.php index b65ae8557..9707d8cc2 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 3045c647b..0460676fc 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 58afe8128..4f94dad13 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 @@ class DDC1476EntityWithDefaultFieldType $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_NONE); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Models/DDC2504/DDC2504RootClass.php b/tests/Doctrine/Tests/Models/DDC2504/DDC2504RootClass.php index 18edd75a3..22828b016 100644 --- a/tests/Doctrine/Tests/Models/DDC2504/DDC2504RootClass.php +++ b/tests/Doctrine/Tests/Models/DDC2504/DDC2504RootClass.php @@ -20,7 +20,7 @@ class DDC2504RootClass public $id; /** - * @var Doctrine\Tests\Models\DDC\DDC2504OtherClass + * @var \Doctrine\Tests\Models\DDC2504\DDC2504OtherClass * * @ManyToOne(targetEntity="DDC2504OtherClass", inversedBy="childClasses") */ diff --git a/tests/Doctrine/Tests/Models/DDC3293/DDC3293User.php b/tests/Doctrine/Tests/Models/DDC3293/DDC3293User.php index 25ed140ea..4df5f9b68 100644 --- a/tests/Doctrine/Tests/Models/DDC3293/DDC3293User.php +++ b/tests/Doctrine/Tests/Models/DDC3293/DDC3293User.php @@ -10,7 +10,7 @@ class DDC3293User protected $id; /** - * @var Doctrine\Tests\Models\DDC3293\DDC3293Address + * @var \Doctrine\Tests\Models\DDC3293\DDC3293Address */ protected $address; } diff --git a/tests/Doctrine/Tests/Models/DDC3293/DDC3293UserPrefixed.php b/tests/Doctrine/Tests/Models/DDC3293/DDC3293UserPrefixed.php index a70b26756..d83da15af 100644 --- a/tests/Doctrine/Tests/Models/DDC3293/DDC3293UserPrefixed.php +++ b/tests/Doctrine/Tests/Models/DDC3293/DDC3293UserPrefixed.php @@ -10,7 +10,7 @@ class DDC3293UserPrefixed protected $id; /** - * @var Doctrine\Tests\Models\DDC3293\DDC3293Address + * @var \Doctrine\Tests\Models\DDC3293\DDC3293Address */ protected $address; } diff --git a/tests/Doctrine/Tests/Models/DDC3579/DDC3579Admin.php b/tests/Doctrine/Tests/Models/DDC3579/DDC3579Admin.php index cc9803d44..effedc3c4 100644 --- a/tests/Doctrine/Tests/Models/DDC3579/DDC3579Admin.php +++ b/tests/Doctrine/Tests/Models/DDC3579/DDC3579Admin.php @@ -2,8 +2,6 @@ namespace Doctrine\Tests\Models\DDC3579; -use Doctrine\Common\Collections\ArrayCollection; - /** * @Entity * @AssociationOverrides({ diff --git a/tests/Doctrine/Tests/Models/DDC3711/DDC3711EntityA.php b/tests/Doctrine/Tests/Models/DDC3711/DDC3711EntityA.php index 3146969ed..ecbfd5277 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 @@ class DDC3711EntityA 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 ff589e092..48c4fd860 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 @@ class DDC3711EntityB $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 eaf9006c7..783faef61 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 @@ class DDC753CustomRepository extends EntityRepository 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 5be9aa522..1a3e071fa 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 @@ class DDC753DefaultRepository extends EntityRepository 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 7b92e66ac..7a9ce8d83 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 8ca2a2c94..6f448755f 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 d12660cf4..e480e912c 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 9f0937aa1..4e8c7bad7 100644 --- a/tests/Doctrine/Tests/Models/DDC753/DDC753InvalidRepository.php +++ b/tests/Doctrine/Tests/Models/DDC753/DDC753InvalidRepository.php @@ -1,28 +1,8 @@ . - */ - namespace Doctrine\Tests\Models\DDC753; -use Doctrine\ORM\EntityRepository; - 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 a9f548ffc..00e5da017 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 @@ class DDC869ChequePayment extends DDC869Payment )); } -} \ 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 cd637b3c0..4c1f8c306 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 @@ class DDC869CreditCardPayment extends DDC869Payment )); } -} \ 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 01e7fbefd..ea052d12e 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 @@ class DDC869Payment $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 f950df0e0..3c11b154b 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 @@ class DDC869PaymentRepository extends EntityRepository { 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 7520568b0..8bba1274c 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 @@ class DDC889Class extends DDC889SuperClass $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 59cd21a61..43884435f 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 @@ class DDC889Entity extends DDC889SuperClass { } -} \ 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 7cffe488b..42fd93386 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 @@ class DDC889SuperClass $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/DDC964/DDC964Admin.php b/tests/Doctrine/Tests/Models/DDC964/DDC964Admin.php index 464471b31..110326b2c 100644 --- a/tests/Doctrine/Tests/Models/DDC964/DDC964Admin.php +++ b/tests/Doctrine/Tests/Models/DDC964/DDC964Admin.php @@ -2,8 +2,6 @@ namespace Doctrine\Tests\Models\DDC964; -use Doctrine\Common\Collections\ArrayCollection; - /** * @Entity * @AssociationOverrides({ diff --git a/tests/Doctrine/Tests/Models/DDC964/DDC964Guest.php b/tests/Doctrine/Tests/Models/DDC964/DDC964Guest.php index 935ee59c0..cb64d15fa 100644 --- a/tests/Doctrine/Tests/Models/DDC964/DDC964Guest.php +++ b/tests/Doctrine/Tests/Models/DDC964/DDC964Guest.php @@ -2,8 +2,6 @@ namespace Doctrine\Tests\Models\DDC964; -use Doctrine\Common\Collections\ArrayCollection; - /** * @Entity * @AttributeOverrides({ diff --git a/tests/Doctrine/Tests/Models/DirectoryTree/AbstractContentItem.php b/tests/Doctrine/Tests/Models/DirectoryTree/AbstractContentItem.php index d2ba439a0..166f86cb0 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 f0db778b8..cb3729974 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 428daad8b..2e18a06cf 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/Models/Issue5989/Issue5989Employee.php b/tests/Doctrine/Tests/Models/Issue5989/Issue5989Employee.php new file mode 100644 index 000000000..9f5e248d8 --- /dev/null +++ b/tests/Doctrine/Tests/Models/Issue5989/Issue5989Employee.php @@ -0,0 +1,17 @@ +getMock('Doctrine\ORM\Cache\Logging\CacheLogger'); + $logger = $this->createMock(CacheLogger::class); $this->assertNull($this->config->getCacheLogger()); @@ -53,7 +57,7 @@ class CacheConfigTest extends DoctrineTestCase public function testSetGetCacheFactory() { - $factory = $this->getMock('Doctrine\ORM\Cache\CacheFactory'); + $factory = $this->createMock(CacheFactory::class); $this->assertNull($this->config->getCacheFactory()); @@ -64,7 +68,12 @@ class CacheConfigTest extends DoctrineTestCase public function testSetGetQueryValidator() { - $validator = $this->getMock('Doctrine\ORM\Cache\QueryCacheValidator'); + $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()); @@ -72,4 +81,4 @@ class CacheConfigTest extends DoctrineTestCase $this->assertEquals($validator, $this->config->getQueryValidator()); } -} \ 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 e0fd5d2a4..39c28af1e 100644 --- a/tests/Doctrine/Tests/ORM/Cache/CacheKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/CacheKeyTest.php @@ -4,11 +4,12 @@ namespace Doctrine\Tests\ORM\Cache; use Doctrine\ORM\Cache\EntityCacheKey; use Doctrine\ORM\Cache\CollectionCacheKey; +use Doctrine\Tests\DoctrineTestCase; /** * @group DDC-2183 */ -class CacheKeyTest extends \Doctrine\Tests\DoctrineTestCase +class CacheKeyTest extends DoctrineTestCase { public function testEntityCacheKeyIdentifierCollision() { diff --git a/tests/Doctrine/Tests/ORM/Cache/CacheLoggerChainTest.php b/tests/Doctrine/Tests/ORM/Cache/CacheLoggerChainTest.php index 8f8c65c0f..0af90cb07 100644 --- a/tests/Doctrine/Tests/ORM/Cache/CacheLoggerChainTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/CacheLoggerChainTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Cache; +use Doctrine\ORM\Cache\Logging\CacheLogger; use Doctrine\ORM\Cache\Logging\CacheLoggerChain; use Doctrine\ORM\Cache\CollectionCacheKey; use Doctrine\ORM\Cache\EntityCacheKey; @@ -29,7 +30,7 @@ class CacheLoggerChainTest extends DoctrineTestCase parent::setUp(); $this->logger = new CacheLoggerChain(); - $this->mock = $this->getMock('Doctrine\ORM\Cache\Logging\CacheLogger'); + $this->mock = $this->createMock(CacheLogger::class); } public function testGetAndSetLogger() diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php index cd41726d5..40c997d42 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\ORM\Cache; +use Doctrine\Common\Cache\Cache; +use Doctrine\Common\Cache\CacheProvider; use \Doctrine\Tests\OrmTestCase; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Cache\DefaultCacheFactory; @@ -39,9 +41,10 @@ class DefaultCacheFactoryTest extends OrmTestCase $this->em = $this->_getTestEntityManager(); $this->regionsConfig = new RegionsConfiguration; $arguments = array($this->regionsConfig, $this->getSharedSecondLevelCacheDriverImpl()); - $this->factory = $this->getMock('\Doctrine\ORM\Cache\DefaultCacheFactory', array( - 'getRegion' - ), $arguments); + $this->factory = $this->getMockBuilder(DefaultCacheFactory::class) + ->setMethods(array('getRegion')) + ->setConstructorArgs($arguments) + ->getMock(); } public function testImplementsCacheFactory() @@ -252,7 +255,7 @@ class DefaultCacheFactoryTest extends OrmTestCase /** * @expectedException LogicException - * @expectedExceptionMessage If you what 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 what to use it please provide a valid directory + * @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() { @@ -284,7 +287,7 @@ class DefaultCacheFactoryTest extends OrmTestCase public function testBuildsDefaultCacheRegionFromGenericCacheRegion() { /* @var $cache \Doctrine\Common\Cache\Cache */ - $cache = $this->getMock('Doctrine\Common\Cache\Cache'); + $cache = $this->createMock(Cache::class); $factory = new DefaultCacheFactory($this->regionsConfig, $cache); @@ -300,7 +303,7 @@ class DefaultCacheFactoryTest extends OrmTestCase public function testBuildsMultiGetCacheRegionFromGenericCacheRegion() { /* @var $cache \Doctrine\Common\Cache\CacheProvider */ - $cache = $this->getMockForAbstractClass('Doctrine\Common\Cache\CacheProvider'); + $cache = $this->getMockForAbstractClass(CacheProvider::class); $factory = new DefaultCacheFactory($this->regionsConfig, $cache); diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php index 2d13378d6..8fa09bac6 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Cache; +use Doctrine\Tests\Mocks\TimestampRegionMock; use Doctrine\Tests\OrmTestCase; use Doctrine\Tests\Mocks\CacheRegionMock; use Doctrine\ORM\Cache\DefaultQueryCache; @@ -11,7 +12,7 @@ use Doctrine\ORM\Query\ResultSetMappingBuilder; use Doctrine\Tests\Models\Cache\Country; use Doctrine\Tests\Models\Cache\City; use Doctrine\Tests\Models\Cache\State; -use Doctrine\Tests\Models\Cache\Travel; +use Doctrine\Tests\Models\Cache\Restaurant; use Doctrine\ORM\EntityManagerInterface; use Doctrine\Tests\Models\Generic\BooleanModel; use Doctrine\ORM\Cache\EntityCacheEntry; @@ -67,7 +68,7 @@ class DefaultQueryCacheTest extends OrmTestCase { $this->assertSame($this->region, $this->queryCache->getRegion()); } - + public function testClearShouldEvictRegion() { $this->queryCache->clear(); @@ -176,13 +177,13 @@ class DefaultQueryCacheTest extends OrmTestCase $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' => $city->getName(), 'country' => $country)); + $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)); } $this->assertTrue($this->queryCache->put($key, $rsm, $result)); $this->assertArrayHasKey('put', $this->region->calls); - $this->assertCount(9, $this->region->calls['put']); + $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']); @@ -192,7 +193,11 @@ class DefaultQueryCacheTest extends OrmTestCase $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('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']); } public function testPutToOneAssociationNullQueryResult() @@ -431,7 +436,7 @@ class DefaultQueryCacheTest extends OrmTestCase 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])); @@ -482,6 +487,50 @@ class DefaultQueryCacheTest extends OrmTestCase $this->assertNull($this->queryCache->get($key, $rsm)); } + public function testGetAssociationValue() + { + $reflection = new \ReflectionMethod($this->queryCache, 'getAssociationValue'); + $rsm = new ResultSetMappingBuilder($this->em); + $key = new QueryCacheKey('query.key1', 0); + + $reflection->setAccessible(true); + + $germany = new Country("Germany"); + $bavaria = new State("Bavaria", $germany); + $wurzburg = new City("Würzburg", $bavaria); + $munich = new City("Munich", $bavaria); + + $bavaria->addCity($munich); + $bavaria->addCity($wurzburg); + + $munich->addAttraction(new Restaurant('Reinstoff', $munich)); + $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', array( + 'id' => 'c_id', + 'name' => 'c_name' + )); + $rsm->addJoinedEntityFromClassMetadata(Restaurant::CLASSNAME, 'a', 'c', 'attractions', array( + 'id' => 'a_id', + 'name' => 'a_name' + )); + + $cities = $reflection->invoke($this->queryCache, $rsm, 'c', $bavaria); + $attractions = $reflection->invoke($this->queryCache, $rsm, 'a', $bavaria); + + $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->assertCount(2, $attractions[0]); + $this->assertCount(1, $attractions[1]); + } + /** * @expectedException Doctrine\ORM\Cache\CacheException * @expectedExceptionMessage Second level cache does not support scalar results. @@ -542,7 +591,7 @@ class DefaultQueryCacheTest extends OrmTestCase } -class CacheFactoryDefaultQueryCacheTest extends \Doctrine\ORM\Cache\DefaultCacheFactory +class CacheFactoryDefaultQueryCacheTest extends Cache\DefaultCacheFactory { private $queryCache; private $region; @@ -565,6 +614,6 @@ class CacheFactoryDefaultQueryCacheTest extends \Doctrine\ORM\Cache\DefaultCache public function getTimestampRegion() { - return new \Doctrine\Tests\Mocks\TimestampRegionMock(); + return new TimestampRegionMock(); } } diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultRegionTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultRegionTest.php index 9debdbb34..2bcc1fc21 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultRegionTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultRegionTest.php @@ -2,7 +2,9 @@ namespace Doctrine\Tests\ORM\Cache; +use Doctrine\Common\Cache\ApcCache; use Doctrine\Common\Cache\ArrayCache; +use Doctrine\Common\Cache\Cache; use Doctrine\ORM\Cache\CollectionCacheEntry; use Doctrine\ORM\Cache\Region\DefaultRegion; use Doctrine\Tests\Mocks\CacheEntryMock; @@ -32,8 +34,8 @@ class DefaultRegionTest extends AbstractRegionTest $key = new CacheKeyMock('key'); $entry = new CacheEntryMock(array('value' => 'foo')); - $region1 = new DefaultRegion('region1', new \Doctrine\Common\Cache\ApcCache()); - $region2 = new DefaultRegion('region2', new \Doctrine\Common\Cache\ApcCache()); + $region1 = new DefaultRegion('region1', new ApcCache()); + $region2 = new DefaultRegion('region2', new ApcCache()); $this->assertFalse($region1->contains($key)); $this->assertFalse($region2->contains($key)); @@ -65,11 +67,11 @@ class DefaultRegionTest extends AbstractRegionTest public function testEvictAllWithGenericCacheThrowsUnsupportedException() { /* @var $cache \Doctrine\Common\Cache\Cache */ - $cache = $this->getMock('Doctrine\Common\Cache\Cache'); + $cache = $this->createMock(Cache::class); $region = new DefaultRegion('foo', $cache); - $this->setExpectedException('BadMethodCallException'); + $this->expectException(\BadMethodCallException::class); $region->evictAll(); } diff --git a/tests/Doctrine/Tests/ORM/Cache/MultiGetRegionTest.php b/tests/Doctrine/Tests/ORM/Cache/MultiGetRegionTest.php index 091ec672a..65d21b93f 100644 --- a/tests/Doctrine/Tests/ORM/Cache/MultiGetRegionTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/MultiGetRegionTest.php @@ -2,12 +2,10 @@ namespace Doctrine\Tests\ORM\Cache; -use Doctrine\Common\Cache\ArrayCache; use Doctrine\Tests\Mocks\CacheEntryMock; use Doctrine\Tests\Mocks\CacheKeyMock; use Doctrine\ORM\Cache\Region\DefaultMultiGetRegion; use Doctrine\ORM\Cache\CollectionCacheEntry; -use Doctrine\ORM\Cache\EntityCacheKey; /** * @author Asmir Mustafic diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/AbstractCollectionPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/AbstractCollectionPersisterTest.php index 0d767aca9..adc8ec0ba 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/AbstractCollectionPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/AbstractCollectionPersisterTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Cache\Persister\Collection; +use Doctrine\ORM\PersistentCollection; use Doctrine\Tests\OrmTestCase; use Doctrine\ORM\Cache\Region; @@ -79,10 +80,9 @@ abstract class AbstractCollectionPersisterTest extends OrmTestCase $this->em = $this->_getTestEntityManager(); $this->region = $this->createRegion(); - $this->collectionPersister = $this->getMock( - 'Doctrine\ORM\Persisters\Collection\CollectionPersister', - $this->collectionPersisterMockMethods - ); + $this->collectionPersister = $this->getMockBuilder(CollectionPersister::class) + ->setMethods($this->collectionPersisterMockMethods) + ->getMock(); } /** @@ -90,7 +90,9 @@ abstract class AbstractCollectionPersisterTest extends OrmTestCase */ protected function createRegion() { - return $this->getMock('Doctrine\ORM\Cache\Region', $this->regionMockMethods); + return $this->getMockBuilder(Region::class) + ->setMethods($this->regionMockMethods) + ->getMock(); } /** @@ -101,7 +103,7 @@ abstract class AbstractCollectionPersisterTest extends OrmTestCase $em = $this->em; $class = $class ?: $this->em->getClassMetadata('Doctrine\Tests\Models\Cache\State'); $assoc = $assoc ?: $class->associationMappings['cities']; - $coll = new \Doctrine\ORM\PersistentCollection($em, $class, $elements ?: new ArrayCollection); + $coll = new PersistentCollection($em, $class, $elements ?: new ArrayCollection); $coll->setOwner($owner, $assoc); $coll->setInitialized(true); diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersisterTest.php index 529da203f..b41d27ab1 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersisterTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Cache\Persister\Collection; +use Doctrine\ORM\Cache\ConcurrentRegion; use Doctrine\ORM\Cache\Lock; use Doctrine\ORM\Cache\Region; use Doctrine\ORM\EntityManager; @@ -40,7 +41,9 @@ class ReadWriteCachedCollectionPersisterTest extends AbstractCollectionPersister */ protected function createRegion() { - return $this->getMock('Doctrine\ORM\Cache\ConcurrentRegion', $this->regionMockMethods); + return $this->getMockBuilder(ConcurrentRegion::class) + ->setMethods($this->regionMockMethods) + ->getMock(); } public function testDeleteShouldLockItem() diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/AbstractEntityPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/AbstractEntityPersisterTest.php index bf94b1e46..83fd3ad85 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/AbstractEntityPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/AbstractEntityPersisterTest.php @@ -99,10 +99,9 @@ abstract class AbstractEntityPersisterTest extends OrmTestCase $this->em = $this->_getTestEntityManager(); $this->region = $this->createRegion(); - $this->entityPersister = $this->getMock( - 'Doctrine\ORM\Persisters\Entity\EntityPersister', - $this->entityPersisterMockMethods - ); + $this->entityPersister = $this->getMockBuilder(EntityPersister::class) + ->setMethods($this->entityPersisterMockMethods) + ->getMock(); } /** @@ -110,7 +109,9 @@ abstract class AbstractEntityPersisterTest extends OrmTestCase */ protected function createRegion() { - return $this->getMock('Doctrine\ORM\Cache\Region', $this->regionMockMethods); + return $this->getMockBuilder(Region::class) + ->setMethods($this->regionMockMethods) + ->getMock(); } /** diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersisterTest.php index 6cf3fea3b..df1f6ac59 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersisterTest.php @@ -2,14 +2,14 @@ namespace Doctrine\Tests\ORM\Cache\Persister\Entity; +use Doctrine\ORM\Cache\EntityCacheEntry; +use Doctrine\ORM\Cache\EntityCacheKey; +use Doctrine\ORM\Cache\Persister\Entity\NonStrictReadWriteCachedEntityPersister; use Doctrine\ORM\Cache\Region; use Doctrine\ORM\EntityManager; -use Doctrine\Tests\Models\Cache\Country; -use Doctrine\ORM\Cache\EntityCacheKey; -use Doctrine\ORM\Cache\EntityCacheEntry; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Persisters\Entity\EntityPersister; -use Doctrine\ORM\Cache\Persister\Entity\NonStrictReadWriteCachedEntityPersister; +use Doctrine\Tests\Models\Cache\Country; /** * @group DDC-2183 @@ -28,7 +28,7 @@ class NonStrictReadWriteCachedEntityPersisterTest extends AbstractEntityPersiste { $entity = new Country("Foo"); $persister = $this->createPersisterDefault(); - $property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister', 'queuedCache'); + $property = new \ReflectionProperty($persister, 'queuedCache'); $property->setAccessible(true); @@ -50,7 +50,7 @@ class NonStrictReadWriteCachedEntityPersisterTest extends AbstractEntityPersiste $persister = $this->createPersisterDefault(); $key = new EntityCacheKey(Country::CLASSNAME, array('id'=>1)); $entry = new EntityCacheEntry(Country::CLASSNAME, array('id'=>1, 'name'=>'Foo')); - $property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister', 'queuedCache'); + $property = new \ReflectionProperty($persister, 'queuedCache'); $property->setAccessible(true); @@ -87,7 +87,7 @@ class NonStrictReadWriteCachedEntityPersisterTest extends AbstractEntityPersiste $persister = $this->createPersisterDefault(); $key = new EntityCacheKey(Country::CLASSNAME, array('id'=>1)); $entry = new EntityCacheEntry(Country::CLASSNAME, array('id'=>1, 'name'=>'Foo')); - $property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister', 'queuedCache'); + $property = new \ReflectionProperty($persister, 'queuedCache'); $property->setAccessible(true); @@ -115,7 +115,7 @@ class NonStrictReadWriteCachedEntityPersisterTest extends AbstractEntityPersiste $entity = new Country("Foo"); $persister = $this->createPersisterDefault(); $key = new EntityCacheKey(Country::CLASSNAME, array('id'=>1)); - $property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister', 'queuedCache'); + $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 054bf951d..dc9fef43a 100644 --- a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersisterTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Cache\Persister\Entity; +use Doctrine\ORM\Cache\ConcurrentRegion; use Doctrine\ORM\Cache\Region; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Cache\Lock; @@ -41,7 +42,9 @@ class ReadWriteCachedEntityPersisterTest extends AbstractEntityPersisterTest */ protected function createRegion() { - return $this->getMock('Doctrine\ORM\Cache\ConcurrentRegion', $this->regionMockMethods); + return $this->getMockBuilder(ConcurrentRegion::class) + ->setConstructorArgs($this->regionMockMethods) + ->getMock(); } public function testDeleteShouldLockItem() diff --git a/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php b/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php index e9bf04459..770ec7deb 100644 --- a/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php +++ b/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php @@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM; use Doctrine\ORM\Internal\CommitOrderCalculator; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\Tests\OrmTestCase; /** * Tests of the commit order calculation. @@ -12,7 +13,7 @@ use Doctrine\ORM\Mapping\ClassMetadata; * can have many valid orderings, so you may want to build a graph that has only * 1 valid order to simplify your tests. */ -class CommitOrderCalculatorTest extends \Doctrine\Tests\OrmTestCase +class CommitOrderCalculatorTest extends OrmTestCase { private $_calc; diff --git a/tests/Doctrine/Tests/ORM/ConfigurationTest.php b/tests/Doctrine/Tests/ORM/ConfigurationTest.php index cb9ec66be..d99d2b1e8 100644 --- a/tests/Doctrine/Tests/ORM/ConfigurationTest.php +++ b/tests/Doctrine/Tests/ORM/ConfigurationTest.php @@ -2,11 +2,18 @@ namespace Doctrine\Tests\ORM; +use Doctrine\Common\Cache\Cache; +use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; use Doctrine\Common\Proxy\AbstractProxyFactory; use Doctrine\Common\Cache\ArrayCache; +use Doctrine\ORM\Cache\CacheConfiguration; use Doctrine\ORM\Mapping as AnnotationNamespace; use Doctrine\ORM\Configuration; +use Doctrine\ORM\Mapping\EntityListenerResolver; +use Doctrine\ORM\Mapping\NamingStrategy; +use Doctrine\ORM\Mapping\QuoteStrategy; use Doctrine\ORM\ORMException; +use Doctrine\ORM\Query\ResultSetMapping; use ReflectionClass; use PHPUnit_Framework_TestCase; @@ -61,7 +68,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase { $this->assertSame(null, $this->configuration->getMetadataDriverImpl()); // defaults - $metadataDriver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver'); + $metadataDriver = $this->createMock(MappingDriver::class); $this->configuration->setMetadataDriverImpl($metadataDriver); $this->assertSame($metadataDriver, $this->configuration->getMetadataDriverImpl()); } @@ -95,14 +102,14 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase $namespaces = array('OtherNamespace' => __NAMESPACE__); $this->configuration->setEntityNamespaces($namespaces); $this->assertSame($namespaces, $this->configuration->getEntityNamespaces()); - $this->setExpectedException('Doctrine\ORM\ORMException'); + $this->expectException(\Doctrine\ORM\ORMException::class); $this->configuration->getEntityNamespace('NonExistingNamespace'); } public function testSetGetQueryCacheImpl() { $this->assertSame(null, $this->configuration->getQueryCacheImpl()); // defaults - $queryCacheImpl = $this->getMock('Doctrine\Common\Cache\Cache'); + $queryCacheImpl = $this->createMock(Cache::class); $this->configuration->setQueryCacheImpl($queryCacheImpl); $this->assertSame($queryCacheImpl, $this->configuration->getQueryCacheImpl()); } @@ -110,7 +117,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase public function testSetGetHydrationCacheImpl() { $this->assertSame(null, $this->configuration->getHydrationCacheImpl()); // defaults - $queryCacheImpl = $this->getMock('Doctrine\Common\Cache\Cache'); + $queryCacheImpl = $this->createMock(Cache::class); $this->configuration->setHydrationCacheImpl($queryCacheImpl); $this->assertSame($queryCacheImpl, $this->configuration->getHydrationCacheImpl()); } @@ -118,7 +125,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase public function testSetGetMetadataCacheImpl() { $this->assertSame(null, $this->configuration->getMetadataCacheImpl()); // defaults - $queryCacheImpl = $this->getMock('Doctrine\Common\Cache\Cache'); + $queryCacheImpl = $this->createMock(Cache::class); $this->configuration->setMetadataCacheImpl($queryCacheImpl); $this->assertSame($queryCacheImpl, $this->configuration->getMetadataCacheImpl()); } @@ -128,19 +135,19 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase $dql = 'SELECT u FROM User u'; $this->configuration->addNamedQuery('QueryName', $dql); $this->assertSame($dql, $this->configuration->getNamedQuery('QueryName')); - $this->setExpectedException('Doctrine\ORM\ORMException'); + $this->expectException(\Doctrine\ORM\ORMException::class); $this->configuration->getNamedQuery('NonExistingQuery'); } public function testAddGetNamedNativeQuery() { $sql = 'SELECT * FROM user'; - $rsm = $this->getMock('Doctrine\ORM\Query\ResultSetMapping'); + $rsm = $this->createMock(ResultSetMapping::class); $this->configuration->addNamedNativeQuery('QueryName', $sql, $rsm); $fetched = $this->configuration->getNamedNativeQuery('QueryName'); $this->assertSame($sql, $fetched[0]); $this->assertSame($rsm, $fetched[1]); - $this->setExpectedException('Doctrine\ORM\ORMException'); + $this->expectException(\Doctrine\ORM\ORMException::class); $this->configuration->getNamedQuery('NonExistingQuery'); } @@ -153,7 +160,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase { $this->configuration->setAutoGenerateProxyClasses(AbstractProxyFactory::AUTOGENERATE_NEVER); - $cache = $this->getMock('Doctrine\Common\Cache\Cache'); + $cache = $this->createMock(Cache::class); if ('query' !== $skipCache) { $this->configuration->setQueryCacheImpl($cache); @@ -173,14 +180,20 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase public function testEnsureProductionSettingsQueryCache() { $this->setProductionSettings('query'); - $this->setExpectedException('Doctrine\ORM\ORMException', 'Query Cache is not configured.'); + + $this->expectException(ORMException::class); + $this->expectExceptionMessage('Query Cache is not configured.'); + $this->configuration->ensureProductionSettings(); } public function testEnsureProductionSettingsMetadataCache() { $this->setProductionSettings('metadata'); - $this->setExpectedException('Doctrine\ORM\ORMException', 'Metadata Cache is not configured.'); + + $this->expectException(ORMException::class); + $this->expectExceptionMessage('Metadata Cache is not configured.'); + $this->configuration->ensureProductionSettings(); } @@ -188,9 +201,10 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase { $this->setProductionSettings(); $this->configuration->setQueryCacheImpl(new ArrayCache()); - $this->setExpectedException( - 'Doctrine\ORM\ORMException', - 'Query Cache uses a non-persistent cache driver, Doctrine\Common\Cache\ArrayCache.'); + + $this->expectException(ORMException::class); + $this->expectExceptionMessage('Query Cache uses a non-persistent cache driver, Doctrine\Common\Cache\ArrayCache.'); + $this->configuration->ensureProductionSettings(); } @@ -198,9 +212,10 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase { $this->setProductionSettings(); $this->configuration->setMetadataCacheImpl(new ArrayCache()); - $this->setExpectedException( - 'Doctrine\ORM\ORMException', - 'Metadata Cache uses a non-persistent cache driver, Doctrine\Common\Cache\ArrayCache.'); + + $this->expectException(ORMException::class); + $this->expectExceptionMessage('Metadata Cache uses a non-persistent cache driver, Doctrine\Common\Cache\ArrayCache.'); + $this->configuration->ensureProductionSettings(); } @@ -208,7 +223,10 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase { $this->setProductionSettings(); $this->configuration->setAutoGenerateProxyClasses(AbstractProxyFactory::AUTOGENERATE_ALWAYS); - $this->setExpectedException('Doctrine\ORM\ORMException', 'Proxy Classes are always regenerating.'); + + $this->expectException(ORMException::class); + $this->expectExceptionMessage('Proxy Classes are always regenerating.'); + $this->configuration->ensureProductionSettings(); } @@ -216,7 +234,10 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase { $this->setProductionSettings(); $this->configuration->setAutoGenerateProxyClasses(AbstractProxyFactory::AUTOGENERATE_FILE_NOT_EXISTS); - $this->setExpectedException('Doctrine\ORM\ORMException', 'Proxy Classes are always regenerating.'); + + $this->expectException(ORMException::class); + $this->expectExceptionMessage('Proxy Classes are always regenerating.'); + $this->configuration->ensureProductionSettings(); } @@ -224,7 +245,10 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase { $this->setProductionSettings(); $this->configuration->setAutoGenerateProxyClasses(AbstractProxyFactory::AUTOGENERATE_EVAL); - $this->setExpectedException('Doctrine\ORM\ORMException', 'Proxy Classes are always regenerating.'); + + $this->expectException(ORMException::class); + $this->expectExceptionMessage('Proxy Classes are always regenerating.'); + $this->configuration->ensureProductionSettings(); } @@ -235,7 +259,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase $this->assertSame(null, $this->configuration->getCustomStringFunction('NonExistingFunction')); $this->configuration->setCustomStringFunctions(array('OtherFunctionName' => __CLASS__)); $this->assertSame(__CLASS__, $this->configuration->getCustomStringFunction('OtherFunctionName')); - $this->setExpectedException('Doctrine\ORM\ORMException'); + $this->expectException(\Doctrine\ORM\ORMException::class); $this->configuration->addCustomStringFunction('concat', __CLASS__); } @@ -246,7 +270,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase $this->assertSame(null, $this->configuration->getCustomNumericFunction('NonExistingFunction')); $this->configuration->setCustomNumericFunctions(array('OtherFunctionName' => __CLASS__)); $this->assertSame(__CLASS__, $this->configuration->getCustomNumericFunction('OtherFunctionName')); - $this->setExpectedException('Doctrine\ORM\ORMException'); + $this->expectException(\Doctrine\ORM\ORMException::class); $this->configuration->addCustomNumericFunction('abs', __CLASS__); } @@ -257,7 +281,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase $this->assertSame(null, $this->configuration->getCustomDatetimeFunction('NonExistingFunction')); $this->configuration->setCustomDatetimeFunctions(array('OtherFunctionName' => __CLASS__)); $this->assertSame(__CLASS__, $this->configuration->getCustomDatetimeFunction('OtherFunctionName')); - $this->setExpectedException('Doctrine\ORM\ORMException'); + $this->expectException(\Doctrine\ORM\ORMException::class); $this->configuration->addCustomDatetimeFunction('date_add', __CLASS__); } @@ -303,14 +327,14 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase $repositoryClass = 'Doctrine\Tests\Models\DDC753\DDC753CustomRepository'; $this->configuration->setDefaultRepositoryClassName($repositoryClass); $this->assertSame($repositoryClass, $this->configuration->getDefaultRepositoryClassName()); - $this->setExpectedException('Doctrine\ORM\ORMException'); + $this->expectException(\Doctrine\ORM\ORMException::class); $this->configuration->setDefaultRepositoryClassName(__CLASS__); } public function testSetGetNamingStrategy() { $this->assertInstanceOf('Doctrine\ORM\Mapping\NamingStrategy', $this->configuration->getNamingStrategy()); - $namingStrategy = $this->getMock('Doctrine\ORM\Mapping\NamingStrategy'); + $namingStrategy = $this->createMock(NamingStrategy::class); $this->configuration->setNamingStrategy($namingStrategy); $this->assertSame($namingStrategy, $this->configuration->getNamingStrategy()); } @@ -318,7 +342,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase public function testSetGetQuoteStrategy() { $this->assertInstanceOf('Doctrine\ORM\Mapping\QuoteStrategy', $this->configuration->getQuoteStrategy()); - $quoteStrategy = $this->getMock('Doctrine\ORM\Mapping\QuoteStrategy'); + $quoteStrategy = $this->createMock(QuoteStrategy::class); $this->configuration->setQuoteStrategy($quoteStrategy); $this->assertSame($quoteStrategy, $this->configuration->getQuoteStrategy()); } @@ -330,7 +354,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase { $this->assertInstanceOf('Doctrine\ORM\Mapping\EntityListenerResolver', $this->configuration->getEntityListenerResolver()); $this->assertInstanceOf('Doctrine\ORM\Mapping\DefaultEntityListenerResolver', $this->configuration->getEntityListenerResolver()); - $resolver = $this->getMock('Doctrine\ORM\Mapping\EntityListenerResolver'); + $resolver = $this->createMock(EntityListenerResolver::class); $this->configuration->setEntityListenerResolver($resolver); $this->assertSame($resolver, $this->configuration->getEntityListenerResolver()); } @@ -340,7 +364,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase */ public function testSetGetSecondLevelCacheConfig() { - $mockClass = $this->getMock('Doctrine\ORM\Cache\CacheConfiguration'); + $mockClass = $this->createMock(CacheConfiguration::class); $this->assertNull($this->configuration->getSecondLevelCacheConfiguration()); $this->configuration->setSecondLevelCacheConfiguration($mockClass); diff --git a/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php b/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php index 849f579fa..c52ce550c 100644 --- a/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php +++ b/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Decorator; -use Doctrine\ORM\Decorator\EntityManagerDecorator; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query\ResultSetMapping; @@ -13,7 +12,7 @@ class EntityManagerDecoratorTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->wrapped = $this->getMock('Doctrine\ORM\EntityManagerInterface'); + $this->wrapped = $this->createMock(EntityManagerInterface::class); $this->decorator = $this->getMockBuilder('Doctrine\ORM\Decorator\EntityManagerDecorator') ->setConstructorArgs(array($this->wrapped)) ->setMethods(null) diff --git a/tests/Doctrine/Tests/ORM/Entity/ConstructorTest.php b/tests/Doctrine/Tests/ORM/Entity/ConstructorTest.php index 4cf98ec5e..117525eca 100644 --- a/tests/Doctrine/Tests/ORM/Entity/ConstructorTest.php +++ b/tests/Doctrine/Tests/ORM/Entity/ConstructorTest.php @@ -2,7 +2,9 @@ namespace Doctrine\Tests\ORM\Entity; -class ConstructorTest extends \Doctrine\Tests\OrmTestCase +use Doctrine\Tests\OrmTestCase; + +class ConstructorTest extends OrmTestCase { public function testFieldInitializationInConstructor() { diff --git a/tests/Doctrine/Tests/ORM/EntityManagerTest.php b/tests/Doctrine/Tests/ORM/EntityManagerTest.php index 37a444a60..cf6fc99a4 100644 --- a/tests/Doctrine/Tests/ORM/EntityManagerTest.php +++ b/tests/Doctrine/Tests/ORM/EntityManagerTest.php @@ -2,7 +2,12 @@ namespace Doctrine\Tests\ORM; -class EntityManagerTest extends \Doctrine\Tests\OrmTestCase +use Doctrine\ORM\ORMException; +use Doctrine\ORM\ORMInvalidArgumentException; +use Doctrine\ORM\Query\ResultSetMapping; +use Doctrine\Tests\OrmTestCase; + +class EntityManagerTest extends OrmTestCase { private $_em; @@ -54,7 +59,7 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase public function testCreateNativeQuery() { - $rsm = new \Doctrine\ORM\Query\ResultSetMapping(); + $rsm = new ResultSetMapping(); $query = $this->_em->createNativeQuery('SELECT foo', $rsm); $this->assertSame('SELECT foo', $query->getSql()); @@ -65,7 +70,7 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase */ public function testCreateNamedNativeQuery() { - $rsm = new \Doctrine\ORM\Query\ResultSetMapping(); + $rsm = new ResultSetMapping(); $this->_em->getConfiguration()->addNamedNativeQuery('foo', 'SELECT foo', $rsm); $query = $this->_em->createNamedNativeQuery('foo'); @@ -139,8 +144,9 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase * @dataProvider dataMethodsAffectedByNoObjectArguments */ public function testThrowsExceptionOnNonObjectValues($methodName) { - $this->setExpectedException('Doctrine\ORM\ORMInvalidArgumentException', - 'EntityManager#'.$methodName.'() expects parameter 1 to be an entity object, NULL given.'); + $this->expectException(ORMInvalidArgumentException::class); + $this->expectExceptionMessage('EntityManager#' . $methodName . '() expects parameter 1 to be an entity object, NULL given.'); + $this->_em->$methodName(null); } @@ -161,7 +167,8 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase */ public function testAffectedByErrorIfClosedException($methodName) { - $this->setExpectedException('Doctrine\ORM\ORMException', 'closed'); + $this->expectException(ORMException::class); + $this->expectExceptionMessage('closed'); $this->_em->close(); $this->_em->$methodName(new \stdClass()); @@ -186,7 +193,9 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase public function testTransactionalThrowsInvalidArgumentExceptionIfNonCallablePassed() { - $this->setExpectedException('InvalidArgumentException', 'Expected argument of type "callable", got "object"'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Expected argument of type "callable", got "object"'); + $this->_em->transactional($this); } diff --git a/tests/Doctrine/Tests/ORM/Event/OnClassMetadataNotFoundEventArgsTest.php b/tests/Doctrine/Tests/ORM/Event/OnClassMetadataNotFoundEventArgsTest.php index 3aad1c04c..54f2feb0d 100644 --- a/tests/Doctrine/Tests/ORM/Event/OnClassMetadataNotFoundEventArgsTest.php +++ b/tests/Doctrine/Tests/ORM/Event/OnClassMetadataNotFoundEventArgsTest.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\ORM; +use Doctrine\Common\Persistence\Mapping\ClassMetadata; +use Doctrine\Common\Persistence\ObjectManager; use Doctrine\ORM\Event\OnClassMetadataNotFoundEventArgs; use PHPUnit_Framework_TestCase; @@ -15,7 +17,7 @@ class OnClassMetadataNotFoundEventArgsTest extends PHPUnit_Framework_TestCase public function testEventArgsMutability() { /* @var $objectManager \Doctrine\Common\Persistence\ObjectManager */ - $objectManager = $this->getMock('Doctrine\Common\Persistence\ObjectManager'); + $objectManager = $this->createMock(ObjectManager::class); $args = new OnClassMetadataNotFoundEventArgs('foo', $objectManager); @@ -25,7 +27,7 @@ class OnClassMetadataNotFoundEventArgsTest extends PHPUnit_Framework_TestCase $this->assertNull($args->getFoundMetadata()); /* @var $metadata \Doctrine\Common\Persistence\Mapping\ClassMetadata */ - $metadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata'); + $metadata = $this->createMock(ClassMetadata::class); $args->setFoundMetadata($metadata); diff --git a/tests/Doctrine/Tests/ORM/Functional/AbstractManyToManyAssociationTestCase.php b/tests/Doctrine/Tests/ORM/Functional/AbstractManyToManyAssociationTestCase.php index d6dd12e8b..37f0fcd29 100644 --- a/tests/Doctrine/Tests/ORM/Functional/AbstractManyToManyAssociationTestCase.php +++ b/tests/Doctrine/Tests/ORM/Functional/AbstractManyToManyAssociationTestCase.php @@ -3,11 +3,12 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Common\Collections\Collection; +use Doctrine\Tests\OrmFunctionalTestCase; /** * Base class for testing a many-to-many association mapping (without inheritance). */ -class AbstractManyToManyAssociationTestCase extends \Doctrine\Tests\OrmFunctionalTestCase +class AbstractManyToManyAssociationTestCase extends OrmFunctionalTestCase { protected $_firstField; protected $_secondField; diff --git a/tests/Doctrine/Tests/ORM/Functional/AdvancedAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/AdvancedAssociationTest.php index 6847d01c3..5546b285e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/AdvancedAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/AdvancedAssociationTest.php @@ -2,14 +2,16 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Query; +use Doctrine\Tests\OrmFunctionalTestCase; /** * Functional tests for the Single Table Inheritance mapping strategy. * * @author robo */ -class AdvancedAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCase +class AdvancedAssociationTest extends OrmFunctionalTestCase { protected function setUp() { parent::setUp(); @@ -151,7 +153,7 @@ class Lemma { private $types; public function __construct() { - $this->types = new \Doctrine\Common\Collections\ArrayCollection(); + $this->types = new ArrayCollection(); } @@ -257,7 +259,7 @@ class Type { private $lemmas; public function __construct(){ - $this->lemmas = new \Doctrine\Common\Collections\ArrayCollection(); + $this->lemmas = new ArrayCollection(); } /** @@ -372,7 +374,7 @@ class Phrase { private $definitions; public function __construct() { - $this->definitions = new \Doctrine\Common\Collections\ArrayCollection; + $this->definitions = new ArrayCollection; } /** @@ -464,7 +466,7 @@ class PhraseType { private $phrases; public function __construct() { - $this->phrases = new \Doctrine\Common\Collections\ArrayCollection; + $this->phrases = new ArrayCollection; } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/AdvancedDqlQueryTest.php b/tests/Doctrine/Tests/ORM/Functional/AdvancedDqlQueryTest.php index 7302a1d6f..a7c35412b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/AdvancedDqlQueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/AdvancedDqlQueryTest.php @@ -4,15 +4,15 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Tests\Models\Company\CompanyEmployee, Doctrine\Tests\Models\Company\CompanyManager, - Doctrine\Tests\Models\Company\CompanyPerson, Doctrine\Tests\Models\Company\CompanyCar; +use Doctrine\Tests\OrmFunctionalTestCase; /** * Functional Query tests. * * @author Benjamin */ -class AdvancedDqlQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase +class AdvancedDqlQueryTest extends OrmFunctionalTestCase { protected function setUp() { diff --git a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php index 29f8fab85..bee055f84 100644 --- a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php @@ -2,16 +2,20 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\ORM\Tools\SchemaTool; +use Doctrine\DBAL\Logging\DebugStack; +use Doctrine\ORM\EntityNotFoundException; +use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\ORMInvalidArgumentException; 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\CmsGroup; use Doctrine\Tests\Models\CMS\CmsArticle; use Doctrine\Tests\Models\CMS\CmsComment; +use Doctrine\Tests\OrmFunctionalTestCase; -class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase +class BasicFunctionalTest extends OrmFunctionalTestCase { protected function setUp() { @@ -67,9 +71,9 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertFalse($this->_em->getUnitOfWork()->isScheduledForDelete($user)); $this->assertFalse($this->_em->getUnitOfWork()->isScheduledForDelete($ph)); $this->assertFalse($this->_em->getUnitOfWork()->isScheduledForDelete($ph2)); - $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($user)); - $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($ph)); - $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($ph2)); + $this->assertEquals(UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($user)); + $this->assertEquals(UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($ph)); + $this->assertEquals(UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($ph2)); } public function testOneToManyAssociationModification() @@ -148,15 +152,15 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $user->username = 'gblanco'; $user->status = 'developer'; - $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($user), "State should be UnitOfWork::STATE_NEW"); + $this->assertEquals(UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($user), "State should be UnitOfWork::STATE_NEW"); $this->_em->persist($user); - $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_MANAGED, $this->_em->getUnitOfWork()->getEntityState($user), "State should be UnitOfWork::STATE_MANAGED"); + $this->assertEquals(UnitOfWork::STATE_MANAGED, $this->_em->getUnitOfWork()->getEntityState($user), "State should be UnitOfWork::STATE_MANAGED"); $this->_em->remove($user); - $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($user), "State should be UnitOfWork::STATE_NEW"); + $this->assertEquals(UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($user), "State should be UnitOfWork::STATE_NEW"); $this->_em->persist($user); $this->_em->flush(); @@ -164,10 +168,10 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->remove($user); - $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_REMOVED, $this->_em->getUnitOfWork()->getEntityState($user), "State should be UnitOfWork::STATE_REMOVED"); + $this->assertEquals(UnitOfWork::STATE_REMOVED, $this->_em->getUnitOfWork()->getEntityState($user), "State should be UnitOfWork::STATE_REMOVED"); $this->_em->flush(); - $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($user), "State should be UnitOfWork::STATE_NEW"); + $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)); } @@ -567,7 +571,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->persist($user); - $article = new \Doctrine\Tests\Models\CMS\CmsArticle(); + $article = new CmsArticle(); $article->text = "Lorem ipsum dolor sunt."; $article->topic = "A Test Article!"; $article->setAuthor($user); @@ -610,7 +614,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $address->user = $user; $user->address = $address; - $article = new \Doctrine\Tests\Models\CMS\CmsArticle(); + $article = new CmsArticle(); $article->text = "Lorem ipsum dolor sunt."; $article->topic = "A Test Article!"; $article->setAuthor($user); @@ -630,7 +634,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress', $user2->address); $oldLogger = $this->_em->getConnection()->getConfiguration()->getSQLLogger(); - $debugStack = new \Doctrine\DBAL\Logging\DebugStack; + $debugStack = new DebugStack(); $this->_em->getConnection()->getConfiguration()->setSQLLogger($debugStack); $this->_em->flush(); @@ -940,7 +944,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase try { $this->_em->merge($user); $this->fail(); - } catch (\Doctrine\ORM\EntityNotFoundException $enfe) {} + } catch (EntityNotFoundException $enfe) {} } /** @@ -997,7 +1001,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $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', \Doctrine\ORM\Mapping\ClassMetadata::FETCH_EAGER) + ->setFetchMode('Doctrine\Tests\Models\CMS\CmsArticle', 'user', ClassMetadata::FETCH_EAGER) ->getSingleResult(); $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $article->user, "It IS a proxy, ..."); $this->assertTrue($article->user->__isInitialized__, "...but its initialized!"); @@ -1043,14 +1047,14 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->clear('Doctrine\Tests\Models\CMS\CmsUser'); - $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_DETACHED, $unitOfWork->getEntityState($user)); - $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_DETACHED, $unitOfWork->getEntityState($article1)); - $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_DETACHED, $unitOfWork->getEntityState($article2)); - $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_MANAGED, $unitOfWork->getEntityState($address)); + $this->assertEquals(UnitOfWork::STATE_DETACHED, $unitOfWork->getEntityState($user)); + $this->assertEquals(UnitOfWork::STATE_DETACHED, $unitOfWork->getEntityState($article1)); + $this->assertEquals(UnitOfWork::STATE_DETACHED, $unitOfWork->getEntityState($article2)); + $this->assertEquals(UnitOfWork::STATE_MANAGED, $unitOfWork->getEntityState($address)); $this->_em->clear(); - $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_DETACHED, $unitOfWork->getEntityState($address)); + $this->assertEquals(UnitOfWork::STATE_DETACHED, $unitOfWork->getEntityState($address)); } public function testFlushManyExplicitEntities() @@ -1115,7 +1119,9 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $user->username = 'domnikl'; $user->status = 'developer'; - $this->setExpectedException('InvalidArgumentException', 'Entity has to be managed or scheduled for removal for single computation'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Entity has to be managed or scheduled for removal for single computation'); + $this->_em->flush($user); } @@ -1192,7 +1198,9 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $article1->author = $user; $user->articles[] = $article1; - $this->setExpectedException('InvalidArgumentException', "A new entity was found through the relationship 'Doctrine\Tests\Models\CMS\CmsUser#articles'"); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("A new entity was found through the relationship 'Doctrine\Tests\Models\CMS\CmsUser#articles'"); + $this->_em->flush($user); } @@ -1288,10 +1296,10 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $user->status = 'developer'; $user->address = $user; - $this->setExpectedException( - 'Doctrine\ORM\ORMInvalidArgumentException', - 'Expected value of type "Doctrine\Tests\Models\CMS\CmsAddress" for association field ' - . '"Doctrine\Tests\Models\CMS\CmsUser#$address", got "Doctrine\Tests\Models\CMS\CmsUser" instead.' + $this->expectException(ORMInvalidArgumentException::class); + $this->expectExceptionMessage( + 'Expected value of type "Doctrine\Tests\Models\CMS\CmsAddress" for association field ' . + '"Doctrine\Tests\Models\CMS\CmsUser#$address", got "Doctrine\Tests\Models\CMS\CmsUser" instead.' ); $this->_em->persist($user); diff --git a/tests/Doctrine/Tests/ORM/Functional/CascadeRemoveOrderTest.php b/tests/Doctrine/Tests/ORM/Functional/CascadeRemoveOrderTest.php index 9fd1648e0..a2392a3e8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CascadeRemoveOrderTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CascadeRemoveOrderTest.php @@ -3,11 +3,12 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Tests\OrmFunctionalTestCase; /** * @group CascadeRemoveOrderTest */ -class CascadeRemoveOrderTest extends \Doctrine\Tests\OrmFunctionalTestCase +class CascadeRemoveOrderTest extends OrmFunctionalTestCase { protected function setUp() { diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php index 9fa1cb8af..697f568ff 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php @@ -6,21 +6,21 @@ 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\CompanyEvent, Doctrine\Tests\Models\Company\CompanyAuction, - Doctrine\Tests\Models\Company\CompanyRaffle, - Doctrine\Tests\Models\Company\CompanyCar; + Doctrine\Tests\Models\Company\CompanyRaffle; use Doctrine\Common\Collections\Criteria; +use Doctrine\Tests\OrmFunctionalTestCase; /** * Functional tests for the Class Table Inheritance mapping strategy. * * @author robo */ -class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase +class ClassTableInheritanceTest extends OrmFunctionalTestCase { - protected function setUp() { + protected function setUp() + { $this->useModelSet('company'); parent::setUp(); //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); @@ -82,7 +82,7 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $query->setParameter(1, 'NewName', 'string'); $query->setParameter(2, 'NewDepartment'); $query->setParameter(3, 100000); - $query->getSql(); + $query->getSQL(); $numUpdated = $query->execute(); $this->assertEquals(1, $numUpdated); diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest2.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest2.php index 9c50a1496..5682bffe1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest2.php +++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest2.php @@ -1,15 +1,18 @@ _schemaTool->createSchema(array( @@ -156,19 +159,23 @@ class CTIRelated2 private $ctiChildren; - public function __construct() { - $this->ctiChildren = new \Doctrine\Common\Collections\ArrayCollection; + public function __construct() + { + $this->ctiChildren = new ArrayCollection(); } - public function getId() { + public function getId() + { return $this->id; } - public function addCTIChild(CTIChild $child) { + public function addCTIChild(CTIChild $child) + { $this->ctiChildren->add($child); } - public function getCTIChildren() { + public function getCTIChildren() + { return $this->ctiChildren; } } diff --git a/tests/Doctrine/Tests/ORM/Functional/ClearEventTest.php b/tests/Doctrine/Tests/ORM/Functional/ClearEventTest.php index 389b09a54..8c234c0f3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ClearEventTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ClearEventTest.php @@ -4,18 +4,15 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\ORM\Event\OnClearEventArgs; use Doctrine\ORM\Events; +use Doctrine\Tests\OrmFunctionalTestCase; /** * ClearEventTest * * @author Michael Ridgway */ -class ClearEventTest extends \Doctrine\Tests\OrmFunctionalTestCase +class ClearEventTest extends OrmFunctionalTestCase { - protected function setUp() { - parent::setUp(); - } - public function testEventIsCalledOnClear() { $listener = new OnClearListener; diff --git a/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php index 2e1cedb39..1df74636c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php @@ -1,13 +1,16 @@ setExpectedException('Doctrine\ORM\Query\QueryException', 'A single-valued association path expression to an entity with a composite primary key is not supported.'); + $this->expectException(QueryException::class); + $this->expectExceptionMessage('A single-valued association path expression to an entity with a composite primary key is not supported.'); + $sql = $this->_em->createQuery($dql)->getSQL(); } @@ -132,13 +137,17 @@ class CompositePrimaryKeyTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testSpecifyUnknownIdentifierPrimaryKeyFails() { - $this->setExpectedException('Doctrine\ORM\ORMException', 'The identifier long is missing for a query of Doctrine\Tests\Models\Navigation\NavPointOfInterest'); + $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)); } public function testUnrecognizedIdentifierFieldsOnGetReference() { - $this->setExpectedException('Doctrine\ORM\ORMException', "Unrecognized identifier fields: 'key1'"); + $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)); } diff --git a/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyWithAssociationsTest.php b/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyWithAssociationsTest.php index 6ded5bb49..b735925e6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyWithAssociationsTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyWithAssociationsTest.php @@ -5,8 +5,9 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Tests\Models\GeoNames\Country; use Doctrine\Tests\Models\GeoNames\Admin1; use Doctrine\Tests\Models\GeoNames\Admin1AlternateName; +use Doctrine\Tests\OrmFunctionalTestCase; -class CompositePrimaryKeyWithAssociationsTest extends \Doctrine\Tests\OrmFunctionalTestCase +class CompositePrimaryKeyWithAssociationsTest extends OrmFunctionalTestCase { public function setUp() { diff --git a/tests/Doctrine/Tests/ORM/Functional/CustomIdObjectTypeTest.php b/tests/Doctrine/Tests/ORM/Functional/CustomIdObjectTypeTest.php index 2e7abf76c..ea6fdfaff 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/DatabaseDriverTest.php b/tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTest.php index 29d718560..37149abfd 100644 --- a/tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\DBAL\Platforms\SQLServerPlatform; +use Doctrine\DBAL\Schema\Table; use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\DBAL\Platforms\PostgreSqlPlatform; @@ -30,10 +31,10 @@ class DatabaseDriverTest extends DatabaseDriverTestCase $this->markTestSkipped('Platform does not support foreign keys.'); } - $user = new \Doctrine\DBAL\Schema\Table("ddc2059_user"); + $user = new Table("ddc2059_user"); $user->addColumn('id', 'integer'); $user->setPrimaryKey(array('id')); - $project = new \Doctrine\DBAL\Schema\Table("ddc2059_project"); + $project = new Table("ddc2059_project"); $project->addColumn('id', 'integer'); $project->addColumn('user_id', 'integer'); $project->addColumn('user', 'string'); @@ -52,7 +53,7 @@ class DatabaseDriverTest extends DatabaseDriverTestCase $this->markTestSkipped('Platform does not support foreign keys.'); } - $table = new \Doctrine\DBAL\Schema\Table("dbdriver_foo"); + $table = new Table("dbdriver_foo"); $table->addColumn('id', 'integer'); $table->setPrimaryKey(array('id')); $table->addColumn('bar', 'string', array('notnull' => false, 'length' => 200)); @@ -83,13 +84,13 @@ class DatabaseDriverTest extends DatabaseDriverTestCase $this->markTestSkipped('Platform does not support foreign keys.'); } - $tableB = new \Doctrine\DBAL\Schema\Table("dbdriver_bar"); + $tableB = new Table("dbdriver_bar"); $tableB->addColumn('id', 'integer'); $tableB->setPrimaryKey(array('id')); $this->_sm->dropAndCreateTable($tableB); - $tableA = new \Doctrine\DBAL\Schema\Table("dbdriver_baz"); + $tableA = new Table("dbdriver_baz"); $tableA->addColumn('id', 'integer'); $tableA->setPrimaryKey(array('id')); $tableA->addColumn('bar_id', 'integer'); @@ -133,15 +134,15 @@ class DatabaseDriverTest extends DatabaseDriverTestCase public function testIgnoreManyToManyTableWithoutFurtherForeignKeyDetails() { - $tableB = new \Doctrine\DBAL\Schema\Table("dbdriver_bar"); + $tableB = new Table("dbdriver_bar"); $tableB->addColumn('id', 'integer'); $tableB->setPrimaryKey(array('id')); - $tableA = new \Doctrine\DBAL\Schema\Table("dbdriver_baz"); + $tableA = new Table("dbdriver_baz"); $tableA->addColumn('id', 'integer'); $tableA->setPrimaryKey(array('id')); - $tableMany = new \Doctrine\DBAL\Schema\Table("dbdriver_bar_baz"); + $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')); @@ -157,7 +158,7 @@ class DatabaseDriverTest extends DatabaseDriverTestCase $this->markTestSkipped('Platform does not support foreign keys.'); } - $table = new \Doctrine\DBAL\Schema\Table("dbdriver_foo"); + $table = new Table("dbdriver_foo"); $table->addColumn('id', 'integer', array('unsigned' => true)); $table->setPrimaryKey(array('id')); diff --git a/tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTestCase.php b/tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTestCase.php index 35fd8b20c..03902c40c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTestCase.php +++ b/tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTestCase.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\ORM\Mapping\Driver\DatabaseDriver; use Doctrine\Tests\OrmFunctionalTestCase; use Doctrine\ORM\Mapping\ClassMetadataInfo; @@ -13,7 +14,7 @@ abstract class DatabaseDriverTestCase extends OrmFunctionalTestCase protected function convertToClassMetadata(array $entityTables, array $manyTables = array()) { $sm = $this->_em->getConnection()->getSchemaManager(); - $driver = new \Doctrine\ORM\Mapping\Driver\DatabaseDriver($sm); + $driver = new DatabaseDriver($sm); $driver->setTables($entityTables, $manyTables); $metadatas = array(); @@ -36,7 +37,7 @@ abstract class DatabaseDriverTestCase extends OrmFunctionalTestCase $metadatas = array(); $sm = $this->_em->getConnection()->getSchemaManager(); - $driver = new \Doctrine\ORM\Mapping\Driver\DatabaseDriver($sm); + $driver = new DatabaseDriver($sm); foreach ($driver->getAllClassNames() as $className) { if (!in_array(strtolower($className), $classNames)) { diff --git a/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php b/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php index b1f7cda9c..e81bd7f8a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php @@ -1,15 +1,17 @@ _schemaTool->createSchema(array( diff --git a/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php b/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php index 85d588880..d067836f7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php @@ -2,20 +2,22 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\ORM\OptimisticLockException; 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\ORM\UnitOfWork; +use Doctrine\Tests\OrmFunctionalTestCase; /** * Description of DetachedEntityTest * * @author robo */ -class DetachedEntityTest extends \Doctrine\Tests\OrmFunctionalTestCase +class DetachedEntityTest extends OrmFunctionalTestCase { - protected function setUp() { + protected function setUp() + { $this->useModelSet('cms'); parent::setUp(); } @@ -216,7 +218,9 @@ class DetachedEntityTest extends \Doctrine\Tests\OrmFunctionalTestCase $sql = "UPDATE cms_articles SET version = version+1 WHERE id = " . $article->id; $this->_em->getConnection()->executeUpdate($sql); - $this->setExpectedException('Doctrine\ORM\OptimisticLockException', 'The optimistic lock failed, version 1 was expected, but is actually 2'); + $this->expectException(OptimisticLockException::class); + $this->expectExceptionMessage('The optimistic lock failed, version 1 was expected, but is actually 2'); + $this->_em->merge($article); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityListenersTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityListenersTest.php index 584795263..89901be19 100644 --- a/tests/Doctrine/Tests/ORM/Functional/EntityListenersTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/EntityListenersTest.php @@ -3,11 +3,12 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Tests\Models\Company\CompanyFixContract; +use Doctrine\Tests\OrmFunctionalTestCase; /** * @group DDC-1955 */ -class EntityListenersTest extends \Doctrine\Tests\OrmFunctionalTestCase +class EntityListenersTest extends OrmFunctionalTestCase { /** diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryCriteriaTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryCriteriaTest.php index 6a626b3f4..76e269a20 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; @@ -23,11 +6,12 @@ use Doctrine\Tests\Models\Generic\DateTimeModel; use Doctrine\Common\Collections\Criteria; use Doctrine\Tests\Models\Tweet\Tweet; use Doctrine\Tests\Models\Tweet\User; +use Doctrine\Tests\OrmFunctionalTestCase; /** * @author Josiah */ -class EntityRepositoryCriteriaTest extends \Doctrine\Tests\OrmFunctionalTestCase +class EntityRepositoryCriteriaTest extends OrmFunctionalTestCase { protected function setUp() { diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php index 705802306..e0b96387a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php @@ -2,19 +2,25 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\DBAL\Connection; +use Doctrine\DBAL\LockMode; +use Doctrine\ORM\OptimisticLockException; +use Doctrine\ORM\ORMException; +use Doctrine\ORM\TransactionRequiredException; 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\Common\Collections\Criteria; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Tests\OrmFunctionalTestCase; /** * @author robo */ -class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase +class EntityRepositoryTest extends OrmFunctionalTestCase { - protected function setUp() { + protected function setUp() + { $this->useModelSet('cms'); parent::setUp(); } @@ -266,6 +272,30 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $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 */ @@ -288,10 +318,10 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase */ public function testPessimisticReadLockWithoutTransaction_ThrowsException() { - $this->setExpectedException('Doctrine\ORM\TransactionRequiredException'); + $this->expectException(TransactionRequiredException::class); $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser') - ->find(1, \Doctrine\DBAL\LockMode::PESSIMISTIC_READ); + ->find(1, LockMode::PESSIMISTIC_READ); } /** @@ -300,10 +330,10 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase */ public function testPessimisticWriteLockWithoutTransaction_ThrowsException() { - $this->setExpectedException('Doctrine\ORM\TransactionRequiredException'); + $this->expectException(TransactionRequiredException::class); $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser') - ->find(1, \Doctrine\DBAL\LockMode::PESSIMISTIC_WRITE); + ->find(1, LockMode::PESSIMISTIC_WRITE); } /** @@ -312,10 +342,10 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase */ public function testOptimisticLockUnversionedEntity_ThrowsException() { - $this->setExpectedException('Doctrine\ORM\OptimisticLockException'); + $this->expectException(OptimisticLockException::class); $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser') - ->find(1, \Doctrine\DBAL\LockMode::OPTIMISTIC); + ->find(1, LockMode::OPTIMISTIC); } /** @@ -335,8 +365,9 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $userId); - $this->setExpectedException('Doctrine\ORM\OptimisticLockException'); - $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $userId, \Doctrine\DBAL\LockMode::OPTIMISTIC); + $this->expectException(OptimisticLockException::class); + + $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $userId, LockMode::OPTIMISTIC); } /** @@ -357,7 +388,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase */ public function testInvalidMagicCall() { - $this->setExpectedException('BadMethodCallException'); + $this->expectException(\BadMethodCallException::class); $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $repos->foo(); @@ -371,7 +402,9 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase list($userId, $addressId) = $this->loadAssociatedFixture(); $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); - $this->setExpectedException('Doctrine\ORM\ORMException', "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."); + $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)); } @@ -457,7 +490,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase { $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); + $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); $repos->createNamedQuery('invalidNamedQuery'); } @@ -655,7 +688,8 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase */ public function testInvalidOrientation() { - $this->setExpectedException('Doctrine\ORM\ORMException', 'Invalid order by orientation specified for Doctrine\Tests\Models\CMS\CmsUser#username'); + $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->findBy(array('status' => 'test'), array('username' => 'INVALID')); @@ -671,7 +705,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $query = array_pop($this->_sqlLoggerStack->queries); $this->assertEquals(array(1,2,3), $query['params'][0]); - $this->assertEquals(\Doctrine\DBAL\Connection::PARAM_INT_ARRAY, $query['types'][0]); + $this->assertEquals(Connection::PARAM_INT_ARRAY, $query['types'][0]); } /** @@ -915,7 +949,8 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase */ public function testFindByFieldInjectionPrevented() { - $this->setExpectedException('Doctrine\ORM\ORMException', 'Unrecognized field: '); + $this->expectException(ORMException::class); + $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')); @@ -926,7 +961,8 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase */ public function testFindOneByFieldInjectionPrevented() { - $this->setExpectedException('Doctrine\ORM\ORMException', 'Unrecognized field: '); + $this->expectException(ORMException::class); + $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')); @@ -937,7 +973,8 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase */ public function testMatchingInjectionPrevented() { - $this->setExpectedException('Doctrine\ORM\ORMException', 'Unrecognized field: '); + $this->expectException(ORMException::class); + $this->expectExceptionMessage('Unrecognized field: '); $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $result = $repository->matching(new Criteria( @@ -953,7 +990,8 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase */ public function testFindInjectionPrevented() { - $this->setExpectedException('Doctrine\ORM\ORMException', 'Unrecognized identifier fields: '); + $this->expectException(ORMException::class); + $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)); diff --git a/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php index 731a0826d..c8af5bd85 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php @@ -3,6 +3,10 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\Tests\Models\CMS\CmsArticle; +use Doctrine\Tests\Models\CMS\CmsGroup; +use Doctrine\Tests\Models\CMS\CmsPhonenumber; +use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\DDC2504\DDC2504ChildClass; use Doctrine\Tests\Models\DDC2504\DDC2504OtherClass; use Doctrine\Tests\Models\Tweet\Tweet; @@ -99,7 +103,7 @@ class ExtraLazyCollectionTest extends OrmFunctionalTestCase { $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); - $newGroup = new \Doctrine\Tests\Models\CMS\CmsGroup(); + $newGroup = new CmsGroup(); $newGroup->name = "Test4"; $user->addGroup($newGroup); @@ -277,7 +281,7 @@ class ExtraLazyCollectionTest extends OrmFunctionalTestCase $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); // Test One to Many existence with state new - $article = new \Doctrine\Tests\Models\CMS\CmsArticle(); + $article = new CmsArticle(); $article->topic = "Testnew"; $article->text = "blub"; @@ -295,7 +299,7 @@ class ExtraLazyCollectionTest extends OrmFunctionalTestCase $this->assertFalse($user->articles->isInitialized(), "Post-Condition: Collection is not initialized."); // Test One to Many existence with state managed - $article = new \Doctrine\Tests\Models\CMS\CmsArticle(); + $article = new CmsArticle(); $article->topic = "How to not fail anymore on tests"; $article->text = "That is simple! Just write more tests!"; @@ -414,7 +418,7 @@ class ExtraLazyCollectionTest extends OrmFunctionalTestCase $this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized."); // Test Many to Many existence with state new - $group = new \Doctrine\Tests\Models\CMS\CmsGroup(); + $group = new CmsGroup(); $group->name = "A New group!"; $queryCount = $this->getCurrentQueryCount(); @@ -434,7 +438,7 @@ class ExtraLazyCollectionTest extends OrmFunctionalTestCase $this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized."); // Test Many to Many existence with state managed - $group = new \Doctrine\Tests\Models\CMS\CmsGroup(); + $group = new CmsGroup(); $group->name = "My managed group"; $this->_em->persist($group); @@ -461,7 +465,7 @@ class ExtraLazyCollectionTest extends OrmFunctionalTestCase $this->assertEquals($queryCount+1, $this->getCurrentQueryCount(), "Checking for contains of managed entity should cause one query to be executed."); $this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized."); - $newUser = new \Doctrine\Tests\Models\CMS\CmsUser(); + $newUser = new CmsUser(); $newUser->name = "A New group!"; $queryCount = $this->getCurrentQueryCount(); @@ -488,7 +492,7 @@ class ExtraLazyCollectionTest extends OrmFunctionalTestCase $this->assertEquals($queryCount, $this->getCurrentQueryCount()); // Test One to Many removal with Entity state as new - $article = new \Doctrine\Tests\Models\CMS\CmsArticle(); + $article = new CmsArticle(); $article->topic = "Testnew"; $article->text = "blub"; @@ -510,7 +514,7 @@ class ExtraLazyCollectionTest extends OrmFunctionalTestCase $this->assertFalse($user->articles->isInitialized(), "Post-Condition: Collection is not initialized."); // Test One to Many removal with Entity state as managed - $article = new \Doctrine\Tests\Models\CMS\CmsArticle(); + $article = new CmsArticle(); $article->topic = "How to not fail anymore on tests"; $article->text = "That is simple! Just write more tests!"; @@ -642,7 +646,7 @@ class ExtraLazyCollectionTest extends OrmFunctionalTestCase $this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized."); // Test Many to Many removal with Entity state as new - $group = new \Doctrine\Tests\Models\CMS\CmsGroup(); + $group = new CmsGroup(); $group->name = "A New group!"; $queryCount = $this->getCurrentQueryCount(); @@ -664,7 +668,7 @@ class ExtraLazyCollectionTest extends OrmFunctionalTestCase $this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized."); // Test Many to Many removal with Entity state as managed - $group = new \Doctrine\Tests\Models\CMS\CmsGroup(); + $group = new CmsGroup(); $group->name = "A New group!"; $this->_em->persist($group); @@ -693,7 +697,7 @@ class ExtraLazyCollectionTest extends OrmFunctionalTestCase $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Removing a managed entity should cause one query to be executed."); $this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized."); - $newUser = new \Doctrine\Tests\Models\CMS\CmsUser(); + $newUser = new CmsUser(); $newUser->name = "A New group!"; $queryCount = $this->getCurrentQueryCount(); @@ -711,7 +715,7 @@ class ExtraLazyCollectionTest extends OrmFunctionalTestCase { $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); - $newGroup = new \Doctrine\Tests\Models\CMS\CmsGroup(); + $newGroup = new CmsGroup(); $newGroup->name = "Test4"; $user->addGroup($newGroup); @@ -735,7 +739,7 @@ class ExtraLazyCollectionTest extends OrmFunctionalTestCase $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); /* @var $user CmsUser */ - $newGroup = new \Doctrine\Tests\Models\CMS\CmsGroup(); + $newGroup = new CmsGroup(); $newGroup->name = "Test4"; $user->addGroup($newGroup); @@ -947,22 +951,22 @@ class ExtraLazyCollectionTest extends OrmFunctionalTestCase private function loadFixture() { - $user1 = new \Doctrine\Tests\Models\CMS\CmsUser(); + $user1 = new CmsUser(); $user1->username = "beberlei"; $user1->name = "Benjamin"; $user1->status = "active"; - $user2 = new \Doctrine\Tests\Models\CMS\CmsUser(); + $user2 = new CmsUser(); $user2->username = "jwage"; $user2->name = "Jonathan"; $user2->status = "active"; - $user3 = new \Doctrine\Tests\Models\CMS\CmsUser(); + $user3 = new CmsUser(); $user3->username = "romanb"; $user3->name = "Roman"; $user3->status = "active"; - $user4 = new \Doctrine\Tests\Models\CMS\CmsUser(); + $user4 = new CmsUser(); $user4->username = "gblanco"; $user4->name = "Guilherme"; $user4->status = "active"; @@ -972,13 +976,13 @@ class ExtraLazyCollectionTest extends OrmFunctionalTestCase $this->_em->persist($user3); $this->_em->persist($user4); - $group1 = new \Doctrine\Tests\Models\CMS\CmsGroup(); + $group1 = new CmsGroup(); $group1->name = "Test1"; - $group2 = new \Doctrine\Tests\Models\CMS\CmsGroup(); + $group2 = new CmsGroup(); $group2->name = "Test2"; - $group3 = new \Doctrine\Tests\Models\CMS\CmsGroup(); + $group3 = new CmsGroup(); $group3->name = "Test3"; $user1->addGroup($group1); @@ -993,12 +997,12 @@ class ExtraLazyCollectionTest extends OrmFunctionalTestCase $this->_em->persist($group2); $this->_em->persist($group3); - $article1 = new \Doctrine\Tests\Models\CMS\CmsArticle(); + $article1 = new CmsArticle(); $article1->topic = "Test1"; $article1->text = "Test1"; $article1->setAuthor($user1); - $article2 = new \Doctrine\Tests\Models\CMS\CmsArticle(); + $article2 = new CmsArticle(); $article2->topic = "Test2"; $article2->text = "Test2"; $article2->setAuthor($user1); @@ -1006,10 +1010,10 @@ class ExtraLazyCollectionTest extends OrmFunctionalTestCase $this->_em->persist($article1); $this->_em->persist($article2); - $phonenumber1 = new \Doctrine\Tests\Models\CMS\CmsPhonenumber(); + $phonenumber1 = new CmsPhonenumber(); $phonenumber1->phonenumber = '12345'; - $phonenumber2 = new \Doctrine\Tests\Models\CMS\CmsPhonenumber(); + $phonenumber2 = new CmsPhonenumber(); $phonenumber2->phonenumber = '67890'; $this->_em->persist($phonenumber1); diff --git a/tests/Doctrine/Tests/ORM/Functional/FlushEventTest.php b/tests/Doctrine/Tests/ORM/Functional/FlushEventTest.php index bd3a33002..b9298e3dc 100644 --- a/tests/Doctrine/Tests/ORM/Functional/FlushEventTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/FlushEventTest.php @@ -6,15 +6,17 @@ use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\CMS\CmsPhonenumber; use Doctrine\ORM\Event\OnFlushEventArgs; use Doctrine\ORM\Events; +use Doctrine\Tests\OrmFunctionalTestCase; /** * FlushEventTest * * @author robo */ -class FlushEventTest extends \Doctrine\Tests\OrmFunctionalTestCase +class FlushEventTest extends OrmFunctionalTestCase { - protected function setUp() { + protected function setUp() + { $this->useModelSet('cms'); parent::setUp(); } diff --git a/tests/Doctrine/Tests/ORM/Functional/HydrationCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/HydrationCacheTest.php index 9dc556d4b..dc84ac4ed 100644 --- a/tests/Doctrine/Tests/ORM/Functional/HydrationCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/HydrationCacheTest.php @@ -1,4 +1,5 @@ name = "Benjamin"; $user->username = "beberlei"; $user->status = 'active'; diff --git a/tests/Doctrine/Tests/ORM/Functional/IdentityMapTest.php b/tests/Doctrine/Tests/ORM/Functional/IdentityMapTest.php index b79f9f3cb..94a11dab4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/IdentityMapTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/IdentityMapTest.php @@ -2,10 +2,11 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\Tests\Models\CMS\CmsUser, - Doctrine\Tests\Models\CMS\CmsAddress, - Doctrine\Tests\Models\CMS\CmsPhonenumber, - Doctrine\ORM\Query; +use Doctrine\ORM\Query; +use Doctrine\Tests\Models\CMS\CmsAddress; +use Doctrine\Tests\Models\CMS\CmsPhonenumber; +use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\OrmFunctionalTestCase; /** * IdentityMapTest @@ -15,9 +16,10 @@ use Doctrine\Tests\Models\CMS\CmsUser, * * @author Roman Borschel */ -class IdentityMapTest extends \Doctrine\Tests\OrmFunctionalTestCase +class IdentityMapTest extends OrmFunctionalTestCase { - protected function setUp() { + protected function setUp() + { $this->useModelSet('cms'); parent::setUp(); } diff --git a/tests/Doctrine/Tests/ORM/Functional/IndexByAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/IndexByAssociationTest.php index e5a4d1d9e..9dac4155d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/IndexByAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/IndexByAssociationTest.php @@ -5,14 +5,15 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Tests\Models\StockExchange\Stock; use Doctrine\Tests\Models\StockExchange\Market; use Doctrine\Tests\Models\StockExchange\Bond; +use Doctrine\Tests\OrmFunctionalTestCase; /** * @group DDC-250 */ -class IndexByAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCase +class IndexByAssociationTest extends OrmFunctionalTestCase { /** - * @var Doctrine\Tests\Models\StockExchange\Market + * @var Market */ private $market; diff --git a/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php b/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php index 9b60c43b2..508645927 100644 --- a/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php @@ -1,12 +1,18 @@ _schemaTool->createSchema(array( @@ -470,7 +476,7 @@ class LifecycleCallbackCascader public function __construct() { - $this->entities = new \Doctrine\Common\Collections\ArrayCollection(); + $this->entities = new ArrayCollection(); } /** @PostLoad */ @@ -516,7 +522,7 @@ class LifecycleCallbackEventArgEntity /** * @PostPersist */ - public function postPersistHandler(\Doctrine\ORM\Event\LifecycleEventArgs $event) + public function postPersistHandler(LifecycleEventArgs $event) { $this->calls[__FUNCTION__] = $event; } @@ -524,7 +530,7 @@ class LifecycleCallbackEventArgEntity /** * @PrePersist */ - public function prePersistHandler(\Doctrine\ORM\Event\LifecycleEventArgs $event) + public function prePersistHandler(LifecycleEventArgs $event) { $this->calls[__FUNCTION__] = $event; } @@ -532,7 +538,7 @@ class LifecycleCallbackEventArgEntity /** * @PostUpdate */ - public function postUpdateHandler(\Doctrine\ORM\Event\LifecycleEventArgs $event) + public function postUpdateHandler(LifecycleEventArgs $event) { $this->calls[__FUNCTION__] = $event; } @@ -540,7 +546,7 @@ class LifecycleCallbackEventArgEntity /** * @PreUpdate */ - public function preUpdateHandler(\Doctrine\ORM\Event\PreUpdateEventArgs $event) + public function preUpdateHandler(PreUpdateEventArgs $event) { $this->calls[__FUNCTION__] = $event; } @@ -548,7 +554,7 @@ class LifecycleCallbackEventArgEntity /** * @PostRemove */ - public function postRemoveHandler(\Doctrine\ORM\Event\LifecycleEventArgs $event) + public function postRemoveHandler(LifecycleEventArgs $event) { $this->calls[__FUNCTION__] = $event; } @@ -556,7 +562,7 @@ class LifecycleCallbackEventArgEntity /** * @PreRemove */ - public function preRemoveHandler(\Doctrine\ORM\Event\LifecycleEventArgs $event) + public function preRemoveHandler(LifecycleEventArgs $event) { $this->calls[__FUNCTION__] = $event; } @@ -564,7 +570,7 @@ class LifecycleCallbackEventArgEntity /** * @PreFlush */ - public function preFlushHandler(\Doctrine\ORM\Event\PreFlushEventArgs $event) + public function preFlushHandler(PreFlushEventArgs $event) { $this->calls[__FUNCTION__] = $event; } @@ -572,7 +578,7 @@ class LifecycleCallbackEventArgEntity /** * @PostLoad */ - public function postLoadHandler(\Doctrine\ORM\Event\LifecycleEventArgs $event) + public function postLoadHandler(LifecycleEventArgs $event) { $this->calls[__FUNCTION__] = $event; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php index c7bdf6bf8..e69d3ee6a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php @@ -2,15 +2,14 @@ namespace Doctrine\Tests\ORM\Functional\Locking; -use Doctrine\Tests\Models\CMS\CmsArticle, - Doctrine\Tests\Models\CMS\CmsUser, - Doctrine\DBAL\LockMode, - Doctrine\ORM\EntityManager; +use Doctrine\Tests\Models\CMS\CmsArticle; +use Doctrine\DBAL\LockMode; +use Doctrine\Tests\OrmFunctionalTestCase; /** * @group locking_functional */ -class GearmanLockTest extends \Doctrine\Tests\OrmFunctionalTestCase +class GearmanLockTest extends OrmFunctionalTestCase { private $gearman = null; private $maxRunTime = 0; diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php b/tests/Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php index 4cd8dfec0..0ca10460f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/LockAgentWorker.php @@ -2,6 +2,11 @@ namespace Doctrine\Tests\ORM\Functional\Locking; +use Doctrine\Common\Cache\ArrayCache; +use Doctrine\DBAL\Logging\EchoSQLLogger; +use Doctrine\ORM\Configuration; +use Doctrine\ORM\EntityManager; + class LockAgentWorker { private $em; @@ -88,7 +93,7 @@ class LockAgentWorker protected function createEntityManager($conn) { - $config = new \Doctrine\ORM\Configuration(); + $config = new Configuration(); $config->setProxyDir(__DIR__ . '/../../../Proxies'); $config->setProxyNamespace('MyProject\Proxies'); $config->setAutoGenerateProxyClasses(true); @@ -96,12 +101,12 @@ class LockAgentWorker $annotDriver = $config->newDefaultAnnotationDriver(array(__DIR__ . '/../../../Models/'), true); $config->setMetadataDriverImpl($annotDriver); - $cache = new \Doctrine\Common\Cache\ArrayCache(); + $cache = new ArrayCache(); $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); - $config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger()); + $config->setSQLLogger(new EchoSQLLogger()); - $em = \Doctrine\ORM\EntityManager::create($conn, $config); + $em = EntityManager::create($conn, $config); return $em; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php index c2d3c7315..421b075d9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php @@ -2,16 +2,21 @@ namespace Doctrine\Tests\ORM\Functional\Locking; -use Doctrine\Tests\Models\CMS\CmsArticle, - Doctrine\Tests\Models\CMS\CmsUser, - Doctrine\DBAL\LockMode, - Doctrine\ORM\EntityManager; +use Doctrine\DBAL\LockMode; +use Doctrine\ORM\OptimisticLockException; +use Doctrine\ORM\Query; +use Doctrine\ORM\TransactionRequiredException; +use Doctrine\Tests\Models\CMS\CmsArticle; +use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\OrmFunctionalTestCase; /** * @group locking */ -class LockTest extends \Doctrine\Tests\OrmFunctionalTestCase { - protected function setUp() { +class LockTest extends OrmFunctionalTestCase +{ + protected function setUp() + { $this->useModelSet('cms'); parent::setUp(); $this->handles = array(); @@ -44,7 +49,8 @@ class LockTest extends \Doctrine\Tests\OrmFunctionalTestCase { $this->_em->persist($article); $this->_em->flush(); - $this->setExpectedException('Doctrine\ORM\OptimisticLockException'); + $this->expectException(OptimisticLockException::class); + $this->_em->lock($article, LockMode::OPTIMISTIC, $article->version + 1); } @@ -61,7 +67,8 @@ class LockTest extends \Doctrine\Tests\OrmFunctionalTestCase { $this->_em->persist($user); $this->_em->flush(); - $this->setExpectedException('Doctrine\ORM\OptimisticLockException'); + $this->expectException(OptimisticLockException::class); + $this->_em->lock($user, LockMode::OPTIMISTIC); } @@ -72,7 +79,9 @@ class LockTest extends \Doctrine\Tests\OrmFunctionalTestCase { public function testLockUnmanagedEntity_ThrowsException() { $article = new CmsArticle(); - $this->setExpectedException('InvalidArgumentException', 'Entity Doctrine\Tests\Models\CMS\CmsArticle'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Entity Doctrine\Tests\Models\CMS\CmsArticle'); + $this->_em->lock($article, LockMode::OPTIMISTIC, $article->version + 1); } @@ -88,7 +97,8 @@ class LockTest extends \Doctrine\Tests\OrmFunctionalTestCase { $this->_em->persist($article); $this->_em->flush(); - $this->setExpectedException('Doctrine\ORM\TransactionRequiredException'); + $this->expectException(TransactionRequiredException::class); + $this->_em->lock($article, LockMode::PESSIMISTIC_READ); } @@ -104,7 +114,8 @@ class LockTest extends \Doctrine\Tests\OrmFunctionalTestCase { $this->_em->persist($article); $this->_em->flush(); - $this->setExpectedException('Doctrine\ORM\TransactionRequiredException'); + $this->expectException(TransactionRequiredException::class); + $this->_em->lock($article, LockMode::PESSIMISTIC_WRITE); } @@ -112,8 +123,9 @@ class LockTest extends \Doctrine\Tests\OrmFunctionalTestCase { * @group DDC-178 * @group locking */ - public function testLockPessimisticWrite() { - $writeLockSql = $this->_em->getConnection()->getDatabasePlatform()->getWriteLockSql(); + public function testLockPessimisticWrite() + { + $writeLockSql = $this->_em->getConnection()->getDatabasePlatform()->getWriteLockSQL(); if (strlen($writeLockSql) == 0) { $this->markTestSkipped('Database Driver has no Write Lock support.'); } @@ -142,8 +154,9 @@ class LockTest extends \Doctrine\Tests\OrmFunctionalTestCase { /** * @group DDC-178 */ - public function testLockPessimisticRead() { - $readLockSql = $this->_em->getConnection()->getDatabasePlatform()->getReadLockSql(); + public function testLockPessimisticRead() + { + $readLockSql = $this->_em->getConnection()->getDatabasePlatform()->getReadLockSQL(); if (strlen($readLockSql) == 0) { $this->markTestSkipped('Database Driver has no Write Lock support.'); } @@ -176,9 +189,11 @@ class LockTest extends \Doctrine\Tests\OrmFunctionalTestCase { { $dql = "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 'gblanco'"; - $this->setExpectedException('Doctrine\ORM\OptimisticLockException', 'The optimistic lock on an entity failed.'); + $this->expectException(OptimisticLockException::class); + $this->expectExceptionMessage('The optimistic lock on an entity failed.'); + $sql = $this->_em->createQuery($dql)->setHint( - \Doctrine\ORM\Query::HINT_LOCK_MODE, \Doctrine\DBAL\LockMode::OPTIMISTIC + 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 df55bd798..e4cad5171 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php @@ -2,15 +2,12 @@ namespace Doctrine\Tests\ORM\Functional\Locking; -use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\OptimisticLockException; -use Doctrine\Common\EventManager; -use Doctrine\ORM\Mapping\ClassMetadataFactory; -use Doctrine\Tests\TestUtil; use Doctrine\DBAL\LockMode; use DateTime; +use Doctrine\Tests\OrmFunctionalTestCase; -class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase +class OptimisticTest extends OrmFunctionalTestCase { protected function setUp() { diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php index da4d30077..2d051b688 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php @@ -3,10 +3,12 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Common\Collections\Criteria; +use Doctrine\ORM\UnitOfWork; use Doctrine\Tests\Models\CMS\CmsTag; use Doctrine\Tests\Models\CMS\CmsUser, Doctrine\Tests\Models\CMS\CmsGroup, Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Tests\OrmFunctionalTestCase; /** * Basic many-to-many association tests. @@ -14,7 +16,7 @@ use Doctrine\Tests\Models\CMS\CmsUser, * * @author robo */ -class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCase +class ManyToManyBasicAssociationTest extends OrmFunctionalTestCase { protected function setUp() { @@ -53,8 +55,8 @@ class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCa $groups = $result[0]->getGroups(); $this->assertEquals('Developers_0', $groups[0]->getName()); - $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_MANAGED, $this->_em->getUnitOfWork()->getEntityState($result[0])); - $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_MANAGED, $this->_em->getUnitOfWork()->getEntityState($groups[0])); + $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()); diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToManyEventTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToManyEventTest.php index 105ba095c..87283ec4b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManyEventTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManyEventTest.php @@ -5,13 +5,14 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\CMS\CmsGroup; use Doctrine\ORM\Events; +use Doctrine\Tests\OrmFunctionalTestCase; /** * ManyToManyEventTest * * @author Francisco Facioni */ -class ManyToManyEventTest extends \Doctrine\Tests\OrmFunctionalTestCase +class ManyToManyEventTest extends OrmFunctionalTestCase { /** * @var PostUpdateListener diff --git a/tests/Doctrine/Tests/ORM/Functional/MappedSuperclassTest.php b/tests/Doctrine/Tests/ORM/Functional/MappedSuperclassTest.php index 700340766..fb7f0a724 100644 --- a/tests/Doctrine/Tests/ORM/Functional/MappedSuperclassTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/MappedSuperclassTest.php @@ -1,13 +1,16 @@ useModelSet('directorytree'); @@ -16,15 +19,15 @@ class MappedSuperclassTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testCRUD() { - $root = new \Doctrine\Tests\Models\DirectoryTree\Directory(); + $root = new Directory(); $root->setName('Root'); $root->setPath('/root'); - $directory = new \Doctrine\Tests\Models\DirectoryTree\Directory($root); + $directory = new Directory($root); $directory->setName('TestA'); $directory->setPath('/root/dir'); - $file = new \Doctrine\Tests\Models\DirectoryTree\File($directory); + $file = new File($directory); $file->setName('test-b.html'); $this->_em->persist($root); diff --git a/tests/Doctrine/Tests/ORM/Functional/MergeCompositeToOneKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/MergeCompositeToOneKeyTest.php index 6c6198520..9b3b338a0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/MergeCompositeToOneKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/MergeCompositeToOneKeyTest.php @@ -4,8 +4,9 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Tests\Models\MixedToOneIdentity\CompositeToOneKeyState; use Doctrine\Tests\Models\MixedToOneIdentity\Country; +use Doctrine\Tests\OrmFunctionalTestCase; -class MergeCompositeToOneKeyTest extends \Doctrine\Tests\OrmFunctionalTestCase +class MergeCompositeToOneKeyTest extends OrmFunctionalTestCase { /** * {@inheritDoc} diff --git a/tests/Doctrine/Tests/ORM/Functional/MergeSharedEntitiesTest.php b/tests/Doctrine/Tests/ORM/Functional/MergeSharedEntitiesTest.php index 28e89c360..ffe64fcff 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/MergeVersionedManyToOneTest.php b/tests/Doctrine/Tests/ORM/Functional/MergeVersionedManyToOneTest.php index b534a5cb4..43af6720c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/MergeVersionedManyToOneTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/MergeVersionedManyToOneTest.php @@ -2,15 +2,14 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\ORM\OptimisticLockException; -use Doctrine\ORM\ORMException; use Doctrine\Tests\Models\VersionedManyToOne\Article; use Doctrine\Tests\Models\VersionedManyToOne\Category; +use Doctrine\Tests\OrmFunctionalTestCase; /** * @group MergeVersionedOneToMany */ -class MergeVersionedManyToOneTest extends \Doctrine\Tests\OrmFunctionalTestCase +class MergeVersionedManyToOneTest extends OrmFunctionalTestCase { protected function setUp() { diff --git a/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php b/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php index 281846503..320aa357a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php @@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\ORM\Internal\Hydration\HydrationException; use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\ORM\Query\ResultSetMappingBuilder; use Doctrine\ORM\Query\Parameter; @@ -13,17 +14,19 @@ use Doctrine\Tests\Models\CMS\CmsAddress; use Doctrine\Tests\Models\CMS\CmsEmail; use Doctrine\Tests\Models\Company\CompanyEmployee; use Doctrine\Tests\Models\Company\CompanyPerson; +use Doctrine\Tests\OrmFunctionalTestCase; /** * NativeQueryTest * * @author robo */ -class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase +class NativeQueryTest extends OrmFunctionalTestCase { private $platform = null; - protected function setUp() { + protected function setUp() + { $this->useModelSet('cms'); $this->useModelSet('company'); parent::setUp(); @@ -197,7 +200,7 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase $rsm = new ResultSetMapping; $q = $this->_em->createNativeQuery('SELECT id, name, status, phonenumber FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username = ?', $rsm); - $q2 = $q->setSql('foo', $rsm) + $q2 = $q->setSQL('foo') ->setResultSetMapping($rsm) ->expireResultCache(true) ->setHint('foo', 'bar') @@ -322,7 +325,9 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase */ public function testAbstractClassInSingleTableInheritanceSchemaWithRSMBuilderThrowsException() { - $this->setExpectedException('\InvalidArgumentException', 'ResultSetMapping builder does not currently support your inheritance scheme.'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('ResultSetMapping builder does not currently support your inheritance scheme.'); + $rsm = new ResultSetMappingBuilder($this->_em); $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\Company\CompanyContract', 'c'); } @@ -349,10 +354,9 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase $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'); - $this->setExpectedException( - "Doctrine\ORM\Internal\Hydration\HydrationException", - "The parent object of entity result with alias 'a' was not found. The parent alias is 'un'." - ); + $this->expectException(HydrationException::class); + $this->expectExceptionMessage("The parent object of entity result with alias 'a' was not found. The parent alias is 'un'."); + $users = $query->getResult(); } diff --git a/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php b/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php index e8c0e300f..37067aec0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php @@ -7,11 +7,12 @@ 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\OrmFunctionalTestCase; /** * @group DDC-1574 */ -class NewOperatorTest extends \Doctrine\Tests\OrmFunctionalTestCase +class NewOperatorTest extends OrmFunctionalTestCase { /** * @var array diff --git a/tests/Doctrine/Tests/ORM/Functional/NotifyPolicyTest.php b/tests/Doctrine/Tests/ORM/Functional/NotifyPolicyTest.php index ab6aa61cf..ecebc28d9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/NotifyPolicyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/NotifyPolicyTest.php @@ -1,18 +1,21 @@ _schemaTool->createSchema(array( diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php index c904a1474..8327142fd 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php @@ -5,11 +5,12 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Tests\Models\ECommerce\ECommerceProduct; use Doctrine\Tests\Models\ECommerce\ECommerceFeature; use Doctrine\Common\Collections\Criteria; +use Doctrine\Tests\OrmFunctionalTestCase; /** * Tests a bidirectional one-to-one association mapping (without inheritance). */ -class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCase +class OneToManyBidirectionalAssociationTest extends OrmFunctionalTestCase { private $product; private $firstFeature; diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManyOrphanRemovalTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManyOrphanRemovalTest.php index e10c1f923..d22dbd4e2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToManyOrphanRemovalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToManyOrphanRemovalTest.php @@ -3,13 +3,13 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Tests\Models\CMS\CmsUser, - Doctrine\Tests\Models\CMS\CmsAddress, Doctrine\Tests\Models\CMS\CmsPhonenumber; +use Doctrine\Tests\OrmFunctionalTestCase; /** * Tests a bidirectional one-to-many association mapping with orphan removal. */ -class OneToManyOrphanRemovalTest extends \Doctrine\Tests\OrmFunctionalTestCase +class OneToManyOrphanRemovalTest extends OrmFunctionalTestCase { protected $userId; diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php index ab077fe4a..3d6c688bd 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php @@ -5,11 +5,12 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Tests\Models\ECommerce\ECommerceCategory; use Doctrine\ORM\Mapping\AssociationMapping; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\Tests\OrmFunctionalTestCase; /** * Tests a bidirectional one-to-one association mapping (without inheritance). */ -class OneToManySelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCase +class OneToManySelfReferentialAssociationTest extends OrmFunctionalTestCase { private $parent; private $firstChild; diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManyUnidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManyUnidirectionalAssociationTest.php index b4db3b90e..e2c663118 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToManyUnidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToManyUnidirectionalAssociationTest.php @@ -5,11 +5,12 @@ 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\OrmFunctionalTestCase; /** * Tests a bidirectional one-to-one association mapping (without inheritance). */ -class OneToManyUnidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCase +class OneToManyUnidirectionalAssociationTest extends OrmFunctionalTestCase { protected $locations = array(); diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php index 4ecfd5f90..6d42e7634 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php @@ -6,11 +6,12 @@ use Doctrine\Tests\Models\ECommerce\ECommerceCart; use Doctrine\Tests\Models\ECommerce\ECommerceCustomer; use Doctrine\ORM\Mapping\AssociationMapping; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\Tests\OrmFunctionalTestCase; /** * Tests a bidirectional one-to-one association mapping (without inheritance). */ -class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCase +class OneToOneBidirectionalAssociationTest extends OrmFunctionalTestCase { private $customer; private $cart; @@ -88,7 +89,7 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional $customer = $result[0]; $this->assertNull($customer->getMentor()); - $this->assertInstanceOF('Doctrine\Tests\Models\ECommerce\ECommerceCart', $customer->getCart()); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCart', $customer->getCart()); $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $customer->getCart()); $this->assertEquals('paypal', $customer->getCart()->getPayment()); } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php index fb6ed5ab7..522a009eb 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php @@ -1,16 +1,19 @@ _em); + $schemaTool = new SchemaTool($this->_em); try { $schemaTool->createSchema(array( $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Train'), @@ -248,7 +251,7 @@ class Train public function __construct(TrainOwner $owner) { - $this->waggons = new \Doctrine\Common\Collections\ArrayCollection(); + $this->waggons = new ArrayCollection(); $this->setOwner($owner); } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneOrphanRemovalTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneOrphanRemovalTest.php index 98e307800..34bbc8c55 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneOrphanRemovalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneOrphanRemovalTest.php @@ -4,13 +4,13 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Tests\Models\CMS\CmsUser, Doctrine\Tests\Models\CMS\CmsEmail, - Doctrine\Tests\Models\CMS\CmsAddress, - Doctrine\Tests\Models\CMS\CmsPhonenumber; + Doctrine\Tests\Models\CMS\CmsAddress; +use Doctrine\Tests\OrmFunctionalTestCase; /** * Tests a bidirectional one-to-one association mapping with orphan removal. */ -class OneToOneOrphanRemovalTest extends \Doctrine\Tests\OrmFunctionalTestCase +class OneToOneOrphanRemovalTest extends OrmFunctionalTestCase { protected function setUp() { diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php index 4d173f3dc..cad28d4c3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php @@ -5,6 +5,7 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Tests\Models\ECommerce\ECommerceCustomer; use Doctrine\ORM\Mapping\AssociationMapping; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\Tests\OrmFunctionalTestCase; /** * Tests a self referential one-to-one association mapping (without inheritance). @@ -13,7 +14,7 @@ use Doctrine\ORM\Mapping\ClassMetadata; * for receiving support. * Inverse side is not present. */ -class OneToOneSelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCase +class OneToOneSelfReferentialAssociationTest extends OrmFunctionalTestCase { private $customer; private $mentor; diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneSingleTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneSingleTableInheritanceTest.php index af9379327..b677df624 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneSingleTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneSingleTableInheritanceTest.php @@ -2,10 +2,6 @@ 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\OneToOneSingleTableInheritance\Cat; use Doctrine\Tests\Models\OneToOneSingleTableInheritance\LitterBox; diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php index 61bb8c611..60b5b3656 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php @@ -7,12 +7,13 @@ use Doctrine\Tests\Models\ECommerce\ECommerceShipping; use Doctrine\ORM\Mapping\AssociationMapping; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Query; +use Doctrine\Tests\OrmFunctionalTestCase; /** * Tests a unidirectional one-to-one association mapping (without inheritance). * Inverse side is not present. */ -class OneToOneUnidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCase +class OneToOneUnidirectionalAssociationTest extends OrmFunctionalTestCase { private $product; private $shipping; diff --git a/tests/Doctrine/Tests/ORM/Functional/OrderedCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/OrderedCollectionTest.php index d85357bac..c4e5dca70 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OrderedCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OrderedCollectionTest.php @@ -6,8 +6,9 @@ use Doctrine\Tests\Models\Routing\RoutingRoute; use Doctrine\Tests\Models\Routing\RoutingLocation; use Doctrine\Tests\Models\Routing\RoutingLeg; use Doctrine\Tests\Models\Routing\RoutingRouteBooking; +use Doctrine\Tests\OrmFunctionalTestCase; -class OrderedCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase +class OrderedCollectionTest extends OrmFunctionalTestCase { protected $locations = array(); diff --git a/tests/Doctrine/Tests/ORM/Functional/OrderedJoinedTableInheritanceCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/OrderedJoinedTableInheritanceCollectionTest.php index cef464574..b3d85340e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OrderedJoinedTableInheritanceCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OrderedJoinedTableInheritanceCollectionTest.php @@ -3,15 +3,17 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\ORM\Query; +use Doctrine\Tests\OrmFunctionalTestCase; /** * Functional tests for the Single Table Inheritance mapping strategy. * * @author Benjamin Eberlei */ -class OrderedJoinedTableInheritanceCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase +class OrderedJoinedTableInheritanceCollectionTest extends OrmFunctionalTestCase { - protected function setUp() { + protected function setUp() + { parent::setUp(); try { $this->_schemaTool->createSchema(array( diff --git a/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php b/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php index eea2e8375..8afe9d332 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PaginationTest.php @@ -13,12 +13,13 @@ 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; /** * @group DDC-1613 */ -class PaginationTest extends \Doctrine\Tests\OrmFunctionalTestCase +class PaginationTest extends OrmFunctionalTestCase { protected function setUp() { @@ -73,10 +74,9 @@ class PaginationTest extends \Doctrine\Tests\OrmFunctionalTestCase $paginator = new Paginator($query); $paginator->setUseOutputWalkers(false); - $this->setExpectedException( - 'RuntimeException', - 'Cannot count query that uses a HAVING clause. Use the output walkers for pagination' - ); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Cannot count query that uses a HAVING clause. Use the output walkers for pagination'); + $this->assertCount(3, $paginator); } @@ -494,7 +494,9 @@ class PaginationTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testIterateWithFetchJoinOneToManyWithOrderByColumnFromBothWithLimitWithoutOutputWalker() { - $this->setExpectedException("RuntimeException", "Cannot select distinct identifiers from query with LIMIT and ORDER BY on a column from a fetch joined to-many association. Use output walkers."); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Cannot select distinct identifiers from query with LIMIT and ORDER BY on a column from a fetch joined to-many association. Use output walkers.'); + $dql = 'SELECT c, d FROM Doctrine\Tests\Models\Pagination\Company c JOIN c.departments d ORDER BY c.name'; $dqlAsc = $dql . " ASC, d.name"; $dqlDesc = $dql . " DESC, d.name"; @@ -551,7 +553,9 @@ class PaginationTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testIterateWithFetchJoinOneToManyWithOrderByColumnFromJoinedWithLimitWithoutOutputWalker() { - $this->setExpectedException("RuntimeException", "Cannot select distinct identifiers from query with LIMIT and ORDER BY on a column from a fetch joined to-many association. Use output walkers."); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Cannot select distinct identifiers from query with LIMIT and ORDER BY on a column from a fetch joined to-many association. Use output walkers.'); + $dql = 'SELECT c, d FROM Doctrine\Tests\Models\Pagination\Company c JOIN c.departments d ORDER BY d.name'; $this->iterateWithOrderAscWithLimit(false, true, $dql, "name"); @@ -594,10 +598,8 @@ class PaginationTest extends \Doctrine\Tests\OrmFunctionalTestCase $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Query\SqlWalker'); $paginator = new Paginator($query); - $this->setExpectedException( - 'RuntimeException', - 'Cannot count query that uses a HAVING clause. Use the output walkers for pagination' - ); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Cannot count query that uses a HAVING clause. Use the output walkers for pagination'); count($paginator); } diff --git a/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php b/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php index b6e58246f..a730546d6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php @@ -1,20 +1,4 @@ */ -class PersistentCollectionCriteriaTest extends \Doctrine\Tests\OrmFunctionalTestCase +class PersistentCollectionCriteriaTest extends OrmFunctionalTestCase { protected function setUp() { diff --git a/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php index c2181b8b1..d3d22825b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php @@ -2,12 +2,12 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Criteria; use Doctrine\Common\Persistence\PersistentObject; +use Doctrine\Tests\OrmFunctionalTestCase; -/** - */ -class PersistentCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase +class PersistentCollectionTest extends OrmFunctionalTestCase { protected function setUp() { @@ -114,7 +114,7 @@ class PersistentCollectionHolder extends PersistentObject public function __construct() { - $this->collection = new \Doctrine\Common\Collections\ArrayCollection(); + $this->collection = new ArrayCollection(); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php b/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php index 88e54ae2e..861b29225 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PersistentObjectTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Common\Persistence\PersistentObject; +use Doctrine\Tests\OrmFunctionalTestCase; /** * Test that Doctrine ORM correctly works with the ObjectManagerAware and PersistentObject @@ -10,7 +11,7 @@ use Doctrine\Common\Persistence\PersistentObject; * * @group DDC-1448 */ -class PersistentObjectTest extends \Doctrine\Tests\OrmFunctionalTestCase +class PersistentObjectTest extends OrmFunctionalTestCase { protected function setUp() { diff --git a/tests/Doctrine/Tests/ORM/Functional/PostFlushEventTest.php b/tests/Doctrine/Tests/ORM/Functional/PostFlushEventTest.php index e23038e69..12e2c4080 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PostFlushEventTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PostFlushEventTest.php @@ -5,13 +5,14 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\ORM\Event\PostFlushEventArgs; use Doctrine\ORM\Events; +use Doctrine\Tests\OrmFunctionalTestCase; /** * PostFlushEventTest * * @author Daniel Freudenberger */ -class PostFlushEventTest extends \Doctrine\Tests\OrmFunctionalTestCase +class PostFlushEventTest extends OrmFunctionalTestCase { /** * @var PostFlushListener diff --git a/tests/Doctrine/Tests/ORM/Functional/PostLoadEventTest.php b/tests/Doctrine/Tests/ORM/Functional/PostLoadEventTest.php index 9dcff9cb6..b6fb57964 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PostLoadEventTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PostLoadEventTest.php @@ -8,13 +8,14 @@ use Doctrine\Tests\Models\CMS\CmsAddress; use Doctrine\Tests\Models\CMS\CmsEmail; use Doctrine\ORM\Event\LifecycleEventArgs; use Doctrine\ORM\Events; +use Doctrine\Tests\OrmFunctionalTestCase; /** * PostLoadEventTest * * @author Guilherme Blanco */ -class PostLoadEventTest extends \Doctrine\Tests\OrmFunctionalTestCase +class PostLoadEventTest extends OrmFunctionalTestCase { /** * @var integer @@ -35,7 +36,7 @@ class PostLoadEventTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testLoadedEntityUsingFindShouldTriggerEvent() { - $mockListener = $this->getMock('Doctrine\Tests\ORM\Functional\PostLoadListener'); + $mockListener = $this->createMock(PostLoadListener::class); // CmsUser and CmsAddres, because it's a ToOne inverse side on CmsUser $mockListener @@ -52,7 +53,7 @@ class PostLoadEventTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testLoadedEntityUsingQueryShouldTriggerEvent() { - $mockListener = $this->getMock('Doctrine\Tests\ORM\Functional\PostLoadListener'); + $mockListener = $this->createMock(PostLoadListener::class); // CmsUser and CmsAddres, because it's a ToOne inverse side on CmsUser $mockListener @@ -72,7 +73,7 @@ class PostLoadEventTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testLoadedAssociationToOneShouldTriggerEvent() { - $mockListener = $this->getMock('Doctrine\Tests\ORM\Functional\PostLoadListener'); + $mockListener = $this->createMock(PostLoadListener::class); // CmsUser (root), CmsAddress (ToOne inverse side), CmsEmail (joined association) $mockListener @@ -92,7 +93,7 @@ class PostLoadEventTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testLoadedAssociationToManyShouldTriggerEvent() { - $mockListener = $this->getMock('Doctrine\Tests\ORM\Functional\PostLoadListener'); + $mockListener = $this->createMock(PostLoadListener::class); // CmsUser (root), CmsAddress (ToOne inverse side), 2 CmsPhonenumber (joined association) $mockListener @@ -115,7 +116,7 @@ class PostLoadEventTest extends \Doctrine\Tests\OrmFunctionalTestCase $eventManager = $this->_em->getEventManager(); // Should not be invoked during getReference call - $mockListener = $this->getMock('Doctrine\Tests\ORM\Functional\PostLoadListener'); + $mockListener = $this->createMock(PostLoadListener::class); $mockListener ->expects($this->never()) @@ -129,7 +130,7 @@ class PostLoadEventTest extends \Doctrine\Tests\OrmFunctionalTestCase // Now deactivate original listener and attach new one $eventManager->removeEventListener(array(Events::postLoad), $mockListener); - $mockListener2 = $this->getMock('Doctrine\Tests\ORM\Functional\PostLoadListener'); + $mockListener2 = $this->createMock(PostLoadListener::class); $mockListener2 ->expects($this->exactly(2)) @@ -146,7 +147,7 @@ class PostLoadEventTest extends \Doctrine\Tests\OrmFunctionalTestCase $eventManager = $this->_em->getEventManager(); // Should not be invoked during getReference call - $mockListener = $this->getMock('Doctrine\Tests\ORM\Functional\PostLoadListener'); + $mockListener = $this->createMock(PostLoadListener::class); // CmsUser (partially loaded), CmsAddress (inverse ToOne), 2 CmsPhonenumber $mockListener @@ -166,7 +167,7 @@ class PostLoadEventTest extends \Doctrine\Tests\OrmFunctionalTestCase { $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); - $mockListener = $this->getMock('Doctrine\Tests\ORM\Functional\PostLoadListener'); + $mockListener = $this->createMock(PostLoadListener::class); // CmsEmail (proxy) $mockListener @@ -187,7 +188,7 @@ class PostLoadEventTest extends \Doctrine\Tests\OrmFunctionalTestCase { $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); - $mockListener = $this->getMock('Doctrine\Tests\ORM\Functional\PostLoadListener'); + $mockListener = $this->createMock(PostLoadListener::class); // 2 CmsPhonenumber (proxy) $mockListener diff --git a/tests/Doctrine/Tests/ORM/Functional/ProxiesLikeEntitiesTest.php b/tests/Doctrine/Tests/ORM/Functional/ProxiesLikeEntitiesTest.php index 592706588..1528404df 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ProxiesLikeEntitiesTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ProxiesLikeEntitiesTest.php @@ -2,8 +2,8 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\Common\Util\ClassUtils; use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\OrmFunctionalTestCase; /** * Test that Doctrine ORM correctly works with proxy instances exactly like with ordinary Entities @@ -13,7 +13,7 @@ use Doctrine\Tests\Models\CMS\CmsUser; * b) __initialized__ = false and identifier set in proxy and in property * @todo All other cases would cause lazy loading */ -class ProxiesLikeEntitiesTest extends \Doctrine\Tests\OrmFunctionalTestCase +class ProxiesLikeEntitiesTest extends OrmFunctionalTestCase { /** * @var CmsUser diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php index 039bb1655..a24445271 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php @@ -2,15 +2,19 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Common\Cache\ArrayCache; +use Doctrine\Common\Cache\Cache; +use Doctrine\Common\Cache\CacheProvider; +use Doctrine\ORM\Query\Exec\AbstractSqlExecutor; +use Doctrine\ORM\Query\ParserResult; +use Doctrine\Tests\OrmFunctionalTestCase; /** * QueryCacheTest * * @author robo */ -class QueryCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase +class QueryCacheTest extends OrmFunctionalTestCase { /** * @var \ReflectionProperty @@ -105,7 +109,7 @@ class QueryCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); - $cache = $this->getMock('Doctrine\Common\Cache\Cache'); + $cache = $this->createMock(Cache::class); $query->setQueryCacheDriver($cache); @@ -123,18 +127,23 @@ class QueryCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); - $sqlExecMock = $this->getMock('Doctrine\ORM\Query\Exec\AbstractSqlExecutor', array('execute')); + $sqlExecMock = $this->getMockBuilder(AbstractSqlExecutor::class) + ->setMethods(array('execute')) + ->getMock(); + $sqlExecMock->expects($this->once()) ->method('execute') ->will($this->returnValue( 10 )); - $parserResultMock = $this->getMock('Doctrine\ORM\Query\ParserResult'); + $parserResultMock = $this->createMock(ParserResult::class); $parserResultMock->expects($this->once()) ->method('getSqlExecutor') ->will($this->returnValue($sqlExecMock)); - $cache = $this->getMock('Doctrine\Common\Cache\CacheProvider', - array('doFetch', 'doContains', 'doSave', 'doDelete', 'doFlush', 'doGetStats')); + $cache = $this->getMockBuilder(CacheProvider::class) + ->setMethods(array('doFetch', 'doContains', 'doSave', 'doDelete', 'doFlush', 'doGetStats')) + ->getMock(); + $cache->expects($this->at(0))->method('doFetch')->will($this->returnValue(1)); $cache->expects($this->at(1)) ->method('doFetch') diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php index b0a4905ac..764b213dd 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php @@ -3,13 +3,14 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Tests\Models\Company\CompanyManager; +use Doctrine\Tests\OrmFunctionalTestCase; /** * Functional Query tests. * * @author robo */ -class QueryDqlFunctionTest extends \Doctrine\Tests\OrmFunctionalTestCase +class QueryDqlFunctionTest extends OrmFunctionalTestCase { protected function setUp() { diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php index 2e6dbc3c6..f23409506 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php @@ -4,20 +4,23 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Common\Collections\ArrayCollection; -use Doctrine\DBAL\Connection; +use Doctrine\ORM\NonUniqueResultException; +use Doctrine\ORM\Query\QueryException; +use Doctrine\ORM\UnexpectedResultException; use Doctrine\Tests\Models\CMS\CmsUser, Doctrine\Tests\Models\CMS\CmsArticle, Doctrine\Tests\Models\CMS\CmsPhonenumber; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Query; use Doctrine\ORM\Query\Parameter; +use Doctrine\Tests\OrmFunctionalTestCase; /** * Functional Query tests. * * @author robo */ -class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase +class QueryTest extends OrmFunctionalTestCase { protected function setUp() { @@ -117,10 +120,8 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testUsingUnknownQueryParameterShouldThrowException() { - $this->setExpectedException( - "Doctrine\ORM\Query\QueryException", - "Invalid parameter: token 2 is not defined in the query." - ); + $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->setParameter(2, 'jwage'); @@ -129,10 +130,8 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testTooManyParametersShouldThrowException() { - $this->setExpectedException( - "Doctrine\ORM\Query\QueryException", - "Too many parameters: the query defines 1 parameters and you bound 2" - ); + $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->setParameter(1, 'jwage'); @@ -143,10 +142,8 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testTooFewParametersShouldThrowException() { - $this->setExpectedException( - "Doctrine\ORM\Query\QueryException", - "Too few parameters: the query defines 1 parameters but you only bound 0" - ); + $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'); @@ -155,7 +152,7 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testInvalidInputParameterThrowsException() { - $this->setExpectedException("Doctrine\ORM\Query\QueryException"); + $this->expectException(QueryException::class); $q = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = ?'); $q->setParameter(1, 'jwage'); @@ -391,7 +388,7 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase try { $query = $this->_em->createQuery('UPDATE CMS:CmsUser u SET u.name = ?1'); - $this->assertEquals('UPDATE cms_users SET name = ?', $query->getSql()); + $this->assertEquals('UPDATE cms_users SET name = ?', $query->getSQL()); $query->free(); } catch (\Exception $e) { $this->fail($e->getMessage()); @@ -504,7 +501,8 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase $query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u"); - $this->setExpectedException('Doctrine\ORM\NonUniqueResultException'); + $this->expectException(NonUniqueResultException::class); + $fetchedUser = $query->getOneOrNullResult(); } @@ -754,7 +752,7 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase try { $this->_em->createQuery($dql)->getSingleResult(); $this->fail('Expected exception "\Doctrine\ORM\NoResultException".'); - } catch (\Doctrine\ORM\UnexpectedResultException $exc) { + } catch (UnexpectedResultException $exc) { $this->assertInstanceOf('\Doctrine\ORM\NoResultException', $exc); } @@ -767,7 +765,7 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase try { $this->_em->createQuery($dql)->getSingleResult(); $this->fail('Expected exception "\Doctrine\ORM\NonUniqueResultException".'); - } catch (\Doctrine\ORM\UnexpectedResultException $exc) { + } catch (UnexpectedResultException $exc) { $this->assertInstanceOf('\Doctrine\ORM\NonUniqueResultException', $exc); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/ReadOnlyTest.php b/tests/Doctrine/Tests/ORM/Functional/ReadOnlyTest.php index 0cfbdc16e..dd8a23ff3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ReadOnlyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ReadOnlyTest.php @@ -1,13 +1,14 @@ * @author Benjamin Eberlei */ -class ReferenceProxyTest extends \Doctrine\Tests\OrmFunctionalTestCase +class ReferenceProxyTest extends OrmFunctionalTestCase { protected function setUp() { @@ -230,9 +232,9 @@ class ReferenceProxyTest extends \Doctrine\Tests\OrmFunctionalTestCase { $id = $this->createProduct(); - /* @var $entity Doctrine\Tests\Models\ECommerce\ECommerceProduct */ + /* @var $entity ECommerceProduct */ $entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id); - $className = \Doctrine\Common\Util\ClassUtils::getClass($entity); + $className = ClassUtils::getClass($entity); $this->assertInstanceOf('Doctrine\Common\Persistence\Proxy', $entity); $this->assertFalse($entity->__isInitialized()); diff --git a/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php index 580473476..e1bd93ed7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php @@ -2,16 +2,19 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\ORM\Query; +use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\CMS\CmsArticle; use Doctrine\Common\Cache\ArrayCache; +use Doctrine\Tests\OrmFunctionalTestCase; /** * ResultCacheTest * * @author robo */ -class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase +class ResultCacheTest extends OrmFunctionalTestCase { /** * @var \ReflectionProperty @@ -133,7 +136,7 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testNativeQueryResultCaching() { $cache = new ArrayCache(); - $rsm = new \Doctrine\ORM\Query\ResultSetMapping(); + $rsm = new ResultSetMapping(); $rsm->addScalarResult('id', 'u', 'integer'); @@ -190,7 +193,7 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase $cache = $query->getResultCacheDriver(); $cacheCount = $this->getCacheSize($cache); - $this->assertNotEquals(\Doctrine\ORM\Query::HYDRATE_ARRAY, $query->getHydrationMode()); + $this->assertNotEquals(Query::HYDRATE_ARRAY, $query->getHydrationMode()); $query->getArrayResult(); $this->assertEquals($cacheCount, $this->getCacheSize($cache)); diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index 831d0b564..5fccc0bdb 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -3,8 +3,9 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\DBAL\Types\Type as DBALType; +use Doctrine\ORM\Configuration; use Doctrine\ORM\Query\Filter\SQLFilter; -use Doctrine\ORM\Mapping\ClassMetaData; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\Common\Cache\ArrayCache; use Doctrine\ORM\Mapping\ClassMetadataInfo; @@ -21,6 +22,7 @@ use Doctrine\Tests\Models\Company\CompanyAuction; use Doctrine\Tests\Models\Company\CompanyFlexContract; use Doctrine\Tests\Models\Company\CompanyFlexUltraContract; +use Doctrine\Tests\OrmFunctionalTestCase; /** * Tests SQLFilter functionality. @@ -29,7 +31,7 @@ use Doctrine\Tests\Models\Company\CompanyFlexUltraContract; * * @group non-cacheable */ -class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase +class SQLFilterTest extends OrmFunctionalTestCase { private $userId, $userId2, $articleId, $articleId2; private $groupId, $groupId2; @@ -54,7 +56,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testConfigureFilter() { - $config = new \Doctrine\ORM\Configuration(); + $config = new Configuration(); $config->addFilter("locale", "\Doctrine\Tests\ORM\Functional\MyLocaleFilter"); @@ -69,7 +71,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase // Enable an existing filter $filter = $em->getFilters()->enable("locale"); - $this->assertTrue($filter instanceof \Doctrine\Tests\ORM\Functional\MyLocaleFilter); + $this->assertTrue($filter instanceof MyLocaleFilter); // Enable the filter again $filter2 = $em->getFilters()->enable("locale"); @@ -223,7 +225,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase ->with($this->equalTo('en')) ->will($this->returnValue("'en'")); - $em = $this->getMockEntityManager($conn); + $em = $this->getMockEntityManager(); $em->expects($this->once()) ->method('getConnection') ->will($this->returnValue($conn)); @@ -249,7 +251,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase // Setup mock connection $conn = $this->getMockConnection(); - $em = $this->getMockEntityManager($conn); + $em = $this->getMockEntityManager(); $em->expects($this->once()) ->method('getConnection') ->will($this->returnValue($conn)); @@ -271,7 +273,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase ->with($this->equalTo('en')) ->will($this->returnValue("'en'")); - $em = $this->getMockEntityManager($conn); + $em = $this->getMockEntityManager(); $em->expects($this->once()) ->method('getConnection') ->will($this->returnValue($conn)); diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/CompanySchemaTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/CompanySchemaTest.php index 5e9fcda37..32c75d25d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/CompanySchemaTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/CompanySchemaTest.php @@ -3,13 +3,14 @@ namespace Doctrine\Tests\ORM\Functional\SchemaTool; use Doctrine\DBAL\Schema\Schema; +use Doctrine\Tests\OrmFunctionalTestCase; /** * Functional tests for the Class Table Inheritance mapping strategy. * * @author robo */ -class CompanySchemaTest extends \Doctrine\Tests\OrmFunctionalTestCase +class CompanySchemaTest extends OrmFunctionalTestCase { protected function setUp() { diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DBAL483Test.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DBAL483Test.php index 0c76edf73..22debe962 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DBAL483Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DBAL483Test.php @@ -3,14 +3,15 @@ namespace Doctrine\Tests\ORM\Functional\SchemaTool; use Doctrine\ORM\Tools; +use Doctrine\Tests\OrmFunctionalTestCase; -class DBAL483Test extends \Doctrine\Tests\OrmFunctionalTestCase +class DBAL483Test extends OrmFunctionalTestCase { public function setUp() { parent::setUp(); - $conn = $this->_em->getConnection(); + $this->_em->getConnection(); $this->schemaTool = new Tools\SchemaTool($this->_em); } diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php index 22d2b1f8e..4b4d0328d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php @@ -2,12 +2,14 @@ namespace Doctrine\Tests\ORM\Functional\SchemaTool; +use Doctrine\DBAL\Schema\Comparator; use Doctrine\ORM\Tools; +use Doctrine\Tests\OrmFunctionalTestCase; /** * WARNING: This test should be run as last test! It can affect others very easily! */ -class DDC214Test extends \Doctrine\Tests\OrmFunctionalTestCase +class DDC214Test extends OrmFunctionalTestCase { private $classes = array(); private $schemaTool = null; @@ -78,7 +80,7 @@ class DDC214Test extends \Doctrine\Tests\OrmFunctionalTestCase $fromSchema = $sm->createSchema(); $toSchema = $this->schemaTool->getSchemaFromMetadata($classMetadata); - $comparator = new \Doctrine\DBAL\Schema\Comparator(); + $comparator = new Comparator(); $schemaDiff = $comparator->compare($fromSchema, $toSchema); $sql = $schemaDiff->toSql($this->_em->getConnection()->getDatabasePlatform()); diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php index 4df6032d0..a923c40fc 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php @@ -2,10 +2,10 @@ namespace Doctrine\Tests\ORM\Functional\SchemaTool; -use Doctrine\ORM\Tools\SchemaTool, - Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Tools\SchemaTool; +use Doctrine\Tests\OrmFunctionalTestCase; -class MySqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase +class MySqlSchemaToolTest extends OrmFunctionalTestCase { protected function setUp() { parent::setUp(); diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php index 52151e4ba..f98fe4beb 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php @@ -2,10 +2,10 @@ namespace Doctrine\Tests\ORM\Functional\SchemaTool; -use Doctrine\ORM\Tools\SchemaTool, - Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Tools\SchemaTool; +use Doctrine\Tests\OrmFunctionalTestCase; -class PostgreSqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase +class PostgreSqlSchemaToolTest extends OrmFunctionalTestCase { protected function setUp() { diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php index 948aad2ef..06eb67a2e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php @@ -2,15 +2,15 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\ORM\Tools\SchemaValidator; +use Doctrine\Tests\OrmFunctionalTestCase; /** * Test the validity of all modelsets * * @group DDC-1601 */ -class SchemaValidatorTest extends \Doctrine\Tests\OrmFunctionalTestCase +class SchemaValidatorTest extends OrmFunctionalTestCase { static public function dataValidateModelSets() { diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheConcurrentTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheConcurrentTest.php index 6b177562f..f4d8e6b76 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheConcurrentTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheConcurrentTest.php @@ -2,9 +2,11 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\ORM\Cache\DefaultCacheFactory; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\Tests\Mocks\ConcurrentRegionMock; use Doctrine\ORM\Cache\Region\DefaultRegion; +use Doctrine\Tests\Mocks\TimestampRegionMock; use Doctrine\Tests\Models\Cache\Country; use Doctrine\ORM\Cache\CollectionCacheKey; use Doctrine\ORM\Cache\EntityCacheKey; @@ -126,7 +128,7 @@ class SecondLevelCacheConcurrentTest extends SecondLevelCacheAbstractTest } } -class CacheFactorySecondLevelCacheConcurrentTest extends \Doctrine\ORM\Cache\DefaultCacheFactory +class CacheFactorySecondLevelCacheConcurrentTest extends DefaultCacheFactory { public function __construct(Cache $cache) { @@ -143,6 +145,6 @@ class CacheFactorySecondLevelCacheConcurrentTest extends \Doctrine\ORM\Cache\Def public function getTimestampRegion() { - return new \Doctrine\Tests\Mocks\TimestampRegionMock(); + return new TimestampRegionMock(); } } \ 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 00fa40973..57215f8e0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheManyToOneTest.php @@ -193,7 +193,7 @@ class SecondLevelCacheManyToOneTest extends SecondLevelCacheAbstractTest $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 @@ class SecondLevelCacheManyToOneTest extends SecondLevelCacheAbstractTest $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 @@ class SecondLevelCacheManyToOneTest extends SecondLevelCacheAbstractTest $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 @@ class SecondLevelCacheManyToOneTest extends SecondLevelCacheAbstractTest $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 diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToOneTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToOneTest.php index e84be7e07..316620f82 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToOneTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheOneToOneTest.php @@ -2,10 +2,8 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\Tests\Models\Cache\Action; use Doctrine\Tests\Models\Cache\Address; use Doctrine\Tests\Models\Cache\Client; -use Doctrine\Tests\Models\Cache\ComplexAction; use Doctrine\Tests\Models\Cache\Person; use Doctrine\Tests\Models\Cache\Token; use Doctrine\Tests\Models\Cache\Traveler; diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheQueryCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheQueryCacheTest.php index 995c1d07f..b34b0f825 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheQueryCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheQueryCacheTest.php @@ -2,10 +2,12 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\Tests\Models\Cache\Country; +use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\Query\ResultSetMapping; -use Doctrine\Tests\Models\Cache\State; 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; @@ -188,7 +190,7 @@ class SecondLevelCacheQueryCacheTest extends SecondLevelCacheAbstractTest $countryId2 = $this->countries[1]->getId(); $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')); @@ -282,6 +284,89 @@ class SecondLevelCacheQueryCacheTest extends SecondLevelCacheAbstractTest $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionMissCount($this->getDefaultQueryRegionName())); } + /** + * @group 5854 + */ + public function testMultipleNestedDQLAliases() + { + $this->loadFixturesCountries(); + $this->loadFixturesStates(); + $this->loadFixturesCities(); + $this->loadFixturesAttractions(); + + $queryRegionName = $this->getDefaultQueryRegionName(); + $cityRegionName = $this->getEntityRegion(City::CLASSNAME); + $stateRegionName = $this->getEntityRegion(State::CLASSNAME); + $attractionRegionName = $this->getEntityRegion(Attraction::CLASSNAME); + + $this->secondLevelCacheLogger->clearStats(); + $this->evictRegions(); + $this->_em->clear(); + + $queryCount = $this->getCurrentQueryCount(); + $dql = 'SELECT s, c, a FROM Doctrine\Tests\Models\Cache\State s JOIN s.cities c JOIN c.attractions a'; + $result1 = $this->_em->createQuery($dql) + ->setCacheable(true) + ->getResult(); + + $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(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(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->assertInstanceOf(State::CLASSNAME, $result1[0]); + $this->assertInstanceOf(State::CLASSNAME, $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->assertCount(2, $result1[0]->getCities()->get(0)->getAttractions()); + $this->assertCount(2, $result1[0]->getCities()->get(1)->getAttractions()); + $this->assertCount(2, $result1[1]->getCities()->get(0)->getAttractions()); + $this->assertCount(1, $result1[1]->getCities()->get(1)->getAttractions()); + + $this->_em->clear(); + + $result2 = $this->_em->createQuery($dql) + ->setCacheable(true) + ->getResult(); + + $this->assertCount(2, $result2); + $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); + + $this->assertInstanceOf(State::CLASSNAME, $result2[0]); + $this->assertInstanceOf(State::CLASSNAME, $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->assertCount(2, $result2[0]->getCities()->get(0)->getAttractions()); + $this->assertCount(2, $result2[0]->getCities()->get(1)->getAttractions()); + $this->assertCount(2, $result2[1]->getCities()->get(0)->getAttractions()); + $this->assertCount(1, $result2[1]->getCities()->get(1)->getAttractions()); + } + public function testBasicQueryParams() { $this->evictRegions(); @@ -339,7 +424,7 @@ class SecondLevelCacheQueryCacheTest extends SecondLevelCacheAbstractTest $this->assertEquals($this->countries[1]->getId(), $result1[1]->getId()); $this->assertEquals($this->countries[0]->getName(), $result1[0]->getName()); $this->assertEquals($this->countries[1]->getName(), $result1[1]->getName()); - + $this->assertEquals(3, $this->secondLevelCacheLogger->getPutCount()); $this->assertEquals(1, $this->secondLevelCacheLogger->getMissCount()); $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionPutCount($this->getDefaultQueryRegionName())); @@ -716,7 +801,7 @@ class SecondLevelCacheQueryCacheTest extends SecondLevelCacheAbstractTest $this->secondLevelCacheLogger->clearStats(); $this->_em->clear(); - $getHash = function(\Doctrine\ORM\AbstractQuery $query){ + $getHash = function(AbstractQuery $query){ $method = new \ReflectionMethod($query, 'getHash'); $method->setAccessible(true); @@ -1035,4 +1120,37 @@ class SecondLevelCacheQueryCacheTest extends SecondLevelCacheAbstractTest ->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); + } + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/SequenceEmulatedIdentityStrategyTest.php b/tests/Doctrine/Tests/ORM/Functional/SequenceEmulatedIdentityStrategyTest.php index 38a6e4d2d..02c891e75 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SequenceEmulatedIdentityStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SequenceEmulatedIdentityStrategyTest.php @@ -3,8 +3,9 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\DBAL\Schema\Sequence; +use Doctrine\Tests\OrmFunctionalTestCase; -class SequenceEmulatedIdentityStrategyTest extends \Doctrine\Tests\OrmFunctionalTestCase +class SequenceEmulatedIdentityStrategyTest extends OrmFunctionalTestCase { /** * {@inheritdoc} diff --git a/tests/Doctrine/Tests/ORM/Functional/SequenceGeneratorTest.php b/tests/Doctrine/Tests/ORM/Functional/SequenceGeneratorTest.php index 6cb00f686..2fcd6a1b9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SequenceGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SequenceGeneratorTest.php @@ -1,13 +1,14 @@ salesPerson = new \Doctrine\Tests\Models\Company\CompanyEmployee(); + $this->salesPerson = new CompanyEmployee(); $this->salesPerson->setName('Poor Sales Guy'); $this->salesPerson->setDepartment('Sales'); $this->salesPerson->setSalary(100); - $engineer1 = new \Doctrine\Tests\Models\Company\CompanyEmployee(); + $engineer1 = new CompanyEmployee(); $engineer1->setName('Roman B.'); $engineer1->setDepartment('IT'); $engineer1->setSalary(100); $this->engineers[] = $engineer1; - $engineer2 = new \Doctrine\Tests\Models\Company\CompanyEmployee(); + $engineer2 = new CompanyEmployee(); $engineer2->setName('Jonathan W.'); $engineer2->setDepartment('IT'); $engineer2->setSalary(100); $this->engineers[] = $engineer2; - $engineer3 = new \Doctrine\Tests\Models\Company\CompanyEmployee(); + $engineer3 = new CompanyEmployee(); $engineer3->setName('Benjamin E.'); $engineer3->setDepartment('IT'); $engineer3->setSalary(100); $this->engineers[] = $engineer3; - $engineer4 = new \Doctrine\Tests\Models\Company\CompanyEmployee(); + $engineer4 = new CompanyEmployee(); $engineer4->setName('Guilherme B.'); $engineer4->setDepartment('IT'); $engineer4->setSalary(100); @@ -61,14 +67,14 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase { $this->persistRelatedEmployees(); - $this->fix = new \Doctrine\Tests\Models\Company\CompanyFixContract(); + $this->fix = new CompanyFixContract(); $this->fix->setFixPrice(1000); $this->fix->setSalesPerson($this->salesPerson); $this->fix->addEngineer($this->engineers[0]); $this->fix->addEngineer($this->engineers[1]); $this->fix->markCompleted(); - $this->flex = new \Doctrine\Tests\Models\Company\CompanyFlexContract(); + $this->flex = new CompanyFlexContract(); $this->flex->setSalesPerson($this->salesPerson); $this->flex->setHoursWorked(100); $this->flex->setPricePerHour(100); @@ -77,7 +83,7 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->flex->addEngineer($this->engineers[3]); $this->flex->markCompleted(); - $this->ultra = new \Doctrine\Tests\Models\Company\CompanyFlexUltraContract(); + $this->ultra = new CompanyFlexUltraContract(); $this->ultra->setSalesPerson($this->salesPerson); $this->ultra->setHoursWorked(150); $this->ultra->setPricePerHour(150); @@ -96,7 +102,7 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase { $this->persistRelatedEmployees(); - $fixContract = new \Doctrine\Tests\Models\Company\CompanyFixContract(); + $fixContract = new CompanyFixContract(); $fixContract->setFixPrice(1000); $fixContract->setSalesPerson($this->salesPerson); @@ -115,7 +121,7 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase { $this->persistRelatedEmployees(); - $ultraContract = new \Doctrine\Tests\Models\Company\CompanyFlexUltraContract(); + $ultraContract = new CompanyFlexUltraContract(); $ultraContract->setSalesPerson($this->salesPerson); $ultraContract->setHoursWorked(100); $ultraContract->setPricePerHour(50); @@ -366,7 +372,9 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $repository = $this->_em->getRepository("Doctrine\Tests\Models\Company\CompanyContract"); - $this->setExpectedException('Doctrine\ORM\Persisters\PersisterException', 'annot match on Doctrine\Tests\Models\Company\CompanyContract::salesPerson with a non-object value.'); + $this->expectException(PersisterException::class); + $this->expectExceptionMessage('annot match on Doctrine\Tests\Models\Company\CompanyContract::salesPerson with a non-object value.'); + $contracts = $repository->matching(new Criteria( Criteria::expr()->eq('salesPerson', $this->salesPerson->getId()) )); diff --git a/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php b/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php index 31f28db3b..a335b234e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php @@ -8,12 +8,13 @@ use Doctrine\Tests\Models\ECommerce\ECommerceCart, Doctrine\Tests\Models\ECommerce\ECommerceProduct; use Doctrine\ORM\Mapping\AssociationMapping; +use Doctrine\Tests\OrmFunctionalTestCase; /** * Tests capabilities of the persister. * @author Giorgio Sironi */ -class StandardEntityPersisterTest extends \Doctrine\Tests\OrmFunctionalTestCase +class StandardEntityPersisterTest extends OrmFunctionalTestCase { protected function setUp() { @@ -56,7 +57,7 @@ class StandardEntityPersisterTest extends \Doctrine\Tests\OrmFunctionalTestCase $p = new ECommerceProduct; $p->addFeature($f1); - $p->addfeature($f2); + $p->addFeature($f2); $this->_em->persist($p); $this->_em->flush(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1040Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1040Test.php index 1b7c5b521..988e8ba99 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1040Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1040Test.php @@ -2,14 +2,14 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Tests\Models\CMS\CmsArticle; use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\OrmFunctionalTestCase; /** * @group DDC-1040 */ -class DDC1040Test extends \Doctrine\Tests\OrmFunctionalTestCase +class DDC1040Test extends OrmFunctionalTestCase { public function setUp() { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1041Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1041Test.php index 0cf14aecc..ee1218187 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1041Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1041Test.php @@ -2,12 +2,13 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Tests\Models\Company\CompanyFixContract; +use Doctrine\Tests\OrmFunctionalTestCase; /** * @group DDC-1041 */ -class DDC1041Test extends \Doctrine\Tests\OrmFunctionalTestCase +class DDC1041Test extends OrmFunctionalTestCase { public function setUp() { @@ -17,7 +18,7 @@ class DDC1041Test extends \Doctrine\Tests\OrmFunctionalTestCase public function testGrabWrongSubtypeReturnsNull() { - $fix = new \Doctrine\Tests\Models\Company\CompanyFixContract(); + $fix = new CompanyFixContract(); $fix->setFixPrice(2000); $this->_em->persist($fix); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1043Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1043Test.php index babb43844..f3e255042 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1043Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1043Test.php @@ -2,12 +2,13 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\OrmFunctionalTestCase; /** * @group DDC-1043 */ -class DDC1043Test extends \Doctrine\Tests\OrmFunctionalTestCase +class DDC1043Test extends OrmFunctionalTestCase { public function setUp() { @@ -17,7 +18,7 @@ class DDC1043Test extends \Doctrine\Tests\OrmFunctionalTestCase public function testChangeSetPlusWeirdPHPCastingIntCastingRule() { - $user = new \Doctrine\Tests\Models\CMS\CmsUser(); + $user = new CmsUser(); $user->name = "John Galt"; $user->username = "jgalt"; $user->status = "+44"; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1050Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1050Test.php index d95605425..fccb0fd4c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1050Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1050Test.php @@ -2,12 +2,13 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\OrmFunctionalTestCase; /** * @group DDC-1050 */ -class DDC1050Test extends \Doctrine\Tests\OrmFunctionalTestCase +class DDC1050Test extends OrmFunctionalTestCase { public function setUp() { @@ -21,9 +22,9 @@ class DDC1050Test extends \Doctrine\Tests\OrmFunctionalTestCase public function testPerformance() { for ($i = 2; $i < 10000; ++$i) { - $user = new \Doctrine\Tests\Models\CMS\CmsUser(); + $user = new CmsUser(); $user->status = 'developer'; - $user->username = 'jwage'+$i; + $user->username = 'jwage'.$i; $user->name = 'Jonathan'; $this->_em->persist($user); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1080Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1080Test.php index 500b4e1e1..9369ca4c9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1080Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1080Test.php @@ -2,10 +2,12 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\Tests\OrmFunctionalTestCase; + /** * @group DDC-1080 */ -class DDC1080Test extends \Doctrine\Tests\OrmFunctionalTestCase +class DDC1080Test extends OrmFunctionalTestCase { public function testHydration() { @@ -55,7 +57,7 @@ class DDC1080Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->flush(); $this->_em->clear(); - $foo = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC1080Foo', $foo1->getFooId()); + $foo = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC1080Foo', $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 335c89dce..e40f27994 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1113Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1113Test.php @@ -2,8 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Common\Collections\ArrayCollection; - /** * @group DDC-1113 * @group DDC-1306 diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1129Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1129Test.php index 70d2e9fea..1f59d07ba 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1129Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1129Test.php @@ -2,8 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Common\Collections\ArrayCollection; - /** * @group DDC-1129 */ diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php index 5a6d2e599..b6d82816c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php @@ -2,7 +2,9 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -class DDC1181Test extends \Doctrine\Tests\OrmFunctionalTestCase +use Doctrine\Tests\OrmFunctionalTestCase; + +class DDC1181Test extends OrmFunctionalTestCase { public function setUp() { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php index 8e77ff0a3..a4ecf5d39 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php @@ -1,9 +1,10 @@ markTestSkipped("PostgreSQL only test."); } - $sql = $this->_schemaTool->getCreateSchemaSQL(array( + $sql = $this->_schemaTool->getCreateSchemaSql(array( $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1360DoubleQuote') )); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1383Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1383Test.php index ad5fc4317..fb6ae25e6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1383Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1383Test.php @@ -1,7 +1,6 @@ groups = $user1->groups; $user2->groups->add($group3); - $this->assertEQuals(1, count($user1->groups->getInsertDiff())); + $this->assertCount(1, $user1->groups->getInsertDiff()); $this->_em->persist($group3); $this->_em->flush(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1685Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1685Test.php index ee4c64a19..52e028394 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1685Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1685Test.php @@ -55,7 +55,9 @@ class DDC1685Test extends \Doctrine\Tests\OrmFunctionalTestCase { $this->paginator->setUseOutputWalkers(false); - $this->setExpectedException('RuntimeException', 'Paginating an entity with foreign key as identifier only works when using the Output Walkers. Call Paginator#setUseOutputWalkers(true) before iterating the paginator.'); + $this->expectException(\RuntimeException::class); + $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); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1707Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1707Test.php index c6c23b991..5e587c4df 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1707Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1707Test.php @@ -2,12 +2,13 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\ORM\Event\LifecycleEventArgs; +use Doctrine\ORM\Events; +use Doctrine\Tests\OrmFunctionalTestCase; /** * @group DDC-1707 */ -class DDC1707Test extends \Doctrine\Tests\OrmFunctionalTestCase +class DDC1707Test extends OrmFunctionalTestCase { public function setUp() { @@ -27,9 +28,8 @@ class DDC1707Test extends \Doctrine\Tests\OrmFunctionalTestCase { $class = $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1707Child'); $entity = new DDC1707Child(); - $event = new LifecycleEventArgs($entity, $this->_em); - $class->invokeLifecycleCallbacks(\Doctrine\ORM\Events::postLoad, $entity, $event); + $class->invokeLifecycleCallbacks(Events::postLoad, $entity); $this->assertTrue($entity->postLoad); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php index b02f401b7..13b1868d5 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php @@ -2,9 +2,9 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\ORM\UnitOfWork; +use Doctrine\Tests\OrmFunctionalTestCase; -class DDC1757Test extends \Doctrine\Tests\OrmFunctionalTestCase +class DDC1757Test extends OrmFunctionalTestCase { public function testFailingCase() { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1778Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1778Test.php index aebc6422c..b2e02c26b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1778Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1778Test.php @@ -23,9 +23,9 @@ class DDC1778Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->user->name = "Benjamin"; $this->user->status = "active"; - $this->phone = new CmsPhoneNumber(); + $this->phone = new CmsPhonenumber(); $this->phone->phonenumber = '0123456789'; - $this->user->addPhoneNumber($this->phone); + $this->user->addPhonenumber($this->phone); $this->_em->persist($this->user); $this->_em->persist($this->phone); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1884Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1884Test.php index b3199fcc7..46f7cca7f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1884Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1884Test.php @@ -1,9 +1,7 @@ _schemaTool->createSchema(array( diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2256Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2256Test.php index 949091f77..42aeca43e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2256Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2256Test.php @@ -10,9 +10,9 @@ use Doctrine\ORM\Query\ResultSetMappingBuilder; */ class DDC2256Test extends \Doctrine\Tests\OrmFunctionalTestCase { - protected function setup() + protected function setUp() { - parent::setup(); + parent::setUp(); $this->_schemaTool->createSchema(array( $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2256User'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2256Group') diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2306Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2306Test.php index 6a4066c19..ca3ee1a50 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2306Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2306Test.php @@ -12,9 +12,9 @@ class DDC2306Test extends \Doctrine\Tests\OrmFunctionalTestCase /** * {@inheritDoc} */ - protected function setup() + protected function setUp() { - parent::setup(); + parent::setUp(); $this->_schemaTool->createSchema(array( $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2306Zone'), diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2346Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2346Test.php index 8832b0f50..3d2781763 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2346Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2346Test.php @@ -18,9 +18,9 @@ class DDC2346Test extends \Doctrine\Tests\OrmFunctionalTestCase /** * {@inheritDoc} */ - protected function setup() + protected function setUp() { - parent::setup(); + parent::setUp(); $this->_schemaTool->createSchema(array( $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2346Foo'), diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2359Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2359Test.php index c1189d797..12be3241a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2359Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2359Test.php @@ -1,7 +1,12 @@ getMock('Doctrine\\Common\\Persistence\\Mapping\\Driver\\MappingDriver'); - $mockMetadata = $this->getMock('Doctrine\\ORM\\Mapping\\ClassMetadata', array(), array(), '', false); - $entityManager = $this->getMock('Doctrine\\ORM\\EntityManager', array(), array(), '', false); + $mockDriver = $this->createMock(MappingDriver::class); + $mockMetadata = $this->createMock(ClassMetadata::class); + $entityManager = $this->createMock(EntityManager::class); /* @var $metadataFactory \Doctrine\ORM\Mapping\ClassMetadataFactory|\PHPUnit_Framework_MockObject_MockObject */ - $metadataFactory = $this->getMock( - 'Doctrine\\ORM\\Mapping\\ClassMetadataFactory', - array('newClassMetadataInstance', 'wakeupReflection') - ); - - $configuration = $this->getMock('Doctrine\\ORM\\Configuration', array('getMetadataDriverImpl')); - $connection = $this->getMock('Doctrine\\DBAL\\Connection', array(), array(), '', false); + $metadataFactory = $this->getMockBuilder(ClassMetadataFactory::class) + ->setMethods(array('newClassMetadataInstance', 'wakeupReflection')) + ->getMock(); + + $configuration = $this->getMockBuilder(Configuration::class) + ->setMethods(array('getMetadataDriverImpl')) + ->getMock(); + + $connection = $this->createMock(Connection::class); $configuration ->expects($this->any()) @@ -39,7 +46,7 @@ class DDC2359Test extends \PHPUnit_Framework_TestCase $entityManager ->expects($this->any()) ->method('getEventManager') - ->will($this->returnValue($this->getMock('Doctrine\\Common\\EventManager'))); + ->will($this->returnValue($this->createMock(EventManager::class))); $metadataFactory->expects($this->any())->method('newClassMetadataInstance')->will($this->returnValue($mockMetadata)); $metadataFactory->expects($this->once())->method('wakeupReflection'); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC258Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC258Test.php index 39b918d26..d9dca3752 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC258Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC258Test.php @@ -1,7 +1,10 @@ _schemaTool->createSchema(array( diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2692Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2692Test.php index 94c3d60f0..437f89ffb 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2692Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2692Test.php @@ -13,9 +13,9 @@ class DDC2692Test extends \Doctrine\Tests\OrmFunctionalTestCase /** * {@inheritDoc} */ - protected function setup() + protected function setUp() { - parent::setup(); + parent::setUp(); try { $this->_schemaTool->createSchema(array( @@ -29,7 +29,10 @@ class DDC2692Test extends \Doctrine\Tests\OrmFunctionalTestCase public function testIsListenerCalledOnlyOnceOnPreFlush() { - $listener = $this->getMock('Doctrine\Tests\ORM\Functional\Ticket\DDC2692Listener', array('preFlush')); + $listener = $this->getMockBuilder(DDC2692Listener::class) + ->setMethods(array('preFlush')) + ->getMock(); + $listener->expects($this->once())->method('preFlush'); $this->_em->getEventManager()->addEventSubscriber($listener); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2759Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2759Test.php index a071d4c0c..6198663e6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2759Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2759Test.php @@ -10,9 +10,9 @@ class DDC2759Test extends \Doctrine\Tests\OrmFunctionalTestCase /** * {@inheritDoc} */ - protected function setup() + protected function setUp() { - parent::setup(); + parent::setUp(); try { $this->_schemaTool->createSchema(array( diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php index 0ba50564f..87c94cb84 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php @@ -16,9 +16,9 @@ class DDC2825Test extends \Doctrine\Tests\OrmFunctionalTestCase /** * {@inheritDoc} */ - protected function setup() + protected function setUp() { - parent::setup(); + parent::setUp(); $platform = $this->_em->getConnection()->getDatabasePlatform(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2996Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2996Test.php index 30724b2c7..09d7415d2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2996Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2996Test.php @@ -2,9 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Common\Collections\ArrayCollection; -use Doctrine\ORM\Event\LifecycleEventArgs; - /** * @group DDC-2996 */ diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC309Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC309Test.php index af1fcdc87..402c4374a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC309Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC309Test.php @@ -1,7 +1,10 @@ _em->persist($user); $uow->scheduleExtraUpdate($user, array('name' => 'changed name')); - $listener = $this->getMock('stdClass', array(Events::postFlush)); + $listener = $this->getMockBuilder(\stdClass::class) + ->setMethods(array(Events::postFlush)) + ->getMock(); $listener ->expects($this->once()) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php index 591b0fd71..4924d39f9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3170Test.php @@ -13,9 +13,9 @@ class DDC3170Test extends \Doctrine\Tests\OrmFunctionalTestCase /** * {@inheritDoc} */ - protected function setup() + protected function setUp() { - parent::setup(); + parent::setUp(); $this->_schemaTool->createSchema( array( diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3303Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3303Test.php new file mode 100644 index 000000000..b40f99ff9 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3303Test.php @@ -0,0 +1,91 @@ +_schemaTool->createSchema([$this->_em->getClassMetadata(DDC3303Employee::class)]); + } + + /** + * @group 4097 + * @group 4277 + * @group 5867 + * + * When using an embedded field in an inheritance, private properties should also be inherited. + */ + public function testEmbeddedObjectsAreAlsoInherited() + { + $employee = new DDC3303Employee( + 'John Doe', + new DDC3303Address('Somewhere', 123, 'Over the rainbow'), + 'Doctrine Inc' + ); + + $this->_em->persist($employee); + $this->_em->flush(); + $this->_em->clear(); + + self::assertEquals($employee, $this->_em->find(DDC3303Employee::class, 'John Doe')); + } +} + +/** @MappedSuperclass */ +abstract class DDC3303Person +{ + /** @Id @GeneratedValue(strategy="NONE") @Column(type="string") @var string */ + private $name; + + /** @Embedded(class="DDC3303Address") @var DDC3303Address */ + private $address; + + public function __construct($name, DDC3303Address $address) + { + $this->name = $name; + $this->address = $address; + } +} + +/** + * @Embeddable + */ +class DDC3303Address +{ + /** @Column(type="string") @var string */ + private $street; + + /** @Column(type="integer") @var int */ + private $number; + + /** @Column(type="string") @var string */ + private $city; + + public function __construct($street, $number, $city) + { + $this->street = $street; + $this->number = $number; + $this->city = $city; + } +} + +/** + * @Entity + * @Table(name="ddc3303_employee") + */ +class DDC3303Employee extends DDC3303Person +{ + /** @Column(type="string") @var string */ + private $company; + + public function __construct($name, DDC3303Address $address, $company) + { + parent::__construct($name, $address); + + $this->company = $company; + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC331Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC331Test.php index 88da3268f..5ec8ad730 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC331Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC331Test.php @@ -2,15 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -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\CompanyEvent, - Doctrine\Tests\Models\Company\CompanyAuction, - Doctrine\Tests\Models\Company\CompanyRaffle, - Doctrine\Tests\Models\Company\CompanyCar; - /** * Functional tests for the Class Table Inheritance mapping strategy. * @@ -31,7 +22,7 @@ class DDC331Test extends \Doctrine\Tests\OrmFunctionalTestCase $q = $this->_em->createQuery('SELECT e.name FROM Doctrine\Tests\Models\Company\CompanyEmployee e'); $this->assertEquals( strtolower('SELECT c0_.name AS name_0 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id LEFT JOIN company_managers c2_ ON c1_.id = c2_.id'), - strtolower($q->getSql()) + strtolower($q->getSQL()) ); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3699Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3699Test.php index a2eff6b57..b33f9a448 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3699Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3699Test.php @@ -1,7 +1,5 @@ - */ namespace Doctrine\Tests\ORM\Functional\Ticket; @@ -9,6 +6,9 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; 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 @@ class DDC3711Test extends YamlMappingDriverTest $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/Functional/Ticket/DDC381Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC381Test.php index 941685a0d..eb3b77f56 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC381Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC381Test.php @@ -2,8 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\ORM\UnitOfWork; - class DDC381Test extends \Doctrine\Tests\OrmFunctionalTestCase { protected function setUp() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC4003Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC4003Test.php index 5a0cfda59..1c286781a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC4003Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC4003Test.php @@ -1,6 +1,7 @@ -_em->persist($entity); $this->_em->getUnitOfWork()->computeChangeSet($this->_em->getClassMetadata(get_class($entity)), $entity); - $data1 = $this->_em->getUnitOfWork()->getEntityChangeset($entity); + $data1 = $this->_em->getUnitOfWork()->getEntityChangeSet($entity); $entity->setType('type2'); $this->_em->getUnitOfWork()->recomputeSingleEntityChangeSet($this->_em->getClassMetadata(get_class($entity)), $entity); - $data2 = $this->_em->getUnitOfWork()->getEntityChangeset($entity); + $data2 = $this->_em->getUnitOfWork()->getEntityChangeSet($entity); $this->assertEquals(array_keys($data1), array_keys($data2)); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC698Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC698Test.php index f4713c8ab..cf15770a8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC698Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC698Test.php @@ -2,8 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use DateTime; - class DDC698Test extends \Doctrine\Tests\OrmFunctionalTestCase { protected function setUp() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC748Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC748Test.php index 84a35a7e7..b71ae5cde 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC748Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC748Test.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\CMS\CmsArticle; use Doctrine\Tests\Models\CMS\CmsAddress; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC758Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC758Test.php index 716ec6f5e..295542aab 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC758Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC758Test.php @@ -4,7 +4,6 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Tests\Models\CMS\CmsUser; -use Doctrine\Tests\Models\CMS\CmsPhonenumber; use Doctrine\Tests\Models\CMS\CmsGroup; class DDC758Test extends \Doctrine\Tests\OrmFunctionalTestCase @@ -23,7 +22,7 @@ class DDC758Test extends \Doctrine\Tests\OrmFunctionalTestCase */ private function setCascadeMergeFor($class) { - $metadata = $this->_em->getMetadataFactory()->getMetaDataFor($class); + $metadata = $this->_em->getMetadataFactory()->getMetadataFor($class); foreach ($metadata->associationMappings as $key => $associationMapping) { $metadata->associationMappings[$key]["isCascadePersist"] = false; $metadata->associationMappings[$key]["isCascadeMerge"] = true; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC767Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC767Test.php index 1072fc00c..bcf72e4e9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC767Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC767Test.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\CMS\CmsGroup; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php index 7527bba98..a88bbad81 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php @@ -2,10 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Common\Collections\ArrayCollection; -use Doctrine\Tests\Models\CMS\CmsUser; -use Doctrine\Tests\Models\CMS\CmsGroup; - class DDC809Test extends \Doctrine\Tests\OrmFunctionalTestCase { public function setUp() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php index 8bc7c69f0..219aed48d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php @@ -2,10 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Common\Collections\ArrayCollection; -use Doctrine\Tests\Models\CMS\CmsUser; -use Doctrine\Tests\Models\CMS\CmsGroup; - class DDC832Test extends \Doctrine\Tests\OrmFunctionalTestCase { public function setUp() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC849Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC849Test.php index 78cfd2958..bab38f0be 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC849Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC849Test.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\CMS\CmsGroup; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC933Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC933Test.php index ca03cc179..e4c9d1328 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC933Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC933Test.php @@ -2,11 +2,9 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Common\Collections\ArrayCollection; -use Doctrine\Tests\Models\CMS\CmsUser; -use Doctrine\Tests\Models\CMS\CmsGroup; +use Doctrine\Tests\OrmFunctionalTestCase; -class DDC933Test extends \Doctrine\Tests\OrmFunctionalTestCase +class DDC933Test extends OrmFunctionalTestCase { public function setUp() { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC949Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC949Test.php index fa8be3848..a1634fe5d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC949Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC949Test.php @@ -2,10 +2,10 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Tests\Models\Generic\BooleanModel; +use Doctrine\Tests\OrmFunctionalTestCase; -class DDC949Test extends \Doctrine\Tests\OrmFunctionalTestCase +class DDC949Test extends OrmFunctionalTestCase { public function setUp() { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC960Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC960Test.php index ce39b9e01..b1432ec8b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC960Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC960Test.php @@ -2,9 +2,9 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Tests\OrmFunctionalTestCase; -class DDC960Test extends \Doctrine\Tests\OrmFunctionalTestCase +class DDC960Test extends OrmFunctionalTestCase { protected function setUp() { 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 000000000..b42dd6534 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5762Test.php @@ -0,0 +1,188 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(GH5762Driver::class), + $this->_em->getClassMetadata(GH5762DriverRide::class), + $this->_em->getClassMetadata(GH5762Car::class), + )); + } + + public function testIssue() + { + $result = $this->fetchData(); + + 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; + } + + 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() + { + $this->createData(); + + $qb = $this->_em->createQueryBuilder(); + $qb->select('d, dr, c') + ->from(GH5762Driver::class, '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") + */ + public $id; + + /** + * @Column(type="string", length=255); + */ + public $name; + + /** + * @OneToMany(targetEntity="GH5762DriverRide", mappedBy="driver") + */ + public $driverRides; + + public function __construct($id, $name) + { + $this->driverRides = new ArrayCollection(); + $this->id = $id; + $this->name = $name; + } +} + +/** + * @Entity + * @Table(name="driver_ride") + */ +class GH5762DriverRide +{ + /** + * @Id + * @ManyToOne(targetEntity="GH5762Driver", inversedBy="driverRides") + * @JoinColumn(name="driver_id", referencedColumnName="id") + */ + public $driver; + + /** + * @Id + * @ManyToOne(targetEntity="GH5762Car", inversedBy="carRides") + * @JoinColumn(name="car", referencedColumnName="brand") + */ + public $car; + + function __construct(GH5762Driver $driver, GH5762Car $car) + { + $this->driver = $driver; + $this->car = $car; + + $this->driver->driverRides->add($this); + $this->car->carRides->add($this); + } +} + +/** + * @Entity + * @Table(name="car") + */ +class GH5762Car +{ + + /** + * @Id + * @Column(type="string", length=25) + * @GeneratedValue(strategy="NONE") + */ + public $brand; + + /** + * @Column(type="string", length=255); + */ + public $model; + + /** + * @OneToMany(targetEntity="GH5762DriverRide", mappedBy="car") + */ + public $carRides; + + public function __construct($brand, $model) + { + $this->carRides = new ArrayCollection(); + $this->brand = $brand; + $this->model = $model; + } +} 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 000000000..cf601b99a --- /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 = ['tag1', 'tag2']; + $manager->tags = $managerTags; + $this->_em->persist($manager); + + $employee = new Issue5989Employee(); + + $employeeTags =['tag2', 'tag3']; + $employee->tags = $employeeTags; + $this->_em->persist($employee); + + $this->_em->flush(); + + $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 + $this->_em->clear(); + + $repository = $this->_em->getRepository(Issue5989Person::class); + + $manager = $repository->find($managerId); + $employee = $repository->find($employeeId); + + static::assertEquals($managerTags, $manager->tags); + static::assertEquals($employeeTags, $employee->tags); + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php index 47064d5e2..c27e0dee6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php @@ -9,8 +9,9 @@ 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 \Doctrine\Tests\OrmFunctionalTestCase +class TypeTest extends OrmFunctionalTestCase { protected function setUp() { diff --git a/tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php b/tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php index aae0fbc71..8e305d1f1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php @@ -6,8 +6,9 @@ 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 \Doctrine\Tests\OrmFunctionalTestCase +class TypeValueSqlTest extends OrmFunctionalTestCase { protected function setUp() { diff --git a/tests/Doctrine/Tests/ORM/Functional/UUIDGeneratorTest.php b/tests/Doctrine/Tests/ORM/Functional/UUIDGeneratorTest.php index 5fa237ee4..d5d559a4f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/UUIDGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/UUIDGeneratorTest.php @@ -1,10 +1,11 @@ _em->persist($user); $this->_em->flush(); - $this->setExpectedException("Doctrine\ORM\ORMInvalidArgumentException", "A managed+dirty entity Doctrine\Tests\Models\CMS\CmsUser"); + $this->expectException(ORMInvalidArgumentException::class); + $this->expectExceptionMessage('A managed+dirty entity Doctrine\Tests\Models\CMS\CmsUser'); + $this->_em->getUnitOfWork()->scheduleForInsert($user); } @@ -36,7 +40,9 @@ class UnitOfWorkLifecycleTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->remove($user); - $this->setExpectedException("Doctrine\ORM\ORMInvalidArgumentException", "Removed entity Doctrine\Tests\Models\CMS\CmsUser"); + $this->expectException(ORMInvalidArgumentException::class); + $this->expectExceptionMessage('Removed entity Doctrine\Tests\Models\CMS\CmsUser'); + $this->_em->getUnitOfWork()->scheduleForInsert($user); } @@ -49,7 +55,9 @@ class UnitOfWorkLifecycleTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->getUnitOfWork()->scheduleForInsert($user); - $this->setExpectedException("Doctrine\ORM\ORMInvalidArgumentException", "Entity Doctrine\Tests\Models\CMS\CmsUser"); + $this->expectException(ORMInvalidArgumentException::class); + $this->expectExceptionMessage('Entity Doctrine\Tests\Models\CMS\CmsUser'); + $this->_em->getUnitOfWork()->scheduleForInsert($user); } @@ -57,7 +65,9 @@ class UnitOfWorkLifecycleTest extends \Doctrine\Tests\OrmFunctionalTestCase { $user = new CmsUser(); - $this->setExpectedException("Doctrine\ORM\ORMInvalidArgumentException", "The given entity of type 'Doctrine\Tests\Models\CMS\CmsUser' (Doctrine\Tests\Models\CMS\CmsUser@"); + $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()); } @@ -65,7 +75,9 @@ class UnitOfWorkLifecycleTest extends \Doctrine\Tests\OrmFunctionalTestCase { $user = new CmsUser(); - $this->setExpectedException("Doctrine\ORM\ORMInvalidArgumentException", "Only managed entities can be marked or checked as read only. But Doctrine\Tests\Models\CMS\CmsUser@"); + $this->expectException(ORMInvalidArgumentException::class); + $this->expectExceptionMessage('Only managed entities can be marked or checked as read only. But Doctrine\Tests\Models\CMS\CmsUser@'); + $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 877d1a279..a6ad68d0a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php index 6b56073a3..327791648 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php index 3d1df24b8..a8ea389c9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php index 66193fb14..2c51d6cd2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php index 17a8ea873..e899fbeb8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php index c094afa78..eabf26a80 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php index e83453714..137a5eaa9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php index 4a595c21f..762cad2ee 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php index 96daa6016..a179ab61a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php index 15e45f9fe..0de217e36 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php index 264ea4309..47e98d25c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php @@ -1,11 +1,14 @@ setExpectedException('Doctrine\ORM\Query\QueryException', 'no field or association named address.asdfasdf'); + $this->expectException(QueryException::class); + $this->expectExceptionMessage('no field or association named address.asdfasdf'); $this->_em->createQuery("SELECT p FROM " . __NAMESPACE__ . "\\DDC93Person p WHERE p.address.asdfasdf IS NULL") ->execute(); @@ -235,8 +239,9 @@ class ValueObjectsTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testPartialDqlWithNonExistentEmbeddableField() { - $this->setExpectedException('Doctrine\ORM\Query\QueryException', "no mapped field named 'address.asdfasdf'"); - + $this->expectException(QueryException::class); + $this->expectExceptionMessage("no mapped field named 'address.asdfasdf'"); + $this->_em->createQuery("SELECT PARTIAL p.{id,address.asdfasdf} FROM " . __NAMESPACE__ . "\\DDC93Person p") ->execute(); } @@ -296,8 +301,8 @@ class ValueObjectsTest extends \Doctrine\Tests\OrmFunctionalTestCase */ public function testThrowsExceptionOnInfiniteEmbeddableNesting($embeddableClassName, $declaredEmbeddableClassName) { - $this->setExpectedException( - 'Doctrine\ORM\Mapping\MappingException', + $this->expectException(MappingException::class); + $this->expectExceptionMessage( sprintf( 'Infinite nesting detected for embedded property %s::nested. ' . 'You cannot embed an embeddable from the same type inside an embeddable.', diff --git a/tests/Doctrine/Tests/ORM/Functional/VersionedOneToOneTest.php b/tests/Doctrine/Tests/ORM/Functional/VersionedOneToOneTest.php index f0a89ba5e..f354be600 100644 --- a/tests/Doctrine/Tests/ORM/Functional/VersionedOneToOneTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/VersionedOneToOneTest.php @@ -5,6 +5,7 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Tests\Models\VersionedOneToOne\FirstRelatedEntity; use Doctrine\Tests\Models\VersionedOneToOne\SecondRelatedEntity; use Doctrine\ORM\ORMException; +use Doctrine\Tests\OrmFunctionalTestCase; /** * Tests that an entity with a OneToOne relationship defined as the id, with a version field can be created. @@ -13,7 +14,7 @@ use Doctrine\ORM\ORMException; * * @group VersionedOneToOne */ -class VersionedOneToOneTest extends \Doctrine\Tests\OrmFunctionalTestCase +class VersionedOneToOneTest extends OrmFunctionalTestCase { protected function setUp() { diff --git a/tests/Doctrine/Tests/ORM/Hydration/HydrationTestCase.php b/tests/Doctrine/Tests/ORM/Hydration/HydrationTestCase.php index d9c95c76a..a2b099162 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/HydrationTestCase.php +++ b/tests/Doctrine/Tests/ORM/Hydration/HydrationTestCase.php @@ -3,7 +3,6 @@ namespace Doctrine\Tests\ORM\Hydration; use Doctrine\ORM\Query\ParserResult; -use Doctrine\ORM\Query\Parser; class HydrationTestCase extends \Doctrine\Tests\OrmTestCase { diff --git a/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php index ff77312aa..22cf3b598 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php @@ -2,17 +2,14 @@ namespace Doctrine\Tests\ORM\Hydration; +use Doctrine\ORM\Proxy\ProxyFactory; use Doctrine\Tests\Mocks\HydratorMockStatement; use Doctrine\ORM\Query\ResultSetMapping; -use Doctrine\ORM\Proxy\ProxyFactory; -use Doctrine\ORM\Mapping\AssociationMapping; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Query; use Doctrine\Tests\Models\Hydration\EntityWithArrayDefaultArrayValueM2M; use Doctrine\Tests\Models\Hydration\SimpleEntity; -use Doctrine\Tests\Models\CMS\CmsUser; - class ObjectHydratorTest extends HydrationTestCase { public function provideDataForUserEntityResult() @@ -1008,7 +1005,11 @@ class ObjectHydratorTest extends HydrationTestCase $proxyInstance = new \Doctrine\Tests\Models\ECommerce\ECommerceShipping(); // mocking the proxy factory - $proxyFactory = $this->getMock('Doctrine\ORM\Proxy\ProxyFactory', array('getProxy'), array(), '', false, false, false); + $proxyFactory = $this->getMockBuilder(ProxyFactory::class) + ->setMethods(array('getProxy')) + ->disableOriginalConstructor() + ->getMock(); + $proxyFactory->expects($this->once()) ->method('getProxy') ->with($this->equalTo('Doctrine\Tests\Models\ECommerce\ECommerceShipping'), array('id' => 42)) @@ -1053,7 +1054,11 @@ class ObjectHydratorTest extends HydrationTestCase $proxyInstance = new \Doctrine\Tests\Models\ECommerce\ECommerceShipping(); // mocking the proxy factory - $proxyFactory = $this->getMock('Doctrine\ORM\Proxy\ProxyFactory', array('getProxy'), array(), '', false, false, false); + $proxyFactory = $this->getMockBuilder(ProxyFactory::class) + ->setMethods(array('getProxy')) + ->disableOriginalConstructor() + ->getMock(); + $proxyFactory->expects($this->once()) ->method('getProxy') ->with($this->equalTo('Doctrine\Tests\Models\ECommerce\ECommerceShipping'), array('id' => 42)) diff --git a/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php index eb33c23c2..d56718834 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php @@ -86,4 +86,34 @@ class SimpleObjectHydratorTest extends HydrationTestCase $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); + } } diff --git a/tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php b/tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php index cd7331054..855a9256f 100644 --- a/tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php @@ -3,13 +3,15 @@ namespace Doctrine\Tests\ORM\Id; use Doctrine\ORM\Id\AssignedGenerator; +use Doctrine\ORM\ORMException; +use Doctrine\Tests\OrmTestCase; /** * AssignedGeneratorTest * * @author robo */ -class AssignedGeneratorTest extends \Doctrine\Tests\OrmTestCase +class AssignedGeneratorTest extends OrmTestCase { private $_em; private $_assignedGen; @@ -26,13 +28,13 @@ class AssignedGeneratorTest extends \Doctrine\Tests\OrmTestCase $entity = new AssignedSingleIdEntity; $this->_assignedGen->generate($this->_em, $entity); $this->fail('Assigned generator did not throw exception even though ID was missing.'); - } catch (\Doctrine\ORM\ORMException $expected) {} + } catch (ORMException $expected) {} try { $entity = new AssignedCompositeIdEntity; $this->_assignedGen->generate($this->_em, $entity); $this->fail('Assigned generator did not throw exception even though ID was missing.'); - } catch (\Doctrine\ORM\ORMException $expected) {} + } catch (ORMException $expected) {} } public function testCorrectIdGeneration() diff --git a/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php b/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php index 413384971..5d7f7a59b 100644 --- a/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php @@ -3,13 +3,14 @@ namespace Doctrine\Tests\ORM\Id; use Doctrine\ORM\Id\SequenceGenerator; +use Doctrine\Tests\OrmTestCase; /** * Description of SequenceGeneratorTest * * @author robo */ -class SequenceGeneratorTest extends \Doctrine\Tests\OrmTestCase +class SequenceGeneratorTest extends OrmTestCase { private $_em; private $_seqGen; diff --git a/tests/Doctrine/Tests/ORM/Internal/HydrationCompleteHandlerTest.php b/tests/Doctrine/Tests/ORM/Internal/HydrationCompleteHandlerTest.php index b767bd225..1063b5aca 100644 --- a/tests/Doctrine/Tests/ORM/Internal/HydrationCompleteHandlerTest.php +++ b/tests/Doctrine/Tests/ORM/Internal/HydrationCompleteHandlerTest.php @@ -20,9 +20,11 @@ namespace Doctrine\Tests\ORM\Internal; use Doctrine\Common\Persistence\Event\LifecycleEventArgs; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Event\ListenersInvoker; use Doctrine\ORM\Events; use Doctrine\ORM\Internal\HydrationCompleteHandler; +use Doctrine\ORM\Mapping\ClassMetadata; use PHPUnit_Framework_TestCase; use stdClass; @@ -53,8 +55,8 @@ class HydrationCompleteHandlerTest extends PHPUnit_Framework_TestCase */ protected function setUp() { - $this->listenersInvoker = $this->getMock('Doctrine\ORM\Event\ListenersInvoker', array(), array(), '', false); - $this->entityManager = $this->getMock('Doctrine\ORM\EntityManagerInterface'); + $this->listenersInvoker = $this->createMock(ListenersInvoker::class); + $this->entityManager = $this->createMock(EntityManagerInterface::class); $this->handler = new HydrationCompleteHandler($this->listenersInvoker, $this->entityManager); } @@ -66,7 +68,7 @@ class HydrationCompleteHandlerTest extends PHPUnit_Framework_TestCase public function testDefersPostLoadOfEntity($listenersFlag) { /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */ - $metadata = $this->getMock('Doctrine\ORM\Mapping\ClassMetadata', array(), array(), '', false); + $metadata = $this->createMock(ClassMetadata::class); $entity = new stdClass(); $entityManager = $this->entityManager; @@ -104,7 +106,7 @@ class HydrationCompleteHandlerTest extends PHPUnit_Framework_TestCase public function testDefersPostLoadOfEntityOnlyOnce($listenersFlag) { /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */ - $metadata = $this->getMock('Doctrine\ORM\Mapping\ClassMetadata', array(), array(), '', false); + $metadata = $this->createMock(ClassMetadata::class); $entity = new stdClass(); $this @@ -131,8 +133,8 @@ class HydrationCompleteHandlerTest extends PHPUnit_Framework_TestCase { /* @var $metadata1 \Doctrine\ORM\Mapping\ClassMetadata */ /* @var $metadata2 \Doctrine\ORM\Mapping\ClassMetadata */ - $metadata1 = $this->getMock('Doctrine\ORM\Mapping\ClassMetadata', array(), array(), '', false); - $metadata2 = $this->getMock('Doctrine\ORM\Mapping\ClassMetadata', array(), array(), '', false); + $metadata1 = $this->createMock(ClassMetadata::class); + $metadata2 = $this->createMock(ClassMetadata::class); $entity1 = new stdClass(); $entity2 = new stdClass(); $entityManager = $this->entityManager; @@ -168,7 +170,7 @@ class HydrationCompleteHandlerTest extends PHPUnit_Framework_TestCase public function testSkipsDeferredPostLoadOfMetadataWithNoInvokedListeners() { /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */ - $metadata = $this->getMock('Doctrine\ORM\Mapping\ClassMetadata', array(), array(), '', false); + $metadata = $this->createMock(ClassMetadata::class); $entity = new stdClass(); $this diff --git a/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php b/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php index 92da34cda..512b21115 100644 --- a/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php @@ -4,16 +4,15 @@ namespace Doctrine\Tests\ORM; use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\LazyCriteriaCollection; -use Doctrine\Tests\Mocks\ConnectionMock; +use Doctrine\ORM\Persisters\Entity\EntityPersister; use stdClass; -use PHPUnit_Framework_TestCase; /** * @author Marco Pivetta * * @covers \Doctrine\ORM\LazyCriteriaCollection */ -class LazyCriteriaCollectionTest extends PHPUnit_Framework_TestCase +class LazyCriteriaCollectionTest extends \PHPUnit_Framework_TestCase { /** * @var \Doctrine\ORM\Persisters\Entity\EntityPersister|\PHPUnit_Framework_MockObject_MockObject @@ -35,7 +34,7 @@ class LazyCriteriaCollectionTest extends PHPUnit_Framework_TestCase */ protected function setUp() { - $this->persister = $this->getMock('Doctrine\ORM\Persisters\Entity\EntityPersister'); + $this->persister = $this->createMock(EntityPersister::class); $this->criteria = new Criteria(); $this->lazyCriteriaCollection = new LazyCriteriaCollection($this->persister, $this->criteria); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 7410979e0..8d90931f9 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -2,19 +2,22 @@ namespace Doctrine\Tests\ORM\Mapping; +use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; +use Doctrine\ORM\EntityManager; use Doctrine\ORM\Events; -use Doctrine\ORM\Event\LifecycleEventArgs; +use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\DiscriminatorColumn; use Doctrine\ORM\Mapping\Id; -use Doctrine\Tests\Models\Company\CompanyFixContract; -use Doctrine\Tests\Models\Company\CompanyFlexContract; +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\DDC2825\ExplicitSchemaAndTable; use Doctrine\Tests\Models\DDC2825\SchemaAndTableInTableName; +use Doctrine\Tests\OrmTestCase; -abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase +abstract class AbstractMappingDriverTest extends OrmTestCase { abstract protected function _loadDriver(); @@ -23,7 +26,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase $mappingDriver = $this->_loadDriver(); $class = new ClassMetadata($entityClassName); - $class->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); + $class->initializeReflection(new RuntimeReflectionService()); $mappingDriver->loadMetadataForClass($entityClassName, $class); return $class; @@ -33,11 +36,11 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase * @param \Doctrine\ORM\EntityManager $entityClassName * @return \Doctrine\ORM\Mapping\ClassMetadataFactory */ - protected function createClassMetadataFactory(\Doctrine\ORM\EntityManager $em = null) + protected function createClassMetadataFactory(EntityManager $em = null) { $driver = $this->_loadDriver(); $em = $em ?: $this->_getTestEntityManager(); - $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory(); + $factory = new ClassMetadataFactory(); $em->getConfiguration()->setMetadataDriverImpl($driver); $factory->setEntityManager($em); @@ -488,7 +491,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase $this->assertInstanceOf('Doctrine\ORM\Mapping\DefaultNamingStrategy', $em->getConfiguration()->getNamingStrategy()); - $em->getConfiguration()->setNamingStrategy(new \Doctrine\ORM\Mapping\UnderscoreNamingStrategy(CASE_UPPER)); + $em->getConfiguration()->setNamingStrategy(new UnderscoreNamingStrategy(CASE_UPPER)); $this->assertInstanceOf('Doctrine\ORM\Mapping\UnderscoreNamingStrategy', $em->getConfiguration()->getNamingStrategy()); $class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC1476\DDC1476EntityWithDefaultFieldType'); @@ -518,7 +521,8 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase */ public function testInvalidEntityOrMappedSuperClassShouldMentionParentClasses() { - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', 'Class "Doctrine\Tests\Models\DDC889\DDC889Class" sub class of "Doctrine\Tests\Models\DDC889\DDC889SuperClass" is not a valid entity or mapped super class.'); + $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'); } @@ -530,7 +534,9 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase { $factory = $this->createClassMetadataFactory(); - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', '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.'); + $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'); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php index e1838dfe8..ac17b63a2 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php @@ -2,10 +2,13 @@ namespace Doctrine\Tests\ORM\Mapping; +use Doctrine\Common\Annotations\AnnotationException; +use Doctrine\Common\Annotations\AnnotationReader; +use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; use Doctrine\ORM\Mapping\ClassMetadata; -use Doctrine\ORM\Events; -use Doctrine\Tests\Models\DDC2825\ExplicitSchemaAndTable; -use Doctrine\Tests\Models\DDC2825\SchemaAndTableInTableName; +use Doctrine\ORM\Mapping\ClassMetadataFactory; +use Doctrine\ORM\Mapping\Driver\AnnotationDriver; +use Doctrine\ORM\Mapping\MappingException; class AnnotationDriverTest extends AbstractMappingDriverTest { @@ -15,11 +18,11 @@ class AnnotationDriverTest extends AbstractMappingDriverTest public function testLoadMetadataForNonEntityThrowsException() { $cm = new ClassMetadata('stdClass'); - $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); - $reader = new \Doctrine\Common\Annotations\AnnotationReader(); - $annotationDriver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader); + $cm->initializeReflection(new RuntimeReflectionService()); + $reader = new AnnotationReader(); + $annotationDriver = new AnnotationDriver($reader); - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); + $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); $annotationDriver->loadMetadataForClass('stdClass', $cm); } @@ -42,7 +45,7 @@ class AnnotationDriverTest extends AbstractMappingDriverTest public function testColumnWithMissingTypeDefaultsToString() { $cm = new ClassMetadata('Doctrine\Tests\ORM\Mapping\ColumnWithoutType'); - $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); + $cm->initializeReflection(new RuntimeReflectionService()); $annotationDriver = $this->_loadDriver(); $annotationDriver->loadMetadataForClass('Doctrine\Tests\ORM\Mapping\InvalidColumn', $cm); @@ -134,7 +137,7 @@ class AnnotationDriverTest extends AbstractMappingDriverTest $em = $this->_getTestEntityManager(); $em->getConfiguration()->setMetadataDriverImpl($annotationDriver); - $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory(); + $factory = new ClassMetadataFactory(); $factory->setEntityManager($em); $classPage = $factory->getMetadataFor('Doctrine\Tests\Models\DirectoryTree\File'); @@ -153,12 +156,15 @@ class AnnotationDriverTest extends AbstractMappingDriverTest $em = $this->_getTestEntityManager(); $em->getConfiguration()->setMetadataDriverImpl($annotationDriver); - $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory(); + $factory = new ClassMetadataFactory(); $factory->setEntityManager($em); - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', - "It is illegal to put an inverse side one-to-many or many-to-many association on ". - "mapped superclass 'Doctrine\Tests\ORM\Mapping\InvalidMappedSuperClass#users'"); + $this->expectException(MappingException::class); + $this->expectExceptionMessage( + "It is illegal to put an inverse side one-to-many or many-to-many association on " . + "mapped superclass 'Doctrine\Tests\ORM\Mapping\InvalidMappedSuperClass#users'" + ); + $usingInvalidMsc = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\UsingInvalidMappedSuperClass'); } @@ -171,12 +177,15 @@ class AnnotationDriverTest extends AbstractMappingDriverTest $em = $this->_getTestEntityManager(); $em->getConfiguration()->setMetadataDriverImpl($annotationDriver); - $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory(); + $factory = new ClassMetadataFactory(); $factory->setEntityManager($em); - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', - "It is not supported to define inheritance information on a mapped ". - "superclass 'Doctrine\Tests\ORM\Mapping\MappedSuperClassInheritence'."); + $this->expectException(MappingException::class); + $this->expectExceptionMessage( + "It is not supported to define inheritance information on a mapped " . + "superclass 'Doctrine\Tests\ORM\Mapping\MappedSuperClassInheritence'." + ); + $usingInvalidMsc = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\MappedSuperClassInheritence'); } @@ -187,10 +196,9 @@ class AnnotationDriverTest extends AbstractMappingDriverTest { $annotationDriver = $this->_loadDriver(); - $cm = new ClassMetadata('Doctrine\Tests\ORM\Mapping\AnnotationChild'); $em = $this->_getTestEntityManager(); $em->getConfiguration()->setMetadataDriverImpl($annotationDriver); - $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory(); + $factory = new ClassMetadataFactory(); $factory->setEntityManager($em); $cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\AnnotationChild'); @@ -209,7 +217,7 @@ class AnnotationDriverTest extends AbstractMappingDriverTest $em = $this->_getTestEntityManager(); $em->getConfiguration()->setMetadataDriverImpl($annotationDriver); - $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory(); + $factory = new ClassMetadataFactory(); $factory->setEntityManager($em); $cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\ChildEntity'); @@ -221,11 +229,12 @@ class AnnotationDriverTest extends AbstractMappingDriverTest $em = $this->_getTestEntityManager(); $em->getConfiguration()->setMetadataDriverImpl($annotationDriver); - $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory(); + $factory = new ClassMetadataFactory(); $factory->setEntityManager($em); - $this->setExpectedException('Doctrine\Common\Annotations\AnnotationException', - '[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.'); + $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'); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/AnsiQuoteStrategyTest.php b/tests/Doctrine/Tests/ORM/Mapping/AnsiQuoteStrategyTest.php index 8cec99717..d5f2a9738 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AnsiQuoteStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AnsiQuoteStrategyTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Mapping; +use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; use Doctrine\ORM\Mapping\AnsiQuoteStrategy; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\Tests\OrmTestCase; @@ -39,7 +40,7 @@ class AnsiQuoteStrategyTest extends OrmTestCase private function createClassMetadata($className) { $class = new ClassMetadata($className); - $class->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); + $class->initializeReflection(new RuntimeReflectionService()); return $class; } diff --git a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php index 5a5f64277..be2bee9f5 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php @@ -5,9 +5,11 @@ namespace Doctrine\Tests\ORM\Mapping; use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\ORM\Mapping\MappingException; use Doctrine\Tests\Models\DDC869\DDC869Payment; +use Doctrine\Tests\OrmTestCase; -class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase +class BasicInheritanceMappingTest extends OrmTestCase { /** * @var ClassMetadataFactory @@ -25,7 +27,7 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase public function testGetMetadataForTransientClassThrowsException() { - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); + $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); $this->cmf->getMetadataFor('Doctrine\Tests\ORM\Mapping\TransientBaseClass'); } @@ -121,12 +123,13 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase */ public function testUnmappedEntityInHierarchy() { - $this->setExpectedException( - 'Doctrine\ORM\Mapping\MappingException', - 'Entity \'Doctrine\Tests\ORM\Mapping\HierarchyBEntity\' has to be part of the discriminator map' + $this->expectException(MappingException::class); + $this->expectExceptionMessage( + 'Entity \'Doctrine\Tests\ORM\Mapping\HierarchyBEntity\' has to be part of the discriminator map' . ' of \'Doctrine\Tests\ORM\Mapping\HierarchyBase\' to be properly mapped in the inheritance hierarchy.' . ' Alternatively you can make \'Doctrine\Tests\ORM\Mapping\HierarchyBEntity\' an abstract class to' - . ' avoid this exception from occurring.'); + . ' avoid this exception from occurring.' + ); $this->cmf->getMetadataFor(__NAMESPACE__ . '\\HierarchyE'); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php index d8824e767..da4f4abf5 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php @@ -1,31 +1,16 @@ . - */ namespace Doctrine\Tests\ORM\Mapping; +use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder; +use Doctrine\Tests\OrmTestCase; /** * @group DDC-659 */ -class ClassMetadataBuilderTest extends \Doctrine\Tests\OrmTestCase +class ClassMetadataBuilderTest extends OrmTestCase { /** * @var ClassMetadata @@ -39,7 +24,7 @@ class ClassMetadataBuilderTest extends \Doctrine\Tests\OrmTestCase public function setUp() { $this->cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); - $this->cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); + $this->cm->initializeReflection(new RuntimeReflectionService()); $this->builder = new ClassMetadataBuilder($this->cm); } @@ -526,7 +511,7 @@ class ClassMetadataBuilderTest extends \Doctrine\Tests\OrmTestCase public function testThrowsExceptionOnCreateOneToOneWithIdentityOnInverseSide() { - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); + $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); $this ->builder @@ -622,7 +607,7 @@ class ClassMetadataBuilderTest extends \Doctrine\Tests\OrmTestCase public function testThrowsExceptionOnCreateManyToManyWithIdentity() { - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); + $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); $this->builder->createManyToMany('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') ->makePrimaryKey() @@ -675,7 +660,7 @@ class ClassMetadataBuilderTest extends \Doctrine\Tests\OrmTestCase public function testThrowsExceptionOnCreateOneToManyWithIdentity() { - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); + $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); $this->builder->createOneToMany('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') ->makePrimaryKey() @@ -773,7 +758,7 @@ class ClassMetadataBuilderTest extends \Doctrine\Tests\OrmTestCase public function testExceptionOnOrphanRemovalOnManyToOne() { - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); + $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); $this->builder ->createManyToOne('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index 4cabaec88..f40d657b5 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -3,18 +3,26 @@ namespace Doctrine\Tests\ORM\Mapping; use Doctrine\Common\EventManager; +use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; +use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; +use Doctrine\DBAL\Connection; +use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Event\OnClassMetadataNotFoundEventArgs; use Doctrine\ORM\Events; use Doctrine\ORM\Id\AbstractIdGenerator; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataFactory; +use Doctrine\ORM\Mapping\MappingException; +use Doctrine\ORM\ORMException; use Doctrine\Tests\Mocks\ConnectionMock; use Doctrine\Tests\Mocks\DriverMock; use Doctrine\Tests\Mocks\EntityManagerMock; use Doctrine\Tests\Mocks\MetadataDriverMock; +use Doctrine\Tests\OrmTestCase; -class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase +class ClassMetadataFactoryTest extends OrmTestCase { public function testGetMetadataForSingleClass() { @@ -75,7 +83,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase $cm1->customGeneratorDefinition = array("class" => "NotExistingGenerator"); $cmf = $this->_createTestFactory(); $cmf->setMetadataForClass($cm1->name, $cm1); - $this->setExpectedException("Doctrine\ORM\ORMException"); + $this->expectException(ORMException::class); $actual = $cmf->getMetadataFor($cm1->name); } @@ -86,7 +94,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_CUSTOM); $cmf = $this->_createTestFactory(); $cmf->setMetadataForClass($cm1->name, $cm1); - $this->setExpectedException("Doctrine\ORM\ORMException"); + $this->expectException(ORMException::class); $actual = $cmf->getMetadataFor($cm1->name); } @@ -116,7 +124,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase public function testIsTransient() { $cmf = new ClassMetadataFactory(); - $driver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver'); + $driver = $this->createMock(MappingDriver::class); $driver->expects($this->at(0)) ->method('isTransient') ->with($this->equalTo('Doctrine\Tests\Models\CMS\CmsUser')) @@ -138,7 +146,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase public function testIsTransientEntityNamespace() { $cmf = new ClassMetadataFactory(); - $driver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver'); + $driver = $this->createMock(MappingDriver::class); $driver->expects($this->at(0)) ->method('isTransient') ->with($this->equalTo('Doctrine\Tests\Models\CMS\CmsUser')) @@ -186,7 +194,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase // ClassMetadataFactory::addDefaultDiscriminatorMap shouldn't be called again, because the // discriminator map is already cached - $cmf = $this->getMock('Doctrine\ORM\Mapping\ClassMetadataFactory', array('addDefaultDiscriminatorMap')); + $cmf = $this->getMockBuilder(ClassMetadataFactory::class)->setMethods(array('addDefaultDiscriminatorMap'))->getMock(); $cmf->setEntityManager($em); $cmf->expects($this->never()) ->method('addDefaultDiscriminatorMap'); @@ -197,9 +205,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase public function testGetAllMetadataWorksWithBadConnection() { // DDC-3551 - $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') - ->disableOriginalConstructor() - ->getMock(); + $conn = $this->createMock(Connection::class); $mockDriver = new MetadataDriverMock(); $em = $this->_createEntityManager($mockDriver, $conn); @@ -219,7 +225,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase protected function _createEntityManager($metadataDriver, $conn = null) { $driverMock = new DriverMock(); - $config = new \Doctrine\ORM\Configuration(); + $config = new Configuration(); $config->setProxyDir(__DIR__ . '/../../Proxies'); $config->setProxyNamespace('Doctrine\Tests\Proxies'); $eventManager = new EventManager(); @@ -251,7 +257,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase { // Self-made metadata $cm1 = new ClassMetadata('Doctrine\Tests\ORM\Mapping\TestEntity1'); - $cm1->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); + $cm1->initializeReflection(new RuntimeReflectionService()); $cm1->setPrimaryTable(array('name' => '`group`')); // Add a mapped field $cm1->mapField(array('fieldName' => 'name', 'type' => 'string')); @@ -358,11 +364,11 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase { $test = $this; /* @var $metadata \Doctrine\Common\Persistence\Mapping\ClassMetadata */ - $metadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata'); + $metadata = $this->createMock(ClassMetadata::class); $cmf = new ClassMetadataFactory(); $mockDriver = new MetadataDriverMock(); $em = $this->_createEntityManager($mockDriver); - $listener = $this->getMock('stdClass', array('onClassMetadataNotFound')); + $listener = $this->getMockBuilder(\stdClass::class)->setMethods(array('onClassMetadataNotFound'))->getMock(); $eventManager = $em->getEventManager(); $cmf->setEntityManager($em); @@ -391,7 +397,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase $classMetadataFactory = new ClassMetadataFactory(); /* @var $entityManager EntityManager */ - $entityManager = $this->getMock('Doctrine\\ORM\\EntityManagerInterface'); + $entityManager = $this->createMock(EntityManagerInterface::class); $classMetadataFactory->setEntityManager($entityManager); @@ -416,10 +422,8 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase $cmf->setMetadataForClass($metadata->name, $metadata); - $this->setExpectedException( - 'Doctrine\ORM\Mapping\MappingException', - 'The embed mapping \'embedded\' misses the \'class\' attribute.' - ); + $this->expectException(MappingException::class); + $this->expectExceptionMessage('The embed mapping \'embedded\' misses the \'class\' attribute.'); $cmf->getMetadataFor($metadata->name); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataLoadEventTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataLoadEventTest.php index 2d949aeef..04cea3894 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataLoadEventTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataLoadEventTest.php @@ -2,10 +2,11 @@ namespace Doctrine\Tests\ORM\Mapping; -use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Event\LoadClassMetadataEventArgs; use Doctrine\ORM\Events; +use Doctrine\Tests\OrmTestCase; -class ClassMetadataLoadEventTest extends \Doctrine\Tests\OrmTestCase +class ClassMetadataLoadEventTest extends OrmTestCase { /** * @group DDC-1610 @@ -22,7 +23,7 @@ class ClassMetadataLoadEventTest extends \Doctrine\Tests\OrmTestCase $this->assertInstanceOf('ReflectionProperty', $classMetadata->reflFields['about']); } - public function loadClassMetadata(\Doctrine\ORM\Event\LoadClassMetadataEventArgs $eventArgs) + public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs) { $classMetadata = $eventArgs->getClassMetadata(); $field = array( diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php index 2a7b65002..44243e113 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php @@ -7,10 +7,14 @@ use Doctrine\Common\Persistence\Mapping\StaticReflectionService; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Events; use Doctrine\ORM\Mapping\DefaultNamingStrategy; +use Doctrine\ORM\Mapping\MappingException; +use Doctrine\ORM\Mapping\UnderscoreNamingStrategy; +use Doctrine\Tests\OrmTestCase; +use Doctrine\Tests\Proxies\__CG__\Doctrine\Tests\Models\CMS\CmsUser; require_once __DIR__ . '/../../Models/Global/GlobalNamespaceModel.php'; -class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase +class ClassMetadataTest extends OrmTestCase { public function testClassMetadataInstanceSerialization() { @@ -179,7 +183,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); + $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); $cm->setVersionMapping($field); } @@ -189,7 +193,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase $cm->initializeReflection(new RuntimeReflectionService()); $cm->isIdentifierComposite = true; - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); + $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); $cm->getSingleIdentifierFieldName(); } @@ -202,7 +206,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase $a2 = array('fieldName' => 'foo', 'sourceEntity' => 'stdClass', 'targetEntity' => 'stdClass', 'mappedBy' => 'foo'); $cm->addInheritedAssociationMapping($a1); - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); + $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); $cm->addInheritedAssociationMapping($a2); } @@ -213,7 +217,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase $cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); + $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); $cm->mapField(array('fieldName' => 'username', 'columnName' => 'name')); } @@ -224,7 +228,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase $cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); + $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); $cm->setDiscriminatorColumn(array('name' => 'name')); } @@ -235,7 +239,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase $cm->setDiscriminatorColumn(array('name' => 'name')); - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); + $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); $cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); } @@ -246,7 +250,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase $cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); + $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); $cm->mapOneToOne(array('fieldName' => 'name', 'targetEntity' => 'CmsUser')); } @@ -257,7 +261,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase $cm->mapOneToOne(array('fieldName' => 'name', 'targetEntity' => 'CmsUser')); - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); + $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); $cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); } @@ -329,7 +333,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase */ public function testUnderscoreNamingStrategyDefaults() { - $namingStrategy = new \Doctrine\ORM\Mapping\UnderscoreNamingStrategy(CASE_UPPER); + $namingStrategy = new UnderscoreNamingStrategy(CASE_UPPER); $oneToOneMetadata = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', $namingStrategy); $manyToManyMetadata = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', $namingStrategy); @@ -392,7 +396,9 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', "No mapping found for field 'foo' on class 'Doctrine\Tests\Models\CMS\CmsUser'."); + $this->expectException(MappingException::class); + $this->expectExceptionMessage("No mapping found for field 'foo' on class 'Doctrine\Tests\Models\CMS\CmsUser'."); + $cm->getFieldMapping('foo'); } @@ -436,7 +442,9 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase $cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); $cm->initializeReflection(new RuntimeReflectionService()); - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', 'The orphan removal option is not allowed on an association that'); + $this->expectException(MappingException::class); + $this->expectExceptionMessage('The orphan removal option is not allowed on an association that'); + $cm->mapOneToOne(array( 'fieldName' => 'article', 'id' => true, @@ -454,8 +462,9 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase $cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); $cm->initializeReflection(new RuntimeReflectionService()); + $this->expectException(MappingException::class); + $this->expectExceptionMessage('An inverse association is not allowed to be identifier in'); - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', 'An inverse association is not allowed to be identifier in'); $cm->mapOneToOne(array( 'fieldName' => 'article', 'id' => true, @@ -473,8 +482,9 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase $cm = new ClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails'); $cm->initializeReflection(new RuntimeReflectionService()); + $this->expectException(MappingException::class); + $this->expectExceptionMessage('Many-to-many or one-to-many associations are not allowed to be identifier in'); - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', 'Many-to-many or one-to-many associations are not allowed to be identifier in'); $cm->mapManyToMany(array( 'fieldName' => 'article', 'id' => true, @@ -488,8 +498,9 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase */ public function testEmptyFieldNameThrowsException() { - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', - "The field or association mapping misses the 'fieldName' attribute in entity 'Doctrine\Tests\Models\CMS\CmsUser'."); + $this->expectException(MappingException::class); + $this->expectExceptionMessage("The field or association mapping misses the 'fieldName' attribute in entity 'Doctrine\Tests\Models\CMS\CmsUser'."); + $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); @@ -724,8 +735,8 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase $metadata = new ClassMetadata('Doctrine\Tests\Models\Company\CompanyContract'); $metadata->initializeReflection(new RuntimeReflectionService()); - $metadata->addEntityListener(\Doctrine\ORM\Events::prePersist, 'CompanyContractListener', 'prePersistHandler'); - $metadata->addEntityListener(\Doctrine\ORM\Events::postPersist, 'CompanyContractListener', 'postPersistHandler'); + $metadata->addEntityListener(Events::prePersist, 'CompanyContractListener', 'prePersistHandler'); + $metadata->addEntityListener(Events::postPersist, 'CompanyContractListener', 'postPersistHandler'); $serialize = serialize($metadata); $unserialize = unserialize($serialize); @@ -814,7 +825,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase */ public function testClassCaseSensitivity() { - $user = new \Doctrine\Tests\Models\CMS\CmsUser(); + $user = new CmsUser(); $cm = new ClassMetadata('DOCTRINE\TESTS\MODELS\CMS\CMSUSER'); $cm->initializeReflection(new RuntimeReflectionService()); @@ -830,7 +841,9 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase $cm->initializeReflection(new RuntimeReflectionService()); $cm->addLifecycleCallback('notfound', 'postLoad'); - $this->setExpectedException("Doctrine\ORM\Mapping\MappingException", "Entity 'Doctrine\Tests\Models\CMS\CmsUser' has no method 'notfound' to be registered as lifecycle callback."); + $this->expectException(MappingException::class); + $this->expectExceptionMessage("Entity 'Doctrine\Tests\Models\CMS\CmsUser' has no method 'notfound' to be registered as lifecycle callback."); + $cm->validateLifecycleCallbacks(new RuntimeReflectionService()); } @@ -843,7 +856,9 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase $cm->initializeReflection(new RuntimeReflectionService()); $cm->mapManyToOne(array('fieldName' => 'address', 'targetEntity' => 'UnknownClass')); - $this->setExpectedException("Doctrine\ORM\Mapping\MappingException", "The target-entity Doctrine\Tests\Models\CMS\UnknownClass cannot be found in 'Doctrine\Tests\Models\CMS\CmsUser#address'."); + $this->expectException(MappingException::class); + $this->expectExceptionMessage("The target-entity Doctrine\Tests\Models\CMS\UnknownClass cannot be found in 'Doctrine\Tests\Models\CMS\CmsUser#address'."); + $cm->validateAssociations(); } @@ -969,8 +984,8 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $this->setExpectedException("Doctrine\ORM\Mapping\MappingException", "You have specified invalid cascade options for Doctrine\Tests\Models\CMS\CmsUser::\$address: 'invalid'; available options: 'remove', 'persist', 'refresh', 'merge', and 'detach'"); - + $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'))); } @@ -1077,7 +1092,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->initializeReflection(new RuntimeReflectionService()); - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); + $this->expectException(\Doctrine\ORM\Mapping\MappingException::class); $cm->setSequenceGeneratorDefinition(array()); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/EntityListenerResolverTest.php b/tests/Doctrine/Tests/ORM/Mapping/EntityListenerResolverTest.php index 64007b031..bef03b9ba 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/EntityListenerResolverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/EntityListenerResolverTest.php @@ -3,11 +3,12 @@ namespace Doctrine\Tests\ORM\Mapping; use Doctrine\ORM\Mapping\DefaultEntityListenerResolver; +use Doctrine\Tests\OrmTestCase; /** * @group DDC-1955 */ -class EntityListenerResolverTest extends \Doctrine\Tests\OrmTestCase +class EntityListenerResolverTest extends OrmTestCase { /** diff --git a/tests/Doctrine/Tests/ORM/Mapping/FieldBuilderTest.php b/tests/Doctrine/Tests/ORM/Mapping/FieldBuilderTest.php index f882dacc4..67a0ebce0 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/FieldBuilderTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/FieldBuilderTest.php @@ -1,28 +1,12 @@ . - */ namespace Doctrine\Tests\ORM\Mapping; use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder; use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\Tests\OrmTestCase; -class FieldBuilderTest extends \Doctrine\Tests\OrmTestCase +class FieldBuilderTest extends OrmTestCase { public function testCustomIdGeneratorCanBeSet() { diff --git a/tests/Doctrine/Tests/ORM/Mapping/NamingStrategy/JoinColumnClassNamingStrategy.php b/tests/Doctrine/Tests/ORM/Mapping/NamingStrategy/JoinColumnClassNamingStrategy.php index 8de8fa940..c4f967589 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/NamingStrategyTest.php b/tests/Doctrine/Tests/ORM/Mapping/NamingStrategyTest.php index 16f0fe576..6274a1468 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/NamingStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/NamingStrategyTest.php @@ -6,11 +6,12 @@ use Doctrine\ORM\Mapping\UnderscoreNamingStrategy; use Doctrine\ORM\Mapping\DefaultNamingStrategy; use Doctrine\ORM\Mapping\NamingStrategy; use Doctrine\Tests\ORM\Mapping\NamingStrategy\JoinColumnClassNamingStrategy; +use Doctrine\Tests\OrmTestCase; /** * @group DDC-559 */ -class NamingStrategyTest extends \Doctrine\Tests\OrmTestCase +class NamingStrategyTest extends OrmTestCase { /** * @return DefaultNamingStrategy diff --git a/tests/Doctrine/Tests/ORM/Mapping/PHPMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/PHPMappingDriverTest.php index 142455542..cfc7f0cc8 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/PHPMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/PHPMappingDriverTest.php @@ -3,8 +3,7 @@ namespace Doctrine\Tests\ORM\Mapping; use Doctrine\ORM\Mapping\ClassMetadata, - Doctrine\Common\Persistence\Mapping\Driver\PHPDriver, - Doctrine\ORM\Tools\Export\ClassMetadataExporter; + Doctrine\Common\Persistence\Mapping\Driver\PHPDriver; class PHPMappingDriverTest extends AbstractMappingDriverTest { diff --git a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php index 0cb60fde4..0b736dd0b 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php @@ -2,14 +2,15 @@ namespace Doctrine\Tests\ORM\Mapping; +use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; use Doctrine\ORM\Mapping\DefaultQuoteStrategy; -use Doctrine\ORM\Mapping\QuoteStrategy; use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\Tests\OrmTestCase; /** * @group DDC-1845 */ -class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase +class QuoteStrategyTest extends OrmTestCase { /** @@ -37,7 +38,7 @@ class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase private function createClassMetadata($className) { $cm = new ClassMetadata($className); - $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); + $cm->initializeReflection(new RuntimeReflectionService()); return $cm; } @@ -73,7 +74,7 @@ class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals('"cms_user"' ,$this->strategy->getTableName($cm, $this->platform)); $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); - $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); + $cm->initializeReflection(new RuntimeReflectionService()); $cm->setPrimaryTable(array('name'=>'cms_user')); $this->assertEquals('cms_user' ,$this->strategy->getTableName($cm, $this->platform)); } @@ -189,7 +190,7 @@ class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase } } -class MyQuoteStrategy extends \Doctrine\ORM\Mapping\DefaultQuoteStrategy +class MyQuoteStrategy extends DefaultQuoteStrategy { } diff --git a/tests/Doctrine/Tests/ORM/Mapping/Reflection/ReflectionPropertiesGetterTest.php b/tests/Doctrine/Tests/ORM/Mapping/Reflection/ReflectionPropertiesGetterTest.php index 7bc83df2e..1b18deb11 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/Reflection/ReflectionPropertiesGetterTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/Reflection/ReflectionPropertiesGetterTest.php @@ -90,7 +90,7 @@ class ReflectionPropertiesGetterTest extends PHPUnit_Framework_TestCase public function testPropertyGetterWillSkipPropertiesNotRetrievedByTheRuntimeReflectionService() { /* @var $reflectionService ReflectionService|\PHPUnit_Framework_MockObject_MockObject */ - $reflectionService = $this->getMock('Doctrine\Common\Persistence\Mapping\ReflectionService'); + $reflectionService = $this->createMock(ReflectionService::class); $reflectionService ->expects($this->exactly(2)) @@ -113,7 +113,7 @@ class ReflectionPropertiesGetterTest extends PHPUnit_Framework_TestCase public function testPropertyGetterWillSkipClassesNotRetrievedByTheRuntimeReflectionService() { /* @var $reflectionService ReflectionService|\PHPUnit_Framework_MockObject_MockObject */ - $reflectionService = $this->getMock('Doctrine\Common\Persistence\Mapping\ReflectionService'); + $reflectionService = $this->createMock(ReflectionService::class); $reflectionService ->expects($this->once()) diff --git a/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php index 99e436ae8..ac8f1d695 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php @@ -1,23 +1,7 @@ . -*/ namespace Doctrine\Tests\ORM\Mapping\Symfony; +use Doctrine\Common\Persistence\Mapping\MappingException; /** * @group DDC-1418 @@ -47,10 +31,8 @@ abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase public function testFindMappingFileNamespacedFoundFileNotFound() { - $this->setExpectedException( - 'Doctrine\Common\Persistence\Mapping\MappingException', - "No mapping file found named" - ); + $this->expectException(MappingException::class); + $this->expectExceptionMessage('No mapping file found named'); $driver = $this->getDriver(array( 'MyNamespace\MySubnamespace\Entity' => $this->dir, @@ -61,10 +43,8 @@ abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase public function testFindMappingNamespaceNotFound() { - $this->setExpectedException( - 'Doctrine\Common\Persistence\Mapping\MappingException', - "No mapping file found named 'Foo".$this->getFileExtension()."' for class 'MyOtherNamespace\MySubnamespace\Entity\Foo'." - ); + $this->expectException(MappingException::class); + $this->expectExceptionMessage("No mapping file found named 'Foo" . $this->getFileExtension() . "' for class 'MyOtherNamespace\MySubnamespace\Entity\Foo'."); $driver = $this->getDriver(array( 'MyNamespace\MySubnamespace\Entity' => $this->dir, @@ -96,18 +76,4 @@ abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase abstract protected function getFileExtension(); abstract protected function getDriver(array $paths = array()); - - private function setField($obj, $field, $value) - { - $ref = new \ReflectionProperty($obj, $field); - $ref->setAccessible(true); - $ref->setValue($obj, $value); - } - - private function invoke($obj, $method, array $args = array()) { - $ref = new \ReflectionMethod($obj, $method); - $ref->setAccessible(true); - - return $ref->invokeArgs($obj, $args); - } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/Symfony/XmlDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/Symfony/XmlDriverTest.php index 5908b674a..f32d9f2ad 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 c5d8d1cd1..5b7f38ead 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/Mapping/XmlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php index c2822f178..735c16ed5 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\Persistence\Mapping\RuntimeReflectionService; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\Driver\XmlDriver; @@ -19,7 +20,7 @@ class XmlMappingDriverTest extends AbstractMappingDriverTest $mappingDriver = $this->_loadDriver(); $class = new ClassMetadata($className); - $class->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); + $class->initializeReflection(new RuntimeReflectionService()); $mappingDriver->loadMetadataForClass($className, $class); $expectedMap = array( diff --git a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php index 95d6c7f9a..c752c6a82 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php @@ -3,8 +3,8 @@ namespace Doctrine\Tests\ORM\Mapping; use Doctrine\ORM\Mapping\ClassMetadata, - Doctrine\ORM\Mapping\Driver\XmlDriver, Doctrine\ORM\Mapping\Driver\YamlDriver; +use Doctrine\ORM\Mapping\ClassMetadataFactory; class YamlMappingDriverTest extends AbstractMappingDriverTest { @@ -29,7 +29,7 @@ class YamlMappingDriverTest extends AbstractMappingDriverTest $em = $this->_getTestEntityManager(); $em->getConfiguration()->setMetadataDriverImpl($yamlDriver); - $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory(); + $factory = new ClassMetadataFactory(); $factory->setEntityManager($em); $classPage = new ClassMetadata('Doctrine\Tests\Models\DirectoryTree\File'); diff --git a/tests/Doctrine/Tests/ORM/Performance/DDC2602Test.php b/tests/Doctrine/Tests/ORM/Performance/DDC2602Test.php index 5b307eba1..210f72c80 100644 --- a/tests/Doctrine/Tests/ORM/Performance/DDC2602Test.php +++ b/tests/Doctrine/Tests/ORM/Performance/DDC2602Test.php @@ -5,12 +5,13 @@ namespace Doctrine\Tests\ORM\Performance; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Event\LifecycleEventArgs; use Doctrine\ORM\Events; +use Doctrine\Tests\OrmPerformanceTestCase; /** * @group performance * @group DDC-2602 */ -class DDC2602Test extends \Doctrine\Tests\OrmPerformanceTestCase +class DDC2602Test extends OrmPerformanceTestCase { protected function setUp() { diff --git a/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php index ab6e3259c..e4d65e1e7 100644 --- a/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php @@ -2,9 +2,13 @@ namespace Doctrine\Tests\ORM\Performance; +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\Tests\OrmPerformanceTestCase; /** * Tests to prevent serious performance regressions. @@ -15,7 +19,7 @@ use Doctrine\Tests\Mocks\HydratorMockStatement, * @author robo * @group performance */ -class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase +class HydrationPerformanceTest extends OrmPerformanceTestCase { /** * Times for comparison: @@ -66,7 +70,7 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase } $stmt = new HydratorMockStatement($resultSet); - $hydrator = new \Doctrine\ORM\Internal\Hydration\ScalarHydrator($this->_em); + $hydrator = new ScalarHydrator($this->_em); $this->setMaxRunningTime(1); $s = microtime(true); @@ -124,7 +128,7 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase } $stmt = new HydratorMockStatement($resultSet); - $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); + $hydrator = new ArrayHydrator($this->_em); $this->setMaxRunningTime(2); $s = microtime(true); @@ -198,7 +202,7 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase } $stmt = new HydratorMockStatement($resultSet); - $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); + $hydrator = new ArrayHydrator($this->_em); $this->setMaxRunningTime(3); $s = microtime(true); @@ -254,7 +258,7 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase } $stmt = new HydratorMockStatement($resultSet); - $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); + $hydrator = new ObjectHydrator($this->_em); $this->setMaxRunningTime(3); $s = microtime(true); @@ -310,7 +314,7 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase } $stmt = new HydratorMockStatement($resultSet); - $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); + $hydrator = new ObjectHydrator($this->_em); $this->setMaxRunningTime(5); $s = microtime(true); @@ -382,7 +386,7 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase } $stmt = new HydratorMockStatement($resultSet); - $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); + $hydrator = new ObjectHydrator($this->_em); $this->setMaxRunningTime(1); $s = microtime(true); @@ -447,7 +451,7 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase } $stmt = new HydratorMockStatement($resultSet); - $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); + $hydrator = new ObjectHydrator($this->_em); $this->setMaxRunningTime(1); $s = microtime(true); diff --git a/tests/Doctrine/Tests/ORM/Performance/InheritancePersisterPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/InheritancePersisterPerformanceTest.php index b18fe2850..2104587ae 100644 --- a/tests/Doctrine/Tests/ORM/Performance/InheritancePersisterPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/InheritancePersisterPerformanceTest.php @@ -2,13 +2,17 @@ namespace Doctrine\Tests\ORM\Performance; -use Doctrine\ORM\Tools\SchemaTool; use Doctrine\ORM\Query; +use Doctrine\Tests\Models\Company\CompanyEmployee; +use Doctrine\Tests\Models\Company\CompanyFixContract; +use Doctrine\Tests\Models\Company\CompanyFlexContract; +use Doctrine\Tests\Models\Company\CompanyFlexUltraContract; +use Doctrine\Tests\OrmFunctionalTestCase; /** * @group performance */ -class InheritancePersisterPerformanceTest extends \Doctrine\Tests\OrmFunctionalTestCase +class InheritancePersisterPerformanceTest extends OrmFunctionalTestCase { protected function setUp() { @@ -18,27 +22,27 @@ class InheritancePersisterPerformanceTest extends \Doctrine\Tests\OrmFunctionalT public function testCompanyContract() { - $person = new \Doctrine\Tests\Models\Company\CompanyEmployee(); + $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 \Doctrine\Tests\Models\Company\CompanyFixContract(); + $fix = new CompanyFixContract(); $fix->setFixPrice(1000); $fix->setSalesPerson($person); $fix->markCompleted(); $this->_em->persist($fix); - $flex = new \Doctrine\Tests\Models\Company\CompanyFlexContract(); + $flex = new CompanyFlexContract(); $flex->setSalesPerson($person); $flex->setHoursWorked(100); $flex->setPricePerHour(100); $flex->markCompleted(); $this->_em->persist($flex); - $ultra = new \Doctrine\Tests\Models\Company\CompanyFlexUltraContract(); + $ultra = new CompanyFlexUltraContract(); $ultra->setSalesPerson($person); $ultra->setHoursWorked(150); $ultra->setPricePerHour(150); diff --git a/tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php index f387d1d23..db5455b06 100644 --- a/tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM\Performance; use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\OrmPerformanceTestCase; /** * Description of InsertPerformanceTest @@ -10,9 +11,10 @@ use Doctrine\Tests\Models\CMS\CmsUser; * @author robo * @group performance */ -class InsertPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase +class InsertPerformanceTest extends OrmPerformanceTestCase { - protected function setUp() { + protected function setUp() + { $this->useModelSet('cms'); parent::setUp(); } diff --git a/tests/Doctrine/Tests/ORM/Performance/PersisterPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/PersisterPerformanceTest.php index 21be1abad..db5d0f8ef 100644 --- a/tests/Doctrine/Tests/ORM/Performance/PersisterPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/PersisterPerformanceTest.php @@ -2,19 +2,16 @@ namespace Doctrine\Tests\ORM\Performance; -use Doctrine\ORM\Tools\SchemaTool; use Doctrine\ORM\Query; use Doctrine\Tests\Models\CMS\CmsUser; -use Doctrine\Tests\Models\CMS\CmsPhonenumber; -use Doctrine\Tests\Models\CMS\CmsAddress; use Doctrine\Tests\Models\CMS\CmsGroup; use Doctrine\Tests\Models\CMS\CmsArticle; -use Doctrine\Tests\Models\CMS\CmsComment; +use Doctrine\Tests\OrmFunctionalTestCase; /** * @group performance */ -class PersisterPerformanceTest extends \Doctrine\Tests\OrmFunctionalTestCase +class PersisterPerformanceTest extends OrmFunctionalTestCase { protected function setUp() { diff --git a/tests/Doctrine/Tests/ORM/Performance/ProxyPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/ProxyPerformanceTest.php index a43907f9e..bc98c23f6 100644 --- a/tests/Doctrine/Tests/ORM/Performance/ProxyPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/ProxyPerformanceTest.php @@ -1,26 +1,8 @@ . - */ namespace Doctrine\Tests\ORM\Performance; use Doctrine\Tests\OrmPerformanceTestCase; -use Doctrine\Common\Proxy\Proxy; use Doctrine\ORM\EntityManager; use Doctrine\ORM\UnitOfWork; use Doctrine\ORM\Proxy\ProxyFactory; diff --git a/tests/Doctrine/Tests/ORM/Performance/SecondLevelCacheTest.php b/tests/Doctrine/Tests/ORM/Performance/SecondLevelCacheTest.php index 61b9c7ce7..774945c5a 100644 --- a/tests/Doctrine/Tests/ORM/Performance/SecondLevelCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/SecondLevelCacheTest.php @@ -101,7 +101,7 @@ class SecondLevelCacheTest extends OrmFunctionalTestCase $this->findEntityOneToMany($em, __FUNCTION__); - $this->assertEquals(487, $this->countQuery($em)); + $this->assertEquals(472, $this->countQuery($em)); } public function testQueryEntityWithoutCache() diff --git a/tests/Doctrine/Tests/ORM/Performance/UnitOfWorkPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/UnitOfWorkPerformanceTest.php index f2aeda714..934933635 100644 --- a/tests/Doctrine/Tests/ORM/Performance/UnitOfWorkPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/UnitOfWorkPerformanceTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM\Performance; use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\OrmPerformanceTestCase; /** * Description of InsertPerformanceTest @@ -10,7 +11,7 @@ use Doctrine\Tests\Models\CMS\CmsUser; * @author robo * @group performance */ -class UnitOfWorkPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase +class UnitOfWorkPerformanceTest extends OrmPerformanceTestCase { protected function setUp() { diff --git a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php index 5b1ffce62..4956e5648 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\Tests\Mocks\ConnectionMock; use Doctrine\Tests\Mocks\DriverMock; diff --git a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeParametersTest.php b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeParametersTest.php index 76daadc3f..74d72856e 100644 --- a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeParametersTest.php +++ b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeParametersTest.php @@ -6,8 +6,9 @@ use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\Persisters\Entity\BasicEntityPersister; use Doctrine\Tests\Models\GeoNames\Admin1; use Doctrine\Tests\Models\GeoNames\Country; +use Doctrine\Tests\OrmTestCase; -class BasicEntityPersisterCompositeTypeParametersTest extends \Doctrine\Tests\OrmTestCase +class BasicEntityPersisterCompositeTypeParametersTest extends OrmTestCase { /** * @var BasicEntityPersister diff --git a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeSqlTest.php b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeSqlTest.php index 54b1a2351..e788826d4 100644 --- a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeSqlTest.php +++ b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterCompositeTypeSqlTest.php @@ -2,15 +2,11 @@ namespace Doctrine\Tests\ORM\Persisters; -use Doctrine\Common\Collections\Criteria; -use Doctrine\DBAL\Types\Type as DBALType; -use Doctrine\ORM\EntityManager; use Doctrine\ORM\Persisters\Entity\BasicEntityPersister; -use Doctrine\Tests\Models\CustomType\CustomTypeParent; -use Doctrine\Tests\Models\CustomType\CustomTypeChild; use Doctrine\Common\Collections\Expr\Comparison; +use Doctrine\Tests\OrmTestCase; -class BasicEntityPersisterCompositeTypeSqlTest extends \Doctrine\Tests\OrmTestCase +class BasicEntityPersisterCompositeTypeSqlTest extends OrmTestCase { /** * @var BasicEntityPersister diff --git a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php index d51e40555..b617d14da 100644 --- a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php +++ b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php @@ -9,8 +9,9 @@ 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\OrmTestCase; -class BasicEntityPersisterTypeValueSqlTest extends \Doctrine\Tests\OrmTestCase +class BasicEntityPersisterTypeValueSqlTest extends OrmTestCase { /** * @var BasicEntityPersister diff --git a/tests/Doctrine/Tests/ORM/Persisters/JoinedSubclassPersisterTest.php b/tests/Doctrine/Tests/ORM/Persisters/JoinedSubclassPersisterTest.php index 18145070f..5d4e992f7 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/Proxy/ProxyFactoryTest.php b/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php index a8a2adaba..174daf3c0 100644 --- a/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php @@ -2,21 +2,25 @@ 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\Common\Proxy\ProxyGenerator; 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\Models\Company\CompanyPerson; +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. * @author Giorgio Sironi */ -class ProxyFactoryTest extends \Doctrine\Tests\OrmTestCase +class ProxyFactoryTest extends OrmTestCase { /** * @var ConnectionMock @@ -55,16 +59,17 @@ class ProxyFactoryTest extends \Doctrine\Tests\OrmTestCase { $identifier = array('id' => 42); $proxyClass = 'Proxies\__CG__\Doctrine\Tests\Models\ECommerce\ECommerceFeature'; - $persister = $this->getMock('Doctrine\ORM\Persisters\Entity\BasicEntityPersister', array('load'), array(), '', false); + $persister = $this->getMockBuilder(BasicEntityPersister::class)->setMethods(array('load'))->disableOriginalConstructor()->getMock(); + $this->uowMock->setEntityPersister('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $persister); $proxy = $this->proxyFactory->getProxy('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $identifier); $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(); } @@ -75,7 +80,7 @@ class ProxyFactoryTest extends \Doctrine\Tests\OrmTestCase public function testSkipAbstractClassesOnGeneration() { $cm = new ClassMetadata(__NAMESPACE__ . '\\AbstractClass'); - $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); + $cm->initializeReflection(new RuntimeReflectionService()); $this->assertNotNull($cm->reflClass); $num = $this->proxyFactory->generateProxyClasses(array($cm)); @@ -88,7 +93,7 @@ class ProxyFactoryTest extends \Doctrine\Tests\OrmTestCase */ public function testFailedProxyLoadingDoesNotMarkTheProxyAsInitialized() { - $persister = $this->getMock('Doctrine\ORM\Persisters\Entity\BasicEntityPersister', array('load'), array(), '', false); + $persister = $this->getMockBuilder(BasicEntityPersister::class)->setMethods(array('load'))->disableOriginalConstructor()->getMock(); $this->uowMock->setEntityPersister('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $persister); /* @var $proxy \Doctrine\Common\Proxy\Proxy */ @@ -115,7 +120,7 @@ class ProxyFactoryTest extends \Doctrine\Tests\OrmTestCase */ public function testFailedProxyCloningDoesNotMarkTheProxyAsInitialized() { - $persister = $this->getMock('Doctrine\ORM\Persisters\Entity\BasicEntityPersister', array('load'), array(), '', false); + $persister = $this->getMockBuilder(BasicEntityPersister::class)->setMethods(array('load'))->disableOriginalConstructor()->getMock(); $this->uowMock->setEntityPersister('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $persister); /* @var $proxy \Doctrine\Common\Proxy\Proxy */ @@ -136,6 +141,48 @@ class ProxyFactoryTest extends \Doctrine\Tests\OrmTestCase $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) + $property = new \ReflectionProperty(CompanyPerson::class, 'id'); + + $property->setAccessible(true); + $property->setValue($companyEmployee, 42); + + $classMetaData = $this->emMock->getClassMetadata(CompanyEmployee::class); + + $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(CompanyEmployee::class, ['id' => 42]); + + $persister + ->expects(self::atLeastOnce()) + ->method('load') + ->willReturn($companyEmployee); + + $persister + ->expects(self::atLeastOnce()) + ->method('getClassMetadata') + ->willReturn($classMetaData); + + /* @var $cloned CompanyEmployee */ + $cloned = clone $proxy; + + 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'); + } } abstract class AbstractClass diff --git a/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersJoinTest.php b/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersJoinTest.php index 60545d4f9..e47c48215 100644 --- a/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersJoinTest.php +++ b/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersJoinTest.php @@ -1,25 +1,9 @@ . - */ namespace Doctrine\Tests\ORM\Query; use Doctrine\ORM\Query; +use Doctrine\Tests\OrmTestCase; /** * Test case for custom AST walking and adding new joins. @@ -28,7 +12,7 @@ use Doctrine\ORM\Query; * @license MIT * @link http://www.doctrine-project.org */ -class CustomTreeWalkersJoinTest extends \Doctrine\Tests\OrmTestCase +class CustomTreeWalkersJoinTest extends OrmTestCase { private $em; diff --git a/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersTest.php b/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersTest.php index 574b37ae7..4114c4f8b 100644 --- a/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersTest.php +++ b/tests/Doctrine/Tests/ORM/Query/CustomTreeWalkersTest.php @@ -1,25 +1,10 @@ . - */ namespace Doctrine\Tests\ORM\Functional; use Doctrine\ORM\Query; +use Doctrine\ORM\Query\QueryException; +use Doctrine\Tests\OrmTestCase; /** * Test case for custom AST walking and modification. @@ -29,7 +14,7 @@ use Doctrine\ORM\Query; * @link http://www.doctrine-project.org * @since 2.0 */ -class CustomTreeWalkersTest extends \Doctrine\Tests\OrmTestCase +class CustomTreeWalkersTest extends OrmTestCase { private $_em; @@ -89,7 +74,9 @@ class CustomTreeWalkersTest extends \Doctrine\Tests\OrmTestCase public function testSetUnknownQueryComponentThrowsException() { - $this->setExpectedException("Doctrine\ORM\Query\QueryException", "Invalid query component given for DQL alias 'x', requires 'metadata', 'parent', 'relation', 'map', 'nestingLevel' and 'token' keys."); + $this->expectException(QueryException::class); + $this->expectExceptionMessage("Invalid query component given for DQL alias 'x', requires 'metadata', 'parent', 'relation', 'map', 'nestingLevel' and 'token' keys."); + $this->generateSql( 'select u from Doctrine\Tests\Models\CMS\CmsUser u', array(), @@ -234,4 +221,4 @@ class CustomTreeWalkerJoin extends Query\TreeWalkerAdapter ) ); } -} \ 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 21679c894..8218339df 100644 --- a/tests/Doctrine/Tests/ORM/Query/DeleteSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/DeleteSqlGenerationTest.php @@ -1,25 +1,7 @@ . - */ namespace Doctrine\Tests\ORM\Query; +use Doctrine\Tests\OrmTestCase; /** * Test case for testing the saving and referencing of query identifiers. @@ -35,7 +17,7 @@ namespace Doctrine\Tests\ORM\Query; * testcases later since we'll have a lot of them and we might want to have special SQL * generation tests for some dbms specific SQL syntaxes. */ -class DeleteSqlGenerationTest extends \Doctrine\Tests\OrmTestCase +class DeleteSqlGenerationTest extends OrmTestCase { private $_em; diff --git a/tests/Doctrine/Tests/ORM/Query/ExprTest.php b/tests/Doctrine/Tests/ORM/Query/ExprTest.php index d64fed335..61def1770 100644 --- a/tests/Doctrine/Tests/ORM/Query/ExprTest.php +++ b/tests/Doctrine/Tests/ORM/Query/ExprTest.php @@ -1,26 +1,10 @@ . - */ namespace Doctrine\Tests\ORM\Query; use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query; +use Doctrine\Tests\OrmTestCase; /** * Test case for the DQL Expr class used for generating DQL snippets through @@ -32,7 +16,7 @@ use Doctrine\ORM\Query; * @since 2.0 * @version $Revision$ */ -class ExprTest extends \Doctrine\Tests\OrmTestCase +class ExprTest extends OrmTestCase { private $_em; @@ -119,20 +103,20 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase public function testAndExpr() { - $this->assertEquals('1 = 1 AND 2 = 2', (string) $this->_expr->andx((string) $this->_expr->eq(1, 1), (string) $this->_expr->eq(2, 2))); + $this->assertEquals('1 = 1 AND 2 = 2', (string) $this->_expr->andX((string) $this->_expr->eq(1, 1), (string) $this->_expr->eq(2, 2))); } public function testIntelligentParenthesisPreventionAndExpr() { $this->assertEquals( '1 = 1 AND 2 = 2', - (string) $this->_expr->andx($this->_expr->orx($this->_expr->andx($this->_expr->eq(1, 1))), (string) $this->_expr->eq(2, 2)) + (string) $this->_expr->andX($this->_expr->orX($this->_expr->andX($this->_expr->eq(1, 1))), (string) $this->_expr->eq(2, 2)) ); } public function testOrExpr() { - $this->assertEquals('1 = 1 OR 2 = 2', (string) $this->_expr->orx((string) $this->_expr->eq(1, 1), (string) $this->_expr->eq(2, 2))); + $this->assertEquals('1 = 1 OR 2 = 2', (string) $this->_expr->orX((string) $this->_expr->eq(1, 1), (string) $this->_expr->eq(2, 2))); } public function testAbsExpr() @@ -310,11 +294,11 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase public function testAndxOrxExpr() { - $andExpr = $this->_expr->andx(); + $andExpr = $this->_expr->andX(); $andExpr->add($this->_expr->eq(1, 1)); $andExpr->add($this->_expr->lt(1, 5)); - $orExpr = $this->_expr->orx(); + $orExpr = $this->_expr->orX(); $orExpr->add($andExpr); $orExpr->add($this->_expr->eq(1, 1)); @@ -323,7 +307,7 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase public function testOrxExpr() { - $orExpr = $this->_expr->orx(); + $orExpr = $this->_expr->orX(); $orExpr->add($this->_expr->eq(1, 1)); $orExpr->add($this->_expr->lt(1, 5)); @@ -355,7 +339,7 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase */ public function testAddThrowsException() { - $orExpr = $this->_expr->orx(); + $orExpr = $this->_expr->orX(); $orExpr->add($this->_expr->quot(5, 2)); } @@ -432,15 +416,17 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals(array('foo', 'bar'), $select->getParts()); } - public function testAddEmpty() { - $andExpr = $this->_expr->andx(); - $andExpr->add($this->_expr->andx()); + public function testAddEmpty() + { + $andExpr = $this->_expr->andX(); + $andExpr->add($this->_expr->andX()); $this->assertEquals(0, $andExpr->count()); } - public function testAddNull() { - $andExpr = $this->_expr->andx(); + public function testAddNull() + { + $andExpr = $this->_expr->andX(); $andExpr->add(null); $this->assertEquals(0, $andExpr->count()); diff --git a/tests/Doctrine/Tests/ORM/Query/FilterCollectionTest.php b/tests/Doctrine/Tests/ORM/Query/FilterCollectionTest.php index 455949de0..7a50516a7 100644 --- a/tests/Doctrine/Tests/ORM/Query/FilterCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Query/FilterCollectionTest.php @@ -2,15 +2,16 @@ namespace Doctrine\Tests\ORM\Query; -use Doctrine\ORM\Mapping\ClassMetaData, +use Doctrine\ORM\Mapping\ClassMetadata, Doctrine\ORM\Query\Filter\SQLFilter; +use Doctrine\Tests\OrmTestCase; /** * Test case for FilterCollection * * @author Guilherme Blanco */ -class FilterCollectionTest extends \Doctrine\Tests\OrmTestCase +class FilterCollectionTest extends OrmTestCase { /** * @var \Doctrine\ORM\EntityManager diff --git a/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php b/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php index b90047e19..fe12b3989 100644 --- a/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php +++ b/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php @@ -1,11 +1,13 @@ _em->createQuery($dql); $query->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true); - $query->setDql($dql); + $query->setDQL($dql); foreach ($hints as $key => $value) { $query->setHint($key, $value); } - $parser = new \Doctrine\ORM\Query\Parser($query); + $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'); @@ -82,7 +84,7 @@ class LanguageRecognitionTest extends \Doctrine\Tests\OrmTestCase */ public function testRejectsInvalidDQL($dql) { - $this->setExpectedException('\Doctrine\ORM\Query\QueryException'); + $this->expectException(QueryException::class); $this->_em->getConfiguration()->setEntityNamespaces(array( 'Unknown' => 'Unknown', diff --git a/tests/Doctrine/Tests/ORM/Query/LexerTest.php b/tests/Doctrine/Tests/ORM/Query/LexerTest.php index 5c9828731..9c4a889f0 100644 --- a/tests/Doctrine/Tests/ORM/Query/LexerTest.php +++ b/tests/Doctrine/Tests/ORM/Query/LexerTest.php @@ -3,8 +3,9 @@ namespace Doctrine\Tests\ORM\Query; use Doctrine\ORM\Query\Lexer; +use Doctrine\Tests\OrmTestCase; -class LexerTest extends \Doctrine\Tests\OrmTestCase +class LexerTest extends OrmTestCase { //private $_lexer; diff --git a/tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php b/tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php index 4e00bbc88..640a91314 100644 --- a/tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php +++ b/tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php @@ -1,29 +1,14 @@ . - */ + namespace Doctrine\Tests\ORM\Query; use Doctrine\ORM\Query\ParameterTypeInferer; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Types\Type; +use Doctrine\Tests\OrmTestCase; use PDO; -class ParameterTypeInfererTest extends \Doctrine\Tests\OrmTestCase +class ParameterTypeInfererTest extends OrmTestCase { public function providerParameterTypeInferer() diff --git a/tests/Doctrine/Tests/ORM/Query/ParserResultTest.php b/tests/Doctrine/Tests/ORM/Query/ParserResultTest.php index 64f3afb0f..086e1d43e 100644 --- a/tests/Doctrine/Tests/ORM/Query/ParserResultTest.php +++ b/tests/Doctrine/Tests/ORM/Query/ParserResultTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Query; +use Doctrine\ORM\Query\Exec\AbstractSqlExecutor; use Doctrine\ORM\Query\ParserResult; class ParserResultTest extends \PHPUnit_Framework_TestCase @@ -25,7 +26,7 @@ class ParserResultTest extends \PHPUnit_Framework_TestCase { $this->assertNull($this->parserResult->getSqlExecutor()); - $executor = $this->getMock('Doctrine\ORM\Query\Exec\AbstractSqlExecutor', array('execute')); + $executor = $this->getMockBuilder(AbstractSqlExecutor::class)->setMethods(array('execute'))->getMock(); $this->parserResult->setSqlExecutor($executor); $this->assertSame($executor, $this->parserResult->getSqlExecutor()); } diff --git a/tests/Doctrine/Tests/ORM/Query/ParserTest.php b/tests/Doctrine/Tests/ORM/Query/ParserTest.php index 1bc7f5dfb..fb320773e 100644 --- a/tests/Doctrine/Tests/ORM/Query/ParserTest.php +++ b/tests/Doctrine/Tests/ORM/Query/ParserTest.php @@ -5,8 +5,10 @@ namespace Doctrine\Tests\ORM\Query; use Doctrine\ORM\Query; use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; +use Doctrine\ORM\Query\QueryException; +use Doctrine\Tests\OrmTestCase; -class ParserTest extends \Doctrine\Tests\OrmTestCase +class ParserTest extends OrmTestCase { /** @@ -89,7 +91,7 @@ class ParserTest extends \Doctrine\Tests\OrmTestCase */ public function testMatchFailure($expectedToken, $inputString) { - $this->setExpectedException('\Doctrine\ORM\Query\QueryException'); + $this->expectException(QueryException::class); $parser = $this->createParser($inputString); diff --git a/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php b/tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php index 2b9fc2304..b8d688261 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/QueryTest.php b/tests/Doctrine/Tests/ORM/Query/QueryTest.php index 2618af1db..7a3687c52 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryTest.php @@ -9,8 +9,9 @@ use Doctrine\ORM\EntityManager; use Doctrine\ORM\Query\Parameter; use Doctrine\Tests\Mocks\DriverConnectionMock; use Doctrine\Tests\Mocks\StatementArrayMock; +use Doctrine\Tests\OrmTestCase; -class QueryTest extends \Doctrine\Tests\OrmTestCase +class QueryTest extends OrmTestCase { /** @var EntityManager */ protected $_em = null; @@ -73,7 +74,7 @@ class QueryTest extends \Doctrine\Tests\OrmTestCase $cloned = clone $query; - $this->assertEquals($dql, $cloned->getDql()); + $this->assertEquals($dql, $cloned->getDQL()); $this->assertEquals(0, count($cloned->getParameters())); $this->assertFalse($cloned->getHint('foo')); } @@ -91,7 +92,7 @@ class QueryTest extends \Doctrine\Tests\OrmTestCase ->setParameters(new ArrayCollection(array(new Parameter(2, 'baz')))) ->setResultCacheDriver(null) ->setResultCacheId('foo') - ->setDql('foo') + ->setDQL('foo') ->setFirstResult(10) ->setMaxResults(10); diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 1aabaa78b..707973495 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -2,10 +2,25 @@ namespace Doctrine\Tests\ORM\Query; +use Doctrine\DBAL\LockMode; +use Doctrine\DBAL\Platforms\MySqlPlatform; +use Doctrine\DBAL\Platforms\OraclePlatform; +use Doctrine\DBAL\Platforms\PostgreSqlPlatform; +use Doctrine\DBAL\Platforms\SqlitePlatform; +use Doctrine\DBAL\Platforms\SQLServerPlatform; use Doctrine\DBAL\Types\Type as DBALType; -use Doctrine\ORM\Query; +use Doctrine\ORM\Query as ORMQuery; +use Doctrine\ORM\Query\AST\Functions\FunctionNode; +use Doctrine\ORM\Query\Lexer; +use Doctrine\ORM\Query\Parser; +use Doctrine\ORM\Query\QueryException; +use Doctrine\ORM\Query\SqlWalker; +use Doctrine\Tests\Models\CMS\CmsGroup; +use Doctrine\Tests\Models\CMS\CmsPhonenumber; +use Doctrine\Tests\Models\Company\CompanyPerson; +use Doctrine\Tests\OrmTestCase; -class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase +class SelectSqlGenerationTest extends OrmTestCase { private $_em; @@ -31,7 +46,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $query->setParameter($name, $value); } - $query->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true) + $query->setHint(ORMQuery::HINT_FORCE_PARTIAL_LOAD, true) ->useQueryCache(false); foreach ($queryHints AS $name => $value) { @@ -62,7 +77,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase */ public function assertInvalidSqlGeneration($dqlToBeTested, $expectedException, array $queryHints = array(), array $queryParams = array()) { - $this->setExpectedException($expectedException); + $this->expectException($expectedException); $query = $this->_em->createQuery($dqlToBeTested); @@ -70,7 +85,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $query->setParameter($name, $value); } - $query->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true) + $query->setHint(ORMQuery::HINT_FORCE_PARTIAL_LOAD, true) ->useQueryCache(false); foreach ($queryHints AS $name => $value) { @@ -92,7 +107,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $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(Query::HINT_FORCE_PARTIAL_LOAD => true) + array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => true) ); } @@ -109,7 +124,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $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(Query::HINT_FORCE_PARTIAL_LOAD => false) + array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => false) ); } @@ -299,7 +314,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $connMock = $this->_em->getConnection(); $orgPlatform = $connMock->getDatabasePlatform(); - $connMock->setDatabasePlatform(new \Doctrine\DBAL\Platforms\MySqlPlatform); + $connMock->setDatabasePlatform(new MySqlPlatform()); $this->assertSqlGeneration( 'SELECT COUNT(CONCAT(u.id, u.name)) FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u.id', @@ -415,7 +430,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase */ public function testJoinOnClause_NotYetSupported_ThrowsException() { - $this->setExpectedException('Doctrine\ORM\Query\QueryException'); + $this->expectException(QueryException::class); $sql = $this->_em->createQuery( "SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a ON a.topic LIKE '%foo%'" @@ -514,7 +529,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase { $this->assertInvalidSqlGeneration( "SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF \Doctrine\Tests\Models\CMS\CmsUser", - "Doctrine\ORM\Query\QueryException" + "Doctrine\\ORM\\Query\\QueryException" ); } @@ -601,7 +616,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $connMock = $this->_em->getConnection(); $orgPlatform = $connMock->getDatabasePlatform(); - $connMock->setDatabasePlatform(new \Doctrine\DBAL\Platforms\MySqlPlatform); + $connMock->setDatabasePlatform(new MySqlPlatform()); $this->assertSqlGeneration( "SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE CONCAT(u.name, 's') = ?1", "SELECT c0_.id AS id_0 FROM cms_users c0_ WHERE CONCAT(c0_.name, 's') = ?" @@ -611,7 +626,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase "SELECT CONCAT(c0_.id, c0_.name) AS sclr_0 FROM cms_users c0_ WHERE c0_.id = ?" ); - $connMock->setDatabasePlatform(new \Doctrine\DBAL\Platforms\PostgreSqlPlatform); + $connMock->setDatabasePlatform(new PostgreSqlPlatform()); $this->assertSqlGeneration( "SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE CONCAT(u.name, 's') = ?1", "SELECT c0_.id AS id_0 FROM cms_users c0_ WHERE c0_.name || 's' = ?" @@ -647,9 +662,9 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase { // "Get all users who have $phone as a phonenumber." (*cough* doesnt really make sense...) $q = $this->_em->createQuery('SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE :param MEMBER OF u.phonenumbers'); - $q->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true); + $q->setHint(ORMQuery::HINT_FORCE_PARTIAL_LOAD, true); - $phone = new \Doctrine\Tests\Models\CMS\CmsPhonenumber; + $phone = new CmsPhonenumber(); $phone->phonenumber = 101; $q->setParameter('param', $phone); @@ -663,9 +678,9 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase { // "Get all users who are members of $group." $q = $this->_em->createQuery('SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE :param MEMBER OF u.groups'); - $q->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true); + $q->setHint(ORMQuery::HINT_FORCE_PARTIAL_LOAD, true); - $group = new \Doctrine\Tests\Models\CMS\CmsGroup; + $group = new CmsGroup(); $group->id = 101; $q->setParameter('param', $group); @@ -678,11 +693,11 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase public function testSupportsMemberOfExpressionManyToManyParameterArray() { $q = $this->_em->createQuery('SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE :param MEMBER OF u.groups'); - $q->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true); + $q->setHint(ORMQuery::HINT_FORCE_PARTIAL_LOAD, true); - $group = new \Doctrine\Tests\Models\CMS\CmsGroup; + $group = new CmsGroup(); $group->id = 101; - $group2 = new \Doctrine\Tests\Models\CMS\CmsGroup; + $group2 = new CmsGroup(); $group2->id = 105; $q->setParameter('param', array($group, $group2)); @@ -697,7 +712,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase // "Get all persons who have $person as a friend." // 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 \Doctrine\Tests\Models\Company\CompanyPerson; + $person = new CompanyPerson(); $this->_em->getClassMetadata(get_class($person))->setIdentifierValues($person, array('id' => 101)); $q->setParameter('param', $person); $this->assertEquals( @@ -731,21 +746,21 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase public function testSupportsCurrentDateFunction() { $q = $this->_em->createQuery('SELECT d.id FROM Doctrine\Tests\Models\Generic\DateTimeModel d WHERE d.datetime > current_date()'); - $q->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true); + $q->setHint(ORMQuery::HINT_FORCE_PARTIAL_LOAD, true); $this->assertEquals('SELECT d0_.id AS id_0 FROM date_time_model d0_ WHERE d0_.col_datetime > CURRENT_DATE', $q->getSql()); } public function testSupportsCurrentTimeFunction() { $q = $this->_em->createQuery('SELECT d.id FROM Doctrine\Tests\Models\Generic\DateTimeModel d WHERE d.time > current_time()'); - $q->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true); + $q->setHint(ORMQuery::HINT_FORCE_PARTIAL_LOAD, true); $this->assertEquals('SELECT d0_.id AS id_0 FROM date_time_model d0_ WHERE d0_.col_time > CURRENT_TIME', $q->getSql()); } public function testSupportsCurrentTimestampFunction() { $q = $this->_em->createQuery('SELECT d.id FROM Doctrine\Tests\Models\Generic\DateTimeModel d WHERE d.datetime > current_timestamp()'); - $q->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true); + $q->setHint(ORMQuery::HINT_FORCE_PARTIAL_LOAD, true); $this->assertEquals('SELECT d0_.id AS id_0 FROM date_time_model d0_ WHERE d0_.col_datetime > CURRENT_TIMESTAMP', $q->getSql()); } @@ -884,7 +899,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase public function testBooleanLiteralInWhereOnSqlite() { $oldPlat = $this->_em->getConnection()->getDatabasePlatform(); - $this->_em->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\SqlitePlatform); + $this->_em->getConnection()->setDatabasePlatform(new SqlitePlatform()); $this->assertSqlGeneration( "SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = true", @@ -902,7 +917,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase public function testBooleanLiteralInWhereOnPostgres() { $oldPlat = $this->_em->getConnection()->getDatabasePlatform(); - $this->_em->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\PostgreSqlPlatform); + $this->_em->getConnection()->setDatabasePlatform(new PostgreSqlPlatform()); $this->assertSqlGeneration( "SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = true", @@ -1024,7 +1039,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase */ public function testPessimisticWriteLockQueryHint() { - if ($this->_em->getConnection()->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) { + if ($this->_em->getConnection()->getDatabasePlatform() instanceof SqlitePlatform) { $this->markTestSkipped('SqLite does not support Row locking at all.'); } @@ -1032,7 +1047,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase "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(Query::HINT_LOCK_MODE => \Doctrine\DBAL\LockMode::PESSIMISTIC_WRITE) + array(ORMQuery::HINT_LOCK_MODE => LockMode::PESSIMISTIC_WRITE) ); } @@ -1042,14 +1057,14 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase */ public function testPessimisticReadLockQueryHintPostgreSql() { - $this->_em->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\PostgreSqlPlatform); + $this->_em->getConnection()->setDatabasePlatform(new PostgreSqlPlatform()); $this->assertSqlGeneration( "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(Query::HINT_LOCK_MODE => \Doctrine\DBAL\LockMode::PESSIMISTIC_READ) - ); + array(ORMQuery::HINT_LOCK_MODE => LockMode::PESSIMISTIC_READ) + ); } /** @@ -1062,8 +1077,8 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase "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(Query::HINT_LOCK_MODE => \Doctrine\DBAL\LockMode::NONE) - ); + array(ORMQuery::HINT_LOCK_MODE => LockMode::NONE) + ); } /** @@ -1083,13 +1098,13 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase */ public function testPessimisticReadLockQueryHintMySql() { - $this->_em->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\MySqlPlatform); + $this->_em->getConnection()->setDatabasePlatform(new MySqlPlatform()); $this->assertSqlGeneration( "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(Query::HINT_LOCK_MODE => \Doctrine\DBAL\LockMode::PESSIMISTIC_READ) + array(ORMQuery::HINT_LOCK_MODE => LockMode::PESSIMISTIC_READ) ); } @@ -1099,13 +1114,13 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase */ public function testPessimisticReadLockQueryHintOracle() { - $this->_em->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\OraclePlatform); + $this->_em->getConnection()->setDatabasePlatform(new OraclePlatform()); $this->assertSqlGeneration( "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(Query::HINT_LOCK_MODE => \Doctrine\DBAL\LockMode::PESSIMISTIC_READ) + array(ORMQuery::HINT_LOCK_MODE => LockMode::PESSIMISTIC_READ) ); } @@ -1426,7 +1441,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $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(Query::HINT_FORCE_PARTIAL_LOAD => false) + array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => false) ); } @@ -1438,7 +1453,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $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(Query::HINT_FORCE_PARTIAL_LOAD => true) + array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => true) ); } @@ -1450,7 +1465,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $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(Query::HINT_FORCE_PARTIAL_LOAD => false) + array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => false) ); } @@ -1462,7 +1477,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $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(Query::HINT_FORCE_PARTIAL_LOAD => true) + array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => true) ); } @@ -1474,7 +1489,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $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(Query::HINT_FORCE_PARTIAL_LOAD => false) + array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => false) ); } @@ -1486,7 +1501,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $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(Query::HINT_FORCE_PARTIAL_LOAD => true) + array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => true) ); } @@ -1498,7 +1513,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $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(Query::HINT_FORCE_PARTIAL_LOAD => false) + array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => false) ); } @@ -1510,7 +1525,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $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(Query::HINT_FORCE_PARTIAL_LOAD => true) + array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => true) ); } @@ -1522,7 +1537,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $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(Query::HINT_FORCE_PARTIAL_LOAD => false) + array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => false) ); } @@ -1534,7 +1549,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $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(Query::HINT_FORCE_PARTIAL_LOAD => true) + array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => true) ); } @@ -1546,7 +1561,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $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(Query::HINT_FORCE_PARTIAL_LOAD => false) + array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => false) ); } @@ -1558,7 +1573,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $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(Query::HINT_FORCE_PARTIAL_LOAD => true) + array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => true) ); } @@ -1570,7 +1585,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $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(Query::HINT_FORCE_PARTIAL_LOAD => false) + array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => false) ); } @@ -2051,7 +2066,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $connMock = $this->_em->getConnection(); $orgPlatform = $connMock->getDatabasePlatform(); - $connMock->setDatabasePlatform(new \Doctrine\DBAL\Platforms\MySqlPlatform); + $connMock->setDatabasePlatform(new MySqlPlatform()); $this->assertSqlGeneration( "SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE CONCAT(u.name, u.status, 's') = ?1", "SELECT c0_.id AS id_0 FROM cms_users c0_ WHERE CONCAT(c0_.name, c0_.status, 's') = ?" @@ -2061,7 +2076,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase "SELECT CONCAT(c0_.id, c0_.name, c0_.status) AS sclr_0 FROM cms_users c0_ WHERE c0_.id = ?" ); - $connMock->setDatabasePlatform(new \Doctrine\DBAL\Platforms\PostgreSqlPlatform); + $connMock->setDatabasePlatform(new PostgreSqlPlatform()); $this->assertSqlGeneration( "SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE CONCAT(u.name, u.status, 's') = ?1", "SELECT c0_.id AS id_0 FROM cms_users c0_ WHERE c0_.name || c0_.status || 's' = ?" @@ -2071,7 +2086,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase "SELECT c0_.id || c0_.name || c0_.status AS sclr_0 FROM cms_users c0_ WHERE c0_.id = ?" ); - $connMock->setDatabasePlatform(new \Doctrine\DBAL\Platforms\SQLServerPlatform()); + $connMock->setDatabasePlatform(new SQLServerPlatform()); $this->assertSqlGeneration( "SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE CONCAT(u.name, u.status, 's') = ?1", "SELECT c0_.id AS id_0 FROM cms_users c0_ WHERE (c0_.name + c0_.status + 's') = ?" @@ -2145,7 +2160,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $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(Query::HINT_FORCE_PARTIAL_LOAD => false) + array(ORMQuery::HINT_FORCE_PARTIAL_LOAD => false) ); } @@ -2294,14 +2309,14 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase } } -class MyAbsFunction extends \Doctrine\ORM\Query\AST\Functions\FunctionNode +class MyAbsFunction extends FunctionNode { public $simpleArithmeticExpression; /** * @override */ - public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) + public function getSql(SqlWalker $sqlWalker) { return 'ABS(' . $sqlWalker->walkSimpleArithmeticExpression($this->simpleArithmeticExpression) . ')'; } @@ -2309,16 +2324,16 @@ class MyAbsFunction extends \Doctrine\ORM\Query\AST\Functions\FunctionNode /** * @override */ - public function parse(\Doctrine\ORM\Query\Parser $parser) + public function parse(Parser $parser) { $lexer = $parser->getLexer(); - $parser->match(\Doctrine\ORM\Query\Lexer::T_IDENTIFIER); - $parser->match(\Doctrine\ORM\Query\Lexer::T_OPEN_PARENTHESIS); + $parser->match(Lexer::T_IDENTIFIER); + $parser->match(Lexer::T_OPEN_PARENTHESIS); $this->simpleArithmeticExpression = $parser->SimpleArithmeticExpression(); - $parser->match(\Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS); + $parser->match(Lexer::T_CLOSE_PARENTHESIS); } } /** diff --git a/tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php index de71ba9b7..4110b54e6 100644 --- a/tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php @@ -1,27 +1,9 @@ . - */ namespace Doctrine\Tests\ORM\Query; use Doctrine\DBAL\Types\Type as DBALType; +use Doctrine\Tests\OrmTestCase; /** * Test case for testing the saving and referencing of query identifiers. @@ -37,7 +19,7 @@ use Doctrine\DBAL\Types\Type as DBALType; * testcases later since we'll have a lot of them and we might want to have special SQL * generation tests for some dbms specific SQL syntaxes. */ -class UpdateSqlGenerationTest extends \Doctrine\Tests\OrmTestCase +class UpdateSqlGenerationTest extends OrmTestCase { private $_em; diff --git a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php index abe602a53..acf4d08e6 100644 --- a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php +++ b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\ORM; @@ -27,6 +10,7 @@ use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Parameter; use Doctrine\ORM\Query\ParameterTypeInferer; +use Doctrine\Tests\OrmTestCase; /** * Test case for the QueryBuilder class used to build DQL query string in a @@ -36,7 +20,7 @@ use Doctrine\ORM\Query\ParameterTypeInferer; * @author Roman Borschel getDql(); + $dql = $qb->getDQL(); $q = $qb->getQuery(); $this->assertEquals($expectedDql, $dql); @@ -631,7 +615,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase $qb = $this->_em->createQueryBuilder(); $qb->select('u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') - ->where($qb->expr()->orx('u.username = :username', 'u.username = :username2')); + ->where($qb->expr()->orX('u.username = :username', 'u.username = :username2')); $parameters = new ArrayCollection(); $parameters->add(new Parameter('username', 'jwage')); @@ -787,7 +771,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase $q1 = $qb->getQuery(); - $this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = :name', $q1->getDql()); + $this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = :name', $q1->getDQL()); $this->assertEquals(1, count($q1->getParameters())); // add another condition and construct a second query @@ -796,7 +780,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase $q2 = $qb->getQuery(); - $this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = :name AND u.id = :id', $q2->getDql()); + $this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = :name AND u.id = :id', $q2->getDQL()); $this->assertTrue($q1 !== $q2); // two different, independent queries $this->assertEquals(2, count($q2->getParameters())); $this->assertEquals(1, count($q1->getParameters())); // $q1 unaffected @@ -842,7 +826,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals('u.username = ?1', (string)$qb->getDQLPart('where')); $this->assertEquals(1, count($qb->getDQLPart('orderBy'))); - $qb->resetDqlPart('where')->resetDqlPart('orderBy'); + $qb->resetDQLPart('where')->resetDQLPart('orderBy'); $this->assertNull($qb->getDQLPart('where')); $this->assertEquals(0, count($qb->getDQLPart('orderBy'))); @@ -1082,7 +1066,8 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase */ public function testWhereAppend() { - $this->setExpectedException('InvalidArgumentException', "Using \$append = true does not have an effect with 'where' or 'having' parts. See QueryBuilder#andWhere() for an example for correct usage."); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("Using \$append = true does not have an effect with 'where' or 'having' parts. See QueryBuilder#andWhere() for an example for correct usage."); $qb = $this->_em->createQueryBuilder() ->add('where', 'u.foo = ?1') diff --git a/tests/Doctrine/Tests/ORM/Repository/DefaultRepositoryFactoryTest.php b/tests/Doctrine/Tests/ORM/Repository/DefaultRepositoryFactoryTest.php index bfe5179a0..bdccb4d7e 100644 --- a/tests/Doctrine/Tests/ORM/Repository/DefaultRepositoryFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Repository/DefaultRepositoryFactoryTest.php @@ -2,6 +2,9 @@ namespace Doctrine\Tests\ORM\Repository; +use Doctrine\ORM\Configuration; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Repository\DefaultRepositoryFactory; use PHPUnit_Framework_TestCase; @@ -32,7 +35,7 @@ class DefaultRepositoryFactoryTest extends PHPUnit_Framework_TestCase */ protected function setUp() { - $this->configuration = $this->getMock('Doctrine\\ORM\\Configuration'); + $this->configuration = $this->createMock(Configuration::class); $this->entityManager = $this->createEntityManager(); $this->repositoryFactory = new DefaultRepositoryFactory(); @@ -122,10 +125,7 @@ class DefaultRepositoryFactoryTest extends PHPUnit_Framework_TestCase public function buildClassMetadata($className) { /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata|\PHPUnit_Framework_MockObject_MockObject */ - $metadata = $this - ->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata') - ->disableOriginalConstructor() - ->getMock(); + $metadata = $this->createMock(ClassMetadata::class); $metadata->expects($this->any())->method('getName')->will($this->returnValue($className)); @@ -139,7 +139,7 @@ class DefaultRepositoryFactoryTest extends PHPUnit_Framework_TestCase */ private function createEntityManager() { - $entityManager = $this->getMock('Doctrine\\ORM\\EntityManagerInterface'); + $entityManager = $this->createMock(EntityManagerInterface::class); $entityManager ->expects($this->any()) diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommandTest.php index ea19fefc3..af89c866d 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommandTest.php @@ -3,16 +3,19 @@ namespace Doctrine\Tests\ORM\Tools\Console\Command; use Doctrine\ORM\Tools\Console\Command\ConvertDoctrine1SchemaCommand; +use Doctrine\ORM\Tools\EntityGenerator; +use Doctrine\Tests\OrmTestCase; +use Symfony\Component\Console\Output\OutputInterface; -class ConvertDoctrine1SchemaCommandTest extends \Doctrine\Tests\OrmTestCase +class ConvertDoctrine1SchemaCommandTest extends OrmTestCase { public function testExecution() { - $entityGenerator = $this->getMock('Doctrine\ORM\Tools\EntityGenerator'); + $entityGenerator = $this->createMock(EntityGenerator::class); $command = new ConvertDoctrine1SchemaCommand(); $command->setEntityGenerator($entityGenerator); - $output = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); + $output = $this->createMock(OutputInterface::class); $output->expects($this->once()) ->method('writeln') ->with($this->equalTo('No Metadata Classes to process.')); diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php index 4dde04862..08ade2999 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php @@ -62,7 +62,7 @@ class GenerateRepositoriesCommandTest extends OrmFunctionalTestCase if ($file->isFile()) { \unlink($file->getPathname()); } elseif ($file->getBasename() === '.') { - $dirs[] = $file->getRealpath(); + $dirs[] = $file->getRealPath(); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/InfoCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/InfoCommandTest.php index 5594299ac..fb63e4f64 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/InfoCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/InfoCommandTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Tools\Console\Command; -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; diff --git a/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php b/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php index 22f04c318..6c62ca352 100644 --- a/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php @@ -1,35 +1,18 @@ . - */ namespace Doctrine\Tests\ORM\Tools; +use Doctrine\ORM\Configuration; +use Doctrine\ORM\Mapping\Driver\YamlDriver; use Doctrine\ORM\Tools\Export\ClassMetadataExporter; use Doctrine\ORM\Tools\ConvertDoctrine1Schema; use Doctrine\Tests\Mocks\MetadataDriverMock; -use Doctrine\Tests\Mocks\DatabasePlatformMock; use Doctrine\Tests\Mocks\EntityManagerMock; use Doctrine\Tests\Mocks\ConnectionMock; use Doctrine\Tests\Mocks\DriverMock; use Doctrine\Common\EventManager; use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory; +use Doctrine\Tests\OrmTestCase; /** * Test case for converting a Doctrine 1 style schema to Doctrine 2 mapping files @@ -41,17 +24,16 @@ use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory; * @since 2.0 * @version $Revision$ */ -class ConvertDoctrine1SchemaTest extends \Doctrine\Tests\OrmTestCase +class ConvertDoctrine1SchemaTest extends OrmTestCase { protected function _createEntityManager($metadataDriver) { $driverMock = new DriverMock(); - $config = new \Doctrine\ORM\Configuration(); + $config = new Configuration(); $config->setProxyDir(__DIR__ . '/../../Proxies'); $config->setProxyNamespace('Doctrine\Tests\Proxies'); $eventManager = new EventManager(); $conn = new ConnectionMock(array(), $driverMock, $config, $eventManager); - $mockDriver = new MetadataDriverMock(); $config->setMetadataDriverImpl($metadataDriver); return EntityManagerMock::create($conn, $config, $eventManager); @@ -74,7 +56,7 @@ class ConvertDoctrine1SchemaTest extends \Doctrine\Tests\OrmTestCase $this->assertTrue(file_exists(__DIR__ . '/convert/User.dcm.yml')); $this->assertTrue(file_exists(__DIR__ . '/convert/Profile.dcm.yml')); - $metadataDriver = new \Doctrine\ORM\Mapping\Driver\YamlDriver(__DIR__ . '/convert'); + $metadataDriver = new YamlDriver(__DIR__ . '/convert'); $em = $this->_createEntityManager($metadataDriver); $cmf = new DisconnectedClassMetadataFactory(); $cmf->setEntityManager($em); diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index 9fdf3b88a..0cbae94d7 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM\Tools; use Doctrine\Common\Annotations\AnnotationReader; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\ClassMetadataInfo; @@ -264,9 +265,9 @@ class EntityGeneratorTest extends OrmTestCase $comment = new EntityGeneratorComment(); $this->assertInstanceOf($metadata->name, $book->addComment($comment)); $this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $book->getComments()); - $this->assertEquals(new \Doctrine\Common\Collections\ArrayCollection(array($comment)), $book->getComments()); + $this->assertEquals(new ArrayCollection(array($comment)), $book->getComments()); $this->assertInternalType('boolean', $book->removeComment($comment)); - $this->assertEquals(new \Doctrine\Common\Collections\ArrayCollection(array()), $book->getComments()); + $this->assertEquals(new ArrayCollection(array()), $book->getComments()); $this->newInstance($isbnMetadata); $isbn = new $isbnMetadata->name(); @@ -612,7 +613,9 @@ class EntityGeneratorTest extends OrmTestCase $this->assertEquals($expected, $actual); } - $this->setExpectedException('\InvalidArgumentException', 'Invalid provided InheritanceType: INVALID'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid provided InheritanceType: INVALID'); + $method->invoke($this->_generator, 'INVALID'); } @@ -639,7 +642,9 @@ class EntityGeneratorTest extends OrmTestCase $this->assertEquals($expected, $actual); } - $this->setExpectedException('\InvalidArgumentException', 'Invalid provided ChangeTrackingPolicy: INVALID'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid provided ChangeTrackingPolicy: INVALID'); + $method->invoke($this->_generator, 'INVALID'); } @@ -666,7 +671,9 @@ class EntityGeneratorTest extends OrmTestCase $this->assertEquals($expected, $actual); } - $this->setExpectedException('\InvalidArgumentException', 'Invalid provided IdGeneratorType: INVALID'); + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid provided IdGeneratorType: INVALID'); + $method->invoke($this->_generator, 'INVALID'); } diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityRepositoryGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityRepositoryGeneratorTest.php index 02d6ed5a1..bcb16a3d6 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityRepositoryGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityRepositoryGeneratorTest.php @@ -5,8 +5,9 @@ namespace Doctrine\Tests\ORM\Tools; use Doctrine\ORM\Tools\EntityGenerator; use Doctrine\ORM\Tools\EntityRepositoryGenerator; use Doctrine\ORM\Mapping\ClassMetadataFactory; +use Doctrine\Tests\OrmTestCase; -class EntityRepositoryGeneratorTest extends \Doctrine\Tests\OrmTestCase +class EntityRepositoryGeneratorTest extends OrmTestCase { /** * @var EntityGenerator @@ -54,7 +55,7 @@ class EntityRepositoryGeneratorTest extends \Doctrine\Tests\OrmTestCase if ($file->isFile()) { \unlink($file->getPathname()); } elseif ($file->getBasename() === '.') { - $dirs[] = $file->getRealpath(); + $dirs[] = $file->getRealPath(); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php index 0743a89d6..5edd47b03 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php @@ -1,37 +1,20 @@ . - */ namespace Doctrine\Tests\ORM\Tools\Export; +use Doctrine\ORM\Configuration; use Doctrine\ORM\Tools\Export\ClassMetadataExporter; use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Tools\EntityGenerator; use Doctrine\Tests\Mocks\MetadataDriverMock; -use Doctrine\Tests\Mocks\DatabasePlatformMock; use Doctrine\Tests\Mocks\EntityManagerMock; 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\OrmTestCase; +use Symfony\Component\Yaml\Parser; /** * Test case for ClassMetadataExporter @@ -43,7 +26,7 @@ use Doctrine\ORM\Mapping\ClassMetadataFactory; * @since 2.0 * @version $Revision$ */ -abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTestCase +abstract class AbstractClassMetadataExporterTest extends OrmTestCase { protected $_extension; @@ -52,12 +35,11 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest protected function _createEntityManager($metadataDriver) { $driverMock = new DriverMock(); - $config = new \Doctrine\ORM\Configuration(); + $config = new Configuration(); $config->setProxyDir(__DIR__ . '/../../Proxies'); $config->setProxyNamespace('Doctrine\Tests\Proxies'); $eventManager = new EventManager(); $conn = new ConnectionMock(array(), $driverMock, $config, $eventManager); - $mockDriver = new MetadataDriverMock(); $config->setMetadataDriverImpl($metadataDriver); return EntityManagerMock::create($conn, $config, $eventManager); @@ -376,7 +358,7 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest $this->assertEquals('cascade-all', $nodes[0]->getName()); } else if ($type == 'yaml') { - $yaml = new \Symfony\Component\Yaml\Parser(); + $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'])); diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/AnnotationClassMetadataExporterTest.php b/tests/Doctrine/Tests/ORM/Tools/Export/AnnotationClassMetadataExporterTest.php index 9fa20941c..a432ec451 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 2ad37588f..6ca3cf948 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 5bec99cfe..3eca15f9c 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 85c6e1c5e..a47c396d2 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; 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 8dc8e874d..4a379f82e 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 @@ -62,6 +62,18 @@ $metadata->mapOneToOne(array( 'orphanRemoval' => true, 'fetch' => ClassMetadataInfo::FETCH_EAGER, )); +$metadata->mapOneToOne(array( + '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( 'fieldName' => 'phonenumbers', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\Export\\Phonenumber', 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 70b1a8dae..8d0c5d217 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 @@ -35,6 +35,12 @@ + + + + + + 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 76c3902d6..d52e94601 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 @@ -34,6 +34,10 @@ Doctrine\Tests\ORM\Tools\Export\User: inversedBy: user orphanRemoval: true fetch: EAGER + cart: + targetEntity: Doctrine\Tests\ORM\Tools\Export\Cart + mappedBy: user + cascade: [ remove ] manyToOne: mainGroup: targetEntity: Doctrine\Tests\ORM\Tools\Export\Group diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/CountOutputWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/CountOutputWalkerTest.php index a9bb02da4..691b8ef20 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/CountOutputWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/CountOutputWalkerTest.php @@ -14,7 +14,7 @@ class CountOutputWalkerTest extends PaginationTestCase $query->setFirstResult(null)->setMaxResults(null); $this->assertEquals( - "SELECT COUNT(*) AS dctrn_count FROM (SELECT DISTINCT id_0 FROM (SELECT b0_.id AS id_0, c1_.id AS id_1, a2_.id AS id_2, a2_.name AS name_3, b0_.author_id AS author_id_4, b0_.category_id AS category_id_5 FROM BlogPost b0_ INNER JOIN Category c1_ ON b0_.category_id = c1_.id INNER JOIN Author a2_ ON b0_.author_id = a2_.id) dctrn_result) dctrn_table", $query->getSql() + "SELECT COUNT(*) AS dctrn_count FROM (SELECT DISTINCT id_0 FROM (SELECT b0_.id AS id_0, c1_.id AS id_1, a2_.id AS id_2, a2_.name AS name_3, b0_.author_id AS author_id_4, b0_.category_id AS category_id_5 FROM BlogPost b0_ INNER JOIN Category c1_ ON b0_.category_id = c1_.id INNER JOIN Author a2_ ON b0_.author_id = a2_.id) dctrn_result) dctrn_table", $query->getSQL() ); } @@ -26,7 +26,7 @@ class CountOutputWalkerTest extends PaginationTestCase $query->setFirstResult(null)->setMaxResults(null); $this->assertEquals( - "SELECT COUNT(*) AS dctrn_count FROM (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) dctrn_table", $query->getSql() + "SELECT COUNT(*) AS dctrn_count FROM (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) dctrn_table", $query->getSQL() ); } @@ -38,7 +38,7 @@ class CountOutputWalkerTest extends PaginationTestCase $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() + "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() ); } @@ -55,7 +55,7 @@ class CountOutputWalkerTest extends PaginationTestCase $this->assertEquals( "SELECT COUNT(*) AS dctrn_count 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_) dctrn_result) dctrn_table", - $query->getSql() + $query->getSQL() ); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/CountWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/CountWalkerTest.php index e44248926..a85a5f6f8 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/CountWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/CountWalkerTest.php @@ -19,7 +19,7 @@ class CountWalkerTest extends PaginationTestCase $query->setFirstResult(null)->setMaxResults(null); $this->assertEquals( - "SELECT count(DISTINCT b0_.id) AS sclr_0 FROM BlogPost b0_ INNER JOIN Category c1_ ON b0_.category_id = c1_.id INNER JOIN Author a2_ ON b0_.author_id = a2_.id", $query->getSql() + "SELECT count(DISTINCT b0_.id) AS sclr_0 FROM BlogPost b0_ INNER JOIN Category c1_ ON b0_.category_id = c1_.id INNER JOIN Author a2_ ON b0_.author_id = a2_.id", $query->getSQL() ); } @@ -32,7 +32,7 @@ class CountWalkerTest extends PaginationTestCase $query->setFirstResult(null)->setMaxResults(null); $this->assertEquals( - "SELECT count(DISTINCT a0_.id) AS sclr_0 FROM Author a0_", $query->getSql() + "SELECT count(DISTINCT a0_.id) AS sclr_0 FROM Author a0_", $query->getSQL() ); } @@ -45,7 +45,7 @@ class CountWalkerTest extends PaginationTestCase $query->setFirstResult(null)->setMaxResults(null); $this->assertEquals( - "SELECT count(DISTINCT b0_.id) AS sclr_0 FROM BlogPost b0_ GROUP BY b0_.id", $query->getSql() + "SELECT count(DISTINCT b0_.id) AS sclr_0 FROM BlogPost b0_ GROUP BY b0_.id", $query->getSQL() ); } @@ -58,7 +58,7 @@ class CountWalkerTest extends PaginationTestCase $query->setFirstResult(null)->setMaxResults(null); $this->assertEquals( - "SELECT count(DISTINCT b0_.id) AS sclr_0 FROM BlogPost b0_ INNER JOIN Category c1_ ON b0_.category_id = c1_.id INNER JOIN Author a2_ ON b0_.author_id = a2_.id", $query->getSql() + "SELECT count(DISTINCT b0_.id) AS sclr_0 FROM BlogPost b0_ INNER JOIN Category c1_ ON b0_.category_id = c1_.id INNER JOIN Author a2_ ON b0_.author_id = a2_.id", $query->getSQL() ); } @@ -71,7 +71,7 @@ class CountWalkerTest extends PaginationTestCase $query->setFirstResult(null)->setMaxResults(null); $this->assertEquals( - "SELECT count(DISTINCT b0_.id) AS sclr_0 FROM BlogPost b0_ INNER JOIN Category c1_ ON b0_.category_id = c1_.id INNER JOIN Author a2_ ON b0_.author_id = a2_.id", $query->getSql() + "SELECT count(DISTINCT b0_.id) AS sclr_0 FROM BlogPost b0_ INNER JOIN Category c1_ ON b0_.category_id = c1_.id INNER JOIN Author a2_ ON b0_.author_id = a2_.id", $query->getSQL() ); } @@ -83,12 +83,10 @@ class CountWalkerTest extends PaginationTestCase $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\CountWalker')); $query->setFirstResult(null)->setMaxResults(null); - $this->setExpectedException( - 'RuntimeException', - 'Cannot count query that uses a HAVING clause. Use the output walkers for pagination' - ); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Cannot count query that uses a HAVING clause. Use the output walkers for pagination'); - $query->getSql(); + $query->getSQL(); } /** @@ -103,7 +101,7 @@ class CountWalkerTest extends PaginationTestCase $query->setFirstResult(null)->setMaxResults(null); $this->assertEquals( - "SELECT count(DISTINCT b0_.id) AS sclr_0 FROM BlogPost b0_ LEFT JOIN Category c1_ ON (b0_.category_id = c1_.id)", $query->getSql() + "SELECT count(DISTINCT b0_.id) AS sclr_0 FROM BlogPost b0_ LEFT JOIN Category c1_ ON (b0_.category_id = c1_.id)", $query->getSQL() ); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php index 897e3531e..78fd38e9a 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php @@ -5,7 +5,6 @@ namespace Doctrine\Tests\ORM\Tools\Pagination; use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Platforms\PostgreSqlPlatform; -use Doctrine\DBAL\Platforms\SQLServerPlatform; use Doctrine\ORM\Query; class LimitSubqueryOutputWalkerTest extends PaginationTestCase @@ -19,7 +18,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); $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() + "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() ); } @@ -34,7 +33,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); $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() + "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); @@ -53,7 +52,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase $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", - $limitQuery->getSql() + $limitQuery->getSQL() ); $this->entityManager->getConnection()->setDatabasePlatform($odp); @@ -72,7 +71,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase $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", - $limitQuery->getSql() + $limitQuery->getSQL() ); $this->entityManager->getConnection()->setDatabasePlatform($odp); @@ -91,7 +90,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase $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", - $limitQuery->getSql() + $limitQuery->getSQL() ); $this->entityManager->getConnection()->setDatabasePlatform($odp); @@ -119,7 +118,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); $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() + "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); @@ -139,7 +138,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase $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", - $limitQuery->getSql() + $limitQuery->getSQL() ); $this->entityManager->getConnection()->setDatabasePlatform($odp); @@ -159,7 +158,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase $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", - $limitQuery->getSql() + $limitQuery->getSQL() ); $this->entityManager->getConnection()->setDatabasePlatform($odp); @@ -177,7 +176,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); $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() + "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); @@ -191,7 +190,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase $limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker'); $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() + "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() ); } @@ -286,7 +285,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase $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', - $query->getSql() + $query->getSQL() ); } @@ -375,7 +374,7 @@ ORDER BY b.id DESC' */ public function testLimitSubqueryOrderBySubSelectOrderByExpression() { - $this->entityManager->getConnection()->setDatabasePlatform(new MysqlPlatform()); + $this->entityManager->getConnection()->setDatabasePlatform(new MySqlPlatform()); $query = $this->entityManager->createQuery( 'SELECT a, diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php index 597ec1350..30da25789 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php @@ -19,7 +19,7 @@ class LimitSubqueryWalkerTest extends PaginationTestCase $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", - $limitQuery->getSql() + $limitQuery->getSQL() ); } @@ -33,7 +33,7 @@ class LimitSubqueryWalkerTest extends PaginationTestCase $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", - $limitQuery->getSql() + $limitQuery->getSQL() ); } @@ -47,7 +47,7 @@ class LimitSubqueryWalkerTest extends PaginationTestCase $this->assertEquals( "SELECT DISTINCT a0_.id AS id_0, sum(a0_.name) AS sclr_1 FROM Author a0_", - $limitQuery->getSql() + $limitQuery->getSQL() ); } @@ -64,7 +64,7 @@ class LimitSubqueryWalkerTest extends PaginationTestCase $this->assertEquals( "SELECT DISTINCT m0_.id AS id_0, m0_.author_id AS sclr_1 FROM MyBlogPost m0_ ORDER BY m0_.author_id ASC", - $limitQuery->getSql() + $limitQuery->getSQL() ); } @@ -81,7 +81,7 @@ class LimitSubqueryWalkerTest extends PaginationTestCase $this->assertEquals( "SELECT DISTINCT m0_.id AS id_0 FROM MyBlogPost m0_ INNER JOIN Category c1_ ON (m0_.category_id = c1_.id)", - $limitQuery->getSql() + $limitQuery->getSQL() ); } @@ -95,7 +95,7 @@ class LimitSubqueryWalkerTest extends PaginationTestCase $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", - $limitQuery->getSql() + $limitQuery->getSQL() ); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/WhereInWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/WhereInWalkerTest.php index 41152dc5d..f89ea5704 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/WhereInWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/WhereInWalkerTest.php @@ -20,7 +20,7 @@ class WhereInWalkerTest extends PaginationTestCase $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 u0_.id IN (?)", $whereInQuery->getSql() + "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() ); } @@ -34,7 +34,7 @@ class WhereInWalkerTest extends PaginationTestCase $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, 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() + "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() ); } @@ -48,7 +48,7 @@ class WhereInWalkerTest extends PaginationTestCase $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 1 = 1 AND u0_.id IN (?)", $whereInQuery->getSql() + "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() ); } @@ -62,7 +62,7 @@ class WhereInWalkerTest extends PaginationTestCase $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 1 = 1 AND 2 = 2 AND u0_.id IN (?)", $whereInQuery->getSql() + "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() ); } @@ -76,7 +76,7 @@ class WhereInWalkerTest extends PaginationTestCase $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 (1 = 1 OR 2 = 2) AND u0_.id IN (?)", $whereInQuery->getSql() + "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() ); } @@ -90,7 +90,7 @@ class WhereInWalkerTest extends PaginationTestCase $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 (1 = 1 OR 2 = 2) AND 3 = 3 AND u0_.id IN (?)", $whereInQuery->getSql() + "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() ); } @@ -104,7 +104,7 @@ class WhereInWalkerTest extends PaginationTestCase $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 (1 = 1 AND 2 = 2 OR 3 = 3) AND u0_.id IN (?)", $whereInQuery->getSql() + "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() ); } @@ -118,7 +118,7 @@ class WhereInWalkerTest extends PaginationTestCase $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() + "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() ); } @@ -134,7 +134,7 @@ class WhereInWalkerTest extends PaginationTestCase $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() + "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() ); } @@ -147,7 +147,7 @@ class WhereInWalkerTest extends PaginationTestCase $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 1 = 1 AND b0_.id IN (?)", $whereInQuery->getSql() + "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() ); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/ResolveTargetEntityListenerTest.php b/tests/Doctrine/Tests/ORM/Tools/ResolveTargetEntityListenerTest.php index 2934693f8..28753078d 100644 --- a/tests/Doctrine/Tests/ORM/Tools/ResolveTargetEntityListenerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/ResolveTargetEntityListenerTest.php @@ -5,8 +5,9 @@ namespace Doctrine\Tests\ORM\Tools; use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Tools\ResolveTargetEntityListener; use Doctrine\ORM\Events; +use Doctrine\Tests\OrmTestCase; -class ResolveTargetEntityListenerTest extends \Doctrine\Tests\OrmTestCase +class ResolveTargetEntityListenerTest extends OrmTestCase { /** * @var \Doctrine\ORM\EntityManager diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php index fd2cd20f7..bc54744b9 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php @@ -6,8 +6,9 @@ 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\OrmTestCase; -class SchemaToolTest extends \Doctrine\Tests\OrmTestCase +class SchemaToolTest extends OrmTestCase { public function testAddUniqueIndexForUniqueFieldAnnotation() { diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php index 57305818b..a17d92e7f 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php @@ -2,9 +2,11 @@ namespace Doctrine\Tests\ORM\Tools; +use Doctrine\ORM\EntityManager; use Doctrine\ORM\Tools\SchemaValidator; +use Doctrine\Tests\OrmTestCase; -class SchemaValidatorTest extends \Doctrine\Tests\OrmTestCase +class SchemaValidatorTest extends OrmTestCase { /** * @var EntityManager diff --git a/tests/Doctrine/Tests/ORM/Tools/SetupTest.php b/tests/Doctrine/Tests/ORM/Tools/SetupTest.php index 20ad5ee0a..06ef2a07a 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SetupTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SetupTest.php @@ -3,16 +3,19 @@ namespace Doctrine\Tests\ORM\Tools; use Doctrine\ORM\Tools\Setup; +use Doctrine\Common\Cache\Cache; use Doctrine\Common\Cache\ArrayCache; +use Doctrine\ORM\Version; +use Doctrine\Tests\OrmTestCase; -class SetupTest extends \Doctrine\Tests\OrmTestCase +class SetupTest extends OrmTestCase { private $originalAutoloaderCount; private $originalIncludePath; public function setUp() { - if (strpos(\Doctrine\ORM\Version::VERSION, "DEV") === false) { + if (strpos(Version::VERSION, "DEV") === false) { $this->markTestSkipped("Test only runs in a dev-installation from Github"); } @@ -95,9 +98,7 @@ class SetupTest extends \Doctrine\Tests\OrmTestCase */ public function testConfigureCacheCustomInstance() { - $cache = $this->getMock('Doctrine\Common\Cache\Cache'); - $cache->expects($this->never())->method('setNamespace'); - + $cache = $this->createMock(Cache::class); $config = Setup::createConfiguration(array(), true, $cache); $this->assertSame($cache, $config->getResultCacheImpl()); diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index d855c7817..0ff2572b9 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -6,20 +6,26 @@ use Doctrine\Common\Collections\ArrayCollection; 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; use Doctrine\Tests\Mocks\EntityManagerMock; 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; +use Doctrine\Tests\Models\GeoNames\Country; +use Doctrine\Tests\OrmTestCase; use stdClass; /** * UnitOfWork tests. */ -class UnitOfWorkTest extends \Doctrine\Tests\OrmTestCase +class UnitOfWorkTest extends OrmTestCase { /** * SUT @@ -198,7 +204,7 @@ class UnitOfWorkTest extends \Doctrine\Tests\OrmTestCase $persister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber')); $this->_unitOfWork->setEntityPersister('Doctrine\Tests\Models\CMS\CmsPhonenumber', $persister); - $ph = new \Doctrine\Tests\Models\CMS\CmsPhonenumber(); + $ph = new CmsPhonenumber(); $ph->phonenumber = '12345'; $this->assertEquals(UnitOfWork::STATE_NEW, $this->_unitOfWork->getEntityState($ph)); @@ -210,7 +216,7 @@ class UnitOfWorkTest extends \Doctrine\Tests\OrmTestCase $this->_unitOfWork->registerManaged($ph, array('phonenumber' => '12345'), array()); $this->assertEquals(UnitOfWork::STATE_MANAGED, $this->_unitOfWork->getEntityState($ph)); $this->assertFalse($persister->isExistsCalled()); - $ph2 = new \Doctrine\Tests\Models\CMS\CmsPhonenumber(); + $ph2 = new CmsPhonenumber(); $ph2->phonenumber = '12345'; $this->assertEquals(UnitOfWork::STATE_DETACHED, $this->_unitOfWork->getEntityState($ph2)); $this->assertFalse($persister->isExistsCalled()); @@ -244,7 +250,7 @@ class UnitOfWorkTest extends \Doctrine\Tests\OrmTestCase */ public function testLockWithoutEntityThrowsException() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->_unitOfWork->lock(null, null, null); } @@ -269,7 +275,7 @@ class UnitOfWorkTest extends \Doctrine\Tests\OrmTestCase $user->username = 'John'; $user->avatar = $invalidValue; - $this->setExpectedException('Doctrine\ORM\ORMInvalidArgumentException'); + $this->expectException(\Doctrine\ORM\ORMInvalidArgumentException::class); $this->_unitOfWork->persist($user); } @@ -297,7 +303,7 @@ class UnitOfWorkTest extends \Doctrine\Tests\OrmTestCase $user->username = 'John'; $user->avatar = $invalidValue; - $this->setExpectedException('Doctrine\ORM\ORMInvalidArgumentException'); + $this->expectException(\Doctrine\ORM\ORMInvalidArgumentException::class); $this->_unitOfWork->computeChangeSet($metadata, $user); } @@ -321,6 +327,28 @@ class UnitOfWorkTest extends \Doctrine\Tests\OrmTestCase $this->assertTrue($this->_unitOfWork->isInIdentityMap($entity)); } + /** + * @group 5849 + * @group 5850 + */ + public function testPersistedEntityAndClearManager() + { + $entity1 = new City(123, 'London'); + $entity2 = new Country(456, 'United Kingdom'); + + $this->_unitOfWork->persist($entity1); + $this->assertTrue($this->_unitOfWork->isInIdentityMap($entity1)); + + $this->_unitOfWork->persist($entity2); + $this->assertTrue($this->_unitOfWork->isInIdentityMap($entity2)); + + $this->_unitOfWork->clear(Country::class); + $this->assertTrue($this->_unitOfWork->isInIdentityMap($entity1)); + $this->assertFalse($this->_unitOfWork->isInIdentityMap($entity2)); + $this->assertTrue($this->_unitOfWork->isScheduledForInsert($entity1)); + $this->assertFalse($this->_unitOfWork->isScheduledForInsert($entity2)); + } + /** * Data Provider * @@ -337,6 +365,129 @@ class UnitOfWorkTest extends \Doctrine\Tests\OrmTestCase [new ArrayCollection()], ]; } + + /** + * @dataProvider entitiesWithValidIdentifiersProvider + * + * @param object $entity + * @param string $idHash + * + * @return void + */ + public function testAddToIdentityMapValidIdentifiers($entity, $idHash) + { + $this->_unitOfWork->persist($entity); + $this->_unitOfWork->addToIdentityMap($entity); + + self::assertSame($entity, $this->_unitOfWork->getByIdHash($idHash, get_class($entity))); + } + + public function entitiesWithValidIdentifiersProvider() + { + $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 [ + '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' => [$booleanFalse, ''], + ]; + } + + public function testRegisteringAManagedInstanceRequiresANonEmptyIdentifier() + { + $this->expectException(ORMInvalidArgumentException::class); + + $this->_unitOfWork->registerManaged(new EntityWithBooleanIdentifier(), [], []); + } + + /** + * @dataProvider entitiesWithInvalidIdentifiersProvider + * + * @param object $entity + * @param array $identifier + * + * @return void + */ + public function testAddToIdentityMapInvalidIdentifiers($entity, array $identifier) + { + $this->expectException(ORMInvalidArgumentException::class); + + $this->_unitOfWork->registerManaged($entity, $identifier, []); + } + + + public function entitiesWithInvalidIdentifiersProvider() + { + $firstNullString = new EntityWithCompositeStringIdentifier(); + + $firstNullString->id2 = uniqid('id2', true); + + $secondNullString = new EntityWithCompositeStringIdentifier(); + + $secondNullString->id1 = uniqid('id1', true); + + return [ + '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]], + ]; + } + + /** + * @group 5689 + * @group 1465 + */ + public function testObjectHashesOfMergedEntitiesAreNotUsedInOriginalEntityDataMap() + { + $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'); + } } /** @@ -443,3 +594,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; +} diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index d40b31082..a6a3bece4 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -2,7 +2,15 @@ namespace Doctrine\Tests; +use Doctrine\Common\Cache\ArrayCache; +use Doctrine\DBAL\Driver\PDOSqlite\Driver as SqliteDriver; +use Doctrine\DBAL\Logging\DebugStack; use Doctrine\DBAL\Types\Type; +use Doctrine\ORM\Cache\CacheConfiguration; +use Doctrine\ORM\Configuration; +use Doctrine\ORM\EntityManager; +use Doctrine\ORM\Tools\DebugUnitOfWorkListener; +use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Tests\EventListener\CacheMetadataListener; use Doctrine\ORM\Cache\Logging\StatisticsCacheLogger; use Doctrine\ORM\Cache\DefaultCacheFactory; @@ -287,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', + ), ); /** @@ -452,8 +465,8 @@ abstract class OrmFunctionalTestCase extends OrmTestCase $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'); } @@ -555,6 +568,12 @@ abstract class OrmFunctionalTestCase extends OrmTestCase $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(); } @@ -599,7 +618,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase if ( ! isset(static::$_sharedConn)) { static::$_sharedConn = TestUtil::getConnection(); - if (static::$_sharedConn->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) { + if (static::$_sharedConn->getDriver() instanceof SqliteDriver) { $forceCreateTables = true; } } @@ -614,7 +633,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase if ( ! $this->_em) { $this->_em = $this->_getEntityManager(); - $this->_schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->_em); + $this->_schemaTool = new SchemaTool($this->_em); } $classes = array(); @@ -652,20 +671,20 @@ abstract class OrmFunctionalTestCase extends OrmTestCase if (isset($GLOBALS['DOCTRINE_CACHE_IMPL'])) { self::$_metadataCacheImpl = new $GLOBALS['DOCTRINE_CACHE_IMPL']; } else { - self::$_metadataCacheImpl = new \Doctrine\Common\Cache\ArrayCache; + self::$_metadataCacheImpl = new ArrayCache(); } } if (is_null(self::$_queryCacheImpl)) { - self::$_queryCacheImpl = new \Doctrine\Common\Cache\ArrayCache; + self::$_queryCacheImpl = new ArrayCache(); } - $this->_sqlLoggerStack = new \Doctrine\DBAL\Logging\DebugStack(); + $this->_sqlLoggerStack = new DebugStack(); $this->_sqlLoggerStack->enabled = false; //FIXME: two different configs! $conn and the created entity manager have // different configs. - $config = new \Doctrine\ORM\Configuration(); + $config = new Configuration(); $config->setMetadataCacheImpl(self::$_metadataCacheImpl); $config->setQueryCacheImpl(self::$_queryCacheImpl); $config->setProxyDir(__DIR__ . '/Proxies'); @@ -675,7 +694,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase if ($this->isSecondLevelCacheEnabled || $enableSecondLevelCache) { - $cacheConfig = new \Doctrine\ORM\Cache\CacheConfiguration(); + $cacheConfig = new CacheConfiguration(); $cache = $this->getSharedSecondLevelCacheDriverImpl(); $factory = new DefaultCacheFactory($cacheConfig->getRegionsConfiguration(), $cache); @@ -721,10 +740,10 @@ abstract class OrmFunctionalTestCase extends OrmTestCase } if (isset($GLOBALS['debug_uow_listener'])) { - $evm->addEventListener(array('onFlush'), new \Doctrine\ORM\Tools\DebugUnitOfWorkListener()); + $evm->addEventListener(array('onFlush'), new DebugUnitOfWorkListener()); } - return \Doctrine\ORM\EntityManager::create($conn, $config); + return EntityManager::create($conn, $config); } /** @@ -734,7 +753,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase * * @throws \Exception */ - protected function onNotSuccessfulTest(\Exception $e) + protected function onNotSuccessfulTest($e) { if ($e instanceof \PHPUnit_Framework_AssertionFailedError) { throw $e; @@ -742,10 +761,10 @@ abstract class OrmFunctionalTestCase extends OrmTestCase 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(); diff --git a/tests/Doctrine/Tests/OrmTestCase.php b/tests/Doctrine/Tests/OrmTestCase.php index 7cc9c0580..200f53450 100644 --- a/tests/Doctrine/Tests/OrmTestCase.php +++ b/tests/Doctrine/Tests/OrmTestCase.php @@ -5,7 +5,12 @@ namespace Doctrine\Tests; use Doctrine\Common\Annotations; use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\Version; +use Doctrine\DBAL\DriverManager; +use Doctrine\ORM\Cache\CacheConfiguration; use Doctrine\ORM\Cache\DefaultCacheFactory; +use Doctrine\ORM\Configuration; +use Doctrine\ORM\Mapping\Driver\AnnotationDriver; +use Doctrine\Tests\Mocks\EntityManagerMock; /** * Base testcase class for all ORM testcases. @@ -93,7 +98,7 @@ abstract class OrmTestCase extends DoctrineTestCase Annotations\AnnotationRegistry::registerFile(__DIR__ . "/../../../lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php"); - return new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, (array) $paths); + return new AnnotationDriver($reader, (array) $paths); } /** @@ -117,7 +122,7 @@ abstract class OrmTestCase extends DoctrineTestCase ? self::getSharedMetadataCacheImpl() : new ArrayCache(); - $config = new \Doctrine\ORM\Configuration(); + $config = new Configuration(); $config->setMetadataCacheImpl($metadataCache); $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(array(), true)); @@ -130,7 +135,7 @@ abstract class OrmTestCase extends DoctrineTestCase if ($this->isSecondLevelCacheEnabled) { - $cacheConfig = new \Doctrine\ORM\Cache\CacheConfiguration(); + $cacheConfig = new CacheConfiguration(); $cache = $this->getSharedSecondLevelCacheDriverImpl(); $factory = new DefaultCacheFactory($cacheConfig->getRegionsConfiguration(), $cache); @@ -151,10 +156,10 @@ abstract class OrmTestCase extends DoctrineTestCase } if (is_array($conn)) { - $conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, $eventManager); + $conn = DriverManager::getConnection($conn, $config, $eventManager); } - return \Doctrine\Tests\Mocks\EntityManagerMock::create($conn, $config, $eventManager); + return EntityManagerMock::create($conn, $config, $eventManager); } protected function enableSecondLevelCache($log = true)