diff --git a/README.markdown b/README.markdown index e279f5f06..a0b5f2a20 100644 --- a/README.markdown +++ b/README.markdown @@ -1,6 +1,6 @@ # Doctrine 2 ORM -Doctrine 2 is an object-relational mapper (ORM) for PHP 5.3.0+ that provides transparent persistence +Doctrine 2 is an object-relational mapper (ORM) for PHP 5.3.2+ 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 Hibernates HQL. This provides developers with a powerful alternative to SQL that maintains flexibility diff --git a/UPGRADE_TO_2_1 b/UPGRADE_TO_2_1 new file mode 100644 index 000000000..f42244493 --- /dev/null +++ b/UPGRADE_TO_2_1 @@ -0,0 +1,25 @@ +This document details all the possible changes that you should investigate when updating +your project from Doctrine 2.0.x to 2.1 + +## Interface for EntityRepository + +The EntityRepository now has an interface Doctrine\Common\Persistence\ObjectRepository. This means that your classes that override EntityRepository and extend find(), findOneBy() or findBy() must be adjusted to follow this interface. + +## AnnotationReader changes + +The annotation reader was heavily refactored between 2.0 and 2.1-RC1. In theory the operation of the new reader should be backwards compatible, but it has to be setup differently to work that way: + + // new call to the AnnotationRegistry + \Doctrine\Common\Annotations\AnnotationRegistry::registerFile('/doctrine-src/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'); + + $reader = new \Doctrine\Common\Annotations\AnnotationReader(); + $reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\'); + // new code necessary starting here + $reader->setIgnoreNotImportedAnnotations(true); + $reader->setEnableParsePhpImports(false); + $reader = new \Doctrine\Common\Annotations\CachedReader( + new \Doctrine\Common\Annotations\IndexedReader($reader), new ArrayCache() + ); + +This is already done inside the ``$config->newDefaultAnnotationDriver``, so everything should automatically work if you are using this method. You can verify if everything still works by executing a console command such as schema-validate that loads all metadata into memory. + diff --git a/UPGRADE_TO_2_2 b/UPGRADE_TO_2_2 new file mode 100644 index 000000000..220fb39f9 --- /dev/null +++ b/UPGRADE_TO_2_2 @@ -0,0 +1,30 @@ +# EntityManager#getPartialReference() creates read-only entity + +Entities returned from EntityManager#getPartialReference() are now marked as read-only if they +haven't been in the identity map before. This means objects of this kind never lead to changes +in the UnitOfWork. + +# Fields omitted in a partial DQL query or a native query are never updated + +Fields of an entity that are not returned from a partial DQL Query or native SQL query +will never be updated through an UPDATE statement. + +# Removed support for onUpdate in @JoinColumn + +The onUpdate foreign key handling makes absolutly no sense in an ORM. Additionally Oracle doesn't even support it. Support for it is removed. + +# Changes in Annotation Handling + +There have been some changes to the annotation handling in Common 2.2 again, that affect how people with old configurations +from 2.0 have to configure the annotation driver if they don't use `Configuration::newDefaultAnnotationDriver()`: + + // Register the ORM Annotations in the AnnotationRegistry + AnnotationRegistry::registerFile('path/to/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'); + + $reader = new \Doctrine\Common\Annotations\SimpleAnnotationReader(); + $reader->addNamespace('Doctrine\ORM\Mapping'); + $reader = new \Doctrine\Common\Annotations\CachedReader($reader, new ArrayCache()); + + $driver = new AnnotationDriver($reader, (array)$paths); + + $config->setMetadataDriverImpl($driver); \ No newline at end of file diff --git a/build.properties.dev b/build.properties.dev index 7e72d6f1e..20e91dc37 100644 --- a/build.properties.dev +++ b/build.properties.dev @@ -8,6 +8,7 @@ report.dir=reports log.archive.dir=logs project.pirum_dir= project.download_dir= +project.xsd_dir= test.phpunit_configuration_file= test.phpunit_generate_coverage=0 test.pmd_reports=0 diff --git a/build.xml b/build.xml index 320b593ed..b36457f3d 100644 --- a/build.xml +++ b/build.xml @@ -100,10 +100,30 @@ + + + + + + + + + + + + + + + + + + + + @@ -166,7 +186,7 @@ script Doctrine/Common/ Doctrine/DBAL/ - Symfony/Component/Yaml/ + Symfony/Component/Yaml/ Symfony/Component/Console/ @@ -188,9 +208,12 @@ - - - + + + + + + @@ -200,19 +223,24 @@ + + + + + + - + - - + + + + + + ./tests/Doctrine/Tests/ORM + + + + + + performance + locking_functional + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/run-all.sh b/run-all.sh new file mode 100755 index 000000000..80712eebc --- /dev/null +++ b/run-all.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# This script is a small convenience wrapper for running the doctrine testsuite against a large bunch of databases. +# Just create the phpunit.xmls as described in the array below and configure the specific files section +# to connect to that database. Just omit a file if you dont have that database and the tests will be skipped. + +configs[1]="mysql.phpunit.xml" +configs[2]='postgres.phpunit.xml' +configs[3]='sqlite.phpunit.xml' +configs[4]='oracle.phpunit.xml' +configs[5]='db2.phpunit.xml' +configs[6]='pdo-ibm.phpunit.xml' +configs[7]='sqlsrv.phpunit.xml' + +for i in "${configs[@]}"; do + if [ -f "$i" ]; + then + echo "RUNNING TESTS WITH CONFIG $i" + phpunit -c "$i" "$@" + fi; +done diff --git a/tests/Doctrine/Tests/AllTests.php b/tests/Doctrine/Tests/AllTests.php deleted file mode 100644 index 032366d04..000000000 --- a/tests/Doctrine/Tests/AllTests.php +++ /dev/null @@ -1,33 +0,0 @@ -addTest(ORM\AllTests::suite()); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'AllTests::main') { - AllTests::main(); -} \ No newline at end of file diff --git a/tests/Doctrine/Tests/DbalFunctionalTestSuite.php b/tests/Doctrine/Tests/DbalFunctionalTestSuite.php deleted file mode 100644 index e6c78cbd8..000000000 --- a/tests/Doctrine/Tests/DbalFunctionalTestSuite.php +++ /dev/null @@ -1,19 +0,0 @@ -sharedFixture['conn'])) { - $this->sharedFixture['conn'] = TestUtil::getConnection(); - } - } - - protected function tearDown() - { - $this->sharedFixture['conn']->close(); - $this->sharedFixture = null; - } -} \ No newline at end of file diff --git a/tests/Doctrine/Tests/DbalTestSuite.php b/tests/Doctrine/Tests/DbalTestSuite.php deleted file mode 100644 index 4f9cc4ef3..000000000 --- a/tests/Doctrine/Tests/DbalTestSuite.php +++ /dev/null @@ -1,10 +0,0 @@ -setProxyDir(__DIR__ . '/../Proxies'); $config->setProxyNamespace('Doctrine\Tests\Proxies'); - $config->setMetadataDriverImpl(\Doctrine\ORM\Mapping\Driver\AnnotationDriver::create()); + $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver()); } if (is_null($eventManager)) { $eventManager = new \Doctrine\Common\EventManager(); diff --git a/tests/Doctrine/Tests/Models/CMS/CmsEmail.php b/tests/Doctrine/Tests/Models/CMS/CmsEmail.php new file mode 100644 index 000000000..2d8818cbd --- /dev/null +++ b/tests/Doctrine/Tests/Models/CMS/CmsEmail.php @@ -0,0 +1,48 @@ +id; + } + + public function getEmail() { + return $this->email; + } + + public function setEmail($email) { + $this->email = $email; + } + + public function getUser() { + return $this->user; + } + + public function setUser(CmsUser $user) { + $this->user = $user; + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/CMS/CmsUser.php b/tests/Doctrine/Tests/Models/CMS/CmsUser.php index d9ac982ff..f02d0441b 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsUser.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsUser.php @@ -31,7 +31,7 @@ class CmsUser */ public $name; /** - * @OneToMany(targetEntity="CmsPhonenumber", mappedBy="user", cascade={"persist", "remove", "merge"}, orphanRemoval=true) + * @OneToMany(targetEntity="CmsPhonenumber", mappedBy="user", cascade={"persist", "merge"}, orphanRemoval=true) */ public $phonenumbers; /** @@ -42,6 +42,11 @@ class CmsUser * @OneToOne(targetEntity="CmsAddress", mappedBy="user", cascade={"persist"}, orphanRemoval=true) */ public $address; + /** + * @OneToOne(targetEntity="CmsEmail", inversedBy="user", cascade={"persist"}, orphanRemoval=true) + * @JoinColumn(referencedColumnName="id", nullable=true) + */ + public $email; /** * @ManyToMany(targetEntity="CmsGroup", inversedBy="users", cascade={"persist", "merge"}) * @JoinTable(name="cms_users_groups", @@ -119,4 +124,16 @@ class CmsUser $address->setUser($this); } } + + public function getEmail() { return $this->email; } + + public function setEmail(CmsEmail $email = null) { + if ($this->email !== $email) { + $this->email = $email; + + if ($email) { + $email->setUser($this); + } + } + } } diff --git a/tests/Doctrine/Tests/Models/Company/CompanyCar.php b/tests/Doctrine/Tests/Models/Company/CompanyCar.php index 62f400486..f970c273d 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyCar.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyCar.php @@ -15,7 +15,7 @@ class CompanyCar private $id; /** - * @Column(type="string", length="50") + * @Column(type="string", length=50) */ private $brand; diff --git a/tests/Doctrine/Tests/Models/Company/CompanyContract.php b/tests/Doctrine/Tests/Models/Company/CompanyContract.php index fd534f403..655d4fccb 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyContract.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyContract.php @@ -7,7 +7,11 @@ namespace Doctrine\Tests\Models\Company; * @Table(name="company_contracts") * @InheritanceType("SINGLE_TABLE") * @DiscriminatorColumn(name="discr", type="string") - * @DiscriminatorMap({"fix" = "CompanyFixContract", "flexible" = "CompanyFlexContract", "flexultra" = "CompanyFlexUltraContract"}) + * @DiscriminatorMap({ + * "fix" = "CompanyFixContract", + * "flexible" = "CompanyFlexContract", + * "flexultra" = "CompanyFlexUltraContract" + * }) */ abstract class CompanyContract { diff --git a/tests/Doctrine/Tests/Models/Company/CompanyEmployee.php b/tests/Doctrine/Tests/Models/Company/CompanyEmployee.php index 46b66cecc..61be7c5e6 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyEmployee.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyEmployee.php @@ -17,6 +17,11 @@ class CompanyEmployee extends CompanyPerson * @Column(type="string", length=255) */ private $department; + + /** + * @Column(type="datetime", nullable=true) + */ + private $startDate; public function getSalary() { return $this->salary; @@ -33,4 +38,12 @@ class CompanyEmployee extends CompanyPerson public function setDepartment($dep) { $this->department = $dep; } + + public function getStartDate() { + return $this->startDate; + } + + public function setStartDate($date) { + $this->startDate = $date; + } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/Company/CompanyManager.php b/tests/Doctrine/Tests/Models/Company/CompanyManager.php index 0c34fca3c..226995185 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyManager.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyManager.php @@ -9,7 +9,7 @@ namespace Doctrine\Tests\Models\Company; class CompanyManager extends CompanyEmployee { /** - * @Column(type="string", length="250") + * @Column(type="string", length=250) */ private $title; diff --git a/tests/Doctrine/Tests/Models/DDC117/DDC117Article.php b/tests/Doctrine/Tests/Models/DDC117/DDC117Article.php index 111c4fabe..51ea2278d 100644 --- a/tests/Doctrine/Tests/Models/DDC117/DDC117Article.php +++ b/tests/Doctrine/Tests/Models/DDC117/DDC117Article.php @@ -27,6 +27,11 @@ class DDC117Article */ private $translations; + /** + * @OneToMany(targetEntity="DDC117Link", mappedBy="source") + */ + private $links; + public function __construct($title) { $this->title = $title; diff --git a/tests/Doctrine/Tests/Models/DDC117/DDC117Link.php b/tests/Doctrine/Tests/Models/DDC117/DDC117Link.php new file mode 100644 index 000000000..7e0084a67 --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC117/DDC117Link.php @@ -0,0 +1,31 @@ +source = $source; + $this->target = $target; + } +} diff --git a/tests/Doctrine/Tests/Models/DDC753/DDC753CustomRepository.php b/tests/Doctrine/Tests/Models/DDC753/DDC753CustomRepository.php new file mode 100644 index 000000000..d277cf8aa --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC753/DDC753CustomRepository.php @@ -0,0 +1,36 @@ +. + */ + +namespace Doctrine\Tests\Models\DDC753; + +use Doctrine\ORM\EntityRepository; + +class DDC753CustomRepository extends EntityRepository +{ + + /** + * @return bool + */ + public function isCustomRepository() + { + return true; + } + +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/DDC753/DDC753DefaultRepository.php b/tests/Doctrine/Tests/Models/DDC753/DDC753DefaultRepository.php new file mode 100644 index 000000000..feba2cb50 --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC753/DDC753DefaultRepository.php @@ -0,0 +1,35 @@ +. + */ + +namespace Doctrine\Tests\Models\DDC753; + +use Doctrine\ORM\EntityRepository; + +class DDC753DefaultRepository extends EntityRepository +{ + /** + * @return bool + */ + public function isDefaultRepository() + { + return true; + } + +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithCustomRepository.php b/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithCustomRepository.php new file mode 100644 index 000000000..fa8a77957 --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithCustomRepository.php @@ -0,0 +1,39 @@ +. + */ + +namespace Doctrine\Tests\Models\DDC753; + +/** + * @Entity(repositoryClass = "Doctrine\Tests\Models\DDC753\DDC753CustomRepository") + */ +class DDC753EntityWithCustomRepository +{ + + /** + * @Id + * @Column(type="integer") + * @GeneratedValue + */ + protected $id; + + /** @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 new file mode 100644 index 000000000..43f435a98 --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithDefaultCustomRepository.php @@ -0,0 +1,39 @@ +. + */ + +namespace Doctrine\Tests\Models\DDC753; + +/** + * @Entity() + */ +class DDC753EntityWithDefaultCustomRepository +{ + + /** + * @Id + * @Column(type="integer") + * @GeneratedValue + */ + protected $id; + + /** @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 new file mode 100644 index 000000000..e7c21762a --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithInvalidRepository.php @@ -0,0 +1,39 @@ +. + */ + +namespace Doctrine\Tests\Models\DDC753; + +/** + * @Entity(repositoryClass = "\stdClass") + */ +class DDC753EntityWithInvalidRepository +{ + + /** + * @Id + * @Column(type="integer") + * @GeneratedValue + */ + protected $id; + + /** @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 new file mode 100644 index 000000000..9f0937aa1 --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC753/DDC753InvalidRepository.php @@ -0,0 +1,28 @@ +. + */ + +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 new file mode 100644 index 000000000..46cceb4c7 --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php @@ -0,0 +1,40 @@ +. + */ + +namespace Doctrine\Tests\Models\DDC869; + +/** + * @Entity + */ +class DDC869ChequePayment extends DDC869Payment +{ + + /** @column(type="string") */ + protected $serialNumber; + + public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) + { + $metadata->mapField(array( + 'fieldName' => 'serialNumber', + 'type' => 'string', + )); + } + +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php b/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php new file mode 100644 index 000000000..b446e059a --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php @@ -0,0 +1,40 @@ +. + */ + +namespace Doctrine\Tests\Models\DDC869; + +/** + * @Entity + */ +class DDC869CreditCardPayment extends DDC869Payment +{ + + /** @column(type="string") */ + protected $creditCardNumber; + + public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) + { + $metadata->mapField(array( + 'fieldName' => 'creditCardNumber', + 'type' => 'string', + )); + } + +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php b/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php new file mode 100644 index 000000000..c3c365715 --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php @@ -0,0 +1,57 @@ +. + */ + +namespace Doctrine\Tests\Models\DDC869; + +/** + * @MappedSuperclass(repositoryClass = "Doctrine\Tests\Models\DDC869\DDC869PaymentRepository") + */ +class DDC869Payment +{ + + /** + * @Id + * @Column(type="integer") + * @GeneratedValue + */ + protected $id; + + /** @column(type="float") */ + protected $value; + + + public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) + { + $metadata->mapField(array( + 'id' => true, + 'fieldName' => 'id', + 'type' => 'integer', + 'columnName' => 'id', + )); + $metadata->mapField(array( + 'fieldName' => 'value', + 'type' => 'float', + )); + $metadata->isMappedSuperclass = true; + $metadata->setCustomRepositoryClass("Doctrine\Tests\Models\DDC869\DDC869PaymentRepository"); + $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 new file mode 100644 index 000000000..d9018266a --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869PaymentRepository.php @@ -0,0 +1,37 @@ +. + */ + +namespace Doctrine\Tests\Models\DDC869; + +use Doctrine\ORM\EntityRepository; + +class DDC869PaymentRepository extends EntityRepository +{ + + /** + * Very complex method + * + * @return bool + */ + public function isTrue() + { + return true; + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/ECommerce/ECommerceCustomer.php b/tests/Doctrine/Tests/Models/ECommerce/ECommerceCustomer.php index fff4c9b82..0144b0998 100644 --- a/tests/Doctrine/Tests/Models/ECommerce/ECommerceCustomer.php +++ b/tests/Doctrine/Tests/Models/ECommerce/ECommerceCustomer.php @@ -34,7 +34,7 @@ class ECommerceCustomer * only one customer at the time, while a customer can choose only one * mentor. Not properly appropriate but it works. * - * @OneToOne(targetEntity="ECommerceCustomer", cascade={"persist"}) + * @OneToOne(targetEntity="ECommerceCustomer", cascade={"persist"}, fetch="EAGER") * @JoinColumn(name="mentor_id", referencedColumnName="id") */ private $mentor; diff --git a/tests/Doctrine/Tests/Models/ECommerce/ECommerceProduct.php b/tests/Doctrine/Tests/Models/ECommerce/ECommerceProduct.php index 198e16720..f843436b7 100644 --- a/tests/Doctrine/Tests/Models/ECommerce/ECommerceProduct.php +++ b/tests/Doctrine/Tests/Models/ECommerce/ECommerceProduct.php @@ -22,7 +22,7 @@ class ECommerceProduct private $id; /** - * @Column(type="string", length=50, nullable="true") + * @Column(type="string", length=50, nullable=true) */ private $name; @@ -56,6 +56,7 @@ class ECommerceProduct private $related; public $isCloned = false; + public $wakeUp = false; public function __construct() { @@ -166,4 +167,12 @@ class ECommerceProduct { $this->isCloned = true; } + + /** + * Testing docblock contents here + */ + public function __wakeup() + { + $this->wakeUp = true; + } } diff --git a/tests/Doctrine/Tests/Models/Legacy/LegacyArticle.php b/tests/Doctrine/Tests/Models/Legacy/LegacyArticle.php new file mode 100644 index 000000000..fb754462e --- /dev/null +++ b/tests/Doctrine/Tests/Models/Legacy/LegacyArticle.php @@ -0,0 +1,33 @@ +_user = $author; + } +} diff --git a/tests/Doctrine/Tests/Models/Legacy/LegacyCar.php b/tests/Doctrine/Tests/Models/Legacy/LegacyCar.php new file mode 100644 index 000000000..ac3834145 --- /dev/null +++ b/tests/Doctrine/Tests/Models/Legacy/LegacyCar.php @@ -0,0 +1,41 @@ +_description; + } + + public function addUser(LegacyUser $user) { + $this->_users[] = $user; + } + + public function getUsers() { + return $this->_users; + } +} diff --git a/tests/Doctrine/Tests/Models/Legacy/LegacyUser.php b/tests/Doctrine/Tests/Models/Legacy/LegacyUser.php new file mode 100644 index 000000000..f4f5e1fcb --- /dev/null +++ b/tests/Doctrine/Tests/Models/Legacy/LegacyUser.php @@ -0,0 +1,80 @@ +_articles = new ArrayCollection; + $this->_references = new ArrayCollection; + $this->_cars = new ArrayCollection; + } + + public function getId() { + return $this->_id; + } + + public function getUsername() { + return $this->_username; + } + + public function addArticle(LegacyArticle $article) { + $this->_articles[] = $article; + $article->setAuthor($this); + } + + public function addReference($reference) + { + $this->_references[] = $reference; + } + + public function references() + { + return $this->_references; + } + + public function addCar(LegacyCar $car) { + $this->_cars[] = $car; + $car->addUser($this); + } + + public function getCars() { + return $this->_cars; + } +} diff --git a/tests/Doctrine/Tests/Models/Legacy/LegacyUserReference.php b/tests/Doctrine/Tests/Models/Legacy/LegacyUserReference.php new file mode 100644 index 000000000..c6cd891a1 --- /dev/null +++ b/tests/Doctrine/Tests/Models/Legacy/LegacyUserReference.php @@ -0,0 +1,65 @@ +addReference($this); + $target->addReference($this); + + $this->_source = $source; + $this->_target = $target; + $this->_description = $description; + $this->_created = new \DateTime("now"); + } + + public function source() + { + return $this->_source; + } + + public function target() + { + return $this->_target; + } + + public function setDescription($desc) + { + $this->_description = $desc; + } + + public function getDescription() + { + return $this->_description; + } +} diff --git a/tests/Doctrine/Tests/ORM/AllTests.php b/tests/Doctrine/Tests/ORM/AllTests.php deleted file mode 100644 index fd7c25d7f..000000000 --- a/tests/Doctrine/Tests/ORM/AllTests.php +++ /dev/null @@ -1,41 +0,0 @@ -addTestSuite('Doctrine\Tests\ORM\UnitOfWorkTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\EntityManagerTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\CommitOrderCalculatorTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\QueryBuilderTest'); - $suite->addTest(Query\AllTests::suite()); - $suite->addTest(Hydration\AllTests::suite()); - $suite->addTest(Entity\AllTests::suite()); - $suite->addTest(Mapping\AllTests::suite()); - $suite->addTest(Functional\AllTests::suite()); - $suite->addTest(Id\AllTests::suite()); - $suite->addTest(Proxy\AllTests::suite()); - $suite->addTest(Tools\AllTests::suite()); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Orm_AllTests::main') { - AllTests::main(); -} diff --git a/tests/Doctrine/Tests/ORM/Entity/AllTests.php b/tests/Doctrine/Tests/ORM/Entity/AllTests.php deleted file mode 100644 index 3de6ee880..000000000 --- a/tests/Doctrine/Tests/ORM/Entity/AllTests.php +++ /dev/null @@ -1,31 +0,0 @@ -addTestSuite('Doctrine\Tests\ORM\Entity\ConstructorTest'); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Orm_Entity_AllTests::main') { - AllTests::main(); -} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/EntityManagerTest.php b/tests/Doctrine/Tests/ORM/EntityManagerTest.php index ca896ad10..f54974a27 100644 --- a/tests/Doctrine/Tests/ORM/EntityManagerTest.php +++ b/tests/Doctrine/Tests/ORM/EntityManagerTest.php @@ -26,32 +26,32 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase public function testGetConnection() { - $this->assertInstanceOf('\Doctrine\DBAL\Connection', $this->_em->getConnection()); + $this->assertInstanceOf('Doctrine\DBAL\Connection', $this->_em->getConnection()); } public function testGetMetadataFactory() { - $this->assertInstanceOf('\Doctrine\ORM\Mapping\ClassMetadataFactory', $this->_em->getMetadataFactory()); + $this->assertInstanceOf('Doctrine\ORM\Mapping\ClassMetadataFactory', $this->_em->getMetadataFactory()); } public function testGetConfiguration() { - $this->assertInstanceOf('\Doctrine\ORM\Configuration', $this->_em->getConfiguration()); + $this->assertInstanceOf('Doctrine\ORM\Configuration', $this->_em->getConfiguration()); } public function testGetUnitOfWork() { - $this->assertInstanceOf('\Doctrine\ORM\UnitOfWork', $this->_em->getUnitOfWork()); + $this->assertInstanceOf('Doctrine\ORM\UnitOfWork', $this->_em->getUnitOfWork()); } public function testGetProxyFactory() { - $this->assertInstanceOf('\Doctrine\ORM\Proxy\ProxyFactory', $this->_em->getProxyFactory()); + $this->assertInstanceOf('Doctrine\ORM\Proxy\ProxyFactory', $this->_em->getProxyFactory()); } public function testGetEventManager() { - $this->assertInstanceOf('\Doctrine\Common\EventManager', $this->_em->getEventManager()); + $this->assertInstanceOf('Doctrine\Common\EventManager', $this->_em->getEventManager()); } public function testCreateNativeQuery() @@ -64,7 +64,7 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase public function testCreateQueryBuilder() { - $this->assertInstanceOf('\Doctrine\ORM\QueryBuilder', $this->_em->createQueryBuilder()); + $this->assertInstanceOf('Doctrine\ORM\QueryBuilder', $this->_em->createQueryBuilder()); } public function testCreateQueryBuilderAliasValid() @@ -83,7 +83,7 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase public function testCreateQuery_DqlIsOptional() { - $this->assertInstanceOf('\Doctrine\ORM\Query', $this->_em->createQuery()); + $this->assertInstanceOf('Doctrine\ORM\Query', $this->_em->createQuery()); } public function testGetPartialReference() @@ -97,7 +97,7 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase public function testCreateQuery() { $q = $this->_em->createQuery('SELECT 1'); - $this->assertInstanceOf('\Doctrine\ORM\Query', $q); + $this->assertInstanceOf('Doctrine\ORM\Query', $q); $this->assertEquals('SELECT 1', $q->getDql()); } diff --git a/tests/Doctrine/Tests/ORM/Event/EntityEventDelegateeTest.php b/tests/Doctrine/Tests/ORM/Event/EntityEventDelegateeTest.php new file mode 100644 index 000000000..5c4db0101 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Event/EntityEventDelegateeTest.php @@ -0,0 +1,91 @@ +delegator = new \Doctrine\ORM\Event\EntityEventDelegator(); + } + + public function testGetSubscribedEventsWhenEmpty() + { + $this->assertEquals(array(), $this->delegator->getSubscribedEvents()); + } + + public function testAddListener() + { + $this->delegator->addEventListener('postLoad', 'stdClass', new DelegateeEventListener()); + $this->assertEquals(array('postLoad'), $this->delegator->getSubscribedEvents()); + } + + public function testAddSubscriber() + { + $this->delegator->addEventSubscriber(new DelegateeEventListener(), 'stdClass'); + $this->assertEquals(array('postLoad'), $this->delegator->getSubscribedEvents()); + } + + public function testAddListenerAfterFrozenThrowsException() + { + $this->delegator->getSubscribedEvents(); // freezes + + $this->setExpectedException("LogicException", "Cannot add event listeners aft"); + $this->delegator->addEventListener('postLoad', 'stdClass', new DelegateeEventListener()); + } + + public function testDelegateEvent() + { + $delegatee = new DelegateeEventListener(); + $this->delegator->addEventListener('postLoad', 'stdClass', $delegatee); + + $event = new \Doctrine\ORM\Event\LifecycleEventArgs(new \stdClass(), $this->_getTestEntityManager()); + $this->delegator->postLoad($event); + $this->delegator->postLoad($event); + + $this->assertEquals(2, $delegatee->postLoad); + } + + public function testDelegatePickEntity() + { + $delegatee = new DelegateeEventListener(); + $this->delegator->addEventListener('postLoad', 'stdClass', $delegatee); + + $event1 = new \Doctrine\ORM\Event\LifecycleEventArgs(new \stdClass(), $this->_getTestEntityManager()); + $event2 = new \Doctrine\ORM\Event\LifecycleEventArgs(new \Doctrine\Tests\Models\CMS\CmsUser(), $this->_getTestEntityManager()); + $this->delegator->postLoad($event1); + $this->delegator->postLoad($event2); + + $this->assertEquals(1, $delegatee->postLoad); + } +} + +class DelegateeEventListener implements \Doctrine\Common\EventSubscriber +{ + public $postLoad = 0; + + public function postLoad($args) + { + $this->postLoad++; + } + + /** + * Returns an array of events this subscriber wants to listen to. + * + * @return array + */ + function getSubscribedEvents() + { + return array('postLoad'); + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/AdvancedAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/AdvancedAssociationTest.php index a7c9cdc07..c4e43dfad 100644 --- a/tests/Doctrine/Tests/ORM/Functional/AdvancedAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/AdvancedAssociationTest.php @@ -64,8 +64,8 @@ class AdvancedAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCase $query = $this->_em->createQuery("SELECT p,t FROM Doctrine\Tests\ORM\Functional\Phrase p JOIN p.type t"); $res = $query->getResult(); $this->assertEquals(1, count($res)); - $this->assertTrue($res[0]->getType() instanceof PhraseType); - $this->assertTrue($res[0]->getType()->getPhrases() instanceof \Doctrine\ORM\PersistentCollection); + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\PhraseType', $res[0]->getType()); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $res[0]->getType()->getPhrases()); $this->assertFalse($res[0]->getType()->getPhrases()->isInitialized()); $this->_em->clear(); @@ -74,8 +74,8 @@ class AdvancedAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCase $query = $this->_em->createQuery("SELECT p,t,pp FROM Doctrine\Tests\ORM\Functional\Phrase p JOIN p.type t JOIN t.phrases pp"); $res = $query->getResult(); $this->assertEquals(1, count($res)); - $this->assertTrue($res[0]->getType() instanceof PhraseType); - $this->assertTrue($res[0]->getType()->getPhrases() instanceof \Doctrine\ORM\PersistentCollection); + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\PhraseType', $res[0]->getType()); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $res[0]->getType()->getPhrases()); $this->assertTrue($res[0]->getType()->getPhrases()->isInitialized()); $this->_em->clear(); @@ -83,8 +83,8 @@ class AdvancedAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCase // test3 - lazy-loading one-to-many after find() $phrase3 = $this->_em->find('Doctrine\Tests\ORM\Functional\Phrase', $phrase->getId()); $definitions = $phrase3->getDefinitions(); - $this->assertTrue($definitions instanceof \Doctrine\ORM\PersistentCollection); - $this->assertTrue($definitions[0] instanceof Definition); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $definitions); + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Definition', $definitions[0]); $this->_em->clear(); @@ -95,7 +95,7 @@ class AdvancedAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(1, count($res)); - $this->assertTrue($definitions[0] instanceof Definition); + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Definition', $definitions[0]); $this->assertEquals(2, $definitions->count()); } @@ -119,7 +119,7 @@ class AdvancedAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCase $res = $query->getResult(); $types = $res[0]->getTypes(); - $this->assertTrue($types[0] instanceof Type); + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Type', $types[0]); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/AllTests.php b/tests/Doctrine/Tests/ORM/Functional/AllTests.php deleted file mode 100644 index 4dd2b0644..000000000 --- a/tests/Doctrine/Tests/ORM/Functional/AllTests.php +++ /dev/null @@ -1,75 +0,0 @@ -addTestSuite('Doctrine\Tests\ORM\Functional\BasicFunctionalTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\DefaultValuesTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\TypeTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\AdvancedAssociationTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\NativeQueryTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\SingleTableInheritanceTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\ClassTableInheritanceTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\ClassTableInheritanceTest2'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\DetachedEntityTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\QueryCacheTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\ResultCacheTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\QueryTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\QueryDqlFunctionTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\AdvancedDqlQueryTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\OneToOneUnidirectionalAssociationTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\OneToOneBidirectionalAssociationTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\OneToOneEagerLoadingTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\OneToManyBidirectionalAssociationTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\OneToManyUnidirectionalAssociationTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\ManyToManyBasicAssociationTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\ManyToManyUnidirectionalAssociationTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\ManyToManyBidirectionalAssociationTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\OneToOneSelfReferentialAssociationTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\OneToManySelfReferentialAssociationTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\ManyToManySelfReferentialAssociationTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\OrderedCollectionTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\OrderedJoinedTableInheritanceCollectionTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\IndexByAssociationTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\CompositePrimaryKeyTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\ReferenceProxyTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\LifecycleCallbackTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\StandardEntityPersisterTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\CustomTreeWalkersTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\MappedSuperclassTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\EntityRepositoryTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\IdentityMapTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\DatabaseDriverTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\PostgreSQLIdentityStrategyTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\ExtraLazyCollectionTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\ClearEventTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\ReadOnlyTest'); - - $suite->addTest(Locking\AllTests::suite()); - $suite->addTest(Ticket\AllTests::suite()); - $suite->addTest(SchemaTool\AllTests::suite()); - - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Orm_Functional_AllTests::main') { - AllTests::main(); -} diff --git a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php index b6ca444ca..8d636dffb 100644 --- a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php @@ -46,7 +46,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->flush(); $this->assertTrue($this->_em->contains($ph)); $this->assertTrue($this->_em->contains($user)); - //$this->assertTrue($user->phonenumbers instanceof \Doctrine\ORM\PersistentCollection); + //$this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $user->phonenumbers); // Update name $user->name = 'guilherme'; @@ -92,7 +92,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->persist($user); $this->_em->flush(); - //$this->assertTrue($user->phonenumbers instanceof \Doctrine\ORM\PersistentCollection); + //$this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $user->phonenumbers); // Remove the first element from the collection unset($user->phonenumbers[0]); @@ -136,8 +136,42 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase ->getSingleResult(); // Address has been eager-loaded because it cant be lazy - $this->assertTrue($user2->address instanceof CmsAddress); - $this->assertFalse($user2->address instanceof \Doctrine\ORM\Proxy\Proxy); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress', $user2->address); + $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $user2->address); + } + + /** + * @group DDC-1230 + */ + public function testRemove() + { + $user = new CmsUser; + $user->name = 'Guilherme'; + $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->_em->persist($user); + + $this->assertEquals(\Doctrine\ORM\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->_em->persist($user); + $this->_em->flush(); + $id = $user->getId(); + + $this->_em->remove($user); + + $this->assertEquals(\Doctrine\ORM\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->assertNull($this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $id)); } public function testOneToManyOrphanRemoval() @@ -242,7 +276,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals('Guilherme', $users[0]->name); $this->assertEquals('gblanco', $users[0]->username); $this->assertEquals('developer', $users[0]->status); - $this->assertTrue($users[0]->phonenumbers instanceof \Doctrine\ORM\PersistentCollection); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $users[0]->phonenumbers); $this->assertTrue($users[0]->phonenumbers->isInitialized()); $this->assertEquals(0, $users[0]->phonenumbers->count()); //$this->assertNull($users[0]->articles); @@ -486,8 +520,8 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $query = $this->_em->createQuery("select u, a from Doctrine\Tests\Models\CMS\CmsUser u join u.address a where u.username='gblanco'"); $gblanco = $query->getSingleResult(); - $this->assertTrue($gblanco instanceof CmsUser); - $this->assertTrue($gblanco->getAddress() instanceof CmsAddress); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $gblanco); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress', $gblanco->getAddress()); $this->assertEquals('Berlin', $gblanco->getAddress()->getCity()); } @@ -595,7 +629,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $user2 = $query->getSingleResult(); $this->assertEquals(1, count($user2->articles)); - $this->assertTrue($user2->address instanceof CmsAddress); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress', $user2->address); $oldLogger = $this->_em->getConnection()->getConfiguration()->getSQLLogger(); $debugStack = new \Doctrine\DBAL\Logging\DebugStack; @@ -656,7 +690,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase ->setParameter('user', $userRef) ->getSingleResult(); - $this->assertTrue($address2->getUser() instanceof \Doctrine\ORM\Proxy\Proxy); + $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $address2->getUser()); $this->assertTrue($userRef === $address2->getUser()); $this->assertFalse($userRef->__isInitialized__); $this->assertEquals('Germany', $address2->country); @@ -827,39 +861,8 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(0, $this->_em->getConnection()->fetchColumn("select count(*) from cms_addresses where id=".$addressId."")); } - public function testClearingCollectionDoesNotInitialize() - { - $user = new CmsUser(); - $user->username = "beberlei"; - $user->name = "Benjamin E."; - $user->status = 'active'; - - $grp = new CmsGroup(); - $grp->setName("The Dudes"); - - $grp->addUser($user); - $user->addGroup($grp); - - $this->_em->persist($user); - $this->_em->persist($grp); - $this->_em->flush(); - $this->_em->clear(); - - $this->assertEquals(1, $this->_em->getConnection()->fetchColumn("select count(*) from cms_users_groups")); - - $user2 = $this->_em->find(get_class($user), $user->id); - $this->assertFalse($user2->groups->isInitialized()); - $user2->groups->clear(); - $this->assertFalse($user2->groups->isInitialized()); - $this->_em->flush(); - $this->assertFalse($user2->groups->isInitialized()); - - $this->assertEquals(0, $this->_em->getConnection()->fetchColumn("select count(*) from cms_users_groups")); - } - public function testGetPartialReferenceToUpdateObjectWithoutLoadingIt() { - //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); $user = new CmsUser(); $user->username = "beberlei"; $user->name = "Benjamin E."; @@ -878,7 +881,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->flush(); $this->_em->clear(); - $this->assertEquals('Stephan', $this->_em->find(get_class($user), $userId)->name); + $this->assertEquals('Benjamin E.', $this->_em->find(get_class($user), $userId)->name); } public function testMergePersistsNewEntities() @@ -901,7 +904,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->clear(); $user2 = $this->_em->find(get_class($managedUser), $userId); - $this->assertTrue($user2 instanceof CmsUser); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $user2); } public function testMergeThrowsExceptionIfEntityWithGeneratedIdentifierDoesNotExist() diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php index 0fbff503e..e8768e7ff 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php @@ -50,8 +50,8 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $entities = $query->getResult(); $this->assertEquals(2, count($entities)); - $this->assertTrue($entities[0] instanceof CompanyPerson); - $this->assertTrue($entities[1] instanceof CompanyEmployee); + $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyPerson', $entities[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $entities[1]); $this->assertTrue(is_numeric($entities[0]->getId())); $this->assertTrue(is_numeric($entities[1]->getId())); $this->assertEquals('Roman S. Borschel', $entities[0]->getName()); @@ -65,7 +65,7 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $entities = $query->getResult(); $this->assertEquals(1, count($entities)); - $this->assertTrue($entities[0] instanceof CompanyEmployee); + $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $entities[0]); $this->assertTrue(is_numeric($entities[0]->getId())); $this->assertEquals('Guilherme Blanco', $entities[0]->getName()); $this->assertEquals(100000, $entities[0]->getSalary()); @@ -73,7 +73,7 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->clear(); $guilherme = $this->_em->getRepository(get_class($employee))->findOneBy(array('name' => 'Guilherme Blanco')); - $this->assertTrue($guilherme instanceof CompanyEmployee); + $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $guilherme); $this->assertEquals('Guilherme Blanco', $guilherme->getName()); $this->_em->clear(); @@ -110,7 +110,7 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $manager = $this->_em->find('Doctrine\Tests\Models\Company\CompanyManager', $manager->getId()); - $this->assertTrue($manager instanceof CompanyManager); + $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyManager', $manager); $this->assertEquals('Roman B.', $manager->getName()); $this->assertEquals(119000, $manager->getSalary()); $this->assertEquals('CEO', $manager->getTitle()); @@ -130,12 +130,12 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $person = $this->_em->find('Doctrine\Tests\Models\Company\CompanyPerson', $manager->getId()); - $this->assertTrue($person instanceof CompanyManager); + $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyManager', $person); $this->assertEquals('Roman S. Borschel', $person->getName()); $this->assertEquals(100000, $person->getSalary()); $this->assertEquals('CTO', $person->getTitle()); $this->assertTrue(is_numeric($person->getId())); - //$this->assertTrue($person->getCar() instanceof CompanyCar); + //$this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyCar', $person->getCar()); } public function testSelfReferencingOneToOne() { @@ -167,9 +167,9 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $result = $query->getResult(); $this->assertEquals(1, count($result)); - $this->assertTrue($result[0] instanceof CompanyPerson); + $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyPerson', $result[0]); $this->assertEquals('Mary Smith', $result[0]->getName()); - $this->assertTrue($result[0]->getSpouse() instanceof CompanyEmployee); + $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $result[0]->getSpouse()); $this->assertEquals('John Smith', $result[0]->getSpouse()->getName()); $this->assertSame($result[0], $result[0]->getSpouse()->getSpouse()); } @@ -229,20 +229,20 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $result = $q->getResult(); $this->assertEquals(1, count($result)); - $this->assertTrue($result[0] instanceof CompanyOrganization); + $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyOrganization', $result[0]); $this->assertNull($result[0]->getMainEvent()); $events = $result[0]->getEvents(); - $this->assertTrue($events instanceof \Doctrine\ORM\PersistentCollection); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $events); $this->assertFalse($events->isInitialized()); $this->assertEquals(2, count($events)); if ($events[0] instanceof CompanyAuction) { - $this->assertTrue($events[1] instanceof CompanyRaffle); + $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyRaffle', $events[1]); } else { - $this->assertTrue($events[0] instanceof CompanyRaffle); - $this->assertTrue($events[1] instanceof CompanyAuction); + $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyRaffle', $events[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyAuction', $events[1]); } } @@ -263,7 +263,7 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $result = $q->getResult(); $this->assertEquals(1, count($result)); - $this->assertTrue($result[0] instanceof CompanyAuction, sprintf("Is of class %s",get_class($result[0]))); + $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyAuction', $result[0], sprintf("Is of class %s",get_class($result[0]))); $this->_em->clear(); @@ -273,12 +273,12 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $result = $q->getResult(); $this->assertEquals(1, count($result)); - $this->assertTrue($result[0] instanceof CompanyOrganization); + $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyOrganization', $result[0]); $mainEvent = $result[0]->getMainEvent(); // mainEvent should have been loaded because it can't be lazy - $this->assertTrue($mainEvent instanceof CompanyAuction); - $this->assertFalse($mainEvent instanceof \Doctrine\ORM\Proxy\Proxy); + $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyAuction', $mainEvent); + $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $mainEvent); } /** @@ -291,8 +291,21 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertTrue(count($this->_em->createQuery( 'SELECT count(p.id) FROM Doctrine\Tests\Models\Company\CompanyEmployee p WHERE p.salary = 1') - ->getResult()) > 0); + ->getResult()) > 0); + } + + /** + * @group DDC-1341 + */ + public function testBulkUpdateNonScalarParameterDDC1341() + { + $dql = 'UPDATE Doctrine\Tests\Models\Company\CompanyEmployee AS p SET p.startDate = ?0 WHERE p.department = ?1'; + $query = $this->_em->createQuery($dql) + ->setParameter(0, new \DateTime()) + ->setParameter(1, 'IT'); + $result = $query->execute(); + } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest2.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest2.php index d720f5d92..e558f2abb 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest2.php +++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest2.php @@ -43,9 +43,9 @@ class ClassTableInheritanceTest2 extends \Doctrine\Tests\OrmFunctionalTestCase $related2 = $this->_em->find('Doctrine\Tests\ORM\Functional\CTIRelated', $relatedId); - $this->assertTrue($related2 instanceof CTIRelated); - $this->assertTrue($related2->getCTIParent() instanceof CTIChild); - $this->assertFalse($related2->getCTIParent() instanceof \Doctrine\ORM\Proxy\Proxy); + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\CTIRelated', $related2); + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\CTIChild', $related2->getCTIParent()); + $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $related2->getCTIParent()); $this->assertEquals('hello', $related2->getCTIParent()->getData()); $this->assertSame($related2, $related2->getCTIParent()->getRelated()); @@ -69,7 +69,7 @@ class ClassTableInheritanceTest2 extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertFalse($mmrel2->getCTIChildren()->isInitialized()); $this->assertEquals(1, count($mmrel2->getCTIChildren())); $this->assertTrue($mmrel2->getCTIChildren()->isInitialized()); - $this->assertTrue($mmrel2->getCTIChildren()->get(0) instanceof CTIChild); + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\CTIChild', $mmrel2->getCTIChildren()->get(0)); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php index 7eced1b84..ee762d345 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php @@ -45,7 +45,7 @@ class CompositePrimaryKeyTest extends \Doctrine\Tests\OrmFunctionalTestCase $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 100, 'long' => 200)); - $this->assertType('Doctrine\Tests\Models\Navigation\NavPointOfInterest', $poi); + $this->assertInstanceOf('Doctrine\Tests\Models\Navigation\NavPointOfInterest', $poi); $this->assertEquals(100, $poi->getLat()); $this->assertEquals(200, $poi->getLong()); $this->assertEquals('Brandenburger Tor', $poi->getName()); diff --git a/tests/Doctrine/Tests/ORM/Functional/CustomTreeWalkersTest.php b/tests/Doctrine/Tests/ORM/Functional/CustomTreeWalkersTest.php index c295af478..ada41d00b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CustomTreeWalkersTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CustomTreeWalkersTest.php @@ -59,7 +59,7 @@ class CustomTreeWalkersTest extends \Doctrine\Tests\OrmFunctionalTestCase { $this->assertSqlGeneration( 'select u from Doctrine\Tests\Models\CMS\CmsUser u', - "SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE c0_.id = 1" + "SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, c0_.email_id AS email_id4 FROM cms_users c0_ WHERE c0_.id = 1" ); } @@ -67,7 +67,7 @@ class CustomTreeWalkersTest extends \Doctrine\Tests\OrmFunctionalTestCase { $this->assertSqlGeneration( 'select u from Doctrine\Tests\Models\CMS\CmsUser u where u.name = :name or u.name = :otherName', - "SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE (c0_.name = ? OR c0_.name = ?) AND c0_.id = 1" + "SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, c0_.email_id AS email_id4 FROM cms_users c0_ WHERE (c0_.name = ? OR c0_.name = ?) AND c0_.id = 1" ); } @@ -75,7 +75,7 @@ class CustomTreeWalkersTest extends \Doctrine\Tests\OrmFunctionalTestCase { $this->assertSqlGeneration( 'select u from Doctrine\Tests\Models\CMS\CmsUser u where u.name = :name', - "SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE c0_.name = ? AND c0_.id = 1" + "SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, c0_.email_id AS email_id4 FROM cms_users c0_ WHERE c0_.name = ? AND c0_.id = 1" ); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php b/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php index 873f0d938..2e17ccf12 100644 --- a/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php @@ -50,11 +50,34 @@ class DefaultValuesTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->clear(); $a2 = $this->_em->find(get_class($a), $a->id); - $this->assertTrue($a2->getUser() instanceof DefaultValueUser); + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\DefaultValueUser', $a2->getUser()); $this->assertEquals($userId, $a2->getUser()->getId()); $this->assertEquals('Poweruser', $a2->getUser()->type); } - + + /** + * @group DDC-1386 + */ + public function testGetPartialReferenceWithDefaultValueNotEvalutedInFlush() + { + $user = new DefaultValueUser; + $user->name = 'romanb'; + $user->type = 'Normaluser'; + + $this->_em->persist($user); + $this->_em->flush(); + $this->_em->clear(); + + $user = $this->_em->getPartialReference('Doctrine\Tests\ORM\Functional\DefaultValueUser', $user->id); + $this->assertTrue($this->_em->getUnitOfWork()->isReadOnly($user)); + + $this->_em->flush(); + $this->_em->clear(); + + $user = $this->_em->find('Doctrine\Tests\ORM\Functional\DefaultValueUser', $user->id); + + $this->assertEquals('Normaluser', $user->type); + } } diff --git a/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php b/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php index c6509f938..ee265d0ea 100644 --- a/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php @@ -5,6 +5,7 @@ namespace Doctrine\Tests\ORM\Functional; 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; require_once __DIR__ . '/../../TestInit.php'; @@ -137,14 +138,14 @@ class DetachedEntityTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->clear(); $address2 = $this->_em->find(get_class($address), $address->id); - $this->assertTrue($address2->user instanceof \Doctrine\ORM\Proxy\Proxy); + $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $address2->user); $this->assertFalse($address2->user->__isInitialized__); $detachedAddress2 = unserialize(serialize($address2)); - $this->assertTrue($detachedAddress2->user instanceof \Doctrine\ORM\Proxy\Proxy); + $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $detachedAddress2->user); $this->assertFalse($detachedAddress2->user->__isInitialized__); $managedAddress2 = $this->_em->merge($detachedAddress2); - $this->assertTrue($managedAddress2->user instanceof \Doctrine\ORM\Proxy\Proxy); + $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $managedAddress2->user); $this->assertFalse($managedAddress2->user === $detachedAddress2->user); $this->assertFalse($managedAddress2->user->__isInitialized__); } @@ -192,5 +193,26 @@ class DetachedEntityTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertFalse($this->_em->contains($user)); $this->assertFalse($this->_em->getUnitOfWork()->isInIdentityMap($user)); } + + /** + * @group DDC-1340 + */ + public function testMergeArticleWrongVersion() + { + $article = new CmsArticle(); + $article->topic = "test"; + $article->text = "test"; + + $this->_em->persist($article); + $this->_em->flush(); + + $this->_em->detach($article); + + $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->_em->merge($article); + } } diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php index 6c620db38..c5216fb94 100644 --- a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php @@ -3,8 +3,8 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Tests\Models\CMS\CmsUser; -use Doctrine\Tests\Models\CMS\CmsPhonenumber; use Doctrine\Tests\Models\CMS\CmsAddress; +use Doctrine\Tests\Models\CMS\CmsPhonenumber; require_once __DIR__ . '/../../TestInit.php'; @@ -18,6 +18,12 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase parent::setUp(); } + public function tearDown() + { + $this->_em->getConfiguration()->setEntityNamespaces(array()); + parent::tearDown(); + } + public function loadFixture() { $user = new CmsUser; @@ -33,13 +39,66 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->persist($user2); $this->_em->flush(); + $user1Id = $user->getId(); + unset($user); unset($user2); + $this->_em->clear(); return $user1Id; } + + public function loadAssociatedFixture() + { + $address = new CmsAddress(); + $address->city = "Berlin"; + $address->country = "Germany"; + $address->street = "Foostreet"; + $address->zip = "12345"; + + $user = new CmsUser(); + $user->name = 'Roman'; + $user->username = 'romanb'; + $user->status = 'freak'; + $user->setAddress($address); + + $this->_em->persist($user); + $this->_em->persist($address); + $this->_em->flush(); + $this->_em->clear(); + + return array($user->id, $address->id); + } + + public function buildUser($name, $username, $status, $address) + { + $user = new CmsUser(); + $user->name = $name; + $user->username = $username; + $user->status = $status; + $user->setAddress($address); + + $this->_em->persist($user); + $this->_em->flush(); + + return $user; + } + + public function buildAddress($country, $city, $street, $zip) + { + $address = new CmsAddress(); + $address->country = $country; + $address->city = $city; + $address->street = $street; + $address->zip = $zip; + + $this->_em->persist($address); + $this->_em->flush(); + + return $address; + } public function testBasicFind() { @@ -47,7 +106,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $user = $repos->find($user1Id); - $this->assertTrue($user instanceof CmsUser); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser',$user); $this->assertEquals('Roman', $user->name); $this->assertEquals('freak', $user->status); } @@ -59,11 +118,58 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $users = $repos->findBy(array('status' => 'dev')); $this->assertEquals(1, count($users)); - $this->assertTrue($users[0] instanceof CmsUser); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser',$users[0]); $this->assertEquals('Guilherme', $users[0]->name); $this->assertEquals('dev', $users[0]->status); } + public function testFindByAssociationWithIntegerAsParameter() + { + $address1 = $this->buildAddress('Germany', 'Berlim', 'Foo st.', '123456'); + $user1 = $this->buildUser('Benjamin', 'beberlei', 'dev', $address1); + + $address2 = $this->buildAddress('Brazil', 'São Paulo', 'Bar st.', '654321'); + $user2 = $this->buildUser('Guilherme', 'guilhermeblanco', 'freak', $address2); + + $address3 = $this->buildAddress('USA', 'Nashville', 'Woo st.', '321654'); + $user3 = $this->buildUser('Jonathan', 'jwage', 'dev', $address3); + + unset($address1); + unset($address2); + unset($address3); + + $this->_em->clear(); + + $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsAddress'); + $addresses = $repository->findBy(array('user' => array($user1->getId(), $user2->getId()))); + + $this->assertEquals(2, count($addresses)); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress',$addresses[0]); + } + + public function testFindByAssociationWithObjectAsParameter() + { + $address1 = $this->buildAddress('Germany', 'Berlim', 'Foo st.', '123456'); + $user1 = $this->buildUser('Benjamin', 'beberlei', 'dev', $address1); + + $address2 = $this->buildAddress('Brazil', 'São Paulo', 'Bar st.', '654321'); + $user2 = $this->buildUser('Guilherme', 'guilhermeblanco', 'freak', $address2); + + $address3 = $this->buildAddress('USA', 'Nashville', 'Woo st.', '321654'); + $user3 = $this->buildUser('Jonathan', 'jwage', 'dev', $address3); + + unset($address1); + unset($address2); + unset($address3); + + $this->_em->clear(); + + $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsAddress'); + $addresses = $repository->findBy(array('user' => array($user1, $user2))); + + $this->assertEquals(2, count($addresses)); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress',$addresses[0]); + } public function testFindFieldByMagicCall() { @@ -72,7 +178,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $users = $repos->findByStatus('dev'); $this->assertEquals(1, count($users)); - $this->assertTrue($users[0] instanceof CmsUser); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser',$users[0]); $this->assertEquals('Guilherme', $users[0]->name); $this->assertEquals('dev', $users[0]->status); } @@ -99,12 +205,6 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(2, count($users)); } - public function tearDown() - { - $this->_em->getConfiguration()->setEntityNamespaces(array()); - parent::tearDown(); - } - /** * @expectedException \Doctrine\ORM\ORMException */ @@ -201,28 +301,6 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $repos->foo(); } - public function loadAssociatedFixture() - { - $address = new CmsAddress(); - $address->city = "Berlin"; - $address->country = "Germany"; - $address->street = "Foostreet"; - $address->zip = "12345"; - - $user = new CmsUser(); - $user->name = 'Roman'; - $user->username = 'romanb'; - $user->status = 'freak'; - $user->setAddress($address); - - $this->_em->persist($user); - $this->_em->persist($address); - $this->_em->flush(); - $this->_em->clear(); - - return array($user->id, $address->id); - } - /** * @group DDC-817 */ @@ -244,7 +322,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsAddress'); $address = $repos->findOneBy(array('user' => $userId)); - $this->assertType('Doctrine\Tests\Models\CMS\CmsAddress', $address); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress', $address); $this->assertEquals($addressId, $address->id); } @@ -285,7 +363,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsAddress'); $address = $repos->findOneByUser($userId); - $this->assertType('Doctrine\Tests\Models\CMS\CmsAddress', $address); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress', $address); $this->assertEquals($addressId, $address->id); } @@ -295,7 +373,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $query = $repos->createNamedQuery('all'); - $this->assertType('Doctrine\ORM\Query', $query); + $this->assertInstanceOf('Doctrine\ORM\Query', $query); $this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u', $query->getDQL()); } @@ -355,5 +433,43 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertSame($usersAsc[0], $usersDesc[1]); $this->assertSame($usersAsc[1], $usersDesc[0]); } + + + /** + * @group DDC-753 + */ + public function testDefaultRepositoryClassName() + { + $this->assertEquals($this->_em->getConfiguration()->getDefaultRepositoryClassName(), "Doctrine\ORM\EntityRepository"); + $this->_em->getConfiguration()->setDefaultRepositoryClassName("Doctrine\Tests\Models\DDC753\DDC753DefaultRepository"); + $this->assertEquals($this->_em->getConfiguration()->getDefaultRepositoryClassName(), "Doctrine\Tests\Models\DDC753\DDC753DefaultRepository"); + + $repos = $this->_em->getRepository('Doctrine\Tests\Models\DDC753\DDC753EntityWithDefaultCustomRepository'); + $this->assertInstanceOf("Doctrine\Tests\Models\DDC753\DDC753DefaultRepository", $repos); + $this->assertTrue($repos->isDefaultRepository()); + + + $repos = $this->_em->getRepository('Doctrine\Tests\Models\DDC753\DDC753EntityWithCustomRepository'); + $this->assertInstanceOf("Doctrine\Tests\Models\DDC753\DDC753CustomRepository", $repos); + $this->assertTrue($repos->isCustomRepository()); + + $this->assertEquals($this->_em->getConfiguration()->getDefaultRepositoryClassName(), "Doctrine\Tests\Models\DDC753\DDC753DefaultRepository"); + $this->_em->getConfiguration()->setDefaultRepositoryClassName("Doctrine\ORM\EntityRepository"); + $this->assertEquals($this->_em->getConfiguration()->getDefaultRepositoryClassName(), "Doctrine\ORM\EntityRepository"); + + } + + + /** + * @group DDC-753 + * @expectedException Doctrine\ORM\ORMException + * @expectedExceptionMessage Invalid repository class 'Doctrine\Tests\Models\DDC753\DDC753InvalidRepository'. it must be a Doctrine\ORM\EntityRepository. + */ + public function testSetDefaultRepositoryInvalidClassError() + { + $this->assertEquals($this->_em->getConfiguration()->getDefaultRepositoryClassName(), "Doctrine\ORM\EntityRepository"); + $this->_em->getConfiguration()->setDefaultRepositoryClassName("Doctrine\Tests\Models\DDC753\DDC753InvalidRepository"); + } + } diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/AllTests.php b/tests/Doctrine/Tests/ORM/Functional/Locking/AllTests.php deleted file mode 100644 index be725f0b0..000000000 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/AllTests.php +++ /dev/null @@ -1,31 +0,0 @@ -addTestSuite('Doctrine\Tests\ORM\Functional\Locking\OptimisticTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\Locking\LockTest'); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Orm_Functional_Locking_AllTests::main') { - AllTests::main(); -} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php index c1d4037d3..a597cc207 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php @@ -9,6 +9,9 @@ use Doctrine\Tests\Models\CMS\CmsArticle, require_once __DIR__ . '/../../../TestInit.php'; +/** + * @group locking_functional + */ class GearmanLockTest extends \Doctrine\Tests\OrmFunctionalTestCase { private $gearman = null; diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php index 62ba0c08a..cbdb44104 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php @@ -47,7 +47,7 @@ class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCa $result = $query->getResult(); $this->assertEquals(2, $this->_em->getUnitOfWork()->size()); - $this->assertTrue($result[0] instanceof CmsUser); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0]); $this->assertEquals('Guilherme', $result[0]->name); $this->assertEquals(1, $result[0]->getGroups()->count()); $groups = $result[0]->getGroups(); @@ -56,8 +56,8 @@ class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCa $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->assertTrue($groups instanceof \Doctrine\ORM\PersistentCollection); - $this->assertTrue($groups[0]->getUsers() instanceof \Doctrine\ORM\PersistentCollection); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $groups); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $groups[0]->getUsers()); $groups[0]->getUsers()->clear(); $groups->clear(); @@ -342,4 +342,39 @@ class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCa $this->assertEquals('Developers_New1', $user->groups[0]->name); $this->assertEquals('Developers_New2', $user->groups[1]->name); } + + /** + * @group DDC-733 + */ + public function testInitializePersistentCollection() + { + $user = $this->addCmsUserGblancoWithGroups(2); + $this->_em->clear(); + + $user = $this->_em->find(get_class($user), $user->id); + + $this->assertFalse($user->groups->isInitialized(), "Pre-condition: lazy collection"); + $this->_em->getUnitOfWork()->initializeObject($user->groups); + $this->assertTrue($user->groups->isInitialized(), "Collection should be initialized after calling UnitOfWork::initializeObject()"); + } + + /** + * @group DDC-1189 + * @group DDC-956 + */ + public function testClearBeforeLazyLoad() + { + $user = $this->addCmsUserGblancoWithGroups(4); + + $this->_em->clear(); + + $user = $this->_em->find(get_class($user), $user->id); + $user->groups->clear(); + $this->assertEquals(0, count($user->groups)); + + $this->_em->flush(); + + $user = $this->_em->find(get_class($user), $user->id); + $this->assertEquals(0, count($user->groups)); + } } diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBidirectionalAssociationTest.php index 5a6a2dd50..f8228d7ad 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBidirectionalAssociationTest.php @@ -117,8 +117,8 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati //$query->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true); $result = $query->getResult(); $this->assertEquals(2, count($result)); - $this->assertTrue($result[0] instanceof ECommerceCategory); - $this->assertTrue($result[1] instanceof ECommerceCategory); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCategory', $result[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCategory', $result[1]); $prods1 = $result[0]->getProducts(); $prods2 = $result[1]->getProducts(); $this->assertTrue($prods1->isInitialized()); @@ -157,10 +157,10 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati $this->assertEquals(2, count($secondCategoryProducts)); // lazy-load $this->assertTrue($secondCategoryProducts->isInitialized()); - $this->assertTrue($firstCategoryProducts[0] instanceof ECommerceProduct); - $this->assertTrue($firstCategoryProducts[1] instanceof ECommerceProduct); - $this->assertTrue($secondCategoryProducts[0] instanceof ECommerceProduct); - $this->assertTrue($secondCategoryProducts[1] instanceof ECommerceProduct); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $firstCategoryProducts[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $firstCategoryProducts[1]); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $secondCategoryProducts[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $secondCategoryProducts[1]); $this->assertCollectionEquals($firstCategoryProducts, $secondCategoryProducts); } @@ -192,10 +192,10 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati $this->assertEquals(2, count($secondProductCategories)); // lazy-load $this->assertTrue($secondProductCategories->isInitialized()); - $this->assertTrue($firstProductCategories[0] instanceof ECommerceCategory); - $this->assertTrue($firstProductCategories[1] instanceof ECommerceCategory); - $this->assertTrue($secondProductCategories[0] instanceof ECommerceCategory); - $this->assertTrue($secondProductCategories[1] instanceof ECommerceCategory); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCategory', $firstProductCategories[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCategory', $firstProductCategories[1]); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCategory', $secondProductCategories[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCategory', $secondProductCategories[1]); $this->assertCollectionEquals($firstProductCategories, $secondProductCategories); } diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToManySelfReferentialAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToManySelfReferentialAssociationTest.php index 020e77aec..2993825fa 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManySelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManySelfReferentialAssociationTest.php @@ -95,10 +95,10 @@ class ManyToManySelfReferentialAssociationTest extends AbstractManyToManyAssocia $this->assertEquals(2, count($firstRelatedBy)); $this->assertEquals(2, count($secondRelatedBy)); - $this->assertTrue($firstRelatedBy[0] instanceof ECommerceProduct); - $this->assertTrue($firstRelatedBy[1] instanceof ECommerceProduct); - $this->assertTrue($secondRelatedBy[0] instanceof ECommerceProduct); - $this->assertTrue($secondRelatedBy[1] instanceof ECommerceProduct); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $firstRelatedBy[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $firstRelatedBy[1]); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $secondRelatedBy[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $secondRelatedBy[1]); $this->assertCollectionEquals($firstRelatedBy, $secondRelatedBy); } diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToManyUnidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToManyUnidirectionalAssociationTest.php index d6c38fc54..7de55e4f0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManyUnidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManyUnidirectionalAssociationTest.php @@ -69,8 +69,8 @@ class ManyToManyUnidirectionalAssociationTest extends AbstractManyToManyAssociat $products = $firstCart->getProducts(); $secondCart = $result[1]; - $this->assertTrue($products[0] instanceof ECommerceProduct); - $this->assertTrue($products[1] instanceof ECommerceProduct); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $products[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $products[1]); $this->assertCollectionEquals($products, $secondCart->getProducts()); //$this->assertEquals("Doctrine 1.x Manual", $products[0]->getName()); //$this->assertEquals("Doctrine 2.x Manual", $products[1]->getName()); @@ -88,8 +88,8 @@ class ManyToManyUnidirectionalAssociationTest extends AbstractManyToManyAssociat $products = $firstCart->getProducts(); $secondCart = $result[1]; - $this->assertTrue($products[0] instanceof ECommerceProduct); - $this->assertTrue($products[1] instanceof ECommerceProduct); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $products[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $products[1]); $this->assertCollectionEquals($products, $secondCart->getProducts()); } diff --git a/tests/Doctrine/Tests/ORM/Functional/MappedSuperclassTest.php b/tests/Doctrine/Tests/ORM/Functional/MappedSuperclassTest.php index 9b1f8d607..bb324bf67 100644 --- a/tests/Doctrine/Tests/ORM/Functional/MappedSuperclassTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/MappedSuperclassTest.php @@ -38,9 +38,9 @@ class MappedSuperclassTest extends \Doctrine\Tests\OrmFunctionalTestCase $cleanFile = $this->_em->find(get_class($file), $file->getId()); - $this->assertType('Doctrine\Tests\Models\DirectoryTree\Directory', $cleanFile->getParent()); + $this->assertInstanceOf('Doctrine\Tests\Models\DirectoryTree\Directory', $cleanFile->getParent()); $this->assertEquals($directory->getId(), $cleanFile->getParent()->getId()); - $this->assertType('Doctrine\Tests\Models\DirectoryTree\Directory', $cleanFile->getParent()->getParent()); + $this->assertInstanceOf('Doctrine\Tests\Models\DirectoryTree\Directory', $cleanFile->getParent()->getParent()); $this->assertEquals($root->getId(), $cleanFile->getParent()->getParent()->getId()); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php b/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php index f997c6c01..3c41e0201 100644 --- a/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php @@ -49,9 +49,51 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase $users = $query->getResult(); $this->assertEquals(1, count($users)); - $this->assertTrue($users[0] instanceof CmsUser); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[0]); $this->assertEquals('Roman', $users[0]->name); } + + public function testBasicNativeQueryWithMetaResult() + { + $user = new CmsUser; + $user->name = 'Roman'; + $user->username = 'romanb'; + $user->status = 'dev'; + + $addr = new CmsAddress; + $addr->country = 'germany'; + $addr->zip = 10827; + $addr->city = 'Berlin'; + + + $user->setAddress($addr); + + $this->_em->persist($user); + $this->_em->flush(); + + $this->_em->clear(); + + $rsm = new ResultSetMapping; + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsAddress', 'a'); + $rsm->addFieldResult('a', $this->platform->getSQLResultCasing('id'), 'id'); + $rsm->addFieldResult('a', $this->platform->getSQLResultCasing('country'), 'country'); + $rsm->addFieldResult('a', $this->platform->getSQLResultCasing('zip'), 'zip'); + $rsm->addFieldResult('a', $this->platform->getSQLResultCasing('city'), 'city'); + $rsm->addMetaResult('a', $this->platform->getSQLResultCasing('user_id'), 'user_id'); + + $query = $this->_em->createNativeQuery('SELECT a.id, a.country, a.zip, a.city, a.user_id FROM cms_addresses a WHERE a.id = ?', $rsm); + $query->setParameter(1, $addr->id); + + $addresses = $query->getResult(); + + $this->assertEquals(1, count($addresses)); + $this->assertTrue($addresses[0] instanceof CmsAddress); + $this->assertEquals($addr->country, $addresses[0]->country); + $this->assertEquals($addr->zip, $addresses[0]->zip); + $this->assertEquals($addr->city, $addresses[0]->city); + $this->assertEquals($addr->street, $addresses[0]->street); + $this->assertTrue($addresses[0]->user instanceof CmsUser); + } public function testJoinedOneToManyNativeQuery() { @@ -83,9 +125,9 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase $users = $query->getResult(); $this->assertEquals(1, count($users)); - $this->assertTrue($users[0] instanceof CmsUser); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[0]); $this->assertEquals('Roman', $users[0]->name); - $this->assertTrue($users[0]->getPhonenumbers() instanceof \Doctrine\ORM\PersistentCollection); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $users[0]->getPhonenumbers()); $this->assertTrue($users[0]->getPhonenumbers()->isInitialized()); $this->assertEquals(1, count($users[0]->getPhonenumbers())); $phones = $users[0]->getPhonenumbers(); @@ -132,11 +174,11 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase $users = $query->getResult(); $this->assertEquals(1, count($users)); - $this->assertTrue($users[0] instanceof CmsUser); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[0]); $this->assertEquals('Roman', $users[0]->name); - $this->assertTrue($users[0]->getPhonenumbers() instanceof \Doctrine\ORM\PersistentCollection); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $users[0]->getPhonenumbers()); $this->assertFalse($users[0]->getPhonenumbers()->isInitialized()); - $this->assertTrue($users[0]->getAddress() instanceof CmsAddress); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress', $users[0]->getAddress()); $this->assertTrue($users[0]->getAddress()->getUser() == $users[0]); $this->assertEquals('germany', $users[0]->getAddress()->getCountry()); $this->assertEquals(10827, $users[0]->getAddress()->getZipCode()); @@ -185,14 +227,25 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase $users = $query->getResult(); $this->assertEquals(1, count($users)); - $this->assertTrue($users[0] instanceof CmsUser); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[0]); $this->assertEquals('Roman', $users[0]->name); - $this->assertTrue($users[0]->getPhonenumbers() instanceof \Doctrine\ORM\PersistentCollection); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $users[0]->getPhonenumbers()); $this->assertTrue($users[0]->getPhonenumbers()->isInitialized()); $this->assertEquals(1, count($users[0]->getPhonenumbers())); $phones = $users[0]->getPhonenumbers(); $this->assertEquals(424242, $phones[0]->phonenumber); $this->assertTrue($phones[0]->getUser() === $users[0]); + + $this->_em->clear(); + + $rsm = new ResultSetMappingBuilder($this->_em); + $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber', 'p'); + $query = $this->_em->createNativeQuery('SELECT p.* FROM cms_phonenumbers p WHERE p.phonenumber = ?', $rsm); + $query->setParameter(1, $phone->phonenumber); + $phone = $query->getSingleResult(); + + $this->assertNotNull($phone->getUser()); + $this->assertEquals($user->name, $phone->getUser()->getName()); } public function testJoinedOneToOneNativeQueryWithRSMBuilder() @@ -226,15 +279,26 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase $users = $query->getResult(); $this->assertEquals(1, count($users)); - $this->assertTrue($users[0] instanceof CmsUser); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[0]); $this->assertEquals('Roman', $users[0]->name); - $this->assertTrue($users[0]->getPhonenumbers() instanceof \Doctrine\ORM\PersistentCollection); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $users[0]->getPhonenumbers()); $this->assertFalse($users[0]->getPhonenumbers()->isInitialized()); - $this->assertTrue($users[0]->getAddress() instanceof CmsAddress); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress', $users[0]->getAddress()); $this->assertTrue($users[0]->getAddress()->getUser() == $users[0]); $this->assertEquals('germany', $users[0]->getAddress()->getCountry()); $this->assertEquals(10827, $users[0]->getAddress()->getZipCode()); $this->assertEquals('Berlin', $users[0]->getAddress()->getCity()); + + $this->_em->clear(); + + $rsm = new ResultSetMappingBuilder($this->_em); + $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', 'a'); + $query = $this->_em->createNativeQuery('SELECT a.* FROM cms_addresses a WHERE a.id = ?', $rsm); + $query->setParameter(1, $addr->getId()); + $address = $query->getSingleResult(); + + $this->assertNotNull($address->getUser()); + $this->assertEquals($user->name, $address->getUser()->getName()); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php index 16a633dde..e39e10b3e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php @@ -77,13 +77,13 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona $features = $product->getFeatures(); - $this->assertTrue($features[0] instanceof ECommerceFeature); - $this->assertFalse($features[0]->getProduct() instanceof \Doctrine\ORM\Proxy\Proxy); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $features[0]); + $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $features[0]->getProduct()); $this->assertSame($product, $features[0]->getProduct()); $this->assertEquals('Model writing tutorial', $features[0]->getDescription()); - $this->assertTrue($features[1] instanceof ECommerceFeature); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $features[1]); $this->assertSame($product, $features[1]->getProduct()); - $this->assertFalse($features[1]->getProduct() instanceof \Doctrine\ORM\Proxy\Proxy); + $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $features[1]->getProduct()); $this->assertEquals('Annotations examples', $features[1]->getDescription()); } @@ -97,11 +97,11 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona $features = $product->getFeatures(); $this->assertFalse($features->isInitialized()); - $this->assertTrue($features[0] instanceof ECommerceFeature); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $features[0]); $this->assertTrue($features->isInitialized()); $this->assertSame($product, $features[0]->getProduct()); $this->assertEquals('Model writing tutorial', $features[0]->getDescription()); - $this->assertTrue($features[1] instanceof ECommerceFeature); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $features[1]); $this->assertSame($product, $features[1]->getProduct()); $this->assertEquals('Annotations examples', $features[1]->getDescription()); } @@ -114,8 +114,8 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona $features = $query->getResult(); $product = $features[0]->getProduct(); - $this->assertTrue($product instanceof \Doctrine\ORM\Proxy\Proxy); - $this->assertTrue($product instanceof ECommerceProduct); + $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $product); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $product); $this->assertFalse($product->__isInitialized__); $this->assertSame('Doctrine Cookbook', $product->getName()); $this->assertTrue($product->__isInitialized__); @@ -130,8 +130,8 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona $features = $query->getResult(); $product = $features[0]->getProduct(); - $this->assertFalse($product instanceof \Doctrine\ORM\Proxy\Proxy); - $this->assertTrue($product instanceof ECommerceProduct); + $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $product); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $product); $this->assertSame('Doctrine Cookbook', $product->getName()); $this->assertFalse($product->getFeatures()->isInitialized()); diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManyOrphanRemovalTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManyOrphanRemovalTest.php new file mode 100644 index 000000000..78b2fe517 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/OneToManyOrphanRemovalTest.php @@ -0,0 +1,58 @@ +useModelSet('cms'); + + parent::setUp(); + } + + public function testOrphanRemoval() + { + $user = new CmsUser; + $user->status = 'dev'; + $user->username = 'romanb'; + $user->name = 'Roman B.'; + + $phone = new CmsPhonenumber; + $phone->phonenumber = '123456'; + + $user->addPhonenumber($phone); + + $this->_em->persist($user); + $this->_em->flush(); + + $userId = $user->getId(); + + $this->_em->clear(); + + $userProxy = $this->_em->getReference('Doctrine\Tests\Models\CMS\CmsUser', $userId); + + $this->_em->remove($userProxy); + $this->_em->flush(); + $this->_em->clear(); + + $query = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u'); + $result = $query->getResult(); + + $this->assertEquals(0, count($result), 'CmsUser should be removed by EntityManager'); + + $query = $this->_em->createQuery('SELECT p FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p'); + $result = $query->getResult(); + + $this->assertEquals(0, count($result), 'CmsPhonenumber should be removed by orphanRemoval'); + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php index 5d6c182ab..e37497658 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php @@ -79,10 +79,10 @@ class OneToManySelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunctio $parent = $result[0]; $children = $parent->getChildren(); - $this->assertTrue($children[0] instanceof ECommerceCategory); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCategory', $children[0]); $this->assertSame($parent, $children[0]->getParent()); $this->assertEquals(' books', strstr($children[0]->getName(), ' books')); - $this->assertTrue($children[1] instanceof ECommerceCategory); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCategory', $children[1]); $this->assertSame($parent, $children[1]->getParent()); $this->assertEquals(' books', strstr($children[1]->getName(), ' books')); } @@ -98,10 +98,10 @@ class OneToManySelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunctio $parent = $result[0]; $children = $parent->getChildren(); - $this->assertTrue($children[0] instanceof ECommerceCategory); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCategory', $children[0]); $this->assertSame($parent, $children[0]->getParent()); $this->assertEquals(' books', strstr($children[0]->getName(), ' books')); - $this->assertTrue($children[1] instanceof ECommerceCategory); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCategory', $children[1]); $this->assertSame($parent, $children[1]->getParent()); $this->assertEquals(' books', strstr($children[1]->getName(), ' books')); } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php index 93e30cbc0..75be67e77 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php @@ -62,7 +62,7 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional $result = $query->getResult(); $customer = $result[0]; - $this->assertTrue($customer->getCart() instanceof ECommerceCart); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCart', $customer->getCart()); $this->assertEquals('paypal', $customer->getCart()->getPayment()); } @@ -75,7 +75,7 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional $result = $query->getResult(); $cart = $result[0]; - $this->assertTrue($cart->getCustomer() instanceof ECommerceCustomer); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCustomer', $cart->getCustomer()); $this->assertEquals('Giorgio', $cart->getCustomer()->getName()); } @@ -90,8 +90,8 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional $customer = $result[0]; $this->assertNull($customer->getMentor()); - $this->assertTrue($customer->getCart() instanceof ECommerceCart); - $this->assertFalse($customer->getCart() instanceof \Doctrine\ORM\Proxy\Proxy); + $this->assertInstanceOF('Doctrine\Tests\Models\ECommerce\ECommerceCart', $customer->getCart()); + $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $customer->getCart()); $this->assertEquals('paypal', $customer->getCart()->getPayment()); } @@ -107,7 +107,7 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional $this->_em->flush(); $this->_em->clear(); - $this->assertTrue($cust->getCart() instanceof ECommerceCart); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCart', $cust->getCart()); $this->assertEquals('Roman', $cust->getName()); $this->assertSame($cust, $cart->getCustomer()); @@ -126,7 +126,7 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional $cart3 = $query2->getSingleResult(); - $this->assertTrue($cart3->getCustomer() instanceof ECommerceCustomer); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCustomer', $cart3->getCustomer()); $this->assertEquals('Roman', $cart3->getCustomer()->getName()); } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneOrphanRemovalTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneOrphanRemovalTest.php new file mode 100644 index 000000000..c9bd72fcf --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneOrphanRemovalTest.php @@ -0,0 +1,94 @@ +useModelSet('cms'); + + parent::setUp(); + } + + public function testOrphanRemoval() + { + $user = new CmsUser; + $user->status = 'dev'; + $user->username = 'romanb'; + $user->name = 'Roman B.'; + + $address = new CmsAddress; + $address->country = 'de'; + $address->zip = 1234; + $address->city = 'Berlin'; + + $user->setAddress($address); + + $this->_em->persist($user); + $this->_em->flush(); + + $userId = $user->getId(); + + $this->_em->clear(); + + $userProxy = $this->_em->getReference('Doctrine\Tests\Models\CMS\CmsUser', $userId); + + $this->_em->remove($userProxy); + $this->_em->flush(); + $this->_em->clear(); + + $query = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u'); + $result = $query->getResult(); + + $this->assertEquals(0, count($result), 'CmsUser should be removed by EntityManager'); + + $query = $this->_em->createQuery('SELECT a FROM Doctrine\Tests\Models\CMS\CmsAddress a'); + $result = $query->getResult(); + + $this->assertEquals(0, count($result), 'CmsAddress should be removed by orphanRemoval'); + } + + public function testOrphanRemovalWhenUnlink() + { + $user = new CmsUser; + $user->status = 'dev'; + $user->username = 'beberlei'; + $user->name = 'Bejamin Eberlei'; + + $email = new CmsEmail; + $email->email = 'beberlei@domain.com'; + + $user->setEmail($email); + + $this->_em->persist($user); + $this->_em->flush(); + + $userId = $user->getId(); + + $this->_em->clear(); + + $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $userId); + + $user->setEmail(null); + + $this->_em->persist($user); + $this->_em->flush(); + $this->_em->clear(); + + $query = $this->_em->createQuery('SELECT e FROM Doctrine\Tests\Models\CMS\CmsEmail e'); + $result = $query->getResult(); + + $this->assertEquals(0, count($result), 'CmsEmail should be removed by orphanRemoval'); + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php index 321f66340..bcd41dcaf 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php @@ -49,6 +49,14 @@ class OneToOneSelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunction $this->assertForeignKeyIs(null); } + public function testFind() + { + $id = $this->_createFixture(); + + $customer = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceCustomer', $id); + $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $customer->getMentor()); + } + public function testEagerLoadsAssociation() { $this->_createFixture(); @@ -96,8 +104,8 @@ class OneToOneSelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunction $entity2 = $this->_em->find(get_class($entity1), $entity1->getId()); - $this->assertTrue($entity2->getOther1() instanceof MultiSelfReference); - $this->assertTrue($entity2->getOther2() instanceof MultiSelfReference); + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\MultiSelfReference', $entity2->getOther1()); + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\MultiSelfReference', $entity2->getOther2()); $this->assertNull($entity2->getOther1()->getOther1()); $this->assertNull($entity2->getOther1()->getOther2()); $this->assertNull($entity2->getOther2()->getOther1()); @@ -106,7 +114,7 @@ class OneToOneSelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunction public function assertLoadingOfAssociation($customer) { - $this->assertTrue($customer->getMentor() instanceof ECommerceCustomer); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCustomer', $customer->getMentor()); $this->assertEquals('Obi-wan Kenobi', $customer->getMentor()->getName()); } @@ -127,6 +135,8 @@ class OneToOneSelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunction $this->_em->flush(); $this->_em->clear(); + + return $customer->getId(); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php index 3adde7c10..ad4dd7404 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php @@ -56,7 +56,7 @@ class OneToOneUnidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona $result = $query->getResult(); $product = $result[0]; - $this->assertTrue($product->getShipping() instanceof ECommerceShipping); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceShipping', $product->getShipping()); $this->assertEquals(1, $product->getShipping()->getDays()); } @@ -69,7 +69,7 @@ class OneToOneUnidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona $result = $query->getResult(); $product = $result[0]; - $this->assertTrue($product->getShipping() instanceof ECommerceShipping); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceShipping', $product->getShipping()); $this->assertEquals(1, $product->getShipping()->getDays()); } diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php index 34d317d2b..eb7d662d6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php @@ -14,10 +14,27 @@ require_once __DIR__ . '/../../TestInit.php'; */ class QueryCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase { + /** + * @var \ReflectionProperty + */ + private $cacheDataReflection; + protected function setUp() { + $this->cacheDataReflection = new \ReflectionProperty("Doctrine\Common\Cache\ArrayCache", "data"); + $this->cacheDataReflection->setAccessible(true); $this->useModelSet('cms'); parent::setUp(); } + + /** + * @param ArrayCache $cache + * @return integer + */ + private function getCacheSize(ArrayCache $cache) + { + return sizeof($this->cacheDataReflection->getValue($cache)); + } + public function testQueryCache_DependsOnHints() { @@ -27,12 +44,12 @@ class QueryCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase $query->setQueryCacheDriver($cache); $query->getResult(); - $this->assertEquals(1, count($cache->getIds())); + $this->assertEquals(1, $this->getCacheSize($cache)); $query->setHint('foo', 'bar'); $query->getResult(); - $this->assertEquals(2, count($cache->getIds())); + $this->assertEquals(2, $this->getCacheSize($cache)); return $query; } @@ -44,13 +61,13 @@ class QueryCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testQueryCache_DependsOnFirstResult($query) { $cache = $query->getQueryCacheDriver(); - $cacheCount = count($cache->getIds()); + $cacheCount = $this->getCacheSize($cache); $query->setFirstResult(10); $query->setMaxResults(9999); $query->getResult(); - $this->assertEquals($cacheCount + 1, count($cache->getIds())); + $this->assertEquals($cacheCount + 1, $this->getCacheSize($cache)); } /** @@ -60,12 +77,12 @@ class QueryCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testQueryCache_DependsOnMaxResults($query) { $cache = $query->getQueryCacheDriver(); - $cacheCount = count($cache->getIds()); + $cacheCount = $this->getCacheSize($cache); $query->setMaxResults(10); $query->getResult(); - $this->assertEquals($cacheCount + 1, count($cache->getIds())); + $this->assertEquals($cacheCount + 1, $this->getCacheSize($cache)); } /** @@ -75,10 +92,10 @@ class QueryCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testQueryCache_DependsOnHydrationMode($query) { $cache = $query->getQueryCacheDriver(); - $cacheCount = count($cache->getIds()); + $cacheCount = $this->getCacheSize($cache); $query->getArrayResult(); - $this->assertEquals($cacheCount + 1, count($cache->getIds())); + $this->assertEquals($cacheCount + 1, $this->getCacheSize($cache)); } public function testQueryCache_NoHitSaveParserResult() @@ -87,13 +104,13 @@ 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\AbstractCache', array('_doFetch', '_doContains', '_doSave', '_doDelete', 'getIds')); + $cache = $this->getMock('Doctrine\Common\Cache\ArrayCache', array('doFetch', 'doSave')); $cache->expects($this->at(0)) - ->method('_doFetch') + ->method('doFetch') ->with($this->isType('string')) ->will($this->returnValue(false)); $cache->expects($this->at(1)) - ->method('_doSave') + ->method('doSave') ->with($this->isType('string'), $this->isInstanceOf('Doctrine\ORM\Query\ParserResult'), $this->equalTo(null)); $query->setQueryCacheDriver($cache); @@ -117,13 +134,14 @@ class QueryCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase ->method('getSqlExecutor') ->will($this->returnValue($sqlExecMock)); - $cache = $this->getMock('Doctrine\Common\Cache\AbstractCache', array('_doFetch', '_doContains', '_doSave', '_doDelete', 'getIds')); + $cache = $this->getMock('Doctrine\Common\Cache\CacheProvider', + array('doFetch', 'doContains', 'doSave', 'doDelete', 'doFlush')); $cache->expects($this->once()) - ->method('_doFetch') + ->method('doFetch') ->with($this->isType('string')) ->will($this->returnValue($parserResultMock)); $cache->expects($this->never()) - ->method('_doSave'); + ->method('doSave'); $query->setQueryCacheDriver($cache); diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php index 42971e6b0..e37ea9f62 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php @@ -274,10 +274,15 @@ class QueryDqlFunctionTest extends \Doctrine\Tests\OrmFunctionalTestCase */ public function testDateDiff() { - $arg = $this->_em->createQuery("SELECT DATE_DIFF(CURRENT_TIMESTAMP(), '2011-01-01') AS diff FROM Doctrine\Tests\Models\Company\CompanyManager m") - ->getARrayResult(); - - $this->assertTrue($arg[0]['diff'] > 0); + $query = $this->_em->createQuery("SELECT DATE_DIFF(CURRENT_TIMESTAMP(), DATE_ADD(CURRENT_TIMESTAMP(), 10, 'day')) AS diff FROM Doctrine\Tests\Models\Company\CompanyManager m"); + $arg = $query->getArrayResult(); + + $this->assertEquals(-10, $arg[0]['diff'], "Should be roughly -10 (or -9)", 1); + + $query = $this->_em->createQuery("SELECT DATE_DIFF(DATE_ADD(CURRENT_TIMESTAMP(), 10, 'day'), CURRENT_TIMESTAMP()) AS diff FROM Doctrine\Tests\Models\Company\CompanyManager m"); + $arg = $query->getArrayResult(); + + $this->assertEquals(10, $arg[0]['diff'], "Should be roughly 10 (or 9)", 1); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php index d8937289a..596d929f6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php @@ -38,7 +38,7 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase $result = $query->getResult(); $this->assertEquals(1, count($result)); - $this->assertTrue($result[0][0] instanceof CmsUser); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0][0]); $this->assertEquals('Guilherme', $result[0][0]->name); $this->assertEquals('gblanco', $result[0][0]->username); $this->assertEquals('developer', $result[0][0]->status); @@ -90,7 +90,7 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase $query = $this->_em->createQuery("select u, a from Doctrine\Tests\Models\CMS\CmsUser u join u.articles a"); $users = $query->getResult(); $this->assertEquals(1, count($users)); - $this->assertTrue($users[0] instanceof CmsUser); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[0]); $this->assertEquals(2, count($users[0]->articles)); $this->assertEquals('Doctrine 2', $users[0]->articles[0]->topic); $this->assertEquals('Symfony 2', $users[0]->articles[1]->topic); @@ -361,9 +361,9 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase $result = $q->getResult(); $this->assertEquals(1, count($result)); - $this->assertTrue($result[0] instanceof CmsArticle); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[0]); $this->assertEquals("dr. dolittle", $result[0]->topic); - $this->assertTrue($result[0]->user instanceof \Doctrine\ORM\Proxy\Proxy); + $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $result[0]->user); $this->assertFalse($result[0]->user->__isInitialized__); } @@ -501,4 +501,66 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(0, count($users)); } + + public function testQueryWithArrayOfEntitiesAsParameter() + { + $userA = new CmsUser; + $userA->name = 'Benjamin'; + $userA->username = 'beberlei'; + $userA->status = 'developer'; + $this->_em->persist($userA); + + $userB = new CmsUser; + $userB->name = 'Roman'; + $userB->username = 'romanb'; + $userB->status = 'developer'; + $this->_em->persist($userB); + + $userC = new CmsUser; + $userC->name = 'Jonathan'; + $userC->username = 'jwage'; + $userC->status = 'developer'; + $this->_em->persist($userC); + + $this->_em->flush(); + $this->_em->clear(); + + $query = $this->_em->createQuery("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u IN (?0) OR u.username = ?1"); + $query->setParameter(0, array($userA, $userC)); + $query->setParameter(1, 'beberlei'); + + $users = $query->execute(); + + $this->assertEquals(2, count($users)); + } + + public function testQueryWithHiddenAsSelectExpression() + { + $userA = new CmsUser; + $userA->name = 'Benjamin'; + $userA->username = 'beberlei'; + $userA->status = 'developer'; + $this->_em->persist($userA); + + $userB = new CmsUser; + $userB->name = 'Roman'; + $userB->username = 'romanb'; + $userB->status = 'developer'; + $this->_em->persist($userB); + + $userC = new CmsUser; + $userC->name = 'Jonathan'; + $userC->username = 'jwage'; + $userC->status = 'developer'; + $this->_em->persist($userC); + + $this->_em->flush(); + $this->_em->clear(); + + $query = $this->_em->createQuery("SELECT u, (SELECT COUNT(u2.id) FROM Doctrine\Tests\Models\CMS\CmsUser u2) AS HIDDEN total FROM Doctrine\Tests\Models\CMS\CmsUser u"); + $users = $query->execute(); + + $this->assertEquals(3, count($users)); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[0]); + } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php b/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php index 3e66e0b12..8ecb389af 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php @@ -97,4 +97,54 @@ class ReferenceProxyTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertTrue($clone->isCloned); $this->assertFalse($entity->isCloned); } + + /** + * @group DDC-733 + */ + public function testInitializeProxy() + { + $id = $this->createProduct(); + + /* @var $entity Doctrine\Tests\Models\ECommerce\ECommerceProduct */ + $entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id); + + $this->assertFalse($entity->__isInitialized__, "Pre-Condition: Object is unitialized proxy."); + $this->_em->getUnitOfWork()->initializeObject($entity); + $this->assertTrue($entity->__isInitialized__, "Should be initialized after called UnitOfWork::initializeObject()"); + } + + /** + * @group DDC-1163 + */ + public function testInitializeChangeAndFlushProxy() + { + $id = $this->createProduct(); + + /* @var $entity Doctrine\Tests\Models\ECommerce\ECommerceProduct */ + $entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id); + $entity->setName('Doctrine 2 Cookbook'); + + $this->_em->flush(); + $this->_em->clear(); + + $entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id); + $this->assertEquals('Doctrine 2 Cookbook', $entity->getName()); + } + + /** + * @group DDC-1022 + */ + public function testWakeupCalledOnProxy() + { + $id = $this->createProduct(); + + /* @var $entity Doctrine\Tests\Models\ECommerce\ECommerceProduct */ + $entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id); + + $this->assertFalse($entity->wakeUp); + + $entity->setName('Doctrine 2 Cookbook'); + + $this->assertTrue($entity->wakeUp, "Loading the proxy should call __wakeup()."); + } } diff --git a/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php index b1b39a7be..235b4c91c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php @@ -15,10 +15,26 @@ require_once __DIR__ . '/../../TestInit.php'; */ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase { + /** + * @var \ReflectionProperty + */ + private $cacheDataReflection; + protected function setUp() { + $this->cacheDataReflection = new \ReflectionProperty("Doctrine\Common\Cache\ArrayCache", "data"); + $this->cacheDataReflection->setAccessible(true); $this->useModelSet('cms'); parent::setUp(); } + + /** + * @param ArrayCache $cache + * @return integer + */ + private function getCacheSize(ArrayCache $cache) + { + return sizeof($this->cacheDataReflection->getValue($cache)); + } public function testResultCache() { @@ -125,9 +141,9 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase $cache = new ArrayCache(); $query->setResultCacheDriver($cache)->useResultCache(true); - $this->assertEquals(0, count($cache->getIds())); + $this->assertEquals(0, $this->getCacheSize($cache)); $query->getResult(); - $this->assertEquals(1, count($cache->getIds())); + $this->assertEquals(1, $this->getCacheSize($cache)); return $query; } @@ -139,12 +155,12 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testResultCacheDependsOnQueryHints($query) { $cache = $query->getResultCacheDriver(); - $cacheCount = count($cache->getIds()); + $cacheCount = $this->getCacheSize($cache); $query->setHint('foo', 'bar'); $query->getResult(); - $this->assertEquals($cacheCount + 1, count($cache->getIds())); + $this->assertEquals($cacheCount + 1, $this->getCacheSize($cache)); } /** @@ -154,12 +170,12 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testResultCacheDependsOnParameters($query) { $cache = $query->getResultCacheDriver(); - $cacheCount = count($cache->getIds()); + $cacheCount = $this->getCacheSize($cache); $query->setParameter(1, 50); $query->getResult(); - $this->assertEquals($cacheCount + 1, count($cache->getIds())); + $this->assertEquals($cacheCount + 1, $this->getCacheSize($cache)); } /** @@ -169,12 +185,12 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testResultCacheDependsOnHydrationMode($query) { $cache = $query->getResultCacheDriver(); - $cacheCount = count($cache->getIds()); + $cacheCount = $this->getCacheSize($cache); $this->assertNotEquals(\Doctrine\ORM\Query::HYDRATE_ARRAY, $query->getHydrationMode()); $query->getArrayResult(); - $this->assertEquals($cacheCount + 1, count($cache->getIds())); + $this->assertEquals($cacheCount + 1, $this->getCacheSize($cache)); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/AllTests.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/AllTests.php deleted file mode 100644 index d9479b98a..000000000 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/AllTests.php +++ /dev/null @@ -1,33 +0,0 @@ -addTestSuite('Doctrine\Tests\ORM\Functional\SchemaTool\CompanySchemaTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\SchemaTool\MySqlSchemaToolTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\SchemaTool\PostgreSqlSchemaToolTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Functional\SchemaTool\DDC214Test'); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Orm_Functional_Tools_AllTests::main') { - AllTests::main(); -} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php index e4e5e69a0..fb58bf07f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php @@ -68,8 +68,11 @@ class DDC214Test extends \Doctrine\Tests\OrmFunctionalTestCase $classMetadata[] = $this->_em->getClassMetadata($class); } - $this->schemaTool->dropDatabase(); - $this->schemaTool->createSchema($classMetadata); + try { + $this->schemaTool->createSchema($classMetadata); + } catch(\Exception $e) { + // was already created + } $sm = $this->_em->getConnection()->getSchemaManager(); @@ -80,6 +83,8 @@ class DDC214Test extends \Doctrine\Tests\OrmFunctionalTestCase $schemaDiff = $comparator->compare($fromSchema, $toSchema); $sql = $schemaDiff->toSql($this->_em->getConnection()->getDatabasePlatform()); + $sql = array_filter($sql, function($sql) { return strpos($sql, 'DROP') === false; }); + $this->assertEquals(0, count($sql), "SQL: " . implode(PHP_EOL, $sql)); } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php index 681485251..b93753ce0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/PostgreSqlSchemaToolTest.php @@ -80,4 +80,25 @@ class PostgreSqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals("CREATE TABLE boolean_model (id INT NOT NULL, booleanField BOOLEAN NOT NULL, PRIMARY KEY(id))", $sql[0]); $this->assertEquals("CREATE SEQUENCE boolean_model_id_seq INCREMENT BY 1 MINVALUE 1 START 1", $sql[1]); } + + public function testGetDropSchemaSql() + { + $classes = array( + $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'), + $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), + $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), + ); + + $tool = new SchemaTool($this->_em); + $sql = $tool->getDropSchemaSQL($classes); + + $this->assertEquals(13, count($sql)); + $dropSequenceSQLs = 0; + foreach ($sql AS $stmt) { + if (strpos($stmt, "DROP SEQUENCE") === 0) { + $dropSequenceSQLs++; + } + } + $this->assertEquals(4, $dropSequenceSQLs, "Expect 4 sequences to be dropped."); + } } diff --git a/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php b/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php index 8b37a02ba..e8132de5c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php @@ -64,7 +64,7 @@ class StandardEntityPersisterTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->flush(); $this->assertEquals(2, count($p->getFeatures())); - $this->assertTrue($p->getFeatures() instanceof \Doctrine\ORM\PersistentCollection); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $p->getFeatures()); $q = $this->_em->createQuery( 'SELECT p, f @@ -75,7 +75,7 @@ class StandardEntityPersisterTest extends \Doctrine\Tests\OrmFunctionalTestCase $res = $q->getResult(); $this->assertEquals(2, count($p->getFeatures())); - $this->assertTrue($p->getFeatures() instanceof \Doctrine\ORM\PersistentCollection); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $p->getFeatures()); // Check that the features are the same instances still foreach ($p->getFeatures() as $feature) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/AllTests.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/AllTests.php deleted file mode 100644 index 5820a273f..000000000 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/AllTests.php +++ /dev/null @@ -1,34 +0,0 @@ -addTestSuite('Doctrine\Tests\ORM\Functional\Ticket\\' . $info['filename']); - } - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Orm_Functional_Ticket_AllTests::main') { - AllTests::main(); -} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1113Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1113Test.php new file mode 100644 index 000000000..3e8a2fc0a --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1113Test.php @@ -0,0 +1,99 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1113Engine'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1113Vehicle'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1113Car'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1113Bus'), + )); + } catch (\Exception $e) { + + } + } + + public function testIssue() + { + $car = new DDC1113Car(); + $car->engine = new DDC1113Engine(); + + $bus = new DDC1113Bus(); + $bus->engine = new DDC1113Engine(); + + $this->_em->persist($car); + $this->_em->flush(); + + $this->_em->persist($bus); + $this->_em->flush(); + + $this->_em->remove($bus); + $this->_em->remove($car); + $this->_em->flush(); + } + +} + +/** + * @Entity + * @InheritanceType("SINGLE_TABLE") + * @DiscriminatorMap({"car" = "DDC1113Car", "bus" = "DDC1113Bus"}) + */ +class DDC1113Vehicle +{ + + /** @Id @GeneratedValue @Column(type="integer") */ + public $id; + + /** + * @ManyToOne(targetEntity="DDC1113Vehicle") + */ + public $parent; + + /** @OneToOne(targetEntity="DDC1113Engine", cascade={"persist", "remove"}) */ + public $engine; + +} + +/** + * @Entity + */ +class DDC1113Car extends DDC1113Vehicle +{ + +} + +/** + * @Entity + */ +class DDC1113Bus extends DDC1113Vehicle +{ + +} + +/** + * @Entity + */ +class DDC1113Engine +{ + + /** @Id @GeneratedValue @Column(type="integer") */ + public $id; + +} + diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php new file mode 100644 index 000000000..7142ff211 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php @@ -0,0 +1,215 @@ +_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); + $this->_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1163Product'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1163SpecialProduct'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1163ProxyHolder'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1163Tag'), + )); + } + + public function testIssue() + { + $this->createSpecialProductAndProxyHolderReferencingIt(); + $this->_em->clear(); + + $this->createProxyForSpecialProduct(); + + $this->setPropertyAndAssignTagToSpecialProduct(); + + // fails + $this->_em->flush(); + } + + private function createSpecialProductAndProxyHolderReferencingIt() + { + $specialProduct = new DDC1163SpecialProduct(); + $this->_em->persist($specialProduct); + + $proxyHolder = new DDC1163ProxyHolder(); + $this->_em->persist($proxyHolder); + + $proxyHolder->setSpecialProduct($specialProduct); + + $this->_em->flush(); + + $this->productId = $specialProduct->getId(); + $this->proxyHolderId = $proxyHolder->getId(); + } + + /** + * We want Doctrine to instantiate a lazy-load proxy for the previously created + * 'SpecialProduct' and register it. + * + * When Doctrine loads the 'ProxyHolder', it will do just that because the 'ProxyHolder' + * references the 'SpecialProduct'. + */ + private function createProxyForSpecialProduct() + { + /* @var $proxyHolder ProxyHolder */ + $proxyHolder = $this->_em->find(__NAMESPACE__ . '\\DDC1163ProxyHolder', $this->proxyHolderId); + + $this->assertInstanceOf(__NAMESPACE__.'\\DDC1163SpecialProduct', $proxyHolder->getSpecialProduct()); + } + + private function setPropertyAndAssignTagToSpecialProduct() + { + /* @var $specialProduct SpecialProduct */ + $specialProduct = $this->_em->find(__NAMESPACE__ . '\\DDC1163SpecialProduct', $this->productId); + + $this->assertInstanceOf(__NAMESPACE__.'\\DDC1163SpecialProduct', $specialProduct); + $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $specialProduct); + + $specialProduct->setSubclassProperty('foobar'); + + // this screams violation of law of demeter ;) + $this->assertEquals( + __NAMESPACE__.'\\DDC1163SpecialProduct', + $this->_em->getUnitOfWork()->getEntityPersister(get_class($specialProduct))->getClassMetadata()->name + ); + + $tag = new DDC1163Tag('Foo'); + $this->_em->persist($tag); + $tag->setProduct($specialProduct); + } +} + +/** + * @Entity + */ +class DDC1163ProxyHolder +{ + + /** + * @var int + * @Column(name="id", type="integer") + * @Id + * @GeneratedValue(strategy="AUTO") + */ + private $id; + /** + * @var SpecialProduct + * @OneToOne(targetEntity="DDC1163SpecialProduct") + */ + private $specialProduct; + + public function getId() + { + return $this->id; + } + + public function setSpecialProduct(DDC1163SpecialProduct $specialProduct) + { + $this->specialProduct = $specialProduct; + } + + public function getSpecialProduct() + { + return $this->specialProduct; + } + +} + +/** + * @Entity + * @InheritanceType("JOINED") + * @DiscriminatorColumn(name="type", type="string") + * @DiscriminatorMap({"special" = "DDC1163SpecialProduct"}) + */ +abstract class DDC1163Product +{ + + /** + * @var int + * @Column(name="id", type="integer") + * @Id + * @GeneratedValue(strategy="AUTO") + */ + protected $id; + + public function getId() + { + return $this->id; + } + +} + +/** + * @Entity + */ +class DDC1163SpecialProduct extends DDC1163Product +{ + + /** + * @var string + * @Column(name="subclass_property", type="string", nullable=true) + */ + private $subclassProperty; + + /** + * @param string $value + */ + public function setSubclassProperty($value) + { + $this->subclassProperty = $value; + } + +} + +/** + * @Entity + */ +class DDC1163Tag +{ + + /** + * @var int + * @Column(name="id", type="integer") + * @Id + * @GeneratedValue(strategy="AUTO") + */ + private $id; + /** + * @var string + * @Column(name="name", type="string") + */ + private $name; + /** + * @var Product + * @ManyToOne(targetEntity="DDC1163Product", inversedBy="tags") + * @JoinColumns({ + * @JoinColumn(name="product_id", referencedColumnName="id") + * }) + */ + private $product; + + /** + * @param string $name + */ + public function __construct($name) + { + $this->name = $name; + } + + /** + * @param Product $product + */ + public function setProduct(DDC1163Product $product) + { + $this->product = $product; + } + +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php new file mode 100644 index 000000000..225353034 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php @@ -0,0 +1,101 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1181Hotel'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1181Booking'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1181Room'), + )); + } + + /** + * @group DDC-1181 + */ + public function testIssue() + { + $hotel = new DDC1181Hotel(); + $room1 = new DDC1181Room(); + $room2 = new DDC1181Room(); + + $this->_em->persist($hotel); + $this->_em->persist($room1); + $this->_em->persist($room2); + $this->_em->flush(); + + $booking1 = new DDC1181Booking; + $booking1->hotel = $hotel; + $booking1->room = $room1; + $booking2 = new DDC1181Booking; + $booking2->hotel = $hotel; + $booking2->room = $room2; + $hotel->bookings[] = $booking1; + $hotel->bookings[] = $booking2; + + $this->_em->persist($booking1); + $this->_em->persist($booking2); + $this->_em->flush(); + + $this->_em->remove($hotel); + $this->_em->flush(); + } +} + +/** + * @Entity + */ +class DDC1181Hotel +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; + + /** + * @oneToMany(targetEntity="DDC1181Booking", mappedBy="hotel", cascade={"remove"}) + * @var Booking[] + */ + public $bookings; + +} + +/** + * @Entity + */ +class DDC1181Booking +{ + /** + * @var Hotel + * + * @Id + * @ManyToOne(targetEntity="DDC1181Hotel", inversedBy="bookings") + * @JoinColumns({ + * @JoinColumn(name="hotel_id", referencedColumnName="id") + * }) + */ + public $hotel; + /** + * @var Room + * + * @Id + * @ManyToOne(targetEntity="DDC1181Room") + * @JoinColumns({ + * @JoinColumn(name="room_id", referencedColumnName="id") + * }) + */ + public $room; +} + +/** + * @Entity + */ +class DDC1181Room +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php new file mode 100644 index 000000000..3ddf37e70 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php @@ -0,0 +1,93 @@ +_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); + $this->_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1193Company'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1193Person'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1193Account') + )); + } + + /** + * @group DDC-1193 + */ + public function testIssue() + { + $company = new DDC1193Company(); + $person = new DDC1193Person(); + $account = new DDC1193Account(); + + $person->account = $account; + $person->company = $company; + + $company->member = $person; + + $this->_em->persist($company); + + $this->_em->flush(); + + $companyId = $company->id; + $accountId = $account->id; + $this->_em->clear(); + + $company = $this->_em->find(get_class($company), $companyId); + + $this->assertTrue($this->_em->getUnitOfWork()->isInIdentityMap($company), "Company is in identity map."); + $this->assertFalse($company->member->__isInitialized__, "Pre-Condition"); + $this->assertTrue($this->_em->getUnitOfWork()->isInIdentityMap($company->member), "Member is in identity map."); + + $this->_em->remove($company); + $this->_em->flush(); + + $this->assertEquals(count($this->_em->getRepository(get_class($account))->findAll()), 0); + } +} + +/** @Entity */ +class DDC1193Company { + /** + * @Id @Column(type="integer") + * @GeneratedValue + */ + public $id; + + /** @OneToOne(targetEntity="DDC1193Person", cascade={"persist", "remove"}) */ + public $member; + +} + +/** @Entity */ +class DDC1193Person { + /** + * @Id @Column(type="integer") + * @GeneratedValue + */ + public $id; + + /** + * @OneToOne(targetEntity="DDC1193Account", cascade={"persist", "remove"}) + */ + public $account; +} + +/** @Entity */ +class DDC1193Account { + /** + * @Id @Column(type="integer") + * @GeneratedValue + */ + public $id; + +} + + diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php new file mode 100644 index 000000000..472978bc2 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php @@ -0,0 +1,125 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1209_1'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1209_2'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1209_3') + )); + } catch(\Exception $e) { + } + } + + /** + * @group DDC-1209 + */ + public function testIdentifierCanHaveCustomType() + { + $this->_em->persist(new DDC1209_3()); + $this->_em->flush(); + } + + /** + * @group DDC-1209 + */ + public function testCompositeIdentifierCanHaveCustomType() + { + $future1 = new DDC1209_1(); + $this->_em->persist($future1); + + $this->_em->flush(); + + $future2 = new DDC1209_2($future1); + $this->_em->persist($future2); + + $this->_em->flush(); + } +} + +/** + * @Entity + */ +class DDC1209_1 +{ + /** + * @Id @GeneratedValue @Column(type="integer") + */ + private $id; + + public function getId() + { + return $this->id; + } +} + +/** + * @Entity + */ +class DDC1209_2 +{ + /** + * @Id + * @ManyToOne(targetEntity="DDC1209_1") + * @JoinColumn(referencedColumnName="id", nullable=false) + */ + private $future1; + /** + * @Id + * @Column(type="datetime", nullable=false) + */ + private $starting_datetime; + /** + * @Id + * @Column(type="datetime", nullable=false) + */ + private $during_datetime; + /** + * @Id + * @Column(type="datetime", nullable=false) + */ + private $ending_datetime; + + public function __construct(DDC1209_1 $future1) + { + $this->future1 = $future1; + $this->starting_datetime = new DateTime2(); + $this->during_datetime = new DateTime2(); + $this->ending_datetime = new DateTime2(); + } +} + +/** + * @Entity + */ +class DDC1209_3 +{ + /** + * @Id + * @Column(type="datetime") + */ + private $date; + + public function __construct() + { + $this->date = new DateTime2(); + } +} + +class DateTime2 extends \DateTime +{ + public function __toString() + { + return $this->format('Y'); + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1225Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1225Test.php new file mode 100644 index 000000000..cec258f37 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1225Test.php @@ -0,0 +1,85 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1225_TestEntity1'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1225_TestEntity2'), + )); + } catch(\PDOException $e) { + + } + } + + public function testIssue() + { + $qb = $this->_em->createQueryBuilder(); + $qb->from('Doctrine\Tests\ORM\Functional\Ticket\DDC1225_TestEntity1', 'te1') + ->select('te1') + ->where('te1.testEntity2 = ?1') + ->setParameter(1, 0); + + $this->assertEquals( + 'SELECT t0_.test_entity2_id AS test_entity2_id0 FROM te1 t0_ WHERE t0_.test_entity2_id = ?', + $qb->getQuery()->getSQL() + ); + } +} + +/** + * @Entity + * @Table(name="te1") + */ +class DDC1225_TestEntity1 +{ + /** + * @Id + * @ManyToOne(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\DDC1225_TestEntity2") + * @JoinColumn(name="test_entity2_id", referencedColumnName="id", nullable=false) + */ + private $testEntity2; + + /** + * @param DDC1225_TestEntity2 $testEntity2 + */ + public function setTestEntity2(DDC1225_TestEntity2 $testEntity2) + { + $this->testEntity2 = $testEntity2; + } + + /** + * @return DDC1225_TestEntity2 + */ + public function getTestEntity2() + { + return $this->testEntity2; + } +} + +/** + * @Entity + * @Table(name="te2") + */ +class DDC1225_TestEntity2 +{ + /** + * @Id + * @GeneratedValue(strategy="AUTO") + * @Column(type="integer") + */ + private $id; +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1228Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1228Test.php new file mode 100644 index 000000000..34aef78cf --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1228Test.php @@ -0,0 +1,136 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1228User'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1228Profile'), + )); + } catch(\PDOException $e) { + + } + } + + public function testOneToOnePersist() + { + $user = new DDC1228User; + $profile = new DDC1228Profile(); + $profile->name = "Foo"; + $user->profile = $profile; + + $this->_em->persist($user); + $this->_em->persist($profile); + $this->_em->flush(); + $this->_em->clear(); + + $user = $this->_em->find(__NAMESPACE__ . '\\DDC1228User', $user->id); + + $this->assertFalse($user->getProfile()->__isInitialized__, "Proxy is not initialized"); + $user->getProfile()->setName("Bar"); + $this->assertTrue($user->getProfile()->__isInitialized__, "Proxy is not initialized"); + + $this->assertEquals("Bar", $user->getProfile()->getName()); + $this->assertEquals(array("id" => 1, "name" => "Foo"), $this->_em->getUnitOfWork()->getOriginalEntityData($user->getProfile())); + + $this->_em->flush(); + $this->_em->clear(); + + $user = $this->_em->find(__NAMESPACE__ . '\\DDC1228User', $user->id); + $this->assertEquals("Bar", $user->getProfile()->getName()); + } + + public function testRefresh() + { + $user = new DDC1228User; + $profile = new DDC1228Profile(); + $profile->name = "Foo"; + $user->profile = $profile; + + $this->_em->persist($user); + $this->_em->persist($profile); + $this->_em->flush(); + $this->_em->clear(); + + $user = $this->_em->getReference(__NAMESPACE__ . '\\DDC1228User', $user->id); + + $this->_em->refresh($user); + $user->name = "Baz"; + $this->_em->flush(); + $this->_em->clear(); + + $user = $this->_em->find(__NAMESPACE__ . '\\DDC1228User', $user->id); + $this->assertEquals("Baz", $user->name); + } +} + +/** + * @Entity + */ +class DDC1228User +{ + /** + * @Id @Column(type="integer") @GeneratedValue + * @var int + */ + public $id; + + /** + * @column(type="string") + * @var string + */ + public $name = ''; + + /** + * @OneToOne(targetEntity="DDC1228Profile") + * @var Profile + */ + public $profile; + + public function getProfile() + { + return $this->profile; + } +} + +/** + * @Entity + */ +class DDC1228Profile +{ + /** + * @Id @Column(type="integer") @GeneratedValue + * @var int + */ + public $id; + + /** + * @column(type="string") + * @var string + */ + public $name; + + public function getName() + { + return $this->name; + } + + public function setName($name) + { + $this->name = $name; + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1238Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1238Test.php new file mode 100644 index 000000000..93a89818e --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1238Test.php @@ -0,0 +1,96 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1238User'), + )); + } catch(\PDOException $e) { + + } + } + + public function testIssue() + { + $user = new DDC1238User; + $user->setName("test"); + + $this->_em->persist($user); + $this->_em->flush(); + $this->_em->clear(); + + $userId = $user->getId(); + $this->_em->clear(); + + $user = $this->_em->getReference(__NAMESPACE__ . '\\DDC1238User', $userId); + $this->_em->clear(); + + $userId2 = $user->getId(); + $this->assertEquals($userId, $userId2, "This proxy can still be initialized."); + } + + public function testIssueProxyClear() + { + $user = new DDC1238User; + $user->setName("test"); + + $this->_em->persist($user); + $this->_em->flush(); + $this->_em->clear(); + + $userId = $user->getId(); + $this->_em->clear(); + + $user = $this->_em->getReference(__NAMESPACE__ . '\\DDC1238User', $userId); + $this->_em->clear(); + + $user2 = $this->_em->getReference(__NAMESPACE__ . '\\DDC1238User', $userId); + + $this->assertNull($user->getId(), "Now this is null, we already have a user instance of that type"); + } +} + +/** + * @Entity + */ +class DDC1238User +{ + /** @Id @GeneratedValue @Column(type="integer") */ + private $id; + + /** + * @Column + * @var string + */ + private $name; + + public function getId() + { + return $this->id; + } + + public function getName() + { + return $this->name; + } + + public function setName($name) + { + $this->name = $name; + } +} + diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1250Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1250Test.php new file mode 100644 index 000000000..3a756da9a --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1250Test.php @@ -0,0 +1,96 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1250ClientHistory'), + )); + } catch(\PDOException $e) { + + } + } + + public function testIssue() + { + $c1 = new DDC1250ClientHistory; + $c2 = new DDC1250ClientHistory; + $c1->declinedClientsHistory = $c2; + $c1->declinedBy = $c2; + $c2->declinedBy = $c1; + $c2->declinedClientsHistory= $c1; + + $this->_em->persist($c1); + $this->_em->persist($c2); + $this->_em->flush(); + $this->_em->clear(); + + $history = $this->_em->createQuery('SELECT h FROM ' . __NAMESPACE__ . '\\DDC1250ClientHistory h WHERE h.id = ?1') + ->setParameter(1, $c2->id)->getSingleResult(); + + $this->assertInstanceOf(__NAMESPACE__ . '\\DDC1250ClientHistory', $history); + } +} + +/** + * @Entity + */ +class DDC1250ClientHistory +{ + /** @Id @GeneratedValue @Column(type="integer") */ + public $id; + + /** @OneToOne(targetEntity="DDC1250ClientHistory", inversedBy="declinedBy") + * @JoinColumn(name="declined_clients_history_id", referencedColumnName="id") + */ + public $declinedClientsHistory; + + /** + * @OneToOne(targetEntity="DDC1250ClientHistory", mappedBy="declinedClientsHistory") + * @var + */ + public $declinedBy; +} + +/** + * +Entities\ClientsHistory: +type: entity +table: clients_history +fields: +id: +id: true +type: integer +unsigned: false +nullable: false +generator: +strategy: IDENTITY +[...skiped...] +oneToOne: +declinedClientsHistory: +targetEntity: Entities\ClientsHistory +joinColumn: +name: declined_clients_history_id +referencedColumnName: id +inversedBy: declinedBy +declinedBy: +targetEntity: Entities\ClientsHistory +mappedBy: declinedClientsHistory +lifecycleCallbacks: { } +repositoryClass: Entities\ClientsHistoryRepository + + + */ \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1276Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1276Test.php new file mode 100644 index 000000000..1b9dc8c99 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1276Test.php @@ -0,0 +1,50 @@ +useModelSet('cms'); + parent::setUp(); + } + + public function testIssue() + { + $user = new CmsUser(); + $user->name = "Benjamin"; + $user->username = "beberlei"; + $user->status = "active"; + $this->_em->persist($user); + + for ($i = 0; $i < 2; $i++) { + $group = new CmsGroup(); + $group->name = "group".$i; + $user->groups[] = $group; + $this->_em->persist($group); + } + $this->_em->flush(); + $this->_em->clear(); + + $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $user->id); + $cloned = clone $user; + + $this->assertSame($user->groups, $cloned->groups); + $this->assertEquals(2, count($user->groups)); + $this->_em->merge($cloned); + + $this->assertEquals(2, count($user->groups)); + + $this->_em->flush(); + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1300Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1300Test.php new file mode 100644 index 000000000..38278dc1c --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1300Test.php @@ -0,0 +1,108 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1300Foo'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1300FooLocale'), + )); + } + + public function testIssue() + { + $foo = new DDC1300Foo(); + $foo->_fooReference = "foo"; + + $this->_em->persist($foo); + $this->_em->flush(); + + $locale = new DDC1300FooLocale(); + $locale->_foo = $foo; + $locale->_locale = "en"; + $locale->_title = "blub"; + + $this->_em->persist($locale); + $this->_em->flush(); + + $query = $this->_em->createQuery('SELECT f, fl FROM Doctrine\Tests\ORM\Functional\Ticket\DDC1300Foo f JOIN f._fooLocaleRefFoo fl'); + $result = $query->getResult(); + + $this->assertEquals(1, count($result)); + } +} + +/** + * @Entity + */ +class DDC1300Foo +{ + /** + * @var integer fooID + * @Column(name="fooID", type="integer", nullable=false) + * @GeneratedValue(strategy="AUTO") + * @Id + */ + public $_fooID = null; + + /** + * @var string fooReference + * @Column(name="fooReference", type="string", nullable=true, length=45) + */ + public $_fooReference = null; + + /** + * @OneToMany(targetEntity="DDC1300FooLocale", mappedBy="_foo", + * cascade={"persist"}) + */ + public $_fooLocaleRefFoo = null; + + /** + * Constructor + * + * @param array|Zend_Config|null $options + * @return Bug_Model_Foo + */ + public function __construct($options = null) + { + $this->_fooLocaleRefFoo = new \Doctrine\Common\Collections\ArrayCollection(); + } + +} + +/** + * @Entity + */ +class DDC1300FooLocale +{ + + /** + * @ManyToOne(targetEntity="DDC1300Foo") + * @JoinColumn(name="fooID", referencedColumnName="fooID") + * @Id + */ + public $_foo = null; + + /** + * @var string locale + * @Column(name="locale", type="string", nullable=false, length=5) + * @Id + */ + public $_locale = null; + + /** + * @var string title + * @Column(name="title", type="string", nullable=true, length=150) + */ + public $_title = null; + +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1301Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1301Test.php new file mode 100644 index 000000000..94d02f905 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1301Test.php @@ -0,0 +1,148 @@ +useModelSet('legacy'); + parent::setUp(); + + $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\Legacy\LegacyUser'); + $class->associationMappings['_articles']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY; + $class->associationMappings['_references']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY; + $class->associationMappings['_cars']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY; + + $this->loadFixture(); + } + + public function tearDown() + { + parent::tearDown(); + + $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\Legacy\LegacyUser'); + $class->associationMappings['_articles']['fetch'] = ClassMetadataInfo::FETCH_LAZY; + $class->associationMappings['_references']['fetch'] = ClassMetadataInfo::FETCH_LAZY; + $class->associationMappings['_cars']['fetch'] = ClassMetadataInfo::FETCH_LAZY; + } + + public function testCountNotInitializesLegacyCollection() + { + $user = $this->_em->find('Doctrine\Tests\Models\Legacy\LegacyUser', $this->userId); + $queryCount = $this->getCurrentQueryCount(); + + $this->assertFalse($user->_articles->isInitialized()); + $this->assertEquals(2, count($user->_articles)); + $this->assertFalse($user->_articles->isInitialized()); + + foreach ($user->_articles AS $article) { } + + $this->assertEquals($queryCount + 2, $this->getCurrentQueryCount(), "Expecting two queries to be fired for count, then iteration."); + } + + public function testCountNotInitializesLegacyCollectionWithForeignIdentifier() + { + $user = $this->_em->find('Doctrine\Tests\Models\Legacy\LegacyUser', $this->userId); + $queryCount = $this->getCurrentQueryCount(); + + $this->assertFalse($user->_references->isInitialized()); + $this->assertEquals(2, count($user->_references)); + $this->assertFalse($user->_references->isInitialized()); + + foreach ($user->_references AS $reference) { } + + $this->assertEquals($queryCount + 2, $this->getCurrentQueryCount(), "Expecting two queries to be fired for count, then iteration."); + } + + public function testCountNotInitializesLegacyManyToManyCollection() + { + $user = $this->_em->find('Doctrine\Tests\Models\Legacy\LegacyUser', $this->userId); + $queryCount = $this->getCurrentQueryCount(); + + $this->assertFalse($user->_cars->isInitialized()); + $this->assertEquals(3, count($user->_cars)); + $this->assertFalse($user->_cars->isInitialized()); + + foreach ($user->_cars AS $reference) { } + + $this->assertEquals($queryCount + 2, $this->getCurrentQueryCount(), "Expecting two queries to be fired for count, then iteration."); + } + + public function loadFixture() + { + $user1 = new \Doctrine\Tests\Models\Legacy\LegacyUser(); + $user1->_username = "beberlei"; + $user1->_name = "Benjamin"; + $user1->_status = "active"; + + $user2 = new \Doctrine\Tests\Models\Legacy\LegacyUser(); + $user2->_username = "jwage"; + $user2->_name = "Jonathan"; + $user2->_status = "active"; + + $user3 = new \Doctrine\Tests\Models\Legacy\LegacyUser(); + $user3->_username = "romanb"; + $user3->_name = "Roman"; + $user3->_status = "active"; + + $this->_em->persist($user1); + $this->_em->persist($user2); + $this->_em->persist($user3); + + $article1 = new \Doctrine\Tests\Models\Legacy\LegacyArticle(); + $article1->_topic = "Test"; + $article1->_text = "Test"; + $article1->setAuthor($user1); + + $article2 = new \Doctrine\Tests\Models\Legacy\LegacyArticle(); + $article2->_topic = "Test"; + $article2->_text = "Test"; + $article2->setAuthor($user1); + + $this->_em->persist($article1); + $this->_em->persist($article2); + + $car1 = new \Doctrine\Tests\Models\Legacy\LegacyCar(); + $car1->_description = "Test1"; + + $car2 = new \Doctrine\Tests\Models\Legacy\LegacyCar(); + $car2->_description = "Test2"; + + $car3 = new \Doctrine\Tests\Models\Legacy\LegacyCar(); + $car3->_description = "Test3"; + + $user1->addCar($car1); + $user1->addCar($car2); + $user1->addCar($car3); + + $user2->addCar($car1); + $user3->addCar($car1); + + $this->_em->persist($car1); + $this->_em->persist($car2); + $this->_em->persist($car3); + + $this->_em->flush(); + + $detail1 = new \Doctrine\Tests\Models\Legacy\LegacyUserReference($user1, $user2, "foo"); + $detail2 = new \Doctrine\Tests\Models\Legacy\LegacyUserReference($user1, $user3, "bar"); + + $this->_em->persist($detail1); + $this->_em->persist($detail2); + + $this->_em->flush(); + $this->_em->clear(); + + $this->userId = $user1->getId(); + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1306Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1306Test.php new file mode 100644 index 000000000..b143b0030 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1306Test.php @@ -0,0 +1,54 @@ +useModelSet('cms'); + parent::setUp(); + } + + public function testIssue() + { + $phone = new CmsPhonenumber(); + $phone->phonenumber = "1234"; + + // puts user and phone into commit order calculator + $this->_em->persist($phone); + $this->_em->flush(); + + $address = new \Doctrine\Tests\Models\CMS\CmsAddress(); + $address->city = "bonn"; + $address->country = "Germany"; + $address->street = "somestreet!"; + $address->zip = 12345; + + $this->_em->persist($address); + + $user = new CmsUser(); + $user->username = "beberlei"; + $user->name = "benjamin"; + $user->status = "active"; + $user->setAddress($address); + + // puts user and address into commit order calculator, but does not calculate user dependencies new + $this->_em->persist($user); + $this->_em->flush(); + + $this->_em->remove($user->getAddress()); + $this->_em->remove($user); + $this->_em->flush(); + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1335Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1335Test.php new file mode 100644 index 000000000..e12ee9ab7 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1335Test.php @@ -0,0 +1,214 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1135User'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1135Phone'), + )); + $this->loadFixture(); + } catch(\Exception $e) { + } + } + + + public function testDql() + { + $dql = 'SELECT u FROM ' . __NAMESPACE__ . '\DDC1135User u INDEX BY u.id'; + $query = $this->_em->createQuery($dql); + $result = $query->getResult(); + + $this->assertEquals(sizeof($result), 3); + $this->assertArrayHasKey(1, $result); + $this->assertArrayHasKey(2, $result); + $this->assertArrayHasKey(3, $result); + + $dql = 'SELECT u, p FROM '.__NAMESPACE__ . '\DDC1135User u INDEX BY u.email INNER JOIN u.phones p INDEX BY p.id'; + $query = $this->_em->createQuery($dql); + $result = $query->getResult(); + + $this->assertEquals(sizeof($result), 3); + $this->assertArrayHasKey('foo@foo.com', $result); + $this->assertArrayHasKey('bar@bar.com', $result); + $this->assertArrayHasKey('foobar@foobar.com', $result); + + $this->assertEquals(sizeof($result['foo@foo.com']->phones), 3); + $this->assertEquals(sizeof($result['bar@bar.com']->phones), 3); + $this->assertEquals(sizeof($result['foobar@foobar.com']->phones), 3); + + $this->assertArrayHasKey(1, $result['foo@foo.com']->phones->toArray()); + $this->assertArrayHasKey(2, $result['foo@foo.com']->phones->toArray()); + $this->assertArrayHasKey(3, $result['foo@foo.com']->phones->toArray()); + + $this->assertArrayHasKey(4, $result['bar@bar.com']->phones->toArray()); + $this->assertArrayHasKey(5, $result['bar@bar.com']->phones->toArray()); + $this->assertArrayHasKey(6, $result['bar@bar.com']->phones->toArray()); + + $this->assertArrayHasKey(7, $result['foobar@foobar.com']->phones->toArray()); + $this->assertArrayHasKey(8, $result['foobar@foobar.com']->phones->toArray()); + $this->assertArrayHasKey(9, $result['foobar@foobar.com']->phones->toArray()); + } + + public function testTicket() + { + $builder = $this->_em->createQueryBuilder(); + $builder->select('u')->from(__NAMESPACE__ . '\DDC1135User', 'u', 'u.id'); + + $dql = $builder->getQuery()->getDQL(); + $result = $builder->getQuery()->getResult(); + + $this->assertEquals(sizeof($result), 3); + $this->assertArrayHasKey(1, $result); + $this->assertArrayHasKey(2, $result); + $this->assertArrayHasKey(3, $result); + $this->assertEquals('SELECT u FROM ' . __NAMESPACE__ . '\DDC1135User u INDEX BY u.id', $dql); + } + + public function testIndexByUnique() + { + $builder = $this->_em->createQueryBuilder(); + $builder->select('u')->from(__NAMESPACE__ . '\DDC1135User', 'u', 'u.email'); + + $dql = $builder->getQuery()->getDQL(); + $result = $builder->getQuery()->getResult(); + + $this->assertEquals(sizeof($result), 3); + $this->assertArrayHasKey('foo@foo.com', $result); + $this->assertArrayHasKey('bar@bar.com', $result); + $this->assertArrayHasKey('foobar@foobar.com', $result); + $this->assertEquals('SELECT u FROM ' . __NAMESPACE__ . '\DDC1135User u INDEX BY u.email', $dql); + } + + public function testIndexWithJoin() + { + $builder = $this->_em->createQueryBuilder(); + $builder->select('u','p') + ->from(__NAMESPACE__ . '\DDC1135User', 'u', 'u.email') + ->join('u.phones', 'p', null, null, 'p.id'); + + $dql = $builder->getQuery()->getDQL(); + $result = $builder->getQuery()->getResult(); + + $this->assertEquals(sizeof($result), 3); + $this->assertArrayHasKey('foo@foo.com', $result); + $this->assertArrayHasKey('bar@bar.com', $result); + $this->assertArrayHasKey('foobar@foobar.com', $result); + + $this->assertEquals(sizeof($result['foo@foo.com']->phones), 3); + $this->assertEquals(sizeof($result['bar@bar.com']->phones), 3); + $this->assertEquals(sizeof($result['foobar@foobar.com']->phones), 3); + + $this->assertArrayHasKey(1, $result['foo@foo.com']->phones->toArray()); + $this->assertArrayHasKey(2, $result['foo@foo.com']->phones->toArray()); + $this->assertArrayHasKey(3, $result['foo@foo.com']->phones->toArray()); + + $this->assertArrayHasKey(4, $result['bar@bar.com']->phones->toArray()); + $this->assertArrayHasKey(5, $result['bar@bar.com']->phones->toArray()); + $this->assertArrayHasKey(6, $result['bar@bar.com']->phones->toArray()); + + $this->assertArrayHasKey(7, $result['foobar@foobar.com']->phones->toArray()); + $this->assertArrayHasKey(8, $result['foobar@foobar.com']->phones->toArray()); + $this->assertArrayHasKey(9, $result['foobar@foobar.com']->phones->toArray()); + + $this->assertEquals('SELECT u, p FROM '.__NAMESPACE__ . '\DDC1135User u INDEX BY u.email INNER JOIN u.phones p INDEX BY p.id', $dql); + } + + private function loadFixture() + { + $p1 = array('11 xxxx-xxxx','11 yyyy-yyyy','11 zzzz-zzzz'); + $p2 = array('22 xxxx-xxxx','22 yyyy-yyyy','22 zzzz-zzzz'); + $p3 = array('33 xxxx-xxxx','33 yyyy-yyyy','33 zzzz-zzzz'); + + $u1 = new DDC1135User("foo@foo.com", "Foo",$p1); + $u2 = new DDC1135User("bar@bar.com", "Bar",$p2); + $u3 = new DDC1135User("foobar@foobar.com", "Foo Bar",$p3); + + $this->_em->persist($u1); + $this->_em->persist($u2); + $this->_em->persist($u3); + $this->_em->flush(); + $this->_em->clear(); + } + +} + +/** + * @Entity + */ +class DDC1135User +{ + /** + * @Id @Column(type="integer") + * @GeneratedValue + */ + public $id; + + /** + * @Column(type="string", unique=true) + */ + public $email; + + /** + * @Column(type="string") + */ + public $name; + + /** + * @OneToMany(targetEntity="DDC1135Phone", mappedBy="user", cascade={"persist", "remove"}) + */ + public $phones; + + public function __construct($email, $name, array $numbers = array()) + { + $this->name = $name; + $this->email = $email; + $this->phones = new \Doctrine\Common\Collections\ArrayCollection(); + + foreach ($numbers as $number) { + $this->phones->add(new DDC1135Phone($this,$number)); + } + } +} + +/** + * @Entity + */ +class DDC1135Phone +{ + /** + * @Id + * @Column(name="id", type="integer") + * @GeneratedValue(strategy="AUTO") + */ + public $id; + + /** + * @Column(name="number", type="string", nullable = false) + */ + public $number; + + /** + * @ManyToOne(targetEntity="DDC1135User", inversedBy="phones") + * @JoinColumn(name="user_id", referencedColumnName="id", nullable = false) + */ + public $user; + + public function __construct($user, $number) + { + $this->user = $user; + $this->number = $number; + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1392Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1392Test.php new file mode 100644 index 000000000..095b1976c --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1392Test.php @@ -0,0 +1,127 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1392File'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1392Picture'), + )); + } catch (\Exception $ignored) { + } + } + + public function testFailingCase() + { + $file = new DDC1392File; + + $picture = new DDC1392Picture; + $picture->setFile($file); + + $em = $this->_em; + $em->persist($picture); + $em->flush(); + $em->clear(); + + $fileId = $file->getFileId(); + $pictureId = $picture->getPictureId(); + + $this->assertTrue($fileId > 0); + + $picture = $em->find(__NAMESPACE__ . '\DDC1392Picture', $pictureId); + $this->assertEquals(UnitOfWork::STATE_MANAGED, $em->getUnitOfWork()->getEntityState($picture->getFile()), "Lazy Proxy should be marked MANAGED."); + + $file = $picture->getFile(); + + // With this activated there will be no problem + //$file->__load(); + + $picture->setFile(null); + + $em->clear(); + + $em->merge($file); + + $em->flush(); + + $q = $this->_em->createQuery("SELECT COUNT(e) FROM " . __NAMESPACE__ . '\DDC1392File e'); + $result = $q->getSingleScalarResult(); + + self::assertEquals(1, $result); + } +} + +/** + * @Entity + */ +class DDC1392Picture +{ + /** + * @Column(name="picture_id", type="integer") + * @Id @GeneratedValue + */ + private $pictureId; + + /** + * @ManyToOne(targetEntity="DDC1392File", cascade={"persist", "remove"}) + * @JoinColumn(name="file_id", referencedColumnName="file_id") + */ + private $file; + + /** + * Get pictureId + */ + public function getPictureId() + { + return $this->pictureId; + } + + /** + * Set file + */ + public function setFile($value = null) + { + $this->file = $value; + } + + /** + * Get file + */ + public function getFile() + { + return $this->file; + } +} + +/** + * @Entity + */ +class DDC1392File +{ + /** + * @Column(name="file_id", type="integer") + * @Id + * @GeneratedValue(strategy="AUTO") + */ + public $fileId; + + /** + * Get fileId + */ + public function getFileId() + { + return $this->fileId; + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC168Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC168Test.php index 41c41df45..004acfa8c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC168Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC168Test.php @@ -58,7 +58,7 @@ class DDC168Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals("bar", $theEmployee->getDepartment()); $this->assertEquals("Foo", $theEmployee->getName()); $this->assertEquals(1000, $theEmployee->getSalary()); - $this->assertTrue($theEmployee instanceof CompanyEmployee); - $this->assertTrue($theEmployee->getSpouse() instanceof CompanyEmployee); + $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $theEmployee); + $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $theEmployee->getSpouse()); } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php index e912c389f..8b5eddbf8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php @@ -40,11 +40,11 @@ class DDC199Test extends \Doctrine\Tests\OrmFunctionalTestCase $result = $query->getResult(); $this->assertEquals(1, count($result)); - $this->assertTrue($result[0] instanceof DDC199ChildClass); + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC199ParentClass', $result[0]); $this->assertTrue($result[0]->relatedEntities->isInitialized()); $this->assertEquals(2, $result[0]->relatedEntities->count()); - $this->assertTrue($result[0]->relatedEntities[0] instanceof DDC199RelatedClass); - $this->assertTrue($result[0]->relatedEntities[1] instanceof DDC199RelatedClass); + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC199RelatedClass', $result[0]->relatedEntities[0]); + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC199RelatedClass', $result[0]->relatedEntities[1]); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php index 6dc23c895..87939ff71 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php @@ -37,7 +37,7 @@ class DDC237Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->clear(); $x2 = $this->_em->find(get_class($x), $x->id); // proxy injected for Y - $this->assertTrue($x2->y instanceof \Doctrine\ORM\Proxy\Proxy); + $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $x2->y); $this->assertFalse($x2->y->__isInitialized__); // proxy for Y is in identity map @@ -45,7 +45,7 @@ class DDC237Test extends \Doctrine\Tests\OrmFunctionalTestCase $z2 = $this->_em->createQuery('select z,y from ' . get_class($z) . ' z join z.y y where z.id = ?1') ->setParameter(1, $z->id) ->getSingleResult(); - $this->assertTrue($z2->y instanceof \Doctrine\ORM\Proxy\Proxy); + $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $z2->y); $this->assertTrue($z2->y->__isInitialized__); $this->assertEquals('Y', $z2->y->data); $this->assertEquals($y->id, $z2->y->id); @@ -56,7 +56,7 @@ class DDC237Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertNotSame($x, $x2); $this->assertNotSame($z, $z2); $this->assertSame($z2->y, $x2->y); - $this->assertTrue($z2->y instanceof \Doctrine\ORM\Proxy\Proxy); + $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $z2->y); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC258Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC258Test.php index 29a35dada..d1bcc166e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC258Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC258Test.php @@ -44,7 +44,7 @@ class DDC258Test extends \Doctrine\Tests\OrmFunctionalTestCase $e2 = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC258Super', $c2->id); - $this->assertType('Doctrine\Tests\ORM\Functional\Ticket\DDC258Class2', $e2); + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC258Class2', $e2); $this->assertEquals('Bar', $e2->title); $this->assertEquals('Bar', $e2->description); $this->assertEquals('Bar', $e2->text); @@ -92,12 +92,12 @@ abstract class DDC258Super class DDC258Class1 extends DDC258Super { /** - * @Column(name="title", type="string", length="150") + * @Column(name="title", type="string", length=150) */ public $title; /** - * @Column(name="content", type="string", length="500") + * @Column(name="content", type="string", length=500) */ public $description; } @@ -108,12 +108,12 @@ class DDC258Class1 extends DDC258Super class DDC258Class2 extends DDC258Super { /** - * @Column(name="title", type="string", length="150") + * @Column(name="title", type="string", length=150) */ public $title; /** - * @Column(name="content", type="string", length="500") + * @Column(name="content", type="string", length=500) */ public $description; @@ -131,12 +131,12 @@ class DDC258Class2 extends DDC258Super class DDC258Class3 extends DDC258Super { /** - * @Column(name="title", type="string", length="150") + * @Column(name="title", type="string", length=150) */ public $apples; /** - * @Column(name="content", type="string", length="500") + * @Column(name="content", type="string", length=500) */ public $bananas; } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php index 63a084c87..fc2c3fc6d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php @@ -48,7 +48,7 @@ class DDC345Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(1, $membership->prePersistCallCount); $this->assertEquals(0, $membership->preUpdateCallCount); - $this->assertTrue($membership->updated instanceof \DateTime); + $this->assertInstanceOf('DateTime', $membership->updated); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php index 399e35c34..ad1584fa0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php @@ -41,7 +41,7 @@ class DDC371Test extends \Doctrine\Tests\OrmFunctionalTestCase ->getResult(); $this->assertEquals(1, count($children)); - $this->assertFalse($children[0]->parent instanceof \Doctrine\ORM\Proxy\Proxy); + $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $children[0]->parent); $this->assertFalse($children[0]->parent->children->isInitialized()); $this->assertEquals(0, $children[0]->parent->children->unwrap()->count()); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC422Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC422Test.php index bec65acae..ebe9f9d55 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC422Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC422Test.php @@ -28,7 +28,7 @@ class DDC422Test extends \Doctrine\Tests\OrmFunctionalTestCase $customer = $this->_em->find(get_class($customer), $customer->id); - $this->assertTrue($customer->contacts instanceof \Doctrine\ORM\PersistentCollection); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $customer->contacts); $this->assertFalse($customer->contacts->isInitialized()); $contact = new DDC422Contact; $customer->contacts->add($contact); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC440Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC440Test.php index a11c62407..46096fe5b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC440Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC440Test.php @@ -64,13 +64,13 @@ class DDC440Test extends \Doctrine\Tests\OrmFunctionalTestCase // Test the first phone. The assertion actually failed because original entity data is not set properly. // This was because it is also set as MainPhone and that one is created as a proxy, not the // original object when the find on Client is called. However loading proxies did not work correctly. - $this->assertType('Doctrine\Tests\ORM\Functional\Ticket\DDC440Phone', $p1); + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC440Phone', $p1); $originalData = $uw->getOriginalEntityData($p1); $this->assertEquals($phone->getNumber(), $originalData['number']); //If you comment out previous test, this one should pass - $this->assertType('Doctrine\Tests\ORM\Functional\Ticket\DDC440Phone', $p2); + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC440Phone', $p2); $originalData = $uw->getOriginalEntityData($p2); $this->assertEquals($phone2->getNumber(), $originalData['number']); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC448Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC448Test.php index 91c9e129e..f0867f352 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC448Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC448Test.php @@ -42,7 +42,7 @@ class DDC448MainTable /** * @ManyToOne(targetEntity="DDC448ConnectedClass", cascade={"all"}, fetch="EAGER") - * @JoinColumn(name="connectedClassId", referencedColumnName="id", onDelete="CASCADE", onUpdate="CASCADE", nullable=true) + * @JoinColumn(name="connectedClassId", referencedColumnName="id", onDelete="CASCADE", nullable=true) */ private $connectedClassId; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC501Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC501Test.php index 99da4c203..45c4340dc 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC501Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC501Test.php @@ -50,7 +50,7 @@ class DDC501Test extends OrmFunctionalTestCase // freeze and unfreeze $userClone = unserialize(serialize($userReloaded)); - $this->assertType('Doctrine\Tests\Models\CMS\CmsUser', $userClone); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $userClone); // detached user can't know about his phonenumbers $this->assertEquals(0, count($userClone->getPhonenumbers())); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC512Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC512Test.php index 72b11aaab..b9c74d399 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC512Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC512Test.php @@ -32,14 +32,14 @@ class DDC512Test extends \Doctrine\Tests\OrmFunctionalTestCase $result = $q->getResult(); $this->assertEquals(2, count($result)); - $this->assertTrue($result[0] instanceof DDC512Customer); - $this->assertTrue($result[1] instanceof DDC512Customer); + $this->assertInstanceOf(__NAMESPACE__ . '\DDC512Customer', $result[0]); + $this->assertInstanceOf(__NAMESPACE__ . '\DDC512Customer', $result[1]); if ($result[0]->id == $customer1->id) { - $this->assertTrue($result[0]->item instanceof DDC512OfferItem); + $this->assertInstanceOf(__NAMESPACE__ . '\DDC512OfferItem', $result[0]->item); $this->assertEquals($item->id, $result[0]->item->id); $this->assertNull($result[1]->item); } else { - $this->assertTrue($result[1]->item instanceof DDC512OfferItem); + $this->assertInstanceOf(__NAMESPACE__ . '\DDC512OfferItem', $result[1]->item); $this->assertNull($result[0]->item); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php index d0e8f4c7d..f251522ee 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php @@ -48,9 +48,9 @@ class DDC522Test extends \Doctrine\Tests\OrmFunctionalTestCase $r = $this->_em->createQuery("select ca,c from ".get_class($cart)." ca join ca.customer c") ->getResult(); - $this->assertTrue($r[0] instanceof DDC522Cart); - $this->assertTrue($r[0]->customer instanceof DDC522Customer); - $this->assertFalse($r[0]->customer instanceof \Doctrine\ORM\Proxy\Proxy); + $this->assertInstanceOf(__NAMESPACE__ . '\DDC522Cart', $r[0]); + $this->assertInstanceOf(__NAMESPACE__ . '\DDC522Customer', $r[0]->customer); + $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $r[0]->customer); $this->assertEquals('name', $r[0]->customer->name); $fkt = new DDC522ForeignKeyTest(); @@ -62,7 +62,7 @@ class DDC522Test extends \Doctrine\Tests\OrmFunctionalTestCase $fkt2 = $this->_em->find(get_class($fkt), $fkt->id); $this->assertEquals($fkt->cart->id, $fkt2->cartId); - $this->assertTrue($fkt2->cart instanceof \Doctrine\ORM\Proxy\Proxy); + $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $fkt2->cart); $this->assertFalse($fkt2->cart->__isInitialized__); } @@ -111,7 +111,7 @@ class DDC522Cart { class DDC522ForeignKeyTest { /** @Id @Column(type="integer") @GeneratedValue */ public $id; - /** @Column(type="integer", name="cart_id", nullable="true") */ + /** @Column(type="integer", name="cart_id", nullable=true) */ public $cartId; /** * @OneToOne(targetEntity="DDC522Cart") diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC531Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC531Test.php index 0ac3b9b8d..7ce19cfab 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC531Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC531Test.php @@ -29,8 +29,8 @@ class DDC531Test extends \Doctrine\Tests\OrmFunctionalTestCase $item3 = $this->_em->find(__NAMESPACE__ . '\DDC531Item', $item2->id); // Load child item first (id 2) // parent will already be loaded, cannot be lazy because it has mapped subclasses and we would not // know which proxy type to put in. - $this->assertTrue($item3->parent instanceof DDC531Item); - $this->assertFalse($item3->parent instanceof \Doctrine\ORM\Proxy\Proxy); + $this->assertInstanceOf(__NAMESPACE__ . '\DDC531Item', $item3->parent); + $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $item3->parent); $item4 = $this->_em->find(__NAMESPACE__ . '\DDC531Item', $item1->id); // Load parent item (id 1) $this->assertNull($item4->parent); $this->assertNotNull($item4->getChildren()); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php index d51bdd361..fa7e0af2f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php @@ -66,7 +66,7 @@ class DDC633Test extends \Doctrine\Tests\OrmFunctionalTestCase $appointments = $this->_em->createQuery("SELECT a FROM " . __NAMESPACE__ . "\DDC633Appointment a")->getResult(); foreach ($appointments AS $eagerAppointment) { - $this->assertType('Doctrine\ORM\Proxy\Proxy', $eagerAppointment->patient); + $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $eagerAppointment->patient); $this->assertTrue($eagerAppointment->patient->__isInitialized__, "Proxy should already be initialized due to eager loading!"); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC698Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC698Test.php index c2c20c0ce..9fbfd01ab 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC698Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC698Test.php @@ -49,14 +49,14 @@ class DDC698Role protected $roleID; /** - * @Column(name="name", type="string", length="45") + * @Column(name="name", type="string", length=45) * * */ protected $name; /** - * @Column(name="shortName", type="string", length="45") + * @Column(name="shortName", type="string", length=45) * * */ @@ -91,7 +91,7 @@ class DDC698Privilege protected $privilegeID; /** - * @Column(name="name", type="string", length="45") + * @Column(name="name", type="string", length=45) * * */ diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC729Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC729Test.php index c2be27b11..939c35d7b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC729Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC729Test.php @@ -36,11 +36,11 @@ class DDC729Test extends \Doctrine\Tests\OrmFunctionalTestCase $a = new DDC729A(); $a->id = $aId; - $this->assertType('Doctrine\Common\Collections\ArrayCollection', $a->related); + $this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $a->related); $a = $this->_em->merge($a); - $this->assertType('Doctrine\ORM\PersistentCollection', $a->related); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $a->related); $this->assertFalse($a->related->isInitialized(), "Collection should not be marked initialized."); $this->assertFalse($a->related->isDirty(), "Collection should not be marked as dirty."); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC736Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC736Test.php index 66c73bb78..de9e275bf 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC736Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC736Test.php @@ -72,7 +72,7 @@ class DDC736Test extends \Doctrine\Tests\OrmFunctionalTestCase /* @var $cart2 Doctrine\Tests\Models\ECommerce\ECommerceCart */ $cart2 = $result[0][0]; - $this->assertType('Doctrine\ORM\Proxy\Proxy', $cart2->getCustomer()); + $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $cart2->getCustomer()); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC748Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC748Test.php index 1548552d7..9954a697b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC748Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC748Test.php @@ -33,10 +33,10 @@ class DDC748Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->persist($article); $this->_em->flush(); - $this->assertType('Doctrine\Common\Collections\Collection', $user->articles); + $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $user->articles); $this->_em->refresh($article); $this->assertTrue($article !== $user->articles, "The article should not be replaced on the inverse side of the relation."); - $this->assertType('Doctrine\Common\Collections\Collection', $user->articles); + $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $user->articles); } public function testRefreshOneToOne() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC758Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC758Test.php index 60a0ff89c..76bb3bba8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC758Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC758Test.php @@ -14,6 +14,7 @@ class DDC758Test extends \Doctrine\Tests\OrmFunctionalTestCase public function setUp() { + $this->markTestSkipped('Destroys testsuite'); $this->useModelSet("cms"); parent::setUp(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC837Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC837Test.php index 6afea88cd..d44c3af7d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC837Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC837Test.php @@ -52,20 +52,20 @@ class DDC837Test extends \Doctrine\Tests\OrmFunctionalTestCase // Test Class1 $e1 = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC837Super', $c1->id); - $this->assertType('Doctrine\Tests\ORM\Functional\Ticket\DDC837Class1', $e1); + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC837Class1', $e1); $this->assertEquals('Foo', $e1->title); $this->assertEquals('Foo', $e1->description); - $this->assertType(__NAMESPACE__ . '\DDC837Aggregate', $e1->aggregate); + $this->assertInstanceOf(__NAMESPACE__ . '\DDC837Aggregate', $e1->aggregate); $this->assertEquals('test1', $e1->aggregate->getSysname()); // Test Class 2 $e2 = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC837Super', $c2->id); - $this->assertType('Doctrine\Tests\ORM\Functional\Ticket\DDC837Class2', $e2); + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC837Class2', $e2); $this->assertEquals('Bar', $e2->title); $this->assertEquals('Bar', $e2->description); $this->assertEquals('Bar', $e2->text); - $this->assertType(__NAMESPACE__ . '\DDC837Aggregate', $e2->aggregate); + $this->assertInstanceOf(__NAMESPACE__ . '\DDC837Aggregate', $e2->aggregate); $this->assertEquals('test2', $e2->aggregate->getSysname()); $all = $this->_em->getRepository(__NAMESPACE__.'\DDC837Super')->findAll(); @@ -111,12 +111,12 @@ abstract class DDC837Super class DDC837Class1 extends DDC837Super { /** - * @Column(name="title", type="string", length="150") + * @Column(name="title", type="string", length=150) */ public $title; /** - * @Column(name="content", type="string", length="500") + * @Column(name="content", type="string", length=500) */ public $description; @@ -132,12 +132,12 @@ class DDC837Class1 extends DDC837Super class DDC837Class2 extends DDC837Super { /** - * @Column(name="title", type="string", length="150") + * @Column(name="title", type="string", length=150) */ public $title; /** - * @Column(name="content", type="string", length="500") + * @Column(name="content", type="string", length=500) */ public $description; @@ -160,12 +160,12 @@ class DDC837Class2 extends DDC837Super class DDC837Class3 extends DDC837Super { /** - * @Column(name="title", type="string", length="150") + * @Column(name="title", type="string", length=150) */ public $apples; /** - * @Column(name="content", type="string", length="500") + * @Column(name="content", type="string", length=500) */ public $bananas; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC949Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC949Test.php index adab29d93..473a8679f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC949Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC949Test.php @@ -34,10 +34,10 @@ class DDC949Test extends \Doctrine\Tests\OrmFunctionalTestCase $true = $this->_em->getRepository('Doctrine\Tests\Models\Generic\BooleanModel')->findOneBy(array('booleanField' => true)); $false = $this->_em->getRepository('Doctrine\Tests\Models\Generic\BooleanModel')->findOneBy(array('booleanField' => false)); - $this->assertType('Doctrine\Tests\Models\Generic\BooleanModel', $true); + $this->assertInstanceOf('Doctrine\Tests\Models\Generic\BooleanModel', $true); $this->assertTrue($true->booleanField, "True Boolean Model should be true."); - $this->assertType('Doctrine\Tests\Models\Generic\BooleanModel', $false); + $this->assertInstanceOf('Doctrine\Tests\Models\Generic\BooleanModel', $false); $this->assertFalse($false->booleanField, "False Boolean Model should be false."); } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC992Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC992Test.php index 36d9a392f..001e3801f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC992Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC992Test.php @@ -124,7 +124,7 @@ class DDC992Role */ public $roleID; /** - * @Column (name="name", type="string", length="45") + * @Column (name="name", type="string", length=45) */ public $name; /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket69.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket69.php index f6ef6c3bf..759a593fd 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket69.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket69.php @@ -85,11 +85,11 @@ class AdvancedAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCase { $lemma = $res[0]; $this->assertEquals('foo', $lemma->getLemma()); - $this->assertTrue($lemma instanceof Lemma); + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\Lemma', $lemma); $relations = $lemma->getRelations(); foreach($relations as $relation) { - $this->assertTrue($relation instanceof Relation); + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\Relation', $relation); $this->assertTrue($relation->getType()->getType() != ''); } diff --git a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php index a2a738b56..8a2eab70e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php @@ -8,7 +8,7 @@ use Doctrine\Tests\Models\Generic\DecimalModel; use Doctrine\Tests\Models\Generic\SerializationModel; use Doctrine\ORM\Mapping\AssociationMapping; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Type as DBALType; require_once __DIR__ . '/../../TestInit.php'; @@ -37,6 +37,10 @@ class TypeTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(0.1515, $decimal->highScale); } + /** + * @group DDC-1394 + * @return void + */ public function testBoolean() { $bool = new BooleanModel(); @@ -46,7 +50,7 @@ class TypeTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->flush(); $this->_em->clear(); - $dql = "SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b"; + $dql = "SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = true"; $bool = $this->_em->createQuery($dql)->getSingleResult(); $this->assertTrue($bool->booleanField); @@ -56,7 +60,7 @@ class TypeTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->flush(); $this->_em->clear(); - $dql = "SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b"; + $dql = "SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = false"; $bool = $this->_em->createQuery($dql)->getSingleResult(); $this->assertFalse($bool->booleanField); @@ -135,7 +139,7 @@ class TypeTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->clear(); $dateTimeDb = $this->_em->createQuery('SELECT d FROM Doctrine\Tests\Models\Generic\DateTimeModel d WHERE d.datetime = ?1') - ->setParameter(1, $date, Type::DATETIME) + ->setParameter(1, $date, DBALType::DATETIME) ->getSingleResult(); } @@ -154,7 +158,7 @@ class TypeTest extends \Doctrine\Tests\OrmFunctionalTestCase ->select('d') ->from('Doctrine\Tests\Models\Generic\DateTimeModel', 'd') ->where('d.datetime = ?1') - ->setParameter(1, $date, Type::DATETIME) + ->setParameter(1, $date, DBALType::DATETIME) ->getQuery()->getSingleResult(); } diff --git a/tests/Doctrine/Tests/ORM/Hydration/AllTests.php b/tests/Doctrine/Tests/ORM/Hydration/AllTests.php deleted file mode 100644 index d2ecafec3..000000000 --- a/tests/Doctrine/Tests/ORM/Hydration/AllTests.php +++ /dev/null @@ -1,36 +0,0 @@ -addTestSuite('Doctrine\Tests\ORM\Hydration\ObjectHydratorTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Hydration\ArrayHydratorTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Hydration\ScalarHydratorTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Hydration\SingleScalarHydratorTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Hydration\ResultSetMappingTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Hydration\CustomHydratorTest'); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Orm_Hydration_AllTests::main') { - AllTests::main(); -} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Hydration/CustomHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/CustomHydratorTest.php index 6b5e45149..8daf961b5 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/CustomHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/CustomHydratorTest.php @@ -15,7 +15,7 @@ class CustomHydratorTest extends HydrationTestCase $config->addCustomHydrationMode('CustomHydrator', 'Doctrine\Tests\ORM\Hydration\CustomHydrator'); $hydrator = $em->newHydrator('CustomHydrator'); - $this->assertTrue($hydrator instanceof \Doctrine\Tests\ORM\Hydration\CustomHydrator); + $this->assertInstanceOf('Doctrine\Tests\ORM\Hydration\CustomHydrator', $hydrator); $this->assertNull($config->getCustomHydrationMode('does not exist')); } } diff --git a/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php index ecd50f237..f2673ac70 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php @@ -44,8 +44,8 @@ class ObjectHydratorTest extends HydrationTestCase $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); $this->assertEquals(2, count($result)); - $this->assertTrue($result[0] instanceof \Doctrine\Tests\Models\CMS\CmsUser); - $this->assertTrue($result[1] instanceof \Doctrine\Tests\Models\CMS\CmsUser); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[1]); $this->assertEquals(1, $result[0]->id); $this->assertEquals('romanb', $result[0]->name); $this->assertEquals(2, $result[1]->id); @@ -116,10 +116,10 @@ class ObjectHydratorTest extends HydrationTestCase $this->assertEquals(4, count($result)); - $this->assertTrue($result[0] instanceof \Doctrine\Tests\Models\CMS\CmsUser); - $this->assertTrue($result[1] instanceof \Doctrine\Tests\Models\CMS\CmsArticle); - $this->assertTrue($result[2] instanceof \Doctrine\Tests\Models\CMS\CmsUser); - $this->assertTrue($result[3] instanceof \Doctrine\Tests\Models\CMS\CmsArticle); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[1]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[2]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[3]); $this->assertEquals(1, $result[0]->id); $this->assertEquals('romanb', $result[0]->name); @@ -173,7 +173,7 @@ class ObjectHydratorTest extends HydrationTestCase $result = $hydrator->hydrateAll($stmt, $rsm); $this->assertEquals(1, count($result)); - $this->assertTrue($result[0] instanceof \Doctrine\Tests\Models\ECommerce\ECommerceProduct); + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $result[0]); } /** @@ -231,12 +231,12 @@ class ObjectHydratorTest extends HydrationTestCase $this->assertTrue(is_array($result[0])); $this->assertTrue(is_array($result[1])); - $this->assertTrue($result[0][0] instanceof \Doctrine\Tests\Models\CMS\CmsUser); - $this->assertTrue($result[0][0]->phonenumbers instanceof \Doctrine\ORM\PersistentCollection); - $this->assertTrue($result[0][0]->phonenumbers[0] instanceof \Doctrine\Tests\Models\CMS\CmsPhonenumber); - $this->assertTrue($result[0][0]->phonenumbers[1] instanceof \Doctrine\Tests\Models\CMS\CmsPhonenumber); - $this->assertTrue($result[1][0] instanceof \Doctrine\Tests\Models\CMS\CmsUser); - $this->assertTrue($result[1][0]->phonenumbers instanceof \Doctrine\ORM\PersistentCollection); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0][0]); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[0][0]->phonenumbers); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsPhonenumber', $result[0][0]->phonenumbers[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsPhonenumber', $result[0][0]->phonenumbers[1]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[1][0]); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[1][0]->phonenumbers); // first user => 2 phonenumbers $this->assertEquals(2, count($result[0][0]->phonenumbers)); @@ -293,8 +293,8 @@ class ObjectHydratorTest extends HydrationTestCase $this->assertEquals(2, $result[0]['numPhones']); // second user => 1 phonenumber $this->assertEquals(1, $result[1]['numPhones']); - $this->assertTrue($result[0][0] instanceof \Doctrine\Tests\Models\CMS\CmsUser); - $this->assertTrue($result[1][0] instanceof \Doctrine\Tests\Models\CMS\CmsUser); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0][0]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[1][0]); } /** @@ -359,9 +359,9 @@ class ObjectHydratorTest extends HydrationTestCase $this->assertEquals('ROMANB', $result[0]['nameUpper']); $this->assertEquals('JWAGE', $result[1]['nameUpper']); - $this->assertTrue($result[0]['1'] instanceof \Doctrine\Tests\Models\CMS\CmsUser); - $this->assertTrue($result[1]['2'] instanceof \Doctrine\Tests\Models\CMS\CmsUser); - $this->assertTrue($result[0]['1']->phonenumbers instanceof \Doctrine\ORM\PersistentCollection); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0]['1']); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[1]['2']); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[0]['1']->phonenumbers); // first user => 2 phonenumbers. notice the custom indexing by user id $this->assertEquals(2, count($result[0]['1']->phonenumbers)); // second user => 1 phonenumber. notice the custom indexing by user id @@ -469,18 +469,18 @@ class ObjectHydratorTest extends HydrationTestCase $this->assertTrue(is_array($result[0])); $this->assertTrue(is_array($result[1])); - $this->assertTrue($result[0][0] instanceof \Doctrine\Tests\Models\CMS\CmsUser); - $this->assertTrue($result[0][0]->phonenumbers instanceof \Doctrine\ORM\PersistentCollection); - $this->assertTrue($result[0][0]->phonenumbers[0] instanceof \Doctrine\Tests\Models\CMS\CmsPhonenumber); - $this->assertTrue($result[0][0]->phonenumbers[1] instanceof \Doctrine\Tests\Models\CMS\CmsPhonenumber); - $this->assertTrue($result[0][0]->articles instanceof \Doctrine\ORM\PersistentCollection); - $this->assertTrue($result[0][0]->articles[0] instanceof \Doctrine\Tests\Models\CMS\CmsArticle); - $this->assertTrue($result[0][0]->articles[1] instanceof \Doctrine\Tests\Models\CMS\CmsArticle); - $this->assertTrue($result[1][0] instanceof \Doctrine\Tests\Models\CMS\CmsUser); - $this->assertTrue($result[1][0]->phonenumbers instanceof \Doctrine\ORM\PersistentCollection); - $this->assertTrue($result[1][0]->phonenumbers[0] instanceof \Doctrine\Tests\Models\CMS\CmsPhonenumber); - $this->assertTrue($result[1][0]->articles[0] instanceof \Doctrine\Tests\Models\CMS\CmsArticle); - $this->assertTrue($result[1][0]->articles[1] instanceof \Doctrine\Tests\Models\CMS\CmsArticle); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0][0]); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[0][0]->phonenumbers); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsPhonenumber', $result[0][0]->phonenumbers[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsPhonenumber', $result[0][0]->phonenumbers[1]); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[0][0]->articles); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[0][0]->articles[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[0][0]->articles[1]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[1][0]); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[1][0]->phonenumbers); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsPhonenumber', $result[1][0]->phonenumbers[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[1][0]->articles[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[1][0]->articles[1]); } /** @@ -604,29 +604,29 @@ class ObjectHydratorTest extends HydrationTestCase $this->assertTrue(is_array($result[0])); $this->assertTrue(is_array($result[1])); - $this->assertTrue($result[0][0] instanceof \Doctrine\Tests\Models\CMS\CmsUser); - $this->assertTrue($result[1][0] instanceof \Doctrine\Tests\Models\CMS\CmsUser); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0][0]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[1][0]); // phonenumbers - $this->assertTrue($result[0][0]->phonenumbers instanceof \Doctrine\ORM\PersistentCollection); - $this->assertTrue($result[0][0]->phonenumbers[0] instanceof \Doctrine\Tests\Models\CMS\CmsPhonenumber); - $this->assertTrue($result[0][0]->phonenumbers[1] instanceof \Doctrine\Tests\Models\CMS\CmsPhonenumber); - $this->assertTrue($result[1][0]->phonenumbers instanceof \Doctrine\ORM\PersistentCollection); - $this->assertTrue($result[1][0]->phonenumbers[0] instanceof \Doctrine\Tests\Models\CMS\CmsPhonenumber); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[0][0]->phonenumbers); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsPhonenumber', $result[0][0]->phonenumbers[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsPhonenumber', $result[0][0]->phonenumbers[1]); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[1][0]->phonenumbers); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsPhonenumber', $result[1][0]->phonenumbers[0]); // articles - $this->assertTrue($result[0][0]->articles instanceof \Doctrine\ORM\PersistentCollection); - $this->assertTrue($result[0][0]->articles[0] instanceof \Doctrine\Tests\Models\CMS\CmsArticle); - $this->assertTrue($result[0][0]->articles[1] instanceof \Doctrine\Tests\Models\CMS\CmsArticle); - $this->assertTrue($result[1][0]->articles[0] instanceof \Doctrine\Tests\Models\CMS\CmsArticle); - $this->assertTrue($result[1][0]->articles[1] instanceof \Doctrine\Tests\Models\CMS\CmsArticle); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[0][0]->articles); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[0][0]->articles[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[0][0]->articles[1]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[1][0]->articles[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $result[1][0]->articles[1]); // article comments - $this->assertTrue($result[0][0]->articles[0]->comments instanceof \Doctrine\ORM\PersistentCollection); - $this->assertTrue($result[0][0]->articles[0]->comments[0] instanceof \Doctrine\Tests\Models\CMS\CmsComment); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[0][0]->articles[0]->comments); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsComment', $result[0][0]->articles[0]->comments[0]); // empty comment collections - $this->assertTrue($result[0][0]->articles[1]->comments instanceof \Doctrine\ORM\PersistentCollection); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[0][0]->articles[1]->comments); $this->assertEquals(0, count($result[0][0]->articles[1]->comments)); - $this->assertTrue($result[1][0]->articles[0]->comments instanceof \Doctrine\ORM\PersistentCollection); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[1][0]->articles[0]->comments); $this->assertEquals(0, count($result[1][0]->articles[0]->comments)); - $this->assertTrue($result[1][0]->articles[1]->comments instanceof \Doctrine\ORM\PersistentCollection); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[1][0]->articles[1]->comments); $this->assertEquals(0, count($result[1][0]->articles[1]->comments)); } @@ -706,8 +706,8 @@ class ObjectHydratorTest extends HydrationTestCase $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); $this->assertEquals(2, count($result)); - $this->assertTrue($result[0] instanceof \Doctrine\Tests\Models\Forum\ForumCategory); - $this->assertTrue($result[1] instanceof \Doctrine\Tests\Models\Forum\ForumCategory); + $this->assertInstanceOf('Doctrine\Tests\Models\Forum\ForumCategory', $result[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\Forum\ForumCategory', $result[1]); $this->assertTrue($result[0] !== $result[1]); $this->assertEquals(1, $result[0]->getId()); $this->assertEquals(2, $result[1]->getId()); @@ -768,8 +768,8 @@ class ObjectHydratorTest extends HydrationTestCase $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); $this->assertEquals(2, count($result)); - $this->assertTrue($result[0] instanceof CmsUser); - $this->assertTrue($result[1] instanceof CmsUser); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[1]); $this->assertEquals(0, $result[0]->articles->count()); $this->assertEquals(0, $result[1]->articles->count()); } @@ -826,19 +826,19 @@ class ObjectHydratorTest extends HydrationTestCase $this->assertEquals(3, count($result)); - $this->assertTrue($result[0][0] instanceof CmsUser); // User object + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0][0]); // User object $this->assertEquals(1, $result[0]['id']); $this->assertEquals('The First', $result[0]['topic']); $this->assertEquals(1, $result[0]['cid']); $this->assertEquals('First Comment', $result[0]['ctopic']); - $this->assertTrue($result[1][0] instanceof CmsUser); // Same User object + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[1][0]); // Same User object $this->assertEquals(1, $result[1]['id']); // duplicated $this->assertEquals('The First', $result[1]['topic']); // duplicated $this->assertEquals(2, $result[1]['cid']); $this->assertEquals('Second Comment', $result[1]['ctopic']); - $this->assertTrue($result[2][0] instanceof CmsUser); // Same User object + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[2][0]); // Same User object $this->assertEquals(42, $result[2]['id']); $this->assertEquals('The Answer', $result[2]['topic']); $this->assertNull($result[2]['cid']); @@ -877,7 +877,7 @@ class ObjectHydratorTest extends HydrationTestCase $rowNum = 0; while (($row = $iterableResult->next()) !== false) { $this->assertEquals(1, count($row)); - $this->assertTrue($row[0] instanceof \Doctrine\Tests\Models\CMS\CmsUser); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $row[0]); if ($rowNum == 0) { $this->assertEquals(1, $row[0]->id); $this->assertEquals('romanb', $row[0]->name); diff --git a/tests/Doctrine/Tests/ORM/Id/AllTests.php b/tests/Doctrine/Tests/ORM/Id/AllTests.php deleted file mode 100644 index 87201d915..000000000 --- a/tests/Doctrine/Tests/ORM/Id/AllTests.php +++ /dev/null @@ -1,31 +0,0 @@ -addTestSuite('Doctrine\Tests\ORM\Id\SequenceGeneratorTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Id\AssignedGeneratorTest'); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Orm_Id_AllTests::main') { - AllTests::main(); -} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index ee2ea4249..98c43a5b9 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -182,10 +182,11 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase $this->assertTrue(isset($class->associationMappings['phonenumbers'])); $this->assertFalse($class->associationMappings['phonenumbers']['isOwningSide']); $this->assertTrue($class->associationMappings['phonenumbers']['isCascadePersist']); - $this->assertFalse($class->associationMappings['phonenumbers']['isCascadeRemove']); + $this->assertTrue($class->associationMappings['phonenumbers']['isCascadeRemove']); $this->assertFalse($class->associationMappings['phonenumbers']['isCascadeRefresh']); $this->assertFalse($class->associationMappings['phonenumbers']['isCascadeDetach']); $this->assertFalse($class->associationMappings['phonenumbers']['isCascadeMerge']); + $this->assertTrue($class->associationMappings['phonenumbers']['orphanRemoval']); // Test Order By $this->assertEquals(array('number' => 'ASC'), $class->associationMappings['phonenumbers']['orderBy']); @@ -267,10 +268,9 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase * @depends testColumnDefinition * @param ClassMetadata $class */ - public function testJoinColumnOnDeleteAndOnUpdate($class) + public function testJoinColumnOnDelete($class) { $this->assertEquals('CASCADE', $class->associationMappings['address']['joinColumns'][0]['onDelete']); - $this->assertEquals('CASCADE', $class->associationMappings['address']['joinColumns'][0]['onUpdate']); return $class; } @@ -291,6 +291,42 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase $class->discriminatorColumn ); } + + /** + * @group DDC-869 + */ + public function testMappedSuperclassWithRepository() + { + $driver = $this->_loadDriver(); + $em = $this->_getTestEntityManager(); + $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory(); + + $em->getConfiguration()->setMetadataDriverImpl($driver); + $factory->setEntityManager($em); + + + $class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment'); + + $this->assertTrue(isset($class->fieldMappings['id'])); + $this->assertTrue(isset($class->fieldMappings['value'])); + $this->assertTrue(isset($class->fieldMappings['creditCardNumber'])); + $this->assertEquals($class->customRepositoryClassName, "Doctrine\Tests\Models\DDC869\DDC869PaymentRepository"); + $this->assertInstanceOf("Doctrine\Tests\Models\DDC869\DDC869PaymentRepository", + $em->getRepository("Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment")); + $this->assertTrue($em->getRepository("Doctrine\Tests\Models\DDC869\DDC869ChequePayment")->isTrue()); + + + + $class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869ChequePayment'); + + $this->assertTrue(isset($class->fieldMappings['id'])); + $this->assertTrue(isset($class->fieldMappings['value'])); + $this->assertTrue(isset($class->fieldMappings['serialNumber'])); + $this->assertEquals($class->customRepositoryClassName, "Doctrine\Tests\Models\DDC869\DDC869PaymentRepository"); + $this->assertInstanceOf("Doctrine\Tests\Models\DDC869\DDC869PaymentRepository", + $em->getRepository("Doctrine\Tests\Models\DDC869\DDC869ChequePayment")); + $this->assertTrue($em->getRepository("Doctrine\Tests\Models\DDC869\DDC869ChequePayment")->isTrue()); + } } /** @@ -324,12 +360,12 @@ class User /** * @OneToOne(targetEntity="Address", cascade={"remove"}, inversedBy="user") - * @JoinColumn(onDelete="CASCADE", onUpdate="CASCADE") + * @JoinColumn(onDelete="CASCADE") */ public $address; /** - * @OneToMany(targetEntity="Phonenumber", mappedBy="user", cascade={"persist"}) + * @OneToMany(targetEntity="Phonenumber", mappedBy="user", cascade={"persist"}, orphanRemoval=true) * @OrderBy({"number"="ASC"}) */ public $phonenumbers; @@ -412,7 +448,6 @@ class User 'name' => 'address_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE', - 'onUpdate' => 'CASCADE' ), ), 'orphanRemoval' => false, @@ -425,7 +460,7 @@ class User 1 => 'persist', ), 'mappedBy' => 'user', - 'orphanRemoval' => false, + 'orphanRemoval' => true, 'orderBy' => array( 'number' => 'ASC', diff --git a/tests/Doctrine/Tests/ORM/Mapping/AllTests.php b/tests/Doctrine/Tests/ORM/Mapping/AllTests.php deleted file mode 100644 index 30a8ead5b..000000000 --- a/tests/Doctrine/Tests/ORM/Mapping/AllTests.php +++ /dev/null @@ -1,39 +0,0 @@ -addTestSuite('Doctrine\Tests\ORM\Mapping\ClassMetadataTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\XmlMappingDriverTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\YamlMappingDriverTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\AnnotationDriverTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\PHPMappingDriverTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\StaticPHPMappingDriverTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\ClassMetadataFactoryTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\ClassMetadataLoadEventTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\BasicInheritanceMappingTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\DriverChainTest'); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Orm_Mapping_AllTests::main') { - AllTests::main(); -} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php index f02401975..e946a2628 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php @@ -99,10 +99,7 @@ class AnnotationDriverTest extends AbstractMappingDriverTest protected function _loadDriver() { - $cache = new \Doctrine\Common\Cache\ArrayCache(); - $reader = new \Doctrine\Common\Annotations\AnnotationReader($cache); - $reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\'); - return new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader); + return $this->createAnnotationDriver(); } protected function _ensureIsLoaded($entityClassName) @@ -187,6 +184,21 @@ class AnnotationDriverTest extends AbstractMappingDriverTest $cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\AnnotationParent'); $this->assertEquals(array("postLoad" => array("postLoad"), "preUpdate" => array("preUpdate")), $cm->lifecycleCallbacks); } + + /** + * @group DDC-1156 + */ + public function testMappedSuperclassInMiddleOfInheritanceHierachy() + { + $annotationDriver = $this->_loadDriver(); + + $em = $this->_getTestEntityManager(); + $em->getConfiguration()->setMetadataDriverImpl($annotationDriver); + $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory(); + $factory->setEntityManager($em); + + $cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\ChildEntity'); + } } /** @@ -267,4 +279,35 @@ class AnnotationParent class AnnotationChild extends AnnotationParent { +} + +/** + * @Entity + * @InheritanceType("SINGLE_TABLE") + * @DiscriminatorMap({"s"="SuperEntity", "c"="ChildEntity"}) + */ +class SuperEntity +{ + /** @Id @Column(type="string") */ + private $id; +} + +/** + * @MappedSuperclass + */ +class MiddleMappedSuperclass extends SuperEntity +{ + /** @Column(type="string") */ + private $name; +} + +/** + * @Entity + */ +class ChildEntity extends MiddleMappedSuperclass +{ + /** + * @Column(type="string") + */ + private $text; } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php index 671028852..93504ec53 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM\Mapping; use Doctrine\ORM\Mapping\ClassMetadataFactory; +use Doctrine\ORM\Tools\SchemaTool; require_once __DIR__ . '/../../TestInit.php'; @@ -51,6 +52,35 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase $this->assertTrue(isset($class->associationMappings['mappedRelated1'])); } + + /** + * @group DDC-869 + */ + public function testGetMetadataForSubclassWithMappedSuperclassWhithRepository() + { + $class = $this->_factory->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment'); + + $this->assertTrue(isset($class->fieldMappings['id'])); + $this->assertTrue(isset($class->fieldMappings['value'])); + $this->assertTrue(isset($class->fieldMappings['creditCardNumber'])); + $this->assertEquals($class->customRepositoryClassName, "Doctrine\Tests\Models\DDC869\DDC869PaymentRepository"); + + + $class = $this->_factory->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869ChequePayment'); + + $this->assertTrue(isset($class->fieldMappings['id'])); + $this->assertTrue(isset($class->fieldMappings['value'])); + $this->assertTrue(isset($class->fieldMappings['serialNumber'])); + $this->assertEquals($class->customRepositoryClassName, "Doctrine\Tests\Models\DDC869\DDC869PaymentRepository"); + + + // override repositoryClass + $class = $this->_factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\SubclassWithRepository'); + + $this->assertTrue(isset($class->fieldMappings['id'])); + $this->assertTrue(isset($class->fieldMappings['value'])); + $this->assertEquals($class->customRepositoryClassName, "Doctrine\ORM\EntityRepository"); + } /** * @group DDC-388 @@ -66,6 +96,78 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase $this->assertTrue(isset($class2->reflFields['mapped2'])); $this->assertTrue(isset($class2->reflFields['mappedRelated1'])); } + + /** + * @group DDC-1203 + */ + public function testUnmappedSuperclassInHierachy() + { + $class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\HierachyD'); + + $this->assertTrue(isset($class->fieldMappings['id'])); + $this->assertTrue(isset($class->fieldMappings['a'])); + $this->assertTrue(isset($class->fieldMappings['d'])); + } + + /** + * @group DDC-1204 + */ + public function testUnmappedEntityInHierachy() + { + $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', "Entity 'Doctrine\Tests\ORM\Mapping\HierachyBEntity' has to be part of the descriminator map of 'Doctrine\Tests\ORM\Mapping\HierachyBase' to be properly mapped in the inheritance hierachy. Alternatively you can make 'Doctrine\Tests\ORM\Mapping\HierachyBEntity' an abstract class to avoid this exception from occuring."); + + $class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\HierachyE'); + } + + /** + * @group DDC-1204 + * @group DDC-1203 + */ + public function testMappedSuperclassWithId() + { + $class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\SuperclassEntity'); + + $this->assertTrue(isset($class->fieldMappings['id'])); + } + + /** + * @group DDC-1156 + * @group DDC-1218 + */ + public function testGeneratedValueFromMappedSuperclass() + { + $class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\SuperclassEntity'); + /* @var $class ClassMetadataInfo */ + + $this->assertInstanceOf('Doctrine\ORM\Id\SequenceGenerator', $class->idGenerator); + $this->assertEquals(array('allocationSize' => 1, 'initialValue' => 10, 'sequenceName' => 'foo'), $class->sequenceGeneratorDefinition); + } + + /** + * @group DDC-1156 + * @group DDC-1218 + */ + public function testSequenceDefinitionInHierachyWithSandwichMappedSuperclass() + { + $class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\HierachyD'); + /* @var $class ClassMetadataInfo */ + + $this->assertInstanceOf('Doctrine\ORM\Id\SequenceGenerator', $class->idGenerator); + $this->assertEquals(array('allocationSize' => 1, 'initialValue' => 10, 'sequenceName' => 'foo'), $class->sequenceGeneratorDefinition); + } + + /** + * @group DDC-1156 + * @group DDC-1218 + */ + public function testMultipleMappedSuperclasses() + { + $class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\MediumSuperclassEntity'); + /* @var $class ClassMetadataInfo */ + + $this->assertInstanceOf('Doctrine\ORM\Id\SequenceGenerator', $class->idGenerator); + $this->assertEquals(array('allocationSize' => 1, 'initialValue' => 10, 'sequenceName' => 'foo'), $class->sequenceGeneratorDefinition); + } } class TransientBaseClass { @@ -103,3 +205,113 @@ class EntitySubClass2 extends MappedSuperclassBase { /** @Column(type="string") */ private $name; } + +/** + * @Entity + * @InheritanceType("SINGLE_TABLE") + * @DiscriminatorColumn(name="type", type="string", length=20) + * @DiscriminatorMap({ + * "c" = "HierachyC", + * "d" = "HierachyD", + * "e" = "HierachyE" + * }) + */ +abstract class HierachyBase +{ + /** + * @Column(type="integer") @Id @GeneratedValue(strategy="SEQUENCE") + * @SequenceGenerator(sequenceName="foo", initialValue=10) + * @var int + */ + public $id; +} + +/** + * @MappedSuperclass + */ +abstract class HierachyASuperclass extends HierachyBase +{ + /** @Column(type="string") */ + public $a; +} + +/** + * @Entity + */ +class HierachyBEntity extends HierachyBase +{ + /** @Column(type="string") */ + public $b; +} + +/** + * @Entity + */ +class HierachyC extends HierachyBase +{ + /** @Column(type="string") */ + public $c; +} + +/** + * @Entity + */ +class HierachyD extends HierachyASuperclass +{ + /** @Column(type="string") */ + public $d; +} + +/** + * @Entity + */ +class HierachyE extends HierachyBEntity +{ + /** @Column(type="string") */ + public $e; +} + +/** + * @Entity + */ +class SuperclassEntity extends SuperclassBase +{ + +} + +/** + * @MappedSuperclass + */ +abstract class SuperclassBase +{ + /** + * @Column(type="integer") @Id @GeneratedValue(strategy="SEQUENCE") + * @SequenceGenerator(sequenceName="foo", initialValue=10) + * @var int + */ + public $id; +} + +/** + * @MappedSuperclass + */ +abstract class MediumSuperclassBase extends SuperclassBase +{ + +} + +/** + * @Entity + */ +class MediumSuperclassEntity extends MediumSuperclassBase +{ + +} + +/** + * @Entity(repositoryClass = "Doctrine\ORM\EntityRepository") + */ +class SubclassWithRepository extends \Doctrine\Tests\Models\DDC869\DDC869Payment +{ + +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php new file mode 100644 index 000000000..38cecd5cc --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php @@ -0,0 +1,426 @@ +. + */ + + +namespace Doctrine\Tests\ORM\Mapping; + +use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder; + +/** + * @group DDC-659 + */ +class ClassMetadataBuilderTest extends \Doctrine\Tests\OrmTestCase +{ + /** + * @var ClassMetadata + */ + private $cm; + /** + * @var ClassMetadataBuilder + */ + private $builder; + + public function setUp() + { + $this->cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $this->builder = new ClassMetadataBuilder($this->cm); + } + + public function testSetMappedSuperClass() + { + $this->assertIsFluent($this->builder->setMappedSuperClass()); + $this->assertTrue($this->cm->isMappedSuperclass); + } + + public function testSetCustomRepositoryClass() + { + $this->assertIsFluent($this->builder->setCustomRepositoryClass('Doctrine\Tests\Models\CMS\CmsGroup')); + $this->assertEquals('Doctrine\Tests\Models\CMS\CmsGroup', $this->cm->customRepositoryClassName); + } + + public function testSetReadOnly() + { + $this->assertIsFluent($this->builder->setReadOnly()); + $this->assertTrue($this->cm->isReadOnly); + } + + public function testSetTable() + { + $this->assertIsFluent($this->builder->setTable('users')); + $this->assertEquals('users', $this->cm->table['name']); + } + + public function testAddIndex() + { + $this->assertIsFluent($this->builder->addIndex(array('username', 'name'), 'users_idx')); + $this->assertEquals(array('users_idx' => array('columns' => array('username', 'name'))), $this->cm->table['indexes']); + } + + public function testAddUniqueConstraint() + { + $this->assertIsFluent($this->builder->addUniqueConstraint(array('username', 'name'), 'users_idx')); + $this->assertEquals(array('users_idx' => array('columns' => array('username', 'name'))), $this->cm->table['uniqueConstraints']); + } + + public function testSetPrimaryTableRelated() + { + $this->builder->addUniqueConstraint(array('username', 'name'), 'users_idx'); + $this->builder->addIndex(array('username', 'name'), 'users_idx'); + $this->builder->setTable('users'); + + $this->assertEquals( + array( + 'name' => 'users', + 'indexes' => array('users_idx' => array('columns' => array('username', 'name'))), + 'uniqueConstraints' => array('users_idx' => array('columns' => array('username', 'name'))), + ), + $this->cm->table + ); + } + + public function testSetInheritanceJoined() + { + $this->assertIsFluent($this->builder->setJoinedTableInheritance()); + $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_JOINED, $this->cm->inheritanceType); + } + + public function testSetInheritanceSingleTable() + { + $this->assertIsFluent($this->builder->setSingleTableInheritance()); + $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_SINGLE_TABLE, $this->cm->inheritanceType); + } + + public function testSetDiscriminatorColumn() + { + $this->assertIsFluent($this->builder->setDiscriminatorColumn('discr', 'string', '124')); + $this->assertEquals(array('fieldName' => 'discr', 'name' => 'discr', 'type' => 'string', 'length' => '124'), $this->cm->discriminatorColumn); + } + + public function testAddDiscriminatorMapClass() + { + $this->assertIsFluent($this->builder->addDiscriminatorMapClass('test', 'Doctrine\Tests\Models\CMS\CmsUser')); + $this->assertIsFluent($this->builder->addDiscriminatorMapClass('test2', 'Doctrine\Tests\Models\CMS\CmsGroup')); + + $this->assertEquals(array('test' => 'Doctrine\Tests\Models\CMS\CmsUser', 'test2' => 'Doctrine\Tests\Models\CMS\CmsGroup'), $this->cm->discriminatorMap); + $this->assertEquals('test', $this->cm->discriminatorValue); + } + + public function testChangeTrackingPolicyExplicit() + { + $this->assertIsFluent($this->builder->setChangeTrackingPolicyDeferredExplicit()); + $this->assertEquals(ClassMetadata::CHANGETRACKING_DEFERRED_EXPLICIT, $this->cm->changeTrackingPolicy); + } + + public function testChangeTrackingPolicyNotify() + { + $this->assertIsFluent($this->builder->setChangeTrackingPolicyNotify()); + $this->assertEquals(ClassMetadata::CHANGETRACKING_NOTIFY, $this->cm->changeTrackingPolicy); + } + + public function testAddField() + { + $this->assertIsFluent($this->builder->addField('name', 'string')); + $this->assertEquals(array('columnName' => 'name', 'fieldName' => 'name', 'type' => 'string'), $this->cm->fieldMappings['name']); + } + + public function testCreateField() + { + $fieldBuilder = ($this->builder->createField('name', 'string')); + $this->assertInstanceOf('Doctrine\ORM\Mapping\Builder\FieldBuilder', $fieldBuilder); + + $this->assertFalse(isset($this->cm->fieldMappings['name'])); + $this->assertIsFluent($fieldBuilder->build()); + $this->assertEquals(array('columnName' => 'name', 'fieldName' => 'name', 'type' => 'string'), $this->cm->fieldMappings['name']); + } + + public function testCreateVersionedField() + { + $this->builder->createField('name', 'integer')->columnName('username')->length(124)->nullable()->columnDefinition('foobar')->unique()->isVersionField()->build(); + $this->assertEquals(array( + 'columnDefinition' => 'foobar', + 'columnName' => 'username', + 'default' => 1, + 'fieldName' => 'name', + 'length' => 124, + 'type' => 'integer', + 'nullable' => true, + 'unique' => true, + ), $this->cm->fieldMappings['name']); + } + + public function testCreatePrimaryField() + { + $this->builder->createField('id', 'integer')->isPrimaryKey()->generatedValue()->build(); + + $this->assertEquals(array('id'), $this->cm->identifier); + $this->assertEquals(array('columnName' => 'id', 'fieldName' => 'id', 'id' => true, 'type' => 'integer'), $this->cm->fieldMappings['id']); + } + + public function testAddLifecycleEvent() + { + $this->builder->addLifecycleEvent('getStatus', 'postLoad'); + + $this->assertEquals(array('postLoad' => array('getStatus')), $this->cm->lifecycleCallbacks); + } + + public function testCreateManyToOne() + { + $this->assertIsFluent( + $this->builder->createManyToOne('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') + ->addJoinColumn('group_id', 'id', true, false, 'CASCADE') + ->cascadeAll() + ->fetchExtraLazy() + ->build() + ); + + $this->assertEquals(array('groups' => array ( + 'fieldName' => 'groups', + 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsGroup', + 'cascade' => array ( + 0 => 'remove', + 1 => 'persist', + 2 => 'refresh', + 3 => 'merge', + 4 => 'detach', + ), + 'fetch' => 4, + 'joinColumns' => array ( + 0 => + array ( + 'name' => 'group_id', + 'referencedColumnName' => 'id', + 'nullable' => true, + 'unique' => false, + 'onDelete' => 'CASCADE', + 'columnDefinition' => NULL, + ), + ), + 'type' => 2, + 'mappedBy' => NULL, + 'inversedBy' => NULL, + 'isOwningSide' => true, + 'sourceEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', + 'isCascadeRemove' => true, + 'isCascadePersist' => true, + 'isCascadeRefresh' => true, + 'isCascadeMerge' => true, + 'isCascadeDetach' => true, + 'sourceToTargetKeyColumns' => + array ( + 'group_id' => 'id', + ), + 'joinColumnFieldNames' => + array ( + 'group_id' => 'group_id', + ), + 'targetToSourceKeyColumns' => + array ( + 'id' => 'group_id', + ), + 'orphanRemoval' => false, + ), + ), $this->cm->associationMappings); + } + + public function testCreateOneToOne() + { + $this->assertIsFluent( + $this->builder->createOneToOne('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') + ->addJoinColumn('group_id', 'id', true, false, 'CASCADE') + ->cascadeAll() + ->fetchExtraLazy() + ->build() + ); + + $this->assertEquals(array('groups' => array ( + 'fieldName' => 'groups', + 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsGroup', + 'cascade' => array ( + 0 => 'remove', + 1 => 'persist', + 2 => 'refresh', + 3 => 'merge', + 4 => 'detach', + ), + 'fetch' => 4, + 'joinColumns' => array ( + 0 => + array ( + 'name' => 'group_id', + 'referencedColumnName' => 'id', + 'nullable' => true, + 'unique' => true, + 'onDelete' => 'CASCADE', + 'columnDefinition' => NULL, + ), + ), + 'type' => 1, + 'mappedBy' => NULL, + 'inversedBy' => NULL, + 'isOwningSide' => true, + 'sourceEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', + 'isCascadeRemove' => true, + 'isCascadePersist' => true, + 'isCascadeRefresh' => true, + 'isCascadeMerge' => true, + 'isCascadeDetach' => true, + 'sourceToTargetKeyColumns' => + array ( + 'group_id' => 'id', + ), + 'joinColumnFieldNames' => + array ( + 'group_id' => 'group_id', + ), + 'targetToSourceKeyColumns' => + array ( + 'id' => 'group_id', + ), + 'orphanRemoval' => false, + ), + ), $this->cm->associationMappings); + } + + public function testCreateManyToMany() + { + $this->assertIsFluent( + $this->builder->createManyToMany('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') + ->setJoinTable('groups_users') + ->addJoinColumn('group_id', 'id', true, false, 'CASCADE') + ->addInverseJoinColumn('user_id', 'id') + ->cascadeAll() + ->fetchExtraLazy() + ->build() + ); + + $this->assertEquals(array( + 'groups' => + array( + 'fieldName' => 'groups', + 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsGroup', + 'cascade' => + array( + 0 => 'remove', + 1 => 'persist', + 2 => 'refresh', + 3 => 'merge', + 4 => 'detach', + ), + 'fetch' => 4, + 'joinTable' => + array( + 'joinColumns' => + array( + 0 => + array( + 'name' => 'group_id', + 'referencedColumnName' => 'id', + 'nullable' => true, + 'unique' => false, + 'onDelete' => 'CASCADE', + 'columnDefinition' => NULL, + ), + ), + 'inverseJoinColumns' => + array( + 0 => + array( + 'name' => 'user_id', + 'referencedColumnName' => 'id', + 'nullable' => true, + 'unique' => false, + 'onDelete' => NULL, + 'columnDefinition' => NULL, + ), + ), + 'name' => 'groups_users', + ), + 'type' => 8, + 'mappedBy' => NULL, + 'inversedBy' => NULL, + 'isOwningSide' => true, + 'sourceEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', + 'isCascadeRemove' => true, + 'isCascadePersist' => true, + 'isCascadeRefresh' => true, + 'isCascadeMerge' => true, + 'isCascadeDetach' => true, + 'isOnDeleteCascade' => true, + 'relationToSourceKeyColumns' => + array( + 'group_id' => 'id', + ), + 'joinTableColumns' => + array( + 0 => 'group_id', + 1 => 'user_id', + ), + 'relationToTargetKeyColumns' => + array( + 'user_id' => 'id', + ), + ), + ), $this->cm->associationMappings); + } + + public function testCreateOneToMany() + { + $this->assertIsFluent( + $this->builder->createOneToMany('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') + ->mappedBy('test') + ->setOrderBy(array('test')) + ->setIndexBy('test') + ->build() + ); + + $this->assertEquals(array( + 'groups' => + array( + 'fieldName' => 'groups', + 'targetEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsGroup', + 'mappedBy' => 'test', + 'orderBy' => + array( + 0 => 'test', + ), + 'indexBy' => 'test', + 'type' => 4, + 'inversedBy' => NULL, + 'isOwningSide' => false, + 'sourceEntity' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', + 'fetch' => 2, + 'cascade' => + array( + ), + 'isCascadeRemove' => false, + 'isCascadePersist' => false, + 'isCascadeRefresh' => false, + 'isCascadeMerge' => false, + 'isCascadeDetach' => false, + 'orphanRemoval' => false, + ), + ), $this->cm->associationMappings); + } + + public function assertIsFluent($ret) + { + $this->assertSame($this->builder, $ret, "Return Value has to be same instance as used builder"); + } +} diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index 72a49a701..dbb82f054 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -67,10 +67,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase { require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php"; - $reader = new \Doctrine\Common\Annotations\AnnotationReader(new \Doctrine\Common\Cache\ArrayCache); - $reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\'); - $metadataDriver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader); - $metadataDriver->addPaths(array(__DIR__ . '/../../Models/Global/')); + $metadataDriver = $this->createAnnotationDriver(array(__DIR__ . '/../../Models/Global/')); $entityManager = $this->_createEntityManager($metadataDriver); diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php index 8f57280df..fed31d9c5 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php @@ -16,7 +16,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase // Test initial state $this->assertTrue(count($cm->getReflectionProperties()) == 0); - $this->assertTrue($cm->reflClass instanceof \ReflectionClass); + $this->assertInstanceOf('ReflectionClass', $cm->reflClass); $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->name); $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->rootEntityName); $this->assertEquals(array(), $cm->subClasses); @@ -40,12 +40,12 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase // Check state $this->assertTrue(count($cm->getReflectionProperties()) > 0); $this->assertEquals('Doctrine\Tests\Models\CMS', $cm->namespace); - $this->assertTrue($cm->reflClass instanceof \ReflectionClass); + $this->assertInstanceOf('ReflectionClass', $cm->reflClass); $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->name); $this->assertEquals('UserParent', $cm->rootEntityName); $this->assertEquals(array('Doctrine\Tests\Models\CMS\One', 'Doctrine\Tests\Models\CMS\Two', 'Doctrine\Tests\Models\CMS\Three'), $cm->subClasses); $this->assertEquals(array('UserParent'), $cm->parentClasses); - $this->assertEquals('UserRepository', $cm->customRepositoryClassName); + $this->assertEquals('Doctrine\Tests\Models\CMS\UserRepository', $cm->customRepositoryClassName); $this->assertEquals(array('name' => 'disc', 'type' => 'integer', 'fieldName' => 'disc'), $cm->discriminatorColumn); $this->assertTrue($cm->associationMappings['phonenumbers']['type'] == ClassMetadata::ONE_TO_ONE); $this->assertEquals(1, count($cm->associationMappings)); @@ -105,7 +105,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase )); $assoc = $cm->associationMappings['groups']; - //$this->assertTrue($assoc instanceof \Doctrine\ORM\Mapping\ManyToManyMapping); + //$this->assertInstanceOf('Doctrine\ORM\Mapping\ManyToManyMapping', $assoc); $this->assertEquals(array( 'name' => 'cmsuser_cmsgroup', 'joinColumns' => array(array('name' => 'cmsuser_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE')), @@ -236,6 +236,17 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase $this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); } + + /** + * @group DDC-1224 + */ + public function testGetTemporaryTableNameSchema() + { + $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm->setTableName('foo.bar'); + + $this->assertEquals('foo_bar_id_tmp', $cm->getTemporaryIdTableName()); + } public function testDefaultTableName() { @@ -460,4 +471,15 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase $cm = new ClassMetadata('DOCTRINE\TESTS\MODELS\CMS\CMSUSER'); $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->name); } + + /** + * @group DDC-659 + */ + public function testLifecycleCallbackNotFound() + { + $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + + $this->setExpectedException("Doctrine\ORM\Mapping\MappingException", "Entity 'Doctrine\Tests\Models\CMS\CmsUser' has no method 'notfound' to be registered as lifecycle callback."); + $cm->addLifecycleCallback('notfound', 'postLoad'); + } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/DriverChainTest.php b/tests/Doctrine/Tests/ORM/Mapping/DriverChainTest.php index d218aaf8f..dc8bc695d 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/DriverChainTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/DriverChainTest.php @@ -81,12 +81,9 @@ class DriverChainTest extends \Doctrine\Tests\OrmTestCase * @group DDC-706 */ public function testIsTransient() - { - $reader = new \Doctrine\Common\Annotations\AnnotationReader(new \Doctrine\Common\Cache\ArrayCache()); - $reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\'); - + { $chain = new DriverChain(); - $chain->addDriver(new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, array()), 'Doctrine\Tests\Models\CMS'); + $chain->addDriver($this->createAnnotationDriver(), 'Doctrine\Tests\Models\CMS'); $this->assertTrue($chain->isTransient('stdClass'), "stdClass isTransient"); $this->assertFalse($chain->isTransient('Doctrine\Tests\Models\CMS\CmsUser'), "CmsUser is not Transient"); diff --git a/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php new file mode 100644 index 000000000..d16db4fbb --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/Symfony/AbstractDriverTest.php @@ -0,0 +1,113 @@ +. +*/ + +namespace Doctrine\Tests\ORM\Mapping\Symfony; + +/** + * @group DDC-1418 + */ +abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase +{ + public function testFindMappingFile() + { + $driver = $this->getDriver(array( + 'MyNamespace\MySubnamespace\EntityFoo' => 'foo', + 'MyNamespace\MySubnamespace\Entity' => $this->dir, + )); + + touch($filename = $this->dir.'/Foo'.$this->getFileExtension()); + $this->assertEquals($filename, $this->invoke($driver, '_findMappingFile', array('MyNamespace\MySubnamespace\Entity\Foo'))); + } + + public function testFindMappingFileInSubnamespace() + { + $driver = $this->getDriver(array( + 'MyNamespace\MySubnamespace\Entity' => $this->dir, + )); + + touch($filename = $this->dir.'/Foo.Bar'.$this->getFileExtension()); + $this->assertEquals($filename, $this->invoke($driver, '_findMappingFile', array('MyNamespace\MySubnamespace\Entity\Foo\Bar'))); + } + + public function testFindMappingFileNamespacedFoundFileNotFound() + { + $this->setExpectedException( + 'Doctrine\ORM\Mapping\MappingException', + "No mapping file found named '".$this->dir."/Foo".$this->getFileExtension()."' for class 'MyNamespace\MySubnamespace\Entity\Foo'." + ); + + $driver = $this->getDriver(array( + 'MyNamespace\MySubnamespace\Entity' => $this->dir, + )); + + $this->invoke($driver, '_findMappingFile', array('MyNamespace\MySubnamespace\Entity\Foo')); + } + + public function testFindMappingNamespaceNotFound() + { + $this->setExpectedException( + 'Doctrine\ORM\Mapping\MappingException', + "No mapping file found named 'Foo".$this->getFileExtension()."' for class 'MyOtherNamespace\MySubnamespace\Entity\Foo'." + ); + + $driver = $this->getDriver(array( + 'MyNamespace\MySubnamespace\Entity' => $this->dir, + )); + + $this->invoke($driver, '_findMappingFile', array('MyOtherNamespace\MySubnamespace\Entity\Foo')); + } + + protected function setUp() + { + $this->dir = sys_get_temp_dir().'/abstract_driver_test'; + @mkdir($this->dir, 0777, true); + } + + protected function tearDown() + { + $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->dir), \RecursiveIteratorIterator::CHILD_FIRST); + + foreach ($iterator as $path) { + if ($path->isDir()) { + @rmdir($path); + } else { + @unlink($path); + } + } + + @rmdir($this->dir); + } + + 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 new file mode 100644 index 000000000..5908b674a --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/Symfony/XmlDriverTest.php @@ -0,0 +1,40 @@ +. +*/ + +namespace Doctrine\Tests\ORM\Mapping\Symfony; + +use \Doctrine\ORM\Mapping\Driver\SimplifiedXmlDriver; + +/** + * @group DDC-1418 + */ +class XmlDriverTest extends AbstractDriverTest +{ + protected function getFileExtension() + { + return '.orm.xml'; + } + + protected function getDriver(array $paths = array()) + { + $driver = new SimplifiedXmlDriver(array_flip($paths)); + + return $driver; + } +} diff --git a/tests/Doctrine/Tests/ORM/Mapping/Symfony/YamlDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/Symfony/YamlDriverTest.php new file mode 100644 index 000000000..c5d8d1cd1 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/Symfony/YamlDriverTest.php @@ -0,0 +1,40 @@ +. +*/ + +namespace Doctrine\Tests\ORM\Mapping\Symfony; + +use \Doctrine\ORM\Mapping\Driver\SimplifiedYamlDriver; + +/** + * @group DDC-1418 + */ +class YamlDriverTest extends AbstractDriverTest +{ + protected function getFileExtension() + { + return '.orm.yml'; + } + + protected function getDriver(array $paths = array()) + { + $driver = new SimplifiedYamlDriver(array_flip($paths)); + + return $driver; + } +} diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.php new file mode 100644 index 000000000..ad8b86d9e --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.php @@ -0,0 +1,5 @@ +mapField(array( + 'fieldName' => 'serialNumber', + 'type' => 'string', +)); \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.php new file mode 100644 index 000000000..1318333a8 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.php @@ -0,0 +1,5 @@ +mapField(array( + 'fieldName' => 'creditCardNumber', + 'type' => 'string', +)); \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869Payment.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869Payment.php new file mode 100644 index 000000000..1d1f551ba --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869Payment.php @@ -0,0 +1,17 @@ +mapField(array( + 'id' => true, + 'fieldName' => 'id', + 'type' => 'integer', + 'columnName' => 'id', +)); +$metadata->mapField(array( + 'fieldName' => 'value', + 'type' => 'float', + )); +$metadata->isMappedSuperclass = true; +$metadata->setCustomRepositoryClass("Doctrine\Tests\Models\DDC869\DDC869PaymentRepository"); +$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php index 2abe648ad..2039578a3 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php @@ -51,7 +51,6 @@ $metadata->mapOneToOne(array( 'name' => 'address_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE', - 'onUpdate' => 'CASCADE' ), ), 'orphanRemoval' => false, @@ -64,7 +63,7 @@ $metadata->mapOneToMany(array( 1 => 'persist', ), 'mappedBy' => 'user', - 'orphanRemoval' => false, + 'orphanRemoval' => true, 'orderBy' => array( 'number' => 'ASC', diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.dcm.xml new file mode 100644 index 000000000..05e2540ef --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.dcm.xml @@ -0,0 +1,11 @@ + + + + + + + + \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.dcm.xml new file mode 100644 index 000000000..daf01f034 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.dcm.xml @@ -0,0 +1,11 @@ + + + + + + + + \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869Payment.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869Payment.dcm.xml new file mode 100644 index 000000000..be9f760b9 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869Payment.dcm.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml index c066cbef1..f116fb0fe 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml @@ -39,7 +39,7 @@ - + diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.dcm.yml new file mode 100644 index 000000000..94f269817 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.dcm.yml @@ -0,0 +1,5 @@ +Doctrine\Tests\Models\DDC869\DDC869ChequePayment: + type: entity + fields: + serialNumber: + type: string \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.dcm.yml new file mode 100644 index 000000000..153a99fa7 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.dcm.yml @@ -0,0 +1,5 @@ +Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment: + type: entity + fields: + creditCardNumber: + type: string \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC869.DDC869Payment.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC869.DDC869Payment.dcm.yml new file mode 100644 index 000000000..b776664e1 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC869.DDC869Payment.dcm.yml @@ -0,0 +1,12 @@ +Doctrine\Tests\Models\DDC869\DDC869Payment: + type: mappedSuperclass + repositoryClass : Doctrine\Tests\Models\DDC869\DDC869PaymentRepository + id: + id: + type: integer + unsigned: true + generator: + strategy: AUTO + fields: + value: + type: float \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml index a787a93c9..333474981 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml @@ -30,11 +30,11 @@ Doctrine\Tests\ORM\Mapping\User: name: address_id referencedColumnName: id onDelete: CASCADE - onUpdate: CASCADE cascade: [ remove ] oneToMany: phonenumbers: targetEntity: Phonenumber + orphanRemoval: true mappedBy: user orderBy: number: ASC diff --git a/tests/Doctrine/Tests/ORM/Performance/AllTests.php b/tests/Doctrine/Tests/ORM/Performance/AllTests.php deleted file mode 100644 index b4a993bb2..000000000 --- a/tests/Doctrine/Tests/ORM/Performance/AllTests.php +++ /dev/null @@ -1,32 +0,0 @@ -addTestSuite('Doctrine\Tests\ORM\Performance\HydrationPerformanceTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Performance\InsertPerformanceTest'); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Orm_Performance_AllTests::main') { - AllTests::main(); -} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php index a8a16e428..01f02c0d9 100644 --- a/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php @@ -15,6 +15,7 @@ use Doctrine\Tests\Mocks\HydratorMockStatement, * seriously degrade performance. * * @author robo + * @group performance */ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase { diff --git a/tests/Doctrine/Tests/ORM/Performance/InheritancePersisterPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/InheritancePersisterPerformanceTest.php index 01113f21b..1c192648a 100644 --- a/tests/Doctrine/Tests/ORM/Performance/InheritancePersisterPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/InheritancePersisterPerformanceTest.php @@ -7,6 +7,9 @@ use Doctrine\ORM\Query; require_once __DIR__ . '/../../TestInit.php'; +/** +* @group performance + */ class InheritancePersisterPerformanceTest extends \Doctrine\Tests\OrmFunctionalTestCase { protected function setUp() diff --git a/tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php index 97466e69f..cccc480a2 100644 --- a/tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php @@ -10,6 +10,7 @@ use Doctrine\Tests\Models\CMS\CmsUser; * Description of InsertPerformanceTest * * @author robo + * @group performance */ class InsertPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase { diff --git a/tests/Doctrine/Tests/ORM/Performance/PersisterPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/PersisterPerformanceTest.php index bbd4f445f..ec432689d 100644 --- a/tests/Doctrine/Tests/ORM/Performance/PersisterPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/PersisterPerformanceTest.php @@ -13,6 +13,9 @@ use Doctrine\Tests\Models\CMS\CmsComment; require_once __DIR__ . '/../../TestInit.php'; +/** + * @group performance + */ class PersisterPerformanceTest extends \Doctrine\Tests\OrmFunctionalTestCase { protected function setUp() diff --git a/tests/Doctrine/Tests/ORM/Performance/UnitOfWorkPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/UnitOfWorkPerformanceTest.php index 28d9ea6d3..650228ba4 100644 --- a/tests/Doctrine/Tests/ORM/Performance/UnitOfWorkPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/UnitOfWorkPerformanceTest.php @@ -10,6 +10,7 @@ use Doctrine\Tests\Models\CMS\CmsUser; * Description of InsertPerformanceTest * * @author robo + * @group performance */ class UnitOfWorkPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase { diff --git a/tests/Doctrine/Tests/ORM/Proxy/AllTests.php b/tests/Doctrine/Tests/ORM/Proxy/AllTests.php deleted file mode 100644 index aeaff5848..000000000 --- a/tests/Doctrine/Tests/ORM/Proxy/AllTests.php +++ /dev/null @@ -1,30 +0,0 @@ -addTestSuite('Doctrine\Tests\ORM\Proxy\ProxyClassGeneratorTest'); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Orm_Proxy_AllTests::main') { - AllTests::main(); -} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Query/AllTests.php b/tests/Doctrine/Tests/ORM/Query/AllTests.php deleted file mode 100644 index 0d94856f9..000000000 --- a/tests/Doctrine/Tests/ORM/Query/AllTests.php +++ /dev/null @@ -1,37 +0,0 @@ -addTestSuite('Doctrine\Tests\ORM\Query\SelectSqlGenerationTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Query\LanguageRecognitionTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Query\LexerTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Query\DeleteSqlGenerationTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Query\UpdateSqlGenerationTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Query\ExprTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Query\ParserResultTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Query\QueryTest'); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Orm_Query_AllTests::main') { - AllTests::main(); -} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php b/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php index 2733d80f7..cf9575869 100644 --- a/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php +++ b/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php @@ -570,6 +570,16 @@ class LanguageRecognitionTest extends \Doctrine\Tests\OrmTestCase { $this->assertValidDQL("SELECT e, t FROM Doctrine\Tests\Models\DDC117\DDC117Editor e JOIN e.reviewingTranslations t WHERE SIZE(e.reviewingTranslations) > 0"); } + + public function testCaseSupportContainingNullIfExpression() + { + $this->assertValidDQL("SELECT u.id, NULLIF(u.name, u.name) AS shouldBeNull FROM Doctrine\Tests\Models\CMS\CmsUser u"); + } + + public function testCaseSupportContainingCoalesceExpression() + { + $this->assertValidDQL("select COALESCE(NULLIF(u.name, ''), u.username) as Display FROM Doctrine\Tests\Models\CMS\CmsUser u"); + } } /** @Entity */ diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 2d0101e03..8e1585819 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -33,13 +33,13 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase } $query->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true) - ->useQueryCache(false); + ->useQueryCache(false); foreach ($queryHints AS $name => $value) { $query->setHint($name, $value); } - - parent::assertEquals($sqlToBeConfirmed, $query->getSql()); + + parent::assertEquals($sqlToBeConfirmed, $query->getSQL()); $query->free(); } catch (\Exception $e) { $this->fail($e->getMessage() ."\n".$e->getTraceAsString()); @@ -65,7 +65,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase } $query->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true) - ->useQueryCache(false); + ->useQueryCache(false); foreach ($queryHints AS $name => $value) { $query->setHint($name, $value); @@ -380,7 +380,37 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase { $this->assertSqlGeneration( "SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF Doctrine\Tests\Models\Company\CompanyEmployee", - "SELECT c0_.id AS id0, c0_.name AS name1, c0_.discr AS discr2 FROM company_persons c0_ WHERE c0_.discr = 'employee'" + "SELECT c0_.id AS id0, c0_.name AS name1, c0_.discr AS discr2 FROM company_persons c0_ WHERE c0_.discr IN ('employee')" + ); + } + + public function testSupportsInstanceOfExpressionInWherePartWithMultipleValues() + { + $this->assertSqlGeneration( + "SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF (Doctrine\Tests\Models\Company\CompanyEmployee, \Doctrine\Tests\Models\Company\CompanyManager)", + "SELECT c0_.id AS id0, c0_.name AS name1, c0_.discr AS discr2 FROM company_persons c0_ WHERE c0_.discr IN ('employee', 'manager')" + ); + } + + /** + * @group DDC-1194 + */ + public function testSupportsInstanceOfExpressionsInWherePartPrefixedSlash() + { + $this->assertSqlGeneration( + "SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF \Doctrine\Tests\Models\Company\CompanyEmployee", + "SELECT c0_.id AS id0, c0_.name AS name1, c0_.discr AS discr2 FROM company_persons c0_ WHERE c0_.discr IN ('employee')" + ); + } + + /** + * @group DDC-1194 + */ + public function testSupportsInstanceOfExpressionsInWherePartWithUnrelatedClass() + { + $this->assertInvalidSqlGeneration( + "SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF \Doctrine\Tests\Models\CMS\CmsUser", + "Doctrine\ORM\Query\QueryException" ); } @@ -388,7 +418,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase { $this->assertSqlGeneration( "SELECT u FROM Doctrine\Tests\Models\Company\CompanyEmployee u WHERE u INSTANCE OF Doctrine\Tests\Models\Company\CompanyManager", - "SELECT c0_.id AS id0, c0_.name AS name1, c1_.salary AS salary2, c1_.department AS department3, c0_.discr AS discr4 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id WHERE c0_.discr = 'manager'" + "SELECT c0_.id AS id0, c0_.name AS name1, c1_.salary AS salary2, c1_.department AS department3, c1_.startDate AS startDate4, c0_.discr AS discr5 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id WHERE c0_.discr IN ('manager')" ); } @@ -396,7 +426,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase { $this->assertSqlGeneration( "SELECT u FROM Doctrine\Tests\Models\Company\CompanyManager u WHERE u INSTANCE OF Doctrine\Tests\Models\Company\CompanyManager", - "SELECT c0_.id AS id0, c0_.name AS name1, c1_.salary AS salary2, c1_.department AS department3, c2_.title AS title4, c0_.discr AS discr5 FROM company_managers c2_ INNER JOIN company_employees c1_ ON c2_.id = c1_.id INNER JOIN company_persons c0_ ON c2_.id = c0_.id WHERE c0_.discr = 'manager'" + "SELECT c0_.id AS id0, c0_.name AS name1, c1_.salary AS salary2, c1_.department AS department3, c1_.startDate AS startDate4, c2_.title AS title5, c0_.discr AS discr6 FROM company_managers c2_ INNER JOIN company_employees c1_ ON c2_.id = c1_.id INNER JOIN company_persons c0_ ON c2_.id = c0_.id WHERE c0_.discr IN ('manager')" ); } @@ -404,7 +434,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase { $this->assertSqlGeneration( "SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF ?1", - "SELECT c0_.id AS id0, c0_.name AS name1, c0_.discr AS discr2 FROM company_persons c0_ WHERE c0_.discr = 'employee'", + "SELECT c0_.id AS id0, c0_.name AS name1, c0_.discr AS discr2 FROM company_persons c0_ WHERE c0_.discr IN ('employee')", array(), array(1 => $this->_em->getClassMetadata('Doctrine\Tests\Models\Company\CompanyEmployee')) ); } @@ -533,7 +563,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $this->_em->getClassMetadata(get_class($person))->setIdentifierValues($person, array('id' => 101)); $q3->setParameter('param', $person); $this->assertEquals( - 'SELECT c0_.id AS id0, c0_.name AS name1, c1_.title AS title2, c1_.car_id AS car_id3, c2_.salary AS salary4, c2_.department AS department5, c0_.discr AS discr6, c0_.spouse_id AS spouse_id7 FROM company_persons c0_ LEFT JOIN company_managers c1_ ON c0_.id = c1_.id LEFT JOIN company_employees c2_ ON c0_.id = c2_.id WHERE EXISTS (SELECT 1 FROM company_persons_friends c3_ INNER JOIN company_persons c4_ ON c3_.friend_id = c4_.id WHERE c3_.person_id = c0_.id AND c4_.id = ?)', + 'SELECT c0_.id AS id0, c0_.name AS name1, c1_.title AS title2, c1_.car_id AS car_id3, c2_.salary AS salary4, c2_.department AS department5, c2_.startDate AS startDate6, c0_.discr AS discr7, c0_.spouse_id AS spouse_id8 FROM company_persons c0_ LEFT JOIN company_managers c1_ ON c0_.id = c1_.id LEFT JOIN company_employees c2_ ON c0_.id = c2_.id WHERE EXISTS (SELECT 1 FROM company_persons_friends c3_ INNER JOIN company_persons c4_ ON c3_.friend_id = c4_.id WHERE c3_.person_id = c0_.id AND c4_.id = ?)', $q3->getSql() ); } @@ -584,7 +614,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u') ->setMaxResults(10); - $this->assertEquals('SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ LIMIT 10', $q->getSql()); + $this->assertEquals('SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, c0_.email_id AS email_id4 FROM cms_users c0_ LIMIT 10', $q->getSql()); } public function testLimitAndOffsetFromQueryClass() @@ -594,7 +624,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ->setMaxResults(10) ->setFirstResult(0); - $this->assertEquals('SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ LIMIT 10 OFFSET 0', $q->getSql()); + $this->assertEquals('SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, c0_.email_id AS email_id4 FROM cms_users c0_ LIMIT 10 OFFSET 0', $q->getSql()); } public function testSizeFunction() @@ -656,6 +686,23 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase "SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, (SELECT COUNT(*) FROM cms_articles c1_ WHERE c1_.user_id = c0_.id) AS sclr4 FROM cms_users c0_ ORDER BY sclr4 ASC" ); } + + public function testOrderBySupportsSingleValuedPathExpressionOwningSide() + { + $this->assertSqlGeneration( + "select a from Doctrine\Tests\Models\CMS\CmsArticle a order by a.user", + "SELECT c0_.id AS id0, c0_.topic AS topic1, c0_.text AS text2, c0_.version AS version3 FROM cms_articles c0_ ORDER BY c0_.user_id ASC" + ); + } + + /** + * @expectedException Doctrine\ORM\Query\QueryException + */ + public function testOrderBySupportsSingleValuedPathExpressionInverseSide() + { + $q = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u order by u.address"); + $q->getSQL(); + } public function testBooleanLiteralInWhereOnSqlite() { @@ -682,12 +729,12 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $this->assertSqlGeneration( "SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = true", - "SELECT b0_.id AS id0, b0_.booleanField AS booleanField1 FROM boolean_model b0_ WHERE b0_.booleanField = 'true'" + "SELECT b0_.id AS id0, b0_.booleanField AS booleanField1 FROM boolean_model b0_ WHERE b0_.booleanField = true" ); $this->assertSqlGeneration( "SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = false", - "SELECT b0_.id AS id0, b0_.booleanField AS booleanField1 FROM boolean_model b0_ WHERE b0_.booleanField = 'false'" + "SELECT b0_.id AS id0, b0_.booleanField AS booleanField1 FROM boolean_model b0_ WHERE b0_.booleanField = false" ); $this->_em->getConnection()->setDatabasePlatform($oldPlat); @@ -884,6 +931,314 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase 'SELECT c0_.id AS id0, c0_.name AS name1, count(c1_.id) AS sclr2 FROM cms_groups c0_ INNER JOIN cms_users_groups c2_ ON c0_.id = c2_.group_id INNER JOIN cms_users c1_ ON c1_.id = c2_.user_id GROUP BY c0_.id' ); } + + public function testCaseContainingNullIf() + { + $this->assertSqlGeneration( + "SELECT NULLIF(g.id, g.name) AS NullIfEqual FROM Doctrine\Tests\Models\CMS\CmsGroup g", + 'SELECT NULLIF(c0_.id, c0_.name) AS sclr0 FROM cms_groups c0_' + ); + } + + public function testCaseContainingCoalesce() + { + $this->assertSqlGeneration( + "SELECT COALESCE(NULLIF(u.name, ''), u.username) as Display FROM Doctrine\Tests\Models\CMS\CmsUser u", + "SELECT COALESCE(NULLIF(c0_.name, ''), c0_.username) AS sclr0 FROM cms_users c0_" + ); + } + + /** + * Test that the right discriminator data is inserted in a subquery. + */ + public function testSubSelectDiscriminator() + { + $this->assertSqlGeneration( + "SELECT u.name, (SELECT COUNT(cfc.id) total FROM Doctrine\Tests\Models\Company\CompanyFixContract cfc) as cfc_count FROM Doctrine\Tests\Models\CMS\CmsUser u", + "SELECT c0_.name AS name0, (SELECT COUNT(c1_.id) AS dctrn__total FROM company_contracts c1_ WHERE c1_.discr IN ('fix')) AS sclr1 FROM cms_users c0_" + ); + } + + public function testIdVariableResultVariableReuse() + { + $exceptionThrown = false; + try { + $query = $this->_em->createQuery("SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name IN (SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u)"); + + $query->getSql(); + $query->free(); + } catch (\Exception $e) { + $exceptionThrown = true; + } + + $this->assertTrue($exceptionThrown); + + } + + public function testSubSelectAliasesFromOuterQuery() + { + $this->assertSqlGeneration( + "SELECT uo, (SELECT ui.name FROM Doctrine\Tests\Models\CMS\CmsUser ui WHERE ui.id = uo.id) AS bar FROM Doctrine\Tests\Models\CMS\CmsUser uo", + "SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, (SELECT c1_.name FROM cms_users c1_ WHERE c1_.id = c0_.id) AS sclr4 FROM cms_users c0_" + ); + } + + public function testSubSelectAliasesFromOuterQueryWithSubquery() + { + $this->assertSqlGeneration( + "SELECT uo, (SELECT ui.name FROM Doctrine\Tests\Models\CMS\CmsUser ui WHERE ui.id = uo.id AND ui.name IN (SELECT uii.name FROM Doctrine\Tests\Models\CMS\CmsUser uii)) AS bar FROM Doctrine\Tests\Models\CMS\CmsUser uo", + "SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, (SELECT c1_.name FROM cms_users c1_ WHERE c1_.id = c0_.id AND c1_.name IN (SELECT c2_.name FROM cms_users c2_)) AS sclr4 FROM cms_users c0_" + ); + } + + public function testSubSelectAliasesFromOuterQueryReuseInWhereClause() + { + $this->assertSqlGeneration( + "SELECT uo, (SELECT ui.name FROM Doctrine\Tests\Models\CMS\CmsUser ui WHERE ui.id = uo.id) AS bar FROM Doctrine\Tests\Models\CMS\CmsUser uo WHERE bar = ?0", + "SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, (SELECT c1_.name FROM cms_users c1_ WHERE c1_.id = c0_.id) AS sclr4 FROM cms_users c0_ WHERE sclr4 = ?" + ); + } + + /** + * @group DDC-1298 + */ + public function testSelectForeignKeyPKWithoutFields() + { + $this->assertSqlGeneration( + "SELECT t, s, l FROM Doctrine\Tests\Models\DDC117\DDC117Link l INNER JOIN l.target t INNER JOIN l.source s", + "SELECT d0_.article_id AS article_id0, d0_.title AS title1, d1_.article_id AS article_id2, d1_.title AS title3 FROM DDC117Link d2_ INNER JOIN DDC117Article d0_ ON d2_.target_id = d0_.article_id INNER JOIN DDC117Article d1_ ON d2_.source_id = d1_.article_id" + ); + } + + public function testGeneralCaseWithSingleWhenClause() + { + $this->assertSqlGeneration( + "SELECT g.id, CASE WHEN ((g.id / 2) > 18) THEN 1 ELSE 0 END AS test FROM Doctrine\Tests\Models\CMS\CmsGroup g", + "SELECT c0_.id AS id0, CASE WHEN (c0_.id / 2 > 18) THEN 1 ELSE 0 END AS sclr1 FROM cms_groups c0_" + ); + } + + public function testGeneralCaseWithMultipleWhenClause() + { + $this->assertSqlGeneration( + "SELECT g.id, CASE WHEN (g.id / 2 < 10) THEN 2 WHEN ((g.id / 2) > 20) THEN 1 ELSE 0 END AS test FROM Doctrine\Tests\Models\CMS\CmsGroup g", + "SELECT c0_.id AS id0, CASE WHEN (c0_.id / 2 < 10) THEN 2 WHEN (c0_.id / 2 > 20) THEN 1 ELSE 0 END AS sclr1 FROM cms_groups c0_" + ); + } + + public function testSimpleCaseWithSingleWhenClause() + { + $this->assertSqlGeneration( + "SELECT g FROM Doctrine\Tests\Models\CMS\CmsGroup g WHERE g.id = CASE g.name WHEN 'admin' THEN 1 ELSE 2 END", + "SELECT c0_.id AS id0, c0_.name AS name1 FROM cms_groups c0_ WHERE c0_.id = CASE c0_.name WHEN admin THEN 1 ELSE 2 END" + ); + } + + public function testSimpleCaseWithMultipleWhenClause() + { + $this->assertSqlGeneration( + "SELECT g FROM Doctrine\Tests\Models\CMS\CmsGroup g WHERE g.id = (CASE g.name WHEN 'admin' THEN 1 WHEN 'moderator' THEN 2 ELSE 3 END)", + "SELECT c0_.id AS id0, c0_.name AS name1 FROM cms_groups c0_ WHERE c0_.id = CASE c0_.name WHEN admin THEN 1 WHEN moderator THEN 2 ELSE 3 END" + ); + } + + public function testGeneralCaseWithSingleWhenClauseInSubselect() + { + $this->assertSqlGeneration( + "SELECT g FROM Doctrine\Tests\Models\CMS\CmsGroup g WHERE g.id IN (SELECT CASE WHEN ((g2.id / 2) > 18) THEN 2 ELSE 1 END FROM Doctrine\Tests\Models\CMS\CmsGroup g2)", + "SELECT c0_.id AS id0, c0_.name AS name1 FROM cms_groups c0_ WHERE c0_.id IN (SELECT CASE WHEN (c1_.id / 2 > 18) THEN 2 ELSE 1 END AS sclr2 FROM cms_groups c1_)" + ); + } + + public function testGeneralCaseWithMultipleWhenClauseInSubselect() + { + $this->assertSqlGeneration( + "SELECT g FROM Doctrine\Tests\Models\CMS\CmsGroup g WHERE g.id IN (SELECT CASE WHEN (g.id / 2 < 10) THEN 3 WHEN ((g.id / 2) > 20) THEN 2 ELSE 1 END FROM Doctrine\Tests\Models\CMS\CmsGroup g2)", + "SELECT c0_.id AS id0, c0_.name AS name1 FROM cms_groups c0_ WHERE c0_.id IN (SELECT CASE WHEN (c0_.id / 2 < 10) THEN 3 WHEN (c0_.id / 2 > 20) THEN 2 ELSE 1 END AS sclr2 FROM cms_groups c1_)" + ); + } + + public function testSimpleCaseWithSingleWhenClauseInSubselect() + { + $this->assertSqlGeneration( + "SELECT g FROM Doctrine\Tests\Models\CMS\CmsGroup g WHERE g.id IN (SELECT CASE g2.name WHEN 'admin' THEN 1 ELSE 2 END FROM Doctrine\Tests\Models\CMS\CmsGroup g2)", + "SELECT c0_.id AS id0, c0_.name AS name1 FROM cms_groups c0_ WHERE c0_.id IN (SELECT CASE c1_.name WHEN admin THEN 1 ELSE 2 END AS sclr2 FROM cms_groups c1_)" + ); + } + + public function testSimpleCaseWithMultipleWhenClauseInSubselect() + { + $this->assertSqlGeneration( + "SELECT g FROM Doctrine\Tests\Models\CMS\CmsGroup g WHERE g.id IN (SELECT CASE g2.name WHEN 'admin' THEN 1 WHEN 'moderator' THEN 2 ELSE 3 END FROM Doctrine\Tests\Models\CMS\CmsGroup g2)", + "SELECT c0_.id AS id0, c0_.name AS name1 FROM cms_groups c0_ WHERE c0_.id IN (SELECT CASE c1_.name WHEN admin THEN 1 WHEN moderator THEN 2 ELSE 3 END AS sclr2 FROM cms_groups c1_)" + ); + } + + /** + * @group DDC-1339 + */ + public function testIdentityFunctionInSelectClause() + { + $this->assertSqlGeneration( + "SELECT IDENTITY(u.email) as email_id FROM Doctrine\Tests\Models\CMS\CmsUser u", + "SELECT c0_.email_id AS sclr0 FROM cms_users c0_" + ); + } + + /** + * @group DDC-1339 + */ + public function testIdentityFunctionDoesNotAcceptStateField() + { + $this->assertInvalidSqlGeneration( + "SELECT IDENTITY(u.name) as name FROM Doctrine\Tests\Models\CMS\CmsUser u", + "Doctrine\ORM\Query\QueryException" + ); + } + + /** + * @group DDC-1389 + */ + public function testInheritanceTypeJoinInRootClassWithDisabledForcePartialLoad() + { + $this->assertSqlGeneration( + 'SELECT p FROM Doctrine\Tests\Models\Company\CompanyPerson p', + 'SELECT c0_.id AS id0, c0_.name AS name1, c1_.title AS title2, c1_.car_id AS car_id3, c2_.salary AS salary4, c2_.department AS department5, c2_.startDate AS startDate6, c0_.discr AS discr7, c0_.spouse_id AS spouse_id8 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) + ); + } + + /** + * @group DDC-1389 + */ + public function testInheritanceTypeJoinInRootClassWithEnabledForcePartialLoad() + { + $this->assertSqlGeneration( + 'SELECT p FROM Doctrine\Tests\Models\Company\CompanyPerson p', + 'SELECT c0_.id AS id0, c0_.name AS name1, c0_.discr AS discr2 FROM company_persons c0_', + array(Query::HINT_FORCE_PARTIAL_LOAD => true) + ); + } + + /** + * @group DDC-1389 + */ + public function testInheritanceTypeJoinInChildClassWithDisabledForcePartialLoad() + { + $this->assertSqlGeneration( + 'SELECT e FROM Doctrine\Tests\Models\Company\CompanyEmployee e', + 'SELECT c0_.id AS id0, c0_.name AS name1, c1_.salary AS salary2, c1_.department AS department3, c1_.startDate AS startDate4, c2_.title AS title5, c2_.car_id AS car_id6, c0_.discr AS discr7, c0_.spouse_id AS spouse_id8 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) + ); + } + + /** + * @group DDC-1389 + */ + public function testInheritanceTypeJoinInChildClassWithEnabledForcePartialLoad() + { + $this->assertSqlGeneration( + 'SELECT e FROM Doctrine\Tests\Models\Company\CompanyEmployee e', + 'SELECT c0_.id AS id0, c0_.name AS name1, c1_.salary AS salary2, c1_.department AS department3, c1_.startDate AS startDate4, c0_.discr AS discr5 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id', + array(Query::HINT_FORCE_PARTIAL_LOAD => true) + ); + } + + /** + * @group DDC-1389 + */ + public function testInheritanceTypeJoinInLeafClassWithDisabledForcePartialLoad() + { + $this->assertSqlGeneration( + 'SELECT m FROM Doctrine\Tests\Models\Company\CompanyManager m', + 'SELECT c0_.id AS id0, c0_.name AS name1, c1_.salary AS salary2, c1_.department AS department3, c1_.startDate AS startDate4, c2_.title AS title5, c0_.discr AS discr6, c0_.spouse_id AS spouse_id7, c2_.car_id AS car_id8 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) + ); + } + + /** + * @group DDC-1389 + */ + public function testInheritanceTypeJoinInLeafClassWithEnabledForcePartialLoad() + { + $this->assertSqlGeneration( + 'SELECT m FROM Doctrine\Tests\Models\Company\CompanyManager m', + 'SELECT c0_.id AS id0, c0_.name AS name1, c1_.salary AS salary2, c1_.department AS department3, c1_.startDate AS startDate4, c2_.title AS title5, c0_.discr AS discr6 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) + ); + } + + /** + * @group DDC-1389 + */ + public function testInheritanceTypeSingleTableInRootClassWithDisabledForcePartialLoad() + { + $this->assertSqlGeneration( + 'SELECT c FROM Doctrine\Tests\Models\Company\CompanyContract c', + "SELECT c0_.id AS id0, c0_.completed AS completed1, c0_.fixPrice AS fixPrice2, c0_.hoursWorked AS hoursWorked3, c0_.pricePerHour AS pricePerHour4, c0_.maxPrice AS maxPrice5, c0_.discr AS discr6, c0_.salesPerson_id AS salesPerson_id7 FROM company_contracts c0_ WHERE c0_.discr IN ('fix', 'flexible', 'flexultra')", + array(Query::HINT_FORCE_PARTIAL_LOAD => false) + ); + } + + /** + * @group DDC-1389 + */ + public function testInheritanceTypeSingleTableInRootClassWithEnabledForcePartialLoad() + { + $this->assertSqlGeneration( + 'SELECT c FROM Doctrine\Tests\Models\Company\CompanyContract c', + "SELECT c0_.id AS id0, c0_.completed AS completed1, c0_.fixPrice AS fixPrice2, c0_.hoursWorked AS hoursWorked3, c0_.pricePerHour AS pricePerHour4, c0_.maxPrice AS maxPrice5, c0_.discr AS discr6 FROM company_contracts c0_ WHERE c0_.discr IN ('fix', 'flexible', 'flexultra')", + array(Query::HINT_FORCE_PARTIAL_LOAD => true) + ); + } + + /** + * @group DDC-1389 + */ + public function testInheritanceTypeSingleTableInChildClassWithDisabledForcePartialLoad() + { + $this->assertSqlGeneration( + 'SELECT fc FROM Doctrine\Tests\Models\Company\CompanyFlexContract fc', + "SELECT c0_.id AS id0, c0_.completed AS completed1, c0_.hoursWorked AS hoursWorked2, c0_.pricePerHour AS pricePerHour3, c0_.maxPrice AS maxPrice4, c0_.discr AS discr5, c0_.salesPerson_id AS salesPerson_id6 FROM company_contracts c0_ WHERE c0_.discr IN ('flexible', 'flexultra')", + array(Query::HINT_FORCE_PARTIAL_LOAD => false) + ); + } + + /** + * @group DDC-1389 + */ + public function testInheritanceTypeSingleTableInChildClassWithEnabledForcePartialLoad() + { + $this->assertSqlGeneration( + 'SELECT fc FROM Doctrine\Tests\Models\Company\CompanyFlexContract fc', + "SELECT c0_.id AS id0, c0_.completed AS completed1, c0_.hoursWorked AS hoursWorked2, c0_.pricePerHour AS pricePerHour3, c0_.maxPrice AS maxPrice4, c0_.discr AS discr5 FROM company_contracts c0_ WHERE c0_.discr IN ('flexible', 'flexultra')", + array(Query::HINT_FORCE_PARTIAL_LOAD => true) + ); + } + + /** + * @group DDC-1389 + */ + public function testInheritanceTypeSingleTableInLeafClassWithDisabledForcePartialLoad() + { + $this->assertSqlGeneration( + 'SELECT fuc FROM Doctrine\Tests\Models\Company\CompanyFlexUltraContract fuc', + "SELECT c0_.id AS id0, c0_.completed AS completed1, c0_.hoursWorked AS hoursWorked2, c0_.pricePerHour AS pricePerHour3, c0_.maxPrice AS maxPrice4, c0_.discr AS discr5, c0_.salesPerson_id AS salesPerson_id6 FROM company_contracts c0_ WHERE c0_.discr IN ('flexultra')", + array(Query::HINT_FORCE_PARTIAL_LOAD => false) + ); + } + + /** + * @group DDC-1389 + */ + public function testInheritanceTypeSingleTableInLeafClassWithEnabledForcePartialLoad() + { + $this->assertSqlGeneration( + 'SELECT fuc FROM Doctrine\Tests\Models\Company\CompanyFlexUltraContract fuc', + "SELECT c0_.id AS id0, c0_.completed AS completed1, c0_.hoursWorked AS hoursWorked2, c0_.pricePerHour AS pricePerHour3, c0_.maxPrice AS maxPrice4, c0_.discr AS discr5 FROM company_contracts c0_ WHERE c0_.discr IN ('flexultra')", + array(Query::HINT_FORCE_PARTIAL_LOAD => true) + ); + } } @@ -896,9 +1251,7 @@ class MyAbsFunction extends \Doctrine\ORM\Query\AST\Functions\FunctionNode */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { - return 'ABS(' . $sqlWalker->walkSimpleArithmeticExpression( - $this->simpleArithmeticExpression - ) . ')'; + return 'ABS(' . $sqlWalker->walkSimpleArithmeticExpression($this->simpleArithmeticExpression) . ')'; } /** diff --git a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php index cf570f52c..2b352bdce 100644 --- a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php +++ b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php @@ -197,6 +197,17 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid'); } + + public function testComplexAndWhere() + { + $qb = $this->_em->createQueryBuilder() + ->select('u') + ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->where('u.id = :uid OR u.id = :uid2 OR u.id = :uid3') + ->andWhere('u.name = :name'); + + $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid OR u.id = :uid2 OR u.id = :uid3) AND u.name = :name'); + } public function testAndWhere() { @@ -652,6 +663,15 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals(array('u'), $qb->getRootAliases()); } + public function testGetRootEntities() + { + $qb = $this->_em->createQueryBuilder() + ->select('u') + ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u'); + + $this->assertEquals(array('Doctrine\Tests\Models\CMS\CmsUser'), $qb->getRootEntities()); + } + public function testGetSeveralRootAliases() { $qb = $this->_em->createQueryBuilder() @@ -672,4 +692,44 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.groups g', $qb->getDQL()); } + + /** + * @group DDC-1211 + */ + public function testEmptyStringLiteral() + { + $expr = $this->_em->getExpressionBuilder(); + $qb = $this->_em->createQueryBuilder() + ->select('u') + ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->where($expr->eq('u.username', $expr->literal(""))); + + $this->assertEquals("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = ''", $qb->getDQL()); + } + + /** + * @group DDC-1211 + */ + public function testEmptyNumericLiteral() + { + $expr = $this->_em->getExpressionBuilder(); + $qb = $this->_em->createQueryBuilder() + ->select('u') + ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->where($expr->eq('u.username', $expr->literal(0))); + + $this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 0', $qb->getDQL()); + } + + /** + * @group DDC-1227 + */ + public function testAddFromString() + { + $qb = $this->_em->createQueryBuilder() + ->add('select', 'u') + ->add('from', 'Doctrine\Tests\Models\CMS\CmsUser u'); + + $this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u', $qb->getDQL()); + } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Tools/AllTests.php b/tests/Doctrine/Tests/ORM/Tools/AllTests.php deleted file mode 100644 index 3d9fe929c..000000000 --- a/tests/Doctrine/Tests/ORM/Tools/AllTests.php +++ /dev/null @@ -1,39 +0,0 @@ -addTestSuite('Doctrine\Tests\ORM\Tools\Export\YamlClassMetadataExporterTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Tools\Export\XmlClassMetadataExporterTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Tools\Export\PhpClassMetadataExporterTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Tools\Export\AnnotationClassMetadataExporterTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Tools\ConvertDoctrine1SchemaTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Tools\SchemaToolTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Tools\EntityGeneratorTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Tools\SchemaValidatorTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Tools\Console\Command\ConvertDoctrine1SchemaCommandTest'); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Orm_Tools_AllTests::main') { - AllTests::main(); -} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index d7cd56132..fce7d4c20 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -98,7 +98,7 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase $this->assertTrue(method_exists($metadata->namespace . '\EntityGeneratorBook', 'setAuthor'), "EntityGeneratorBook::setAuthor() missing."); $this->assertTrue(method_exists($metadata->namespace . '\EntityGeneratorBook', 'getAuthor'), "EntityGeneratorBook::getAuthor() missing."); $this->assertTrue(method_exists($metadata->namespace . '\EntityGeneratorBook', 'getComments'), "EntityGeneratorBook::getComments() missing."); - $this->assertTrue(method_exists($metadata->namespace . '\EntityGeneratorBook', 'addComments'), "EntityGeneratorBook::addComments() missing."); + $this->assertTrue(method_exists($metadata->namespace . '\EntityGeneratorBook', 'addEntityGeneratorComment'), "EntityGeneratorBook::addEntityGeneratorComment() missing."); $this->assertEquals('published', $book->getStatus()); @@ -110,7 +110,7 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals($author, $book->getAuthor()); $comment = new EntityGeneratorComment(); - $book->addComments($comment); + $book->addEntityGeneratorComment($comment); $this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $book->getComments()); $this->assertEquals(new \Doctrine\Common\Collections\ArrayCollection(array($comment)), $book->getComments()); } @@ -166,9 +166,7 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase $book = $this->newInstance($metadata); $cm = new \Doctrine\ORM\Mapping\ClassMetadata($metadata->name); - $reader = new \Doctrine\Common\Annotations\AnnotationReader(); - $reader->setDefaultAnnotationNamespace("Doctrine\\ORM\\Mapping\\"); - $driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader); + $driver = $this->createAnnotationDriver(); $driver->loadMetadataForClass($cm->name, $cm); $this->assertEquals($cm->columnNames, $metadata->columnNames); @@ -188,9 +186,7 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase $book = $this->newInstance($metadata); $cm = new \Doctrine\ORM\Mapping\ClassMetadata($metadata->name); - $reader = new \Doctrine\Common\Annotations\AnnotationReader(); - $reader->setAnnotationNamespaceAlias("Doctrine\\ORM\\Mapping\\", "orm"); - $driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader); + $driver = $this->createAnnotationDriver(array(), 'orm'); $driver->loadMetadataForClass($cm->name, $cm); $this->assertEquals($cm->columnNames, $metadata->columnNames); diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php index 4a85918d6..c9bfdccf0 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php @@ -78,7 +78,7 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest $class = 'Doctrine\ORM\Mapping\Driver\\' . $driverName; if ($type === 'annotation') { - $driver = $class::create($path); + $driver = $this->createAnnotationDriver(array($path)); } else { $driver = new $class($path); } @@ -212,18 +212,18 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest public function testOneToOneAssociationsAreExported($class) { $this->assertTrue(isset($class->associationMappings['address'])); - //$this->assertTrue($class->associationMappings['address'] instanceof \Doctrine\ORM\Mapping\OneToOneMapping); + //$this->assertInstanceOf('Doctrine\ORM\Mapping\OneToOneMapping', $class->associationMappings['address']); $this->assertEquals('Doctrine\Tests\ORM\Tools\Export\Address', $class->associationMappings['address']['targetEntity']); $this->assertEquals('address_id', $class->associationMappings['address']['joinColumns'][0]['name']); $this->assertEquals('id', $class->associationMappings['address']['joinColumns'][0]['referencedColumnName']); $this->assertEquals('CASCADE', $class->associationMappings['address']['joinColumns'][0]['onDelete']); - $this->assertEquals('CASCADE', $class->associationMappings['address']['joinColumns'][0]['onUpdate']); $this->assertTrue($class->associationMappings['address']['isCascadeRemove']); - $this->assertFalse($class->associationMappings['address']['isCascadePersist']); + $this->assertTrue($class->associationMappings['address']['isCascadePersist']); $this->assertFalse($class->associationMappings['address']['isCascadeRefresh']); $this->assertFalse($class->associationMappings['address']['isCascadeMerge']); $this->assertFalse($class->associationMappings['address']['isCascadeDetach']); + $this->assertTrue($class->associationMappings['address']['orphanRemoval']); return $class; } @@ -235,16 +235,17 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest public function testOneToManyAssociationsAreExported($class) { $this->assertTrue(isset($class->associationMappings['phonenumbers'])); - //$this->assertTrue($class->associationMappings['phonenumbers'] instanceof \Doctrine\ORM\Mapping\OneToManyMapping); + //$this->assertInstanceOf('Doctrine\ORM\Mapping\OneToManyMapping', $class->associationMappings['phonenumbers']); $this->assertEquals('Doctrine\Tests\ORM\Tools\Export\Phonenumber', $class->associationMappings['phonenumbers']['targetEntity']); $this->assertEquals('user', $class->associationMappings['phonenumbers']['mappedBy']); $this->assertEquals(array('number' => 'ASC'), $class->associationMappings['phonenumbers']['orderBy']); - $this->assertFalse($class->associationMappings['phonenumbers']['isCascadeRemove']); + $this->assertTrue($class->associationMappings['phonenumbers']['isCascadeRemove']); $this->assertTrue($class->associationMappings['phonenumbers']['isCascadePersist']); $this->assertFalse($class->associationMappings['phonenumbers']['isCascadeRefresh']); - $this->assertFalse($class->associationMappings['phonenumbers']['isCascadeMerge']); + $this->assertTrue($class->associationMappings['phonenumbers']['isCascadeMerge']); $this->assertFalse($class->associationMappings['phonenumbers']['isCascadeDetach']); + $this->assertTrue($class->associationMappings['phonenumbers']['orphanRemoval']); return $class; } @@ -256,7 +257,7 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest public function testManyToManyAssociationsAreExported($class) { $this->assertTrue(isset($class->associationMappings['groups'])); - //$this->assertTrue($class->associationMappings['groups'] instanceof \Doctrine\ORM\Mapping\ManyToManyMapping); + //$this->assertInstanceOf('Doctrine\ORM\Mapping\ManyToManyMapping', $class->associationMappings['groups']); $this->assertEquals('Doctrine\Tests\ORM\Tools\Export\Group', $class->associationMappings['groups']['targetEntity']); $this->assertEquals('cms_users_groups', $class->associationMappings['groups']['joinTable']['name']); @@ -301,9 +302,11 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest public function testCascadeIsExported($class) { $this->assertTrue($class->associationMappings['phonenumbers']['isCascadePersist']); - $this->assertFalse($class->associationMappings['phonenumbers']['isCascadeMerge']); - $this->assertFalse($class->associationMappings['phonenumbers']['isCascadeRemove']); + $this->assertTrue($class->associationMappings['phonenumbers']['isCascadeMerge']); + $this->assertTrue($class->associationMappings['phonenumbers']['isCascadeRemove']); $this->assertFalse($class->associationMappings['phonenumbers']['isCascadeRefresh']); + $this->assertFalse($class->associationMappings['phonenumbers']['isCascadeDetach']); + $this->assertTrue($class->associationMappings['phonenumbers']['orphanRemoval']); return $class; } diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/annotation/Doctrine.Tests.ORM.Tools.Export.User.php b/tests/Doctrine/Tests/ORM/Tools/Export/annotation/Doctrine.Tests.ORM.Tools.Export.User.php index e71da460e..ddeece824 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/annotation/Doctrine.Tests.ORM.Tools.Export.User.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/annotation/Doctrine.Tests.ORM.Tools.Export.User.php @@ -23,14 +23,14 @@ class User public $email; /** - * @OneToOne(targetEntity="Doctrine\Tests\ORM\Tools\Export\Address", cascade={"remove"}, inversedBy="user") - * @JoinColumn(name="address_id", onDelete="CASCADE", onUpdate="CASCADE") + * @OneToOne(targetEntity="Doctrine\Tests\ORM\Tools\Export\Address", inversedBy="user", cascade={"persist"}, orphanRemoval=true) + * @JoinColumn(name="address_id", onDelete="CASCADE") */ public $address; /** * - * @OneToMany(targetEntity="Doctrine\Tests\ORM\Tools\Export\Phonenumber", mappedBy="user", cascade={"persist"}) + * @OneToMany(targetEntity="Doctrine\Tests\ORM\Tools\Export\Phonenumber", mappedBy="user", cascade={"persist", "merge"}, orphanRemoval=true) * @OrderBy({"number"="ASC"}) */ public $phonenumbers; 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 1a3824543..c50d2a75b 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 @@ -37,7 +37,7 @@ $metadata->mapOneToOne(array( 'inversedBy' => 'user', 'cascade' => array( - 0 => 'remove', + 0 => 'persist', ), 'mappedBy' => NULL, 'joinColumns' => @@ -47,10 +47,9 @@ $metadata->mapOneToOne(array( 'name' => 'address_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE', - 'onUpdate' => 'CASCADE' ), ), - 'orphanRemoval' => false, + 'orphanRemoval' => true, )); $metadata->mapOneToMany(array( 'fieldName' => 'phonenumbers', @@ -58,9 +57,10 @@ $metadata->mapOneToMany(array( 'cascade' => array( 1 => 'persist', + 2 => 'merge', ), 'mappedBy' => 'user', - 'orphanRemoval' => false, + 'orphanRemoval' => true, 'orderBy' => array( 'number' => 'ASC', 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 11bb6ac95..c562003c6 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 @@ -20,18 +20,19 @@ - - + + - + + + + + - - - 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 2b3048fba..9231bb189 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 @@ -23,16 +23,17 @@ Doctrine\Tests\ORM\Tools\Export\User: name: address_id referencedColumnName: id onDelete: CASCADE - onUpdate: CASCADE - cascade: [ remove ] + cascade: [ persist ] inversedBy: user + orphanRemoval: true oneToMany: phonenumbers: targetEntity: Doctrine\Tests\ORM\Tools\Export\Phonenumber mappedBy: user orderBy: number: ASC - cascade: [ persist ] + cascade: [ persist, merge ] + orphanRemoval: true manyToMany: groups: targetEntity: Doctrine\Tests\ORM\Tools\Export\Group diff --git a/tests/Doctrine/Tests/ORM/Tools/SetupTest.php b/tests/Doctrine/Tests/ORM/Tools/SetupTest.php new file mode 100644 index 000000000..643464df0 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Tools/SetupTest.php @@ -0,0 +1,106 @@ +markTestSkipped("Test only runs in a dev-installation from Github"); + } + + $this->originalAutoloaderCount = count(spl_autoload_functions()); + $this->originalIncludePath = get_include_path(); + } + + public function testGitAutoload() + { + Setup::registerAutoloadGit(__DIR__ . "/../../../../../"); + + $this->assertEquals($this->originalAutoloaderCount + 4, count(spl_autoload_functions())); + } + + public function testPEARAutoload() + { + set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ . "/../../../../../lib/vendor/doctrine-common/lib"); + + Setup::registerAutoloadPEAR(); + + $this->assertEquals($this->originalAutoloaderCount + 2, count(spl_autoload_functions())); + } + + public function testDirectoryAutoload() + { + Setup::registerAutoloadDirectory(__DIR__ . "/../../../../../lib/vendor/doctrine-common/lib"); + + $this->assertEquals($this->originalAutoloaderCount + 2, count(spl_autoload_functions())); + } + + public function testAnnotationConfiguration() + { + $config = Setup::createAnnotationMetadataConfiguration(array(), true); + + $this->assertInstanceOf('Doctrine\ORM\Configuration', $config); + $this->assertEquals(sys_get_temp_dir(), $config->getProxyDir()); + $this->assertEquals('DoctrineProxies', $config->getProxyNamespace()); + $this->assertInstanceOf('Doctrine\ORM\Mapping\Driver\AnnotationDriver', $config->getMetadataDriverImpl()); + } + + public function testXMLConfiguration() + { + $config = Setup::createXMLMetadataConfiguration(array(), true); + + $this->assertInstanceOf('Doctrine\ORM\Configuration', $config); + $this->assertInstanceOf('Doctrine\ORM\Mapping\Driver\XmlDriver', $config->getMetadataDriverImpl()); + } + + public function testYAMLConfiguration() + { + $config = Setup::createYAMLMetadataConfiguration(array(), true); + + $this->assertInstanceOf('Doctrine\ORM\Configuration', $config); + $this->assertInstanceOf('Doctrine\ORM\Mapping\Driver\YamlDriver', $config->getMetadataDriverImpl()); + } + + /** + * @group DDC-1350 + */ + public function testConfigureProxyDir() + { + $config = Setup::createAnnotationMetadataConfiguration(array(), true, "/foo"); + $this->assertEquals('/foo', $config->getProxyDir()); + } + + /** + * @group DDC-1350 + */ + public function testConfigureCache() + { + $cache = new ArrayCache(); + $config = Setup::createAnnotationMetadataConfiguration(array(), true, null, $cache); + + $this->assertSame($cache, $config->getResultCacheImpl()); + $this->assertSame($cache, $config->getMetadataCacheImpl()); + $this->assertSame($cache, $config->getQueryCacheImpl()); + } + + public function tearDown() + { + set_include_path($this->originalIncludePath); + $loaders = spl_autoload_functions(); + for ($i = 0; $i < count($loaders); $i++) { + if ($i > $this->originalAutoloaderCount+1) { + spl_autoload_unregister($loaders[$i]); + } + } + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Tools/doctrine1schema/schema.yml b/tests/Doctrine/Tests/ORM/Tools/doctrine1schema/schema.yml index 67301c05d..efa24c791 100644 --- a/tests/Doctrine/Tests/ORM/Tools/doctrine1schema/schema.yml +++ b/tests/Doctrine/Tests/ORM/Tools/doctrine1schema/schema.yml @@ -24,6 +24,5 @@ Profile: relations: User: onDelete: CASCADE - onUpdate: CASCADE foreignType: one type: one \ No newline at end of file diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 166cdfb6a..0900e4e99 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -44,6 +44,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase 'Doctrine\Tests\Models\CMS\CmsUser', 'Doctrine\Tests\Models\CMS\CmsPhonenumber', 'Doctrine\Tests\Models\CMS\CmsAddress', + 'Doctrine\Tests\Models\CMS\CmsEmail', 'Doctrine\Tests\Models\CMS\CmsGroup', 'Doctrine\Tests\Models\CMS\CmsArticle', 'Doctrine\Tests\Models\CMS\CmsComment', @@ -98,12 +99,19 @@ abstract class OrmFunctionalTestCase extends OrmTestCase 'Doctrine\Tests\Models\DDC117\DDC117ArticleDetails', 'Doctrine\Tests\Models\DDC117\DDC117ApproveChanges', 'Doctrine\Tests\Models\DDC117\DDC117Editor', + 'Doctrine\Tests\Models\DDC117\DDC117Link', ), 'stockexchange' => array( 'Doctrine\Tests\Models\StockExchange\Bond', 'Doctrine\Tests\Models\StockExchange\Stock', 'Doctrine\Tests\Models\StockExchange\Market', ), + 'legacy' => array( + 'Doctrine\Tests\Models\Legacy\LegacyUser', + 'Doctrine\Tests\Models\Legacy\LegacyUserReference', + 'Doctrine\Tests\Models\Legacy\LegacyArticle', + 'Doctrine\Tests\Models\Legacy\LegacyCar', + ), ); protected function useModelSet($setName) @@ -191,6 +199,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase $conn->executeUpdate('DELETE FROM ddc117editor_ddc117translation'); $conn->executeUpdate('DELETE FROM DDC117Editor'); $conn->executeUpdate('DELETE FROM DDC117ApproveChanges'); + $conn->executeUpdate('DELETE FROM DDC117Link'); $conn->executeUpdate('DELETE FROM DDC117Reference'); $conn->executeUpdate('DELETE FROM DDC117ArticleDetails'); $conn->executeUpdate('DELETE FROM DDC117Translation'); @@ -202,6 +211,13 @@ abstract class OrmFunctionalTestCase extends OrmTestCase $conn->executeUpdate('DELETE FROM exchange_stocks'); $conn->executeUpdate('DELETE FROM exchange_markets'); } + if (isset($this->_usedModelSets['legacy'])) { + $conn->executeUpdate('DELETE FROM legacy_users_cars'); + $conn->executeUpdate('DELETE FROM legacy_users_reference'); + $conn->executeUpdate('DELETE FROM legacy_articles'); + $conn->executeUpdate('DELETE FROM legacy_cars'); + $conn->executeUpdate('DELETE FROM legacy_users'); + } $this->_em->clear(); } @@ -288,6 +304,25 @@ abstract class OrmFunctionalTestCase extends OrmTestCase $conn = static::$_sharedConn; $conn->getConfiguration()->setSQLLogger($this->_sqlLoggerStack); + + // get rid of more global state + $evm = $conn->getEventManager(); + foreach ($evm->getListeners() AS $event => $listeners) { + foreach ($listeners AS $listener) { + $evm->removeEventListener(array($event), $listener); + } + } + + if (isset($GLOBALS['db_event_subscribers'])) { + foreach (explode(",", $GLOBALS['db_event_subscribers']) AS $subscriberClass) { + $subscriberInstance = new $subscriberClass(); + $evm->addEventSubscriber($subscriberInstance); + } + } + + if (isset($GLOBALS['debug_uow_listener'])) { + $evm->addEventListener(array('onFlush'), new \Doctrine\ORM\Tools\DebugUnitOfWorkListener()); + } return \Doctrine\ORM\EntityManager::create($conn, $config); } diff --git a/tests/Doctrine/Tests/OrmFunctionalTestSuite.php b/tests/Doctrine/Tests/OrmFunctionalTestSuite.php deleted file mode 100644 index 8d4b8b058..000000000 --- a/tests/Doctrine/Tests/OrmFunctionalTestSuite.php +++ /dev/null @@ -1,15 +0,0 @@ -=')) { + $reader = new \Doctrine\Common\Annotations\CachedReader( + new \Doctrine\Common\Annotations\AnnotationReader(), new ArrayCache() + ); + } + else if (version_compare(\Doctrine\Common\Version::VERSION, '2.2.0-DEV', '>=')) { + // Register the ORM Annotations in the AnnotationRegistry + $reader = new \Doctrine\Common\Annotations\SimpleAnnotationReader(); + $reader->addNamespace('Doctrine\ORM\Mapping'); + $reader = new \Doctrine\Common\Annotations\CachedReader($reader, new ArrayCache()); + } + else if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0-BETA3-DEV', '>=')) { + $reader = new \Doctrine\Common\Annotations\AnnotationReader(); + $reader->setIgnoreNotImportedAnnotations(true); + $reader->setEnableParsePhpImports(false); + if ($alias) { + $reader->setAnnotationNamespaceAlias('Doctrine\ORM\Mapping\\', $alias); + } else { + $reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\'); + } + $reader = new \Doctrine\Common\Annotations\CachedReader( + new \Doctrine\Common\Annotations\IndexedReader($reader), new ArrayCache() + ); + } else { + $reader = new \Doctrine\Common\Annotations\AnnotationReader(); + if ($alias) { + $reader->setAnnotationNamespaceAlias('Doctrine\ORM\Mapping\\', $alias); + } else { + $reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\'); + } + } + return new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, (array)$paths); + } + /** * Creates an EntityManager for testing purposes. * diff --git a/tests/Doctrine/Tests/OrmTestSuite.php b/tests/Doctrine/Tests/OrmTestSuite.php deleted file mode 100644 index b387b71dc..000000000 --- a/tests/Doctrine/Tests/OrmTestSuite.php +++ /dev/null @@ -1,10 +0,0 @@ -register(); -$classLoader = new \Doctrine\Common\ClassLoader('Doctrine'); +$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\ORM', __DIR__ . '/../../../lib'); +$classLoader->register(); + +$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\Tests', __DIR__ . '/../../'); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Symfony', __DIR__ . "/../../../lib/vendor"); @@ -38,9 +41,3 @@ if (!file_exists(__DIR__."/ORM/Proxy/generated")) { throw new Exception("Could not create " . __DIR__."/ORM/Proxy/generated Folder."); } } - -set_include_path( - __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'lib' - . PATH_SEPARATOR . - get_include_path() -); \ No newline at end of file diff --git a/tests/Doctrine/Tests/TestUtil.php b/tests/Doctrine/Tests/TestUtil.php index 5a187e595..a77812f7f 100644 --- a/tests/Doctrine/Tests/TestUtil.php +++ b/tests/Doctrine/Tests/TestUtil.php @@ -77,17 +77,7 @@ class TestUtil } } - $eventManager = null; - if (isset($GLOBALS['db_event_subscribers'])) { - $eventManager = new \Doctrine\Common\EventManager(); - foreach (explode(",", $GLOBALS['db_event_subscribers']) AS $subscriberClass) { - $subscriberInstance = new $subscriberClass(); - $eventManager->addEventSubscriber($subscriberInstance); - } - } - - $conn = \Doctrine\DBAL\DriverManager::getConnection($realDbParams, null, $eventManager); - + $conn = \Doctrine\DBAL\DriverManager::getConnection($realDbParams, null, null); } else { $params = array( 'driver' => 'pdo_sqlite',